Collection of tools useful for audio production
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.

1472 lines
48KB

  1. /*
  2. * Carla Backend
  3. * Copyright (C) 2011-2012 Filipe Coelho <falktx@gmail.com>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * 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 COPYING file
  16. */
  17. #include "carla_plugin.h"
  18. #include "carla_dssi.h"
  19. CARLA_BACKEND_START_NAMESPACE
  20. #if 0
  21. } /* adjust editor indent */
  22. #endif
  23. /*!
  24. * @defgroup CarlaBackendDssiPlugin Carla Backend DSSI Plugin
  25. *
  26. * The Carla Backend DSSI Plugin.\n
  27. * http://dssi.sourceforge.net/
  28. * @{
  29. */
  30. class DssiPlugin : public CarlaPlugin
  31. {
  32. public:
  33. DssiPlugin(CarlaEngine* const engine, unsigned short id) : CarlaPlugin(engine, id)
  34. {
  35. qDebug("DssiPlugin::DssiPlugin()");
  36. m_type = PLUGIN_DSSI;
  37. handle = h2 = nullptr;
  38. descriptor = nullptr;
  39. ldescriptor = nullptr;
  40. param_buffers = nullptr;
  41. memset(midiEvents, 0, sizeof(snd_seq_event_t)*MAX_MIDI_EVENTS);
  42. }
  43. ~DssiPlugin()
  44. {
  45. qDebug("DssiPlugin::~DssiPlugin()");
  46. #ifndef BUILD_BRIDGE
  47. // close UI
  48. if (m_hints & PLUGIN_HAS_GUI)
  49. {
  50. if (osc.data.target)
  51. {
  52. osc_send_hide(&osc.data);
  53. osc_send_quit(&osc.data);
  54. }
  55. if (osc.thread)
  56. {
  57. // Wait a bit first, try safe quit, then force kill
  58. if (osc.thread->isRunning())
  59. {
  60. if (! osc.thread->wait(2000))
  61. osc.thread->quit();
  62. if (osc.thread->isRunning() && ! osc.thread->wait(1000))
  63. {
  64. qWarning("Failed to properly stop DSSI GUI thread");
  65. osc.thread->terminate();
  66. }
  67. }
  68. delete osc.thread;
  69. }
  70. osc_clear_data(&osc.data);
  71. }
  72. #endif
  73. if (ldescriptor)
  74. {
  75. if (ldescriptor->deactivate && m_activeBefore)
  76. {
  77. if (handle)
  78. ldescriptor->deactivate(handle);
  79. if (h2)
  80. ldescriptor->deactivate(h2);
  81. }
  82. if (ldescriptor->cleanup)
  83. {
  84. if (handle)
  85. ldescriptor->cleanup(handle);
  86. if (h2)
  87. ldescriptor->cleanup(h2);
  88. }
  89. }
  90. }
  91. // -------------------------------------------------------------------
  92. // Information (base)
  93. PluginCategory category()
  94. {
  95. if (m_hints & PLUGIN_IS_SYNTH)
  96. return PLUGIN_CATEGORY_SYNTH;
  97. return getPluginCategoryFromName(m_name);
  98. }
  99. long uniqueId()
  100. {
  101. return ldescriptor->UniqueID;
  102. }
  103. // -------------------------------------------------------------------
  104. // Information (current data)
  105. int32_t chunkData(void** const dataPtr)
  106. {
  107. assert(dataPtr);
  108. unsigned long dataSize = 0;
  109. if (descriptor->get_custom_data(handle, dataPtr, &dataSize))
  110. return dataSize;
  111. return 0;
  112. }
  113. // -------------------------------------------------------------------
  114. // Information (per-plugin data)
  115. double getParameterValue(uint32_t parameterId)
  116. {
  117. assert(parameterId < param.count);
  118. return param_buffers[parameterId];
  119. }
  120. void getLabel(char* const strBuf)
  121. {
  122. if (ldescriptor->Label)
  123. strncpy(strBuf, ldescriptor->Label, STR_MAX);
  124. else
  125. CarlaPlugin::getLabel(strBuf);
  126. }
  127. void getMaker(char* const strBuf)
  128. {
  129. if (ldescriptor->Maker)
  130. strncpy(strBuf, ldescriptor->Maker, STR_MAX);
  131. else
  132. CarlaPlugin::getMaker(strBuf);
  133. }
  134. void getCopyright(char* const strBuf)
  135. {
  136. if (ldescriptor->Copyright)
  137. strncpy(strBuf, ldescriptor->Copyright, STR_MAX);
  138. else
  139. CarlaPlugin::getCopyright(strBuf);
  140. }
  141. void getRealName(char* const strBuf)
  142. {
  143. if (ldescriptor->Name)
  144. strncpy(strBuf, ldescriptor->Name, STR_MAX);
  145. else
  146. CarlaPlugin::getRealName(strBuf);
  147. }
  148. void getParameterName(uint32_t parameterId, char* const strBuf)
  149. {
  150. assert(parameterId < param.count);
  151. int32_t rindex = param.data[parameterId].rindex;
  152. strncpy(strBuf, ldescriptor->PortNames[rindex], STR_MAX);
  153. }
  154. void getGuiInfo(GuiType* type, bool* resizable)
  155. {
  156. *type = (m_hints & PLUGIN_HAS_GUI) ? GUI_EXTERNAL_OSC : GUI_NONE;
  157. *resizable = false;
  158. }
  159. // -------------------------------------------------------------------
  160. // Set data (plugin-specific stuff)
  161. void setParameterValue(uint32_t parameterId, double value, bool sendGui, bool sendOsc, bool sendCallback)
  162. {
  163. assert(parameterId < param.count);
  164. param_buffers[parameterId] = fixParameterValue(value, param.ranges[parameterId]);
  165. #ifndef BUILD_BRIDGE
  166. if (sendGui)
  167. osc_send_control(&osc.data, param.data[parameterId].rindex, value);
  168. #endif
  169. CarlaPlugin::setParameterValue(parameterId, value, sendGui, sendOsc, sendCallback);
  170. }
  171. void setCustomData(CustomDataType type, const char* const key, const char* const value, bool sendGui)
  172. {
  173. assert(key);
  174. assert(value);
  175. descriptor->configure(handle, key, value);
  176. #ifndef BUILD_BRIDGE
  177. if (sendGui)
  178. osc_send_configure(&osc.data, key, value);
  179. #endif
  180. if (strcmp(key, "reloadprograms") == 0 || strcmp(key, "load") == 0 || strncmp(key, "patches", 7) == 0)
  181. {
  182. const CarlaPluginScopedDisabler m(this);
  183. reloadPrograms(false);
  184. }
  185. CarlaPlugin::setCustomData(type, key, value, sendGui);
  186. }
  187. void setChunkData(const char* const stringData)
  188. {
  189. assert(stringData);
  190. static QByteArray chunk;
  191. chunk = QByteArray::fromBase64(stringData);
  192. if (x_engine->isOffline())
  193. {
  194. engineProcessLock();
  195. descriptor->set_custom_data(handle, chunk.data(), chunk.size());
  196. engineProcessUnlock();
  197. }
  198. else
  199. {
  200. const CarlaPluginScopedDisabler m(this);
  201. descriptor->set_custom_data(handle, chunk.data(), chunk.size());
  202. }
  203. }
  204. void setMidiProgram(int32_t index, bool sendGui, bool sendOsc, bool sendCallback, bool block)
  205. {
  206. assert(index < (int32_t)midiprog.count);
  207. if (index >= 0)
  208. {
  209. if (x_engine->isOffline())
  210. {
  211. if (block) engineProcessLock();
  212. descriptor->select_program(handle, midiprog.data[index].bank, midiprog.data[index].program);
  213. if (block) engineProcessUnlock();
  214. }
  215. else
  216. {
  217. const CarlaPluginScopedDisabler m(this, block);
  218. descriptor->select_program(handle, midiprog.data[index].bank, midiprog.data[index].program);
  219. }
  220. #ifndef BUILD_BRIDGE
  221. if (sendGui)
  222. osc_send_program(&osc.data, midiprog.data[index].bank, midiprog.data[index].program);
  223. #endif
  224. }
  225. CarlaPlugin::setMidiProgram(index, sendGui, sendOsc, sendCallback, block);
  226. }
  227. // -------------------------------------------------------------------
  228. // Set gui stuff
  229. #ifndef BUILD_BRIDGE
  230. void showGui(bool yesNo)
  231. {
  232. if (yesNo)
  233. {
  234. osc.thread->start();
  235. }
  236. else
  237. {
  238. osc_send_hide(&osc.data);
  239. osc_send_quit(&osc.data);
  240. osc_clear_data(&osc.data);
  241. osc.thread->quit(); // FIXME - stop thread?
  242. }
  243. }
  244. #endif
  245. // -------------------------------------------------------------------
  246. // Plugin state
  247. void reload()
  248. {
  249. qDebug("DssiPlugin::reload() - start");
  250. // Safely disable plugin for reload
  251. const CarlaPluginScopedDisabler m(this);
  252. if (x_client->isActive())
  253. x_client->deactivate();
  254. // Remove client ports
  255. removeClientPorts();
  256. // Delete old data
  257. deleteBuffers();
  258. uint32_t ains, aouts, mins, params, j;
  259. ains = aouts = mins = params = 0;
  260. const double sampleRate = x_engine->getSampleRate();
  261. const unsigned long PortCount = ldescriptor->PortCount;
  262. for (unsigned long i=0; i<PortCount; i++)
  263. {
  264. const LADSPA_PortDescriptor PortType = ldescriptor->PortDescriptors[i];
  265. if (LADSPA_IS_PORT_AUDIO(PortType))
  266. {
  267. if (LADSPA_IS_PORT_INPUT(PortType))
  268. ains += 1;
  269. else if (LADSPA_IS_PORT_OUTPUT(PortType))
  270. aouts += 1;
  271. }
  272. else if (LADSPA_IS_PORT_CONTROL(PortType))
  273. params += 1;
  274. }
  275. if (carlaOptions.process_mode == PROCESS_MODE_CONTINUOUS_RACK && (ains == 1 || aouts == 1) && ! h2)
  276. h2 = ldescriptor->instantiate(ldescriptor, sampleRate);
  277. if (descriptor->run_synth || descriptor->run_multiple_synths)
  278. mins = 1;
  279. if (ains > 0)
  280. {
  281. ain.ports = new CarlaEngineAudioPort*[ains];
  282. ain.rindexes = new uint32_t[ains];
  283. }
  284. if (aouts > 0)
  285. {
  286. aout.ports = new CarlaEngineAudioPort*[aouts];
  287. aout.rindexes = new uint32_t[aouts];
  288. }
  289. if (params > 0)
  290. {
  291. param.data = new ParameterData[params];
  292. param.ranges = new ParameterRanges[params];
  293. param_buffers = new float[params];
  294. }
  295. const int portNameSize = CarlaEngine::maxPortNameSize() - 1;
  296. char portName[portNameSize];
  297. bool needsCin = false;
  298. bool needsCout = false;
  299. for (unsigned long i=0; i<PortCount; i++)
  300. {
  301. const LADSPA_PortDescriptor PortType = ldescriptor->PortDescriptors[i];
  302. const LADSPA_PortRangeHint PortHint = ldescriptor->PortRangeHints[i];
  303. if (LADSPA_IS_PORT_AUDIO(PortType))
  304. {
  305. #ifndef BUILD_BRIDGE
  306. if (carlaOptions.process_mode != PROCESS_MODE_MULTIPLE_CLIENTS)
  307. {
  308. strcpy(portName, m_name);
  309. strcat(portName, ":");
  310. strncat(portName, ldescriptor->PortNames[i], portNameSize/2);
  311. }
  312. else
  313. #endif
  314. strncpy(portName, ldescriptor->PortNames[i], portNameSize);
  315. if (LADSPA_IS_PORT_INPUT(PortType))
  316. {
  317. j = ain.count++;
  318. ain.ports[j] = (CarlaEngineAudioPort*)x_client->addPort(CarlaEnginePortTypeAudio, portName, true);
  319. ain.rindexes[j] = i;
  320. }
  321. else if (LADSPA_IS_PORT_OUTPUT(PortType))
  322. {
  323. j = aout.count++;
  324. aout.ports[j] = (CarlaEngineAudioPort*)x_client->addPort(CarlaEnginePortTypeAudio, portName, false);
  325. aout.rindexes[j] = i;
  326. needsCin = true;
  327. }
  328. else
  329. qWarning("WARNING - Got a broken Port (Audio, but not input or output)");
  330. }
  331. else if (LADSPA_IS_PORT_CONTROL(PortType))
  332. {
  333. j = param.count++;
  334. param.data[j].index = j;
  335. param.data[j].rindex = i;
  336. param.data[j].hints = 0;
  337. param.data[j].midiChannel = 0;
  338. param.data[j].midiCC = -1;
  339. double min, max, def, step, step_small, step_large;
  340. // min value
  341. if (LADSPA_IS_HINT_BOUNDED_BELOW(PortHint.HintDescriptor))
  342. min = PortHint.LowerBound;
  343. else
  344. min = 0.0;
  345. // max value
  346. if (LADSPA_IS_HINT_BOUNDED_ABOVE(PortHint.HintDescriptor))
  347. max = PortHint.UpperBound;
  348. else
  349. max = 1.0;
  350. if (min > max)
  351. max = min;
  352. else if (max < min)
  353. min = max;
  354. if (max - min == 0.0)
  355. {
  356. qWarning("Broken plugin parameter: max - min == 0");
  357. max = min + 0.1;
  358. }
  359. // default value
  360. if (LADSPA_IS_HINT_HAS_DEFAULT(PortHint.HintDescriptor))
  361. {
  362. switch (PortHint.HintDescriptor & LADSPA_HINT_DEFAULT_MASK)
  363. {
  364. case LADSPA_HINT_DEFAULT_MINIMUM:
  365. def = min;
  366. break;
  367. case LADSPA_HINT_DEFAULT_MAXIMUM:
  368. def = max;
  369. break;
  370. case LADSPA_HINT_DEFAULT_0:
  371. def = 0.0;
  372. break;
  373. case LADSPA_HINT_DEFAULT_1:
  374. def = 1.0;
  375. break;
  376. case LADSPA_HINT_DEFAULT_100:
  377. def = 100.0;
  378. break;
  379. case LADSPA_HINT_DEFAULT_440:
  380. def = 440.0;
  381. break;
  382. case LADSPA_HINT_DEFAULT_LOW:
  383. if (LADSPA_IS_HINT_LOGARITHMIC(PortHint.HintDescriptor))
  384. def = exp((log(min)*0.75) + (log(max)*0.25));
  385. else
  386. def = (min*0.75) + (max*0.25);
  387. break;
  388. case LADSPA_HINT_DEFAULT_MIDDLE:
  389. if (LADSPA_IS_HINT_LOGARITHMIC(PortHint.HintDescriptor))
  390. def = sqrt(min*max);
  391. else
  392. def = (min+max)/2;
  393. break;
  394. case LADSPA_HINT_DEFAULT_HIGH:
  395. if (LADSPA_IS_HINT_LOGARITHMIC(PortHint.HintDescriptor))
  396. def = exp((log(min)*0.25) + (log(max)*0.75));
  397. else
  398. def = (min*0.25) + (max*0.75);
  399. break;
  400. default:
  401. if (min < 0.0 && max > 0.0)
  402. def = 0.0;
  403. else
  404. def = min;
  405. break;
  406. }
  407. }
  408. else
  409. {
  410. // no default value
  411. if (min < 0.0 && max > 0.0)
  412. def = 0.0;
  413. else
  414. def = min;
  415. }
  416. if (def < min)
  417. def = min;
  418. else if (def > max)
  419. def = max;
  420. if (LADSPA_IS_HINT_SAMPLE_RATE(PortHint.HintDescriptor))
  421. {
  422. min *= sampleRate;
  423. max *= sampleRate;
  424. def *= sampleRate;
  425. param.data[j].hints |= PARAMETER_USES_SAMPLERATE;
  426. }
  427. if (LADSPA_IS_HINT_TOGGLED(PortHint.HintDescriptor))
  428. {
  429. step = max - min;
  430. step_small = step;
  431. step_large = step;
  432. param.data[j].hints |= PARAMETER_IS_BOOLEAN;
  433. }
  434. else if (LADSPA_IS_HINT_INTEGER(PortHint.HintDescriptor))
  435. {
  436. step = 1.0;
  437. step_small = 1.0;
  438. step_large = 10.0;
  439. param.data[j].hints |= PARAMETER_IS_INTEGER;
  440. }
  441. else
  442. {
  443. double range = max - min;
  444. step = range/100.0;
  445. step_small = range/1000.0;
  446. step_large = range/10.0;
  447. }
  448. if (LADSPA_IS_PORT_INPUT(PortType))
  449. {
  450. param.data[j].type = PARAMETER_INPUT;
  451. param.data[j].hints |= PARAMETER_IS_ENABLED;
  452. param.data[j].hints |= PARAMETER_IS_AUTOMABLE;
  453. needsCin = true;
  454. // MIDI CC value
  455. if (descriptor->get_midi_controller_for_port)
  456. {
  457. int controller = descriptor->get_midi_controller_for_port(handle, i);
  458. if (DSSI_CONTROLLER_IS_SET(controller) && DSSI_IS_CC(controller))
  459. {
  460. int16_t cc = DSSI_CC_NUMBER(controller);
  461. if (! MIDI_IS_CONTROL_BANK_SELECT(cc))
  462. param.data[j].midiCC = cc;
  463. }
  464. }
  465. }
  466. else if (LADSPA_IS_PORT_OUTPUT(PortType))
  467. {
  468. if (strcmp(ldescriptor->PortNames[i], "latency") == 0 || strcmp(ldescriptor->PortNames[i], "_latency") == 0)
  469. {
  470. min = 0.0;
  471. max = sampleRate;
  472. def = 0.0;
  473. step = 1.0;
  474. step_small = 1.0;
  475. step_large = 1.0;
  476. param.data[j].type = PARAMETER_LATENCY;
  477. param.data[j].hints = 0;
  478. }
  479. else
  480. {
  481. param.data[j].type = PARAMETER_OUTPUT;
  482. param.data[j].hints |= PARAMETER_IS_ENABLED;
  483. param.data[j].hints |= PARAMETER_IS_AUTOMABLE;
  484. needsCout = true;
  485. }
  486. }
  487. else
  488. {
  489. param.data[j].type = PARAMETER_UNKNOWN;
  490. qWarning("WARNING - Got a broken Port (Control, but not input or output)");
  491. }
  492. // extra parameter hints
  493. if (LADSPA_IS_HINT_LOGARITHMIC(PortHint.HintDescriptor))
  494. param.data[j].hints |= PARAMETER_IS_LOGARITHMIC;
  495. param.ranges[j].min = min;
  496. param.ranges[j].max = max;
  497. param.ranges[j].def = def;
  498. param.ranges[j].step = step;
  499. param.ranges[j].stepSmall = step_small;
  500. param.ranges[j].stepLarge = step_large;
  501. // Start parameters in their default values
  502. param_buffers[j] = def;
  503. ldescriptor->connect_port(handle, i, &param_buffers[j]);
  504. if (h2) ldescriptor->connect_port(h2, i, &param_buffers[j]);
  505. }
  506. else
  507. {
  508. // Not Audio or Control
  509. qCritical("ERROR - Got a broken Port (neither Audio or Control)");
  510. ldescriptor->connect_port(handle, i, nullptr);
  511. if (h2) ldescriptor->connect_port(h2, i, nullptr);
  512. }
  513. }
  514. if (needsCin)
  515. {
  516. #ifndef BUILD_BRIDGE
  517. if (carlaOptions.process_mode != PROCESS_MODE_MULTIPLE_CLIENTS)
  518. {
  519. strcpy(portName, m_name);
  520. strcat(portName, ":control-in");
  521. }
  522. else
  523. #endif
  524. strcpy(portName, "control-in");
  525. param.portCin = (CarlaEngineControlPort*)x_client->addPort(CarlaEnginePortTypeControl, portName, true);
  526. }
  527. if (needsCout)
  528. {
  529. #ifndef BUILD_BRIDGE
  530. if (carlaOptions.process_mode != PROCESS_MODE_MULTIPLE_CLIENTS)
  531. {
  532. strcpy(portName, m_name);
  533. strcat(portName, ":control-out");
  534. }
  535. else
  536. #endif
  537. strcpy(portName, "control-out");
  538. param.portCout = (CarlaEngineControlPort*)x_client->addPort(CarlaEnginePortTypeControl, portName, false);
  539. }
  540. if (mins > 0)
  541. {
  542. #ifndef BUILD_BRIDGE
  543. if (carlaOptions.process_mode != PROCESS_MODE_MULTIPLE_CLIENTS)
  544. {
  545. strcpy(portName, m_name);
  546. strcat(portName, ":midi-in");
  547. }
  548. else
  549. #endif
  550. strcpy(portName, "midi-in");
  551. midi.portMin = (CarlaEngineMidiPort*)x_client->addPort(CarlaEnginePortTypeMIDI, portName, true);
  552. }
  553. ain.count = ains;
  554. aout.count = aouts;
  555. param.count = params;
  556. // plugin checks
  557. m_hints &= ~(PLUGIN_IS_SYNTH | PLUGIN_USES_CHUNKS | PLUGIN_CAN_DRYWET | PLUGIN_CAN_VOLUME | PLUGIN_CAN_BALANCE);
  558. if (midi.portMin && aout.count > 0)
  559. m_hints |= PLUGIN_IS_SYNTH;
  560. #ifndef BUILD_BRIDGE
  561. if (carlaOptions.use_dssi_chunks && QString(m_filename).endsWith("dssi-vst.so", Qt::CaseInsensitive))
  562. {
  563. if (descriptor->get_custom_data && descriptor->set_custom_data)
  564. m_hints |= PLUGIN_USES_CHUNKS;
  565. }
  566. #endif
  567. if (aouts > 0 && (ains == aouts || ains == 1))
  568. m_hints |= PLUGIN_CAN_DRYWET;
  569. if (aouts > 0)
  570. m_hints |= PLUGIN_CAN_VOLUME;
  571. if (carlaOptions.process_mode == PROCESS_MODE_CONTINUOUS_RACK || (aouts >= 2 && aouts%2 == 0))
  572. m_hints |= PLUGIN_CAN_BALANCE;
  573. reloadPrograms(true);
  574. x_client->activate();
  575. qDebug("DssiPlugin::reload() - end");
  576. }
  577. void reloadPrograms(bool init)
  578. {
  579. qDebug("DssiPlugin::reloadPrograms(%s)", bool2str(init));
  580. uint32_t i, oldCount = midiprog.count;
  581. // Delete old programs
  582. if (midiprog.count > 0)
  583. {
  584. for (uint32_t i=0; i < midiprog.count; i++)
  585. free((void*)midiprog.data[i].name);
  586. delete[] midiprog.data;
  587. }
  588. midiprog.count = 0;
  589. midiprog.data = nullptr;
  590. // Query new programs
  591. if (descriptor->get_program && descriptor->select_program)
  592. {
  593. while (descriptor->get_program(handle, midiprog.count))
  594. midiprog.count += 1;
  595. }
  596. if (midiprog.count > 0)
  597. midiprog.data = new midi_program_t [midiprog.count];
  598. // Update data
  599. for (i=0; i < midiprog.count; i++)
  600. {
  601. const DSSI_Program_Descriptor* const pdesc = descriptor->get_program(handle, i);
  602. assert(pdesc);
  603. midiprog.data[i].bank = pdesc->Bank;
  604. midiprog.data[i].program = pdesc->Program;
  605. midiprog.data[i].name = strdup(pdesc->Name);
  606. }
  607. #ifndef BUILD_BRIDGE
  608. // Update OSC Names
  609. x_engine->osc_send_set_midi_program_count(m_id, midiprog.count);
  610. for (i=0; i < midiprog.count; i++)
  611. x_engine->osc_send_set_midi_program_data(m_id, i, midiprog.data[i].bank, midiprog.data[i].program, midiprog.data[i].name);
  612. x_engine->callback(CALLBACK_RELOAD_PROGRAMS, m_id, 0, 0, 0.0);
  613. #endif
  614. if (init)
  615. {
  616. if (midiprog.count > 0)
  617. setMidiProgram(0, false, false, false, true);
  618. }
  619. else
  620. {
  621. x_engine->callback(CALLBACK_UPDATE, m_id, 0, 0, 0.0);
  622. // Check if current program is invalid
  623. bool programChanged = false;
  624. if (midiprog.count == oldCount+1)
  625. {
  626. // one midi program added, probably created by user
  627. midiprog.current = oldCount;
  628. programChanged = true;
  629. }
  630. else if (midiprog.current >= (int32_t)midiprog.count)
  631. {
  632. // current midi program > count
  633. midiprog.current = 0;
  634. programChanged = true;
  635. }
  636. else if (midiprog.current < 0 && midiprog.count > 0)
  637. {
  638. // programs exist now, but not before
  639. midiprog.current = 0;
  640. programChanged = true;
  641. }
  642. else if (midiprog.current >= 0 && midiprog.count == 0)
  643. {
  644. // programs existed before, but not anymore
  645. midiprog.current = -1;
  646. programChanged = true;
  647. }
  648. if (programChanged)
  649. setMidiProgram(midiprog.current, true, true, true, true);
  650. }
  651. }
  652. // -------------------------------------------------------------------
  653. // Plugin processing
  654. void process(float** inBuffer, float** outBuffer, uint32_t frames, uint32_t framesOffset)
  655. {
  656. uint32_t i, k;
  657. unsigned long midiEventCount = 0;
  658. double ains_peak_tmp[2] = { 0.0 };
  659. double aouts_peak_tmp[2] = { 0.0 };
  660. CARLA_PROCESS_CONTINUE_CHECK;
  661. // --------------------------------------------------------------------------------------------------------
  662. // Input VU
  663. if (ain.count > 0)
  664. {
  665. uint32_t count = h2 ? 2 : ain.count;
  666. if (count == 1)
  667. {
  668. for (k=0; k < frames; k++)
  669. {
  670. if (abs(inBuffer[0][k]) > ains_peak_tmp[0])
  671. ains_peak_tmp[0] = abs(inBuffer[0][k]);
  672. }
  673. }
  674. else if (count > 1)
  675. {
  676. for (k=0; k < frames; k++)
  677. {
  678. if (abs(inBuffer[0][k]) > ains_peak_tmp[0])
  679. ains_peak_tmp[0] = abs(inBuffer[0][k]);
  680. if (abs(inBuffer[1][k]) > ains_peak_tmp[1])
  681. ains_peak_tmp[1] = abs(inBuffer[1][k]);
  682. }
  683. }
  684. }
  685. CARLA_PROCESS_CONTINUE_CHECK;
  686. // --------------------------------------------------------------------------------------------------------
  687. // Parameters Input [Automation]
  688. if (param.portCin && m_active && m_activeBefore)
  689. {
  690. bool allNotesOffSent = false;
  691. const CarlaEngineControlEvent* cinEvent;
  692. uint32_t time, nEvents = param.portCin->getEventCount();
  693. uint32_t nextBankId = 0;
  694. if (midiprog.current >= 0 && midiprog.count > 0)
  695. nextBankId = midiprog.data[midiprog.current].bank;
  696. for (i=0; i < nEvents; i++)
  697. {
  698. cinEvent = param.portCin->getEvent(i);
  699. if (! cinEvent)
  700. continue;
  701. time = cinEvent->time - framesOffset;
  702. if (time >= frames)
  703. continue;
  704. // Control change
  705. switch (cinEvent->type)
  706. {
  707. case CarlaEngineEventNull:
  708. break;
  709. case CarlaEngineEventControlChange:
  710. {
  711. double value;
  712. // Control backend stuff
  713. if (cinEvent->channel == cin_channel)
  714. {
  715. if (MIDI_IS_CONTROL_BREATH_CONTROLLER(cinEvent->controller) && (m_hints & PLUGIN_CAN_DRYWET) > 0)
  716. {
  717. value = cinEvent->value;
  718. setDryWet(value, false, false);
  719. postponeEvent(PluginPostEventParameterChange, PARAMETER_DRYWET, value);
  720. continue;
  721. }
  722. if (MIDI_IS_CONTROL_CHANNEL_VOLUME(cinEvent->controller) && (m_hints & PLUGIN_CAN_VOLUME) > 0)
  723. {
  724. value = cinEvent->value*127/100;
  725. setVolume(value, false, false);
  726. postponeEvent(PluginPostEventParameterChange, PARAMETER_VOLUME, value);
  727. continue;
  728. }
  729. if (MIDI_IS_CONTROL_BALANCE(cinEvent->controller) && (m_hints & PLUGIN_CAN_BALANCE) > 0)
  730. {
  731. double left, right;
  732. value = cinEvent->value/0.5 - 1.0;
  733. if (value < 0)
  734. {
  735. left = -1.0;
  736. right = (value*2)+1.0;
  737. }
  738. else if (value > 0)
  739. {
  740. left = (value*2)-1.0;
  741. right = 1.0;
  742. }
  743. else
  744. {
  745. left = -1.0;
  746. right = 1.0;
  747. }
  748. setBalanceLeft(left, false, false);
  749. setBalanceRight(right, false, false);
  750. postponeEvent(PluginPostEventParameterChange, PARAMETER_BALANCE_LEFT, left);
  751. postponeEvent(PluginPostEventParameterChange, PARAMETER_BALANCE_RIGHT, right);
  752. continue;
  753. }
  754. }
  755. // Control plugin parameters
  756. for (k=0; k < param.count; k++)
  757. {
  758. if (param.data[k].midiChannel != cinEvent->channel)
  759. continue;
  760. if (param.data[k].midiCC != cinEvent->controller)
  761. continue;
  762. if (param.data[k].type != PARAMETER_INPUT)
  763. continue;
  764. if (param.data[k].hints & PARAMETER_IS_AUTOMABLE)
  765. {
  766. if (param.data[k].hints & PARAMETER_IS_BOOLEAN)
  767. {
  768. value = cinEvent->value < 0.5 ? param.ranges[k].min : param.ranges[k].max;
  769. }
  770. else
  771. {
  772. value = cinEvent->value * (param.ranges[k].max - param.ranges[k].min) + param.ranges[k].min;
  773. if (param.data[k].hints & PARAMETER_IS_INTEGER)
  774. value = rint(value);
  775. }
  776. setParameterValue(k, value, false, false, false);
  777. postponeEvent(PluginPostEventParameterChange, k, value);
  778. }
  779. }
  780. break;
  781. }
  782. case CarlaEngineEventMidiBankChange:
  783. if (cinEvent->channel == cin_channel)
  784. nextBankId = rint(cinEvent->value);
  785. break;
  786. case CarlaEngineEventMidiProgramChange:
  787. if (cinEvent->channel == cin_channel)
  788. {
  789. uint32_t nextProgramId = rint(cinEvent->value);
  790. for (k=0; k < midiprog.count; k++)
  791. {
  792. if (midiprog.data[k].bank == nextBankId && midiprog.data[k].program == nextProgramId)
  793. {
  794. setMidiProgram(k, false, false, false, false);
  795. postponeEvent(PluginPostEventMidiProgramChange, k, 0.0);
  796. break;
  797. }
  798. }
  799. }
  800. break;
  801. case CarlaEngineEventAllSoundOff:
  802. if (cinEvent->channel == cin_channel)
  803. {
  804. if (midi.portMin && ! allNotesOffSent)
  805. sendMidiAllNotesOff();
  806. if (ldescriptor->deactivate)
  807. {
  808. ldescriptor->deactivate(handle);
  809. if (h2) ldescriptor->deactivate(h2);
  810. }
  811. if (ldescriptor->activate)
  812. {
  813. ldescriptor->activate(handle);
  814. if (h2) ldescriptor->activate(h2);
  815. }
  816. allNotesOffSent = true;
  817. }
  818. break;
  819. case CarlaEngineEventAllNotesOff:
  820. if (cinEvent->channel == cin_channel)
  821. {
  822. if (midi.portMin && ! allNotesOffSent)
  823. sendMidiAllNotesOff();
  824. allNotesOffSent = true;
  825. }
  826. break;
  827. }
  828. }
  829. } // End of Parameters Input
  830. CARLA_PROCESS_CONTINUE_CHECK;
  831. // --------------------------------------------------------------------------------------------------------
  832. // MIDI Input (External)
  833. if (midi.portMin && cin_channel >= 0 && cin_channel < 16 && m_active && m_activeBefore)
  834. {
  835. engineMidiLock();
  836. for (i=0; i < MAX_MIDI_EVENTS && midiEventCount < MAX_MIDI_EVENTS; i++)
  837. {
  838. if (extMidiNotes[i].channel < 0)
  839. break;
  840. snd_seq_event_t* const midiEvent = &midiEvents[midiEventCount];
  841. memset(midiEvent, 0, sizeof(snd_seq_event_t));
  842. midiEvent->type = extMidiNotes[i].velo ? SND_SEQ_EVENT_NOTEON : SND_SEQ_EVENT_NOTEOFF;
  843. midiEvent->data.note.channel = cin_channel;
  844. midiEvent->data.note.note = extMidiNotes[i].note;
  845. midiEvent->data.note.velocity = extMidiNotes[i].velo;
  846. extMidiNotes[i].channel = -1;
  847. midiEventCount += 1;
  848. }
  849. engineMidiUnlock();
  850. } // End of MIDI Input (External)
  851. CARLA_PROCESS_CONTINUE_CHECK;
  852. // --------------------------------------------------------------------------------------------------------
  853. // MIDI Input (System)
  854. if (midi.portMin && m_active && m_activeBefore)
  855. {
  856. const CarlaEngineMidiEvent* minEvent;
  857. uint32_t time, nEvents = midi.portMin->getEventCount();
  858. for (i=0; i < nEvents && midiEventCount < MAX_MIDI_EVENTS; i++)
  859. {
  860. minEvent = midi.portMin->getEvent(i);
  861. if (! minEvent)
  862. continue;
  863. time = minEvent->time - framesOffset;
  864. if (time >= frames)
  865. continue;
  866. uint8_t status = minEvent->data[0];
  867. uint8_t channel = status & 0x0F;
  868. // Fix bad note-off
  869. if (MIDI_IS_STATUS_NOTE_ON(status) && minEvent->data[2] == 0)
  870. status -= 0x10;
  871. snd_seq_event_t* const midiEvent = &midiEvents[midiEventCount];
  872. memset(midiEvent, 0, sizeof(snd_seq_event_t));
  873. midiEvent->time.tick = time;
  874. if (MIDI_IS_STATUS_NOTE_OFF(status))
  875. {
  876. uint8_t note = minEvent->data[1];
  877. midiEvent->type = SND_SEQ_EVENT_NOTEOFF;
  878. midiEvent->data.note.channel = channel;
  879. midiEvent->data.note.note = note;
  880. if (channel == cin_channel)
  881. postponeEvent(PluginPostEventNoteOff, note, 0.0);
  882. }
  883. else if (MIDI_IS_STATUS_NOTE_ON(status))
  884. {
  885. uint8_t note = minEvent->data[1];
  886. uint8_t velo = minEvent->data[2];
  887. midiEvent->type = SND_SEQ_EVENT_NOTEON;
  888. midiEvent->data.note.channel = channel;
  889. midiEvent->data.note.note = note;
  890. midiEvent->data.note.velocity = velo;
  891. if (channel == cin_channel)
  892. postponeEvent(PluginPostEventNoteOn, note, velo);
  893. }
  894. else if (MIDI_IS_STATUS_POLYPHONIC_AFTERTOUCH(status))
  895. {
  896. uint8_t note = minEvent->data[1];
  897. uint8_t pressure = minEvent->data[2];
  898. midiEvent->type = SND_SEQ_EVENT_KEYPRESS;
  899. midiEvent->data.note.channel = channel;
  900. midiEvent->data.note.note = note;
  901. midiEvent->data.note.velocity = pressure;
  902. }
  903. else if (MIDI_IS_STATUS_AFTERTOUCH(status))
  904. {
  905. uint8_t pressure = minEvent->data[1];
  906. midiEvent->type = SND_SEQ_EVENT_CHANPRESS;
  907. midiEvent->data.control.channel = channel;
  908. midiEvent->data.control.value = pressure;
  909. }
  910. else if (MIDI_IS_STATUS_PITCH_WHEEL_CONTROL(status))
  911. {
  912. uint8_t lsb = minEvent->data[1];
  913. uint8_t msb = minEvent->data[2];
  914. midiEvent->type = SND_SEQ_EVENT_PITCHBEND;
  915. midiEvent->data.control.channel = channel;
  916. midiEvent->data.control.value = ((msb << 7) | lsb) - 8192;
  917. }
  918. else
  919. continue;
  920. midiEventCount += 1;
  921. }
  922. } // End of MIDI Input (System)
  923. CARLA_PROCESS_CONTINUE_CHECK;
  924. // --------------------------------------------------------------------------------------------------------
  925. // Special Parameters
  926. #if 0
  927. for (k=0; k < param.count; k++)
  928. {
  929. if (param.data[k].type == PARAMETER_LATENCY)
  930. {
  931. // TODO
  932. }
  933. }
  934. CARLA_PROCESS_CONTINUE_CHECK;
  935. #endif
  936. // --------------------------------------------------------------------------------------------------------
  937. // Plugin processing
  938. if (m_active)
  939. {
  940. if (! m_activeBefore)
  941. {
  942. if (midi.portMin && cin_channel >= 0 && cin_channel < 16)
  943. {
  944. memset(&midiEvents[0], 0, sizeof(snd_seq_event_t));
  945. midiEvents[0].type = SND_SEQ_EVENT_CONTROLLER;
  946. midiEvents[0].data.control.channel = cin_channel;
  947. midiEvents[0].data.control.param = MIDI_CONTROL_ALL_SOUND_OFF;
  948. memset(&midiEvents[1], 0, sizeof(snd_seq_event_t));
  949. midiEvents[1].type = SND_SEQ_EVENT_CONTROLLER;
  950. midiEvents[1].data.control.channel = cin_channel;
  951. midiEvents[1].data.control.param = MIDI_CONTROL_ALL_NOTES_OFF;
  952. midiEventCount = 2;
  953. }
  954. if (ldescriptor->activate)
  955. {
  956. ldescriptor->activate(handle);
  957. if (h2) ldescriptor->activate(h2);
  958. }
  959. }
  960. for (i=0; i < ain.count; i++)
  961. {
  962. ldescriptor->connect_port(handle, ain.rindexes[i], inBuffer[i]);
  963. if (h2 && i == 0) ldescriptor->connect_port(h2, ain.rindexes[i], inBuffer[1]);
  964. }
  965. for (i=0; i < aout.count; i++)
  966. {
  967. ldescriptor->connect_port(handle, aout.rindexes[i], outBuffer[i]);
  968. if (h2 && i == 0) ldescriptor->connect_port(h2, aout.rindexes[i], outBuffer[1]);
  969. }
  970. if (descriptor->run_synth)
  971. {
  972. descriptor->run_synth(handle, frames, midiEvents, midiEventCount);
  973. if (h2) descriptor->run_synth(handle, frames, midiEvents, midiEventCount);
  974. }
  975. else if (descriptor->run_multiple_synths)
  976. {
  977. LADSPA_Handle handlePtr[2] = { handle, h2 };
  978. snd_seq_event_t* midiEventsPtr[2] = { midiEvents, midiEvents };
  979. unsigned long midiEventCountPtr[2] = { midiEventCount, midiEventCount };
  980. descriptor->run_multiple_synths(h2 ? 2 : 1, handlePtr, frames, midiEventsPtr, midiEventCountPtr);
  981. }
  982. else
  983. {
  984. ldescriptor->run(handle, frames);
  985. if (h2) ldescriptor->run(h2, frames);
  986. }
  987. }
  988. else
  989. {
  990. if (m_activeBefore)
  991. {
  992. if (ldescriptor->deactivate)
  993. {
  994. ldescriptor->deactivate(handle);
  995. if (h2) ldescriptor->deactivate(h2);
  996. }
  997. }
  998. }
  999. CARLA_PROCESS_CONTINUE_CHECK;
  1000. // --------------------------------------------------------------------------------------------------------
  1001. // Post-processing (dry/wet, volume and balance)
  1002. if (m_active)
  1003. {
  1004. bool do_drywet = (m_hints & PLUGIN_CAN_DRYWET) > 0 && x_drywet != 1.0;
  1005. bool do_volume = (m_hints & PLUGIN_CAN_VOLUME) > 0 && x_vol != 1.0;
  1006. bool do_balance = (m_hints & PLUGIN_CAN_BALANCE) > 0 && (x_bal_left != -1.0 || x_bal_right != 1.0);
  1007. double bal_rangeL, bal_rangeR;
  1008. float oldBufLeft[do_balance ? frames : 0];
  1009. uint32_t count = h2 ? 2 : aout.count;
  1010. for (i=0; i < count; i++)
  1011. {
  1012. // Dry/Wet and Volume
  1013. if (do_drywet || do_volume)
  1014. {
  1015. for (k=0; k < frames; k++)
  1016. {
  1017. if (do_drywet)
  1018. {
  1019. if (aout.count == 1 && ! h2)
  1020. outBuffer[i][k] = (outBuffer[i][k]*x_drywet)+(inBuffer[0][k]*(1.0-x_drywet));
  1021. else
  1022. outBuffer[i][k] = (outBuffer[i][k]*x_drywet)+(inBuffer[i][k]*(1.0-x_drywet));
  1023. }
  1024. if (do_volume)
  1025. outBuffer[i][k] *= x_vol;
  1026. }
  1027. }
  1028. // Balance
  1029. if (do_balance)
  1030. {
  1031. if (i%2 == 0)
  1032. memcpy(&oldBufLeft, outBuffer[i], sizeof(float)*frames);
  1033. bal_rangeL = (x_bal_left+1.0)/2;
  1034. bal_rangeR = (x_bal_right+1.0)/2;
  1035. for (k=0; k < frames; k++)
  1036. {
  1037. if (i%2 == 0)
  1038. {
  1039. // left output
  1040. outBuffer[i][k] = oldBufLeft[k]*(1.0-bal_rangeL);
  1041. outBuffer[i][k] += outBuffer[i+1][k]*(1.0-bal_rangeR);
  1042. }
  1043. else
  1044. {
  1045. // right
  1046. outBuffer[i][k] = outBuffer[i][k]*bal_rangeR;
  1047. outBuffer[i][k] += oldBufLeft[k]*bal_rangeL;
  1048. }
  1049. }
  1050. }
  1051. // Output VU
  1052. for (k=0; i < 2 && k < frames; k++)
  1053. {
  1054. if (abs(outBuffer[i][k]) > aouts_peak_tmp[i])
  1055. aouts_peak_tmp[i] = abs(outBuffer[i][k]);
  1056. }
  1057. }
  1058. }
  1059. else
  1060. {
  1061. // disable any output sound if not active
  1062. for (i=0; i < aout.count; i++)
  1063. memset(outBuffer[i], 0.0f, sizeof(float)*frames);
  1064. aouts_peak_tmp[0] = 0.0;
  1065. aouts_peak_tmp[1] = 0.0;
  1066. } // End of Post-processing
  1067. CARLA_PROCESS_CONTINUE_CHECK;
  1068. // --------------------------------------------------------------------------------------------------------
  1069. // Control Output
  1070. if (param.portCout && m_active)
  1071. {
  1072. double value;
  1073. for (k=0; k < param.count; k++)
  1074. {
  1075. if (param.data[k].type == PARAMETER_OUTPUT)
  1076. {
  1077. fixParameterValue(param_buffers[k], param.ranges[k]);
  1078. if (param.data[k].midiCC > 0)
  1079. {
  1080. value = (param_buffers[k] - param.ranges[k].min) / (param.ranges[k].max - param.ranges[k].min);
  1081. param.portCout->writeEvent(CarlaEngineEventControlChange, framesOffset, param.data[k].midiChannel, param.data[k].midiCC, value);
  1082. }
  1083. }
  1084. }
  1085. } // End of Control Output
  1086. CARLA_PROCESS_CONTINUE_CHECK;
  1087. // --------------------------------------------------------------------------------------------------------
  1088. // Peak Values
  1089. x_engine->setInputPeak(m_id, 0, ains_peak_tmp[0]);
  1090. x_engine->setInputPeak(m_id, 1, ains_peak_tmp[1]);
  1091. x_engine->setOutputPeak(m_id, 0, aouts_peak_tmp[0]);
  1092. x_engine->setOutputPeak(m_id, 1, aouts_peak_tmp[1]);
  1093. m_activeBefore = m_active;
  1094. }
  1095. // -------------------------------------------------------------------
  1096. // Cleanup
  1097. void deleteBuffers()
  1098. {
  1099. qDebug("DssiPlugin::deleteBuffers() - start");
  1100. if (param.count > 0)
  1101. delete[] param_buffers;
  1102. param_buffers = nullptr;
  1103. qDebug("DssiPlugin::deleteBuffers() - end");
  1104. }
  1105. // -------------------------------------------------------------------
  1106. bool init(const char* const filename, const char* const name, const char* const label, const char* const guiFilename)
  1107. {
  1108. // ---------------------------------------------------------------
  1109. // open DLL
  1110. if (! libOpen(filename))
  1111. {
  1112. setLastError(libError(filename));
  1113. return false;
  1114. }
  1115. // ---------------------------------------------------------------
  1116. // get DLL main entry
  1117. DSSI_Descriptor_Function descfn = (DSSI_Descriptor_Function)libSymbol("dssi_descriptor");
  1118. if (! descfn)
  1119. {
  1120. setLastError("Could not find the LASDPA Descriptor in the plugin library");
  1121. return false;
  1122. }
  1123. // ---------------------------------------------------------------
  1124. // get descriptor that matches label
  1125. unsigned long i = 0;
  1126. while ((descriptor = descfn(i++)))
  1127. {
  1128. ldescriptor = descriptor->LADSPA_Plugin;
  1129. if (strcmp(ldescriptor->Label, label) == 0)
  1130. break;
  1131. }
  1132. if (! descriptor)
  1133. {
  1134. setLastError("Could not find the requested plugin Label in the plugin library");
  1135. return false;
  1136. }
  1137. // ---------------------------------------------------------------
  1138. // initialize plugin
  1139. handle = ldescriptor->instantiate(ldescriptor, x_engine->getSampleRate());
  1140. if (! handle)
  1141. {
  1142. setLastError("Plugin failed to initialize");
  1143. return false;
  1144. }
  1145. // ---------------------------------------------------------------
  1146. // get info
  1147. m_filename = strdup(filename);
  1148. if (name)
  1149. m_name = x_engine->getUniqueName(name);
  1150. else
  1151. m_name = x_engine->getUniqueName(ldescriptor->Name);
  1152. // ---------------------------------------------------------------
  1153. // register client
  1154. x_client = x_engine->addClient(this);
  1155. if (! x_client->isOk())
  1156. {
  1157. setLastError("Failed to register plugin client");
  1158. return false;
  1159. }
  1160. // ---------------------------------------------------------------
  1161. // gui stuff
  1162. #ifndef BUILD_BRIDGE
  1163. if (guiFilename)
  1164. {
  1165. osc.thread = new CarlaPluginThread(x_engine, this, CarlaPluginThread::PLUGIN_THREAD_DSSI_GUI);
  1166. osc.thread->setOscData(guiFilename, ldescriptor->Label);
  1167. m_hints |= PLUGIN_HAS_GUI;
  1168. }
  1169. #else
  1170. Q_UNUSED(guiFilename);
  1171. #endif
  1172. return true;
  1173. }
  1174. private:
  1175. LADSPA_Handle handle, h2;
  1176. const LADSPA_Descriptor* ldescriptor;
  1177. const DSSI_Descriptor* descriptor;
  1178. snd_seq_event_t midiEvents[MAX_MIDI_EVENTS];
  1179. float* param_buffers;
  1180. };
  1181. CarlaPlugin* CarlaPlugin::newDSSI(const initializer& init, const void* const extra)
  1182. {
  1183. qDebug("CarlaPlugin::newDSSI(%p, %s, %s, %s, %p)", init.engine, init.filename, init.name, init.label, extra);
  1184. short id = init.engine->getNewPluginId();
  1185. if (id < 0)
  1186. {
  1187. setLastError("Maximum number of plugins reached");
  1188. return nullptr;
  1189. }
  1190. DssiPlugin* const plugin = new DssiPlugin(init.engine, id);
  1191. if (! plugin->init(init.filename, init.name, init.label, (const char*)extra))
  1192. {
  1193. delete plugin;
  1194. return nullptr;
  1195. }
  1196. plugin->reload();
  1197. #ifndef BUILD_BRIDGE
  1198. if (carlaOptions.process_mode == PROCESS_MODE_CONTINUOUS_RACK)
  1199. {
  1200. uint32_t ins = plugin->audioInCount();
  1201. uint32_t outs = plugin->audioOutCount();
  1202. if (ins > 2 || outs > 2 || (ins != outs && ins != 0 && outs != 0))
  1203. {
  1204. setLastError("Carla's Rack Mode can only work with Mono or Stereo DSSI plugins, sorry!");
  1205. delete plugin;
  1206. return nullptr;
  1207. }
  1208. }
  1209. #endif
  1210. plugin->registerToOsc();
  1211. return plugin;
  1212. }
  1213. /**@}*/
  1214. CARLA_BACKEND_END_NAMESPACE