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.

2607 lines
87KB

  1. /*
  2. * Carla Native Plugin
  3. * Copyright (C) 2012-2013 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 GPL.txt file
  16. */
  17. #include "CarlaPluginInternal.hpp"
  18. #ifdef WANT_NATIVE
  19. #include "CarlaNative.h"
  20. #include <QtCore/Qt>
  21. #if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
  22. # include <QtWidgets/QFileDialog>
  23. #else
  24. # include <QtGui/QFileDialog>
  25. #endif
  26. // Simple plugins
  27. void carla_register_native_plugin_bypass();
  28. void carla_register_native_plugin_lfo();
  29. void carla_register_native_plugin_midiSequencer();
  30. void carla_register_native_plugin_midiSplit();
  31. void carla_register_native_plugin_midiThrough();
  32. void carla_register_native_plugin_midiTranspose();
  33. void carla_register_native_plugin_nekofilter();
  34. void carla_register_native_plugin_sunvoxfile();
  35. #ifndef BUILD_BRIDGE
  36. // Carla
  37. void carla_register_native_plugin_carla();
  38. #endif
  39. #ifdef WANT_AUDIOFILE
  40. // AudioFile
  41. void carla_register_native_plugin_audiofile();
  42. #endif
  43. #ifdef WANT_MIDIFILE
  44. // MidiFile
  45. void carla_register_native_plugin_midifile();
  46. #endif
  47. #ifdef WANT_OPENGL
  48. // DISTRHO plugins (OpenGL)
  49. void carla_register_native_plugin_3BandEQ();
  50. void carla_register_native_plugin_3BandSplitter();
  51. void carla_register_native_plugin_Nekobi();
  52. void carla_register_native_plugin_PingPongPan();
  53. void carla_register_native_plugin_StereoEnhancer();
  54. #endif
  55. // DISTRHO plugins (Qt)
  56. void carla_register_native_plugin_Notes();
  57. #ifdef WANT_ZYNADDSUBFX
  58. // ZynAddSubFX
  59. void carla_register_native_plugin_zynaddsubfx();
  60. #endif
  61. void carla_register_all_plugins()
  62. {
  63. // Simple plugins
  64. carla_register_native_plugin_bypass();
  65. carla_register_native_plugin_lfo();
  66. //carla_register_native_plugin_midiSequencer(); // unfinished
  67. carla_register_native_plugin_midiSplit();
  68. carla_register_native_plugin_midiThrough();
  69. carla_register_native_plugin_midiTranspose();
  70. carla_register_native_plugin_nekofilter();
  71. //carla_register_native_plugin_sunvoxfile(); // unfinished
  72. #ifndef BUILD_BRIDGE
  73. // Carla
  74. //carla_register_native_plugin_carla(); // kinda unfinished
  75. #endif
  76. #ifdef WANT_AUDIOFILE
  77. // AudioFile
  78. carla_register_native_plugin_audiofile();
  79. #endif
  80. #ifdef WANT_MIDIFILE
  81. // MidiFile
  82. carla_register_native_plugin_midifile();
  83. #endif
  84. #ifdef WANT_OPENGL
  85. // DISTRHO plugins (OpenGL)
  86. carla_register_native_plugin_3BandEQ();
  87. carla_register_native_plugin_3BandSplitter();
  88. carla_register_native_plugin_Nekobi();
  89. carla_register_native_plugin_PingPongPan();
  90. carla_register_native_plugin_StereoEnhancer(); // unfinished
  91. #endif
  92. // DISTRHO plugins (Qt)
  93. carla_register_native_plugin_Notes(); // unfinished
  94. #ifdef WANT_ZYNADDSUBFX
  95. // ZynAddSubFX
  96. carla_register_native_plugin_zynaddsubfx();
  97. #endif
  98. }
  99. CARLA_BACKEND_START_NAMESPACE
  100. #if 0
  101. }
  102. #endif
  103. struct NativePluginMidiData {
  104. uint32_t count;
  105. uint32_t* indexes;
  106. CarlaEngineEventPort** ports;
  107. NativePluginMidiData()
  108. : count(0),
  109. indexes(nullptr),
  110. ports(nullptr) {}
  111. ~NativePluginMidiData()
  112. {
  113. CARLA_ASSERT_INT(count == 0, count);
  114. CARLA_ASSERT(ports == nullptr);
  115. CARLA_ASSERT(indexes == nullptr);
  116. }
  117. void createNew(const uint32_t newCount)
  118. {
  119. CARLA_ASSERT_INT(count == 0, count);
  120. CARLA_ASSERT(ports == nullptr);
  121. CARLA_ASSERT(indexes == nullptr);
  122. CARLA_ASSERT_INT(newCount > 0, newCount);
  123. if (ports != nullptr || indexes != nullptr || newCount == 0)
  124. return;
  125. ports = new CarlaEngineEventPort*[newCount];
  126. indexes = new uint32_t[newCount];
  127. count = newCount;
  128. for (uint32_t i=0; i < newCount; ++i)
  129. ports[i] = nullptr;
  130. for (uint32_t i=0; i < newCount; ++i)
  131. indexes[i] = 0;
  132. }
  133. void clear()
  134. {
  135. if (ports != nullptr)
  136. {
  137. for (uint32_t i=0; i < count; ++i)
  138. {
  139. if (ports[i] != nullptr)
  140. {
  141. delete ports[i];
  142. ports[i] = nullptr;
  143. }
  144. }
  145. delete[] ports;
  146. ports = nullptr;
  147. }
  148. if (indexes != nullptr)
  149. {
  150. delete[] indexes;
  151. indexes = nullptr;
  152. }
  153. count = 0;
  154. }
  155. void initBuffers(CarlaEngine* const engine)
  156. {
  157. for (uint32_t i=0; i < count; ++i)
  158. {
  159. if (ports[i] != nullptr)
  160. ports[i]->initBuffer(engine);
  161. }
  162. }
  163. CARLA_DECLARE_NON_COPY_STRUCT_WITH_LEAK_DETECTOR(NativePluginMidiData)
  164. };
  165. class NativePlugin : public CarlaPlugin
  166. {
  167. public:
  168. NativePlugin(CarlaEngine* const engine, const unsigned int id)
  169. : CarlaPlugin(engine, id),
  170. fHandle(nullptr),
  171. fHandle2(nullptr),
  172. fDescriptor(nullptr),
  173. fIsProcessing(false),
  174. fIsUiVisible(false),
  175. fAudioInBuffers(nullptr),
  176. fAudioOutBuffers(nullptr),
  177. #ifdef CARLA_PROPER_CPP11_SUPPORT
  178. fMidiEventCount(0),
  179. fCurMidiProgs{0}
  180. #else
  181. fMidiEventCount(0)
  182. #endif
  183. {
  184. carla_debug("NativePlugin::NativePlugin(%p, %i)", engine, id);
  185. #ifndef CARLA_PROPER_CPP11_SUPPORT
  186. carla_fill<int32_t>(fCurMidiProgs, MAX_MIDI_CHANNELS, 0);
  187. #endif
  188. carla_zeroStruct< ::MidiEvent>(fMidiEvents, MAX_MIDI_EVENTS*2);
  189. carla_zeroStruct< ::TimeInfo>(fTimeInfo);
  190. fHost.handle = this;
  191. fHost.resourceDir = carla_strdup((const char*)engine->getOptions().resourceDir);
  192. fHost.uiName = nullptr;
  193. fHost.get_buffer_size = carla_host_get_buffer_size;
  194. fHost.get_sample_rate = carla_host_get_sample_rate;
  195. fHost.is_offline = carla_host_is_offline;
  196. fHost.get_time_info = carla_host_get_time_info;
  197. fHost.write_midi_event = carla_host_write_midi_event;
  198. fHost.ui_parameter_changed = carla_host_ui_parameter_changed;
  199. fHost.ui_custom_data_changed = carla_host_ui_custom_data_changed;
  200. fHost.ui_closed = carla_host_ui_closed;
  201. fHost.ui_open_file = carla_host_ui_open_file;
  202. fHost.ui_save_file = carla_host_ui_save_file;
  203. fHost.dispatcher = carla_host_dispatcher;
  204. }
  205. ~NativePlugin() override
  206. {
  207. carla_debug("NativePlugin::~NativePlugin()");
  208. // close UI
  209. if (fHints & PLUGIN_HAS_GUI)
  210. {
  211. if (fIsUiVisible && fDescriptor != nullptr && fDescriptor->ui_show != nullptr && fHandle != nullptr)
  212. fDescriptor->ui_show(fHandle, false);
  213. }
  214. kData->singleMutex.lock();
  215. kData->masterMutex.lock();
  216. if (kData->client != nullptr && kData->client->isActive())
  217. kData->client->deactivate();
  218. CARLA_ASSERT(! fIsProcessing);
  219. if (kData->active)
  220. {
  221. deactivate();
  222. kData->active = false;
  223. }
  224. if (fDescriptor != nullptr)
  225. {
  226. if (fDescriptor->cleanup != nullptr)
  227. {
  228. if (fHandle != nullptr)
  229. fDescriptor->cleanup(fHandle);
  230. if (fHandle2 != nullptr)
  231. fDescriptor->cleanup(fHandle2);
  232. }
  233. fHandle = nullptr;
  234. fHandle2 = nullptr;
  235. fDescriptor = nullptr;
  236. }
  237. if (fHost.resource_dir != nullptr)
  238. {
  239. delete[] fHost.resource_dir;
  240. fHost.resource_dir = nullptr;
  241. }
  242. if (fHost.ui_name != nullptr)
  243. {
  244. delete[] fHost.ui_name;
  245. fHost.ui_name = nullptr;
  246. }
  247. clearBuffers();
  248. }
  249. // -------------------------------------------------------------------
  250. // Information (base)
  251. PluginType type() const override
  252. {
  253. return PLUGIN_INTERNAL;
  254. }
  255. PluginCategory category() override
  256. {
  257. CARLA_ASSERT(fDescriptor != nullptr);
  258. return static_cast<PluginCategory>(fDescriptor->category);
  259. }
  260. // -------------------------------------------------------------------
  261. // Information (count)
  262. uint32_t midiInCount() const override
  263. {
  264. return fMidiIn.count;
  265. }
  266. uint32_t midiOutCount() const override
  267. {
  268. return fMidiOut.count;
  269. }
  270. uint32_t parameterScalePointCount(const uint32_t parameterId) const override
  271. {
  272. CARLA_ASSERT(fDescriptor != nullptr);
  273. CARLA_ASSERT(fHandle != nullptr);
  274. CARLA_ASSERT(parameterId < kData->param.count);
  275. if (fDescriptor->get_parameter_info != nullptr && parameterId < kData->param.count)
  276. {
  277. if (const Parameter* const param = fDescriptor->get_parameter_info(fHandle, parameterId))
  278. return param->scalePointCount;
  279. }
  280. return 0;
  281. }
  282. // -------------------------------------------------------------------
  283. // Information (current data)
  284. // nothing
  285. // -------------------------------------------------------------------
  286. // Information (per-plugin data)
  287. unsigned int availableOptions() override
  288. {
  289. CARLA_ASSERT(fDescriptor != nullptr);
  290. if (fDescriptor == nullptr)
  291. return 0x0;
  292. const bool hasMidiProgs(fDescriptor->get_midi_program_count != nullptr && fDescriptor->get_midi_program_count(fHandle) > 0);
  293. unsigned int options = 0x0;
  294. if (hasMidiProgs && (fDescriptor->supports & ::PLUGIN_SUPPORTS_PROGRAM_CHANGES) == 0)
  295. options |= PLUGIN_OPTION_MAP_PROGRAM_CHANGES;
  296. if (midiInCount() == 0 && (fDescriptor->hints & ::PLUGIN_USES_STATIC_BUFFERS) == 0)
  297. options |= PLUGIN_OPTION_FIXED_BUFFER;
  298. if (kData->engine->getProccessMode() != PROCESS_MODE_CONTINUOUS_RACK)
  299. {
  300. if (fOptions & PLUGIN_OPTION_FORCE_STEREO)
  301. options |= PLUGIN_OPTION_FORCE_STEREO;
  302. else if (kData->audioIn.count <= 1 && kData->audioOut.count <= 1 && (kData->audioIn.count != 0 || kData->audioOut.count != 0))
  303. options |= PLUGIN_OPTION_FORCE_STEREO;
  304. }
  305. if (fDescriptor->supports & ::PLUGIN_SUPPORTS_CONTROL_CHANGES)
  306. options |= PLUGIN_OPTION_SEND_CONTROL_CHANGES;
  307. if (fDescriptor->supports & ::PLUGIN_SUPPORTS_CHANNEL_PRESSURE)
  308. options |= PLUGIN_OPTION_SEND_CHANNEL_PRESSURE;
  309. if (fDescriptor->supports & ::PLUGIN_SUPPORTS_NOTE_AFTERTOUCH)
  310. options |= PLUGIN_OPTION_SEND_NOTE_AFTERTOUCH;
  311. if (fDescriptor->supports & ::PLUGIN_SUPPORTS_PITCHBEND)
  312. options |= PLUGIN_OPTION_SEND_PITCHBEND;
  313. if (fDescriptor->supports & ::PLUGIN_SUPPORTS_ALL_SOUND_OFF)
  314. options |= PLUGIN_OPTION_SEND_ALL_SOUND_OFF;
  315. return options;
  316. }
  317. float getParameterValue(const uint32_t parameterId) override
  318. {
  319. CARLA_ASSERT(fDescriptor != nullptr);
  320. CARLA_ASSERT(fHandle != nullptr);
  321. CARLA_ASSERT(parameterId < kData->param.count);
  322. if (fDescriptor->get_parameter_value != nullptr && parameterId < kData->param.count)
  323. return fDescriptor->get_parameter_value(fHandle, parameterId);
  324. return 0.0f;
  325. }
  326. float getParameterScalePointValue(const uint32_t parameterId, const uint32_t scalePointId) override
  327. {
  328. CARLA_ASSERT(fDescriptor != nullptr);
  329. CARLA_ASSERT(fHandle != nullptr);
  330. CARLA_ASSERT(parameterId < kData->param.count);
  331. CARLA_ASSERT(scalePointId < parameterScalePointCount(parameterId));
  332. if (fDescriptor->get_parameter_info != nullptr && parameterId < kData->param.count)
  333. {
  334. if (const Parameter* const param = fDescriptor->get_parameter_info(fHandle, parameterId))
  335. {
  336. const ParameterScalePoint& scalePoint(param->scalePoints[scalePointId]);
  337. return scalePoint.value;
  338. }
  339. }
  340. return 0.0f;
  341. }
  342. void getLabel(char* const strBuf) override
  343. {
  344. CARLA_ASSERT(fDescriptor != nullptr);
  345. if (fDescriptor->label != nullptr)
  346. std::strncpy(strBuf, fDescriptor->label, STR_MAX);
  347. else
  348. CarlaPlugin::getLabel(strBuf);
  349. }
  350. void getMaker(char* const strBuf) override
  351. {
  352. CARLA_ASSERT(fDescriptor != nullptr);
  353. if (fDescriptor->maker != nullptr)
  354. std::strncpy(strBuf, fDescriptor->maker, STR_MAX);
  355. else
  356. CarlaPlugin::getMaker(strBuf);
  357. }
  358. void getCopyright(char* const strBuf) override
  359. {
  360. CARLA_ASSERT(fDescriptor != nullptr);
  361. if (fDescriptor->copyright != nullptr)
  362. std::strncpy(strBuf, fDescriptor->copyright, STR_MAX);
  363. else
  364. CarlaPlugin::getCopyright(strBuf);
  365. }
  366. void getRealName(char* const strBuf) override
  367. {
  368. CARLA_ASSERT(fDescriptor != nullptr);
  369. if (fDescriptor->name != nullptr)
  370. std::strncpy(strBuf, fDescriptor->name, STR_MAX);
  371. else
  372. CarlaPlugin::getRealName(strBuf);
  373. }
  374. void getParameterName(const uint32_t parameterId, char* const strBuf) override
  375. {
  376. CARLA_ASSERT(fDescriptor != nullptr);
  377. CARLA_ASSERT(fHandle != nullptr);
  378. CARLA_ASSERT(parameterId < kData->param.count);
  379. if (fDescriptor->get_parameter_info != nullptr && parameterId < kData->param.count)
  380. {
  381. const Parameter* const param(fDescriptor->get_parameter_info(fHandle, parameterId));
  382. if (param != nullptr && param->name != nullptr)
  383. {
  384. std::strncpy(strBuf, param->name, STR_MAX);
  385. return;
  386. }
  387. }
  388. CarlaPlugin::getParameterName(parameterId, strBuf);
  389. }
  390. void getParameterText(const uint32_t parameterId, char* const strBuf) override
  391. {
  392. CARLA_ASSERT(fDescriptor != nullptr);
  393. CARLA_ASSERT(fHandle != nullptr);
  394. CARLA_ASSERT(parameterId < kData->param.count);
  395. if (fDescriptor->get_parameter_value != nullptr && fDescriptor->get_parameter_text != nullptr && parameterId < kData->param.count)
  396. {
  397. const float value(fDescriptor->get_parameter_value(fHandle, parameterId));
  398. if (const char* const text = fDescriptor->get_parameter_text(fHandle, parameterId, value))
  399. {
  400. std::strncpy(strBuf, text, STR_MAX);
  401. return;
  402. }
  403. }
  404. CarlaPlugin::getParameterText(parameterId, strBuf);
  405. }
  406. void getParameterUnit(const uint32_t parameterId, char* const strBuf) override
  407. {
  408. CARLA_ASSERT(fDescriptor != nullptr);
  409. CARLA_ASSERT(fHandle != nullptr);
  410. CARLA_ASSERT(parameterId < kData->param.count);
  411. if (fDescriptor->get_parameter_info != nullptr && parameterId < kData->param.count)
  412. {
  413. const Parameter* const param(fDescriptor->get_parameter_info(fHandle, parameterId));
  414. if (param != nullptr && param->unit != nullptr)
  415. {
  416. std::strncpy(strBuf, param->unit, STR_MAX);
  417. return;
  418. }
  419. }
  420. CarlaPlugin::getParameterUnit(parameterId, strBuf);
  421. }
  422. void getParameterScalePointLabel(const uint32_t parameterId, const uint32_t scalePointId, char* const strBuf) override
  423. {
  424. CARLA_ASSERT(fDescriptor != nullptr);
  425. CARLA_ASSERT(fHandle != nullptr);
  426. CARLA_ASSERT(parameterId < kData->param.count);
  427. CARLA_ASSERT(scalePointId < parameterScalePointCount(parameterId));
  428. if (fDescriptor->get_parameter_info != nullptr && parameterId < kData->param.count)
  429. {
  430. if (const Parameter* const param = fDescriptor->get_parameter_info(fHandle, parameterId))
  431. {
  432. const ParameterScalePoint& scalePoint(param->scalePoints[scalePointId]);
  433. if (scalePoint.label != nullptr)
  434. {
  435. std::strncpy(strBuf, scalePoint.label, STR_MAX);
  436. return;
  437. }
  438. }
  439. }
  440. CarlaPlugin::getParameterScalePointLabel(parameterId, scalePointId, strBuf);
  441. }
  442. // -------------------------------------------------------------------
  443. // Set data (state)
  444. void prepareForSave() override
  445. {
  446. CARLA_ASSERT(fDescriptor != nullptr);
  447. CARLA_ASSERT(fHandle != nullptr);
  448. if (kData->midiprog.count > 0 && (fHints & PLUGIN_IS_SYNTH) != 0)
  449. {
  450. char strBuf[STR_MAX+1];
  451. std::snprintf(strBuf, STR_MAX, "%i:%i:%i:%i:%i:%i:%i:%i:%i:%i:%i:%i:%i:%i:%i:%i",
  452. fCurMidiProgs[0], fCurMidiProgs[1], fCurMidiProgs[2], fCurMidiProgs[3],
  453. fCurMidiProgs[4], fCurMidiProgs[5], fCurMidiProgs[6], fCurMidiProgs[7],
  454. fCurMidiProgs[8], fCurMidiProgs[9], fCurMidiProgs[10], fCurMidiProgs[11],
  455. fCurMidiProgs[12], fCurMidiProgs[13], fCurMidiProgs[14], fCurMidiProgs[15]);
  456. strBuf[STR_MAX] = '\0';
  457. CarlaPlugin::setCustomData(CUSTOM_DATA_STRING, "midiPrograms", strBuf, false);
  458. }
  459. if (fDescriptor == nullptr || fDescriptor->get_state == nullptr || (fDescriptor->hints & ::PLUGIN_USES_STATE) == 0)
  460. return;
  461. if (char* data = fDescriptor->get_state(fHandle))
  462. {
  463. CarlaPlugin::setCustomData(CUSTOM_DATA_CHUNK, "State", data, false);
  464. std::free(data);
  465. }
  466. }
  467. // -------------------------------------------------------------------
  468. // Set data (internal stuff)
  469. void setName(const char* const newName) override
  470. {
  471. CARLA_ASSERT(fDescriptor != nullptr);
  472. CARLA_ASSERT(fHandle != nullptr);
  473. char uiName[std::strlen(newName)+6+1];
  474. std::strcpy(uiName, newName);
  475. std::strcat(uiName, " (GUI)");
  476. if (fHost.ui_name != nullptr)
  477. delete[] fHost.ui_name;
  478. fHost.ui_name = carla_strdup(uiName);
  479. if (fDescriptor != nullptr && fDescriptor->dispatcher != nullptr)
  480. fDescriptor->dispatcher(fHandle, PLUGIN_OPCODE_UI_NAME_CHANGED, 0, 0, uiName, 0.0f);
  481. CarlaPlugin::setName(newName);
  482. }
  483. void setCtrlChannel(const int8_t channel, const bool sendOsc, const bool sendCallback) override
  484. {
  485. if (channel < MAX_MIDI_CHANNELS && kData->midiprog.count > 0)
  486. kData->midiprog.current = fCurMidiProgs[channel];
  487. CarlaPlugin::setCtrlChannel(channel, sendOsc, sendCallback);
  488. }
  489. // -------------------------------------------------------------------
  490. // Set data (plugin-specific stuff)
  491. void setParameterValue(const uint32_t parameterId, const float value, const bool sendGui, const bool sendOsc, const bool sendCallback) override
  492. {
  493. CARLA_ASSERT(fDescriptor != nullptr);
  494. CARLA_ASSERT(fHandle != nullptr);
  495. CARLA_ASSERT(parameterId < kData->param.count);
  496. const float fixedValue(kData->param.fixValue(parameterId, value));
  497. if (fDescriptor->set_parameter_value != nullptr && parameterId < kData->param.count)
  498. {
  499. fDescriptor->set_parameter_value(fHandle, parameterId, fixedValue);
  500. if (fHandle2 != nullptr)
  501. fDescriptor->set_parameter_value(fHandle2, parameterId, fixedValue);
  502. }
  503. CarlaPlugin::setParameterValue(parameterId, fixedValue, sendGui, sendOsc, sendCallback);
  504. }
  505. void setCustomData(const char* const type, const char* const key, const char* const value, const bool sendGui) override
  506. {
  507. CARLA_ASSERT(fDescriptor != nullptr);
  508. CARLA_ASSERT(fHandle != nullptr);
  509. CARLA_ASSERT(type != nullptr);
  510. CARLA_ASSERT(key != nullptr);
  511. CARLA_ASSERT(value != nullptr);
  512. carla_debug("NativePlugin::setCustomData(%s, %s, %s, %s)", type, key, value, bool2str(sendGui));
  513. if (type == nullptr)
  514. return carla_stderr2("NativePlugin::setCustomData(\"%s\", \"%s\", \"%s\", %s) - type is null", type, key, value, bool2str(sendGui));
  515. if (std::strcmp(type, CUSTOM_DATA_STRING) != 0 && std::strcmp(type, CUSTOM_DATA_CHUNK) != 0)
  516. return carla_stderr2("NativePlugin::setCustomData(\"%s\", \"%s\", \"%s\", %s) - type is invalid", type, key, value, bool2str(sendGui));
  517. if (key == nullptr)
  518. return carla_stderr2("NativePlugin::setCustomData(\"%s\", \"%s\", \"%s\", %s) - key is null", type, key, value, bool2str(sendGui));
  519. if (value == nullptr)
  520. return carla_stderr2("Nativelugin::setCustomData(\"%s\", \"%s\", \"%s\", %s) - value is null", type, key, value, bool2str(sendGui));
  521. if (std::strcmp(type, CUSTOM_DATA_CHUNK) == 0)
  522. {
  523. if (fDescriptor->set_state != nullptr && (fDescriptor->hints & ::PLUGIN_USES_STATE) != 0)
  524. {
  525. const ScopedSingleProcessLocker spl(this, true);
  526. fDescriptor->set_state(fHandle, value);
  527. if (fHandle2 != nullptr)
  528. fDescriptor->set_state(fHandle2, value);
  529. }
  530. }
  531. else if (std::strcmp(key, "midiPrograms") == 0 && fDescriptor->set_midi_program != nullptr)
  532. {
  533. QStringList midiProgramList(QString(value).split(":", QString::SkipEmptyParts));
  534. if (midiProgramList.count() == MAX_MIDI_CHANNELS)
  535. {
  536. uint i = 0;
  537. foreach (const QString& midiProg, midiProgramList)
  538. {
  539. bool ok;
  540. const uint index(midiProg.toUInt(&ok));
  541. if (ok && index < kData->midiprog.count)
  542. {
  543. const uint32_t bank = kData->midiprog.data[index].bank;
  544. const uint32_t program = kData->midiprog.data[index].program;
  545. fDescriptor->set_midi_program(fHandle, i, bank, program);
  546. if (fHandle2 != nullptr)
  547. fDescriptor->set_midi_program(fHandle2, i, bank, program);
  548. fCurMidiProgs[i] = index;
  549. if (kData->ctrlChannel == static_cast<int32_t>(i))
  550. {
  551. kData->midiprog.current = index;
  552. kData->engine->callback(CALLBACK_MIDI_PROGRAM_CHANGED, fId, index, 0, 0.0f, nullptr);
  553. }
  554. }
  555. ++i;
  556. }
  557. }
  558. }
  559. else
  560. {
  561. if (fDescriptor->set_custom_data != nullptr)
  562. {
  563. fDescriptor->set_custom_data(fHandle, key, value);
  564. if (fHandle2 != nullptr)
  565. fDescriptor->set_custom_data(fHandle2, key, value);
  566. }
  567. if (sendGui && fIsUiVisible && fDescriptor->ui_set_custom_data != nullptr)
  568. fDescriptor->ui_set_custom_data(fHandle, key, value);
  569. }
  570. CarlaPlugin::setCustomData(type, key, value, sendGui);
  571. }
  572. void setMidiProgram(int32_t index, const bool sendGui, const bool sendOsc, const bool sendCallback) override
  573. {
  574. CARLA_ASSERT(fDescriptor != nullptr);
  575. CARLA_ASSERT(fHandle != nullptr);
  576. CARLA_ASSERT(index >= -1 && index < static_cast<int32_t>(kData->midiprog.count));
  577. if (index < -1)
  578. index = -1;
  579. else if (index > static_cast<int32_t>(kData->midiprog.count))
  580. return;
  581. if ((fHints & PLUGIN_IS_SYNTH) != 0 && (kData->ctrlChannel < 0 || kData->ctrlChannel >= MAX_MIDI_CHANNELS))
  582. return;
  583. if (index >= 0)
  584. {
  585. const uint8_t channel = (kData->ctrlChannel >= 0 || kData->ctrlChannel < MAX_MIDI_CHANNELS) ? kData->ctrlChannel : 0;
  586. const uint32_t bank = kData->midiprog.data[index].bank;
  587. const uint32_t program = kData->midiprog.data[index].program;
  588. const ScopedSingleProcessLocker spl(this, (sendGui || sendOsc || sendCallback));
  589. fDescriptor->set_midi_program(fHandle, channel, bank, program);
  590. if (fHandle2 != nullptr)
  591. fDescriptor->set_midi_program(fHandle2, channel, bank, program);
  592. fCurMidiProgs[channel] = index;
  593. }
  594. CarlaPlugin::setMidiProgram(index, sendGui, sendOsc, sendCallback);
  595. }
  596. // -------------------------------------------------------------------
  597. // Set gui stuff
  598. void showGui(const bool yesNo) override
  599. {
  600. CARLA_ASSERT(fDescriptor != nullptr);
  601. CARLA_ASSERT(fHandle != nullptr);
  602. if (fDescriptor->ui_show == nullptr)
  603. return;
  604. fDescriptor->ui_show(fHandle, yesNo);
  605. fIsUiVisible = yesNo;
  606. if (! yesNo)
  607. return;
  608. if (fDescriptor->ui_set_custom_data != nullptr)
  609. {
  610. for (NonRtList<CustomData>::Itenerator it = kData->custom.begin(); it.valid(); it.next())
  611. {
  612. const CustomData& cData(*it);
  613. if (std::strcmp(cData.type, CUSTOM_DATA_STRING) == 0 && std::strcmp(cData.key, "midiPrograms") != 0)
  614. fDescriptor->ui_set_custom_data(fHandle, cData.key, cData.value);
  615. }
  616. }
  617. if (fDescriptor->ui_set_midi_program != nullptr && kData->midiprog.current >= 0 && kData->midiprog.count > 0)
  618. {
  619. const uint32_t index = kData->midiprog.current;
  620. const uint8_t channel = (kData->ctrlChannel >= 0 || kData->ctrlChannel < MAX_MIDI_CHANNELS) ? kData->ctrlChannel : 0;
  621. const uint32_t bank = kData->midiprog.data[index].bank;
  622. const uint32_t program = kData->midiprog.data[index].program;
  623. fDescriptor->ui_set_midi_program(fHandle, channel, bank, program);
  624. }
  625. if (fDescriptor->ui_set_parameter_value != nullptr)
  626. {
  627. for (uint32_t i=0; i < kData->param.count; ++i)
  628. fDescriptor->ui_set_parameter_value(fHandle, i, fDescriptor->get_parameter_value(fHandle, i));
  629. }
  630. }
  631. void idleGui() override
  632. {
  633. CARLA_ASSERT(fDescriptor != nullptr);
  634. CARLA_ASSERT(fHandle != nullptr);
  635. if (fIsUiVisible && fDescriptor->ui_idle != nullptr)
  636. fDescriptor->ui_idle(fHandle);
  637. }
  638. // -------------------------------------------------------------------
  639. // Plugin state
  640. void reload() override
  641. {
  642. carla_debug("NativePlugin::reload() - start");
  643. CARLA_ASSERT(kData->engine != nullptr);
  644. CARLA_ASSERT(fDescriptor != nullptr);
  645. CARLA_ASSERT(fHandle != nullptr);
  646. if (kData->engine == nullptr)
  647. return;
  648. if (fDescriptor == nullptr)
  649. return;
  650. if (fHandle == nullptr)
  651. return;
  652. const ProcessMode processMode(kData->engine->getProccessMode());
  653. // Safely disable plugin for reload
  654. const ScopedDisabler sd(this);
  655. if (kData->active)
  656. deactivate();
  657. clearBuffers();
  658. const float sampleRate((float)kData->engine->getSampleRate());
  659. uint32_t aIns, aOuts, mIns, mOuts, params, j;
  660. bool forcedStereoIn, forcedStereoOut;
  661. forcedStereoIn = forcedStereoOut = false;
  662. bool needsCtrlIn, needsCtrlOut;
  663. needsCtrlIn = needsCtrlOut = false;
  664. aIns = fDescriptor->audioIns;
  665. aOuts = fDescriptor->audioOuts;
  666. mIns = fDescriptor->midiIns;
  667. mOuts = fDescriptor->midiOuts;
  668. params = (fDescriptor->get_parameter_count != nullptr && fDescriptor->get_parameter_info != nullptr) ? fDescriptor->get_parameter_count(fHandle) : 0;
  669. if ((fOptions & PLUGIN_OPTION_FORCE_STEREO) != 0 && (aIns == 1 || aOuts == 1) && mIns <= 1 && mOuts <= 1)
  670. {
  671. if (fHandle2 == nullptr)
  672. fHandle2 = fDescriptor->instantiate(fDescriptor, &fHost);
  673. if (fHandle2 != nullptr)
  674. {
  675. if (aIns == 1)
  676. {
  677. aIns = 2;
  678. forcedStereoIn = true;
  679. }
  680. if (aOuts == 1)
  681. {
  682. aOuts = 2;
  683. forcedStereoOut = true;
  684. }
  685. }
  686. }
  687. if (aIns > 0)
  688. {
  689. kData->audioIn.createNew(aIns);
  690. fAudioInBuffers = new float*[aIns];
  691. for (uint32_t i=0; i < aIns; ++i)
  692. fAudioInBuffers[i] = nullptr;
  693. }
  694. if (aOuts > 0)
  695. {
  696. kData->audioOut.createNew(aOuts);
  697. fAudioOutBuffers = new float*[aOuts];
  698. needsCtrlIn = true;
  699. for (uint32_t i=0; i < aOuts; ++i)
  700. fAudioOutBuffers[i] = nullptr;
  701. }
  702. if (mIns > 0)
  703. {
  704. fMidiIn.createNew(mIns);
  705. needsCtrlIn = (mIns == 1);
  706. }
  707. if (mOuts > 0)
  708. {
  709. fMidiOut.createNew(mOuts);
  710. needsCtrlOut = (mOuts == 1);
  711. }
  712. if (params > 0)
  713. {
  714. kData->param.createNew(params);
  715. }
  716. const uint portNameSize(kData->engine->maxPortNameSize());
  717. CarlaString portName;
  718. // Audio Ins
  719. for (j=0; j < aIns; ++j)
  720. {
  721. portName.clear();
  722. if (processMode == PROCESS_MODE_SINGLE_CLIENT)
  723. {
  724. portName = fName;
  725. portName += ":";
  726. }
  727. if (aIns > 1 && ! forcedStereoIn)
  728. {
  729. portName += "input_";
  730. portName += CarlaString(j+1);
  731. }
  732. else
  733. portName += "input";
  734. portName.truncate(portNameSize);
  735. kData->audioIn.ports[j].port = (CarlaEngineAudioPort*)kData->client->addPort(kEnginePortTypeAudio, portName, true);
  736. kData->audioIn.ports[j].rindex = j;
  737. if (forcedStereoIn)
  738. {
  739. portName += "_2";
  740. kData->audioIn.ports[1].port = (CarlaEngineAudioPort*)kData->client->addPort(kEnginePortTypeAudio, portName, true);
  741. kData->audioIn.ports[1].rindex = j;
  742. break;
  743. }
  744. }
  745. // Audio Outs
  746. for (j=0; j < aOuts; ++j)
  747. {
  748. portName.clear();
  749. if (processMode == PROCESS_MODE_SINGLE_CLIENT)
  750. {
  751. portName = fName;
  752. portName += ":";
  753. }
  754. if (aOuts > 1 && ! forcedStereoOut)
  755. {
  756. portName += "output_";
  757. portName += CarlaString(j+1);
  758. }
  759. else
  760. portName += "output";
  761. portName.truncate(portNameSize);
  762. kData->audioOut.ports[j].port = (CarlaEngineAudioPort*)kData->client->addPort(kEnginePortTypeAudio, portName, false);
  763. kData->audioOut.ports[j].rindex = j;
  764. if (forcedStereoOut)
  765. {
  766. portName += "_2";
  767. kData->audioOut.ports[1].port = (CarlaEngineAudioPort*)kData->client->addPort(kEnginePortTypeAudio, portName, false);
  768. kData->audioOut.ports[1].rindex = j;
  769. break;
  770. }
  771. }
  772. // MIDI Input (only if multiple)
  773. if (mIns > 1)
  774. {
  775. for (j=0; j < mIns; ++j)
  776. {
  777. portName.clear();
  778. if (processMode == PROCESS_MODE_SINGLE_CLIENT)
  779. {
  780. portName = fName;
  781. portName += ":";
  782. }
  783. portName += "midi-in_";
  784. portName += CarlaString(j+1);
  785. portName.truncate(portNameSize);
  786. fMidiIn.ports[j] = (CarlaEngineEventPort*)kData->client->addPort(kEnginePortTypeEvent, portName, true);
  787. fMidiIn.indexes[j] = j;
  788. }
  789. }
  790. // MIDI Output (only if multiple)
  791. if (mOuts > 1)
  792. {
  793. for (j=0; j < mOuts; ++j)
  794. {
  795. portName.clear();
  796. if (processMode == PROCESS_MODE_SINGLE_CLIENT)
  797. {
  798. portName = fName;
  799. portName += ":";
  800. }
  801. portName += "midi-out_";
  802. portName += CarlaString(j+1);
  803. portName.truncate(portNameSize);
  804. fMidiOut.ports[j] = (CarlaEngineEventPort*)kData->client->addPort(kEnginePortTypeEvent, portName, false);
  805. fMidiOut.indexes[j] = j;
  806. }
  807. }
  808. for (j=0; j < params; ++j)
  809. {
  810. const ::Parameter* const paramInfo(fDescriptor->get_parameter_info(fHandle, j));
  811. CARLA_ASSERT(paramInfo != nullptr);
  812. if (paramInfo == nullptr)
  813. continue;
  814. kData->param.data[j].index = j;
  815. kData->param.data[j].rindex = j;
  816. kData->param.data[j].hints = 0x0;
  817. kData->param.data[j].midiChannel = 0;
  818. kData->param.data[j].midiCC = -1;
  819. float min, max, def, step, stepSmall, stepLarge;
  820. // min value
  821. min = paramInfo->ranges.min;
  822. // max value
  823. max = paramInfo->ranges.max;
  824. if (min > max)
  825. max = min;
  826. else if (max < min)
  827. min = max;
  828. if (max - min == 0.0f)
  829. {
  830. carla_stderr2("WARNING - Broken plugin parameter '%s': max - min == 0.0f", paramInfo->name);
  831. max = min + 0.1f;
  832. }
  833. // default value
  834. def = paramInfo->ranges.def;
  835. if (def < min)
  836. def = min;
  837. else if (def > max)
  838. def = max;
  839. if (paramInfo->hints & ::PARAMETER_USES_SAMPLE_RATE)
  840. {
  841. min *= sampleRate;
  842. max *= sampleRate;
  843. def *= sampleRate;
  844. kData->param.data[j].hints |= PARAMETER_USES_SAMPLERATE;
  845. }
  846. if (paramInfo->hints & ::PARAMETER_IS_BOOLEAN)
  847. {
  848. step = max - min;
  849. stepSmall = step;
  850. stepLarge = step;
  851. kData->param.data[j].hints |= PARAMETER_IS_BOOLEAN;
  852. }
  853. else if (paramInfo->hints & ::PARAMETER_IS_INTEGER)
  854. {
  855. step = 1.0f;
  856. stepSmall = 1.0f;
  857. stepLarge = 10.0f;
  858. kData->param.data[j].hints |= PARAMETER_IS_INTEGER;
  859. }
  860. else
  861. {
  862. float range = max - min;
  863. step = range/100.0f;
  864. stepSmall = range/1000.0f;
  865. stepLarge = range/10.0f;
  866. }
  867. if (paramInfo->hints & ::PARAMETER_IS_OUTPUT)
  868. {
  869. kData->param.data[j].type = PARAMETER_OUTPUT;
  870. needsCtrlOut = true;
  871. }
  872. else
  873. {
  874. kData->param.data[j].type = PARAMETER_INPUT;
  875. needsCtrlIn = true;
  876. }
  877. // extra parameter hints
  878. if (paramInfo->hints & ::PARAMETER_IS_ENABLED)
  879. kData->param.data[j].hints |= PARAMETER_IS_ENABLED;
  880. if (paramInfo->hints & ::PARAMETER_IS_AUTOMABLE)
  881. kData->param.data[j].hints |= PARAMETER_IS_AUTOMABLE;
  882. if (paramInfo->hints & ::PARAMETER_IS_LOGARITHMIC)
  883. kData->param.data[j].hints |= PARAMETER_IS_LOGARITHMIC;
  884. if (paramInfo->hints & ::PARAMETER_USES_SCALEPOINTS)
  885. kData->param.data[j].hints |= PARAMETER_USES_SCALEPOINTS;
  886. if (paramInfo->hints & ::PARAMETER_USES_CUSTOM_TEXT)
  887. kData->param.data[j].hints |= PARAMETER_USES_CUSTOM_TEXT;
  888. kData->param.ranges[j].min = min;
  889. kData->param.ranges[j].max = max;
  890. kData->param.ranges[j].def = def;
  891. kData->param.ranges[j].step = step;
  892. kData->param.ranges[j].stepSmall = stepSmall;
  893. kData->param.ranges[j].stepLarge = stepLarge;
  894. }
  895. if (needsCtrlIn)
  896. {
  897. portName.clear();
  898. if (processMode == PROCESS_MODE_SINGLE_CLIENT)
  899. {
  900. portName = fName;
  901. portName += ":";
  902. }
  903. portName += "events-in";
  904. portName.truncate(portNameSize);
  905. kData->event.portIn = (CarlaEngineEventPort*)kData->client->addPort(kEnginePortTypeEvent, portName, true);
  906. }
  907. if (needsCtrlOut)
  908. {
  909. portName.clear();
  910. if (processMode == PROCESS_MODE_SINGLE_CLIENT)
  911. {
  912. portName = fName;
  913. portName += ":";
  914. }
  915. portName += "events-out";
  916. portName.truncate(portNameSize);
  917. kData->event.portOut = (CarlaEngineEventPort*)kData->client->addPort(kEnginePortTypeEvent, portName, false);
  918. }
  919. if (forcedStereoIn || forcedStereoOut)
  920. fOptions |= PLUGIN_OPTION_FORCE_STEREO;
  921. else
  922. fOptions &= ~PLUGIN_OPTION_FORCE_STEREO;
  923. // plugin hints
  924. fHints = 0x0;
  925. if (aOuts > 0 && (aIns == aOuts || aIns == 1))
  926. fHints |= PLUGIN_CAN_DRYWET;
  927. if (aOuts > 0)
  928. fHints |= PLUGIN_CAN_VOLUME;
  929. if (aOuts >= 2 && aOuts % 2 == 0)
  930. fHints |= PLUGIN_CAN_BALANCE;
  931. // native plugin hints
  932. if (fDescriptor->hints & ::PLUGIN_IS_RTSAFE)
  933. fHints |= PLUGIN_IS_RTSAFE;
  934. if (fDescriptor->hints & ::PLUGIN_IS_SYNTH)
  935. fHints |= PLUGIN_IS_SYNTH;
  936. if (fDescriptor->hints & ::PLUGIN_HAS_GUI)
  937. fHints |= PLUGIN_HAS_GUI;
  938. if (fDescriptor->hints & ::PLUGIN_USES_GUI_AS_FILE)
  939. fHints |= PLUGIN_HAS_GUI_AS_FILE;
  940. if (fDescriptor->hints & ::PLUGIN_USES_SINGLE_THREAD)
  941. fHints |= PLUGIN_HAS_SINGLE_THREAD;
  942. // extra plugin hints
  943. kData->extraHints = 0x0;
  944. if (aIns <= 2 && aOuts <= 2 && (aIns == aOuts || aIns == 0 || aOuts == 0) && mIns <= 1 && mOuts <= 1)
  945. kData->extraHints |= PLUGIN_HINT_CAN_RUN_RACK;
  946. bufferSizeChanged(kData->engine->getBufferSize());
  947. reloadPrograms(true);
  948. if (kData->active)
  949. activate();
  950. carla_debug("NativePlugin::reload() - end");
  951. }
  952. void reloadPrograms(const bool init) override
  953. {
  954. carla_debug("NativePlugin::reloadPrograms(%s)", bool2str(init));
  955. uint32_t i, oldCount = kData->midiprog.count;
  956. const int32_t current = kData->midiprog.current;
  957. // Delete old programs
  958. kData->midiprog.clear();
  959. // Query new programs
  960. uint32_t count = 0;
  961. if (fDescriptor->get_midi_program_count != nullptr && fDescriptor->get_midi_program_info != nullptr && fDescriptor->set_midi_program != nullptr)
  962. count = fDescriptor->get_midi_program_count(fHandle);
  963. if (count > 0)
  964. {
  965. kData->midiprog.createNew(count);
  966. // Update data
  967. for (i=0; i < count; ++i)
  968. {
  969. const ::MidiProgram* const mpDesc = fDescriptor->get_midi_program_info(fHandle, i);
  970. CARLA_ASSERT(mpDesc != nullptr);
  971. CARLA_ASSERT(mpDesc->name != nullptr);
  972. kData->midiprog.data[i].bank = mpDesc->bank;
  973. kData->midiprog.data[i].program = mpDesc->program;
  974. kData->midiprog.data[i].name = carla_strdup(mpDesc->name);
  975. }
  976. }
  977. #ifndef BUILD_BRIDGE
  978. // Update OSC Names
  979. if (kData->engine->isOscControlRegistered())
  980. {
  981. kData->engine->osc_send_control_set_midi_program_count(fId, count);
  982. for (i=0; i < count; ++i)
  983. kData->engine->osc_send_control_set_midi_program_data(fId, i, kData->midiprog.data[i].bank, kData->midiprog.data[i].program, kData->midiprog.data[i].name);
  984. }
  985. #endif
  986. if (init)
  987. {
  988. if (count > 0)
  989. setMidiProgram(0, false, false, false);
  990. }
  991. else
  992. {
  993. // Check if current program is invalid
  994. bool programChanged = false;
  995. if (count == oldCount+1)
  996. {
  997. // one midi program added, probably created by user
  998. kData->midiprog.current = oldCount;
  999. programChanged = true;
  1000. }
  1001. else if (current < 0 && count > 0)
  1002. {
  1003. // programs exist now, but not before
  1004. kData->midiprog.current = 0;
  1005. programChanged = true;
  1006. }
  1007. else if (current >= 0 && count == 0)
  1008. {
  1009. // programs existed before, but not anymore
  1010. kData->midiprog.current = -1;
  1011. programChanged = true;
  1012. }
  1013. else if (current >= static_cast<int32_t>(count))
  1014. {
  1015. // current midi program > count
  1016. kData->midiprog.current = 0;
  1017. programChanged = true;
  1018. }
  1019. else
  1020. {
  1021. // no change
  1022. kData->midiprog.current = current;
  1023. }
  1024. if (programChanged)
  1025. setMidiProgram(kData->midiprog.current, true, true, true);
  1026. kData->engine->callback(CALLBACK_RELOAD_PROGRAMS, fId, 0, 0, 0.0f, nullptr);
  1027. }
  1028. }
  1029. // -------------------------------------------------------------------
  1030. // Plugin processing
  1031. void activate() override
  1032. {
  1033. CARLA_ASSERT(fDescriptor != nullptr);
  1034. CARLA_ASSERT(fHandle != nullptr);
  1035. if (fDescriptor->activate != nullptr)
  1036. {
  1037. fDescriptor->activate(fHandle);
  1038. if (fHandle2 != nullptr)
  1039. fDescriptor->activate(fHandle2);
  1040. }
  1041. }
  1042. void deactivate() override
  1043. {
  1044. CARLA_ASSERT(fDescriptor != nullptr);
  1045. CARLA_ASSERT(fHandle != nullptr);
  1046. if (fDescriptor->deactivate != nullptr)
  1047. {
  1048. fDescriptor->deactivate(fHandle);
  1049. if (fHandle2 != nullptr)
  1050. fDescriptor->deactivate(fHandle2);
  1051. }
  1052. }
  1053. void process(float** const inBuffer, float** const outBuffer, const uint32_t frames) override
  1054. {
  1055. uint32_t i, k;
  1056. // --------------------------------------------------------------------------------------------------------
  1057. // Check if active
  1058. if (! kData->active)
  1059. {
  1060. // disable any output sound
  1061. for (i=0; i < kData->audioOut.count; ++i)
  1062. carla_zeroFloat(outBuffer[i], frames);
  1063. return;
  1064. }
  1065. fMidiEventCount = 0;
  1066. carla_zeroStruct< ::MidiEvent>(fMidiEvents, MAX_MIDI_EVENTS*2);
  1067. // --------------------------------------------------------------------------------------------------------
  1068. // Check if needs reset
  1069. if (kData->needsReset)
  1070. {
  1071. if (fOptions & PLUGIN_OPTION_SEND_ALL_SOUND_OFF)
  1072. {
  1073. for (k=0, i=MAX_MIDI_CHANNELS; k < MAX_MIDI_CHANNELS; ++k)
  1074. {
  1075. fMidiEvents[k].data[0] = MIDI_STATUS_CONTROL_CHANGE + k;
  1076. fMidiEvents[k].data[1] = MIDI_CONTROL_ALL_NOTES_OFF;
  1077. fMidiEvents[k].data[2] = 0;
  1078. fMidiEvents[k].size = 3;
  1079. fMidiEvents[k+i].data[0] = MIDI_STATUS_CONTROL_CHANGE + k;
  1080. fMidiEvents[k+i].data[1] = MIDI_CONTROL_ALL_SOUND_OFF;
  1081. fMidiEvents[k+i].data[2] = 0;
  1082. fMidiEvents[k+i].size = 3;
  1083. }
  1084. fMidiEventCount = MAX_MIDI_CHANNELS*2;
  1085. }
  1086. else if (kData->ctrlChannel >= 0 && kData->ctrlChannel < MAX_MIDI_CHANNELS)
  1087. {
  1088. for (k=0; k < MAX_MIDI_NOTE; ++k)
  1089. {
  1090. fMidiEvents[k].data[0] = MIDI_STATUS_NOTE_OFF + kData->ctrlChannel;
  1091. fMidiEvents[k].data[1] = k;
  1092. fMidiEvents[k].data[2] = 0;
  1093. fMidiEvents[k].size = 3;
  1094. }
  1095. fMidiEventCount = MAX_MIDI_NOTE;
  1096. }
  1097. kData->needsReset = false;
  1098. }
  1099. CARLA_PROCESS_CONTINUE_CHECK;
  1100. // --------------------------------------------------------------------------------------------------------
  1101. // Set TimeInfo
  1102. const EngineTimeInfo& timeInfo(kData->engine->getTimeInfo());
  1103. fTimeInfo.playing = timeInfo.playing;
  1104. fTimeInfo.frame = timeInfo.frame;
  1105. fTimeInfo.usecs = timeInfo.usecs;
  1106. if (timeInfo.valid & EngineTimeInfo::ValidBBT)
  1107. {
  1108. fTimeInfo.bbt.valid = true;
  1109. fTimeInfo.bbt.bar = timeInfo.bbt.bar;
  1110. fTimeInfo.bbt.beat = timeInfo.bbt.beat;
  1111. fTimeInfo.bbt.tick = timeInfo.bbt.tick;
  1112. fTimeInfo.bbt.barStartTick = timeInfo.bbt.barStartTick;
  1113. fTimeInfo.bbt.beatsPerBar = timeInfo.bbt.beatsPerBar;
  1114. fTimeInfo.bbt.beatType = timeInfo.bbt.beatType;
  1115. fTimeInfo.bbt.ticksPerBeat = timeInfo.bbt.ticksPerBeat;
  1116. fTimeInfo.bbt.beatsPerMinute = timeInfo.bbt.beatsPerMinute;
  1117. }
  1118. else
  1119. fTimeInfo.bbt.valid = false;
  1120. CARLA_PROCESS_CONTINUE_CHECK;
  1121. // --------------------------------------------------------------------------------------------------------
  1122. // Event Input and Processing
  1123. if (kData->event.portIn != nullptr)
  1124. {
  1125. // ----------------------------------------------------------------------------------------------------
  1126. // MIDI Input (External)
  1127. if (kData->extNotes.mutex.tryLock())
  1128. {
  1129. while (fMidiEventCount < MAX_MIDI_EVENTS*2 && ! kData->extNotes.data.isEmpty())
  1130. {
  1131. const ExternalMidiNote& note(kData->extNotes.data.getFirst(true));
  1132. CARLA_ASSERT(note.channel >= 0 && note.channel < MAX_MIDI_CHANNELS);
  1133. fMidiEvents[fMidiEventCount].data[0] = (note.velo > 0) ? MIDI_STATUS_NOTE_ON : MIDI_STATUS_NOTE_OFF;
  1134. fMidiEvents[fMidiEventCount].data[0] += note.channel;
  1135. fMidiEvents[fMidiEventCount].data[1] = note.note;
  1136. fMidiEvents[fMidiEventCount].data[2] = note.velo;
  1137. fMidiEvents[fMidiEventCount].size = 3;
  1138. fMidiEventCount += 1;
  1139. }
  1140. kData->extNotes.mutex.unlock();
  1141. } // End of MIDI Input (External)
  1142. // ----------------------------------------------------------------------------------------------------
  1143. // Event Input (System)
  1144. bool allNotesOffSent = false;
  1145. bool sampleAccurate = (fOptions & PLUGIN_OPTION_FIXED_BUFFER) == 0;
  1146. uint32_t time, nEvents = kData->event.portIn->getEventCount();
  1147. uint32_t startTime = 0;
  1148. uint32_t timeOffset = 0;
  1149. uint32_t nextBankId = 0;
  1150. if (kData->midiprog.current >= 0 && kData->midiprog.count > 0)
  1151. nextBankId = kData->midiprog.data[kData->midiprog.current].bank;
  1152. for (i=0; i < nEvents; ++i)
  1153. {
  1154. const EngineEvent& event(kData->event.portIn->getEvent(i));
  1155. time = event.time;
  1156. if (time >= frames)
  1157. continue;
  1158. CARLA_ASSERT_INT2(time >= timeOffset, time, timeOffset);
  1159. if (time > timeOffset && sampleAccurate)
  1160. {
  1161. if (processSingle(inBuffer, outBuffer, time - timeOffset, timeOffset))
  1162. {
  1163. startTime = 0;
  1164. timeOffset = time;
  1165. if (kData->midiprog.current >= 0 && kData->midiprog.count > 0)
  1166. nextBankId = kData->midiprog.data[kData->midiprog.current].bank;
  1167. else
  1168. nextBankId = 0;
  1169. if (fMidiEventCount > 0)
  1170. {
  1171. carla_zeroStruct< ::MidiEvent>(fMidiEvents, fMidiEventCount);
  1172. fMidiEventCount = 0;
  1173. }
  1174. }
  1175. else
  1176. startTime += timeOffset;
  1177. }
  1178. // Control change
  1179. switch (event.type)
  1180. {
  1181. case kEngineEventTypeNull:
  1182. break;
  1183. case kEngineEventTypeControl:
  1184. {
  1185. const EngineControlEvent& ctrlEvent = event.ctrl;
  1186. switch (ctrlEvent.type)
  1187. {
  1188. case kEngineControlEventTypeNull:
  1189. break;
  1190. case kEngineControlEventTypeParameter:
  1191. {
  1192. #ifndef BUILD_BRIDGE
  1193. // Control backend stuff
  1194. if (event.channel == kData->ctrlChannel)
  1195. {
  1196. float value;
  1197. if (MIDI_IS_CONTROL_BREATH_CONTROLLER(ctrlEvent.param) && (fHints & PLUGIN_CAN_DRYWET) > 0)
  1198. {
  1199. value = ctrlEvent.value;
  1200. setDryWet(value, false, false);
  1201. postponeRtEvent(kPluginPostRtEventParameterChange, PARAMETER_DRYWET, 0, value);
  1202. }
  1203. if (MIDI_IS_CONTROL_CHANNEL_VOLUME(ctrlEvent.param) && (fHints & PLUGIN_CAN_VOLUME) > 0)
  1204. {
  1205. value = ctrlEvent.value*127.0f/100.0f;
  1206. setVolume(value, false, false);
  1207. postponeRtEvent(kPluginPostRtEventParameterChange, PARAMETER_VOLUME, 0, value);
  1208. }
  1209. if (MIDI_IS_CONTROL_BALANCE(ctrlEvent.param) && (fHints & PLUGIN_CAN_BALANCE) > 0)
  1210. {
  1211. float left, right;
  1212. value = ctrlEvent.value/0.5f - 1.0f;
  1213. if (value < 0.0f)
  1214. {
  1215. left = -1.0f;
  1216. right = (value*2.0f)+1.0f;
  1217. }
  1218. else if (value > 0.0f)
  1219. {
  1220. left = (value*2.0f)-1.0f;
  1221. right = 1.0f;
  1222. }
  1223. else
  1224. {
  1225. left = -1.0f;
  1226. right = 1.0f;
  1227. }
  1228. setBalanceLeft(left, false, false);
  1229. setBalanceRight(right, false, false);
  1230. postponeRtEvent(kPluginPostRtEventParameterChange, PARAMETER_BALANCE_LEFT, 0, left);
  1231. postponeRtEvent(kPluginPostRtEventParameterChange, PARAMETER_BALANCE_RIGHT, 0, right);
  1232. }
  1233. }
  1234. #endif
  1235. // Control plugin parameters
  1236. for (k=0; k < kData->param.count; ++k)
  1237. {
  1238. if (kData->param.data[k].midiChannel != event.channel)
  1239. continue;
  1240. if (kData->param.data[k].midiCC != ctrlEvent.param)
  1241. continue;
  1242. if (kData->param.data[k].type != PARAMETER_INPUT)
  1243. continue;
  1244. if ((kData->param.data[k].hints & PARAMETER_IS_AUTOMABLE) == 0)
  1245. continue;
  1246. float value;
  1247. if (kData->param.data[k].hints & PARAMETER_IS_BOOLEAN)
  1248. {
  1249. value = (ctrlEvent.value < 0.5f) ? kData->param.ranges[k].min : kData->param.ranges[k].max;
  1250. }
  1251. else
  1252. {
  1253. value = kData->param.ranges[k].unnormalizeValue(ctrlEvent.value);
  1254. if (kData->param.data[k].hints & PARAMETER_IS_INTEGER)
  1255. value = std::rint(value);
  1256. }
  1257. setParameterValue(k, value, false, false, false);
  1258. postponeRtEvent(kPluginPostRtEventParameterChange, static_cast<int32_t>(k), 0, value);
  1259. }
  1260. if ((fOptions & PLUGIN_OPTION_SEND_CONTROL_CHANGES) != 0 && ctrlEvent.param <= 0x5F)
  1261. {
  1262. if (fMidiEventCount >= MAX_MIDI_EVENTS*2)
  1263. continue;
  1264. fMidiEvents[fMidiEventCount].port = 0;
  1265. fMidiEvents[fMidiEventCount].time = sampleAccurate ? startTime : time;
  1266. fMidiEvents[fMidiEventCount].data[0] = MIDI_STATUS_CONTROL_CHANGE + event.channel;
  1267. fMidiEvents[fMidiEventCount].data[1] = ctrlEvent.param;
  1268. fMidiEvents[fMidiEventCount].data[2] = ctrlEvent.value*127.0f;
  1269. fMidiEvents[fMidiEventCount].size = 3;
  1270. fMidiEventCount += 1;
  1271. }
  1272. break;
  1273. }
  1274. case kEngineControlEventTypeMidiBank:
  1275. if (event.channel == kData->ctrlChannel && (fOptions & PLUGIN_OPTION_MAP_PROGRAM_CHANGES) != 0)
  1276. nextBankId = ctrlEvent.param;
  1277. break;
  1278. case kEngineControlEventTypeMidiProgram:
  1279. if (event.channel < MAX_MIDI_CHANNELS && (fOptions & PLUGIN_OPTION_MAP_PROGRAM_CHANGES) != 0)
  1280. {
  1281. const uint32_t nextProgramId(ctrlEvent.param);
  1282. for (k=0; k < kData->midiprog.count; ++k)
  1283. {
  1284. if (kData->midiprog.data[k].bank == nextBankId && kData->midiprog.data[k].program == nextProgramId)
  1285. {
  1286. fDescriptor->set_midi_program(fHandle, event.channel, nextBankId, nextProgramId);
  1287. if (fHandle2 != nullptr)
  1288. fDescriptor->set_midi_program(fHandle2, event.channel, nextBankId, nextProgramId);
  1289. fCurMidiProgs[event.channel] = k;
  1290. if (event.channel == kData->ctrlChannel)
  1291. postponeRtEvent(kPluginPostRtEventMidiProgramChange, k, 0, 0.0f);
  1292. break;
  1293. }
  1294. }
  1295. }
  1296. break;
  1297. case kEngineControlEventTypeAllSoundOff:
  1298. if (fOptions & PLUGIN_OPTION_SEND_ALL_SOUND_OFF)
  1299. {
  1300. if (fMidiEventCount >= MAX_MIDI_EVENTS*2)
  1301. continue;
  1302. fMidiEvents[fMidiEventCount].port = 0;
  1303. fMidiEvents[fMidiEventCount].time = sampleAccurate ? startTime : time;
  1304. fMidiEvents[fMidiEventCount].data[0] = MIDI_STATUS_CONTROL_CHANGE + event.channel;
  1305. fMidiEvents[fMidiEventCount].data[1] = MIDI_CONTROL_ALL_SOUND_OFF;
  1306. fMidiEvents[fMidiEventCount].data[2] = 0;
  1307. fMidiEvents[fMidiEventCount].size = 3;
  1308. fMidiEventCount += 1;
  1309. }
  1310. break;
  1311. case kEngineControlEventTypeAllNotesOff:
  1312. if (fOptions & PLUGIN_OPTION_SEND_ALL_SOUND_OFF)
  1313. {
  1314. if (event.channel == kData->ctrlChannel && ! allNotesOffSent)
  1315. {
  1316. allNotesOffSent = true;
  1317. sendMidiAllNotesOffToCallback();
  1318. }
  1319. if (fMidiEventCount >= MAX_MIDI_EVENTS*2)
  1320. continue;
  1321. fMidiEvents[fMidiEventCount].port = 0;
  1322. fMidiEvents[fMidiEventCount].time = sampleAccurate ? startTime : time;
  1323. fMidiEvents[fMidiEventCount].data[0] = MIDI_STATUS_CONTROL_CHANGE + event.channel;
  1324. fMidiEvents[fMidiEventCount].data[1] = MIDI_CONTROL_ALL_NOTES_OFF;
  1325. fMidiEvents[fMidiEventCount].data[2] = 0;
  1326. fMidiEvents[fMidiEventCount].size = 3;
  1327. fMidiEventCount += 1;
  1328. }
  1329. break;
  1330. }
  1331. break;
  1332. }
  1333. case kEngineEventTypeMidi:
  1334. {
  1335. if (fMidiEventCount >= MAX_MIDI_EVENTS*2)
  1336. continue;
  1337. const EngineMidiEvent& midiEvent(event.midi);
  1338. uint8_t status = MIDI_GET_STATUS_FROM_DATA(midiEvent.data);
  1339. uint8_t channel = event.channel;
  1340. if (MIDI_IS_STATUS_AFTERTOUCH(status) && (fOptions & PLUGIN_OPTION_SEND_CHANNEL_PRESSURE) == 0)
  1341. continue;
  1342. if (MIDI_IS_STATUS_CONTROL_CHANGE(status) && (fOptions & PLUGIN_OPTION_SEND_CONTROL_CHANGES) == 0)
  1343. continue;
  1344. if (MIDI_IS_STATUS_POLYPHONIC_AFTERTOUCH(status) && (fOptions & PLUGIN_OPTION_SEND_NOTE_AFTERTOUCH) == 0)
  1345. continue;
  1346. if (MIDI_IS_STATUS_PITCH_WHEEL_CONTROL(status) && (fOptions & PLUGIN_OPTION_SEND_PITCHBEND) == 0)
  1347. continue;
  1348. // Fix bad note-off
  1349. if (status == MIDI_STATUS_NOTE_ON && midiEvent.data[2] == 0)
  1350. status -= 0x10;
  1351. fMidiEvents[fMidiEventCount].port = 0;
  1352. fMidiEvents[fMidiEventCount].time = sampleAccurate ? startTime : time;
  1353. fMidiEvents[fMidiEventCount].size = midiEvent.size;
  1354. fMidiEvents[fMidiEventCount].data[0] = status + channel;
  1355. fMidiEvents[fMidiEventCount].data[1] = midiEvent.data[1];
  1356. fMidiEvents[fMidiEventCount].data[2] = midiEvent.data[2];
  1357. fMidiEvents[fMidiEventCount].data[3] = midiEvent.data[3];
  1358. fMidiEventCount += 1;
  1359. if (status == MIDI_STATUS_NOTE_ON)
  1360. postponeRtEvent(kPluginPostRtEventNoteOn, channel, midiEvent.data[1], midiEvent.data[2]);
  1361. else if (status == MIDI_STATUS_NOTE_OFF)
  1362. postponeRtEvent(kPluginPostRtEventNoteOff, channel, midiEvent.data[1], 0.0f);
  1363. break;
  1364. }
  1365. }
  1366. }
  1367. kData->postRtEvents.trySplice();
  1368. if (frames > timeOffset)
  1369. processSingle(inBuffer, outBuffer, frames - timeOffset, timeOffset);
  1370. } // End of Event Input and Processing
  1371. // --------------------------------------------------------------------------------------------------------
  1372. // Plugin processing (no events)
  1373. else
  1374. {
  1375. processSingle(inBuffer, outBuffer, frames, 0);
  1376. } // End of Plugin processing (no events)
  1377. CARLA_PROCESS_CONTINUE_CHECK;
  1378. // --------------------------------------------------------------------------------------------------------
  1379. // Control and MIDI Output
  1380. if (fMidiOut.count > 0 || kData->event.portOut != nullptr)
  1381. {
  1382. float value, curValue;
  1383. for (k=0; k < kData->param.count; ++k)
  1384. {
  1385. if (kData->param.data[k].type != PARAMETER_OUTPUT)
  1386. continue;
  1387. curValue = fDescriptor->get_parameter_value(fHandle, k);
  1388. kData->param.ranges[k].fixValue(curValue);
  1389. if (kData->param.data[k].midiCC > 0)
  1390. {
  1391. value = kData->param.ranges[k].normalizeValue(curValue);
  1392. kData->event.portOut->writeControlEvent(0, kData->param.data[k].midiChannel, kEngineControlEventTypeParameter, kData->param.data[k].midiCC, value);
  1393. }
  1394. }
  1395. // reverse lookup MIDI events
  1396. for (k = (MAX_MIDI_EVENTS*2)-1; k >= fMidiEventCount; --k)
  1397. {
  1398. if (fMidiEvents[k].data[0] == 0)
  1399. break;
  1400. const uint8_t channel = MIDI_GET_CHANNEL_FROM_DATA(fMidiEvents[k].data);
  1401. const uint8_t port = fMidiEvents[k].port;
  1402. if (kData->event.portOut != nullptr)
  1403. kData->event.portOut->writeMidiEvent(fMidiEvents[k].time, channel, port, fMidiEvents[k].data, fMidiEvents[k].size);
  1404. else if (port < fMidiOut.count)
  1405. fMidiOut.ports[port]->writeMidiEvent(fMidiEvents[k].time, channel, port, fMidiEvents[k].data, fMidiEvents[k].size);
  1406. }
  1407. } // End of Control and MIDI Output
  1408. }
  1409. bool processSingle(float** const inBuffer, float** const outBuffer, const uint32_t frames, const uint32_t timeOffset)
  1410. {
  1411. CARLA_ASSERT(frames > 0);
  1412. if (frames == 0)
  1413. return false;
  1414. if (kData->audioIn.count > 0)
  1415. {
  1416. CARLA_ASSERT(inBuffer != nullptr);
  1417. if (inBuffer == nullptr)
  1418. return false;
  1419. }
  1420. if (kData->audioOut.count > 0)
  1421. {
  1422. CARLA_ASSERT(outBuffer != nullptr);
  1423. if (outBuffer == nullptr)
  1424. return false;
  1425. }
  1426. uint32_t i, k;
  1427. // --------------------------------------------------------------------------------------------------------
  1428. // Try lock, silence otherwise
  1429. if (kData->engine->isOffline())
  1430. {
  1431. kData->singleMutex.lock();
  1432. }
  1433. else if (! kData->singleMutex.tryLock())
  1434. {
  1435. for (i=0; i < kData->audioOut.count; ++i)
  1436. {
  1437. for (k=0; k < frames; ++k)
  1438. outBuffer[i][k+timeOffset] = 0.0f;
  1439. }
  1440. return false;
  1441. }
  1442. // --------------------------------------------------------------------------------------------------------
  1443. // Reset audio buffers
  1444. for (i=0; i < kData->audioIn.count; ++i)
  1445. carla_copyFloat(fAudioInBuffers[i], inBuffer[i]+timeOffset, frames);
  1446. for (i=0; i < kData->audioOut.count; ++i)
  1447. carla_zeroFloat(fAudioOutBuffers[i], frames);
  1448. // --------------------------------------------------------------------------------------------------------
  1449. // Run plugin
  1450. fIsProcessing = true;
  1451. if (fHandle2 == nullptr)
  1452. {
  1453. fDescriptor->process(fHandle, fAudioInBuffers, fAudioOutBuffers, frames, fMidiEventCount, fMidiEvents);
  1454. }
  1455. else
  1456. {
  1457. fDescriptor->process(fHandle,
  1458. (kData->audioIn.count > 0) ? &fAudioInBuffers[0] : nullptr,
  1459. (kData->audioOut.count > 0) ? &fAudioOutBuffers[0] : nullptr,
  1460. frames, fMidiEventCount, fMidiEvents);
  1461. fDescriptor->process(fHandle2,
  1462. (kData->audioIn.count > 0) ? &fAudioInBuffers[1] : nullptr,
  1463. (kData->audioOut.count > 0) ? &fAudioOutBuffers[1] : nullptr,
  1464. frames, fMidiEventCount, fMidiEvents);
  1465. }
  1466. fIsProcessing = false;
  1467. fTimeInfo.frame += frames;
  1468. #ifndef BUILD_BRIDGE
  1469. // --------------------------------------------------------------------------------------------------------
  1470. // Post-processing (dry/wet, volume and balance)
  1471. {
  1472. const bool doDryWet = (fHints & PLUGIN_CAN_DRYWET) != 0 && kData->postProc.dryWet != 1.0f;
  1473. const bool doBalance = (fHints & PLUGIN_CAN_BALANCE) != 0 && (kData->postProc.balanceLeft != -1.0f || kData->postProc.balanceRight != 1.0f);
  1474. bool isPair;
  1475. float bufValue, oldBufLeft[doBalance ? frames : 1];
  1476. for (i=0; i < kData->audioOut.count; ++i)
  1477. {
  1478. // Dry/Wet
  1479. if (doDryWet)
  1480. {
  1481. for (k=0; k < frames; ++k)
  1482. {
  1483. bufValue = fAudioInBuffers[(kData->audioIn.count == 1) ? 0 : i][k];
  1484. fAudioOutBuffers[i][k] = (fAudioOutBuffers[i][k] * kData->postProc.dryWet) + (bufValue * (1.0f - kData->postProc.dryWet));
  1485. }
  1486. }
  1487. // Balance
  1488. if (doBalance)
  1489. {
  1490. isPair = (i % 2 == 0);
  1491. if (isPair)
  1492. {
  1493. CARLA_ASSERT(i+1 < kData->audioOut.count);
  1494. carla_copyFloat(oldBufLeft, fAudioOutBuffers[i], frames);
  1495. }
  1496. float balRangeL = (kData->postProc.balanceLeft + 1.0f)/2.0f;
  1497. float balRangeR = (kData->postProc.balanceRight + 1.0f)/2.0f;
  1498. for (k=0; k < frames; ++k)
  1499. {
  1500. if (isPair)
  1501. {
  1502. // left
  1503. fAudioOutBuffers[i][k] = oldBufLeft[k] * (1.0f - balRangeL);
  1504. fAudioOutBuffers[i][k] += fAudioOutBuffers[i+1][k] * (1.0f - balRangeR);
  1505. }
  1506. else
  1507. {
  1508. // right
  1509. fAudioOutBuffers[i][k] = fAudioOutBuffers[i][k] * balRangeR;
  1510. fAudioOutBuffers[i][k] += oldBufLeft[k] * balRangeL;
  1511. }
  1512. }
  1513. }
  1514. // Volume (and buffer copy)
  1515. {
  1516. for (k=0; k < frames; ++k)
  1517. outBuffer[i][k+timeOffset] = fAudioOutBuffers[i][k] * kData->postProc.volume;
  1518. }
  1519. }
  1520. } // End of Post-processing
  1521. #else
  1522. for (i=0; i < kData->audioOut.count; ++i)
  1523. {
  1524. for (k=0; k < frames; ++k)
  1525. outBuffer[i][k+timeOffset] = fAudioOutBuffers[i][k];
  1526. }
  1527. #endif
  1528. // --------------------------------------------------------------------------------------------------------
  1529. kData->singleMutex.unlock();
  1530. return true;
  1531. }
  1532. void bufferSizeChanged(const uint32_t newBufferSize) override
  1533. {
  1534. CARLA_ASSERT_INT(newBufferSize > 0, newBufferSize);
  1535. carla_debug("NativePlugin::bufferSizeChanged(%i)", newBufferSize);
  1536. for (uint32_t i=0; i < kData->audioIn.count; ++i)
  1537. {
  1538. if (fAudioInBuffers[i] != nullptr)
  1539. delete[] fAudioInBuffers[i];
  1540. fAudioInBuffers[i] = new float[newBufferSize];
  1541. }
  1542. for (uint32_t i=0; i < kData->audioOut.count; ++i)
  1543. {
  1544. if (fAudioOutBuffers[i] != nullptr)
  1545. delete[] fAudioOutBuffers[i];
  1546. fAudioOutBuffers[i] = new float[newBufferSize];
  1547. }
  1548. if (fDescriptor != nullptr && fDescriptor->dispatcher != nullptr)
  1549. {
  1550. fDescriptor->dispatcher(fHandle, PLUGIN_OPCODE_BUFFER_SIZE_CHANGED, 0, newBufferSize, nullptr, 0.0f);
  1551. if (fHandle2 != nullptr)
  1552. fDescriptor->dispatcher(fHandle2, PLUGIN_OPCODE_BUFFER_SIZE_CHANGED, 0, newBufferSize, nullptr, 0.0f);
  1553. }
  1554. }
  1555. void sampleRateChanged(const double newSampleRate) override
  1556. {
  1557. CARLA_ASSERT_INT(newSampleRate > 0.0, newSampleRate);
  1558. carla_debug("NativePlugin::sampleRateChanged(%g)", newSampleRate);
  1559. if (fDescriptor != nullptr && fDescriptor->dispatcher != nullptr)
  1560. {
  1561. fDescriptor->dispatcher(fHandle, PLUGIN_OPCODE_SAMPLE_RATE_CHANGED, 0, 0, nullptr, newSampleRate);
  1562. if (fHandle2 != nullptr)
  1563. fDescriptor->dispatcher(fHandle2, PLUGIN_OPCODE_SAMPLE_RATE_CHANGED, 0, 0, nullptr, newSampleRate);
  1564. }
  1565. }
  1566. void offlineModeChanged(const bool isOffline) override
  1567. {
  1568. if (fDescriptor != nullptr && fDescriptor->dispatcher != nullptr)
  1569. {
  1570. fDescriptor->dispatcher(fHandle, PLUGIN_OPCODE_OFFLINE_CHANGED, 0, isOffline ? 1 : 0, nullptr, 0.0f);
  1571. if (fHandle2 != nullptr)
  1572. fDescriptor->dispatcher(fHandle2, PLUGIN_OPCODE_OFFLINE_CHANGED, 0, isOffline ? 1 : 0, nullptr, 0.0f);
  1573. }
  1574. }
  1575. // -------------------------------------------------------------------
  1576. // Plugin buffers
  1577. void initBuffers() override
  1578. {
  1579. fMidiIn.initBuffers(kData->engine);
  1580. fMidiOut.initBuffers(kData->engine);
  1581. CarlaPlugin::initBuffers();
  1582. }
  1583. void clearBuffers() override
  1584. {
  1585. carla_debug("NativePlugin::clearBuffers() - start");
  1586. if (fAudioInBuffers != nullptr)
  1587. {
  1588. for (uint32_t i=0; i < kData->audioIn.count; ++i)
  1589. {
  1590. if (fAudioInBuffers[i] != nullptr)
  1591. {
  1592. delete[] fAudioInBuffers[i];
  1593. fAudioInBuffers[i] = nullptr;
  1594. }
  1595. }
  1596. delete[] fAudioInBuffers;
  1597. fAudioInBuffers = nullptr;
  1598. }
  1599. if (fAudioOutBuffers != nullptr)
  1600. {
  1601. for (uint32_t i=0; i < kData->audioOut.count; ++i)
  1602. {
  1603. if (fAudioOutBuffers[i] != nullptr)
  1604. {
  1605. delete[] fAudioOutBuffers[i];
  1606. fAudioOutBuffers[i] = nullptr;
  1607. }
  1608. }
  1609. delete[] fAudioOutBuffers;
  1610. fAudioOutBuffers = nullptr;
  1611. }
  1612. fMidiIn.clear();
  1613. fMidiOut.clear();
  1614. CarlaPlugin::clearBuffers();
  1615. carla_debug("NativePlugin::clearBuffers() - end");
  1616. }
  1617. // -------------------------------------------------------------------
  1618. // Post-poned UI Stuff
  1619. void uiParameterChange(const uint32_t index, const float value) override
  1620. {
  1621. CARLA_ASSERT(fDescriptor != nullptr);
  1622. CARLA_ASSERT(fHandle != nullptr);
  1623. CARLA_ASSERT(index < kData->param.count);
  1624. if (! fIsUiVisible)
  1625. return;
  1626. if (fDescriptor == nullptr || fHandle == nullptr)
  1627. return;
  1628. if (index >= kData->param.count)
  1629. return;
  1630. if (fDescriptor->ui_set_parameter_value != nullptr)
  1631. fDescriptor->ui_set_parameter_value(fHandle, index, value);
  1632. }
  1633. void uiMidiProgramChange(const uint32_t index) override
  1634. {
  1635. CARLA_ASSERT(fDescriptor != nullptr);
  1636. CARLA_ASSERT(fHandle != nullptr);
  1637. CARLA_ASSERT(index < kData->midiprog.count);
  1638. if (! fIsUiVisible)
  1639. return;
  1640. if (fDescriptor == nullptr || fHandle == nullptr)
  1641. return;
  1642. if (index >= kData->midiprog.count)
  1643. return;
  1644. if (fDescriptor->ui_set_midi_program != nullptr) // TODO
  1645. fDescriptor->ui_set_midi_program(fHandle, 0, kData->midiprog.data[index].bank, kData->midiprog.data[index].program);
  1646. }
  1647. void uiNoteOn(const uint8_t channel, const uint8_t note, const uint8_t velo) override
  1648. {
  1649. CARLA_ASSERT(fDescriptor != nullptr);
  1650. CARLA_ASSERT(fHandle != nullptr);
  1651. CARLA_ASSERT(channel < MAX_MIDI_CHANNELS);
  1652. CARLA_ASSERT(note < MAX_MIDI_NOTE);
  1653. CARLA_ASSERT(velo > 0 && velo < MAX_MIDI_VALUE);
  1654. if (! fIsUiVisible)
  1655. return;
  1656. if (fDescriptor == nullptr || fHandle == nullptr)
  1657. return;
  1658. if (channel >= MAX_MIDI_CHANNELS)
  1659. return;
  1660. if (note >= MAX_MIDI_NOTE)
  1661. return;
  1662. if (velo >= MAX_MIDI_VALUE)
  1663. return;
  1664. // TODO
  1665. }
  1666. void uiNoteOff(const uint8_t channel, const uint8_t note) override
  1667. {
  1668. CARLA_ASSERT(fDescriptor != nullptr);
  1669. CARLA_ASSERT(fHandle != nullptr);
  1670. CARLA_ASSERT(channel < MAX_MIDI_CHANNELS);
  1671. CARLA_ASSERT(note < MAX_MIDI_NOTE);
  1672. if (! fIsUiVisible)
  1673. return;
  1674. if (fDescriptor == nullptr || fHandle == nullptr)
  1675. return;
  1676. if (channel >= MAX_MIDI_CHANNELS)
  1677. return;
  1678. if (note >= MAX_MIDI_NOTE)
  1679. return;
  1680. // TODO
  1681. }
  1682. // -------------------------------------------------------------------
  1683. protected:
  1684. uint32_t handleGetBufferSize()
  1685. {
  1686. return kData->engine->getBufferSize();
  1687. }
  1688. double handleGetSampleRate()
  1689. {
  1690. return kData->engine->getSampleRate();
  1691. }
  1692. bool handleIsOffline()
  1693. {
  1694. return kData->engine->isOffline();
  1695. }
  1696. const ::TimeInfo* handleGetTimeInfo()
  1697. {
  1698. CARLA_ASSERT(fIsProcessing);
  1699. return &fTimeInfo;
  1700. }
  1701. bool handleWriteMidiEvent(const ::MidiEvent* const event)
  1702. {
  1703. CARLA_ASSERT(fEnabled);
  1704. CARLA_ASSERT(fIsProcessing);
  1705. CARLA_ASSERT(fMidiOut.count > 0 || kData->event.portOut != nullptr);
  1706. CARLA_ASSERT(event != nullptr);
  1707. CARLA_ASSERT(event->data[0] != 0);
  1708. if (! fEnabled)
  1709. return false;
  1710. if (fMidiOut.count == 0)
  1711. return false;
  1712. if (event == nullptr)
  1713. return false;
  1714. if (event->data[0] == 0)
  1715. return false;
  1716. if (! fIsProcessing)
  1717. {
  1718. carla_stderr2("NativePlugin::handleWriteMidiEvent(%p) - received MIDI out event outside audio thread, ignoring", event);
  1719. return false;
  1720. }
  1721. if (fMidiEventCount >= MAX_MIDI_EVENTS*2)
  1722. return false;
  1723. // reverse-find first free event, and put it there
  1724. for (uint32_t i=(MAX_MIDI_EVENTS*2)-1; i >= fMidiEventCount; --i)
  1725. {
  1726. if (fMidiEvents[i].data[0] == 0)
  1727. {
  1728. std::memcpy(&fMidiEvents[i], event, sizeof(::MidiEvent));
  1729. break;
  1730. }
  1731. }
  1732. return true;
  1733. }
  1734. void handleUiParameterChanged(const uint32_t index, const float value)
  1735. {
  1736. setParameterValue(index, value, false, true, true);
  1737. }
  1738. void handleUiCustomDataChanged(const char* const key, const char* const value)
  1739. {
  1740. setCustomData(CUSTOM_DATA_STRING, key, value, false);
  1741. }
  1742. void handleUiClosed()
  1743. {
  1744. kData->engine->callback(CALLBACK_SHOW_GUI, fId, 0, 0, 0.0f, nullptr);
  1745. fIsUiVisible = false;
  1746. }
  1747. const char* handleUiOpenFile(const bool isDir, const char* const title, const char* const filter)
  1748. {
  1749. static CarlaString retStr;
  1750. QFileDialog::Options options(isDir ? QFileDialog::ShowDirsOnly : 0x0);
  1751. retStr = QFileDialog::getOpenFileName(nullptr, title, "", filter, nullptr, options).toUtf8().constData();
  1752. return retStr.isNotEmpty() ? (const char*)retStr : nullptr;
  1753. }
  1754. const char* handleUiSaveFile(const bool isDir, const char* const title, const char* const filter)
  1755. {
  1756. static CarlaString retStr;
  1757. QFileDialog::Options options(isDir ? QFileDialog::ShowDirsOnly : 0x0);
  1758. retStr = QFileDialog::getSaveFileName(nullptr, title, "", filter, nullptr, options).toUtf8().constData();
  1759. return retStr.isNotEmpty() ? (const char*)retStr : nullptr;
  1760. }
  1761. intptr_t handleDispatcher(const ::HostDispatcherOpcode opcode, const int32_t index, const intptr_t value, void* const ptr, const float opt)
  1762. {
  1763. carla_debug("NativePlugin::handleDispatcher(%i, %i, " P_INTPTR ", %p, %f)", opcode, index, value, ptr, opt);
  1764. intptr_t ret = 0;
  1765. switch (opcode)
  1766. {
  1767. case ::HOST_OPCODE_NULL:
  1768. break;
  1769. #ifdef BUILD_BRIDGE
  1770. case ::HOST_OPCODE_SET_VOLUME:
  1771. case ::HOST_OPCODE_SET_DRYWET:
  1772. case ::HOST_OPCODE_SET_BALANCE_LEFT:
  1773. case ::HOST_OPCODE_SET_BALANCE_RIGHT:
  1774. case ::HOST_OPCODE_SET_PANNING:
  1775. break;
  1776. #else
  1777. case ::HOST_OPCODE_SET_VOLUME:
  1778. setVolume(opt, true, true);
  1779. break;
  1780. case ::HOST_OPCODE_SET_DRYWET:
  1781. setDryWet(opt, true, true);
  1782. break;
  1783. case ::HOST_OPCODE_SET_BALANCE_LEFT:
  1784. setBalanceLeft(opt, true, true);
  1785. break;
  1786. case ::HOST_OPCODE_SET_BALANCE_RIGHT:
  1787. setBalanceRight(opt, true, true);
  1788. break;
  1789. case ::HOST_OPCODE_SET_PANNING:
  1790. setPanning(opt, true, true);
  1791. break;
  1792. #endif
  1793. case ::HOST_OPCODE_SET_PROCESS_PRECISION:
  1794. // TODO
  1795. break;
  1796. case ::HOST_OPCODE_UPDATE_PARAMETER:
  1797. break;
  1798. case ::HOST_OPCODE_UPDATE_MIDI_PROGRAM:
  1799. break;
  1800. case ::HOST_OPCODE_RELOAD_PARAMETERS:
  1801. break;
  1802. case ::HOST_OPCODE_RELOAD_MIDI_PROGRAMS:
  1803. break;
  1804. case ::HOST_OPCODE_RELOAD_ALL:
  1805. break;
  1806. case HOST_OPCODE_UI_UNAVAILABLE:
  1807. kData->engine->callback(CALLBACK_SHOW_GUI, fId, -1, 0, 0.0f, nullptr);
  1808. break;
  1809. }
  1810. return ret;
  1811. // unused for now
  1812. (void)index;
  1813. (void)value;
  1814. (void)ptr;
  1815. }
  1816. // -------------------------------------------------------------------
  1817. public:
  1818. static size_t getPluginCount()
  1819. {
  1820. return sPluginDescriptors.count();
  1821. }
  1822. static const ::PluginDescriptor* getPluginDescriptor(const size_t index)
  1823. {
  1824. CARLA_ASSERT(index < sPluginDescriptors.count());
  1825. if (index < sPluginDescriptors.count())
  1826. return sPluginDescriptors.getAt(index);
  1827. return nullptr;
  1828. }
  1829. static void registerPlugin(const ::PluginDescriptor* desc)
  1830. {
  1831. sPluginDescriptors.append(desc);
  1832. }
  1833. // -------------------------------------------------------------------
  1834. bool init(const char* const name, const char* const label)
  1835. {
  1836. CARLA_ASSERT(kData->engine != nullptr);
  1837. CARLA_ASSERT(kData->client == nullptr);
  1838. CARLA_ASSERT(label != nullptr);
  1839. // ---------------------------------------------------------------
  1840. // first checks
  1841. if (kData->engine == nullptr)
  1842. {
  1843. return false;
  1844. }
  1845. if (kData->client != nullptr)
  1846. {
  1847. kData->engine->setLastError("Plugin client is already registered");
  1848. return false;
  1849. }
  1850. if (label == nullptr)
  1851. {
  1852. kData->engine->setLastError("null label");
  1853. return false;
  1854. }
  1855. // ---------------------------------------------------------------
  1856. // get descriptor that matches label
  1857. for (NonRtList<const ::PluginDescriptor*>::Itenerator it = sPluginDescriptors.begin(); it.valid(); it.next())
  1858. {
  1859. fDescriptor = *it;
  1860. CARLA_ASSERT(fDescriptor != nullptr);
  1861. if (fDescriptor == nullptr)
  1862. break;
  1863. if (fDescriptor->label != nullptr && std::strcmp(fDescriptor->label, label) == 0)
  1864. break;
  1865. fDescriptor = nullptr;
  1866. }
  1867. if (fDescriptor == nullptr)
  1868. {
  1869. kData->engine->setLastError("Invalid internal plugin");
  1870. return false;
  1871. }
  1872. // ---------------------------------------------------------------
  1873. // set icon
  1874. if (std::strcmp(fDescriptor->label, "audiofile") == 0)
  1875. fIconName = "file";
  1876. else if (std::strcmp(fDescriptor->label, "midifile") == 0)
  1877. fIconName = "file";
  1878. else if (std::strcmp(fDescriptor->label, "sunvoxfile") == 0)
  1879. fIconName = "file";
  1880. else if (std::strcmp(fDescriptor->label, "3BandEQ") == 0)
  1881. fIconName = "distrho";
  1882. else if (std::strcmp(fDescriptor->label, "3BandSplitter") == 0)
  1883. fIconName = "distrho";
  1884. else if (std::strcmp(fDescriptor->label, "Nekobi") == 0)
  1885. fIconName = "distrho";
  1886. else if (std::strcmp(fDescriptor->label, "Notes") == 0)
  1887. fIconName = "distrho";
  1888. else if (std::strcmp(fDescriptor->label, "PingPongPan") == 0)
  1889. fIconName = "distrho";
  1890. else if (std::strcmp(fDescriptor->label, "StereoEnhancer") == 0)
  1891. fIconName = "distrho";
  1892. // ---------------------------------------------------------------
  1893. // get info
  1894. if (name != nullptr)
  1895. fName = kData->engine->getUniquePluginName(name);
  1896. else if (fDescriptor->name != nullptr)
  1897. fName = kData->engine->getUniquePluginName(fDescriptor->name);
  1898. else
  1899. fName = kData->engine->getUniquePluginName(label);
  1900. {
  1901. CARLA_ASSERT(fHost.ui_name == nullptr);
  1902. char uiName[fName.length()+6+1];
  1903. std::strcpy(uiName, (const char*)fName);
  1904. std::strcat(uiName, " (GUI)");
  1905. fHost.ui_name = carla_strdup(uiName);
  1906. }
  1907. // ---------------------------------------------------------------
  1908. // register client
  1909. kData->client = kData->engine->addClient(this);
  1910. if (kData->client == nullptr || ! kData->client->isOk())
  1911. {
  1912. kData->engine->setLastError("Failed to register plugin client");
  1913. return false;
  1914. }
  1915. // ---------------------------------------------------------------
  1916. // initialize plugin
  1917. fHandle = fDescriptor->instantiate(fDescriptor, &fHost);
  1918. if (fHandle == nullptr)
  1919. {
  1920. kData->engine->setLastError("Plugin failed to initialize");
  1921. return false;
  1922. }
  1923. // ---------------------------------------------------------------
  1924. // load plugin settings
  1925. {
  1926. const bool hasMidiProgs(fDescriptor->get_midi_program_count != nullptr && fDescriptor->get_midi_program_count(fHandle) > 0);
  1927. // set default options
  1928. fOptions = 0x0;
  1929. if (hasMidiProgs && (fDescriptor->supports & ::PLUGIN_SUPPORTS_PROGRAM_CHANGES) == 0)
  1930. fOptions |= PLUGIN_OPTION_MAP_PROGRAM_CHANGES;
  1931. if (midiInCount() > 0 || (fDescriptor->hints & ::PLUGIN_USES_STATIC_BUFFERS) != 0)
  1932. fOptions |= PLUGIN_OPTION_FIXED_BUFFER;
  1933. if (kData->engine->getOptions().forceStereo)
  1934. fOptions |= PLUGIN_OPTION_FORCE_STEREO;
  1935. if (fDescriptor->supports & ::PLUGIN_SUPPORTS_CHANNEL_PRESSURE)
  1936. fOptions |= PLUGIN_OPTION_SEND_CHANNEL_PRESSURE;
  1937. if (fDescriptor->supports & ::PLUGIN_SUPPORTS_NOTE_AFTERTOUCH)
  1938. fOptions |= PLUGIN_OPTION_SEND_NOTE_AFTERTOUCH;
  1939. if (fDescriptor->supports & ::PLUGIN_SUPPORTS_PITCHBEND)
  1940. fOptions |= PLUGIN_OPTION_SEND_PITCHBEND;
  1941. if (fDescriptor->supports & ::PLUGIN_SUPPORTS_ALL_SOUND_OFF)
  1942. fOptions |= PLUGIN_OPTION_SEND_ALL_SOUND_OFF;
  1943. // load settings
  1944. kData->idStr = "Native/";
  1945. kData->idStr += label;
  1946. fOptions = kData->loadSettings(fOptions, availableOptions());
  1947. // ignore settings, we need this anyway
  1948. if (midiInCount() > 0 || (fDescriptor->hints & ::PLUGIN_USES_STATIC_BUFFERS) != 0)
  1949. fOptions |= PLUGIN_OPTION_FIXED_BUFFER;
  1950. }
  1951. return true;
  1952. }
  1953. class ScopedInitializer
  1954. {
  1955. public:
  1956. ScopedInitializer()
  1957. {
  1958. carla_register_all_plugins();
  1959. }
  1960. ~ScopedInitializer()
  1961. {
  1962. sPluginDescriptors.clear();
  1963. }
  1964. };
  1965. private:
  1966. ::PluginHandle fHandle;
  1967. ::PluginHandle fHandle2;
  1968. ::HostDescriptor fHost;
  1969. const ::PluginDescriptor* fDescriptor;
  1970. bool fIsProcessing;
  1971. bool fIsUiVisible;
  1972. float** fAudioInBuffers;
  1973. float** fAudioOutBuffers;
  1974. uint32_t fMidiEventCount;
  1975. ::MidiEvent fMidiEvents[MAX_MIDI_EVENTS*2];
  1976. int32_t fCurMidiProgs[MAX_MIDI_CHANNELS];
  1977. NativePluginMidiData fMidiIn;
  1978. NativePluginMidiData fMidiOut;
  1979. ::TimeInfo fTimeInfo;
  1980. static NonRtList<const ::PluginDescriptor*> sPluginDescriptors;
  1981. // -------------------------------------------------------------------
  1982. #define handlePtr ((NativePlugin*)handle)
  1983. static uint32_t carla_host_get_buffer_size(::HostHandle handle)
  1984. {
  1985. return handlePtr->handleGetBufferSize();
  1986. }
  1987. static double carla_host_get_sample_rate(::HostHandle handle)
  1988. {
  1989. return handlePtr->handleGetSampleRate();
  1990. }
  1991. static bool carla_host_is_offline(::HostHandle handle)
  1992. {
  1993. return handlePtr->handleIsOffline();
  1994. }
  1995. static const ::TimeInfo* carla_host_get_time_info(::HostHandle handle)
  1996. {
  1997. return handlePtr->handleGetTimeInfo();
  1998. }
  1999. static bool carla_host_write_midi_event(::HostHandle handle, const ::MidiEvent* event)
  2000. {
  2001. return handlePtr->handleWriteMidiEvent(event);
  2002. }
  2003. static void carla_host_ui_parameter_changed(::HostHandle handle, uint32_t index, float value)
  2004. {
  2005. handlePtr->handleUiParameterChanged(index, value);
  2006. }
  2007. static void carla_host_ui_custom_data_changed(::HostHandle handle, const char* key, const char* value)
  2008. {
  2009. handlePtr->handleUiCustomDataChanged(key, value);
  2010. }
  2011. static void carla_host_ui_closed(::HostHandle handle)
  2012. {
  2013. handlePtr->handleUiClosed();
  2014. }
  2015. static const char* carla_host_ui_open_file(::HostHandle handle, bool isDir, const char* title, const char* filter)
  2016. {
  2017. return handlePtr->handleUiOpenFile(isDir, title, filter);
  2018. }
  2019. static const char* carla_host_ui_save_file(::HostHandle handle, bool isDir, const char* title, const char* filter)
  2020. {
  2021. return handlePtr->handleUiSaveFile(isDir, title, filter);
  2022. }
  2023. static intptr_t carla_host_dispatcher(::HostHandle handle, ::HostDispatcherOpcode opcode, int32_t index, intptr_t value, void* ptr, float opt)
  2024. {
  2025. return handlePtr->handleDispatcher(opcode, index, value, ptr, opt);
  2026. }
  2027. #undef handlePtr
  2028. CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(NativePlugin)
  2029. };
  2030. NonRtList<const ::PluginDescriptor*> NativePlugin::sPluginDescriptors;
  2031. static const NativePlugin::ScopedInitializer _si;
  2032. CARLA_BACKEND_END_NAMESPACE
  2033. void carla_register_native_plugin(const PluginDescriptor* desc)
  2034. {
  2035. CARLA_BACKEND_USE_NAMESPACE
  2036. NativePlugin::registerPlugin(desc);
  2037. }
  2038. #else // WANT_NATIVE
  2039. # warning Building without Internal plugin support
  2040. #endif
  2041. CARLA_BACKEND_START_NAMESPACE
  2042. // -----------------------------------------------------------------------
  2043. #ifdef WANT_NATIVE
  2044. size_t CarlaPlugin::getNativePluginCount()
  2045. {
  2046. return NativePlugin::getPluginCount();
  2047. }
  2048. const PluginDescriptor* CarlaPlugin::getNativePluginDescriptor(const size_t index)
  2049. {
  2050. return NativePlugin::getPluginDescriptor(index);
  2051. }
  2052. #endif
  2053. // -----------------------------------------------------------------------
  2054. CarlaPlugin* CarlaPlugin::newNative(const Initializer& init)
  2055. {
  2056. carla_debug("CarlaPlugin::newNative({%p, \"%s\", \"%s\", \"%s\"})", init.engine, init.filename, init.name, init.label);
  2057. #ifdef WANT_NATIVE
  2058. NativePlugin* const plugin(new NativePlugin(init.engine, init.id));
  2059. if (! plugin->init(init.name, init.label))
  2060. {
  2061. delete plugin;
  2062. return nullptr;
  2063. }
  2064. plugin->reload();
  2065. if (init.engine->getProccessMode() == PROCESS_MODE_CONTINUOUS_RACK && ! CarlaPluginProtectedData::canRunInRack(plugin))
  2066. {
  2067. init.engine->setLastError("Carla's rack mode can only work with Mono or Stereo Internal plugins, sorry!");
  2068. delete plugin;
  2069. return nullptr;
  2070. }
  2071. return plugin;
  2072. #else
  2073. init.engine->setLastError("Internal plugins support not available");
  2074. return nullptr;
  2075. #endif
  2076. }
  2077. CARLA_BACKEND_END_NAMESPACE