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.

2509 lines
81KB

  1. /*
  2. * Carla Plugin
  3. * Copyright (C) 2011-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. #include "CarlaBackendUtils.hpp"
  20. #include "CarlaBase64Utils.hpp"
  21. #include "CarlaMathUtils.hpp"
  22. #include "CarlaPluginUI.hpp"
  23. #include "CarlaScopeUtils.hpp"
  24. #include "CarlaStringList.hpp"
  25. #include <ctime>
  26. #include "water/files/File.h"
  27. #include "water/streams/MemoryOutputStream.h"
  28. #include "water/xml/XmlDocument.h"
  29. #include "water/xml/XmlElement.h"
  30. using water::CharPointer_UTF8;
  31. using water::File;
  32. using water::MemoryOutputStream;
  33. using water::Result;
  34. using water::String;
  35. using water::XmlDocument;
  36. using water::XmlElement;
  37. CARLA_BACKEND_START_NAMESPACE
  38. // -------------------------------------------------------------------
  39. // Fallback data
  40. static const ParameterData kParameterDataNull = { PARAMETER_UNKNOWN, 0x0, PARAMETER_NULL, -1, -1, 0 };
  41. static const ParameterRanges kParameterRangesNull = { 0.0f, 0.0f, 1.0f, 0.01f, 0.0001f, 0.1f };
  42. static const MidiProgramData kMidiProgramDataNull = { 0, 0, nullptr };
  43. static const CustomData kCustomDataFallback = { nullptr, nullptr, nullptr };
  44. static /* */ CustomData kCustomDataFallbackNC = { nullptr, nullptr, nullptr };
  45. static const PluginPostRtEvent kPluginPostRtEventFallback = { kPluginPostRtEventNull, false, 0, 0, 0, 0.0f };
  46. // -------------------------------------------------------------------
  47. // ParamSymbol struct, needed for CarlaPlugin::loadStateSave()
  48. struct ParamSymbol {
  49. int32_t index;
  50. const char* symbol;
  51. ParamSymbol(const uint32_t i, const char* const s)
  52. : index(static_cast<int32_t>(i)),
  53. symbol(carla_strdup(s)) {}
  54. ~ParamSymbol() noexcept
  55. {
  56. CARLA_SAFE_ASSERT_RETURN(symbol != nullptr,)
  57. delete[] symbol;
  58. symbol = nullptr;
  59. }
  60. #ifdef CARLA_PROPER_CPP11_SUPPORT
  61. ParamSymbol() = delete;
  62. CARLA_DECLARE_NON_COPY_STRUCT(ParamSymbol)
  63. #endif
  64. };
  65. // -------------------------------------------------------------------
  66. // Constructor and destructor
  67. CarlaPlugin::CarlaPlugin(CarlaEngine* const engine, const uint id)
  68. : pData(new ProtectedData(engine, id))
  69. {
  70. CARLA_SAFE_ASSERT_RETURN(engine != nullptr,);
  71. CARLA_SAFE_ASSERT(id < engine->getMaxPluginNumber());
  72. carla_debug("CarlaPlugin::CarlaPlugin(%p, %i)", engine, id);
  73. switch (engine->getProccessMode())
  74. {
  75. case ENGINE_PROCESS_MODE_SINGLE_CLIENT:
  76. case ENGINE_PROCESS_MODE_MULTIPLE_CLIENTS:
  77. CARLA_SAFE_ASSERT(id < MAX_DEFAULT_PLUGINS);
  78. break;
  79. case ENGINE_PROCESS_MODE_CONTINUOUS_RACK:
  80. CARLA_SAFE_ASSERT(id < MAX_RACK_PLUGINS);
  81. break;
  82. case ENGINE_PROCESS_MODE_PATCHBAY:
  83. CARLA_SAFE_ASSERT(id < MAX_PATCHBAY_PLUGINS);
  84. break;
  85. case ENGINE_PROCESS_MODE_BRIDGE:
  86. CARLA_SAFE_ASSERT(id == 0);
  87. break;
  88. }
  89. }
  90. CarlaPlugin::~CarlaPlugin()
  91. {
  92. carla_debug("CarlaPlugin::~CarlaPlugin()");
  93. delete pData;
  94. }
  95. // -------------------------------------------------------------------
  96. // Information (base)
  97. uint CarlaPlugin::getId() const noexcept
  98. {
  99. return pData->id;
  100. }
  101. uint CarlaPlugin::getHints() const noexcept
  102. {
  103. return pData->hints;
  104. }
  105. uint CarlaPlugin::getOptionsEnabled() const noexcept
  106. {
  107. return pData->options;
  108. }
  109. bool CarlaPlugin::isEnabled() const noexcept
  110. {
  111. return pData->enabled;
  112. }
  113. const char* CarlaPlugin::getName() const noexcept
  114. {
  115. return pData->name;
  116. }
  117. const char* CarlaPlugin::getFilename() const noexcept
  118. {
  119. return pData->filename;
  120. }
  121. const char* CarlaPlugin::getIconName() const noexcept
  122. {
  123. return pData->iconName;
  124. }
  125. PluginCategory CarlaPlugin::getCategory() const noexcept
  126. {
  127. return getPluginCategoryFromName(pData->name);
  128. }
  129. int64_t CarlaPlugin::getUniqueId() const noexcept
  130. {
  131. return 0;
  132. }
  133. uint32_t CarlaPlugin::getLatencyInFrames() const noexcept
  134. {
  135. return 0;
  136. }
  137. // -------------------------------------------------------------------
  138. // Information (count)
  139. uint32_t CarlaPlugin::getAudioInCount() const noexcept
  140. {
  141. return pData->audioIn.count;
  142. }
  143. uint32_t CarlaPlugin::getAudioOutCount() const noexcept
  144. {
  145. return pData->audioOut.count;
  146. }
  147. uint32_t CarlaPlugin::getCVInCount() const noexcept
  148. {
  149. return pData->cvIn.count + (pData->event.portIn != nullptr ? pData->event.portIn->getCVSourceCount() : 0);
  150. }
  151. uint32_t CarlaPlugin::getCVOutCount() const noexcept
  152. {
  153. return pData->cvOut.count;
  154. }
  155. uint32_t CarlaPlugin::getMidiInCount() const noexcept
  156. {
  157. return (pData->extraHints & PLUGIN_EXTRA_HINT_HAS_MIDI_IN) ? 1 : 0;
  158. }
  159. uint32_t CarlaPlugin::getMidiOutCount() const noexcept
  160. {
  161. return (pData->extraHints & PLUGIN_EXTRA_HINT_HAS_MIDI_OUT) ? 1 : 0;
  162. }
  163. uint32_t CarlaPlugin::getParameterCount() const noexcept
  164. {
  165. return pData->param.count;
  166. }
  167. uint32_t CarlaPlugin::getParameterScalePointCount(const uint32_t parameterId) const noexcept
  168. {
  169. CARLA_SAFE_ASSERT_RETURN(parameterId < pData->param.count, 0);
  170. return 0;
  171. }
  172. uint32_t CarlaPlugin::getProgramCount() const noexcept
  173. {
  174. return pData->prog.count;
  175. }
  176. uint32_t CarlaPlugin::getMidiProgramCount() const noexcept
  177. {
  178. return pData->midiprog.count;
  179. }
  180. uint32_t CarlaPlugin::getCustomDataCount() const noexcept
  181. {
  182. return static_cast<uint32_t>(pData->custom.count());
  183. }
  184. // -------------------------------------------------------------------
  185. // Information (current data)
  186. int32_t CarlaPlugin::getCurrentProgram() const noexcept
  187. {
  188. return pData->prog.current;
  189. }
  190. int32_t CarlaPlugin::getCurrentMidiProgram() const noexcept
  191. {
  192. return pData->midiprog.current;
  193. }
  194. const ParameterData& CarlaPlugin::getParameterData(const uint32_t parameterId) const noexcept
  195. {
  196. CARLA_SAFE_ASSERT_RETURN(parameterId < pData->param.count, kParameterDataNull);
  197. return pData->param.data[parameterId];
  198. }
  199. const ParameterRanges& CarlaPlugin::getParameterRanges(const uint32_t parameterId) const noexcept
  200. {
  201. CARLA_SAFE_ASSERT_RETURN(parameterId < pData->param.count, kParameterRangesNull);
  202. return pData->param.ranges[parameterId];
  203. }
  204. bool CarlaPlugin::isParameterOutput(const uint32_t parameterId) const noexcept
  205. {
  206. CARLA_SAFE_ASSERT_RETURN(parameterId < pData->param.count, false);
  207. return (pData->param.data[parameterId].type == PARAMETER_OUTPUT);
  208. }
  209. const MidiProgramData& CarlaPlugin::getMidiProgramData(const uint32_t index) const noexcept
  210. {
  211. CARLA_SAFE_ASSERT_RETURN(index < pData->midiprog.count, kMidiProgramDataNull);
  212. return pData->midiprog.data[index];
  213. }
  214. const CustomData& CarlaPlugin::getCustomData(const uint32_t index) const noexcept
  215. {
  216. return pData->custom.getAt(index, kCustomDataFallback);
  217. }
  218. std::size_t CarlaPlugin::getChunkData(void** const dataPtr) noexcept
  219. {
  220. CARLA_SAFE_ASSERT_RETURN(dataPtr != nullptr, 0);
  221. CARLA_SAFE_ASSERT(false); // this should never happen
  222. return 0;
  223. }
  224. // -------------------------------------------------------------------
  225. // Information (per-plugin data)
  226. uint CarlaPlugin::getOptionsAvailable() const noexcept
  227. {
  228. CARLA_SAFE_ASSERT(false); // this should never happen
  229. return 0x0;
  230. }
  231. float CarlaPlugin::getParameterValue(const uint32_t parameterId) const noexcept
  232. {
  233. CARLA_SAFE_ASSERT_RETURN(parameterId < getParameterCount(), 0.0f);
  234. CARLA_SAFE_ASSERT(false); // this should never happen
  235. return 0.0f;
  236. }
  237. float CarlaPlugin::getParameterScalePointValue(const uint32_t parameterId, const uint32_t scalePointId) const noexcept
  238. {
  239. CARLA_SAFE_ASSERT_RETURN(parameterId < getParameterCount(), 0.0f);
  240. CARLA_SAFE_ASSERT_RETURN(scalePointId < getParameterScalePointCount(parameterId), 0.0f);
  241. CARLA_SAFE_ASSERT(false); // this should never happen
  242. return 0.0f;
  243. }
  244. bool CarlaPlugin::getLabel(char* const strBuf) const noexcept
  245. {
  246. strBuf[0] = '\0';
  247. return false;
  248. }
  249. bool CarlaPlugin::getMaker(char* const strBuf) const noexcept
  250. {
  251. strBuf[0] = '\0';
  252. return false;
  253. }
  254. bool CarlaPlugin::getCopyright(char* const strBuf) const noexcept
  255. {
  256. strBuf[0] = '\0';
  257. return false;
  258. }
  259. bool CarlaPlugin::getRealName(char* const strBuf) const noexcept
  260. {
  261. strBuf[0] = '\0';
  262. return false;
  263. }
  264. bool CarlaPlugin::getParameterName(const uint32_t parameterId, char* const strBuf) const noexcept
  265. {
  266. CARLA_SAFE_ASSERT_RETURN(parameterId < getParameterCount(), false);
  267. CARLA_SAFE_ASSERT(false); // this should never happen
  268. strBuf[0] = '\0';
  269. return false;
  270. }
  271. bool CarlaPlugin::getParameterSymbol(const uint32_t parameterId, char* const strBuf) const noexcept
  272. {
  273. CARLA_SAFE_ASSERT_RETURN(parameterId < getParameterCount(), false);
  274. strBuf[0] = '\0';
  275. return false;
  276. }
  277. bool CarlaPlugin::getParameterText(const uint32_t parameterId, char* const strBuf) noexcept
  278. {
  279. CARLA_SAFE_ASSERT_RETURN(parameterId < getParameterCount(), false);
  280. CARLA_SAFE_ASSERT(false); // this should never happen
  281. strBuf[0] = '\0';
  282. return false;
  283. }
  284. bool CarlaPlugin::getParameterUnit(const uint32_t parameterId, char* const strBuf) const noexcept
  285. {
  286. CARLA_SAFE_ASSERT_RETURN(parameterId < getParameterCount(), false);
  287. strBuf[0] = '\0';
  288. return false;
  289. }
  290. bool CarlaPlugin::getParameterComment(const uint32_t parameterId, char* const strBuf) const noexcept
  291. {
  292. CARLA_SAFE_ASSERT_RETURN(parameterId < getParameterCount(), false);
  293. strBuf[0] = '\0';
  294. return false;
  295. }
  296. bool CarlaPlugin::getParameterGroupName(const uint32_t parameterId, char* const strBuf) const noexcept
  297. {
  298. CARLA_SAFE_ASSERT_RETURN(parameterId < getParameterCount(), false);
  299. strBuf[0] = '\0';
  300. return false;
  301. }
  302. bool CarlaPlugin::getParameterScalePointLabel(const uint32_t parameterId, const uint32_t scalePointId, char* const strBuf) const noexcept
  303. {
  304. CARLA_SAFE_ASSERT_RETURN(parameterId < getParameterCount(), false);
  305. CARLA_SAFE_ASSERT_RETURN(scalePointId < getParameterScalePointCount(parameterId), false);
  306. CARLA_SAFE_ASSERT(false); // this should never happen
  307. strBuf[0] = '\0';
  308. return false;
  309. }
  310. float CarlaPlugin::getInternalParameterValue(const int32_t parameterId) const noexcept
  311. {
  312. #ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH
  313. CARLA_SAFE_ASSERT_RETURN(parameterId != PARAMETER_NULL && parameterId > PARAMETER_MAX, 0.0f);
  314. switch (parameterId)
  315. {
  316. case PARAMETER_ACTIVE:
  317. return pData->active;
  318. case PARAMETER_CTRL_CHANNEL:
  319. return pData->ctrlChannel;
  320. case PARAMETER_DRYWET:
  321. return pData->postProc.dryWet;
  322. case PARAMETER_VOLUME:
  323. return pData->postProc.volume;
  324. case PARAMETER_BALANCE_LEFT:
  325. return pData->postProc.balanceLeft;
  326. case PARAMETER_BALANCE_RIGHT:
  327. return pData->postProc.balanceRight;
  328. case PARAMETER_PANNING:
  329. return pData->postProc.panning;
  330. };
  331. #endif
  332. CARLA_SAFE_ASSERT_RETURN(parameterId >= 0, 0.0f);
  333. return getParameterValue(static_cast<uint32_t>(parameterId));
  334. }
  335. bool CarlaPlugin::getProgramName(const uint32_t index, char* const strBuf) const noexcept
  336. {
  337. CARLA_SAFE_ASSERT_RETURN(index < pData->prog.count, false);
  338. CARLA_SAFE_ASSERT_RETURN(pData->prog.names[index] != nullptr, false);
  339. std::strncpy(strBuf, pData->prog.names[index], STR_MAX);
  340. return false;
  341. }
  342. bool CarlaPlugin::getMidiProgramName(const uint32_t index, char* const strBuf) const noexcept
  343. {
  344. CARLA_SAFE_ASSERT_RETURN(index < pData->midiprog.count, false);
  345. CARLA_SAFE_ASSERT_RETURN(pData->midiprog.data[index].name != nullptr, false);
  346. std::strncpy(strBuf, pData->midiprog.data[index].name, STR_MAX);
  347. return false;
  348. }
  349. void CarlaPlugin::getParameterCountInfo(uint32_t& ins, uint32_t& outs) const noexcept
  350. {
  351. ins = 0;
  352. outs = 0;
  353. for (uint32_t i=0; i < pData->param.count; ++i)
  354. {
  355. if (pData->param.data[i].type == PARAMETER_INPUT)
  356. ++ins;
  357. else if (pData->param.data[i].type == PARAMETER_OUTPUT)
  358. ++outs;
  359. }
  360. }
  361. // -------------------------------------------------------------------
  362. // Set data (state)
  363. void CarlaPlugin::prepareForSave()
  364. {
  365. }
  366. void CarlaPlugin::resetParameters() noexcept
  367. {
  368. for (uint i=0; i < pData->param.count; ++i)
  369. {
  370. const ParameterData& paramData(pData->param.data[i]);
  371. const ParameterRanges& paramRanges(pData->param.ranges[i]);
  372. if (paramData.type != PARAMETER_INPUT)
  373. continue;
  374. if ((paramData.hints & PARAMETER_IS_ENABLED) == 0)
  375. continue;
  376. setParameterValue(i, paramRanges.def, true, true, true);
  377. }
  378. }
  379. void CarlaPlugin::randomizeParameters() noexcept
  380. {
  381. float value, random;
  382. char strBuf[STR_MAX+1];
  383. strBuf[STR_MAX] = '\0';
  384. std::srand(static_cast<uint>(std::time(nullptr)));
  385. for (uint i=0; i < pData->param.count; ++i)
  386. {
  387. const ParameterData& paramData(pData->param.data[i]);
  388. if (paramData.type != PARAMETER_INPUT)
  389. continue;
  390. if ((paramData.hints & PARAMETER_IS_ENABLED) == 0)
  391. continue;
  392. if (! getParameterName(i, strBuf))
  393. strBuf[0] = '\0';
  394. if (std::strstr(strBuf, "olume") != nullptr)
  395. continue;
  396. if (std::strstr(strBuf, "Master") != nullptr)
  397. continue;
  398. const ParameterRanges& paramRanges(pData->param.ranges[i]);
  399. if (paramData.hints & PARAMETER_IS_BOOLEAN)
  400. {
  401. random = static_cast<float>(std::rand()) / static_cast<float>(RAND_MAX);
  402. value = random > 0.5f ? paramRanges.max : paramRanges.min;
  403. }
  404. else
  405. {
  406. random = static_cast<float>(std::rand()) / static_cast<float>(RAND_MAX);
  407. value = random * (paramRanges.max - paramRanges.min) + paramRanges.min;
  408. if (paramData.hints & PARAMETER_IS_INTEGER)
  409. value = std::rint(value);
  410. }
  411. setParameterValue(i, value, true, true, true);
  412. }
  413. }
  414. const CarlaStateSave& CarlaPlugin::getStateSave(const bool callPrepareForSave)
  415. {
  416. if (callPrepareForSave)
  417. prepareForSave();
  418. pData->stateSave.clear();
  419. const PluginType pluginType(getType());
  420. char strBuf[STR_MAX+1];
  421. carla_zeroChars(strBuf, STR_MAX+1);
  422. // ---------------------------------------------------------------
  423. // Basic info
  424. if (! getLabel(strBuf))
  425. strBuf[0] = '\0';
  426. pData->stateSave.type = carla_strdup(getPluginTypeAsString(pluginType));
  427. pData->stateSave.name = carla_strdup(pData->name);
  428. pData->stateSave.label = carla_strdup(strBuf);
  429. pData->stateSave.uniqueId = getUniqueId();
  430. #ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH
  431. pData->stateSave.options = pData->options;
  432. #endif
  433. if (pData->filename != nullptr)
  434. pData->stateSave.binary = carla_strdup(pData->filename);
  435. #ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH
  436. // ---------------------------------------------------------------
  437. // Internals
  438. pData->stateSave.active = pData->active;
  439. pData->stateSave.dryWet = pData->postProc.dryWet;
  440. pData->stateSave.volume = pData->postProc.volume;
  441. pData->stateSave.balanceLeft = pData->postProc.balanceLeft;
  442. pData->stateSave.balanceRight = pData->postProc.balanceRight;
  443. pData->stateSave.panning = pData->postProc.panning;
  444. pData->stateSave.ctrlChannel = pData->ctrlChannel;
  445. #endif
  446. bool usingChunk = false;
  447. // ---------------------------------------------------------------
  448. // Chunk
  449. if (pData->options & PLUGIN_OPTION_USE_CHUNKS)
  450. {
  451. void* data = nullptr;
  452. const std::size_t dataSize(getChunkData(&data));
  453. if (data != nullptr && dataSize > 0)
  454. {
  455. pData->stateSave.chunk = CarlaString::asBase64(data, dataSize).dup();
  456. if (pluginType != PLUGIN_INTERNAL)
  457. usingChunk = true;
  458. }
  459. }
  460. // ---------------------------------------------------------------
  461. // Current Program
  462. if (pData->prog.current >= 0 && pluginType != PLUGIN_LV2)
  463. {
  464. pData->stateSave.currentProgramIndex = pData->prog.current;
  465. pData->stateSave.currentProgramName = carla_strdup(pData->prog.names[pData->prog.current]);
  466. }
  467. // ---------------------------------------------------------------
  468. // Current MIDI Program
  469. if (pData->midiprog.current >= 0 && pluginType != PLUGIN_LV2 && pluginType != PLUGIN_SF2)
  470. {
  471. const MidiProgramData& mpData(pData->midiprog.getCurrent());
  472. pData->stateSave.currentMidiBank = static_cast<int32_t>(mpData.bank);
  473. pData->stateSave.currentMidiProgram = static_cast<int32_t>(mpData.program);
  474. }
  475. // ---------------------------------------------------------------
  476. // Parameters
  477. const float sampleRate(static_cast<float>(pData->engine->getSampleRate()));
  478. for (uint32_t i=0; i < pData->param.count; ++i)
  479. {
  480. const ParameterData& paramData(pData->param.data[i]);
  481. if ((paramData.hints & PARAMETER_IS_ENABLED) == 0)
  482. continue;
  483. const bool dummy = paramData.type != PARAMETER_INPUT || usingChunk;
  484. if (dummy && paramData.midiCC <= -1)
  485. continue;
  486. CarlaStateSave::Parameter* const stateParameter(new CarlaStateSave::Parameter());
  487. stateParameter->dummy = dummy;
  488. stateParameter->index = paramData.index;
  489. #ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH
  490. stateParameter->midiCC = paramData.midiCC;
  491. stateParameter->midiChannel = paramData.midiChannel;
  492. #endif
  493. if (! getParameterName(i, strBuf))
  494. strBuf[0] = '\0';
  495. stateParameter->name = carla_strdup(strBuf);
  496. if (! getParameterSymbol(i, strBuf))
  497. strBuf[0] = '\0';
  498. stateParameter->symbol = carla_strdup(strBuf);;
  499. if (! dummy)
  500. {
  501. stateParameter->value = getParameterValue(i);
  502. if (paramData.hints & PARAMETER_USES_SAMPLERATE)
  503. stateParameter->value /= sampleRate;
  504. }
  505. pData->stateSave.parameters.append(stateParameter);
  506. }
  507. // ---------------------------------------------------------------
  508. // Custom Data
  509. if (pData->hints & PLUGIN_IS_BRIDGE)
  510. waitForBridgeSaveSignal();
  511. for (LinkedList<CustomData>::Itenerator it = pData->custom.begin2(); it.valid(); it.next())
  512. {
  513. const CustomData& cData(it.getValue(kCustomDataFallback));
  514. CARLA_SAFE_ASSERT_CONTINUE(cData.isValid());
  515. CarlaStateSave::CustomData* stateCustomData(new CarlaStateSave::CustomData());
  516. stateCustomData->type = carla_strdup(cData.type);
  517. stateCustomData->key = carla_strdup(cData.key);
  518. stateCustomData->value = carla_strdup(cData.value);
  519. pData->stateSave.customData.append(stateCustomData);
  520. }
  521. return pData->stateSave;
  522. }
  523. void CarlaPlugin::loadStateSave(const CarlaStateSave& stateSave)
  524. {
  525. const bool usesMultiProgs(pData->hints & PLUGIN_USES_MULTI_PROGS);
  526. const PluginType pluginType(getType());
  527. char strBuf[STR_MAX+1];
  528. carla_zeroChars(strBuf, STR_MAX+1);
  529. // ---------------------------------------------------------------
  530. // Part 1 - PRE-set custom data (only those which reload programs)
  531. for (CarlaStateSave::CustomDataItenerator it = stateSave.customData.begin2(); it.valid(); it.next())
  532. {
  533. const CarlaStateSave::CustomData* const stateCustomData(it.getValue(nullptr));
  534. CARLA_SAFE_ASSERT_CONTINUE(stateCustomData != nullptr);
  535. CARLA_SAFE_ASSERT_CONTINUE(stateCustomData->isValid());
  536. const char* const key(stateCustomData->key);
  537. /**/ if (pluginType == PLUGIN_DSSI && (std::strcmp (key, "reloadprograms") == 0 ||
  538. std::strcmp (key, "load" ) == 0 ||
  539. std::strncmp(key, "patches", 7) == 0 ))
  540. pass();
  541. else if (usesMultiProgs && std::strcmp(key, "midiPrograms") == 0)
  542. pass();
  543. else
  544. continue;
  545. setCustomData(stateCustomData->type, key, stateCustomData->value, true);
  546. }
  547. // ---------------------------------------------------------------
  548. // Part 2 - set program
  549. if (stateSave.currentProgramIndex >= 0 && stateSave.currentProgramName != nullptr)
  550. {
  551. int32_t programId = -1;
  552. // index < count
  553. if (stateSave.currentProgramIndex < static_cast<int32_t>(pData->prog.count))
  554. {
  555. programId = stateSave.currentProgramIndex;
  556. }
  557. // index not valid, try to find by name
  558. else
  559. {
  560. for (uint32_t i=0; i < pData->prog.count; ++i)
  561. {
  562. if (getProgramName(i, strBuf) && std::strcmp(stateSave.currentProgramName, strBuf) == 0)
  563. {
  564. programId = static_cast<int32_t>(i);
  565. break;
  566. }
  567. }
  568. }
  569. // set program now, if valid
  570. if (programId >= 0)
  571. setProgram(programId, true, true, true);
  572. }
  573. // ---------------------------------------------------------------
  574. // Part 3 - set midi program
  575. if (stateSave.currentMidiBank >= 0 && stateSave.currentMidiProgram >= 0 && ! usesMultiProgs)
  576. setMidiProgramById(static_cast<uint32_t>(stateSave.currentMidiBank), static_cast<uint32_t>(stateSave.currentMidiProgram), true, true, true);
  577. // ---------------------------------------------------------------
  578. // Part 4a - get plugin parameter symbols
  579. LinkedList<ParamSymbol*> paramSymbols;
  580. if (pluginType == PLUGIN_LADSPA || pluginType == PLUGIN_LV2)
  581. {
  582. for (uint32_t i=0; i < pData->param.count; ++i)
  583. {
  584. if (getParameterSymbol(i, strBuf))
  585. {
  586. ParamSymbol* const paramSymbol(new ParamSymbol(i, strBuf));
  587. paramSymbols.append(paramSymbol);
  588. }
  589. }
  590. }
  591. // ---------------------------------------------------------------
  592. // Part 4b - set parameter values (carefully)
  593. const float sampleRate(static_cast<float>(pData->engine->getSampleRate()));
  594. for (CarlaStateSave::ParameterItenerator it = stateSave.parameters.begin2(); it.valid(); it.next())
  595. {
  596. CarlaStateSave::Parameter* const stateParameter(it.getValue(nullptr));
  597. CARLA_SAFE_ASSERT_CONTINUE(stateParameter != nullptr);
  598. int32_t index = -1;
  599. if (pluginType == PLUGIN_LADSPA)
  600. {
  601. // Try to set by symbol, otherwise use index
  602. if (stateParameter->symbol != nullptr && stateParameter->symbol[0] != '\0')
  603. {
  604. for (LinkedList<ParamSymbol*>::Itenerator it2 = paramSymbols.begin2(); it2.valid(); it2.next())
  605. {
  606. ParamSymbol* const paramSymbol(it2.getValue(nullptr));
  607. CARLA_SAFE_ASSERT_CONTINUE(paramSymbol != nullptr);
  608. CARLA_SAFE_ASSERT_CONTINUE(paramSymbol->symbol != nullptr);
  609. if (std::strcmp(stateParameter->symbol, paramSymbol->symbol) == 0)
  610. {
  611. index = paramSymbol->index;
  612. break;
  613. }
  614. }
  615. if (index == -1)
  616. index = stateParameter->index;
  617. }
  618. else
  619. {
  620. index = stateParameter->index;
  621. }
  622. }
  623. else if (pluginType == PLUGIN_LV2)
  624. {
  625. // Symbol only
  626. if (stateParameter->symbol != nullptr && stateParameter->symbol[0] != '\0')
  627. {
  628. for (LinkedList<ParamSymbol*>::Itenerator it2 = paramSymbols.begin2(); it2.valid(); it2.next())
  629. {
  630. ParamSymbol* const paramSymbol(it2.getValue(nullptr));
  631. CARLA_SAFE_ASSERT_CONTINUE(paramSymbol != nullptr);
  632. CARLA_SAFE_ASSERT_CONTINUE(paramSymbol->symbol != nullptr);
  633. if (std::strcmp(stateParameter->symbol, paramSymbol->symbol) == 0)
  634. {
  635. index = paramSymbol->index;
  636. break;
  637. }
  638. }
  639. if (index == -1)
  640. carla_stderr("Failed to find LV2 parameter symbol '%s' for '%s'",
  641. stateParameter->symbol, pData->name);
  642. }
  643. else
  644. {
  645. carla_stderr("LV2 Plugin parameter '%s' has no symbol", stateParameter->name);
  646. }
  647. }
  648. else
  649. {
  650. // Index only
  651. index = stateParameter->index;
  652. }
  653. // Now set parameter
  654. if (index >= 0 && index < static_cast<int32_t>(pData->param.count))
  655. {
  656. //CARLA_SAFE_ASSERT(stateParameter->isInput == (pData
  657. if (! stateParameter->dummy)
  658. {
  659. if (pData->param.data[index].hints & PARAMETER_USES_SAMPLERATE)
  660. stateParameter->value *= sampleRate;
  661. setParameterValue(static_cast<uint32_t>(index), stateParameter->value, true, true, true);
  662. }
  663. #ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH
  664. setParameterMidiCC(static_cast<uint32_t>(index), stateParameter->midiCC, true, true);
  665. setParameterMidiChannel(static_cast<uint32_t>(index), stateParameter->midiChannel, true, true);
  666. #endif
  667. }
  668. else
  669. carla_stderr("Could not set parameter '%s' value for '%s'",
  670. stateParameter->name, pData->name);
  671. }
  672. // ---------------------------------------------------------------
  673. // Part 4c - clear
  674. for (LinkedList<ParamSymbol*>::Itenerator it = paramSymbols.begin2(); it.valid(); it.next())
  675. {
  676. ParamSymbol* const paramSymbol(it.getValue(nullptr));
  677. delete paramSymbol;
  678. }
  679. paramSymbols.clear();
  680. // ---------------------------------------------------------------
  681. // Part 5 - set custom data
  682. for (CarlaStateSave::CustomDataItenerator it = stateSave.customData.begin2(); it.valid(); it.next())
  683. {
  684. const CarlaStateSave::CustomData* const stateCustomData(it.getValue(nullptr));
  685. CARLA_SAFE_ASSERT_CONTINUE(stateCustomData != nullptr);
  686. CARLA_SAFE_ASSERT_CONTINUE(stateCustomData->isValid());
  687. const char* const key(stateCustomData->key);
  688. if (pluginType == PLUGIN_DSSI && (std::strcmp (key, "reloadprograms") == 0 ||
  689. std::strcmp (key, "load" ) == 0 ||
  690. std::strncmp(key, "patches", 7) == 0 ))
  691. continue;
  692. if (usesMultiProgs && std::strcmp(key, "midiPrograms") == 0)
  693. continue;
  694. setCustomData(stateCustomData->type, key, stateCustomData->value, true);
  695. }
  696. // ---------------------------------------------------------------
  697. // Part 5x - set lv2 state
  698. if (pluginType == PLUGIN_LV2)
  699. {
  700. for (LinkedList<CustomData>::Itenerator it = pData->custom.begin2(); it.valid(); it.next())
  701. {
  702. const CustomData& customData(it.getValue(kCustomDataFallback));
  703. CARLA_SAFE_ASSERT_CONTINUE(customData.isValid());
  704. if (std::strcmp(customData.type, CUSTOM_DATA_TYPE_PROPERTY) == 0)
  705. continue;
  706. restoreLV2State();
  707. break;
  708. }
  709. }
  710. // ---------------------------------------------------------------
  711. // Part 6 - set chunk
  712. if (stateSave.chunk != nullptr && (pData->options & PLUGIN_OPTION_USE_CHUNKS) != 0)
  713. {
  714. std::vector<uint8_t> chunk(carla_getChunkFromBase64String(stateSave.chunk));
  715. #ifdef CARLA_PROPER_CPP11_SUPPORT
  716. setChunkData(chunk.data(), chunk.size());
  717. #else
  718. setChunkData(&chunk.front(), chunk.size());
  719. #endif
  720. }
  721. #ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH
  722. // ---------------------------------------------------------------
  723. // Part 6 - set internal stuff
  724. const uint availOptions(getOptionsAvailable());
  725. for (uint i=0; i<10; ++i) // FIXME - get this value somehow...
  726. {
  727. const uint option(1u << i);
  728. if (availOptions & option)
  729. setOption(option, (stateSave.options & option) != 0, true);
  730. }
  731. setDryWet(stateSave.dryWet, true, true);
  732. setVolume(stateSave.volume, true, true);
  733. setBalanceLeft(stateSave.balanceLeft, true, true);
  734. setBalanceRight(stateSave.balanceRight, true, true);
  735. setPanning(stateSave.panning, true, true);
  736. setCtrlChannel(stateSave.ctrlChannel, true, true);
  737. setActive(stateSave.active, true, true);
  738. if (! pData->engine->isLoadingProject())
  739. pData->engine->callback(true, true, ENGINE_CALLBACK_UPDATE, pData->id, 0, 0, 0, 0.0f, nullptr);
  740. #endif
  741. }
  742. bool CarlaPlugin::saveStateToFile(const char* const filename)
  743. {
  744. CARLA_SAFE_ASSERT_RETURN(filename != nullptr && filename[0] != '\0', false);
  745. carla_debug("CarlaPlugin::saveStateToFile(\"%s\")", filename);
  746. MemoryOutputStream out, streamState;
  747. getStateSave().dumpToMemoryStream(streamState);
  748. out << "<?xml version='1.0' encoding='UTF-8'?>\n";
  749. out << "<!DOCTYPE CARLA-PRESET>\n";
  750. out << "<CARLA-PRESET VERSION='2.0'>\n";
  751. out << streamState;
  752. out << "</CARLA-PRESET>\n";
  753. const String jfilename = String(CharPointer_UTF8(filename));
  754. File file(jfilename);
  755. if (file.replaceWithData(out.getData(), out.getDataSize()))
  756. return true;
  757. pData->engine->setLastError("Failed to write file");
  758. return false;
  759. }
  760. bool CarlaPlugin::loadStateFromFile(const char* const filename)
  761. {
  762. // TODO set errors
  763. CARLA_SAFE_ASSERT_RETURN(filename != nullptr && filename[0] != '\0', false);
  764. carla_debug("CarlaPlugin::loadStateFromFile(\"%s\")", filename);
  765. const String jfilename = String(CharPointer_UTF8(filename));
  766. File file(jfilename);
  767. CARLA_SAFE_ASSERT_RETURN(file.existsAsFile(), false);
  768. XmlDocument xml(file);
  769. CarlaScopedPointer<XmlElement> xmlElement(xml.getDocumentElement(true));
  770. CARLA_SAFE_ASSERT_RETURN(xmlElement != nullptr, false);
  771. CARLA_SAFE_ASSERT_RETURN(xmlElement->getTagName().equalsIgnoreCase("carla-preset"), false);
  772. // completely load file
  773. xmlElement = xml.getDocumentElement(false);
  774. CARLA_SAFE_ASSERT_RETURN(xmlElement != nullptr, false);
  775. if (pData->stateSave.fillFromXmlElement(xmlElement))
  776. {
  777. loadStateSave(pData->stateSave);
  778. return true;
  779. }
  780. return false;
  781. }
  782. bool CarlaPlugin::exportAsLV2(const char* const lv2path)
  783. {
  784. CARLA_SAFE_ASSERT_RETURN(lv2path != nullptr && lv2path[0] != '\0', false);
  785. carla_debug("CarlaPlugin::exportAsLV2(\"%s\")", lv2path);
  786. CarlaString bundlepath(lv2path);
  787. if (! bundlepath.endsWith(".lv2"))
  788. bundlepath += ".lv2";
  789. const File bundlefolder(bundlepath.buffer());
  790. if (bundlefolder.existsAsFile())
  791. {
  792. pData->engine->setLastError("Requested filename already exists as file, use a folder instead");
  793. return false;
  794. }
  795. if (! bundlefolder.exists())
  796. {
  797. const Result res(bundlefolder.createDirectory());
  798. if (res.failed())
  799. {
  800. pData->engine->setLastError(res.getErrorMessage().toRawUTF8());
  801. return false;
  802. }
  803. }
  804. CarlaString symbol(pData->name);
  805. symbol.toBasic();
  806. {
  807. const CarlaString pluginFilename(bundlepath + CARLA_OS_SEP_STR + symbol + ".xml");
  808. if (! saveStateToFile(pluginFilename))
  809. return false;
  810. }
  811. {
  812. MemoryOutputStream manifestStream;
  813. manifestStream << "@prefix lv2: <http://lv2plug.in/ns/lv2core#> .\n";
  814. manifestStream << "@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .\n";
  815. manifestStream << "@prefix ui: <http://lv2plug.in/ns/extensions/ui#> .\n";
  816. manifestStream << "\n";
  817. manifestStream << "<" << symbol.buffer() << ".ttl>\n";
  818. manifestStream << " a lv2:Plugin ;\n";
  819. manifestStream << " lv2:binary <" << symbol.buffer() << CARLA_LIB_EXT "> ;\n";
  820. manifestStream << " rdfs:seeAlso <" << symbol.buffer() << ".ttl> .\n";
  821. manifestStream << "\n";
  822. manifestStream << "<ext-ui>\n";
  823. manifestStream << " a <http://kxstudio.sf.net/ns/lv2ext/external-ui#Widget> ;\n";
  824. manifestStream << " ui:binary <" << symbol.buffer() << CARLA_LIB_EXT "> ;\n";
  825. manifestStream << " lv2:extensionData <http://lv2plug.in/ns/extensions/ui#idleInterface> ,\n";
  826. manifestStream << " <http://lv2plug.in/ns/extensions/ui#showInterface> ;\n";
  827. manifestStream << " lv2:requiredFeature <http://lv2plug.in/ns/ext/instance-access> .\n";
  828. manifestStream << "\n";
  829. const CarlaString manifestFilename(bundlepath + CARLA_OS_SEP_STR "manifest.ttl");
  830. const File manifestFile(manifestFilename.buffer());
  831. if (! manifestFile.replaceWithData(manifestStream.getData(), manifestStream.getDataSize()))
  832. {
  833. pData->engine->setLastError("Failed to write manifest.ttl file");
  834. return false;
  835. }
  836. }
  837. {
  838. MemoryOutputStream mainStream;
  839. mainStream << "@prefix atom: <http://lv2plug.in/ns/ext/atom#> .\n";
  840. mainStream << "@prefix doap: <http://usefulinc.com/ns/doap#> .\n";
  841. mainStream << "@prefix foaf: <http://xmlns.com/foaf/0.1/> .\n";
  842. mainStream << "@prefix lv2: <http://lv2plug.in/ns/lv2core#> .\n";
  843. mainStream << "@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .\n";
  844. mainStream << "@prefix ui: <http://lv2plug.in/ns/extensions/ui#> .\n";
  845. mainStream << "\n";
  846. mainStream << "<>\n";
  847. mainStream << " a lv2:Plugin ;\n";
  848. mainStream << "\n";
  849. mainStream << " lv2:requiredFeature <http://lv2plug.in/ns/ext/buf-size#boundedBlockLength> ,\n";
  850. mainStream << " <http://lv2plug.in/ns/ext/options#options> ,\n";
  851. mainStream << " <http://lv2plug.in/ns/ext/urid#map> ;\n";
  852. mainStream << "\n";
  853. if (pData->hints & PLUGIN_HAS_CUSTOM_UI)
  854. {
  855. mainStream << " ui:ui <ext-ui> ;\n";
  856. mainStream << "\n";
  857. }
  858. const uint32_t midiIns = getMidiInCount();
  859. const uint32_t midiOuts = getMidiOutCount();
  860. int portIndex = 0;
  861. if (midiIns > 0)
  862. {
  863. mainStream << " lv2:port [\n";
  864. mainStream << " a lv2:InputPort, atom:AtomPort ;\n";
  865. mainStream << " lv2:index 0 ;\n";
  866. mainStream << " lv2:symbol \"clv2_events_in\" ;\n";
  867. mainStream << " lv2:name \"Events Input\" ;\n";
  868. mainStream << " atom:bufferType atom:Sequence ;\n";
  869. mainStream << " atom:supports <http://lv2plug.in/ns/ext/midi#MidiEvent> ,\n";
  870. mainStream << " <http://lv2plug.in/ns/ext/time#Position> ;\n";
  871. mainStream << " ] ;\n";
  872. ++portIndex;
  873. for (uint32_t i=1; i<midiIns; ++i)
  874. {
  875. const String portIndexNum(portIndex++);
  876. const String portIndexLabel(portIndex);
  877. mainStream << " lv2:port [\n";
  878. mainStream << " a lv2:InputPort, atom:AtomPort ;\n";
  879. mainStream << " lv2:index " << portIndexNum << " ;\n";
  880. mainStream << " lv2:symbol \"clv2_midi_in_" << portIndexLabel << "\" ;\n";
  881. mainStream << " lv2:name \"MIDI Input " << portIndexLabel << "\" ;\n";
  882. mainStream << " ] ;\n";
  883. }
  884. }
  885. else
  886. {
  887. mainStream << " lv2:port [\n";
  888. mainStream << " a lv2:InputPort, atom:AtomPort ;\n";
  889. mainStream << " lv2:index 0 ;\n";
  890. mainStream << " lv2:symbol \"clv2_time_info\" ;\n";
  891. mainStream << " lv2:name \"Time Info\" ;\n";
  892. mainStream << " atom:bufferType atom:Sequence ;\n";
  893. mainStream << " atom:supports <http://lv2plug.in/ns/ext/time#Position> ;\n";
  894. mainStream << " ] ;\n";
  895. ++portIndex;
  896. }
  897. for (uint32_t i=0; i<midiOuts; ++i)
  898. {
  899. const String portIndexNum(portIndex++);
  900. const String portIndexLabel(portIndex);
  901. mainStream << " lv2:port [\n";
  902. mainStream << " a lv2:InputPort, atom:AtomPort ;\n";
  903. mainStream << " lv2:index " << portIndexNum << " ;\n";
  904. mainStream << " lv2:symbol \"clv2_midi_out_" << portIndexLabel << "\" ;\n";
  905. mainStream << " lv2:name \"MIDI Output " << portIndexLabel << "\" ;\n";
  906. mainStream << " atom:bufferType atom:Sequence ;\n";
  907. mainStream << " atom:supports <http://lv2plug.in/ns/ext/midi#MidiEvent> ;\n";
  908. mainStream << " ] ;\n";
  909. }
  910. mainStream << " lv2:port [\n";
  911. mainStream << " a lv2:InputPort, lv2:ControlPort ;\n";
  912. mainStream << " lv2:index " << String(portIndex++) << " ;\n";
  913. mainStream << " lv2:name \"freewheel\" ;\n";
  914. mainStream << " lv2:symbol \"clv2_freewheel\" ;\n";
  915. mainStream << " lv2:default 0 ;\n";
  916. mainStream << " lv2:minimum 0 ;\n";
  917. mainStream << " lv2:maximum 1 ;\n";
  918. mainStream << " lv2:designation lv2:freeWheeling ;\n";
  919. mainStream << " lv2:portProperty lv2:toggled , lv2:integer ;\n";
  920. mainStream << " lv2:portProperty <http://lv2plug.in/ns/ext/port-props#notOnGUI> ;\n";
  921. mainStream << " ] ;\n";
  922. for (uint32_t i=0; i<pData->audioIn.count; ++i)
  923. {
  924. const String portIndexNum(portIndex++);
  925. const String portIndexLabel(i+1);
  926. mainStream << " lv2:port [\n";
  927. mainStream << " a lv2:InputPort, lv2:AudioPort ;\n";
  928. mainStream << " lv2:index " << portIndexNum << " ;\n";
  929. mainStream << " lv2:symbol \"clv2_audio_in_" << portIndexLabel << "\" ;\n";
  930. mainStream << " lv2:name \"Audio Input " << portIndexLabel << "\" ;\n";
  931. mainStream << " ] ;\n";
  932. }
  933. for (uint32_t i=0; i<pData->audioOut.count; ++i)
  934. {
  935. const String portIndexNum(portIndex++);
  936. const String portIndexLabel(i+1);
  937. mainStream << " lv2:port [\n";
  938. mainStream << " a lv2:OutputPort, lv2:AudioPort ;\n";
  939. mainStream << " lv2:index " << portIndexNum << " ;\n";
  940. mainStream << " lv2:symbol \"clv2_audio_out_" << portIndexLabel << "\" ;\n";
  941. mainStream << " lv2:name \"Audio Output " << portIndexLabel << "\" ;\n";
  942. mainStream << " ] ;\n";
  943. }
  944. CarlaStringList uniqueSymbolNames;
  945. char strBufName[STR_MAX+1];
  946. char strBufSymbol[STR_MAX+1];
  947. carla_zeroChars(strBufName, STR_MAX+1);
  948. carla_zeroChars(strBufSymbol, STR_MAX+1);
  949. for (uint32_t i=0; i<pData->param.count; ++i)
  950. {
  951. const ParameterData& paramData(pData->param.data[i]);
  952. const ParameterRanges& paramRanges(pData->param.ranges[i]);
  953. const String portIndexNum(portIndex++);
  954. mainStream << " lv2:port [\n";
  955. if (paramData.type == PARAMETER_INPUT)
  956. mainStream << " a lv2:InputPort, lv2:ControlPort ;\n";
  957. else
  958. mainStream << " a lv2:OutputPort, lv2:ControlPort ;\n";
  959. if (paramData.hints & PARAMETER_IS_BOOLEAN)
  960. mainStream << " lv2:portProperty lv2:toggled ;\n";
  961. if (paramData.hints & PARAMETER_IS_INTEGER)
  962. mainStream << " lv2:portProperty lv2:integer ;\n";
  963. // TODO logarithmic, enabled (not on gui), automable, samplerate, scalepoints
  964. if (! getParameterName(i, strBufName))
  965. strBufName[0] = '\0';
  966. if (! getParameterSymbol(i, strBufSymbol))
  967. strBufSymbol[0] = '\0';
  968. if (strBufSymbol[0] == '\0')
  969. {
  970. CarlaString s(strBufName);
  971. s.toBasic();
  972. std::memcpy(strBufSymbol, s.buffer(), s.length()+1);
  973. if (strBufSymbol[0] >= '0' && strBufSymbol[0] <= '9')
  974. {
  975. const size_t len(std::strlen(strBufSymbol));
  976. std::memmove(strBufSymbol+1, strBufSymbol, len);
  977. strBufSymbol[0] = '_';
  978. strBufSymbol[len+1] = '\0';
  979. }
  980. }
  981. if (uniqueSymbolNames.contains(strBufSymbol))
  982. std::snprintf(strBufSymbol, STR_MAX, "clv2_param_%d", i+1);
  983. mainStream << " lv2:index " << portIndexNum << " ;\n";
  984. mainStream << " lv2:symbol \"" << strBufSymbol << "\" ;\n";
  985. mainStream << " lv2:name \"\"\"" << strBufName << "\"\"\" ;\n";
  986. mainStream << " lv2:default " << String(paramRanges.def) << " ;\n";
  987. mainStream << " lv2:minimum " << String(paramRanges.min) << " ;\n";
  988. mainStream << " lv2:maximum " << String(paramRanges.max) << " ;\n";
  989. // TODO midiCC, midiChannel
  990. mainStream << " ] ;\n";
  991. }
  992. char strBuf[STR_MAX+1];
  993. carla_zeroChars(strBuf, STR_MAX+1);
  994. if (! getMaker(strBuf))
  995. strBuf[0] = '\0';
  996. mainStream << " rdfs:comment \"Plugin generated using Carla LV2 export.\" ;\n";
  997. mainStream << " doap:name \"\"\"" << getName() << "\"\"\" ;\n";
  998. mainStream << " doap:maintainer [ foaf:name \"\"\"" << strBuf << "\"\"\" ] .\n";
  999. mainStream << "\n";
  1000. const CarlaString mainFilename(bundlepath + CARLA_OS_SEP_STR + symbol + ".ttl");
  1001. const File mainFile(mainFilename.buffer());
  1002. if (! mainFile.replaceWithData(mainStream.getData(), mainStream.getDataSize()))
  1003. {
  1004. pData->engine->setLastError("Failed to write main plugin ttl file");
  1005. return false;
  1006. }
  1007. }
  1008. const CarlaString binaryFilename(bundlepath + CARLA_OS_SEP_STR + symbol + CARLA_LIB_EXT);
  1009. const File binaryFileSource(File::getSpecialLocation(File::currentExecutableFile).getSiblingFile("carla-bridge-lv2" CARLA_LIB_EXT));
  1010. const File binaryFileTarget(binaryFilename.buffer());
  1011. const EngineOptions& opts(pData->engine->getOptions());
  1012. const CarlaString binFolderTarget(bundlepath + CARLA_OS_SEP_STR + "bin");
  1013. const CarlaString resFolderTarget(bundlepath + CARLA_OS_SEP_STR + "res");
  1014. if (! binaryFileSource.copyFileTo(binaryFileTarget))
  1015. {
  1016. pData->engine->setLastError("Failed to copy plugin binary");
  1017. return false;
  1018. }
  1019. #ifdef CARLA_OS_WIN
  1020. File(opts.resourceDir).copyDirectoryTo(File(resFolderTarget.buffer()));
  1021. // Copying all the binaries is pointless, just go through the expected needed bits
  1022. const File binFolder1(opts.binaryDir);
  1023. const File binFolder2(binFolderTarget.buffer());
  1024. binFolder2.createDirectory();
  1025. static const char* files[] = {
  1026. "carla-bridge-native.exe",
  1027. "carla-bridge-win32.exe",
  1028. "carla-discovery-win32.exe",
  1029. "carla-discovery-win64.exe",
  1030. "libcarla_utils.dll"
  1031. };
  1032. for (int i=0; i<5; ++i)
  1033. binFolder1.getChildFile(files[i]).copyFileTo(binFolder2.getChildFile(files[i]));;
  1034. #else
  1035. File(opts.binaryDir).createSymbolicLink(File(binFolderTarget.buffer()), true);
  1036. File(opts.resourceDir).createSymbolicLink(File(resFolderTarget.buffer()), true);
  1037. #endif
  1038. return true;
  1039. }
  1040. // -------------------------------------------------------------------
  1041. // Set data (internal stuff)
  1042. void CarlaPlugin::setId(const uint newId) noexcept
  1043. {
  1044. pData->id = newId;
  1045. }
  1046. void CarlaPlugin::setName(const char* const newName)
  1047. {
  1048. CARLA_SAFE_ASSERT_RETURN(newName != nullptr && newName[0] != '\0',);
  1049. if (pData->name != nullptr)
  1050. delete[] pData->name;
  1051. pData->name = carla_strdup(newName);
  1052. }
  1053. void CarlaPlugin::setOption(const uint option, const bool yesNo, const bool sendCallback)
  1054. {
  1055. CARLA_SAFE_ASSERT_RETURN(getOptionsAvailable() & option,);
  1056. if (yesNo)
  1057. pData->options |= option;
  1058. else
  1059. pData->options &= ~option;
  1060. #ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH
  1061. if (sendCallback)
  1062. pData->engine->callback(true, true,
  1063. ENGINE_CALLBACK_OPTION_CHANGED,
  1064. pData->id,
  1065. static_cast<int>(option),
  1066. yesNo ? 1 : 0,
  1067. 0, 0.0f, nullptr);
  1068. #else
  1069. // unused
  1070. return; (void)sendCallback;
  1071. #endif
  1072. }
  1073. void CarlaPlugin::setEnabled(const bool yesNo) noexcept
  1074. {
  1075. if (pData->enabled == yesNo)
  1076. return;
  1077. pData->masterMutex.lock();
  1078. pData->enabled = yesNo;
  1079. if (yesNo && ! pData->client->isActive())
  1080. pData->client->activate();
  1081. pData->masterMutex.unlock();
  1082. }
  1083. void CarlaPlugin::setActive(const bool active, const bool sendOsc, const bool sendCallback) noexcept
  1084. {
  1085. if (pData->engineBridged) {
  1086. CARLA_SAFE_ASSERT_RETURN(!sendOsc && !sendCallback,);
  1087. } else if (pData->enginePlugin) {
  1088. // nothing here
  1089. } else {
  1090. CARLA_SAFE_ASSERT_RETURN(sendOsc || sendCallback,); // never call this from RT
  1091. }
  1092. if (pData->active == active)
  1093. return;
  1094. {
  1095. const ScopedSingleProcessLocker spl(this, true);
  1096. if (active)
  1097. activate();
  1098. else
  1099. deactivate();
  1100. }
  1101. pData->active = active;
  1102. #ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH
  1103. const float value = active ? 1.0f : 0.0f;
  1104. pData->engine->callback(sendCallback, sendOsc,
  1105. ENGINE_CALLBACK_PARAMETER_VALUE_CHANGED,
  1106. pData->id,
  1107. PARAMETER_ACTIVE,
  1108. 0, 0,
  1109. value,
  1110. nullptr);
  1111. #endif
  1112. }
  1113. #ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH
  1114. void CarlaPlugin::setDryWet(const float value, const bool sendOsc, const bool sendCallback) noexcept
  1115. {
  1116. if (pData->engineBridged) {
  1117. CARLA_SAFE_ASSERT_RETURN(!sendOsc && !sendCallback,);
  1118. } else {
  1119. CARLA_SAFE_ASSERT_RETURN(sendOsc || sendCallback,); // never call this from RT
  1120. }
  1121. CARLA_SAFE_ASSERT(value >= 0.0f && value <= 1.0f);
  1122. const float fixedValue(carla_fixedValue<float>(0.0f, 1.0f, value));
  1123. if (carla_isEqual(pData->postProc.dryWet, fixedValue))
  1124. return;
  1125. pData->postProc.dryWet = fixedValue;
  1126. pData->engine->callback(sendCallback, sendOsc,
  1127. ENGINE_CALLBACK_PARAMETER_VALUE_CHANGED,
  1128. pData->id,
  1129. PARAMETER_DRYWET,
  1130. 0, 0,
  1131. fixedValue,
  1132. nullptr);
  1133. }
  1134. void CarlaPlugin::setVolume(const float value, const bool sendOsc, const bool sendCallback) noexcept
  1135. {
  1136. if (pData->engineBridged) {
  1137. CARLA_SAFE_ASSERT_RETURN(!sendOsc && !sendCallback,);
  1138. } else {
  1139. CARLA_SAFE_ASSERT_RETURN(sendOsc || sendCallback,); // never call this from RT
  1140. }
  1141. CARLA_SAFE_ASSERT(value >= 0.0f && value <= 1.27f);
  1142. const float fixedValue(carla_fixedValue<float>(0.0f, 1.27f, value));
  1143. if (carla_isEqual(pData->postProc.volume, fixedValue))
  1144. return;
  1145. pData->postProc.volume = fixedValue;
  1146. pData->engine->callback(sendCallback, sendOsc,
  1147. ENGINE_CALLBACK_PARAMETER_VALUE_CHANGED,
  1148. pData->id,
  1149. PARAMETER_VOLUME,
  1150. 0, 0,
  1151. fixedValue,
  1152. nullptr);
  1153. }
  1154. void CarlaPlugin::setBalanceLeft(const float value, const bool sendOsc, const bool sendCallback) noexcept
  1155. {
  1156. if (pData->engineBridged) {
  1157. CARLA_SAFE_ASSERT_RETURN(!sendOsc && !sendCallback,);
  1158. } else {
  1159. CARLA_SAFE_ASSERT_RETURN(sendOsc || sendCallback,); // never call this from RT
  1160. }
  1161. CARLA_SAFE_ASSERT(value >= -1.0f && value <= 1.0f);
  1162. const float fixedValue(carla_fixedValue<float>(-1.0f, 1.0f, value));
  1163. if (carla_isEqual(pData->postProc.balanceLeft, fixedValue))
  1164. return;
  1165. pData->postProc.balanceLeft = fixedValue;
  1166. pData->engine->callback(sendCallback, sendOsc,
  1167. ENGINE_CALLBACK_PARAMETER_VALUE_CHANGED,
  1168. pData->id,
  1169. PARAMETER_BALANCE_LEFT,
  1170. 0, 0,
  1171. fixedValue,
  1172. nullptr);
  1173. }
  1174. void CarlaPlugin::setBalanceRight(const float value, const bool sendOsc, const bool sendCallback) noexcept
  1175. {
  1176. if (pData->engineBridged) {
  1177. CARLA_SAFE_ASSERT_RETURN(!sendOsc && !sendCallback,);
  1178. } else {
  1179. CARLA_SAFE_ASSERT_RETURN(sendOsc || sendCallback,); // never call this from RT
  1180. }
  1181. CARLA_SAFE_ASSERT(value >= -1.0f && value <= 1.0f);
  1182. const float fixedValue(carla_fixedValue<float>(-1.0f, 1.0f, value));
  1183. if (carla_isEqual(pData->postProc.balanceRight, fixedValue))
  1184. return;
  1185. pData->postProc.balanceRight = fixedValue;
  1186. pData->engine->callback(sendCallback, sendOsc,
  1187. ENGINE_CALLBACK_PARAMETER_VALUE_CHANGED,
  1188. pData->id,
  1189. PARAMETER_BALANCE_RIGHT,
  1190. 0, 0,
  1191. fixedValue,
  1192. nullptr);
  1193. }
  1194. void CarlaPlugin::setPanning(const float value, const bool sendOsc, const bool sendCallback) noexcept
  1195. {
  1196. if (pData->engineBridged) {
  1197. CARLA_SAFE_ASSERT_RETURN(!sendOsc && !sendCallback,);
  1198. } else {
  1199. CARLA_SAFE_ASSERT_RETURN(sendOsc || sendCallback,); // never call this from RT
  1200. }
  1201. CARLA_SAFE_ASSERT(value >= -1.0f && value <= 1.0f);
  1202. const float fixedValue(carla_fixedValue<float>(-1.0f, 1.0f, value));
  1203. if (carla_isEqual(pData->postProc.panning, fixedValue))
  1204. return;
  1205. pData->postProc.panning = fixedValue;
  1206. pData->engine->callback(sendCallback, sendOsc,
  1207. ENGINE_CALLBACK_PARAMETER_VALUE_CHANGED,
  1208. pData->id,
  1209. PARAMETER_PANNING,
  1210. 0, 0,
  1211. fixedValue,
  1212. nullptr);
  1213. }
  1214. void CarlaPlugin::setDryWetRT(const float value, const bool sendCallbackLater) noexcept
  1215. {
  1216. CARLA_SAFE_ASSERT(value >= 0.0f && value <= 1.0f);
  1217. const float fixedValue(carla_fixedValue<float>(0.0f, 1.0f, value));
  1218. if (carla_isEqual(pData->postProc.dryWet, fixedValue))
  1219. return;
  1220. pData->postProc.dryWet = fixedValue;
  1221. pData->postponeRtEvent(kPluginPostRtEventParameterChange, sendCallbackLater, PARAMETER_DRYWET, 0, 0, fixedValue);
  1222. }
  1223. void CarlaPlugin::setVolumeRT(const float value, const bool sendCallbackLater) noexcept
  1224. {
  1225. CARLA_SAFE_ASSERT(value >= 0.0f && value <= 1.27f);
  1226. const float fixedValue(carla_fixedValue<float>(0.0f, 1.27f, value));
  1227. if (carla_isEqual(pData->postProc.volume, fixedValue))
  1228. return;
  1229. pData->postProc.volume = fixedValue;
  1230. pData->postponeRtEvent(kPluginPostRtEventParameterChange, sendCallbackLater, PARAMETER_VOLUME, 0, 0, fixedValue);
  1231. }
  1232. void CarlaPlugin::setBalanceLeftRT(const float value, const bool sendCallbackLater) noexcept
  1233. {
  1234. CARLA_SAFE_ASSERT(value >= -1.0f && value <= 1.0f);
  1235. const float fixedValue(carla_fixedValue<float>(-1.0f, 1.0f, value));
  1236. if (carla_isEqual(pData->postProc.balanceLeft, fixedValue))
  1237. return;
  1238. pData->postProc.balanceLeft = fixedValue;
  1239. pData->postponeRtEvent(kPluginPostRtEventParameterChange, sendCallbackLater, PARAMETER_BALANCE_LEFT, 0, 0, fixedValue);
  1240. }
  1241. void CarlaPlugin::setBalanceRightRT(const float value, const bool sendCallbackLater) noexcept
  1242. {
  1243. CARLA_SAFE_ASSERT(value >= -1.0f && value <= 1.0f);
  1244. const float fixedValue(carla_fixedValue<float>(-1.0f, 1.0f, value));
  1245. if (carla_isEqual(pData->postProc.balanceRight, fixedValue))
  1246. return;
  1247. pData->postProc.balanceRight = fixedValue;
  1248. pData->postponeRtEvent(kPluginPostRtEventParameterChange, sendCallbackLater, PARAMETER_BALANCE_RIGHT, 0, 0, fixedValue);
  1249. }
  1250. void CarlaPlugin::setPanningRT(const float value, const bool sendCallbackLater) noexcept
  1251. {
  1252. CARLA_SAFE_ASSERT(value >= -1.0f && value <= 1.0f);
  1253. const float fixedValue(carla_fixedValue<float>(-1.0f, 1.0f, value));
  1254. if (carla_isEqual(pData->postProc.panning, fixedValue))
  1255. return;
  1256. pData->postProc.panning = fixedValue;
  1257. pData->postponeRtEvent(kPluginPostRtEventParameterChange, sendCallbackLater, PARAMETER_PANNING, 0, 0, fixedValue);
  1258. }
  1259. #endif // ! BUILD_BRIDGE_ALTERNATIVE_ARCH
  1260. void CarlaPlugin::setCtrlChannel(const int8_t channel, const bool sendOsc, const bool sendCallback) noexcept
  1261. {
  1262. if (pData->engineBridged) {
  1263. CARLA_SAFE_ASSERT_RETURN(!sendOsc && !sendCallback,);
  1264. } else {
  1265. CARLA_SAFE_ASSERT_RETURN(sendOsc || sendCallback,); // never call this from RT
  1266. }
  1267. CARLA_SAFE_ASSERT_RETURN(channel >= -1 && channel < MAX_MIDI_CHANNELS,);
  1268. if (pData->ctrlChannel == channel)
  1269. return;
  1270. pData->ctrlChannel = channel;
  1271. #ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH
  1272. const float channelf = static_cast<float>(channel);
  1273. pData->engine->callback(sendCallback, sendOsc,
  1274. ENGINE_CALLBACK_PARAMETER_VALUE_CHANGED,
  1275. pData->id,
  1276. PARAMETER_CTRL_CHANNEL,
  1277. 0, 0,
  1278. channelf, nullptr);
  1279. #endif
  1280. }
  1281. // -------------------------------------------------------------------
  1282. // Set data (plugin-specific stuff)
  1283. void CarlaPlugin::setParameterValue(const uint32_t parameterId, const float value, const bool sendGui, const bool sendOsc, const bool sendCallback) noexcept
  1284. {
  1285. if (pData->engineBridged) {
  1286. // NOTE: some LV2 plugins feedback messages to UI on purpose
  1287. CARLA_SAFE_ASSERT_RETURN(getType() == PLUGIN_LV2 || !sendGui,);
  1288. } else if (pData->enginePlugin) {
  1289. // nothing here
  1290. } else {
  1291. CARLA_SAFE_ASSERT_RETURN(sendGui || sendOsc || sendCallback,); // never call this from RT
  1292. }
  1293. CARLA_SAFE_ASSERT_RETURN(parameterId < pData->param.count,);
  1294. if (sendGui && (pData->hints & PLUGIN_HAS_CUSTOM_UI) != 0)
  1295. uiParameterChange(parameterId, value);
  1296. pData->engine->callback(sendCallback, sendOsc,
  1297. ENGINE_CALLBACK_PARAMETER_VALUE_CHANGED,
  1298. pData->id,
  1299. static_cast<int>(parameterId),
  1300. 0, 0,
  1301. value,
  1302. nullptr);
  1303. }
  1304. void CarlaPlugin::setParameterValueRT(const uint32_t parameterId, const float value, const bool sendCallbackLater) noexcept
  1305. {
  1306. pData->postponeRtEvent(kPluginPostRtEventParameterChange,
  1307. sendCallbackLater, static_cast<int32_t>(parameterId), 0, 0, value);
  1308. }
  1309. void CarlaPlugin::setParameterValueByRealIndex(const int32_t rindex, const float value, const bool sendGui, const bool sendOsc, const bool sendCallback) noexcept
  1310. {
  1311. #ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH
  1312. CARLA_SAFE_ASSERT_RETURN(rindex > PARAMETER_MAX && rindex != PARAMETER_NULL,);
  1313. switch (rindex)
  1314. {
  1315. case PARAMETER_ACTIVE:
  1316. return setActive((value > 0.0f), sendOsc, sendCallback);
  1317. case PARAMETER_CTRL_CHANNEL:
  1318. return setCtrlChannel(int8_t(value), sendOsc, sendCallback);
  1319. case PARAMETER_DRYWET:
  1320. return setDryWet(value, sendOsc, sendCallback);
  1321. case PARAMETER_VOLUME:
  1322. return setVolume(value, sendOsc, sendCallback);
  1323. case PARAMETER_BALANCE_LEFT:
  1324. return setBalanceLeft(value, sendOsc, sendCallback);
  1325. case PARAMETER_BALANCE_RIGHT:
  1326. return setBalanceRight(value, sendOsc, sendCallback);
  1327. case PARAMETER_PANNING:
  1328. return setPanning(value, sendOsc, sendCallback);
  1329. }
  1330. #endif
  1331. CARLA_SAFE_ASSERT_RETURN(rindex >= 0,);
  1332. for (uint32_t i=0; i < pData->param.count; ++i)
  1333. {
  1334. if (pData->param.data[i].rindex == rindex)
  1335. {
  1336. //if (carla_isNotEqual(getParameterValue(i), value))
  1337. setParameterValue(i, value, sendGui, sendOsc, sendCallback);
  1338. break;
  1339. }
  1340. }
  1341. }
  1342. void CarlaPlugin::setParameterMidiChannel(const uint32_t parameterId, const uint8_t channel, const bool sendOsc, const bool sendCallback) noexcept
  1343. {
  1344. if (pData->engineBridged) {
  1345. CARLA_SAFE_ASSERT_RETURN(!sendOsc && !sendCallback,);
  1346. } else {
  1347. CARLA_SAFE_ASSERT_RETURN(sendOsc || sendCallback,); // never call this from RT
  1348. }
  1349. CARLA_SAFE_ASSERT_RETURN(parameterId < pData->param.count,);
  1350. CARLA_SAFE_ASSERT_RETURN(channel < MAX_MIDI_CHANNELS,);
  1351. pData->param.data[parameterId].midiChannel = channel;
  1352. #ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH
  1353. pData->engine->callback(sendCallback, sendOsc,
  1354. ENGINE_CALLBACK_PARAMETER_MIDI_CHANNEL_CHANGED,
  1355. pData->id,
  1356. static_cast<int>(parameterId),
  1357. channel,
  1358. 0, 0.0f, nullptr);
  1359. #endif
  1360. }
  1361. void CarlaPlugin::setParameterMidiCC(const uint32_t parameterId, const int16_t cc, const bool sendOsc, const bool sendCallback) noexcept
  1362. {
  1363. if (pData->engineBridged) {
  1364. CARLA_SAFE_ASSERT_RETURN(!sendOsc && !sendCallback,);
  1365. } else {
  1366. CARLA_SAFE_ASSERT_RETURN(sendOsc || sendCallback,); // never call this from RT
  1367. }
  1368. CARLA_SAFE_ASSERT_RETURN(parameterId < pData->param.count,);
  1369. CARLA_SAFE_ASSERT_RETURN(cc >= -1 && cc < MAX_MIDI_CONTROL,);
  1370. pData->param.data[parameterId].midiCC = cc;
  1371. #ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH
  1372. pData->engine->callback(sendCallback, sendOsc,
  1373. ENGINE_CALLBACK_PARAMETER_MIDI_CC_CHANGED,
  1374. pData->id,
  1375. static_cast<int>(parameterId),
  1376. cc,
  1377. 0, 0.0f, nullptr);
  1378. #endif
  1379. }
  1380. void CarlaPlugin::setCustomData(const char* const type, const char* const key, const char* const value, const bool)
  1381. {
  1382. CARLA_SAFE_ASSERT_RETURN(type != nullptr && type[0] != '\0',);
  1383. CARLA_SAFE_ASSERT_RETURN(key != nullptr && key[0] != '\0',);
  1384. CARLA_SAFE_ASSERT_RETURN(value != nullptr,);
  1385. // Ignore some keys
  1386. if (std::strcmp(type, CUSTOM_DATA_TYPE_STRING) == 0)
  1387. {
  1388. const PluginType ptype = getType();
  1389. if ((ptype == PLUGIN_INTERNAL && std::strncmp(key, "CarlaAlternateFile", 18) == 0) ||
  1390. (ptype == PLUGIN_DSSI && std::strcmp (key, "guiVisible") == 0) ||
  1391. (ptype == PLUGIN_LV2 && std::strncmp(key, "OSC:", 4) == 0))
  1392. return;
  1393. }
  1394. // Check if we already have this key
  1395. for (LinkedList<CustomData>::Itenerator it = pData->custom.begin2(); it.valid(); it.next())
  1396. {
  1397. CustomData& customData(it.getValue(kCustomDataFallbackNC));
  1398. CARLA_SAFE_ASSERT_CONTINUE(customData.isValid());
  1399. if (std::strcmp(customData.key, key) == 0)
  1400. {
  1401. if (customData.value != nullptr)
  1402. delete[] customData.value;
  1403. customData.value = carla_strdup(value);
  1404. return;
  1405. }
  1406. }
  1407. // Otherwise store it
  1408. CustomData customData;
  1409. customData.type = carla_strdup(type);
  1410. customData.key = carla_strdup(key);
  1411. customData.value = carla_strdup(value);
  1412. pData->custom.append(customData);
  1413. }
  1414. void CarlaPlugin::setChunkData(const void* const data, const std::size_t dataSize)
  1415. {
  1416. CARLA_SAFE_ASSERT_RETURN(data != nullptr,);
  1417. CARLA_SAFE_ASSERT_RETURN(dataSize > 0,);
  1418. CARLA_SAFE_ASSERT(false); // this should never happen
  1419. }
  1420. void CarlaPlugin::setProgram(const int32_t index,
  1421. const bool sendGui, const bool sendOsc, const bool sendCallback, const bool) noexcept
  1422. {
  1423. CARLA_SAFE_ASSERT_RETURN(index >= -1 && index < static_cast<int32_t>(pData->prog.count),);
  1424. pData->prog.current = index;
  1425. pData->engine->callback(sendCallback, sendOsc,
  1426. ENGINE_CALLBACK_PROGRAM_CHANGED,
  1427. pData->id,
  1428. index,
  1429. 0, 0, 0.0f, nullptr);
  1430. // Change default parameter values
  1431. if (index >= 0)
  1432. {
  1433. if (sendGui && (pData->hints & PLUGIN_HAS_CUSTOM_UI) != 0)
  1434. uiProgramChange(static_cast<uint32_t>(index));
  1435. switch (getType())
  1436. {
  1437. case PLUGIN_SF2:
  1438. case PLUGIN_SFZ:
  1439. break;
  1440. default:
  1441. pData->updateParameterValues(this, sendCallback, sendOsc, true);
  1442. break;
  1443. }
  1444. }
  1445. }
  1446. void CarlaPlugin::setMidiProgram(const int32_t index,
  1447. const bool sendGui, const bool sendOsc, const bool sendCallback, const bool) noexcept
  1448. {
  1449. CARLA_SAFE_ASSERT_RETURN(index >= -1 && index < static_cast<int32_t>(pData->midiprog.count),);
  1450. pData->midiprog.current = index;
  1451. pData->engine->callback(sendCallback, sendOsc,
  1452. ENGINE_CALLBACK_MIDI_PROGRAM_CHANGED,
  1453. pData->id,
  1454. index,
  1455. 0, 0, 0.0f, nullptr);
  1456. // Change default parameter values
  1457. if (index >= 0)
  1458. {
  1459. if (sendGui && (pData->hints & PLUGIN_HAS_CUSTOM_UI) != 0)
  1460. uiMidiProgramChange(static_cast<uint32_t>(index));
  1461. switch (getType())
  1462. {
  1463. case PLUGIN_SF2:
  1464. case PLUGIN_SFZ:
  1465. break;
  1466. default:
  1467. pData->updateParameterValues(this, sendCallback, sendOsc, true);
  1468. break;
  1469. }
  1470. }
  1471. }
  1472. void CarlaPlugin::setMidiProgramById(const uint32_t bank, const uint32_t program, const bool sendGui, const bool sendOsc, const bool sendCallback) noexcept
  1473. {
  1474. for (uint32_t i=0; i < pData->midiprog.count; ++i)
  1475. {
  1476. if (pData->midiprog.data[i].bank == bank && pData->midiprog.data[i].program == program)
  1477. return setMidiProgram(static_cast<int32_t>(i), sendGui, sendOsc, sendCallback);
  1478. }
  1479. }
  1480. void CarlaPlugin::setProgramRT(const uint32_t uindex, const bool sendCallbackLater) noexcept
  1481. {
  1482. CARLA_SAFE_ASSERT_RETURN(uindex < pData->prog.count,);
  1483. const int32_t index = static_cast<int32_t>(uindex);
  1484. pData->prog.current = index;
  1485. // Change default parameter values
  1486. switch (getType())
  1487. {
  1488. case PLUGIN_SF2:
  1489. case PLUGIN_SFZ:
  1490. break;
  1491. default:
  1492. pData->updateDefaultParameterValues(this);
  1493. break;
  1494. }
  1495. pData->postponeRtEvent(kPluginPostRtEventProgramChange, sendCallbackLater, index, 0, 0, 0.0f);
  1496. }
  1497. void CarlaPlugin::setMidiProgramRT(const uint32_t uindex, const bool sendCallbackLater) noexcept
  1498. {
  1499. CARLA_SAFE_ASSERT_RETURN(uindex < pData->midiprog.count,);
  1500. const int32_t index = static_cast<int32_t>(uindex);
  1501. pData->midiprog.current = index;
  1502. // Change default parameter values
  1503. switch (getType())
  1504. {
  1505. case PLUGIN_SF2:
  1506. case PLUGIN_SFZ:
  1507. break;
  1508. default:
  1509. pData->updateDefaultParameterValues(this);
  1510. break;
  1511. }
  1512. pData->postponeRtEvent(kPluginPostRtEventMidiProgramChange, sendCallbackLater, index, 0, 0, 0.0f);
  1513. }
  1514. // -------------------------------------------------------------------
  1515. // Plugin state
  1516. void CarlaPlugin::reloadPrograms(const bool)
  1517. {
  1518. }
  1519. // -------------------------------------------------------------------
  1520. // Plugin processing
  1521. void CarlaPlugin::activate() noexcept
  1522. {
  1523. CARLA_SAFE_ASSERT(! pData->active);
  1524. }
  1525. void CarlaPlugin::deactivate() noexcept
  1526. {
  1527. CARLA_SAFE_ASSERT(pData->active);
  1528. }
  1529. void CarlaPlugin::bufferSizeChanged(const uint32_t)
  1530. {
  1531. }
  1532. void CarlaPlugin::sampleRateChanged(const double)
  1533. {
  1534. }
  1535. void CarlaPlugin::offlineModeChanged(const bool)
  1536. {
  1537. }
  1538. // -------------------------------------------------------------------
  1539. // Misc
  1540. void CarlaPlugin::idle()
  1541. {
  1542. if (! pData->enabled)
  1543. return;
  1544. const bool hasUI(pData->hints & PLUGIN_HAS_CUSTOM_UI);
  1545. const bool needsUiMainThread(pData->hints & PLUGIN_NEEDS_UI_MAIN_THREAD);
  1546. const uint32_t latency(getLatencyInFrames());
  1547. if (pData->latency.frames != latency)
  1548. {
  1549. carla_stdout("latency changed to %i samples", latency);
  1550. const ScopedSingleProcessLocker sspl(this, true);
  1551. pData->client->setLatency(latency);
  1552. #ifndef BUILD_BRIDGE
  1553. pData->latency.recreateBuffers(pData->latency.channels, latency);
  1554. #else
  1555. pData->latency.frames = latency;
  1556. #endif
  1557. }
  1558. const CarlaMutexLocker sl(pData->postRtEvents.getDataMutex());
  1559. for (RtLinkedList<PluginPostRtEvent>::Itenerator it = pData->postRtEvents.getDataIterator(); it.valid(); it.next())
  1560. {
  1561. const PluginPostRtEvent& event(it.getValue(kPluginPostRtEventFallback));
  1562. CARLA_SAFE_ASSERT_CONTINUE(event.type != kPluginPostRtEventNull);
  1563. switch (event.type)
  1564. {
  1565. case kPluginPostRtEventNull: {
  1566. } break;
  1567. case kPluginPostRtEventDebug: {
  1568. pData->engine->callback(true, true,
  1569. ENGINE_CALLBACK_DEBUG, pData->id,
  1570. event.value1, event.value2, event.value3, event.valuef, nullptr);
  1571. } break;
  1572. case kPluginPostRtEventParameterChange: {
  1573. // Update UI
  1574. if (event.value1 >= 0 && hasUI)
  1575. {
  1576. if (needsUiMainThread)
  1577. pData->postUiEvents.append(event);
  1578. else
  1579. uiParameterChange(static_cast<uint32_t>(event.value1), event.valuef);
  1580. }
  1581. if (event.sendCallback)
  1582. {
  1583. // Update Host
  1584. pData->engine->callback(true, true,
  1585. ENGINE_CALLBACK_PARAMETER_VALUE_CHANGED,
  1586. pData->id,
  1587. event.value1,
  1588. 0, 0,
  1589. event.valuef,
  1590. nullptr);
  1591. }
  1592. } break;
  1593. case kPluginPostRtEventProgramChange: {
  1594. // Update UI
  1595. if (event.value1 >= 0 && hasUI)
  1596. {
  1597. if (needsUiMainThread)
  1598. pData->postUiEvents.append(event);
  1599. else
  1600. uiProgramChange(static_cast<uint32_t>(event.value1));
  1601. }
  1602. // Update param values
  1603. for (uint32_t j=0; j < pData->param.count; ++j)
  1604. {
  1605. const float paramDefault(pData->param.ranges[j].def);
  1606. const float paramValue(getParameterValue(j));
  1607. pData->engine->callback(true, true,
  1608. ENGINE_CALLBACK_PARAMETER_VALUE_CHANGED,
  1609. pData->id,
  1610. static_cast<int>(j),
  1611. 0, 0,
  1612. paramValue,
  1613. nullptr);
  1614. pData->engine->callback(true, true,
  1615. ENGINE_CALLBACK_PARAMETER_DEFAULT_CHANGED,
  1616. pData->id,
  1617. static_cast<int>(j),
  1618. 0, 0,
  1619. paramDefault,
  1620. nullptr);
  1621. }
  1622. if (event.sendCallback)
  1623. {
  1624. // Update Host
  1625. pData->engine->callback(true, true,
  1626. ENGINE_CALLBACK_PROGRAM_CHANGED,
  1627. pData->id,
  1628. event.value1,
  1629. 0, 0, 0.0f, nullptr);
  1630. }
  1631. } break;
  1632. case kPluginPostRtEventMidiProgramChange: {
  1633. // Update UI
  1634. if (event.value1 >= 0 && hasUI)
  1635. {
  1636. if (needsUiMainThread)
  1637. pData->postUiEvents.append(event);
  1638. else
  1639. uiMidiProgramChange(static_cast<uint32_t>(event.value1));
  1640. }
  1641. // Update param values
  1642. for (uint32_t j=0; j < pData->param.count; ++j)
  1643. {
  1644. const float paramDefault(pData->param.ranges[j].def);
  1645. const float paramValue(getParameterValue(j));
  1646. pData->engine->callback(true, true,
  1647. ENGINE_CALLBACK_PARAMETER_VALUE_CHANGED,
  1648. pData->id,
  1649. static_cast<int>(j),
  1650. 0, 0,
  1651. paramValue,
  1652. nullptr);
  1653. pData->engine->callback(true, true,
  1654. ENGINE_CALLBACK_PARAMETER_DEFAULT_CHANGED,
  1655. pData->id,
  1656. static_cast<int>(j),
  1657. 0, 0,
  1658. paramDefault,
  1659. nullptr);
  1660. }
  1661. if (event.sendCallback)
  1662. {
  1663. // Update Host
  1664. pData->engine->callback(true, true,
  1665. ENGINE_CALLBACK_MIDI_PROGRAM_CHANGED,
  1666. pData->id,
  1667. event.value1,
  1668. 0, 0, 0.0f, nullptr);
  1669. }
  1670. } break;
  1671. case kPluginPostRtEventNoteOn: {
  1672. CARLA_SAFE_ASSERT_BREAK(event.value1 >= 0 && event.value1 < MAX_MIDI_CHANNELS);
  1673. CARLA_SAFE_ASSERT_BREAK(event.value2 >= 0 && event.value2 < MAX_MIDI_NOTE);
  1674. CARLA_SAFE_ASSERT_BREAK(event.value3 >= 0 && event.value3 < MAX_MIDI_VALUE);
  1675. const uint8_t channel = static_cast<uint8_t>(event.value1);
  1676. const uint8_t note = static_cast<uint8_t>(event.value2);
  1677. const uint8_t velocity = static_cast<uint8_t>(event.value3);
  1678. // Update UI
  1679. if (hasUI)
  1680. {
  1681. if (needsUiMainThread)
  1682. pData->postUiEvents.append(event);
  1683. else
  1684. uiNoteOn(channel, note, velocity);
  1685. }
  1686. if (event.sendCallback)
  1687. {
  1688. // Update Host
  1689. pData->engine->callback(true, true,
  1690. ENGINE_CALLBACK_NOTE_ON,
  1691. pData->id,
  1692. event.value1,
  1693. event.value2,
  1694. event.value3,
  1695. 0.0f, nullptr);
  1696. }
  1697. } break;
  1698. case kPluginPostRtEventNoteOff: {
  1699. CARLA_SAFE_ASSERT_BREAK(event.value1 >= 0 && event.value1 < MAX_MIDI_CHANNELS);
  1700. CARLA_SAFE_ASSERT_BREAK(event.value2 >= 0 && event.value2 < MAX_MIDI_NOTE);
  1701. const uint8_t channel = static_cast<uint8_t>(event.value1);
  1702. const uint8_t note = static_cast<uint8_t>(event.value2);
  1703. // Update UI
  1704. if (hasUI)
  1705. {
  1706. if (needsUiMainThread)
  1707. pData->postUiEvents.append(event);
  1708. else
  1709. uiNoteOff(channel, note);
  1710. }
  1711. if (event.sendCallback)
  1712. {
  1713. // Update Host
  1714. pData->engine->callback(true, true,
  1715. ENGINE_CALLBACK_NOTE_OFF,
  1716. pData->id,
  1717. event.value1,
  1718. event.value2,
  1719. 0, 0.0f, nullptr);
  1720. }
  1721. } break;
  1722. }
  1723. }
  1724. pData->postRtEvents.clearData();
  1725. }
  1726. bool CarlaPlugin::tryLock(const bool forcedOffline) noexcept
  1727. {
  1728. if (forcedOffline)
  1729. {
  1730. #ifndef STOAT_TEST_BUILD
  1731. pData->masterMutex.lock();
  1732. return true;
  1733. #endif
  1734. }
  1735. return pData->masterMutex.tryLock();
  1736. }
  1737. void CarlaPlugin::unlock() noexcept
  1738. {
  1739. pData->masterMutex.unlock();
  1740. }
  1741. // -------------------------------------------------------------------
  1742. // Plugin buffers
  1743. void CarlaPlugin::initBuffers() const noexcept
  1744. {
  1745. pData->audioIn.initBuffers();
  1746. pData->audioOut.initBuffers();
  1747. pData->cvIn.initBuffers();
  1748. pData->cvOut.initBuffers();
  1749. pData->event.initBuffers();
  1750. }
  1751. void CarlaPlugin::clearBuffers() noexcept
  1752. {
  1753. pData->clearBuffers();
  1754. }
  1755. // -------------------------------------------------------------------
  1756. // OSC stuff
  1757. // FIXME
  1758. void CarlaPlugin::handleOscMessage(const char* const, const int, const void* const, const char* const, const lo_message)
  1759. {
  1760. // do nothing
  1761. }
  1762. // -------------------------------------------------------------------
  1763. // MIDI events
  1764. void CarlaPlugin::sendMidiSingleNote(const uint8_t channel, const uint8_t note, const uint8_t velo, const bool sendGui, const bool sendOsc, const bool sendCallback)
  1765. {
  1766. CARLA_SAFE_ASSERT_RETURN(channel < MAX_MIDI_CHANNELS,);
  1767. CARLA_SAFE_ASSERT_RETURN(note < MAX_MIDI_NOTE,);
  1768. CARLA_SAFE_ASSERT_RETURN(velo < MAX_MIDI_VALUE,);
  1769. if (! pData->active)
  1770. return;
  1771. ExternalMidiNote extNote;
  1772. extNote.channel = static_cast<int8_t>(channel);
  1773. extNote.note = note;
  1774. extNote.velo = velo;
  1775. pData->extNotes.appendNonRT(extNote);
  1776. if (sendGui && (pData->hints & PLUGIN_HAS_CUSTOM_UI) != 0)
  1777. {
  1778. if (velo > 0)
  1779. uiNoteOn(channel, note, velo);
  1780. else
  1781. uiNoteOff(channel, note);
  1782. }
  1783. pData->engine->callback(sendCallback, sendOsc,
  1784. (velo > 0) ? ENGINE_CALLBACK_NOTE_ON : ENGINE_CALLBACK_NOTE_OFF,
  1785. pData->id,
  1786. channel,
  1787. note,
  1788. velo,
  1789. 0.0f, nullptr);
  1790. }
  1791. #ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH
  1792. void CarlaPlugin::postponeRtAllNotesOff()
  1793. {
  1794. if (pData->ctrlChannel < 0 || pData->ctrlChannel >= MAX_MIDI_CHANNELS)
  1795. return;
  1796. PluginPostRtEvent postEvent = {
  1797. kPluginPostRtEventNoteOff,
  1798. true,
  1799. pData->ctrlChannel,
  1800. 0, 0, 0.0f
  1801. };
  1802. for (int32_t i=0; i < MAX_MIDI_NOTE; ++i)
  1803. {
  1804. postEvent.value2 = i;
  1805. pData->postRtEvents.appendRT(postEvent);
  1806. }
  1807. }
  1808. #endif
  1809. // -------------------------------------------------------------------
  1810. // UI Stuff
  1811. void CarlaPlugin::showCustomUI(const bool yesNo)
  1812. {
  1813. if (yesNo) {
  1814. CARLA_SAFE_ASSERT(false);
  1815. }
  1816. }
  1817. void CarlaPlugin::uiIdle()
  1818. {
  1819. if (pData->hints & PLUGIN_NEEDS_UI_MAIN_THREAD)
  1820. {
  1821. // Update parameter outputs
  1822. for (uint32_t i=0; i < pData->param.count; ++i)
  1823. {
  1824. if (pData->param.data[i].type == PARAMETER_OUTPUT)
  1825. uiParameterChange(i, getParameterValue(i));
  1826. }
  1827. const CarlaMutexLocker sl(pData->postUiEvents.mutex);
  1828. for (LinkedList<PluginPostRtEvent>::Itenerator it = pData->postUiEvents.data.begin2(); it.valid(); it.next())
  1829. {
  1830. const PluginPostRtEvent& event(it.getValue(kPluginPostRtEventFallback));
  1831. CARLA_SAFE_ASSERT_CONTINUE(event.type != kPluginPostRtEventNull);
  1832. switch (event.type)
  1833. {
  1834. case kPluginPostRtEventNull:
  1835. case kPluginPostRtEventDebug:
  1836. break;
  1837. case kPluginPostRtEventParameterChange:
  1838. uiParameterChange(static_cast<uint32_t>(event.value1), event.valuef);
  1839. break;
  1840. case kPluginPostRtEventProgramChange:
  1841. uiProgramChange(static_cast<uint32_t>(event.value1));
  1842. break;
  1843. case kPluginPostRtEventMidiProgramChange:
  1844. uiMidiProgramChange(static_cast<uint32_t>(event.value1));
  1845. break;
  1846. case kPluginPostRtEventNoteOn:
  1847. uiNoteOn(static_cast<uint8_t>(event.value1),
  1848. static_cast<uint8_t>(event.value2),
  1849. static_cast<uint8_t>(event.value3));
  1850. break;
  1851. case kPluginPostRtEventNoteOff:
  1852. uiNoteOff(static_cast<uint8_t>(event.value1),
  1853. static_cast<uint8_t>(event.value2));
  1854. break;
  1855. }
  1856. }
  1857. pData->postUiEvents.data.clear();
  1858. }
  1859. #ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH
  1860. if (pData->transientTryCounter == 0)
  1861. return;
  1862. if (++pData->transientTryCounter % 10 != 0)
  1863. return;
  1864. if (pData->transientTryCounter >= 200)
  1865. return;
  1866. carla_stdout("Trying to get window...");
  1867. CarlaString uiTitle(pData->name);
  1868. uiTitle += " (GUI)";
  1869. if (CarlaPluginUI::tryTransientWinIdMatch(getUiBridgeProcessId(), uiTitle,
  1870. pData->engine->getOptions().frontendWinId, pData->transientFirstTry))
  1871. {
  1872. pData->transientTryCounter = 0;
  1873. pData->transientFirstTry = false;
  1874. }
  1875. #endif
  1876. }
  1877. void CarlaPlugin::uiParameterChange(const uint32_t index, const float value) noexcept
  1878. {
  1879. CARLA_SAFE_ASSERT_RETURN(index < getParameterCount(),);
  1880. return;
  1881. // unused
  1882. (void)value;
  1883. }
  1884. void CarlaPlugin::uiProgramChange(const uint32_t index) noexcept
  1885. {
  1886. CARLA_SAFE_ASSERT_RETURN(index < getProgramCount(),);
  1887. }
  1888. void CarlaPlugin::uiMidiProgramChange(const uint32_t index) noexcept
  1889. {
  1890. CARLA_SAFE_ASSERT_RETURN(index < getMidiProgramCount(),);
  1891. }
  1892. void CarlaPlugin::uiNoteOn(const uint8_t channel, const uint8_t note, const uint8_t velo) noexcept
  1893. {
  1894. CARLA_SAFE_ASSERT_RETURN(channel < MAX_MIDI_CHANNELS,);
  1895. CARLA_SAFE_ASSERT_RETURN(note < MAX_MIDI_NOTE,);
  1896. CARLA_SAFE_ASSERT_RETURN(velo > 0 && velo < MAX_MIDI_VALUE,);
  1897. }
  1898. void CarlaPlugin::uiNoteOff(const uint8_t channel, const uint8_t note) noexcept
  1899. {
  1900. CARLA_SAFE_ASSERT_RETURN(channel < MAX_MIDI_CHANNELS,);
  1901. CARLA_SAFE_ASSERT_RETURN(note < MAX_MIDI_NOTE,);
  1902. }
  1903. CarlaEngine* CarlaPlugin::getEngine() const noexcept
  1904. {
  1905. return pData->engine;
  1906. }
  1907. CarlaEngineClient* CarlaPlugin::getEngineClient() const noexcept
  1908. {
  1909. return pData->client;
  1910. }
  1911. CarlaEngineAudioPort* CarlaPlugin::getAudioInPort(const uint32_t index) const noexcept
  1912. {
  1913. return pData->audioIn.ports[index].port;
  1914. }
  1915. CarlaEngineAudioPort* CarlaPlugin::getAudioOutPort(const uint32_t index) const noexcept
  1916. {
  1917. return pData->audioOut.ports[index].port;
  1918. }
  1919. CarlaEngineCVPort* CarlaPlugin::getCVInPort(uint32_t index) const noexcept
  1920. {
  1921. if (index < pData->cvIn.count)
  1922. return pData->cvIn.ports[index].port;
  1923. CARLA_SAFE_ASSERT_RETURN(pData->event.portIn != nullptr, nullptr);
  1924. index -= pData->cvIn.count;
  1925. return pData->event.portIn->getCVSourcePort(index);
  1926. }
  1927. CarlaEngineCVPort* CarlaPlugin::getCVOutPort(const uint32_t index) const noexcept
  1928. {
  1929. return pData->cvOut.ports[index].port;
  1930. }
  1931. CarlaEngineEventPort* CarlaPlugin::getDefaultEventInPort() const noexcept
  1932. {
  1933. return pData->event.portIn;
  1934. }
  1935. CarlaEngineEventPort* CarlaPlugin::getDefaultEventOutPort() const noexcept
  1936. {
  1937. return pData->event.portOut;
  1938. }
  1939. void* CarlaPlugin::getNativeHandle() const noexcept
  1940. {
  1941. return nullptr;
  1942. }
  1943. const void* CarlaPlugin::getNativeDescriptor() const noexcept
  1944. {
  1945. return nullptr;
  1946. }
  1947. uintptr_t CarlaPlugin::getUiBridgeProcessId() const noexcept
  1948. {
  1949. return 0;
  1950. }
  1951. // -------------------------------------------------------------------
  1952. uint32_t CarlaPlugin::getPatchbayNodeId() const noexcept
  1953. {
  1954. return pData->nodeId;
  1955. }
  1956. void CarlaPlugin::setPatchbayNodeId(const uint32_t nodeId) noexcept
  1957. {
  1958. pData->nodeId = nodeId;
  1959. }
  1960. // -------------------------------------------------------------------
  1961. void CarlaPlugin::restoreLV2State() noexcept
  1962. {
  1963. carla_stderr2("Warning: restoreLV2State() called for non-implemented type");
  1964. }
  1965. void CarlaPlugin::waitForBridgeSaveSignal() noexcept
  1966. {
  1967. }
  1968. // -------------------------------------------------------------------
  1969. // Scoped Disabler
  1970. CarlaPlugin::ScopedDisabler::ScopedDisabler(CarlaPlugin* const plugin) noexcept
  1971. : fPlugin(plugin),
  1972. fWasEnabled(false)
  1973. {
  1974. CARLA_SAFE_ASSERT_RETURN(plugin != nullptr,);
  1975. CARLA_SAFE_ASSERT_RETURN(plugin->pData != nullptr,);
  1976. CARLA_SAFE_ASSERT_RETURN(plugin->pData->client != nullptr,);
  1977. carla_debug("CarlaPlugin::ScopedDisabler(%p)", plugin);
  1978. plugin->pData->masterMutex.lock();
  1979. if (plugin->pData->enabled)
  1980. {
  1981. fWasEnabled = true;
  1982. plugin->pData->enabled = false;
  1983. if (plugin->pData->client->isActive())
  1984. plugin->pData->client->deactivate();
  1985. }
  1986. }
  1987. CarlaPlugin::ScopedDisabler::~ScopedDisabler() noexcept
  1988. {
  1989. CARLA_SAFE_ASSERT_RETURN(fPlugin != nullptr,);
  1990. CARLA_SAFE_ASSERT_RETURN(fPlugin->pData != nullptr,);
  1991. CARLA_SAFE_ASSERT_RETURN(fPlugin->pData->client != nullptr,);
  1992. carla_debug("CarlaPlugin::~ScopedDisabler()");
  1993. if (fWasEnabled)
  1994. {
  1995. fPlugin->pData->enabled = true;
  1996. fPlugin->pData->client->activate();
  1997. }
  1998. fPlugin->pData->masterMutex.unlock();
  1999. }
  2000. // -------------------------------------------------------------------
  2001. // Scoped Process Locker
  2002. CarlaPlugin::ScopedSingleProcessLocker::ScopedSingleProcessLocker(CarlaPlugin* const plugin, const bool block) noexcept
  2003. : fPlugin(plugin),
  2004. fBlock(block)
  2005. {
  2006. CARLA_SAFE_ASSERT_RETURN(fPlugin != nullptr,);
  2007. CARLA_SAFE_ASSERT_RETURN(fPlugin->pData != nullptr,);
  2008. carla_debug("CarlaPlugin::ScopedSingleProcessLocker(%p, %s)", plugin, bool2str(block));
  2009. if (! fBlock)
  2010. return;
  2011. plugin->pData->singleMutex.lock();
  2012. }
  2013. CarlaPlugin::ScopedSingleProcessLocker::~ScopedSingleProcessLocker() noexcept
  2014. {
  2015. CARLA_SAFE_ASSERT_RETURN(fPlugin != nullptr,);
  2016. CARLA_SAFE_ASSERT_RETURN(fPlugin->pData != nullptr,);
  2017. carla_debug("CarlaPlugin::~ScopedSingleProcessLocker()");
  2018. if (! fBlock)
  2019. return;
  2020. #ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH
  2021. if (fPlugin->pData->singleMutex.wasTryLockCalled())
  2022. fPlugin->pData->needsReset = true;
  2023. #endif
  2024. fPlugin->pData->singleMutex.unlock();
  2025. }
  2026. // -------------------------------------------------------------------
  2027. CARLA_BACKEND_END_NAMESPACE