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.

2001 lines
70KB

  1. /*
  2. * Carla DSSI Plugin
  3. * Copyright (C) 2011-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_DSSI
  19. #include "CarlaLadspaUtils.hpp"
  20. #include "dssi/dssi.h"
  21. CARLA_BACKEND_START_NAMESPACE
  22. #if 0
  23. }
  24. #endif
  25. class DssiPlugin : public CarlaPlugin
  26. {
  27. public:
  28. DssiPlugin(CarlaEngine* const engine, const unsigned int id)
  29. : CarlaPlugin(engine, id),
  30. fHandle(nullptr),
  31. fHandle2(nullptr),
  32. fDescriptor(nullptr),
  33. fDssiDescriptor(nullptr),
  34. fAudioInBuffers(nullptr),
  35. fAudioOutBuffers(nullptr),
  36. fParamBuffers(nullptr)
  37. {
  38. carla_debug("DssiPlugin::DssiPlugin(%p, %i)", engine, id);
  39. carla_zeroStruct<snd_seq_event_t>(fMidiEvents, MAX_MIDI_EVENTS);
  40. kData->osc.thread.setMode(CarlaPluginThread::PLUGIN_THREAD_DSSI_GUI);
  41. }
  42. ~DssiPlugin() override
  43. {
  44. carla_debug("DssiPlugin::~DssiPlugin()");
  45. // close UI
  46. if (fHints & PLUGIN_HAS_GUI)
  47. {
  48. showGui(false);
  49. // Wait a bit first, then force kill
  50. if (kData->osc.thread.isRunning() && ! kData->osc.thread.wait(kData->engine->getOptions().oscUiTimeout))
  51. {
  52. carla_stderr("DSSI GUI thread still running, forcing termination now");
  53. kData->osc.thread.terminate();
  54. }
  55. }
  56. kData->singleMutex.lock();
  57. kData->masterMutex.lock();
  58. if (kData->active)
  59. {
  60. deactivate();
  61. kData->active = false;
  62. }
  63. if (fDescriptor != nullptr)
  64. {
  65. if (fDescriptor->cleanup != nullptr)
  66. {
  67. if (fHandle != nullptr)
  68. fDescriptor->cleanup(fHandle);
  69. if (fHandle2 != nullptr)
  70. fDescriptor->cleanup(fHandle2);
  71. }
  72. fHandle = nullptr;
  73. fHandle2 = nullptr;
  74. fDescriptor = nullptr;
  75. fDssiDescriptor = nullptr;
  76. }
  77. clearBuffers();
  78. }
  79. // -------------------------------------------------------------------
  80. // Information (base)
  81. PluginType type() const override
  82. {
  83. return PLUGIN_DSSI;
  84. }
  85. PluginCategory category() override
  86. {
  87. if (fHints & PLUGIN_IS_SYNTH)
  88. return PLUGIN_CATEGORY_SYNTH;
  89. return getPluginCategoryFromName(fName);
  90. }
  91. long uniqueId() const override
  92. {
  93. CARLA_ASSERT(fDescriptor != nullptr);
  94. return fDescriptor->UniqueID;
  95. }
  96. // -------------------------------------------------------------------
  97. // Information (count)
  98. // nothing
  99. // -------------------------------------------------------------------
  100. // Information (current data)
  101. int32_t chunkData(void** const dataPtr) override
  102. {
  103. CARLA_ASSERT(fOptions & PLUGIN_OPTION_USE_CHUNKS);
  104. CARLA_ASSERT(fDssiDescriptor != nullptr);
  105. CARLA_ASSERT(fDssiDescriptor->get_custom_data != nullptr);
  106. CARLA_ASSERT(fHandle != nullptr);
  107. CARLA_ASSERT(fHandle2 == nullptr);
  108. CARLA_ASSERT(dataPtr != nullptr);
  109. unsigned long dataSize = 0;
  110. if (fDssiDescriptor->get_custom_data != nullptr && fDssiDescriptor->get_custom_data(fHandle, dataPtr, &dataSize) != 0)
  111. return static_cast<int32_t>(dataSize);
  112. return 0;
  113. }
  114. // -------------------------------------------------------------------
  115. // Information (per-plugin data)
  116. unsigned int availableOptions() override
  117. {
  118. CARLA_ASSERT(fDssiDescriptor != nullptr);
  119. if (fDssiDescriptor == nullptr)
  120. return 0x0;
  121. #ifdef __USE_GNU
  122. const bool isDssiVst = fFilename.contains("dssi-vst", true);
  123. #else
  124. const bool isDssiVst = fFilename.contains("dssi-vst");
  125. #endif
  126. unsigned int options = 0x0;
  127. options |= PLUGIN_OPTION_MAP_PROGRAM_CHANGES;
  128. if (isDssiVst)
  129. {
  130. if (kData->engine->getOptions().useDssiVstChunks && fDssiDescriptor->get_custom_data != nullptr && fDssiDescriptor->set_custom_data != nullptr)
  131. options |= PLUGIN_OPTION_USE_CHUNKS;
  132. }
  133. else
  134. {
  135. if (kData->engine->getProccessMode() != PROCESS_MODE_CONTINUOUS_RACK)
  136. {
  137. if (fOptions & PLUGIN_OPTION_FORCE_STEREO)
  138. options |= PLUGIN_OPTION_FORCE_STEREO;
  139. else if (kData->audioIn.count <= 1 && kData->audioOut.count <= 1 && (kData->audioIn.count != 0 || kData->audioOut.count != 0))
  140. options |= PLUGIN_OPTION_FORCE_STEREO;
  141. }
  142. options |= PLUGIN_OPTION_FIXED_BUFFER;
  143. }
  144. if (fDssiDescriptor->run_synth != nullptr || fDssiDescriptor->run_multiple_synths != nullptr)
  145. {
  146. options |= PLUGIN_OPTION_SEND_CONTROL_CHANGES;
  147. options |= PLUGIN_OPTION_SEND_CHANNEL_PRESSURE;
  148. options |= PLUGIN_OPTION_SEND_NOTE_AFTERTOUCH;
  149. options |= PLUGIN_OPTION_SEND_PITCHBEND;
  150. options |= PLUGIN_OPTION_SEND_ALL_SOUND_OFF;
  151. }
  152. return options;
  153. }
  154. float getParameterValue(const uint32_t parameterId) override
  155. {
  156. CARLA_ASSERT(fParamBuffers != nullptr);
  157. CARLA_ASSERT(parameterId < kData->param.count);
  158. return fParamBuffers[parameterId];
  159. }
  160. void getLabel(char* const strBuf) override
  161. {
  162. CARLA_ASSERT(fDescriptor != nullptr);
  163. if (fDescriptor->Label != nullptr)
  164. std::strncpy(strBuf, fDescriptor->Label, STR_MAX);
  165. else
  166. CarlaPlugin::getLabel(strBuf);
  167. }
  168. void getMaker(char* const strBuf) override
  169. {
  170. CARLA_ASSERT(fDescriptor != nullptr);
  171. if (fDescriptor->Maker != nullptr)
  172. std::strncpy(strBuf, fDescriptor->Maker, STR_MAX);
  173. else
  174. CarlaPlugin::getMaker(strBuf);
  175. }
  176. void getCopyright(char* const strBuf) override
  177. {
  178. CARLA_ASSERT(fDescriptor != nullptr);
  179. if (fDescriptor->Copyright != nullptr)
  180. std::strncpy(strBuf, fDescriptor->Copyright, STR_MAX);
  181. else
  182. CarlaPlugin::getCopyright(strBuf);
  183. }
  184. void getRealName(char* const strBuf) override
  185. {
  186. CARLA_ASSERT(fDescriptor != nullptr);
  187. if (fDescriptor->Name != nullptr)
  188. std::strncpy(strBuf, fDescriptor->Name, STR_MAX);
  189. else
  190. CarlaPlugin::getRealName(strBuf);
  191. }
  192. void getParameterName(const uint32_t parameterId, char* const strBuf) override
  193. {
  194. CARLA_ASSERT(fDescriptor != nullptr);
  195. CARLA_ASSERT(parameterId < kData->param.count);
  196. const int32_t rindex(kData->param.data[parameterId].rindex);
  197. if (rindex < static_cast<int32_t>(fDescriptor->PortCount))
  198. std::strncpy(strBuf, fDescriptor->PortNames[rindex], STR_MAX);
  199. else
  200. CarlaPlugin::getParameterName(parameterId, strBuf);
  201. }
  202. // -------------------------------------------------------------------
  203. // Set data (state)
  204. // nothing
  205. // -------------------------------------------------------------------
  206. // Set data (internal stuff)
  207. // nothing
  208. // -------------------------------------------------------------------
  209. // Set data (plugin-specific stuff)
  210. void setParameterValue(const uint32_t parameterId, const float value, const bool sendGui, const bool sendOsc, const bool sendCallback) override
  211. {
  212. CARLA_ASSERT(parameterId < kData->param.count);
  213. const float fixedValue(kData->param.fixValue(parameterId, value));
  214. fParamBuffers[parameterId] = fixedValue;
  215. CarlaPlugin::setParameterValue(parameterId, fixedValue, sendGui, sendOsc, sendCallback);
  216. }
  217. void setCustomData(const char* const type, const char* const key, const char* const value, const bool sendGui) override
  218. {
  219. CARLA_ASSERT(fDescriptor != nullptr);
  220. CARLA_ASSERT(fHandle != nullptr);
  221. CARLA_ASSERT(type != nullptr);
  222. CARLA_ASSERT(key != nullptr);
  223. CARLA_ASSERT(value != nullptr);
  224. carla_debug("DssiPlugin::setCustomData(%s, %s, %s, %s)", type, key, value, bool2str(sendGui));
  225. if (type == nullptr)
  226. return carla_stderr2("DssiPlugin::setCustomData(\"%s\", \"%s\", \"%s\", %s) - type is invalid", type, key, value, bool2str(sendGui));
  227. if (std::strcmp(type, CUSTOM_DATA_STRING) != 0)
  228. return carla_stderr2("DssiPlugin::setCustomData(\"%s\", \"%s\", \"%s\", %s) - type is not string", type, key, value, bool2str(sendGui));
  229. if (key == nullptr)
  230. return carla_stderr2("DssiPlugin::setCustomData(\"%s\", \"%s\", \"%s\", %s) - key is null", type, key, value, bool2str(sendGui));
  231. if (value == nullptr)
  232. return carla_stderr2("DssiPlugin::setCustomData(\"%s\", \"%s\", \"%s\", %s) - value is null", type, key, value, bool2str(sendGui));
  233. if (fDssiDescriptor->configure != nullptr)
  234. {
  235. fDssiDescriptor->configure(fHandle, key, value);
  236. if (fHandle2)
  237. fDssiDescriptor->configure(fHandle2, key, value);
  238. }
  239. if (sendGui && kData->osc.data.target != nullptr)
  240. osc_send_configure(&kData->osc.data, key, value);
  241. if (std::strcmp(key, "reloadprograms") == 0 || std::strcmp(key, "load") == 0 || std::strncmp(key, "patches", 7) == 0)
  242. {
  243. const ScopedDisabler sd(this);
  244. reloadPrograms(false);
  245. }
  246. CarlaPlugin::setCustomData(type, key, value, sendGui);
  247. }
  248. void setChunkData(const char* const stringData) override
  249. {
  250. CARLA_ASSERT(fOptions & PLUGIN_OPTION_USE_CHUNKS);
  251. CARLA_ASSERT(fDssiDescriptor != nullptr);
  252. CARLA_ASSERT(fDssiDescriptor->set_custom_data != nullptr);
  253. CARLA_ASSERT(fHandle != nullptr);
  254. CARLA_ASSERT(fHandle2 == nullptr);
  255. CARLA_ASSERT(stringData != nullptr);
  256. if (fDssiDescriptor->set_custom_data == nullptr)
  257. return;
  258. QByteArray chunk(QByteArray::fromBase64(stringData));
  259. CARLA_ASSERT(chunk.size() > 0);
  260. if (chunk.size() > 0)
  261. {
  262. const ScopedSingleProcessLocker spl(this, true);
  263. fDssiDescriptor->set_custom_data(fHandle, chunk.data(), chunk.size());
  264. }
  265. }
  266. void setMidiProgram(int32_t index, const bool sendGui, const bool sendOsc, const bool sendCallback) override
  267. {
  268. CARLA_ASSERT(fDssiDescriptor != nullptr);
  269. CARLA_ASSERT(fHandle != nullptr);
  270. CARLA_ASSERT(index >= -1 && index < static_cast<int32_t>(kData->midiprog.count));
  271. if (index < -1)
  272. index = -1;
  273. else if (index > static_cast<int32_t>(kData->midiprog.count))
  274. return;
  275. if (index >= 0 && fDssiDescriptor != nullptr && fDssiDescriptor->select_program != nullptr)
  276. {
  277. const uint32_t bank = kData->midiprog.data[index].bank;
  278. const uint32_t program = kData->midiprog.data[index].program;
  279. const ScopedSingleProcessLocker spl(this, (sendGui || sendOsc || sendCallback));
  280. fDssiDescriptor->select_program(fHandle, bank, program);
  281. if (fHandle2 != nullptr)
  282. fDssiDescriptor->select_program(fHandle2, bank, program);
  283. }
  284. CarlaPlugin::setMidiProgram(index, sendGui, sendOsc, sendCallback);
  285. }
  286. // -------------------------------------------------------------------
  287. // Set gui stuff
  288. void showGui(const bool yesNo) override
  289. {
  290. if (yesNo)
  291. {
  292. kData->osc.thread.start();
  293. }
  294. else
  295. {
  296. if (kData->osc.data.target != nullptr)
  297. {
  298. osc_send_hide(&kData->osc.data);
  299. osc_send_quit(&kData->osc.data);
  300. kData->osc.data.free();
  301. }
  302. if (kData->osc.thread.isRunning() && ! kData->osc.thread.wait(kData->engine->getOptions().oscUiTimeout))
  303. kData->osc.thread.terminate();
  304. }
  305. }
  306. // -------------------------------------------------------------------
  307. // Plugin state
  308. void reload() override
  309. {
  310. carla_debug("DssiPlugin::reload() - start");
  311. CARLA_ASSERT(kData->engine != nullptr);
  312. CARLA_ASSERT(fDescriptor != nullptr);
  313. CARLA_ASSERT(fDssiDescriptor != nullptr);
  314. CARLA_ASSERT(fHandle != nullptr);
  315. if (kData->engine == nullptr)
  316. return;
  317. if (fDescriptor == nullptr)
  318. return;
  319. if (fDssiDescriptor == nullptr)
  320. return;
  321. if (fHandle == nullptr)
  322. return;
  323. const ProcessMode processMode(kData->engine->getProccessMode());
  324. // Safely disable plugin for reload
  325. const ScopedDisabler sd(this);
  326. if (kData->active)
  327. deactivate();
  328. clearBuffers();
  329. const float sampleRate(static_cast<float>(kData->engine->getSampleRate()));
  330. const uint32_t portCount(static_cast<uint32_t>(fDescriptor->PortCount));
  331. uint32_t aIns, aOuts, mIns, params, j;
  332. aIns = aOuts = mIns = params = 0;
  333. bool forcedStereoIn, forcedStereoOut;
  334. forcedStereoIn = forcedStereoOut = false;
  335. bool needsCtrlIn, needsCtrlOut;
  336. needsCtrlIn = needsCtrlOut = false;
  337. if (portCount > 0)
  338. {
  339. CARLA_ASSERT(fDescriptor->PortDescriptors != nullptr);
  340. CARLA_ASSERT(fDescriptor->PortRangeHints != nullptr);
  341. CARLA_ASSERT(fDescriptor->PortNames != nullptr);
  342. for (uint32_t i=0; i < portCount; ++i)
  343. {
  344. const LADSPA_PortDescriptor portType = fDescriptor->PortDescriptors[i];
  345. if (LADSPA_IS_PORT_AUDIO(portType))
  346. {
  347. if (LADSPA_IS_PORT_INPUT(portType))
  348. aIns += 1;
  349. else if (LADSPA_IS_PORT_OUTPUT(portType))
  350. aOuts += 1;
  351. }
  352. else if (LADSPA_IS_PORT_CONTROL(portType))
  353. params += 1;
  354. }
  355. }
  356. if ((fOptions & PLUGIN_OPTION_FORCE_STEREO) != 0 && (aIns == 1 || aOuts == 1))
  357. {
  358. if (fHandle2 == nullptr)
  359. fHandle2 = fDescriptor->instantiate(fDescriptor, (unsigned long)sampleRate);
  360. if (aIns == 1)
  361. {
  362. aIns = 2;
  363. forcedStereoIn = true;
  364. }
  365. if (aOuts == 1)
  366. {
  367. aOuts = 2;
  368. forcedStereoOut = true;
  369. }
  370. }
  371. if (fDssiDescriptor->run_synth != nullptr || fDssiDescriptor->run_multiple_synths != nullptr)
  372. {
  373. mIns = 1;
  374. needsCtrlIn = true;
  375. }
  376. if (aIns > 0)
  377. {
  378. kData->audioIn.createNew(aIns);
  379. fAudioInBuffers = new float*[aIns];
  380. for (uint32_t i=0; i < aIns; ++i)
  381. fAudioInBuffers[i] = nullptr;
  382. }
  383. if (aOuts > 0)
  384. {
  385. kData->audioOut.createNew(aOuts);
  386. fAudioOutBuffers = new float*[aOuts];
  387. needsCtrlIn = true;
  388. for (uint32_t i=0; i < aOuts; ++i)
  389. fAudioOutBuffers[i] = nullptr;
  390. }
  391. if (params > 0)
  392. {
  393. kData->param.createNew(params);
  394. fParamBuffers = new float[params];
  395. for (uint32_t i=0; i < params; ++i)
  396. fParamBuffers[i] = 0.0f;
  397. }
  398. const uint portNameSize(kData->engine->maxPortNameSize());
  399. CarlaString portName;
  400. for (uint32_t i=0, iAudioIn=0, iAudioOut=0, iCtrl=0; i < portCount; ++i)
  401. {
  402. const LADSPA_PortDescriptor portType = fDescriptor->PortDescriptors[i];
  403. const LADSPA_PortRangeHint portRangeHints = fDescriptor->PortRangeHints[i];
  404. CARLA_ASSERT(fDescriptor->PortNames[i] != nullptr);
  405. if (LADSPA_IS_PORT_AUDIO(portType))
  406. {
  407. portName.clear();
  408. if (processMode == PROCESS_MODE_SINGLE_CLIENT)
  409. {
  410. portName = fName;
  411. portName += ":";
  412. }
  413. portName += fDescriptor->PortNames[i];
  414. portName.truncate(portNameSize);
  415. if (LADSPA_IS_PORT_INPUT(portType))
  416. {
  417. j = iAudioIn++;
  418. kData->audioIn.ports[j].port = (CarlaEngineAudioPort*)kData->client->addPort(kEnginePortTypeAudio, portName, true);
  419. kData->audioIn.ports[j].rindex = i;
  420. if (forcedStereoIn)
  421. {
  422. portName += "_2";
  423. kData->audioIn.ports[1].port = (CarlaEngineAudioPort*)kData->client->addPort(kEnginePortTypeAudio, portName, true);
  424. kData->audioIn.ports[1].rindex = i;
  425. }
  426. }
  427. else if (LADSPA_IS_PORT_OUTPUT(portType))
  428. {
  429. j = iAudioOut++;
  430. kData->audioOut.ports[j].port = (CarlaEngineAudioPort*)kData->client->addPort(kEnginePortTypeAudio, portName, false);
  431. kData->audioOut.ports[j].rindex = i;
  432. if (forcedStereoOut)
  433. {
  434. portName += "_2";
  435. kData->audioOut.ports[1].port = (CarlaEngineAudioPort*)kData->client->addPort(kEnginePortTypeAudio, portName, false);
  436. kData->audioOut.ports[1].rindex = i;
  437. }
  438. }
  439. else
  440. carla_stderr2("WARNING - Got a broken Port (Audio, but not input or output)");
  441. }
  442. else if (LADSPA_IS_PORT_CONTROL(portType))
  443. {
  444. j = iCtrl++;
  445. kData->param.data[j].index = j;
  446. kData->param.data[j].rindex = i;
  447. kData->param.data[j].hints = 0x0;
  448. kData->param.data[j].midiChannel = 0;
  449. kData->param.data[j].midiCC = -1;
  450. float min, max, def, step, stepSmall, stepLarge;
  451. // min value
  452. if (LADSPA_IS_HINT_BOUNDED_BELOW(portRangeHints.HintDescriptor))
  453. min = portRangeHints.LowerBound;
  454. else
  455. min = 0.0f;
  456. // max value
  457. if (LADSPA_IS_HINT_BOUNDED_ABOVE(portRangeHints.HintDescriptor))
  458. max = portRangeHints.UpperBound;
  459. else
  460. max = 1.0f;
  461. if (min > max)
  462. max = min;
  463. else if (max < min)
  464. min = max;
  465. if (max - min == 0.0f)
  466. {
  467. carla_stderr2("WARNING - Broken plugin parameter '%s': max - min == 0.0f", fDescriptor->PortNames[i]);
  468. max = min + 0.1f;
  469. }
  470. // default value
  471. def = get_default_ladspa_port_value(portRangeHints.HintDescriptor, min, max);
  472. if (def < min)
  473. def = min;
  474. else if (def > max)
  475. def = max;
  476. if (LADSPA_IS_HINT_SAMPLE_RATE(portRangeHints.HintDescriptor))
  477. {
  478. min *= sampleRate;
  479. max *= sampleRate;
  480. def *= sampleRate;
  481. kData->param.data[j].hints |= PARAMETER_USES_SAMPLERATE;
  482. }
  483. if (LADSPA_IS_HINT_TOGGLED(portRangeHints.HintDescriptor))
  484. {
  485. step = max - min;
  486. stepSmall = step;
  487. stepLarge = step;
  488. kData->param.data[j].hints |= PARAMETER_IS_BOOLEAN;
  489. }
  490. else if (LADSPA_IS_HINT_INTEGER(portRangeHints.HintDescriptor))
  491. {
  492. step = 1.0f;
  493. stepSmall = 1.0f;
  494. stepLarge = 10.0f;
  495. kData->param.data[j].hints |= PARAMETER_IS_INTEGER;
  496. }
  497. else
  498. {
  499. float range = max - min;
  500. step = range/100.0f;
  501. stepSmall = range/1000.0f;
  502. stepLarge = range/10.0f;
  503. }
  504. if (LADSPA_IS_PORT_INPUT(portType))
  505. {
  506. kData->param.data[j].type = PARAMETER_INPUT;
  507. kData->param.data[j].hints |= PARAMETER_IS_ENABLED;
  508. kData->param.data[j].hints |= PARAMETER_IS_AUTOMABLE;
  509. needsCtrlIn = true;
  510. // MIDI CC value
  511. if (fDssiDescriptor->get_midi_controller_for_port != nullptr)
  512. {
  513. int controller = fDssiDescriptor->get_midi_controller_for_port(fHandle, i);
  514. if (DSSI_CONTROLLER_IS_SET(controller) && DSSI_IS_CC(controller))
  515. {
  516. int16_t cc = DSSI_CC_NUMBER(controller);
  517. if (! MIDI_IS_CONTROL_BANK_SELECT(cc))
  518. kData->param.data[j].midiCC = cc;
  519. }
  520. }
  521. }
  522. else if (LADSPA_IS_PORT_OUTPUT(portType))
  523. {
  524. if (std::strcmp(fDescriptor->PortNames[i], "latency") == 0 || std::strcmp(fDescriptor->PortNames[i], "_latency") == 0)
  525. {
  526. min = 0.0f;
  527. max = sampleRate;
  528. def = 0.0f;
  529. step = 1.0f;
  530. stepSmall = 1.0f;
  531. stepLarge = 1.0f;
  532. kData->param.data[j].type = PARAMETER_LATENCY;
  533. kData->param.data[j].hints = 0;
  534. }
  535. else if (std::strcmp(fDescriptor->PortNames[i], "_sample-rate") == 0)
  536. {
  537. def = sampleRate;
  538. step = 1.0f;
  539. stepSmall = 1.0f;
  540. stepLarge = 1.0f;
  541. kData->param.data[j].type = PARAMETER_SAMPLE_RATE;
  542. kData->param.data[j].hints = 0;
  543. }
  544. else
  545. {
  546. kData->param.data[j].type = PARAMETER_OUTPUT;
  547. kData->param.data[j].hints |= PARAMETER_IS_ENABLED;
  548. kData->param.data[j].hints |= PARAMETER_IS_AUTOMABLE;
  549. needsCtrlOut = true;
  550. }
  551. }
  552. else
  553. {
  554. kData->param.data[j].type = PARAMETER_UNKNOWN;
  555. carla_stderr2("WARNING - Got a broken Port (Control, but not input or output)");
  556. }
  557. // extra parameter hints
  558. if (LADSPA_IS_HINT_LOGARITHMIC(portRangeHints.HintDescriptor))
  559. kData->param.data[j].hints |= PARAMETER_IS_LOGARITHMIC;
  560. kData->param.ranges[j].min = min;
  561. kData->param.ranges[j].max = max;
  562. kData->param.ranges[j].def = def;
  563. kData->param.ranges[j].step = step;
  564. kData->param.ranges[j].stepSmall = stepSmall;
  565. kData->param.ranges[j].stepLarge = stepLarge;
  566. // Start parameters in their default values
  567. fParamBuffers[j] = def;
  568. fDescriptor->connect_port(fHandle, i, &fParamBuffers[j]);
  569. if (fHandle2 != nullptr)
  570. fDescriptor->connect_port(fHandle2, i, &fParamBuffers[j]);
  571. }
  572. else
  573. {
  574. // Not Audio or Control
  575. carla_stderr2("ERROR - Got a broken Port (neither Audio or Control)");
  576. fDescriptor->connect_port(fHandle, i, nullptr);
  577. if (fHandle2 != nullptr)
  578. fDescriptor->connect_port(fHandle2, i, nullptr);
  579. }
  580. }
  581. if (needsCtrlIn)
  582. {
  583. portName.clear();
  584. if (processMode == PROCESS_MODE_SINGLE_CLIENT)
  585. {
  586. portName = fName;
  587. portName += ":";
  588. }
  589. portName += "events-in";
  590. portName.truncate(portNameSize);
  591. kData->event.portIn = (CarlaEngineEventPort*)kData->client->addPort(kEnginePortTypeEvent, portName, true);
  592. }
  593. if (needsCtrlOut)
  594. {
  595. portName.clear();
  596. if (processMode == PROCESS_MODE_SINGLE_CLIENT)
  597. {
  598. portName = fName;
  599. portName += ":";
  600. }
  601. portName += "events-out";
  602. portName.truncate(portNameSize);
  603. kData->event.portOut = (CarlaEngineEventPort*)kData->client->addPort(kEnginePortTypeEvent, portName, false);
  604. }
  605. if (forcedStereoIn || forcedStereoOut)
  606. fOptions |= PLUGIN_OPTION_FORCE_STEREO;
  607. else
  608. fOptions &= ~PLUGIN_OPTION_FORCE_STEREO;
  609. // plugin hints
  610. fHints = 0x0;
  611. if (LADSPA_IS_HARD_RT_CAPABLE(fDescriptor->Properties))
  612. fHints |= PLUGIN_IS_RTSAFE;
  613. if (fGuiFilename.isNotEmpty())
  614. fHints |= PLUGIN_HAS_GUI;
  615. if (mIns == 1 && aIns == 0 && aOuts > 0)
  616. fHints |= PLUGIN_IS_SYNTH;
  617. if (aOuts > 0 && (aIns == aOuts || aIns == 1))
  618. fHints |= PLUGIN_CAN_DRYWET;
  619. if (aOuts > 0)
  620. fHints |= PLUGIN_CAN_VOLUME;
  621. if (aOuts >= 2 && aOuts % 2 == 0)
  622. fHints |= PLUGIN_CAN_BALANCE;
  623. // extra plugin hints
  624. kData->extraHints = 0x0;
  625. if (mIns > 0)
  626. kData->extraHints |= PLUGIN_HINT_HAS_MIDI_IN;
  627. if (aIns <= 2 && aOuts <= 2 && (aIns == aOuts || aIns == 0 || aOuts == 0))
  628. kData->extraHints |= PLUGIN_HINT_CAN_RUN_RACK;
  629. // check latency
  630. if (fHints & PLUGIN_CAN_DRYWET)
  631. {
  632. for (uint32_t i=0; i < kData->param.count; ++i)
  633. {
  634. if (kData->param.data[i].type != PARAMETER_LATENCY)
  635. continue;
  636. // we need to pre-run the plugin so it can update its latency control-port
  637. float tmpIn[aIns][2];
  638. float tmpOut[aOuts][2];
  639. for (j=0; j < aIns; ++j)
  640. {
  641. tmpIn[j][0] = 0.0f;
  642. tmpIn[j][1] = 0.0f;
  643. fDescriptor->connect_port(fHandle, kData->audioIn.ports[j].rindex, tmpIn[j]);
  644. }
  645. for (j=0; j < aOuts; ++j)
  646. {
  647. tmpOut[j][0] = 0.0f;
  648. tmpOut[j][1] = 0.0f;
  649. fDescriptor->connect_port(fHandle, kData->audioOut.ports[j].rindex, tmpOut[j]);
  650. }
  651. if (fDescriptor->activate != nullptr)
  652. fDescriptor->activate(fHandle);
  653. fDescriptor->run(fHandle, 2);
  654. if (fDescriptor->deactivate != nullptr)
  655. fDescriptor->deactivate(fHandle);
  656. const uint32_t latency = (uint32_t)fParamBuffers[i];
  657. if (kData->latency != latency)
  658. {
  659. kData->latency = latency;
  660. kData->client->setLatency(latency);
  661. kData->recreateLatencyBuffers();
  662. }
  663. break;
  664. }
  665. }
  666. bufferSizeChanged(kData->engine->getBufferSize());
  667. reloadPrograms(true);
  668. if (kData->active)
  669. activate();
  670. carla_debug("DssiPlugin::reload() - end");
  671. }
  672. void reloadPrograms(const bool init) override
  673. {
  674. carla_debug("DssiPlugin::reloadPrograms(%s)", bool2str(init));
  675. uint32_t i, oldCount = kData->midiprog.count;
  676. const int32_t current = kData->midiprog.current;
  677. // Delete old programs
  678. kData->midiprog.clear();
  679. // Query new programs
  680. uint32_t count = 0;
  681. if (fDssiDescriptor->get_program != nullptr && fDssiDescriptor->select_program != nullptr)
  682. {
  683. while (fDssiDescriptor->get_program(fHandle, count))
  684. count++;
  685. }
  686. if (count > 0)
  687. {
  688. kData->midiprog.createNew(count);
  689. // Update data
  690. for (i=0; i < count; ++i)
  691. {
  692. const DSSI_Program_Descriptor* const pdesc(fDssiDescriptor->get_program(fHandle, i));
  693. CARLA_ASSERT(pdesc != nullptr);
  694. CARLA_ASSERT(pdesc->Name != nullptr);
  695. kData->midiprog.data[i].bank = static_cast<uint32_t>(pdesc->Bank);
  696. kData->midiprog.data[i].program = static_cast<uint32_t>(pdesc->Program);
  697. kData->midiprog.data[i].name = carla_strdup(pdesc->Name);
  698. }
  699. }
  700. #ifndef BUILD_BRIDGE
  701. // Update OSC Names
  702. if (kData->engine->isOscControlRegistered())
  703. {
  704. kData->engine->osc_send_control_set_midi_program_count(fId, count);
  705. for (i=0; i < count; ++i)
  706. 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);
  707. }
  708. #endif
  709. if (init)
  710. {
  711. if (count > 0)
  712. setMidiProgram(0, false, false, false);
  713. }
  714. else
  715. {
  716. // Check if current program is invalid
  717. bool programChanged = false;
  718. if (count == oldCount+1)
  719. {
  720. // one midi program added, probably created by user
  721. kData->midiprog.current = oldCount;
  722. programChanged = true;
  723. }
  724. else if (current < 0 && count > 0)
  725. {
  726. // programs exist now, but not before
  727. kData->midiprog.current = 0;
  728. programChanged = true;
  729. }
  730. else if (current >= 0 && count == 0)
  731. {
  732. // programs existed before, but not anymore
  733. kData->midiprog.current = -1;
  734. programChanged = true;
  735. }
  736. else if (current >= static_cast<int32_t>(count))
  737. {
  738. // current midi program > count
  739. kData->midiprog.current = 0;
  740. programChanged = true;
  741. }
  742. else
  743. {
  744. // no change
  745. kData->midiprog.current = current;
  746. }
  747. if (programChanged)
  748. setMidiProgram(kData->midiprog.current, true, true, true);
  749. kData->engine->callback(CALLBACK_RELOAD_PROGRAMS, fId, 0, 0, 0.0f, nullptr);
  750. }
  751. }
  752. // -------------------------------------------------------------------
  753. // Plugin processing
  754. void activate() override
  755. {
  756. CARLA_ASSERT(fDescriptor != nullptr);
  757. CARLA_ASSERT(fHandle != nullptr);
  758. if (fDescriptor->activate != nullptr)
  759. {
  760. fDescriptor->activate(fHandle);
  761. if (fHandle2 != nullptr)
  762. fDescriptor->activate(fHandle2);
  763. }
  764. }
  765. void deactivate() override
  766. {
  767. CARLA_ASSERT(fDescriptor != nullptr);
  768. CARLA_ASSERT(fHandle != nullptr);
  769. if (fDescriptor->deactivate != nullptr)
  770. {
  771. fDescriptor->deactivate(fHandle);
  772. if (fHandle2 != nullptr)
  773. fDescriptor->deactivate(fHandle2);
  774. }
  775. }
  776. void process(float** const inBuffer, float** const outBuffer, const uint32_t frames) override
  777. {
  778. uint32_t i, k;
  779. // --------------------------------------------------------------------------------------------------------
  780. // Check if active
  781. if (! kData->active)
  782. {
  783. // disable any output sound
  784. for (i=0; i < kData->audioOut.count; ++i)
  785. carla_zeroFloat(outBuffer[i], frames);
  786. return;
  787. }
  788. unsigned long midiEventCount = 0;
  789. // --------------------------------------------------------------------------------------------------------
  790. // Check if needs reset
  791. if (kData->needsReset)
  792. {
  793. if (fOptions & PLUGIN_OPTION_SEND_ALL_SOUND_OFF)
  794. {
  795. for (unsigned char j=0, l=MAX_MIDI_CHANNELS; j < MAX_MIDI_CHANNELS; ++j)
  796. {
  797. carla_zeroStruct<snd_seq_event_t>(fMidiEvents[j]);
  798. carla_zeroStruct<snd_seq_event_t>(fMidiEvents[j+l]);
  799. fMidiEvents[j].type = SND_SEQ_EVENT_CONTROLLER;
  800. fMidiEvents[j].data.control.channel = j;
  801. fMidiEvents[j].data.control.param = MIDI_CONTROL_ALL_NOTES_OFF;
  802. fMidiEvents[j+l].type = SND_SEQ_EVENT_CONTROLLER;
  803. fMidiEvents[j+l].data.control.channel = j;
  804. fMidiEvents[j+l].data.control.param = MIDI_CONTROL_ALL_SOUND_OFF;
  805. }
  806. midiEventCount = MAX_MIDI_CHANNELS*2;
  807. }
  808. else if (kData->ctrlChannel >= 0 && kData->ctrlChannel < MAX_MIDI_CHANNELS)
  809. {
  810. for (unsigned char j=0; j < MAX_MIDI_NOTE; ++j)
  811. {
  812. carla_zeroStruct<snd_seq_event_t>(fMidiEvents[j]);
  813. fMidiEvents[j].type = SND_SEQ_EVENT_NOTEOFF;
  814. fMidiEvents[j].data.note.channel = kData->ctrlChannel;
  815. fMidiEvents[j].data.note.note = j;
  816. }
  817. midiEventCount = MAX_MIDI_NOTE;
  818. }
  819. if (kData->latency > 0)
  820. {
  821. for (i=0; i < kData->audioIn.count; ++i)
  822. carla_zeroFloat(kData->latencyBuffers[i], kData->latency);
  823. }
  824. kData->needsReset = false;
  825. }
  826. // --------------------------------------------------------------------------------------------------------
  827. // Event Input and Processing
  828. if (kData->event.portIn != nullptr)
  829. {
  830. // ----------------------------------------------------------------------------------------------------
  831. // MIDI Input (External)
  832. if (kData->extNotes.mutex.tryLock())
  833. {
  834. while (midiEventCount < MAX_MIDI_EVENTS && ! kData->extNotes.data.isEmpty())
  835. {
  836. const ExternalMidiNote& note(kData->extNotes.data.getFirst(true));
  837. CARLA_ASSERT(note.channel >= 0 && note.channel < MAX_MIDI_CHANNELS);
  838. fMidiEvents[midiEventCount].type = (note.velo > 0) ? SND_SEQ_EVENT_NOTEON : SND_SEQ_EVENT_NOTEOFF;
  839. fMidiEvents[midiEventCount].data.note.channel = note.channel;
  840. fMidiEvents[midiEventCount].data.note.note = note.note;
  841. fMidiEvents[midiEventCount].data.note.velocity = note.velo;
  842. midiEventCount += 1;
  843. }
  844. kData->extNotes.mutex.unlock();
  845. } // End of MIDI Input (External)
  846. // ----------------------------------------------------------------------------------------------------
  847. // Event Input (System)
  848. bool allNotesOffSent = false;
  849. bool sampleAccurate = (fOptions & PLUGIN_OPTION_FIXED_BUFFER) == 0;
  850. uint32_t time, nEvents = kData->event.portIn->getEventCount();
  851. uint32_t startTime = 0;
  852. uint32_t timeOffset = 0;
  853. uint32_t nextBankId = 0;
  854. if (kData->midiprog.current >= 0 && kData->midiprog.count > 0)
  855. nextBankId = kData->midiprog.data[kData->midiprog.current].bank;
  856. for (i=0; i < nEvents; ++i)
  857. {
  858. const EngineEvent& event(kData->event.portIn->getEvent(i));
  859. time = event.time;
  860. if (time >= frames)
  861. continue;
  862. CARLA_ASSERT_INT2(time >= timeOffset, time, timeOffset);
  863. if (time > timeOffset && sampleAccurate)
  864. {
  865. if (processSingle(inBuffer, outBuffer, time - timeOffset, timeOffset, midiEventCount))
  866. {
  867. startTime = 0;
  868. timeOffset = time;
  869. midiEventCount = 0;
  870. if (kData->midiprog.current >= 0 && kData->midiprog.count > 0)
  871. nextBankId = kData->midiprog.data[kData->midiprog.current].bank;
  872. else
  873. nextBankId = 0;
  874. }
  875. else
  876. startTime += timeOffset;
  877. }
  878. // Control change
  879. switch (event.type)
  880. {
  881. case kEngineEventTypeNull:
  882. break;
  883. case kEngineEventTypeControl:
  884. {
  885. const EngineControlEvent& ctrlEvent = event.ctrl;
  886. switch (ctrlEvent.type)
  887. {
  888. case kEngineControlEventTypeNull:
  889. break;
  890. case kEngineControlEventTypeParameter:
  891. {
  892. #ifndef BUILD_BRIDGE
  893. // Control backend stuff
  894. if (event.channel == kData->ctrlChannel)
  895. {
  896. float value;
  897. if (MIDI_IS_CONTROL_BREATH_CONTROLLER(ctrlEvent.param) && (fHints & PLUGIN_CAN_DRYWET) > 0)
  898. {
  899. value = ctrlEvent.value;
  900. setDryWet(value, false, false);
  901. postponeRtEvent(kPluginPostRtEventParameterChange, PARAMETER_DRYWET, 0, value);
  902. }
  903. if (MIDI_IS_CONTROL_CHANNEL_VOLUME(ctrlEvent.param) && (fHints & PLUGIN_CAN_VOLUME) > 0)
  904. {
  905. value = ctrlEvent.value*127.0f/100.0f;
  906. setVolume(value, false, false);
  907. postponeRtEvent(kPluginPostRtEventParameterChange, PARAMETER_VOLUME, 0, value);
  908. }
  909. if (MIDI_IS_CONTROL_BALANCE(ctrlEvent.param) && (fHints & PLUGIN_CAN_BALANCE) > 0)
  910. {
  911. float left, right;
  912. value = ctrlEvent.value/0.5f - 1.0f;
  913. if (value < 0.0f)
  914. {
  915. left = -1.0f;
  916. right = (value*2.0f)+1.0f;
  917. }
  918. else if (value > 0.0f)
  919. {
  920. left = (value*2.0f)-1.0f;
  921. right = 1.0f;
  922. }
  923. else
  924. {
  925. left = -1.0f;
  926. right = 1.0f;
  927. }
  928. setBalanceLeft(left, false, false);
  929. setBalanceRight(right, false, false);
  930. postponeRtEvent(kPluginPostRtEventParameterChange, PARAMETER_BALANCE_LEFT, 0, left);
  931. postponeRtEvent(kPluginPostRtEventParameterChange, PARAMETER_BALANCE_RIGHT, 0, right);
  932. }
  933. }
  934. #endif
  935. // Control plugin parameters
  936. for (k=0; k < kData->param.count; ++k)
  937. {
  938. if (kData->param.data[k].midiChannel != event.channel)
  939. continue;
  940. if (kData->param.data[k].midiCC != ctrlEvent.param)
  941. continue;
  942. if (kData->param.data[k].type != PARAMETER_INPUT)
  943. continue;
  944. if ((kData->param.data[k].hints & PARAMETER_IS_AUTOMABLE) == 0)
  945. continue;
  946. float value;
  947. if (kData->param.data[k].hints & PARAMETER_IS_BOOLEAN)
  948. {
  949. value = (ctrlEvent.value < 0.5f) ? kData->param.ranges[k].min : kData->param.ranges[k].max;
  950. }
  951. else
  952. {
  953. value = kData->param.ranges[i].unnormalizeValue(ctrlEvent.value);
  954. if (kData->param.data[k].hints & PARAMETER_IS_INTEGER)
  955. value = std::rint(value);
  956. }
  957. setParameterValue(k, value, false, false, false);
  958. postponeRtEvent(kPluginPostRtEventParameterChange, static_cast<int32_t>(k), 0, value);
  959. }
  960. if ((fOptions & PLUGIN_OPTION_SEND_CONTROL_CHANGES) != 0 && ctrlEvent.param <= 0x5F)
  961. {
  962. if (midiEventCount >= MAX_MIDI_EVENTS)
  963. continue;
  964. carla_zeroStruct<snd_seq_event_t>(fMidiEvents[midiEventCount]);
  965. fMidiEvents[midiEventCount].time.tick = sampleAccurate ? startTime : time;
  966. fMidiEvents[midiEventCount].type = SND_SEQ_EVENT_CONTROLLER;
  967. fMidiEvents[midiEventCount].data.control.channel = event.channel;
  968. fMidiEvents[midiEventCount].data.control.param = ctrlEvent.param;
  969. fMidiEvents[midiEventCount].data.control.value = ctrlEvent.value*127.0f;
  970. midiEventCount += 1;
  971. }
  972. break;
  973. }
  974. case kEngineControlEventTypeMidiBank:
  975. if (event.channel == kData->ctrlChannel && (fOptions & PLUGIN_OPTION_MAP_PROGRAM_CHANGES) != 0)
  976. nextBankId = ctrlEvent.param;
  977. break;
  978. case kEngineControlEventTypeMidiProgram:
  979. if (event.channel == kData->ctrlChannel && (fOptions & PLUGIN_OPTION_MAP_PROGRAM_CHANGES) != 0)
  980. {
  981. const uint32_t nextProgramId = ctrlEvent.param;
  982. for (k=0; k < kData->midiprog.count; ++k)
  983. {
  984. if (kData->midiprog.data[k].bank == nextBankId && kData->midiprog.data[k].program == nextProgramId)
  985. {
  986. setMidiProgram(k, false, false, false);
  987. postponeRtEvent(kPluginPostRtEventMidiProgramChange, k, 0, 0.0f);
  988. break;
  989. }
  990. }
  991. }
  992. break;
  993. case kEngineControlEventTypeAllSoundOff:
  994. if (fOptions & PLUGIN_OPTION_SEND_ALL_SOUND_OFF)
  995. {
  996. if (midiEventCount >= MAX_MIDI_EVENTS)
  997. continue;
  998. carla_zeroStruct<snd_seq_event_t>(fMidiEvents[midiEventCount]);
  999. fMidiEvents[midiEventCount].time.tick = sampleAccurate ? startTime : time;
  1000. fMidiEvents[midiEventCount].type = SND_SEQ_EVENT_CONTROLLER;
  1001. fMidiEvents[midiEventCount].data.control.channel = event.channel;
  1002. fMidiEvents[midiEventCount].data.control.param = MIDI_CONTROL_ALL_SOUND_OFF;
  1003. midiEventCount += 1;
  1004. }
  1005. break;
  1006. case kEngineControlEventTypeAllNotesOff:
  1007. if (fOptions & PLUGIN_OPTION_SEND_ALL_SOUND_OFF)
  1008. {
  1009. if (event.channel == kData->ctrlChannel && ! allNotesOffSent)
  1010. {
  1011. allNotesOffSent = true;
  1012. sendMidiAllNotesOffToCallback();
  1013. }
  1014. if (midiEventCount >= MAX_MIDI_EVENTS)
  1015. continue;
  1016. carla_zeroStruct<snd_seq_event_t>(fMidiEvents[midiEventCount]);
  1017. fMidiEvents[midiEventCount].time.tick = sampleAccurate ? startTime : time;
  1018. fMidiEvents[midiEventCount].type = SND_SEQ_EVENT_CONTROLLER;
  1019. fMidiEvents[midiEventCount].data.control.channel = event.channel;
  1020. fMidiEvents[midiEventCount].data.control.param = MIDI_CONTROL_ALL_NOTES_OFF;
  1021. midiEventCount += 1;
  1022. }
  1023. break;
  1024. }
  1025. break;
  1026. }
  1027. case kEngineEventTypeMidi:
  1028. {
  1029. if (midiEventCount >= MAX_MIDI_EVENTS)
  1030. continue;
  1031. const EngineMidiEvent& midiEvent(event.midi);
  1032. uint8_t status = MIDI_GET_STATUS_FROM_DATA(midiEvent.data);
  1033. uint8_t channel = event.channel;
  1034. // Fix bad note-off (per DSSI spec)
  1035. if (MIDI_IS_STATUS_NOTE_ON(status) && midiEvent.data[2] == 0)
  1036. status -= 0x10;
  1037. carla_zeroStruct<snd_seq_event_t>(fMidiEvents[midiEventCount]);
  1038. fMidiEvents[midiEventCount].time.tick = sampleAccurate ? startTime : time;
  1039. if (MIDI_IS_STATUS_NOTE_OFF(status))
  1040. {
  1041. const uint8_t note = midiEvent.data[1];
  1042. fMidiEvents[midiEventCount].type = SND_SEQ_EVENT_NOTEOFF;
  1043. fMidiEvents[midiEventCount].data.note.channel = channel;
  1044. fMidiEvents[midiEventCount].data.note.note = note;
  1045. postponeRtEvent(kPluginPostRtEventNoteOff, channel, note, 0.0f);
  1046. }
  1047. else if (MIDI_IS_STATUS_NOTE_ON(status))
  1048. {
  1049. const uint8_t note = midiEvent.data[1];
  1050. const uint8_t velo = midiEvent.data[2];
  1051. fMidiEvents[midiEventCount].type = SND_SEQ_EVENT_NOTEON;
  1052. fMidiEvents[midiEventCount].data.note.channel = channel;
  1053. fMidiEvents[midiEventCount].data.note.note = note;
  1054. fMidiEvents[midiEventCount].data.note.velocity = velo;
  1055. postponeRtEvent(kPluginPostRtEventNoteOn, channel, note, velo);
  1056. }
  1057. else if (MIDI_IS_STATUS_POLYPHONIC_AFTERTOUCH(status) && (fOptions & PLUGIN_OPTION_SEND_NOTE_AFTERTOUCH) != 0)
  1058. {
  1059. const uint8_t note = midiEvent.data[1];
  1060. const uint8_t pressure = midiEvent.data[2];
  1061. fMidiEvents[midiEventCount].type = SND_SEQ_EVENT_KEYPRESS;
  1062. fMidiEvents[midiEventCount].data.note.channel = channel;
  1063. fMidiEvents[midiEventCount].data.note.note = note;
  1064. fMidiEvents[midiEventCount].data.note.velocity = pressure;
  1065. }
  1066. else if (MIDI_IS_STATUS_CONTROL_CHANGE(status) && (fOptions & PLUGIN_OPTION_SEND_CONTROL_CHANGES) != 0)
  1067. {
  1068. const uint8_t control = midiEvent.data[1];
  1069. const uint8_t value = midiEvent.data[2];
  1070. fMidiEvents[midiEventCount].type = SND_SEQ_EVENT_CONTROLLER;
  1071. fMidiEvents[midiEventCount].data.control.channel = channel;
  1072. fMidiEvents[midiEventCount].data.control.param = control;
  1073. fMidiEvents[midiEventCount].data.control.value = value;
  1074. }
  1075. else if (MIDI_IS_STATUS_AFTERTOUCH(status) && (fOptions & PLUGIN_OPTION_SEND_CHANNEL_PRESSURE) != 0)
  1076. {
  1077. const uint8_t pressure = midiEvent.data[1];
  1078. fMidiEvents[midiEventCount].type = SND_SEQ_EVENT_CHANPRESS;
  1079. fMidiEvents[midiEventCount].data.control.channel = channel;
  1080. fMidiEvents[midiEventCount].data.control.value = pressure;
  1081. }
  1082. else if (MIDI_IS_STATUS_PITCH_WHEEL_CONTROL(status) && (fOptions & PLUGIN_OPTION_SEND_PITCHBEND) != 0)
  1083. {
  1084. const uint8_t lsb = midiEvent.data[1];
  1085. const uint8_t msb = midiEvent.data[2];
  1086. fMidiEvents[midiEventCount].type = SND_SEQ_EVENT_PITCHBEND;
  1087. fMidiEvents[midiEventCount].data.control.channel = channel;
  1088. fMidiEvents[midiEventCount].data.control.value = ((msb << 7) | lsb) - 8192;
  1089. }
  1090. else
  1091. continue;
  1092. midiEventCount += 1;
  1093. break;
  1094. }
  1095. }
  1096. }
  1097. kData->postRtEvents.trySplice();
  1098. if (frames > timeOffset)
  1099. processSingle(inBuffer, outBuffer, frames - timeOffset, timeOffset, midiEventCount);
  1100. } // End of Event Input and Processing
  1101. // --------------------------------------------------------------------------------------------------------
  1102. // Plugin processing (no events)
  1103. else
  1104. {
  1105. processSingle(inBuffer, outBuffer, frames, 0, midiEventCount);
  1106. } // End of Plugin processing (no events)
  1107. CARLA_PROCESS_CONTINUE_CHECK;
  1108. // --------------------------------------------------------------------------------------------------------
  1109. // Control Output
  1110. if (kData->event.portOut != nullptr)
  1111. {
  1112. uint8_t channel;
  1113. uint16_t param;
  1114. float value;
  1115. for (k=0; k < kData->param.count; ++k)
  1116. {
  1117. if (kData->param.data[k].type != PARAMETER_OUTPUT)
  1118. continue;
  1119. kData->param.ranges[k].fixValue(fParamBuffers[k]);
  1120. if (kData->param.data[k].midiCC > 0)
  1121. {
  1122. channel = kData->param.data[k].midiChannel;
  1123. param = static_cast<uint16_t>(kData->param.data[k].midiCC);
  1124. value = kData->param.ranges[k].normalizeValue(fParamBuffers[k]);
  1125. kData->event.portOut->writeControlEvent(0, channel, kEngineControlEventTypeParameter, param, value);
  1126. }
  1127. }
  1128. } // End of Control Output
  1129. }
  1130. bool processSingle(float** const inBuffer, float** const outBuffer, const uint32_t frames, const uint32_t timeOffset, const unsigned long midiEventCount)
  1131. {
  1132. CARLA_ASSERT(frames > 0);
  1133. if (frames == 0)
  1134. return false;
  1135. if (kData->audioIn.count > 0)
  1136. {
  1137. CARLA_ASSERT(inBuffer != nullptr);
  1138. if (inBuffer == nullptr)
  1139. return false;
  1140. }
  1141. if (kData->audioOut.count > 0)
  1142. {
  1143. CARLA_ASSERT(outBuffer != nullptr);
  1144. if (outBuffer == nullptr)
  1145. return false;
  1146. }
  1147. uint32_t i, k;
  1148. // --------------------------------------------------------------------------------------------------------
  1149. // Try lock, silence otherwise
  1150. if (kData->engine->isOffline())
  1151. {
  1152. kData->singleMutex.lock();
  1153. }
  1154. else if (! kData->singleMutex.tryLock())
  1155. {
  1156. for (i=0; i < kData->audioOut.count; ++i)
  1157. {
  1158. for (k=0; k < frames; ++k)
  1159. outBuffer[i][k+timeOffset] = 0.0f;
  1160. }
  1161. return false;
  1162. }
  1163. // --------------------------------------------------------------------------------------------------------
  1164. // Reset audio buffers
  1165. for (i=0; i < kData->audioIn.count; ++i)
  1166. carla_copyFloat(fAudioInBuffers[i], inBuffer[i]+timeOffset, frames);
  1167. for (i=0; i < kData->audioOut.count; ++i)
  1168. carla_zeroFloat(fAudioOutBuffers[i], frames);
  1169. // --------------------------------------------------------------------------------------------------------
  1170. // Run plugin
  1171. if (fDssiDescriptor->run_synth != nullptr)
  1172. {
  1173. fDssiDescriptor->run_synth(fHandle, frames, fMidiEvents, midiEventCount);
  1174. if (fHandle2 != nullptr)
  1175. fDssiDescriptor->run_synth(fHandle2, frames, fMidiEvents, midiEventCount);
  1176. }
  1177. else if (fDssiDescriptor->run_multiple_synths != nullptr)
  1178. {
  1179. unsigned long instances = (fHandle2 != nullptr) ? 2 : 1;
  1180. LADSPA_Handle handlePtr[2] = { fHandle, fHandle2 };
  1181. snd_seq_event_t* midiEventsPtr[2] = { fMidiEvents, fMidiEvents };
  1182. unsigned long midiEventCountPtr[2] = { midiEventCount, midiEventCount };
  1183. fDssiDescriptor->run_multiple_synths(instances, handlePtr, frames, midiEventsPtr, midiEventCountPtr);
  1184. }
  1185. else
  1186. {
  1187. fDescriptor->run(fHandle, frames);
  1188. if (fHandle2 != nullptr)
  1189. fDescriptor->run(fHandle2, frames);
  1190. }
  1191. #ifndef BUILD_BRIDGE
  1192. // --------------------------------------------------------------------------------------------------------
  1193. // Post-processing (dry/wet, volume and balance)
  1194. {
  1195. const bool doDryWet = (fHints & PLUGIN_CAN_DRYWET) != 0 && kData->postProc.dryWet != 1.0f;
  1196. const bool doBalance = (fHints & PLUGIN_CAN_BALANCE) != 0 && (kData->postProc.balanceLeft != -1.0f || kData->postProc.balanceRight != 1.0f);
  1197. bool isPair;
  1198. float bufValue, oldBufLeft[doBalance ? frames : 1];
  1199. for (i=0; i < kData->audioOut.count; ++i)
  1200. {
  1201. // Dry/Wet
  1202. if (doDryWet)
  1203. {
  1204. for (k=0; k < frames; ++k)
  1205. {
  1206. // TODO
  1207. //if (k < kData->latency && kData->latency < frames)
  1208. // bufValue = (kData->audioIn.count == 1) ? kData->latencyBuffers[0][k] : kData->latencyBuffers[i][k];
  1209. //else
  1210. // bufValue = (kData->audioIn.count == 1) ? inBuffer[0][k-m_latency] : inBuffer[i][k-m_latency];
  1211. bufValue = fAudioInBuffers[(kData->audioIn.count == 1) ? 0 : i][k];
  1212. fAudioOutBuffers[i][k] = (fAudioOutBuffers[i][k] * kData->postProc.dryWet) + (bufValue * (1.0f - kData->postProc.dryWet));
  1213. }
  1214. }
  1215. // Balance
  1216. if (doBalance)
  1217. {
  1218. isPair = (i % 2 == 0);
  1219. if (isPair)
  1220. {
  1221. CARLA_ASSERT(i+1 < kData->audioOut.count);
  1222. carla_copyFloat(oldBufLeft, fAudioOutBuffers[i], frames);
  1223. }
  1224. float balRangeL = (kData->postProc.balanceLeft + 1.0f)/2.0f;
  1225. float balRangeR = (kData->postProc.balanceRight + 1.0f)/2.0f;
  1226. for (k=0; k < frames; ++k)
  1227. {
  1228. if (isPair)
  1229. {
  1230. // left
  1231. fAudioOutBuffers[i][k] = oldBufLeft[k] * (1.0f - balRangeL);
  1232. fAudioOutBuffers[i][k] += fAudioOutBuffers[i+1][k] * (1.0f - balRangeR);
  1233. }
  1234. else
  1235. {
  1236. // right
  1237. fAudioOutBuffers[i][k] = fAudioOutBuffers[i][k] * balRangeR;
  1238. fAudioOutBuffers[i][k] += oldBufLeft[k] * balRangeL;
  1239. }
  1240. }
  1241. }
  1242. // Volume (and buffer copy)
  1243. {
  1244. for (k=0; k < frames; ++k)
  1245. outBuffer[i][k+timeOffset] = fAudioOutBuffers[i][k] * kData->postProc.volume;
  1246. }
  1247. }
  1248. #if 0
  1249. // Latency, save values for next callback, TODO
  1250. if (kData->latency > 0 && kData->latency < frames)
  1251. {
  1252. for (i=0; i < kData->audioIn.count; ++i)
  1253. carla_copyFloat(kData->latencyBuffers[i], inBuffer[i] + (frames - kData->latency), kData->latency);
  1254. }
  1255. #endif
  1256. } // End of Post-processing
  1257. #else
  1258. for (i=0; i < kData->audioOut.count; ++i)
  1259. {
  1260. for (k=0; k < frames; ++k)
  1261. outBuffer[i][k+timeOffset] = fAudioOutBuffers[i][k];
  1262. }
  1263. #endif
  1264. // --------------------------------------------------------------------------------------------------------
  1265. kData->singleMutex.unlock();
  1266. return true;
  1267. }
  1268. void bufferSizeChanged(const uint32_t newBufferSize) override
  1269. {
  1270. CARLA_ASSERT_INT(newBufferSize > 0, newBufferSize);
  1271. carla_debug("DssiPlugin::bufferSizeChanged(%i) - start", newBufferSize);
  1272. for (uint32_t i=0; i < kData->audioIn.count; ++i)
  1273. {
  1274. if (fAudioInBuffers[i] != nullptr)
  1275. delete[] fAudioInBuffers[i];
  1276. fAudioInBuffers[i] = new float[newBufferSize];
  1277. }
  1278. for (uint32_t i=0; i < kData->audioOut.count; ++i)
  1279. {
  1280. if (fAudioOutBuffers[i] != nullptr)
  1281. delete[] fAudioOutBuffers[i];
  1282. fAudioOutBuffers[i] = new float[newBufferSize];
  1283. }
  1284. if (fHandle2 == nullptr)
  1285. {
  1286. for (uint32_t i=0; i < kData->audioIn.count; ++i)
  1287. {
  1288. CARLA_ASSERT(fAudioInBuffers[i] != nullptr);
  1289. fDescriptor->connect_port(fHandle, kData->audioIn.ports[i].rindex, fAudioInBuffers[i]);
  1290. }
  1291. for (uint32_t i=0; i < kData->audioOut.count; ++i)
  1292. {
  1293. CARLA_ASSERT(fAudioOutBuffers[i] != nullptr);
  1294. fDescriptor->connect_port(fHandle, kData->audioOut.ports[i].rindex, fAudioOutBuffers[i]);
  1295. }
  1296. }
  1297. else
  1298. {
  1299. if (kData->audioIn.count > 0)
  1300. {
  1301. CARLA_ASSERT(kData->audioIn.count == 2);
  1302. CARLA_ASSERT(fAudioInBuffers[0] != nullptr);
  1303. CARLA_ASSERT(fAudioInBuffers[1] != nullptr);
  1304. fDescriptor->connect_port(fHandle, kData->audioIn.ports[0].rindex, fAudioInBuffers[0]);
  1305. fDescriptor->connect_port(fHandle2, kData->audioIn.ports[1].rindex, fAudioInBuffers[1]);
  1306. }
  1307. if (kData->audioOut.count > 0)
  1308. {
  1309. CARLA_ASSERT(kData->audioOut.count == 2);
  1310. CARLA_ASSERT(fAudioOutBuffers[0] != nullptr);
  1311. CARLA_ASSERT(fAudioOutBuffers[1] != nullptr);
  1312. fDescriptor->connect_port(fHandle, kData->audioOut.ports[0].rindex, fAudioOutBuffers[0]);
  1313. fDescriptor->connect_port(fHandle2, kData->audioOut.ports[1].rindex, fAudioOutBuffers[1]);
  1314. }
  1315. }
  1316. carla_debug("DssiPlugin::bufferSizeChanged(%i) - start", newBufferSize);
  1317. }
  1318. void sampleRateChanged(const double newSampleRate) override
  1319. {
  1320. CARLA_ASSERT_INT(newSampleRate > 0.0, newSampleRate);
  1321. carla_debug("DssiPlugin::sampleRateChanged(%g) - start", newSampleRate);
  1322. // TODO
  1323. (void)newSampleRate;
  1324. carla_debug("DssiPlugin::sampleRateChanged(%g) - end", newSampleRate);
  1325. }
  1326. // -------------------------------------------------------------------
  1327. // Plugin buffers
  1328. void clearBuffers() override
  1329. {
  1330. carla_debug("DssiPlugin::clearBuffers() - start");
  1331. if (fAudioInBuffers != nullptr)
  1332. {
  1333. for (uint32_t i=0; i < kData->audioIn.count; ++i)
  1334. {
  1335. if (fAudioInBuffers[i] != nullptr)
  1336. {
  1337. delete[] fAudioInBuffers[i];
  1338. fAudioInBuffers[i] = nullptr;
  1339. }
  1340. }
  1341. delete[] fAudioInBuffers;
  1342. fAudioInBuffers = nullptr;
  1343. }
  1344. if (fAudioOutBuffers != nullptr)
  1345. {
  1346. for (uint32_t i=0; i < kData->audioOut.count; ++i)
  1347. {
  1348. if (fAudioOutBuffers[i] != nullptr)
  1349. {
  1350. delete[] fAudioOutBuffers[i];
  1351. fAudioOutBuffers[i] = nullptr;
  1352. }
  1353. }
  1354. delete[] fAudioOutBuffers;
  1355. fAudioOutBuffers = nullptr;
  1356. }
  1357. if (fParamBuffers != nullptr)
  1358. {
  1359. delete[] fParamBuffers;
  1360. fParamBuffers = nullptr;
  1361. }
  1362. CarlaPlugin::clearBuffers();
  1363. carla_debug("DssiPlugin::clearBuffers() - end");
  1364. }
  1365. // -------------------------------------------------------------------
  1366. // Post-poned UI Stuff
  1367. void uiParameterChange(const uint32_t index, const float value) override
  1368. {
  1369. CARLA_ASSERT(index < kData->param.count);
  1370. if (index >= kData->param.count)
  1371. return;
  1372. if (kData->osc.data.target == nullptr)
  1373. return;
  1374. osc_send_control(&kData->osc.data, kData->param.data[index].rindex, value);
  1375. }
  1376. void uiMidiProgramChange(const uint32_t index) override
  1377. {
  1378. CARLA_ASSERT(index < kData->midiprog.count);
  1379. if (index >= kData->midiprog.count)
  1380. return;
  1381. if (kData->osc.data.target == nullptr)
  1382. return;
  1383. osc_send_program(&kData->osc.data, kData->midiprog.data[index].bank, kData->midiprog.data[index].program);
  1384. }
  1385. void uiNoteOn(const uint8_t channel, const uint8_t note, const uint8_t velo) override
  1386. {
  1387. CARLA_ASSERT(channel < MAX_MIDI_CHANNELS);
  1388. CARLA_ASSERT(note < MAX_MIDI_NOTE);
  1389. CARLA_ASSERT(velo > 0 && velo < MAX_MIDI_VALUE);
  1390. if (channel >= MAX_MIDI_CHANNELS)
  1391. return;
  1392. if (note >= MAX_MIDI_NOTE)
  1393. return;
  1394. if (velo >= MAX_MIDI_VALUE)
  1395. return;
  1396. if (kData->osc.data.target == nullptr)
  1397. return;
  1398. #if 0
  1399. uint8_t midiData[4] = { 0 };
  1400. midiData[1] = MIDI_STATUS_NOTE_ON + channel;
  1401. midiData[2] = note;
  1402. midiData[3] = velo;
  1403. osc_send_midi(&kData->osc.data, midiData);
  1404. #endif
  1405. }
  1406. void uiNoteOff(const uint8_t channel, const uint8_t note) override
  1407. {
  1408. CARLA_ASSERT(channel < MAX_MIDI_CHANNELS);
  1409. CARLA_ASSERT(note < MAX_MIDI_NOTE);
  1410. if (channel >= MAX_MIDI_CHANNELS)
  1411. return;
  1412. if (note >= MAX_MIDI_NOTE)
  1413. return;
  1414. if (kData->osc.data.target == nullptr)
  1415. return;
  1416. #if 0
  1417. uint8_t midiData[4] = { 0 };
  1418. midiData[1] = MIDI_STATUS_NOTE_OFF + channel;
  1419. midiData[2] = note;
  1420. osc_send_midi(&kData->osc.data, midiData);
  1421. #endif
  1422. }
  1423. // -------------------------------------------------------------------
  1424. const void* getExtraStuff() override
  1425. {
  1426. return fGuiFilename.isNotEmpty() ? (const char*)fGuiFilename : nullptr;
  1427. }
  1428. bool init(const char* const filename, const char* const name, const char* const label, const char* const guiFilename)
  1429. {
  1430. CARLA_ASSERT(kData->engine != nullptr);
  1431. CARLA_ASSERT(kData->client == nullptr);
  1432. CARLA_ASSERT(filename != nullptr);
  1433. CARLA_ASSERT(label != nullptr);
  1434. // ---------------------------------------------------------------
  1435. // first checks
  1436. if (kData->engine == nullptr)
  1437. {
  1438. return false;
  1439. }
  1440. if (kData->client != nullptr)
  1441. {
  1442. kData->engine->setLastError("Plugin client is already registered");
  1443. return false;
  1444. }
  1445. if (filename == nullptr)
  1446. {
  1447. kData->engine->setLastError("null filename");
  1448. return false;
  1449. }
  1450. if (label == nullptr)
  1451. {
  1452. kData->engine->setLastError("null label");
  1453. return false;
  1454. }
  1455. // ---------------------------------------------------------------
  1456. // open DLL
  1457. if (! kData->libOpen(filename))
  1458. {
  1459. kData->engine->setLastError(kData->libError(filename));
  1460. return false;
  1461. }
  1462. // ---------------------------------------------------------------
  1463. // get DLL main entry
  1464. const DSSI_Descriptor_Function descFn = (DSSI_Descriptor_Function)kData->libSymbol("dssi_descriptor");
  1465. if (descFn == nullptr)
  1466. {
  1467. kData->engine->setLastError("Could not find the DSSI Descriptor in the plugin library");
  1468. return false;
  1469. }
  1470. // ---------------------------------------------------------------
  1471. // get descriptor that matches label
  1472. unsigned long i = 0;
  1473. while ((fDssiDescriptor = descFn(i++)) != nullptr)
  1474. {
  1475. fDescriptor = fDssiDescriptor->LADSPA_Plugin;
  1476. if (fDescriptor != nullptr && fDescriptor->Label != nullptr && std::strcmp(fDescriptor->Label, label) == 0)
  1477. break;
  1478. }
  1479. if (fDescriptor == nullptr || fDssiDescriptor == nullptr)
  1480. {
  1481. kData->engine->setLastError("Could not find the requested plugin label in the plugin library");
  1482. return false;
  1483. }
  1484. // ---------------------------------------------------------------
  1485. // get info
  1486. if (name != nullptr)
  1487. fName = kData->engine->getUniquePluginName(name);
  1488. else if (fDescriptor->Name != nullptr)
  1489. fName = kData->engine->getUniquePluginName(fDescriptor->Name);
  1490. else
  1491. fName = kData->engine->getUniquePluginName(fDescriptor->Label);
  1492. fFilename = filename;
  1493. // ---------------------------------------------------------------
  1494. // register client
  1495. kData->client = kData->engine->addClient(this);
  1496. if (kData->client == nullptr || ! kData->client->isOk())
  1497. {
  1498. kData->engine->setLastError("Failed to register plugin client");
  1499. return false;
  1500. }
  1501. // ---------------------------------------------------------------
  1502. // initialize plugin
  1503. fHandle = fDescriptor->instantiate(fDescriptor, (unsigned long)kData->engine->getSampleRate());
  1504. if (fHandle == nullptr)
  1505. {
  1506. kData->engine->setLastError("Plugin failed to initialize");
  1507. return false;
  1508. }
  1509. // ---------------------------------------------------------------
  1510. // gui stuff
  1511. if (guiFilename != nullptr)
  1512. {
  1513. fGuiFilename = guiFilename;
  1514. kData->osc.thread.setOscData(guiFilename, fDescriptor->Label);
  1515. }
  1516. // ---------------------------------------------------------------
  1517. // load plugin settings
  1518. {
  1519. #ifdef __USE_GNU
  1520. const bool isDssiVst = fFilename.contains("dssi-vst", true);
  1521. #else
  1522. const bool isDssiVst = fFilename.contains("dssi-vst");
  1523. #endif
  1524. // set default options
  1525. fOptions = 0x0;
  1526. fOptions |= PLUGIN_OPTION_MAP_PROGRAM_CHANGES;
  1527. if (kData->engine->getOptions().forceStereo)
  1528. fOptions |= PLUGIN_OPTION_FORCE_STEREO;
  1529. if (isDssiVst)
  1530. {
  1531. fOptions |= PLUGIN_OPTION_FIXED_BUFFER;
  1532. if (kData->engine->getOptions().useDssiVstChunks && fDssiDescriptor->get_custom_data != nullptr && fDssiDescriptor->set_custom_data != nullptr)
  1533. fOptions |= PLUGIN_OPTION_USE_CHUNKS;
  1534. }
  1535. if (fDssiDescriptor->run_synth != nullptr || fDssiDescriptor->run_multiple_synths != nullptr)
  1536. {
  1537. fOptions |= PLUGIN_OPTION_SEND_CHANNEL_PRESSURE;
  1538. fOptions |= PLUGIN_OPTION_SEND_NOTE_AFTERTOUCH;
  1539. fOptions |= PLUGIN_OPTION_SEND_PITCHBEND;
  1540. fOptions |= PLUGIN_OPTION_SEND_ALL_SOUND_OFF;
  1541. if (fDssiDescriptor->run_synth == nullptr)
  1542. carla_stderr2("Plugin can ONLY use run_multiple_synths!");
  1543. }
  1544. // load settings
  1545. kData->idStr = "DSSI/";
  1546. kData->idStr += std::strrchr(filename, OS_SEP)+1;
  1547. kData->idStr += "/";
  1548. kData->idStr += label;
  1549. fOptions = kData->loadSettings(fOptions, availableOptions());
  1550. // ignore settings, we need this anyway
  1551. if (isDssiVst)
  1552. fOptions |= PLUGIN_OPTION_FIXED_BUFFER;
  1553. }
  1554. return true;
  1555. }
  1556. private:
  1557. LADSPA_Handle fHandle;
  1558. LADSPA_Handle fHandle2;
  1559. const LADSPA_Descriptor* fDescriptor;
  1560. const DSSI_Descriptor* fDssiDescriptor;
  1561. CarlaString fGuiFilename;
  1562. float** fAudioInBuffers;
  1563. float** fAudioOutBuffers;
  1564. float* fParamBuffers;
  1565. snd_seq_event_t fMidiEvents[MAX_MIDI_EVENTS];
  1566. CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(DssiPlugin)
  1567. };
  1568. CARLA_BACKEND_END_NAMESPACE
  1569. #else // WANT_DSSI
  1570. # warning Building without DSSI support
  1571. #endif
  1572. CARLA_BACKEND_START_NAMESPACE
  1573. CarlaPlugin* CarlaPlugin::newDSSI(const Initializer& init, const char* const guiFilename)
  1574. {
  1575. carla_debug("CarlaPlugin::newDSSI({%p, \"%s\", \"%s\", \"%s\"}, \"%s\")", init.engine, init.filename, init.name, init.label, guiFilename);
  1576. #ifdef WANT_DSSI
  1577. DssiPlugin* const plugin(new DssiPlugin(init.engine, init.id));
  1578. if (! plugin->init(init.filename, init.name, init.label, guiFilename))
  1579. {
  1580. delete plugin;
  1581. return nullptr;
  1582. }
  1583. plugin->reload();
  1584. if (init.engine->getProccessMode() == PROCESS_MODE_CONTINUOUS_RACK && ! CarlaPluginProtectedData::canRunInRack(plugin))
  1585. {
  1586. init.engine->setLastError("Carla's rack mode can only work with Mono or Stereo DSSI plugins, sorry!");
  1587. delete plugin;
  1588. return nullptr;
  1589. }
  1590. return plugin;
  1591. #else
  1592. init.engine->setLastError("DSSI support not available");
  1593. return nullptr;
  1594. #endif
  1595. }
  1596. CARLA_BACKEND_END_NAMESPACE