Audio plugin host https://kx.studio/carla
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2593 lines
87KB

  1. /*
  2. * Carla VST Plugin
  3. * Copyright (C) 2011-2014 Filipe Coelho <falktx@falktx.com>
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License as
  7. * published by the Free Software Foundation; either version 2 of
  8. * the License, or any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * For a full copy of the GNU General Public License see the doc/GPL.txt file.
  16. */
  17. #include "CarlaPluginInternal.hpp"
  18. #include "CarlaEngine.hpp"
  19. #if defined(CARLA_OS_MAC) || defined(CARLA_OS_WIN)
  20. # define USE_JUCE_FOR_VST
  21. #endif
  22. #ifndef USE_JUCE_FOR_VST
  23. #include "CarlaVstUtils.hpp"
  24. #include "CarlaMathUtils.hpp"
  25. #include "CarlaPluginUI.hpp"
  26. #include "juce_core.h"
  27. #include <pthread.h>
  28. #undef VST_FORCE_DEPRECATED
  29. #define VST_FORCE_DEPRECATED 0
  30. using juce::File;
  31. CARLA_BACKEND_START_NAMESPACE
  32. // -----------------------------------------------------
  33. const uint PLUGIN_CAN_PROCESS_REPLACING = 0x1000;
  34. const uint PLUGIN_HAS_COCKOS_EXTENSIONS = 0x2000;
  35. const uint PLUGIN_USES_OLD_VSTSDK = 0x4000;
  36. const uint PLUGIN_WANTS_MIDI_INPUT = 0x8000;
  37. // -----------------------------------------------------
  38. class VstPlugin : public CarlaPlugin,
  39. CarlaPluginUI::CloseCallback
  40. {
  41. public:
  42. VstPlugin(CarlaEngine* const engine, const uint id)
  43. : CarlaPlugin(engine, id),
  44. fUnique1(1),
  45. fEffect(nullptr),
  46. fMidiEventCount(0),
  47. fTimeInfo(),
  48. fNeedIdle(false),
  49. fLastChunk(nullptr),
  50. fIsProcessing(false),
  51. #ifdef PTW32_DLLPORT
  52. fProcThread({nullptr, 0}),
  53. #else
  54. fProcThread(0),
  55. #endif
  56. fEvents(),
  57. fUI(),
  58. fUnique2(2),
  59. leakDetector_VstPlugin()
  60. {
  61. carla_debug("VstPlugin::VstPlugin(%p, %i)", engine, id);
  62. carla_zeroStruct<VstMidiEvent>(fMidiEvents, kPluginMaxMidiEvents*2);
  63. carla_zeroStruct<VstTimeInfo>(fTimeInfo);
  64. for (ushort i=0; i < kPluginMaxMidiEvents*2; ++i)
  65. fEvents.data[i] = (VstEvent*)&fMidiEvents[i];
  66. pData->osc.thread.setMode(CarlaPluginThread::PLUGIN_THREAD_VST_GUI);
  67. #ifdef CARLA_OS_WIN
  68. fProcThread.p = nullptr;
  69. fProcThread.x = 0;
  70. #else
  71. fProcThread = 0;
  72. #endif
  73. // make plugin valid
  74. srand(id);
  75. fUnique1 = fUnique2 = rand();
  76. }
  77. ~VstPlugin() override
  78. {
  79. carla_debug("VstPlugin::~VstPlugin()");
  80. // close UI
  81. if (pData->hints & PLUGIN_HAS_CUSTOM_UI)
  82. {
  83. showCustomUI(false);
  84. if (fUI.type == UI::UI_OSC)
  85. pData->osc.thread.stopThread(static_cast<int>(pData->engine->getOptions().uiBridgesTimeout * 2));
  86. }
  87. pData->singleMutex.lock();
  88. pData->masterMutex.lock();
  89. if (pData->client != nullptr && pData->client->isActive())
  90. pData->client->deactivate();
  91. CARLA_ASSERT(! fIsProcessing);
  92. if (pData->active)
  93. {
  94. deactivate();
  95. pData->active = false;
  96. }
  97. if (fEffect != nullptr)
  98. {
  99. dispatcher(effClose, 0, 0, nullptr, 0.0f);
  100. fEffect = nullptr;
  101. }
  102. // make plugin invalid
  103. fUnique2 += 1;
  104. if (fLastChunk != nullptr)
  105. {
  106. std::free(fLastChunk);
  107. fLastChunk = nullptr;
  108. }
  109. clearBuffers();
  110. }
  111. // -------------------------------------------------------------------
  112. // Information (base)
  113. PluginType getType() const noexcept override
  114. {
  115. return PLUGIN_VST;
  116. }
  117. PluginCategory getCategory() const noexcept override
  118. {
  119. CARLA_SAFE_ASSERT_RETURN(fEffect != nullptr, CarlaPlugin::getCategory());
  120. const intptr_t category(dispatcher(effGetPlugCategory, 0, 0, nullptr, 0.0f));
  121. switch (category)
  122. {
  123. case kPlugCategSynth:
  124. return PLUGIN_CATEGORY_SYNTH;
  125. case kPlugCategAnalysis:
  126. return PLUGIN_CATEGORY_UTILITY;
  127. case kPlugCategMastering:
  128. return PLUGIN_CATEGORY_DYNAMICS;
  129. case kPlugCategRoomFx:
  130. return PLUGIN_CATEGORY_DELAY;
  131. case kPlugCategRestoration:
  132. return PLUGIN_CATEGORY_UTILITY;
  133. case kPlugCategGenerator:
  134. return PLUGIN_CATEGORY_SYNTH;
  135. }
  136. if (fEffect->flags & effFlagsIsSynth)
  137. return PLUGIN_CATEGORY_SYNTH;
  138. return CarlaPlugin::getCategory();
  139. }
  140. int64_t getUniqueId() const noexcept override
  141. {
  142. CARLA_SAFE_ASSERT_RETURN(fEffect != nullptr, 0);
  143. return static_cast<int64_t>(fEffect->uniqueID);
  144. }
  145. // -------------------------------------------------------------------
  146. // Information (count)
  147. // nothing
  148. // -------------------------------------------------------------------
  149. // Information (current data)
  150. std::size_t getChunkData(void** const dataPtr) noexcept override
  151. {
  152. CARLA_SAFE_ASSERT_RETURN(pData->options & PLUGIN_OPTION_USE_CHUNKS, 0);
  153. CARLA_SAFE_ASSERT_RETURN(fEffect != nullptr, 0);
  154. CARLA_SAFE_ASSERT_RETURN(dataPtr != nullptr, 0);
  155. *dataPtr = nullptr;
  156. try {
  157. const intptr_t ret = dispatcher(effGetChunk, 0 /* bank */, 0, dataPtr, 0.0f);
  158. CARLA_SAFE_ASSERT_RETURN(ret >= 0, 0);
  159. return static_cast<std::size_t>(ret);
  160. } CARLA_SAFE_EXCEPTION_RETURN("VstPlugin::getChunkData", 0);
  161. }
  162. // -------------------------------------------------------------------
  163. // Information (per-plugin data)
  164. uint getOptionsAvailable() const noexcept override
  165. {
  166. CARLA_SAFE_ASSERT_RETURN(fEffect != nullptr, 0);
  167. uint options = 0x0;
  168. options |= PLUGIN_OPTION_MAP_PROGRAM_CHANGES;
  169. if (fEffect->flags & effFlagsProgramChunks)
  170. options |= PLUGIN_OPTION_USE_CHUNKS;
  171. if (getMidiInCount() == 0)
  172. {
  173. options |= PLUGIN_OPTION_FIXED_BUFFERS;
  174. }
  175. else
  176. {
  177. options |= PLUGIN_OPTION_SEND_CONTROL_CHANGES;
  178. options |= PLUGIN_OPTION_SEND_CHANNEL_PRESSURE;
  179. options |= PLUGIN_OPTION_SEND_NOTE_AFTERTOUCH;
  180. options |= PLUGIN_OPTION_SEND_PITCHBEND;
  181. options |= PLUGIN_OPTION_SEND_ALL_SOUND_OFF;
  182. }
  183. return options;
  184. }
  185. float getParameterValue(const uint32_t parameterId) const noexcept override
  186. {
  187. CARLA_SAFE_ASSERT_RETURN(fEffect != nullptr, 0.0f);
  188. CARLA_SAFE_ASSERT_RETURN(parameterId < pData->param.count, 0.0f);
  189. return fEffect->getParameter(fEffect, static_cast<int32_t>(parameterId));
  190. }
  191. void getLabel(char* const strBuf) const noexcept override
  192. {
  193. CARLA_SAFE_ASSERT_RETURN(fEffect != nullptr,);
  194. strBuf[0] = '\0';
  195. dispatcher(effGetProductString, 0, 0, strBuf, 0.0f);
  196. }
  197. void getMaker(char* const strBuf) const noexcept override
  198. {
  199. CARLA_SAFE_ASSERT_RETURN(fEffect != nullptr,);
  200. strBuf[0] = '\0';
  201. dispatcher(effGetVendorString, 0, 0, strBuf, 0.0f);
  202. }
  203. void getCopyright(char* const strBuf) const noexcept override
  204. {
  205. getMaker(strBuf);
  206. }
  207. void getRealName(char* const strBuf) const noexcept override
  208. {
  209. CARLA_SAFE_ASSERT_RETURN(fEffect != nullptr,);
  210. strBuf[0] = '\0';
  211. dispatcher(effGetEffectName, 0, 0, strBuf, 0.0f);
  212. }
  213. void getParameterName(const uint32_t parameterId, char* const strBuf) const noexcept override
  214. {
  215. CARLA_SAFE_ASSERT_RETURN(fEffect != nullptr,);
  216. CARLA_SAFE_ASSERT_RETURN(parameterId < pData->param.count,);
  217. strBuf[0] = '\0';
  218. dispatcher(effGetParamName, static_cast<int32_t>(parameterId), 0, strBuf, 0.0f);
  219. }
  220. void getParameterText(const uint32_t parameterId, char* const strBuf) const noexcept override
  221. {
  222. CARLA_SAFE_ASSERT_RETURN(fEffect != nullptr,);
  223. CARLA_SAFE_ASSERT_RETURN(parameterId < pData->param.count,);
  224. strBuf[0] = '\0';
  225. dispatcher(effGetParamDisplay, static_cast<int32_t>(parameterId), 0, strBuf, 0.0f);
  226. if (strBuf[0] == '\0')
  227. std::snprintf(strBuf, STR_MAX, "%f", getParameterValue(parameterId));
  228. }
  229. void getParameterUnit(const uint32_t parameterId, char* const strBuf) const noexcept override
  230. {
  231. CARLA_SAFE_ASSERT_RETURN(fEffect != nullptr,);
  232. CARLA_SAFE_ASSERT_RETURN(parameterId < pData->param.count,);
  233. strBuf[0] = '\0';
  234. dispatcher(effGetParamLabel, static_cast<int32_t>(parameterId), 0, strBuf, 0.0f);
  235. }
  236. // -------------------------------------------------------------------
  237. // Set data (state)
  238. // nothing
  239. // -------------------------------------------------------------------
  240. // Set data (internal stuff)
  241. void setName(const char* const newName) override
  242. {
  243. CarlaPlugin::setName(newName);
  244. if (fUI.window != nullptr)
  245. {
  246. CarlaString guiTitle(pData->name);
  247. guiTitle += " (GUI)";
  248. fUI.window->setTitle(guiTitle.buffer());
  249. }
  250. }
  251. // -------------------------------------------------------------------
  252. // Set data (plugin-specific stuff)
  253. void setParameterValue(const uint32_t parameterId, const float value, const bool sendGui, const bool sendOsc, const bool sendCallback) noexcept override
  254. {
  255. CARLA_SAFE_ASSERT_RETURN(fEffect != nullptr,);
  256. CARLA_SAFE_ASSERT_RETURN(parameterId < pData->param.count,);
  257. const float fixedValue(pData->param.getFixedValue(parameterId, value));
  258. fEffect->setParameter(fEffect, static_cast<int32_t>(parameterId), fixedValue);
  259. CarlaPlugin::setParameterValue(parameterId, fixedValue, sendGui, sendOsc, sendCallback);
  260. }
  261. void setChunkData(const void* const data, const std::size_t dataSize) override
  262. {
  263. CARLA_SAFE_ASSERT_RETURN(pData->options & PLUGIN_OPTION_USE_CHUNKS,);
  264. CARLA_SAFE_ASSERT_RETURN(fEffect != nullptr,);
  265. CARLA_SAFE_ASSERT_RETURN(data != nullptr,);
  266. CARLA_SAFE_ASSERT_RETURN(dataSize > 0,);
  267. if (fLastChunk != nullptr)
  268. std::free(fLastChunk);
  269. fLastChunk = std::malloc(dataSize);
  270. CARLA_SAFE_ASSERT_RETURN(fLastChunk != nullptr,);
  271. std::memcpy(fLastChunk, data, dataSize);
  272. {
  273. const ScopedSingleProcessLocker spl(this, true);
  274. dispatcher(effSetChunk, 0 /* bank */, static_cast<intptr_t>(dataSize), fLastChunk, 0.0f);
  275. }
  276. // simulate an updateDisplay callback
  277. handleAudioMasterCallback(audioMasterUpdateDisplay, 0, 0, nullptr, 0.0f);
  278. #ifdef BUILD_BRIDGE
  279. const bool sendOsc(false);
  280. #else
  281. const bool sendOsc(pData->engine->isOscControlRegistered());
  282. #endif
  283. pData->updateParameterValues(this, sendOsc, true, false);
  284. }
  285. void setProgram(const int32_t index, const bool sendGui, const bool sendOsc, const bool sendCallback) noexcept override
  286. {
  287. CARLA_SAFE_ASSERT_RETURN(fEffect != nullptr,);
  288. CARLA_SAFE_ASSERT_RETURN(index >= -1 && index < static_cast<int32_t>(pData->prog.count),);
  289. if (index >= 0)
  290. {
  291. try {
  292. dispatcher(effBeginSetProgram, 0, 0, nullptr, 0.0f);
  293. } catch (...) {
  294. return;
  295. }
  296. {
  297. const ScopedSingleProcessLocker spl(this, (sendGui || sendOsc || sendCallback));
  298. try {
  299. dispatcher(effSetProgram, 0, index, nullptr, 0.0f);
  300. } catch(...) {}
  301. }
  302. try {
  303. dispatcher(effEndSetProgram, 0, 0, nullptr, 0.0f);
  304. } catch(...) {}
  305. }
  306. CarlaPlugin::setProgram(index, sendGui, sendOsc, sendCallback);
  307. }
  308. // -------------------------------------------------------------------
  309. // Set ui stuff
  310. void showCustomUI(const bool yesNo) override
  311. {
  312. if (fUI.type == UI::UI_OSC)
  313. {
  314. if (yesNo)
  315. {
  316. pData->osc.data.clear();
  317. pData->osc.thread.startThread();
  318. }
  319. else
  320. {
  321. pData->transientTryCounter = 0;
  322. if (pData->osc.data.target != nullptr)
  323. {
  324. osc_send_hide(pData->osc.data);
  325. osc_send_quit(pData->osc.data);
  326. pData->osc.data.clear();
  327. }
  328. pData->osc.thread.stopThread(static_cast<int>(pData->engine->getOptions().uiBridgesTimeout * 2));
  329. }
  330. return;
  331. }
  332. if (fUI.isVisible == yesNo)
  333. return;
  334. if (yesNo)
  335. {
  336. CarlaString uiTitle(pData->name);
  337. uiTitle += " (GUI)";
  338. intptr_t value = 0;
  339. void* vstPtr = nullptr;
  340. ERect* vstRect = nullptr;
  341. if (fUI.window == nullptr && fUI.type == UI::UI_EMBED)
  342. {
  343. const char* msg = nullptr;
  344. const uintptr_t frontendWinId(pData->engine->getOptions().frontendWinId);
  345. #if defined(CARLA_OS_LINUX)
  346. # ifdef HAVE_X11
  347. fUI.window = CarlaPluginUI::newX11(this, frontendWinId, false);
  348. # else
  349. msg = "UI is only for systems with X11";
  350. (void)frontendWinId; // unused
  351. # endif
  352. #elif defined(CARLA_OS_MAC)
  353. # ifdef __LP64__
  354. fUI.window = CarlaPluginUI::newCocoa(this, frontendWinId);
  355. # endif
  356. #elif defined(CARLA_OS_WIN)
  357. fUI.window = CarlaPluginUI::newWindows(this, frontendWinId);
  358. #else
  359. msg = "Unknown UI type";
  360. #endif
  361. if (fUI.window == nullptr)
  362. return pData->engine->callback(ENGINE_CALLBACK_UI_STATE_CHANGED, pData->id, -1, 0, 0.0f, msg);
  363. fUI.window->setTitle(uiTitle.buffer());
  364. }
  365. if (fUI.type == UI::UI_EMBED)
  366. vstPtr = fUI.window->getPtr();
  367. else
  368. vstPtr = const_cast<char*>(uiTitle.buffer());
  369. dispatcher(effEditGetRect, 0, 0, &vstRect, 0.0f);
  370. #ifdef HAVE_X11
  371. value = (intptr_t)fUI.window->getDisplay();
  372. #endif
  373. if (dispatcher(effEditOpen, 0, value, vstPtr, 0.0f) != 0)
  374. {
  375. if (fUI.type == UI::UI_EMBED)
  376. {
  377. if (vstRect == nullptr || vstRect->right - vstRect->left < 2)
  378. dispatcher(effEditGetRect, 0, 0, &vstRect, 0.0f);
  379. if (vstRect != nullptr)
  380. {
  381. const int width(vstRect->right - vstRect->left);
  382. const int height(vstRect->bottom - vstRect->top);
  383. CARLA_SAFE_ASSERT_INT2(width > 1 && height > 1, width, height);
  384. if (width > 1 && height > 1)
  385. fUI.window->setSize(static_cast<uint>(width), static_cast<uint>(height), false);
  386. }
  387. fUI.window->show();
  388. }
  389. else
  390. {
  391. if (pData->engine->getOptions().frontendWinId)
  392. pData->transientTryCounter = 1;
  393. }
  394. fUI.isVisible = true;
  395. }
  396. else
  397. {
  398. if (fUI.type == UI::UI_EMBED)
  399. {
  400. delete fUI.window;
  401. fUI.window = nullptr;
  402. }
  403. return pData->engine->callback(ENGINE_CALLBACK_UI_STATE_CHANGED, pData->id, -1, 0, 0.0f, "Plugin refused to open its own UI");
  404. }
  405. }
  406. else
  407. {
  408. fUI.isVisible = false;
  409. if (fUI.type == UI::UI_EMBED)
  410. {
  411. CARLA_SAFE_ASSERT_RETURN(fUI.window != nullptr,);
  412. fUI.window->hide();
  413. }
  414. else
  415. {
  416. pData->transientTryCounter = 0;
  417. }
  418. dispatcher(effEditClose, 0, 0, nullptr, 0.0f);
  419. }
  420. }
  421. void idle() override
  422. {
  423. if (fNeedIdle)
  424. dispatcher(effIdle, 0, 0, nullptr, 0.0f);
  425. if (fUI.window != nullptr)
  426. {
  427. fUI.window->idle();
  428. if (fUI.isVisible)
  429. dispatcher(effEditIdle, 0, 0, nullptr, 0.0f);
  430. }
  431. CarlaPlugin::idle();
  432. }
  433. // -------------------------------------------------------------------
  434. // Plugin state
  435. void reload() override
  436. {
  437. CARLA_SAFE_ASSERT_RETURN(pData->engine != nullptr,);
  438. CARLA_SAFE_ASSERT_RETURN(fEffect != nullptr,);
  439. carla_debug("VstPlugin::reload() - start");
  440. const EngineProcessMode processMode(pData->engine->getProccessMode());
  441. // Safely disable plugin for reload
  442. const ScopedDisabler sd(this);
  443. if (pData->active)
  444. deactivate();
  445. clearBuffers();
  446. uint32_t aIns, aOuts, mIns, mOuts, params;
  447. bool needsCtrlIn, needsCtrlOut;
  448. needsCtrlIn = needsCtrlOut = false;
  449. aIns = (fEffect->numInputs > 0) ? static_cast<uint32_t>(fEffect->numInputs) : 0;
  450. aOuts = (fEffect->numOutputs > 0) ? static_cast<uint32_t>(fEffect->numOutputs) : 0;
  451. params = (fEffect->numParams > 0) ? static_cast<uint32_t>(fEffect->numParams) : 0;
  452. if (hasMidiInput())
  453. {
  454. mIns = 1;
  455. needsCtrlIn = true;
  456. }
  457. else
  458. mIns = 0;
  459. if (hasMidiOutput())
  460. {
  461. mOuts = 1;
  462. needsCtrlOut = true;
  463. }
  464. else
  465. mOuts = 0;
  466. if (aIns > 0)
  467. {
  468. pData->audioIn.createNew(aIns);
  469. }
  470. if (aOuts > 0)
  471. {
  472. pData->audioOut.createNew(aOuts);
  473. needsCtrlIn = true;
  474. }
  475. if (params > 0)
  476. {
  477. pData->param.createNew(params, false);
  478. needsCtrlIn = true;
  479. }
  480. const uint portNameSize(pData->engine->getMaxPortNameSize());
  481. CarlaString portName;
  482. // Audio Ins
  483. for (uint32_t j=0; j < aIns; ++j)
  484. {
  485. portName.clear();
  486. if (processMode == ENGINE_PROCESS_MODE_SINGLE_CLIENT)
  487. {
  488. portName = pData->name;
  489. portName += ":";
  490. }
  491. if (aIns > 1)
  492. {
  493. portName += "input_";
  494. portName += CarlaString(j+1);
  495. }
  496. else
  497. portName += "input";
  498. portName.truncate(portNameSize);
  499. pData->audioIn.ports[j].port = (CarlaEngineAudioPort*)pData->client->addPort(kEnginePortTypeAudio, portName, true);
  500. pData->audioIn.ports[j].rindex = j;
  501. }
  502. // Audio Outs
  503. for (uint32_t j=0; j < aOuts; ++j)
  504. {
  505. portName.clear();
  506. if (processMode == ENGINE_PROCESS_MODE_SINGLE_CLIENT)
  507. {
  508. portName = pData->name;
  509. portName += ":";
  510. }
  511. if (aOuts > 1)
  512. {
  513. portName += "output_";
  514. portName += CarlaString(j+1);
  515. }
  516. else
  517. portName += "output";
  518. portName.truncate(portNameSize);
  519. pData->audioOut.ports[j].port = (CarlaEngineAudioPort*)pData->client->addPort(kEnginePortTypeAudio, portName, false);
  520. pData->audioOut.ports[j].rindex = j;
  521. }
  522. for (uint32_t j=0; j < params; ++j)
  523. {
  524. pData->param.data[j].type = PARAMETER_INPUT;
  525. pData->param.data[j].index = static_cast<int32_t>(j);
  526. pData->param.data[j].rindex = static_cast<int32_t>(j);
  527. float min, max, def, step, stepSmall, stepLarge;
  528. VstParameterProperties prop;
  529. carla_zeroStruct<VstParameterProperties>(prop);
  530. if (pData->hints & PLUGIN_HAS_COCKOS_EXTENSIONS)
  531. {
  532. double vrange[2] = { 0.0, 1.0 };
  533. bool isInteger = false;
  534. if (static_cast<uintptr_t>(dispatcher(effVendorSpecific, static_cast<int32_t>(0xdeadbef0), static_cast<int32_t>(j), vrange, 0.0f)) >= 0xbeef)
  535. {
  536. min = static_cast<float>(vrange[0]);
  537. max = static_cast<float>(vrange[1]);
  538. if (min > max)
  539. {
  540. carla_stderr2("WARNING - Broken plugin parameter min > max (with cockos extensions)");
  541. min = max - 0.1f;
  542. }
  543. else if (carla_compareFloats(min, max))
  544. {
  545. carla_stderr2("WARNING - Broken plugin parameter min == max (with cockos extensions)");
  546. max = min + 0.1f;
  547. }
  548. // only use values as integer if we have a proper range
  549. if (max - min >= 1.0f)
  550. isInteger = dispatcher(effVendorSpecific, kVstParameterUsesIntStep, static_cast<int32_t>(j), nullptr, 0.0f) >= 0xbeef;
  551. }
  552. else
  553. {
  554. min = 0.0f;
  555. max = 1.0f;
  556. }
  557. if (isInteger)
  558. {
  559. step = 1.0f;
  560. stepSmall = 1.0f;
  561. stepLarge = 10.0f;
  562. }
  563. else
  564. {
  565. const float range = max - min;
  566. step = range/100.0f;
  567. stepSmall = range/1000.0f;
  568. stepLarge = range/10.0f;
  569. }
  570. }
  571. else if (dispatcher(effGetParameterProperties, static_cast<int32_t>(j), 0, &prop, 0) == 1)
  572. {
  573. if (prop.flags & kVstParameterUsesIntegerMinMax)
  574. {
  575. min = static_cast<float>(prop.minInteger);
  576. max = static_cast<float>(prop.maxInteger);
  577. if (min > max)
  578. {
  579. carla_stderr2("WARNING - Broken plugin parameter min > max");
  580. min = max - 0.1f;
  581. }
  582. else if (carla_compareFloats(min, max))
  583. {
  584. carla_stderr2("WARNING - Broken plugin parameter min == max");
  585. max = min + 0.1f;
  586. }
  587. }
  588. else
  589. {
  590. min = 0.0f;
  591. max = 1.0f;
  592. }
  593. if (prop.flags & kVstParameterIsSwitch)
  594. {
  595. step = max - min;
  596. stepSmall = step;
  597. stepLarge = step;
  598. pData->param.data[j].hints |= PARAMETER_IS_BOOLEAN;
  599. }
  600. else if (prop.flags & kVstParameterUsesIntStep)
  601. {
  602. step = static_cast<float>(prop.stepInteger);
  603. stepSmall = static_cast<float>(prop.stepInteger)/10.0f;
  604. stepLarge = static_cast<float>(prop.largeStepInteger);
  605. pData->param.data[j].hints |= PARAMETER_IS_INTEGER;
  606. }
  607. else if (prop.flags & kVstParameterUsesFloatStep)
  608. {
  609. step = prop.stepFloat;
  610. stepSmall = prop.smallStepFloat;
  611. stepLarge = prop.largeStepFloat;
  612. }
  613. else
  614. {
  615. const float range = max - min;
  616. step = range/100.0f;
  617. stepSmall = range/1000.0f;
  618. stepLarge = range/10.0f;
  619. }
  620. if (prop.flags & kVstParameterCanRamp)
  621. pData->param.data[j].hints |= PARAMETER_IS_LOGARITHMIC;
  622. }
  623. else
  624. {
  625. min = 0.0f;
  626. max = 1.0f;
  627. step = 0.001f;
  628. stepSmall = 0.0001f;
  629. stepLarge = 0.1f;
  630. }
  631. pData->param.data[j].hints |= PARAMETER_IS_ENABLED;
  632. #ifndef BUILD_BRIDGE
  633. pData->param.data[j].hints |= PARAMETER_USES_CUSTOM_TEXT;
  634. #endif
  635. if ((pData->hints & PLUGIN_USES_OLD_VSTSDK) != 0 || dispatcher(effCanBeAutomated, static_cast<int32_t>(j), 0, nullptr, 0.0f) == 1)
  636. pData->param.data[j].hints |= PARAMETER_IS_AUTOMABLE;
  637. // no such thing as VST default parameters
  638. def = fEffect->getParameter(fEffect, static_cast<int32_t>(j));
  639. if (def < min)
  640. def = min;
  641. else if (def > max)
  642. def = max;
  643. pData->param.ranges[j].min = min;
  644. pData->param.ranges[j].max = max;
  645. pData->param.ranges[j].def = def;
  646. pData->param.ranges[j].step = step;
  647. pData->param.ranges[j].stepSmall = stepSmall;
  648. pData->param.ranges[j].stepLarge = stepLarge;
  649. }
  650. if (needsCtrlIn)
  651. {
  652. portName.clear();
  653. if (processMode == ENGINE_PROCESS_MODE_SINGLE_CLIENT)
  654. {
  655. portName = pData->name;
  656. portName += ":";
  657. }
  658. portName += "events-in";
  659. portName.truncate(portNameSize);
  660. pData->event.portIn = (CarlaEngineEventPort*)pData->client->addPort(kEnginePortTypeEvent, portName, true);
  661. }
  662. if (needsCtrlOut)
  663. {
  664. portName.clear();
  665. if (processMode == ENGINE_PROCESS_MODE_SINGLE_CLIENT)
  666. {
  667. portName = pData->name;
  668. portName += ":";
  669. }
  670. portName += "events-out";
  671. portName.truncate(portNameSize);
  672. pData->event.portOut = (CarlaEngineEventPort*)pData->client->addPort(kEnginePortTypeEvent, portName, false);
  673. }
  674. // plugin hints
  675. const intptr_t vstCategory = dispatcher(effGetPlugCategory, 0, 0, nullptr, 0.0f);
  676. pData->hints = 0x0;
  677. if (vstCategory == kPlugCategSynth || vstCategory == kPlugCategGenerator)
  678. pData->hints |= PLUGIN_IS_SYNTH;
  679. if (fEffect->flags & effFlagsHasEditor)
  680. {
  681. pData->hints |= PLUGIN_HAS_CUSTOM_UI;
  682. if (fUI.type == UI::UI_EMBED)
  683. pData->hints |= PLUGIN_NEEDS_SINGLE_THREAD;
  684. }
  685. if (dispatcher(effGetVstVersion, 0, 0, nullptr, 0.0f) < kVstVersion)
  686. pData->hints |= PLUGIN_USES_OLD_VSTSDK;
  687. if ((fEffect->flags & effFlagsCanReplacing) != 0 && fEffect->processReplacing != fEffect->process)
  688. pData->hints |= PLUGIN_CAN_PROCESS_REPLACING;
  689. if (static_cast<uintptr_t>(dispatcher(effCanDo, 0, 0, const_cast<char*>("hasCockosExtensions"), 0.0f)) == 0xbeef0000)
  690. pData->hints |= PLUGIN_HAS_COCKOS_EXTENSIONS;
  691. if (aOuts > 0 && (aIns == aOuts || aIns == 1))
  692. pData->hints |= PLUGIN_CAN_DRYWET;
  693. if (aOuts > 0)
  694. pData->hints |= PLUGIN_CAN_VOLUME;
  695. if (aOuts >= 2 && aOuts % 2 == 0)
  696. pData->hints |= PLUGIN_CAN_BALANCE;
  697. // extra plugin hints
  698. pData->extraHints = 0x0;
  699. if (mIns > 0)
  700. pData->extraHints |= PLUGIN_EXTRA_HINT_HAS_MIDI_IN;
  701. if (mOuts > 0)
  702. pData->extraHints |= PLUGIN_EXTRA_HINT_HAS_MIDI_OUT;
  703. if (aIns <= 2 && aOuts <= 2 && (aIns == aOuts || aIns == 0 || aOuts == 0))
  704. pData->extraHints |= PLUGIN_EXTRA_HINT_CAN_RUN_RACK;
  705. // dummy pre-start to get latency and wantEvents() on old plugins
  706. {
  707. activate();
  708. deactivate();
  709. }
  710. // check latency
  711. if (pData->hints & PLUGIN_CAN_DRYWET)
  712. {
  713. #ifdef VESTIGE_HEADER
  714. char* const empty3Ptr = &fEffect->empty3[0];
  715. int32_t initialDelay = *(int32_t*)empty3Ptr;
  716. pData->latency = (initialDelay > 0) ? static_cast<uint32_t>(initialDelay) : 0;
  717. #else
  718. pData->latency = (fEffect->initialDelay > 0) ? static_cast<uint32_t>(fEffect->initialDelay) : 0;
  719. #endif
  720. pData->client->setLatency(pData->latency);
  721. #ifndef BUILD_BRIDGE
  722. pData->recreateLatencyBuffers();
  723. #endif
  724. }
  725. // special plugin fixes
  726. // 1. IL Harmless - disable threaded processing
  727. if (fEffect->uniqueID == 1229484653)
  728. {
  729. char strBuf[STR_MAX+1] = { '\0' };
  730. getLabel(strBuf);
  731. if (std::strcmp(strBuf, "IL Harmless") == 0)
  732. {
  733. // TODO - disable threaded processing
  734. }
  735. }
  736. //bufferSizeChanged(pData->engine->getBufferSize());
  737. reloadPrograms(true);
  738. if (pData->active)
  739. activate();
  740. carla_debug("VstPlugin::reload() - end");
  741. }
  742. void reloadPrograms(const bool doInit) override
  743. {
  744. carla_debug("VstPlugin::reloadPrograms(%s)", bool2str(doInit));
  745. const uint32_t oldCount = pData->prog.count;
  746. const int32_t current = pData->prog.current;
  747. // Delete old programs
  748. pData->prog.clear();
  749. // Query new programs
  750. uint32_t newCount = (fEffect->numPrograms > 0) ? static_cast<uint32_t>(fEffect->numPrograms) : 0;
  751. if (newCount > 0)
  752. {
  753. pData->prog.createNew(newCount);
  754. // Update names
  755. for (int32_t i=0; i < fEffect->numPrograms; ++i)
  756. {
  757. char strBuf[STR_MAX+1] = { '\0' };
  758. if (dispatcher(effGetProgramNameIndexed, i, 0, strBuf, 0.0f) != 1)
  759. {
  760. // program will be [re-]changed later
  761. dispatcher(effSetProgram, 0, i, nullptr, 0.0f);
  762. dispatcher(effGetProgramName, 0, 0, strBuf, 0.0f);
  763. }
  764. pData->prog.names[i] = carla_strdup(strBuf);
  765. }
  766. }
  767. #ifndef BUILD_BRIDGE
  768. // Update OSC Names
  769. if (pData->engine->isOscControlRegistered())
  770. {
  771. pData->engine->oscSend_control_set_program_count(pData->id, newCount);
  772. for (uint32_t i=0; i < newCount; ++i)
  773. pData->engine->oscSend_control_set_program_name(pData->id, i, pData->prog.names[i]);
  774. }
  775. #endif
  776. if (doInit)
  777. {
  778. if (newCount > 0)
  779. setProgram(0, false, false, false);
  780. }
  781. else
  782. {
  783. // Check if current program is invalid
  784. bool programChanged = false;
  785. if (newCount == oldCount+1)
  786. {
  787. // one program added, probably created by user
  788. pData->prog.current = static_cast<int32_t>(oldCount);
  789. programChanged = true;
  790. }
  791. else if (current < 0 && newCount > 0)
  792. {
  793. // programs exist now, but not before
  794. pData->prog.current = 0;
  795. programChanged = true;
  796. }
  797. else if (current >= 0 && newCount == 0)
  798. {
  799. // programs existed before, but not anymore
  800. pData->prog.current = -1;
  801. programChanged = true;
  802. }
  803. else if (current >= static_cast<int32_t>(newCount))
  804. {
  805. // current program > count
  806. pData->prog.current = 0;
  807. programChanged = true;
  808. }
  809. else
  810. {
  811. // no change
  812. pData->prog.current = current;
  813. }
  814. if (programChanged)
  815. {
  816. setProgram(pData->prog.current, true, true, true);
  817. }
  818. else
  819. {
  820. // Program was changed during update, re-set it
  821. if (pData->prog.current >= 0)
  822. dispatcher(effSetProgram, 0, pData->prog.current, nullptr, 0.0f);
  823. }
  824. pData->engine->callback(ENGINE_CALLBACK_RELOAD_PROGRAMS, pData->id, 0, 0, 0.0f, nullptr);
  825. }
  826. }
  827. // -------------------------------------------------------------------
  828. // Plugin processing
  829. void activate() noexcept override
  830. {
  831. CARLA_SAFE_ASSERT_RETURN(fEffect != nullptr,);
  832. try {
  833. dispatcher(effMainsChanged, 0, 1, nullptr, 0.0f);
  834. } catch(...) {}
  835. try {
  836. dispatcher(effStartProcess, 0, 0, nullptr, 0.0f);
  837. } catch(...) {}
  838. }
  839. void deactivate() noexcept override
  840. {
  841. CARLA_SAFE_ASSERT_RETURN(fEffect != nullptr,);
  842. try {
  843. dispatcher(effStopProcess, 0, 0, nullptr, 0.0f);
  844. } catch(...) {}
  845. try {
  846. dispatcher(effMainsChanged, 0, 0, nullptr, 0.0f);
  847. } catch(...) {}
  848. }
  849. void process(const float** const audioIn, float** const audioOut, const float** const, float** const, const uint32_t frames) override
  850. {
  851. fProcThread = pthread_self();
  852. // --------------------------------------------------------------------------------------------------------
  853. // Check if active
  854. if (! pData->active)
  855. {
  856. // disable any output sound
  857. for (uint32_t i=0; i < pData->audioOut.count; ++i)
  858. FloatVectorOperations::clear(audioOut[i], static_cast<int>(frames));
  859. return;
  860. }
  861. fMidiEventCount = 0;
  862. carla_zeroStruct<VstMidiEvent>(fMidiEvents, kPluginMaxMidiEvents*2);
  863. // --------------------------------------------------------------------------------------------------------
  864. // Check if needs reset
  865. if (pData->needsReset)
  866. {
  867. if (pData->options & PLUGIN_OPTION_SEND_ALL_SOUND_OFF)
  868. {
  869. fMidiEventCount = MAX_MIDI_CHANNELS*2;
  870. for (uint8_t i=0, k=MAX_MIDI_CHANNELS; i < MAX_MIDI_CHANNELS; ++i)
  871. {
  872. fMidiEvents[k].type = kVstMidiType;
  873. fMidiEvents[k].byteSize = static_cast<int32_t>(sizeof(VstMidiEvent));
  874. fMidiEvents[k].midiData[0] = static_cast<char>(MIDI_STATUS_CONTROL_CHANGE + k);
  875. fMidiEvents[k].midiData[1] = MIDI_CONTROL_ALL_NOTES_OFF;
  876. fMidiEvents[k+i].type = kVstMidiType;
  877. fMidiEvents[k+i].byteSize = static_cast<int32_t>(sizeof(VstMidiEvent));
  878. fMidiEvents[k+i].midiData[0] = static_cast<char>(MIDI_STATUS_CONTROL_CHANGE + k);
  879. fMidiEvents[k+i].midiData[1] = MIDI_CONTROL_ALL_SOUND_OFF;
  880. }
  881. }
  882. else if (pData->ctrlChannel >= 0 && pData->ctrlChannel < MAX_MIDI_CHANNELS)
  883. {
  884. fMidiEventCount = MAX_MIDI_NOTE;
  885. for (uint8_t i=0; i < MAX_MIDI_NOTE; ++i)
  886. {
  887. fMidiEvents[i].type = kVstMidiType;
  888. fMidiEvents[i].byteSize = static_cast<int32_t>(sizeof(VstMidiEvent));
  889. fMidiEvents[i].midiData[0] = static_cast<char>(MIDI_STATUS_NOTE_OFF + pData->ctrlChannel);
  890. fMidiEvents[i].midiData[1] = static_cast<char>(i);
  891. }
  892. }
  893. #ifndef BUILD_BRIDGE
  894. if (pData->latency > 0)
  895. {
  896. for (uint32_t i=0; i < pData->audioIn.count; ++i)
  897. FloatVectorOperations::clear(pData->latencyBuffers[i], static_cast<int>(pData->latency));
  898. }
  899. #endif
  900. pData->needsReset = false;
  901. }
  902. // --------------------------------------------------------------------------------------------------------
  903. // Set TimeInfo
  904. const EngineTimeInfo& timeInfo(pData->engine->getTimeInfo());
  905. fTimeInfo.flags = kVstTransportChanged;
  906. if (timeInfo.playing)
  907. fTimeInfo.flags |= kVstTransportPlaying;
  908. fTimeInfo.samplePos = double(timeInfo.frame);
  909. fTimeInfo.sampleRate = pData->engine->getSampleRate();
  910. if (timeInfo.usecs != 0)
  911. {
  912. fTimeInfo.nanoSeconds = double(timeInfo.usecs)/1000.0;
  913. fTimeInfo.flags |= kVstNanosValid;
  914. }
  915. if (timeInfo.valid & EngineTimeInfo::kValidBBT)
  916. {
  917. double ppqBar = double(timeInfo.bbt.bar - 1) * timeInfo.bbt.beatsPerBar;
  918. double ppqBeat = double(timeInfo.bbt.beat - 1);
  919. double ppqTick = double(timeInfo.bbt.tick) / timeInfo.bbt.ticksPerBeat;
  920. // PPQ Pos
  921. fTimeInfo.ppqPos = ppqBar + ppqBeat + ppqTick;
  922. fTimeInfo.flags |= kVstPpqPosValid;
  923. // Tempo
  924. fTimeInfo.tempo = timeInfo.bbt.beatsPerMinute;
  925. fTimeInfo.flags |= kVstTempoValid;
  926. // Bars
  927. fTimeInfo.barStartPos = ppqBar;
  928. fTimeInfo.flags |= kVstBarsValid;
  929. // Time Signature
  930. fTimeInfo.timeSigNumerator = static_cast<int32_t>(timeInfo.bbt.beatsPerBar);
  931. fTimeInfo.timeSigDenominator = static_cast<int32_t>(timeInfo.bbt.beatType);
  932. fTimeInfo.flags |= kVstTimeSigValid;
  933. }
  934. else
  935. {
  936. // Tempo
  937. fTimeInfo.tempo = 120.0;
  938. fTimeInfo.flags |= kVstTempoValid;
  939. // Time Signature
  940. fTimeInfo.timeSigNumerator = 4;
  941. fTimeInfo.timeSigDenominator = 4;
  942. fTimeInfo.flags |= kVstTimeSigValid;
  943. // Missing info
  944. fTimeInfo.ppqPos = 0.0;
  945. fTimeInfo.barStartPos = 0.0;
  946. }
  947. // --------------------------------------------------------------------------------------------------------
  948. // Event Input and Processing
  949. if (pData->event.portIn != nullptr)
  950. {
  951. // ----------------------------------------------------------------------------------------------------
  952. // MIDI Input (External)
  953. if (pData->extNotes.mutex.tryLock())
  954. {
  955. ExternalMidiNote note = { 0, 0, 0 };
  956. for (; fMidiEventCount < kPluginMaxMidiEvents*2 && ! pData->extNotes.data.isEmpty();)
  957. {
  958. note = pData->extNotes.data.getFirst(note, true);
  959. CARLA_SAFE_ASSERT_CONTINUE(note.channel >= 0 && note.channel < MAX_MIDI_CHANNELS);
  960. fMidiEvents[fMidiEventCount].type = kVstMidiType;
  961. fMidiEvents[fMidiEventCount].byteSize = static_cast<int32_t>(sizeof(VstMidiEvent));
  962. fMidiEvents[fMidiEventCount].midiData[0] = static_cast<char>((note.velo > 0 ? MIDI_STATUS_NOTE_ON : MIDI_STATUS_NOTE_OFF) | (note.channel & MIDI_CHANNEL_BIT));
  963. fMidiEvents[fMidiEventCount].midiData[1] = static_cast<char>(note.note);
  964. fMidiEvents[fMidiEventCount].midiData[2] = static_cast<char>(note.velo);
  965. ++fMidiEventCount;
  966. }
  967. pData->extNotes.mutex.unlock();
  968. } // End of MIDI Input (External)
  969. // ----------------------------------------------------------------------------------------------------
  970. // Event Input (System)
  971. #ifndef BUILD_BRIDGE
  972. bool allNotesOffSent = false;
  973. #endif
  974. bool isSampleAccurate = (pData->options & PLUGIN_OPTION_FIXED_BUFFERS) == 0;
  975. uint32_t numEvents = pData->event.portIn->getEventCount();
  976. uint32_t startTime = 0;
  977. uint32_t timeOffset = 0;
  978. for (uint32_t i=0; i < numEvents; ++i)
  979. {
  980. const EngineEvent& event(pData->event.portIn->getEvent(i));
  981. if (event.time >= frames)
  982. continue;
  983. CARLA_ASSERT_INT2(event.time >= timeOffset, event.time, timeOffset);
  984. if (isSampleAccurate && event.time > timeOffset)
  985. {
  986. if (processSingle(audioIn, audioOut, event.time - timeOffset, timeOffset))
  987. {
  988. startTime = 0;
  989. timeOffset = event.time;
  990. if (fMidiEventCount > 0)
  991. {
  992. carla_zeroStruct<VstMidiEvent>(fMidiEvents, fMidiEventCount);
  993. fMidiEventCount = 0;
  994. }
  995. }
  996. else
  997. startTime += timeOffset;
  998. }
  999. switch (event.type)
  1000. {
  1001. case kEngineEventTypeNull:
  1002. break;
  1003. case kEngineEventTypeControl: {
  1004. const EngineControlEvent& ctrlEvent(event.ctrl);
  1005. switch (ctrlEvent.type)
  1006. {
  1007. case kEngineControlEventTypeNull:
  1008. break;
  1009. case kEngineControlEventTypeParameter: {
  1010. #ifndef BUILD_BRIDGE
  1011. // Control backend stuff
  1012. if (event.channel == pData->ctrlChannel)
  1013. {
  1014. float value;
  1015. if (MIDI_IS_CONTROL_BREATH_CONTROLLER(ctrlEvent.param) && (pData->hints & PLUGIN_CAN_DRYWET) != 0)
  1016. {
  1017. value = ctrlEvent.value;
  1018. setDryWet(value, false, false);
  1019. pData->postponeRtEvent(kPluginPostRtEventParameterChange, PARAMETER_DRYWET, 0, value);
  1020. break;
  1021. }
  1022. if (MIDI_IS_CONTROL_CHANNEL_VOLUME(ctrlEvent.param) && (pData->hints & PLUGIN_CAN_VOLUME) != 0)
  1023. {
  1024. value = ctrlEvent.value*127.0f/100.0f;
  1025. setVolume(value, false, false);
  1026. pData->postponeRtEvent(kPluginPostRtEventParameterChange, PARAMETER_VOLUME, 0, value);
  1027. break;
  1028. }
  1029. if (MIDI_IS_CONTROL_BALANCE(ctrlEvent.param) && (pData->hints & PLUGIN_CAN_BALANCE) != 0)
  1030. {
  1031. float left, right;
  1032. value = ctrlEvent.value/0.5f - 1.0f;
  1033. if (value < 0.0f)
  1034. {
  1035. left = -1.0f;
  1036. right = (value*2.0f)+1.0f;
  1037. }
  1038. else if (value > 0.0f)
  1039. {
  1040. left = (value*2.0f)-1.0f;
  1041. right = 1.0f;
  1042. }
  1043. else
  1044. {
  1045. left = -1.0f;
  1046. right = 1.0f;
  1047. }
  1048. setBalanceLeft(left, false, false);
  1049. setBalanceRight(right, false, false);
  1050. pData->postponeRtEvent(kPluginPostRtEventParameterChange, PARAMETER_BALANCE_LEFT, 0, left);
  1051. pData->postponeRtEvent(kPluginPostRtEventParameterChange, PARAMETER_BALANCE_RIGHT, 0, right);
  1052. break;
  1053. }
  1054. }
  1055. #endif
  1056. // Control plugin parameters
  1057. uint32_t k;
  1058. for (k=0; k < pData->param.count; ++k)
  1059. {
  1060. if (pData->param.data[k].midiChannel != event.channel)
  1061. continue;
  1062. if (pData->param.data[k].midiCC != ctrlEvent.param)
  1063. continue;
  1064. if (pData->param.data[k].type != PARAMETER_INPUT)
  1065. continue;
  1066. if ((pData->param.data[k].hints & PARAMETER_IS_AUTOMABLE) == 0)
  1067. continue;
  1068. float value;
  1069. if (pData->param.data[k].hints & PARAMETER_IS_BOOLEAN)
  1070. {
  1071. value = (ctrlEvent.value < 0.5f) ? pData->param.ranges[k].min : pData->param.ranges[k].max;
  1072. }
  1073. else
  1074. {
  1075. value = pData->param.ranges[k].getUnnormalizedValue(ctrlEvent.value);
  1076. if (pData->param.data[k].hints & PARAMETER_IS_INTEGER)
  1077. value = std::rint(value);
  1078. }
  1079. setParameterValue(k, value, false, false, false);
  1080. pData->postponeRtEvent(kPluginPostRtEventParameterChange, static_cast<int32_t>(k), 0, value);
  1081. break;
  1082. }
  1083. // check if event is already handled
  1084. if (k != pData->param.count)
  1085. break;
  1086. if ((pData->options & PLUGIN_OPTION_SEND_CONTROL_CHANGES) != 0 && ctrlEvent.param <= 0x5F)
  1087. {
  1088. if (fMidiEventCount >= kPluginMaxMidiEvents*2)
  1089. continue;
  1090. carla_zeroStruct<VstMidiEvent>(fMidiEvents[fMidiEventCount]);
  1091. fMidiEvents[fMidiEventCount].type = kVstMidiType;
  1092. fMidiEvents[fMidiEventCount].byteSize = static_cast<int32_t>(sizeof(VstMidiEvent));
  1093. fMidiEvents[fMidiEventCount].midiData[0] = static_cast<char>(MIDI_STATUS_CONTROL_CHANGE + event.channel);
  1094. fMidiEvents[fMidiEventCount].midiData[1] = static_cast<char>(ctrlEvent.param);
  1095. fMidiEvents[fMidiEventCount].midiData[2] = char(ctrlEvent.value*127.0f);
  1096. fMidiEvents[fMidiEventCount].deltaFrames = static_cast<int32_t>(isSampleAccurate ? startTime : event.time);
  1097. ++fMidiEventCount;
  1098. }
  1099. break;
  1100. } // case kEngineControlEventTypeParameter
  1101. case kEngineControlEventTypeMidiBank:
  1102. break;
  1103. case kEngineControlEventTypeMidiProgram:
  1104. if (event.channel == pData->ctrlChannel && (pData->options & PLUGIN_OPTION_MAP_PROGRAM_CHANGES) != 0)
  1105. {
  1106. if (ctrlEvent.param < pData->prog.count)
  1107. {
  1108. setProgram(ctrlEvent.param, false, false, false);
  1109. pData->postponeRtEvent(kPluginPostRtEventProgramChange, ctrlEvent.param, 0, 0.0f);
  1110. break;
  1111. }
  1112. }
  1113. break;
  1114. case kEngineControlEventTypeAllSoundOff:
  1115. if (pData->options & PLUGIN_OPTION_SEND_ALL_SOUND_OFF)
  1116. {
  1117. if (fMidiEventCount >= kPluginMaxMidiEvents*2)
  1118. continue;
  1119. carla_zeroStruct<VstMidiEvent>(fMidiEvents[fMidiEventCount]);
  1120. fMidiEvents[fMidiEventCount].type = kVstMidiType;
  1121. fMidiEvents[fMidiEventCount].byteSize = static_cast<int32_t>(sizeof(VstMidiEvent));
  1122. fMidiEvents[fMidiEventCount].midiData[0] = static_cast<char>(MIDI_STATUS_CONTROL_CHANGE + event.channel);
  1123. fMidiEvents[fMidiEventCount].midiData[1] = MIDI_CONTROL_ALL_SOUND_OFF;
  1124. fMidiEvents[fMidiEventCount].deltaFrames = static_cast<int32_t>(isSampleAccurate ? startTime : event.time);
  1125. ++fMidiEventCount;
  1126. }
  1127. break;
  1128. case kEngineControlEventTypeAllNotesOff:
  1129. if (pData->options & PLUGIN_OPTION_SEND_ALL_SOUND_OFF)
  1130. {
  1131. #ifndef BUILD_BRIDGE
  1132. if (event.channel == pData->ctrlChannel && ! allNotesOffSent)
  1133. {
  1134. allNotesOffSent = true;
  1135. sendMidiAllNotesOffToCallback();
  1136. }
  1137. #endif
  1138. if (fMidiEventCount >= kPluginMaxMidiEvents*2)
  1139. continue;
  1140. carla_zeroStruct<VstMidiEvent>(fMidiEvents[fMidiEventCount]);
  1141. fMidiEvents[fMidiEventCount].type = kVstMidiType;
  1142. fMidiEvents[fMidiEventCount].byteSize = static_cast<int32_t>(sizeof(VstMidiEvent));
  1143. fMidiEvents[fMidiEventCount].midiData[0] = static_cast<char>(MIDI_STATUS_CONTROL_CHANGE + event.channel);
  1144. fMidiEvents[fMidiEventCount].midiData[1] = MIDI_CONTROL_ALL_NOTES_OFF;
  1145. fMidiEvents[fMidiEventCount].deltaFrames = static_cast<int32_t>(isSampleAccurate ? startTime : event.time);
  1146. ++fMidiEventCount;
  1147. }
  1148. break;
  1149. } // switch (ctrlEvent.type)
  1150. break;
  1151. } // case kEngineEventTypeControl
  1152. case kEngineEventTypeMidi: {
  1153. if (fMidiEventCount >= kPluginMaxMidiEvents*2)
  1154. continue;
  1155. const EngineMidiEvent& midiEvent(event.midi);
  1156. uint8_t status = static_cast<uint8_t>(MIDI_GET_STATUS_FROM_DATA(midiEvent.data));
  1157. uint8_t channel = event.channel;
  1158. // Fix bad note-off (per VST spec)
  1159. if (MIDI_IS_STATUS_NOTE_ON(status) && midiEvent.data[2] == 0)
  1160. status = MIDI_STATUS_NOTE_OFF;
  1161. if (status == MIDI_STATUS_CHANNEL_PRESSURE && (pData->options & PLUGIN_OPTION_SEND_CHANNEL_PRESSURE) == 0)
  1162. continue;
  1163. if (status == MIDI_STATUS_CONTROL_CHANGE && (pData->options & PLUGIN_OPTION_SEND_CONTROL_CHANGES) == 0)
  1164. continue;
  1165. if (status == MIDI_STATUS_POLYPHONIC_AFTERTOUCH && (pData->options & PLUGIN_OPTION_SEND_NOTE_AFTERTOUCH) == 0)
  1166. continue;
  1167. if (status == MIDI_STATUS_PITCH_WHEEL_CONTROL && (pData->options & PLUGIN_OPTION_SEND_PITCHBEND) == 0)
  1168. continue;
  1169. carla_zeroStruct<VstMidiEvent>(fMidiEvents[fMidiEventCount]);
  1170. fMidiEvents[fMidiEventCount].type = kVstMidiType;
  1171. fMidiEvents[fMidiEventCount].byteSize = static_cast<int32_t>(sizeof(VstMidiEvent));
  1172. fMidiEvents[fMidiEventCount].midiData[0] = static_cast<char>(status + channel);
  1173. fMidiEvents[fMidiEventCount].midiData[1] = static_cast<char>(midiEvent.data[1]);
  1174. fMidiEvents[fMidiEventCount].midiData[2] = static_cast<char>(midiEvent.data[2]);
  1175. fMidiEvents[fMidiEventCount].deltaFrames = static_cast<int32_t>(isSampleAccurate ? startTime : event.time);
  1176. ++fMidiEventCount;
  1177. if (status == MIDI_STATUS_NOTE_ON)
  1178. pData->postponeRtEvent(kPluginPostRtEventNoteOn, channel, midiEvent.data[1], midiEvent.data[2]);
  1179. else if (status == MIDI_STATUS_NOTE_OFF)
  1180. pData->postponeRtEvent(kPluginPostRtEventNoteOff, channel, midiEvent.data[1], 0.0f);
  1181. break;
  1182. } // case kEngineEventTypeMidi
  1183. } // switch (event.type)
  1184. }
  1185. pData->postRtEvents.trySplice();
  1186. if (frames > timeOffset)
  1187. processSingle(audioIn, audioOut, frames - timeOffset, timeOffset);
  1188. } // End of Event Input and Processing
  1189. // --------------------------------------------------------------------------------------------------------
  1190. // Plugin processing (no events)
  1191. else
  1192. {
  1193. processSingle(audioIn, audioOut, frames, 0);
  1194. } // End of Plugin processing (no events)
  1195. // --------------------------------------------------------------------------------------------------------
  1196. // MIDI Output
  1197. if (pData->event.portOut != nullptr)
  1198. {
  1199. // reverse lookup MIDI events
  1200. for (uint32_t k = (kPluginMaxMidiEvents*2)-1; k >= fMidiEventCount; --k)
  1201. {
  1202. if (fMidiEvents[k].type == 0)
  1203. break;
  1204. CARLA_SAFE_ASSERT_CONTINUE(fMidiEvents[k].deltaFrames >= 0);
  1205. CARLA_SAFE_ASSERT_CONTINUE(fMidiEvents[k].midiData[0] != 0);
  1206. const uint8_t status(static_cast<uint8_t>(fMidiEvents[k].midiData[0]));
  1207. const uint8_t channel(static_cast<uint8_t>(status < MIDI_STATUS_BIT ? status & MIDI_CHANNEL_BIT : 0));
  1208. uint8_t midiData[3];
  1209. midiData[0] = static_cast<uint8_t>(fMidiEvents[k].midiData[0]);
  1210. midiData[1] = static_cast<uint8_t>(fMidiEvents[k].midiData[1]);
  1211. midiData[2] = static_cast<uint8_t>(fMidiEvents[k].midiData[2]);
  1212. pData->event.portOut->writeMidiEvent(static_cast<uint32_t>(fMidiEvents[k].deltaFrames), channel, 0, 3, midiData);
  1213. }
  1214. } // End of MIDI Output
  1215. }
  1216. bool processSingle(const float** const inBuffer, float** const outBuffer, const uint32_t frames, const uint32_t timeOffset)
  1217. {
  1218. CARLA_SAFE_ASSERT_RETURN(frames > 0, false);
  1219. if (pData->audioIn.count > 0)
  1220. {
  1221. CARLA_SAFE_ASSERT_RETURN(inBuffer != nullptr, false);
  1222. }
  1223. if (pData->audioOut.count > 0)
  1224. {
  1225. CARLA_SAFE_ASSERT_RETURN(outBuffer != nullptr, false);
  1226. }
  1227. // --------------------------------------------------------------------------------------------------------
  1228. // Try lock, silence otherwise
  1229. if (pData->engine->isOffline())
  1230. {
  1231. pData->singleMutex.lock();
  1232. }
  1233. else if (! pData->singleMutex.tryLock())
  1234. {
  1235. for (uint32_t i=0; i < pData->audioOut.count; ++i)
  1236. {
  1237. for (uint32_t k=0; k < frames; ++k)
  1238. outBuffer[i][k+timeOffset] = 0.0f;
  1239. }
  1240. return false;
  1241. }
  1242. // --------------------------------------------------------------------------------------------------------
  1243. // Set audio buffers
  1244. float* vstInBuffer[pData->audioIn.count];
  1245. float* vstOutBuffer[pData->audioOut.count];
  1246. for (uint32_t i=0; i < pData->audioIn.count; ++i)
  1247. vstInBuffer[i] = const_cast<float*>(inBuffer[i]+timeOffset);
  1248. for (uint32_t i=0; i < pData->audioOut.count; ++i)
  1249. vstOutBuffer[i] = outBuffer[i]+timeOffset;
  1250. // --------------------------------------------------------------------------------------------------------
  1251. // Set MIDI events
  1252. if (fMidiEventCount > 0)
  1253. {
  1254. fEvents.numEvents = static_cast<int32_t>(fMidiEventCount);
  1255. fEvents.reserved = 0;
  1256. dispatcher(effProcessEvents, 0, 0, &fEvents, 0.0f);
  1257. }
  1258. // --------------------------------------------------------------------------------------------------------
  1259. // Run plugin
  1260. fIsProcessing = true;
  1261. if (pData->hints & PLUGIN_CAN_PROCESS_REPLACING)
  1262. {
  1263. fEffect->processReplacing(fEffect, (pData->audioIn.count > 0) ? vstInBuffer : nullptr, (pData->audioOut.count > 0) ? vstOutBuffer : nullptr, static_cast<int32_t>(frames));
  1264. }
  1265. else
  1266. {
  1267. for (uint32_t i=0; i < pData->audioOut.count; ++i)
  1268. FloatVectorOperations::clear(vstOutBuffer[i], static_cast<int>(frames));
  1269. #if ! VST_FORCE_DEPRECATED
  1270. fEffect->process(fEffect, (pData->audioIn.count > 0) ? vstInBuffer : nullptr, (pData->audioOut.count > 0) ? vstOutBuffer : nullptr, static_cast<int32_t>(frames));
  1271. #endif
  1272. }
  1273. fIsProcessing = false;
  1274. fTimeInfo.samplePos += frames;
  1275. #ifndef BUILD_BRIDGE
  1276. // --------------------------------------------------------------------------------------------------------
  1277. // Post-processing (dry/wet, volume and balance)
  1278. {
  1279. const bool doVolume = (pData->hints & PLUGIN_CAN_VOLUME) != 0 && ! carla_compareFloats(pData->postProc.volume, 1.0f);
  1280. const bool doDryWet = (pData->hints & PLUGIN_CAN_DRYWET) != 0 && ! carla_compareFloats(pData->postProc.dryWet, 1.0f);
  1281. const bool doBalance = (pData->hints & PLUGIN_CAN_BALANCE) != 0 && ! (carla_compareFloats(pData->postProc.balanceLeft, -1.0f) && carla_compareFloats(pData->postProc.balanceRight, 1.0f));
  1282. bool isPair;
  1283. float bufValue, oldBufLeft[doBalance ? frames : 1];
  1284. for (uint32_t i=0; i < pData->audioOut.count; ++i)
  1285. {
  1286. // Dry/Wet
  1287. if (doDryWet)
  1288. {
  1289. for (uint32_t k=0; k < frames; ++k)
  1290. {
  1291. bufValue = inBuffer[(pData->audioIn.count == 1) ? 0 : i][k+timeOffset];
  1292. outBuffer[i][k+timeOffset] = (outBuffer[i][k+timeOffset] * pData->postProc.dryWet) + (bufValue * (1.0f - pData->postProc.dryWet));
  1293. }
  1294. }
  1295. // Balance
  1296. if (doBalance)
  1297. {
  1298. isPair = (i % 2 == 0);
  1299. if (isPair)
  1300. {
  1301. CARLA_ASSERT(i+1 < pData->audioOut.count);
  1302. FloatVectorOperations::copy(oldBufLeft, outBuffer[i]+timeOffset, static_cast<int>(frames));
  1303. }
  1304. float balRangeL = (pData->postProc.balanceLeft + 1.0f)/2.0f;
  1305. float balRangeR = (pData->postProc.balanceRight + 1.0f)/2.0f;
  1306. for (uint32_t k=0; k < frames; ++k)
  1307. {
  1308. if (isPair)
  1309. {
  1310. // left
  1311. outBuffer[i][k+timeOffset] = oldBufLeft[k] * (1.0f - balRangeL);
  1312. outBuffer[i][k+timeOffset] += outBuffer[i+1][k+timeOffset] * (1.0f - balRangeR);
  1313. }
  1314. else
  1315. {
  1316. // right
  1317. outBuffer[i][k+timeOffset] = outBuffer[i][k+timeOffset] * balRangeR;
  1318. outBuffer[i][k+timeOffset] += oldBufLeft[k] * balRangeL;
  1319. }
  1320. }
  1321. }
  1322. // Volume
  1323. if (doVolume)
  1324. {
  1325. for (uint32_t k=0; k < frames; ++k)
  1326. outBuffer[i][k+timeOffset] *= pData->postProc.volume;
  1327. }
  1328. }
  1329. } // End of Post-processing
  1330. #endif
  1331. // --------------------------------------------------------------------------------------------------------
  1332. pData->singleMutex.unlock();
  1333. return true;
  1334. }
  1335. void bufferSizeChanged(const uint32_t newBufferSize) override
  1336. {
  1337. CARLA_ASSERT_INT(newBufferSize > 0, newBufferSize);
  1338. carla_debug("VstPlugin::bufferSizeChanged(%i)", newBufferSize);
  1339. if (pData->active)
  1340. deactivate();
  1341. #if ! VST_FORCE_DEPRECATED
  1342. dispatcher(effSetBlockSizeAndSampleRate, 0, static_cast<int32_t>(newBufferSize), nullptr, static_cast<float>(pData->engine->getSampleRate()));
  1343. #endif
  1344. dispatcher(effSetBlockSize, 0, static_cast<int32_t>(newBufferSize), nullptr, 0.0f);
  1345. if (pData->active)
  1346. activate();
  1347. }
  1348. void sampleRateChanged(const double newSampleRate) override
  1349. {
  1350. CARLA_ASSERT_INT(newSampleRate > 0.0, newSampleRate);
  1351. carla_debug("VstPlugin::sampleRateChanged(%g)", newSampleRate);
  1352. if (pData->active)
  1353. deactivate();
  1354. #if ! VST_FORCE_DEPRECATED
  1355. dispatcher(effSetBlockSizeAndSampleRate, 0, static_cast<int32_t>(pData->engine->getBufferSize()), nullptr, static_cast<float>(newSampleRate));
  1356. #endif
  1357. dispatcher(effSetSampleRate, 0, 0, nullptr, static_cast<float>(newSampleRate));
  1358. if (pData->active)
  1359. activate();
  1360. }
  1361. // -------------------------------------------------------------------
  1362. // Plugin buffers
  1363. // nothing
  1364. // -------------------------------------------------------------------
  1365. // Post-poned UI Stuff
  1366. void uiParameterChange(const uint32_t index, const float value) noexcept override
  1367. {
  1368. CARLA_SAFE_ASSERT_RETURN(index < pData->param.count,);
  1369. if (fUI.type != UI::UI_OSC)
  1370. return;
  1371. if (pData->osc.data.target == nullptr)
  1372. return;
  1373. osc_send_control(pData->osc.data, pData->param.data[index].rindex, value);
  1374. }
  1375. void uiProgramChange(const uint32_t index) noexcept override
  1376. {
  1377. CARLA_SAFE_ASSERT_RETURN(index < pData->prog.count,);
  1378. if (fUI.type != UI::UI_OSC)
  1379. return;
  1380. if (pData->osc.data.target == nullptr)
  1381. return;
  1382. osc_send_program(pData->osc.data, index);
  1383. }
  1384. void uiNoteOn(const uint8_t channel, const uint8_t note, const uint8_t velo) noexcept override
  1385. {
  1386. CARLA_SAFE_ASSERT_RETURN(channel < MAX_MIDI_CHANNELS,);
  1387. CARLA_SAFE_ASSERT_RETURN(note < MAX_MIDI_NOTE,);
  1388. CARLA_SAFE_ASSERT_RETURN(velo > 0 && velo < MAX_MIDI_VALUE,);
  1389. if (fUI.type != UI::UI_OSC)
  1390. return;
  1391. if (pData->osc.data.target == nullptr)
  1392. return;
  1393. uint8_t midiData[4];
  1394. midiData[0] = 0;
  1395. midiData[1] = static_cast<uint8_t>(MIDI_STATUS_NOTE_ON + channel);
  1396. midiData[2] = note;
  1397. midiData[3] = velo;
  1398. osc_send_midi(pData->osc.data, midiData);
  1399. }
  1400. void uiNoteOff(const uint8_t channel, const uint8_t note) noexcept override
  1401. {
  1402. CARLA_SAFE_ASSERT_RETURN(channel < MAX_MIDI_CHANNELS,);
  1403. CARLA_SAFE_ASSERT_RETURN(note < MAX_MIDI_NOTE,);
  1404. if (fUI.type != UI::UI_OSC)
  1405. return;
  1406. if (pData->osc.data.target == nullptr)
  1407. return;
  1408. uint8_t midiData[4];
  1409. midiData[0] = 0;
  1410. midiData[1] = static_cast<uint8_t>(MIDI_STATUS_NOTE_OFF + channel);
  1411. midiData[2] = note;
  1412. midiData[3] = 0;
  1413. osc_send_midi(pData->osc.data, midiData);
  1414. }
  1415. // -------------------------------------------------------------------
  1416. protected:
  1417. void handlePluginUIClosed() override
  1418. {
  1419. CARLA_SAFE_ASSERT_RETURN(fUI.type == UI::UI_EMBED || fUI.type == UI::UI_EXTERNAL,);
  1420. CARLA_SAFE_ASSERT_RETURN(fUI.window != nullptr,);
  1421. carla_debug("VstPlugin::handlePluginUIClosed()");
  1422. showCustomUI(false);
  1423. pData->engine->callback(ENGINE_CALLBACK_UI_STATE_CHANGED, pData->id, 0, 0, 0.0f, nullptr);
  1424. }
  1425. void handlePluginUIResized(const uint width, const uint height) override
  1426. {
  1427. CARLA_SAFE_ASSERT_RETURN(fUI.type == UI::UI_EMBED,);
  1428. CARLA_SAFE_ASSERT_RETURN(fUI.window != nullptr,);
  1429. carla_debug("VstPlugin::handlePluginUIResized(%u, %u)", width, height);
  1430. return; // unused
  1431. (void)width; (void)height;
  1432. }
  1433. // -------------------------------------------------------------------
  1434. intptr_t dispatcher(int32_t opcode, int32_t index, intptr_t value, void* ptr, float opt) const noexcept
  1435. {
  1436. CARLA_SAFE_ASSERT_RETURN(fEffect != nullptr, 0);
  1437. #ifdef DEBUG
  1438. if (opcode != effIdle && opcode != effEditIdle && opcode != effProcessEvents)
  1439. carla_debug("VstPlugin::dispatcher(%02i:%s, %i, " P_INTPTR ", %p, %f)", opcode, vstEffectOpcode2str(opcode), index, value, ptr, opt);
  1440. #endif
  1441. try {
  1442. return fEffect->dispatcher(fEffect, opcode, index, value, ptr, opt);
  1443. } CARLA_SAFE_EXCEPTION_RETURN("Vst dispatcher", 0);
  1444. }
  1445. intptr_t handleAudioMasterCallback(const int32_t opcode, const int32_t index, const intptr_t value, void* const ptr, const float opt)
  1446. {
  1447. #ifdef DEBUG
  1448. if (opcode != audioMasterGetTime)
  1449. carla_debug("VstPlugin::handleAudioMasterCallback(%02i:%s, %i, " P_INTPTR ", %p, %f)", opcode, vstMasterOpcode2str(opcode), index, value, ptr, opt);
  1450. #endif
  1451. intptr_t ret = 0;
  1452. switch (opcode)
  1453. {
  1454. case audioMasterAutomate: {
  1455. CARLA_SAFE_ASSERT_BREAK(pData->enabled);
  1456. // plugins should never do this:
  1457. CARLA_SAFE_ASSERT_INT(index >= 0 && index < static_cast<int32_t>(pData->param.count), index);
  1458. if (index < 0 || index >= static_cast<int32_t>(pData->param.count))
  1459. break;
  1460. const uint32_t uindex(static_cast<uint32_t>(index));
  1461. const float fixedValue(pData->param.getFixedValue(uindex, opt));
  1462. // Called from plugin process thread, nasty!
  1463. if (pthread_equal(pthread_self(), fProcThread))
  1464. {
  1465. CARLA_SAFE_ASSERT(fIsProcessing);
  1466. pData->postponeRtEvent(kPluginPostRtEventParameterChange, index, 0, fixedValue);
  1467. }
  1468. // Called from UI
  1469. else if (fUI.isVisible)
  1470. {
  1471. CarlaPlugin::setParameterValue(uindex, fixedValue, false, true, true);
  1472. }
  1473. // Unknown
  1474. // TODO - check if plugin or UI is initializing
  1475. else
  1476. {
  1477. carla_stdout("audioMasterAutomate called from unknown source");
  1478. setParameterValue(uindex, fixedValue, true, true, true);
  1479. //pData->postponeRtEvent(kPluginPostRtEventParameterChange, index, 0, fixedValue);
  1480. }
  1481. break;
  1482. }
  1483. case audioMasterCurrentId:
  1484. // TODO
  1485. // if using old sdk, return effect->uniqueID
  1486. break;
  1487. case audioMasterIdle:
  1488. //pData->engine->callback(ENGINE_CALLBACK_IDLE, 0, 0, 0, 0.0f, nullptr);
  1489. //pData->engine->idle();
  1490. break;
  1491. #if ! VST_FORCE_DEPRECATED
  1492. case audioMasterPinConnected:
  1493. // Deprecated in VST SDK 2.4
  1494. // TODO
  1495. break;
  1496. case audioMasterWantMidi:
  1497. // Deprecated in VST SDK 2.4
  1498. pData->hints |= PLUGIN_WANTS_MIDI_INPUT;
  1499. break;
  1500. #endif
  1501. case audioMasterGetTime:
  1502. ret = (intptr_t)&fTimeInfo;
  1503. break;
  1504. case audioMasterProcessEvents:
  1505. CARLA_SAFE_ASSERT_RETURN(pData->enabled, 0);
  1506. CARLA_SAFE_ASSERT_RETURN(fIsProcessing, 0);
  1507. CARLA_SAFE_ASSERT_RETURN(pData->event.portOut != nullptr, 0);
  1508. if (fMidiEventCount >= kPluginMaxMidiEvents*2)
  1509. return 0;
  1510. if (const VstEvents* const vstEvents = (const VstEvents*)ptr)
  1511. {
  1512. for (int32_t i=0; i < vstEvents->numEvents && i < kPluginMaxMidiEvents*2; ++i)
  1513. {
  1514. if (vstEvents->events[i] == nullptr)
  1515. break;
  1516. const VstMidiEvent* const vstMidiEvent((const VstMidiEvent*)vstEvents->events[i]);
  1517. if (vstMidiEvent->type != kVstMidiType)
  1518. continue;
  1519. // reverse-find first free event, and put it there
  1520. for (uint32_t j=(kPluginMaxMidiEvents*2)-1; j >= fMidiEventCount; --j)
  1521. {
  1522. if (fMidiEvents[j].type == 0)
  1523. {
  1524. std::memcpy(&fMidiEvents[j], vstMidiEvent, sizeof(VstMidiEvent));
  1525. break;
  1526. }
  1527. }
  1528. }
  1529. }
  1530. ret = 1;
  1531. break;
  1532. #if ! VST_FORCE_DEPRECATED
  1533. case audioMasterSetTime:
  1534. // Deprecated in VST SDK 2.4
  1535. break;
  1536. case audioMasterTempoAt:
  1537. // Deprecated in VST SDK 2.4
  1538. ret = static_cast<intptr_t>(fTimeInfo.tempo * 10000);
  1539. break;
  1540. case audioMasterGetNumAutomatableParameters:
  1541. // Deprecated in VST SDK 2.4
  1542. ret = carla_fixValue<intptr_t>(0, static_cast<intptr_t>(pData->engine->getOptions().maxParameters), fEffect->numParams);
  1543. break;
  1544. case audioMasterGetParameterQuantization:
  1545. // Deprecated in VST SDK 2.4
  1546. ret = 1; // full single float precision
  1547. break;
  1548. #endif
  1549. #if 0
  1550. case audioMasterIOChanged:
  1551. CARLA_ASSERT(pData->enabled);
  1552. // TESTING
  1553. if (! pData->enabled)
  1554. {
  1555. ret = 1;
  1556. break;
  1557. }
  1558. if (x_engine->getOptions().processMode == PROCESS_MODE_CONTINUOUS_RACK)
  1559. {
  1560. carla_stderr2("VstPlugin::handleAudioMasterIOChanged() - plugin asked IO change, but it's not supported in rack mode");
  1561. return 0;
  1562. }
  1563. engineProcessLock();
  1564. m_enabled = false;
  1565. engineProcessUnlock();
  1566. if (m_active)
  1567. {
  1568. effect->dispatcher(effect, effStopProcess, 0, 0, nullptr, 0.0f);
  1569. effect->dispatcher(effect, effMainsChanged, 0, 0, nullptr, 0.0f);
  1570. }
  1571. reload();
  1572. if (m_active)
  1573. {
  1574. effect->dispatcher(effect, effMainsChanged, 0, 1, nullptr, 0.0f);
  1575. effect->dispatcher(effect, effStartProcess, 0, 0, nullptr, 0.0f);
  1576. }
  1577. x_engine->callback(CALLBACK_RELOAD_ALL, m_id, 0, 0, 0.0, nullptr);
  1578. ret = 1;
  1579. break;
  1580. #endif
  1581. #if ! VST_FORCE_DEPRECATED
  1582. case audioMasterNeedIdle:
  1583. // Deprecated in VST SDK 2.4
  1584. fNeedIdle = true;
  1585. ret = 1;
  1586. break;
  1587. #endif
  1588. case audioMasterSizeWindow:
  1589. CARLA_SAFE_ASSERT_BREAK(fUI.window != nullptr);
  1590. CARLA_SAFE_ASSERT_BREAK(index > 0);
  1591. CARLA_SAFE_ASSERT_BREAK(value > 0);
  1592. fUI.window->setSize(static_cast<uint>(index), static_cast<uint>(value), true);
  1593. ret = 1;
  1594. break;
  1595. case audioMasterGetSampleRate:
  1596. ret = static_cast<intptr_t>(pData->engine->getSampleRate());
  1597. break;
  1598. case audioMasterGetBlockSize:
  1599. ret = static_cast<intptr_t>(pData->engine->getBufferSize());
  1600. break;
  1601. case audioMasterGetInputLatency:
  1602. ret = 0;
  1603. break;
  1604. case audioMasterGetOutputLatency:
  1605. ret = 0;
  1606. break;
  1607. #if ! VST_FORCE_DEPRECATED
  1608. case audioMasterGetPreviousPlug:
  1609. // Deprecated in VST SDK 2.4
  1610. // TODO
  1611. break;
  1612. case audioMasterGetNextPlug:
  1613. // Deprecated in VST SDK 2.4
  1614. // TODO
  1615. break;
  1616. case audioMasterWillReplaceOrAccumulate:
  1617. // Deprecated in VST SDK 2.4
  1618. ret = 1; // replace
  1619. break;
  1620. #endif
  1621. case audioMasterGetCurrentProcessLevel:
  1622. if (pthread_equal(pthread_self(), fProcThread))
  1623. {
  1624. CARLA_SAFE_ASSERT(fIsProcessing);
  1625. if (pData->engine->isOffline())
  1626. ret = kVstProcessLevelOffline;
  1627. else
  1628. ret = kVstProcessLevelRealtime;
  1629. }
  1630. else
  1631. ret = kVstProcessLevelUser;
  1632. break;
  1633. case audioMasterGetAutomationState:
  1634. ret = pData->active ? kVstAutomationReadWrite : kVstAutomationOff;
  1635. break;
  1636. case audioMasterOfflineStart:
  1637. case audioMasterOfflineRead:
  1638. case audioMasterOfflineWrite:
  1639. case audioMasterOfflineGetCurrentPass:
  1640. case audioMasterOfflineGetCurrentMetaPass:
  1641. // TODO
  1642. break;
  1643. #if ! VST_FORCE_DEPRECATED
  1644. case audioMasterSetOutputSampleRate:
  1645. // Deprecated in VST SDK 2.4
  1646. break;
  1647. case audioMasterGetOutputSpeakerArrangement:
  1648. // Deprecated in VST SDK 2.4
  1649. // TODO
  1650. break;
  1651. #endif
  1652. case audioMasterVendorSpecific:
  1653. if (index == 0xedcd && value == 0 && ptr != nullptr && std::strcmp((const char*)ptr, "EditorClosed") == 0)
  1654. {
  1655. CARLA_SAFE_ASSERT_BREAK(fUI.type == UI::UI_EXTERNAL);
  1656. handlePluginUIClosed();
  1657. break;
  1658. }
  1659. // TODO - cockos extensions
  1660. break;
  1661. #if ! VST_FORCE_DEPRECATED
  1662. case audioMasterSetIcon:
  1663. // Deprecated in VST SDK 2.4
  1664. break;
  1665. #endif
  1666. #if ! VST_FORCE_DEPRECATED
  1667. case audioMasterOpenWindow:
  1668. case audioMasterCloseWindow:
  1669. // Deprecated in VST SDK 2.4
  1670. // TODO
  1671. break;
  1672. #endif
  1673. case audioMasterGetDirectory:
  1674. // TODO
  1675. break;
  1676. case audioMasterUpdateDisplay:
  1677. // Idle UI if visible
  1678. if (fUI.isVisible)
  1679. dispatcher(effEditIdle, 0, 0, nullptr, 0.0f);
  1680. // Update current program
  1681. if (pData->prog.count > 0)
  1682. {
  1683. const int32_t current = static_cast<int32_t>(dispatcher(effGetProgram, 0, 0, nullptr, 0.0f));
  1684. if (current >= 0 && current < static_cast<int32_t>(pData->prog.count))
  1685. {
  1686. char strBuf[STR_MAX+1] = { '\0' };
  1687. dispatcher(effGetProgramName, 0, 0, strBuf, 0.0f);
  1688. if (pData->prog.names[current] != nullptr)
  1689. delete[] pData->prog.names[current];
  1690. pData->prog.names[current] = carla_strdup(strBuf);
  1691. if (pData->prog.current != current)
  1692. {
  1693. pData->prog.current = current;
  1694. pData->engine->callback(ENGINE_CALLBACK_PROGRAM_CHANGED, pData->id, current, 0, 0.0f, nullptr);
  1695. }
  1696. }
  1697. }
  1698. pData->engine->callback(ENGINE_CALLBACK_UPDATE, pData->id, 0, 0, 0.0f, nullptr);
  1699. ret = 1;
  1700. break;
  1701. case audioMasterBeginEdit:
  1702. case audioMasterEndEdit:
  1703. // TODO
  1704. break;
  1705. case audioMasterOpenFileSelector:
  1706. case audioMasterCloseFileSelector:
  1707. // TODO
  1708. break;
  1709. #if ! VST_FORCE_DEPRECATED
  1710. case audioMasterEditFile:
  1711. // Deprecated in VST SDK 2.4
  1712. // TODO
  1713. break;
  1714. case audioMasterGetChunkFile:
  1715. // Deprecated in VST SDK 2.4
  1716. // TODO
  1717. break;
  1718. case audioMasterGetInputSpeakerArrangement:
  1719. // Deprecated in VST SDK 2.4
  1720. // TODO
  1721. break;
  1722. #endif
  1723. default:
  1724. carla_debug("VstPlugin::handleAudioMasterCallback(%02i:%s, %i, " P_INTPTR ", %p, %f) UNDEF", opcode, vstMasterOpcode2str(opcode), index, value, ptr, opt);
  1725. break;
  1726. }
  1727. return ret;
  1728. // unused
  1729. (void)opt;
  1730. }
  1731. bool canDo(const char* const feature) const noexcept
  1732. {
  1733. try {
  1734. return (fEffect->dispatcher(fEffect, effCanDo, 0, 0, const_cast<char*>(feature), 0.0f) == 1);
  1735. } CARLA_SAFE_EXCEPTION_RETURN("vstPluginCanDo", false);
  1736. }
  1737. bool hasMidiInput() const noexcept
  1738. {
  1739. return (canDo("receiveVstEvents") || canDo("receiveVstMidiEvent") || (fEffect->flags & effFlagsIsSynth) > 0 || (pData->hints & PLUGIN_WANTS_MIDI_INPUT));
  1740. }
  1741. bool hasMidiOutput() const noexcept
  1742. {
  1743. return (canDo("sendVstEvents") || canDo("sendVstMidiEvent"));
  1744. }
  1745. // -------------------------------------------------------------------
  1746. const void* getNativeDescriptor() const noexcept override
  1747. {
  1748. return fEffect;
  1749. }
  1750. // -------------------------------------------------------------------
  1751. public:
  1752. bool init(const char* const filename, const char* const name, const int64_t uniqueId)
  1753. {
  1754. CARLA_SAFE_ASSERT_RETURN(pData->engine != nullptr, false);
  1755. // ---------------------------------------------------------------
  1756. // first checks
  1757. if (pData->client != nullptr)
  1758. {
  1759. pData->engine->setLastError("Plugin client is already registered");
  1760. return false;
  1761. }
  1762. if (filename == nullptr || filename[0] == '\0')
  1763. {
  1764. pData->engine->setLastError("null filename");
  1765. return false;
  1766. }
  1767. // ---------------------------------------------------------------
  1768. // open DLL
  1769. if (! pData->libOpen(filename))
  1770. {
  1771. pData->engine->setLastError(pData->libError(filename));
  1772. return false;
  1773. }
  1774. // ---------------------------------------------------------------
  1775. // get DLL main entry
  1776. VST_Function vstFn = (VST_Function)pData->libSymbol("VSTPluginMain");
  1777. if (vstFn == nullptr)
  1778. {
  1779. vstFn = (VST_Function)pData->libSymbol("main");
  1780. if (vstFn == nullptr)
  1781. {
  1782. pData->engine->setLastError("Could not find the VST main entry in the plugin library");
  1783. return false;
  1784. }
  1785. }
  1786. // ---------------------------------------------------------------
  1787. // initialize plugin (part 1)
  1788. sLastVstPlugin = this;
  1789. fEffect = vstFn(carla_vst_audioMasterCallback);
  1790. sLastVstPlugin = nullptr;
  1791. if (fEffect == nullptr)
  1792. {
  1793. pData->engine->setLastError("Plugin failed to initialize");
  1794. return false;
  1795. }
  1796. if (fEffect->magic != kEffectMagic)
  1797. {
  1798. pData->engine->setLastError("Plugin is not valid (wrong vst effect magic code)");
  1799. return false;
  1800. }
  1801. #ifdef VESTIGE_HEADER
  1802. fEffect->ptr1 = this;
  1803. #else
  1804. fEffect->resvd1 = (intptr_t)this;
  1805. #endif
  1806. dispatcher(effOpen, 0, 0, nullptr, 0.0f);
  1807. // ---------------------------------------------------------------
  1808. // get info
  1809. if (name != nullptr && name[0] != '\0')
  1810. {
  1811. pData->name = pData->engine->getUniquePluginName(name);
  1812. }
  1813. else
  1814. {
  1815. char strBuf[STR_MAX+1];
  1816. carla_zeroChar(strBuf, STR_MAX+1);
  1817. dispatcher(effGetEffectName, 0, 0, strBuf, 0.0f);
  1818. if (strBuf[0] != '\0')
  1819. pData->name = pData->engine->getUniquePluginName(strBuf);
  1820. else if (const char* const shortname = std::strrchr(filename, CARLA_OS_SEP))
  1821. pData->name = pData->engine->getUniquePluginName(shortname+1);
  1822. else
  1823. pData->name = pData->engine->getUniquePluginName("unknown");
  1824. }
  1825. pData->filename = carla_strdup(filename);
  1826. // ---------------------------------------------------------------
  1827. // register client
  1828. pData->client = pData->engine->addClient(this);
  1829. if (pData->client == nullptr || ! pData->client->isOk())
  1830. {
  1831. pData->engine->setLastError("Failed to register plugin client");
  1832. return false;
  1833. }
  1834. // ---------------------------------------------------------------
  1835. // initialize plugin (part 2)
  1836. #if ! VST_FORCE_DEPRECATED
  1837. dispatcher(effSetBlockSizeAndSampleRate, 0, static_cast<int32_t>(pData->engine->getBufferSize()), nullptr, static_cast<float>(pData->engine->getSampleRate()));
  1838. #endif
  1839. dispatcher(effSetSampleRate, 0, 0, nullptr, static_cast<float>(pData->engine->getSampleRate()));
  1840. dispatcher(effSetBlockSize, 0, static_cast<int32_t>(pData->engine->getBufferSize()), nullptr, 0.0f);
  1841. dispatcher(effSetProcessPrecision, 0, kVstProcessPrecision32, nullptr, 0.0f);
  1842. if (dispatcher(effGetVstVersion, 0, 0, nullptr, 0.0f) < kVstVersion)
  1843. pData->hints |= PLUGIN_USES_OLD_VSTSDK;
  1844. if (static_cast<uintptr_t>(dispatcher(effCanDo, 0, 0, const_cast<char*>("hasCockosExtensions"), 0.0f)) == 0xbeef0000)
  1845. pData->hints |= PLUGIN_HAS_COCKOS_EXTENSIONS;
  1846. // ---------------------------------------------------------------
  1847. // gui stuff
  1848. if (fEffect->flags & effFlagsHasEditor)
  1849. {
  1850. fUI.type = UI::UI_EMBED;
  1851. if ((fEffect->flags & effFlagsProgramChunks) == 0 && pData->engine->getOptions().preferUiBridges)
  1852. {
  1853. CarlaString bridgeBinary(pData->engine->getOptions().binaryDir);
  1854. #if defined(CARLA_OS_LINUX)
  1855. bridgeBinary += CARLA_OS_SEP_STR "carla-bridge-vst-x11";
  1856. #endif
  1857. if (bridgeBinary.isNotEmpty() && File(bridgeBinary.buffer()).existsAsFile())
  1858. {
  1859. pData->osc.thread.setOscData(bridgeBinary, nullptr);
  1860. fUI.type = UI::UI_OSC;
  1861. }
  1862. }
  1863. }
  1864. else if (vstPluginCanDo(fEffect, "ExternalUI"))
  1865. {
  1866. fUI.type = UI::UI_EXTERNAL;
  1867. }
  1868. // ---------------------------------------------------------------
  1869. // set default options
  1870. pData->options = 0x0;
  1871. pData->options |= PLUGIN_OPTION_MAP_PROGRAM_CHANGES;
  1872. if (fEffect->flags & effFlagsProgramChunks)
  1873. pData->options |= PLUGIN_OPTION_USE_CHUNKS;
  1874. if (hasMidiInput())
  1875. {
  1876. pData->options |= PLUGIN_OPTION_FIXED_BUFFERS;
  1877. pData->options |= PLUGIN_OPTION_SEND_CHANNEL_PRESSURE;
  1878. pData->options |= PLUGIN_OPTION_SEND_NOTE_AFTERTOUCH;
  1879. pData->options |= PLUGIN_OPTION_SEND_PITCHBEND;
  1880. pData->options |= PLUGIN_OPTION_SEND_ALL_SOUND_OFF;
  1881. }
  1882. return true;
  1883. // unused
  1884. (void)uniqueId;
  1885. }
  1886. private:
  1887. int fUnique1;
  1888. AEffect* fEffect;
  1889. uint32_t fMidiEventCount;
  1890. VstMidiEvent fMidiEvents[kPluginMaxMidiEvents*2];
  1891. VstTimeInfo fTimeInfo;
  1892. bool fNeedIdle;
  1893. void* fLastChunk;
  1894. bool fIsProcessing;
  1895. pthread_t fProcThread;
  1896. struct FixedVstEvents {
  1897. int32_t numEvents;
  1898. intptr_t reserved;
  1899. VstEvent* data[kPluginMaxMidiEvents*2];
  1900. FixedVstEvents()
  1901. : numEvents(0),
  1902. reserved(0)
  1903. {
  1904. carla_fill<VstEvent*>(data, nullptr, kPluginMaxMidiEvents*2);
  1905. }
  1906. CARLA_DECLARE_NON_COPY_STRUCT(FixedVstEvents);
  1907. } fEvents;
  1908. struct UI {
  1909. enum Type {
  1910. UI_NULL = 0,
  1911. UI_EMBED = 1,
  1912. UI_EXTERNAL = 2,
  1913. UI_OSC = 3
  1914. } type;
  1915. bool isVisible; // not used in OSC mode
  1916. CarlaPluginUI* window;
  1917. UI()
  1918. : type(UI_NULL),
  1919. isVisible(false),
  1920. window(nullptr) {}
  1921. ~UI()
  1922. {
  1923. CARLA_ASSERT(! isVisible);
  1924. if (window != nullptr)
  1925. {
  1926. delete window;
  1927. window = nullptr;
  1928. }
  1929. }
  1930. CARLA_DECLARE_NON_COPY_STRUCT(UI);
  1931. } fUI;
  1932. int fUnique2;
  1933. static VstPlugin* sLastVstPlugin;
  1934. // -------------------------------------------------------------------
  1935. static intptr_t carla_vst_hostCanDo(const char* const feature)
  1936. {
  1937. carla_debug("carla_vst_hostCanDo(\"%s\")", feature);
  1938. if (std::strcmp(feature, "supplyIdle") == 0)
  1939. return 1;
  1940. if (std::strcmp(feature, "sendVstEvents") == 0)
  1941. return 1;
  1942. if (std::strcmp(feature, "sendVstMidiEvent") == 0)
  1943. return 1;
  1944. if (std::strcmp(feature, "sendVstMidiEventFlagIsRealtime") == 0)
  1945. return 1;
  1946. if (std::strcmp(feature, "sendVstTimeInfo") == 0)
  1947. return 1;
  1948. if (std::strcmp(feature, "receiveVstEvents") == 0)
  1949. return 1;
  1950. if (std::strcmp(feature, "receiveVstMidiEvent") == 0)
  1951. return 1;
  1952. if (std::strcmp(feature, "receiveVstTimeInfo") == 0)
  1953. return -1;
  1954. if (std::strcmp(feature, "reportConnectionChanges") == 0)
  1955. return -1;
  1956. if (std::strcmp(feature, "acceptIOChanges") == 0)
  1957. return 1;
  1958. if (std::strcmp(feature, "sizeWindow") == 0)
  1959. return 1;
  1960. if (std::strcmp(feature, "offline") == 0)
  1961. return -1;
  1962. if (std::strcmp(feature, "openFileSelector") == 0)
  1963. return -1;
  1964. if (std::strcmp(feature, "closeFileSelector") == 0)
  1965. return -1;
  1966. if (std::strcmp(feature, "startStopProcess") == 0)
  1967. return 1;
  1968. if (std::strcmp(feature, "supportShell") == 0)
  1969. return -1;
  1970. if (std::strcmp(feature, "shellCategory") == 0)
  1971. return -1;
  1972. // unimplemented
  1973. carla_stderr("carla_vst_hostCanDo(\"%s\") - unknown feature", feature);
  1974. return 0;
  1975. }
  1976. static intptr_t VSTCALLBACK carla_vst_audioMasterCallback(AEffect* effect, int32_t opcode, int32_t index, intptr_t value, void* ptr, float opt)
  1977. {
  1978. #if defined(DEBUG) && ! defined(CARLA_OS_WIN)
  1979. if (opcode != audioMasterGetTime && opcode != audioMasterProcessEvents && opcode != audioMasterGetCurrentProcessLevel && opcode != audioMasterGetOutputLatency)
  1980. carla_debug("carla_vst_audioMasterCallback(%p, %02i:%s, %i, " P_INTPTR ", %p, %f)", effect, opcode, vstMasterOpcode2str(opcode), index, value, ptr, opt);
  1981. #endif
  1982. switch (opcode)
  1983. {
  1984. case audioMasterVersion:
  1985. return kVstVersion;
  1986. case audioMasterGetVendorString:
  1987. CARLA_SAFE_ASSERT_RETURN(ptr != nullptr, 0);
  1988. std::strcpy((char*)ptr, "falkTX");
  1989. return 1;
  1990. case audioMasterGetProductString:
  1991. CARLA_SAFE_ASSERT_RETURN(ptr != nullptr, 0);
  1992. std::strcpy((char*)ptr, "Carla");
  1993. return 1;
  1994. case audioMasterGetVendorVersion:
  1995. return 0x110; // 1.1.0
  1996. case audioMasterCanDo:
  1997. CARLA_SAFE_ASSERT_RETURN(ptr != nullptr, 0);
  1998. return carla_vst_hostCanDo((const char*)ptr);
  1999. case audioMasterGetLanguage:
  2000. return kVstLangEnglish;
  2001. }
  2002. // Check if 'resvd1' points to us, otherwise register ourselfs if possible
  2003. VstPlugin* self = nullptr;
  2004. if (effect != nullptr)
  2005. {
  2006. #ifdef VESTIGE_HEADER
  2007. if (effect->ptr1 != nullptr)
  2008. {
  2009. self = (VstPlugin*)effect->ptr1;
  2010. if (self->fUnique1 != self->fUnique2)
  2011. self = nullptr;
  2012. }
  2013. #else
  2014. if (effect->resvd1 != 0)
  2015. {
  2016. self = (VstPlugin*)effect->resvd1;
  2017. if (self->fUnique1 != self->fUnique2)
  2018. self = nullptr;
  2019. }
  2020. #endif
  2021. if (self != nullptr)
  2022. {
  2023. if (self->fEffect == nullptr)
  2024. self->fEffect = effect;
  2025. if (self->fEffect != effect)
  2026. {
  2027. carla_stderr2("carla_vst_audioMasterCallback() - host pointer mismatch: %p != %p", self->fEffect, effect);
  2028. self = nullptr;
  2029. }
  2030. }
  2031. else if (sLastVstPlugin != nullptr)
  2032. {
  2033. #ifdef VESTIGE_HEADER
  2034. effect->ptr1 = sLastVstPlugin;
  2035. #else
  2036. effect->resvd1 = (intptr_t)sLastVstPlugin;
  2037. #endif
  2038. self = sLastVstPlugin;
  2039. }
  2040. }
  2041. return (self != nullptr) ? self->handleAudioMasterCallback(opcode, index, value, ptr, opt) : 0;
  2042. }
  2043. CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(VstPlugin)
  2044. };
  2045. VstPlugin* VstPlugin::sLastVstPlugin = nullptr;
  2046. CARLA_BACKEND_END_NAMESPACE
  2047. #endif // ! USE_JUCE_FOR_VST
  2048. // -------------------------------------------------------------------------------------------------------------------
  2049. CARLA_BACKEND_START_NAMESPACE
  2050. CarlaPlugin* CarlaPlugin::newVST(const Initializer& init)
  2051. {
  2052. carla_debug("CarlaPlugin::newVST({%p, \"%s\", \"%s\", " P_INT64 "})", init.engine, init.filename, init.name, init.uniqueId);
  2053. #ifdef USE_JUCE_FOR_VST
  2054. return newJuce(init, "VST");
  2055. #else
  2056. VstPlugin* const plugin(new VstPlugin(init.engine, init.id));
  2057. if (! plugin->init(init.filename, init.name, init.uniqueId))
  2058. {
  2059. delete plugin;
  2060. return nullptr;
  2061. }
  2062. plugin->reload();
  2063. if (init.engine->getProccessMode() == ENGINE_PROCESS_MODE_CONTINUOUS_RACK && ! plugin->canRunInRack())
  2064. {
  2065. init.engine->setLastError("Carla's rack mode can only work with Stereo VST plugins, sorry!");
  2066. delete plugin;
  2067. return nullptr;
  2068. }
  2069. return plugin;
  2070. #endif
  2071. }
  2072. // -------------------------------------------------------------------------------------------------------------------
  2073. CARLA_BACKEND_END_NAMESPACE