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.

780 lines
24KB

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