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.

874 lines
21KB

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