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.

767 lines
23KB

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