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.

CarlaEngine.cpp 109KB

11 years ago
11 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
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
10 years ago
11 years ago
11 years ago
11 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
11 years ago
10 years ago
11 years ago
10 years ago
11 years ago
10 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
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
10 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
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
10 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
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
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877
  1. /*
  2. * Carla Plugin Host
  3. * Copyright (C) 2011-2014 Filipe Coelho <falktx@falktx.com>
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License as
  7. * published by the Free Software Foundation; either version 2 of
  8. * the License, or any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * For a full copy of the GNU General Public License see the doc/GPL.txt file.
  16. */
  17. /* TODO:
  18. * - complete processRack(): carefully add to input, sorted events
  19. * - implement processPatchbay()
  20. * - implement oscSend_control_switch_plugins()
  21. * - proper find&load plugins
  22. * - something about the peaks?
  23. * - patchbayDisconnect should return false sometimes
  24. */
  25. #include "CarlaEngineInternal.hpp"
  26. #include "CarlaPlugin.hpp"
  27. #include "CarlaBackendUtils.hpp"
  28. #include "CarlaEngineUtils.hpp"
  29. #include "CarlaMathUtils.hpp"
  30. #include "CarlaStateUtils.hpp"
  31. #include "CarlaMIDI.h"
  32. #include <QtCore/QDir>
  33. #include <QtCore/QFile>
  34. #include <QtCore/QFileInfo>
  35. #include <QtCore/QTextStream>
  36. #include <QtXml/QDomNode>
  37. // -----------------------------------------------------------------------
  38. CARLA_BACKEND_START_NAMESPACE
  39. #if 0
  40. } // Fix editor indentation
  41. #endif
  42. // -----------------------------------------------------------------------
  43. // Fallback data
  44. static const EngineEvent kFallbackEngineEvent = { kEngineEventTypeNull, 0, 0, {{ kEngineControlEventTypeNull, 0, 0.0f }} };
  45. // -----------------------------------------------------------------------
  46. // Carla Engine port (Abstract)
  47. CarlaEnginePort::CarlaEnginePort(const CarlaEngine& engine, const bool isInputPort)
  48. : fEngine(engine),
  49. fIsInput(isInputPort)
  50. {
  51. carla_debug("CarlaEnginePort::CarlaEnginePort(%s)", bool2str(isInputPort));
  52. }
  53. CarlaEnginePort::~CarlaEnginePort()
  54. {
  55. carla_debug("CarlaEnginePort::~CarlaEnginePort()");
  56. }
  57. // -----------------------------------------------------------------------
  58. // Carla Engine Audio port
  59. CarlaEngineAudioPort::CarlaEngineAudioPort(const CarlaEngine& engine, const bool isInputPort)
  60. : CarlaEnginePort(engine, isInputPort),
  61. fBuffer(nullptr)
  62. {
  63. carla_debug("CarlaEngineAudioPort::CarlaEngineAudioPort(%s)", bool2str(isInputPort));
  64. }
  65. CarlaEngineAudioPort::~CarlaEngineAudioPort()
  66. {
  67. carla_debug("CarlaEngineAudioPort::~CarlaEngineAudioPort()");
  68. }
  69. void CarlaEngineAudioPort::initBuffer() noexcept
  70. {
  71. }
  72. // -----------------------------------------------------------------------
  73. // Carla Engine CV port
  74. CarlaEngineCVPort::CarlaEngineCVPort(const CarlaEngine& engine, const bool isInputPort)
  75. : CarlaEnginePort(engine, isInputPort),
  76. fBuffer(nullptr),
  77. fProcessMode(engine.getProccessMode())
  78. {
  79. carla_debug("CarlaEngineCVPort::CarlaEngineCVPort(%s)", bool2str(isInputPort));
  80. if (fProcessMode != ENGINE_PROCESS_MODE_SINGLE_CLIENT && fProcessMode != ENGINE_PROCESS_MODE_MULTIPLE_CLIENTS)
  81. fBuffer = new float[engine.getBufferSize()];
  82. }
  83. CarlaEngineCVPort::~CarlaEngineCVPort()
  84. {
  85. carla_debug("CarlaEngineCVPort::~CarlaEngineCVPort()");
  86. if (fProcessMode != ENGINE_PROCESS_MODE_SINGLE_CLIENT && fProcessMode != ENGINE_PROCESS_MODE_MULTIPLE_CLIENTS)
  87. {
  88. CARLA_SAFE_ASSERT_RETURN(fBuffer != nullptr,);
  89. delete[] fBuffer;
  90. fBuffer = nullptr;
  91. }
  92. }
  93. void CarlaEngineCVPort::initBuffer() noexcept
  94. {
  95. CARLA_SAFE_ASSERT_RETURN(fBuffer != nullptr,);
  96. CARLA_SAFE_ASSERT_RETURN(fProcessMode != ENGINE_PROCESS_MODE_SINGLE_CLIENT && fProcessMode != ENGINE_PROCESS_MODE_MULTIPLE_CLIENTS,);
  97. carla_zeroFloat(fBuffer, fEngine.getBufferSize());
  98. }
  99. void CarlaEngineCVPort::setBufferSize(const uint32_t bufferSize)
  100. {
  101. CARLA_SAFE_ASSERT_RETURN(fBuffer != nullptr,);
  102. CARLA_SAFE_ASSERT_RETURN(fProcessMode != ENGINE_PROCESS_MODE_SINGLE_CLIENT && fProcessMode != ENGINE_PROCESS_MODE_MULTIPLE_CLIENTS,);
  103. delete[] fBuffer;
  104. fBuffer = new float[bufferSize];
  105. }
  106. // -----------------------------------------------------------------------
  107. // Carla Engine Event port
  108. CarlaEngineEventPort::CarlaEngineEventPort(const CarlaEngine& engine, const bool isInputPort)
  109. : CarlaEnginePort(engine, isInputPort),
  110. fBuffer(nullptr),
  111. fProcessMode(engine.getProccessMode())
  112. {
  113. carla_debug("CarlaEngineEventPort::CarlaEngineEventPort(%s)", bool2str(isInputPort));
  114. if (fProcessMode == ENGINE_PROCESS_MODE_PATCHBAY)
  115. fBuffer = new EngineEvent[kMaxEngineEventInternalCount];
  116. }
  117. CarlaEngineEventPort::~CarlaEngineEventPort()
  118. {
  119. carla_debug("CarlaEngineEventPort::~CarlaEngineEventPort()");
  120. if (fProcessMode == ENGINE_PROCESS_MODE_PATCHBAY)
  121. {
  122. CARLA_SAFE_ASSERT_RETURN(fBuffer != nullptr,);
  123. delete[] fBuffer;
  124. fBuffer = nullptr;
  125. }
  126. }
  127. void CarlaEngineEventPort::initBuffer() noexcept
  128. {
  129. if (fProcessMode == ENGINE_PROCESS_MODE_CONTINUOUS_RACK || fProcessMode == ENGINE_PROCESS_MODE_BRIDGE)
  130. fBuffer = fEngine.getInternalEventBuffer(fIsInput);
  131. else if (fProcessMode == ENGINE_PROCESS_MODE_PATCHBAY && ! fIsInput)
  132. carla_zeroStruct<EngineEvent>(fBuffer, kMaxEngineEventInternalCount);
  133. }
  134. uint32_t CarlaEngineEventPort::getEventCount() const noexcept
  135. {
  136. CARLA_SAFE_ASSERT_RETURN(fIsInput, 0);
  137. CARLA_SAFE_ASSERT_RETURN(fBuffer != nullptr, 0);
  138. CARLA_SAFE_ASSERT_RETURN(fProcessMode != ENGINE_PROCESS_MODE_SINGLE_CLIENT && fProcessMode != ENGINE_PROCESS_MODE_MULTIPLE_CLIENTS, 0);
  139. uint32_t i=0;
  140. for (; i < kMaxEngineEventInternalCount; ++i)
  141. {
  142. if (fBuffer[i].type == kEngineEventTypeNull)
  143. break;
  144. }
  145. return i;
  146. }
  147. const EngineEvent& CarlaEngineEventPort::getEvent(const uint32_t index) const noexcept
  148. {
  149. CARLA_SAFE_ASSERT_RETURN(fIsInput, kFallbackEngineEvent);
  150. CARLA_SAFE_ASSERT_RETURN(fBuffer != nullptr, kFallbackEngineEvent);
  151. CARLA_SAFE_ASSERT_RETURN(fProcessMode != ENGINE_PROCESS_MODE_SINGLE_CLIENT && fProcessMode != ENGINE_PROCESS_MODE_MULTIPLE_CLIENTS, kFallbackEngineEvent);
  152. CARLA_SAFE_ASSERT_RETURN(index < kMaxEngineEventInternalCount, kFallbackEngineEvent);
  153. return fBuffer[index];
  154. }
  155. const EngineEvent& CarlaEngineEventPort::getEventUnchecked(const uint32_t index) const noexcept
  156. {
  157. return fBuffer[index];
  158. }
  159. bool CarlaEngineEventPort::writeControlEvent(const uint32_t time, const uint8_t channel, const EngineControlEventType type, const uint16_t param, const float value) noexcept
  160. {
  161. CARLA_SAFE_ASSERT_RETURN(! fIsInput, false);
  162. CARLA_SAFE_ASSERT_RETURN(fBuffer != nullptr, false);
  163. CARLA_SAFE_ASSERT_RETURN(fProcessMode != ENGINE_PROCESS_MODE_SINGLE_CLIENT && fProcessMode != ENGINE_PROCESS_MODE_MULTIPLE_CLIENTS, false);
  164. CARLA_SAFE_ASSERT_RETURN(type != kEngineControlEventTypeNull, false);
  165. CARLA_SAFE_ASSERT_RETURN(channel < MAX_MIDI_CHANNELS, false);
  166. CARLA_SAFE_ASSERT(value >= 0.0f && value <= 1.0f);
  167. if (type == kEngineControlEventTypeParameter) {
  168. CARLA_SAFE_ASSERT(! MIDI_IS_CONTROL_BANK_SELECT(param));
  169. }
  170. // FIXME? should not fix range if midi-program
  171. const float fixedValue(carla_fixValue<float>(0.0f, 1.0f, value));
  172. for (uint32_t i=0; i < kMaxEngineEventInternalCount; ++i)
  173. {
  174. EngineEvent& event(fBuffer[i]);
  175. if (event.type != kEngineEventTypeNull)
  176. continue;
  177. event.type = kEngineEventTypeControl;
  178. event.time = time;
  179. event.channel = channel;
  180. event.ctrl.type = type;
  181. event.ctrl.param = param;
  182. event.ctrl.value = fixedValue;
  183. return true;
  184. }
  185. carla_stderr2("CarlaEngineEventPort::writeControlEvent() - buffer full");
  186. return false;
  187. }
  188. bool CarlaEngineEventPort::writeControlEvent(const uint32_t time, const uint8_t channel, const EngineControlEvent& ctrl) noexcept
  189. {
  190. return writeControlEvent(time, channel, ctrl.type, ctrl.param, ctrl.value);
  191. }
  192. bool CarlaEngineEventPort::writeMidiEvent(const uint32_t time, const uint8_t channel, const uint8_t port, const uint8_t size, const uint8_t* const data) noexcept
  193. {
  194. CARLA_SAFE_ASSERT_RETURN(! fIsInput, false);
  195. CARLA_SAFE_ASSERT_RETURN(fBuffer != nullptr, false);
  196. CARLA_SAFE_ASSERT_RETURN(fProcessMode != ENGINE_PROCESS_MODE_SINGLE_CLIENT && fProcessMode != ENGINE_PROCESS_MODE_MULTIPLE_CLIENTS, false);
  197. CARLA_SAFE_ASSERT_RETURN(channel < MAX_MIDI_CHANNELS, false);
  198. CARLA_SAFE_ASSERT_RETURN(size > 0 && size <= EngineMidiEvent::kDataSize, false);
  199. CARLA_SAFE_ASSERT_RETURN(data != nullptr, false);
  200. for (uint32_t i=0; i < kMaxEngineEventInternalCount; ++i)
  201. {
  202. EngineEvent& event(fBuffer[i]);
  203. if (event.type != kEngineEventTypeNull)
  204. continue;
  205. event.type = kEngineEventTypeMidi;
  206. event.time = time;
  207. event.channel = channel;
  208. event.midi.port = port;
  209. event.midi.size = size;
  210. event.midi.data[0] = uint8_t(MIDI_GET_STATUS_FROM_DATA(data));
  211. uint8_t j=1;
  212. for (; j < size; ++j)
  213. event.midi.data[j] = data[j];
  214. for (; j < EngineMidiEvent::kDataSize; ++j)
  215. event.midi.data[j] = 0;
  216. return true;
  217. }
  218. carla_stderr2("CarlaEngineEventPort::writeMidiEvent() - buffer full");
  219. return false;
  220. }
  221. bool CarlaEngineEventPort::writeMidiEvent(const uint32_t time, const uint8_t size, const uint8_t* const data) noexcept
  222. {
  223. return writeMidiEvent(time, uint8_t(MIDI_GET_CHANNEL_FROM_DATA(data)), 0, size, data);
  224. }
  225. bool CarlaEngineEventPort::writeMidiEvent(const uint32_t time, const uint8_t channel, const EngineMidiEvent& midi) noexcept
  226. {
  227. return writeMidiEvent(time, channel, midi.port, midi.size, midi.data);
  228. }
  229. // -----------------------------------------------------------------------
  230. // Carla Engine client (Abstract)
  231. CarlaEngineClient::CarlaEngineClient(const CarlaEngine& engine)
  232. : fEngine(engine),
  233. fActive(false),
  234. fLatency(0)
  235. {
  236. carla_debug("CarlaEngineClient::CarlaEngineClient()");
  237. }
  238. CarlaEngineClient::~CarlaEngineClient()
  239. {
  240. CARLA_ASSERT(! fActive);
  241. carla_debug("CarlaEngineClient::~CarlaEngineClient()");
  242. }
  243. void CarlaEngineClient::activate() noexcept
  244. {
  245. CARLA_ASSERT(! fActive);
  246. carla_debug("CarlaEngineClient::activate()");
  247. fActive = true;
  248. }
  249. void CarlaEngineClient::deactivate() noexcept
  250. {
  251. CARLA_ASSERT(fActive);
  252. carla_debug("CarlaEngineClient::deactivate()");
  253. fActive = false;
  254. }
  255. bool CarlaEngineClient::isActive() const noexcept
  256. {
  257. return fActive;
  258. }
  259. bool CarlaEngineClient::isOk() const noexcept
  260. {
  261. return true;
  262. }
  263. uint32_t CarlaEngineClient::getLatency() const noexcept
  264. {
  265. return fLatency;
  266. }
  267. void CarlaEngineClient::setLatency(const uint32_t samples) noexcept
  268. {
  269. fLatency = samples;
  270. }
  271. CarlaEnginePort* CarlaEngineClient::addPort(const EnginePortType portType, const char* const name, const bool isInput)
  272. {
  273. CARLA_SAFE_ASSERT_RETURN(name != nullptr && name[0] != '\0', nullptr);
  274. carla_debug("CarlaEngineClient::addPort(%i:%s, \"%s\", %s)", portType, EnginePortType2Str(portType), name, bool2str(isInput));
  275. switch (portType)
  276. {
  277. case kEnginePortTypeNull:
  278. break;
  279. case kEnginePortTypeAudio:
  280. return new CarlaEngineAudioPort(fEngine, isInput);
  281. case kEnginePortTypeCV:
  282. return new CarlaEngineCVPort(fEngine, isInput);
  283. case kEnginePortTypeEvent:
  284. return new CarlaEngineEventPort(fEngine, isInput);
  285. }
  286. carla_stderr("CarlaEngineClient::addPort(%i, \"%s\", %s) - invalid type", portType, name, bool2str(isInput));
  287. return nullptr;
  288. }
  289. // -----------------------------------------------------------------------
  290. // Carla Engine
  291. CarlaEngine::CarlaEngine()
  292. : pData(new CarlaEngineProtectedData(this))
  293. {
  294. carla_debug("CarlaEngine::CarlaEngine()");
  295. }
  296. CarlaEngine::~CarlaEngine()
  297. {
  298. carla_debug("CarlaEngine::~CarlaEngine()");
  299. delete pData;
  300. }
  301. // -----------------------------------------------------------------------
  302. // Static calls
  303. unsigned int CarlaEngine::getDriverCount()
  304. {
  305. carla_debug("CarlaEngine::getDriverCount()");
  306. unsigned int count = 1; // JACK
  307. #ifndef BUILD_BRIDGE
  308. count += getRtAudioApiCount();
  309. # ifdef HAVE_JUCE
  310. count += getJuceApiCount();
  311. # endif
  312. #endif
  313. return count;
  314. }
  315. const char* CarlaEngine::getDriverName(const unsigned int index)
  316. {
  317. carla_debug("CarlaEngine::getDriverName(%i)", index);
  318. if (index == 0)
  319. return "JACK";
  320. #ifndef BUILD_BRIDGE
  321. const unsigned int rtAudioIndex(index-1);
  322. if (rtAudioIndex < getRtAudioApiCount())
  323. return getRtAudioApiName(rtAudioIndex);
  324. # ifdef HAVE_JUCE
  325. const unsigned int juceIndex(index-rtAudioIndex-1);
  326. if (juceIndex < getJuceApiCount())
  327. return getJuceApiName(juceIndex);
  328. # endif
  329. #endif
  330. carla_stderr("CarlaEngine::getDriverName(%i) - invalid index", index);
  331. return nullptr;
  332. }
  333. const char* const* CarlaEngine::getDriverDeviceNames(const unsigned int index)
  334. {
  335. carla_debug("CarlaEngine::getDriverDeviceNames(%i)", index);
  336. if (index == 0) // JACK
  337. {
  338. static const char* ret[3] = { "Auto-Connect OFF", "Auto-Connect ON", nullptr };
  339. return ret;
  340. }
  341. #ifndef BUILD_BRIDGE
  342. const unsigned int rtAudioIndex(index-1);
  343. if (rtAudioIndex < getRtAudioApiCount())
  344. return getRtAudioApiDeviceNames(rtAudioIndex);
  345. # ifdef HAVE_JUCE
  346. const unsigned int juceIndex(index-rtAudioIndex-1);
  347. if (juceIndex < getJuceApiCount())
  348. return getJuceApiDeviceNames(juceIndex);
  349. # endif
  350. #endif
  351. carla_stderr("CarlaEngine::getDriverDeviceNames(%i) - invalid index", index);
  352. return nullptr;
  353. }
  354. const EngineDriverDeviceInfo* CarlaEngine::getDriverDeviceInfo(const unsigned int index, const char* const deviceName)
  355. {
  356. carla_debug("CarlaEngine::getDriverDeviceInfo(%i, \"%s\")", index, deviceName);
  357. if (index == 0) // JACK
  358. {
  359. static uint32_t bufSizes[11] = { 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 0 };
  360. static EngineDriverDeviceInfo devInfo;
  361. devInfo.hints = ENGINE_DRIVER_DEVICE_VARIABLE_BUFFER_SIZE;
  362. devInfo.bufferSizes = bufSizes;
  363. devInfo.sampleRates = nullptr;
  364. return &devInfo;
  365. }
  366. #ifndef BUILD_BRIDGE
  367. const unsigned int rtAudioIndex(index-1);
  368. if (rtAudioIndex < getRtAudioApiCount())
  369. return getRtAudioDeviceInfo(rtAudioIndex, deviceName);
  370. # ifdef HAVE_JUCE
  371. const unsigned int juceIndex(index-rtAudioIndex-1);
  372. if (juceIndex < getJuceApiCount())
  373. return getJuceDeviceInfo(juceIndex, deviceName);
  374. # endif
  375. #endif
  376. carla_stderr("CarlaEngine::getDriverDeviceNames(%i, \"%s\") - invalid index", index, deviceName);
  377. return nullptr;
  378. }
  379. CarlaEngine* CarlaEngine::newDriverByName(const char* const driverName)
  380. {
  381. CARLA_SAFE_ASSERT_RETURN(driverName != nullptr && driverName[0] != '\0', nullptr);
  382. carla_debug("CarlaEngine::newDriverByName(\"%s\")", driverName);
  383. if (std::strcmp(driverName, "JACK") == 0)
  384. return newJack();
  385. // common
  386. if (std::strncmp(driverName, "JACK ", 5) == 0)
  387. return newRtAudio(AUDIO_API_JACK);
  388. // linux
  389. #ifdef HAVE_JUCE
  390. if (std::strcmp(driverName, "ALSA") == 0)
  391. return newJuce(AUDIO_API_ALSA);
  392. #else
  393. if (std::strcmp(driverName, "ALSA") == 0)
  394. return newRtAudio(AUDIO_API_ALSA);
  395. #endif
  396. if (std::strcmp(driverName, "OSS") == 0)
  397. return newRtAudio(AUDIO_API_OSS);
  398. if (std::strcmp(driverName, "PulseAudio") == 0)
  399. return newRtAudio(AUDIO_API_PULSE);
  400. // macos
  401. #ifdef HAVE_JUCE
  402. if (std::strcmp(driverName, "CoreAudio") == 0)
  403. return newJuce(AUDIO_API_CORE);
  404. #else
  405. if (std::strcmp(driverName, "CoreAudio") == 0)
  406. return newRtAudio(AUDIO_API_CORE);
  407. #endif
  408. // windows
  409. #ifdef HAVE_JUCE
  410. if (std::strcmp(driverName, "ASIO") == 0)
  411. return newJuce(AUDIO_API_ASIO);
  412. if (std::strcmp(driverName, "DirectSound") == 0)
  413. return newJuce(AUDIO_API_DS);
  414. #else
  415. if (std::strcmp(driverName, "ASIO") == 0)
  416. return newRtAudio(AUDIO_API_ASIO);
  417. if (std::strcmp(driverName, "DirectSound") == 0)
  418. return newRtAudio(AUDIO_API_DS);
  419. #endif
  420. carla_stderr("CarlaEngine::newDriverByName(\"%s\") - invalid driver name", driverName);
  421. return nullptr;
  422. }
  423. // -----------------------------------------------------------------------
  424. // Maximum values
  425. unsigned int CarlaEngine::getMaxClientNameSize() const noexcept
  426. {
  427. return STR_MAX/2;
  428. }
  429. unsigned int CarlaEngine::getMaxPortNameSize() const noexcept
  430. {
  431. return STR_MAX;
  432. }
  433. unsigned int CarlaEngine::getCurrentPluginCount() const noexcept
  434. {
  435. return pData->curPluginCount;
  436. }
  437. unsigned int CarlaEngine::getMaxPluginNumber() const noexcept
  438. {
  439. return pData->maxPluginNumber;
  440. }
  441. // -----------------------------------------------------------------------
  442. // Virtual, per-engine type calls
  443. bool CarlaEngine::init(const char* const clientName)
  444. {
  445. CARLA_SAFE_ASSERT_RETURN_ERR(pData->name.isEmpty(), "Invalid engine internal data (err #1)");
  446. CARLA_SAFE_ASSERT_RETURN_ERR(pData->oscData == nullptr, "Invalid engine internal data (err #2)");
  447. CARLA_SAFE_ASSERT_RETURN_ERR(pData->plugins == nullptr, "Invalid engine internal data (err #3)");
  448. CARLA_SAFE_ASSERT_RETURN_ERR(pData->bufEvents.in == nullptr, "Invalid engine internal data (err #4)");
  449. CARLA_SAFE_ASSERT_RETURN_ERR(pData->bufEvents.out == nullptr, "Invalid engine internal data (err #5)");
  450. CARLA_SAFE_ASSERT_RETURN_ERR(clientName != nullptr && clientName[0] != '\0', "Invalid client name");
  451. carla_debug("CarlaEngine::init(\"%s\")", clientName);
  452. CARLA_ENGINE_THREAD_SAFE_SECTION
  453. pData->aboutToClose = false;
  454. pData->curPluginCount = 0;
  455. pData->maxPluginNumber = 0;
  456. pData->nextPluginId = 0;
  457. switch (pData->options.processMode)
  458. {
  459. case ENGINE_PROCESS_MODE_SINGLE_CLIENT:
  460. case ENGINE_PROCESS_MODE_MULTIPLE_CLIENTS:
  461. pData->maxPluginNumber = MAX_DEFAULT_PLUGINS;
  462. break;
  463. case ENGINE_PROCESS_MODE_CONTINUOUS_RACK:
  464. pData->maxPluginNumber = MAX_RACK_PLUGINS;
  465. pData->bufEvents.in = new EngineEvent[kMaxEngineEventInternalCount];
  466. pData->bufEvents.out = new EngineEvent[kMaxEngineEventInternalCount];
  467. break;
  468. case ENGINE_PROCESS_MODE_PATCHBAY:
  469. pData->maxPluginNumber = MAX_PATCHBAY_PLUGINS;
  470. break;
  471. case ENGINE_PROCESS_MODE_BRIDGE:
  472. pData->maxPluginNumber = 1;
  473. pData->bufEvents.in = new EngineEvent[kMaxEngineEventInternalCount];
  474. pData->bufEvents.out = new EngineEvent[kMaxEngineEventInternalCount];
  475. break;
  476. }
  477. CARLA_SAFE_ASSERT_RETURN_ERR(pData->maxPluginNumber != 0, "Invalid engine process mode");
  478. pData->nextPluginId = pData->maxPluginNumber;
  479. pData->name = clientName;
  480. pData->name.toBasic();
  481. pData->timeInfo.clear();
  482. pData->plugins = new EnginePluginData[pData->maxPluginNumber];
  483. for (uint i=0; i < pData->maxPluginNumber; ++i)
  484. pData->plugins[i].clear();
  485. pData->osc.init(clientName);
  486. #ifndef BUILD_BRIDGE
  487. pData->oscData = pData->osc.getControlData();
  488. #endif
  489. pData->nextAction.ready();
  490. pData->thread.start();
  491. callback(ENGINE_CALLBACK_ENGINE_STARTED, 0, 0, 0, 0.0f, getCurrentDriverName());
  492. return true;
  493. }
  494. bool CarlaEngine::close()
  495. {
  496. CARLA_SAFE_ASSERT_RETURN_ERR(pData->name.isNotEmpty(), "Invalid engine internal data (err #6)");
  497. CARLA_SAFE_ASSERT_RETURN_ERR(pData->plugins != nullptr, "Invalid engine internal data (err #7)");
  498. CARLA_SAFE_ASSERT_RETURN_ERR(pData->nextPluginId == pData->maxPluginNumber, "Invalid engine internal data (err #8)");
  499. CARLA_SAFE_ASSERT_RETURN_ERR(pData->nextAction.opcode == kEnginePostActionNull, "Invalid engine internal data (err #9)");
  500. carla_debug("CarlaEngine::close()");
  501. CARLA_ENGINE_THREAD_SAFE_SECTION
  502. pData->aboutToClose = true;
  503. if (pData->curPluginCount != 0)
  504. removeAllPlugins();
  505. pData->thread.stop(500);
  506. pData->nextAction.ready();
  507. #ifndef BUILD_BRIDGE
  508. if (pData->osc.isControlRegistered())
  509. oscSend_control_exit();
  510. #endif
  511. pData->osc.close();
  512. pData->oscData = nullptr;
  513. pData->curPluginCount = 0;
  514. pData->maxPluginNumber = 0;
  515. pData->nextPluginId = 0;
  516. if (pData->plugins != nullptr)
  517. {
  518. delete[] pData->plugins;
  519. pData->plugins = nullptr;
  520. }
  521. if (pData->bufEvents.in != nullptr)
  522. {
  523. delete[] pData->bufEvents.in;
  524. pData->bufEvents.in = nullptr;
  525. }
  526. if (pData->bufEvents.out != nullptr)
  527. {
  528. delete[] pData->bufEvents.out;
  529. pData->bufEvents.out = nullptr;
  530. }
  531. pData->name.clear();
  532. callback(ENGINE_CALLBACK_ENGINE_STOPPED, 0, 0, 0, 0.0f, nullptr);
  533. return true;
  534. }
  535. void CarlaEngine::idle()
  536. {
  537. CARLA_ASSERT(pData->nextAction.opcode == kEnginePostActionNull); // TESTING, remove later
  538. CARLA_ASSERT(pData->nextPluginId == pData->maxPluginNumber); // TESTING, remove later
  539. CARLA_ASSERT(pData->plugins != nullptr); // this one too maybe
  540. CARLA_ENGINE_THREAD_SAFE_SECTION
  541. for (unsigned int i=0; i < pData->curPluginCount; ++i)
  542. {
  543. CarlaPlugin* const plugin(pData->plugins[i].plugin);
  544. if (plugin != nullptr && plugin->isEnabled())
  545. plugin->idle();
  546. }
  547. }
  548. CarlaEngineClient* CarlaEngine::addClient(CarlaPlugin* const)
  549. {
  550. return new CarlaEngineClient(*this);
  551. }
  552. // -----------------------------------------------------------------------
  553. // Plugin management
  554. bool CarlaEngine::addPlugin(const BinaryType btype, const PluginType ptype, const char* const filename, const char* const name, const char* const label, const void* const extra)
  555. {
  556. CARLA_SAFE_ASSERT_RETURN_ERR(pData->plugins != nullptr, "Invalid engine internal data (err #10)");
  557. CARLA_SAFE_ASSERT_RETURN_ERR(pData->nextPluginId <= pData->maxPluginNumber, "Invalid engine internal data (err #11)");
  558. CARLA_SAFE_ASSERT_RETURN_ERR(pData->nextAction.opcode == kEnginePostActionNull, "Invalid engine internal data (err #12)");
  559. CARLA_SAFE_ASSERT_RETURN_ERR(btype != BINARY_NONE, "Invalid plugin params (err #1)");
  560. CARLA_SAFE_ASSERT_RETURN_ERR(ptype != PLUGIN_NONE, "Invalid plugin params (err #2)");
  561. CARLA_SAFE_ASSERT_RETURN_ERR((filename != nullptr && filename[0] != '\0') || (label != nullptr && label[0] != '\0'), "Invalid plugin params (err #3)");
  562. carla_debug("CarlaEngine::addPlugin(%i:%s, %i:%s, \"%s\", \"%s\", \"%s\", %p)", btype, BinaryType2Str(btype), ptype, PluginType2Str(ptype), filename, name, label, extra);
  563. CARLA_ENGINE_THREAD_SAFE_SECTION
  564. unsigned int id;
  565. CarlaPlugin* oldPlugin = nullptr;
  566. if (pData->nextPluginId < pData->curPluginCount)
  567. {
  568. id = pData->nextPluginId;
  569. pData->nextPluginId = pData->maxPluginNumber;
  570. oldPlugin = pData->plugins[id].plugin;
  571. CARLA_SAFE_ASSERT_RETURN_ERR(oldPlugin != nullptr, "Invalid replace plugin Id");
  572. }
  573. else
  574. {
  575. id = pData->curPluginCount;
  576. if (id == pData->maxPluginNumber)
  577. {
  578. setLastError("Maximum number of plugins reached");
  579. return false;
  580. }
  581. CARLA_SAFE_ASSERT_RETURN_ERR(pData->plugins[id].plugin == nullptr, "Invalid engine internal data (err #13)");
  582. }
  583. CarlaPlugin::Initializer initializer = {
  584. this,
  585. id,
  586. filename,
  587. name,
  588. label
  589. };
  590. CarlaPlugin* plugin = nullptr;
  591. #ifndef BUILD_BRIDGE
  592. CarlaString bridgeBinary(pData->options.binaryDir);
  593. if (bridgeBinary.isNotEmpty())
  594. {
  595. # ifdef CARLA_OS_LINUX
  596. // test for local build
  597. if (bridgeBinary.endsWith("/source/backend/"))
  598. bridgeBinary += "../bridges/";
  599. # endif
  600. # ifndef CARLA_OS_WIN
  601. if (btype == BINARY_NATIVE)
  602. {
  603. bridgeBinary += "carla-bridge-native";
  604. }
  605. else
  606. # endif
  607. {
  608. switch (btype)
  609. {
  610. case BINARY_POSIX32:
  611. bridgeBinary += "carla-bridge-posix32";
  612. break;
  613. case BINARY_POSIX64:
  614. bridgeBinary += "carla-bridge-posix64";
  615. break;
  616. case BINARY_WIN32:
  617. bridgeBinary += "carla-bridge-win32.exe";
  618. break;
  619. case BINARY_WIN64:
  620. bridgeBinary += "carla-bridge-win64.exe";
  621. break;
  622. default:
  623. bridgeBinary.clear();
  624. break;
  625. }
  626. }
  627. QFile file(bridgeBinary.getBuffer());
  628. if (! file.exists())
  629. bridgeBinary.clear();
  630. }
  631. if (ptype != PLUGIN_INTERNAL && ptype != PLUGIN_JACK && (btype != BINARY_NATIVE || (pData->options.preferPluginBridges && bridgeBinary.isNotEmpty())))
  632. {
  633. if (bridgeBinary.isNotEmpty())
  634. {
  635. plugin = CarlaPlugin::newBridge(initializer, btype, ptype, bridgeBinary.getBuffer());
  636. }
  637. # ifdef CARLA_OS_LINUX
  638. else if (btype == BINARY_WIN32)
  639. {
  640. // fallback to dssi-vst
  641. QFileInfo fileInfo(filename);
  642. CarlaString label2(fileInfo.fileName().toUtf8().constData());
  643. label2.replace(' ', '*');
  644. CarlaPlugin::Initializer init2 = {
  645. this,
  646. id,
  647. "/usr/lib/dssi/dssi-vst.so",
  648. name,
  649. (const char*)label2
  650. };
  651. char* const oldVstPath(getenv("VST_PATH"));
  652. carla_setenv("VST_PATH", fileInfo.absoluteDir().absolutePath().toUtf8().constData());
  653. plugin = CarlaPlugin::newDSSI(init2);
  654. if (oldVstPath != nullptr)
  655. carla_setenv("VST_PATH", oldVstPath);
  656. }
  657. # endif
  658. else
  659. {
  660. setLastError("This Carla build cannot handle this binary");
  661. return false;
  662. }
  663. }
  664. else
  665. #endif // ! BUILD_BRIDGE
  666. {
  667. bool use16Outs;
  668. setLastError("Invalid or unsupported plugin type");
  669. switch (ptype)
  670. {
  671. case PLUGIN_NONE:
  672. break;
  673. case PLUGIN_INTERNAL:
  674. if (std::strcmp(label, "Csound") == 0)
  675. {
  676. plugin = CarlaPlugin::newCsound(initializer);
  677. }
  678. else if (std::strcmp(label, "FluidSynth") == 0)
  679. {
  680. use16Outs = (extra != nullptr && std::strcmp((const char*)extra, "true") == 0);
  681. plugin = CarlaPlugin::newFluidSynth(initializer, use16Outs);
  682. }
  683. else if (std::strcmp(label, "LinuxSampler (GIG)") == 0)
  684. {
  685. use16Outs = (extra != nullptr && std::strcmp((const char*)extra, "true") == 0);
  686. plugin = CarlaPlugin::newLinuxSampler(initializer, "GIG", use16Outs);
  687. }
  688. else if (std::strcmp(label, "LinuxSampler (SF2)") == 0)
  689. {
  690. use16Outs = (extra != nullptr && std::strcmp((const char*)extra, "true") == 0);
  691. plugin = CarlaPlugin::newLinuxSampler(initializer, "SF2", use16Outs);
  692. }
  693. else if (std::strcmp(label, "LinuxSampler (SFZ)") == 0)
  694. {
  695. use16Outs = (extra != nullptr && std::strcmp((const char*)extra, "true") == 0);
  696. plugin = CarlaPlugin::newLinuxSampler(initializer, "SFZ", use16Outs);
  697. }
  698. else
  699. {
  700. plugin = CarlaPlugin::newNative(initializer);
  701. }
  702. break;
  703. case PLUGIN_LADSPA:
  704. plugin = CarlaPlugin::newLADSPA(initializer, (const LADSPA_RDF_Descriptor*)extra);
  705. break;
  706. case PLUGIN_DSSI:
  707. plugin = CarlaPlugin::newDSSI(initializer);
  708. break;
  709. case PLUGIN_LV2:
  710. plugin = CarlaPlugin::newLV2(initializer);
  711. break;
  712. case PLUGIN_VST:
  713. plugin = CarlaPlugin::newVST(initializer);
  714. break;
  715. case PLUGIN_VST3:
  716. plugin = CarlaPlugin::newVST3(initializer);
  717. break;
  718. case PLUGIN_AU:
  719. plugin = CarlaPlugin::newAU(initializer);
  720. break;
  721. case PLUGIN_JACK:
  722. plugin = CarlaPlugin::newJACK(initializer);
  723. break;
  724. case PLUGIN_REWIRE:
  725. plugin = CarlaPlugin::newReWire(initializer);
  726. break;
  727. case PLUGIN_FILE_CSD:
  728. plugin = CarlaPlugin::newFileCSD(initializer);
  729. break;
  730. case PLUGIN_FILE_GIG:
  731. use16Outs = (extra != nullptr && std::strcmp((const char*)extra, "true") == 0);
  732. plugin = CarlaPlugin::newFileGIG(initializer, use16Outs);
  733. break;
  734. case PLUGIN_FILE_SF2:
  735. use16Outs = (extra != nullptr && std::strcmp((const char*)extra, "true") == 0);
  736. plugin = CarlaPlugin::newFileSF2(initializer, use16Outs);
  737. break;
  738. case PLUGIN_FILE_SFZ:
  739. plugin = CarlaPlugin::newFileSFZ(initializer);
  740. break;
  741. }
  742. }
  743. if (plugin == nullptr)
  744. return false;
  745. plugin->registerToOscClient();
  746. EnginePluginData& pluginData(pData->plugins[id]);
  747. pluginData.plugin = plugin;
  748. pluginData.insPeak[0] = 0.0f;
  749. pluginData.insPeak[1] = 0.0f;
  750. pluginData.outsPeak[0] = 0.0f;
  751. pluginData.outsPeak[1] = 0.0f;
  752. if (oldPlugin != nullptr)
  753. {
  754. delete oldPlugin;
  755. callback(ENGINE_CALLBACK_RELOAD_ALL, id, 0, 0, 0.0f, plugin->getName());
  756. }
  757. else
  758. {
  759. ++pData->curPluginCount;
  760. callback(ENGINE_CALLBACK_PLUGIN_ADDED, id, 0, 0, 0.0f, plugin->getName());
  761. }
  762. return true;
  763. }
  764. bool CarlaEngine::removePlugin(const unsigned int id)
  765. {
  766. CARLA_SAFE_ASSERT_RETURN_ERR(pData->plugins != nullptr, "Invalid engine internal data (err #14)");
  767. CARLA_SAFE_ASSERT_RETURN_ERR(pData->curPluginCount != 0, "Invalid engine internal data (err #15)");
  768. CARLA_SAFE_ASSERT_RETURN_ERR(pData->nextAction.opcode == kEnginePostActionNull, "Invalid engine internal data (err #16)");
  769. CARLA_SAFE_ASSERT_RETURN_ERR(id < pData->curPluginCount, "Invalid plugin Id (err #1)");
  770. carla_debug("CarlaEngine::removePlugin(%i)", id);
  771. CARLA_ENGINE_THREAD_SAFE_SECTION
  772. CarlaPlugin* const plugin(pData->plugins[id].plugin);
  773. CARLA_SAFE_ASSERT_RETURN_ERR(plugin != nullptr, "Could not find plugin to remove");
  774. CARLA_SAFE_ASSERT_RETURN_ERR(plugin->getId() == id, "Invalid engine internal data (err #17)");
  775. pData->thread.stop(500);
  776. const bool lockWait(isRunning() && pData->options.processMode != ENGINE_PROCESS_MODE_MULTIPLE_CLIENTS);
  777. const CarlaEngineProtectedData::ScopedActionLock sal(pData, kEnginePostActionRemovePlugin, id, 0, lockWait);
  778. #ifndef BUILD_BRIDGE
  779. if (isOscControlRegistered())
  780. oscSend_control_remove_plugin(id);
  781. #endif
  782. delete plugin;
  783. if (isRunning() && ! pData->aboutToClose)
  784. pData->thread.start();
  785. callback(ENGINE_CALLBACK_PLUGIN_REMOVED, id, 0, 0, 0.0f, nullptr);
  786. return true;
  787. }
  788. bool CarlaEngine::removeAllPlugins()
  789. {
  790. CARLA_SAFE_ASSERT_RETURN_ERR(pData->plugins != nullptr, "Invalid engine internal data (err #18)");
  791. CARLA_SAFE_ASSERT_RETURN_ERR(pData->nextPluginId == pData->maxPluginNumber, "Invalid engine internal data (err #19)");
  792. CARLA_SAFE_ASSERT_RETURN_ERR(pData->nextAction.opcode == kEnginePostActionNull, "Invalid engine internal data (err #20)");
  793. carla_debug("CarlaEngine::removeAllPlugins()");
  794. CARLA_ENGINE_THREAD_SAFE_SECTION
  795. if (pData->curPluginCount == 0)
  796. return true;
  797. pData->thread.stop(500);
  798. const bool lockWait(isRunning());
  799. const CarlaEngineProtectedData::ScopedActionLock sal(pData, kEnginePostActionZeroCount, 0, 0, lockWait);
  800. for (unsigned int i=0; i < pData->maxPluginNumber; ++i)
  801. {
  802. EnginePluginData& pluginData(pData->plugins[i]);
  803. if (pluginData.plugin != nullptr)
  804. {
  805. delete pluginData.plugin;
  806. pluginData.plugin = nullptr;
  807. }
  808. pluginData.insPeak[0] = 0.0f;
  809. pluginData.insPeak[1] = 0.0f;
  810. pluginData.outsPeak[0] = 0.0f;
  811. pluginData.outsPeak[1] = 0.0f;
  812. }
  813. if (isRunning() && ! pData->aboutToClose)
  814. pData->thread.start();
  815. return true;
  816. }
  817. const char* CarlaEngine::renamePlugin(const unsigned int id, const char* const newName)
  818. {
  819. CARLA_SAFE_ASSERT_RETURN_ERRN(pData->plugins != nullptr, "Invalid engine internal data (err #21)");
  820. CARLA_SAFE_ASSERT_RETURN_ERRN(pData->curPluginCount != 0, "Invalid engine internal data (err #22)");
  821. CARLA_SAFE_ASSERT_RETURN_ERRN(pData->nextAction.opcode == kEnginePostActionNull, "Invalid engine internal data (err #23)");
  822. CARLA_SAFE_ASSERT_RETURN_ERRN(id < pData->curPluginCount, "Invalid plugin Id (err #2)");
  823. CARLA_SAFE_ASSERT_RETURN_ERRN(newName != nullptr && newName[0] != '\0', "Invalid plugin name");
  824. carla_debug("CarlaEngine::renamePlugin(%i, \"%s\")", id, newName);
  825. CARLA_ENGINE_THREAD_SAFE_SECTION
  826. CarlaPlugin* const plugin(pData->plugins[id].plugin);
  827. CARLA_SAFE_ASSERT_RETURN_ERRN(plugin != nullptr, "Could not find plugin to rename");
  828. CARLA_SAFE_ASSERT_RETURN_ERRN(plugin->getId() == id, "Invalid engine internal data (err #24)");
  829. if (const char* const name = getUniquePluginName(newName))
  830. {
  831. plugin->setName(name);
  832. return name;
  833. }
  834. setLastError("Unable to get new unique plugin name");
  835. return nullptr;
  836. }
  837. bool CarlaEngine::clonePlugin(const unsigned int id)
  838. {
  839. CARLA_SAFE_ASSERT_RETURN_ERR(pData->plugins != nullptr, "Invalid engine internal data (err #25)");
  840. CARLA_SAFE_ASSERT_RETURN_ERR(pData->curPluginCount != 0, "Invalid engine internal data (err #26)");
  841. CARLA_SAFE_ASSERT_RETURN_ERR(pData->nextAction.opcode == kEnginePostActionNull, "Invalid engine internal data (err #27)");
  842. CARLA_SAFE_ASSERT_RETURN_ERR(id < pData->curPluginCount, "Invalid plugin Id (err #3)");
  843. carla_debug("CarlaEngine::clonePlugin(%i)", id);
  844. CARLA_ENGINE_THREAD_SAFE_SECTION
  845. CarlaPlugin* const plugin(pData->plugins[id].plugin);
  846. CARLA_SAFE_ASSERT_RETURN_ERR(plugin != nullptr, "Could not find plugin to clone");
  847. CARLA_SAFE_ASSERT_RETURN_ERR(plugin->getId() == id, "Invalid engine internal data (err #28)");
  848. char label[STR_MAX+1];
  849. carla_zeroChar(label, STR_MAX+1);
  850. plugin->getLabel(label);
  851. const unsigned int pluginCountBefore(pData->curPluginCount);
  852. if (! addPlugin(plugin->getBinaryType(), plugin->getType(), plugin->getFilename(), plugin->getName(), label, plugin->getExtraStuff()))
  853. return false;
  854. CARLA_ASSERT(pluginCountBefore+1 == pData->curPluginCount);
  855. if (CarlaPlugin* const newPlugin = pData->plugins[pluginCountBefore].plugin)
  856. newPlugin->loadSaveState(plugin->getSaveState());
  857. return true;
  858. }
  859. bool CarlaEngine::replacePlugin(const unsigned int id)
  860. {
  861. CARLA_SAFE_ASSERT_RETURN_ERR(pData->plugins != nullptr, "Invalid engine internal data (err #29)");
  862. CARLA_SAFE_ASSERT_RETURN_ERR(pData->curPluginCount != 0, "Invalid engine internal data (err #30)");
  863. CARLA_SAFE_ASSERT_RETURN_ERR(pData->nextAction.opcode == kEnginePostActionNull, "Invalid engine internal data (err #31)");
  864. CARLA_SAFE_ASSERT_RETURN_ERR(id < pData->curPluginCount, "Invalid plugin Id (err #4)");
  865. carla_debug("CarlaEngine::replacePlugin(%i)", id);
  866. CARLA_ENGINE_THREAD_SAFE_SECTION
  867. CarlaPlugin* const plugin(pData->plugins[id].plugin);
  868. CARLA_SAFE_ASSERT_RETURN_ERR(plugin != nullptr, "Could not find plugin to replace");
  869. CARLA_SAFE_ASSERT_RETURN_ERR(plugin->getId() == id, "Invalid engine internal data (err #32)");
  870. pData->nextPluginId = id;
  871. return true;
  872. }
  873. bool CarlaEngine::switchPlugins(const unsigned int idA, const unsigned int idB)
  874. {
  875. CARLA_SAFE_ASSERT_RETURN_ERR(pData->plugins != nullptr, "Invalid engine internal data (err #33)");
  876. CARLA_SAFE_ASSERT_RETURN_ERR(pData->curPluginCount >= 2, "Invalid engine internal data (err #34)");
  877. CARLA_SAFE_ASSERT_RETURN_ERR(pData->nextAction.opcode == kEnginePostActionNull, "Invalid engine internal data (err #35)");
  878. CARLA_SAFE_ASSERT_RETURN_ERR(idA != idB, "Invalid operation, cannot switch plugin with itself");
  879. CARLA_SAFE_ASSERT_RETURN_ERR(idA < pData->curPluginCount, "Invalid plugin Id (err #5)");
  880. CARLA_SAFE_ASSERT_RETURN_ERR(idB < pData->curPluginCount, "Invalid plugin Id (err #6)");
  881. carla_debug("CarlaEngine::switchPlugins(%i)", idA, idB);
  882. CARLA_ENGINE_THREAD_SAFE_SECTION
  883. CarlaPlugin* const pluginA(pData->plugins[idA].plugin);
  884. CarlaPlugin* const pluginB(pData->plugins[idB].plugin);
  885. CARLA_SAFE_ASSERT_RETURN_ERR(pluginA != nullptr, "Could not find plugin to switch (err #1)");
  886. CARLA_SAFE_ASSERT_RETURN_ERR(pluginA != nullptr, "Could not find plugin to switch (err #2)");
  887. CARLA_SAFE_ASSERT_RETURN_ERR(pluginA->getId() == idA, "Invalid engine internal data (err #36)");
  888. CARLA_SAFE_ASSERT_RETURN_ERR(pluginB->getId() == idB, "Invalid engine internal data (err #37)");
  889. pData->thread.stop(500);
  890. const bool lockWait(isRunning() && pData->options.processMode != ENGINE_PROCESS_MODE_MULTIPLE_CLIENTS);
  891. const CarlaEngineProtectedData::ScopedActionLock sal(pData, kEnginePostActionSwitchPlugins, idA, idB, lockWait);
  892. #ifndef BUILD_BRIDGE // TODO
  893. //if (isOscControlRegistered())
  894. // oscSend_control_switch_plugins(idA, idB);
  895. #endif
  896. if (isRunning() && ! pData->aboutToClose)
  897. pData->thread.start();
  898. return true;
  899. }
  900. CarlaPlugin* CarlaEngine::getPlugin(const unsigned int id) const
  901. {
  902. CARLA_SAFE_ASSERT_RETURN_ERRN(pData->plugins != nullptr, "Invalid engine internal data (err #38)");
  903. CARLA_SAFE_ASSERT_RETURN_ERRN(pData->curPluginCount != 0, "Invalid engine internal data (err #39)");
  904. CARLA_SAFE_ASSERT_RETURN_ERRN(pData->nextAction.opcode == kEnginePostActionNull, "Invalid engine internal data (err #40)");
  905. CARLA_SAFE_ASSERT_RETURN_ERRN(id < pData->curPluginCount, "Invalid plugin Id (err #7)");
  906. carla_debug("CarlaEngine::getPlugin(%i) [count:%i]", id, pData->curPluginCount);
  907. return pData->plugins[id].plugin;
  908. }
  909. CarlaPlugin* CarlaEngine::getPluginUnchecked(const unsigned int id) const noexcept
  910. {
  911. return pData->plugins[id].plugin;
  912. }
  913. const char* CarlaEngine::getUniquePluginName(const char* const name) const
  914. {
  915. CARLA_SAFE_ASSERT_RETURN(pData->nextAction.opcode == kEnginePostActionNull, nullptr);
  916. CARLA_SAFE_ASSERT_RETURN(name != nullptr && name[0] != '\0', nullptr);
  917. carla_debug("CarlaEngine::getUniquePluginName(\"%s\")", name);
  918. CarlaString sname;
  919. sname = name;
  920. if (sname.isEmpty())
  921. {
  922. sname = "(No name)";
  923. return sname.dup();
  924. }
  925. const size_t maxNameSize(carla_min<uint>(getMaxClientNameSize(), 0xff, 6) - 6); // 6 = strlen(" (10)") + 1
  926. if (maxNameSize == 0 || ! isRunning())
  927. return sname.dup();
  928. sname.truncate(maxNameSize);
  929. sname.replace(':', '.'); // ':' is used in JACK1 to split client/port names
  930. for (unsigned short i=0; i < pData->curPluginCount; ++i)
  931. {
  932. CARLA_SAFE_ASSERT_BREAK(pData->plugins[i].plugin != nullptr);
  933. // Check if unique name doesn't exist
  934. if (const char* const pluginName = pData->plugins[i].plugin->getName())
  935. {
  936. if (sname != pluginName)
  937. continue;
  938. }
  939. // Check if string has already been modified
  940. {
  941. const size_t len(sname.length());
  942. // 1 digit, ex: " (2)"
  943. if (sname[len-4] == ' ' && sname[len-3] == '(' && sname.isDigit(len-2) && sname[len-1] == ')')
  944. {
  945. int number = sname[len-2] - '0';
  946. if (number == 9)
  947. {
  948. // next number is 10, 2 digits
  949. sname.truncate(len-4);
  950. sname += " (10)";
  951. //sname.replace(" (9)", " (10)");
  952. }
  953. else
  954. sname[len-2] = char('0' + number + 1);
  955. continue;
  956. }
  957. // 2 digits, ex: " (11)"
  958. if (sname[len-5] == ' ' && sname[len-4] == '(' && sname.isDigit(len-3) && sname.isDigit(len-2) && sname[len-1] == ')')
  959. {
  960. char n2 = sname[len-2];
  961. char n3 = sname[len-3];
  962. if (n2 == '9')
  963. {
  964. n2 = '0';
  965. n3 = static_cast<char>(n3 + 1);
  966. }
  967. else
  968. n2 = static_cast<char>(n2 + 1);
  969. sname[len-2] = n2;
  970. sname[len-3] = n3;
  971. continue;
  972. }
  973. }
  974. // Modify string if not
  975. sname += " (2)";
  976. }
  977. return sname.dup();
  978. }
  979. // -----------------------------------------------------------------------
  980. // Project management
  981. bool CarlaEngine::loadFile(const char* const filename)
  982. {
  983. CARLA_SAFE_ASSERT_RETURN_ERR(filename != nullptr && filename[0] != '\0', "Invalid filename (err #1)");
  984. carla_debug("CarlaEngine::loadFile(\"%s\")", filename);
  985. CARLA_ENGINE_THREAD_SAFE_SECTION
  986. QFileInfo fileInfo(filename);
  987. if (! fileInfo.exists())
  988. {
  989. setLastError("File does not exist");
  990. return false;
  991. }
  992. if (! fileInfo.isFile())
  993. {
  994. setLastError("Not a file");
  995. return false;
  996. }
  997. if (! fileInfo.isReadable())
  998. {
  999. setLastError("File is not readable");
  1000. return false;
  1001. }
  1002. CarlaString baseName(fileInfo.baseName().toUtf8().constData());
  1003. CarlaString extension(fileInfo.suffix().toLower().toUtf8().constData());
  1004. extension.toLower();
  1005. // -------------------------------------------------------------------
  1006. if (extension == "carxp" || extension == "carxs")
  1007. return loadProject(filename);
  1008. // -------------------------------------------------------------------
  1009. if (extension == "csd")
  1010. return addPlugin(PLUGIN_FILE_CSD, filename, baseName, baseName);
  1011. if (extension == "gig")
  1012. return addPlugin(PLUGIN_FILE_GIG, filename, baseName, baseName);
  1013. if (extension == "sf2")
  1014. return addPlugin(PLUGIN_FILE_SF2, filename, baseName, baseName);
  1015. if (extension == "sfz")
  1016. return addPlugin(PLUGIN_FILE_SFZ, filename, baseName, baseName);
  1017. // -------------------------------------------------------------------
  1018. if (extension == "aiff" || extension == "flac" || extension == "oga" || extension == "ogg" || extension == "w64" || extension == "wav")
  1019. {
  1020. #ifdef WANT_AUDIOFILE
  1021. if (addPlugin(PLUGIN_INTERNAL, nullptr, baseName, "audiofile"))
  1022. {
  1023. if (CarlaPlugin* const plugin = getPlugin(pData->curPluginCount-1))
  1024. plugin->setCustomData(CUSTOM_DATA_TYPE_STRING, "file", filename, true);
  1025. return true;
  1026. }
  1027. return false;
  1028. #else
  1029. setLastError("This Carla build does not have Audio file support");
  1030. return false;
  1031. #endif
  1032. }
  1033. if (extension == "3g2" || extension == "3gp" || extension == "aac" || extension == "ac3" || extension == "amr" || extension == "ape" ||
  1034. extension == "mp2" || extension == "mp3" || extension == "mpc" || extension == "wma")
  1035. {
  1036. #ifdef WANT_AUDIOFILE
  1037. # ifdef HAVE_FFMPEG
  1038. if (addPlugin(PLUGIN_INTERNAL, nullptr, baseName, "audiofile"))
  1039. {
  1040. if (CarlaPlugin* const plugin = getPlugin(pData->curPluginCount-1))
  1041. plugin->setCustomData(CUSTOM_DATA_TYPE_STRING, "file", filename, true);
  1042. return true;
  1043. }
  1044. return false;
  1045. # else
  1046. setLastError("This Carla build has Audio file support, but not libav/ffmpeg");
  1047. return false;
  1048. # endif
  1049. #else
  1050. setLastError("This Carla build does not have Audio file support");
  1051. return false;
  1052. #endif
  1053. }
  1054. // -------------------------------------------------------------------
  1055. if (extension == "mid" || extension == "midi")
  1056. {
  1057. #ifdef WANT_MIDIFILE
  1058. if (addPlugin(PLUGIN_INTERNAL, nullptr, baseName, "midifile"))
  1059. {
  1060. if (CarlaPlugin* const plugin = getPlugin(pData->curPluginCount-1))
  1061. plugin->setCustomData(CUSTOM_DATA_TYPE_STRING, "file", filename, true);
  1062. return true;
  1063. }
  1064. return false;
  1065. #else
  1066. setLastError("This Carla build does not have MIDI file support");
  1067. return false;
  1068. #endif
  1069. }
  1070. // -------------------------------------------------------------------
  1071. // ZynAddSubFX
  1072. if (extension == "xmz" || extension == "xiz")
  1073. {
  1074. #ifdef WANT_ZYNADDSUBFX
  1075. if (addPlugin(PLUGIN_INTERNAL, nullptr, baseName, "zynaddsubfx"))
  1076. {
  1077. if (CarlaPlugin* const plugin = getPlugin(pData->curPluginCount-1))
  1078. plugin->setCustomData(CUSTOM_DATA_TYPE_STRING, (extension == "xmz") ? "CarlaAlternateFile1" : "CarlaAlternateFile2", filename, true);
  1079. return true;
  1080. }
  1081. return false;
  1082. #else
  1083. setLastError("This Carla build does not have ZynAddSubFX support");
  1084. return false;
  1085. #endif
  1086. }
  1087. // -------------------------------------------------------------------
  1088. setLastError("Unknown file extension");
  1089. return false;
  1090. }
  1091. bool CarlaEngine::loadProject(const char* const filename)
  1092. {
  1093. CARLA_SAFE_ASSERT_RETURN_ERR(filename != nullptr && filename[0] != '\0', "Invalid filename (err #2)");
  1094. carla_debug("CarlaEngine::loadProject(\"%s\")", filename);
  1095. CARLA_ENGINE_THREAD_SAFE_SECTION
  1096. QFile file(filename);
  1097. if (! file.open(QIODevice::ReadOnly | QIODevice::Text))
  1098. return false;
  1099. QDomDocument xml;
  1100. xml.setContent(file.readAll());
  1101. file.close();
  1102. QDomNode xmlNode(xml.documentElement());
  1103. const bool isPreset(xmlNode.toElement().tagName().compare("carla-preset", Qt::CaseInsensitive) == 0);
  1104. if (xmlNode.toElement().tagName().compare("carla-project", Qt::CaseInsensitive) != 0 && ! isPreset)
  1105. {
  1106. setLastError("Not a valid Carla project or preset file");
  1107. return false;
  1108. }
  1109. // handle plugins first
  1110. for (QDomNode node = xmlNode.firstChild(); ! node.isNull(); node = node.nextSibling())
  1111. {
  1112. if (isPreset || node.toElement().tagName().compare("plugin", Qt::CaseInsensitive) == 0)
  1113. {
  1114. SaveState saveState;
  1115. fillSaveStateFromXmlNode(saveState, isPreset ? xmlNode : node);
  1116. CARLA_SAFE_ASSERT_CONTINUE(saveState.type != nullptr);
  1117. const void* extraStuff = nullptr;
  1118. // check if using GIG, SF2 or SFZ 16outs
  1119. static const char kUse16OutsSuffix[] = " (16 outs)";
  1120. if (CarlaString(saveState.label).endsWith(kUse16OutsSuffix))
  1121. {
  1122. if (std::strcmp(saveState.type, "GIG") == 0 || std::strcmp(saveState.type, "SF2") == 0)
  1123. extraStuff = "true";
  1124. }
  1125. // TODO - proper find&load plugins
  1126. if (addPlugin(getPluginTypeFromString(saveState.type), saveState.binary, saveState.name, saveState.label, extraStuff))
  1127. {
  1128. if (CarlaPlugin* const plugin = getPlugin(pData->curPluginCount-1))
  1129. plugin->loadSaveState(saveState);
  1130. }
  1131. }
  1132. if (isPreset)
  1133. return true;
  1134. }
  1135. #ifndef BUILD_BRIDGE
  1136. // now connections
  1137. for (QDomNode node = xmlNode.firstChild(); ! node.isNull(); node = node.nextSibling())
  1138. {
  1139. if (node.toElement().tagName().compare("patchbay", Qt::CaseInsensitive) == 0)
  1140. {
  1141. CarlaString sourcePort, targetPort;
  1142. for (QDomNode patchNode = node.firstChild(); ! patchNode.isNull(); patchNode = patchNode.nextSibling())
  1143. {
  1144. sourcePort.clear();
  1145. targetPort.clear();
  1146. if (patchNode.toElement().tagName().compare("connection", Qt::CaseInsensitive) != 0)
  1147. continue;
  1148. for (QDomNode connNode = patchNode.firstChild(); ! connNode.isNull(); connNode = connNode.nextSibling())
  1149. {
  1150. const QString tag(connNode.toElement().tagName());
  1151. const QString text(connNode.toElement().text().trimmed());
  1152. if (tag.compare("source", Qt::CaseInsensitive) == 0)
  1153. sourcePort = text.toUtf8().constData();
  1154. else if (tag.compare("target", Qt::CaseInsensitive) == 0)
  1155. targetPort = text.toUtf8().constData();
  1156. }
  1157. if (sourcePort.isNotEmpty() && targetPort.isNotEmpty())
  1158. restorePatchbayConnection(sourcePort.getBuffer(), targetPort.getBuffer());
  1159. }
  1160. break;
  1161. }
  1162. }
  1163. #endif
  1164. return true;
  1165. }
  1166. bool CarlaEngine::saveProject(const char* const filename)
  1167. {
  1168. CARLA_SAFE_ASSERT_RETURN_ERR(filename != nullptr && filename[0] != '\0', "Invalid filename (err #3)");
  1169. carla_debug("CarlaEngine::saveProject(\"%s\")", filename);
  1170. CARLA_ENGINE_THREAD_SAFE_SECTION
  1171. QFile file(filename);
  1172. if (! file.open(QIODevice::WriteOnly | QIODevice::Text))
  1173. return false;
  1174. QTextStream out(&file);
  1175. out << "<?xml version='1.0' encoding='UTF-8'?>\n";
  1176. out << "<!DOCTYPE CARLA-PROJECT>\n";
  1177. out << "<CARLA-PROJECT VERSION='2.0'>\n";
  1178. bool firstPlugin = true;
  1179. char strBuf[STR_MAX+1];
  1180. for (unsigned int i=0; i < pData->curPluginCount; ++i)
  1181. {
  1182. CarlaPlugin* const plugin(pData->plugins[i].plugin);
  1183. if (plugin != nullptr && plugin->isEnabled())
  1184. {
  1185. if (! firstPlugin)
  1186. out << "\n";
  1187. strBuf[0] = '\0';
  1188. plugin->getRealName(strBuf);
  1189. //if (strBuf[0] != '\0')
  1190. // out << QString(" <!-- %1 -->\n").arg(xmlSafeString(strBuf, true));
  1191. QString content;
  1192. fillXmlStringFromSaveState(content, plugin->getSaveState());
  1193. out << " <Plugin>\n";
  1194. out << content;
  1195. out << " </Plugin>\n";
  1196. firstPlugin = false;
  1197. }
  1198. }
  1199. #ifndef BUILD_BRIDGE
  1200. if (const char* const* patchbayConns = getPatchbayConnections())
  1201. {
  1202. if (! firstPlugin)
  1203. out << "\n";
  1204. out << " <Patchbay>\n";
  1205. for (int i=0; patchbayConns[i] != nullptr && patchbayConns[i+1] != nullptr; ++i, ++i )
  1206. {
  1207. const char* const connSource(patchbayConns[i]);
  1208. const char* const connTarget(patchbayConns[i+1]);
  1209. CARLA_SAFE_ASSERT_CONTINUE(connSource != nullptr && connSource[0] != '\0');
  1210. CARLA_SAFE_ASSERT_CONTINUE(connTarget != nullptr && connTarget[0] != '\0');
  1211. out << " <Connection>\n";
  1212. out << " <Source>" << connSource << "</Source>\n";
  1213. out << " <Target>" << connTarget << "</Target>\n";
  1214. out << " </Connection>\n";
  1215. delete[] connSource;
  1216. delete[] connTarget;
  1217. }
  1218. out << " </Patchbay>\n";
  1219. }
  1220. #endif
  1221. out << "</CARLA-PROJECT>\n";
  1222. file.close();
  1223. return true;
  1224. }
  1225. // -----------------------------------------------------------------------
  1226. // Information (base)
  1227. unsigned int CarlaEngine::getHints() const noexcept
  1228. {
  1229. return pData->hints;
  1230. }
  1231. uint32_t CarlaEngine::getBufferSize() const noexcept
  1232. {
  1233. return pData->bufferSize;
  1234. }
  1235. double CarlaEngine::getSampleRate() const noexcept
  1236. {
  1237. return pData->sampleRate;
  1238. }
  1239. const char* CarlaEngine::getName() const noexcept
  1240. {
  1241. return pData->name.getBuffer();
  1242. }
  1243. EngineProcessMode CarlaEngine::getProccessMode() const noexcept
  1244. {
  1245. return pData->options.processMode;
  1246. }
  1247. const EngineOptions& CarlaEngine::getOptions() const noexcept
  1248. {
  1249. return pData->options;
  1250. }
  1251. const EngineTimeInfo& CarlaEngine::getTimeInfo() const noexcept
  1252. {
  1253. return pData->timeInfo;
  1254. }
  1255. // -----------------------------------------------------------------------
  1256. // Information (peaks)
  1257. float CarlaEngine::getInputPeak(const unsigned int pluginId, const bool isLeft) const noexcept
  1258. {
  1259. CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount, 0.0f);
  1260. return pData->plugins[pluginId].insPeak[isLeft ? 0 : 1];
  1261. }
  1262. float CarlaEngine::getOutputPeak(const unsigned int pluginId, const bool isLeft) const noexcept
  1263. {
  1264. CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount, 0.0f);
  1265. return pData->plugins[pluginId].outsPeak[isLeft ? 0 : 1];
  1266. }
  1267. // -----------------------------------------------------------------------
  1268. // Callback
  1269. void CarlaEngine::callback(const EngineCallbackOpcode action, const unsigned int pluginId, const int value1, const int value2, const float value3, const char* const valueStr) noexcept
  1270. {
  1271. carla_debug("CarlaEngine::callback(%s, %i, %i, %i, %f, \"%s\")", EngineCallbackOpcode2Str(action), pluginId, value1, value2, value3, valueStr);
  1272. if (pData->callback != nullptr)
  1273. {
  1274. try {
  1275. pData->callback(pData->callbackPtr, action, pluginId, value1, value2, value3, valueStr);
  1276. } catch(...) {}
  1277. }
  1278. }
  1279. void CarlaEngine::setCallback(const EngineCallbackFunc func, void* const ptr) noexcept
  1280. {
  1281. carla_debug("CarlaEngine::setCallback(%p, %p)", func, ptr);
  1282. CARLA_ENGINE_THREAD_SAFE_SECTION
  1283. pData->callback = func;
  1284. pData->callbackPtr = ptr;
  1285. }
  1286. // -----------------------------------------------------------------------
  1287. // File Callback
  1288. const char* CarlaEngine::runFileCallback(const FileCallbackOpcode action, const bool isDir, const char* const title, const char* const filter) noexcept
  1289. {
  1290. CARLA_SAFE_ASSERT_RETURN(title != nullptr && title[0] != '\0', nullptr);
  1291. CARLA_SAFE_ASSERT_RETURN(filter != nullptr, nullptr);
  1292. carla_debug("CarlaEngine::runFileCallback(%i:%s, %s, \"%s\", \"%s\")", action, FileCallbackOpcode2Str(action), bool2str(isDir), title, filter);
  1293. CARLA_ENGINE_THREAD_SAFE_SECTION
  1294. const char* ret = nullptr;
  1295. if (pData->fileCallback != nullptr)
  1296. {
  1297. try {
  1298. ret = pData->fileCallback(pData->fileCallbackPtr, action, isDir, title, filter);
  1299. } catch(...) {}
  1300. }
  1301. return ret;
  1302. }
  1303. void CarlaEngine::setFileCallback(const FileCallbackFunc func, void* const ptr) noexcept
  1304. {
  1305. CARLA_ENGINE_THREAD_SAFE_SECTION
  1306. pData->fileCallback = func;
  1307. pData->fileCallbackPtr = ptr;
  1308. }
  1309. #ifndef BUILD_BRIDGE
  1310. // -----------------------------------------------------------------------
  1311. // Patchbay
  1312. bool CarlaEngine::patchbayConnect(const int portA, const int portB)
  1313. {
  1314. CARLA_SAFE_ASSERT_RETURN(pData->options.processMode == ENGINE_PROCESS_MODE_CONTINUOUS_RACK || pData->options.processMode == ENGINE_PROCESS_MODE_PATCHBAY, false);
  1315. CARLA_SAFE_ASSERT_RETURN(pData->bufAudio.isReady, false);
  1316. carla_debug("CarlaEngineRtAudio::patchbayConnect(%i, %i)", portA, portB);
  1317. CARLA_ENGINE_THREAD_SAFE_SECTION
  1318. if (pData->bufAudio.usePatchbay)
  1319. {
  1320. // not implemented yet
  1321. return false;
  1322. }
  1323. EngineRackBuffers* const rack(pData->bufAudio.rack);
  1324. CARLA_SAFE_ASSERT_RETURN_ERR(portA > RACK_PATCHBAY_PORT_MAX, "Invalid output port");
  1325. CARLA_SAFE_ASSERT_RETURN_ERR(portB > RACK_PATCHBAY_PORT_MAX, "Invalid input port");
  1326. // only allow connections between Carla and other ports
  1327. if (portA < 0 && portB < 0)
  1328. {
  1329. setLastError("Invalid connection (1)");
  1330. return false;
  1331. }
  1332. if (portA >= 0 && portB >= 0)
  1333. {
  1334. setLastError("Invalid connection (2)");
  1335. return false;
  1336. }
  1337. const int carlaPort = (portA < 0) ? portA : portB;
  1338. const int targetPort = (carlaPort == portA) ? portB : portA;
  1339. bool makeConnection = false;
  1340. switch (carlaPort)
  1341. {
  1342. case RACK_PATCHBAY_PORT_AUDIO_IN1:
  1343. CARLA_SAFE_ASSERT_BREAK(targetPort >= RACK_PATCHBAY_GROUP_AUDIO_IN*1000);
  1344. CARLA_SAFE_ASSERT_BREAK(targetPort <= RACK_PATCHBAY_GROUP_AUDIO_IN*1000+999);
  1345. rack->connectLock.lock();
  1346. rack->connectedIns[0].append(targetPort - RACK_PATCHBAY_GROUP_AUDIO_IN*1000);
  1347. rack->connectLock.unlock();
  1348. makeConnection = true;
  1349. break;
  1350. case RACK_PATCHBAY_PORT_AUDIO_IN2:
  1351. CARLA_SAFE_ASSERT_BREAK(targetPort >= RACK_PATCHBAY_GROUP_AUDIO_IN*1000);
  1352. CARLA_SAFE_ASSERT_BREAK(targetPort <= RACK_PATCHBAY_GROUP_AUDIO_IN*1000+999);
  1353. rack->connectLock.lock();
  1354. rack->connectedIns[1].append(targetPort - RACK_PATCHBAY_GROUP_AUDIO_IN*1000);
  1355. rack->connectLock.unlock();
  1356. makeConnection = true;
  1357. break;
  1358. case RACK_PATCHBAY_PORT_AUDIO_OUT1:
  1359. CARLA_SAFE_ASSERT_BREAK(targetPort >= RACK_PATCHBAY_GROUP_AUDIO_OUT*1000);
  1360. CARLA_SAFE_ASSERT_BREAK(targetPort <= RACK_PATCHBAY_GROUP_AUDIO_OUT*1000+999);
  1361. rack->connectLock.lock();
  1362. rack->connectedOuts[0].append(targetPort - RACK_PATCHBAY_GROUP_AUDIO_OUT*1000);
  1363. rack->connectLock.unlock();
  1364. makeConnection = true;
  1365. break;
  1366. case RACK_PATCHBAY_PORT_AUDIO_OUT2:
  1367. CARLA_SAFE_ASSERT_BREAK(targetPort >= RACK_PATCHBAY_GROUP_AUDIO_OUT*1000);
  1368. CARLA_SAFE_ASSERT_BREAK(targetPort <= RACK_PATCHBAY_GROUP_AUDIO_OUT*1000+999);
  1369. rack->connectLock.lock();
  1370. rack->connectedOuts[1].append(targetPort - RACK_PATCHBAY_GROUP_AUDIO_OUT*1000);
  1371. rack->connectLock.unlock();
  1372. makeConnection = true;
  1373. break;
  1374. case RACK_PATCHBAY_PORT_MIDI_IN:
  1375. CARLA_SAFE_ASSERT_BREAK(targetPort >= RACK_PATCHBAY_GROUP_MIDI_IN*1000);
  1376. CARLA_SAFE_ASSERT_BREAK(targetPort <= RACK_PATCHBAY_GROUP_MIDI_IN*1000+999);
  1377. makeConnection = connectRackMidiInPort(targetPort - RACK_PATCHBAY_GROUP_MIDI_IN*1000);
  1378. break;
  1379. case RACK_PATCHBAY_PORT_MIDI_OUT:
  1380. CARLA_SAFE_ASSERT_BREAK(targetPort >= RACK_PATCHBAY_GROUP_MIDI_OUT*1000);
  1381. CARLA_SAFE_ASSERT_BREAK(targetPort <= RACK_PATCHBAY_GROUP_MIDI_OUT*1000+999);
  1382. makeConnection = connectRackMidiOutPort(targetPort - RACK_PATCHBAY_GROUP_MIDI_OUT*1000);
  1383. break;
  1384. }
  1385. if (! makeConnection)
  1386. {
  1387. setLastError("Invalid connection (3)");
  1388. return false;
  1389. }
  1390. ConnectionToId connectionToId;
  1391. connectionToId.id = rack->lastConnectionId;
  1392. connectionToId.portOut = portA;
  1393. connectionToId.portIn = portB;
  1394. callback(ENGINE_CALLBACK_PATCHBAY_CONNECTION_ADDED, rack->lastConnectionId, portA, portB, 0.0f, nullptr);
  1395. rack->usedConnections.append(connectionToId);
  1396. rack->lastConnectionId++;
  1397. return true;
  1398. }
  1399. bool CarlaEngine::patchbayDisconnect(const uint connectionId)
  1400. {
  1401. CARLA_SAFE_ASSERT_RETURN(pData->options.processMode == ENGINE_PROCESS_MODE_CONTINUOUS_RACK || pData->options.processMode == ENGINE_PROCESS_MODE_PATCHBAY, false);
  1402. CARLA_SAFE_ASSERT_RETURN(pData->bufAudio.isReady, false);
  1403. carla_debug("CarlaEngineRtAudio::patchbayDisconnect(%i)", connectionId);
  1404. CARLA_ENGINE_THREAD_SAFE_SECTION
  1405. if (pData->bufAudio.usePatchbay)
  1406. {
  1407. // not implemented yet
  1408. return false;
  1409. }
  1410. EngineRackBuffers* const rack(pData->bufAudio.rack);
  1411. CARLA_SAFE_ASSERT_RETURN_ERR(rack->usedConnections.count() > 0, "No connections available");
  1412. for (LinkedList<ConnectionToId>::Itenerator it=rack->usedConnections.begin(); it.valid(); it.next())
  1413. {
  1414. const ConnectionToId& connection(it.getValue());
  1415. if (connection.id == connectionId)
  1416. {
  1417. const int otherPort((connection.portOut >= 0) ? connection.portOut : connection.portIn);
  1418. const int carlaPort((otherPort == connection.portOut) ? connection.portIn : connection.portOut);
  1419. if (otherPort >= RACK_PATCHBAY_GROUP_MIDI_OUT*1000)
  1420. {
  1421. CARLA_SAFE_ASSERT_RETURN(carlaPort == RACK_PATCHBAY_PORT_MIDI_IN, false);
  1422. const int portId(otherPort-RACK_PATCHBAY_GROUP_MIDI_OUT*1000);
  1423. disconnectRackMidiInPort(portId);
  1424. }
  1425. else if (otherPort >= RACK_PATCHBAY_GROUP_MIDI_IN*1000)
  1426. {
  1427. CARLA_SAFE_ASSERT_RETURN(carlaPort == RACK_PATCHBAY_PORT_MIDI_OUT, false);
  1428. const int portId(otherPort-RACK_PATCHBAY_GROUP_MIDI_IN*1000);
  1429. disconnectRackMidiOutPort(portId);
  1430. }
  1431. else if (otherPort >= RACK_PATCHBAY_GROUP_AUDIO_OUT*1000)
  1432. {
  1433. CARLA_SAFE_ASSERT_RETURN(carlaPort == RACK_PATCHBAY_PORT_AUDIO_OUT1 || carlaPort == RACK_PATCHBAY_PORT_AUDIO_OUT2, false);
  1434. const int portId(otherPort-RACK_PATCHBAY_GROUP_AUDIO_OUT*1000);
  1435. rack->connectLock.lock();
  1436. if (carlaPort == RACK_PATCHBAY_PORT_AUDIO_OUT1)
  1437. rack->connectedOuts[0].removeAll(portId);
  1438. else
  1439. rack->connectedOuts[1].removeAll(portId);
  1440. rack->connectLock.unlock();
  1441. }
  1442. else if (otherPort >= RACK_PATCHBAY_GROUP_AUDIO_IN*1000)
  1443. {
  1444. CARLA_SAFE_ASSERT_RETURN(carlaPort == RACK_PATCHBAY_PORT_AUDIO_IN1 || carlaPort == RACK_PATCHBAY_PORT_AUDIO_IN2, false);
  1445. const int portId(otherPort-RACK_PATCHBAY_GROUP_AUDIO_IN*1000);
  1446. rack->connectLock.lock();
  1447. if (carlaPort == RACK_PATCHBAY_PORT_AUDIO_IN1)
  1448. rack->connectedIns[0].removeAll(portId);
  1449. else
  1450. rack->connectedIns[1].removeAll(portId);
  1451. rack->connectLock.unlock();
  1452. }
  1453. else
  1454. {
  1455. CARLA_SAFE_ASSERT_RETURN(false, false);
  1456. }
  1457. callback(ENGINE_CALLBACK_PATCHBAY_CONNECTION_REMOVED, connection.id, connection.portOut, connection.portIn, 0.0f, nullptr);
  1458. rack->usedConnections.remove(it);
  1459. return true;
  1460. }
  1461. }
  1462. setLastError("Failed to find connection");
  1463. return false;
  1464. }
  1465. bool CarlaEngine::patchbayRefresh()
  1466. {
  1467. setLastError("Unsupported operation");
  1468. return false;
  1469. }
  1470. #endif
  1471. // -----------------------------------------------------------------------
  1472. // Transport
  1473. void CarlaEngine::transportPlay() noexcept
  1474. {
  1475. pData->time.playing = true;
  1476. }
  1477. void CarlaEngine::transportPause() noexcept
  1478. {
  1479. pData->time.playing = false;
  1480. }
  1481. void CarlaEngine::transportRelocate(const uint64_t frame) noexcept
  1482. {
  1483. pData->time.frame = frame;
  1484. }
  1485. // -----------------------------------------------------------------------
  1486. // Error handling
  1487. const char* CarlaEngine::getLastError() const noexcept
  1488. {
  1489. return pData->lastError.getBuffer();
  1490. }
  1491. void CarlaEngine::setLastError(const char* const error) const
  1492. {
  1493. CARLA_ENGINE_THREAD_SAFE_SECTION
  1494. pData->lastError = error;
  1495. }
  1496. void CarlaEngine::setAboutToClose() noexcept
  1497. {
  1498. carla_debug("CarlaEngine::setAboutToClose()");
  1499. pData->aboutToClose = true;
  1500. }
  1501. // -----------------------------------------------------------------------
  1502. // Global options
  1503. void CarlaEngine::setOption(const EngineOption option, const int value, const char* const valueStr)
  1504. {
  1505. carla_debug("CarlaEngine::setOption(%i:%s, %i, \"%s\")", option, EngineOption2Str(option), value, valueStr);
  1506. CARLA_ENGINE_THREAD_SAFE_SECTION
  1507. if (isRunning() && (option == ENGINE_OPTION_PROCESS_MODE || option == ENGINE_OPTION_AUDIO_NUM_PERIODS || option == ENGINE_OPTION_AUDIO_DEVICE))
  1508. return carla_stderr("CarlaEngine::setOption(%i:%s, %i, \"%s\") - Cannot set this option while engine is running!", option, EngineOption2Str(option), value, valueStr);
  1509. switch (option)
  1510. {
  1511. case ENGINE_OPTION_DEBUG:
  1512. break;
  1513. case ENGINE_OPTION_PROCESS_MODE:
  1514. CARLA_SAFE_ASSERT_RETURN(value >= ENGINE_PROCESS_MODE_SINGLE_CLIENT && value <= ENGINE_PROCESS_MODE_BRIDGE,);
  1515. pData->options.processMode = static_cast<EngineProcessMode>(value);
  1516. break;
  1517. case ENGINE_OPTION_TRANSPORT_MODE:
  1518. CARLA_SAFE_ASSERT_RETURN(value >= ENGINE_TRANSPORT_MODE_INTERNAL && value <= ENGINE_TRANSPORT_MODE_BRIDGE,);
  1519. pData->options.transportMode = static_cast<EngineTransportMode>(value);
  1520. break;
  1521. case ENGINE_OPTION_FORCE_STEREO:
  1522. CARLA_SAFE_ASSERT_RETURN(value == 0 || value == 1,);
  1523. pData->options.forceStereo = (value != 0);
  1524. break;
  1525. case ENGINE_OPTION_PREFER_PLUGIN_BRIDGES:
  1526. CARLA_SAFE_ASSERT_RETURN(value == 0 || value == 1,);
  1527. pData->options.preferPluginBridges = (value != 0);
  1528. break;
  1529. case ENGINE_OPTION_PREFER_UI_BRIDGES:
  1530. CARLA_SAFE_ASSERT_RETURN(value == 0 || value == 1,);
  1531. pData->options.preferUiBridges = (value != 0);
  1532. break;
  1533. case ENGINE_OPTION_UIS_ALWAYS_ON_TOP:
  1534. CARLA_SAFE_ASSERT_RETURN(value == 0 || value == 1,);
  1535. pData->options.uisAlwaysOnTop = (value != 0);
  1536. break;
  1537. case ENGINE_OPTION_MAX_PARAMETERS:
  1538. CARLA_SAFE_ASSERT_RETURN(value >= 0,);
  1539. pData->options.maxParameters = static_cast<uint>(value);
  1540. break;
  1541. case ENGINE_OPTION_UI_BRIDGES_TIMEOUT:
  1542. CARLA_SAFE_ASSERT_RETURN(value >= 0,);
  1543. pData->options.uiBridgesTimeout = static_cast<uint>(value);
  1544. break;
  1545. case ENGINE_OPTION_AUDIO_NUM_PERIODS:
  1546. CARLA_SAFE_ASSERT_RETURN(value >= 2 && value <= 3,);
  1547. pData->options.audioNumPeriods = static_cast<uint>(value);
  1548. break;
  1549. case ENGINE_OPTION_AUDIO_BUFFER_SIZE:
  1550. CARLA_SAFE_ASSERT_RETURN(value >= 8,);
  1551. pData->options.audioBufferSize = static_cast<uint>(value);
  1552. break;
  1553. case ENGINE_OPTION_AUDIO_SAMPLE_RATE:
  1554. CARLA_SAFE_ASSERT_RETURN(value >= 22050,);
  1555. pData->options.audioSampleRate = static_cast<uint>(value);
  1556. break;
  1557. case ENGINE_OPTION_AUDIO_DEVICE:
  1558. CARLA_SAFE_ASSERT_RETURN(valueStr != nullptr,);
  1559. if (pData->options.audioDevice != nullptr)
  1560. delete[] pData->options.audioDevice;
  1561. pData->options.audioDevice = carla_strdup(valueStr);
  1562. break;
  1563. case ENGINE_OPTION_PATH_BINARIES:
  1564. CARLA_SAFE_ASSERT_RETURN(valueStr != nullptr && valueStr[0] != '\0',);
  1565. if (pData->options.binaryDir != nullptr)
  1566. delete[] pData->options.binaryDir;
  1567. pData->options.binaryDir = carla_strdup(valueStr);
  1568. break;
  1569. case ENGINE_OPTION_PATH_RESOURCES:
  1570. CARLA_SAFE_ASSERT_RETURN(valueStr != nullptr && valueStr[0] != '\0',);
  1571. if (pData->options.resourceDir != nullptr)
  1572. delete[] pData->options.resourceDir;
  1573. pData->options.resourceDir = carla_strdup(valueStr);
  1574. break;
  1575. case ENGINE_OPTION_FRONTEND_WIN_ID:
  1576. CARLA_SAFE_ASSERT_RETURN(valueStr != nullptr && valueStr[0] != '\0',);
  1577. const long winId(std::atol(valueStr));
  1578. CARLA_SAFE_ASSERT_RETURN(winId >= 0,);
  1579. pData->options.frontendWinId = static_cast<uintptr_t>(winId);
  1580. break;
  1581. }
  1582. }
  1583. // -----------------------------------------------------------------------
  1584. // OSC Stuff
  1585. #ifdef BUILD_BRIDGE
  1586. bool CarlaEngine::isOscBridgeRegistered() const noexcept
  1587. {
  1588. return (pData->oscData != nullptr);
  1589. }
  1590. #else
  1591. bool CarlaEngine::isOscControlRegistered() const noexcept
  1592. {
  1593. return pData->osc.isControlRegistered();
  1594. }
  1595. #endif
  1596. const char* CarlaEngine::getOscServerPathTCP() const noexcept
  1597. {
  1598. return pData->osc.getServerPathTCP();
  1599. }
  1600. const char* CarlaEngine::getOscServerPathUDP() const noexcept
  1601. {
  1602. return pData->osc.getServerPathUDP();
  1603. }
  1604. #ifdef BUILD_BRIDGE
  1605. void CarlaEngine::setOscBridgeData(const CarlaOscData* const oscData) const noexcept
  1606. {
  1607. CARLA_ENGINE_THREAD_SAFE_SECTION
  1608. pData->oscData = oscData;
  1609. }
  1610. #endif
  1611. // -----------------------------------------------------------------------
  1612. // Helper functions
  1613. EngineEvent* CarlaEngine::getInternalEventBuffer(const bool isInput) const noexcept
  1614. {
  1615. return isInput ? pData->bufEvents.in : pData->bufEvents.out;
  1616. }
  1617. void CarlaEngine::registerEnginePlugin(const unsigned int id, CarlaPlugin* const plugin) noexcept
  1618. {
  1619. CARLA_SAFE_ASSERT_RETURN(id == pData->curPluginCount,);
  1620. carla_debug("CarlaEngine::registerEnginePlugin(%i, %p)", id, plugin);
  1621. pData->plugins[id].plugin = plugin;
  1622. }
  1623. // -----------------------------------------------------------------------
  1624. // Internal stuff
  1625. void CarlaEngine::bufferSizeChanged(const uint32_t newBufferSize)
  1626. {
  1627. carla_debug("CarlaEngine::bufferSizeChanged(%i)", newBufferSize);
  1628. for (unsigned int i=0; i < pData->curPluginCount; ++i)
  1629. {
  1630. CarlaPlugin* const plugin(pData->plugins[i].plugin);
  1631. if (plugin != nullptr && plugin->isEnabled())
  1632. plugin->bufferSizeChanged(newBufferSize);
  1633. }
  1634. callback(ENGINE_CALLBACK_BUFFER_SIZE_CHANGED, 0, static_cast<int>(newBufferSize), 0, 0.0f, nullptr);
  1635. }
  1636. void CarlaEngine::sampleRateChanged(const double newSampleRate)
  1637. {
  1638. carla_debug("CarlaEngine::sampleRateChanged(%g)", newSampleRate);
  1639. for (unsigned int i=0; i < pData->curPluginCount; ++i)
  1640. {
  1641. CarlaPlugin* const plugin(pData->plugins[i].plugin);
  1642. if (plugin != nullptr && plugin->isEnabled())
  1643. plugin->sampleRateChanged(newSampleRate);
  1644. }
  1645. callback(ENGINE_CALLBACK_SAMPLE_RATE_CHANGED, 0, 0, 0, static_cast<float>(newSampleRate), nullptr);
  1646. }
  1647. void CarlaEngine::offlineModeChanged(const bool isOfflineNow)
  1648. {
  1649. carla_debug("CarlaEngine::offlineModeChanged(%s)", bool2str(isOfflineNow));
  1650. for (unsigned int i=0; i < pData->curPluginCount; ++i)
  1651. {
  1652. CarlaPlugin* const plugin(pData->plugins[i].plugin);
  1653. if (plugin != nullptr && plugin->isEnabled())
  1654. plugin->offlineModeChanged(isOfflineNow);
  1655. }
  1656. }
  1657. void CarlaEngine::runPendingRtEvents() noexcept
  1658. {
  1659. pData->doNextPluginAction(true);
  1660. if (pData->time.playing)
  1661. pData->time.frame += pData->bufferSize;
  1662. if (pData->options.transportMode == ENGINE_TRANSPORT_MODE_INTERNAL)
  1663. {
  1664. pData->timeInfo.playing = pData->time.playing;
  1665. pData->timeInfo.frame = pData->time.frame;
  1666. }
  1667. }
  1668. void CarlaEngine::setPluginPeaks(const unsigned int pluginId, float const inPeaks[2], float const outPeaks[2]) noexcept
  1669. {
  1670. EnginePluginData& pluginData(pData->plugins[pluginId]);
  1671. pluginData.insPeak[0] = inPeaks[0];
  1672. pluginData.insPeak[1] = inPeaks[1];
  1673. pluginData.outsPeak[0] = outPeaks[0];
  1674. pluginData.outsPeak[1] = outPeaks[1];
  1675. }
  1676. #ifndef BUILD_BRIDGE
  1677. // -----------------------------------------------------------------------
  1678. // Patchbay stuff
  1679. const char* const* CarlaEngine::getPatchbayConnections() const
  1680. {
  1681. carla_debug("CarlaEngine::getPatchbayConnections()");
  1682. if (pData->bufAudio.usePatchbay)
  1683. {
  1684. CARLA_SAFE_ASSERT_RETURN(pData->bufAudio.patchbay != nullptr, nullptr);
  1685. return pData->bufAudio.patchbay->getConnections();
  1686. }
  1687. else
  1688. {
  1689. CARLA_SAFE_ASSERT_RETURN(pData->bufAudio.rack != nullptr, nullptr);
  1690. return pData->bufAudio.rack->getConnections();
  1691. }
  1692. }
  1693. static int getCarlaPortIdFromName(const char* const shortname) noexcept
  1694. {
  1695. if (std::strcmp(shortname, "AudioIn1") == 0)
  1696. return RACK_PATCHBAY_PORT_AUDIO_IN1;
  1697. if (std::strcmp(shortname, "AudioIn2") == 0)
  1698. return RACK_PATCHBAY_PORT_AUDIO_IN2;
  1699. if (std::strcmp(shortname, "AudioOut1") == 0)
  1700. return RACK_PATCHBAY_PORT_AUDIO_OUT1;
  1701. if (std::strcmp(shortname, "AudioOut2") == 0)
  1702. return RACK_PATCHBAY_PORT_AUDIO_OUT2;
  1703. if (std::strcmp(shortname, "MidiIn") == 0)
  1704. return RACK_PATCHBAY_PORT_MIDI_IN;
  1705. if (std::strcmp(shortname, "MidiOut") == 0)
  1706. return RACK_PATCHBAY_PORT_MIDI_OUT;
  1707. return RACK_PATCHBAY_PORT_MAX;
  1708. }
  1709. void CarlaEngine::restorePatchbayConnection(const char* const connSource, const char* const connTarget)
  1710. {
  1711. CARLA_SAFE_ASSERT_RETURN(connSource != nullptr && connSource[0] != '\0',);
  1712. CARLA_SAFE_ASSERT_RETURN(connTarget != nullptr && connTarget[0] != '\0',);
  1713. carla_debug("CarlaEngine::restorePatchbayConnection(\"%s\", \"%s\")", connSource, connTarget);
  1714. if (pData->bufAudio.usePatchbay)
  1715. {
  1716. // TODO
  1717. }
  1718. else
  1719. {
  1720. int sourcePort, targetPort;
  1721. if (std::strncmp(connSource, "Carla:", 6) == 0)
  1722. sourcePort = getCarlaPortIdFromName(connSource+6);
  1723. else if (std::strncmp(connSource, "AudioIn:", 8) == 0)
  1724. sourcePort = std::atoi(connSource+8) + RACK_PATCHBAY_GROUP_AUDIO_IN*1000 - 1;
  1725. else if (std::strncmp(connSource, "AudioOut:", 9) == 0)
  1726. sourcePort = std::atoi(connSource+9) + RACK_PATCHBAY_GROUP_AUDIO_OUT*1000 - 1;
  1727. else if (std::strncmp(connSource, "MidiIn:", 7) == 0)
  1728. sourcePort = std::atoi(connSource+7) + RACK_PATCHBAY_GROUP_MIDI_IN*1000 - 1;
  1729. else if (std::strncmp(connSource, "MidiOut:", 8) == 0)
  1730. sourcePort = std::atoi(connSource+8) + RACK_PATCHBAY_GROUP_MIDI_OUT*1000 - 1;
  1731. else
  1732. sourcePort = RACK_PATCHBAY_PORT_MAX;
  1733. if (std::strncmp(connTarget, "Carla:", 6) == 0)
  1734. targetPort = getCarlaPortIdFromName(connTarget+6);
  1735. else if (std::strncmp(connTarget, "AudioIn:", 8) == 0)
  1736. targetPort = std::atoi(connTarget+8) + RACK_PATCHBAY_GROUP_AUDIO_IN*1000 - 1;
  1737. else if (std::strncmp(connTarget, "AudioOut:", 9) == 0)
  1738. targetPort = std::atoi(connTarget+9) + RACK_PATCHBAY_GROUP_AUDIO_OUT*1000 - 1;
  1739. else if (std::strncmp(connTarget, "MidiIn:", 7) == 0)
  1740. targetPort = std::atoi(connTarget+7) + RACK_PATCHBAY_GROUP_MIDI_IN*1000 - 1;
  1741. else if (std::strncmp(connTarget, "MidiOut:", 8) == 0)
  1742. targetPort = std::atoi(connTarget+8) + RACK_PATCHBAY_GROUP_MIDI_OUT*1000 - 1;
  1743. else
  1744. targetPort = RACK_PATCHBAY_PORT_MAX;
  1745. if (sourcePort != RACK_PATCHBAY_PORT_MAX && targetPort != RACK_PATCHBAY_PORT_MAX)
  1746. patchbayConnect(targetPort, sourcePort);
  1747. }
  1748. }
  1749. #endif
  1750. // -----------------------------------------------------------------------
  1751. // Bridge/Controller OSC stuff
  1752. #ifdef BUILD_BRIDGE
  1753. void CarlaEngine::oscSend_bridge_plugin_info1(const PluginCategory category, const uint hints, const long uniqueId) const noexcept
  1754. {
  1755. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  1756. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  1757. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  1758. carla_debug("CarlaEngine::oscSend_bridge_plugin_info1(%i:%s, %X, %l)", category, PluginCategory2Str(category), hints, uniqueId);
  1759. char targetPath[std::strlen(pData->oscData->path)+21];
  1760. std::strcpy(targetPath, pData->oscData->path);
  1761. std::strcat(targetPath, "/bridge_plugin_info1");
  1762. try_lo_send(pData->oscData->target, targetPath, "iih", static_cast<int32_t>(category), static_cast<int32_t>(hints), static_cast<int64_t>(uniqueId));
  1763. }
  1764. void CarlaEngine::oscSend_bridge_plugin_info2(const char* const realName, const char* const label, const char* const maker, const char* const copyright) const noexcept
  1765. {
  1766. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  1767. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  1768. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  1769. CARLA_SAFE_ASSERT_RETURN(realName != nullptr && realName[0] != '\0',);
  1770. CARLA_SAFE_ASSERT_RETURN(label != nullptr && label[0] != '\0',);
  1771. CARLA_SAFE_ASSERT_RETURN(maker != nullptr,);
  1772. CARLA_SAFE_ASSERT_RETURN(copyright != nullptr,);
  1773. carla_debug("CarlaEngine::oscSend_bridge_plugin_info2(\"%s\", \"%s\", \"%s\", \"%s\")", realName, label, maker, copyright);
  1774. char targetPath[std::strlen(pData->oscData->path)+21];
  1775. std::strcpy(targetPath, pData->oscData->path);
  1776. std::strcat(targetPath, "/bridge_plugin_info2");
  1777. try_lo_send(pData->oscData->target, targetPath, "ssss", realName, label, maker, copyright);
  1778. }
  1779. void CarlaEngine::oscSend_bridge_audio_count(const uint32_t ins, const uint32_t outs) const noexcept
  1780. {
  1781. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  1782. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  1783. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  1784. carla_debug("CarlaEngine::oscSend_bridge_audio_count(%i, %i)", ins, outs);
  1785. char targetPath[std::strlen(pData->oscData->path)+20];
  1786. std::strcpy(targetPath, pData->oscData->path);
  1787. std::strcat(targetPath, "/bridge_audio_count");
  1788. try_lo_send(pData->oscData->target, targetPath, "ii", static_cast<int32_t>(ins), static_cast<int32_t>(outs));
  1789. }
  1790. void CarlaEngine::oscSend_bridge_midi_count(const uint32_t ins, const uint32_t outs) const noexcept
  1791. {
  1792. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  1793. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  1794. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  1795. carla_debug("CarlaEngine::oscSend_bridge_midi_count(%i, %i)", ins, outs);
  1796. char targetPath[std::strlen(pData->oscData->path)+19];
  1797. std::strcpy(targetPath, pData->oscData->path);
  1798. std::strcat(targetPath, "/bridge_midi_count");
  1799. try_lo_send(pData->oscData->target, targetPath, "ii", static_cast<int32_t>(ins), static_cast<int32_t>(outs));
  1800. }
  1801. void CarlaEngine::oscSend_bridge_parameter_count(const uint32_t ins, const uint32_t outs) const noexcept
  1802. {
  1803. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  1804. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  1805. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  1806. carla_debug("CarlaEngine::oscSend_bridge_parameter_count(%i, %i)", ins, outs);
  1807. char targetPath[std::strlen(pData->oscData->path)+24];
  1808. std::strcpy(targetPath, pData->oscData->path);
  1809. std::strcat(targetPath, "/bridge_parameter_count");
  1810. try_lo_send(pData->oscData->target, targetPath, "ii", static_cast<int32_t>(ins), static_cast<int32_t>(outs));
  1811. }
  1812. void CarlaEngine::oscSend_bridge_program_count(const uint32_t count) const noexcept
  1813. {
  1814. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  1815. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  1816. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  1817. carla_debug("CarlaEngine::oscSend_bridge_program_count(%i)", count);
  1818. char targetPath[std::strlen(pData->oscData->path)+23];
  1819. std::strcpy(targetPath, pData->oscData->path);
  1820. std::strcat(targetPath, "/bridge_program_count");
  1821. try_lo_send(pData->oscData->target, targetPath, "i", static_cast<int32_t>(count));
  1822. }
  1823. void CarlaEngine::oscSend_bridge_midi_program_count(const uint32_t count) const noexcept
  1824. {
  1825. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  1826. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  1827. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  1828. carla_debug("CarlaEngine::oscSend_bridge_midi_program_count(%i)", count);
  1829. char targetPath[std::strlen(pData->oscData->path)+27];
  1830. std::strcpy(targetPath, pData->oscData->path);
  1831. std::strcat(targetPath, "/bridge_midi_program_count");
  1832. try_lo_send(pData->oscData->target, targetPath, "i", static_cast<int32_t>(count));
  1833. }
  1834. void CarlaEngine::oscSend_bridge_parameter_data(const uint32_t index, const int32_t rindex, const ParameterType type, const uint hints, const char* const name, const char* const unit) const noexcept
  1835. {
  1836. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  1837. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  1838. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  1839. CARLA_SAFE_ASSERT_RETURN(name != nullptr,);
  1840. CARLA_SAFE_ASSERT_RETURN(unit != nullptr,);
  1841. carla_debug("CarlaEngine::oscSend_bridge_parameter_data(%i, %i, %i:%s, %X, \"%s\", \"%s\")", index, rindex, type, ParameterType2Str(type), hints, name, unit);
  1842. char targetPath[std::strlen(pData->oscData->path)+23];
  1843. std::strcpy(targetPath, pData->oscData->path);
  1844. std::strcat(targetPath, "/bridge_parameter_data");
  1845. try_lo_send(pData->oscData->target, targetPath, "iiiiss", static_cast<int32_t>(index), static_cast<int32_t>(rindex), static_cast<int32_t>(type), static_cast<int32_t>(hints), name, unit);
  1846. }
  1847. void CarlaEngine::oscSend_bridge_parameter_ranges1(const uint32_t index, const float def, const float min, const float max) const noexcept
  1848. {
  1849. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  1850. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  1851. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  1852. carla_debug("CarlaEngine::oscSend_bridge_parameter_ranges(%i, %f, %f, %f)", index, def, min, max);
  1853. char targetPath[std::strlen(pData->oscData->path)+26];
  1854. std::strcpy(targetPath, pData->oscData->path);
  1855. std::strcat(targetPath, "/bridge_parameter_ranges1");
  1856. try_lo_send(pData->oscData->target, targetPath, "ifff", static_cast<int32_t>(index), def, min, max);
  1857. }
  1858. void CarlaEngine::oscSend_bridge_parameter_ranges2(const uint32_t index, const float step, const float stepSmall, const float stepLarge) const noexcept
  1859. {
  1860. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  1861. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  1862. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  1863. carla_debug("CarlaEngine::oscSend_bridge_parameter_ranges(%i, %f, %f, %f)", index, step, stepSmall, stepLarge);
  1864. char targetPath[std::strlen(pData->oscData->path)+26];
  1865. std::strcpy(targetPath, pData->oscData->path);
  1866. std::strcat(targetPath, "/bridge_parameter_ranges2");
  1867. try_lo_send(pData->oscData->target, targetPath, "ifff", static_cast<int32_t>(index), step, stepSmall, stepLarge);
  1868. }
  1869. void CarlaEngine::oscSend_bridge_parameter_midi_cc(const uint32_t index, const int16_t cc) const noexcept
  1870. {
  1871. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  1872. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  1873. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  1874. carla_debug("CarlaEngine::oscSend_bridge_parameter_midi_cc(%i, %i)", index, cc);
  1875. char targetPath[std::strlen(pData->oscData->path)+26];
  1876. std::strcpy(targetPath, pData->oscData->path);
  1877. std::strcat(targetPath, "/bridge_parameter_midi_cc");
  1878. try_lo_send(pData->oscData->target, targetPath, "ii", static_cast<int32_t>(index), static_cast<int32_t>(cc));
  1879. }
  1880. void CarlaEngine::oscSend_bridge_parameter_midi_channel(const uint32_t index, const uint8_t channel) const noexcept
  1881. {
  1882. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  1883. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  1884. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  1885. carla_debug("CarlaEngine::oscSend_bridge_parameter_midi_channel(%i, %i)", index, channel);
  1886. char targetPath[std::strlen(pData->oscData->path)+31];
  1887. std::strcpy(targetPath, pData->oscData->path);
  1888. std::strcat(targetPath, "/bridge_parameter_midi_channel");
  1889. try_lo_send(pData->oscData->target, targetPath, "ii", static_cast<int32_t>(index), static_cast<int32_t>(channel));
  1890. }
  1891. void CarlaEngine::oscSend_bridge_parameter_value(const uint32_t index, const float value) const noexcept
  1892. {
  1893. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  1894. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  1895. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  1896. carla_debug("CarlaEngine::oscSend_bridge_parameter_value(%i, %f)", index, value);
  1897. char targetPath[std::strlen(pData->oscData->path)+24];
  1898. std::strcpy(targetPath, pData->oscData->path);
  1899. std::strcat(targetPath, "/bridge_parameter_value");
  1900. try_lo_send(pData->oscData->target, targetPath, "if", static_cast<int32_t>(index), value);
  1901. }
  1902. void CarlaEngine::oscSend_bridge_default_value(const uint32_t index, const float value) const noexcept
  1903. {
  1904. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  1905. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  1906. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  1907. carla_debug("CarlaEngine::oscSend_bridge_default_value(%i, %f)", index, value);
  1908. char targetPath[std::strlen(pData->oscData->path)+22];
  1909. std::strcpy(targetPath, pData->oscData->path);
  1910. std::strcat(targetPath, "/bridge_default_value");
  1911. try_lo_send(pData->oscData->target, targetPath, "if", static_cast<int32_t>(index), value);
  1912. }
  1913. void CarlaEngine::oscSend_bridge_current_program(const int32_t index) const noexcept
  1914. {
  1915. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  1916. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  1917. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  1918. carla_debug("CarlaEngine::oscSend_bridge_current_program(%i)", index);
  1919. char targetPath[std::strlen(pData->oscData->path)+24];
  1920. std::strcpy(targetPath, pData->oscData->path);
  1921. std::strcat(targetPath, "/bridge_current_program");
  1922. try_lo_send(pData->oscData->target, targetPath, "i", index);
  1923. }
  1924. void CarlaEngine::oscSend_bridge_current_midi_program(const int32_t index) const noexcept
  1925. {
  1926. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  1927. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  1928. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  1929. carla_debug("CarlaEngine::oscSend_bridge_current_midi_program(%i)", index);
  1930. char targetPath[std::strlen(pData->oscData->path)+30];
  1931. std::strcpy(targetPath, pData->oscData->path);
  1932. std::strcat(targetPath, "/bridge_current_midi_program");
  1933. try_lo_send(pData->oscData->target, targetPath, "i", index);
  1934. }
  1935. void CarlaEngine::oscSend_bridge_program_name(const uint32_t index, const char* const name) const noexcept
  1936. {
  1937. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  1938. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  1939. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  1940. CARLA_SAFE_ASSERT_RETURN(name != nullptr,);
  1941. carla_debug("CarlaEngine::oscSend_bridge_program_name(%i, \"%s\")", index, name);
  1942. char targetPath[std::strlen(pData->oscData->path)+21];
  1943. std::strcpy(targetPath, pData->oscData->path);
  1944. std::strcat(targetPath, "/bridge_program_name");
  1945. try_lo_send(pData->oscData->target, targetPath, "is", static_cast<int32_t>(index), name);
  1946. }
  1947. void CarlaEngine::oscSend_bridge_midi_program_data(const uint32_t index, const uint32_t bank, const uint32_t program, const char* const name) const noexcept
  1948. {
  1949. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  1950. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  1951. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  1952. CARLA_SAFE_ASSERT_RETURN(name != nullptr,);
  1953. carla_debug("CarlaEngine::oscSend_bridge_midi_program_data(%i, %i, %i, \"%s\")", index, bank, program, name);
  1954. char targetPath[std::strlen(pData->oscData->path)+26];
  1955. std::strcpy(targetPath, pData->oscData->path);
  1956. std::strcat(targetPath, "/bridge_midi_program_data");
  1957. try_lo_send(pData->oscData->target, targetPath, "iiis", static_cast<int32_t>(index), static_cast<int32_t>(bank), static_cast<int32_t>(program), name);
  1958. }
  1959. void CarlaEngine::oscSend_bridge_configure(const char* const key, const char* const value) const noexcept
  1960. {
  1961. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  1962. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  1963. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  1964. CARLA_SAFE_ASSERT_RETURN(key != nullptr && key[0] != '\0',);
  1965. CARLA_SAFE_ASSERT_RETURN(value != nullptr,);
  1966. carla_debug("CarlaEngine::oscSend_bridge_configure(\"%s\", \"%s\")", key, value);
  1967. char targetPath[std::strlen(pData->oscData->path)+18];
  1968. std::strcpy(targetPath, pData->oscData->path);
  1969. std::strcat(targetPath, "/bridge_configure");
  1970. try_lo_send(pData->oscData->target, targetPath, "ss", key, value);
  1971. }
  1972. void CarlaEngine::oscSend_bridge_set_custom_data(const char* const type, const char* const key, const char* const value) const noexcept
  1973. {
  1974. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  1975. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  1976. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  1977. CARLA_SAFE_ASSERT_RETURN(type != nullptr && type[0] != '\0',);
  1978. CARLA_SAFE_ASSERT_RETURN(key != nullptr && key[0] != '\0',);
  1979. CARLA_SAFE_ASSERT_RETURN(value != nullptr,);
  1980. carla_debug("CarlaEngine::oscSend_bridge_set_custom_data(\"%s\", \"%s\", \"%s\")", type, key, value);
  1981. char targetPath[std::strlen(pData->oscData->path)+24];
  1982. std::strcpy(targetPath, pData->oscData->path);
  1983. std::strcat(targetPath, "/bridge_set_custom_data");
  1984. try_lo_send(pData->oscData->target, targetPath, "sss", type, key, value);
  1985. }
  1986. void CarlaEngine::oscSend_bridge_set_chunk_data(const char* const chunkFile) const noexcept
  1987. {
  1988. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  1989. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  1990. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  1991. CARLA_SAFE_ASSERT_RETURN(chunkFile != nullptr && chunkFile[0] != '\0',);
  1992. carla_debug("CarlaEngine::oscSend_bridge_set_chunk_data(\"%s\")", chunkFile);
  1993. char targetPath[std::strlen(pData->oscData->path)+23];
  1994. std::strcpy(targetPath, pData->oscData->path);
  1995. std::strcat(targetPath, "/bridge_set_chunk_data");
  1996. try_lo_send(pData->oscData->target, targetPath, "s", chunkFile);
  1997. }
  1998. #else
  1999. void CarlaEngine::oscSend_control_add_plugin_start(const uint pluginId, const char* const pluginName) const noexcept
  2000. {
  2001. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  2002. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  2003. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  2004. CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
  2005. CARLA_SAFE_ASSERT_RETURN(pluginName != nullptr && pluginName[0] != '\0',);
  2006. carla_debug("CarlaEngine::oscSend_control_add_plugin_start(%i, \"%s\")", pluginId, pluginName);
  2007. char targetPath[std::strlen(pData->oscData->path)+18];
  2008. std::strcpy(targetPath, pData->oscData->path);
  2009. std::strcat(targetPath, "/add_plugin_start");
  2010. try_lo_send(pData->oscData->target, targetPath, "is", static_cast<int32_t>(pluginId), pluginName);
  2011. }
  2012. void CarlaEngine::oscSend_control_add_plugin_end(const uint pluginId) const noexcept
  2013. {
  2014. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  2015. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  2016. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  2017. CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
  2018. carla_debug("CarlaEngine::oscSend_control_add_plugin_end(%i)", pluginId);
  2019. char targetPath[std::strlen(pData->oscData->path)+16];
  2020. std::strcpy(targetPath, pData->oscData->path);
  2021. std::strcat(targetPath, "/add_plugin_end");
  2022. try_lo_send(pData->oscData->target, targetPath, "i", static_cast<int32_t>(pluginId));
  2023. }
  2024. void CarlaEngine::oscSend_control_remove_plugin(const uint pluginId) const noexcept
  2025. {
  2026. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  2027. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  2028. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  2029. CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
  2030. carla_debug("CarlaEngine::oscSend_control_remove_plugin(%i)", pluginId);
  2031. char targetPath[std::strlen(pData->oscData->path)+15];
  2032. std::strcpy(targetPath, pData->oscData->path);
  2033. std::strcat(targetPath, "/remove_plugin");
  2034. try_lo_send(pData->oscData->target, targetPath, "i", static_cast<int32_t>(pluginId));
  2035. }
  2036. void CarlaEngine::oscSend_control_set_plugin_info1(const uint pluginId, const PluginType type, const PluginCategory category, const uint hints, const long uniqueId) const noexcept
  2037. {
  2038. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  2039. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  2040. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  2041. CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
  2042. CARLA_SAFE_ASSERT_RETURN(type != PLUGIN_NONE,);
  2043. carla_debug("CarlaEngine::oscSend_control_set_plugin_data(%i, %i:%s, %i:%s, %X, %l)", pluginId, type, PluginType2Str(type), category, PluginCategory2Str(category), hints, uniqueId);
  2044. char targetPath[std::strlen(pData->oscData->path)+18];
  2045. std::strcpy(targetPath, pData->oscData->path);
  2046. std::strcat(targetPath, "/set_plugin_info1");
  2047. try_lo_send(pData->oscData->target, targetPath, "iiiih", static_cast<int32_t>(pluginId), static_cast<int32_t>(type), static_cast<int32_t>(category), static_cast<int32_t>(hints), static_cast<int64_t>(uniqueId));
  2048. }
  2049. void CarlaEngine::oscSend_control_set_plugin_info2(const uint pluginId, const char* const realName, const char* const label, const char* const maker, const char* const copyright) const noexcept
  2050. {
  2051. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  2052. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  2053. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  2054. CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
  2055. CARLA_SAFE_ASSERT_RETURN(realName != nullptr && realName[0] != '\0',);
  2056. CARLA_SAFE_ASSERT_RETURN(label != nullptr && label[0] != '\0',);
  2057. CARLA_SAFE_ASSERT_RETURN(maker != nullptr,);
  2058. CARLA_SAFE_ASSERT_RETURN(copyright != nullptr,);
  2059. carla_debug("CarlaEngine::oscSend_control_set_plugin_data(%i, \"%s\", \"%s\", \"%s\", \"%s\")", pluginId, realName, label, maker, copyright);
  2060. char targetPath[std::strlen(pData->oscData->path)+18];
  2061. std::strcpy(targetPath, pData->oscData->path);
  2062. std::strcat(targetPath, "/set_plugin_info2");
  2063. try_lo_send(pData->oscData->target, targetPath, "issss", static_cast<int32_t>(pluginId), realName, label, maker, copyright);
  2064. }
  2065. void CarlaEngine::oscSend_control_set_audio_count(const uint pluginId, const uint32_t ins, const uint32_t outs) const noexcept
  2066. {
  2067. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  2068. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  2069. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  2070. CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
  2071. carla_debug("CarlaEngine::oscSend_control_set_audio_count(%i, %i, %i)", pluginId, ins, outs);
  2072. char targetPath[std::strlen(pData->oscData->path)+18];
  2073. std::strcpy(targetPath, pData->oscData->path);
  2074. std::strcat(targetPath, "/set_audio_count");
  2075. try_lo_send(pData->oscData->target, targetPath, "iii", static_cast<int32_t>(pluginId), static_cast<int32_t>(ins), static_cast<int32_t>(outs));
  2076. }
  2077. void CarlaEngine::oscSend_control_set_midi_count(const uint pluginId, const uint32_t ins, const uint32_t outs) const noexcept
  2078. {
  2079. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  2080. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  2081. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  2082. CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
  2083. carla_debug("CarlaEngine::oscSend_control_set_midi_count(%i, %i, %i)", pluginId, ins, outs);
  2084. char targetPath[std::strlen(pData->oscData->path)+18];
  2085. std::strcpy(targetPath, pData->oscData->path);
  2086. std::strcat(targetPath, "/set_midi_count");
  2087. try_lo_send(pData->oscData->target, targetPath, "iii", static_cast<int32_t>(pluginId), static_cast<int32_t>(ins), static_cast<int32_t>(outs));
  2088. }
  2089. void CarlaEngine::oscSend_control_set_parameter_count(const uint pluginId, const uint32_t ins, const uint32_t outs) const noexcept
  2090. {
  2091. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  2092. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  2093. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  2094. CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
  2095. carla_debug("CarlaEngine::oscSend_control_set_parameter_count(%i, %i, %i)", pluginId, ins, outs);
  2096. char targetPath[std::strlen(pData->oscData->path)+18];
  2097. std::strcpy(targetPath, pData->oscData->path);
  2098. std::strcat(targetPath, "/set_parameter_count");
  2099. try_lo_send(pData->oscData->target, targetPath, "iii", static_cast<int32_t>(pluginId), static_cast<int32_t>(ins), static_cast<int32_t>(outs));
  2100. }
  2101. void CarlaEngine::oscSend_control_set_program_count(const uint pluginId, const uint32_t count) const noexcept
  2102. {
  2103. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  2104. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  2105. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  2106. CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
  2107. carla_debug("CarlaEngine::oscSend_control_set_program_count(%i, %i)", pluginId, count);
  2108. char targetPath[std::strlen(pData->oscData->path)+19];
  2109. std::strcpy(targetPath, pData->oscData->path);
  2110. std::strcat(targetPath, "/set_program_count");
  2111. try_lo_send(pData->oscData->target, targetPath, "ii", static_cast<int32_t>(pluginId), static_cast<int32_t>(count));
  2112. }
  2113. void CarlaEngine::oscSend_control_set_midi_program_count(const uint pluginId, const uint32_t count) const noexcept
  2114. {
  2115. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  2116. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  2117. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  2118. CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
  2119. carla_debug("CarlaEngine::oscSend_control_set_midi_program_count(%i, %i)", pluginId, count);
  2120. char targetPath[std::strlen(pData->oscData->path)+24];
  2121. std::strcpy(targetPath, pData->oscData->path);
  2122. std::strcat(targetPath, "/set_midi_program_count");
  2123. try_lo_send(pData->oscData->target, targetPath, "ii", static_cast<int32_t>(pluginId), static_cast<int32_t>(count));
  2124. }
  2125. void CarlaEngine::oscSend_control_set_parameter_data(const uint pluginId, const uint32_t index, const ParameterType type, const uint hints, const char* const name, const char* const unit) const noexcept
  2126. {
  2127. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  2128. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  2129. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  2130. CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
  2131. CARLA_SAFE_ASSERT_RETURN(name != nullptr && name[0] != '\0',);
  2132. CARLA_SAFE_ASSERT_RETURN(unit != nullptr,);
  2133. carla_debug("CarlaEngine::oscSend_control_set_parameter_data(%i, %i, %i:%s, %X, \"%s\", \"%s\")", pluginId, index, type, ParameterType2Str(type), hints, name, unit);
  2134. char targetPath[std::strlen(pData->oscData->path)+20];
  2135. std::strcpy(targetPath, pData->oscData->path);
  2136. std::strcat(targetPath, "/set_parameter_data");
  2137. try_lo_send(pData->oscData->target, targetPath, "iiiiss", static_cast<int32_t>(pluginId), static_cast<int32_t>(index), static_cast<int32_t>(type), static_cast<int32_t>(hints), name, unit);
  2138. }
  2139. void CarlaEngine::oscSend_control_set_parameter_ranges1(const uint pluginId, const uint32_t index, const float def, const float min, const float max) const noexcept
  2140. {
  2141. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  2142. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  2143. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  2144. CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
  2145. CARLA_SAFE_ASSERT_RETURN(def <= min && def >= max,);
  2146. CARLA_SAFE_ASSERT_RETURN(min < max,);
  2147. carla_debug("CarlaEngine::oscSend_control_set_parameter_ranges1(%i, %i, %f, %f, %f)", pluginId, index, def, min, max, def);
  2148. char targetPath[std::strlen(pData->oscData->path)+23];
  2149. std::strcpy(targetPath, pData->oscData->path);
  2150. std::strcat(targetPath, "/set_parameter_ranges1");
  2151. try_lo_send(pData->oscData->target, targetPath, "iifff", static_cast<int32_t>(pluginId), static_cast<int32_t>(index), def, min, max);
  2152. }
  2153. void CarlaEngine::oscSend_control_set_parameter_ranges2(const uint pluginId, const uint32_t index, const float step, const float stepSmall, const float stepLarge) const noexcept
  2154. {
  2155. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  2156. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  2157. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  2158. CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
  2159. CARLA_SAFE_ASSERT_RETURN(step <= stepSmall && step >= stepLarge,);
  2160. CARLA_SAFE_ASSERT_RETURN(stepSmall <= stepLarge,);
  2161. carla_debug("CarlaEngine::oscSend_control_set_parameter_ranges2(%i, %i, %f, %f, %f)", pluginId, index, step, stepSmall, stepLarge);
  2162. char targetPath[std::strlen(pData->oscData->path)+23];
  2163. std::strcpy(targetPath, pData->oscData->path);
  2164. std::strcat(targetPath, "/set_parameter_ranges");
  2165. try_lo_send(pData->oscData->target, targetPath, "iifff", static_cast<int32_t>(pluginId), static_cast<int32_t>(index), step, stepSmall, stepLarge);
  2166. }
  2167. void CarlaEngine::oscSend_control_set_parameter_midi_cc(const uint pluginId, const uint32_t index, const int16_t cc) const noexcept
  2168. {
  2169. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  2170. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  2171. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  2172. CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
  2173. CARLA_SAFE_ASSERT_RETURN(cc <= 0x5F,);
  2174. carla_debug("CarlaEngine::oscSend_control_set_parameter_midi_cc(%i, %i, %i)", pluginId, index, cc);
  2175. char targetPath[std::strlen(pData->oscData->path)+23];
  2176. std::strcpy(targetPath, pData->oscData->path);
  2177. std::strcat(targetPath, "/set_parameter_midi_cc");
  2178. try_lo_send(pData->oscData->target, targetPath, "iii", static_cast<int32_t>(pluginId), static_cast<int32_t>(index), static_cast<int32_t>(cc));
  2179. }
  2180. void CarlaEngine::oscSend_control_set_parameter_midi_channel(const uint pluginId, const uint32_t index, const uint8_t channel) const noexcept
  2181. {
  2182. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  2183. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  2184. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  2185. CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
  2186. CARLA_SAFE_ASSERT_RETURN(channel < MAX_MIDI_CHANNELS,);
  2187. carla_debug("CarlaEngine::oscSend_control_set_parameter_midi_channel(%i, %i, %i)", pluginId, index, channel);
  2188. char targetPath[std::strlen(pData->oscData->path)+28];
  2189. std::strcpy(targetPath, pData->oscData->path);
  2190. std::strcat(targetPath, "/set_parameter_midi_channel");
  2191. try_lo_send(pData->oscData->target, targetPath, "iii", static_cast<int32_t>(pluginId), static_cast<int32_t>(index), static_cast<int32_t>(channel));
  2192. }
  2193. void CarlaEngine::oscSend_control_set_parameter_value(const uint pluginId, const int32_t index, const float value) const noexcept
  2194. {
  2195. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  2196. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  2197. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  2198. CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
  2199. CARLA_SAFE_ASSERT_RETURN(index != PARAMETER_NULL,);
  2200. carla_debug("CarlaEngine::oscSend_control_set_parameter_value(%i, %i:%s, %f)", pluginId, index, (index < 0) ? InternalParameterIndex2Str(static_cast<InternalParameterIndex>(index)) : "(none)", value);
  2201. char targetPath[std::strlen(pData->oscData->path)+21];
  2202. std::strcpy(targetPath, pData->oscData->path);
  2203. std::strcat(targetPath, "/set_parameter_value");
  2204. try_lo_send(pData->oscData->target, targetPath, "iif", static_cast<int32_t>(pluginId), index, value);
  2205. }
  2206. void CarlaEngine::oscSend_control_set_default_value(const uint pluginId, const uint32_t index, const float value) const noexcept
  2207. {
  2208. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  2209. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  2210. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  2211. CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
  2212. carla_debug("CarlaEngine::oscSend_control_set_default_value(%i, %i, %f)", pluginId, index, value);
  2213. char targetPath[std::strlen(pData->oscData->path)+19];
  2214. std::strcpy(targetPath, pData->oscData->path);
  2215. std::strcat(targetPath, "/set_default_value");
  2216. try_lo_send(pData->oscData->target, targetPath, "iif", static_cast<int32_t>(pluginId), static_cast<int32_t>(index), value);
  2217. }
  2218. void CarlaEngine::oscSend_control_set_current_program(const uint pluginId, const int32_t index) const noexcept
  2219. {
  2220. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  2221. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  2222. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  2223. CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
  2224. carla_debug("CarlaEngine::oscSend_control_set_current_program(%i, %i)", pluginId, index);
  2225. char targetPath[std::strlen(pData->oscData->path)+21];
  2226. std::strcpy(targetPath, pData->oscData->path);
  2227. std::strcat(targetPath, "/set_current_program");
  2228. try_lo_send(pData->oscData->target, targetPath, "ii", static_cast<int32_t>(pluginId), index);
  2229. }
  2230. void CarlaEngine::oscSend_control_set_current_midi_program(const uint pluginId, const int32_t index) const noexcept
  2231. {
  2232. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  2233. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  2234. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  2235. CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
  2236. carla_debug("CarlaEngine::oscSend_control_set_current_midi_program(%i, %i)", pluginId, index);
  2237. char targetPath[std::strlen(pData->oscData->path)+26];
  2238. std::strcpy(targetPath, pData->oscData->path);
  2239. std::strcat(targetPath, "/set_current_midi_program");
  2240. try_lo_send(pData->oscData->target, targetPath, "ii", static_cast<int32_t>(pluginId), index);
  2241. }
  2242. void CarlaEngine::oscSend_control_set_program_name(const uint pluginId, const uint32_t index, const char* const name) const noexcept
  2243. {
  2244. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  2245. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  2246. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  2247. CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
  2248. CARLA_SAFE_ASSERT_RETURN(name != nullptr,);
  2249. carla_debug("CarlaEngine::oscSend_control_set_program_name(%i, %i, \"%s\")", pluginId, index, name);
  2250. char targetPath[std::strlen(pData->oscData->path)+18];
  2251. std::strcpy(targetPath, pData->oscData->path);
  2252. std::strcat(targetPath, "/set_program_name");
  2253. try_lo_send(pData->oscData->target, targetPath, "iis", static_cast<int32_t>(pluginId), static_cast<int32_t>(index), name);
  2254. }
  2255. void CarlaEngine::oscSend_control_set_midi_program_data(const uint pluginId, const uint32_t index, const uint32_t bank, const uint32_t program, const char* const name) const noexcept
  2256. {
  2257. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  2258. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  2259. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  2260. CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
  2261. CARLA_SAFE_ASSERT_RETURN(name != nullptr,);
  2262. carla_debug("CarlaEngine::oscSend_control_set_midi_program_data(%i, %i, %i, %i, \"%s\")", pluginId, index, bank, program, name);
  2263. char targetPath[std::strlen(pData->oscData->path)+23];
  2264. std::strcpy(targetPath, pData->oscData->path);
  2265. std::strcat(targetPath, "/set_midi_program_data");
  2266. try_lo_send(pData->oscData->target, targetPath, "iiiis", static_cast<int32_t>(pluginId), static_cast<int32_t>(index), static_cast<int32_t>(bank), static_cast<int32_t>(program), name);
  2267. }
  2268. void CarlaEngine::oscSend_control_note_on(const uint pluginId, const uint8_t channel, const uint8_t note, const uint8_t velo) const noexcept
  2269. {
  2270. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  2271. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  2272. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  2273. CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
  2274. CARLA_SAFE_ASSERT_RETURN(channel < MAX_MIDI_CHANNELS,);
  2275. CARLA_SAFE_ASSERT_RETURN(note < MAX_MIDI_NOTE,);
  2276. CARLA_SAFE_ASSERT_RETURN(velo < MAX_MIDI_VALUE,);
  2277. carla_debug("CarlaEngine::oscSend_control_note_on(%i, %i, %i, %i)", pluginId, channel, note, velo);
  2278. char targetPath[std::strlen(pData->oscData->path)+9];
  2279. std::strcpy(targetPath, pData->oscData->path);
  2280. std::strcat(targetPath, "/note_on");
  2281. try_lo_send(pData->oscData->target, targetPath, "iiii", static_cast<int32_t>(pluginId), static_cast<int32_t>(channel), static_cast<int32_t>(note), static_cast<int32_t>(velo));
  2282. }
  2283. void CarlaEngine::oscSend_control_note_off(const uint pluginId, const uint8_t channel, const uint8_t note) const noexcept
  2284. {
  2285. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  2286. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  2287. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  2288. CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
  2289. CARLA_SAFE_ASSERT_RETURN(channel < MAX_MIDI_CHANNELS,);
  2290. CARLA_SAFE_ASSERT_RETURN(note < MAX_MIDI_NOTE,);
  2291. carla_debug("CarlaEngine::oscSend_control_note_off(%i, %i, %i)", pluginId, channel, note);
  2292. char targetPath[std::strlen(pData->oscData->path)+10];
  2293. std::strcpy(targetPath, pData->oscData->path);
  2294. std::strcat(targetPath, "/note_off");
  2295. try_lo_send(pData->oscData->target, targetPath, "iii", static_cast<int32_t>(pluginId), static_cast<int32_t>(channel), static_cast<int32_t>(note));
  2296. }
  2297. void CarlaEngine::oscSend_control_set_peaks(const uint pluginId) const noexcept
  2298. {
  2299. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  2300. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  2301. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  2302. CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
  2303. // TODO - try and see if we can get peaks[4] ref
  2304. const EnginePluginData& epData(pData->plugins[pluginId]);
  2305. char targetPath[std::strlen(pData->oscData->path)+11];
  2306. std::strcpy(targetPath, pData->oscData->path);
  2307. std::strcat(targetPath, "/set_peaks");
  2308. try_lo_send(pData->oscData->target, targetPath, "iffff", static_cast<int32_t>(pluginId), epData.insPeak[0], epData.insPeak[1], epData.outsPeak[0], epData.outsPeak[1]);
  2309. }
  2310. void CarlaEngine::oscSend_control_exit() const noexcept
  2311. {
  2312. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  2313. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  2314. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  2315. carla_debug("CarlaEngine::oscSend_control_exit()");
  2316. char targetPath[std::strlen(pData->oscData->path)+6];
  2317. std::strcpy(targetPath, pData->oscData->path);
  2318. std::strcat(targetPath, "/exit");
  2319. try_lo_send(pData->oscData->target, targetPath, "");
  2320. }
  2321. #endif
  2322. // -----------------------------------------------------------------------
  2323. CARLA_BACKEND_END_NAMESPACE