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.

1533 lines
50KB

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