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.

CarlaPluginDSSI.cpp 102KB

11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
9 years ago
11 years ago
8 years ago
8 years ago
9 years ago
9 years ago
9 years ago
9 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
10 years ago
10 years ago
10 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
10 years ago
11 years ago
11 years ago
11 years ago
10 years ago
10 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
10 years ago
11 years ago
11 years ago
11 years ago
11 years ago
10 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
10 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
10 years ago
11 years ago
11 years ago
10 years ago
11 years ago
11 years ago
11 years ago
10 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
10 years ago
11 years ago
11 years ago
10 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
10 years ago
11 years ago
11 years ago
11 years ago
11 years ago
10 years ago
10 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
10 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
8 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
10 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810
  1. /*
  2. * Carla Plugin, DSSI implementation
  3. * Copyright (C) 2011-2017 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 "CarlaEngineUtils.hpp"
  19. #include "CarlaDssiUtils.hpp"
  20. #include "CarlaMathUtils.hpp"
  21. #ifdef HAVE_LIBLO
  22. # include "CarlaOscUtils.hpp"
  23. # include "CarlaPipeUtils.hpp"
  24. # include "CarlaThread.hpp"
  25. #endif
  26. #include "water/threads/ChildProcess.h"
  27. using water::ChildProcess;
  28. using water::String;
  29. using water::StringArray;
  30. #define CARLA_PLUGIN_DSSI_OSC_CHECK_OSC_TYPES(/* argc, types, */ argcToCompare, typesToCompare) \
  31. /* check argument count */ \
  32. if (argc != argcToCompare) \
  33. { \
  34. carla_stderr("CarlaPluginDSSI::%s() - argument count mismatch: %i != %i", __FUNCTION__, argc, argcToCompare); \
  35. return; \
  36. } \
  37. if (argc > 0) \
  38. { \
  39. /* check for nullness */ \
  40. if (types == nullptr || typesToCompare == nullptr) \
  41. { \
  42. carla_stderr("CarlaPluginDSSI::%s() - argument types are null", __FUNCTION__); \
  43. return; \
  44. } \
  45. /* check argument types */ \
  46. if (std::strcmp(types, typesToCompare) != 0) \
  47. { \
  48. carla_stderr("CarlaPluginDSSI::%s() - argument types mismatch: '%s' != '%s'", __FUNCTION__, types, typesToCompare); \
  49. return; \
  50. } \
  51. }
  52. CARLA_BACKEND_START_NAMESPACE
  53. // -------------------------------------------------------------------
  54. // Fallback data
  55. static const CustomData kCustomDataFallback = { nullptr, nullptr, nullptr };
  56. #ifdef HAVE_LIBLO
  57. // -------------------------------------------------------------------
  58. class CarlaThreadDSSIUI : public CarlaThread
  59. {
  60. public:
  61. CarlaThreadDSSIUI(CarlaEngine* const engine, CarlaPlugin* const plugin, const CarlaOscData& oscData) noexcept
  62. : CarlaThread("CarlaThreadDSSIUI"),
  63. kEngine(engine),
  64. kPlugin(plugin),
  65. fBinary(),
  66. fLabel(),
  67. fOscData(oscData),
  68. fProcess() {}
  69. void setData(const char* const binary, const char* const label) noexcept
  70. {
  71. CARLA_SAFE_ASSERT_RETURN(binary != nullptr && binary[0] != '\0',);
  72. CARLA_SAFE_ASSERT_RETURN(label != nullptr /*&& label[0] != '\0'*/,);
  73. CARLA_SAFE_ASSERT(! isThreadRunning());
  74. fBinary = binary;
  75. fLabel = label;
  76. if (fLabel.isEmpty())
  77. fLabel = "\"\"";
  78. }
  79. uintptr_t getProcessId() const noexcept
  80. {
  81. CARLA_SAFE_ASSERT_RETURN(fProcess != nullptr, 0);
  82. return (uintptr_t)fProcess->getPID();
  83. }
  84. void run()
  85. {
  86. carla_stdout("DSSI UI thread started");
  87. if (fProcess == nullptr)
  88. {
  89. fProcess = new ChildProcess();
  90. }
  91. else if (fProcess->isRunning())
  92. {
  93. carla_stderr("CarlaThreadDSSI::run() - already running, giving up...");
  94. fProcess->kill();
  95. fProcess = nullptr;
  96. kEngine->callback(CarlaBackend::ENGINE_CALLBACK_UI_STATE_CHANGED, kPlugin->getId(), 0, 0, 0.0f, nullptr);
  97. return;
  98. }
  99. String name(kPlugin->getName());
  100. String filename(kPlugin->getFilename());
  101. if (name.isEmpty())
  102. name = "(none)";
  103. if (filename.isEmpty())
  104. filename = "\"\"";
  105. StringArray arguments;
  106. // binary
  107. arguments.add(fBinary.buffer());
  108. // osc-url
  109. arguments.add(String(kEngine->getOscServerPathUDP()) + String("/") + String(kPlugin->getId()));
  110. // filename
  111. arguments.add(filename);
  112. // label
  113. arguments.add(fLabel.buffer());
  114. // ui-title
  115. arguments.add(name + String(" (GUI)"));
  116. bool started;
  117. {
  118. #ifdef CARLA_OS_LINUX
  119. /*
  120. * If the frontend uses winId parent, set LD_PRELOAD to auto-map the DSSI UI.
  121. * If not, unset LD_PRELOAD.
  122. */
  123. const uintptr_t winId(kEngine->getOptions().frontendWinId);
  124. // for CARLA_ENGINE_OPTION_FRONTEND_WIN_ID
  125. char winIdStr[STR_MAX+1];
  126. winIdStr[STR_MAX] = '\0';
  127. // for LD_PRELOAD
  128. CarlaString ldPreloadValue;
  129. if (winId != 0)
  130. {
  131. std::snprintf(winIdStr, STR_MAX, P_UINTPTR, winId);
  132. ldPreloadValue = (CarlaString(kEngine->getOptions().binaryDir)
  133. + "/libcarla_interposer-x11.so");
  134. }
  135. else
  136. {
  137. winIdStr[0] = '\0';
  138. }
  139. const ScopedEngineEnvironmentLocker _seel(kEngine);
  140. const ScopedEnvVar _sev1("CARLA_ENGINE_OPTION_FRONTEND_WIN_ID", winIdStr[0] != '\0' ? winIdStr : nullptr);
  141. const ScopedEnvVar _sev2("LD_PRELOAD", ldPreloadValue.isNotEmpty() ? ldPreloadValue.buffer() : nullptr);
  142. #endif // CARLA_OS_LINUX
  143. // start the DSSI UI application
  144. carla_stdout("starting DSSI UI...");
  145. started = fProcess->start(arguments);
  146. }
  147. if (! started)
  148. {
  149. carla_stdout("failed!");
  150. fProcess = nullptr;
  151. return;
  152. }
  153. if (waitForOscGuiShow())
  154. {
  155. for (; fProcess->isRunning() && ! shouldThreadExit();)
  156. carla_sleep(1);
  157. // we only get here if UI was closed or thread asked to exit
  158. if (fProcess->isRunning() && shouldThreadExit())
  159. {
  160. fProcess->waitForProcessToFinish(static_cast<int>(kEngine->getOptions().uiBridgesTimeout));
  161. if (fProcess->isRunning())
  162. {
  163. carla_stdout("CarlaThreadDSSIUI::run() - UI refused to close, force kill now");
  164. fProcess->kill();
  165. }
  166. else
  167. {
  168. carla_stdout("CarlaThreadDSSIUI::run() - UI auto-closed successfully");
  169. }
  170. }
  171. else if (fProcess->getExitCode() != 0 /*|| fProcess->exitStatus() == QProcess::CrashExit*/)
  172. carla_stderr("CarlaThreadDSSIUI::run() - UI crashed while running");
  173. else
  174. carla_stdout("CarlaThreadDSSIUI::run() - UI closed cleanly");
  175. }
  176. else
  177. {
  178. fProcess->kill();
  179. carla_stdout("CarlaThreadDSSIUI::run() - GUI timeout");
  180. }
  181. fProcess = nullptr;
  182. kEngine->callback(CarlaBackend::ENGINE_CALLBACK_UI_STATE_CHANGED, kPlugin->getId(), 0, 0, 0.0f, nullptr);
  183. carla_stdout("DSSI UI thread finished");
  184. }
  185. private:
  186. CarlaEngine* const kEngine;
  187. CarlaPlugin* const kPlugin;
  188. CarlaString fBinary;
  189. CarlaString fLabel;
  190. const CarlaOscData& fOscData;
  191. ScopedPointer<ChildProcess> fProcess;
  192. bool waitForOscGuiShow()
  193. {
  194. carla_stdout("CarlaThreadDSSIUI::waitForOscGuiShow()");
  195. const uint uiBridgesTimeout = kEngine->getOptions().uiBridgesTimeout;
  196. // wait for UI 'update' call
  197. for (uint i=0; i < uiBridgesTimeout/100; ++i)
  198. {
  199. if (fOscData.target != nullptr)
  200. {
  201. carla_stdout("CarlaThreadDSSIUI::waitForOscGuiShow() - got response, asking UI to show itself now");
  202. osc_send_show(fOscData);
  203. return true;
  204. }
  205. if (fProcess != nullptr && fProcess->isRunning() && ! shouldThreadExit())
  206. carla_msleep(100);
  207. else
  208. return false;
  209. }
  210. carla_stdout("CarlaThreadDSSIUI::waitForOscGuiShow() - Timeout while waiting for UI to respond"
  211. "(waited %u msecs)", uiBridgesTimeout);
  212. return false;
  213. }
  214. CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(CarlaThreadDSSIUI)
  215. };
  216. #endif
  217. // -----------------------------------------------------
  218. class CarlaPluginDSSI : public CarlaPlugin
  219. {
  220. public:
  221. CarlaPluginDSSI(CarlaEngine* const engine, const uint id) noexcept
  222. : CarlaPlugin(engine, id),
  223. fHandles(),
  224. fDescriptor(nullptr),
  225. fDssiDescriptor(nullptr),
  226. fAudioInBuffers(nullptr),
  227. fAudioOutBuffers(nullptr),
  228. fExtraStereoBuffer(),
  229. fParamBuffers(nullptr),
  230. fLatencyIndex(-1),
  231. fForcedStereoIn(false),
  232. fForcedStereoOut(false),
  233. fNeedsFixedBuffers(false),
  234. fUsesCustomData(false)
  235. #ifdef HAVE_LIBLO
  236. , fOscData(),
  237. fThreadUI(engine, this, fOscData),
  238. fUiFilename(nullptr)
  239. #endif
  240. {
  241. carla_debug("CarlaPluginDSSI::CarlaPluginDSSI(%p, %i)", engine, id);
  242. carla_zeroPointers(fExtraStereoBuffer, 2);
  243. }
  244. ~CarlaPluginDSSI() noexcept override
  245. {
  246. carla_debug("CarlaPluginDSSI::~CarlaPluginDSSI()");
  247. #ifdef HAVE_LIBLO
  248. // close UI
  249. if (fUiFilename != nullptr)
  250. {
  251. showCustomUI(false);
  252. delete[] fUiFilename;
  253. fUiFilename = nullptr;
  254. }
  255. #endif
  256. pData->singleMutex.lock();
  257. pData->masterMutex.lock();
  258. if (pData->client != nullptr && pData->client->isActive())
  259. pData->client->deactivate();
  260. if (pData->active)
  261. {
  262. deactivate();
  263. pData->active = false;
  264. }
  265. if (fDescriptor != nullptr)
  266. {
  267. if (fDescriptor->cleanup != nullptr)
  268. {
  269. for (LinkedList<LADSPA_Handle>::Itenerator it = fHandles.begin2(); it.valid(); it.next())
  270. {
  271. LADSPA_Handle const handle(it.getValue(nullptr));
  272. CARLA_SAFE_ASSERT_CONTINUE(handle != nullptr);
  273. try {
  274. fDescriptor->cleanup(handle);
  275. } CARLA_SAFE_EXCEPTION("LADSPA cleanup");
  276. }
  277. }
  278. fHandles.clear();
  279. fDescriptor = nullptr;
  280. fDssiDescriptor = nullptr;
  281. }
  282. clearBuffers();
  283. }
  284. // -------------------------------------------------------------------
  285. // Information (base)
  286. PluginType getType() const noexcept override
  287. {
  288. return PLUGIN_DSSI;
  289. }
  290. PluginCategory getCategory() const noexcept override
  291. {
  292. CARLA_SAFE_ASSERT_RETURN(fDssiDescriptor != nullptr, PLUGIN_CATEGORY_NONE);
  293. if (pData->audioIn.count == 0 && pData->audioOut.count > 0 && fDssiDescriptor->run_synth != nullptr)
  294. return PLUGIN_CATEGORY_SYNTH;
  295. return CarlaPlugin::getCategory();
  296. }
  297. int64_t getUniqueId() const noexcept override
  298. {
  299. CARLA_SAFE_ASSERT_RETURN(fDescriptor != nullptr, 0);
  300. return static_cast<int64_t>(fDescriptor->UniqueID);
  301. }
  302. uint32_t getLatencyInFrames() const noexcept override
  303. {
  304. if (fLatencyIndex < 0 || fParamBuffers == nullptr)
  305. return 0;
  306. const float latency(fParamBuffers[fLatencyIndex]);
  307. CARLA_SAFE_ASSERT_RETURN(latency >= 0.0f, 0);
  308. return static_cast<uint32_t>(latency);
  309. }
  310. // -------------------------------------------------------------------
  311. // Information (count)
  312. // nothing
  313. // -------------------------------------------------------------------
  314. // Information (current data)
  315. std::size_t getChunkData(void** const dataPtr) noexcept override
  316. {
  317. CARLA_SAFE_ASSERT_RETURN(fUsesCustomData, 0);
  318. CARLA_SAFE_ASSERT_RETURN(pData->options & PLUGIN_OPTION_USE_CHUNKS, 0);
  319. CARLA_SAFE_ASSERT_RETURN(fDssiDescriptor != nullptr, 0);
  320. CARLA_SAFE_ASSERT_RETURN(fDssiDescriptor->get_custom_data != nullptr, 0);
  321. CARLA_SAFE_ASSERT_RETURN(fHandles.count() > 0, 0);
  322. CARLA_SAFE_ASSERT_RETURN(dataPtr != nullptr, 0);
  323. *dataPtr = nullptr;
  324. int ret = 0;
  325. ulong dataSize = 0;
  326. try {
  327. ret = fDssiDescriptor->get_custom_data(fHandles.getFirst(nullptr), dataPtr, &dataSize);
  328. } CARLA_SAFE_EXCEPTION_RETURN("CarlaPluginDSSI::getChunkData", 0);
  329. return (ret != 0) ? dataSize : 0;
  330. }
  331. // -------------------------------------------------------------------
  332. // Information (per-plugin data)
  333. uint getOptionsAvailable() const noexcept override
  334. {
  335. CARLA_SAFE_ASSERT_RETURN(fDssiDescriptor != nullptr, 0x0);
  336. uint options = 0x0;
  337. // can't disable fixed buffers if using latency
  338. if (fLatencyIndex == -1 && ! fNeedsFixedBuffers)
  339. options |= PLUGIN_OPTION_FIXED_BUFFERS;
  340. // can't disable forced stereo if enabled in the engine
  341. if (pData->engine->getOptions().forceStereo)
  342. pass();
  343. // if inputs or outputs are just 1, then yes we can force stereo
  344. else if (pData->audioIn.count == 1 || pData->audioOut.count == 1 || fForcedStereoIn || fForcedStereoOut)
  345. options |= PLUGIN_OPTION_FORCE_STEREO;
  346. if (fDssiDescriptor->get_program != nullptr && fDssiDescriptor->select_program != nullptr)
  347. options |= PLUGIN_OPTION_MAP_PROGRAM_CHANGES;
  348. if (fUsesCustomData)
  349. options |= PLUGIN_OPTION_USE_CHUNKS;
  350. if (fDssiDescriptor->run_synth != nullptr)
  351. {
  352. options |= PLUGIN_OPTION_SEND_CONTROL_CHANGES;
  353. options |= PLUGIN_OPTION_SEND_CHANNEL_PRESSURE;
  354. options |= PLUGIN_OPTION_SEND_NOTE_AFTERTOUCH;
  355. options |= PLUGIN_OPTION_SEND_PITCHBEND;
  356. options |= PLUGIN_OPTION_SEND_ALL_SOUND_OFF;
  357. }
  358. return options;
  359. }
  360. float getParameterValue(const uint32_t parameterId) const noexcept override
  361. {
  362. CARLA_SAFE_ASSERT_RETURN(fParamBuffers != nullptr, 0.0f);
  363. CARLA_SAFE_ASSERT_RETURN(parameterId < pData->param.count, 0.0f);
  364. // bad plugins might have set output values out of bounds
  365. if (pData->param.data[parameterId].type == PARAMETER_OUTPUT)
  366. return pData->param.ranges[parameterId].getFixedValue(fParamBuffers[parameterId]);
  367. // not output, should be fine
  368. return fParamBuffers[parameterId];
  369. }
  370. void getLabel(char* const strBuf) const noexcept override
  371. {
  372. CARLA_SAFE_ASSERT_RETURN(fDescriptor != nullptr, nullStrBuf(strBuf));
  373. CARLA_SAFE_ASSERT_RETURN(fDescriptor->Label != nullptr, nullStrBuf(strBuf));
  374. std::strncpy(strBuf, fDescriptor->Label, STR_MAX);
  375. }
  376. void getMaker(char* const strBuf) const noexcept override
  377. {
  378. CARLA_SAFE_ASSERT_RETURN(fDescriptor != nullptr, nullStrBuf(strBuf));
  379. CARLA_SAFE_ASSERT_RETURN(fDescriptor->Maker != nullptr, nullStrBuf(strBuf));
  380. std::strncpy(strBuf, fDescriptor->Maker, STR_MAX);
  381. }
  382. void getCopyright(char* const strBuf) const noexcept override
  383. {
  384. CARLA_SAFE_ASSERT_RETURN(fDescriptor != nullptr, nullStrBuf(strBuf));
  385. CARLA_SAFE_ASSERT_RETURN(fDescriptor->Copyright != nullptr, nullStrBuf(strBuf));
  386. std::strncpy(strBuf, fDescriptor->Copyright, STR_MAX);
  387. }
  388. void getRealName(char* const strBuf) const noexcept override
  389. {
  390. CARLA_SAFE_ASSERT_RETURN(fDescriptor != nullptr, nullStrBuf(strBuf));
  391. CARLA_SAFE_ASSERT_RETURN(fDescriptor->Name != nullptr, nullStrBuf(strBuf));
  392. std::strncpy(strBuf, fDescriptor->Name, STR_MAX);
  393. }
  394. void getParameterName(const uint32_t parameterId, char* const strBuf) const noexcept override
  395. {
  396. CARLA_SAFE_ASSERT_RETURN(fDescriptor != nullptr, nullStrBuf(strBuf));
  397. CARLA_SAFE_ASSERT_RETURN(parameterId < pData->param.count, nullStrBuf(strBuf));
  398. const int32_t rindex(pData->param.data[parameterId].rindex);
  399. CARLA_SAFE_ASSERT_RETURN(rindex >= 0, nullStrBuf(strBuf));
  400. CARLA_SAFE_ASSERT_RETURN(rindex < static_cast<int32_t>(fDescriptor->PortCount), nullStrBuf(strBuf));
  401. CARLA_SAFE_ASSERT_RETURN(fDescriptor->PortNames[rindex] != nullptr, nullStrBuf(strBuf));
  402. if (getSeparatedParameterNameOrUnit(fDescriptor->PortNames[rindex], strBuf, true))
  403. return;
  404. std::strncpy(strBuf, fDescriptor->PortNames[rindex], STR_MAX);
  405. }
  406. void getParameterUnit(const uint32_t parameterId, char* const strBuf) const noexcept override
  407. {
  408. CARLA_SAFE_ASSERT_RETURN(parameterId < pData->param.count, nullStrBuf(strBuf));
  409. const int32_t rindex(pData->param.data[parameterId].rindex);
  410. CARLA_SAFE_ASSERT_RETURN(rindex >= 0, nullStrBuf(strBuf));
  411. CARLA_SAFE_ASSERT_RETURN(rindex < static_cast<int32_t>(fDescriptor->PortCount), nullStrBuf(strBuf));
  412. CARLA_SAFE_ASSERT_RETURN(fDescriptor->PortNames[rindex] != nullptr, nullStrBuf(strBuf));
  413. if (getSeparatedParameterNameOrUnit(fDescriptor->PortNames[rindex], strBuf, false))
  414. return;
  415. nullStrBuf(strBuf);
  416. }
  417. // -------------------------------------------------------------------
  418. // Set data (state)
  419. // nothing
  420. // -------------------------------------------------------------------
  421. // Set data (internal stuff)
  422. void setId(const uint newId) noexcept override
  423. {
  424. CarlaPlugin::setId(newId);
  425. // UI osc-url uses Id, so we need to close it when it changes
  426. // FIXME - must be RT safe
  427. showCustomUI(false);
  428. }
  429. // -------------------------------------------------------------------
  430. // Set data (plugin-specific stuff)
  431. void setParameterValue(const uint32_t parameterId, const float value, const bool sendGui, const bool sendOsc, const bool sendCallback) noexcept override
  432. {
  433. CARLA_SAFE_ASSERT_RETURN(fParamBuffers != nullptr,);
  434. CARLA_SAFE_ASSERT_RETURN(parameterId < pData->param.count,);
  435. const float fixedValue(pData->param.getFixedValue(parameterId, value));
  436. fParamBuffers[parameterId] = fixedValue;
  437. CarlaPlugin::setParameterValue(parameterId, fixedValue, sendGui, sendOsc, sendCallback);
  438. }
  439. void setCustomData(const char* const type, const char* const key, const char* const value, const bool sendGui) override
  440. {
  441. CARLA_SAFE_ASSERT_RETURN(fDssiDescriptor != nullptr,);
  442. CARLA_SAFE_ASSERT_RETURN(type != nullptr && type[0] != '\0',);
  443. CARLA_SAFE_ASSERT_RETURN(key != nullptr && key[0] != '\0',);
  444. CARLA_SAFE_ASSERT_RETURN(value != nullptr,);
  445. carla_debug("CarlaPluginDSSI::setCustomData(%s, %s, %s, %s)", type, key, value, bool2str(sendGui));
  446. if (std::strcmp(type, CUSTOM_DATA_TYPE_PROPERTY) == 0)
  447. return CarlaPlugin::setCustomData(type, key, value, sendGui);
  448. if (std::strcmp(type, CUSTOM_DATA_TYPE_STRING) != 0)
  449. return carla_stderr2("CarlaPluginDSSI::setCustomData(\"%s\", \"%s\", \"%s\", %s) - type is not string",
  450. type, key, value, bool2str(sendGui));
  451. if (fDssiDescriptor->configure != nullptr && fHandles.count() > 0)
  452. {
  453. for (LinkedList<LADSPA_Handle>::Itenerator it = fHandles.begin2(); it.valid(); it.next())
  454. {
  455. LADSPA_Handle const handle(it.getValue(nullptr));
  456. CARLA_SAFE_ASSERT_CONTINUE(handle != nullptr);
  457. try {
  458. fDssiDescriptor->configure(handle, key, value);
  459. } CARLA_SAFE_EXCEPTION("DSSI setCustomData");
  460. }
  461. }
  462. #ifdef HAVE_LIBLO
  463. if (sendGui && fOscData.target != nullptr)
  464. osc_send_configure(fOscData, key, value);
  465. #endif
  466. if (std::strcmp(key, "reloadprograms") == 0 || std::strcmp(key, "load") == 0 || std::strncmp(key, "patches", 7) == 0)
  467. {
  468. const ScopedSingleProcessLocker spl(this, true);
  469. reloadPrograms(false);
  470. }
  471. CarlaPlugin::setCustomData(type, key, value, sendGui);
  472. }
  473. void setChunkData(const void* const data, const std::size_t dataSize) override
  474. {
  475. CARLA_SAFE_ASSERT_RETURN(fUsesCustomData,);
  476. CARLA_SAFE_ASSERT_RETURN(pData->options & PLUGIN_OPTION_USE_CHUNKS,);
  477. CARLA_SAFE_ASSERT_RETURN(fDssiDescriptor != nullptr,);
  478. CARLA_SAFE_ASSERT_RETURN(fDssiDescriptor->set_custom_data != nullptr,);
  479. CARLA_SAFE_ASSERT_RETURN(data != nullptr,);
  480. CARLA_SAFE_ASSERT_RETURN(dataSize > 0,);
  481. if (fHandles.count() > 0)
  482. {
  483. const ScopedSingleProcessLocker spl(this, true);
  484. for (LinkedList<LADSPA_Handle>::Itenerator it = fHandles.begin2(); it.valid(); it.next())
  485. {
  486. LADSPA_Handle const handle(it.getValue(nullptr));
  487. CARLA_SAFE_ASSERT_CONTINUE(handle != nullptr);
  488. try {
  489. fDssiDescriptor->set_custom_data(handle, const_cast<void*>(data), static_cast<ulong>(dataSize));
  490. } CARLA_SAFE_EXCEPTION("CarlaPluginDSSI::setChunkData");
  491. }
  492. }
  493. #if defined(HAVE_LIBLO) && ! defined(BUILD_BRIDGE)
  494. const bool sendOsc(pData->engine->isOscControlRegistered());
  495. #else
  496. const bool sendOsc(false);
  497. #endif
  498. pData->updateParameterValues(this, sendOsc, true, false);
  499. }
  500. void setMidiProgram(const int32_t index, const bool sendGui, const bool sendOsc, const bool sendCallback) noexcept override
  501. {
  502. CARLA_SAFE_ASSERT_RETURN(fDssiDescriptor != nullptr,);
  503. CARLA_SAFE_ASSERT_RETURN(fDssiDescriptor->select_program != nullptr,);
  504. CARLA_SAFE_ASSERT_RETURN(index >= -1 && index < static_cast<int32_t>(pData->midiprog.count),);
  505. if (index >= 0 && fHandles.count() > 0)
  506. {
  507. const uint32_t bank(pData->midiprog.data[index].bank);
  508. const uint32_t program(pData->midiprog.data[index].program);
  509. const ScopedSingleProcessLocker spl(this, (sendGui || sendOsc || sendCallback));
  510. for (LinkedList<LADSPA_Handle>::Itenerator it = fHandles.begin2(); it.valid(); it.next())
  511. {
  512. LADSPA_Handle const handle(it.getValue(nullptr));
  513. CARLA_SAFE_ASSERT_CONTINUE(handle != nullptr);
  514. try {
  515. fDssiDescriptor->select_program(handle, bank, program);
  516. } CARLA_SAFE_EXCEPTION("DSSI setMidiProgram")
  517. }
  518. }
  519. CarlaPlugin::setMidiProgram(index, sendGui, sendOsc, sendCallback);
  520. }
  521. #ifdef HAVE_LIBLO
  522. // -------------------------------------------------------------------
  523. // Set ui stuff
  524. void showCustomUI(const bool yesNo) override
  525. {
  526. if (yesNo)
  527. {
  528. fOscData.clear();
  529. fThreadUI.startThread();
  530. }
  531. else
  532. {
  533. pData->transientTryCounter = 0;
  534. if (fOscData.target != nullptr)
  535. {
  536. osc_send_hide(fOscData);
  537. osc_send_quit(fOscData);
  538. fOscData.clear();
  539. }
  540. fThreadUI.stopThread(static_cast<int>(pData->engine->getOptions().uiBridgesTimeout * 2));
  541. }
  542. }
  543. #endif
  544. // -------------------------------------------------------------------
  545. // Plugin state
  546. void reload() override
  547. {
  548. CARLA_SAFE_ASSERT_RETURN(pData->engine != nullptr,);
  549. CARLA_SAFE_ASSERT_RETURN(fDescriptor != nullptr,);
  550. CARLA_SAFE_ASSERT_RETURN(fDssiDescriptor != nullptr,);
  551. CARLA_SAFE_ASSERT_RETURN(fHandles.count() > 0,);
  552. carla_debug("CarlaPluginDSSI::reload() - start");
  553. const EngineProcessMode processMode(pData->engine->getProccessMode());
  554. // Safely disable plugin for reload
  555. const ScopedDisabler sd(this);
  556. if (pData->active)
  557. deactivate();
  558. clearBuffers();
  559. const float sampleRate(static_cast<float>(pData->engine->getSampleRate()));
  560. const uint32_t portCount(getSafePortCount());
  561. uint32_t aIns, aOuts, mIns, params;
  562. aIns = aOuts = mIns = params = 0;
  563. bool forcedStereoIn, forcedStereoOut;
  564. forcedStereoIn = forcedStereoOut = false;
  565. bool needsCtrlIn, needsCtrlOut;
  566. needsCtrlIn = needsCtrlOut = false;
  567. for (uint32_t i=0; i < portCount; ++i)
  568. {
  569. const LADSPA_PortDescriptor portType(fDescriptor->PortDescriptors[i]);
  570. if (LADSPA_IS_PORT_AUDIO(portType))
  571. {
  572. if (LADSPA_IS_PORT_INPUT(portType))
  573. aIns += 1;
  574. else if (LADSPA_IS_PORT_OUTPUT(portType))
  575. aOuts += 1;
  576. }
  577. else if (LADSPA_IS_PORT_CONTROL(portType))
  578. params += 1;
  579. }
  580. if (pData->options & PLUGIN_OPTION_FORCE_STEREO)
  581. {
  582. if ((aIns == 1 || aOuts == 1) && fHandles.count() == 1 && addInstance())
  583. {
  584. if (aIns == 1)
  585. {
  586. aIns = 2;
  587. forcedStereoIn = true;
  588. }
  589. if (aOuts == 1)
  590. {
  591. aOuts = 2;
  592. forcedStereoOut = true;
  593. }
  594. }
  595. }
  596. if (fDssiDescriptor->run_synth != nullptr)
  597. {
  598. mIns = 1;
  599. needsCtrlIn = true;
  600. }
  601. if (aIns > 0)
  602. {
  603. pData->audioIn.createNew(aIns);
  604. fAudioInBuffers = new float*[aIns];
  605. for (uint32_t i=0; i < aIns; ++i)
  606. fAudioInBuffers[i] = nullptr;
  607. }
  608. if (aOuts > 0)
  609. {
  610. pData->audioOut.createNew(aOuts);
  611. fAudioOutBuffers = new float*[aOuts];
  612. needsCtrlIn = true;
  613. for (uint32_t i=0; i < aOuts; ++i)
  614. fAudioOutBuffers[i] = nullptr;
  615. }
  616. if (params > 0)
  617. {
  618. pData->param.createNew(params, true);
  619. fParamBuffers = new float[params];
  620. carla_zeroFloats(fParamBuffers, params);
  621. }
  622. const uint portNameSize(pData->engine->getMaxPortNameSize());
  623. CarlaString portName;
  624. for (uint32_t i=0, iAudioIn=0, iAudioOut=0, iCtrl=0; i < portCount; ++i)
  625. {
  626. const LADSPA_PortDescriptor portType = fDescriptor->PortDescriptors[i];
  627. const LADSPA_PortRangeHint portRangeHints = fDescriptor->PortRangeHints[i];
  628. if (LADSPA_IS_PORT_AUDIO(portType))
  629. {
  630. portName.clear();
  631. if (processMode == ENGINE_PROCESS_MODE_SINGLE_CLIENT)
  632. {
  633. portName = pData->name;
  634. portName += ":";
  635. }
  636. if (fDescriptor->PortNames[i] != nullptr && fDescriptor->PortNames[i][0] != '\0')
  637. {
  638. portName += fDescriptor->PortNames[i];
  639. }
  640. else
  641. {
  642. if (LADSPA_IS_PORT_INPUT(portType))
  643. {
  644. if (aIns > 1)
  645. {
  646. portName += "audio-in_";
  647. portName += CarlaString(iAudioIn+1);
  648. }
  649. else
  650. portName += "audio-in";
  651. }
  652. else
  653. {
  654. if (aOuts > 1)
  655. {
  656. portName += "audio-out_";
  657. portName += CarlaString(iAudioOut+1);
  658. }
  659. else
  660. portName += "audio-out";
  661. }
  662. }
  663. portName.truncate(portNameSize);
  664. if (LADSPA_IS_PORT_INPUT(portType))
  665. {
  666. const uint32_t j = iAudioIn++;
  667. pData->audioIn.ports[j].port = (CarlaEngineAudioPort*)pData->client->addPort(kEnginePortTypeAudio, portName, true, j);
  668. pData->audioIn.ports[j].rindex = i;
  669. if (forcedStereoIn)
  670. {
  671. portName += "_2";
  672. pData->audioIn.ports[1].port = (CarlaEngineAudioPort*)pData->client->addPort(kEnginePortTypeAudio, portName, true, 1);
  673. pData->audioIn.ports[1].rindex = i;
  674. }
  675. }
  676. else if (LADSPA_IS_PORT_OUTPUT(portType))
  677. {
  678. const uint32_t j = iAudioOut++;
  679. pData->audioOut.ports[j].port = (CarlaEngineAudioPort*)pData->client->addPort(kEnginePortTypeAudio, portName, false, j);
  680. pData->audioOut.ports[j].rindex = i;
  681. if (forcedStereoOut)
  682. {
  683. portName += "_2";
  684. pData->audioOut.ports[1].port = (CarlaEngineAudioPort*)pData->client->addPort(kEnginePortTypeAudio, portName, false, 1);
  685. pData->audioOut.ports[1].rindex = i;
  686. }
  687. }
  688. else
  689. carla_stderr2("WARNING - Got a broken Port (Audio, but not input or output)");
  690. }
  691. else if (LADSPA_IS_PORT_CONTROL(portType))
  692. {
  693. const uint32_t j = iCtrl++;
  694. pData->param.data[j].index = static_cast<int32_t>(j);
  695. pData->param.data[j].rindex = static_cast<int32_t>(i);
  696. const char* const paramName(fDescriptor->PortNames[i] != nullptr ? fDescriptor->PortNames[i] : "unknown");
  697. float min, max, def, step, stepSmall, stepLarge;
  698. // min value
  699. if (LADSPA_IS_HINT_BOUNDED_BELOW(portRangeHints.HintDescriptor))
  700. min = portRangeHints.LowerBound;
  701. else
  702. min = 0.0f;
  703. // max value
  704. if (LADSPA_IS_HINT_BOUNDED_ABOVE(portRangeHints.HintDescriptor))
  705. max = portRangeHints.UpperBound;
  706. else
  707. max = 1.0f;
  708. if (LADSPA_IS_HINT_SAMPLE_RATE(portRangeHints.HintDescriptor))
  709. {
  710. min *= sampleRate;
  711. max *= sampleRate;
  712. pData->param.data[j].hints |= PARAMETER_USES_SAMPLERATE;
  713. }
  714. if (min >= max)
  715. {
  716. carla_stderr2("WARNING - Broken plugin parameter '%s': min >= max", paramName);
  717. max = min + 0.1f;
  718. }
  719. // default value
  720. def = get_default_ladspa_port_value(portRangeHints.HintDescriptor, min, max);
  721. if (def < min)
  722. def = min;
  723. else if (def > max)
  724. def = max;
  725. if (LADSPA_IS_HINT_TOGGLED(portRangeHints.HintDescriptor))
  726. {
  727. step = max - min;
  728. stepSmall = step;
  729. stepLarge = step;
  730. pData->param.data[j].hints |= PARAMETER_IS_BOOLEAN;
  731. }
  732. else if (LADSPA_IS_HINT_INTEGER(portRangeHints.HintDescriptor))
  733. {
  734. step = 1.0f;
  735. stepSmall = 1.0f;
  736. stepLarge = 10.0f;
  737. pData->param.data[j].hints |= PARAMETER_IS_INTEGER;
  738. }
  739. else
  740. {
  741. const float range = max - min;
  742. step = range/100.0f;
  743. stepSmall = range/1000.0f;
  744. stepLarge = range/10.0f;
  745. }
  746. if (LADSPA_IS_PORT_INPUT(portType))
  747. {
  748. pData->param.data[j].type = PARAMETER_INPUT;
  749. pData->param.data[j].hints |= PARAMETER_IS_ENABLED;
  750. pData->param.data[j].hints |= PARAMETER_IS_AUTOMABLE;
  751. needsCtrlIn = true;
  752. // MIDI CC value
  753. if (fDssiDescriptor->get_midi_controller_for_port != nullptr)
  754. {
  755. const int ctrl = fDssiDescriptor->get_midi_controller_for_port(fHandles.getFirst(nullptr), i);
  756. if (DSSI_CONTROLLER_IS_SET(ctrl) && DSSI_IS_CC(ctrl))
  757. {
  758. const int16_t cc = DSSI_CC_NUMBER(ctrl);
  759. if (! MIDI_IS_CONTROL_BANK_SELECT(cc))
  760. pData->param.data[j].midiCC = cc;
  761. }
  762. }
  763. }
  764. else if (LADSPA_IS_PORT_OUTPUT(portType))
  765. {
  766. pData->param.data[j].type = PARAMETER_OUTPUT;
  767. if (std::strcmp(paramName, "latency") == 0 || std::strcmp(paramName, "_latency") == 0)
  768. {
  769. min = 0.0f;
  770. max = sampleRate;
  771. def = 0.0f;
  772. step = 1.0f;
  773. stepSmall = 1.0f;
  774. stepLarge = 1.0f;
  775. pData->param.special[j] = PARAMETER_SPECIAL_LATENCY;
  776. CARLA_SAFE_ASSERT_INT2(fLatencyIndex == static_cast<int32_t>(j), fLatencyIndex, j);
  777. }
  778. else
  779. {
  780. pData->param.data[j].hints |= PARAMETER_IS_ENABLED;
  781. pData->param.data[j].hints |= PARAMETER_IS_AUTOMABLE;
  782. needsCtrlOut = true;
  783. }
  784. }
  785. else
  786. {
  787. carla_stderr2("WARNING - Got a broken Port (Control, but not input or output)");
  788. }
  789. // extra parameter hints
  790. if (LADSPA_IS_HINT_LOGARITHMIC(portRangeHints.HintDescriptor))
  791. pData->param.data[j].hints |= PARAMETER_IS_LOGARITHMIC;
  792. pData->param.ranges[j].min = min;
  793. pData->param.ranges[j].max = max;
  794. pData->param.ranges[j].def = def;
  795. pData->param.ranges[j].step = step;
  796. pData->param.ranges[j].stepSmall = stepSmall;
  797. pData->param.ranges[j].stepLarge = stepLarge;
  798. // Start parameters in their default values
  799. fParamBuffers[j] = def;
  800. for (LinkedList<LADSPA_Handle>::Itenerator it = fHandles.begin2(); it.valid(); it.next())
  801. {
  802. LADSPA_Handle const handle(it.getValue(nullptr));
  803. CARLA_SAFE_ASSERT_CONTINUE(handle != nullptr);
  804. try {
  805. fDescriptor->connect_port(handle, i, &fParamBuffers[j]);
  806. } CARLA_SAFE_EXCEPTION("DSSI connect_port (parameter)");
  807. }
  808. }
  809. else
  810. {
  811. // Not Audio or Control
  812. carla_stderr2("ERROR - Got a broken Port (neither Audio or Control)");
  813. for (LinkedList<LADSPA_Handle>::Itenerator it = fHandles.begin2(); it.valid(); it.next())
  814. {
  815. LADSPA_Handle const handle(it.getValue(nullptr));
  816. CARLA_SAFE_ASSERT_CONTINUE(handle != nullptr);
  817. try {
  818. fDescriptor->connect_port(handle, i, nullptr);
  819. } CARLA_SAFE_EXCEPTION("DSSI connect_port (null)");
  820. }
  821. }
  822. }
  823. if (needsCtrlIn)
  824. {
  825. portName.clear();
  826. if (processMode == ENGINE_PROCESS_MODE_SINGLE_CLIENT)
  827. {
  828. portName = pData->name;
  829. portName += ":";
  830. }
  831. portName += "events-in";
  832. portName.truncate(portNameSize);
  833. pData->event.portIn = (CarlaEngineEventPort*)pData->client->addPort(kEnginePortTypeEvent, portName, true, 0);
  834. }
  835. if (needsCtrlOut)
  836. {
  837. portName.clear();
  838. if (processMode == ENGINE_PROCESS_MODE_SINGLE_CLIENT)
  839. {
  840. portName = pData->name;
  841. portName += ":";
  842. }
  843. portName += "events-out";
  844. portName.truncate(portNameSize);
  845. pData->event.portOut = (CarlaEngineEventPort*)pData->client->addPort(kEnginePortTypeEvent, portName, false, 0);
  846. }
  847. if (forcedStereoIn || forcedStereoOut)
  848. pData->options |= PLUGIN_OPTION_FORCE_STEREO;
  849. else
  850. pData->options &= ~PLUGIN_OPTION_FORCE_STEREO;
  851. // plugin hints
  852. pData->hints = 0x0;
  853. if (LADSPA_IS_HARD_RT_CAPABLE(fDescriptor->Properties))
  854. pData->hints |= PLUGIN_IS_RTSAFE;
  855. #ifdef HAVE_LIBLO
  856. if (fUiFilename != nullptr)
  857. pData->hints |= PLUGIN_HAS_CUSTOM_UI;
  858. #endif
  859. #ifndef BUILD_BRIDGE
  860. if (aOuts > 0 && (aIns == aOuts || aIns == 1))
  861. pData->hints |= PLUGIN_CAN_DRYWET;
  862. if (aOuts > 0)
  863. pData->hints |= PLUGIN_CAN_VOLUME;
  864. if (aOuts >= 2 && aOuts % 2 == 0)
  865. pData->hints |= PLUGIN_CAN_BALANCE;
  866. #endif
  867. // extra plugin hints
  868. pData->extraHints = 0x0;
  869. pData->extraHints |= PLUGIN_EXTRA_HINT_CAN_RUN_RACK;
  870. if (mIns > 0)
  871. pData->extraHints |= PLUGIN_EXTRA_HINT_HAS_MIDI_IN;
  872. // check initial latency
  873. findInitialLatencyValue(aIns, aOuts);
  874. fForcedStereoIn = forcedStereoIn;
  875. fForcedStereoOut = forcedStereoOut;
  876. bufferSizeChanged(pData->engine->getBufferSize());
  877. reloadPrograms(true);
  878. if (pData->active)
  879. activate();
  880. carla_debug("CarlaPluginDSSI::reload() - end");
  881. }
  882. void findInitialLatencyValue(const uint32_t aIns, const uint32_t aOuts) const
  883. {
  884. if (fLatencyIndex < 0 || fHandles.count() == 0)
  885. return;
  886. // we need to pre-run the plugin so it can update its latency control-port
  887. const LADSPA_Handle handle(fHandles.getFirst(nullptr));
  888. CARLA_SAFE_ASSERT_RETURN(handle != nullptr,);
  889. float tmpIn [(aIns > 0) ? aIns : 1][2];
  890. float tmpOut[(aOuts > 0) ? aOuts : 1][2];
  891. for (uint32_t j=0; j < aIns; ++j)
  892. {
  893. tmpIn[j][0] = 0.0f;
  894. tmpIn[j][1] = 0.0f;
  895. try {
  896. fDescriptor->connect_port(handle, pData->audioIn.ports[j].rindex, tmpIn[j]);
  897. } CARLA_SAFE_EXCEPTION("DSSI connect_port (latency input)");
  898. }
  899. for (uint32_t j=0; j < aOuts; ++j)
  900. {
  901. tmpOut[j][0] = 0.0f;
  902. tmpOut[j][1] = 0.0f;
  903. try {
  904. fDescriptor->connect_port(handle, pData->audioOut.ports[j].rindex, tmpOut[j]);
  905. } CARLA_SAFE_EXCEPTION("DSSI connect_port (latency output)");
  906. }
  907. if (fDescriptor->activate != nullptr)
  908. {
  909. try {
  910. fDescriptor->activate(handle);
  911. } CARLA_SAFE_EXCEPTION("DSSI latency activate");
  912. }
  913. try {
  914. fDescriptor->run(handle, 2);
  915. } CARLA_SAFE_EXCEPTION("DSSI latency run");
  916. if (fDescriptor->deactivate != nullptr)
  917. {
  918. try {
  919. fDescriptor->deactivate(handle);
  920. } CARLA_SAFE_EXCEPTION("DSSI latency deactivate");
  921. }
  922. // done, let's get the value
  923. if (const uint32_t latency = getLatencyInFrames())
  924. {
  925. pData->client->setLatency(latency);
  926. #ifndef BUILD_BRIDGE
  927. pData->latency.recreateBuffers(std::max(aIns, aOuts), latency);
  928. #endif
  929. }
  930. }
  931. void reloadPrograms(const bool doInit) override
  932. {
  933. carla_debug("CarlaPluginDSSI::reloadPrograms(%s)", bool2str(doInit));
  934. const LADSPA_Handle handle(fHandles.getFirst(nullptr));
  935. CARLA_SAFE_ASSERT_RETURN(handle != nullptr,);
  936. const uint32_t oldCount = pData->midiprog.count;
  937. const int32_t current = pData->midiprog.current;
  938. // Delete old programs
  939. pData->midiprog.clear();
  940. // Query new programs
  941. uint32_t newCount = 0;
  942. if (fDssiDescriptor->get_program != nullptr && fDssiDescriptor->select_program != nullptr)
  943. {
  944. for (; fDssiDescriptor->get_program(handle, newCount) != nullptr;)
  945. ++newCount;
  946. }
  947. if (newCount > 0)
  948. {
  949. pData->midiprog.createNew(newCount);
  950. // Update data
  951. for (uint32_t i=0; i < newCount; ++i)
  952. {
  953. const DSSI_Program_Descriptor* const pdesc(fDssiDescriptor->get_program(handle, i));
  954. CARLA_SAFE_ASSERT_CONTINUE(pdesc != nullptr);
  955. CARLA_SAFE_ASSERT(pdesc->Name != nullptr);
  956. pData->midiprog.data[i].bank = static_cast<uint32_t>(pdesc->Bank);
  957. pData->midiprog.data[i].program = static_cast<uint32_t>(pdesc->Program);
  958. pData->midiprog.data[i].name = carla_strdup(pdesc->Name);
  959. }
  960. }
  961. #if defined(HAVE_LIBLO) && ! defined(BUILD_BRIDGE)
  962. // Update OSC Names
  963. if (pData->engine->isOscControlRegistered() && pData->id < pData->engine->getCurrentPluginCount())
  964. {
  965. pData->engine->oscSend_control_set_midi_program_count(pData->id, newCount);
  966. for (uint32_t i=0; i < newCount; ++i)
  967. pData->engine->oscSend_control_set_midi_program_data(pData->id, i, pData->midiprog.data[i].bank, pData->midiprog.data[i].program, pData->midiprog.data[i].name);
  968. }
  969. #endif
  970. if (doInit)
  971. {
  972. if (newCount > 0)
  973. setMidiProgram(0, false, false, false);
  974. }
  975. else
  976. {
  977. // Check if current program is invalid
  978. bool programChanged = false;
  979. if (newCount == oldCount+1)
  980. {
  981. // one midi program added, probably created by user
  982. pData->midiprog.current = static_cast<int32_t>(oldCount);
  983. programChanged = true;
  984. }
  985. else if (current < 0 && newCount > 0)
  986. {
  987. // programs exist now, but not before
  988. pData->midiprog.current = 0;
  989. programChanged = true;
  990. }
  991. else if (current >= 0 && newCount == 0)
  992. {
  993. // programs existed before, but not anymore
  994. pData->midiprog.current = -1;
  995. programChanged = true;
  996. }
  997. else if (current >= static_cast<int32_t>(newCount))
  998. {
  999. // current midi program > count
  1000. pData->midiprog.current = 0;
  1001. programChanged = true;
  1002. }
  1003. else
  1004. {
  1005. // no change
  1006. pData->midiprog.current = current;
  1007. }
  1008. if (programChanged)
  1009. setMidiProgram(pData->midiprog.current, true, true, true);
  1010. pData->engine->callback(ENGINE_CALLBACK_RELOAD_PROGRAMS, pData->id, 0, 0, 0.0f, nullptr);
  1011. }
  1012. }
  1013. // -------------------------------------------------------------------
  1014. // Plugin processing
  1015. void activate() noexcept override
  1016. {
  1017. CARLA_SAFE_ASSERT_RETURN(fDescriptor != nullptr,);
  1018. if (fDescriptor->activate != nullptr)
  1019. {
  1020. for (LinkedList<LADSPA_Handle>::Itenerator it = fHandles.begin2(); it.valid(); it.next())
  1021. {
  1022. LADSPA_Handle const handle(it.getValue(nullptr));
  1023. CARLA_SAFE_ASSERT_CONTINUE(handle != nullptr);
  1024. try {
  1025. fDescriptor->activate(handle);
  1026. } CARLA_SAFE_EXCEPTION("DSSI activate");
  1027. }
  1028. }
  1029. }
  1030. void deactivate() noexcept override
  1031. {
  1032. CARLA_SAFE_ASSERT_RETURN(fDescriptor != nullptr,);
  1033. if (fDescriptor->deactivate != nullptr)
  1034. {
  1035. for (LinkedList<LADSPA_Handle>::Itenerator it = fHandles.begin2(); it.valid(); it.next())
  1036. {
  1037. LADSPA_Handle const handle(it.getValue(nullptr));
  1038. CARLA_SAFE_ASSERT_CONTINUE(handle != nullptr);
  1039. try {
  1040. fDescriptor->deactivate(handle);
  1041. } CARLA_SAFE_EXCEPTION("DSSI deactivate");
  1042. }
  1043. }
  1044. }
  1045. void process(const float** const audioIn, float** const audioOut, const float** const, float** const, const uint32_t frames) override
  1046. {
  1047. // --------------------------------------------------------------------------------------------------------
  1048. // Check if active
  1049. if (! pData->active)
  1050. {
  1051. // disable any output sound
  1052. for (uint32_t i=0; i < pData->audioOut.count; ++i)
  1053. carla_zeroFloats(audioOut[i], frames);
  1054. return;
  1055. }
  1056. ulong midiEventCount = 0;
  1057. carla_zeroStructs(fMidiEvents, kPluginMaxMidiEvents);
  1058. // --------------------------------------------------------------------------------------------------------
  1059. // Check if needs reset
  1060. if (pData->needsReset)
  1061. {
  1062. if (pData->options & PLUGIN_OPTION_SEND_ALL_SOUND_OFF)
  1063. {
  1064. midiEventCount = MAX_MIDI_CHANNELS*2;
  1065. for (uchar i=0, k=MAX_MIDI_CHANNELS; i < MAX_MIDI_CHANNELS; ++i)
  1066. {
  1067. fMidiEvents[i].type = SND_SEQ_EVENT_CONTROLLER;
  1068. fMidiEvents[i].data.control.channel = i;
  1069. fMidiEvents[i].data.control.param = MIDI_CONTROL_ALL_NOTES_OFF;
  1070. fMidiEvents[k+i].type = SND_SEQ_EVENT_CONTROLLER;
  1071. fMidiEvents[k+i].data.control.channel = i;
  1072. fMidiEvents[k+i].data.control.param = MIDI_CONTROL_ALL_SOUND_OFF;
  1073. }
  1074. }
  1075. else if (pData->ctrlChannel >= 0 && pData->ctrlChannel < MAX_MIDI_CHANNELS)
  1076. {
  1077. midiEventCount = MAX_MIDI_NOTE;
  1078. for (uchar i=0; i < MAX_MIDI_NOTE; ++i)
  1079. {
  1080. fMidiEvents[i].type = SND_SEQ_EVENT_NOTEOFF;
  1081. fMidiEvents[i].data.note.channel = static_cast<uchar>(pData->ctrlChannel);
  1082. fMidiEvents[i].data.note.note = i;
  1083. }
  1084. }
  1085. pData->needsReset = false;
  1086. }
  1087. // --------------------------------------------------------------------------------------------------------
  1088. // Event Input and Processing
  1089. if (pData->event.portIn != nullptr)
  1090. {
  1091. // ----------------------------------------------------------------------------------------------------
  1092. // MIDI Input (External)
  1093. if (pData->extNotes.mutex.tryLock())
  1094. {
  1095. ExternalMidiNote note = { 0, 0, 0 };
  1096. for (; midiEventCount < kPluginMaxMidiEvents && ! pData->extNotes.data.isEmpty();)
  1097. {
  1098. note = pData->extNotes.data.getFirst(note, true);
  1099. CARLA_SAFE_ASSERT_CONTINUE(note.channel >= 0 && note.channel < MAX_MIDI_CHANNELS);
  1100. snd_seq_event_t& seqEvent(fMidiEvents[midiEventCount++]);
  1101. seqEvent.type = (note.velo > 0) ? SND_SEQ_EVENT_NOTEON : SND_SEQ_EVENT_NOTEOFF;
  1102. seqEvent.data.note.channel = static_cast<uchar>(note.channel);
  1103. seqEvent.data.note.note = note.note;
  1104. seqEvent.data.note.velocity = note.velo;
  1105. }
  1106. pData->extNotes.mutex.unlock();
  1107. } // End of MIDI Input (External)
  1108. // ----------------------------------------------------------------------------------------------------
  1109. // Event Input (System)
  1110. #ifndef BUILD_BRIDGE
  1111. bool allNotesOffSent = false;
  1112. #endif
  1113. const bool isSampleAccurate = (pData->options & PLUGIN_OPTION_FIXED_BUFFERS) == 0;
  1114. uint32_t startTime = 0;
  1115. uint32_t timeOffset = 0;
  1116. uint32_t nextBankId;
  1117. if (pData->midiprog.current >= 0 && pData->midiprog.count > 0)
  1118. nextBankId = pData->midiprog.data[pData->midiprog.current].bank;
  1119. else
  1120. nextBankId = 0;
  1121. for (uint32_t i=0, numEvents=pData->event.portIn->getEventCount(); i < numEvents; ++i)
  1122. {
  1123. const EngineEvent& event(pData->event.portIn->getEvent(i));
  1124. if (event.time >= frames)
  1125. continue;
  1126. CARLA_ASSERT_INT2(event.time >= timeOffset, event.time, timeOffset);
  1127. if (isSampleAccurate && event.time > timeOffset)
  1128. {
  1129. if (processSingle(audioIn, audioOut, event.time - timeOffset, timeOffset, midiEventCount))
  1130. {
  1131. startTime = 0;
  1132. timeOffset = event.time;
  1133. midiEventCount = 0;
  1134. if (pData->midiprog.current >= 0 && pData->midiprog.count > 0)
  1135. nextBankId = pData->midiprog.data[pData->midiprog.current].bank;
  1136. else
  1137. nextBankId = 0;
  1138. }
  1139. else
  1140. startTime += timeOffset;
  1141. }
  1142. switch (event.type)
  1143. {
  1144. case kEngineEventTypeNull:
  1145. break;
  1146. case kEngineEventTypeControl: {
  1147. const EngineControlEvent& ctrlEvent(event.ctrl);
  1148. switch (ctrlEvent.type)
  1149. {
  1150. case kEngineControlEventTypeNull:
  1151. break;
  1152. case kEngineControlEventTypeParameter: {
  1153. #ifndef BUILD_BRIDGE
  1154. // Control backend stuff
  1155. if (event.channel == pData->ctrlChannel)
  1156. {
  1157. float value;
  1158. if (MIDI_IS_CONTROL_BREATH_CONTROLLER(ctrlEvent.param) && (pData->hints & PLUGIN_CAN_DRYWET) != 0)
  1159. {
  1160. value = ctrlEvent.value;
  1161. setDryWet(value, false, false);
  1162. pData->postponeRtEvent(kPluginPostRtEventParameterChange, PARAMETER_DRYWET, 0, value);
  1163. }
  1164. if (MIDI_IS_CONTROL_CHANNEL_VOLUME(ctrlEvent.param) && (pData->hints & PLUGIN_CAN_VOLUME) != 0)
  1165. {
  1166. value = ctrlEvent.value*127.0f/100.0f;
  1167. setVolume(value, false, false);
  1168. pData->postponeRtEvent(kPluginPostRtEventParameterChange, PARAMETER_VOLUME, 0, value);
  1169. }
  1170. if (MIDI_IS_CONTROL_BALANCE(ctrlEvent.param) && (pData->hints & PLUGIN_CAN_BALANCE) != 0)
  1171. {
  1172. float left, right;
  1173. value = ctrlEvent.value/0.5f - 1.0f;
  1174. if (value < 0.0f)
  1175. {
  1176. left = -1.0f;
  1177. right = (value*2.0f)+1.0f;
  1178. }
  1179. else if (value > 0.0f)
  1180. {
  1181. left = (value*2.0f)-1.0f;
  1182. right = 1.0f;
  1183. }
  1184. else
  1185. {
  1186. left = -1.0f;
  1187. right = 1.0f;
  1188. }
  1189. setBalanceLeft(left, false, false);
  1190. setBalanceRight(right, false, false);
  1191. pData->postponeRtEvent(kPluginPostRtEventParameterChange, PARAMETER_BALANCE_LEFT, 0, left);
  1192. pData->postponeRtEvent(kPluginPostRtEventParameterChange, PARAMETER_BALANCE_RIGHT, 0, right);
  1193. }
  1194. }
  1195. #endif
  1196. // Control plugin parameters
  1197. for (uint32_t k=0; k < pData->param.count; ++k)
  1198. {
  1199. if (pData->param.data[k].midiChannel != event.channel)
  1200. continue;
  1201. if (pData->param.data[k].midiCC != ctrlEvent.param)
  1202. continue;
  1203. if (pData->param.data[k].type != PARAMETER_INPUT)
  1204. continue;
  1205. if ((pData->param.data[k].hints & PARAMETER_IS_AUTOMABLE) == 0)
  1206. continue;
  1207. float value;
  1208. if (pData->param.data[k].hints & PARAMETER_IS_BOOLEAN)
  1209. {
  1210. value = (ctrlEvent.value < 0.5f) ? pData->param.ranges[k].min : pData->param.ranges[k].max;
  1211. }
  1212. else
  1213. {
  1214. if (pData->param.data[k].hints & PARAMETER_IS_LOGARITHMIC)
  1215. value = pData->param.ranges[k].getUnnormalizedLogValue(ctrlEvent.value);
  1216. else
  1217. value = pData->param.ranges[k].getUnnormalizedValue(ctrlEvent.value);
  1218. if (pData->param.data[k].hints & PARAMETER_IS_INTEGER)
  1219. value = std::rint(value);
  1220. }
  1221. setParameterValue(k, value, false, false, false);
  1222. pData->postponeRtEvent(kPluginPostRtEventParameterChange, static_cast<int32_t>(k), 0, value);
  1223. }
  1224. if ((pData->options & PLUGIN_OPTION_SEND_CONTROL_CHANGES) != 0 && ctrlEvent.param < MAX_MIDI_CONTROL)
  1225. {
  1226. if (midiEventCount >= kPluginMaxMidiEvents)
  1227. continue;
  1228. snd_seq_event_t& seqEvent(fMidiEvents[midiEventCount++]);
  1229. seqEvent.time.tick = isSampleAccurate ? startTime : event.time;
  1230. seqEvent.type = SND_SEQ_EVENT_CONTROLLER;
  1231. seqEvent.data.control.channel = event.channel;
  1232. seqEvent.data.control.param = ctrlEvent.param;
  1233. seqEvent.data.control.value = int8_t(ctrlEvent.value*127.0f);
  1234. }
  1235. break;
  1236. } // case kEngineControlEventTypeParameter
  1237. case kEngineControlEventTypeMidiBank:
  1238. if (event.channel == pData->ctrlChannel && (pData->options & PLUGIN_OPTION_MAP_PROGRAM_CHANGES) != 0)
  1239. nextBankId = ctrlEvent.param;
  1240. break;
  1241. case kEngineControlEventTypeMidiProgram:
  1242. if (event.channel == pData->ctrlChannel && (pData->options & PLUGIN_OPTION_MAP_PROGRAM_CHANGES) != 0)
  1243. {
  1244. const uint32_t nextProgramId = ctrlEvent.param;
  1245. for (uint32_t k=0; k < pData->midiprog.count; ++k)
  1246. {
  1247. if (pData->midiprog.data[k].bank == nextBankId && pData->midiprog.data[k].program == nextProgramId)
  1248. {
  1249. const int32_t index(static_cast<int32_t>(k));
  1250. setMidiProgram(index, false, false, false);
  1251. pData->postponeRtEvent(kPluginPostRtEventMidiProgramChange, index, 0, 0.0f);
  1252. break;
  1253. }
  1254. }
  1255. }
  1256. break;
  1257. case kEngineControlEventTypeAllSoundOff:
  1258. if (pData->options & PLUGIN_OPTION_SEND_ALL_SOUND_OFF)
  1259. {
  1260. if (midiEventCount >= kPluginMaxMidiEvents)
  1261. continue;
  1262. snd_seq_event_t& seqEvent(fMidiEvents[midiEventCount++]);
  1263. seqEvent.time.tick = isSampleAccurate ? startTime : event.time;
  1264. seqEvent.type = SND_SEQ_EVENT_CONTROLLER;
  1265. seqEvent.data.control.channel = event.channel;
  1266. seqEvent.data.control.param = MIDI_CONTROL_ALL_SOUND_OFF;
  1267. }
  1268. break;
  1269. case kEngineControlEventTypeAllNotesOff:
  1270. if (pData->options & PLUGIN_OPTION_SEND_ALL_SOUND_OFF)
  1271. {
  1272. #ifndef BUILD_BRIDGE
  1273. if (event.channel == pData->ctrlChannel && ! allNotesOffSent)
  1274. {
  1275. allNotesOffSent = true;
  1276. sendMidiAllNotesOffToCallback();
  1277. }
  1278. #endif
  1279. if (midiEventCount >= kPluginMaxMidiEvents)
  1280. continue;
  1281. snd_seq_event_t& seqEvent(fMidiEvents[midiEventCount++]);
  1282. seqEvent.time.tick = isSampleAccurate ? startTime : event.time;
  1283. seqEvent.type = SND_SEQ_EVENT_CONTROLLER;
  1284. seqEvent.data.control.channel = event.channel;
  1285. seqEvent.data.control.param = MIDI_CONTROL_ALL_NOTES_OFF;
  1286. }
  1287. break;
  1288. } // switch (ctrlEvent.type)
  1289. break;
  1290. } // case kEngineEventTypeControl
  1291. case kEngineEventTypeMidi: {
  1292. if (midiEventCount >= kPluginMaxMidiEvents)
  1293. continue;
  1294. const EngineMidiEvent& midiEvent(event.midi);
  1295. if (midiEvent.size > EngineMidiEvent::kDataSize)
  1296. continue;
  1297. uint8_t status = uint8_t(MIDI_GET_STATUS_FROM_DATA(midiEvent.data));
  1298. // Fix bad note-off (per DSSI spec)
  1299. if (status == MIDI_STATUS_NOTE_ON && midiEvent.data[2] == 0)
  1300. status = MIDI_STATUS_NOTE_OFF;
  1301. snd_seq_event_t& seqEvent(fMidiEvents[midiEventCount++]);
  1302. seqEvent.time.tick = isSampleAccurate ? startTime : event.time;
  1303. switch (status)
  1304. {
  1305. case MIDI_STATUS_NOTE_OFF: {
  1306. const uint8_t note = midiEvent.data[1];
  1307. seqEvent.type = SND_SEQ_EVENT_NOTEOFF;
  1308. seqEvent.data.note.channel = event.channel;
  1309. seqEvent.data.note.note = note;
  1310. pData->postponeRtEvent(kPluginPostRtEventNoteOff, event.channel, note, 0.0f);
  1311. break;
  1312. }
  1313. case MIDI_STATUS_NOTE_ON: {
  1314. const uint8_t note = midiEvent.data[1];
  1315. const uint8_t velo = midiEvent.data[2];
  1316. seqEvent.type = SND_SEQ_EVENT_NOTEON;
  1317. seqEvent.data.note.channel = event.channel;
  1318. seqEvent.data.note.note = note;
  1319. seqEvent.data.note.velocity = velo;
  1320. pData->postponeRtEvent(kPluginPostRtEventNoteOn, event.channel, note, velo);
  1321. break;
  1322. }
  1323. case MIDI_STATUS_POLYPHONIC_AFTERTOUCH:
  1324. if (pData->options & PLUGIN_OPTION_SEND_NOTE_AFTERTOUCH)
  1325. {
  1326. const uint8_t note = midiEvent.data[1];
  1327. const uint8_t pressure = midiEvent.data[2];
  1328. seqEvent.type = SND_SEQ_EVENT_KEYPRESS;
  1329. seqEvent.data.note.channel = event.channel;
  1330. seqEvent.data.note.note = note;
  1331. seqEvent.data.note.velocity = pressure;
  1332. }
  1333. break;
  1334. case MIDI_STATUS_CONTROL_CHANGE:
  1335. if (pData->options & PLUGIN_OPTION_SEND_CONTROL_CHANGES)
  1336. {
  1337. const uint8_t control = midiEvent.data[1];
  1338. const uint8_t value = midiEvent.data[2];
  1339. seqEvent.type = SND_SEQ_EVENT_CONTROLLER;
  1340. seqEvent.data.control.channel = event.channel;
  1341. seqEvent.data.control.param = control;
  1342. seqEvent.data.control.value = value;
  1343. }
  1344. break;
  1345. case MIDI_STATUS_CHANNEL_PRESSURE:
  1346. if (pData->options & PLUGIN_OPTION_SEND_CHANNEL_PRESSURE)
  1347. {
  1348. const uint8_t pressure = midiEvent.data[1];
  1349. seqEvent.type = SND_SEQ_EVENT_CHANPRESS;
  1350. seqEvent.data.control.channel = event.channel;
  1351. seqEvent.data.control.value = pressure;
  1352. }
  1353. break;
  1354. case MIDI_STATUS_PITCH_WHEEL_CONTROL:
  1355. if (pData->options & PLUGIN_OPTION_SEND_PITCHBEND)
  1356. {
  1357. const uint8_t lsb = midiEvent.data[1];
  1358. const uint8_t msb = midiEvent.data[2];
  1359. seqEvent.type = SND_SEQ_EVENT_PITCHBEND;
  1360. seqEvent.data.control.channel = event.channel;
  1361. seqEvent.data.control.value = ((msb << 7) | lsb) - 8192;
  1362. }
  1363. break;
  1364. default:
  1365. --midiEventCount;
  1366. break;
  1367. } // switch (status)
  1368. } break;
  1369. } // switch (event.type)
  1370. }
  1371. pData->postRtEvents.trySplice();
  1372. if (frames > timeOffset)
  1373. processSingle(audioIn, audioOut, frames - timeOffset, timeOffset, midiEventCount);
  1374. } // End of Event Input and Processing
  1375. // --------------------------------------------------------------------------------------------------------
  1376. // Plugin processing (no events)
  1377. else
  1378. {
  1379. processSingle(audioIn, audioOut, frames, 0, midiEventCount);
  1380. } // End of Plugin processing (no events)
  1381. // --------------------------------------------------------------------------------------------------------
  1382. // Control Output
  1383. if (pData->event.portOut != nullptr)
  1384. {
  1385. uint8_t channel;
  1386. uint16_t param;
  1387. float value;
  1388. for (uint32_t k=0; k < pData->param.count; ++k)
  1389. {
  1390. if (pData->param.data[k].type != PARAMETER_OUTPUT)
  1391. continue;
  1392. pData->param.ranges[k].fixValue(fParamBuffers[k]);
  1393. if (pData->param.data[k].midiCC > 0)
  1394. {
  1395. channel = pData->param.data[k].midiChannel;
  1396. param = static_cast<uint16_t>(pData->param.data[k].midiCC);
  1397. value = pData->param.ranges[k].getNormalizedValue(fParamBuffers[k]);
  1398. pData->event.portOut->writeControlEvent(0, channel, kEngineControlEventTypeParameter, param, value);
  1399. }
  1400. }
  1401. } // End of Control Output
  1402. }
  1403. bool processSingle(const float** const audioIn, float** const audioOut, const uint32_t frames,
  1404. const uint32_t timeOffset, const ulong midiEventCount)
  1405. {
  1406. CARLA_SAFE_ASSERT_RETURN(frames > 0, false);
  1407. if (pData->audioIn.count > 0)
  1408. {
  1409. CARLA_SAFE_ASSERT_RETURN(audioIn != nullptr, false);
  1410. }
  1411. if (pData->audioOut.count > 0)
  1412. {
  1413. CARLA_SAFE_ASSERT_RETURN(audioOut != nullptr, false);
  1414. }
  1415. // --------------------------------------------------------------------------------------------------------
  1416. // Try lock, silence otherwise
  1417. if (pData->engine->isOffline())
  1418. {
  1419. pData->singleMutex.lock();
  1420. }
  1421. else if (! pData->singleMutex.tryLock())
  1422. {
  1423. for (uint32_t i=0; i < pData->audioOut.count; ++i)
  1424. {
  1425. for (uint32_t k=0; k < frames; ++k)
  1426. audioOut[i][k+timeOffset] = 0.0f;
  1427. }
  1428. return false;
  1429. }
  1430. // --------------------------------------------------------------------------------------------------------
  1431. // Set audio buffers
  1432. const bool customMonoOut = pData->audioOut.count == 2 && fForcedStereoOut && ! fForcedStereoIn;
  1433. const bool customStereoOut = pData->audioOut.count == 2 && fForcedStereoIn && ! fForcedStereoOut;
  1434. if (! customMonoOut)
  1435. {
  1436. for (uint32_t i=0; i < pData->audioOut.count; ++i)
  1437. carla_zeroFloats(fAudioOutBuffers[i], frames);
  1438. }
  1439. for (uint32_t i=0; i < pData->audioIn.count; ++i)
  1440. carla_copyFloats(fAudioInBuffers[i], audioIn[i]+timeOffset, frames);
  1441. // --------------------------------------------------------------------------------------------------------
  1442. // Run plugin
  1443. uint instn = 0;
  1444. for (LinkedList<LADSPA_Handle>::Itenerator it = fHandles.begin2(); it.valid(); it.next(), ++instn)
  1445. {
  1446. LADSPA_Handle const handle(it.getValue(nullptr));
  1447. CARLA_SAFE_ASSERT_CONTINUE(handle != nullptr);
  1448. // ----------------------------------------------------------------------------------------------------
  1449. // Mixdown for forced stereo
  1450. if (customMonoOut)
  1451. carla_zeroFloats(fAudioOutBuffers[instn], frames);
  1452. // ----------------------------------------------------------------------------------------------------
  1453. // Run it
  1454. if (fDssiDescriptor->run_synth != nullptr)
  1455. {
  1456. try {
  1457. fDssiDescriptor->run_synth(handle, frames, fMidiEvents, midiEventCount);
  1458. } CARLA_SAFE_EXCEPTION("DSSI run_synth");
  1459. }
  1460. else
  1461. {
  1462. try {
  1463. fDescriptor->run(handle, frames);
  1464. } CARLA_SAFE_EXCEPTION("DSSI run");
  1465. }
  1466. // ----------------------------------------------------------------------------------------------------
  1467. // Mixdown for forced stereo
  1468. if (customMonoOut)
  1469. carla_multiply(fAudioOutBuffers[instn], 0.5f, frames);
  1470. else if (customStereoOut)
  1471. carla_copyFloats(fExtraStereoBuffer[instn], fAudioOutBuffers[instn], frames);
  1472. }
  1473. if (customStereoOut)
  1474. {
  1475. carla_copyFloats(fAudioOutBuffers[0], fExtraStereoBuffer[0], frames);
  1476. carla_copyFloats(fAudioOutBuffers[1], fExtraStereoBuffer[1], frames);
  1477. }
  1478. #ifndef BUILD_BRIDGE
  1479. // --------------------------------------------------------------------------------------------------------
  1480. // Post-processing (dry/wet, volume and balance)
  1481. {
  1482. const bool doDryWet = (pData->hints & PLUGIN_CAN_DRYWET) != 0 && carla_isNotEqual(pData->postProc.dryWet, 1.0f);
  1483. const bool doBalance = (pData->hints & PLUGIN_CAN_BALANCE) != 0 && ! (carla_isEqual(pData->postProc.balanceLeft, -1.0f) && carla_isEqual(pData->postProc.balanceRight, 1.0f));
  1484. const bool isMono = (pData->audioIn.count == 1);
  1485. bool isPair;
  1486. float bufValue, oldBufLeft[doBalance ? frames : 1];
  1487. for (uint32_t i=0; i < pData->audioOut.count; ++i)
  1488. {
  1489. // Dry/Wet
  1490. if (doDryWet)
  1491. {
  1492. const uint32_t c = isMono ? 0 : i;
  1493. for (uint32_t k=0; k < frames; ++k)
  1494. {
  1495. if (k < pData->latency.frames)
  1496. bufValue = pData->latency.buffers[c][k];
  1497. else if (pData->latency.frames < frames)
  1498. bufValue = fAudioInBuffers[c][k-pData->latency.frames];
  1499. else
  1500. bufValue = fAudioInBuffers[c][k];
  1501. fAudioOutBuffers[i][k] = (fAudioOutBuffers[i][k] * pData->postProc.dryWet) + (bufValue * (1.0f - pData->postProc.dryWet));
  1502. }
  1503. }
  1504. // Balance
  1505. if (doBalance)
  1506. {
  1507. isPair = (i % 2 == 0);
  1508. if (isPair)
  1509. {
  1510. CARLA_ASSERT(i+1 < pData->audioOut.count);
  1511. carla_copyFloats(oldBufLeft, fAudioOutBuffers[i], frames);
  1512. }
  1513. float balRangeL = (pData->postProc.balanceLeft + 1.0f)/2.0f;
  1514. float balRangeR = (pData->postProc.balanceRight + 1.0f)/2.0f;
  1515. for (uint32_t k=0; k < frames; ++k)
  1516. {
  1517. if (isPair)
  1518. {
  1519. // left
  1520. fAudioOutBuffers[i][k] = oldBufLeft[k] * (1.0f - balRangeL);
  1521. fAudioOutBuffers[i][k] += fAudioOutBuffers[i+1][k] * (1.0f - balRangeR);
  1522. }
  1523. else
  1524. {
  1525. // right
  1526. fAudioOutBuffers[i][k] = fAudioOutBuffers[i][k] * balRangeR;
  1527. fAudioOutBuffers[i][k] += oldBufLeft[k] * balRangeL;
  1528. }
  1529. }
  1530. }
  1531. // Volume (and buffer copy)
  1532. {
  1533. for (uint32_t k=0; k < frames; ++k)
  1534. audioOut[i][k+timeOffset] = fAudioOutBuffers[i][k] * pData->postProc.volume;
  1535. }
  1536. }
  1537. } // End of Post-processing
  1538. // --------------------------------------------------------------------------------------------------------
  1539. // Save latency values for next callback
  1540. if (const uint32_t latframes = pData->latency.frames)
  1541. {
  1542. CARLA_SAFE_ASSERT(timeOffset == 0);
  1543. if (latframes <= frames)
  1544. {
  1545. for (uint32_t i=0; i < pData->audioIn.count; ++i)
  1546. carla_copyFloats(pData->latency.buffers[i], audioIn[i]+(frames-latframes), latframes);
  1547. }
  1548. else
  1549. {
  1550. const uint32_t diff = pData->latency.frames-frames;
  1551. for (uint32_t i=0, k; i<pData->audioIn.count; ++i)
  1552. {
  1553. // push back buffer by 'frames'
  1554. for (k=0; k < diff; ++k)
  1555. pData->latency.buffers[i][k] = pData->latency.buffers[i][k+frames];
  1556. // put current input at the end
  1557. for (uint32_t j=0; k < latframes; ++j, ++k)
  1558. pData->latency.buffers[i][k] = audioIn[i][j];
  1559. }
  1560. }
  1561. }
  1562. #else // BUILD_BRIDGE
  1563. for (uint32_t i=0; i < pData->audioOut.count; ++i)
  1564. {
  1565. for (uint32_t k=0; k < frames; ++k)
  1566. audioOut[i][k+timeOffset] = fAudioOutBuffers[i][k];
  1567. }
  1568. #endif
  1569. // --------------------------------------------------------------------------------------------------------
  1570. pData->singleMutex.unlock();
  1571. return true;
  1572. }
  1573. void bufferSizeChanged(const uint32_t newBufferSize) override
  1574. {
  1575. CARLA_ASSERT_INT(newBufferSize > 0, newBufferSize);
  1576. carla_debug("CarlaPluginDSSI::bufferSizeChanged(%i) - start", newBufferSize);
  1577. for (uint32_t i=0; i < pData->audioIn.count; ++i)
  1578. {
  1579. if (fAudioInBuffers[i] != nullptr)
  1580. delete[] fAudioInBuffers[i];
  1581. fAudioInBuffers[i] = new float[newBufferSize];
  1582. carla_zeroFloats(fAudioInBuffers[i], newBufferSize);
  1583. }
  1584. for (uint32_t i=0; i < pData->audioOut.count; ++i)
  1585. {
  1586. if (fAudioOutBuffers[i] != nullptr)
  1587. delete[] fAudioOutBuffers[i];
  1588. fAudioOutBuffers[i] = new float[newBufferSize];
  1589. carla_zeroFloats(fAudioOutBuffers[i], newBufferSize);
  1590. }
  1591. if (fExtraStereoBuffer[0] != nullptr)
  1592. {
  1593. delete[] fExtraStereoBuffer[0];
  1594. fExtraStereoBuffer[0] = nullptr;
  1595. }
  1596. if (fExtraStereoBuffer[1] != nullptr)
  1597. {
  1598. delete[] fExtraStereoBuffer[1];
  1599. fExtraStereoBuffer[1] = nullptr;
  1600. }
  1601. if (fForcedStereoIn && pData->audioOut.count == 2)
  1602. {
  1603. fExtraStereoBuffer[0] = new float[newBufferSize];
  1604. fExtraStereoBuffer[1] = new float[newBufferSize];
  1605. carla_zeroFloats(fExtraStereoBuffer[0], newBufferSize);
  1606. carla_zeroFloats(fExtraStereoBuffer[1], newBufferSize);
  1607. }
  1608. reconnectAudioPorts();
  1609. carla_debug("CarlaPluginDSSI::bufferSizeChanged(%i) - end", newBufferSize);
  1610. }
  1611. void sampleRateChanged(const double newSampleRate) override
  1612. {
  1613. CARLA_ASSERT_INT(newSampleRate > 0.0, newSampleRate);
  1614. carla_debug("CarlaPluginDSSI::sampleRateChanged(%g) - start", newSampleRate);
  1615. // TODO - handle UI stuff
  1616. if (pData->active)
  1617. deactivate();
  1618. const std::size_t instanceCount(fHandles.count());
  1619. if (fDescriptor->cleanup == nullptr)
  1620. {
  1621. for (LinkedList<LADSPA_Handle>::Itenerator it = fHandles.begin2(); it.valid(); it.next())
  1622. {
  1623. LADSPA_Handle const handle(it.getValue(nullptr));
  1624. CARLA_SAFE_ASSERT_CONTINUE(handle != nullptr);
  1625. try {
  1626. fDescriptor->cleanup(handle);
  1627. } CARLA_SAFE_EXCEPTION("LADSPA cleanup");
  1628. }
  1629. }
  1630. fHandles.clear();
  1631. for (std::size_t i=0; i<instanceCount; ++i)
  1632. addInstance();
  1633. reconnectAudioPorts();
  1634. if (pData->active)
  1635. activate();
  1636. carla_debug("CarlaPluginDSSI::sampleRateChanged(%g) - end", newSampleRate);
  1637. }
  1638. void reconnectAudioPorts() const noexcept
  1639. {
  1640. if (fForcedStereoIn)
  1641. {
  1642. if (LADSPA_Handle const handle = fHandles.getFirst(nullptr))
  1643. {
  1644. try {
  1645. fDescriptor->connect_port(handle, pData->audioIn.ports[0].rindex, fAudioInBuffers[0]);
  1646. } CARLA_SAFE_EXCEPTION("DSSI connect_port (forced stereo input, first)");
  1647. }
  1648. if (LADSPA_Handle const handle = fHandles.getLast(nullptr))
  1649. {
  1650. try {
  1651. fDescriptor->connect_port(handle, pData->audioIn.ports[1].rindex, fAudioInBuffers[1]);
  1652. } CARLA_SAFE_EXCEPTION("DSSI connect_port (forced stereo input, last)");
  1653. }
  1654. }
  1655. else
  1656. {
  1657. for (LinkedList<LADSPA_Handle>::Itenerator it = fHandles.begin2(); it.valid(); it.next())
  1658. {
  1659. LADSPA_Handle const handle(it.getValue(nullptr));
  1660. CARLA_SAFE_ASSERT_CONTINUE(handle != nullptr);
  1661. for (uint32_t i=0; i < pData->audioIn.count; ++i)
  1662. {
  1663. try {
  1664. fDescriptor->connect_port(handle, pData->audioIn.ports[i].rindex, fAudioInBuffers[i]);
  1665. } CARLA_SAFE_EXCEPTION("DSSI connect_port (audio input)");
  1666. }
  1667. }
  1668. }
  1669. if (fForcedStereoOut)
  1670. {
  1671. if (LADSPA_Handle const handle = fHandles.getFirst(nullptr))
  1672. {
  1673. try {
  1674. fDescriptor->connect_port(handle, pData->audioOut.ports[0].rindex, fAudioOutBuffers[0]);
  1675. } CARLA_SAFE_EXCEPTION("DSSI connect_port (forced stereo output, first)");
  1676. }
  1677. if (LADSPA_Handle const handle = fHandles.getLast(nullptr))
  1678. {
  1679. try {
  1680. fDescriptor->connect_port(handle, pData->audioOut.ports[1].rindex, fAudioOutBuffers[1]);
  1681. } CARLA_SAFE_EXCEPTION("DSSI connect_port (forced stereo output, last)");
  1682. }
  1683. }
  1684. else
  1685. {
  1686. for (LinkedList<LADSPA_Handle>::Itenerator it = fHandles.begin2(); it.valid(); it.next())
  1687. {
  1688. LADSPA_Handle const handle(it.getValue(nullptr));
  1689. CARLA_SAFE_ASSERT_CONTINUE(handle != nullptr);
  1690. for (uint32_t i=0; i < pData->audioOut.count; ++i)
  1691. {
  1692. try {
  1693. fDescriptor->connect_port(handle, pData->audioOut.ports[i].rindex, fAudioOutBuffers[i]);
  1694. } CARLA_SAFE_EXCEPTION("DSSI connect_port (audio output)");
  1695. }
  1696. }
  1697. }
  1698. }
  1699. // -------------------------------------------------------------------
  1700. // Plugin buffers
  1701. void clearBuffers() noexcept override
  1702. {
  1703. carla_debug("CarlaPluginDSSI::clearBuffers() - start");
  1704. if (fAudioInBuffers != nullptr)
  1705. {
  1706. for (uint32_t i=0; i < pData->audioIn.count; ++i)
  1707. {
  1708. if (fAudioInBuffers[i] != nullptr)
  1709. {
  1710. delete[] fAudioInBuffers[i];
  1711. fAudioInBuffers[i] = nullptr;
  1712. }
  1713. }
  1714. delete[] fAudioInBuffers;
  1715. fAudioInBuffers = nullptr;
  1716. }
  1717. if (fAudioOutBuffers != nullptr)
  1718. {
  1719. for (uint32_t i=0; i < pData->audioOut.count; ++i)
  1720. {
  1721. if (fAudioOutBuffers[i] != nullptr)
  1722. {
  1723. delete[] fAudioOutBuffers[i];
  1724. fAudioOutBuffers[i] = nullptr;
  1725. }
  1726. }
  1727. delete[] fAudioOutBuffers;
  1728. fAudioOutBuffers = nullptr;
  1729. }
  1730. if (fExtraStereoBuffer[0] != nullptr)
  1731. {
  1732. delete[] fExtraStereoBuffer[0];
  1733. fExtraStereoBuffer[0] = nullptr;
  1734. }
  1735. if (fExtraStereoBuffer[1] != nullptr)
  1736. {
  1737. delete[] fExtraStereoBuffer[1];
  1738. fExtraStereoBuffer[1] = nullptr;
  1739. }
  1740. if (fParamBuffers != nullptr)
  1741. {
  1742. delete[] fParamBuffers;
  1743. fParamBuffers = nullptr;
  1744. }
  1745. CarlaPlugin::clearBuffers();
  1746. carla_debug("CarlaPluginDSSI::clearBuffers() - end");
  1747. }
  1748. #ifdef HAVE_LIBLO
  1749. // -------------------------------------------------------------------
  1750. // OSC stuff
  1751. void handleOscMessage(const char* const method, const int argc, const void* const argvx, const char* const types, const lo_message msg) override
  1752. {
  1753. const lo_address source(lo_message_get_source(msg));
  1754. CARLA_SAFE_ASSERT_RETURN(source != nullptr,);
  1755. // protocol for DSSI UIs *must* be UDP
  1756. CARLA_SAFE_ASSERT_RETURN(lo_address_get_protocol(source) == LO_UDP,);
  1757. if (fOscData.source == nullptr)
  1758. {
  1759. // if no UI is registered yet only "configure" and "update" messages are valid
  1760. CARLA_SAFE_ASSERT_RETURN(std::strcmp(method, "configure") == 0 || std::strcmp(method, "update") == 0,)
  1761. }
  1762. else
  1763. {
  1764. // make sure message source is the DSSI UI
  1765. const char* const msghost = lo_address_get_hostname(source);
  1766. const char* const msgport = lo_address_get_port(source);
  1767. const char* const ourhost = lo_address_get_hostname(fOscData.source);
  1768. const char* const ourport = lo_address_get_port(fOscData.source);
  1769. CARLA_SAFE_ASSERT_RETURN(std::strcmp(msghost, ourhost) == 0,);
  1770. CARLA_SAFE_ASSERT_RETURN(std::strcmp(msgport, ourport) == 0,);
  1771. }
  1772. const lo_arg* const* const argv(static_cast<const lo_arg* const* const>(argvx));
  1773. if (std::strcmp(method, "configure") == 0)
  1774. return handleOscMessageConfigure(argc, argv, types);
  1775. if (std::strcmp(method, "control") == 0)
  1776. return handleOscMessageControl(argc, argv, types);
  1777. if (std::strcmp(method, "program") == 0)
  1778. return handleOscMessageProgram(argc, argv, types);
  1779. if (std::strcmp(method, "midi") == 0)
  1780. return handleOscMessageMIDI(argc, argv, types);
  1781. if (std::strcmp(method, "update") == 0)
  1782. return handleOscMessageUpdate(argc, argv, types, lo_message_get_source(msg));
  1783. if (std::strcmp(method, "exiting") == 0)
  1784. return handleOscMessageExiting();
  1785. carla_stdout("CarlaPluginDSSI::handleOscMessage() - unknown method '%s'", method);
  1786. }
  1787. void handleOscMessageConfigure(const int argc, const lo_arg* const* const argv, const char* const types)
  1788. {
  1789. carla_debug("CarlaPluginDSSI::handleMsgConfigure()");
  1790. CARLA_PLUGIN_DSSI_OSC_CHECK_OSC_TYPES(2, "ss");
  1791. const char* const key = (const char*)&argv[0]->s;
  1792. const char* const value = (const char*)&argv[1]->s;
  1793. setCustomData(CUSTOM_DATA_TYPE_STRING, key, value, false);
  1794. }
  1795. void handleOscMessageControl(const int argc, const lo_arg* const* const argv, const char* const types)
  1796. {
  1797. carla_debug("CarlaPluginDSSI::handleMsgControl()");
  1798. CARLA_PLUGIN_DSSI_OSC_CHECK_OSC_TYPES(2, "if");
  1799. const int32_t rindex = argv[0]->i;
  1800. const float value = argv[1]->f;
  1801. setParameterValueByRealIndex(rindex, value, false, true, true);
  1802. }
  1803. void handleOscMessageProgram(const int argc, const lo_arg* const* const argv, const char* const types)
  1804. {
  1805. carla_debug("CarlaPluginDSSI::handleMsgProgram()");
  1806. CARLA_PLUGIN_DSSI_OSC_CHECK_OSC_TYPES(2, "ii");
  1807. const int32_t bank = argv[0]->i;
  1808. const int32_t program = argv[1]->i;
  1809. CARLA_SAFE_ASSERT_RETURN(bank >= 0,);
  1810. CARLA_SAFE_ASSERT_RETURN(program >= 0,);
  1811. setMidiProgramById(static_cast<uint32_t>(bank), static_cast<uint32_t>(program), false, true, true);
  1812. }
  1813. void handleOscMessageMIDI(const int argc, const lo_arg* const* const argv, const char* const types)
  1814. {
  1815. carla_debug("CarlaPluginDSSI::handleMsgMidi()");
  1816. CARLA_PLUGIN_DSSI_OSC_CHECK_OSC_TYPES(1, "m");
  1817. if (getMidiInCount() == 0)
  1818. {
  1819. carla_stderr("CarlaPluginDSSI::handleMsgMidi() - received midi when plugin has no midi inputs");
  1820. return;
  1821. }
  1822. const uint8_t* const data = argv[0]->m;
  1823. uint8_t status = data[1];
  1824. uint8_t channel = status & 0x0F;
  1825. // Fix bad note-off
  1826. if (MIDI_IS_STATUS_NOTE_ON(status) && data[3] == 0)
  1827. status = MIDI_STATUS_NOTE_OFF;
  1828. if (MIDI_IS_STATUS_NOTE_OFF(status))
  1829. {
  1830. const uint8_t note = data[2];
  1831. CARLA_SAFE_ASSERT_RETURN(note < MAX_MIDI_NOTE,);
  1832. sendMidiSingleNote(channel, note, 0, false, true, true);
  1833. }
  1834. else if (MIDI_IS_STATUS_NOTE_ON(status))
  1835. {
  1836. const uint8_t note = data[2];
  1837. const uint8_t velo = data[3];
  1838. CARLA_SAFE_ASSERT_RETURN(note < MAX_MIDI_NOTE,);
  1839. CARLA_SAFE_ASSERT_RETURN(velo < MAX_MIDI_VALUE,);
  1840. sendMidiSingleNote(channel, note, velo, false, true, true);
  1841. }
  1842. }
  1843. void handleOscMessageUpdate(const int argc, const lo_arg* const* const argv, const char* const types, const lo_address source)
  1844. {
  1845. carla_debug("CarlaPluginDSSI::handleMsgUpdate()");
  1846. CARLA_PLUGIN_DSSI_OSC_CHECK_OSC_TYPES(1, "s");
  1847. const char* const url = (const char*)&argv[0]->s;
  1848. // FIXME - remove debug prints later
  1849. carla_stdout("CarlaPluginDSSI::updateOscData(%p, \"%s\")", source, url);
  1850. fOscData.clear();
  1851. const int proto = lo_address_get_protocol(source);
  1852. {
  1853. const char* host = lo_address_get_hostname(source);
  1854. const char* port = lo_address_get_port(source);
  1855. fOscData.source = lo_address_new_with_proto(proto, host, port);
  1856. carla_stdout("CarlaPlugin::updateOscData() - source: host \"%s\", port \"%s\"", host, port);
  1857. }
  1858. {
  1859. char* host = lo_url_get_hostname(url);
  1860. char* port = lo_url_get_port(url);
  1861. fOscData.path = carla_strdup_free(lo_url_get_path(url));
  1862. fOscData.target = lo_address_new_with_proto(proto, host, port);
  1863. carla_stdout("CarlaPlugin::updateOscData() - target: host \"%s\", port \"%s\", path \"%s\"", host, port, fOscData.path);
  1864. std::free(host);
  1865. std::free(port);
  1866. }
  1867. osc_send_sample_rate(fOscData, static_cast<float>(pData->engine->getSampleRate()));
  1868. for (LinkedList<CustomData>::Itenerator it = pData->custom.begin2(); it.valid(); it.next())
  1869. {
  1870. const CustomData& customData(it.getValue(kCustomDataFallback));
  1871. CARLA_SAFE_ASSERT_CONTINUE(customData.isValid());
  1872. if (std::strcmp(customData.type, CUSTOM_DATA_TYPE_STRING) == 0)
  1873. osc_send_configure(fOscData, customData.key, customData.value);
  1874. }
  1875. if (pData->prog.current >= 0)
  1876. osc_send_program(fOscData, static_cast<uint32_t>(pData->prog.current));
  1877. if (pData->midiprog.current >= 0)
  1878. {
  1879. const MidiProgramData& curMidiProg(pData->midiprog.getCurrent());
  1880. osc_send_program(fOscData, curMidiProg.bank, curMidiProg.program);
  1881. }
  1882. for (uint32_t i=0; i < pData->param.count; ++i)
  1883. osc_send_control(fOscData, pData->param.data[i].rindex, getParameterValue(i));
  1884. if (pData->engine->getOptions().frontendWinId != 0)
  1885. pData->transientTryCounter = 1;
  1886. carla_stdout("CarlaPluginDSSI::updateOscData() - done");
  1887. }
  1888. void handleOscMessageExiting()
  1889. {
  1890. carla_debug("CarlaPluginDSSI::handleMsgExiting()");
  1891. // hide UI
  1892. showCustomUI(false);
  1893. // tell frontend
  1894. pData->engine->callback(ENGINE_CALLBACK_UI_STATE_CHANGED, pData->id, 0, 0, 0.0f, nullptr);
  1895. }
  1896. // -------------------------------------------------------------------
  1897. // Post-poned UI Stuff
  1898. void uiParameterChange(const uint32_t index, const float value) noexcept override
  1899. {
  1900. CARLA_SAFE_ASSERT_RETURN(index < pData->param.count,);
  1901. if (fOscData.target == nullptr)
  1902. return;
  1903. osc_send_control(fOscData, pData->param.data[index].rindex, value);
  1904. }
  1905. void uiMidiProgramChange(const uint32_t index) noexcept override
  1906. {
  1907. CARLA_SAFE_ASSERT_RETURN(index < pData->midiprog.count,);
  1908. if (fOscData.target == nullptr)
  1909. return;
  1910. osc_send_program(fOscData, pData->midiprog.data[index].bank, pData->midiprog.data[index].program);
  1911. }
  1912. void uiNoteOn(const uint8_t channel, const uint8_t note, const uint8_t velo) noexcept override
  1913. {
  1914. CARLA_SAFE_ASSERT_RETURN(channel < MAX_MIDI_CHANNELS,);
  1915. CARLA_SAFE_ASSERT_RETURN(note < MAX_MIDI_NOTE,);
  1916. CARLA_SAFE_ASSERT_RETURN(velo > 0 && velo < MAX_MIDI_VALUE,);
  1917. if (fOscData.target == nullptr)
  1918. return;
  1919. #if 0
  1920. uint8_t midiData[4];
  1921. midiData[0] = 0;
  1922. midiData[1] = uint8_t(MIDI_STATUS_NOTE_ON | (channel & MIDI_CHANNEL_BIT));
  1923. midiData[2] = note;
  1924. midiData[3] = velo;
  1925. osc_send_midi(fOscData, midiData);
  1926. #endif
  1927. }
  1928. void uiNoteOff(const uint8_t channel, const uint8_t note) noexcept override
  1929. {
  1930. CARLA_SAFE_ASSERT_RETURN(channel < MAX_MIDI_CHANNELS,);
  1931. CARLA_SAFE_ASSERT_RETURN(note < MAX_MIDI_NOTE,);
  1932. if (fOscData.target == nullptr)
  1933. return;
  1934. #if 0
  1935. uint8_t midiData[4];
  1936. midiData[0] = 0;
  1937. midiData[1] = uint8_t(MIDI_STATUS_NOTE_ON | (channel & MIDI_CHANNEL_BIT));
  1938. midiData[2] = note;
  1939. midiData[3] = 0;
  1940. osc_send_midi(fOscData, midiData);
  1941. #endif
  1942. }
  1943. #endif // HAVE_LIBLO
  1944. // -------------------------------------------------------------------
  1945. const void* getNativeDescriptor() const noexcept override
  1946. {
  1947. return fDssiDescriptor;
  1948. }
  1949. #ifdef HAVE_LIBLO
  1950. uintptr_t getUiBridgeProcessId() const noexcept override
  1951. {
  1952. return fThreadUI.getProcessId();
  1953. }
  1954. const void* getExtraStuff() const noexcept override
  1955. {
  1956. return fUiFilename;
  1957. }
  1958. #endif
  1959. // -------------------------------------------------------------------
  1960. bool init(const char* const filename, const char* name, const char* const label, const uint options)
  1961. {
  1962. CARLA_SAFE_ASSERT_RETURN(pData->engine != nullptr, false);
  1963. // ---------------------------------------------------------------
  1964. // first checks
  1965. if (pData->client != nullptr)
  1966. {
  1967. pData->engine->setLastError("Plugin client is already registered");
  1968. return false;
  1969. }
  1970. if (filename == nullptr || filename[0] == '\0')
  1971. {
  1972. pData->engine->setLastError("null filename");
  1973. return false;
  1974. }
  1975. // ---------------------------------------------------------------
  1976. // open DLL
  1977. if (! pData->libOpen(filename))
  1978. {
  1979. pData->engine->setLastError(pData->libError(filename));
  1980. return false;
  1981. }
  1982. // ---------------------------------------------------------------
  1983. // get DLL main entry
  1984. const DSSI_Descriptor_Function descFn = pData->libSymbol<DSSI_Descriptor_Function>("dssi_descriptor");
  1985. if (descFn == nullptr)
  1986. {
  1987. pData->engine->setLastError("Could not find the DSSI Descriptor in the plugin library");
  1988. return false;
  1989. }
  1990. // ---------------------------------------------------------------
  1991. // get descriptor that matches label
  1992. // if label is null, get first valid plugin
  1993. const bool nullLabel = (label == nullptr || label[0] == '\0');
  1994. for (ulong d=0;; ++d)
  1995. {
  1996. try {
  1997. fDssiDescriptor = descFn(d);
  1998. }
  1999. catch(...) {
  2000. carla_stderr2("Caught exception when trying to get DSSI descriptor");
  2001. fDescriptor = nullptr;
  2002. fDssiDescriptor = nullptr;
  2003. break;
  2004. }
  2005. if (fDssiDescriptor == nullptr)
  2006. break;
  2007. fDescriptor = fDssiDescriptor->LADSPA_Plugin;
  2008. if (fDescriptor == nullptr)
  2009. {
  2010. carla_stderr2("WARNING - Missing LADSPA interface, will not use this plugin");
  2011. fDssiDescriptor = nullptr;
  2012. break;
  2013. }
  2014. if (fDescriptor->Label == nullptr || fDescriptor->Label[0] == '\0')
  2015. {
  2016. carla_stderr2("WARNING - Got an invalid label, will not use this plugin");
  2017. fDescriptor = nullptr;
  2018. fDssiDescriptor = nullptr;
  2019. break;
  2020. }
  2021. if (fDescriptor->run == nullptr)
  2022. {
  2023. carla_stderr2("WARNING - Plugin has no run, cannot use it");
  2024. fDescriptor = nullptr;
  2025. fDssiDescriptor = nullptr;
  2026. break;
  2027. }
  2028. if (nullLabel || std::strcmp(fDescriptor->Label, label) == 0)
  2029. break;
  2030. }
  2031. if (fDescriptor == nullptr || fDssiDescriptor == nullptr)
  2032. {
  2033. pData->engine->setLastError("Could not find the requested plugin label in the plugin library");
  2034. return false;
  2035. }
  2036. // ---------------------------------------------------------------
  2037. // check if uses global instance
  2038. if (fDssiDescriptor->run_synth == nullptr && fDssiDescriptor->run_multiple_synths != nullptr)
  2039. {
  2040. pData->engine->setLastError("This plugin requires run_multiple_synths which is not supported");
  2041. return false;
  2042. }
  2043. // ---------------------------------------------------------------
  2044. // check for fixed buffer size requirement
  2045. fNeedsFixedBuffers = CarlaString(filename).contains("dssi-vst", true);
  2046. if (fNeedsFixedBuffers && ! pData->engine->usesConstantBufferSize())
  2047. {
  2048. pData->engine->setLastError("Cannot use this plugin under the current engine.\n"
  2049. "The plugin requires a fixed block size which is not possible right now.");
  2050. return false;
  2051. }
  2052. // ---------------------------------------------------------------
  2053. // get info
  2054. if (name == nullptr || name[0] == '\0')
  2055. {
  2056. if (fDescriptor->Name != nullptr && fDescriptor->Name[0] != '\0')
  2057. name = fDescriptor->Name;
  2058. else
  2059. name = fDescriptor->Label;
  2060. }
  2061. pData->name = pData->engine->getUniquePluginName(name);
  2062. pData->filename = carla_strdup(filename);
  2063. // ---------------------------------------------------------------
  2064. // register client
  2065. pData->client = pData->engine->addClient(this);
  2066. if (pData->client == nullptr || ! pData->client->isOk())
  2067. {
  2068. pData->engine->setLastError("Failed to register plugin client");
  2069. return false;
  2070. }
  2071. // ---------------------------------------------------------------
  2072. // initialize plugin
  2073. if (! addInstance())
  2074. return false;
  2075. // ---------------------------------------------------------------
  2076. // find latency port index
  2077. for (uint32_t i=0, iCtrl=0, count=getSafePortCount(); i<count; ++i)
  2078. {
  2079. const int portType(fDescriptor->PortDescriptors[i]);
  2080. if (! LADSPA_IS_PORT_CONTROL(portType))
  2081. continue;
  2082. const uint32_t index(iCtrl++);
  2083. if (! LADSPA_IS_PORT_OUTPUT(portType))
  2084. continue;
  2085. const char* const portName(fDescriptor->PortNames[i]);
  2086. CARLA_SAFE_ASSERT_BREAK(portName != nullptr);
  2087. if (std::strcmp(portName, "latency") == 0 ||
  2088. std::strcmp(portName, "_latency") == 0)
  2089. {
  2090. fLatencyIndex = static_cast<int32_t>(index);
  2091. break;
  2092. }
  2093. }
  2094. // ---------------------------------------------------------------
  2095. // check for custom data extension
  2096. if (fDssiDescriptor->configure != nullptr)
  2097. {
  2098. if (char* const error = fDssiDescriptor->configure(fHandles.getFirst(nullptr), DSSI_CUSTOMDATA_EXTENSION_KEY, ""))
  2099. {
  2100. if (std::strcmp(error, "true") == 0 && fDssiDescriptor->get_custom_data != nullptr
  2101. && fDssiDescriptor->set_custom_data != nullptr)
  2102. fUsesCustomData = true;
  2103. std::free(error);
  2104. }
  2105. }
  2106. #ifdef HAVE_LIBLO
  2107. // ---------------------------------------------------------------
  2108. // check for gui
  2109. if (const char* const guiFilename = find_dssi_ui(filename, fDescriptor->Label))
  2110. {
  2111. fUiFilename = guiFilename;
  2112. fThreadUI.setData(guiFilename, fDescriptor->Label);
  2113. }
  2114. #endif
  2115. // ---------------------------------------------------------------
  2116. // set default options
  2117. pData->options = 0x0;
  2118. /**/ if (fLatencyIndex >= 0 || fNeedsFixedBuffers)
  2119. pData->options |= PLUGIN_OPTION_FIXED_BUFFERS;
  2120. else if (options & PLUGIN_OPTION_FIXED_BUFFERS)
  2121. pData->options |= PLUGIN_OPTION_FIXED_BUFFERS;
  2122. /**/ if (pData->engine->getOptions().forceStereo)
  2123. pData->options |= PLUGIN_OPTION_FORCE_STEREO;
  2124. else if (options & PLUGIN_OPTION_FORCE_STEREO)
  2125. pData->options |= PLUGIN_OPTION_FORCE_STEREO;
  2126. if (fDssiDescriptor->get_program != nullptr && fDssiDescriptor->select_program != nullptr)
  2127. pData->options |= PLUGIN_OPTION_MAP_PROGRAM_CHANGES;
  2128. if (fUsesCustomData)
  2129. pData->options |= PLUGIN_OPTION_USE_CHUNKS;
  2130. if (fDssiDescriptor->run_synth != nullptr)
  2131. {
  2132. pData->options |= PLUGIN_OPTION_SEND_CHANNEL_PRESSURE;
  2133. pData->options |= PLUGIN_OPTION_SEND_NOTE_AFTERTOUCH;
  2134. pData->options |= PLUGIN_OPTION_SEND_PITCHBEND;
  2135. pData->options |= PLUGIN_OPTION_SEND_ALL_SOUND_OFF;
  2136. if (options & PLUGIN_OPTION_SEND_CONTROL_CHANGES)
  2137. pData->options |= PLUGIN_OPTION_SEND_CONTROL_CHANGES;
  2138. }
  2139. return true;
  2140. }
  2141. // -------------------------------------------------------------------
  2142. private:
  2143. LinkedList<LADSPA_Handle> fHandles;
  2144. const LADSPA_Descriptor* fDescriptor;
  2145. const DSSI_Descriptor* fDssiDescriptor;
  2146. float** fAudioInBuffers;
  2147. float** fAudioOutBuffers;
  2148. float* fExtraStereoBuffer[2]; // used only if forcedStereoIn and audioOut == 2
  2149. float* fParamBuffers;
  2150. snd_seq_event_t fMidiEvents[kPluginMaxMidiEvents];
  2151. int32_t fLatencyIndex; // -1 if invalid
  2152. bool fForcedStereoIn;
  2153. bool fForcedStereoOut;
  2154. bool fNeedsFixedBuffers;
  2155. bool fUsesCustomData;
  2156. #ifdef HAVE_LIBLO
  2157. CarlaOscData fOscData;
  2158. CarlaThreadDSSIUI fThreadUI;
  2159. const char* fUiFilename;
  2160. #endif
  2161. // -------------------------------------------------------------------
  2162. bool addInstance()
  2163. {
  2164. LADSPA_Handle handle;
  2165. try {
  2166. handle = fDescriptor->instantiate(fDescriptor, static_cast<ulong>(pData->engine->getSampleRate()));
  2167. } CARLA_SAFE_EXCEPTION_RETURN_ERR("LADSPA instantiate", "Plugin failed to initialize");
  2168. for (uint32_t i=0, count=pData->param.count; i<count; ++i)
  2169. {
  2170. const int32_t rindex(pData->param.data[i].rindex);
  2171. CARLA_SAFE_ASSERT_CONTINUE(rindex >= 0);
  2172. try {
  2173. fDescriptor->connect_port(handle, static_cast<ulong>(rindex), &fParamBuffers[i]);
  2174. } CARLA_SAFE_EXCEPTION("LADSPA connect_port");
  2175. }
  2176. if (fHandles.append(handle))
  2177. return true;
  2178. try {
  2179. fDescriptor->cleanup(handle);
  2180. } CARLA_SAFE_EXCEPTION("LADSPA cleanup");
  2181. pData->engine->setLastError("Out of memory");
  2182. return false;
  2183. }
  2184. uint32_t getSafePortCount() const noexcept
  2185. {
  2186. if (fDescriptor->PortCount == 0)
  2187. return 0;
  2188. CARLA_SAFE_ASSERT_RETURN(fDescriptor->PortDescriptors != nullptr, 0);
  2189. CARLA_SAFE_ASSERT_RETURN(fDescriptor->PortRangeHints != nullptr, 0);
  2190. CARLA_SAFE_ASSERT_RETURN(fDescriptor->PortNames != nullptr, 0);
  2191. return static_cast<uint32_t>(fDescriptor->PortCount);
  2192. }
  2193. bool getSeparatedParameterNameOrUnit(const char* const paramName, char* const strBuf, const bool wantName) const noexcept
  2194. {
  2195. if (_getSeparatedParameterNameOrUnitImpl(paramName, strBuf, wantName, true))
  2196. return true;
  2197. if (_getSeparatedParameterNameOrUnitImpl(paramName, strBuf, wantName, false))
  2198. return true;
  2199. return false;
  2200. }
  2201. static bool _getSeparatedParameterNameOrUnitImpl(const char* const paramName, char* const strBuf,
  2202. const bool wantName, const bool useBracket) noexcept
  2203. {
  2204. const char* const sepBracketStart(std::strstr(paramName, useBracket ? " [" : " ("));
  2205. if (sepBracketStart == nullptr)
  2206. return false;
  2207. const char* const sepBracketEnd(std::strstr(sepBracketStart, useBracket ? "]" : ")"));
  2208. if (sepBracketEnd == nullptr)
  2209. return false;
  2210. const std::size_t unitSize(static_cast<std::size_t>(sepBracketEnd-sepBracketStart-2));
  2211. if (unitSize > 7) // very unlikely to have such big unit
  2212. return false;
  2213. const std::size_t sepIndex(std::strlen(paramName)-unitSize-3);
  2214. // just in case
  2215. if (sepIndex+2 >= STR_MAX)
  2216. return false;
  2217. if (wantName)
  2218. {
  2219. std::strncpy(strBuf, paramName, sepIndex);
  2220. strBuf[sepIndex] = '\0';
  2221. }
  2222. else
  2223. {
  2224. std::strncpy(strBuf, paramName+(sepIndex+2), unitSize);
  2225. strBuf[unitSize] = '\0';
  2226. }
  2227. return true;
  2228. }
  2229. // -------------------------------------------------------------------
  2230. CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(CarlaPluginDSSI)
  2231. };
  2232. // -------------------------------------------------------------------------------------------------------------------
  2233. CarlaPlugin* CarlaPlugin::newDSSI(const Initializer& init)
  2234. {
  2235. carla_debug("CarlaPlugin::newDSSI({%p, \"%s\", \"%s\", \"%s\", " P_INT64 ", %x})",
  2236. init.engine, init.filename, init.name, init.label, init.uniqueId, init.options);
  2237. CarlaPluginDSSI* const plugin(new CarlaPluginDSSI(init.engine, init.id));
  2238. if (! plugin->init(init.filename, init.name, init.label, init.options))
  2239. {
  2240. delete plugin;
  2241. return nullptr;
  2242. }
  2243. return plugin;
  2244. }
  2245. // -------------------------------------------------------------------------------------------------------------------
  2246. CARLA_BACKEND_END_NAMESPACE