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.

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