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.

828 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. #ifdef CARLA_OS_LINUX
  172. const MessageManagerLock mmLock;
  173. #endif
  174. if (yesNo)
  175. {
  176. if (fWindow == nullptr)
  177. {
  178. String uiName(pData->name);
  179. uiName += " (JUCE GUI)";
  180. fWindow = new JucePluginWindow();
  181. fWindow->setName(uiName);
  182. }
  183. if (AudioProcessorEditor* const editor = fInstance->createEditorIfNeeded())
  184. fWindow->show(editor);
  185. }
  186. else
  187. {
  188. if (fWindow != nullptr)
  189. fWindow->hide();
  190. if (AudioProcessorEditor* const editor = fInstance->getActiveEditor())
  191. delete editor;
  192. fWindow = nullptr;
  193. }
  194. }
  195. void idle() override
  196. {
  197. if (fWindow != nullptr)
  198. {
  199. if (fWindow->wasClosedByUser())
  200. {
  201. showCustomUI(false);
  202. pData->engine->callback(ENGINE_CALLBACK_UI_STATE_CHANGED, pData->id, 0, 0, 0.0f, nullptr);
  203. }
  204. }
  205. CarlaPlugin::idle();
  206. }
  207. // -------------------------------------------------------------------
  208. // Plugin state
  209. void reload() override
  210. {
  211. CARLA_SAFE_ASSERT_RETURN(pData->engine != nullptr,);
  212. CARLA_SAFE_ASSERT_RETURN(fInstance != nullptr,);
  213. carla_debug("VstPlugin::reload() - start");
  214. const EngineProcessMode processMode(pData->engine->getProccessMode());
  215. // Safely disable plugin for reload
  216. const ScopedDisabler sd(this);
  217. if (pData->active)
  218. deactivate();
  219. clearBuffers();
  220. fInstance->refreshParameterList();
  221. uint32_t aIns, aOuts, mIns, mOuts, params;
  222. aIns = aOuts = mIns = mOuts = params = 0;
  223. bool needsCtrlIn, needsCtrlOut;
  224. needsCtrlIn = needsCtrlOut = false;
  225. aIns = (fInstance->getNumInputChannels() > 0) ? static_cast<uint32_t>(fInstance->getNumInputChannels()) : 0;
  226. aOuts = (fInstance->getNumOutputChannels() > 0) ? static_cast<uint32_t>(fInstance->getNumOutputChannels()) : 0;
  227. params = (fInstance->getNumParameters() > 0) ? static_cast<uint32_t>(fInstance->getNumParameters()) : 0;
  228. if (fInstance->acceptsMidi())
  229. {
  230. mIns = 1;
  231. needsCtrlIn = true;
  232. }
  233. if (fInstance->producesMidi())
  234. {
  235. mOuts = 1;
  236. needsCtrlOut = true;
  237. }
  238. if (aIns > 0)
  239. {
  240. pData->audioIn.createNew(aIns);
  241. }
  242. if (aOuts > 0)
  243. {
  244. pData->audioOut.createNew(aOuts);
  245. needsCtrlIn = true;
  246. }
  247. if (params > 0)
  248. {
  249. pData->param.createNew(params, false);
  250. needsCtrlIn = true;
  251. }
  252. const uint portNameSize(pData->engine->getMaxPortNameSize());
  253. CarlaString portName;
  254. // Audio Ins
  255. for (uint32_t j=0; j < aIns; ++j)
  256. {
  257. portName.clear();
  258. if (processMode == ENGINE_PROCESS_MODE_SINGLE_CLIENT)
  259. {
  260. portName = pData->name;
  261. portName += ":";
  262. }
  263. if (aIns > 1)
  264. {
  265. portName += "input_";
  266. portName += CarlaString(j+1);
  267. }
  268. else
  269. portName += "input";
  270. portName.truncate(portNameSize);
  271. pData->audioIn.ports[j].port = (CarlaEngineAudioPort*)pData->client->addPort(kEnginePortTypeAudio, portName, true);
  272. pData->audioIn.ports[j].rindex = j;
  273. }
  274. // Audio Outs
  275. for (uint32_t j=0; j < aOuts; ++j)
  276. {
  277. portName.clear();
  278. if (processMode == ENGINE_PROCESS_MODE_SINGLE_CLIENT)
  279. {
  280. portName = pData->name;
  281. portName += ":";
  282. }
  283. if (aOuts > 1)
  284. {
  285. portName += "output_";
  286. portName += CarlaString(j+1);
  287. }
  288. else
  289. portName += "output";
  290. portName.truncate(portNameSize);
  291. pData->audioOut.ports[j].port = (CarlaEngineAudioPort*)pData->client->addPort(kEnginePortTypeAudio, portName, false);
  292. pData->audioOut.ports[j].rindex = j;
  293. }
  294. for (uint32_t j=0; j < params; ++j)
  295. {
  296. pData->param.data[j].type = PARAMETER_INPUT;
  297. pData->param.data[j].hints = 0x0;
  298. pData->param.data[j].index = static_cast<int32_t>(j);
  299. pData->param.data[j].rindex = static_cast<int32_t>(j);
  300. pData->param.data[j].midiCC = -1;
  301. pData->param.data[j].midiChannel = 0;
  302. float min, max, def, step, stepSmall, stepLarge;
  303. // TODO
  304. //const int numSteps(fInstance->getParameterNumSteps(static_cast<int>(j)));
  305. {
  306. min = 0.0f;
  307. max = 1.0f;
  308. step = 0.001f;
  309. stepSmall = 0.0001f;
  310. stepLarge = 0.1f;
  311. }
  312. pData->param.data[j].hints |= PARAMETER_IS_ENABLED;
  313. #ifndef BUILD_BRIDGE
  314. //pData->param.data[j].hints |= PARAMETER_USES_CUSTOM_TEXT;
  315. #endif
  316. if (fInstance->isParameterAutomatable(static_cast<int>(j)))
  317. pData->param.data[j].hints |= PARAMETER_IS_AUTOMABLE;
  318. // FIXME?
  319. def = fInstance->getParameterDefaultValue(static_cast<int>(j));
  320. if (def < min)
  321. def = min;
  322. else if (def > max)
  323. def = max;
  324. pData->param.ranges[j].min = min;
  325. pData->param.ranges[j].max = max;
  326. pData->param.ranges[j].def = def;
  327. pData->param.ranges[j].step = step;
  328. pData->param.ranges[j].stepSmall = stepSmall;
  329. pData->param.ranges[j].stepLarge = stepLarge;
  330. }
  331. if (needsCtrlIn)
  332. {
  333. portName.clear();
  334. if (processMode == ENGINE_PROCESS_MODE_SINGLE_CLIENT)
  335. {
  336. portName = pData->name;
  337. portName += ":";
  338. }
  339. portName += "events-in";
  340. portName.truncate(portNameSize);
  341. pData->event.portIn = (CarlaEngineEventPort*)pData->client->addPort(kEnginePortTypeEvent, portName, true);
  342. }
  343. if (needsCtrlOut)
  344. {
  345. portName.clear();
  346. if (processMode == ENGINE_PROCESS_MODE_SINGLE_CLIENT)
  347. {
  348. portName = pData->name;
  349. portName += ":";
  350. }
  351. portName += "events-out";
  352. portName.truncate(portNameSize);
  353. pData->event.portOut = (CarlaEngineEventPort*)pData->client->addPort(kEnginePortTypeEvent, portName, false);
  354. }
  355. // plugin hints
  356. pData->hints = 0x0;
  357. if (fDesc.isInstrument)
  358. pData->hints |= PLUGIN_IS_SYNTH;
  359. if (fInstance->hasEditor())
  360. {
  361. pData->hints |= PLUGIN_HAS_CUSTOM_UI;
  362. pData->hints |= PLUGIN_NEEDS_SINGLE_THREAD;
  363. }
  364. if (aOuts > 0 && (aIns == aOuts || aIns == 1))
  365. pData->hints |= PLUGIN_CAN_DRYWET;
  366. if (aOuts > 0)
  367. pData->hints |= PLUGIN_CAN_VOLUME;
  368. if (aOuts >= 2 && aOuts % 2 == 0)
  369. pData->hints |= PLUGIN_CAN_BALANCE;
  370. // extra plugin hints
  371. pData->extraHints = 0x0;
  372. if (mIns > 0)
  373. pData->extraHints |= PLUGIN_EXTRA_HINT_HAS_MIDI_IN;
  374. if (mOuts > 0)
  375. pData->extraHints |= PLUGIN_EXTRA_HINT_HAS_MIDI_OUT;
  376. if (aIns <= 2 && aOuts <= 2 && (aIns == aOuts || aIns == 0 || aOuts == 0))
  377. pData->extraHints |= PLUGIN_EXTRA_HINT_CAN_RUN_RACK;
  378. fInstance->setPlayConfigDetails(static_cast<int>(aIns), static_cast<int>(aOuts), pData->engine->getSampleRate(), static_cast<int>(pData->engine->getBufferSize()));
  379. bufferSizeChanged(pData->engine->getBufferSize());
  380. //reloadPrograms(true);
  381. if (pData->active)
  382. activate();
  383. carla_debug("VstPlugin::reload() - end");
  384. }
  385. // -------------------------------------------------------------------
  386. // Plugin processing
  387. void activate() noexcept override
  388. {
  389. CARLA_SAFE_ASSERT_RETURN(fInstance != nullptr,);
  390. try {
  391. fInstance->prepareToPlay(pData->engine->getSampleRate(), static_cast<int>(pData->engine->getBufferSize()));
  392. } catch(...) {}
  393. }
  394. void deactivate() noexcept override
  395. {
  396. CARLA_SAFE_ASSERT_RETURN(fInstance != nullptr,);
  397. try {
  398. fInstance->releaseResources();
  399. } catch(...) {}
  400. }
  401. void process(float** const inBuffer, float** const outBuffer, const uint32_t frames) override
  402. {
  403. // --------------------------------------------------------------------------------------------------------
  404. // Check if active
  405. if (! pData->active)
  406. {
  407. // disable any output sound
  408. for (uint32_t i=0; i < pData->audioOut.count; ++i)
  409. FloatVectorOperations::clear(outBuffer[i], static_cast<int>(frames));
  410. return;
  411. }
  412. // --------------------------------------------------------------------------------------------------------
  413. // Check if needs reset
  414. if (pData->needsReset)
  415. {
  416. fInstance->reset();
  417. pData->needsReset = false;
  418. }
  419. uint32_t l=0;
  420. for (; l < pData->audioIn.count; ++l)
  421. fAudioBuffer.clear(static_cast<int>(l), 0, static_cast<int>(frames));
  422. for (; l < pData->audioOut.count; ++l)
  423. fAudioBuffer.clear(static_cast<int>(l), 0, static_cast<int>(frames));
  424. processSingle(inBuffer, outBuffer, frames);
  425. }
  426. bool processSingle(float** const inBuffer, float** const outBuffer, const uint32_t frames)
  427. {
  428. CARLA_SAFE_ASSERT_RETURN(frames > 0, false);
  429. if (pData->audioIn.count > 0)
  430. {
  431. CARLA_SAFE_ASSERT_RETURN(inBuffer != nullptr, false);
  432. }
  433. if (pData->audioOut.count > 0)
  434. {
  435. CARLA_SAFE_ASSERT_RETURN(outBuffer != nullptr, false);
  436. }
  437. // --------------------------------------------------------------------------------------------------------
  438. // Try lock, silence otherwise
  439. if (pData->engine->isOffline())
  440. {
  441. pData->singleMutex.lock();
  442. }
  443. else if (! pData->singleMutex.tryLock())
  444. {
  445. for (uint32_t i=0; i < pData->audioOut.count; ++i)
  446. {
  447. for (uint32_t k=0; k < frames; ++k)
  448. outBuffer[i][k/*+timeOffset*/] = 0.0f;
  449. }
  450. return false;
  451. }
  452. // --------------------------------------------------------------------------------------------------------
  453. // Set audio in buffers
  454. uint32_t l;
  455. for (l=0; l < pData->audioIn.count; ++l)
  456. fAudioBuffer.copyFrom(static_cast<int>(l), 0, inBuffer[l], static_cast<int>(frames));
  457. //for (l=0; l < pData->audioOut.count; ++l)
  458. // fAudioBuffer.clear(static_cast<int>(l), 0, static_cast<int>(frames));
  459. // --------------------------------------------------------------------------------------------------------
  460. // Run plugin
  461. fInstance->processBlock(fAudioBuffer, fMidiBuffer);
  462. // --------------------------------------------------------------------------------------------------------
  463. // Set audio out buffers
  464. for (uint32_t i=0; i < pData->audioOut.count; ++i)
  465. FloatVectorOperations::copy(outBuffer[i], fAudioBuffer.getSampleData(static_cast<int>(i)), static_cast<int>(frames));
  466. // --------------------------------------------------------------------------------------------------------
  467. pData->singleMutex.unlock();
  468. return true;
  469. }
  470. void bufferSizeChanged(const uint32_t newBufferSize) override
  471. {
  472. CARLA_ASSERT_INT(newBufferSize > 0, newBufferSize);
  473. carla_debug("VstPlugin::bufferSizeChanged(%i)", newBufferSize);
  474. fAudioBuffer.setSize(static_cast<int>(std::max<uint32_t>(pData->audioIn.count, pData->audioOut.count)), static_cast<int>(newBufferSize));
  475. if (pData->active)
  476. {
  477. deactivate();
  478. activate();
  479. }
  480. }
  481. void sampleRateChanged(const double newSampleRate) override
  482. {
  483. CARLA_ASSERT_INT(newSampleRate > 0.0, newSampleRate);
  484. carla_debug("VstPlugin::sampleRateChanged(%g)", newSampleRate);
  485. if (pData->active)
  486. {
  487. deactivate();
  488. activate();
  489. }
  490. }
  491. // -------------------------------------------------------------------
  492. // Plugin buffers
  493. // nothing
  494. // -------------------------------------------------------------------
  495. // Post-poned UI Stuff
  496. // nothing
  497. // -------------------------------------------------------------------
  498. protected:
  499. // TODO
  500. // -------------------------------------------------------------------
  501. public:
  502. bool init(const char* const filename, const char* const name, const char* const label, const char* const format)
  503. {
  504. CARLA_SAFE_ASSERT_RETURN(pData->engine != nullptr, false);
  505. // ---------------------------------------------------------------
  506. // first checks
  507. if (pData->client != nullptr)
  508. {
  509. pData->engine->setLastError("Plugin client is already registered");
  510. return false;
  511. }
  512. if (filename == nullptr || filename[0] == '\0')
  513. {
  514. pData->engine->setLastError("null filename");
  515. return false;
  516. }
  517. if (label == nullptr || label[0] == '\0')
  518. {
  519. pData->engine->setLastError("null label");
  520. return false;
  521. }
  522. #ifdef CARLA_OS_LINUX
  523. const MessageManagerLock mmLock;
  524. #endif
  525. // ---------------------------------------------------------------
  526. // fix path for wine usage
  527. String jfilename(filename);
  528. #ifdef CARLA_OS_WIN
  529. if (jfilename.startsWith("/"))
  530. {
  531. jfilename.replace("/", "\\");
  532. jfilename = "Z:" + jfilename;
  533. }
  534. #endif
  535. //fDesc.name = fDesc.descriptiveName = label;
  536. fDesc.uid = 0; // TODO - set uid for shell plugins
  537. fDesc.fileOrIdentifier = jfilename;
  538. fDesc.pluginFormatName = format;
  539. fFormatManager.addDefaultFormats();
  540. String error;
  541. fInstance = fFormatManager.createPluginInstance(fDesc, 44100, 512, error);
  542. if (fInstance == nullptr)
  543. {
  544. pData->engine->setLastError(error.toRawUTF8());
  545. return false;
  546. }
  547. fInstance->fillInPluginDescription(fDesc);
  548. // ---------------------------------------------------------------
  549. // get info
  550. if (name != nullptr && name[0] != '\0')
  551. pData->name = pData->engine->getUniquePluginName(name);
  552. else
  553. pData->name = pData->engine->getUniquePluginName(fInstance->getName().toRawUTF8());
  554. pData->filename = carla_strdup(filename);
  555. // ---------------------------------------------------------------
  556. // register client
  557. pData->client = pData->engine->addClient(this);
  558. if (pData->client == nullptr || ! pData->client->isOk())
  559. {
  560. pData->engine->setLastError("Failed to register plugin client");
  561. return false;
  562. }
  563. // ---------------------------------------------------------------
  564. // load plugin settings
  565. {
  566. // set default options
  567. pData->options = 0x0;
  568. //pData->options |= PLUGIN_OPTION_FIXED_BUFFERS;
  569. pData->options |= PLUGIN_OPTION_MAP_PROGRAM_CHANGES;
  570. //pData->options |= PLUGIN_OPTION_USE_CHUNKS;
  571. if (fInstance->acceptsMidi())
  572. {
  573. pData->options |= PLUGIN_OPTION_SEND_CHANNEL_PRESSURE;
  574. pData->options |= PLUGIN_OPTION_SEND_NOTE_AFTERTOUCH;
  575. pData->options |= PLUGIN_OPTION_SEND_PITCHBEND;
  576. pData->options |= PLUGIN_OPTION_SEND_ALL_SOUND_OFF;
  577. }
  578. // set identifier string
  579. String juceId(fDesc.createIdentifierString());
  580. CarlaString identifier("Juce/");
  581. identifier += juceId.toRawUTF8();
  582. pData->identifier = identifier.dup();
  583. // load settings
  584. pData->options = pData->loadSettings(pData->options, getOptionsAvailable());
  585. }
  586. return true;
  587. }
  588. private:
  589. PluginDescription fDesc;
  590. AudioPluginInstance* fInstance;
  591. AudioPluginFormatManager fFormatManager;
  592. AudioSampleBuffer fAudioBuffer;
  593. MidiBuffer fMidiBuffer;
  594. ScopedPointer<JucePluginWindow> fWindow;
  595. CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(JucePlugin)
  596. };
  597. CARLA_BACKEND_END_NAMESPACE
  598. #endif // HAVE_JUCE
  599. // -------------------------------------------------------------------------------------------------------------------
  600. CARLA_BACKEND_START_NAMESPACE
  601. CarlaPlugin* CarlaPlugin::newJuce(const Initializer& init, const char* const format)
  602. {
  603. carla_debug("CarlaPlugin::newJuce({%p, \"%s\", \"%s\", \"%s\"}, %s)", init.engine, init.filename, init.name, init.label, format);
  604. #ifdef HAVE_JUCE
  605. JucePlugin* const plugin(new JucePlugin(init.engine, init.id));
  606. if (! plugin->init(init.filename, init.name, init.label, format))
  607. {
  608. delete plugin;
  609. return nullptr;
  610. }
  611. plugin->reload();
  612. if (init.engine->getProccessMode() == ENGINE_PROCESS_MODE_CONTINUOUS_RACK && ! plugin->canRunInRack())
  613. {
  614. init.engine->setLastError("Carla's rack mode can only work with Stereo VST3 plugins, sorry!");
  615. delete plugin;
  616. return nullptr;
  617. }
  618. return plugin;
  619. #else
  620. init.engine->setLastError("Juce support not available");
  621. return nullptr;
  622. // unused
  623. (void)format;
  624. #endif
  625. }
  626. CARLA_BACKEND_END_NAMESPACE
  627. // -------------------------------------------------------------------------------------------------------------------