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.

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