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.

815 lines
24KB

  1. /*
  2. * Carla Juce Plugin
  3. * Copyright (C) 2013-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. #ifdef HAVE_JUCE
  20. #include "CarlaBackendUtils.hpp"
  21. #include "JucePluginWindow.hpp"
  22. #include "juce_audio_processors.h"
  23. using namespace juce;
  24. CARLA_BACKEND_START_NAMESPACE
  25. class JucePlugin : public CarlaPlugin
  26. {
  27. public:
  28. JucePlugin(CarlaEngine* const engine, const uint id)
  29. : CarlaPlugin(engine, id),
  30. fInstance(nullptr),
  31. fAudioBuffer(1, 0)
  32. {
  33. carla_debug("JucePlugin::JucePlugin(%p, %i)", engine, id);
  34. fMidiBuffer.ensureSize(2048);
  35. fMidiBuffer.clear();
  36. }
  37. ~JucePlugin() override
  38. {
  39. carla_debug("JucePlugin::~JucePlugin()");
  40. // close UI
  41. if (pData->hints & PLUGIN_HAS_CUSTOM_UI)
  42. showCustomUI(false);
  43. pData->singleMutex.lock();
  44. pData->masterMutex.lock();
  45. if (pData->client != nullptr && pData->client->isActive())
  46. pData->client->deactivate();
  47. if (pData->active)
  48. {
  49. deactivate();
  50. pData->active = false;
  51. }
  52. if (fInstance != nullptr)
  53. {
  54. delete fInstance;
  55. fInstance = nullptr;
  56. }
  57. clearBuffers();
  58. }
  59. // -------------------------------------------------------------------
  60. // Information (base)
  61. PluginType getType() const noexcept override
  62. {
  63. PluginType type = PLUGIN_NONE;
  64. try {
  65. type = getPluginTypeFromString(fDesc.pluginFormatName.toRawUTF8());
  66. } catch(...) {}
  67. return type;
  68. }
  69. PluginCategory getCategory() const noexcept override
  70. {
  71. PluginCategory category = PLUGIN_CATEGORY_NONE;
  72. try {
  73. category = getPluginCategoryFromName(fDesc.category.toRawUTF8());
  74. } catch(...) {}
  75. return category;
  76. }
  77. long getUniqueId() const noexcept override
  78. {
  79. return fDesc.uid;
  80. }
  81. // -------------------------------------------------------------------
  82. // Information (count)
  83. // nothing
  84. // -------------------------------------------------------------------
  85. // Information (current data)
  86. // nothing
  87. // -------------------------------------------------------------------
  88. // Information (per-plugin data)
  89. unsigned int getOptionsAvailable() const noexcept override
  90. {
  91. CARLA_SAFE_ASSERT_RETURN(fInstance != nullptr, 0x0);
  92. unsigned int options = 0x0;
  93. //options |= PLUGIN_OPTION_FIXED_BUFFERS;
  94. options |= PLUGIN_OPTION_MAP_PROGRAM_CHANGES;
  95. //options |= PLUGIN_OPTION_USE_CHUNKS;
  96. if (fInstance->acceptsMidi())
  97. {
  98. options |= PLUGIN_OPTION_SEND_CONTROL_CHANGES;
  99. options |= PLUGIN_OPTION_SEND_CHANNEL_PRESSURE;
  100. options |= PLUGIN_OPTION_SEND_NOTE_AFTERTOUCH;
  101. options |= PLUGIN_OPTION_SEND_PITCHBEND;
  102. options |= PLUGIN_OPTION_SEND_ALL_SOUND_OFF;
  103. }
  104. return options;
  105. }
  106. float getParameterValue(const uint32_t parameterId) const noexcept override
  107. {
  108. CARLA_SAFE_ASSERT_RETURN(parameterId < pData->param.count, 0.0f);
  109. CARLA_SAFE_ASSERT_RETURN(fInstance != nullptr, 0.0f);
  110. return fInstance->getParameter(static_cast<int>(parameterId));
  111. }
  112. void getLabel(char* const strBuf) const noexcept override
  113. {
  114. std::strncpy(strBuf, fDesc.name.toRawUTF8(), STR_MAX);
  115. }
  116. void getMaker(char* const strBuf) const noexcept override
  117. {
  118. std::strncpy(strBuf, fDesc.manufacturerName.toRawUTF8(), STR_MAX);
  119. }
  120. void getCopyright(char* const strBuf) const noexcept override
  121. {
  122. getMaker(strBuf);
  123. }
  124. void getRealName(char* const strBuf) const noexcept override
  125. {
  126. CARLA_SAFE_ASSERT_RETURN(fInstance != nullptr,);
  127. std::strncpy(strBuf, fInstance->getName().toRawUTF8(), STR_MAX);
  128. }
  129. void getParameterName(const uint32_t parameterId, char* const strBuf) const noexcept override
  130. {
  131. CARLA_SAFE_ASSERT_RETURN(parameterId < pData->param.count,);
  132. CARLA_SAFE_ASSERT_RETURN(fInstance != nullptr,);
  133. std::strncpy(strBuf, fInstance->getParameterName(static_cast<int>(parameterId)).toRawUTF8(), STR_MAX);
  134. }
  135. void getParameterUnit(const uint32_t parameterId, char* const strBuf) const noexcept override
  136. {
  137. CARLA_SAFE_ASSERT_RETURN(parameterId < pData->param.count,);
  138. CARLA_SAFE_ASSERT_RETURN(fInstance != nullptr,);
  139. std::strncpy(strBuf, fInstance->getParameterLabel(static_cast<int>(parameterId)).toRawUTF8(), STR_MAX);
  140. }
  141. // -------------------------------------------------------------------
  142. // Set data (state)
  143. // nothing
  144. // -------------------------------------------------------------------
  145. // Set data (internal stuff)
  146. void setName(const char* const newName) override
  147. {
  148. CarlaPlugin::setName(newName);
  149. if (fWindow != nullptr)
  150. {
  151. String uiName(pData->name);
  152. uiName += " (JUCE GUI)";
  153. fWindow->setName(uiName);
  154. }
  155. }
  156. // -------------------------------------------------------------------
  157. // Set data (plugin-specific stuff)
  158. void setParameterValue(const uint32_t parameterId, const float value, const bool sendGui, const bool sendOsc, const bool sendCallback) noexcept override
  159. {
  160. CARLA_SAFE_ASSERT_RETURN(parameterId < pData->param.count,);
  161. CARLA_SAFE_ASSERT_RETURN(fInstance != nullptr,);
  162. const float fixedValue(pData->param.getFixedValue(parameterId, value));
  163. fInstance->setParameter(static_cast<int>(parameterId), value);
  164. CarlaPlugin::setParameterValue(parameterId, fixedValue, sendGui, sendOsc, sendCallback);
  165. }
  166. // -------------------------------------------------------------------
  167. // Set ui stuff
  168. void showCustomUI(const bool yesNo) override
  169. {
  170. CARLA_SAFE_ASSERT_RETURN(fInstance != nullptr,);
  171. if (yesNo)
  172. {
  173. if (fWindow == nullptr)
  174. {
  175. String uiName(pData->name);
  176. uiName += " (JUCE GUI)";
  177. fWindow = new JucePluginWindow();
  178. fWindow->setName(uiName);
  179. }
  180. if (AudioProcessorEditor* const editor = fInstance->createEditorIfNeeded())
  181. fWindow->show(editor);
  182. }
  183. else
  184. {
  185. if (fWindow != nullptr)
  186. fWindow->hide();
  187. if (AudioProcessorEditor* const editor = fInstance->getActiveEditor())
  188. delete editor;
  189. fWindow = nullptr;
  190. }
  191. }
  192. void idle() override
  193. {
  194. if (fWindow != nullptr)
  195. {
  196. if (fWindow->wasClosedByUser())
  197. {
  198. showCustomUI(false);
  199. pData->engine->callback(ENGINE_CALLBACK_UI_STATE_CHANGED, pData->id, 0, 0, 0.0f, nullptr);
  200. }
  201. }
  202. CarlaPlugin::idle();
  203. }
  204. // -------------------------------------------------------------------
  205. // Plugin state
  206. void reload() override
  207. {
  208. CARLA_SAFE_ASSERT_RETURN(pData->engine != nullptr,);
  209. CARLA_SAFE_ASSERT_RETURN(fInstance != nullptr,);
  210. carla_debug("VstPlugin::reload() - start");
  211. const EngineProcessMode processMode(pData->engine->getProccessMode());
  212. // Safely disable plugin for reload
  213. const ScopedDisabler sd(this);
  214. if (pData->active)
  215. deactivate();
  216. clearBuffers();
  217. fInstance->refreshParameterList();
  218. uint32_t aIns, aOuts, mIns, mOuts, params;
  219. aIns = aOuts = mIns = mOuts = params = 0;
  220. bool needsCtrlIn, needsCtrlOut;
  221. needsCtrlIn = needsCtrlOut = false;
  222. aIns = (fInstance->getNumInputChannels() > 0) ? static_cast<uint32_t>(fInstance->getNumInputChannels()) : 0;
  223. aOuts = (fInstance->getNumOutputChannels() > 0) ? static_cast<uint32_t>(fInstance->getNumOutputChannels()) : 0;
  224. params = (fInstance->getNumParameters() > 0) ? static_cast<uint32_t>(fInstance->getNumParameters()) : 0;
  225. if (fInstance->acceptsMidi())
  226. {
  227. mIns = 1;
  228. needsCtrlIn = true;
  229. }
  230. if (fInstance->producesMidi())
  231. {
  232. mOuts = 1;
  233. needsCtrlOut = true;
  234. }
  235. if (aIns > 0)
  236. {
  237. pData->audioIn.createNew(aIns);
  238. }
  239. if (aOuts > 0)
  240. {
  241. pData->audioOut.createNew(aOuts);
  242. needsCtrlIn = true;
  243. }
  244. if (params > 0)
  245. {
  246. pData->param.createNew(params, false);
  247. needsCtrlIn = true;
  248. }
  249. const uint portNameSize(pData->engine->getMaxPortNameSize());
  250. CarlaString portName;
  251. // Audio Ins
  252. for (uint32_t j=0; j < aIns; ++j)
  253. {
  254. portName.clear();
  255. if (processMode == ENGINE_PROCESS_MODE_SINGLE_CLIENT)
  256. {
  257. portName = pData->name;
  258. portName += ":";
  259. }
  260. if (aIns > 1)
  261. {
  262. portName += "input_";
  263. portName += CarlaString(j+1);
  264. }
  265. else
  266. portName += "input";
  267. portName.truncate(portNameSize);
  268. pData->audioIn.ports[j].port = (CarlaEngineAudioPort*)pData->client->addPort(kEnginePortTypeAudio, portName, true);
  269. pData->audioIn.ports[j].rindex = j;
  270. }
  271. // Audio Outs
  272. for (uint32_t j=0; j < aOuts; ++j)
  273. {
  274. portName.clear();
  275. if (processMode == ENGINE_PROCESS_MODE_SINGLE_CLIENT)
  276. {
  277. portName = pData->name;
  278. portName += ":";
  279. }
  280. if (aOuts > 1)
  281. {
  282. portName += "output_";
  283. portName += CarlaString(j+1);
  284. }
  285. else
  286. portName += "output";
  287. portName.truncate(portNameSize);
  288. pData->audioOut.ports[j].port = (CarlaEngineAudioPort*)pData->client->addPort(kEnginePortTypeAudio, portName, false);
  289. pData->audioOut.ports[j].rindex = j;
  290. }
  291. for (uint32_t j=0; j < params; ++j)
  292. {
  293. pData->param.data[j].type = PARAMETER_INPUT;
  294. pData->param.data[j].hints = 0x0;
  295. pData->param.data[j].index = static_cast<int32_t>(j);
  296. pData->param.data[j].rindex = static_cast<int32_t>(j);
  297. pData->param.data[j].midiCC = -1;
  298. pData->param.data[j].midiChannel = 0;
  299. float min, max, def, step, stepSmall, stepLarge;
  300. // TODO
  301. //const int numSteps(fInstance->getParameterNumSteps(static_cast<int>(j)));
  302. {
  303. min = 0.0f;
  304. max = 1.0f;
  305. step = 0.001f;
  306. stepSmall = 0.0001f;
  307. stepLarge = 0.1f;
  308. }
  309. pData->param.data[j].hints |= PARAMETER_IS_ENABLED;
  310. #ifndef BUILD_BRIDGE
  311. //pData->param.data[j].hints |= PARAMETER_USES_CUSTOM_TEXT;
  312. #endif
  313. if (fInstance->isParameterAutomatable(static_cast<int>(j)))
  314. pData->param.data[j].hints |= PARAMETER_IS_AUTOMABLE;
  315. // FIXME?
  316. def = fInstance->getParameterDefaultValue(static_cast<int>(j));
  317. if (def < min)
  318. def = min;
  319. else if (def > max)
  320. def = max;
  321. pData->param.ranges[j].min = min;
  322. pData->param.ranges[j].max = max;
  323. pData->param.ranges[j].def = def;
  324. pData->param.ranges[j].step = step;
  325. pData->param.ranges[j].stepSmall = stepSmall;
  326. pData->param.ranges[j].stepLarge = stepLarge;
  327. }
  328. if (needsCtrlIn)
  329. {
  330. portName.clear();
  331. if (processMode == ENGINE_PROCESS_MODE_SINGLE_CLIENT)
  332. {
  333. portName = pData->name;
  334. portName += ":";
  335. }
  336. portName += "events-in";
  337. portName.truncate(portNameSize);
  338. pData->event.portIn = (CarlaEngineEventPort*)pData->client->addPort(kEnginePortTypeEvent, portName, true);
  339. }
  340. if (needsCtrlOut)
  341. {
  342. portName.clear();
  343. if (processMode == ENGINE_PROCESS_MODE_SINGLE_CLIENT)
  344. {
  345. portName = pData->name;
  346. portName += ":";
  347. }
  348. portName += "events-out";
  349. portName.truncate(portNameSize);
  350. pData->event.portOut = (CarlaEngineEventPort*)pData->client->addPort(kEnginePortTypeEvent, portName, false);
  351. }
  352. // plugin hints
  353. pData->hints = 0x0;
  354. if (fDesc.isInstrument)
  355. pData->hints |= PLUGIN_IS_SYNTH;
  356. if (fInstance->hasEditor())
  357. {
  358. pData->hints |= PLUGIN_HAS_CUSTOM_UI;
  359. pData->hints |= PLUGIN_NEEDS_SINGLE_THREAD;
  360. }
  361. if (aOuts > 0 && (aIns == aOuts || aIns == 1))
  362. pData->hints |= PLUGIN_CAN_DRYWET;
  363. if (aOuts > 0)
  364. pData->hints |= PLUGIN_CAN_VOLUME;
  365. if (aOuts >= 2 && aOuts % 2 == 0)
  366. pData->hints |= PLUGIN_CAN_BALANCE;
  367. // extra plugin hints
  368. pData->extraHints = 0x0;
  369. if (mIns > 0)
  370. pData->extraHints |= PLUGIN_EXTRA_HINT_HAS_MIDI_IN;
  371. if (mOuts > 0)
  372. pData->extraHints |= PLUGIN_EXTRA_HINT_HAS_MIDI_OUT;
  373. if (aIns <= 2 && aOuts <= 2 && (aIns == aOuts || aIns == 0 || aOuts == 0))
  374. pData->extraHints |= PLUGIN_EXTRA_HINT_CAN_RUN_RACK;
  375. bufferSizeChanged(pData->engine->getBufferSize());
  376. //reloadPrograms(true);
  377. if (pData->active)
  378. activate();
  379. carla_debug("VstPlugin::reload() - end");
  380. }
  381. // -------------------------------------------------------------------
  382. // Plugin processing
  383. void activate() noexcept override
  384. {
  385. CARLA_SAFE_ASSERT_RETURN(fInstance != nullptr,);
  386. try {
  387. fInstance->prepareToPlay(pData->engine->getSampleRate(), static_cast<int>(pData->engine->getBufferSize()));
  388. } catch(...) {}
  389. }
  390. void deactivate() noexcept override
  391. {
  392. CARLA_SAFE_ASSERT_RETURN(fInstance != nullptr,);
  393. try {
  394. fInstance->releaseResources();
  395. } catch(...) {}
  396. }
  397. void process(float** const inBuffer, float** const outBuffer, const uint32_t frames) override
  398. {
  399. // --------------------------------------------------------------------------------------------------------
  400. // Check if active
  401. if (! pData->active)
  402. {
  403. // disable any output sound
  404. for (uint32_t i=0; i < pData->audioOut.count; ++i)
  405. FloatVectorOperations::clear(outBuffer[i], static_cast<int>(frames));
  406. return;
  407. }
  408. // --------------------------------------------------------------------------------------------------------
  409. // Check if needs reset
  410. if (pData->needsReset)
  411. {
  412. fInstance->reset();
  413. pData->needsReset = false;
  414. }
  415. uint32_t l=0;
  416. for (; l < pData->audioIn.count; ++l)
  417. fAudioBuffer.clear(static_cast<int>(l), 0, static_cast<int>(frames));
  418. for (; l < pData->audioOut.count; ++l)
  419. fAudioBuffer.clear(static_cast<int>(l), 0, static_cast<int>(frames));
  420. processSingle(inBuffer, outBuffer, frames);
  421. }
  422. bool processSingle(float** const inBuffer, float** const outBuffer, const uint32_t frames)
  423. {
  424. CARLA_SAFE_ASSERT_RETURN(frames > 0, false);
  425. if (pData->audioIn.count > 0)
  426. {
  427. CARLA_SAFE_ASSERT_RETURN(inBuffer != nullptr, false);
  428. }
  429. if (pData->audioOut.count > 0)
  430. {
  431. CARLA_SAFE_ASSERT_RETURN(outBuffer != nullptr, false);
  432. }
  433. // --------------------------------------------------------------------------------------------------------
  434. // Try lock, silence otherwise
  435. if (pData->engine->isOffline())
  436. {
  437. pData->singleMutex.lock();
  438. }
  439. else if (! pData->singleMutex.tryLock())
  440. {
  441. for (uint32_t i=0; i < pData->audioOut.count; ++i)
  442. {
  443. for (uint32_t k=0; k < frames; ++k)
  444. outBuffer[i][k/*+timeOffset*/] = 0.0f;
  445. }
  446. return false;
  447. }
  448. // --------------------------------------------------------------------------------------------------------
  449. // Set audio in buffers
  450. uint32_t l;
  451. for (l=0; l < pData->audioIn.count; ++l)
  452. fAudioBuffer.copyFrom(static_cast<int>(l), 0, inBuffer[l], static_cast<int>(frames));
  453. //for (l=0; l < pData->audioOut.count; ++l)
  454. // fAudioBuffer.clear(static_cast<int>(l), 0, static_cast<int>(frames));
  455. // --------------------------------------------------------------------------------------------------------
  456. // Run plugin
  457. fInstance->processBlock(fAudioBuffer, fMidiBuffer);
  458. // --------------------------------------------------------------------------------------------------------
  459. // Set audio out buffers
  460. for (uint32_t i=0; i < pData->audioOut.count; ++i)
  461. FloatVectorOperations::copy(outBuffer[i], fAudioBuffer.getSampleData(static_cast<int>(i)), static_cast<int>(frames));
  462. // --------------------------------------------------------------------------------------------------------
  463. pData->singleMutex.unlock();
  464. return true;
  465. }
  466. void bufferSizeChanged(const uint32_t newBufferSize) override
  467. {
  468. CARLA_ASSERT_INT(newBufferSize > 0, newBufferSize);
  469. carla_debug("VstPlugin::bufferSizeChanged(%i)", newBufferSize);
  470. fAudioBuffer.setSize(static_cast<int>(std::max<uint32_t>(pData->audioIn.count, pData->audioOut.count)), static_cast<int>(newBufferSize));
  471. if (pData->active)
  472. {
  473. deactivate();
  474. activate();
  475. }
  476. }
  477. void sampleRateChanged(const double newSampleRate) override
  478. {
  479. CARLA_ASSERT_INT(newSampleRate > 0.0, newSampleRate);
  480. carla_debug("VstPlugin::sampleRateChanged(%g)", newSampleRate);
  481. if (pData->active)
  482. {
  483. deactivate();
  484. activate();
  485. }
  486. }
  487. // -------------------------------------------------------------------
  488. // Plugin buffers
  489. // nothing
  490. // -------------------------------------------------------------------
  491. // Post-poned UI Stuff
  492. // nothing
  493. // -------------------------------------------------------------------
  494. protected:
  495. // TODO
  496. // -------------------------------------------------------------------
  497. public:
  498. bool init(const char* const filename, const char* const name, const char* const label)
  499. {
  500. CARLA_SAFE_ASSERT_RETURN(pData->engine != nullptr, false);
  501. // ---------------------------------------------------------------
  502. // first checks
  503. if (pData->client != nullptr)
  504. {
  505. pData->engine->setLastError("Plugin client is already registered");
  506. return false;
  507. }
  508. if (filename == nullptr || filename[0] == '\0')
  509. {
  510. pData->engine->setLastError("null filename");
  511. return false;
  512. }
  513. if (label == nullptr || label[0] == '\0')
  514. {
  515. pData->engine->setLastError("null label");
  516. return false;
  517. }
  518. // ---------------------------------------------------------------
  519. // fix path for wine usage
  520. String jfilename(filename);
  521. #ifdef CARLA_OS_WIN
  522. if (jfilename.startsWith("/"))
  523. {
  524. jfilename.replace("/", "\\");
  525. jfilename = "Z:" + jfilename;
  526. }
  527. #endif
  528. //fDesc.name = fDesc.descriptiveName = label;
  529. //fDesc.pluginFormatName = "VST";
  530. fDesc.uid = 0; // TODO - set uid for shell plugins
  531. fDesc.fileOrIdentifier = jfilename;
  532. fInstance = fFormat.createInstanceFromDescription(fDesc, 44100, 512);
  533. if (fInstance == nullptr)
  534. {
  535. pData->engine->setLastError("Plugin failed to initialize");
  536. return false;
  537. }
  538. fInstance->fillInPluginDescription(fDesc);
  539. // ---------------------------------------------------------------
  540. // get info
  541. if (name != nullptr && name[0] != '\0')
  542. pData->name = pData->engine->getUniquePluginName(name);
  543. else
  544. pData->name = pData->engine->getUniquePluginName(fInstance->getName().toRawUTF8());
  545. pData->filename = carla_strdup(filename);
  546. // ---------------------------------------------------------------
  547. // register client
  548. pData->client = pData->engine->addClient(this);
  549. if (pData->client == nullptr || ! pData->client->isOk())
  550. {
  551. pData->engine->setLastError("Failed to register plugin client");
  552. return false;
  553. }
  554. // ---------------------------------------------------------------
  555. // load plugin settings
  556. {
  557. // set default options
  558. pData->options = 0x0;
  559. //pData->options |= PLUGIN_OPTION_FIXED_BUFFERS;
  560. pData->options |= PLUGIN_OPTION_MAP_PROGRAM_CHANGES;
  561. //pData->options |= PLUGIN_OPTION_USE_CHUNKS;
  562. if (fInstance->acceptsMidi())
  563. {
  564. pData->options |= PLUGIN_OPTION_SEND_CHANNEL_PRESSURE;
  565. pData->options |= PLUGIN_OPTION_SEND_NOTE_AFTERTOUCH;
  566. pData->options |= PLUGIN_OPTION_SEND_PITCHBEND;
  567. pData->options |= PLUGIN_OPTION_SEND_ALL_SOUND_OFF;
  568. }
  569. // set identifier string
  570. String juceId(fDesc.createIdentifierString());
  571. CarlaString identifier("Juce/");
  572. identifier += juceId.toRawUTF8();
  573. pData->identifier = identifier.dup();
  574. // load settings
  575. pData->options = pData->loadSettings(pData->options, getOptionsAvailable());
  576. }
  577. return true;
  578. }
  579. private:
  580. PluginDescription fDesc;
  581. VSTPluginFormat fFormat;
  582. AudioPluginInstance* fInstance;
  583. AudioSampleBuffer fAudioBuffer;
  584. MidiBuffer fMidiBuffer;
  585. ScopedPointer<JucePluginWindow> fWindow;
  586. CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(JucePlugin)
  587. };
  588. CARLA_BACKEND_END_NAMESPACE
  589. #endif // HAVE_JUCE
  590. // -------------------------------------------------------------------------------------------------------------------
  591. CARLA_BACKEND_START_NAMESPACE
  592. CarlaPlugin* CarlaPlugin::newJuce(const Initializer& init, const char* const format)
  593. {
  594. carla_debug("CarlaPlugin::newJuce({%p, \"%s\", \"%s\", \"%s\"}, %s)", init.engine, init.filename, init.name, init.label, format);
  595. #ifdef HAVE_JUCE
  596. JucePlugin* const plugin(new JucePlugin(init.engine, init.id));
  597. if (! plugin->init(init.filename, init.name, init.label))
  598. {
  599. delete plugin;
  600. return nullptr;
  601. }
  602. plugin->reload();
  603. if (init.engine->getProccessMode() == ENGINE_PROCESS_MODE_CONTINUOUS_RACK && ! plugin->canRunInRack())
  604. {
  605. init.engine->setLastError("Carla's rack mode can only work with Stereo VST3 plugins, sorry!");
  606. delete plugin;
  607. return nullptr;
  608. }
  609. return plugin;
  610. #else
  611. init.engine->setLastError("Juce support not available");
  612. return nullptr;
  613. // unused
  614. (void)format;
  615. #endif
  616. }
  617. CARLA_BACKEND_END_NAMESPACE
  618. // -------------------------------------------------------------------------------------------------------------------