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.

1318 lines
44KB

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