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
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719
  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[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.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. CARLA_SAFE_ASSERT_RETURN(value1 >= 0,);
  316. if (fUI.writeFunction != nullptr && fUI.controller != nullptr && fUI.isVisible)
  317. {
  318. fUI.writeFunction(fUI.controller,
  319. static_cast<uint32_t>(value1)+fPorts.indexOffset,
  320. sizeof(float), 0, &value3);
  321. }
  322. break;
  323. case ENGINE_CALLBACK_UI_STATE_CHANGED:
  324. fUI.isVisible = (value1 == 1);
  325. if (fUI.host != nullptr)
  326. fUI.host->ui_closed(fUI.controller);
  327. break;
  328. case ENGINE_CALLBACK_IDLE:
  329. break;
  330. default:
  331. carla_stdout("engineCallback(%i:%s, %u, %i, %i, %f, %s)",
  332. action, EngineCallbackOpcode2Str(action), pluginId, value1, value2, value3, valueStr);
  333. break;
  334. }
  335. }
  336. // ----------------------------------------------------------------------------------------------------------------
  337. void handleUiRun() const override
  338. {
  339. try {
  340. fPlugin->uiIdle();
  341. } CARLA_SAFE_EXCEPTION("fPlugin->uiIdle()")
  342. }
  343. void handleUiShow() override
  344. {
  345. fPlugin->showCustomUI(true);
  346. fUI.isVisible = true;
  347. }
  348. void handleUiHide() override
  349. {
  350. fUI.isVisible = false;
  351. fPlugin->showCustomUI(false);
  352. }
  353. // ----------------------------------------------------------------------------------------------------------------
  354. void handleParameterValueChanged(const uint32_t index, const float value) override
  355. {
  356. fPlugin->setParameterValue(index, value, false, false, false);
  357. }
  358. void handleBufferSizeChanged(const uint32_t bufferSize) override
  359. {
  360. CarlaEngine::bufferSizeChanged(bufferSize);
  361. }
  362. void handleSampleRateChanged(const double sampleRate) override
  363. {
  364. CarlaEngine::sampleRateChanged(sampleRate);
  365. }
  366. // ----------------------------------------------------------------------------------------------------------------
  367. private:
  368. CarlaPlugin* fPlugin;
  369. CarlaString fUiName;
  370. void updateParameterOutputs() noexcept
  371. {
  372. float value;
  373. for (uint32_t i=0; i < fPorts.numParams; ++i)
  374. {
  375. if (! fPorts.paramsOut[i])
  376. continue;
  377. fPorts.paramsLast[i] = value = fPlugin->getParameterValue(i);
  378. if (fPorts.paramsPtr[i] != nullptr)
  379. *fPorts.paramsPtr[i] = value;
  380. }
  381. }
  382. bool writeMidiEvent(const uint8_t port, const uint32_t time, const uint8_t midiSize, const uint8_t* midiData)
  383. {
  384. CARLA_SAFE_ASSERT_RETURN(fPorts.numMidiOuts > 0, false);
  385. CARLA_SAFE_ASSERT_RETURN(port < fPorts.numMidiOuts, false);
  386. CARLA_SAFE_ASSERT_RETURN(midiData != nullptr, false);
  387. CARLA_SAFE_ASSERT_RETURN(midiSize > 0, false);
  388. LV2_Atom_Sequence* const seq(fPorts.eventsOut[port]);
  389. CARLA_SAFE_ASSERT_RETURN(seq != nullptr, false);
  390. Ports::EventsOutData& mData(fPorts.eventsOutData[port]);
  391. if (sizeof(LV2_Atom_Event) + midiSize > mData.capacity - mData.offset)
  392. return false;
  393. LV2_Atom_Event* const aev = (LV2_Atom_Event*)(LV2_ATOM_CONTENTS(LV2_Atom_Sequence, seq) + mData.offset);
  394. aev->time.frames = time;
  395. aev->body.size = midiSize;
  396. aev->body.type = fURIs.midiEvent;
  397. std::memcpy(LV2_ATOM_BODY(&aev->body), midiData, midiSize);
  398. const uint32_t size = lv2_atom_pad_size(static_cast<uint32_t>(sizeof(LV2_Atom_Event) + midiSize));
  399. mData.offset += size;
  400. seq->atom.size += size;
  401. return true;
  402. }
  403. // -------------------------------------------------------------------
  404. #define handlePtr ((CarlaEngineSingleLV2*)handle)
  405. static void _engine_callback(void* handle, EngineCallbackOpcode action, uint pluginId, int value1, int value2, float value3, const char* valueStr)
  406. {
  407. handlePtr->engineCallback(action, pluginId, value1, value2, value3, valueStr);
  408. }
  409. #undef handlePtr
  410. CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(CarlaEngineSingleLV2)
  411. };
  412. CARLA_BACKEND_END_NAMESPACE
  413. using CarlaBackend::CarlaEngineSingleLV2;
  414. // --------------------------------------------------------------------------------------------------------------------
  415. // LV2 DSP functions
  416. static LV2_Handle lv2_instantiate(const LV2_Descriptor* lv2Descriptor, double sampleRate, const char* bundlePath, const LV2_Feature* const* features)
  417. {
  418. carla_stdout("lv2_instantiate(%p, %g, %s, %p)", lv2Descriptor, sampleRate, bundlePath, features);
  419. CarlaEngineSingleLV2* const instance(new CarlaEngineSingleLV2(sampleRate, bundlePath, features));
  420. if (instance->hasPlugin())
  421. return (LV2_Handle)instance;
  422. delete instance;
  423. return nullptr;
  424. }
  425. #define instancePtr ((CarlaEngineSingleLV2*)instance)
  426. static void lv2_connect_port(LV2_Handle instance, uint32_t port, void* dataLocation)
  427. {
  428. instancePtr->lv2_connect_port(port, dataLocation);
  429. }
  430. static void lv2_activate(LV2_Handle instance)
  431. {
  432. carla_debug("lv2_activate(%p)", instance);
  433. instancePtr->lv2_activate();
  434. }
  435. static void lv2_run(LV2_Handle instance, uint32_t sampleCount)
  436. {
  437. instancePtr->lv2_run(sampleCount);
  438. }
  439. static void lv2_deactivate(LV2_Handle instance)
  440. {
  441. carla_debug("lv2_deactivate(%p)", instance);
  442. instancePtr->lv2_deactivate();
  443. }
  444. static void lv2_cleanup(LV2_Handle instance)
  445. {
  446. carla_debug("lv2_cleanup(%p)", instance);
  447. delete instancePtr;
  448. }
  449. static const void* lv2_extension_data(const char* uri)
  450. {
  451. carla_debug("lv2_extension_data(\"%s\")", uri);
  452. return nullptr;
  453. // unused
  454. (void)uri;
  455. }
  456. #undef instancePtr
  457. // --------------------------------------------------------------------------------------------------------------------
  458. // LV2 UI functions
  459. static LV2UI_Handle lv2ui_instantiate(const LV2UI_Descriptor*, const char*, const char*,
  460. LV2UI_Write_Function writeFunction, LV2UI_Controller controller,
  461. LV2UI_Widget* widget, const LV2_Feature* const* features)
  462. {
  463. carla_debug("lv2ui_instantiate(..., %p, %p, %p)", writeFunction, controller, widget, features);
  464. CarlaEngineSingleLV2* engine = nullptr;
  465. for (int i=0; features[i] != nullptr; ++i)
  466. {
  467. if (std::strcmp(features[i]->URI, LV2_INSTANCE_ACCESS_URI) == 0)
  468. {
  469. engine = (CarlaEngineSingleLV2*)features[i]->data;
  470. break;
  471. }
  472. }
  473. if (engine == nullptr)
  474. {
  475. carla_stderr("Host doesn't support instance-access, cannot show UI");
  476. return nullptr;
  477. }
  478. if (! engine->lv2ui_instantiate(writeFunction, controller, widget, features))
  479. return nullptr;
  480. return (LV2UI_Handle)engine;
  481. }
  482. #define uiPtr ((CarlaEngineSingleLV2*)ui)
  483. static void lv2ui_port_event(LV2UI_Handle ui, uint32_t portIndex, uint32_t bufferSize, uint32_t format, const void* buffer)
  484. {
  485. carla_debug("lv2ui_port_event(%p, %i, %i, %i, %p)", ui, portIndex, bufferSize, format, buffer);
  486. uiPtr->lv2ui_port_event(portIndex, bufferSize, format, buffer);
  487. }
  488. static void lv2ui_cleanup(LV2UI_Handle ui)
  489. {
  490. carla_debug("lv2ui_cleanup(%p)", ui);
  491. uiPtr->lv2ui_cleanup();
  492. }
  493. static int lv2ui_idle(LV2UI_Handle ui)
  494. {
  495. return uiPtr->lv2ui_idle();
  496. }
  497. static int lv2ui_show(LV2UI_Handle ui)
  498. {
  499. carla_debug("lv2ui_show(%p)", ui);
  500. return uiPtr->lv2ui_show();
  501. }
  502. static int lv2ui_hide(LV2UI_Handle ui)
  503. {
  504. carla_debug("lv2ui_hide(%p)", ui);
  505. return uiPtr->lv2ui_hide();
  506. }
  507. static const void* lv2ui_extension_data(const char* uri)
  508. {
  509. carla_debug("lv2ui_extension_data(\"%s\")", uri);
  510. static const LV2UI_Idle_Interface uiidle = { lv2ui_idle };
  511. static const LV2UI_Show_Interface uishow = { lv2ui_show, lv2ui_hide };
  512. if (std::strcmp(uri, LV2_UI__idleInterface) == 0)
  513. return &uiidle;
  514. if (std::strcmp(uri, LV2_UI__showInterface) == 0)
  515. return &uishow;
  516. return nullptr;
  517. }
  518. #undef uiPtr
  519. // --------------------------------------------------------------------------------------------------------------------
  520. // Startup code
  521. CARLA_EXPORT
  522. const LV2_Descriptor* lv2_descriptor(uint32_t index)
  523. {
  524. carla_stdout("lv2_descriptor(%i)", index);
  525. if (index != 0)
  526. return nullptr;
  527. static CarlaString ret;
  528. if (ret.isEmpty())
  529. {
  530. using namespace water;
  531. const File file(File::getSpecialLocation(File::currentExecutableFile).withFileExtension("ttl"));
  532. ret = String("file://" + file.getFullPathName()).toRawUTF8();
  533. }
  534. static const LV2_Descriptor desc = {
  535. /* URI */ ret.buffer(),
  536. /* instantiate */ lv2_instantiate,
  537. /* connect_port */ lv2_connect_port,
  538. /* activate */ lv2_activate,
  539. /* run */ lv2_run,
  540. /* deactivate */ lv2_deactivate,
  541. /* cleanup */ lv2_cleanup,
  542. /* extension_data */ lv2_extension_data
  543. };
  544. return &desc;
  545. }
  546. CARLA_EXPORT
  547. const LV2UI_Descriptor* lv2ui_descriptor(uint32_t index)
  548. {
  549. carla_stdout("lv2ui_descriptor(%i)", index);
  550. static CarlaString ret;
  551. if (ret.isEmpty())
  552. {
  553. using namespace water;
  554. const File file(File::getSpecialLocation(File::currentExecutableFile).getSiblingFile("ext-ui"));
  555. ret = String("file://" + file.getFullPathName()).toRawUTF8();
  556. }
  557. static const LV2UI_Descriptor lv2UiExtDesc = {
  558. /* URI */ ret.buffer(),
  559. /* instantiate */ lv2ui_instantiate,
  560. /* cleanup */ lv2ui_cleanup,
  561. /* port_event */ lv2ui_port_event,
  562. /* extension_data */ lv2ui_extension_data
  563. };
  564. return (index == 0) ? &lv2UiExtDesc : nullptr;
  565. }
  566. // --------------------------------------------------------------------------------------------------------------------