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.

carla-lv2.cpp 40KB

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