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 23KB

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