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.

2156 lines
66KB

  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_vst.h"
  19. #ifndef __WINE__
  20. #include <QtGui/QDialog>
  21. #endif
  22. CARLA_BACKEND_START_NAMESPACE
  23. #if 0
  24. } /* adjust editor indent */
  25. #endif
  26. /*!
  27. * @defgroup CarlaBackendVstPlugin Carla Backend VST Plugin
  28. *
  29. * The Carla Backend VST Plugin.
  30. * @{
  31. */
  32. /*!
  33. * @defgroup PluginHints Plugin Hints
  34. * @{
  35. */
  36. const unsigned int PLUGIN_CAN_PROCESS_REPLACING = 0x100; //!< VST Plugin cas use processReplacing()
  37. const unsigned int PLUGIN_HAS_COCKOS_EXTENSIONS = 0x200; //!< VST Plugin has Cockos extensions
  38. const unsigned int PLUGIN_USES_OLD_VSTSDK = 0x400; //!< VST Plugin uses an old VST SDK
  39. const unsigned int PLUGIN_WANTS_MIDI_INPUT = 0x800; //!< VST Plugin wants MIDI input
  40. /**@}*/
  41. class VstPlugin : public CarlaPlugin
  42. {
  43. public:
  44. VstPlugin(CarlaEngine* const engine, const unsigned short id)
  45. : CarlaPlugin(engine, id)
  46. {
  47. qDebug("VstPlugin::VstPlugin()");
  48. m_type = PLUGIN_VST;
  49. effect = nullptr;
  50. events.numEvents = 0;
  51. events.reserved = 0;
  52. gui.type = GUI_NONE;
  53. gui.visible = false;
  54. gui.width = 0;
  55. gui.height = 0;
  56. memset(midiEvents, 0, sizeof(VstMidiEvent)*MAX_MIDI_EVENTS*2);
  57. for (unsigned short i=0; i < MAX_MIDI_EVENTS*2; i++)
  58. events.data[i] = (VstEvent*)&midiEvents[i];
  59. // make plugin valid
  60. srand(id);
  61. unique1 = unique2 = rand();
  62. }
  63. ~VstPlugin()
  64. {
  65. qDebug("VstPlugin::~VstPlugin()");
  66. // make plugin invalid
  67. unique2 += 1;
  68. if (effect)
  69. {
  70. // close UI
  71. if (m_hints & PLUGIN_HAS_GUI)
  72. {
  73. showGui(false);
  74. if (gui.type == GUI_EXTERNAL_OSC)
  75. {
  76. #ifndef BUILD_BRIDGE
  77. if (osc.thread)
  78. {
  79. // Wait a bit first, try safe quit, then force kill
  80. if (osc.thread->isRunning() && ! osc.thread->wait(carlaOptions.oscUiTimeout * 100))
  81. {
  82. qWarning("Failed to properly stop VST OSC GUI thread");
  83. osc.thread->terminate();
  84. }
  85. delete osc.thread;
  86. }
  87. #endif
  88. }
  89. else
  90. effect->dispatcher(effect, effEditClose, 0, 0, nullptr, 0.0f);
  91. }
  92. if (m_activeBefore)
  93. {
  94. effect->dispatcher(effect, effStopProcess, 0, 0, nullptr, 0.0f);
  95. effect->dispatcher(effect, effMainsChanged, 0, 0, nullptr, 0.0f);
  96. }
  97. effect->dispatcher(effect, effClose, 0, 0, nullptr, 0.0f);
  98. }
  99. }
  100. // -------------------------------------------------------------------
  101. // Information (base)
  102. PluginCategory category()
  103. {
  104. Q_ASSERT(effect);
  105. intptr_t category = effect->dispatcher(effect, effGetPlugCategory, 0, 0, nullptr, 0.0f);
  106. switch (category)
  107. {
  108. case kPlugCategSynth:
  109. return PLUGIN_CATEGORY_SYNTH;
  110. case kPlugCategAnalysis:
  111. return PLUGIN_CATEGORY_UTILITY;
  112. case kPlugCategMastering:
  113. return PLUGIN_CATEGORY_DYNAMICS;
  114. case kPlugCategRoomFx:
  115. return PLUGIN_CATEGORY_DELAY;
  116. case kPlugCategRestoration:
  117. return PLUGIN_CATEGORY_UTILITY;
  118. case kPlugCategGenerator:
  119. return PLUGIN_CATEGORY_SYNTH;
  120. }
  121. if (effect->flags & effFlagsIsSynth)
  122. return PLUGIN_CATEGORY_SYNTH;
  123. return getPluginCategoryFromName(m_name);
  124. }
  125. long uniqueId()
  126. {
  127. Q_ASSERT(effect);
  128. return effect->uniqueID;
  129. }
  130. // -------------------------------------------------------------------
  131. // Information (current data)
  132. int32_t chunkData(void** const dataPtr)
  133. {
  134. Q_ASSERT(dataPtr);
  135. Q_ASSERT(effect);
  136. if (effect)
  137. return effect->dispatcher(effect, effGetChunk, 0 /* bank */, 0, dataPtr, 0.0f);
  138. return 0;
  139. }
  140. // -------------------------------------------------------------------
  141. // Information (per-plugin data)
  142. double getParameterValue(const uint32_t parameterId)
  143. {
  144. Q_ASSERT(effect);
  145. Q_ASSERT(parameterId < param.count);
  146. if (effect)
  147. return effect->getParameter(effect, parameterId);
  148. return 0.0;
  149. }
  150. void getLabel(char* const strBuf)
  151. {
  152. Q_ASSERT(effect);
  153. if (effect)
  154. effect->dispatcher(effect, effGetProductString, 0, 0, strBuf, 0.0f);
  155. else
  156. CarlaPlugin::getLabel(strBuf);
  157. }
  158. void getMaker(char* const strBuf)
  159. {
  160. Q_ASSERT(effect);
  161. if (effect)
  162. effect->dispatcher(effect, effGetVendorString, 0, 0, strBuf, 0.0f);
  163. else
  164. CarlaPlugin::getMaker(strBuf);
  165. }
  166. void getCopyright(char* const strBuf)
  167. {
  168. Q_ASSERT(effect);
  169. if (effect)
  170. effect->dispatcher(effect, effGetVendorString, 0, 0, strBuf, 0.0f);
  171. else
  172. CarlaPlugin::getCopyright(strBuf);
  173. }
  174. void getRealName(char* const strBuf)
  175. {
  176. Q_ASSERT(effect);
  177. if (effect)
  178. effect->dispatcher(effect, effGetEffectName, 0, 0, strBuf, 0.0f);
  179. else
  180. CarlaPlugin::getRealName(strBuf);
  181. }
  182. void getParameterName(const uint32_t parameterId, char* const strBuf)
  183. {
  184. Q_ASSERT(effect);
  185. Q_ASSERT(parameterId < param.count);
  186. if (effect)
  187. effect->dispatcher(effect, effGetParamName, parameterId, 0, strBuf, 0.0f);
  188. else
  189. CarlaPlugin::getParameterName(parameterId, strBuf);
  190. }
  191. void getParameterText(const uint32_t parameterId, char* const strBuf)
  192. {
  193. Q_ASSERT(effect);
  194. Q_ASSERT(parameterId < param.count);
  195. if (effect)
  196. {
  197. effect->dispatcher(effect, effGetParamDisplay, parameterId, 0, strBuf, 0.0f);
  198. if (*strBuf == 0)
  199. sprintf(strBuf, "%f", getParameterValue(parameterId));
  200. }
  201. else
  202. CarlaPlugin::getParameterText(parameterId, strBuf);
  203. }
  204. void getParameterUnit(const uint32_t parameterId, char* const strBuf)
  205. {
  206. Q_ASSERT(effect);
  207. Q_ASSERT(parameterId < param.count);
  208. if (effect)
  209. effect->dispatcher(effect, effGetParamLabel, parameterId, 0, strBuf, 0.0f);
  210. else
  211. CarlaPlugin::getParameterUnit(parameterId, strBuf);
  212. }
  213. void getGuiInfo(GuiType* const type, bool* const resizable)
  214. {
  215. *type = gui.type;
  216. *resizable = false;
  217. }
  218. // -------------------------------------------------------------------
  219. // Set data (plugin-specific stuff)
  220. void setParameterValue(const uint32_t parameterId, double value, const bool sendGui, const bool sendOsc, const bool sendCallback)
  221. {
  222. Q_ASSERT(parameterId < param.count);
  223. effect->setParameter(effect, parameterId, fixParameterValue(value, param.ranges[parameterId]));
  224. CarlaPlugin::setParameterValue(parameterId, value, sendGui, sendOsc, sendCallback);
  225. }
  226. void setChunkData(const char* const stringData)
  227. {
  228. Q_ASSERT(m_hints & PLUGIN_USES_CHUNKS);
  229. Q_ASSERT(stringData);
  230. static QByteArray chunk;
  231. chunk = QByteArray::fromBase64(stringData);
  232. if (x_engine->isOffline())
  233. {
  234. const CarlaEngine::ScopedLocker m(x_engine);
  235. effect->dispatcher(effect, effSetChunk, 0 /* bank */, chunk.size(), chunk.data(), 0.0f);
  236. }
  237. else
  238. {
  239. const CarlaPlugin::ScopedDisabler m(this);
  240. effect->dispatcher(effect, effSetChunk, 0 /* bank */, chunk.size(), chunk.data(), 0.0f);
  241. }
  242. }
  243. void setProgram(int32_t index, const bool sendGui, const bool sendOsc, const bool sendCallback, const bool block)
  244. {
  245. Q_ASSERT(index >= -1 && index < (int32_t)prog.count);
  246. if (index < -1)
  247. index = -1;
  248. else if (index > (int32_t)prog.count)
  249. return;
  250. if (index >= 0)
  251. {
  252. if (x_engine->isOffline())
  253. {
  254. const CarlaEngine::ScopedLocker m(x_engine, block);
  255. effect->dispatcher(effect, effSetProgram, 0, index, nullptr, 0.0f);
  256. }
  257. else
  258. {
  259. const ScopedDisabler m(this, block);
  260. effect->dispatcher(effect, effSetProgram, 0, index, nullptr, 0.0f);
  261. }
  262. }
  263. CarlaPlugin::setProgram(index, sendGui, sendOsc, sendCallback, block);
  264. }
  265. // -------------------------------------------------------------------
  266. // Set gui stuff
  267. void setGuiData(const int data, const GuiDataHandle handle)
  268. {
  269. qDebug("VstPlugin::setGuiData(%i, %p)", data, handle);
  270. Q_ASSERT(handle);
  271. if (gui.type == GUI_EXTERNAL_OSC)
  272. return;
  273. #ifdef __WINE__
  274. if (effect->dispatcher(effect, effEditOpen, 0, data, handle, 0.0f) == 1)
  275. #else
  276. const QDialog* const dialog = handle;
  277. if (effect->dispatcher(effect, effEditOpen, 0, data, (void*)dialog->winId(), 0.0f) == 1)
  278. #endif
  279. {
  280. ERect* vstRect = nullptr;
  281. effect->dispatcher(effect, effEditGetRect, 0, 0, &vstRect, 0.0f);
  282. if (vstRect)
  283. {
  284. int width = vstRect->right - vstRect->left;
  285. int height = vstRect->bottom - vstRect->top;
  286. if (width <= 0 || height <= 0)
  287. {
  288. qCritical("VstPlugin::setGuiData(%i, %p) - failed to get proper window size", data, handle);
  289. return;
  290. }
  291. gui.width = width;
  292. gui.height = height;
  293. }
  294. else
  295. qCritical("VstPlugin::setGuiData(%i, %p) - failed to get plugin window size", data, handle);
  296. }
  297. else
  298. {
  299. // failed to open UI
  300. m_hints &= ~PLUGIN_HAS_GUI;
  301. x_engine->callback(CALLBACK_SHOW_GUI, m_id, -1, 0, 0.0);
  302. effect->dispatcher(effect, effEditClose, 0, 0, nullptr, 0.0f);
  303. }
  304. }
  305. void showGui(const bool yesNo)
  306. {
  307. if (gui.type == GUI_EXTERNAL_OSC)
  308. {
  309. #ifndef BUILD_BRIDGE
  310. Q_ASSERT(osc.thread);
  311. if (! osc.thread)
  312. {
  313. qCritical("VstPlugin::showGui(%s) - attempt to show gui, but it does not exist!", bool2str(yesNo));
  314. return;
  315. }
  316. if (yesNo)
  317. {
  318. osc.thread->start();
  319. }
  320. else
  321. {
  322. if (osc.data.target)
  323. {
  324. osc_send_hide(&osc.data);
  325. osc_send_quit(&osc.data);
  326. osc_clear_data(&osc.data);
  327. }
  328. if (! osc.thread->wait(500))
  329. osc.thread->quit();
  330. }
  331. #endif
  332. }
  333. else
  334. {
  335. if (yesNo && gui.width > 0 && gui.height > 0)
  336. x_engine->callback(CALLBACK_RESIZE_GUI, m_id, gui.width, gui.height, 0.0);
  337. }
  338. gui.visible = yesNo;
  339. }
  340. void idleGui()
  341. {
  342. qDebug("VstPlugin::idleGui()");
  343. effect->dispatcher(effect, effIdle, 0, 0, nullptr, 0.0f);
  344. // FIXME
  345. //if (gui.type != GUI_EXTERNAL_OSC && gui.visible)
  346. effect->dispatcher(effect, effEditIdle, 0, 0, nullptr, 0.0f);
  347. //CarlaPlugin::idleGui();
  348. }
  349. // -------------------------------------------------------------------
  350. // Plugin state
  351. void reload()
  352. {
  353. qDebug("VstPlugin::reload() - start");
  354. Q_ASSERT(effect);
  355. // Safely disable plugin for reload
  356. const ScopedDisabler m(this);
  357. if (x_client->isActive())
  358. x_client->deactivate();
  359. // Remove client ports
  360. removeClientPorts();
  361. // Delete old data
  362. deleteBuffers();
  363. uint32_t aIns, aOuts, mIns, mOuts, params, j;
  364. aIns = aOuts = mIns = mOuts = params = 0;
  365. aIns = effect->numInputs;
  366. aOuts = effect->numOutputs;
  367. params = effect->numParams;
  368. if (vstPluginCanDo(effect, "receiveVstEvents") || vstPluginCanDo(effect, "receiveVstMidiEvent") || (effect->flags & effFlagsIsSynth) > 0 || (m_hints & PLUGIN_WANTS_MIDI_INPUT))
  369. mIns = 1;
  370. if (vstPluginCanDo(effect, "sendVstEvents") || vstPluginCanDo(effect, "sendVstMidiEvent"))
  371. mOuts = 1;
  372. if (aIns > 0)
  373. {
  374. aIn.ports = new CarlaEngineAudioPort*[aIns];
  375. aIn.rindexes = new uint32_t[aIns];
  376. }
  377. if (aOuts > 0)
  378. {
  379. aOut.ports = new CarlaEngineAudioPort*[aOuts];
  380. aOut.rindexes = new uint32_t[aOuts];
  381. }
  382. if (params > 0)
  383. {
  384. param.data = new ParameterData[params];
  385. param.ranges = new ParameterRanges[params];
  386. }
  387. const int portNameSize = CarlaEngine::maxPortNameSize() - 1;
  388. char portName[portNameSize];
  389. bool needsCtrlIn = (aOuts > 0 || params > 0);
  390. for (j=0; j < aIns; j++)
  391. {
  392. #ifndef BUILD_BRIDGE
  393. if (carlaOptions.processMode != PROCESS_MODE_MULTIPLE_CLIENTS)
  394. sprintf(portName, "%s:input_%02i", m_name, j+1);
  395. else
  396. #endif
  397. sprintf(portName, "input_%02i", j+1);
  398. aIn.ports[j] = (CarlaEngineAudioPort*)x_client->addPort(CarlaEnginePortTypeAudio, portName, true);
  399. aIn.rindexes[j] = j;
  400. }
  401. for (j=0; j < aOuts; j++)
  402. {
  403. #ifndef BUILD_BRIDGE
  404. if (carlaOptions.processMode != PROCESS_MODE_MULTIPLE_CLIENTS)
  405. sprintf(portName, "%s:output_%02i", m_name, j+1);
  406. else
  407. #endif
  408. sprintf(portName, "output_%02i", j+1);
  409. aOut.ports[j] = (CarlaEngineAudioPort*)x_client->addPort(CarlaEnginePortTypeAudio, portName, false);
  410. aOut.rindexes[j] = j;
  411. }
  412. for (j=0; j<params; j++)
  413. {
  414. param.data[j].type = PARAMETER_INPUT;
  415. param.data[j].index = j;
  416. param.data[j].rindex = j;
  417. param.data[j].hints = 0;
  418. param.data[j].midiChannel = 0;
  419. param.data[j].midiCC = -1;
  420. double min, max, def, step, stepSmall, stepLarge;
  421. VstParameterProperties prop;
  422. prop.flags = 0;
  423. if (effect->dispatcher(effect, effGetParameterProperties, j, 0, &prop, 0))
  424. {
  425. double range[2] = { 0.0, 1.0 };
  426. if ((m_hints & PLUGIN_HAS_COCKOS_EXTENSIONS) > 0 && effect->dispatcher(effect, effVendorSpecific, 0xdeadbef0, j, range, 0.0) >= 0xbeef)
  427. {
  428. min = range[0];
  429. max = range[1];
  430. }
  431. else if (prop.flags & kVstParameterUsesIntegerMinMax)
  432. {
  433. min = prop.minInteger;
  434. max = prop.maxInteger;
  435. }
  436. else
  437. {
  438. min = 0.0;
  439. max = 1.0;
  440. }
  441. if (min > max)
  442. max = min;
  443. else if (max < min)
  444. min = max;
  445. if (max - min == 0.0)
  446. {
  447. qWarning("Broken plugin parameter: max - min == 0");
  448. max = min + 0.1;
  449. }
  450. if ((m_hints & PLUGIN_HAS_COCKOS_EXTENSIONS) > 0 && effect->dispatcher(effect, effVendorSpecific, kVstParameterUsesIntStep, j, nullptr, 0.0f) >= 0xbeef)
  451. {
  452. step = 1.0;
  453. stepSmall = 1.0;
  454. stepLarge = 10.0;
  455. }
  456. else if (prop.flags & kVstParameterIsSwitch)
  457. {
  458. step = max - min;
  459. stepSmall = step;
  460. stepLarge = step;
  461. param.data[j].hints |= PARAMETER_IS_BOOLEAN;
  462. }
  463. else if (prop.flags & kVstParameterUsesIntStep)
  464. {
  465. step = prop.stepInteger;
  466. stepSmall = prop.stepInteger;
  467. stepLarge = prop.largeStepInteger;
  468. param.data[j].hints |= PARAMETER_IS_INTEGER;
  469. }
  470. else if (prop.flags & kVstParameterUsesFloatStep)
  471. {
  472. step = prop.stepFloat;
  473. stepSmall = prop.smallStepFloat;
  474. stepLarge = prop.largeStepFloat;
  475. }
  476. else
  477. {
  478. double range = max - min;
  479. step = range/100.0;
  480. stepSmall = range/1000.0;
  481. stepLarge = range/10.0;
  482. }
  483. if (prop.flags & kVstParameterCanRamp)
  484. param.data[j].hints |= PARAMETER_IS_LOGARITHMIC;
  485. }
  486. else
  487. {
  488. min = 0.0;
  489. max = 1.0;
  490. step = 0.001;
  491. stepSmall = 0.0001;
  492. stepLarge = 0.1;
  493. }
  494. // no such thing as VST default parameters
  495. def = effect->getParameter(effect, j);
  496. if (def < min)
  497. def = min;
  498. else if (def > max)
  499. def = max;
  500. param.ranges[j].min = min;
  501. param.ranges[j].max = max;
  502. param.ranges[j].def = def;
  503. param.ranges[j].step = step;
  504. param.ranges[j].stepSmall = stepSmall;
  505. param.ranges[j].stepLarge = stepLarge;
  506. param.data[j].hints |= PARAMETER_IS_ENABLED;
  507. #ifndef BUILD_BRIDGE
  508. param.data[j].hints |= PARAMETER_USES_CUSTOM_TEXT;
  509. #endif
  510. if ((m_hints & PLUGIN_USES_OLD_VSTSDK) > 0 || effect->dispatcher(effect, effCanBeAutomated, j, 0, nullptr, 0.0f) == 1)
  511. param.data[j].hints |= PARAMETER_IS_AUTOMABLE;
  512. }
  513. if (needsCtrlIn)
  514. {
  515. #ifndef BUILD_BRIDGE
  516. if (carlaOptions.processMode != PROCESS_MODE_MULTIPLE_CLIENTS)
  517. {
  518. strcpy(portName, m_name);
  519. strcat(portName, ":control-in");
  520. }
  521. else
  522. #endif
  523. strcpy(portName, "control-in");
  524. param.portCin = (CarlaEngineControlPort*)x_client->addPort(CarlaEnginePortTypeControl, portName, true);
  525. }
  526. if (mIns == 1)
  527. {
  528. #ifndef BUILD_BRIDGE
  529. if (carlaOptions.processMode != PROCESS_MODE_MULTIPLE_CLIENTS)
  530. {
  531. strcpy(portName, m_name);
  532. strcat(portName, ":midi-in");
  533. }
  534. else
  535. #endif
  536. strcpy(portName, "midi-in");
  537. midi.portMin = (CarlaEngineMidiPort*)x_client->addPort(CarlaEnginePortTypeMIDI, portName, true);
  538. }
  539. if (mOuts == 1)
  540. {
  541. #ifndef BUILD_BRIDGE
  542. if (carlaOptions.processMode != PROCESS_MODE_MULTIPLE_CLIENTS)
  543. {
  544. strcpy(portName, m_name);
  545. strcat(portName, ":midi-out");
  546. }
  547. else
  548. #endif
  549. strcpy(portName, "midi-out");
  550. midi.portMout = (CarlaEngineMidiPort*)x_client->addPort(CarlaEnginePortTypeMIDI, portName, false);
  551. }
  552. aIn.count = aIns;
  553. aOut.count = aOuts;
  554. param.count = params;
  555. // plugin checks
  556. m_hints &= ~(PLUGIN_IS_SYNTH | PLUGIN_USES_CHUNKS | PLUGIN_CAN_DRYWET | PLUGIN_CAN_VOLUME | PLUGIN_CAN_BALANCE);
  557. intptr_t vstCategory = effect->dispatcher(effect, effGetPlugCategory, 0, 0, nullptr, 0.0f);
  558. if (vstCategory == kPlugCategSynth || vstCategory == kPlugCategGenerator)
  559. m_hints |= PLUGIN_IS_SYNTH;
  560. if (effect->flags & effFlagsProgramChunks)
  561. m_hints |= PLUGIN_USES_CHUNKS;
  562. if (aOuts > 0 && (aIns == aOuts || aIns == 1))
  563. m_hints |= PLUGIN_CAN_DRYWET;
  564. if (aOuts > 0)
  565. m_hints |= PLUGIN_CAN_VOLUME;
  566. if (aOuts >= 2 && aOuts%2 == 0)
  567. m_hints |= PLUGIN_CAN_BALANCE;
  568. reloadPrograms(true);
  569. x_client->activate();
  570. qDebug("VstPlugin::reload() - end");
  571. }
  572. void reloadPrograms(const bool init)
  573. {
  574. qDebug("VstPlugin::reloadPrograms(%s)", bool2str(init));
  575. uint32_t i, oldCount = prog.count;
  576. // Delete old programs
  577. if (prog.count > 0)
  578. {
  579. for (i=0; i < prog.count; i++)
  580. {
  581. if (prog.names[i])
  582. free((void*)prog.names[i]);
  583. }
  584. delete[] prog.names;
  585. }
  586. prog.count = 0;
  587. prog.names = nullptr;
  588. // Query new programs
  589. prog.count = effect->numPrograms;
  590. if (prog.count > 0)
  591. prog.names = new const char* [prog.count];
  592. // Update names
  593. for (i=0; i < prog.count; i++)
  594. {
  595. char strBuf[STR_MAX] = { 0 };
  596. if (effect->dispatcher(effect, effGetProgramNameIndexed, i, 0, strBuf, 0.0f) != 1)
  597. {
  598. // program will be [re-]changed later
  599. effect->dispatcher(effect, effSetProgram, 0, i, nullptr, 0.0f);
  600. effect->dispatcher(effect, effGetProgramName, 0, 0, strBuf, 0.0f);
  601. }
  602. prog.names[i] = strdup(strBuf);
  603. }
  604. #ifndef BUILD_BRIDGE
  605. // Update OSC Names
  606. x_engine->osc_send_control_set_program_count(m_id, prog.count);
  607. for (i=0; i < prog.count; i++)
  608. x_engine->osc_send_control_set_program_name(m_id, i, prog.names[i]);
  609. #endif
  610. if (init)
  611. {
  612. if (prog.count > 0)
  613. setProgram(0, false, false, false, true);
  614. }
  615. else
  616. {
  617. x_engine->callback(CALLBACK_RELOAD_PROGRAMS, m_id, 0, 0, 0.0);
  618. // Check if current program is invalid
  619. bool programChanged = false;
  620. if (prog.count == oldCount+1)
  621. {
  622. // one program added, probably created by user
  623. prog.current = oldCount;
  624. programChanged = true;
  625. }
  626. else if (prog.current >= (int32_t)prog.count)
  627. {
  628. // current program > count
  629. prog.current = 0;
  630. programChanged = true;
  631. }
  632. else if (prog.current < 0 && prog.count > 0)
  633. {
  634. // programs exist now, but not before
  635. prog.current = 0;
  636. programChanged = true;
  637. }
  638. else if (prog.current >= 0 && prog.count == 0)
  639. {
  640. // programs existed before, but not anymore
  641. prog.current = -1;
  642. programChanged = true;
  643. }
  644. if (programChanged)
  645. {
  646. setProgram(prog.current, true, true, true, true);
  647. }
  648. else
  649. {
  650. // Program was changed during update, re-set it
  651. if (prog.current >= 0)
  652. effect->dispatcher(effect, effSetProgram, 0, prog.current, nullptr, 0.0f);
  653. }
  654. }
  655. }
  656. // -------------------------------------------------------------------
  657. // Plugin processing
  658. void process(float** const inBuffer, float** const outBuffer, const uint32_t frames, const uint32_t framesOffset)
  659. {
  660. uint32_t i, k;
  661. uint32_t midiEventCount = 0;
  662. double aInsPeak[2] = { 0.0 };
  663. double aOutsPeak[2] = { 0.0 };
  664. // reset MIDI
  665. events.numEvents = 0;
  666. midiEvents[0].type = 0;
  667. CARLA_PROCESS_CONTINUE_CHECK;
  668. // --------------------------------------------------------------------------------------------------------
  669. // Input VU
  670. if (aIn.count > 0)
  671. {
  672. if (aIn.count == 1)
  673. {
  674. for (k=0; k < frames; k++)
  675. {
  676. if (abs(inBuffer[0][k]) > aInsPeak[0])
  677. aInsPeak[0] = abs(inBuffer[0][k]);
  678. }
  679. }
  680. else if (aIn.count > 1)
  681. {
  682. for (k=0; k < frames; k++)
  683. {
  684. if (abs(inBuffer[0][k]) > aInsPeak[0])
  685. aInsPeak[0] = abs(inBuffer[0][k]);
  686. if (abs(inBuffer[1][k]) > aInsPeak[1])
  687. aInsPeak[1] = abs(inBuffer[1][k]);
  688. }
  689. }
  690. }
  691. CARLA_PROCESS_CONTINUE_CHECK;
  692. // --------------------------------------------------------------------------------------------------------
  693. // Parameters Input [Automation]
  694. if (param.portCin && m_active && m_activeBefore)
  695. {
  696. bool allNotesOffSent = false;
  697. const CarlaEngineControlEvent* cinEvent;
  698. uint32_t time, nEvents = param.portCin->getEventCount();
  699. for (i=0; i < nEvents; i++)
  700. {
  701. cinEvent = param.portCin->getEvent(i);
  702. if (! cinEvent)
  703. continue;
  704. time = cinEvent->time - framesOffset;
  705. if (time >= frames)
  706. continue;
  707. // Control change
  708. switch (cinEvent->type)
  709. {
  710. case CarlaEngineEventNull:
  711. break;
  712. case CarlaEngineEventControlChange:
  713. {
  714. double value;
  715. // Control backend stuff
  716. if (cinEvent->channel == m_ctrlInChannel)
  717. {
  718. if (MIDI_IS_CONTROL_BREATH_CONTROLLER(cinEvent->controller) && (m_hints & PLUGIN_CAN_DRYWET) > 0)
  719. {
  720. value = cinEvent->value;
  721. setDryWet(value, false, false);
  722. postponeEvent(PluginPostEventParameterChange, PARAMETER_DRYWET, 0, value);
  723. continue;
  724. }
  725. if (MIDI_IS_CONTROL_CHANNEL_VOLUME(cinEvent->controller) && (m_hints & PLUGIN_CAN_VOLUME) > 0)
  726. {
  727. value = cinEvent->value*127/100;
  728. setVolume(value, false, false);
  729. postponeEvent(PluginPostEventParameterChange, PARAMETER_VOLUME, 0, value);
  730. continue;
  731. }
  732. if (MIDI_IS_CONTROL_BALANCE(cinEvent->controller) && (m_hints & PLUGIN_CAN_BALANCE) > 0)
  733. {
  734. double left, right;
  735. value = cinEvent->value/0.5 - 1.0;
  736. if (value < 0.0)
  737. {
  738. left = -1.0;
  739. right = (value*2)+1.0;
  740. }
  741. else if (value > 0.0)
  742. {
  743. left = (value*2)-1.0;
  744. right = 1.0;
  745. }
  746. else
  747. {
  748. left = -1.0;
  749. right = 1.0;
  750. }
  751. setBalanceLeft(left, false, false);
  752. setBalanceRight(right, false, false);
  753. postponeEvent(PluginPostEventParameterChange, PARAMETER_BALANCE_LEFT, 0, left);
  754. postponeEvent(PluginPostEventParameterChange, PARAMETER_BALANCE_RIGHT, 0, right);
  755. continue;
  756. }
  757. }
  758. // Control plugin parameters
  759. for (k=0; k < param.count; k++)
  760. {
  761. if (param.data[k].midiChannel != cinEvent->channel)
  762. continue;
  763. if (param.data[k].midiCC != cinEvent->controller)
  764. continue;
  765. if (param.data[k].type != PARAMETER_INPUT)
  766. continue;
  767. if (param.data[k].hints & PARAMETER_IS_AUTOMABLE)
  768. {
  769. if (param.data[k].hints & PARAMETER_IS_BOOLEAN)
  770. {
  771. value = cinEvent->value < 0.5 ? param.ranges[k].min : param.ranges[k].max;
  772. }
  773. else
  774. {
  775. value = cinEvent->value * (param.ranges[k].max - param.ranges[k].min) + param.ranges[k].min;
  776. if (param.data[k].hints & PARAMETER_IS_INTEGER)
  777. value = rint(value);
  778. }
  779. setParameterValue(k, value, false, false, false);
  780. postponeEvent(PluginPostEventParameterChange, k, 0, value);
  781. }
  782. }
  783. break;
  784. }
  785. case CarlaEngineEventMidiBankChange:
  786. break;
  787. case CarlaEngineEventMidiProgramChange:
  788. if (cinEvent->channel == m_ctrlInChannel)
  789. {
  790. uint32_t progId = rint(cinEvent->value);
  791. if (progId < prog.count)
  792. {
  793. setProgram(progId, false, false, false, false);
  794. postponeEvent(PluginPostEventProgramChange, progId, 0, 0.0);
  795. }
  796. }
  797. break;
  798. case CarlaEngineEventAllSoundOff:
  799. if (cinEvent->channel == m_ctrlInChannel)
  800. {
  801. if (midi.portMin && ! allNotesOffSent)
  802. sendMidiAllNotesOff();
  803. effect->dispatcher(effect, effStopProcess, 0, 0, nullptr, 0.0f);
  804. effect->dispatcher(effect, effMainsChanged, 0, 0, nullptr, 0.0f);
  805. effect->dispatcher(effect, effMainsChanged, 0, 1, nullptr, 0.0f);
  806. effect->dispatcher(effect, effStartProcess, 0, 0, nullptr, 0.0f);
  807. allNotesOffSent = true;
  808. }
  809. break;
  810. case CarlaEngineEventAllNotesOff:
  811. if (cinEvent->channel == m_ctrlInChannel)
  812. {
  813. if (midi.portMin && ! allNotesOffSent)
  814. sendMidiAllNotesOff();
  815. allNotesOffSent = true;
  816. }
  817. break;
  818. }
  819. }
  820. } // End of Parameters Input
  821. CARLA_PROCESS_CONTINUE_CHECK;
  822. // --------------------------------------------------------------------------------------------------------
  823. // MIDI Input
  824. if (midi.portMin && m_active && m_activeBefore)
  825. {
  826. // ----------------------------------------------------------------------------------------------------
  827. // MIDI Input (External)
  828. if (m_ctrlInChannel >= 0 && m_ctrlInChannel < 16)
  829. {
  830. engineMidiLock();
  831. for (i=0; i < MAX_MIDI_EVENTS && midiEventCount < MAX_MIDI_EVENTS; i++)
  832. {
  833. if (extMidiNotes[i].channel < 0)
  834. break;
  835. VstMidiEvent* const midiEvent = &midiEvents[midiEventCount];
  836. memset(midiEvent, 0, sizeof(VstMidiEvent));
  837. midiEvent->type = kVstMidiType;
  838. midiEvent->byteSize = sizeof(VstMidiEvent);
  839. midiEvent->midiData[0] = m_ctrlInChannel + extMidiNotes[i].velo ? MIDI_STATUS_NOTE_ON : MIDI_STATUS_NOTE_OFF;
  840. midiEvent->midiData[1] = extMidiNotes[i].note;
  841. midiEvent->midiData[2] = extMidiNotes[i].velo;
  842. extMidiNotes[i].channel = -1; // mark as invalid
  843. midiEventCount += 1;
  844. }
  845. engineMidiUnlock();
  846. } // End of MIDI Input (External)
  847. CARLA_PROCESS_CONTINUE_CHECK;
  848. // ----------------------------------------------------------------------------------------------------
  849. // MIDI Input (System)
  850. {
  851. const CarlaEngineMidiEvent* minEvent;
  852. uint32_t time, nEvents = midi.portMin->getEventCount();
  853. for (i=0; i < nEvents && midiEventCount < MAX_MIDI_EVENTS; i++)
  854. {
  855. minEvent = midi.portMin->getEvent(i);
  856. if (! minEvent)
  857. continue;
  858. time = minEvent->time - framesOffset;
  859. if (time >= frames)
  860. continue;
  861. uint8_t status = minEvent->data[0];
  862. uint8_t channel = status & 0x0F;
  863. // Fix bad note-off
  864. if (MIDI_IS_STATUS_NOTE_ON(status) && minEvent->data[2] == 0)
  865. status -= 0x10;
  866. VstMidiEvent* const midiEvent = &midiEvents[midiEventCount];
  867. memset(midiEvent, 0, sizeof(VstMidiEvent));
  868. midiEvent->type = kVstMidiType;
  869. midiEvent->byteSize = sizeof(VstMidiEvent);
  870. midiEvent->deltaFrames = minEvent->time;
  871. if (MIDI_IS_STATUS_NOTE_OFF(status))
  872. {
  873. uint8_t note = minEvent->data[1];
  874. midiEvent->midiData[0] = status;
  875. midiEvent->midiData[1] = note;
  876. postponeEvent(PluginPostEventNoteOff, channel, note, 0.0);
  877. }
  878. else if (MIDI_IS_STATUS_NOTE_ON(status))
  879. {
  880. uint8_t note = minEvent->data[1];
  881. uint8_t velo = minEvent->data[2];
  882. midiEvent->midiData[0] = status;
  883. midiEvent->midiData[1] = note;
  884. midiEvent->midiData[2] = velo;
  885. postponeEvent(PluginPostEventNoteOn, channel, note, velo);
  886. }
  887. else if (MIDI_IS_STATUS_POLYPHONIC_AFTERTOUCH(status))
  888. {
  889. uint8_t note = minEvent->data[1];
  890. uint8_t pressure = minEvent->data[2];
  891. midiEvent->midiData[0] = status;
  892. midiEvent->midiData[1] = note;
  893. midiEvent->midiData[2] = pressure;
  894. }
  895. else if (MIDI_IS_STATUS_AFTERTOUCH(status))
  896. {
  897. uint8_t pressure = minEvent->data[1];
  898. midiEvent->midiData[0] = status;
  899. midiEvent->midiData[1] = pressure;
  900. }
  901. else if (MIDI_IS_STATUS_PITCH_WHEEL_CONTROL(status))
  902. {
  903. uint8_t lsb = minEvent->data[1];
  904. uint8_t msb = minEvent->data[2];
  905. midiEvent->midiData[0] = status;
  906. midiEvent->midiData[1] = lsb;
  907. midiEvent->midiData[2] = msb;
  908. }
  909. else
  910. continue;
  911. midiEventCount += 1;
  912. }
  913. } // End of MIDI Input (System)
  914. } // End of MIDI Input
  915. CARLA_PROCESS_CONTINUE_CHECK;
  916. // --------------------------------------------------------------------------------------------------------
  917. // Plugin processing
  918. if (m_active)
  919. {
  920. if (! m_activeBefore)
  921. {
  922. if (midi.portMin && m_ctrlInChannel >= 0 && m_ctrlInChannel < 16)
  923. {
  924. memset(&midiEvents[0], 0, sizeof(VstMidiEvent));
  925. midiEvents[0].type = kVstMidiType;
  926. midiEvents[0].byteSize = sizeof(VstMidiEvent);
  927. midiEvents[0].midiData[0] = MIDI_STATUS_CONTROL_CHANGE + m_ctrlInChannel;
  928. midiEvents[0].midiData[1] = MIDI_CONTROL_ALL_SOUND_OFF;
  929. memset(&midiEvents[1], 0, sizeof(VstMidiEvent));
  930. midiEvents[1].type = kVstMidiType;
  931. midiEvents[1].byteSize = sizeof(VstMidiEvent);
  932. midiEvents[1].midiData[0] = MIDI_STATUS_CONTROL_CHANGE + m_ctrlInChannel;
  933. midiEvents[1].midiData[1] = MIDI_CONTROL_ALL_NOTES_OFF;
  934. midiEventCount = 2;
  935. }
  936. effect->dispatcher(effect, effMainsChanged, 0, 1, nullptr, 0.0f);
  937. effect->dispatcher(effect, effStartProcess, 0, 0, nullptr, 0.0f);
  938. }
  939. if (midiEventCount > 0)
  940. {
  941. events.numEvents = midiEventCount;
  942. events.reserved = 0;
  943. effect->dispatcher(effect, effProcessEvents, 0, 0, &events, 0.0f);
  944. }
  945. // FIXME - make this a global option
  946. // don't process if not needed
  947. //if ((effect->flags & effFlagsNoSoundInStop) > 0 && aInsPeak[0] == 0.0 && aInsPeak[1] == 0.0 && midiEventCount == 0 && ! midi.port_mout)
  948. //{
  949. if (m_hints & PLUGIN_CAN_PROCESS_REPLACING)
  950. {
  951. effect->processReplacing(effect, inBuffer, outBuffer, frames);
  952. }
  953. else
  954. {
  955. for (i=0; i < aOut.count; i++)
  956. memset(outBuffer[i], 0, sizeof(float)*frames);
  957. #if ! VST_FORCE_DEPRECATED
  958. effect->process(effect, inBuffer, outBuffer, frames);
  959. #endif
  960. }
  961. //}
  962. }
  963. else
  964. {
  965. if (m_activeBefore)
  966. {
  967. effect->dispatcher(effect, effStopProcess, 0, 0, nullptr, 0.0f);
  968. effect->dispatcher(effect, effMainsChanged, 0, 0, nullptr, 0.0f);
  969. }
  970. }
  971. CARLA_PROCESS_CONTINUE_CHECK;
  972. // --------------------------------------------------------------------------------------------------------
  973. // Post-processing (dry/wet, volume and balance)
  974. if (m_active)
  975. {
  976. bool do_drywet = (m_hints & PLUGIN_CAN_DRYWET) > 0 && x_dryWet != 1.0;
  977. bool do_volume = (m_hints & PLUGIN_CAN_VOLUME) > 0 && x_volume != 1.0;
  978. bool do_balance = (m_hints & PLUGIN_CAN_BALANCE) > 0 && (x_balanceLeft != -1.0 || x_balanceRight != 1.0);
  979. double bal_rangeL, bal_rangeR;
  980. float oldBufLeft[do_balance ? frames : 0];
  981. for (i=0; i < aOut.count; i++)
  982. {
  983. // Dry/Wet
  984. if (do_drywet)
  985. {
  986. for (k=0; k < frames; k++)
  987. {
  988. if (aOut.count == 1)
  989. outBuffer[i][k] = (outBuffer[i][k]*x_dryWet)+(inBuffer[0][k]*(1.0-x_dryWet));
  990. else
  991. outBuffer[i][k] = (outBuffer[i][k]*x_dryWet)+(inBuffer[i][k]*(1.0-x_dryWet));
  992. }
  993. }
  994. // Balance
  995. if (do_balance)
  996. {
  997. if (i%2 == 0)
  998. memcpy(&oldBufLeft, outBuffer[i], sizeof(float)*frames);
  999. bal_rangeL = (x_balanceLeft+1.0)/2;
  1000. bal_rangeR = (x_balanceRight+1.0)/2;
  1001. for (k=0; k < frames; k++)
  1002. {
  1003. if (i%2 == 0)
  1004. {
  1005. // left output
  1006. outBuffer[i][k] = oldBufLeft[k]*(1.0-bal_rangeL);
  1007. outBuffer[i][k] += outBuffer[i+1][k]*(1.0-bal_rangeR);
  1008. }
  1009. else
  1010. {
  1011. // right
  1012. outBuffer[i][k] = outBuffer[i][k]*bal_rangeR;
  1013. outBuffer[i][k] += oldBufLeft[k]*bal_rangeL;
  1014. }
  1015. }
  1016. }
  1017. // Volume
  1018. if (do_volume)
  1019. {
  1020. for (k=0; k < frames; k++)
  1021. outBuffer[i][k] *= x_volume;
  1022. }
  1023. // Output VU
  1024. for (k=0; i < 2 && k < frames; k++)
  1025. {
  1026. if (abs(outBuffer[i][k]) > aOutsPeak[i])
  1027. aOutsPeak[i] = abs(outBuffer[i][k]);
  1028. }
  1029. }
  1030. }
  1031. else
  1032. {
  1033. // disable any output sound if not active
  1034. for (i=0; i < aOut.count; i++)
  1035. memset(outBuffer[i], 0.0f, sizeof(float)*frames);
  1036. aOutsPeak[0] = 0.0;
  1037. aOutsPeak[1] = 0.0;
  1038. } // End of Post-processing
  1039. CARLA_PROCESS_CONTINUE_CHECK;
  1040. // --------------------------------------------------------------------------------------------------------
  1041. // MIDI Output
  1042. if (midi.portMout && m_active)
  1043. {
  1044. uint8_t data[4] = { 0 };
  1045. for (int32_t i = midiEventCount; i < events.numEvents; i++)
  1046. {
  1047. data[0] = midiEvents[i].midiData[0];
  1048. data[1] = midiEvents[i].midiData[1];
  1049. data[2] = midiEvents[i].midiData[2];
  1050. // Fix bad note-off
  1051. if (MIDI_IS_STATUS_NOTE_ON(data[0]) && data[2] == 0)
  1052. data[0] -= 0x10;
  1053. midi.portMout->writeEvent(midiEvents[i].deltaFrames, data, 3);
  1054. }
  1055. } // End of MIDI Output
  1056. CARLA_PROCESS_CONTINUE_CHECK;
  1057. // --------------------------------------------------------------------------------------------------------
  1058. // Peak Values
  1059. x_engine->setInputPeak(m_id, 0, aInsPeak[0]);
  1060. x_engine->setInputPeak(m_id, 1, aInsPeak[1]);
  1061. x_engine->setOutputPeak(m_id, 0, aOutsPeak[0]);
  1062. x_engine->setOutputPeak(m_id, 1, aOutsPeak[1]);
  1063. m_activeBefore = m_active;
  1064. }
  1065. void bufferSizeChanged(uint32_t newBufferSize)
  1066. {
  1067. if (m_active)
  1068. {
  1069. effect->dispatcher(effect, effStopProcess, 0, 0, nullptr, 0.0f);
  1070. effect->dispatcher(effect, effMainsChanged, 0, 0, nullptr, 0.0f);
  1071. }
  1072. #if ! VST_FORCE_DEPRECATED
  1073. effect->dispatcher(effect, effSetBlockSizeAndSampleRate, 0, newBufferSize, nullptr, x_engine->getSampleRate());
  1074. #endif
  1075. effect->dispatcher(effect, effSetBlockSize, 0, newBufferSize, nullptr, 0.0f);
  1076. if (m_active)
  1077. {
  1078. effect->dispatcher(effect, effMainsChanged, 0, 1, nullptr, 0.0f);
  1079. effect->dispatcher(effect, effStartProcess, 0, 0, nullptr, 0.0f);
  1080. }
  1081. }
  1082. // -------------------------------------------------------------------
  1083. // Post-poned events
  1084. #ifndef BUILD_BRIDGE
  1085. void uiParameterChange(const uint32_t index, const double value)
  1086. {
  1087. Q_ASSERT(index < param.count);
  1088. if (index >= param.count)
  1089. return;
  1090. if (gui.type == GUI_EXTERNAL_OSC && osc.data.target)
  1091. osc_send_control(&osc.data, param.data[index].rindex, value);
  1092. }
  1093. void uiProgramChange(const uint32_t index)
  1094. {
  1095. Q_ASSERT(index < prog.count);
  1096. if (index >= prog.count)
  1097. return;
  1098. if (gui.type == GUI_EXTERNAL_OSC && osc.data.target)
  1099. osc_send_program(&osc.data, index);
  1100. }
  1101. void uiNoteOn(const uint8_t channel, const uint8_t note, const uint8_t velo)
  1102. {
  1103. Q_ASSERT(channel < 16);
  1104. Q_ASSERT(note < 128);
  1105. Q_ASSERT(velo > 0 && velo < 128);
  1106. if (gui.type == GUI_EXTERNAL_OSC && osc.data.target)
  1107. {
  1108. uint8_t midiData[4] = { 0 };
  1109. midiData[1] = MIDI_STATUS_NOTE_ON + channel;
  1110. midiData[2] = note;
  1111. midiData[3] = velo;
  1112. osc_send_midi(&osc.data, midiData);
  1113. }
  1114. }
  1115. void uiNoteOff(const uint8_t channel, const uint8_t note)
  1116. {
  1117. Q_ASSERT(channel < 16);
  1118. Q_ASSERT(note < 128);
  1119. if (gui.type == GUI_EXTERNAL_OSC && osc.data.target)
  1120. {
  1121. uint8_t midiData[4] = { 0 };
  1122. midiData[1] = MIDI_STATUS_NOTE_OFF + channel;
  1123. midiData[2] = note;
  1124. osc_send_midi(&osc.data, midiData);
  1125. }
  1126. }
  1127. #endif
  1128. // -------------------------------------------------------------------
  1129. void handleAudioMasterAutomate(const uint32_t index, const double value)
  1130. {
  1131. //Q_ASSERT(m_enabled);
  1132. Q_ASSERT(index < param.count);
  1133. if (index >= param.count /*|| ! m_enabled*/)
  1134. return;
  1135. if (x_engine->isOnAudioThread() && ! x_engine->isOffline())
  1136. {
  1137. setParameterValue(index, value, false, false, false);
  1138. postponeEvent(PluginPostEventParameterChange, index, 0, value);
  1139. }
  1140. else
  1141. setParameterValue(index, value, true, true, true);
  1142. }
  1143. intptr_t handleAudioMasterGetCurrentProcessLevel()
  1144. {
  1145. if (x_engine->isOffline())
  1146. return kVstProcessLevelOffline;
  1147. if (x_engine->isOnAudioThread())
  1148. return kVstProcessLevelRealtime;
  1149. return kVstProcessLevelUser;
  1150. }
  1151. intptr_t handleAudioMasterGetBlockSize()
  1152. {
  1153. return x_engine->getBufferSize();
  1154. }
  1155. intptr_t handleAudioMasterGetSampleRate()
  1156. {
  1157. return x_engine->getSampleRate();
  1158. }
  1159. const VstTimeInfo_R* handleAudioMasterGetTime()
  1160. {
  1161. static VstTimeInfo_R vstTimeInfo;
  1162. memset(&vstTimeInfo, 0, sizeof(VstTimeInfo_R));
  1163. const CarlaTimeInfo* const timeInfo = x_engine->getTimeInfo();
  1164. vstTimeInfo.flags |= kVstTransportChanged;
  1165. if (timeInfo->playing)
  1166. vstTimeInfo.flags |= kVstTransportPlaying;
  1167. vstTimeInfo.samplePos = timeInfo->frame;
  1168. vstTimeInfo.sampleRate = x_engine->getSampleRate();
  1169. vstTimeInfo.nanoSeconds = timeInfo->time;
  1170. vstTimeInfo.flags |= kVstNanosValid;
  1171. if (timeInfo->valid & CarlaEngineTimeBBT)
  1172. {
  1173. double ppqBar = double(timeInfo->bbt.bar) * timeInfo->bbt.beats_per_bar - timeInfo->bbt.beats_per_bar;
  1174. double ppqBeat = double(timeInfo->bbt.beat) - 1.0;
  1175. double ppqTick = double(timeInfo->bbt.tick) / timeInfo->bbt.ticks_per_beat;
  1176. // Bars
  1177. vstTimeInfo.barStartPos = ppqBar + ppqBeat;
  1178. vstTimeInfo.flags |= kVstBarsValid;
  1179. // PPQ Pos
  1180. vstTimeInfo.ppqPos = ppqBar + ppqBeat + ppqTick;
  1181. vstTimeInfo.flags |= kVstPpqPosValid;
  1182. // Tempo
  1183. vstTimeInfo.tempo = timeInfo->bbt.beats_per_minute;
  1184. vstTimeInfo.flags |= kVstTempoValid;
  1185. // Time Signature
  1186. vstTimeInfo.timeSigNumerator = timeInfo->bbt.beats_per_bar;
  1187. vstTimeInfo.timeSigDenominator = timeInfo->bbt.beat_type;
  1188. vstTimeInfo.flags |= kVstTimeSigValid;
  1189. }
  1190. return &vstTimeInfo;
  1191. }
  1192. intptr_t handleAudioMasterIOChanged()
  1193. {
  1194. Q_ASSERT(m_enabled);
  1195. // TESTING
  1196. qWarning("audioMasterIOChanged called!");
  1197. if (! m_enabled)
  1198. return 1;
  1199. //carla_proc_lock();
  1200. //self->m_enabled = false;
  1201. //carla_proc_unlock();
  1202. //if (self->m_active)
  1203. //{
  1204. // self->effect->dispatcher(self->effect, effStopProcess, 0, 0, nullptr, 0.0f);
  1205. // self->effect->dispatcher(self->effect, effMainsChanged, 0, 0, nullptr, 0.0f);
  1206. //}
  1207. //self->reload();
  1208. //if (self->m_active)
  1209. //{
  1210. // self->effect->dispatcher(self->effect, effMainsChanged, 0, 1, nullptr, 0.0f);
  1211. // self->effect->dispatcher(self->effect, effStartProcess, 0, 0, nullptr, 0.0f);
  1212. //}
  1213. //callback_action(CALLBACK_RELOAD_ALL, self->m_id, 0, 0, 0.0);
  1214. return 0; // FIXME - set as 1 when supported
  1215. }
  1216. intptr_t handleAudioMasterProcessEvents(const VstEvents* const vstEvents)
  1217. {
  1218. Q_ASSERT(m_enabled);
  1219. if (! m_enabled)
  1220. return 0;
  1221. if (! midi.portMout)
  1222. return 0;
  1223. if (! x_engine->isOnAudioThread())
  1224. {
  1225. qCritical("VstPlugin:handleAudioMasterProcessEvents(%p) - received MIDI out events outside audio thread, ignoring", vstEvents);
  1226. return 0;
  1227. }
  1228. for (int32_t i=0; i < vstEvents->numEvents && events.numEvents < MAX_MIDI_EVENTS*2; i++)
  1229. {
  1230. if (! vstEvents->events[i])
  1231. break;
  1232. const VstMidiEvent* const vstMidiEvent = (const VstMidiEvent*)vstEvents->events[i];
  1233. if (vstMidiEvent->type != kVstMidiType)
  1234. memcpy(&midiEvents[events.numEvents++], vstMidiEvent, sizeof(VstMidiEvent));
  1235. }
  1236. return 1;
  1237. }
  1238. intptr_t handleAudioMasterTempoAt()
  1239. {
  1240. const CarlaTimeInfo* const timeInfo = x_engine->getTimeInfo();
  1241. if (timeInfo->valid & CarlaEngineTimeBBT)
  1242. return timeInfo->bbt.beats_per_minute * 10000;
  1243. return 0;
  1244. }
  1245. intptr_t handleAdioMasterSizeWindow(int32_t width, int32_t height)
  1246. {
  1247. gui.width = width;
  1248. gui.height = height;
  1249. x_engine->callback(CALLBACK_RESIZE_GUI, m_id, width, height, 0.0);
  1250. return 1;
  1251. }
  1252. void handleAudioMasterUpdateDisplay()
  1253. {
  1254. // Update current program name
  1255. if (prog.count > 0 && prog.current >= 0)
  1256. {
  1257. const int32_t index = prog.current;
  1258. char strBuf[STR_MAX] = { 0 };
  1259. effect->dispatcher(effect, effGetProgramName, 0, 0, strBuf, 0.0f);
  1260. if (! prog.names[index])
  1261. {
  1262. prog.names[index] = strdup(strBuf);
  1263. }
  1264. else if (strBuf[0] != 0 && strcmp(strBuf, prog.names[index]) != 0)
  1265. {
  1266. free((void*)prog.names[index]);
  1267. prog.names[index] = strdup(strBuf);
  1268. }
  1269. }
  1270. // Tell backend to update
  1271. x_engine->callback(CALLBACK_UPDATE, m_id, 0, 0, 0.0);
  1272. }
  1273. void handleAudioMasterWantMidi()
  1274. {
  1275. m_hints |= PLUGIN_WANTS_MIDI_INPUT;
  1276. }
  1277. // -------------------------------------------------------------------
  1278. static intptr_t hostCanDo(const char* const feature)
  1279. {
  1280. qDebug("VstPlugin::hostCanDo(\"%s\")", feature);
  1281. if (strcmp(feature, "supplyIdle") == 0)
  1282. return 1;
  1283. if (strcmp(feature, "sendVstEvents") == 0)
  1284. return 1;
  1285. if (strcmp(feature, "sendVstMidiEvent") == 0)
  1286. return 1;
  1287. if (strcmp(feature, "sendVstMidiEventFlagIsRealtime") == 0)
  1288. return -1;
  1289. if (strcmp(feature, "sendVstTimeInfo") == 0)
  1290. return 1;
  1291. if (strcmp(feature, "receiveVstEvents") == 0)
  1292. return 1;
  1293. if (strcmp(feature, "receiveVstMidiEvent") == 0)
  1294. return 1;
  1295. if (strcmp(feature, "receiveVstTimeInfo") == 0)
  1296. return -1;
  1297. if (strcmp(feature, "reportConnectionChanges") == 0)
  1298. return -1;
  1299. if (strcmp(feature, "acceptIOChanges") == 0)
  1300. return 1;
  1301. if (strcmp(feature, "sizeWindow") == 0)
  1302. return 1;
  1303. if (strcmp(feature, "offline") == 0)
  1304. return -1;
  1305. if (strcmp(feature, "openFileSelector") == 0)
  1306. return -1;
  1307. if (strcmp(feature, "closeFileSelector") == 0)
  1308. return -1;
  1309. if (strcmp(feature, "startStopProcess") == 0)
  1310. return 1;
  1311. if (strcmp(feature, "supportShell") == 0)
  1312. return -1;
  1313. if (strcmp(feature, "shellCategory") == 0)
  1314. return -1;
  1315. // unimplemented
  1316. qWarning("VstPlugin::hostCanDo(\"%s\") - unknown feature", feature);
  1317. return 0;
  1318. }
  1319. static intptr_t VSTCALLBACK hostCallback(AEffect* const effect, const int32_t opcode, const int32_t index, const intptr_t value, void* const ptr, const float opt)
  1320. {
  1321. #ifdef DEBUG
  1322. if (opcode != audioMasterGetTime)
  1323. qDebug("VstPlugin::hostCallback(%p, %s, %i, " P_INTPTR ", %p, %f", effect, vstMasterOpcode2str(opcode), index, value, ptr, opt);
  1324. #endif
  1325. #if 0
  1326. // Cockos VST extensions
  1327. if (/*effect &&*/ ptr && (uint32_t)opcode == 0xdeadbeef && (uint32_t)index == 0xdeadf00d)
  1328. {
  1329. const char* const func = (char*)ptr;
  1330. if (strcmp(func, "GetPlayPosition") == 0)
  1331. return 0;
  1332. if (strcmp(func, "GetPlayPosition2") == 0)
  1333. return 0;
  1334. if (strcmp(func, "GetCursorPosition") == 0)
  1335. return 0;
  1336. if (strcmp(func, "GetPlayState") == 0)
  1337. return 0;
  1338. if (strcmp(func, "SetEditCurPos") == 0)
  1339. return 0;
  1340. if (strcmp(func, "GetSetRepeat") == 0)
  1341. return 0;
  1342. if (strcmp(func, "GetProjectPath") == 0)
  1343. return 0;
  1344. if (strcmp(func, "OnPlayButton") == 0)
  1345. return 0;
  1346. if (strcmp(func, "OnStopButton") == 0)
  1347. return 0;
  1348. if (strcmp(func, "OnPauseButton") == 0)
  1349. return 0;
  1350. if (strcmp(func, "IsInRealTimeAudio") == 0)
  1351. return 0;
  1352. if (strcmp(func, "Audio_IsRunning") == 0)
  1353. return 0;
  1354. }
  1355. #endif
  1356. // Check if 'resvd1' points to this plugin
  1357. VstPlugin* self = nullptr;
  1358. #ifdef VESTIGE_HEADER
  1359. if (effect && effect->ptr1)
  1360. {
  1361. self = (VstPlugin*)effect->ptr1;
  1362. #else
  1363. if (effect && effect->resvd1)
  1364. {
  1365. //self = (VstPlugin*)getPointer(effect->resvd1);
  1366. //self = (VstPlugin*)effect->resvd1;
  1367. #endif
  1368. //if (self->unique1 != self->unique2)
  1369. // self = nullptr;
  1370. }
  1371. intptr_t ret = 0;
  1372. switch (opcode)
  1373. {
  1374. case audioMasterAutomate:
  1375. if (self)
  1376. self->handleAudioMasterAutomate(index, opt);
  1377. break;
  1378. case audioMasterVersion:
  1379. ret = kVstVersion;
  1380. break;
  1381. case audioMasterCurrentId:
  1382. // TODO
  1383. break;
  1384. case audioMasterIdle:
  1385. //if (effect)
  1386. // effect->dispatcher(effect, effEditIdle, 0, 0, nullptr, 0.0f);
  1387. break;
  1388. #if ! VST_FORCE_DEPRECATED
  1389. case audioMasterPinConnected:
  1390. // Deprecated in VST SDK 2.4
  1391. // TODO
  1392. break;
  1393. case audioMasterWantMidi:
  1394. // Deprecated in VST SDK 2.4
  1395. if (self)
  1396. self->handleAudioMasterWantMidi();
  1397. break;
  1398. #endif
  1399. case audioMasterGetTime:
  1400. if (self)
  1401. {
  1402. ret = (intptr_t)self->handleAudioMasterGetTime();
  1403. }
  1404. else
  1405. {
  1406. static VstTimeInfo_R timeInfo;
  1407. memset(&timeInfo, 0, sizeof(VstTimeInfo_R));
  1408. timeInfo.sampleRate = 44100.0;
  1409. // Tempo
  1410. timeInfo.tempo = 120.0;
  1411. timeInfo.flags |= kVstTempoValid;
  1412. // Time Signature
  1413. timeInfo.timeSigNumerator = 4;
  1414. timeInfo.timeSigDenominator = 4;
  1415. timeInfo.flags |= kVstTimeSigValid;
  1416. ret = (intptr_t)&timeInfo;
  1417. }
  1418. break;
  1419. case audioMasterProcessEvents:
  1420. if (self && ptr)
  1421. ret = self->handleAudioMasterProcessEvents((const VstEvents*)ptr);
  1422. break;
  1423. #if ! VST_FORCE_DEPRECATED
  1424. case audioMasterSetTime:
  1425. // Deprecated in VST SDK 2.4
  1426. break;
  1427. case audioMasterTempoAt:
  1428. // Deprecated in VST SDK 2.4
  1429. if (self)
  1430. ret = self->handleAudioMasterTempoAt();
  1431. if (ret == 0)
  1432. ret = 120 * 10000;
  1433. break;
  1434. case audioMasterGetNumAutomatableParameters:
  1435. // Deprecated in VST SDK 2.4
  1436. #ifdef BUILD_BRIDGE
  1437. ret = MAX_PARAMETERS;
  1438. #else
  1439. ret = carlaOptions.maxParameters;
  1440. #endif
  1441. break;
  1442. case audioMasterGetParameterQuantization:
  1443. // Deprecated in VST SDK 2.4
  1444. // TODO
  1445. break;
  1446. #endif
  1447. case audioMasterIOChanged:
  1448. if (self)
  1449. ret = self->handleAudioMasterIOChanged();
  1450. break;
  1451. case audioMasterNeedIdle:
  1452. // Deprecated in VST SDK 2.4
  1453. // TODO
  1454. break;
  1455. case audioMasterSizeWindow:
  1456. if (self && index > 0 && value > 0)
  1457. ret = self->handleAdioMasterSizeWindow(index, value);
  1458. break;
  1459. case audioMasterGetSampleRate:
  1460. if (self)
  1461. ret = self->handleAudioMasterGetSampleRate();
  1462. else
  1463. ret = 44100;
  1464. break;
  1465. case audioMasterGetBlockSize:
  1466. if (self)
  1467. ret = self->handleAudioMasterGetBlockSize();
  1468. else
  1469. ret = 512;
  1470. break;
  1471. case audioMasterGetInputLatency:
  1472. // TODO
  1473. break;
  1474. case audioMasterGetOutputLatency:
  1475. // TODO
  1476. break;
  1477. #if ! VST_FORCE_DEPRECATED
  1478. case audioMasterGetPreviousPlug:
  1479. // Deprecated in VST SDK 2.4
  1480. // TODO
  1481. break;
  1482. case audioMasterGetNextPlug:
  1483. // Deprecated in VST SDK 2.4
  1484. // TODO
  1485. break;
  1486. case audioMasterWillReplaceOrAccumulate:
  1487. // Deprecated in VST SDK 2.4
  1488. break;
  1489. #endif
  1490. case audioMasterGetCurrentProcessLevel:
  1491. if (self)
  1492. ret = self->handleAudioMasterGetCurrentProcessLevel();
  1493. else
  1494. ret = kVstProcessLevelUnknown;
  1495. break;
  1496. case audioMasterGetAutomationState:
  1497. ret = kVstAutomationReadWrite;
  1498. break;
  1499. case audioMasterOfflineStart:
  1500. case audioMasterOfflineRead:
  1501. case audioMasterOfflineWrite:
  1502. case audioMasterOfflineGetCurrentPass:
  1503. case audioMasterOfflineGetCurrentMetaPass:
  1504. // TODO
  1505. break;
  1506. #if ! VST_FORCE_DEPRECATED
  1507. case audioMasterSetOutputSampleRate:
  1508. // Deprecated in VST SDK 2.4
  1509. break;
  1510. #ifdef VESTIGE_HEADER
  1511. case audioMasterGetSpeakerArrangement:
  1512. #else
  1513. case audioMasterGetOutputSpeakerArrangement:
  1514. #endif
  1515. // Deprecated in VST SDK 2.4
  1516. // TODO
  1517. break;
  1518. #endif
  1519. case audioMasterGetVendorString:
  1520. if (ptr)
  1521. strcpy((char*)ptr, "falkTX");
  1522. break;
  1523. case audioMasterGetProductString:
  1524. if (ptr)
  1525. strcpy((char*)ptr, "Carla");
  1526. break;
  1527. case audioMasterGetVendorVersion:
  1528. ret = 0x050; // 0.5.0
  1529. break;
  1530. case audioMasterVendorSpecific:
  1531. // TODO - cockos extensions
  1532. break;
  1533. #if ! VST_FORCE_DEPRECATED
  1534. case audioMasterSetIcon:
  1535. // Deprecated in VST SDK 2.4
  1536. break;
  1537. #endif
  1538. case audioMasterCanDo:
  1539. if (ptr)
  1540. ret = hostCanDo((const char*)ptr);
  1541. break;
  1542. case audioMasterGetLanguage:
  1543. ret = kVstLangEnglish;
  1544. break;
  1545. #if ! VST_FORCE_DEPRECATED
  1546. case audioMasterOpenWindow:
  1547. case audioMasterCloseWindow:
  1548. // Deprecated in VST SDK 2.4
  1549. // TODO
  1550. break;
  1551. #endif
  1552. case audioMasterGetDirectory:
  1553. // TODO
  1554. break;
  1555. case audioMasterUpdateDisplay:
  1556. if (self)
  1557. self->handleAudioMasterUpdateDisplay();
  1558. break;
  1559. case audioMasterBeginEdit:
  1560. case audioMasterEndEdit:
  1561. // TODO
  1562. break;
  1563. case audioMasterOpenFileSelector:
  1564. case audioMasterCloseFileSelector:
  1565. // TODO
  1566. break;
  1567. #if ! VST_FORCE_DEPRECATED
  1568. case audioMasterEditFile:
  1569. // Deprecated in VST SDK 2.4
  1570. // TODO
  1571. break;
  1572. case audioMasterGetChunkFile:
  1573. // Deprecated in VST SDK 2.4
  1574. // TODO
  1575. break;
  1576. case audioMasterGetInputSpeakerArrangement:
  1577. // Deprecated in VST SDK 2.4
  1578. // TODO
  1579. break;
  1580. #endif
  1581. default:
  1582. #ifdef DEBUG
  1583. qDebug("VstPlugin::hostCallback(%p, %s, %i, " P_INTPTR ", %p, %f", effect, vstMasterOpcode2str(opcode), index, value, ptr, opt);
  1584. #endif
  1585. break;
  1586. }
  1587. return ret;
  1588. }
  1589. // -------------------------------------------------------------------
  1590. bool init(const char* const filename, const char* const name, const char* const label)
  1591. {
  1592. // ---------------------------------------------------------------
  1593. // open DLL
  1594. if (! libOpen(filename))
  1595. {
  1596. setLastError(libError(filename));
  1597. return false;
  1598. }
  1599. // ---------------------------------------------------------------
  1600. // get DLL main entry
  1601. VST_Function vstFn = (VST_Function)libSymbol("VSTPluginMain");
  1602. if (! vstFn)
  1603. {
  1604. vstFn = (VST_Function)libSymbol("main");
  1605. if (! vstFn)
  1606. {
  1607. setLastError("Could not find the VST main entry in the plugin library");
  1608. return false;
  1609. }
  1610. }
  1611. // ---------------------------------------------------------------
  1612. // initialize plugin
  1613. effect = vstFn(hostCallback);
  1614. if ((! effect) || effect->magic != kEffectMagic)
  1615. {
  1616. setLastError("Plugin failed to initialize");
  1617. return false;
  1618. }
  1619. // ---------------------------------------------------------------
  1620. // get info
  1621. m_filename = strdup(filename);
  1622. if (name)
  1623. {
  1624. m_name = x_engine->getUniqueName(name);
  1625. }
  1626. else
  1627. {
  1628. char strBuf[STR_MAX] = { 0 };
  1629. effect->dispatcher(effect, effGetEffectName, 0, 0, strBuf, 0.0f);
  1630. if (strBuf[0] != 0)
  1631. m_name = x_engine->getUniqueName(strBuf);
  1632. else
  1633. m_name = x_engine->getUniqueName(label);
  1634. }
  1635. // ---------------------------------------------------------------
  1636. // initialize VST stuff
  1637. effect->dispatcher(effect, effOpen, 0, 0, nullptr, 0.0f);
  1638. #if ! VST_FORCE_DEPRECATED
  1639. effect->dispatcher(effect, effSetBlockSizeAndSampleRate, 0, x_engine->getBufferSize(), nullptr, x_engine->getSampleRate());
  1640. #endif
  1641. effect->dispatcher(effect, effSetSampleRate, 0, 0, nullptr, x_engine->getSampleRate());
  1642. effect->dispatcher(effect, effSetBlockSize, 0, x_engine->getBufferSize(), nullptr, 0.0f);
  1643. effect->dispatcher(effect, effSetProcessPrecision, 0, kVstProcessPrecision32, nullptr, 0.0f);
  1644. #ifdef VESTIGE_HEADER
  1645. effect->ptr1 = this;
  1646. #else
  1647. effect->resvd1 = (intptr_t)this;
  1648. #endif
  1649. #if ! VST_FORCE_DEPRECATED
  1650. // dummy pre-start to catch possible wantEvents() call on old plugins
  1651. effect->dispatcher(effect, effStartProcess, 0, 0, nullptr, 0.0f);
  1652. effect->dispatcher(effect, effStopProcess, 0, 0, nullptr, 0.0f);
  1653. #endif
  1654. // special checks
  1655. if (effect->dispatcher(effect, effCanDo, 0, 0, (void*)"hasCockosExtensions", 0.0f) == 0xbeef0000)
  1656. m_hints |= PLUGIN_HAS_COCKOS_EXTENSIONS;
  1657. if (effect->dispatcher(effect, effGetVstVersion, 0, 0, nullptr, 0.0f) < kVstVersion)
  1658. m_hints |= PLUGIN_USES_OLD_VSTSDK;
  1659. if ((effect->flags & effFlagsCanReplacing) > 0 && effect->processReplacing != effect->process)
  1660. m_hints |= PLUGIN_CAN_PROCESS_REPLACING;
  1661. // ---------------------------------------------------------------
  1662. // register client
  1663. x_client = x_engine->addClient(this);
  1664. if (! x_client->isOk())
  1665. {
  1666. setLastError("Failed to register plugin client");
  1667. return false;
  1668. }
  1669. // ---------------------------------------------------------------
  1670. // gui stuff
  1671. if (effect->flags & effFlagsHasEditor)
  1672. {
  1673. m_hints |= PLUGIN_HAS_GUI;
  1674. #if defined(Q_OS_LINUX) && ! defined(BUILD_BRIDGE)
  1675. if (carlaOptions.bridge_vstx11 && carlaOptions.preferUiBridges && ! (effect->flags & effFlagsProgramChunks))
  1676. {
  1677. osc.thread = new CarlaPluginThread(x_engine, this, CarlaPluginThread::PLUGIN_THREAD_VST_GUI);
  1678. osc.thread->setOscData(carlaOptions.bridge_vstx11, label);
  1679. gui.type = GUI_EXTERNAL_OSC;
  1680. }
  1681. else
  1682. #endif
  1683. {
  1684. m_hints |= PLUGIN_USES_SINGLE_THREAD;
  1685. #if defined(Q_OS_WIN)
  1686. gui.type = GUI_INTERNAL_HWND;
  1687. #elif defined(Q_OS_MACOS)
  1688. gui.type = GUI_INTERNAL_COCOA;
  1689. #elif defined(Q_OS_LINUX)
  1690. gui.type = GUI_INTERNAL_X11;
  1691. #else
  1692. m_hints &= ~PLUGIN_HAS_GUI;
  1693. #endif
  1694. }
  1695. }
  1696. return true;
  1697. }
  1698. private:
  1699. int unique1;
  1700. AEffect* effect;
  1701. struct {
  1702. int32_t numEvents;
  1703. intptr_t reserved;
  1704. VstEvent* data[MAX_MIDI_EVENTS*2];
  1705. } events;
  1706. VstMidiEvent midiEvents[MAX_MIDI_EVENTS*2];
  1707. struct {
  1708. GuiType type;
  1709. bool visible;
  1710. int width;
  1711. int height;
  1712. } gui;
  1713. int unique2;
  1714. };
  1715. CarlaPlugin* CarlaPlugin::newVST(const initializer& init)
  1716. {
  1717. qDebug("CarlaPlugin::newVST(%p, \"%s\", \"%s\", \"%s\")", init.engine, init.filename, init.name, init.label);
  1718. short id = init.engine->getNewPluginId();
  1719. if (id < 0 || id > MAX_PLUGINS)
  1720. {
  1721. setLastError("Maximum number of plugins reached");
  1722. return nullptr;
  1723. }
  1724. VstPlugin* const plugin = new VstPlugin(init.engine, id);
  1725. if (! plugin->init(init.filename, init.name, init.label))
  1726. {
  1727. delete plugin;
  1728. return nullptr;
  1729. }
  1730. plugin->reload();
  1731. #ifndef BUILD_BRIDGE
  1732. if (carlaOptions.processMode == PROCESS_MODE_CONTINUOUS_RACK)
  1733. {
  1734. const uint32_t ins = plugin->audioInCount();
  1735. const uint32_t outs = plugin->audioOutCount();
  1736. const bool stereoInput = ins == 0 || ins == 2;
  1737. const bool stereoOutput = outs == 0 || outs == 2;
  1738. if (! (stereoInput && stereoOutput))
  1739. {
  1740. setLastError("Carla's rack mode can only work with Stereo VST plugins, sorry!");
  1741. delete plugin;
  1742. return nullptr;
  1743. }
  1744. }
  1745. #endif
  1746. plugin->registerToOsc();
  1747. return plugin;
  1748. }
  1749. /**@}*/
  1750. CARLA_BACKEND_END_NAMESPACE