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.

847 lines
24KB

  1. /*
  2. * Carla LV2 Single Plugin
  3. * Copyright (C) 2017 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. // #define BUILD_BRIDGE
  18. #include "engine/CarlaEngineInternal.hpp"
  19. #include "CarlaPlugin.hpp"
  20. #include "CarlaBackendUtils.hpp"
  21. #include "CarlaEngineUtils.hpp"
  22. #include "CarlaLv2Utils.hpp"
  23. #include "CarlaUtils.h"
  24. #include "juce_audio_basics/juce_audio_basics.h"
  25. #if defined(CARLA_OS_MAC) || defined(CARLA_OS_WIN)
  26. # include "juce_gui_basics/juce_gui_basics.h"
  27. #else
  28. # include "juce_events/juce_events.h"
  29. #endif
  30. using juce::FloatVectorOperations;
  31. using juce::ScopedJuceInitialiser_GUI;
  32. using juce::SharedResourcePointer;
  33. // ---------------------------------------------------------------------------------------------------------------------
  34. CARLA_BACKEND_START_NAMESPACE
  35. class CarlaEngineLV2Single : public CarlaEngine,
  36. public LV2_External_UI_Widget
  37. {
  38. public:
  39. CarlaEngineLV2Single(const uint32_t bufferSize, const double sampleRate, const char* const bundlePath, const LV2_URID_Map* uridMap)
  40. : fPlugin(nullptr),
  41. fIsRunning(false),
  42. fIsOffline(false)
  43. {
  44. run = extui_run;
  45. show = extui_show;
  46. hide = extui_hide;
  47. // xxxxx
  48. CarlaString binaryDir(bundlePath);
  49. binaryDir += CARLA_OS_SEP_STR "bin" CARLA_OS_SEP_STR;
  50. CarlaString resourceDir(bundlePath);
  51. resourceDir += CARLA_OS_SEP_STR "res" CARLA_OS_SEP_STR;
  52. pData->bufferSize = bufferSize;
  53. pData->sampleRate = sampleRate;
  54. pData->initTime(nullptr);
  55. pData->options.processMode = ENGINE_PROCESS_MODE_BRIDGE;
  56. pData->options.transportMode = ENGINE_TRANSPORT_MODE_PLUGIN;
  57. pData->options.forceStereo = false;
  58. pData->options.preferPluginBridges = false;
  59. pData->options.preferUiBridges = false;
  60. init("LV2-Export");
  61. if (pData->options.resourceDir != nullptr)
  62. delete[] pData->options.resourceDir;
  63. if (pData->options.binaryDir != nullptr)
  64. delete[] pData->options.binaryDir;
  65. pData->options.binaryDir = binaryDir.dup();
  66. pData->options.resourceDir = resourceDir.dup();
  67. setCallback(_engine_callback, this);
  68. using juce::File;
  69. const File pluginFile(File::getSpecialLocation(File::currentExecutableFile).withFileExtension("xml"));
  70. if (! loadProject(pluginFile.getFullPathName().toRawUTF8()))
  71. {
  72. carla_stderr2("Failed to init plugin, possible reasons: %s", getLastError());
  73. return;
  74. }
  75. CARLA_SAFE_ASSERT_RETURN(pData->curPluginCount == 1,)
  76. fPlugin = pData->plugins[0].plugin;
  77. CARLA_SAFE_ASSERT_RETURN(fPlugin != nullptr,);
  78. CARLA_SAFE_ASSERT_RETURN(fPlugin->isEnabled(),);
  79. fPorts.init(fPlugin);
  80. }
  81. ~CarlaEngineLV2Single()
  82. {
  83. close();
  84. }
  85. bool hasPlugin()
  86. {
  87. return fPlugin != nullptr;
  88. }
  89. // -----------------------------------------------------------------------------------------------------------------
  90. // LV2 functions
  91. void lv2_connect_port(const uint32_t port, void* const dataLocation)
  92. {
  93. fPorts.connectPort(port, dataLocation);
  94. }
  95. void lv2_activate()
  96. {
  97. CARLA_SAFE_ASSERT_RETURN(! fIsRunning,);
  98. fPlugin->activate();
  99. fIsRunning = true;
  100. }
  101. void lv2_deactivate()
  102. {
  103. CARLA_SAFE_ASSERT_RETURN(fIsRunning,);
  104. fIsRunning = false;
  105. fPlugin->deactivate();
  106. }
  107. void lv2_run(const uint32_t frames)
  108. {
  109. fIsOffline = (fPorts.freewheel != nullptr && *fPorts.freewheel >= 0.5f);
  110. // Check for updated parameters
  111. float curValue;
  112. for (uint32_t i=0; i < fPorts.numParams; ++i)
  113. {
  114. if (fPorts.paramsOut[i])
  115. continue;
  116. CARLA_SAFE_ASSERT_CONTINUE(fPorts.paramsPtr[i] != nullptr)
  117. curValue = *fPorts.paramsPtr[i];
  118. if (carla_isEqual(fPorts.paramsLast[i], curValue))
  119. continue;
  120. fPorts.paramsLast[i] = curValue;
  121. fPlugin->setParameterValue(i, curValue, false, false, false);
  122. }
  123. if (frames == 0)
  124. return fPorts.updateOutputs();
  125. if (fPlugin->tryLock(fIsOffline))
  126. {
  127. fPlugin->initBuffers();
  128. fPlugin->process(fPorts.audioIns, fPorts.audioOuts, nullptr, nullptr, frames);
  129. fPlugin->unlock();
  130. }
  131. else
  132. {
  133. for (uint32_t i=0; i<fPorts.numAudioOuts; ++i)
  134. carla_zeroFloats(fPorts.audioOuts[i], frames);
  135. }
  136. fPorts.updateOutputs();
  137. }
  138. // -----------------------------------------------------------------------------------------------------------------
  139. void lv2ui_instantiate(LV2UI_Write_Function writeFunction, LV2UI_Controller controller,
  140. LV2UI_Widget* widget, const LV2_Feature* const* features)
  141. {
  142. fUI.writeFunction = writeFunction;
  143. fUI.controller = controller;
  144. const LV2_URID_Map* uridMap = nullptr;
  145. // -------------------------------------------------------------------------------------------------------------
  146. // see if the host supports external-ui, get uridMap
  147. for (int i=0; features[i] != nullptr; ++i)
  148. {
  149. if (std::strcmp(features[i]->URI, LV2_EXTERNAL_UI__Host) == 0 ||
  150. std::strcmp(features[i]->URI, LV2_EXTERNAL_UI_DEPRECATED_URI) == 0)
  151. {
  152. fUI.host = (const LV2_External_UI_Host*)features[i]->data;
  153. }
  154. else if (std::strcmp(features[i]->URI, LV2_URID__map) == 0)
  155. {
  156. uridMap = (const LV2_URID_Map*)features[i]->data;
  157. }
  158. }
  159. if (fUI.host != nullptr)
  160. {
  161. fUI.name = fUI.host->plugin_human_id;
  162. *widget = (LV2_External_UI_Widget*)this;
  163. return;
  164. }
  165. // -------------------------------------------------------------------------------------------------------------
  166. // no external-ui support, use showInterface
  167. for (int i=0; features[i] != nullptr; ++i)
  168. {
  169. if (std::strcmp(features[i]->URI, LV2_OPTIONS__options) == 0)
  170. {
  171. const LV2_Options_Option* const options((const LV2_Options_Option*)features[i]->data);
  172. for (int j=0; options[j].key != 0; ++j)
  173. {
  174. if (options[j].key == uridMap->map(uridMap->handle, LV2_UI__windowTitle))
  175. {
  176. fUI.name = (const char*)options[j].value;
  177. break;
  178. }
  179. }
  180. break;
  181. }
  182. }
  183. if (fUI.name.isEmpty())
  184. fUI.name = fPlugin->getName();
  185. *widget = nullptr;
  186. }
  187. void lv2ui_port_event(uint32_t portIndex, uint32_t bufferSize, uint32_t format, const void* buffer) const
  188. {
  189. if (format != 0 || bufferSize != sizeof(float) || buffer == nullptr)
  190. return;
  191. if (portIndex >= fPorts.indexOffset || ! fUI.visible)
  192. return;
  193. const float value(*(const float*)buffer);
  194. fPlugin->uiParameterChange(portIndex-fPorts.indexOffset, value);
  195. }
  196. void lv2ui_cleanup()
  197. {
  198. if (fUI.visible)
  199. handleUiHide();
  200. fUI.writeFunction = nullptr;
  201. fUI.controller = nullptr;
  202. fUI.host = nullptr;
  203. }
  204. // -----------------------------------------------------------------------------------------------------------------
  205. int lv2ui_idle() const
  206. {
  207. if (! fUI.visible)
  208. return 1;
  209. handleUiRun();
  210. return 0;
  211. }
  212. int lv2ui_show()
  213. {
  214. handleUiShow();
  215. return 0;
  216. }
  217. int lv2ui_hide()
  218. {
  219. handleUiHide();
  220. return 0;
  221. }
  222. protected:
  223. // -----------------------------------------------------------------------------------------------------------------
  224. // CarlaEngine virtual calls
  225. bool init(const char* const clientName) override
  226. {
  227. carla_stdout("CarlaEngineNative::init(\"%s\")", clientName);
  228. if (! pData->init(clientName))
  229. {
  230. close();
  231. setLastError("Failed to init internal data");
  232. return false;
  233. }
  234. return true;
  235. }
  236. bool close() override
  237. {
  238. fIsRunning = false;
  239. CarlaEngine::close();
  240. return true;
  241. }
  242. bool isRunning() const noexcept override
  243. {
  244. return fIsRunning;
  245. }
  246. bool isOffline() const noexcept override
  247. {
  248. return fIsOffline;
  249. }
  250. bool usesConstantBufferSize() const noexcept override
  251. {
  252. return true;
  253. }
  254. EngineType getType() const noexcept override
  255. {
  256. return kEngineTypePlugin;
  257. }
  258. const char* getCurrentDriverName() const noexcept override
  259. {
  260. return "LV2 Plugin";
  261. }
  262. void engineCallback(const EngineCallbackOpcode action, const uint pluginId, const int value1, const int value2, const float value3, const char* const valueStr)
  263. {
  264. switch (action)
  265. {
  266. case ENGINE_CALLBACK_PARAMETER_VALUE_CHANGED:
  267. if (fUI.writeFunction != nullptr && fUI.controller != nullptr && fUI.visible)
  268. fUI.writeFunction(fUI.controller, value1+fPorts.indexOffset, sizeof(float), 0, &value3);
  269. break;
  270. case ENGINE_CALLBACK_UI_STATE_CHANGED:
  271. fUI.visible = value1 == 1;
  272. if (fUI.host != nullptr)
  273. fUI.host->ui_closed(fUI.controller);
  274. break;
  275. case ENGINE_CALLBACK_IDLE:
  276. break;
  277. default:
  278. carla_stdout("engineCallback(%i:%s, %u, %i, %i, %f, %s)", action, EngineCallbackOpcode2Str(action), pluginId, value1, value2, value3, valueStr);
  279. break;
  280. }
  281. }
  282. // -----------------------------------------------------------------------------------------------------------------
  283. void handleUiRun() const
  284. {
  285. fPlugin->uiIdle();
  286. }
  287. void handleUiShow()
  288. {
  289. fPlugin->showCustomUI(true);
  290. fUI.visible = true;
  291. }
  292. void handleUiHide()
  293. {
  294. fUI.visible = false;
  295. fPlugin->showCustomUI(false);
  296. }
  297. // -----------------------------------------------------------------------------------------------------------------
  298. private:
  299. CarlaPlugin* fPlugin;
  300. bool fIsRunning;
  301. // Lv2 host data
  302. bool fIsOffline;
  303. struct Ports {
  304. uint32_t numAudioIns;
  305. uint32_t numAudioOuts;
  306. uint32_t numParams;
  307. const float** audioIns;
  308. /* */ float** audioOuts;
  309. float* freewheel;
  310. float* paramsLast;
  311. float** paramsPtr;
  312. bool* paramsOut;
  313. uint32_t indexOffset;
  314. const CarlaPlugin* plugin;
  315. Ports()
  316. : numAudioIns(0),
  317. numAudioOuts(0),
  318. numParams(0),
  319. audioIns(nullptr),
  320. audioOuts(nullptr),
  321. freewheel(nullptr),
  322. paramsLast(nullptr),
  323. paramsPtr(nullptr),
  324. paramsOut(nullptr),
  325. indexOffset(1),
  326. plugin(nullptr) {}
  327. ~Ports()
  328. {
  329. if (audioIns != nullptr)
  330. {
  331. delete[] audioIns;
  332. audioIns = nullptr;
  333. }
  334. if (audioOuts != nullptr)
  335. {
  336. delete[] audioOuts;
  337. audioOuts = nullptr;
  338. }
  339. if (paramsLast != nullptr)
  340. {
  341. delete[] paramsLast;
  342. paramsLast = nullptr;
  343. }
  344. if (paramsPtr != nullptr)
  345. {
  346. delete[] paramsPtr;
  347. paramsPtr = nullptr;
  348. }
  349. if (paramsOut != nullptr)
  350. {
  351. delete[] paramsOut;
  352. paramsOut = nullptr;
  353. }
  354. }
  355. void init(const CarlaPlugin* const pl)
  356. {
  357. plugin = pl;
  358. if ((numAudioIns = plugin->getAudioInCount()) > 0)
  359. {
  360. audioIns = new const float*[numAudioIns];
  361. for (uint32_t i=0; i < numAudioIns; ++i)
  362. audioIns[i] = nullptr;
  363. }
  364. if ((numAudioOuts = plugin->getAudioOutCount()) > 0)
  365. {
  366. audioOuts = new float*[numAudioOuts];
  367. for (uint32_t i=0; i < numAudioOuts; ++i)
  368. audioOuts[i] = nullptr;
  369. }
  370. if ((numParams = plugin->getParameterCount()) > 0)
  371. {
  372. paramsLast = new float[numParams];
  373. paramsPtr = new float*[numParams];
  374. paramsOut = new bool[numParams];
  375. for (uint32_t i=0; i < numParams; ++i)
  376. {
  377. paramsLast[i] = plugin->getParameterValue(i);
  378. paramsPtr [i] = nullptr;
  379. paramsOut [i] = plugin->isParameterOutput(i);
  380. }
  381. }
  382. indexOffset = numAudioIns + numAudioOuts + 1;
  383. }
  384. void connectPort(const uint32_t port, void* const dataLocation) noexcept
  385. {
  386. uint32_t index = 0;
  387. for (uint32_t i=0; i < numAudioIns; ++i)
  388. {
  389. if (port == index++)
  390. {
  391. audioIns[i] = (float*)dataLocation;
  392. return;
  393. }
  394. }
  395. for (uint32_t i=0; i < numAudioOuts; ++i)
  396. {
  397. if (port == index++)
  398. {
  399. audioOuts[i] = (float*)dataLocation;
  400. return;
  401. }
  402. }
  403. if (port == index++)
  404. {
  405. freewheel = (float*)dataLocation;
  406. return;
  407. }
  408. for (uint32_t i=0; i < numParams; ++i)
  409. {
  410. if (port == index++)
  411. {
  412. paramsPtr[i] = (float*)dataLocation;
  413. return;
  414. }
  415. }
  416. }
  417. void updateOutputs() noexcept
  418. {
  419. for (uint32_t i=0; i < numParams; ++i)
  420. {
  421. if (! paramsOut[i])
  422. continue;
  423. paramsLast[i] = plugin->getParameterValue(i);
  424. if (paramsPtr[i] != nullptr)
  425. *paramsPtr[i] = paramsLast[i];
  426. }
  427. }
  428. CARLA_DECLARE_NON_COPY_STRUCT(Ports);
  429. } fPorts;
  430. struct UI {
  431. LV2UI_Write_Function writeFunction;
  432. LV2UI_Controller controller;
  433. const LV2_External_UI_Host* host;
  434. CarlaString name;
  435. bool visible;
  436. UI()
  437. : writeFunction(nullptr),
  438. controller(nullptr),
  439. host(nullptr),
  440. visible(false) {}
  441. } fUI;
  442. SharedResourcePointer<ScopedJuceInitialiser_GUI> sJuceInitialiser;
  443. // -------------------------------------------------------------------
  444. #define handlePtr ((CarlaEngineLV2Single*)handle)
  445. static void extui_run(LV2_External_UI_Widget* handle)
  446. {
  447. handlePtr->handleUiRun();
  448. }
  449. static void extui_show(LV2_External_UI_Widget* handle)
  450. {
  451. handlePtr->handleUiShow();
  452. }
  453. static void extui_hide(LV2_External_UI_Widget* handle)
  454. {
  455. handlePtr->handleUiHide();
  456. }
  457. static void _engine_callback(void* handle, EngineCallbackOpcode action, uint pluginId, int value1, int value2, float value3, const char* valueStr)
  458. {
  459. handlePtr->engineCallback(action, pluginId, value1, value2, value3, valueStr);
  460. }
  461. #undef handlePtr
  462. CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(CarlaEngineLV2Single)
  463. };
  464. CARLA_BACKEND_END_NAMESPACE
  465. CARLA_BACKEND_USE_NAMESPACE
  466. // ---------------------------------------------------------------------------------------------------------------------
  467. // LV2 DSP functions
  468. static LV2_Handle lv2_instantiate(const LV2_Descriptor* lv2Descriptor, double sampleRate, const char* bundlePath, const LV2_Feature* const* features)
  469. {
  470. carla_stdout("lv2_instantiate(%p, %g, %s, %p)", lv2Descriptor, sampleRate, bundlePath, features);
  471. const LV2_Options_Option* options = nullptr;
  472. const LV2_URID_Map* uridMap = nullptr;
  473. const LV2_URID_Unmap* uridUnmap = nullptr;
  474. for (int i=0; features[i] != nullptr; ++i)
  475. {
  476. if (std::strcmp(features[i]->URI, LV2_OPTIONS__options) == 0)
  477. options = (const LV2_Options_Option*)features[i]->data;
  478. else if (std::strcmp(features[i]->URI, LV2_URID__map) == 0)
  479. uridMap = (const LV2_URID_Map*)features[i]->data;
  480. else if (std::strcmp(features[i]->URI, LV2_URID__unmap) == 0)
  481. uridUnmap = (const LV2_URID_Unmap*)features[i]->data;
  482. }
  483. if (options == nullptr || uridMap == nullptr)
  484. {
  485. carla_stderr("Host doesn't provide option or urid-map features");
  486. return nullptr;
  487. }
  488. uint32_t bufferSize = 0;
  489. for (int i=0; options[i].key != 0; ++i)
  490. {
  491. if (uridUnmap != nullptr) {
  492. carla_stdout("Host option %i:\"%s\"", i, uridUnmap->unmap(uridUnmap->handle, options[i].key));
  493. }
  494. if (options[i].key == uridMap->map(uridMap->handle, LV2_BUF_SIZE__nominalBlockLength))
  495. {
  496. if (options[i].type == uridMap->map(uridMap->handle, LV2_ATOM__Int))
  497. {
  498. const int value(*(const int*)options[i].value);
  499. CARLA_SAFE_ASSERT_CONTINUE(value > 0);
  500. bufferSize = static_cast<uint32_t>(value);
  501. }
  502. else
  503. {
  504. carla_stderr("Host provides nominalBlockLength but has wrong value type");
  505. }
  506. break;
  507. }
  508. if (options[i].key == uridMap->map(uridMap->handle, LV2_BUF_SIZE__maxBlockLength))
  509. {
  510. if (options[i].type == uridMap->map(uridMap->handle, LV2_ATOM__Int))
  511. {
  512. const int value(*(const int*)options[i].value);
  513. CARLA_SAFE_ASSERT_CONTINUE(value > 0);
  514. bufferSize = static_cast<uint32_t>(value);
  515. }
  516. else
  517. {
  518. carla_stderr("Host provides maxBlockLength but has wrong value type");
  519. }
  520. // no break, continue in case host supports nominalBlockLength
  521. }
  522. }
  523. if (bufferSize == 0)
  524. {
  525. carla_stderr("Host doesn't provide bufferSize feature");
  526. return nullptr;
  527. }
  528. CarlaEngineLV2Single* const instance(new CarlaEngineLV2Single(bufferSize, sampleRate, bundlePath, uridMap));
  529. if (instance->hasPlugin())
  530. return (LV2_Handle)instance;
  531. delete instance;
  532. return nullptr;
  533. }
  534. #define instancePtr ((CarlaEngineLV2Single*)instance)
  535. static void lv2_connect_port(LV2_Handle instance, uint32_t port, void* dataLocation)
  536. {
  537. instancePtr->lv2_connect_port(port, dataLocation);
  538. }
  539. static void lv2_activate(LV2_Handle instance)
  540. {
  541. carla_stdout("lv2_activate(%p)", instance);
  542. instancePtr->lv2_activate();
  543. }
  544. static void lv2_run(LV2_Handle instance, uint32_t sampleCount)
  545. {
  546. instancePtr->lv2_run(sampleCount);
  547. }
  548. static void lv2_deactivate(LV2_Handle instance)
  549. {
  550. carla_stdout("lv2_deactivate(%p)", instance);
  551. instancePtr->lv2_deactivate();
  552. }
  553. static void lv2_cleanup(LV2_Handle instance)
  554. {
  555. carla_stdout("lv2_cleanup(%p)", instance);
  556. delete instancePtr;
  557. }
  558. static const void* lv2_extension_data(const char* uri)
  559. {
  560. carla_stdout("lv2_extension_data(\"%s\")", uri);
  561. return nullptr;
  562. }
  563. #undef instancePtr
  564. // ---------------------------------------------------------------------------------------------------------------------
  565. // LV2 UI functions
  566. static LV2UI_Handle lv2ui_instantiate(const LV2UI_Descriptor*, const char*, const char*,
  567. LV2UI_Write_Function writeFunction, LV2UI_Controller controller,
  568. LV2UI_Widget* widget, const LV2_Feature* const* features)
  569. {
  570. carla_debug("lv2ui_instantiate(..., %p, %p, %p)", writeFunction, controller, widget, features);
  571. CarlaEngineLV2Single* engine = nullptr;
  572. for (int i=0; features[i] != nullptr; ++i)
  573. {
  574. if (std::strcmp(features[i]->URI, LV2_INSTANCE_ACCESS_URI) == 0)
  575. {
  576. engine = (CarlaEngineLV2Single*)features[i]->data;
  577. break;
  578. }
  579. }
  580. if (engine == nullptr)
  581. {
  582. carla_stderr("Host doesn't support instance-access, cannot show UI");
  583. return nullptr;
  584. }
  585. engine->lv2ui_instantiate(writeFunction, controller, widget, features);
  586. return (LV2UI_Handle)engine;
  587. }
  588. #define uiPtr ((CarlaEngineLV2Single*)ui)
  589. static void lv2ui_port_event(LV2UI_Handle ui, uint32_t portIndex, uint32_t bufferSize, uint32_t format, const void* buffer)
  590. {
  591. carla_debug("lv2ui_port_event(%p, %i, %i, %i, %p)", ui, portIndex, bufferSize, format, buffer);
  592. uiPtr->lv2ui_port_event(portIndex, bufferSize, format, buffer);
  593. }
  594. static void lv2ui_cleanup(LV2UI_Handle ui)
  595. {
  596. carla_debug("lv2ui_cleanup(%p)", ui);
  597. uiPtr->lv2ui_cleanup();
  598. }
  599. static int lv2ui_idle(LV2UI_Handle ui)
  600. {
  601. return uiPtr->lv2ui_idle();
  602. }
  603. static int lv2ui_show(LV2UI_Handle ui)
  604. {
  605. carla_debug("lv2ui_show(%p)", ui);
  606. return uiPtr->lv2ui_show();
  607. }
  608. static int lv2ui_hide(LV2UI_Handle ui)
  609. {
  610. carla_debug("lv2ui_hide(%p)", ui);
  611. return uiPtr->lv2ui_hide();
  612. }
  613. static const void* lv2ui_extension_data(const char* uri)
  614. {
  615. carla_stdout("lv2ui_extension_data(\"%s\")", uri);
  616. static const LV2UI_Idle_Interface uiidle = { lv2ui_idle };
  617. static const LV2UI_Show_Interface uishow = { lv2ui_show, lv2ui_hide };
  618. if (std::strcmp(uri, LV2_UI__idleInterface) == 0)
  619. return &uiidle;
  620. if (std::strcmp(uri, LV2_UI__showInterface) == 0)
  621. return &uishow;
  622. return nullptr;
  623. }
  624. #undef uiPtr
  625. // ---------------------------------------------------------------------------------------------------------------------
  626. // Startup code
  627. CARLA_EXPORT
  628. const LV2_Descriptor* lv2_descriptor(uint32_t index)
  629. {
  630. carla_stdout("lv2_descriptor(%i)", index);
  631. if (index != 0)
  632. return nullptr;
  633. static CarlaString ret;
  634. if (ret.isEmpty())
  635. {
  636. using namespace juce;
  637. const File file(File::getSpecialLocation(File::currentExecutableFile).withFileExtension("ttl"));
  638. ret = String("file://" + file.getFullPathName()).toRawUTF8();
  639. }
  640. static const LV2_Descriptor desc = {
  641. /* URI */ ret.buffer(),
  642. /* instantiate */ lv2_instantiate,
  643. /* connect_port */ lv2_connect_port,
  644. /* activate */ lv2_activate,
  645. /* run */ lv2_run,
  646. /* deactivate */ lv2_deactivate,
  647. /* cleanup */ lv2_cleanup,
  648. /* extension_data */ lv2_extension_data
  649. };
  650. return &desc;
  651. }
  652. CARLA_EXPORT
  653. const LV2UI_Descriptor* lv2ui_descriptor(uint32_t index)
  654. {
  655. carla_stdout("lv2ui_descriptor(%i)", index);
  656. static CarlaString ret;
  657. if (ret.isEmpty())
  658. {
  659. using namespace juce;
  660. const File file(File::getSpecialLocation(File::currentExecutableFile).getSiblingFile("ext-ui"));
  661. ret = String("file://" + file.getFullPathName()).toRawUTF8();
  662. }
  663. static const LV2UI_Descriptor lv2UiExtDesc = {
  664. /* URI */ ret.buffer(),
  665. /* instantiate */ lv2ui_instantiate,
  666. /* cleanup */ lv2ui_cleanup,
  667. /* port_event */ lv2ui_port_event,
  668. /* extension_data */ lv2ui_extension_data
  669. };
  670. return (index == 0) ? &lv2UiExtDesc : nullptr;
  671. }
  672. // ---------------------------------------------------------------------------------------------------------------------