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.

1412 lines
48KB

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