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.

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