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.

CarlaPluginInternal.cpp 19KB

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