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.

CarlaBridgeSingleLV2.cpp 22KB

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