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.

760 lines
23KB

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