Audio plugin host https://kx.studio/carla
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

719 lines
22KB

  1. /*
  2. * Carla LV2 Single Plugin
  3. * Copyright (C) 2017-2018 Filipe Coelho <falktx@falktx.com>
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License as
  7. * published by the Free Software Foundation; either version 2 of
  8. * the License, or any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * For a full copy of the GNU General Public License see the doc/GPL.txt file.
  16. */
  17. #ifndef BUILD_BRIDGE
  18. # error This file should not be compiled if not building bridge
  19. #endif
  20. #include "engine/CarlaEngineInternal.hpp"
  21. #include "CarlaPlugin.hpp"
  22. #include "CarlaBackendUtils.hpp"
  23. #include "CarlaEngineUtils.hpp"
  24. #include "CarlaLv2Utils.hpp"
  25. #include "CarlaUtils.h"
  26. #include "water/files/File.h"
  27. // --------------------------------------------------------------------------------------------------------------------
  28. CARLA_BACKEND_START_NAMESPACE
  29. class CarlaEngineSingleLV2 : public CarlaEngine,
  30. public Lv2PluginBaseClass<EngineTimeInfo>
  31. {
  32. public:
  33. CarlaEngineSingleLV2(const double sampleRate,
  34. const char* const bundlePath,
  35. const LV2_Feature* const* const features)
  36. : Lv2PluginBaseClass(sampleRate, features),
  37. fPlugin(nullptr),
  38. fUiName()
  39. {
  40. CARLA_SAFE_ASSERT_RETURN(pData->curPluginCount == 0,)
  41. CARLA_SAFE_ASSERT_RETURN(pData->plugins[0].plugin == nullptr,);
  42. if (! loadedInProperHost())
  43. return;
  44. // xxxxx
  45. CarlaString binaryDir(bundlePath);
  46. binaryDir += CARLA_OS_SEP_STR "bin" CARLA_OS_SEP_STR;
  47. CarlaString resourceDir(bundlePath);
  48. resourceDir += CARLA_OS_SEP_STR "res" CARLA_OS_SEP_STR;
  49. pData->bufferSize = fBufferSize;
  50. pData->sampleRate = sampleRate;
  51. pData->initTime(nullptr);
  52. pData->options.processMode = ENGINE_PROCESS_MODE_BRIDGE;
  53. pData->options.transportMode = ENGINE_TRANSPORT_MODE_PLUGIN;
  54. pData->options.forceStereo = false;
  55. pData->options.preferPluginBridges = false;
  56. pData->options.preferUiBridges = false;
  57. init("LV2-Export");
  58. if (pData->options.resourceDir != nullptr)
  59. delete[] pData->options.resourceDir;
  60. if (pData->options.binaryDir != nullptr)
  61. delete[] pData->options.binaryDir;
  62. pData->options.binaryDir = binaryDir.dup();
  63. pData->options.resourceDir = resourceDir.dup();
  64. setCallback(_engine_callback, this);
  65. using water::File;
  66. const File pluginFile(File::getSpecialLocation(File::currentExecutableFile).withFileExtension("xml"));
  67. if (! loadProject(pluginFile.getFullPathName().toRawUTF8()))
  68. {
  69. carla_stderr2("Failed to init plugin, possible reasons: %s", getLastError());
  70. return;
  71. }
  72. CARLA_SAFE_ASSERT_RETURN(pData->curPluginCount == 1,)
  73. fPlugin = pData->plugins[0].plugin;
  74. CARLA_SAFE_ASSERT_RETURN(fPlugin != nullptr,);
  75. CARLA_SAFE_ASSERT_RETURN(fPlugin->isEnabled(),);
  76. fPorts.usesTime = true;
  77. fPorts.numAudioIns = fPlugin->getAudioInCount();
  78. fPorts.numAudioOuts = fPlugin->getAudioOutCount();
  79. fPorts.numMidiIns = fPlugin->getMidiInCount();
  80. fPorts.numMidiOuts = fPlugin->getMidiOutCount();
  81. fPorts.numParams = fPlugin->getParameterCount();
  82. fPorts.init();
  83. for (uint32_t i=0; i < fPorts.numParams; ++i)
  84. {
  85. fPorts.paramsLast[i] = fPlugin->getParameterValue(i);
  86. fPorts.paramsOut [i] = fPlugin->isParameterOutput(i);
  87. }
  88. }
  89. ~CarlaEngineSingleLV2()
  90. {
  91. if (fPlugin != nullptr && fIsActive)
  92. fPlugin->setActive(false, false, false);
  93. close();
  94. }
  95. bool hasPlugin() noexcept
  96. {
  97. return fPlugin != nullptr;
  98. }
  99. // ----------------------------------------------------------------------------------------------------------------
  100. // LV2 functions
  101. void lv2_activate() noexcept
  102. {
  103. CARLA_SAFE_ASSERT_RETURN(! fIsActive,);
  104. resetTimeInfo();
  105. fPlugin->setActive(true, false, false);
  106. fIsActive = true;
  107. }
  108. void lv2_deactivate() noexcept
  109. {
  110. CARLA_SAFE_ASSERT_RETURN(fIsActive,);
  111. fIsActive = false;
  112. fPlugin->setActive(false, false, false);
  113. }
  114. void lv2_run(const uint32_t frames)
  115. {
  116. //const PendingRtEventsRunner prt(this, frames);
  117. if (! lv2_pre_run(frames))
  118. {
  119. updateParameterOutputs();
  120. return;
  121. }
  122. if (fPorts.numMidiIns > 0)
  123. {
  124. uint32_t engineEventIndex = 0;
  125. carla_zeroStructs(pData->events.in, kMaxEngineEventInternalCount);
  126. for (uint32_t i=0; i < fPorts.numMidiIns; ++i)
  127. {
  128. LV2_ATOM_SEQUENCE_FOREACH(fPorts.eventsIn[i], event)
  129. {
  130. if (event == nullptr)
  131. continue;
  132. if (event->body.type != fURIs.midiEvent)
  133. continue;
  134. if (event->body.size > 4)
  135. continue;
  136. if (event->time.frames >= frames)
  137. break;
  138. const uint8_t* const data((const uint8_t*)(event + 1));
  139. EngineEvent& engineEvent(pData->events.in[engineEventIndex++]);
  140. engineEvent.time = (uint32_t)event->time.frames;
  141. engineEvent.fillFromMidiData((uint8_t)event->body.size, data, (uint8_t)i);
  142. if (engineEventIndex >= kMaxEngineEventInternalCount)
  143. break;
  144. }
  145. }
  146. }
  147. if (fPorts.numMidiOuts > 0)
  148. {
  149. carla_zeroStructs(pData->events.out, kMaxEngineEventInternalCount);
  150. }
  151. if (fPlugin->tryLock(fIsOffline))
  152. {
  153. fPlugin->initBuffers();
  154. fPlugin->process(fPorts.audioIns, fPorts.audioOuts, nullptr, nullptr, frames);
  155. fPlugin->unlock();
  156. if (fPorts.numMidiOuts > 0)
  157. {
  158. uint8_t port = 0;
  159. uint8_t size = 0;
  160. uint8_t mdata[3] = { 0, 0, 0 };
  161. uint8_t mdataTmp[EngineMidiEvent::kDataSize];
  162. const uint8_t* mdataPtr;
  163. for (ushort i=0; i < kMaxEngineEventInternalCount; ++i)
  164. {
  165. const EngineEvent& engineEvent(pData->events.out[i]);
  166. /**/ if (engineEvent.type == kEngineEventTypeNull)
  167. {
  168. break;
  169. }
  170. else if (engineEvent.type == kEngineEventTypeControl)
  171. {
  172. const EngineControlEvent& ctrlEvent(engineEvent.ctrl);
  173. size = ctrlEvent.convertToMidiData(engineEvent.channel, mdata);
  174. mdataPtr = mdata;
  175. }
  176. else if (engineEvent.type == kEngineEventTypeMidi)
  177. {
  178. const EngineMidiEvent& midiEvent(engineEvent.midi);
  179. port = midiEvent.port;
  180. size = midiEvent.size;
  181. CARLA_SAFE_ASSERT_CONTINUE(size > 0);
  182. if (size > EngineMidiEvent::kDataSize)
  183. {
  184. CARLA_SAFE_ASSERT_CONTINUE(midiEvent.dataExt != nullptr);
  185. mdataPtr = midiEvent.dataExt;
  186. }
  187. else
  188. {
  189. // set first byte
  190. mdataTmp[0] = static_cast<uint8_t>(midiEvent.data[0] | (engineEvent.channel & MIDI_CHANNEL_BIT));
  191. // copy rest
  192. carla_copy<uint8_t>(mdataTmp+1, midiEvent.data+1, size-1);
  193. // done
  194. mdataPtr = mdataTmp;
  195. }
  196. }
  197. else
  198. {
  199. continue;
  200. }
  201. if (size > 0 && ! writeMidiEvent(port, engineEvent.time, size, mdataPtr))
  202. break;
  203. }
  204. }
  205. }
  206. else
  207. {
  208. for (uint32_t i=0; i<fPorts.numAudioOuts; ++i)
  209. carla_zeroFloats(fPorts.audioOuts[i], frames);
  210. }
  211. lv2_post_run(frames);
  212. updateParameterOutputs();
  213. }
  214. // ----------------------------------------------------------------------------------------------------------------
  215. bool lv2ui_instantiate(LV2UI_Write_Function writeFunction, LV2UI_Controller controller,
  216. LV2UI_Widget* widget, const LV2_Feature* const* features)
  217. {
  218. fUI.writeFunction = writeFunction;
  219. fUI.controller = controller;
  220. fUI.host = nullptr;
  221. fUiName.clear();
  222. const LV2_URID_Map* uridMap = nullptr;
  223. // ------------------------------------------------------------------------------------------------------------
  224. // see if the host supports external-ui, get uridMap
  225. for (int i=0; features[i] != nullptr; ++i)
  226. {
  227. if (std::strcmp(features[i]->URI, LV2_EXTERNAL_UI__Host) == 0 ||
  228. std::strcmp(features[i]->URI, LV2_EXTERNAL_UI_DEPRECATED_URI) == 0)
  229. {
  230. fUI.host = (const LV2_External_UI_Host*)features[i]->data;
  231. }
  232. else if (std::strcmp(features[i]->URI, LV2_URID__map) == 0)
  233. {
  234. uridMap = (const LV2_URID_Map*)features[i]->data;
  235. }
  236. }
  237. if (fUI.host != nullptr)
  238. {
  239. fUiName = fUI.host->plugin_human_id;
  240. *widget = (LV2_External_UI_Widget_Compat*)this;
  241. return true;
  242. }
  243. // ------------------------------------------------------------------------------------------------------------
  244. // no external-ui support, use showInterface
  245. for (int i=0; features[i] != nullptr; ++i)
  246. {
  247. if (std::strcmp(features[i]->URI, LV2_OPTIONS__options) == 0)
  248. {
  249. const LV2_Options_Option* const options((const LV2_Options_Option*)features[i]->data);
  250. for (int j=0; options[j].key != 0; ++j)
  251. {
  252. if (options[j].key == uridMap->map(uridMap->handle, LV2_UI__windowTitle))
  253. {
  254. fUiName = (const char*)options[j].value;
  255. break;
  256. }
  257. }
  258. break;
  259. }
  260. }
  261. if (fUiName.isEmpty())
  262. fUiName = fPlugin->getName();
  263. *widget = nullptr;
  264. return true;
  265. }
  266. void lv2ui_port_event(uint32_t portIndex, uint32_t bufferSize, uint32_t format, const void* buffer) const
  267. {
  268. if (format != 0 || bufferSize != sizeof(float) || buffer == nullptr)
  269. return;
  270. if (portIndex >= fPorts.indexOffset || ! fUI.isVisible)
  271. return;
  272. const float value(*(const float*)buffer);
  273. fPlugin->uiParameterChange(portIndex-fPorts.indexOffset, value);
  274. }
  275. protected:
  276. // ----------------------------------------------------------------------------------------------------------------
  277. // CarlaEngine virtual calls
  278. bool init(const char* const clientName) override
  279. {
  280. carla_stdout("CarlaEngineNative::init(\"%s\")", clientName);
  281. if (! pData->init(clientName))
  282. {
  283. close();
  284. setLastError("Failed to init internal data");
  285. return false;
  286. }
  287. return true;
  288. }
  289. bool isRunning() const noexcept override
  290. {
  291. return fIsActive;
  292. }
  293. bool isOffline() const noexcept override
  294. {
  295. return fIsOffline;
  296. }
  297. bool usesConstantBufferSize() const noexcept override
  298. {
  299. return false;
  300. }
  301. EngineType getType() const noexcept override
  302. {
  303. return kEngineTypePlugin;
  304. }
  305. const char* getCurrentDriverName() const noexcept override
  306. {
  307. return "LV2 Plugin";
  308. }
  309. void engineCallback(const EngineCallbackOpcode action, const uint pluginId, const int value1, const int value2, const float value3, const char* const valueStr)
  310. {
  311. switch (action)
  312. {
  313. case ENGINE_CALLBACK_PARAMETER_VALUE_CHANGED:
  314. CARLA_SAFE_ASSERT_RETURN(value1 >= 0,);
  315. if (fUI.writeFunction != nullptr && fUI.controller != nullptr && fUI.isVisible)
  316. {
  317. fUI.writeFunction(fUI.controller,
  318. static_cast<uint32_t>(value1)+fPorts.indexOffset,
  319. sizeof(float), 0, &value3);
  320. }
  321. break;
  322. case ENGINE_CALLBACK_UI_STATE_CHANGED:
  323. fUI.isVisible = (value1 == 1);
  324. if (fUI.host != nullptr)
  325. fUI.host->ui_closed(fUI.controller);
  326. break;
  327. case ENGINE_CALLBACK_IDLE:
  328. break;
  329. default:
  330. carla_stdout("engineCallback(%i:%s, %u, %i, %i, %f, %s)",
  331. action, EngineCallbackOpcode2Str(action), pluginId, value1, value2, value3, valueStr);
  332. break;
  333. }
  334. }
  335. // ----------------------------------------------------------------------------------------------------------------
  336. void handleUiRun() const override
  337. {
  338. try {
  339. fPlugin->uiIdle();
  340. } CARLA_SAFE_EXCEPTION("fPlugin->uiIdle()")
  341. }
  342. void handleUiShow() override
  343. {
  344. fPlugin->showCustomUI(true);
  345. fUI.isVisible = true;
  346. }
  347. void handleUiHide() override
  348. {
  349. fUI.isVisible = false;
  350. fPlugin->showCustomUI(false);
  351. }
  352. // ----------------------------------------------------------------------------------------------------------------
  353. void handleParameterValueChanged(const uint32_t index, const float value) override
  354. {
  355. fPlugin->setParameterValue(index, value, false, false, false);
  356. }
  357. void handleBufferSizeChanged(const uint32_t bufferSize) override
  358. {
  359. CarlaEngine::bufferSizeChanged(bufferSize);
  360. }
  361. void handleSampleRateChanged(const double sampleRate) override
  362. {
  363. CarlaEngine::sampleRateChanged(sampleRate);
  364. }
  365. // ----------------------------------------------------------------------------------------------------------------
  366. private:
  367. CarlaPlugin* fPlugin;
  368. CarlaString fUiName;
  369. void updateParameterOutputs() noexcept
  370. {
  371. float value;
  372. for (uint32_t i=0; i < fPorts.numParams; ++i)
  373. {
  374. if (! fPorts.paramsOut[i])
  375. continue;
  376. fPorts.paramsLast[i] = value = fPlugin->getParameterValue(i);
  377. if (fPorts.paramsPtr[i] != nullptr)
  378. *fPorts.paramsPtr[i] = value;
  379. }
  380. }
  381. bool writeMidiEvent(const uint8_t port, const uint32_t time, const uint8_t midiSize, const uint8_t* midiData)
  382. {
  383. CARLA_SAFE_ASSERT_RETURN(fPorts.numMidiOuts > 0, false);
  384. CARLA_SAFE_ASSERT_RETURN(port < fPorts.numMidiOuts, false);
  385. CARLA_SAFE_ASSERT_RETURN(midiData != nullptr, false);
  386. CARLA_SAFE_ASSERT_RETURN(midiSize > 0, false);
  387. LV2_Atom_Sequence* const seq(fPorts.midiOuts[port]);
  388. CARLA_SAFE_ASSERT_RETURN(seq != nullptr, false);
  389. Ports::MidiOutData& mData(fPorts.midiOutData[port]);
  390. if (sizeof(LV2_Atom_Event) + midiSize > mData.capacity - mData.offset)
  391. return false;
  392. LV2_Atom_Event* const aev = (LV2_Atom_Event*)(LV2_ATOM_CONTENTS(LV2_Atom_Sequence, seq) + mData.offset);
  393. aev->time.frames = time;
  394. aev->body.size = midiSize;
  395. aev->body.type = fURIs.midiEvent;
  396. std::memcpy(LV2_ATOM_BODY(&aev->body), midiData, midiSize);
  397. const uint32_t size = lv2_atom_pad_size(static_cast<uint32_t>(sizeof(LV2_Atom_Event) + midiSize));
  398. mData.offset += size;
  399. seq->atom.size += size;
  400. return true;
  401. }
  402. // -------------------------------------------------------------------
  403. #define handlePtr ((CarlaEngineSingleLV2*)handle)
  404. static void _engine_callback(void* handle, EngineCallbackOpcode action, uint pluginId, int value1, int value2, float value3, const char* valueStr)
  405. {
  406. handlePtr->engineCallback(action, pluginId, value1, value2, value3, valueStr);
  407. }
  408. #undef handlePtr
  409. CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(CarlaEngineSingleLV2)
  410. };
  411. CARLA_BACKEND_END_NAMESPACE
  412. using CarlaBackend::CarlaEngineSingleLV2;
  413. // --------------------------------------------------------------------------------------------------------------------
  414. // LV2 DSP functions
  415. static LV2_Handle lv2_instantiate(const LV2_Descriptor* lv2Descriptor, double sampleRate, const char* bundlePath, const LV2_Feature* const* features)
  416. {
  417. carla_stdout("lv2_instantiate(%p, %g, %s, %p)", lv2Descriptor, sampleRate, bundlePath, features);
  418. CarlaEngineSingleLV2* const instance(new CarlaEngineSingleLV2(sampleRate, bundlePath, features));
  419. if (instance->hasPlugin())
  420. return (LV2_Handle)instance;
  421. delete instance;
  422. return nullptr;
  423. }
  424. #define instancePtr ((CarlaEngineSingleLV2*)instance)
  425. static void lv2_connect_port(LV2_Handle instance, uint32_t port, void* dataLocation)
  426. {
  427. instancePtr->lv2_connect_port(port, dataLocation);
  428. }
  429. static void lv2_activate(LV2_Handle instance)
  430. {
  431. carla_debug("lv2_activate(%p)", instance);
  432. instancePtr->lv2_activate();
  433. }
  434. static void lv2_run(LV2_Handle instance, uint32_t sampleCount)
  435. {
  436. instancePtr->lv2_run(sampleCount);
  437. }
  438. static void lv2_deactivate(LV2_Handle instance)
  439. {
  440. carla_debug("lv2_deactivate(%p)", instance);
  441. instancePtr->lv2_deactivate();
  442. }
  443. static void lv2_cleanup(LV2_Handle instance)
  444. {
  445. carla_debug("lv2_cleanup(%p)", instance);
  446. delete instancePtr;
  447. }
  448. static const void* lv2_extension_data(const char* uri)
  449. {
  450. carla_debug("lv2_extension_data(\"%s\")", uri);
  451. return nullptr;
  452. // unused
  453. (void)uri;
  454. }
  455. #undef instancePtr
  456. // --------------------------------------------------------------------------------------------------------------------
  457. // LV2 UI functions
  458. static LV2UI_Handle lv2ui_instantiate(const LV2UI_Descriptor*, const char*, const char*,
  459. LV2UI_Write_Function writeFunction, LV2UI_Controller controller,
  460. LV2UI_Widget* widget, const LV2_Feature* const* features)
  461. {
  462. carla_debug("lv2ui_instantiate(..., %p, %p, %p)", writeFunction, controller, widget, features);
  463. CarlaEngineSingleLV2* engine = nullptr;
  464. for (int i=0; features[i] != nullptr; ++i)
  465. {
  466. if (std::strcmp(features[i]->URI, LV2_INSTANCE_ACCESS_URI) == 0)
  467. {
  468. engine = (CarlaEngineSingleLV2*)features[i]->data;
  469. break;
  470. }
  471. }
  472. if (engine == nullptr)
  473. {
  474. carla_stderr("Host doesn't support instance-access, cannot show UI");
  475. return nullptr;
  476. }
  477. if (! engine->lv2ui_instantiate(writeFunction, controller, widget, features))
  478. return nullptr;
  479. return (LV2UI_Handle)engine;
  480. }
  481. #define uiPtr ((CarlaEngineSingleLV2*)ui)
  482. static void lv2ui_port_event(LV2UI_Handle ui, uint32_t portIndex, uint32_t bufferSize, uint32_t format, const void* buffer)
  483. {
  484. carla_debug("lv2ui_port_event(%p, %i, %i, %i, %p)", ui, portIndex, bufferSize, format, buffer);
  485. uiPtr->lv2ui_port_event(portIndex, bufferSize, format, buffer);
  486. }
  487. static void lv2ui_cleanup(LV2UI_Handle ui)
  488. {
  489. carla_debug("lv2ui_cleanup(%p)", ui);
  490. uiPtr->lv2ui_cleanup();
  491. }
  492. static int lv2ui_idle(LV2UI_Handle ui)
  493. {
  494. return uiPtr->lv2ui_idle();
  495. }
  496. static int lv2ui_show(LV2UI_Handle ui)
  497. {
  498. carla_debug("lv2ui_show(%p)", ui);
  499. return uiPtr->lv2ui_show();
  500. }
  501. static int lv2ui_hide(LV2UI_Handle ui)
  502. {
  503. carla_debug("lv2ui_hide(%p)", ui);
  504. return uiPtr->lv2ui_hide();
  505. }
  506. static const void* lv2ui_extension_data(const char* uri)
  507. {
  508. carla_debug("lv2ui_extension_data(\"%s\")", uri);
  509. static const LV2UI_Idle_Interface uiidle = { lv2ui_idle };
  510. static const LV2UI_Show_Interface uishow = { lv2ui_show, lv2ui_hide };
  511. if (std::strcmp(uri, LV2_UI__idleInterface) == 0)
  512. return &uiidle;
  513. if (std::strcmp(uri, LV2_UI__showInterface) == 0)
  514. return &uishow;
  515. return nullptr;
  516. }
  517. #undef uiPtr
  518. // --------------------------------------------------------------------------------------------------------------------
  519. // Startup code
  520. CARLA_EXPORT
  521. const LV2_Descriptor* lv2_descriptor(uint32_t index)
  522. {
  523. carla_stdout("lv2_descriptor(%i)", index);
  524. if (index != 0)
  525. return nullptr;
  526. static CarlaString ret;
  527. if (ret.isEmpty())
  528. {
  529. using namespace water;
  530. const File file(File::getSpecialLocation(File::currentExecutableFile).withFileExtension("ttl"));
  531. ret = String("file://" + file.getFullPathName()).toRawUTF8();
  532. }
  533. static const LV2_Descriptor desc = {
  534. /* URI */ ret.buffer(),
  535. /* instantiate */ lv2_instantiate,
  536. /* connect_port */ lv2_connect_port,
  537. /* activate */ lv2_activate,
  538. /* run */ lv2_run,
  539. /* deactivate */ lv2_deactivate,
  540. /* cleanup */ lv2_cleanup,
  541. /* extension_data */ lv2_extension_data
  542. };
  543. return &desc;
  544. }
  545. CARLA_EXPORT
  546. const LV2UI_Descriptor* lv2ui_descriptor(uint32_t index)
  547. {
  548. carla_stdout("lv2ui_descriptor(%i)", index);
  549. static CarlaString ret;
  550. if (ret.isEmpty())
  551. {
  552. using namespace water;
  553. const File file(File::getSpecialLocation(File::currentExecutableFile).getSiblingFile("ext-ui"));
  554. ret = String("file://" + file.getFullPathName()).toRawUTF8();
  555. }
  556. static const LV2UI_Descriptor lv2UiExtDesc = {
  557. /* URI */ ret.buffer(),
  558. /* instantiate */ lv2ui_instantiate,
  559. /* cleanup */ lv2ui_cleanup,
  560. /* port_event */ lv2ui_port_event,
  561. /* extension_data */ lv2ui_extension_data
  562. };
  563. return (index == 0) ? &lv2UiExtDesc : nullptr;
  564. }
  565. // --------------------------------------------------------------------------------------------------------------------