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.

2048 lines
63KB

  1. /*
  2. * Carla Plugin
  3. * Copyright (C) 2011-2013 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 "CarlaMIDI.h"
  21. #include <QtCore/QFile>
  22. #include <QtCore/QTextStream>
  23. #include <QtXml/QDomNode>
  24. CARLA_BACKEND_START_NAMESPACE
  25. // -------------------------------------------------------------------
  26. // Fallback data
  27. static const ParameterData kParameterDataNull = { PARAMETER_UNKNOWN, 0x0, PARAMETER_NULL, -1, -1, 0 };
  28. static const ParameterRanges kParameterRangesNull = { 0.0f, 0.0f, 1.0f, 0.01f, 0.0001f, 0.1f };
  29. static const MidiProgramData kMidiProgramDataNull = { 0, 0, nullptr };
  30. static const CustomData kCustomDataNull = { nullptr, nullptr, nullptr };
  31. static bool gIsLoadingProject = false;
  32. // -------------------------------------------------------------------
  33. // ParamSymbol struct, needed for CarlaPlugin::loadSaveState()
  34. struct ParamSymbol {
  35. uint32_t index;
  36. const char* symbol;
  37. ParamSymbol(uint32_t i, const char* s)
  38. : index(i),
  39. symbol(carla_strdup(s)) {}
  40. ~ParamSymbol()
  41. {
  42. CARLA_SAFE_ASSERT_RETURN(symbol != nullptr,)
  43. delete[] symbol;
  44. symbol = nullptr;
  45. }
  46. #ifdef CARLA_PROPER_CPP11_SUPPORT
  47. ParamSymbol() = delete;
  48. CARLA_DECLARE_NON_COPY_STRUCT(ParamSymbol)
  49. #endif
  50. };
  51. // -----------------------------------------------------------------------
  52. CarlaPlugin* CarlaPlugin::newFileGIG(const Initializer& init, const bool use16Outs)
  53. {
  54. carla_debug("CarlaPlugin::newFileGIG({%p, \"%s\", \"%s\", \"%s\"}, %s)", init.engine, init.filename, init.name, init.label, bool2str(use16Outs));
  55. #ifdef WANT_LINUXSAMPLER
  56. return newLinuxSampler(init, "GIG", use16Outs);
  57. #else
  58. init.engine->setLastError("GIG support not available");
  59. return nullptr;
  60. // unused
  61. (void)use16Outs;
  62. #endif
  63. }
  64. CarlaPlugin* CarlaPlugin::newFileSF2(const Initializer& init, const bool use16Outs)
  65. {
  66. carla_debug("CarlaPlugin::newFileSF2({%p, \"%s\", \"%s\", \"%s\"}, %s)", init.engine, init.filename, init.name, init.label, bool2str(use16Outs));
  67. #if defined(WANT_FLUIDSYNTH)
  68. return newFluidSynth(init, use16Outs);
  69. #elif defined(WANT_LINUXSAMPLER)
  70. return newLinuxSampler(init, "SF2", use16Outs);
  71. #else
  72. init.engine->setLastError("SF2 support not available");
  73. return nullptr;
  74. // unused
  75. (void)use16Outs;
  76. #endif
  77. }
  78. CarlaPlugin* CarlaPlugin::newFileSFZ(const Initializer& init)
  79. {
  80. carla_debug("CarlaPlugin::newFileSFZ({%p, \"%s\", \"%s\", \"%s\"})", init.engine, init.filename, init.name, init.label);
  81. #ifdef WANT_LINUXSAMPLER
  82. return newLinuxSampler(init, "SFZ", false);
  83. #else
  84. init.engine->setLastError("SFZ support not available");
  85. return nullptr;
  86. #endif
  87. }
  88. // -------------------------------------------------------------------
  89. // Constructor and destructor
  90. CarlaPlugin::CarlaPlugin(CarlaEngine* const engine, const unsigned int id)
  91. : pData(new CarlaPluginProtectedData(engine, id, this))
  92. {
  93. CARLA_SAFE_ASSERT_RETURN(engine != nullptr,);
  94. CARLA_ASSERT(id < engine->getMaxPluginNumber());
  95. CARLA_ASSERT(id == engine->getCurrentPluginCount());
  96. carla_debug("CarlaPlugin::CarlaPlugin(%p, %i)", engine, id);
  97. switch (engine->getProccessMode())
  98. {
  99. case ENGINE_PROCESS_MODE_SINGLE_CLIENT:
  100. case ENGINE_PROCESS_MODE_MULTIPLE_CLIENTS:
  101. CARLA_ASSERT(id < MAX_DEFAULT_PLUGINS);
  102. break;
  103. case ENGINE_PROCESS_MODE_CONTINUOUS_RACK:
  104. CARLA_ASSERT(id < MAX_RACK_PLUGINS);
  105. break;
  106. case ENGINE_PROCESS_MODE_PATCHBAY:
  107. CARLA_ASSERT(id < MAX_PATCHBAY_PLUGINS);
  108. break;
  109. case ENGINE_PROCESS_MODE_BRIDGE:
  110. CARLA_ASSERT(id == 0);
  111. break;
  112. }
  113. }
  114. CarlaPlugin::~CarlaPlugin()
  115. {
  116. carla_debug("CarlaPlugin::~CarlaPlugin()");
  117. delete pData;
  118. }
  119. // -------------------------------------------------------------------
  120. // Information (base)
  121. unsigned int CarlaPlugin::getId() const noexcept
  122. {
  123. return pData->id;
  124. }
  125. unsigned int CarlaPlugin::getHints() const noexcept
  126. {
  127. return pData->hints;
  128. }
  129. unsigned int CarlaPlugin::getOptionsEnabled() const noexcept
  130. {
  131. return pData->options;
  132. }
  133. bool CarlaPlugin::isEnabled() const noexcept
  134. {
  135. return pData->enabled;
  136. }
  137. const char* CarlaPlugin::getName() const noexcept
  138. {
  139. return pData->name;
  140. }
  141. const char* CarlaPlugin::getFilename() const noexcept
  142. {
  143. return pData->filename;
  144. }
  145. const char* CarlaPlugin::getIconName() const noexcept
  146. {
  147. return pData->iconName;
  148. }
  149. PluginCategory CarlaPlugin::getCategory() const noexcept
  150. {
  151. PluginCategory category = PLUGIN_CATEGORY_NONE;
  152. try {
  153. category = getPluginCategoryFromName(pData->name);
  154. } catch(...) {}
  155. return category;
  156. }
  157. long CarlaPlugin::getUniqueId() const noexcept
  158. {
  159. return 0;
  160. }
  161. uint32_t CarlaPlugin::getLatencyInFrames() const noexcept
  162. {
  163. return pData->latency;
  164. }
  165. // -------------------------------------------------------------------
  166. // Information (count)
  167. uint32_t CarlaPlugin::getAudioInCount() const noexcept
  168. {
  169. return pData->audioIn.count;
  170. }
  171. uint32_t CarlaPlugin::getAudioOutCount() const noexcept
  172. {
  173. return pData->audioOut.count;
  174. }
  175. uint32_t CarlaPlugin::getMidiInCount() const noexcept
  176. {
  177. return (pData->extraHints & PLUGIN_EXTRA_HINT_HAS_MIDI_IN) ? 1 : 0;
  178. }
  179. uint32_t CarlaPlugin::getMidiOutCount() const noexcept
  180. {
  181. return (pData->extraHints & PLUGIN_EXTRA_HINT_HAS_MIDI_OUT) ? 1 : 0;
  182. }
  183. uint32_t CarlaPlugin::getParameterCount() const noexcept
  184. {
  185. return pData->param.count;
  186. }
  187. uint32_t CarlaPlugin::getParameterScalePointCount(const uint32_t parameterId) const noexcept
  188. {
  189. CARLA_SAFE_ASSERT_RETURN(parameterId < pData->param.count, 0);
  190. return 0;
  191. }
  192. uint32_t CarlaPlugin::getProgramCount() const noexcept
  193. {
  194. return pData->prog.count;
  195. }
  196. uint32_t CarlaPlugin::getMidiProgramCount() const noexcept
  197. {
  198. return pData->midiprog.count;
  199. }
  200. uint32_t CarlaPlugin::getCustomDataCount() const noexcept
  201. {
  202. return static_cast<uint32_t>(pData->custom.count());
  203. }
  204. // -------------------------------------------------------------------
  205. // Information (current data)
  206. int32_t CarlaPlugin::getCurrentProgram() const noexcept
  207. {
  208. return pData->prog.current;
  209. }
  210. int32_t CarlaPlugin::getCurrentMidiProgram() const noexcept
  211. {
  212. return pData->midiprog.current;
  213. }
  214. const ParameterData& CarlaPlugin::getParameterData(const uint32_t parameterId) const noexcept
  215. {
  216. CARLA_SAFE_ASSERT_RETURN(parameterId < pData->param.count, kParameterDataNull);
  217. return pData->param.data[parameterId];
  218. }
  219. const ParameterRanges& CarlaPlugin::getParameterRanges(const uint32_t parameterId) const noexcept
  220. {
  221. CARLA_SAFE_ASSERT_RETURN(parameterId < pData->param.count, kParameterRangesNull);
  222. return pData->param.ranges[parameterId];
  223. }
  224. bool CarlaPlugin::isParameterOutput(const uint32_t parameterId) const noexcept
  225. {
  226. CARLA_SAFE_ASSERT_RETURN(parameterId < pData->param.count, false);
  227. return (pData->param.data[parameterId].type == PARAMETER_OUTPUT);
  228. }
  229. const MidiProgramData& CarlaPlugin::getMidiProgramData(const uint32_t index) const noexcept
  230. {
  231. CARLA_SAFE_ASSERT_RETURN(index < pData->midiprog.count, kMidiProgramDataNull);
  232. return pData->midiprog.data[index];
  233. }
  234. const CustomData& CarlaPlugin::getCustomData(const uint32_t index) const noexcept
  235. {
  236. CARLA_SAFE_ASSERT_RETURN(index < pData->custom.count(), kCustomDataNull);
  237. return pData->custom.getAt(index);
  238. }
  239. int32_t CarlaPlugin::getChunkData(void** const dataPtr) const noexcept
  240. {
  241. CARLA_SAFE_ASSERT_RETURN(dataPtr != nullptr, 0);
  242. CARLA_ASSERT(false); // this should never happen
  243. return 0;
  244. }
  245. // -------------------------------------------------------------------
  246. // Information (per-plugin data)
  247. unsigned int CarlaPlugin::getOptionsAvailable() const noexcept
  248. {
  249. CARLA_ASSERT(false); // this should never happen
  250. return 0x0;
  251. }
  252. float CarlaPlugin::getParameterValue(const uint32_t parameterId) const noexcept
  253. {
  254. CARLA_SAFE_ASSERT_RETURN(parameterId < getParameterCount(), 0.0f);
  255. CARLA_ASSERT(false); // this should never happen
  256. return 0.0f;
  257. }
  258. float CarlaPlugin::getParameterScalePointValue(const uint32_t parameterId, const uint32_t scalePointId) const noexcept
  259. {
  260. CARLA_SAFE_ASSERT_RETURN(parameterId < getParameterCount(), 0.0f);
  261. CARLA_SAFE_ASSERT_RETURN(scalePointId < getParameterScalePointCount(parameterId), 0.0f);
  262. CARLA_ASSERT(false); // this should never happen
  263. return 0.0f;
  264. }
  265. void CarlaPlugin::getLabel(char* const strBuf) const noexcept
  266. {
  267. strBuf[0] = '\0';
  268. }
  269. void CarlaPlugin::getMaker(char* const strBuf) const noexcept
  270. {
  271. strBuf[0] = '\0';
  272. }
  273. void CarlaPlugin::getCopyright(char* const strBuf) const noexcept
  274. {
  275. strBuf[0] = '\0';
  276. }
  277. void CarlaPlugin::getRealName(char* const strBuf) const noexcept
  278. {
  279. strBuf[0] = '\0';
  280. }
  281. void CarlaPlugin::getParameterName(const uint32_t parameterId, char* const strBuf) const noexcept
  282. {
  283. CARLA_SAFE_ASSERT_RETURN(parameterId < getParameterCount(),);
  284. CARLA_ASSERT(false); // this should never happen
  285. strBuf[0] = '\0';
  286. }
  287. void CarlaPlugin::getParameterSymbol(const uint32_t parameterId, char* const strBuf) const noexcept
  288. {
  289. CARLA_SAFE_ASSERT_RETURN(parameterId < getParameterCount(),);
  290. strBuf[0] = '\0';
  291. }
  292. void CarlaPlugin::getParameterText(const uint32_t parameterId, const float, char* const strBuf) const noexcept
  293. {
  294. CARLA_SAFE_ASSERT_RETURN(parameterId < getParameterCount(),);
  295. CARLA_ASSERT(false); // this should never happen
  296. strBuf[0] = '\0';
  297. }
  298. void CarlaPlugin::getParameterUnit(const uint32_t parameterId, char* const strBuf) const noexcept
  299. {
  300. CARLA_SAFE_ASSERT_RETURN(parameterId < getParameterCount(),);
  301. strBuf[0] = '\0';
  302. }
  303. void CarlaPlugin::getParameterScalePointLabel(const uint32_t parameterId, const uint32_t scalePointId, char* const strBuf) const noexcept
  304. {
  305. CARLA_SAFE_ASSERT_RETURN(parameterId < getParameterCount(),);
  306. CARLA_SAFE_ASSERT_RETURN(scalePointId < getParameterScalePointCount(parameterId),);
  307. CARLA_ASSERT(false); // this should never happen
  308. strBuf[0] = '\0';
  309. }
  310. void CarlaPlugin::getProgramName(const uint32_t index, char* const strBuf) const noexcept
  311. {
  312. CARLA_SAFE_ASSERT_RETURN(index < pData->prog.count,);
  313. CARLA_SAFE_ASSERT_RETURN(pData->prog.names[index] != nullptr,);
  314. std::strncpy(strBuf, pData->prog.names[index], STR_MAX);
  315. }
  316. void CarlaPlugin::getMidiProgramName(const uint32_t index, char* const strBuf) const noexcept
  317. {
  318. CARLA_SAFE_ASSERT_RETURN(index < pData->midiprog.count,);
  319. CARLA_SAFE_ASSERT_RETURN(pData->midiprog.data[index].name != nullptr,);
  320. std::strncpy(strBuf, pData->midiprog.data[index].name, STR_MAX);
  321. }
  322. void CarlaPlugin::getParameterCountInfo(uint32_t& ins, uint32_t& outs) const noexcept
  323. {
  324. ins = 0;
  325. outs = 0;
  326. for (uint32_t i=0; i < pData->param.count; ++i)
  327. {
  328. if (pData->param.data[i].type == PARAMETER_INPUT)
  329. ++ins;
  330. else if (pData->param.data[i].type == PARAMETER_OUTPUT)
  331. ++outs;
  332. }
  333. }
  334. // -------------------------------------------------------------------
  335. // Set data (state)
  336. void CarlaPlugin::prepareForSave()
  337. {
  338. }
  339. const SaveState& CarlaPlugin::getSaveState()
  340. {
  341. pData->saveState.reset();
  342. prepareForSave();
  343. char strBuf[STR_MAX+1];
  344. // ---------------------------------------------------------------
  345. // Basic info
  346. getLabel(strBuf);
  347. pData->saveState.type = carla_strdup(getPluginTypeAsString(getType()));
  348. pData->saveState.name = carla_strdup(pData->name);
  349. pData->saveState.label = carla_strdup(strBuf);
  350. pData->saveState.binary = carla_strdup(pData->filename);
  351. pData->saveState.uniqueID = getUniqueId();
  352. // ---------------------------------------------------------------
  353. // Internals
  354. pData->saveState.active = pData->active;
  355. #ifndef BUILD_BRIDGE
  356. pData->saveState.dryWet = pData->postProc.dryWet;
  357. pData->saveState.volume = pData->postProc.volume;
  358. pData->saveState.balanceLeft = pData->postProc.balanceLeft;
  359. pData->saveState.balanceRight = pData->postProc.balanceRight;
  360. pData->saveState.panning = pData->postProc.panning;
  361. pData->saveState.ctrlChannel = pData->ctrlChannel;
  362. #endif
  363. // ---------------------------------------------------------------
  364. // Chunk
  365. if (pData->options & PLUGIN_OPTION_USE_CHUNKS)
  366. {
  367. void* data = nullptr;
  368. const int32_t dataSize(getChunkData(&data));
  369. if (data != nullptr && dataSize > 0)
  370. {
  371. pData->saveState.chunk = carla_strdup(QByteArray((char*)data, dataSize).toBase64().constData());
  372. // Don't save anything else if using chunks
  373. return pData->saveState;
  374. }
  375. }
  376. // ---------------------------------------------------------------
  377. // Current Program
  378. if (pData->prog.current >= 0 && getType() != PLUGIN_LV2)
  379. {
  380. pData->saveState.currentProgramIndex = pData->prog.current;
  381. pData->saveState.currentProgramName = carla_strdup(pData->prog.names[pData->prog.current]);
  382. }
  383. // ---------------------------------------------------------------
  384. // Current MIDI Program
  385. if (pData->midiprog.current >= 0 && getType() != PLUGIN_LV2)
  386. {
  387. const MidiProgramData& mpData(pData->midiprog.getCurrent());
  388. pData->saveState.currentMidiBank = mpData.bank;
  389. pData->saveState.currentMidiProgram = mpData.program;
  390. }
  391. // ---------------------------------------------------------------
  392. // Parameters
  393. const float sampleRate(static_cast<float>(pData->engine->getSampleRate()));
  394. for (uint32_t i=0; i < pData->param.count; ++i)
  395. {
  396. const ParameterData& paramData(pData->param.data[i]);
  397. if (paramData.type != PARAMETER_INPUT || (paramData.hints & PARAMETER_IS_ENABLED) == 0)
  398. continue;
  399. StateParameter* stateParameter(new StateParameter());
  400. stateParameter->index = paramData.index;
  401. stateParameter->midiCC = paramData.midiCC;
  402. stateParameter->midiChannel = paramData.midiChannel;
  403. getParameterName(i, strBuf);
  404. stateParameter->name = carla_strdup(strBuf);
  405. getParameterSymbol(i, strBuf);
  406. stateParameter->symbol = carla_strdup(strBuf);;
  407. stateParameter->value = getParameterValue(i);
  408. if (paramData.hints & PARAMETER_USES_SAMPLERATE)
  409. stateParameter->value /= sampleRate;
  410. pData->saveState.parameters.append(stateParameter);
  411. }
  412. // ---------------------------------------------------------------
  413. // Custom Data
  414. for (LinkedList<CustomData>::Itenerator it = pData->custom.begin(); it.valid(); it.next())
  415. {
  416. const CustomData& cData(it.getValue());
  417. StateCustomData* stateCustomData(new StateCustomData());
  418. stateCustomData->type = carla_strdup(cData.type);
  419. stateCustomData->key = carla_strdup(cData.key);
  420. stateCustomData->value = carla_strdup(cData.value);
  421. pData->saveState.customData.append(stateCustomData);
  422. }
  423. return pData->saveState;
  424. }
  425. void CarlaPlugin::loadSaveState(const SaveState& saveState)
  426. {
  427. char strBuf[STR_MAX+1];
  428. const bool usesMultiProgs(getType() == PLUGIN_FILE_GIG || getType() == PLUGIN_FILE_SF2 || (getType() == PLUGIN_INTERNAL && getCategory() == PLUGIN_CATEGORY_SYNTH));
  429. gIsLoadingProject = true;
  430. ScopedValueSetter<bool>(gIsLoadingProject, false);
  431. // ---------------------------------------------------------------
  432. // Part 1 - PRE-set custom data (only that which reload programs)
  433. for (LinkedList<StateCustomData*>::Itenerator it = saveState.customData.begin(); it.valid(); it.next())
  434. {
  435. const StateCustomData* const stateCustomData(it.getValue());
  436. const char* const key(stateCustomData->key);
  437. bool wantData = false;
  438. if (getType() == PLUGIN_DSSI && (std::strcmp(key, "reloadprograms") == 0 || std::strcmp(key, "load") == 0 || std::strncmp(key, "patches", 7) == 0))
  439. wantData = true;
  440. else if (usesMultiProgs && std::strcmp(key, "midiPrograms") == 0)
  441. wantData = true;
  442. if (wantData)
  443. setCustomData(stateCustomData->type, stateCustomData->key, stateCustomData->value, true);
  444. }
  445. // ---------------------------------------------------------------
  446. // Part 2 - set program
  447. if (saveState.currentProgramIndex >= 0 && saveState.currentProgramName != nullptr)
  448. {
  449. int32_t programId = -1;
  450. // index < count
  451. if (saveState.currentProgramIndex < static_cast<int32_t>(pData->prog.count))
  452. {
  453. programId = saveState.currentProgramIndex;
  454. }
  455. // index not valid, try to find by name
  456. else
  457. {
  458. for (uint32_t i=0; i < pData->prog.count; ++i)
  459. {
  460. strBuf[0] = '\0';
  461. getProgramName(i, strBuf);
  462. if (strBuf[0] != '\0' && std::strcmp(saveState.currentProgramName, strBuf) == 0)
  463. {
  464. programId = i;
  465. break;
  466. }
  467. }
  468. }
  469. // set program now, if valid
  470. if (programId >= 0)
  471. setProgram(programId, true, true, true);
  472. }
  473. // ---------------------------------------------------------------
  474. // Part 3 - set midi program
  475. if (saveState.currentMidiBank >= 0 && saveState.currentMidiProgram >= 0 && ! usesMultiProgs)
  476. setMidiProgramById(saveState.currentMidiBank, saveState.currentMidiProgram, true, true, true);
  477. // ---------------------------------------------------------------
  478. // Part 4a - get plugin parameter symbols
  479. LinkedList<ParamSymbol*> paramSymbols;
  480. if (getType() == PLUGIN_LADSPA || getType() == PLUGIN_LV2)
  481. {
  482. for (uint32_t i=0; i < pData->param.count; ++i)
  483. {
  484. strBuf[0] = '\0';
  485. getParameterSymbol(i, strBuf);
  486. if (strBuf[0] != '\0')
  487. {
  488. ParamSymbol* const paramSymbol(new ParamSymbol(i, strBuf));
  489. paramSymbols.append(paramSymbol);
  490. }
  491. }
  492. }
  493. // ---------------------------------------------------------------
  494. // Part 4b - set parameter values (carefully)
  495. const float sampleRate(static_cast<float>(pData->engine->getSampleRate()));
  496. for (LinkedList<StateParameter*>::Itenerator it = saveState.parameters.begin(); it.valid(); it.next())
  497. {
  498. StateParameter* const stateParameter(it.getValue());
  499. int32_t index = -1;
  500. if (getType() == PLUGIN_LADSPA)
  501. {
  502. // Try to set by symbol, otherwise use index
  503. if (stateParameter->symbol != nullptr && stateParameter->symbol[0] != '\0')
  504. {
  505. for (LinkedList<ParamSymbol*>::Itenerator it = paramSymbols.begin(); it.valid(); it.next())
  506. {
  507. ParamSymbol* const paramSymbol(it.getValue());
  508. if (std::strcmp(stateParameter->symbol, paramSymbol->symbol) == 0)
  509. {
  510. index = paramSymbol->index;
  511. break;
  512. }
  513. }
  514. if (index == -1)
  515. index = stateParameter->index;
  516. }
  517. else
  518. index = stateParameter->index;
  519. }
  520. else if (getType() == PLUGIN_LV2)
  521. {
  522. // Symbol only
  523. if (stateParameter->symbol != nullptr && stateParameter->symbol[0] != '\0')
  524. {
  525. for (LinkedList<ParamSymbol*>::Itenerator it = paramSymbols.begin(); it.valid(); it.next())
  526. {
  527. ParamSymbol* const paramSymbol(it.getValue());
  528. if (std::strcmp(stateParameter->symbol, paramSymbol->symbol) == 0)
  529. {
  530. index = paramSymbol->index;
  531. break;
  532. }
  533. }
  534. if (index == -1)
  535. carla_stderr("Failed to find LV2 parameter symbol '%s')", stateParameter->symbol);
  536. }
  537. else
  538. carla_stderr("LV2 Plugin parameter '%s' has no symbol", stateParameter->name);
  539. }
  540. else
  541. {
  542. // Index only
  543. index = stateParameter->index;
  544. }
  545. // Now set parameter
  546. if (index >= 0 && index < static_cast<int32_t>(pData->param.count))
  547. {
  548. if (pData->param.data[index].hints & PARAMETER_USES_SAMPLERATE)
  549. stateParameter->value *= sampleRate;
  550. setParameterValue(index, stateParameter->value, true, true, true);
  551. #ifndef BUILD_BRIDGE
  552. setParameterMidiCC(index, stateParameter->midiCC, true, true);
  553. setParameterMidiChannel(index, stateParameter->midiChannel, true, true);
  554. #endif
  555. }
  556. else
  557. carla_stderr("Could not set parameter data for '%s'", stateParameter->name);
  558. }
  559. // ---------------------------------------------------------------
  560. // Part 4c - clear
  561. for (LinkedList<ParamSymbol*>::Itenerator it = paramSymbols.begin(); it.valid(); it.next())
  562. {
  563. ParamSymbol* const paramSymbol(it.getValue());
  564. delete paramSymbol;
  565. }
  566. paramSymbols.clear();
  567. // ---------------------------------------------------------------
  568. // Part 5 - set custom data
  569. for (LinkedList<StateCustomData*>::Itenerator it = saveState.customData.begin(); it.valid(); it.next())
  570. {
  571. const StateCustomData* const stateCustomData(it.getValue());
  572. const char* const key(stateCustomData->key);
  573. if (getType() == PLUGIN_DSSI && (std::strcmp(key, "reloadprograms") == 0 || std::strcmp(key, "load") == 0 || std::strncmp(key, "patches", 7) == 0))
  574. continue;
  575. if (usesMultiProgs && std::strcmp(key, "midiPrograms") == 0)
  576. continue;
  577. setCustomData(stateCustomData->type, stateCustomData->key, stateCustomData->value, true);
  578. }
  579. // ---------------------------------------------------------------
  580. // Part 6 - set chunk
  581. if (saveState.chunk != nullptr && (pData->options & PLUGIN_OPTION_USE_CHUNKS) != 0)
  582. setChunkData(saveState.chunk);
  583. // ---------------------------------------------------------------
  584. // Part 6 - set internal stuff
  585. #ifndef BUILD_BRIDGE
  586. setDryWet(saveState.dryWet, true, true);
  587. setVolume(saveState.volume, true, true);
  588. setBalanceLeft(saveState.balanceLeft, true, true);
  589. setBalanceRight(saveState.balanceRight, true, true);
  590. setPanning(saveState.panning, true, true);
  591. setCtrlChannel(saveState.ctrlChannel, true, true);
  592. #endif
  593. setActive(saveState.active, true, true);
  594. }
  595. bool CarlaPlugin::saveStateToFile(const char* const filename)
  596. {
  597. CARLA_SAFE_ASSERT_RETURN(filename != nullptr && filename[0] != '\0', false);
  598. carla_debug("CarlaPlugin::saveStateToFile(\"%s\")", filename);
  599. QFile file(filename);
  600. if (! file.open(QIODevice::WriteOnly | QIODevice::Text))
  601. return false;
  602. QString content;
  603. fillXmlStringFromSaveState(content, getSaveState());
  604. QTextStream out(&file);
  605. out << "<?xml version='1.0' encoding='UTF-8'?>\n";
  606. out << "<!DOCTYPE CARLA-PRESET>\n";
  607. out << "<CARLA-PRESET VERSION='2.0'>\n";
  608. out << content;
  609. out << "</CARLA-PRESET>\n";
  610. file.close();
  611. return true;
  612. }
  613. bool CarlaPlugin::loadStateFromFile(const char* const filename)
  614. {
  615. CARLA_SAFE_ASSERT_RETURN(filename != nullptr && filename[0] != '\0', false);
  616. carla_debug("CarlaPlugin::loadStateFromFile(\"%s\")", filename);
  617. QFile file(filename);
  618. if (! file.open(QIODevice::ReadOnly | QIODevice::Text))
  619. return false;
  620. QDomDocument xml;
  621. xml.setContent(file.readAll());
  622. file.close();
  623. QDomNode xmlNode(xml.documentElement());
  624. if (xmlNode.toElement().tagName().compare("carla-preset", Qt::CaseInsensitive) == 0)
  625. {
  626. pData->engine->setLastError("Not a valid Carla preset file");
  627. return false;
  628. }
  629. pData->saveState.reset();
  630. fillSaveStateFromXmlNode(pData->saveState, xmlNode);
  631. loadSaveState(pData->saveState);
  632. return true;
  633. }
  634. // -------------------------------------------------------------------
  635. // Set data (internal stuff)
  636. void CarlaPlugin::setId(const unsigned int newId) noexcept
  637. {
  638. pData->id = newId;
  639. }
  640. void CarlaPlugin::setName(const char* const newName)
  641. {
  642. CARLA_ASSERT(newName != nullptr && newName[0] != '\0');
  643. if (pData->name != nullptr)
  644. delete[] pData->name;
  645. pData->name = carla_strdup(newName);
  646. }
  647. void CarlaPlugin::setOption(const unsigned int option, const bool yesNo)
  648. {
  649. CARLA_ASSERT(getOptionsAvailable() & option);
  650. if (yesNo)
  651. pData->options |= option;
  652. else
  653. pData->options &= ~option;
  654. pData->saveSetting(option, yesNo);
  655. }
  656. void CarlaPlugin::setEnabled(const bool yesNo) noexcept
  657. {
  658. if (pData->enabled == yesNo)
  659. return;
  660. pData->enabled = yesNo;
  661. pData->masterMutex.lock();
  662. pData->masterMutex.unlock();
  663. }
  664. // -------------------------------------------------------------------
  665. // Set data (internal stuff)
  666. void CarlaPlugin::setActive(const bool active, const bool sendOsc, const bool sendCallback) noexcept
  667. {
  668. #ifndef BUILD_BRIDGE
  669. CARLA_ASSERT(sendOsc || sendCallback); // never call this from RT
  670. #endif
  671. if (pData->active == active)
  672. return;
  673. {
  674. const ScopedSingleProcessLocker spl(this, true);
  675. if (active)
  676. activate();
  677. else
  678. deactivate();
  679. }
  680. pData->active = active;
  681. #ifndef BUILD_BRIDGE
  682. const float value(active ? 1.0f : 0.0f);
  683. if (sendOsc && pData->engine->isOscControlRegistered())
  684. pData->engine->oscSend_control_set_parameter_value(pData->id, PARAMETER_ACTIVE, value);
  685. if (sendCallback)
  686. pData->engine->callback(ENGINE_CALLBACK_PARAMETER_VALUE_CHANGED, pData->id, PARAMETER_ACTIVE, 0, value, nullptr);
  687. #else
  688. return;
  689. // unused
  690. (void)sendOsc;
  691. (void)sendCallback;
  692. #endif
  693. }
  694. #ifndef BUILD_BRIDGE
  695. void CarlaPlugin::setDryWet(const float value, const bool sendOsc, const bool sendCallback) noexcept
  696. {
  697. CARLA_ASSERT(value >= 0.0f && value <= 1.0f);
  698. const float fixedValue(carla_fixValue<float>(0.0f, 1.0f, value));
  699. if (pData->postProc.dryWet == fixedValue)
  700. return;
  701. pData->postProc.dryWet = fixedValue;
  702. if (sendOsc && pData->engine->isOscControlRegistered())
  703. pData->engine->oscSend_control_set_parameter_value(pData->id, PARAMETER_DRYWET, fixedValue);
  704. if (sendCallback)
  705. pData->engine->callback(ENGINE_CALLBACK_PARAMETER_VALUE_CHANGED, pData->id, PARAMETER_DRYWET, 0, fixedValue, nullptr);
  706. }
  707. void CarlaPlugin::setVolume(const float value, const bool sendOsc, const bool sendCallback) noexcept
  708. {
  709. CARLA_ASSERT(value >= 0.0f && value <= 1.27f);
  710. const float fixedValue(carla_fixValue<float>(0.0f, 1.27f, value));
  711. if (pData->postProc.volume == fixedValue)
  712. return;
  713. pData->postProc.volume = fixedValue;
  714. if (sendOsc && pData->engine->isOscControlRegistered())
  715. pData->engine->oscSend_control_set_parameter_value(pData->id, PARAMETER_VOLUME, fixedValue);
  716. if (sendCallback)
  717. pData->engine->callback(ENGINE_CALLBACK_PARAMETER_VALUE_CHANGED, pData->id, PARAMETER_VOLUME, 0, fixedValue, nullptr);
  718. }
  719. void CarlaPlugin::setBalanceLeft(const float value, const bool sendOsc, const bool sendCallback) noexcept
  720. {
  721. CARLA_ASSERT(value >= -1.0f && value <= 1.0f);
  722. const float fixedValue(carla_fixValue<float>(-1.0f, 1.0f, value));
  723. if (pData->postProc.balanceLeft == fixedValue)
  724. return;
  725. pData->postProc.balanceLeft = fixedValue;
  726. if (sendOsc && pData->engine->isOscControlRegistered())
  727. pData->engine->oscSend_control_set_parameter_value(pData->id, PARAMETER_BALANCE_LEFT, fixedValue);
  728. if (sendCallback)
  729. pData->engine->callback(ENGINE_CALLBACK_PARAMETER_VALUE_CHANGED, pData->id, PARAMETER_BALANCE_LEFT, 0, fixedValue, nullptr);
  730. }
  731. void CarlaPlugin::setBalanceRight(const float value, const bool sendOsc, const bool sendCallback) noexcept
  732. {
  733. CARLA_ASSERT(value >= -1.0f && value <= 1.0f);
  734. const float fixedValue(carla_fixValue<float>(-1.0f, 1.0f, value));
  735. if (pData->postProc.balanceRight == fixedValue)
  736. return;
  737. pData->postProc.balanceRight = fixedValue;
  738. if (sendOsc && pData->engine->isOscControlRegistered())
  739. pData->engine->oscSend_control_set_parameter_value(pData->id, PARAMETER_BALANCE_RIGHT, fixedValue);
  740. if (sendCallback)
  741. pData->engine->callback(ENGINE_CALLBACK_PARAMETER_VALUE_CHANGED, pData->id, PARAMETER_BALANCE_RIGHT, 0, fixedValue, nullptr);
  742. }
  743. void CarlaPlugin::setPanning(const float value, const bool sendOsc, const bool sendCallback) noexcept
  744. {
  745. CARLA_ASSERT(value >= -1.0f && value <= 1.0f);
  746. const float fixedValue(carla_fixValue<float>(-1.0f, 1.0f, value));
  747. if (pData->postProc.panning == fixedValue)
  748. return;
  749. pData->postProc.panning = fixedValue;
  750. if (sendOsc && pData->engine->isOscControlRegistered())
  751. pData->engine->oscSend_control_set_parameter_value(pData->id, PARAMETER_PANNING, fixedValue);
  752. if (sendCallback)
  753. pData->engine->callback(ENGINE_CALLBACK_PARAMETER_VALUE_CHANGED, pData->id, PARAMETER_PANNING, 0, fixedValue, nullptr);
  754. }
  755. #endif
  756. void CarlaPlugin::setCtrlChannel(const int8_t channel, const bool sendOsc, const bool sendCallback) noexcept
  757. {
  758. #ifndef BUILD_BRIDGE
  759. CARLA_ASSERT(sendOsc || sendCallback); // never call this from RT
  760. #endif
  761. CARLA_ASSERT_INT(channel >= -1 && channel < MAX_MIDI_CHANNELS, channel);
  762. if (pData->ctrlChannel == channel)
  763. return;
  764. pData->ctrlChannel = channel;
  765. #ifndef BUILD_BRIDGE
  766. const float ctrlf(channel);
  767. if (sendOsc && pData->engine->isOscControlRegistered())
  768. pData->engine->oscSend_control_set_parameter_value(pData->id, PARAMETER_CTRL_CHANNEL, ctrlf);
  769. if (sendCallback)
  770. pData->engine->callback(ENGINE_CALLBACK_PARAMETER_VALUE_CHANGED, pData->id, PARAMETER_CTRL_CHANNEL, 0, ctrlf, nullptr);
  771. if (pData->hints & PLUGIN_IS_BRIDGE)
  772. osc_send_control(pData->osc.data, PARAMETER_CTRL_CHANNEL, ctrlf);
  773. #else
  774. return;
  775. // unused
  776. (void)sendOsc;
  777. (void)sendCallback;
  778. #endif
  779. }
  780. // -------------------------------------------------------------------
  781. // Set data (plugin-specific stuff)
  782. void CarlaPlugin::setParameterValue(const uint32_t parameterId, const float value, const bool sendGui, const bool sendOsc, const bool sendCallback) noexcept
  783. {
  784. CARLA_ASSERT(parameterId < pData->param.count);
  785. #ifdef BUILD_BRIDGE
  786. if (! gIsLoadingProject)
  787. {
  788. CARLA_ASSERT(! sendGui); // this should never happen
  789. }
  790. #endif
  791. #ifndef BUILD_BRIDGE
  792. if (sendGui)
  793. uiParameterChange(parameterId, value);
  794. if (sendOsc && pData->engine->isOscControlRegistered())
  795. pData->engine->oscSend_control_set_parameter_value(pData->id, parameterId, value);
  796. #endif
  797. if (sendCallback)
  798. pData->engine->callback(ENGINE_CALLBACK_PARAMETER_VALUE_CHANGED, pData->id, parameterId, 0, value, nullptr);
  799. #ifdef BUILD_BRIDGE
  800. return;
  801. // unused
  802. (void)sendGui;
  803. (void)sendOsc;
  804. #endif
  805. }
  806. void CarlaPlugin::setParameterValueByRealIndex(const int32_t rindex, const float value, const bool sendGui, const bool sendOsc, const bool sendCallback) noexcept
  807. {
  808. CARLA_ASSERT(rindex > PARAMETER_MAX && rindex != PARAMETER_NULL);
  809. if (rindex <= PARAMETER_MAX)
  810. return;
  811. if (rindex == PARAMETER_NULL)
  812. return;
  813. if (rindex == PARAMETER_ACTIVE)
  814. return setActive((value > 0.0f), sendOsc, sendCallback);
  815. if (rindex == PARAMETER_CTRL_CHANNEL)
  816. return setCtrlChannel(int8_t(value), sendOsc, sendCallback);
  817. #ifndef BUILD_BRIDGE
  818. if (rindex == PARAMETER_DRYWET)
  819. return setDryWet(value, sendOsc, sendCallback);
  820. if (rindex == PARAMETER_VOLUME)
  821. return setVolume(value, sendOsc, sendCallback);
  822. if (rindex == PARAMETER_BALANCE_LEFT)
  823. return setBalanceLeft(value, sendOsc, sendCallback);
  824. if (rindex == PARAMETER_BALANCE_RIGHT)
  825. return setBalanceRight(value, sendOsc, sendCallback);
  826. if (rindex == PARAMETER_PANNING)
  827. return setPanning(value, sendOsc, sendCallback);
  828. #endif
  829. for (uint32_t i=0; i < pData->param.count; ++i)
  830. {
  831. if (pData->param.data[i].rindex == rindex)
  832. {
  833. if (getParameterValue(i) != value)
  834. setParameterValue(i, value, sendGui, sendOsc, sendCallback);
  835. break;
  836. }
  837. }
  838. }
  839. void CarlaPlugin::setParameterMidiChannel(const uint32_t parameterId, uint8_t channel, const bool sendOsc, const bool sendCallback) noexcept
  840. {
  841. CARLA_ASSERT(sendOsc || sendCallback); // never call this from RT
  842. CARLA_ASSERT(parameterId < pData->param.count);
  843. CARLA_ASSERT_INT(channel < MAX_MIDI_CHANNELS, channel);
  844. if (channel >= MAX_MIDI_CHANNELS)
  845. channel = MAX_MIDI_CHANNELS;
  846. pData->param.data[parameterId].midiChannel = channel;
  847. #ifndef BUILD_BRIDGE
  848. if (sendOsc && pData->engine->isOscControlRegistered())
  849. pData->engine->oscSend_control_set_parameter_midi_channel(pData->id, parameterId, channel);
  850. if (sendCallback)
  851. pData->engine->callback(ENGINE_CALLBACK_PARAMETER_MIDI_CHANNEL_CHANGED, pData->id, parameterId, channel, 0.0f, nullptr);
  852. if (pData->hints & PLUGIN_IS_BRIDGE)
  853. {} // TODO
  854. #else
  855. return;
  856. // unused
  857. (void)sendOsc;
  858. (void)sendCallback;
  859. #endif
  860. }
  861. void CarlaPlugin::setParameterMidiCC(const uint32_t parameterId, int16_t cc, const bool sendOsc, const bool sendCallback) noexcept
  862. {
  863. CARLA_ASSERT(sendOsc || sendCallback); // never call this from RT
  864. CARLA_ASSERT(parameterId < pData->param.count);
  865. CARLA_ASSERT_INT(cc >= -1 && cc <= 0x5F, cc);
  866. if (cc < -1 || cc > 0x5F)
  867. cc = -1;
  868. pData->param.data[parameterId].midiCC = cc;
  869. #ifndef BUILD_BRIDGE
  870. if (sendOsc && pData->engine->isOscControlRegistered())
  871. pData->engine->oscSend_control_set_parameter_midi_cc(pData->id, parameterId, cc);
  872. if (sendCallback)
  873. pData->engine->callback(ENGINE_CALLBACK_PARAMETER_MIDI_CC_CHANGED, pData->id, parameterId, cc, 0.0f, nullptr);
  874. if (pData->hints & PLUGIN_IS_BRIDGE)
  875. {} // TODO
  876. #else
  877. return;
  878. // unused
  879. (void)sendOsc;
  880. (void)sendCallback;
  881. #endif
  882. }
  883. void CarlaPlugin::setCustomData(const char* const type, const char* const key, const char* const value, const bool sendGui)
  884. {
  885. CARLA_ASSERT(type != nullptr);
  886. CARLA_ASSERT(key != nullptr);
  887. CARLA_ASSERT(value != nullptr);
  888. #ifdef BUILD_BRIDGE
  889. if (! gIsLoadingProject)
  890. {
  891. CARLA_ASSERT(! sendGui); // this should never happen
  892. }
  893. #endif
  894. if (type == nullptr)
  895. return carla_stderr2("CarlaPlugin::setCustomData(\"%s\", \"%s\", \"%s\", %s) - type is null", type, key, value, bool2str(sendGui));
  896. if (key == nullptr)
  897. return carla_stderr2("CarlaPlugin::setCustomData(\"%s\", \"%s\", \"%s\", %s) - key is null", type, key, value, bool2str(sendGui));
  898. if (value == nullptr)
  899. return carla_stderr2("CarlaPlugin::setCustomData(\"%s\", \"%s\", \"%s\", %s) - value is null", type, key, value, bool2str(sendGui));
  900. bool saveData = true;
  901. if (std::strcmp(type, CUSTOM_DATA_TYPE_STRING) == 0)
  902. {
  903. // Ignore some keys
  904. if (std::strncmp(key, "OSC:", 4) == 0 || std::strncmp(key, "CarlaAlternateFile", 18) == 0 || std::strcmp(key, "guiVisible") == 0)
  905. saveData = false;
  906. //else if (std::strcmp(key, CARLA_BRIDGE_MSG_SAVE_NOW) == 0 || std::strcmp(key, CARLA_BRIDGE_MSG_SET_CHUNK) == 0 || std::strcmp(key, CARLA_BRIDGE_MSG_SET_CUSTOM) == 0)
  907. // saveData = false;
  908. }
  909. if (! saveData)
  910. return;
  911. // Check if we already have this key
  912. for (LinkedList<CustomData>::Itenerator it = pData->custom.begin(); it.valid(); it.next())
  913. {
  914. CustomData& cData(it.getValue());
  915. CARLA_ASSERT(cData.type != nullptr);
  916. CARLA_ASSERT(cData.key != nullptr);
  917. CARLA_ASSERT(cData.value != nullptr);
  918. if (cData.type == nullptr)
  919. return;
  920. if (cData.key == nullptr)
  921. return;
  922. if (std::strcmp(cData.key, key) == 0)
  923. {
  924. if (cData.value != nullptr)
  925. delete[] cData.value;
  926. cData.value = carla_strdup(value);
  927. return;
  928. }
  929. }
  930. // Otherwise store it
  931. CustomData newData;
  932. newData.type = carla_strdup(type);
  933. newData.key = carla_strdup(key);
  934. newData.value = carla_strdup(value);
  935. pData->custom.append(newData);
  936. }
  937. void CarlaPlugin::setChunkData(const char* const stringData)
  938. {
  939. CARLA_ASSERT(stringData != nullptr);
  940. CARLA_ASSERT(false); // this should never happen
  941. return;
  942. // unused
  943. (void)stringData;
  944. }
  945. void CarlaPlugin::setProgram(const int32_t index, const bool sendGui, const bool sendOsc, const bool sendCallback) noexcept
  946. {
  947. CARLA_SAFE_ASSERT_RETURN(index >= -1 && index < static_cast<int32_t>(pData->prog.count),);
  948. #ifdef BUILD_BRIDGE
  949. if (! gIsLoadingProject) {
  950. CARLA_ASSERT(! sendGui); // this should never happen
  951. }
  952. #endif
  953. pData->prog.current = index;
  954. #ifndef BUILD_BRIDGE
  955. const bool reallySendOsc(sendOsc && pData->engine->isOscControlRegistered());
  956. if (reallySendOsc)
  957. pData->engine->oscSend_control_set_current_program(pData->id, index);
  958. #endif
  959. if (sendCallback)
  960. pData->engine->callback(ENGINE_CALLBACK_PROGRAM_CHANGED, pData->id, index, 0, 0.0f, nullptr);
  961. // Change default parameter values
  962. if (index >= 0)
  963. {
  964. #ifndef BUILD_BRIDGE
  965. if (sendGui)
  966. uiProgramChange(index);
  967. #endif
  968. if (getType() == PLUGIN_FILE_CSD || getType() == PLUGIN_FILE_GIG || getType() == PLUGIN_FILE_SF2 || getType() == PLUGIN_FILE_SFZ)
  969. return;
  970. for (uint32_t i=0; i < pData->param.count; ++i)
  971. {
  972. const float value(pData->param.ranges[i].getFixedValue(getParameterValue(i)));
  973. pData->param.ranges[i].def = value;
  974. #ifndef BUILD_BRIDGE
  975. if (reallySendOsc)
  976. {
  977. pData->engine->oscSend_control_set_default_value(pData->id, i, value);
  978. pData->engine->oscSend_control_set_parameter_value(pData->id, i, value);
  979. }
  980. #endif
  981. if (sendCallback)
  982. {
  983. pData->engine->callback(ENGINE_CALLBACK_PARAMETER_VALUE_CHANGED, pData->id, i, 0, value, nullptr);
  984. pData->engine->callback(ENGINE_CALLBACK_PARAMETER_DEFAULT_CHANGED, pData->id, i, 0, value, nullptr);
  985. }
  986. }
  987. }
  988. #ifdef BUILD_BRIDGE
  989. return;
  990. // unused
  991. (void)sendGui;
  992. (void)sendOsc;
  993. #endif
  994. }
  995. void CarlaPlugin::setMidiProgram(const int32_t index, const bool sendGui, const bool sendOsc, const bool sendCallback) noexcept
  996. {
  997. CARLA_SAFE_ASSERT_RETURN(index >= -1 && index < static_cast<int32_t>(pData->midiprog.count),);
  998. #ifdef BUILD_BRIDGE
  999. if (! gIsLoadingProject) {
  1000. CARLA_ASSERT(! sendGui); // this should never happen
  1001. }
  1002. #endif
  1003. pData->midiprog.current = index;
  1004. #ifndef BUILD_BRIDGE
  1005. const bool reallySendOsc(sendOsc && pData->engine->isOscControlRegistered());
  1006. if (reallySendOsc)
  1007. pData->engine->oscSend_control_set_current_midi_program(pData->id, index);
  1008. #endif
  1009. if (sendCallback)
  1010. pData->engine->callback(ENGINE_CALLBACK_MIDI_PROGRAM_CHANGED, pData->id, index, 0, 0.0f, nullptr);
  1011. if (index >= 0)
  1012. {
  1013. #ifndef BUILD_BRIDGE
  1014. if (sendGui)
  1015. uiMidiProgramChange(index);
  1016. #endif
  1017. if (getType() == PLUGIN_FILE_CSD || getType() == PLUGIN_FILE_GIG || getType() == PLUGIN_FILE_SF2 || getType() == PLUGIN_FILE_SFZ)
  1018. return;
  1019. for (uint32_t i=0; i < pData->param.count; ++i)
  1020. {
  1021. const float value(pData->param.ranges[i].getFixedValue(getParameterValue(i)));
  1022. pData->param.ranges[i].def = value;
  1023. #ifndef BUILD_BRIDGE
  1024. if (reallySendOsc)
  1025. {
  1026. pData->engine->oscSend_control_set_default_value(pData->id, i, value);
  1027. pData->engine->oscSend_control_set_parameter_value(pData->id, i, value);
  1028. }
  1029. #endif
  1030. if (sendCallback)
  1031. {
  1032. pData->engine->callback(ENGINE_CALLBACK_PARAMETER_VALUE_CHANGED, pData->id, i, 0, value, nullptr);
  1033. pData->engine->callback(ENGINE_CALLBACK_PARAMETER_DEFAULT_CHANGED, pData->id, i, 0, value, nullptr);
  1034. }
  1035. }
  1036. }
  1037. #ifdef BUILD_BRIDGE
  1038. return;
  1039. // unused
  1040. (void)sendGui;
  1041. (void)sendOsc;
  1042. #endif
  1043. }
  1044. void CarlaPlugin::setMidiProgramById(const uint32_t bank, const uint32_t program, const bool sendGui, const bool sendOsc, const bool sendCallback) noexcept
  1045. {
  1046. for (uint32_t i=0; i < pData->midiprog.count; ++i)
  1047. {
  1048. if (pData->midiprog.data[i].bank == bank && pData->midiprog.data[i].program == program)
  1049. return setMidiProgram(i, sendGui, sendOsc, sendCallback);
  1050. }
  1051. }
  1052. // -------------------------------------------------------------------
  1053. // Set ui stuff
  1054. void CarlaPlugin::idle()
  1055. {
  1056. if (! pData->enabled)
  1057. return;
  1058. if (pData->hints & PLUGIN_NEEDS_SINGLE_THREAD)
  1059. {
  1060. // Process postponed events
  1061. postRtEventsRun();
  1062. // Update parameter outputs
  1063. for (uint32_t i=0; i < pData->param.count; ++i)
  1064. {
  1065. if (pData->param.data[i].type == PARAMETER_OUTPUT)
  1066. uiParameterChange(i, getParameterValue(i));
  1067. }
  1068. }
  1069. }
  1070. void CarlaPlugin::showCustomUI(const bool yesNo)
  1071. {
  1072. CARLA_ASSERT(false);
  1073. return;
  1074. // unused
  1075. (void)yesNo;
  1076. }
  1077. // -------------------------------------------------------------------
  1078. // Plugin state
  1079. void CarlaPlugin::reloadPrograms(const bool)
  1080. {
  1081. }
  1082. // -------------------------------------------------------------------
  1083. // Plugin processing
  1084. void CarlaPlugin::activate() noexcept
  1085. {
  1086. CARLA_ASSERT(! pData->active);
  1087. }
  1088. void CarlaPlugin::deactivate() noexcept
  1089. {
  1090. CARLA_ASSERT(pData->active);
  1091. }
  1092. void CarlaPlugin::bufferSizeChanged(const uint32_t)
  1093. {
  1094. }
  1095. void CarlaPlugin::sampleRateChanged(const double)
  1096. {
  1097. }
  1098. void CarlaPlugin::offlineModeChanged(const bool)
  1099. {
  1100. }
  1101. bool CarlaPlugin::tryLock(const bool forcedOffline) noexcept
  1102. {
  1103. if (forcedOffline)
  1104. {
  1105. pData->masterMutex.lock();
  1106. return true;
  1107. }
  1108. return pData->masterMutex.tryLock();
  1109. }
  1110. void CarlaPlugin::unlock() noexcept
  1111. {
  1112. pData->masterMutex.unlock();
  1113. }
  1114. // -------------------------------------------------------------------
  1115. // Plugin buffers
  1116. void CarlaPlugin::initBuffers()
  1117. {
  1118. pData->audioIn.initBuffers();
  1119. pData->audioOut.initBuffers();
  1120. pData->event.initBuffers();
  1121. }
  1122. void CarlaPlugin::clearBuffers()
  1123. {
  1124. pData->clearBuffers();
  1125. }
  1126. // -------------------------------------------------------------------
  1127. // OSC stuff
  1128. void CarlaPlugin::registerToOscClient() noexcept
  1129. {
  1130. #ifdef BUILD_BRIDGE
  1131. if (! pData->engine->isOscBridgeRegistered())
  1132. #else
  1133. if (! pData->engine->isOscControlRegistered())
  1134. #endif
  1135. return;
  1136. #ifndef BUILD_BRIDGE
  1137. pData->engine->oscSend_control_add_plugin_start(pData->id, pData->name);
  1138. #endif
  1139. // Base data
  1140. {
  1141. // TODO - clear buf
  1142. char bufName[STR_MAX+1] = { '\0' };
  1143. char bufLabel[STR_MAX+1] = { '\0' };
  1144. char bufMaker[STR_MAX+1] = { '\0' };
  1145. char bufCopyright[STR_MAX+1] = { '\0' };
  1146. getRealName(bufName);
  1147. getLabel(bufLabel);
  1148. getMaker(bufMaker);
  1149. getCopyright(bufCopyright);
  1150. #ifdef BUILD_BRIDGE
  1151. pData->engine->oscSend_bridge_plugin_info1(getCategory(), pData->hints, getUniqueId());
  1152. pData->engine->oscSend_bridge_plugin_info2(bufName, bufLabel, bufMaker, bufCopyright);
  1153. #else
  1154. pData->engine->oscSend_control_set_plugin_info1(pData->id, getType(), getCategory(), pData->hints, getUniqueId());
  1155. pData->engine->oscSend_control_set_plugin_info2(pData->id, bufName, bufLabel, bufMaker, bufCopyright);
  1156. #endif
  1157. }
  1158. // Base count
  1159. {
  1160. uint32_t paramIns, paramOuts;
  1161. getParameterCountInfo(paramIns, paramOuts);
  1162. #ifdef BUILD_BRIDGE
  1163. pData->engine->oscSend_bridge_audio_count(getAudioInCount(), getAudioOutCount());
  1164. pData->engine->oscSend_bridge_midi_count(getMidiInCount(), getMidiOutCount());
  1165. pData->engine->oscSend_bridge_parameter_count(paramIns, paramOuts);
  1166. #else
  1167. pData->engine->oscSend_control_set_audio_count(pData->id, getAudioInCount(), getAudioOutCount());
  1168. pData->engine->oscSend_control_set_midi_count(pData->id, getMidiInCount(), getMidiOutCount());
  1169. pData->engine->oscSend_control_set_parameter_count(pData->id, paramIns, paramOuts);
  1170. #endif
  1171. }
  1172. // Plugin Parameters
  1173. if (pData->param.count > 0 && pData->param.count < pData->engine->getOptions().maxParameters)
  1174. {
  1175. char bufName[STR_MAX+1], bufUnit[STR_MAX+1];
  1176. for (uint32_t i=0; i < pData->param.count; ++i)
  1177. {
  1178. carla_fill<char>(bufName, STR_MAX, '\0');
  1179. carla_fill<char>(bufUnit, STR_MAX, '\0');
  1180. getParameterName(i, bufName);
  1181. getParameterUnit(i, bufUnit);
  1182. const ParameterData& paramData(pData->param.data[i]);
  1183. const ParameterRanges& paramRanges(pData->param.ranges[i]);
  1184. #ifdef BUILD_BRIDGE
  1185. pData->engine->oscSend_bridge_parameter_data(i, paramData.rindex, paramData.type, paramData.hints, bufName, bufUnit);
  1186. pData->engine->oscSend_bridge_parameter_ranges1(i, paramRanges.def, paramRanges.min, paramRanges.max);
  1187. pData->engine->oscSend_bridge_parameter_ranges2(i, paramRanges.step, paramRanges.stepSmall, paramRanges.stepLarge);
  1188. pData->engine->oscSend_bridge_parameter_value(i, getParameterValue(i));
  1189. pData->engine->oscSend_bridge_parameter_midi_cc(i, paramData.midiCC);
  1190. pData->engine->oscSend_bridge_parameter_midi_channel(i, paramData.midiChannel);
  1191. #else
  1192. pData->engine->oscSend_control_set_parameter_data(pData->id, i, paramData.type, paramData.hints, bufName, bufUnit);
  1193. pData->engine->oscSend_control_set_parameter_ranges1(pData->id, i, paramRanges.def, paramRanges.min, paramRanges.max);
  1194. pData->engine->oscSend_control_set_parameter_ranges2(pData->id, i, paramRanges.step, paramRanges.stepSmall, paramRanges.stepLarge);
  1195. pData->engine->oscSend_control_set_parameter_value(pData->id, i, getParameterValue(i));
  1196. pData->engine->oscSend_control_set_parameter_midi_cc(pData->id, i, paramData.midiCC);
  1197. pData->engine->oscSend_control_set_parameter_midi_channel(pData->id, i, paramData.midiChannel);
  1198. #endif
  1199. }
  1200. }
  1201. // Programs
  1202. if (pData->prog.count > 0)
  1203. {
  1204. #ifdef BUILD_BRIDGE
  1205. pData->engine->oscSend_bridge_program_count(pData->prog.count);
  1206. for (uint32_t i=0; i < pData->prog.count; ++i)
  1207. pData->engine->oscSend_bridge_program_name(i, pData->prog.names[i]);
  1208. pData->engine->oscSend_bridge_current_program(pData->prog.current);
  1209. #else
  1210. pData->engine->oscSend_control_set_program_count(pData->id, pData->prog.count);
  1211. for (uint32_t i=0; i < pData->prog.count; ++i)
  1212. pData->engine->oscSend_control_set_program_name(pData->id, i, pData->prog.names[i]);
  1213. pData->engine->oscSend_control_set_current_program(pData->id, pData->prog.current);
  1214. #endif
  1215. }
  1216. // MIDI Programs
  1217. if (pData->midiprog.count > 0)
  1218. {
  1219. #ifdef BUILD_BRIDGE
  1220. pData->engine->oscSend_bridge_midi_program_count(pData->midiprog.count);
  1221. for (uint32_t i=0; i < pData->midiprog.count; ++i)
  1222. {
  1223. const MidiProgramData& mpData(pData->midiprog.data[i]);
  1224. pData->engine->oscSend_bridge_midi_program_data(i, mpData.bank, mpData.program, mpData.name);
  1225. }
  1226. pData->engine->oscSend_bridge_current_midi_program(pData->midiprog.current);
  1227. #else
  1228. pData->engine->oscSend_control_set_midi_program_count(pData->id, pData->midiprog.count);
  1229. for (uint32_t i=0; i < pData->midiprog.count; ++i)
  1230. {
  1231. const MidiProgramData& mpData(pData->midiprog.data[i]);
  1232. pData->engine->oscSend_control_set_midi_program_data(pData->id, i, mpData.bank, mpData.program, mpData.name);
  1233. }
  1234. pData->engine->oscSend_control_set_current_midi_program(pData->id, pData->midiprog.current);
  1235. #endif
  1236. }
  1237. #ifndef BUILD_BRIDGE
  1238. pData->engine->oscSend_control_add_plugin_end(pData->id);
  1239. // Internal Parameters
  1240. {
  1241. pData->engine->oscSend_control_set_parameter_value(pData->id, PARAMETER_DRYWET, pData->postProc.dryWet);
  1242. pData->engine->oscSend_control_set_parameter_value(pData->id, PARAMETER_VOLUME, pData->postProc.volume);
  1243. pData->engine->oscSend_control_set_parameter_value(pData->id, PARAMETER_BALANCE_LEFT, pData->postProc.balanceLeft);
  1244. pData->engine->oscSend_control_set_parameter_value(pData->id, PARAMETER_BALANCE_RIGHT, pData->postProc.balanceRight);
  1245. pData->engine->oscSend_control_set_parameter_value(pData->id, PARAMETER_PANNING, pData->postProc.panning);
  1246. pData->engine->oscSend_control_set_parameter_value(pData->id, PARAMETER_CTRL_CHANNEL, pData->ctrlChannel);
  1247. pData->engine->oscSend_control_set_parameter_value(pData->id, PARAMETER_ACTIVE, pData->active ? 1.0f : 0.0f);
  1248. }
  1249. #endif
  1250. }
  1251. void CarlaPlugin::updateOscData(const lo_address& source, const char* const url)
  1252. {
  1253. // FIXME - remove debug prints later
  1254. carla_stdout("CarlaPlugin::updateOscData(%p, \"%s\")", source, url);
  1255. pData->osc.data.free();
  1256. const int proto = lo_address_get_protocol(source);
  1257. {
  1258. const char* host = lo_address_get_hostname(source);
  1259. const char* port = lo_address_get_port(source);
  1260. pData->osc.data.source = lo_address_new_with_proto(proto, host, port);
  1261. carla_stdout("CarlaPlugin::updateOscData() - source: host \"%s\", port \"%s\"", host, port);
  1262. }
  1263. {
  1264. char* host = lo_url_get_hostname(url);
  1265. char* port = lo_url_get_port(url);
  1266. pData->osc.data.path = carla_strdup_free(lo_url_get_path(url));
  1267. pData->osc.data.target = lo_address_new_with_proto(proto, host, port);
  1268. carla_stdout("CarlaPlugin::updateOscData() - target: host \"%s\", port \"%s\", path \"%s\"", host, port, pData->osc.data.path);
  1269. std::free(host);
  1270. std::free(port);
  1271. }
  1272. #ifndef BUILD_BRIDGE
  1273. if (pData->hints & PLUGIN_IS_BRIDGE)
  1274. return;
  1275. #endif
  1276. osc_send_sample_rate(pData->osc.data, static_cast<float>(pData->engine->getSampleRate()));
  1277. for (LinkedList<CustomData>::Itenerator it = pData->custom.begin(); it.valid(); it.next())
  1278. {
  1279. const CustomData& cData(it.getValue());
  1280. CARLA_ASSERT(cData.type != nullptr);
  1281. CARLA_ASSERT(cData.key != nullptr);
  1282. CARLA_ASSERT(cData.value != nullptr);
  1283. if (std::strcmp(cData.type, CUSTOM_DATA_TYPE_STRING) == 0)
  1284. osc_send_configure(pData->osc.data, cData.key, cData.value);
  1285. }
  1286. if (pData->prog.current >= 0)
  1287. osc_send_program(pData->osc.data, pData->prog.current);
  1288. if (pData->midiprog.current >= 0)
  1289. {
  1290. const MidiProgramData& curMidiProg(pData->midiprog.getCurrent());
  1291. if (getType() == PLUGIN_DSSI)
  1292. osc_send_program(pData->osc.data, curMidiProg.bank, curMidiProg.program);
  1293. else
  1294. osc_send_midi_program(pData->osc.data, curMidiProg.bank, curMidiProg.program);
  1295. }
  1296. for (uint32_t i=0; i < pData->param.count; ++i)
  1297. osc_send_control(pData->osc.data, pData->param.data[i].rindex, getParameterValue(i));
  1298. carla_stdout("CarlaPlugin::updateOscData() - done");
  1299. }
  1300. // void CarlaPlugin::freeOscData()
  1301. // {
  1302. // pData->osc.data.free();
  1303. // }
  1304. bool CarlaPlugin::waitForOscGuiShow()
  1305. {
  1306. carla_stdout("CarlaPlugin::waitForOscGuiShow()");
  1307. uint i=0, oscUiTimeout = pData->engine->getOptions().uiBridgesTimeout;
  1308. // wait for UI 'update' call
  1309. for (; i < oscUiTimeout/100; ++i)
  1310. {
  1311. if (pData->osc.data.target != nullptr)
  1312. {
  1313. carla_stdout("CarlaPlugin::waitForOscGuiShow() - got response, asking UI to show itself now");
  1314. osc_send_show(pData->osc.data);
  1315. return true;
  1316. }
  1317. else
  1318. carla_msleep(100);
  1319. }
  1320. carla_stdout("CarlaPlugin::waitForOscGuiShow() - Timeout while waiting for UI to respond (waited %u msecs)", oscUiTimeout);
  1321. return false;
  1322. }
  1323. // -------------------------------------------------------------------
  1324. // MIDI events
  1325. #ifndef BUILD_BRIDGE
  1326. void CarlaPlugin::sendMidiSingleNote(const uint8_t channel, const uint8_t note, const uint8_t velo, const bool sendGui, const bool sendOsc, const bool sendCallback)
  1327. {
  1328. CARLA_ASSERT(channel < MAX_MIDI_CHANNELS);
  1329. CARLA_ASSERT(note < MAX_MIDI_NOTE);
  1330. CARLA_ASSERT(velo < MAX_MIDI_VALUE);
  1331. if (! pData->active)
  1332. return;
  1333. ExternalMidiNote extNote;
  1334. extNote.channel = channel;
  1335. extNote.note = note;
  1336. extNote.velo = velo;
  1337. pData->extNotes.append(extNote);
  1338. if (sendGui)
  1339. {
  1340. if (velo > 0)
  1341. uiNoteOn(channel, note, velo);
  1342. else
  1343. uiNoteOff(channel, note);
  1344. }
  1345. if (sendOsc && pData->engine->isOscControlRegistered())
  1346. {
  1347. if (velo > 0)
  1348. pData->engine->oscSend_control_note_on(pData->id, channel, note, velo);
  1349. else
  1350. pData->engine->oscSend_control_note_off(pData->id, channel, note);
  1351. }
  1352. if (sendCallback)
  1353. pData->engine->callback((velo > 0) ? ENGINE_CALLBACK_NOTE_ON : ENGINE_CALLBACK_NOTE_OFF, pData->id, channel, note, velo, nullptr);
  1354. }
  1355. #endif
  1356. void CarlaPlugin::sendMidiAllNotesOffToCallback()
  1357. {
  1358. if (pData->ctrlChannel < 0 || pData->ctrlChannel >= MAX_MIDI_CHANNELS)
  1359. return;
  1360. PluginPostRtEvent postEvent;
  1361. postEvent.type = kPluginPostRtEventNoteOff;
  1362. postEvent.value1 = pData->ctrlChannel;
  1363. postEvent.value2 = 0;
  1364. postEvent.value3 = 0.0f;
  1365. for (unsigned short i=0; i < MAX_MIDI_NOTE; ++i)
  1366. {
  1367. postEvent.value2 = i;
  1368. pData->postRtEvents.appendRT(postEvent);
  1369. }
  1370. }
  1371. // -------------------------------------------------------------------
  1372. // Post-poned events
  1373. void CarlaPlugin::postRtEventsRun()
  1374. {
  1375. const CarlaMutex::ScopedLocker sl(pData->postRtEvents.mutex);
  1376. while (! pData->postRtEvents.data.isEmpty())
  1377. {
  1378. const PluginPostRtEvent& event(pData->postRtEvents.data.getFirst(true));
  1379. switch (event.type)
  1380. {
  1381. case kPluginPostRtEventNull:
  1382. break;
  1383. case kPluginPostRtEventDebug:
  1384. #ifndef BUILD_BRIDGE
  1385. pData->engine->callback(ENGINE_CALLBACK_DEBUG, pData->id, event.value1, event.value2, event.value3, nullptr);
  1386. #endif
  1387. break;
  1388. case kPluginPostRtEventParameterChange:
  1389. // Update UI
  1390. if (event.value1 >= 0)
  1391. uiParameterChange(event.value1, event.value3);
  1392. #ifndef BUILD_BRIDGE
  1393. if (event.value2 != 1)
  1394. {
  1395. // Update OSC control client
  1396. if (pData->engine->isOscControlRegistered())
  1397. pData->engine->oscSend_control_set_parameter_value(pData->id, event.value1, event.value3);
  1398. // Update Host
  1399. pData->engine->callback(ENGINE_CALLBACK_PARAMETER_VALUE_CHANGED, pData->id, event.value1, 0, event.value3, nullptr);
  1400. }
  1401. #endif
  1402. break;
  1403. case kPluginPostRtEventProgramChange:
  1404. // Update UI
  1405. if (event.value1 >= 0)
  1406. uiProgramChange(event.value1);
  1407. #ifndef BUILD_BRIDGE
  1408. // Update OSC control client
  1409. if (pData->engine->isOscControlRegistered())
  1410. pData->engine->oscSend_control_set_current_program(pData->id, event.value1);
  1411. // Update Host
  1412. pData->engine->callback(ENGINE_CALLBACK_PROGRAM_CHANGED, pData->id, event.value1, 0, 0.0f, nullptr);
  1413. // Update param values
  1414. {
  1415. const bool sendOsc(pData->engine->isOscControlRegistered());
  1416. for (uint32_t j=0; j < pData->param.count; ++j)
  1417. {
  1418. const float value(getParameterValue(j));
  1419. if (sendOsc)
  1420. {
  1421. pData->engine->oscSend_control_set_parameter_value(pData->id, j, value);
  1422. pData->engine->oscSend_control_set_default_value(pData->id, j, pData->param.ranges[j].def);
  1423. }
  1424. pData->engine->callback(ENGINE_CALLBACK_PARAMETER_VALUE_CHANGED, pData->id, j, 0, value, nullptr);
  1425. pData->engine->callback(ENGINE_CALLBACK_PARAMETER_DEFAULT_CHANGED, pData->id, j, 0, pData->param.ranges[j].def, nullptr);
  1426. }
  1427. }
  1428. #endif
  1429. break;
  1430. case kPluginPostRtEventMidiProgramChange:
  1431. // Update UI
  1432. if (event.value1 >= 0)
  1433. uiMidiProgramChange(event.value1);
  1434. #ifndef BUILD_BRIDGE
  1435. // Update OSC control client
  1436. if (pData->engine->isOscControlRegistered())
  1437. pData->engine->oscSend_control_set_current_midi_program(pData->id, event.value1);
  1438. // Update Host
  1439. pData->engine->callback(ENGINE_CALLBACK_MIDI_PROGRAM_CHANGED, pData->id, event.value1, 0, 0.0f, nullptr);
  1440. // Update param values
  1441. {
  1442. const bool sendOsc(pData->engine->isOscControlRegistered());
  1443. for (uint32_t j=0; j < pData->param.count; ++j)
  1444. {
  1445. const float value(getParameterValue(j));
  1446. if (sendOsc)
  1447. {
  1448. pData->engine->oscSend_control_set_parameter_value(pData->id, j, value);
  1449. pData->engine->oscSend_control_set_default_value(pData->id, j, pData->param.ranges[j].def);
  1450. }
  1451. pData->engine->callback(ENGINE_CALLBACK_PARAMETER_VALUE_CHANGED, pData->id, j, 0, value, nullptr);
  1452. pData->engine->callback(ENGINE_CALLBACK_PARAMETER_DEFAULT_CHANGED, pData->id, j, 0, pData->param.ranges[j].def, nullptr);
  1453. }
  1454. }
  1455. #endif
  1456. break;
  1457. case kPluginPostRtEventNoteOn:
  1458. {
  1459. CARLA_SAFE_ASSERT_BREAK(event.value1 < MAX_MIDI_CHANNELS);
  1460. CARLA_SAFE_ASSERT_BREAK(event.value2 < MAX_MIDI_NOTE);
  1461. CARLA_SAFE_ASSERT_BREAK(event.value3 < MAX_MIDI_VALUE);
  1462. const uint8_t channel = static_cast<uint8_t>(event.value1);
  1463. const uint8_t note = static_cast<uint8_t>(event.value2);
  1464. const uint8_t velocity = uint8_t(event.value3);
  1465. // Update UI
  1466. uiNoteOn(channel, note, velocity);
  1467. #ifndef BUILD_BRIDGE
  1468. // Update OSC control client
  1469. if (pData->engine->isOscControlRegistered())
  1470. pData->engine->oscSend_control_note_on(pData->id, channel, note, velocity);
  1471. // Update Host
  1472. pData->engine->callback(ENGINE_CALLBACK_NOTE_ON, pData->id, event.value1, event.value2, event.value3, nullptr);
  1473. #endif
  1474. break;
  1475. }
  1476. case kPluginPostRtEventNoteOff:
  1477. {
  1478. CARLA_SAFE_ASSERT_BREAK(event.value1 < MAX_MIDI_CHANNELS);
  1479. CARLA_SAFE_ASSERT_BREAK(event.value2 < MAX_MIDI_NOTE);
  1480. const uint8_t channel = static_cast<uint8_t>(event.value1);
  1481. const uint8_t note = static_cast<uint8_t>(event.value2);
  1482. // Update UI
  1483. uiNoteOff(channel, note);
  1484. #ifndef BUILD_BRIDGE
  1485. // Update OSC control client
  1486. if (pData->engine->isOscControlRegistered())
  1487. pData->engine->oscSend_control_note_off(pData->id, channel, note);
  1488. // Update Host
  1489. pData->engine->callback(ENGINE_CALLBACK_NOTE_OFF, pData->id, event.value1, event.value2, 0.0f, nullptr);
  1490. #endif
  1491. break;
  1492. }
  1493. }
  1494. }
  1495. }
  1496. // -------------------------------------------------------------------
  1497. // Post-poned UI Stuff
  1498. void CarlaPlugin::uiParameterChange(const uint32_t index, const float value) noexcept
  1499. {
  1500. CARLA_ASSERT(index < getParameterCount());
  1501. return;
  1502. // unused
  1503. (void)index;
  1504. (void)value;
  1505. }
  1506. void CarlaPlugin::uiProgramChange(const uint32_t index) noexcept
  1507. {
  1508. CARLA_ASSERT(index < getProgramCount());
  1509. return;
  1510. // unused
  1511. (void)index;
  1512. }
  1513. void CarlaPlugin::uiMidiProgramChange(const uint32_t index) noexcept
  1514. {
  1515. CARLA_ASSERT(index < getMidiProgramCount());
  1516. return;
  1517. // unused
  1518. (void)index;
  1519. }
  1520. void CarlaPlugin::uiNoteOn(const uint8_t channel, const uint8_t note, const uint8_t velo) noexcept
  1521. {
  1522. CARLA_ASSERT(channel < MAX_MIDI_CHANNELS);
  1523. CARLA_ASSERT(note < MAX_MIDI_NOTE);
  1524. CARLA_ASSERT(velo > 0 && velo < MAX_MIDI_VALUE);
  1525. return;
  1526. // unused
  1527. (void)channel;
  1528. (void)note;
  1529. (void)velo;
  1530. }
  1531. void CarlaPlugin::uiNoteOff(const uint8_t channel, const uint8_t note) noexcept
  1532. {
  1533. CARLA_ASSERT(channel < MAX_MIDI_CHANNELS);
  1534. CARLA_ASSERT(note < MAX_MIDI_NOTE);
  1535. return;
  1536. // unused
  1537. (void)channel;
  1538. (void)note;
  1539. }
  1540. bool CarlaPlugin::canRunInRack() const noexcept
  1541. {
  1542. return (pData->extraHints & PLUGIN_EXTRA_HINT_CAN_RUN_RACK) != 0;
  1543. }
  1544. CarlaEngine* CarlaPlugin::getEngine() const noexcept
  1545. {
  1546. return pData->engine;
  1547. }
  1548. CarlaEngineClient* CarlaPlugin::getEngineClient() const noexcept
  1549. {
  1550. return pData->client;
  1551. }
  1552. CarlaEngineAudioPort* CarlaPlugin::getAudioInPort(const uint32_t index) const noexcept
  1553. {
  1554. return pData->audioIn.ports[index].port;
  1555. }
  1556. CarlaEngineAudioPort* CarlaPlugin::getAudioOutPort(const uint32_t index) const noexcept
  1557. {
  1558. return pData->audioOut.ports[index].port;
  1559. }
  1560. // -------------------------------------------------------------------
  1561. // Scoped Disabler
  1562. CarlaPlugin::ScopedDisabler::ScopedDisabler(CarlaPlugin* const plugin) noexcept
  1563. : fPlugin(plugin)
  1564. {
  1565. CARLA_SAFE_ASSERT_RETURN(plugin != nullptr,);
  1566. CARLA_SAFE_ASSERT_RETURN(plugin->pData != nullptr,);
  1567. CARLA_SAFE_ASSERT_RETURN(plugin->pData->client != nullptr,);
  1568. carla_debug("CarlaPlugin::ScopedDisabler(%p)", plugin);
  1569. plugin->pData->masterMutex.lock();
  1570. if (plugin->pData->enabled)
  1571. plugin->pData->enabled = false;
  1572. if (plugin->pData->client->isActive())
  1573. plugin->pData->client->deactivate();
  1574. }
  1575. CarlaPlugin::ScopedDisabler::~ScopedDisabler() noexcept
  1576. {
  1577. CARLA_SAFE_ASSERT_RETURN(fPlugin != nullptr,);
  1578. CARLA_SAFE_ASSERT_RETURN(fPlugin->pData != nullptr,);
  1579. CARLA_SAFE_ASSERT_RETURN(fPlugin->pData->client != nullptr,);
  1580. carla_debug("CarlaPlugin::~ScopedDisabler()");
  1581. fPlugin->pData->enabled = true;
  1582. fPlugin->pData->client->activate();
  1583. fPlugin->pData->masterMutex.unlock();
  1584. }
  1585. // -------------------------------------------------------------------
  1586. // Scoped Process Locker
  1587. CarlaPlugin::ScopedSingleProcessLocker::ScopedSingleProcessLocker(CarlaPlugin* const plugin, const bool block) noexcept
  1588. : fPlugin(plugin),
  1589. fBlock(block)
  1590. {
  1591. CARLA_SAFE_ASSERT_RETURN(fPlugin != nullptr,);
  1592. CARLA_SAFE_ASSERT_RETURN(fPlugin->pData != nullptr,);
  1593. carla_debug("CarlaPlugin::ScopedSingleProcessLocker(%p, %s)", plugin, bool2str(block));
  1594. if (! fBlock)
  1595. return;
  1596. plugin->pData->singleMutex.lock();
  1597. }
  1598. CarlaPlugin::ScopedSingleProcessLocker::~ScopedSingleProcessLocker() noexcept
  1599. {
  1600. CARLA_SAFE_ASSERT_RETURN(fPlugin != nullptr,);
  1601. CARLA_SAFE_ASSERT_RETURN(fPlugin->pData != nullptr,);
  1602. carla_debug("CarlaPlugin::~ScopedSingleProcessLocker()");
  1603. if (! fBlock)
  1604. return;
  1605. #ifndef BUILD_BRIDGE
  1606. if (fPlugin->pData->singleMutex.wasTryLockCalled())
  1607. fPlugin->pData->needsReset = true;
  1608. #endif
  1609. fPlugin->pData->singleMutex.unlock();
  1610. }
  1611. // -------------------------------------------------------------------
  1612. CARLA_BACKEND_END_NAMESPACE