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.

1486 lines
49KB

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