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.

878 lines
22KB

  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 "CarlaLibCounter.hpp"
  20. #include "CarlaMathUtils.hpp"
  21. CARLA_BACKEND_START_NAMESPACE
  22. // -------------------------------------------------------------------
  23. // Fallback data
  24. static const MidiProgramData kMidiProgramDataNull = { 0, 0, nullptr };
  25. static /* */ CustomData kCustomDataFallbackNC = { nullptr, nullptr, nullptr };
  26. // -----------------------------------------------------------------------
  27. // PluginAudioData
  28. PluginAudioData::PluginAudioData() noexcept
  29. : count(0),
  30. ports(nullptr) {}
  31. PluginAudioData::~PluginAudioData() noexcept
  32. {
  33. CARLA_SAFE_ASSERT_INT(count == 0, count);
  34. CARLA_SAFE_ASSERT(ports == nullptr);
  35. }
  36. void PluginAudioData::createNew(const uint32_t newCount)
  37. {
  38. CARLA_SAFE_ASSERT_INT(count == 0, count);
  39. CARLA_SAFE_ASSERT_RETURN(ports == nullptr,);
  40. CARLA_SAFE_ASSERT_RETURN(newCount > 0,);
  41. ports = new PluginAudioPort[newCount];
  42. carla_zeroStructs(ports, newCount);
  43. count = newCount;
  44. }
  45. void PluginAudioData::clear() noexcept
  46. {
  47. if (ports != nullptr)
  48. {
  49. for (uint32_t i=0; i < count; ++i)
  50. {
  51. if (ports[i].port != nullptr)
  52. {
  53. delete ports[i].port;
  54. ports[i].port = nullptr;
  55. }
  56. }
  57. delete[] ports;
  58. ports = nullptr;
  59. }
  60. count = 0;
  61. }
  62. void PluginAudioData::initBuffers() const noexcept
  63. {
  64. for (uint32_t i=0; i < count; ++i)
  65. {
  66. if (ports[i].port != nullptr)
  67. ports[i].port->initBuffer();
  68. }
  69. }
  70. // -----------------------------------------------------------------------
  71. // PluginCVData
  72. PluginCVData::PluginCVData() noexcept
  73. : count(0),
  74. ports(nullptr) {}
  75. PluginCVData::~PluginCVData() noexcept
  76. {
  77. CARLA_SAFE_ASSERT_INT(count == 0, count);
  78. CARLA_SAFE_ASSERT(ports == nullptr);
  79. }
  80. void PluginCVData::createNew(const uint32_t newCount)
  81. {
  82. CARLA_SAFE_ASSERT_INT(count == 0, count);
  83. CARLA_SAFE_ASSERT_RETURN(ports == nullptr,);
  84. CARLA_SAFE_ASSERT_RETURN(newCount > 0,);
  85. ports = new PluginCVPort[newCount];
  86. carla_zeroStructs(ports, newCount);
  87. count = newCount;
  88. }
  89. void PluginCVData::clear() noexcept
  90. {
  91. if (ports != nullptr)
  92. {
  93. for (uint32_t i=0; i < count; ++i)
  94. {
  95. if (ports[i].port != nullptr)
  96. {
  97. delete ports[i].port;
  98. ports[i].port = nullptr;
  99. }
  100. }
  101. delete[] ports;
  102. ports = nullptr;
  103. }
  104. count = 0;
  105. }
  106. void PluginCVData::initBuffers() const noexcept
  107. {
  108. for (uint32_t i=0; i < count; ++i)
  109. {
  110. if (ports[i].port != nullptr)
  111. ports[i].port->initBuffer();
  112. }
  113. }
  114. // -----------------------------------------------------------------------
  115. // PluginEventData
  116. PluginEventData::PluginEventData() noexcept
  117. : portIn(nullptr),
  118. portOut(nullptr)
  119. #ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH
  120. , cvSourcePorts(nullptr)
  121. #endif
  122. {
  123. }
  124. PluginEventData::~PluginEventData() noexcept
  125. {
  126. CARLA_SAFE_ASSERT(portIn == nullptr);
  127. CARLA_SAFE_ASSERT(portOut == nullptr);
  128. #ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH
  129. CARLA_SAFE_ASSERT(cvSourcePorts == nullptr);
  130. #endif
  131. }
  132. void PluginEventData::clear() noexcept
  133. {
  134. if (portIn != nullptr)
  135. {
  136. delete portIn;
  137. portIn = nullptr;
  138. }
  139. if (portOut != nullptr)
  140. {
  141. delete portOut;
  142. portOut = nullptr;
  143. }
  144. #ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH
  145. if (cvSourcePorts != nullptr)
  146. {
  147. delete cvSourcePorts;
  148. cvSourcePorts = nullptr;
  149. }
  150. #endif
  151. }
  152. void PluginEventData::initBuffers() const noexcept
  153. {
  154. if (portIn != nullptr)
  155. portIn->initBuffer();
  156. if (portOut != nullptr)
  157. portOut->initBuffer();
  158. }
  159. // -----------------------------------------------------------------------
  160. // PluginParameterData
  161. PluginParameterData::PluginParameterData() noexcept
  162. : count(0),
  163. data(nullptr),
  164. ranges(nullptr),
  165. special(nullptr) {}
  166. PluginParameterData::~PluginParameterData() noexcept
  167. {
  168. CARLA_SAFE_ASSERT_INT(count == 0, count);
  169. CARLA_SAFE_ASSERT(data == nullptr);
  170. CARLA_SAFE_ASSERT(ranges == nullptr);
  171. CARLA_SAFE_ASSERT(special == nullptr);
  172. }
  173. void PluginParameterData::createNew(const uint32_t newCount, const bool withSpecial)
  174. {
  175. CARLA_SAFE_ASSERT_INT(count == 0, count);
  176. CARLA_SAFE_ASSERT_RETURN(data == nullptr,);
  177. CARLA_SAFE_ASSERT_RETURN(ranges == nullptr,);
  178. CARLA_SAFE_ASSERT_RETURN(special == nullptr,);
  179. CARLA_SAFE_ASSERT_RETURN(newCount > 0,);
  180. data = new ParameterData[newCount];
  181. carla_zeroStructs(data, newCount);
  182. for (uint32_t i=0; i < newCount; ++i)
  183. {
  184. data[i].index = PARAMETER_NULL;
  185. data[i].rindex = PARAMETER_NULL;
  186. data[i].mappedControlIndex = CONTROL_INDEX_NONE;
  187. data[i].mappedMinimum = -1.0f;
  188. data[i].mappedMaximum = 1.0f;
  189. }
  190. ranges = new ParameterRanges[newCount];
  191. carla_zeroStructs(ranges, newCount);
  192. if (withSpecial)
  193. {
  194. special = new SpecialParameterType[newCount];
  195. carla_zeroStructs(special, newCount);
  196. }
  197. count = newCount;
  198. }
  199. void PluginParameterData::clear() noexcept
  200. {
  201. if (data != nullptr)
  202. {
  203. delete[] data;
  204. data = nullptr;
  205. }
  206. if (ranges != nullptr)
  207. {
  208. delete[] ranges;
  209. ranges = nullptr;
  210. }
  211. if (special != nullptr)
  212. {
  213. delete[] special;
  214. special = nullptr;
  215. }
  216. count = 0;
  217. }
  218. float PluginParameterData::getFixedValue(const uint32_t parameterId, float value) const noexcept
  219. {
  220. CARLA_SAFE_ASSERT_RETURN(parameterId < count, 0.0f);
  221. const uint paramHints (data[parameterId].hints);
  222. const ParameterRanges& paramRanges(ranges[parameterId]);
  223. // if boolean, return either min or max
  224. if (paramHints & PARAMETER_IS_BOOLEAN)
  225. {
  226. const float middlePoint = paramRanges.min + (paramRanges.max-paramRanges.min)/2.0f;
  227. return value >= middlePoint ? paramRanges.max : paramRanges.min;
  228. }
  229. // if integer, round first
  230. if (paramHints & PARAMETER_IS_INTEGER)
  231. return paramRanges.getFixedValue(std::round(value));
  232. // normal mode
  233. return paramRanges.getFixedValue(value);
  234. }
  235. // -----------------------------------------------------------------------
  236. // PluginProgramData
  237. PluginProgramData::PluginProgramData() noexcept
  238. : count(0),
  239. current(-1),
  240. names(nullptr) {}
  241. PluginProgramData::~PluginProgramData() noexcept
  242. {
  243. CARLA_SAFE_ASSERT_INT(count == 0, count);
  244. CARLA_SAFE_ASSERT_INT(current == -1, current);
  245. CARLA_SAFE_ASSERT(names == nullptr);
  246. }
  247. void PluginProgramData::createNew(const uint32_t newCount)
  248. {
  249. CARLA_SAFE_ASSERT_INT(count == 0, count);
  250. CARLA_SAFE_ASSERT_INT(current == -1, current);
  251. CARLA_SAFE_ASSERT_RETURN(names == nullptr,);
  252. CARLA_SAFE_ASSERT_RETURN(newCount > 0,);
  253. names = new ProgramName[newCount];
  254. carla_zeroStructs(names, newCount);
  255. count = newCount;
  256. current = -1;
  257. }
  258. void PluginProgramData::clear() noexcept
  259. {
  260. if (names != nullptr)
  261. {
  262. for (uint32_t i=0; i < count; ++i)
  263. {
  264. if (names[i] != nullptr)
  265. {
  266. delete[] names[i];
  267. names[i] = nullptr;
  268. }
  269. }
  270. delete[] names;
  271. names = nullptr;
  272. }
  273. count = 0;
  274. current = -1;
  275. }
  276. // -----------------------------------------------------------------------
  277. // PluginMidiProgramData
  278. PluginMidiProgramData::PluginMidiProgramData() noexcept
  279. : count(0),
  280. current(-1),
  281. data(nullptr) {}
  282. PluginMidiProgramData::~PluginMidiProgramData() noexcept
  283. {
  284. CARLA_SAFE_ASSERT_INT(count == 0, count);
  285. CARLA_SAFE_ASSERT_INT(current == -1, current);
  286. CARLA_SAFE_ASSERT(data == nullptr);
  287. }
  288. void PluginMidiProgramData::createNew(const uint32_t newCount)
  289. {
  290. CARLA_SAFE_ASSERT_INT(count == 0, count);
  291. CARLA_SAFE_ASSERT_INT(current == -1, current);
  292. CARLA_SAFE_ASSERT_RETURN(data == nullptr,);
  293. CARLA_SAFE_ASSERT_RETURN(newCount > 0,);
  294. data = new MidiProgramData[newCount];
  295. carla_zeroStructs(data, newCount);
  296. count = newCount;
  297. current = -1;
  298. }
  299. void PluginMidiProgramData::clear() noexcept
  300. {
  301. if (data != nullptr)
  302. {
  303. for (uint32_t i=0; i < count; ++i)
  304. {
  305. if (data[i].name != nullptr)
  306. {
  307. delete[] data[i].name;
  308. data[i].name = nullptr;
  309. }
  310. }
  311. delete[] data;
  312. data = nullptr;
  313. }
  314. count = 0;
  315. current = -1;
  316. }
  317. const MidiProgramData& PluginMidiProgramData::getCurrent() const noexcept
  318. {
  319. CARLA_SAFE_ASSERT_RETURN(current >= 0 && current < static_cast<int32_t>(count), kMidiProgramDataNull);
  320. return data[current];
  321. }
  322. // -----------------------------------------------------------------------
  323. // ProtectedData::ExternalNotes
  324. CarlaPlugin::ProtectedData::ExternalNotes::ExternalNotes() noexcept
  325. : mutex(),
  326. dataPool(32, 152),
  327. data(dataPool) {}
  328. CarlaPlugin::ProtectedData::ExternalNotes::~ExternalNotes() noexcept
  329. {
  330. clear();
  331. }
  332. void CarlaPlugin::ProtectedData::ExternalNotes::appendNonRT(const ExternalMidiNote& note) noexcept
  333. {
  334. mutex.lock();
  335. data.append_sleepy(note);
  336. mutex.unlock();
  337. }
  338. void CarlaPlugin::ProtectedData::ExternalNotes::clear() noexcept
  339. {
  340. mutex.lock();
  341. data.clear();
  342. mutex.unlock();
  343. }
  344. // -----------------------------------------------------------------------
  345. // ProtectedData::Latency
  346. CarlaPlugin::ProtectedData::Latency::Latency() noexcept
  347. #ifdef BUILD_BRIDGE
  348. : frames(0) {}
  349. #else
  350. : frames(0),
  351. channels(0),
  352. buffers(nullptr) {}
  353. #endif
  354. #ifndef BUILD_BRIDGE
  355. CarlaPlugin::ProtectedData::Latency::~Latency() noexcept
  356. {
  357. clearBuffers();
  358. }
  359. void CarlaPlugin::ProtectedData::Latency::clearBuffers() noexcept
  360. {
  361. if (buffers != nullptr)
  362. {
  363. for (uint32_t i=0; i < channels; ++i)
  364. {
  365. CARLA_SAFE_ASSERT_CONTINUE(buffers[i] != nullptr);
  366. delete[] buffers[i];
  367. buffers[i] = nullptr;
  368. }
  369. delete[] buffers;
  370. buffers = nullptr;
  371. }
  372. channels = 0;
  373. frames = 0;
  374. }
  375. void CarlaPlugin::ProtectedData::Latency::recreateBuffers(const uint32_t newChannels, const uint32_t newFrames)
  376. {
  377. CARLA_SAFE_ASSERT_RETURN(channels != newChannels || frames != newFrames,);
  378. const bool retrieveOldBuffer = (channels == newChannels && channels > 0 && frames > 0 && newFrames > 0);
  379. float** const oldBuffers = buffers;
  380. const uint32_t oldFrames = frames;
  381. channels = newChannels;
  382. frames = newFrames;
  383. if (channels > 0 && frames > 0)
  384. {
  385. buffers = new float*[channels];
  386. for (uint32_t i=0; i < channels; ++i)
  387. {
  388. buffers[i] = new float[frames];
  389. if (retrieveOldBuffer)
  390. {
  391. if (oldFrames > frames)
  392. {
  393. const uint32_t diff = oldFrames - frames;
  394. carla_copyFloats(buffers[i], oldBuffers[i] + diff, frames);
  395. }
  396. else
  397. {
  398. const uint32_t diff = frames - oldFrames;
  399. carla_zeroFloats(buffers[i], diff);
  400. carla_copyFloats(buffers[i] + diff, oldBuffers[i], oldFrames);
  401. }
  402. }
  403. else
  404. {
  405. carla_zeroFloats(buffers[i], frames);
  406. }
  407. }
  408. }
  409. else
  410. {
  411. buffers = nullptr;
  412. }
  413. // delete old buffer
  414. if (oldBuffers != nullptr)
  415. {
  416. for (uint32_t i=0; i < channels; ++i)
  417. {
  418. CARLA_SAFE_ASSERT_CONTINUE(oldBuffers[i] != nullptr);
  419. delete[] oldBuffers[i];
  420. oldBuffers[i] = nullptr;
  421. }
  422. delete[] oldBuffers;
  423. }
  424. }
  425. #endif
  426. // -----------------------------------------------------------------------
  427. // ProtectedData::PostRtEvents
  428. CarlaPlugin::ProtectedData::PostRtEvents::PostRtEvents() noexcept
  429. : dataPool(128, 128),
  430. dataPendingRT(dataPool),
  431. data(dataPool),
  432. dataMutex(),
  433. dataPendingMutex() {}
  434. CarlaPlugin::ProtectedData::PostRtEvents::~PostRtEvents() noexcept
  435. {
  436. dataMutex.lock();
  437. data.clear();
  438. dataMutex.unlock();
  439. dataPendingMutex.lock();
  440. dataPendingRT.clear();
  441. dataPendingMutex.unlock();
  442. }
  443. void CarlaPlugin::ProtectedData::PostRtEvents::appendRT(const PluginPostRtEvent& e) noexcept
  444. {
  445. CARLA_SAFE_ASSERT_INT2_RETURN(dataPendingMutex.tryLock(), e.type, e.value1,);
  446. dataPendingRT.append(e);
  447. dataPendingMutex.unlock();
  448. }
  449. void CarlaPlugin::ProtectedData::PostRtEvents::trySplice() noexcept
  450. {
  451. const CarlaMutexTryLocker cmtl(dataPendingMutex);
  452. if (cmtl.wasLocked() && dataPendingRT.count() > 0 && dataMutex.tryLock())
  453. {
  454. dataPendingRT.moveTo(data, true);
  455. dataMutex.unlock();
  456. }
  457. }
  458. void CarlaPlugin::ProtectedData::PostRtEvents::clearData() noexcept
  459. {
  460. const bool tryLockOk(dataMutex.tryLock());
  461. CARLA_SAFE_ASSERT(! tryLockOk);
  462. data.clear();
  463. if (tryLockOk)
  464. dataMutex.unlock();
  465. }
  466. // -----------------------------------------------------------------------
  467. // ProtectedData::PostUiEvents
  468. CarlaPlugin::ProtectedData::PostUiEvents::PostUiEvents() noexcept
  469. : mutex(),
  470. data() {}
  471. CarlaPlugin::ProtectedData::PostUiEvents::~PostUiEvents() noexcept
  472. {
  473. clear();
  474. }
  475. void CarlaPlugin::ProtectedData::PostUiEvents::append(const PluginPostRtEvent& e) noexcept
  476. {
  477. mutex.lock();
  478. data.append(e);
  479. mutex.unlock();
  480. }
  481. void CarlaPlugin::ProtectedData::PostUiEvents::clear() noexcept
  482. {
  483. mutex.lock();
  484. data.clear();
  485. mutex.unlock();
  486. }
  487. #ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH
  488. // -----------------------------------------------------------------------
  489. // ProtectedData::PostProc
  490. CarlaPlugin::ProtectedData::PostProc::PostProc() noexcept
  491. : dryWet(1.0f),
  492. volume(1.0f),
  493. balanceLeft(-1.0f),
  494. balanceRight(1.0f),
  495. panning(0.0f) {}
  496. #endif
  497. // -----------------------------------------------------------------------
  498. CarlaPlugin::ProtectedData::ProtectedData(CarlaEngine* const eng, const uint idx) noexcept
  499. : engine(eng),
  500. client(nullptr),
  501. id(idx),
  502. hints(0x0),
  503. options(0x0),
  504. nodeId(0),
  505. active(false),
  506. enabled(false),
  507. needsReset(false),
  508. engineBridged(eng->getType() == kEngineTypeBridge),
  509. enginePlugin(eng->getType() == kEngineTypePlugin),
  510. lib(nullptr),
  511. uiLib(nullptr),
  512. ctrlChannel(0),
  513. extraHints(0x0),
  514. #ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH
  515. transientTryCounter(0),
  516. transientFirstTry(true),
  517. #endif
  518. name(nullptr),
  519. filename(nullptr),
  520. iconName(nullptr),
  521. audioIn(),
  522. audioOut(),
  523. cvIn(),
  524. cvOut(),
  525. event(),
  526. param(),
  527. prog(),
  528. midiprog(),
  529. custom(),
  530. masterMutex(),
  531. singleMutex(),
  532. stateSave(),
  533. extNotes(),
  534. latency(),
  535. postRtEvents(),
  536. postUiEvents()
  537. #ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH
  538. , postProc()
  539. #endif
  540. {}
  541. CarlaPlugin::ProtectedData::~ProtectedData() noexcept
  542. {
  543. CARLA_SAFE_ASSERT(! (active && needsReset));
  544. #ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH
  545. CARLA_SAFE_ASSERT(transientTryCounter == 0);
  546. #endif
  547. {
  548. // mutex MUST have been locked before
  549. const bool lockMaster(masterMutex.tryLock());
  550. const bool lockSingle(singleMutex.tryLock());
  551. CARLA_SAFE_ASSERT(! lockMaster);
  552. CARLA_SAFE_ASSERT(! lockSingle);
  553. }
  554. if (client != nullptr)
  555. {
  556. if (client->isActive())
  557. {
  558. // must not happen
  559. carla_safe_assert("client->isActive()", __FILE__, __LINE__);
  560. client->deactivate();
  561. }
  562. clearBuffers();
  563. delete client;
  564. client = nullptr;
  565. }
  566. if (name != nullptr)
  567. {
  568. delete[] name;
  569. name = nullptr;
  570. }
  571. if (filename != nullptr)
  572. {
  573. delete[] filename;
  574. filename = nullptr;
  575. }
  576. if (iconName != nullptr)
  577. {
  578. delete[] iconName;
  579. iconName = nullptr;
  580. }
  581. for (LinkedList<CustomData>::Itenerator it = custom.begin2(); it.valid(); it.next())
  582. {
  583. CustomData& customData(it.getValue(kCustomDataFallbackNC));
  584. //CARLA_SAFE_ASSERT_CONTINUE(customData.isValid());
  585. if (customData.type != nullptr)
  586. {
  587. delete[] customData.type;
  588. customData.type = nullptr;
  589. }
  590. else
  591. carla_safe_assert("customData.type != nullptr", __FILE__, __LINE__);
  592. if (customData.key != nullptr)
  593. {
  594. delete[] customData.key;
  595. customData.key = nullptr;
  596. }
  597. else
  598. carla_safe_assert("customData.key != nullptr", __FILE__, __LINE__);
  599. if (customData.value != nullptr)
  600. {
  601. delete[] customData.value;
  602. customData.value = nullptr;
  603. }
  604. else
  605. carla_safe_assert("customData.value != nullptr", __FILE__, __LINE__);
  606. }
  607. prog.clear();
  608. midiprog.clear();
  609. custom.clear();
  610. // MUST have been locked before
  611. masterMutex.unlock();
  612. singleMutex.unlock();
  613. CARLA_SAFE_ASSERT(uiLib == nullptr);
  614. if (lib != nullptr)
  615. libClose();
  616. }
  617. // -----------------------------------------------------------------------
  618. // Buffer functions
  619. void CarlaPlugin::ProtectedData::clearBuffers() noexcept
  620. {
  621. audioIn.clear();
  622. audioOut.clear();
  623. cvIn.clear();
  624. cvOut.clear();
  625. param.clear();
  626. event.clear();
  627. #ifndef BUILD_BRIDGE
  628. latency.clearBuffers();
  629. #endif
  630. }
  631. // -----------------------------------------------------------------------
  632. // Post-poned events
  633. void CarlaPlugin::ProtectedData::postponeRtEvent(const PluginPostRtEvent& rtEvent) noexcept
  634. {
  635. CARLA_SAFE_ASSERT_RETURN(rtEvent.type != kPluginPostRtEventNull,);
  636. postRtEvents.appendRT(rtEvent);
  637. }
  638. void CarlaPlugin::ProtectedData::postponeRtEvent(const PluginPostRtEventType type,
  639. const bool sendCallbackLater,
  640. const int32_t value1,
  641. const int32_t value2,
  642. const int32_t value3,
  643. const float valuef) noexcept
  644. {
  645. CARLA_SAFE_ASSERT_RETURN(type != kPluginPostRtEventNull,);
  646. PluginPostRtEvent rtEvent = { type, sendCallbackLater, value1, value2, value3, valuef };
  647. postRtEvents.appendRT(rtEvent);
  648. }
  649. // -----------------------------------------------------------------------
  650. // Library functions
  651. static LibCounter sLibCounter;
  652. const char* CarlaPlugin::ProtectedData::libError(const char* const fname) noexcept
  653. {
  654. return lib_error(fname);
  655. }
  656. bool CarlaPlugin::ProtectedData::libOpen(const char* const fname) noexcept
  657. {
  658. lib = sLibCounter.open(fname);
  659. return (lib != nullptr);
  660. }
  661. bool CarlaPlugin::ProtectedData::libClose() noexcept
  662. {
  663. const bool ret = sLibCounter.close(lib);
  664. lib = nullptr;
  665. return ret;
  666. }
  667. void CarlaPlugin::ProtectedData::setCanDeleteLib(const bool canDelete) noexcept
  668. {
  669. sLibCounter.setCanDelete(lib, canDelete);
  670. }
  671. bool CarlaPlugin::ProtectedData::uiLibOpen(const char* const fname, const bool canDelete) noexcept
  672. {
  673. uiLib = sLibCounter.open(fname, canDelete);
  674. return (uiLib != nullptr);
  675. }
  676. bool CarlaPlugin::ProtectedData::uiLibClose() noexcept
  677. {
  678. const bool ret = sLibCounter.close(uiLib);
  679. uiLib = nullptr;
  680. return ret;
  681. }
  682. // -----------------------------------------------------------------------
  683. #ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH
  684. void CarlaPlugin::ProtectedData::tryTransient() noexcept
  685. {
  686. if (engine->getOptions().frontendWinId != 0)
  687. transientTryCounter = 1;
  688. }
  689. #endif
  690. void CarlaPlugin::ProtectedData::updateParameterValues(CarlaPlugin* const plugin,
  691. const bool sendCallback,
  692. const bool sendOsc,
  693. const bool useDefault) noexcept
  694. {
  695. CARLA_SAFE_ASSERT_RETURN(sendOsc || sendCallback || useDefault,);
  696. for (uint32_t i=0; i < param.count; ++i)
  697. {
  698. const float value(param.ranges[i].getFixedValue(plugin->getParameterValue(i)));
  699. if (useDefault)
  700. param.ranges[i].def = value;
  701. if (useDefault) {
  702. engine->callback(sendCallback, sendOsc,
  703. ENGINE_CALLBACK_PARAMETER_DEFAULT_CHANGED,
  704. id,
  705. static_cast<int>(i),
  706. 0, 0,
  707. value,
  708. nullptr);
  709. }
  710. engine->callback(sendCallback, sendOsc,
  711. ENGINE_CALLBACK_PARAMETER_VALUE_CHANGED,
  712. id,
  713. static_cast<int>(i),
  714. 0, 0,
  715. value,
  716. nullptr);
  717. }
  718. }
  719. void CarlaPlugin::ProtectedData::updateDefaultParameterValues(CarlaPlugin* const plugin) noexcept
  720. {
  721. for (uint32_t i=0; i < param.count; ++i)
  722. param.ranges[i].def = param.ranges[i].getFixedValue(plugin->getParameterValue(i));
  723. }
  724. // -----------------------------------------------------------------------
  725. CARLA_BACKEND_END_NAMESPACE