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.

1375 lines
47KB

  1. /*
  2. * Carla Juce Plugin
  3. * Copyright (C) 2013-2019 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(USING_JUCE)
  20. #include "CarlaBackendUtils.hpp"
  21. #include "CarlaMathUtils.hpp"
  22. #include "JucePluginWindow.hpp"
  23. #include "AppConfig.h"
  24. #include "juce_audio_processors/juce_audio_processors.h"
  25. namespace juce {
  26. extern bool juce_isRunningInWine();
  27. }
  28. CARLA_BACKEND_START_NAMESPACE
  29. // -------------------------------------------------------------------------------------------------------------------
  30. // Fallback data
  31. static const ExternalMidiNote kExternalMidiNoteFallback = { -1, 0, 0 };
  32. // -------------------------------------------------------------------------------------------------------------------
  33. class CarlaPluginJuce : public CarlaPlugin,
  34. private juce::AudioPlayHead,
  35. private juce::AudioProcessorListener
  36. {
  37. public:
  38. CarlaPluginJuce(CarlaEngine* const engine, const uint id)
  39. : CarlaPlugin(engine, id),
  40. fDesc(),
  41. fInstance(nullptr),
  42. fFormatManager(),
  43. fAudioBuffer(),
  44. fMidiBuffer(),
  45. fPosInfo(),
  46. fChunk(),
  47. fWindow()
  48. {
  49. carla_debug("CarlaPluginJuce::CarlaPluginJuce(%p, %i)", engine, id);
  50. fMidiBuffer.ensureSize(2048);
  51. fMidiBuffer.clear();
  52. fPosInfo.resetToDefault();
  53. }
  54. ~CarlaPluginJuce() override
  55. {
  56. carla_debug("CarlaPluginJuce::~CarlaPluginJuce()");
  57. // close UI
  58. if (pData->hints & PLUGIN_HAS_CUSTOM_UI)
  59. showCustomUI(false);
  60. pData->singleMutex.lock();
  61. pData->masterMutex.lock();
  62. if (pData->client != nullptr && pData->client->isActive())
  63. pData->client->deactivate();
  64. if (pData->active)
  65. {
  66. deactivate();
  67. pData->active = false;
  68. }
  69. if (fInstance != nullptr)
  70. {
  71. delete fInstance;
  72. fInstance = nullptr;
  73. }
  74. clearBuffers();
  75. }
  76. // -------------------------------------------------------------------
  77. // Information (base)
  78. PluginType getType() const noexcept override
  79. {
  80. return getPluginTypeFromString(fDesc.pluginFormatName.toRawUTF8());
  81. }
  82. PluginCategory getCategory() const noexcept override
  83. {
  84. if (fDesc.isInstrument)
  85. return PLUGIN_CATEGORY_SYNTH;
  86. return getPluginCategoryFromName(fDesc.category.toRawUTF8());
  87. }
  88. int64_t getUniqueId() const noexcept override
  89. {
  90. return fDesc.uid;
  91. }
  92. // -------------------------------------------------------------------
  93. // Information (count)
  94. // nothing
  95. // -------------------------------------------------------------------
  96. // Information (current data)
  97. std::size_t getChunkData(void** const dataPtr) noexcept override
  98. {
  99. CARLA_SAFE_ASSERT_RETURN(pData->options & PLUGIN_OPTION_USE_CHUNKS, 0);
  100. CARLA_SAFE_ASSERT_RETURN(fInstance != nullptr, 0);
  101. CARLA_SAFE_ASSERT_RETURN(dataPtr != nullptr, 0);
  102. *dataPtr = nullptr;
  103. try {
  104. fChunk.reset();
  105. fInstance->getStateInformation(fChunk);
  106. } CARLA_SAFE_EXCEPTION_RETURN("CarlaPluginJuce::getChunkData", 0);
  107. if (const std::size_t size = fChunk.getSize())
  108. {
  109. *dataPtr = fChunk.getData();
  110. return size;
  111. }
  112. return 0;
  113. }
  114. // -------------------------------------------------------------------
  115. // Information (per-plugin data)
  116. uint getOptionsAvailable() const noexcept override
  117. {
  118. CARLA_SAFE_ASSERT_RETURN(fInstance != nullptr, 0x0);
  119. uint options = 0x0;
  120. options |= PLUGIN_OPTION_MAP_PROGRAM_CHANGES;
  121. options |= PLUGIN_OPTION_USE_CHUNKS;
  122. if (fInstance->getNumPrograms() > 1)
  123. options |= PLUGIN_OPTION_MAP_PROGRAM_CHANGES;
  124. if (fInstance->acceptsMidi())
  125. {
  126. options |= PLUGIN_OPTION_SEND_CONTROL_CHANGES;
  127. options |= PLUGIN_OPTION_SEND_CHANNEL_PRESSURE;
  128. options |= PLUGIN_OPTION_SEND_NOTE_AFTERTOUCH;
  129. options |= PLUGIN_OPTION_SEND_PITCHBEND;
  130. options |= PLUGIN_OPTION_SEND_ALL_SOUND_OFF;
  131. }
  132. return options;
  133. }
  134. float getParameterValue(const uint32_t parameterId) const noexcept override
  135. {
  136. CARLA_SAFE_ASSERT_RETURN(parameterId < pData->param.count, 0.0f);
  137. CARLA_SAFE_ASSERT_RETURN(fInstance != nullptr, 0.0f);
  138. return fInstance->getParameter(static_cast<int>(parameterId));
  139. }
  140. void getLabel(char* const strBuf) const noexcept override
  141. {
  142. if (fDesc.pluginFormatName == "AU" || fDesc.pluginFormatName == "AudioUnit")
  143. std::strncpy(strBuf, fDesc.fileOrIdentifier.toRawUTF8(), STR_MAX);
  144. else
  145. std::strncpy(strBuf, fDesc.name.toRawUTF8(), STR_MAX);
  146. }
  147. void getMaker(char* const strBuf) const noexcept override
  148. {
  149. std::strncpy(strBuf, fDesc.manufacturerName.toRawUTF8(), STR_MAX);
  150. }
  151. void getCopyright(char* const strBuf) const noexcept override
  152. {
  153. getMaker(strBuf);
  154. }
  155. void getRealName(char* const strBuf) const noexcept override
  156. {
  157. std::strncpy(strBuf, fDesc.descriptiveName.toRawUTF8(), STR_MAX);
  158. }
  159. void getParameterName(const uint32_t parameterId, char* const strBuf) const noexcept override
  160. {
  161. CARLA_SAFE_ASSERT_RETURN(parameterId < pData->param.count,);
  162. CARLA_SAFE_ASSERT_RETURN(fInstance != nullptr,);
  163. std::strncpy(strBuf, fInstance->getParameterName(static_cast<int>(parameterId), STR_MAX).toRawUTF8(), STR_MAX);
  164. }
  165. void getParameterText(const uint32_t parameterId, char* const strBuf) noexcept override
  166. {
  167. CARLA_SAFE_ASSERT_RETURN(parameterId < pData->param.count,);
  168. CARLA_SAFE_ASSERT_RETURN(fInstance != nullptr,);
  169. std::strncpy(strBuf, fInstance->getParameterText(static_cast<int>(parameterId), STR_MAX).toRawUTF8(), STR_MAX);
  170. }
  171. void getParameterUnit(const uint32_t parameterId, char* const strBuf) const noexcept override
  172. {
  173. CARLA_SAFE_ASSERT_RETURN(parameterId < pData->param.count,);
  174. CARLA_SAFE_ASSERT_RETURN(fInstance != nullptr,);
  175. std::strncpy(strBuf, fInstance->getParameterLabel(static_cast<int>(parameterId)).toRawUTF8(), STR_MAX);
  176. }
  177. // -------------------------------------------------------------------
  178. // Set data (state)
  179. // nothing
  180. // -------------------------------------------------------------------
  181. // Set data (internal stuff)
  182. void setName(const char* const newName) override
  183. {
  184. CarlaPlugin::setName(newName);
  185. if (fWindow != nullptr)
  186. {
  187. juce::String uiName(pData->name);
  188. uiName += " (GUI)";
  189. fWindow->setName(uiName);
  190. }
  191. }
  192. // -------------------------------------------------------------------
  193. // Set data (plugin-specific stuff)
  194. void setParameterValue(const uint32_t parameterId, const float value, const bool sendGui, const bool sendOsc, const bool sendCallback) noexcept override
  195. {
  196. CARLA_SAFE_ASSERT_RETURN(parameterId < pData->param.count,);
  197. CARLA_SAFE_ASSERT_RETURN(fInstance != nullptr,);
  198. const float fixedValue(pData->param.getFixedValue(parameterId, value));
  199. fInstance->setParameter(static_cast<int>(parameterId), value);
  200. CarlaPlugin::setParameterValue(parameterId, fixedValue, sendGui, sendOsc, sendCallback);
  201. }
  202. void setChunkData(const void* const data, const std::size_t dataSize) override
  203. {
  204. CARLA_SAFE_ASSERT_RETURN(pData->options & PLUGIN_OPTION_USE_CHUNKS,);
  205. CARLA_SAFE_ASSERT_RETURN(fInstance != nullptr,);
  206. CARLA_SAFE_ASSERT_RETURN(data != nullptr,);
  207. CARLA_SAFE_ASSERT_RETURN(dataSize > 0,);
  208. if (isJuceSaveFormat(data, dataSize))
  209. {
  210. const ScopedSingleProcessLocker spl(this, true);
  211. fInstance->setStateInformation(data, static_cast<int>(dataSize));
  212. }
  213. else
  214. {
  215. uint8_t* const dataCompat = (uint8_t*)std::malloc(dataSize + 160);
  216. CARLA_SAFE_ASSERT_RETURN(dataCompat != nullptr,);
  217. carla_stdout("NOTE: Loading plugin state in Carla compatibiity mode");
  218. std::memset(dataCompat, 0, 160);
  219. std::memcpy(dataCompat+160, data, dataSize);
  220. int32_t* const set = (int32_t*)dataCompat;
  221. dataCompat[39] = dataSize;
  222. set[0] = (int32_t)juce::ByteOrder::littleEndianInt("CcnK");
  223. set[2] = (int32_t)juce::ByteOrder::littleEndianInt("FBCh");
  224. set[3] = fxbSwap(1);
  225. set[39] = fxbSwap(dataSize);
  226. {
  227. const ScopedSingleProcessLocker spl(this, true);
  228. fInstance->setStateInformation(dataCompat, static_cast<int>(dataSize+160));
  229. }
  230. std::free(dataCompat);
  231. }
  232. #if defined(HAVE_LIBLO) && ! defined(BUILD_BRIDGE)
  233. const bool sendOsc(pData->engine->isOscControlRegistered());
  234. #else
  235. const bool sendOsc(false);
  236. #endif
  237. pData->updateParameterValues(this, sendOsc, true, false);
  238. }
  239. void setProgram(const int32_t index, const bool sendGui, const bool sendOsc, const bool sendCallback, const bool doingInit) noexcept override
  240. {
  241. CARLA_SAFE_ASSERT_RETURN(fInstance != nullptr,);
  242. CARLA_SAFE_ASSERT_RETURN(index >= -1 && index < static_cast<int32_t>(pData->prog.count),);
  243. if (index >= 0)
  244. {
  245. const ScopedSingleProcessLocker spl(this, (sendGui || sendOsc || sendCallback));
  246. try {
  247. fInstance->setCurrentProgram(index);
  248. } CARLA_SAFE_EXCEPTION("setCurrentProgram");
  249. }
  250. CarlaPlugin::setProgram(index, sendGui, sendOsc, sendCallback, doingInit);
  251. }
  252. // -------------------------------------------------------------------
  253. // Set ui stuff
  254. void showCustomUI(const bool yesNo) override
  255. {
  256. CARLA_SAFE_ASSERT_RETURN(fInstance != nullptr,);
  257. if (yesNo)
  258. {
  259. if (fWindow == nullptr)
  260. {
  261. juce::String uiName(pData->name);
  262. uiName += " (GUI)";
  263. fWindow = new JucePluginWindow(pData->engine->getOptions().frontendWinId);
  264. fWindow->setName(uiName);
  265. }
  266. if (juce::AudioProcessorEditor* const editor = fInstance->createEditorIfNeeded())
  267. fWindow->show(editor);
  268. }
  269. else
  270. {
  271. if (fWindow != nullptr)
  272. fWindow->hide();
  273. if (juce::AudioProcessorEditor* const editor = fInstance->getActiveEditor())
  274. delete editor;
  275. fWindow = nullptr;
  276. }
  277. }
  278. void uiIdle() override
  279. {
  280. if (fWindow != nullptr)
  281. {
  282. if (fWindow->wasClosedByUser())
  283. {
  284. showCustomUI(false);
  285. pData->engine->callback(ENGINE_CALLBACK_UI_STATE_CHANGED, pData->id, 0, 0, 0.0f, nullptr);
  286. }
  287. }
  288. CarlaPlugin::uiIdle();
  289. }
  290. // -------------------------------------------------------------------
  291. // Plugin state
  292. void reload() override
  293. {
  294. CARLA_SAFE_ASSERT_RETURN(pData->engine != nullptr,);
  295. CARLA_SAFE_ASSERT_RETURN(fInstance != nullptr,);
  296. carla_debug("CarlaPluginJuce::reload() - start");
  297. const EngineProcessMode processMode(pData->engine->getProccessMode());
  298. // Safely disable plugin for reload
  299. const ScopedDisabler sd(this);
  300. if (pData->active)
  301. deactivate();
  302. clearBuffers();
  303. fInstance->refreshParameterList();
  304. uint32_t aIns, aOuts, mIns, mOuts, params;
  305. mIns = mOuts = 0;
  306. bool needsCtrlIn, needsCtrlOut;
  307. needsCtrlIn = needsCtrlOut = false;
  308. aIns = (fInstance->getTotalNumInputChannels() > 0) ? static_cast<uint32_t>(fInstance->getTotalNumInputChannels()) : 0;
  309. aOuts = (fInstance->getTotalNumOutputChannels() > 0) ? static_cast<uint32_t>(fInstance->getTotalNumOutputChannels()) : 0;
  310. params = (fInstance->getNumParameters() > 0) ? static_cast<uint32_t>(fInstance->getNumParameters()) : 0;
  311. if (fInstance->acceptsMidi())
  312. {
  313. mIns = 1;
  314. needsCtrlIn = true;
  315. }
  316. if (fInstance->producesMidi())
  317. {
  318. mOuts = 1;
  319. needsCtrlOut = true;
  320. }
  321. if (aIns > 0)
  322. {
  323. pData->audioIn.createNew(aIns);
  324. }
  325. if (aOuts > 0)
  326. {
  327. pData->audioOut.createNew(aOuts);
  328. needsCtrlIn = true;
  329. }
  330. if (params > 0)
  331. {
  332. pData->param.createNew(params, false);
  333. needsCtrlIn = true;
  334. }
  335. const uint portNameSize(pData->engine->getMaxPortNameSize());
  336. CarlaString portName;
  337. // Audio Ins
  338. for (uint32_t j=0; j < aIns; ++j)
  339. {
  340. portName.clear();
  341. if (processMode == ENGINE_PROCESS_MODE_SINGLE_CLIENT)
  342. {
  343. portName = pData->name;
  344. portName += ":";
  345. }
  346. if (aIns > 1)
  347. {
  348. portName += "input_";
  349. portName += CarlaString(j+1);
  350. }
  351. else
  352. portName += "input";
  353. portName.truncate(portNameSize);
  354. pData->audioIn.ports[j].port = (CarlaEngineAudioPort*)pData->client->addPort(kEnginePortTypeAudio, portName, true, j);
  355. pData->audioIn.ports[j].rindex = j;
  356. }
  357. // Audio Outs
  358. for (uint32_t j=0; j < aOuts; ++j)
  359. {
  360. portName.clear();
  361. if (processMode == ENGINE_PROCESS_MODE_SINGLE_CLIENT)
  362. {
  363. portName = pData->name;
  364. portName += ":";
  365. }
  366. if (aOuts > 1)
  367. {
  368. portName += "output_";
  369. portName += CarlaString(j+1);
  370. }
  371. else
  372. portName += "output";
  373. portName.truncate(portNameSize);
  374. pData->audioOut.ports[j].port = (CarlaEngineAudioPort*)pData->client->addPort(kEnginePortTypeAudio, portName, false, j);
  375. pData->audioOut.ports[j].rindex = j;
  376. }
  377. for (uint32_t j=0; j < params; ++j)
  378. {
  379. pData->param.data[j].type = PARAMETER_INPUT;
  380. pData->param.data[j].index = static_cast<int32_t>(j);
  381. pData->param.data[j].rindex = static_cast<int32_t>(j);
  382. float min, max, def, step, stepSmall, stepLarge;
  383. // TODO
  384. //const int numSteps(fInstance->getParameterNumSteps(static_cast<int>(j)));
  385. {
  386. min = 0.0f;
  387. max = 1.0f;
  388. step = 0.001f;
  389. stepSmall = 0.0001f;
  390. stepLarge = 0.1f;
  391. }
  392. pData->param.data[j].hints |= PARAMETER_IS_ENABLED;
  393. #ifndef BUILD_BRIDGE
  394. pData->param.data[j].hints |= PARAMETER_USES_CUSTOM_TEXT;
  395. #endif
  396. if (fInstance->isParameterAutomatable(static_cast<int>(j)))
  397. pData->param.data[j].hints |= PARAMETER_IS_AUTOMABLE;
  398. // FIXME?
  399. def = fInstance->getParameterDefaultValue(static_cast<int>(j));
  400. if (def < min)
  401. def = min;
  402. else if (def > max)
  403. def = max;
  404. pData->param.ranges[j].min = min;
  405. pData->param.ranges[j].max = max;
  406. pData->param.ranges[j].def = def;
  407. pData->param.ranges[j].step = step;
  408. pData->param.ranges[j].stepSmall = stepSmall;
  409. pData->param.ranges[j].stepLarge = stepLarge;
  410. }
  411. if (needsCtrlIn)
  412. {
  413. portName.clear();
  414. if (processMode == ENGINE_PROCESS_MODE_SINGLE_CLIENT)
  415. {
  416. portName = pData->name;
  417. portName += ":";
  418. }
  419. portName += "events-in";
  420. portName.truncate(portNameSize);
  421. pData->event.portIn = (CarlaEngineEventPort*)pData->client->addPort(kEnginePortTypeEvent, portName, true, 0);
  422. }
  423. if (needsCtrlOut)
  424. {
  425. portName.clear();
  426. if (processMode == ENGINE_PROCESS_MODE_SINGLE_CLIENT)
  427. {
  428. portName = pData->name;
  429. portName += ":";
  430. }
  431. portName += "events-out";
  432. portName.truncate(portNameSize);
  433. pData->event.portOut = (CarlaEngineEventPort*)pData->client->addPort(kEnginePortTypeEvent, portName, false, 0);
  434. }
  435. // plugin hints
  436. pData->hints = 0x0;
  437. pData->hints |= PLUGIN_NEEDS_FIXED_BUFFERS;
  438. if (fDesc.isInstrument)
  439. pData->hints |= PLUGIN_IS_SYNTH;
  440. if (fInstance->hasEditor())
  441. {
  442. pData->hints |= PLUGIN_HAS_CUSTOM_UI;
  443. pData->hints |= PLUGIN_NEEDS_UI_MAIN_THREAD;
  444. }
  445. if (aOuts > 0 && (aIns == aOuts || aIns == 1))
  446. pData->hints |= PLUGIN_CAN_DRYWET;
  447. if (aOuts > 0)
  448. pData->hints |= PLUGIN_CAN_VOLUME;
  449. if (aOuts >= 2 && aOuts % 2 == 0)
  450. pData->hints |= PLUGIN_CAN_BALANCE;
  451. // extra plugin hints
  452. pData->extraHints = 0x0;
  453. if (mIns > 0)
  454. pData->extraHints |= PLUGIN_EXTRA_HINT_HAS_MIDI_IN;
  455. if (mOuts > 0)
  456. pData->extraHints |= PLUGIN_EXTRA_HINT_HAS_MIDI_OUT;
  457. fInstance->setPlayConfigDetails(static_cast<int>(aIns), static_cast<int>(aOuts), pData->engine->getSampleRate(), static_cast<int>(pData->engine->getBufferSize()));
  458. bufferSizeChanged(pData->engine->getBufferSize());
  459. reloadPrograms(true);
  460. if (pData->active)
  461. activate();
  462. carla_debug("CarlaPluginJuce::reload() - end");
  463. }
  464. void reloadPrograms(const bool doInit) override
  465. {
  466. carla_debug("CarlaPluginJuce::reloadPrograms(%s)", bool2str(doInit));
  467. const uint32_t oldCount = pData->prog.count;
  468. const int32_t current = pData->prog.current;
  469. // Delete old programs
  470. pData->prog.clear();
  471. // Query new programs
  472. uint32_t newCount = (fInstance->getNumPrograms() > 0) ? static_cast<uint32_t>(fInstance->getNumPrograms()) : 0;
  473. if (newCount > 0)
  474. {
  475. pData->prog.createNew(newCount);
  476. // Update names
  477. for (int i=0, count=fInstance->getNumPrograms(); i<count; ++i)
  478. pData->prog.names[i] = carla_strdup(fInstance->getProgramName(i).toRawUTF8());
  479. }
  480. #if defined(HAVE_LIBLO) && ! defined(BUILD_BRIDGE)
  481. // Update OSC Names
  482. if (pData->engine->isOscControlRegistered() && pData->id < pData->engine->getCurrentPluginCount())
  483. {
  484. pData->engine->oscSend_control_set_program_count(pData->id, newCount);
  485. for (uint32_t i=0; i < newCount; ++i)
  486. pData->engine->oscSend_control_set_program_name(pData->id, i, pData->prog.names[i]);
  487. }
  488. #endif
  489. if (doInit)
  490. {
  491. if (newCount > 0)
  492. setProgram(0, false, false, false, true);
  493. }
  494. else
  495. {
  496. // Check if current program is invalid
  497. bool programChanged = false;
  498. if (newCount == oldCount+1)
  499. {
  500. // one program added, probably created by user
  501. pData->prog.current = static_cast<int32_t>(oldCount);
  502. programChanged = true;
  503. }
  504. else if (current < 0 && newCount > 0)
  505. {
  506. // programs exist now, but not before
  507. pData->prog.current = 0;
  508. programChanged = true;
  509. }
  510. else if (current >= 0 && newCount == 0)
  511. {
  512. // programs existed before, but not anymore
  513. pData->prog.current = -1;
  514. programChanged = true;
  515. }
  516. else if (current >= static_cast<int32_t>(newCount))
  517. {
  518. // current program > count
  519. pData->prog.current = 0;
  520. programChanged = true;
  521. }
  522. else
  523. {
  524. // no change
  525. pData->prog.current = current;
  526. }
  527. if (programChanged)
  528. {
  529. setProgram(pData->prog.current, true, true, true, false);
  530. }
  531. else
  532. {
  533. // Program was changed during update, re-set it
  534. if (pData->prog.current >= 0)
  535. fInstance->setCurrentProgram(pData->prog.current);
  536. }
  537. pData->engine->callback(ENGINE_CALLBACK_RELOAD_PROGRAMS, pData->id, 0, 0, 0.0f, nullptr);
  538. }
  539. }
  540. // -------------------------------------------------------------------
  541. // Plugin processing
  542. void activate() noexcept override
  543. {
  544. CARLA_SAFE_ASSERT_RETURN(fInstance != nullptr,);
  545. try {
  546. fInstance->prepareToPlay(pData->engine->getSampleRate(), static_cast<int>(pData->engine->getBufferSize()));
  547. } catch(...) {}
  548. }
  549. void deactivate() noexcept override
  550. {
  551. CARLA_SAFE_ASSERT_RETURN(fInstance != nullptr,);
  552. try {
  553. fInstance->releaseResources();
  554. } catch(...) {}
  555. }
  556. void process(const float** const audioIn, float** const audioOut, const float** const, float** const, const uint32_t frames) override
  557. {
  558. // --------------------------------------------------------------------------------------------------------
  559. // Check if active
  560. if (! pData->active)
  561. {
  562. // disable any output sound
  563. for (uint32_t i=0; i < pData->audioOut.count; ++i)
  564. carla_zeroFloats(audioOut[i], static_cast<int>(frames));
  565. return;
  566. }
  567. // --------------------------------------------------------------------------------------------------------
  568. // Check if needs reset
  569. if (pData->needsReset)
  570. {
  571. fInstance->reset();
  572. pData->needsReset = false;
  573. }
  574. // --------------------------------------------------------------------------------------------------------
  575. // Event Input
  576. fMidiBuffer.clear();
  577. if (pData->event.portIn != nullptr)
  578. {
  579. // ----------------------------------------------------------------------------------------------------
  580. // MIDI Input (External)
  581. if (pData->extNotes.mutex.tryLock())
  582. {
  583. for (RtLinkedList<ExternalMidiNote>::Itenerator it = pData->extNotes.data.begin2(); it.valid(); it.next())
  584. {
  585. const ExternalMidiNote& note(it.getValue(kExternalMidiNoteFallback));
  586. CARLA_SAFE_ASSERT_CONTINUE(note.channel >= 0 && note.channel < MAX_MIDI_CHANNELS);
  587. uint8_t midiEvent[3];
  588. midiEvent[0] = uint8_t((note.velo > 0 ? MIDI_STATUS_NOTE_ON : MIDI_STATUS_NOTE_OFF) | (note.channel & MIDI_CHANNEL_BIT));
  589. midiEvent[1] = note.note;
  590. midiEvent[2] = note.velo;
  591. fMidiBuffer.addEvent(midiEvent, 3, 0);
  592. }
  593. pData->extNotes.data.clear();
  594. pData->extNotes.mutex.unlock();
  595. } // End of MIDI Input (External)
  596. // ----------------------------------------------------------------------------------------------------
  597. // Event Input (System)
  598. #ifndef BUILD_BRIDGE
  599. bool allNotesOffSent = false;
  600. #endif
  601. for (uint32_t i=0, numEvents=pData->event.portIn->getEventCount(); i < numEvents; ++i)
  602. {
  603. const EngineEvent& event(pData->event.portIn->getEvent(i));
  604. if (event.time >= frames)
  605. continue;
  606. switch (event.type)
  607. {
  608. case kEngineEventTypeNull:
  609. break;
  610. case kEngineEventTypeControl: {
  611. const EngineControlEvent& ctrlEvent(event.ctrl);
  612. switch (ctrlEvent.type)
  613. {
  614. case kEngineControlEventTypeNull:
  615. break;
  616. case kEngineControlEventTypeParameter: {
  617. #ifndef BUILD_BRIDGE
  618. // Control backend stuff
  619. if (event.channel == pData->ctrlChannel)
  620. {
  621. float value;
  622. if (MIDI_IS_CONTROL_BREATH_CONTROLLER(ctrlEvent.param) && (pData->hints & PLUGIN_CAN_DRYWET) != 0)
  623. {
  624. value = ctrlEvent.value;
  625. setDryWet(value, false, false);
  626. pData->postponeRtEvent(kPluginPostRtEventParameterChange, PARAMETER_DRYWET, 0, value);
  627. }
  628. if (MIDI_IS_CONTROL_CHANNEL_VOLUME(ctrlEvent.param) && (pData->hints & PLUGIN_CAN_VOLUME) != 0)
  629. {
  630. value = ctrlEvent.value*127.0f/100.0f;
  631. setVolume(value, false, false);
  632. pData->postponeRtEvent(kPluginPostRtEventParameterChange, PARAMETER_VOLUME, 0, value);
  633. }
  634. if (MIDI_IS_CONTROL_BALANCE(ctrlEvent.param) && (pData->hints & PLUGIN_CAN_BALANCE) != 0)
  635. {
  636. float left, right;
  637. value = ctrlEvent.value/0.5f - 1.0f;
  638. if (value < 0.0f)
  639. {
  640. left = -1.0f;
  641. right = (value*2.0f)+1.0f;
  642. }
  643. else if (value > 0.0f)
  644. {
  645. left = (value*2.0f)-1.0f;
  646. right = 1.0f;
  647. }
  648. else
  649. {
  650. left = -1.0f;
  651. right = 1.0f;
  652. }
  653. setBalanceLeft(left, false, false);
  654. setBalanceRight(right, false, false);
  655. pData->postponeRtEvent(kPluginPostRtEventParameterChange, PARAMETER_BALANCE_LEFT, 0, left);
  656. pData->postponeRtEvent(kPluginPostRtEventParameterChange, PARAMETER_BALANCE_RIGHT, 0, right);
  657. }
  658. }
  659. #endif
  660. // Control plugin parameters
  661. uint32_t k;
  662. for (k=0; k < pData->param.count; ++k)
  663. {
  664. if (pData->param.data[k].midiChannel != event.channel)
  665. continue;
  666. if (pData->param.data[k].midiCC != ctrlEvent.param)
  667. continue;
  668. if (pData->param.data[k].type != PARAMETER_INPUT)
  669. continue;
  670. if ((pData->param.data[k].hints & PARAMETER_IS_AUTOMABLE) == 0)
  671. continue;
  672. float value;
  673. if (pData->param.data[k].hints & PARAMETER_IS_BOOLEAN)
  674. {
  675. value = (ctrlEvent.value < 0.5f) ? pData->param.ranges[k].min : pData->param.ranges[k].max;
  676. }
  677. else
  678. {
  679. if (pData->param.data[k].hints & PARAMETER_IS_LOGARITHMIC)
  680. value = pData->param.ranges[k].getUnnormalizedLogValue(ctrlEvent.value);
  681. else
  682. value = pData->param.ranges[k].getUnnormalizedValue(ctrlEvent.value);
  683. if (pData->param.data[k].hints & PARAMETER_IS_INTEGER)
  684. value = std::rint(value);
  685. }
  686. setParameterValue(k, value, false, false, false);
  687. pData->postponeRtEvent(kPluginPostRtEventParameterChange, static_cast<int32_t>(k), 0, value);
  688. }
  689. if ((pData->options & PLUGIN_OPTION_SEND_CONTROL_CHANGES) != 0 && ctrlEvent.param < MAX_MIDI_CONTROL)
  690. {
  691. uint8_t midiData[3];
  692. midiData[0] = uint8_t(MIDI_STATUS_CONTROL_CHANGE | (event.channel & MIDI_CHANNEL_BIT));
  693. midiData[1] = uint8_t(ctrlEvent.param);
  694. midiData[2] = uint8_t(ctrlEvent.value*127.0f);
  695. fMidiBuffer.addEvent(midiData, 3, static_cast<int>(event.time));
  696. }
  697. break;
  698. } // case kEngineControlEventTypeParameter
  699. case kEngineControlEventTypeMidiBank:
  700. break;
  701. case kEngineControlEventTypeMidiProgram:
  702. if (event.channel == pData->ctrlChannel && (pData->options & PLUGIN_OPTION_MAP_PROGRAM_CHANGES) != 0)
  703. {
  704. if (ctrlEvent.param < pData->prog.count)
  705. {
  706. setProgramRT(ctrlEvent.param);
  707. pData->postponeRtEvent(kPluginPostRtEventProgramChange, ctrlEvent.param, 0, 0.0f);
  708. break;
  709. }
  710. }
  711. break;
  712. case kEngineControlEventTypeAllSoundOff:
  713. if (pData->options & PLUGIN_OPTION_SEND_ALL_SOUND_OFF)
  714. {
  715. uint8_t midiData[3];
  716. midiData[0] = uint8_t(MIDI_STATUS_CONTROL_CHANGE | (event.channel & MIDI_CHANNEL_BIT));
  717. midiData[1] = MIDI_CONTROL_ALL_SOUND_OFF;
  718. midiData[2] = 0;
  719. fMidiBuffer.addEvent(midiData, 3, static_cast<int>(event.time));
  720. }
  721. break;
  722. case kEngineControlEventTypeAllNotesOff:
  723. if (pData->options & PLUGIN_OPTION_SEND_ALL_SOUND_OFF)
  724. {
  725. #ifndef BUILD_BRIDGE
  726. if (event.channel == pData->ctrlChannel && ! allNotesOffSent)
  727. {
  728. allNotesOffSent = true;
  729. sendMidiAllNotesOffToCallback();
  730. }
  731. #endif
  732. uint8_t midiData[3];
  733. midiData[0] = uint8_t(MIDI_STATUS_CONTROL_CHANGE | (event.channel & MIDI_CHANNEL_BIT));
  734. midiData[1] = MIDI_CONTROL_ALL_NOTES_OFF;
  735. midiData[2] = 0;
  736. fMidiBuffer.addEvent(midiData, 3, static_cast<int>(event.time));
  737. }
  738. break;
  739. } // switch (ctrlEvent.type)
  740. break;
  741. } // case kEngineEventTypeControl
  742. case kEngineEventTypeMidi: {
  743. const EngineMidiEvent& midiEvent(event.midi);
  744. const uint8_t* const midiData(midiEvent.size > EngineMidiEvent::kDataSize ? midiEvent.dataExt : midiEvent.data);
  745. uint8_t status = uint8_t(MIDI_GET_STATUS_FROM_DATA(midiData));
  746. if (status == MIDI_STATUS_CHANNEL_PRESSURE && (pData->options & PLUGIN_OPTION_SEND_CHANNEL_PRESSURE) == 0)
  747. continue;
  748. if (status == MIDI_STATUS_CONTROL_CHANGE && (pData->options & PLUGIN_OPTION_SEND_CONTROL_CHANGES) == 0)
  749. continue;
  750. if (status == MIDI_STATUS_POLYPHONIC_AFTERTOUCH && (pData->options & PLUGIN_OPTION_SEND_NOTE_AFTERTOUCH) == 0)
  751. continue;
  752. if (status == MIDI_STATUS_PITCH_WHEEL_CONTROL && (pData->options & PLUGIN_OPTION_SEND_PITCHBEND) == 0)
  753. continue;
  754. // Fix bad note-off
  755. if (status == MIDI_STATUS_NOTE_ON && midiData[2] == 0)
  756. status = MIDI_STATUS_NOTE_OFF;
  757. // put back channel in data
  758. uint8_t midiData2[midiEvent.size];
  759. midiData2[0] = uint8_t(status | (event.channel & MIDI_CHANNEL_BIT));
  760. std::memcpy(midiData2+1, midiData+1, static_cast<std::size_t>(midiEvent.size-1));
  761. fMidiBuffer.addEvent(midiData2, midiEvent.size, static_cast<int>(event.time));
  762. if (status == MIDI_STATUS_NOTE_ON)
  763. pData->postponeRtEvent(kPluginPostRtEventNoteOn, event.channel, midiData[1], midiData[2]);
  764. else if (status == MIDI_STATUS_NOTE_OFF)
  765. pData->postponeRtEvent(kPluginPostRtEventNoteOff, event.channel, midiData[1], 0.0f);
  766. } break;
  767. } // switch (event.type)
  768. }
  769. pData->postRtEvents.trySplice();
  770. } // End of Event Input
  771. // --------------------------------------------------------------------------------------------------------
  772. // Set TimeInfo
  773. const EngineTimeInfo& timeInfo(pData->engine->getTimeInfo());
  774. fPosInfo.isPlaying = timeInfo.playing;
  775. if (timeInfo.bbt.valid)
  776. {
  777. const double ppqBar = double(timeInfo.bbt.bar - 1) * timeInfo.bbt.beatsPerBar;
  778. const double ppqBeat = double(timeInfo.bbt.beat - 1);
  779. const double ppqTick = double(timeInfo.bbt.tick) / timeInfo.bbt.ticksPerBeat;
  780. fPosInfo.bpm = timeInfo.bbt.beatsPerMinute;
  781. fPosInfo.timeSigNumerator = static_cast<int>(timeInfo.bbt.beatsPerBar);
  782. fPosInfo.timeSigDenominator = static_cast<int>(timeInfo.bbt.beatType);
  783. fPosInfo.timeInSamples = static_cast<int64_t>(timeInfo.frame);
  784. fPosInfo.timeInSeconds = static_cast<double>(fPosInfo.timeInSamples)/pData->engine->getSampleRate();
  785. fPosInfo.ppqPosition = ppqBar + ppqBeat + ppqTick;
  786. fPosInfo.ppqPositionOfLastBarStart = ppqBar;
  787. }
  788. // --------------------------------------------------------------------------------------------------------
  789. // Process
  790. processSingle(audioIn, audioOut, frames);
  791. }
  792. bool processSingle(const float** const inBuffer, float** const outBuffer, const uint32_t frames)
  793. {
  794. CARLA_SAFE_ASSERT_RETURN(frames > 0, false);
  795. if (pData->audioIn.count > 0)
  796. {
  797. CARLA_SAFE_ASSERT_RETURN(inBuffer != nullptr, false);
  798. }
  799. if (pData->audioOut.count > 0)
  800. {
  801. CARLA_SAFE_ASSERT_RETURN(outBuffer != nullptr, false);
  802. }
  803. // --------------------------------------------------------------------------------------------------------
  804. // Try lock, silence otherwise
  805. if (pData->engine->isOffline())
  806. {
  807. pData->singleMutex.lock();
  808. }
  809. else if (! pData->singleMutex.tryLock())
  810. {
  811. for (uint32_t i=0; i < pData->audioOut.count; ++i)
  812. carla_zeroFloats(outBuffer[i], static_cast<int>(frames));
  813. return false;
  814. }
  815. // --------------------------------------------------------------------------------------------------------
  816. // Set audio in buffers
  817. for (uint32_t i=0; i < pData->audioIn.count; ++i)
  818. fAudioBuffer.copyFrom(static_cast<int>(i), 0, inBuffer[i], static_cast<int>(frames));
  819. // --------------------------------------------------------------------------------------------------------
  820. // Run plugin
  821. fInstance->processBlock(fAudioBuffer, fMidiBuffer);
  822. // --------------------------------------------------------------------------------------------------------
  823. // Set audio out buffers
  824. for (uint32_t i=0; i < pData->audioOut.count; ++i)
  825. carla_copyFloats(outBuffer[i], fAudioBuffer.getReadPointer(static_cast<int>(i)), static_cast<int>(frames));
  826. // --------------------------------------------------------------------------------------------------------
  827. // Midi out
  828. if (! fMidiBuffer.isEmpty())
  829. {
  830. if (pData->event.portOut != nullptr)
  831. {
  832. const uint8_t* midiEventData;
  833. int midiEventSize, midiEventPosition;
  834. for (juce::MidiBuffer::Iterator i(fMidiBuffer); i.getNextEvent(midiEventData, midiEventSize, midiEventPosition);)
  835. {
  836. CARLA_SAFE_ASSERT_BREAK(midiEventPosition >= 0 && midiEventPosition < static_cast<int>(frames));
  837. CARLA_SAFE_ASSERT_BREAK(midiEventSize > 0);
  838. if (! pData->event.portOut->writeMidiEvent(static_cast<uint32_t>(midiEventPosition), static_cast<uint8_t>(midiEventSize), midiEventData))
  839. break;
  840. }
  841. }
  842. fMidiBuffer.clear();
  843. }
  844. // --------------------------------------------------------------------------------------------------------
  845. pData->singleMutex.unlock();
  846. return true;
  847. }
  848. void bufferSizeChanged(const uint32_t newBufferSize) override
  849. {
  850. CARLA_ASSERT_INT(newBufferSize > 0, newBufferSize);
  851. carla_debug("CarlaPluginJuce::bufferSizeChanged(%i)", newBufferSize);
  852. fAudioBuffer.setSize(static_cast<int>(std::max<uint32_t>(pData->audioIn.count, pData->audioOut.count)), static_cast<int>(newBufferSize));
  853. if (pData->active)
  854. {
  855. deactivate();
  856. activate();
  857. }
  858. }
  859. void sampleRateChanged(const double newSampleRate) override
  860. {
  861. CARLA_ASSERT_INT(newSampleRate > 0.0, newSampleRate);
  862. carla_debug("CarlaPluginJuce::sampleRateChanged(%g)", newSampleRate);
  863. if (pData->active)
  864. {
  865. deactivate();
  866. activate();
  867. }
  868. }
  869. // -------------------------------------------------------------------
  870. // Plugin buffers
  871. // nothing
  872. // -------------------------------------------------------------------
  873. // Post-poned UI Stuff
  874. // nothing
  875. // -------------------------------------------------------------------
  876. void* getNativeHandle() const noexcept override
  877. {
  878. return (fInstance != nullptr) ? fInstance->getPlatformSpecificData() : nullptr;
  879. }
  880. // -------------------------------------------------------------------
  881. protected:
  882. void audioProcessorParameterChanged(juce::AudioProcessor*, int index, float value) override
  883. {
  884. CARLA_SAFE_ASSERT_RETURN(index >= 0,);
  885. const uint32_t uindex(static_cast<uint32_t>(index));
  886. const float fixedValue(pData->param.getFixedValue(uindex, value));
  887. CarlaPlugin::setParameterValue(static_cast<uint32_t>(index), fixedValue, false, true, true);
  888. }
  889. void audioProcessorChanged(juce::AudioProcessor*) override
  890. {
  891. pData->engine->callback(ENGINE_CALLBACK_UPDATE, pData->id, 0, 0, 0.0f, nullptr);
  892. }
  893. void audioProcessorParameterChangeGestureBegin(juce::AudioProcessor*, int) override {}
  894. void audioProcessorParameterChangeGestureEnd(juce::AudioProcessor*, int) override {}
  895. bool getCurrentPosition(CurrentPositionInfo& result) override
  896. {
  897. carla_copyStruct(result, fPosInfo);
  898. return true;
  899. }
  900. // -------------------------------------------------------------------
  901. public:
  902. bool init(const char* const filename, const char* const name, const char* const label, const int64_t uniqueId, const uint options, const char* const format)
  903. {
  904. CARLA_SAFE_ASSERT_RETURN(pData->engine != nullptr, false);
  905. // ---------------------------------------------------------------
  906. // first checks
  907. if (pData->client != nullptr)
  908. {
  909. pData->engine->setLastError("Plugin client is already registered");
  910. return false;
  911. }
  912. if (format == nullptr || format[0] == '\0')
  913. {
  914. pData->engine->setLastError("null format");
  915. return false;
  916. }
  917. // AU and VST3 require label
  918. if (std::strcmp(format, "AU") == 0 || std::strcmp(format, "VST3") == 0)
  919. {
  920. if (label == nullptr || label[0] == '\0')
  921. {
  922. pData->engine->setLastError("null label");
  923. return false;
  924. }
  925. }
  926. juce::String fileOrIdentifier;
  927. if (std::strcmp(format, "AU") == 0)
  928. {
  929. fileOrIdentifier = label;
  930. }
  931. else
  932. {
  933. // VST2 and VST3 require filename
  934. if (filename == nullptr || filename[0] == '\0')
  935. {
  936. pData->engine->setLastError("null filename");
  937. return false;
  938. }
  939. juce::String jfilename(filename);
  940. #ifdef CARLA_OS_WIN
  941. // Fix for wine usage
  942. if (juce::juce_isRunningInWine() && filename[0] == '/')
  943. {
  944. jfilename.replace("/", "\\");
  945. jfilename = "Z:" + jfilename;
  946. }
  947. #endif
  948. fileOrIdentifier = jfilename;
  949. if (label != nullptr && label[0] != '\0')
  950. fDesc.name = label;
  951. }
  952. fFormatManager.addDefaultFormats();
  953. {
  954. juce::OwnedArray<juce::PluginDescription> pluginDescriptions;
  955. juce::KnownPluginList plist;
  956. for (int i = 0; i < fFormatManager.getNumFormats(); ++i)
  957. plist.scanAndAddFile(fileOrIdentifier, true, pluginDescriptions, *fFormatManager.getFormat(i));
  958. if (pluginDescriptions.size() == 0)
  959. {
  960. pData->engine->setLastError("Failed to get plugin description");
  961. return false;
  962. }
  963. fDesc = *pluginDescriptions[0];
  964. }
  965. if (uniqueId != 0)
  966. fDesc.uid = static_cast<int>(uniqueId);
  967. juce::String error;
  968. fInstance = fFormatManager.createPluginInstance(fDesc,
  969. pData->engine->getSampleRate(),
  970. static_cast<int>(pData->engine->getBufferSize()),
  971. error);
  972. if (fInstance == nullptr)
  973. {
  974. pData->engine->setLastError(error.toRawUTF8());
  975. return false;
  976. }
  977. fInstance->fillInPluginDescription(fDesc);
  978. fInstance->setPlayHead(this);
  979. fInstance->addListener(this);
  980. fFormatName = format;
  981. // ---------------------------------------------------------------
  982. // get info
  983. if (name != nullptr && name[0] != '\0')
  984. pData->name = pData->engine->getUniquePluginName(name);
  985. else
  986. pData->name = pData->engine->getUniquePluginName(fInstance->getName().toRawUTF8());
  987. if (filename != nullptr && filename[0] != '\0')
  988. pData->filename = carla_strdup(filename);
  989. // ---------------------------------------------------------------
  990. // register client
  991. pData->client = pData->engine->addClient(this);
  992. if (pData->client == nullptr || ! pData->client->isOk())
  993. {
  994. pData->engine->setLastError("Failed to register plugin client");
  995. return false;
  996. }
  997. // ---------------------------------------------------------------
  998. // set default options
  999. pData->options = 0x0;
  1000. pData->options |= PLUGIN_OPTION_FIXED_BUFFERS;
  1001. pData->options |= PLUGIN_OPTION_USE_CHUNKS;
  1002. if (fInstance->getNumPrograms() > 1)
  1003. pData->options |= PLUGIN_OPTION_MAP_PROGRAM_CHANGES;
  1004. if (fInstance->acceptsMidi())
  1005. {
  1006. pData->options |= PLUGIN_OPTION_SEND_CHANNEL_PRESSURE;
  1007. pData->options |= PLUGIN_OPTION_SEND_NOTE_AFTERTOUCH;
  1008. pData->options |= PLUGIN_OPTION_SEND_PITCHBEND;
  1009. pData->options |= PLUGIN_OPTION_SEND_ALL_SOUND_OFF;
  1010. if (options & PLUGIN_OPTION_SEND_CONTROL_CHANGES)
  1011. pData->options |= PLUGIN_OPTION_SEND_CONTROL_CHANGES;
  1012. }
  1013. return true;
  1014. }
  1015. private:
  1016. juce::PluginDescription fDesc;
  1017. juce::AudioPluginInstance* fInstance;
  1018. juce::AudioPluginFormatManager fFormatManager;
  1019. juce::AudioSampleBuffer fAudioBuffer;
  1020. juce::MidiBuffer fMidiBuffer;
  1021. CurrentPositionInfo fPosInfo;
  1022. juce::MemoryBlock fChunk;
  1023. juce::String fFormatName;
  1024. ScopedPointer<JucePluginWindow> fWindow;
  1025. bool isJuceSaveFormat(const void* const data, const std::size_t dataSize)
  1026. {
  1027. if (fFormatName != "VST2")
  1028. return true;
  1029. if (dataSize < 160)
  1030. return false;
  1031. const int32_t* const set = (const int32_t*)data;
  1032. if (! compareMagic(set[0], "CcnK"))
  1033. return false;
  1034. if (! compareMagic(set[2], "FBCh"))
  1035. return false;
  1036. if (fxbSwap(set[3]) > 1)
  1037. return false;
  1038. const int32_t chunkSize = fxbSwap(set[39]);
  1039. return static_cast<std::size_t>(chunkSize + 160) == dataSize;
  1040. }
  1041. static bool compareMagic(int32_t magic, const char* name) noexcept
  1042. {
  1043. return magic == (int32_t)juce::ByteOrder::littleEndianInt (name)
  1044. || magic == (int32_t)juce::ByteOrder::bigEndianInt (name);
  1045. }
  1046. static int32_t fxbSwap(const int32_t x) noexcept
  1047. {
  1048. return (int32_t)juce::ByteOrder::swapIfLittleEndian ((uint32_t) x);
  1049. }
  1050. CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(CarlaPluginJuce)
  1051. };
  1052. CARLA_BACKEND_END_NAMESPACE
  1053. #endif // USING_JUCE
  1054. // -------------------------------------------------------------------------------------------------------------------
  1055. CARLA_BACKEND_START_NAMESPACE
  1056. CarlaPlugin* CarlaPlugin::newJuce(const Initializer& init, const char* const format)
  1057. {
  1058. carla_debug("CarlaPlugin::newJuce({%p, \"%s\", \"%s\", \"%s\", " P_INT64 "}, %s)", init.engine, init.filename, init.name, init.label, init.uniqueId, format);
  1059. #ifdef USING_JUCE
  1060. CarlaPluginJuce* const plugin(new CarlaPluginJuce(init.engine, init.id));
  1061. if (! plugin->init(init.filename, init.name, init.label, init.uniqueId, init.options, format))
  1062. {
  1063. delete plugin;
  1064. return nullptr;
  1065. }
  1066. return plugin;
  1067. #else
  1068. init.engine->setLastError("Juce-based plugin not available");
  1069. return nullptr;
  1070. // unused
  1071. (void)format;
  1072. #endif
  1073. }
  1074. CARLA_BACKEND_END_NAMESPACE
  1075. // -------------------------------------------------------------------------------------------------------------------