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.

1300 lines
43KB

  1. /*
  2. * Carla Native Plugins
  3. * Copyright (C) 2013-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. #define CARLA_NATIVE_PLUGIN_LV2
  18. #include "carla-base.cpp"
  19. #include "CarlaLv2Utils.hpp"
  20. #include "CarlaMathUtils.hpp"
  21. #include "CarlaPipeUtils.hpp"
  22. #include "CarlaString.hpp"
  23. #include "water/files/File.h"
  24. static const char* const kPathForCarlaFiles = "carlafiles";
  25. template<>
  26. void Lv2PluginBaseClass<NativeTimeInfo>::clearTimeData() noexcept
  27. {
  28. fLastPositionData.clear();
  29. carla_zeroStruct(fTimeInfo);
  30. }
  31. // --------------------------------------------------------------------------------------------------------------------
  32. // Carla Internal Plugin API exposed as LV2 plugin
  33. class NativePlugin : public Lv2PluginBaseClass<NativeTimeInfo>
  34. {
  35. public:
  36. static const uint32_t kMaxMidiEvents = 512;
  37. NativePlugin(const NativePluginDescriptor* const desc,
  38. const double sampleRate,
  39. const char* const bundlePath,
  40. const LV2_Feature* const* const features)
  41. : Lv2PluginBaseClass<NativeTimeInfo>(sampleRate, features),
  42. fHandle(nullptr),
  43. fHost(),
  44. fDescriptor(desc),
  45. #ifdef CARLA_PROPER_CPP11_SUPPORT
  46. fProgramDesc({0, 0, nullptr}),
  47. #endif
  48. kIgnoreParameters(std::strncmp(desc->label, "carla", 5) == 0),
  49. fMidiEventCount(0),
  50. fLastProjectPath(),
  51. fLoadedFile(),
  52. fWorkerUISignal(0)
  53. {
  54. carla_zeroStruct(fHost);
  55. #ifndef CARLA_PROPER_CPP11_SUPPORT
  56. carla_zeroStruct(fProgramDesc);
  57. #endif
  58. if (! loadedInProperHost())
  59. return;
  60. using water::File;
  61. using water::String;
  62. String resourceDir(water::File(bundlePath).getChildFile("resources").getFullPathName());
  63. fHost.handle = this;
  64. fHost.resourceDir = carla_strdup(resourceDir.toRawUTF8());
  65. fHost.uiName = nullptr;
  66. fHost.uiParentId = 0;
  67. fHost.get_buffer_size = host_get_buffer_size;
  68. fHost.get_sample_rate = host_get_sample_rate;
  69. fHost.is_offline = host_is_offline;
  70. fHost.get_time_info = host_get_time_info;
  71. fHost.write_midi_event = host_write_midi_event;
  72. fHost.ui_parameter_changed = host_ui_parameter_changed;
  73. fHost.ui_custom_data_changed = host_ui_custom_data_changed;
  74. fHost.ui_closed = host_ui_closed;
  75. fHost.ui_open_file = host_ui_open_file;
  76. fHost.ui_save_file = host_ui_save_file;
  77. fHost.dispatcher = host_dispatcher;
  78. }
  79. ~NativePlugin()
  80. {
  81. CARLA_SAFE_ASSERT(fHandle == nullptr);
  82. if (fHost.resourceDir != nullptr)
  83. {
  84. delete[] fHost.resourceDir;
  85. fHost.resourceDir = nullptr;
  86. }
  87. if (fHost.uiName != nullptr)
  88. {
  89. delete[] fHost.uiName;
  90. fHost.uiName = nullptr;
  91. }
  92. }
  93. // ----------------------------------------------------------------------------------------------------------------
  94. bool init()
  95. {
  96. if (fHost.resourceDir == nullptr)
  97. return false;
  98. if (fDescriptor->instantiate == nullptr || fDescriptor->process == nullptr)
  99. {
  100. carla_stderr("Plugin is missing something...");
  101. return false;
  102. }
  103. carla_zeroStructs(fMidiEvents, kMaxMidiEvents);
  104. fHandle = fDescriptor->instantiate(&fHost);
  105. CARLA_SAFE_ASSERT_RETURN(fHandle != nullptr, false);
  106. fPorts.hasUI = fDescriptor->hints & NATIVE_PLUGIN_HAS_UI;
  107. fPorts.usesTime = fDescriptor->hints & NATIVE_PLUGIN_USES_TIME;
  108. fPorts.numAudioIns = fDescriptor->audioIns;
  109. fPorts.numAudioOuts = fDescriptor->audioOuts;
  110. fPorts.numCVIns = fDescriptor->cvIns;
  111. fPorts.numCVOuts = fDescriptor->cvOuts;
  112. fPorts.numMidiIns = fDescriptor->midiIns;
  113. fPorts.numMidiOuts = fDescriptor->midiOuts;
  114. if (fDescriptor->get_parameter_count != nullptr &&
  115. fDescriptor->get_parameter_info != nullptr &&
  116. fDescriptor->get_parameter_value != nullptr &&
  117. fDescriptor->set_parameter_value != nullptr &&
  118. ! kIgnoreParameters)
  119. {
  120. fPorts.numParams = fDescriptor->get_parameter_count(fHandle);
  121. }
  122. fPorts.init();
  123. if (fPorts.numParams > 0)
  124. {
  125. for (uint32_t i=0; i < fPorts.numParams; ++i)
  126. {
  127. fPorts.paramsLast[i] = fDescriptor->get_parameter_value(fHandle, i);
  128. fPorts.paramsOut [i] = fDescriptor->get_parameter_info(fHandle, i)->hints & NATIVE_PARAMETER_IS_OUTPUT;
  129. }
  130. }
  131. return true;
  132. }
  133. // ----------------------------------------------------------------------------------------------------------------
  134. // LV2 functions
  135. void lv2_activate()
  136. {
  137. CARLA_SAFE_ASSERT_RETURN(! fIsActive,);
  138. resetTimeInfo();
  139. if (fDescriptor->activate != nullptr)
  140. fDescriptor->activate(fHandle);
  141. fIsActive = true;
  142. }
  143. void lv2_deactivate()
  144. {
  145. CARLA_SAFE_ASSERT_RETURN(fIsActive,);
  146. fIsActive = false;
  147. if (fDescriptor->deactivate != nullptr)
  148. fDescriptor->deactivate(fHandle);
  149. }
  150. void lv2_cleanup()
  151. {
  152. if (fIsActive)
  153. {
  154. carla_stderr("Warning: Host forgot to call deactivate!");
  155. fIsActive = false;
  156. if (fDescriptor->deactivate != nullptr)
  157. fDescriptor->deactivate(fHandle);
  158. }
  159. if (fDescriptor->cleanup != nullptr)
  160. fDescriptor->cleanup(fHandle);
  161. fHandle = nullptr;
  162. }
  163. // ----------------------------------------------------------------------------------------------------------------
  164. void lv2_run(const uint32_t frames)
  165. {
  166. if (! lv2_pre_run(frames))
  167. {
  168. updateParameterOutputs();
  169. return;
  170. }
  171. if (fPorts.numMidiIns > 0 || fPorts.hasUI)
  172. {
  173. uint32_t numEventsIn;
  174. if (fPorts.numMidiIns > 0)
  175. {
  176. numEventsIn = fPorts.numMidiIns;
  177. fMidiEventCount = 0;
  178. carla_zeroStructs(fMidiEvents, kMaxMidiEvents);
  179. }
  180. else
  181. {
  182. numEventsIn = 1;
  183. }
  184. for (uint32_t i=0; i < numEventsIn; ++i)
  185. {
  186. const LV2_Atom_Sequence* const eventsIn(fPorts.eventsIn[i]);
  187. CARLA_SAFE_ASSERT_CONTINUE(eventsIn != nullptr);
  188. LV2_ATOM_SEQUENCE_FOREACH(eventsIn, event)
  189. {
  190. if (event == nullptr)
  191. continue;
  192. if (event->body.type == fURIs.uiEvents && fWorkerUISignal != -1)
  193. {
  194. CARLA_SAFE_ASSERT_CONTINUE((fDescriptor->hints & NATIVE_PLUGIN_NEEDS_UI_OPEN_SAVE) == 0);
  195. if (fWorker != nullptr)
  196. {
  197. // worker is supported by the host, we can continue
  198. fWorkerUISignal = 1;
  199. const char* const msg((const char*)(event + 1));
  200. const size_t msgSize = std::strlen(msg);
  201. fWorker->schedule_work(fWorker->handle, static_cast<uint32_t>(msgSize + 1U), msg);
  202. }
  203. else
  204. {
  205. // worker is not supported, cancel
  206. fWorkerUISignal = -1;
  207. }
  208. continue;
  209. }
  210. if (event->body.type == fURIs.atomObject)
  211. {
  212. const LV2_Atom_Object* const obj = (const LV2_Atom_Object*)(&event->body);
  213. if (obj->body.otype == fURIs.patchSet) {
  214. // Get property URI.
  215. const LV2_Atom* property = nullptr;
  216. lv2_atom_object_get(obj, fURIs.patchProperty, &property, 0);
  217. CARLA_SAFE_ASSERT_CONTINUE(property != nullptr);
  218. CARLA_SAFE_ASSERT_CONTINUE(property->type == fURIs.atomURID);
  219. const LV2_URID urid = ((const LV2_Atom_URID*)property)->body;
  220. /* */ if (std::strcmp(fDescriptor->label, "audiofile") == 0) {
  221. CARLA_SAFE_ASSERT_CONTINUE(urid == fURIs.carlaFileAudio);
  222. } else if (std::strcmp(fDescriptor->label, "midifile") == 0) {
  223. CARLA_SAFE_ASSERT_CONTINUE(urid == fURIs.carlaFileMIDI);
  224. } else {
  225. CARLA_SAFE_ASSERT_CONTINUE(urid == fURIs.carlaFile);
  226. }
  227. // Get value.
  228. const LV2_Atom* fileobj = nullptr;
  229. lv2_atom_object_get(obj, fURIs.patchValue, &fileobj, 0);
  230. CARLA_SAFE_ASSERT_CONTINUE(fileobj != nullptr);
  231. CARLA_SAFE_ASSERT_CONTINUE(fileobj->type == fURIs.atomPath);
  232. const char* const filepath((const char*)(fileobj + 1));
  233. fWorker->schedule_work(fWorker->handle,
  234. static_cast<uint32_t>(std::strlen(filepath) + 1U),
  235. filepath);
  236. }
  237. continue;
  238. }
  239. if (event->body.type != fURIs.midiEvent)
  240. continue;
  241. if (event->body.size > 4)
  242. continue;
  243. if (event->time.frames >= frames)
  244. break;
  245. const uint8_t* const data((const uint8_t*)(event + 1));
  246. NativeMidiEvent& nativeEvent(fMidiEvents[fMidiEventCount++]);
  247. nativeEvent.port = (uint8_t)i;
  248. nativeEvent.size = (uint8_t)event->body.size;
  249. nativeEvent.time = (uint32_t)event->time.frames;
  250. uint32_t j=0;
  251. for (uint32_t size=event->body.size; j<size; ++j)
  252. nativeEvent.data[j] = data[j];
  253. for (; j<4; ++j)
  254. nativeEvent.data[j] = 0;
  255. if (fMidiEventCount >= kMaxMidiEvents)
  256. break;
  257. }
  258. }
  259. }
  260. fDescriptor->process(fHandle, fPorts.audioCVIns, fPorts.audioCVOuts, frames, fMidiEvents, fMidiEventCount);
  261. if (fWorkerUISignal == -1 && fPorts.hasUI)
  262. {
  263. const char* const msg = "quit";
  264. const size_t msgSize = 5;
  265. LV2_Atom_Sequence* const seq(fPorts.eventsOut[0]);
  266. Ports::EventsOutData& mData(fPorts.eventsOutData[0]);
  267. if (sizeof(LV2_Atom_Event) + msgSize <= mData.capacity - mData.offset)
  268. {
  269. LV2_Atom_Event* const aev = (LV2_Atom_Event*)(LV2_ATOM_CONTENTS(LV2_Atom_Sequence, seq) + mData.offset);
  270. aev->time.frames = 0;
  271. aev->body.size = msgSize;
  272. aev->body.type = fURIs.uiEvents;
  273. std::memcpy(LV2_ATOM_BODY(&aev->body), msg, msgSize);
  274. const uint32_t size = lv2_atom_pad_size(static_cast<uint32_t>(sizeof(LV2_Atom_Event) + msgSize));
  275. mData.offset += size;
  276. seq->atom.size += size;
  277. fWorkerUISignal = 0;
  278. }
  279. }
  280. lv2_post_run(frames);
  281. updateParameterOutputs();
  282. }
  283. // ----------------------------------------------------------------------------------------------------------------
  284. const LV2_Program_Descriptor* lv2_get_program(const uint32_t index)
  285. {
  286. if (fDescriptor->category == NATIVE_PLUGIN_CATEGORY_SYNTH)
  287. return nullptr;
  288. if (fDescriptor->get_midi_program_count == nullptr)
  289. return nullptr;
  290. if (fDescriptor->get_midi_program_info == nullptr)
  291. return nullptr;
  292. if (index >= fDescriptor->get_midi_program_count(fHandle))
  293. return nullptr;
  294. const NativeMidiProgram* const midiProg(fDescriptor->get_midi_program_info(fHandle, index));
  295. if (midiProg == nullptr)
  296. return nullptr;
  297. fProgramDesc.bank = midiProg->bank;
  298. fProgramDesc.program = midiProg->program;
  299. fProgramDesc.name = midiProg->name;
  300. return &fProgramDesc;
  301. }
  302. void lv2_select_program(uint32_t bank, uint32_t program)
  303. {
  304. if (fDescriptor->category == NATIVE_PLUGIN_CATEGORY_SYNTH)
  305. return;
  306. if (fDescriptor->set_midi_program == nullptr)
  307. return;
  308. fDescriptor->set_midi_program(fHandle, 0, bank, program);
  309. for (uint32_t i=0; i < fPorts.numParams; ++i)
  310. {
  311. fPorts.paramsLast[i] = fDescriptor->get_parameter_value(fHandle, i);
  312. if (fPorts.paramsPtr[i] != nullptr)
  313. *fPorts.paramsPtr[i] = fPorts.paramsLast[i];
  314. }
  315. }
  316. // ----------------------------------------------------------------------------------------------------------------
  317. void cleanupLastProjectPath()
  318. {
  319. fLastProjectPath.clear();
  320. }
  321. void saveLastProjectPathIfPossible(const LV2_Feature* const* const features)
  322. {
  323. if (features == nullptr)
  324. return cleanupLastProjectPath();
  325. const LV2_State_Free_Path* freePath = nullptr;
  326. const LV2_State_Make_Path* makePath = nullptr;
  327. for (int i=0; features[i] != nullptr; ++i)
  328. {
  329. /**/ if (freePath == nullptr && std::strcmp(features[i]->URI, LV2_STATE__freePath) == 0)
  330. freePath = (const LV2_State_Free_Path*)features[i]->data;
  331. else if (makePath == nullptr && std::strcmp(features[i]->URI, LV2_STATE__makePath) == 0)
  332. makePath = (const LV2_State_Make_Path*)features[i]->data;
  333. }
  334. if (makePath == nullptr || makePath->path == nullptr)
  335. return cleanupLastProjectPath();
  336. if (freePath == nullptr)
  337. freePath = fFreePath;
  338. char* const newpath = makePath->path(makePath->handle, kPathForCarlaFiles);
  339. if (newpath == nullptr)
  340. return cleanupLastProjectPath();
  341. fLastProjectPath = CarlaString(water::File(newpath).getParentDirectory().getFullPathName().toRawUTF8());
  342. if (freePath != nullptr && freePath->free_path != nullptr)
  343. freePath->free_path(freePath->handle, newpath);
  344. #ifndef CARLA_OS_WIN
  345. // this is not safe to call under windows
  346. else
  347. std::free(newpath);
  348. #endif
  349. }
  350. LV2_State_Status lv2_save(const LV2_State_Store_Function store, const LV2_State_Handle handle,
  351. const uint32_t /*flags*/, const LV2_Feature* const* const features)
  352. {
  353. saveLastProjectPathIfPossible(features);
  354. if (fDescriptor->hints & NATIVE_PLUGIN_NEEDS_UI_OPEN_SAVE)
  355. {
  356. store(handle,
  357. fUridMap->map(fUridMap->handle, "http://kxstudio.sf.net/ns/carla/file"),
  358. fLoadedFile.buffer(),
  359. fLoadedFile.length()+1,
  360. fURIs.atomPath,
  361. LV2_STATE_IS_POD);
  362. return LV2_STATE_SUCCESS;
  363. }
  364. if ((fDescriptor->hints & NATIVE_PLUGIN_USES_STATE) == 0 || fDescriptor->get_state == nullptr)
  365. return LV2_STATE_ERR_NO_FEATURE;
  366. if (char* const state = fDescriptor->get_state(fHandle))
  367. {
  368. store(handle, fUridMap->map(fUridMap->handle, "http://kxstudio.sf.net/ns/carla/chunk"),
  369. state, std::strlen(state)+1, fURIs.atomString, LV2_STATE_IS_POD|LV2_STATE_IS_PORTABLE);
  370. std::free(state);
  371. return LV2_STATE_SUCCESS;
  372. }
  373. return LV2_STATE_ERR_UNKNOWN;
  374. }
  375. LV2_State_Status lv2_restore(const LV2_State_Retrieve_Function retrieve, const LV2_State_Handle handle,
  376. uint32_t flags, const LV2_Feature* const* const features)
  377. {
  378. saveLastProjectPathIfPossible(features);
  379. size_t size = 0;
  380. uint32_t type = 0;
  381. if (fDescriptor->hints & NATIVE_PLUGIN_NEEDS_UI_OPEN_SAVE)
  382. {
  383. size = type = 0;
  384. const void* const data = retrieve(handle,
  385. fUridMap->map(fUridMap->handle, "http://kxstudio.sf.net/ns/carla/file"),
  386. &size, &type, &flags);
  387. CARLA_SAFE_ASSERT_RETURN(type == fURIs.atomPath, LV2_STATE_ERR_UNKNOWN);
  388. const char* const filename = (const char*)data;
  389. fLoadedFile = filename;
  390. fDescriptor->set_custom_data(fHandle, "file", filename);
  391. return LV2_STATE_SUCCESS;
  392. }
  393. if ((fDescriptor->hints & NATIVE_PLUGIN_USES_STATE) == 0 || fDescriptor->set_state == nullptr)
  394. return LV2_STATE_ERR_NO_FEATURE;
  395. size = type = 0;
  396. const void* const data = retrieve(handle, fUridMap->map(fUridMap->handle, "http://kxstudio.sf.net/ns/carla/chunk"), &size, &type, &flags);
  397. if (size == 0)
  398. return LV2_STATE_ERR_UNKNOWN;
  399. if (type == 0)
  400. return LV2_STATE_ERR_UNKNOWN;
  401. if (data == nullptr)
  402. return LV2_STATE_ERR_UNKNOWN;
  403. if (type != fURIs.atomString)
  404. return LV2_STATE_ERR_BAD_TYPE;
  405. fDescriptor->set_state(fHandle, (const char*)data);
  406. return LV2_STATE_SUCCESS;
  407. }
  408. // ----------------------------------------------------------------------------------------------------------------
  409. LV2_Worker_Status lv2_work(LV2_Worker_Respond_Function, LV2_Worker_Respond_Handle, uint32_t, const void* data)
  410. {
  411. const char* const msg = (const char*)data;
  412. if (fDescriptor->hints & NATIVE_PLUGIN_NEEDS_UI_OPEN_SAVE)
  413. {
  414. fLoadedFile = msg;
  415. fDescriptor->set_custom_data(fHandle, "file", msg);
  416. return LV2_WORKER_SUCCESS;
  417. }
  418. /**/ if (std::strncmp(msg, "control ", 8) == 0)
  419. {
  420. if (fDescriptor->ui_set_parameter_value == nullptr)
  421. return LV2_WORKER_SUCCESS;
  422. if (const char* const msgSplit = std::strstr(msg+8, " "))
  423. {
  424. const char* const msgIndex = msg+8;
  425. CARLA_SAFE_ASSERT_RETURN(msgSplit - msgIndex < 8, LV2_WORKER_ERR_UNKNOWN);
  426. CARLA_SAFE_ASSERT_RETURN(msgSplit[0] != '\0', LV2_WORKER_ERR_UNKNOWN);
  427. char strBufIndex[8];
  428. carla_zeroChars(strBufIndex, 8);
  429. std::strncpy(strBufIndex, msgIndex, static_cast<size_t>(msgSplit - msgIndex));
  430. const int index = std::atoi(msgIndex) - static_cast<int>(fPorts.indexOffset);
  431. CARLA_SAFE_ASSERT_RETURN(index >= 0, LV2_WORKER_ERR_UNKNOWN);
  432. float value;
  433. {
  434. const CarlaScopedLocale csl;
  435. value = static_cast<float>(std::atof(msgSplit+1));
  436. }
  437. fDescriptor->ui_set_parameter_value(fHandle, static_cast<uint32_t>(index), value);
  438. }
  439. }
  440. else if (std::strcmp(msg, "show") == 0)
  441. {
  442. handleUiShow();
  443. }
  444. else if (std::strcmp(msg, "hide") == 0)
  445. {
  446. handleUiHide();
  447. }
  448. else if (std::strcmp(msg, "idle") == 0)
  449. {
  450. handleUiRun();
  451. }
  452. else if (std::strcmp(msg, "quit") == 0)
  453. {
  454. handleUiClosed();
  455. }
  456. else
  457. {
  458. carla_stdout("lv2_work unknown msg '%s'", msg);
  459. return LV2_WORKER_ERR_UNKNOWN;
  460. }
  461. return LV2_WORKER_SUCCESS;
  462. }
  463. LV2_Worker_Status lv2_work_resp(uint32_t /*size*/, const void* /*body*/)
  464. {
  465. return LV2_WORKER_SUCCESS;
  466. }
  467. // ----------------------------------------------------------------------------------------------------------------
  468. void lv2ui_instantiate(LV2UI_Write_Function writeFunction, LV2UI_Controller controller,
  469. LV2UI_Widget* widget, const LV2_Feature* const* features)
  470. {
  471. fUI.writeFunction = writeFunction;
  472. fUI.controller = controller;
  473. if (fHost.uiName != nullptr)
  474. {
  475. delete[] fHost.uiName;
  476. fHost.uiName = nullptr;
  477. }
  478. // ---------------------------------------------------------------
  479. // see if the host supports external-ui
  480. for (int i=0; features[i] != nullptr; ++i)
  481. {
  482. if (std::strcmp(features[i]->URI, LV2_EXTERNAL_UI__Host) == 0 ||
  483. std::strcmp(features[i]->URI, LV2_EXTERNAL_UI_DEPRECATED_URI) == 0)
  484. {
  485. fUI.host = (const LV2_External_UI_Host*)features[i]->data;
  486. }
  487. if (std::strcmp(features[i]->URI, LV2_UI__touch) == 0)
  488. {
  489. fUI.touch = (const LV2UI_Touch*)features[i]->data;
  490. }
  491. }
  492. if (fUI.host != nullptr)
  493. {
  494. fHost.uiName = carla_strdup(fUI.host->plugin_human_id);
  495. *widget = (LV2_External_UI_Widget_Compat*)this;
  496. return;
  497. }
  498. // ---------------------------------------------------------------
  499. // no external-ui support, use showInterface
  500. for (int i=0; features[i] != nullptr; ++i)
  501. {
  502. if (std::strcmp(features[i]->URI, LV2_OPTIONS__options) != 0)
  503. continue;
  504. const LV2_Options_Option* const options((const LV2_Options_Option*)features[i]->data);
  505. CARLA_SAFE_ASSERT_BREAK(options != nullptr);
  506. for (int j=0; options[j].key != 0; ++j)
  507. {
  508. if (options[j].key != fUridMap->map(fUridMap->handle, LV2_UI__windowTitle))
  509. continue;
  510. const char* const title((const char*)options[j].value);
  511. CARLA_SAFE_ASSERT_BREAK(title != nullptr && title[0] != '\0');
  512. fHost.uiName = carla_strdup(title);
  513. break;
  514. }
  515. break;
  516. }
  517. if (fHost.uiName == nullptr)
  518. fHost.uiName = carla_strdup(fDescriptor->name);
  519. *widget = nullptr;
  520. return;
  521. }
  522. void lv2ui_port_event(uint32_t portIndex, uint32_t bufferSize, uint32_t format, const void* buffer) const
  523. {
  524. if (format != 0 || bufferSize != sizeof(float) || buffer == nullptr)
  525. return;
  526. if (portIndex < fPorts.indexOffset || ! fUI.isVisible)
  527. return;
  528. if (fDescriptor->ui_set_parameter_value == nullptr)
  529. return;
  530. const float value(*(const float*)buffer);
  531. fDescriptor->ui_set_parameter_value(fHandle, portIndex-fPorts.indexOffset, value);
  532. }
  533. // ----------------------------------------------------------------------------------------------------------------
  534. void lv2ui_select_program(uint32_t bank, uint32_t program) const
  535. {
  536. if (fDescriptor->category == NATIVE_PLUGIN_CATEGORY_SYNTH)
  537. return;
  538. if (fDescriptor->ui_set_midi_program == nullptr)
  539. return;
  540. fDescriptor->ui_set_midi_program(fHandle, 0, bank, program);
  541. }
  542. // ----------------------------------------------------------------------------------------------------------------
  543. protected:
  544. void handleUiRun() const override
  545. {
  546. if (fDescriptor->ui_idle != nullptr)
  547. fDescriptor->ui_idle(fHandle);
  548. }
  549. void handleUiShow() override
  550. {
  551. if (fDescriptor->ui_show != nullptr)
  552. fDescriptor->ui_show(fHandle, true);
  553. fUI.isVisible = true;
  554. }
  555. void handleUiHide() override
  556. {
  557. if (fDescriptor->ui_show != nullptr)
  558. fDescriptor->ui_show(fHandle, false);
  559. fUI.isVisible = false;
  560. }
  561. // ----------------------------------------------------------------------------------------------------------------
  562. void handleParameterValueChanged(const uint32_t index, const float value) override
  563. {
  564. fDescriptor->set_parameter_value(fHandle, index, value);
  565. }
  566. void handleBufferSizeChanged(const uint32_t bufferSize) override
  567. {
  568. if (fDescriptor->dispatcher == nullptr)
  569. return;
  570. fDescriptor->dispatcher(fHandle, NATIVE_PLUGIN_OPCODE_BUFFER_SIZE_CHANGED, 0, bufferSize, nullptr, 0.0f);
  571. }
  572. void handleSampleRateChanged(const double sampleRate) override
  573. {
  574. if (fDescriptor->dispatcher == nullptr)
  575. return;
  576. fDescriptor->dispatcher(fHandle, NATIVE_PLUGIN_OPCODE_SAMPLE_RATE_CHANGED, 0, 0, nullptr, (float)sampleRate);
  577. }
  578. // ----------------------------------------------------------------------------------------------------------------
  579. bool handleWriteMidiEvent(const NativeMidiEvent* const event)
  580. {
  581. CARLA_SAFE_ASSERT_RETURN(fPorts.numMidiOuts > 0, false);
  582. CARLA_SAFE_ASSERT_RETURN(event != nullptr, false);
  583. CARLA_SAFE_ASSERT_RETURN(event->size > 0, false);
  584. const uint8_t port(event->port);
  585. CARLA_SAFE_ASSERT_RETURN(port < fPorts.numMidiOuts, false);
  586. LV2_Atom_Sequence* const seq(fPorts.eventsOut[port]);
  587. CARLA_SAFE_ASSERT_RETURN(seq != nullptr, false);
  588. Ports::EventsOutData& mData(fPorts.eventsOutData[port]);
  589. if (sizeof(LV2_Atom_Event) + event->size > mData.capacity - mData.offset)
  590. return false;
  591. LV2_Atom_Event* const aev = (LV2_Atom_Event*)(LV2_ATOM_CONTENTS(LV2_Atom_Sequence, seq) + mData.offset);
  592. aev->time.frames = event->time;
  593. aev->body.size = event->size;
  594. aev->body.type = fURIs.midiEvent;
  595. std::memcpy(LV2_ATOM_BODY(&aev->body), event->data, event->size);
  596. const uint32_t size = lv2_atom_pad_size(static_cast<uint32_t>(sizeof(LV2_Atom_Event) + event->size));
  597. mData.offset += size;
  598. seq->atom.size += size;
  599. return true;
  600. }
  601. void handleUiParameterChanged(const uint32_t index, const float value) const
  602. {
  603. if (kIgnoreParameters || fWorkerUISignal)
  604. return;
  605. if (fUI.writeFunction != nullptr && fUI.controller != nullptr)
  606. fUI.writeFunction(fUI.controller, index+fPorts.indexOffset, sizeof(float), 0, &value);
  607. }
  608. void handleUiParameterTouch(const uint32_t index, const bool touch) const
  609. {
  610. if (kIgnoreParameters)
  611. return;
  612. if (fUI.touch != nullptr && fUI.touch->touch != nullptr)
  613. fUI.touch->touch(fUI.touch->handle, index+fPorts.indexOffset, touch);
  614. }
  615. void handleUiResize(const uint32_t, const uint32_t) const
  616. {
  617. // nothing here
  618. }
  619. void handleUiCustomDataChanged(const char* const key, const char* const value) const
  620. {
  621. carla_stdout("TODO: handleUiCustomDataChanged %s %s", key, value);
  622. //storeCustomData(key, value);
  623. if (fUI.writeFunction == nullptr || fUI.controller == nullptr)
  624. return;
  625. }
  626. void handleUiClosed()
  627. {
  628. fUI.isVisible = false;
  629. if (fWorkerUISignal)
  630. fWorkerUISignal = -1;
  631. if (fUI.host != nullptr && fUI.host->ui_closed != nullptr && fUI.controller != nullptr)
  632. fUI.host->ui_closed(fUI.controller);
  633. fUI.host = nullptr;
  634. fUI.touch = nullptr;
  635. fUI.writeFunction = nullptr;
  636. fUI.controller = nullptr;
  637. }
  638. const char* handleUiOpenFile(const bool /*isDir*/, const char* const /*title*/, const char* const /*filter*/) const
  639. {
  640. // TODO
  641. return nullptr;
  642. }
  643. const char* handleUiSaveFile(const bool /*isDir*/, const char* const /*title*/, const char* const /*filter*/) const
  644. {
  645. // TODO
  646. return nullptr;
  647. }
  648. intptr_t handleDispatcher(const NativeHostDispatcherOpcode opcode, const int32_t index, const intptr_t value, void* const ptr, const float opt)
  649. {
  650. #ifdef DEBUG
  651. if (opcode != NATIVE_HOST_OPCODE_GET_FILE_PATH)
  652. {
  653. carla_debug("NativePlugin::handleDispatcher(%i, %i, " P_INTPTR ", %p, %f)",
  654. opcode, index, value, ptr, static_cast<double>(opt));
  655. }
  656. #endif
  657. intptr_t ret = 0;
  658. switch (opcode)
  659. {
  660. case NATIVE_HOST_OPCODE_NULL:
  661. case NATIVE_HOST_OPCODE_UPDATE_PARAMETER:
  662. case NATIVE_HOST_OPCODE_UPDATE_MIDI_PROGRAM:
  663. case NATIVE_HOST_OPCODE_RELOAD_PARAMETERS:
  664. case NATIVE_HOST_OPCODE_RELOAD_MIDI_PROGRAMS:
  665. case NATIVE_HOST_OPCODE_RELOAD_ALL:
  666. case NATIVE_HOST_OPCODE_HOST_IDLE:
  667. case NATIVE_HOST_OPCODE_INTERNAL_PLUGIN:
  668. case NATIVE_HOST_OPCODE_QUEUE_INLINE_DISPLAY:
  669. case NATIVE_HOST_OPCODE_REQUEST_IDLE:
  670. // nothing
  671. break;
  672. case NATIVE_HOST_OPCODE_GET_FILE_PATH:
  673. CARLA_SAFE_ASSERT_RETURN(ptr != nullptr, 0);
  674. if (std::strcmp((char*)ptr, "carla") == 0 && fLastProjectPath != nullptr)
  675. return static_cast<intptr_t>((uintptr_t)fLastProjectPath.buffer());
  676. break;
  677. case NATIVE_HOST_OPCODE_UI_UNAVAILABLE:
  678. handleUiClosed();
  679. break;
  680. case NATIVE_HOST_OPCODE_UI_TOUCH_PARAMETER:
  681. CARLA_SAFE_ASSERT_RETURN(index >= 0, 0);
  682. handleUiParameterTouch(static_cast<uint32_t>(index), value != 0);
  683. break;
  684. case NATIVE_HOST_OPCODE_UI_RESIZE:
  685. CARLA_SAFE_ASSERT_RETURN(index > 0, 0);
  686. CARLA_SAFE_ASSERT_RETURN(value > 0, 0);
  687. handleUiResize(static_cast<uint32_t>(index), static_cast<uint32_t>(value));
  688. break;
  689. }
  690. return ret;
  691. // unused for now
  692. (void)index;
  693. (void)value;
  694. (void)ptr;
  695. (void)opt;
  696. }
  697. void updateParameterOutputs()
  698. {
  699. float value;
  700. for (uint32_t i=0; i < fPorts.numParams; ++i)
  701. {
  702. if (! fPorts.paramsOut[i])
  703. continue;
  704. fPorts.paramsLast[i] = value = fDescriptor->get_parameter_value(fHandle, i);
  705. if (fPorts.paramsPtr[i] != nullptr)
  706. *fPorts.paramsPtr[i] = value;
  707. }
  708. }
  709. // -------------------------------------------------------------------
  710. private:
  711. // Native data
  712. NativePluginHandle fHandle;
  713. NativeHostDescriptor fHost;
  714. const NativePluginDescriptor* const fDescriptor;
  715. LV2_Program_Descriptor fProgramDesc;
  716. // carla as plugin does not implement lv2 parameter API yet, needed for feedback
  717. const bool kIgnoreParameters;
  718. uint32_t fMidiEventCount;
  719. NativeMidiEvent fMidiEvents[kMaxMidiEvents];
  720. CarlaString fLastProjectPath;
  721. CarlaString fLoadedFile;
  722. int fWorkerUISignal;
  723. // -------------------------------------------------------------------
  724. #define handlePtr ((NativePlugin*)handle)
  725. static uint32_t host_get_buffer_size(NativeHostHandle handle)
  726. {
  727. return handlePtr->fBufferSize;
  728. }
  729. static double host_get_sample_rate(NativeHostHandle handle)
  730. {
  731. return handlePtr->fSampleRate;
  732. }
  733. static bool host_is_offline(NativeHostHandle handle)
  734. {
  735. return handlePtr->fIsOffline;
  736. }
  737. static const NativeTimeInfo* host_get_time_info(NativeHostHandle handle)
  738. {
  739. return &(handlePtr->fTimeInfo);
  740. }
  741. static bool host_write_midi_event(NativeHostHandle handle, const NativeMidiEvent* event)
  742. {
  743. return handlePtr->handleWriteMidiEvent(event);
  744. }
  745. static void host_ui_parameter_changed(NativeHostHandle handle, uint32_t index, float value)
  746. {
  747. handlePtr->handleUiParameterChanged(index, value);
  748. }
  749. static void host_ui_parameter_touch(NativeHostHandle handle, uint32_t index, bool touch)
  750. {
  751. handlePtr->handleUiParameterTouch(index, touch);
  752. }
  753. static void host_ui_custom_data_changed(NativeHostHandle handle, const char* key, const char* value)
  754. {
  755. handlePtr->handleUiCustomDataChanged(key, value);
  756. }
  757. static void host_ui_closed(NativeHostHandle handle)
  758. {
  759. handlePtr->handleUiClosed();
  760. }
  761. static const char* host_ui_open_file(NativeHostHandle handle, bool isDir, const char* title, const char* filter)
  762. {
  763. return handlePtr->handleUiOpenFile(isDir, title, filter);
  764. }
  765. static const char* host_ui_save_file(NativeHostHandle handle, bool isDir, const char* title, const char* filter)
  766. {
  767. return handlePtr->handleUiSaveFile(isDir, title, filter);
  768. }
  769. static intptr_t host_dispatcher(NativeHostHandle handle, NativeHostDispatcherOpcode opcode, int32_t index, intptr_t value, void* ptr, float opt)
  770. {
  771. return handlePtr->handleDispatcher(opcode, index, value, ptr, opt);
  772. }
  773. #undef handlePtr
  774. CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(NativePlugin)
  775. };
  776. // -----------------------------------------------------------------------
  777. // LV2 plugin descriptor functions
  778. static LV2_Handle lv2_instantiate(const LV2_Descriptor* lv2Descriptor, double sampleRate, const char* bundlePath, const LV2_Feature* const* features)
  779. {
  780. carla_debug("lv2_instantiate(%p, %g, %s, %p)", lv2Descriptor, sampleRate, bundlePath, features);
  781. const NativePluginDescriptor* pluginDesc = nullptr;
  782. const char* pluginLabel = nullptr;
  783. if (std::strncmp(lv2Descriptor->URI, "http://kxstudio.sf.net/carla/plugins/", 37) == 0)
  784. pluginLabel = lv2Descriptor->URI+37;
  785. if (pluginLabel == nullptr)
  786. {
  787. carla_stderr("Failed to find carla native plugin with URI \"%s\"", lv2Descriptor->URI);
  788. return nullptr;
  789. }
  790. carla_debug("lv2_instantiate() - looking up label \"%s\"", pluginLabel);
  791. PluginListManager& plm(PluginListManager::getInstance());
  792. for (LinkedList<const NativePluginDescriptor*>::Itenerator it = plm.descs.begin2(); it.valid(); it.next())
  793. {
  794. const NativePluginDescriptor* const& tmpDesc(it.getValue(nullptr));
  795. CARLA_SAFE_ASSERT_CONTINUE(tmpDesc != nullptr);
  796. if (std::strcmp(tmpDesc->label, pluginLabel) == 0)
  797. {
  798. pluginDesc = tmpDesc;
  799. break;
  800. }
  801. }
  802. if (pluginDesc == nullptr)
  803. {
  804. carla_stderr("Failed to find carla native plugin with label \"%s\"", pluginLabel);
  805. return nullptr;
  806. }
  807. NativePlugin* const plugin(new NativePlugin(pluginDesc, sampleRate, bundlePath, features));
  808. if (! plugin->init())
  809. {
  810. carla_stderr("Failed to init plugin");
  811. delete plugin;
  812. return nullptr;
  813. }
  814. return (LV2_Handle)plugin;
  815. }
  816. #define instancePtr ((NativePlugin*)instance)
  817. static void lv2_connect_port(LV2_Handle instance, uint32_t port, void* dataLocation)
  818. {
  819. instancePtr->lv2_connect_port(port, dataLocation);
  820. }
  821. static void lv2_activate(LV2_Handle instance)
  822. {
  823. carla_debug("lv2_activate(%p)", instance);
  824. instancePtr->lv2_activate();
  825. }
  826. static void lv2_run(LV2_Handle instance, uint32_t sampleCount)
  827. {
  828. instancePtr->lv2_run(sampleCount);
  829. }
  830. static void lv2_deactivate(LV2_Handle instance)
  831. {
  832. carla_debug("lv2_deactivate(%p)", instance);
  833. instancePtr->lv2_deactivate();
  834. }
  835. static void lv2_cleanup(LV2_Handle instance)
  836. {
  837. carla_debug("lv2_cleanup(%p)", instance);
  838. instancePtr->lv2_cleanup();
  839. delete instancePtr;
  840. }
  841. static uint32_t lv2_get_options(LV2_Handle instance, LV2_Options_Option* options)
  842. {
  843. carla_debug("lv2_get_options(%p, %p)", instance, options);
  844. return instancePtr->lv2_get_options(options);
  845. }
  846. static uint32_t lv2_set_options(LV2_Handle instance, const LV2_Options_Option* options)
  847. {
  848. carla_debug("lv2_set_options(%p, %p)", instance, options);
  849. return instancePtr->lv2_set_options(options);
  850. }
  851. static const LV2_Program_Descriptor* lv2_get_program(LV2_Handle instance, uint32_t index)
  852. {
  853. carla_debug("lv2_get_program(%p, %i)", instance, index);
  854. return instancePtr->lv2_get_program(index);
  855. }
  856. static void lv2_select_program(LV2_Handle instance, uint32_t bank, uint32_t program)
  857. {
  858. carla_debug("lv2_select_program(%p, %i, %i)", instance, bank, program);
  859. return instancePtr->lv2_select_program(bank, program);
  860. }
  861. static LV2_State_Status lv2_save(LV2_Handle instance, LV2_State_Store_Function store, LV2_State_Handle handle, uint32_t flags, const LV2_Feature* const* features)
  862. {
  863. carla_debug("lv2_save(%p, %p, %p, %i, %p)", instance, store, handle, flags, features);
  864. return instancePtr->lv2_save(store, handle, flags, features);
  865. }
  866. static LV2_State_Status lv2_restore(LV2_Handle instance, LV2_State_Retrieve_Function retrieve, LV2_State_Handle handle, uint32_t flags, const LV2_Feature* const* features)
  867. {
  868. carla_debug("lv2_restore(%p, %p, %p, %i, %p)", instance, retrieve, handle, flags, features);
  869. return instancePtr->lv2_restore(retrieve, handle, flags, features);
  870. }
  871. static LV2_Worker_Status lv2_work(LV2_Handle instance, LV2_Worker_Respond_Function respond, LV2_Worker_Respond_Handle handle, uint32_t size, const void* data)
  872. {
  873. carla_debug("work(%p, %p, %p, %u, %p)", instance, respond, handle, size, data);
  874. return instancePtr->lv2_work(respond, handle, size, data);
  875. }
  876. static LV2_Worker_Status lv2_work_resp(LV2_Handle instance, uint32_t size, const void* body)
  877. {
  878. carla_debug("work_resp(%p, %u, %p)", instance, size, body);
  879. return instancePtr->lv2_work_resp(size, body);
  880. }
  881. static const void* lv2_extension_data(const char* uri)
  882. {
  883. carla_debug("lv2_extension_data(\"%s\")", uri);
  884. static const LV2_Options_Interface options = { lv2_get_options, lv2_set_options };
  885. static const LV2_Programs_Interface programs = { lv2_get_program, lv2_select_program };
  886. static const LV2_State_Interface state = { lv2_save, lv2_restore };
  887. static const LV2_Worker_Interface worker = { lv2_work, lv2_work_resp, nullptr };
  888. if (std::strcmp(uri, LV2_OPTIONS__interface) == 0)
  889. return &options;
  890. if (std::strcmp(uri, LV2_PROGRAMS__Interface) == 0)
  891. return &programs;
  892. if (std::strcmp(uri, LV2_STATE__interface) == 0)
  893. return &state;
  894. if (std::strcmp(uri, LV2_WORKER__interface) == 0)
  895. return &worker;
  896. return nullptr;
  897. }
  898. #undef instancePtr
  899. #ifdef HAVE_PYQT
  900. // -----------------------------------------------------------------------
  901. // LV2 UI descriptor functions
  902. static LV2UI_Handle lv2ui_instantiate(const LV2UI_Descriptor*, const char*, const char*,
  903. LV2UI_Write_Function writeFunction, LV2UI_Controller controller,
  904. LV2UI_Widget* widget, const LV2_Feature* const* features)
  905. {
  906. carla_debug("lv2ui_instantiate(..., %p, %p, %p)", writeFunction, controller, widget, features);
  907. NativePlugin* plugin = nullptr;
  908. for (int i=0; features[i] != nullptr; ++i)
  909. {
  910. if (std::strcmp(features[i]->URI, LV2_INSTANCE_ACCESS_URI) == 0)
  911. {
  912. plugin = (NativePlugin*)features[i]->data;
  913. break;
  914. }
  915. }
  916. if (plugin == nullptr)
  917. {
  918. carla_stderr("Host doesn't support instance-access, cannot show UI");
  919. return nullptr;
  920. }
  921. plugin->lv2ui_instantiate(writeFunction, controller, widget, features);
  922. return (LV2UI_Handle)plugin;
  923. }
  924. #define uiPtr ((NativePlugin*)ui)
  925. static void lv2ui_port_event(LV2UI_Handle ui, uint32_t portIndex, uint32_t bufferSize, uint32_t format, const void* buffer)
  926. {
  927. carla_debug("lv2ui_port_event(%p, %i, %i, %i, %p)", ui, portIndex, bufferSize, format, buffer);
  928. uiPtr->lv2ui_port_event(portIndex, bufferSize, format, buffer);
  929. }
  930. static void lv2ui_cleanup(LV2UI_Handle ui)
  931. {
  932. carla_debug("lv2ui_cleanup(%p)", ui);
  933. uiPtr->lv2ui_cleanup();
  934. }
  935. static void lv2ui_select_program(LV2UI_Handle ui, uint32_t bank, uint32_t program)
  936. {
  937. carla_debug("lv2ui_select_program(%p, %i, %i)", ui, bank, program);
  938. uiPtr->lv2ui_select_program(bank, program);
  939. }
  940. static int lv2ui_idle(LV2UI_Handle ui)
  941. {
  942. return uiPtr->lv2ui_idle();
  943. }
  944. static int lv2ui_show(LV2UI_Handle ui)
  945. {
  946. carla_debug("lv2ui_show(%p)", ui);
  947. return uiPtr->lv2ui_show();
  948. }
  949. static int lv2ui_hide(LV2UI_Handle ui)
  950. {
  951. carla_debug("lv2ui_hide(%p)", ui);
  952. return uiPtr->lv2ui_hide();
  953. }
  954. static const void* lv2ui_extension_data(const char* uri)
  955. {
  956. carla_stdout("lv2ui_extension_data(\"%s\")", uri);
  957. static const LV2UI_Idle_Interface uiidle = { lv2ui_idle };
  958. static const LV2UI_Show_Interface uishow = { lv2ui_show, lv2ui_hide };
  959. static const LV2_Programs_UI_Interface uiprograms = { lv2ui_select_program };
  960. if (std::strcmp(uri, LV2_UI__idleInterface) == 0)
  961. return &uiidle;
  962. if (std::strcmp(uri, LV2_UI__showInterface) == 0)
  963. return &uishow;
  964. if (std::strcmp(uri, LV2_PROGRAMS__UIInterface) == 0)
  965. return &uiprograms;
  966. return nullptr;
  967. }
  968. #endif
  969. #undef uiPtr
  970. // -----------------------------------------------------------------------
  971. // Startup code
  972. CARLA_EXPORT
  973. const LV2_Descriptor* lv2_descriptor(uint32_t index)
  974. {
  975. carla_debug("lv2_descriptor(%i)", index);
  976. PluginListManager& plm(PluginListManager::getInstance());
  977. if (index >= plm.descs.count())
  978. {
  979. carla_debug("lv2_descriptor(%i) - out of bounds", index);
  980. return nullptr;
  981. }
  982. if (index < plm.lv2Descs.count())
  983. {
  984. carla_debug("lv2_descriptor(%i) - found previously allocated", index);
  985. return plm.lv2Descs.getAt(index, nullptr);
  986. }
  987. const NativePluginDescriptor* const pluginDesc(plm.descs.getAt(index, nullptr));
  988. CARLA_SAFE_ASSERT_RETURN(pluginDesc != nullptr, nullptr);
  989. CarlaString tmpURI;
  990. tmpURI = "http://kxstudio.sf.net/carla/plugins/";
  991. tmpURI += pluginDesc->label;
  992. carla_debug("lv2_descriptor(%i) - not found, allocating new with uri \"%s\"", index, (const char*)tmpURI);
  993. const LV2_Descriptor lv2DescTmp = {
  994. /* URI */ carla_strdup(tmpURI),
  995. /* instantiate */ lv2_instantiate,
  996. /* connect_port */ lv2_connect_port,
  997. /* activate */ lv2_activate,
  998. /* run */ lv2_run,
  999. /* deactivate */ lv2_deactivate,
  1000. /* cleanup */ lv2_cleanup,
  1001. /* extension_data */ lv2_extension_data
  1002. };
  1003. LV2_Descriptor* lv2Desc;
  1004. try {
  1005. lv2Desc = new LV2_Descriptor;
  1006. } CARLA_SAFE_EXCEPTION_RETURN("new LV2_Descriptor", nullptr);
  1007. std::memcpy(lv2Desc, &lv2DescTmp, sizeof(LV2_Descriptor));
  1008. plm.lv2Descs.append(lv2Desc);
  1009. return lv2Desc;
  1010. }
  1011. #ifdef HAVE_PYQT
  1012. CARLA_EXPORT
  1013. const LV2UI_Descriptor* lv2ui_descriptor(uint32_t index)
  1014. {
  1015. carla_debug("lv2ui_descriptor(%i)", index);
  1016. static const LV2UI_Descriptor lv2UiExtDesc = {
  1017. /* URI */ "http://kxstudio.sf.net/carla/ui-ext",
  1018. /* instantiate */ lv2ui_instantiate,
  1019. /* cleanup */ lv2ui_cleanup,
  1020. /* port_event */ lv2ui_port_event,
  1021. /* extension_data */ lv2ui_extension_data
  1022. };
  1023. return (index == 0) ? &lv2UiExtDesc : nullptr;
  1024. }
  1025. #endif
  1026. // -----------------------------------------------------------------------