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.

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