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 78KB

11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478
  1. /*
  2. * Carla Engine
  3. * Copyright (C) 2012-2013 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 GPL.txt file
  16. */
  17. #include "CarlaEngineInternal.hpp"
  18. #include "CarlaBackendUtils.hpp"
  19. #include "CarlaStateUtils.hpp"
  20. #include "CarlaMIDI.h"
  21. #include <QtCore/QDir>
  22. #include <QtCore/QFile>
  23. #include <QtCore/QFileInfo>
  24. #include <QtCore/QTextStream>
  25. CARLA_BACKEND_START_NAMESPACE
  26. // -------------------------------------------------------------------------------------------------------------------
  27. // Fallback data
  28. static const EngineEvent kFallbackEngineEvent;
  29. #ifndef BUILD_BRIDGE
  30. // -------------------------------------------------------------------------------------------------------------------
  31. // Bridge Helper, defined in CarlaPlugin.cpp
  32. extern BinaryType CarlaPluginGetBridgeBinaryType(CarlaPlugin* const plugin);
  33. // -------------------------------------------------------------------------------------------------------------------
  34. // Engine Helpers
  35. void registerEnginePlugin(CarlaEngine* const engine, const unsigned int id, CarlaPlugin* const plugin)
  36. {
  37. CarlaEngineProtectedData::registerEnginePlugin(engine, id, plugin);
  38. }
  39. #endif
  40. // -------------------------------------------------------------------------------------------------------------------
  41. // Carla Engine port (Abstract)
  42. CarlaEnginePort::CarlaEnginePort(const bool isInput, const ProcessMode processMode)
  43. : kIsInput(isInput),
  44. kProcessMode(processMode)
  45. {
  46. carla_debug("CarlaEnginePort::CarlaEnginePort(%s, %s)", bool2str(isInput), ProcessMode2Str(processMode));
  47. }
  48. CarlaEnginePort::~CarlaEnginePort()
  49. {
  50. carla_debug("CarlaEnginePort::~CarlaEnginePort()");
  51. }
  52. // -------------------------------------------------------------------------------------------------------------------
  53. // Carla Engine Audio port
  54. CarlaEngineAudioPort::CarlaEngineAudioPort(const bool isInput, const ProcessMode processMode)
  55. : CarlaEnginePort(isInput, processMode),
  56. fBuffer(nullptr)
  57. {
  58. carla_debug("CarlaEngineAudioPort::CarlaEngineAudioPort(%s, %s)", bool2str(isInput), ProcessMode2Str(processMode));
  59. if (kProcessMode == PROCESS_MODE_PATCHBAY)
  60. fBuffer = new float[PATCHBAY_BUFFER_SIZE];
  61. }
  62. CarlaEngineAudioPort::~CarlaEngineAudioPort()
  63. {
  64. carla_debug("CarlaEngineAudioPort::~CarlaEngineAudioPort()");
  65. if (kProcessMode == PROCESS_MODE_PATCHBAY)
  66. {
  67. CARLA_ASSERT(fBuffer != nullptr);
  68. if (fBuffer != nullptr)
  69. delete[] fBuffer;
  70. }
  71. }
  72. void CarlaEngineAudioPort::initBuffer(CarlaEngine* const)
  73. {
  74. if (kProcessMode == PROCESS_MODE_PATCHBAY && ! kIsInput)
  75. carla_zeroFloat(fBuffer, PATCHBAY_BUFFER_SIZE);
  76. }
  77. // -------------------------------------------------------------------------------------------------------------------
  78. // Carla Engine Event port
  79. CarlaEngineEventPort::CarlaEngineEventPort(const bool isInput, const ProcessMode processMode)
  80. : CarlaEnginePort(isInput, processMode),
  81. kMaxEventCount(processMode == PROCESS_MODE_CONTINUOUS_RACK ? RACK_EVENT_COUNT : PATCHBAY_EVENT_COUNT),
  82. fBuffer(nullptr)
  83. {
  84. carla_debug("CarlaEngineEventPort::CarlaEngineEventPort(%s, %s)", bool2str(isInput), ProcessMode2Str(processMode));
  85. if (kProcessMode == PROCESS_MODE_PATCHBAY || kProcessMode == PROCESS_MODE_BRIDGE)
  86. fBuffer = new EngineEvent[kMaxEventCount];
  87. }
  88. CarlaEngineEventPort::~CarlaEngineEventPort()
  89. {
  90. carla_debug("CarlaEngineEventPort::~CarlaEngineEventPort()");
  91. if (kProcessMode == PROCESS_MODE_PATCHBAY || kProcessMode == PROCESS_MODE_BRIDGE)
  92. {
  93. CARLA_ASSERT(fBuffer != nullptr);
  94. if (fBuffer != nullptr)
  95. delete[] fBuffer;
  96. }
  97. }
  98. void CarlaEngineEventPort::initBuffer(CarlaEngine* const engine)
  99. {
  100. CARLA_ASSERT(engine != nullptr);
  101. if (engine == nullptr)
  102. return;
  103. #ifndef BUILD_BRIDGE
  104. if (kProcessMode == PROCESS_MODE_CONTINUOUS_RACK)
  105. fBuffer = engine->getRackEventBuffer(kIsInput);
  106. else
  107. #endif
  108. if ((kProcessMode == PROCESS_MODE_PATCHBAY || kProcessMode == PROCESS_MODE_BRIDGE) && ! kIsInput)
  109. carla_zeroStruct<EngineEvent>(fBuffer, kMaxEventCount);
  110. }
  111. uint32_t CarlaEngineEventPort::getEventCount()
  112. {
  113. CARLA_ASSERT(kIsInput);
  114. CARLA_ASSERT(fBuffer != nullptr);
  115. CARLA_ASSERT(kProcessMode == PROCESS_MODE_CONTINUOUS_RACK || kProcessMode == PROCESS_MODE_PATCHBAY || kProcessMode == PROCESS_MODE_BRIDGE);
  116. if (! kIsInput)
  117. return 0;
  118. if (fBuffer == nullptr)
  119. return 0;
  120. if (kProcessMode != PROCESS_MODE_CONTINUOUS_RACK && kProcessMode != PROCESS_MODE_PATCHBAY && kProcessMode != PROCESS_MODE_BRIDGE)
  121. return 0;
  122. uint32_t count = 0;
  123. const EngineEvent* const events = fBuffer;
  124. for (uint32_t i=0; i < kMaxEventCount; ++i, ++count)
  125. {
  126. if (events[i].type == kEngineEventTypeNull)
  127. break;
  128. }
  129. return count;
  130. }
  131. const EngineEvent& CarlaEngineEventPort::getEvent(const uint32_t index)
  132. {
  133. CARLA_ASSERT(kIsInput);
  134. CARLA_ASSERT(fBuffer != nullptr);
  135. CARLA_ASSERT(kProcessMode == PROCESS_MODE_CONTINUOUS_RACK || kProcessMode == PROCESS_MODE_PATCHBAY || kProcessMode == PROCESS_MODE_BRIDGE);
  136. CARLA_ASSERT(index < kMaxEventCount);
  137. if (! kIsInput)
  138. return kFallbackEngineEvent;
  139. if (fBuffer == nullptr)
  140. return kFallbackEngineEvent;
  141. if (kProcessMode != PROCESS_MODE_CONTINUOUS_RACK && kProcessMode != PROCESS_MODE_PATCHBAY && kProcessMode != PROCESS_MODE_BRIDGE)
  142. return kFallbackEngineEvent;
  143. if (index >= kMaxEventCount)
  144. return kFallbackEngineEvent;
  145. return fBuffer[index];
  146. }
  147. void CarlaEngineEventPort::writeControlEvent(const uint32_t time, const uint8_t channel, const EngineControlEventType type, const uint16_t param, const float value)
  148. {
  149. CARLA_ASSERT(! kIsInput);
  150. CARLA_ASSERT(fBuffer != nullptr);
  151. CARLA_ASSERT(kProcessMode == PROCESS_MODE_CONTINUOUS_RACK || kProcessMode == PROCESS_MODE_PATCHBAY || kProcessMode == PROCESS_MODE_BRIDGE);
  152. CARLA_ASSERT(type != kEngineControlEventTypeNull);
  153. CARLA_ASSERT(channel < MAX_MIDI_CHANNELS);
  154. CARLA_SAFE_ASSERT(value >= 0.0f && value <= 1.0f);
  155. if (kIsInput)
  156. return;
  157. if (fBuffer == nullptr)
  158. return;
  159. if (kProcessMode != PROCESS_MODE_CONTINUOUS_RACK && kProcessMode != PROCESS_MODE_PATCHBAY && kProcessMode != PROCESS_MODE_BRIDGE)
  160. return;
  161. if (type == kEngineControlEventTypeNull)
  162. return;
  163. if (channel >= MAX_MIDI_CHANNELS)
  164. return;
  165. if (type == kEngineControlEventTypeParameter)
  166. {
  167. CARLA_ASSERT(! MIDI_IS_CONTROL_BANK_SELECT(param));
  168. }
  169. for (uint32_t i=0; i < kMaxEventCount; ++i)
  170. {
  171. if (fBuffer[i].type != kEngineEventTypeNull)
  172. continue;
  173. fBuffer[i].type = kEngineEventTypeControl;
  174. fBuffer[i].time = time;
  175. fBuffer[i].channel = channel;
  176. fBuffer[i].ctrl.type = type;
  177. fBuffer[i].ctrl.param = param;
  178. fBuffer[i].ctrl.value = carla_fixValue<float>(0.0f, 1.0f, value);
  179. return;
  180. }
  181. carla_stderr2("CarlaEngineEventPort::writeControlEvent() - buffer full");
  182. }
  183. void CarlaEngineEventPort::writeMidiEvent(const uint32_t time, const uint8_t channel, const uint8_t port, const uint8_t* const data, const uint8_t size)
  184. {
  185. CARLA_ASSERT(! kIsInput);
  186. CARLA_ASSERT(fBuffer != nullptr);
  187. CARLA_ASSERT(kProcessMode == PROCESS_MODE_CONTINUOUS_RACK || kProcessMode == PROCESS_MODE_PATCHBAY || kProcessMode == PROCESS_MODE_BRIDGE);
  188. CARLA_ASSERT(channel < MAX_MIDI_CHANNELS);
  189. CARLA_ASSERT(data != nullptr);
  190. CARLA_ASSERT(size > 0);
  191. if (kIsInput)
  192. return;
  193. if (fBuffer == nullptr)
  194. return;
  195. if (kProcessMode != PROCESS_MODE_CONTINUOUS_RACK && kProcessMode != PROCESS_MODE_PATCHBAY && kProcessMode != PROCESS_MODE_BRIDGE)
  196. return;
  197. if (channel >= MAX_MIDI_CHANNELS)
  198. return;
  199. if (data == nullptr)
  200. return;
  201. if (size == 0)
  202. return;
  203. if (size > 4)
  204. return;
  205. for (uint32_t i=0; i < kMaxEventCount; ++i)
  206. {
  207. if (fBuffer[i].type != kEngineEventTypeNull)
  208. continue;
  209. fBuffer[i].type = kEngineEventTypeMidi;
  210. fBuffer[i].time = time;
  211. fBuffer[i].channel = channel;
  212. fBuffer[i].midi.port = port;
  213. fBuffer[i].midi.size = size;
  214. carla_copy<uint8_t>(fBuffer[i].midi.data, data, size);
  215. return;
  216. }
  217. carla_stderr2("CarlaEngineEventPort::writeMidiEvent() - buffer full");
  218. }
  219. // -------------------------------------------------------------------------------------------------------------------
  220. // Carla Engine client (Abstract)
  221. CarlaEngineClient::CarlaEngineClient(const EngineType engineType, const ProcessMode processMode)
  222. : kEngineType(engineType),
  223. kProcessMode(processMode),
  224. fActive(false),
  225. fLatency(0)
  226. {
  227. CARLA_ASSERT(engineType != kEngineTypeNull);
  228. carla_debug("CarlaEngineClient::CarlaEngineClient(%s, %s)", EngineType2Str(engineType), ProcessMode2Str(processMode));
  229. }
  230. CarlaEngineClient::~CarlaEngineClient()
  231. {
  232. CARLA_ASSERT(! fActive);
  233. carla_debug("CarlaEngineClient::~CarlaEngineClient()");
  234. }
  235. void CarlaEngineClient::activate()
  236. {
  237. CARLA_ASSERT(! fActive);
  238. carla_debug("CarlaEngineClient::activate()");
  239. fActive = true;
  240. }
  241. void CarlaEngineClient::deactivate()
  242. {
  243. CARLA_ASSERT(fActive);
  244. carla_debug("CarlaEngineClient::deactivate()");
  245. fActive = false;
  246. }
  247. bool CarlaEngineClient::isActive() const
  248. {
  249. carla_debug("CarlaEngineClient::isActive()");
  250. return fActive;
  251. }
  252. bool CarlaEngineClient::isOk() const
  253. {
  254. carla_debug("CarlaEngineClient::isOk()");
  255. return true;
  256. }
  257. uint32_t CarlaEngineClient::getLatency() const
  258. {
  259. return fLatency;
  260. }
  261. void CarlaEngineClient::setLatency(const uint32_t samples)
  262. {
  263. fLatency = samples;
  264. }
  265. CarlaEnginePort* CarlaEngineClient::addPort(const EnginePortType portType, const char* const name, const bool isInput)
  266. {
  267. carla_debug("CarlaEngineClient::addPort(%s, \"%s\", %s)", EnginePortType2Str(portType), name, bool2str(isInput));
  268. switch (portType)
  269. {
  270. case kEnginePortTypeNull:
  271. break;
  272. case kEnginePortTypeAudio:
  273. return new CarlaEngineAudioPort(isInput, kProcessMode);
  274. case kEnginePortTypeEvent:
  275. return new CarlaEngineEventPort(isInput, kProcessMode);
  276. }
  277. carla_stderr("CarlaEngineClient::addPort(%i, \"%s\", %s) - invalid type", portType, name, bool2str(isInput));
  278. return nullptr;
  279. }
  280. // -------------------------------------------------------------------------------------------------------------------
  281. // Carla Engine
  282. CarlaEngine::CarlaEngine()
  283. : fBufferSize(0),
  284. fSampleRate(0.0),
  285. kData(new CarlaEngineProtectedData(this))
  286. {
  287. carla_debug("CarlaEngine::CarlaEngine()");
  288. }
  289. CarlaEngine::~CarlaEngine()
  290. {
  291. carla_debug("CarlaEngine::~CarlaEngine()");
  292. delete kData;
  293. }
  294. // -----------------------------------------------------------------------
  295. // Helpers
  296. void doPluginRemove(CarlaEngineProtectedData* const kData, const bool unlock)
  297. {
  298. CARLA_ASSERT(kData->curPluginCount > 0);
  299. kData->curPluginCount--;
  300. const unsigned int id = kData->nextAction.pluginId;
  301. // reset current plugin
  302. kData->plugins[id].plugin = nullptr;
  303. CarlaPlugin* plugin;
  304. // move all plugins 1 spot backwards
  305. for (unsigned int i=id; i < kData->curPluginCount; ++i)
  306. {
  307. plugin = kData->plugins[i+1].plugin;
  308. CARLA_ASSERT(plugin);
  309. if (plugin == nullptr)
  310. break;
  311. plugin->setId(i);
  312. kData->plugins[i].plugin = plugin;
  313. kData->plugins[i].insPeak[0] = 0.0f;
  314. kData->plugins[i].insPeak[1] = 0.0f;
  315. kData->plugins[i].outsPeak[0] = 0.0f;
  316. kData->plugins[i].outsPeak[1] = 0.0f;
  317. }
  318. kData->nextAction.opcode = EnginePostActionNull;
  319. if (unlock)
  320. kData->nextAction.mutex.unlock();
  321. }
  322. void doPluginsSwitch(CarlaEngineProtectedData* const kData, const bool unlock)
  323. {
  324. CARLA_ASSERT(kData->curPluginCount >= 2);
  325. const unsigned int idA = kData->nextAction.pluginId;
  326. const unsigned int idB = kData->nextAction.value;
  327. CarlaPlugin* const tmp = kData->plugins[idA].plugin;
  328. kData->plugins[idA].plugin = kData->plugins[idB].plugin;
  329. kData->plugins[idB].plugin = tmp;
  330. kData->nextAction.opcode = EnginePostActionNull;
  331. if (unlock)
  332. kData->nextAction.mutex.unlock();
  333. }
  334. const char* findDSSIGUI(const char* const filename, const char* const label)
  335. {
  336. QString guiFilename;
  337. guiFilename.clear();
  338. QString pluginDir(filename);
  339. pluginDir.resize(pluginDir.lastIndexOf("."));
  340. QString shortName = QFileInfo(pluginDir).baseName();
  341. QString checkLabel = QString(label);
  342. QString checkSName = shortName;
  343. if (! checkLabel.endsWith("_")) checkLabel += "_";
  344. if (! checkSName.endsWith("_")) checkSName += "_";
  345. QStringList guiFiles = QDir(pluginDir).entryList();
  346. foreach (const QString& gui, guiFiles)
  347. {
  348. if (gui.startsWith(checkLabel) || gui.startsWith(checkSName))
  349. {
  350. QFileInfo finalname(pluginDir + QDir::separator() + gui);
  351. guiFilename = finalname.absoluteFilePath();
  352. break;
  353. }
  354. }
  355. if (guiFilename.isEmpty())
  356. return nullptr;
  357. return carla_strdup(guiFilename.toUtf8().constData());
  358. }
  359. // -----------------------------------------------------------------------
  360. // Static values and calls
  361. unsigned int CarlaEngine::getDriverCount()
  362. {
  363. carla_debug("CarlaEngine::getDriverCount()");
  364. unsigned int count = 1; // JACK
  365. #ifdef WANT_RTAUDIO
  366. count += getRtAudioApiCount();
  367. #endif
  368. return count;
  369. }
  370. const char* CarlaEngine::getDriverName(unsigned int index)
  371. {
  372. carla_debug("CarlaEngine::getDriverName(%i)", index);
  373. if (index == 0)
  374. return "JACK";
  375. else
  376. index -= 1;
  377. #ifdef WANT_RTAUDIO
  378. if (index < getRtAudioApiCount())
  379. return getRtAudioApiName(index);
  380. #endif
  381. carla_stderr("CarlaEngine::getDriverName(%i) - invalid index", index);
  382. return nullptr;
  383. }
  384. const char** CarlaEngine::getDriverDeviceNames(unsigned int index)
  385. {
  386. carla_debug("CarlaEngine::getDriverDeviceNames(%i)", index);
  387. if (index == 0)
  388. return nullptr;
  389. else
  390. index -= 1;
  391. #ifdef WANT_RTAUDIO
  392. if (index < getRtAudioApiCount())
  393. return getRtAudioApiDeviceNames(index);
  394. #endif
  395. carla_stderr("CarlaEngine::getDriverDeviceNames(%i) - invalid index", index);
  396. return nullptr;
  397. }
  398. CarlaEngine* CarlaEngine::newDriverByName(const char* const driverName)
  399. {
  400. carla_debug("CarlaEngine::newDriverByName(\"%s\")", driverName);
  401. if (std::strcmp(driverName, "JACK") == 0)
  402. return newJack();
  403. #ifdef WANT_RTAUDIO
  404. # ifdef __LINUX_ALSA__
  405. if (std::strcmp(driverName, "ALSA") == 0)
  406. return newRtAudio(RTAUDIO_LINUX_ALSA);
  407. # endif
  408. # ifdef __LINUX_PULSE__
  409. if (std::strcmp(driverName, "PulseAudio") == 0)
  410. return newRtAudio(RTAUDIO_LINUX_PULSE);
  411. # endif
  412. # ifdef __LINUX_OSS__
  413. if (std::strcmp(driverName, "OSS") == 0)
  414. return newRtAudio(RTAUDIO_LINUX_OSS);
  415. # endif
  416. # ifdef __UNIX_JACK__
  417. if (std::strncmp(driverName, "JACK ", 5) == 0)
  418. return newRtAudio(RTAUDIO_UNIX_JACK);
  419. # endif
  420. # ifdef __MACOSX_CORE__
  421. if (std::strcmp(driverName, "CoreAudio") == 0)
  422. return newRtAudio(RTAUDIO_MACOSX_CORE);
  423. # endif
  424. # ifdef __WINDOWS_ASIO__
  425. if (std::strcmp(driverName, "ASIO") == 0)
  426. return newRtAudio(RTAUDIO_WINDOWS_ASIO);
  427. # endif
  428. # ifdef __WINDOWS_DS__
  429. if (std::strcmp(driverName, "DirectSound") == 0)
  430. return newRtAudio(RTAUDIO_WINDOWS_DS);
  431. # endif
  432. #endif
  433. return nullptr;
  434. }
  435. // -----------------------------------------------------------------------
  436. // Maximum values
  437. unsigned int CarlaEngine::maxClientNameSize() const
  438. {
  439. return STR_MAX/2;
  440. }
  441. unsigned int CarlaEngine::maxPortNameSize() const
  442. {
  443. return STR_MAX;
  444. }
  445. unsigned int CarlaEngine::currentPluginCount() const
  446. {
  447. return kData->curPluginCount;
  448. }
  449. unsigned int CarlaEngine::maxPluginNumber() const
  450. {
  451. return kData->maxPluginNumber;
  452. }
  453. // -----------------------------------------------------------------------
  454. // Virtual, per-engine type calls
  455. bool CarlaEngine::init(const char* const clientName)
  456. {
  457. CARLA_ASSERT(kData->plugins == nullptr);
  458. carla_debug("CarlaEngine::init(\"%s\")", clientName);
  459. #ifndef BUILD_BRIDGE
  460. CARLA_ASSERT(kData->rack.in == nullptr);
  461. CARLA_ASSERT(kData->rack.out == nullptr);
  462. #endif
  463. fName = clientName;
  464. fName.toBasic();
  465. fTimeInfo.clear();
  466. kData->aboutToClose = false;
  467. kData->curPluginCount = 0;
  468. #ifdef BUILD_BRIDGE
  469. kData->maxPluginNumber = 1;
  470. #else
  471. switch (fOptions.processMode)
  472. {
  473. case PROCESS_MODE_CONTINUOUS_RACK:
  474. kData->maxPluginNumber = MAX_RACK_PLUGINS;
  475. kData->rack.in = new EngineEvent[RACK_EVENT_COUNT];
  476. kData->rack.out = new EngineEvent[RACK_EVENT_COUNT];
  477. break;
  478. case PROCESS_MODE_PATCHBAY:
  479. kData->maxPluginNumber = MAX_PATCHBAY_PLUGINS;
  480. break;
  481. default:
  482. kData->maxPluginNumber = MAX_DEFAULT_PLUGINS;
  483. break;
  484. }
  485. #endif
  486. kData->plugins = new EnginePluginData[kData->maxPluginNumber];
  487. kData->osc.init(clientName);
  488. #ifndef BUILD_BRIDGE
  489. kData->oscData = kData->osc.getControlData();
  490. #else
  491. kData->oscData = nullptr; // set later in setOscBridgeData()
  492. #endif
  493. #ifndef BUILD_BRIDGE
  494. if (type() != kEngineTypePlugin)
  495. carla_setprocname(clientName);
  496. #endif
  497. kData->nextAction.ready();
  498. kData->thread.startNow();
  499. return true;
  500. }
  501. bool CarlaEngine::close()
  502. {
  503. CARLA_ASSERT(kData->plugins != nullptr);
  504. carla_debug("CarlaEngine::close()");
  505. kData->thread.stopNow();
  506. kData->nextAction.ready();
  507. #ifndef BUILD_BRIDGE
  508. osc_send_control_exit();
  509. #endif
  510. kData->osc.close();
  511. kData->oscData = nullptr;
  512. kData->aboutToClose = true;
  513. kData->curPluginCount = 0;
  514. kData->maxPluginNumber = 0;
  515. if (kData->plugins != nullptr)
  516. {
  517. delete[] kData->plugins;
  518. kData->plugins = nullptr;
  519. }
  520. #ifndef BUILD_BRIDGE
  521. if (kData->rack.in != nullptr)
  522. {
  523. delete[] kData->rack.in;
  524. kData->rack.in = nullptr;
  525. }
  526. if (kData->rack.out != nullptr)
  527. {
  528. delete[] kData->rack.out;
  529. kData->rack.out = nullptr;
  530. }
  531. #endif
  532. fName.clear();
  533. return true;
  534. }
  535. void CarlaEngine::idle()
  536. {
  537. CARLA_ASSERT(kData->plugins != nullptr);
  538. for (unsigned int i=0; i < kData->curPluginCount; ++i)
  539. {
  540. CarlaPlugin* const plugin = kData->plugins[i].plugin;
  541. if (plugin != nullptr && plugin->enabled())
  542. plugin->idleGui();
  543. }
  544. }
  545. CarlaEngineClient* CarlaEngine::addClient(CarlaPlugin* const)
  546. {
  547. return new CarlaEngineClient(type(), fOptions.processMode);
  548. }
  549. // -----------------------------------------------------------------------
  550. // Plugin management
  551. 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)
  552. {
  553. CARLA_ASSERT(btype != BINARY_NONE);
  554. CARLA_ASSERT(ptype != PLUGIN_NONE);
  555. carla_debug("CarlaEngine::addPlugin(%s, %s, \"%s\", \"%s\", \"%s\", %p)", BinaryType2Str(btype), PluginType2Str(ptype), filename, name, label, extra);
  556. if (kData->curPluginCount == kData->maxPluginNumber)
  557. {
  558. setLastError("Maximum number of plugins reached");
  559. return false;
  560. }
  561. const unsigned int id = kData->curPluginCount;
  562. CarlaPlugin::Initializer init = {
  563. this,
  564. id,
  565. filename,
  566. name,
  567. label
  568. };
  569. CarlaPlugin* plugin = nullptr;
  570. #ifndef BUILD_BRIDGE
  571. const char* bridgeBinary;
  572. switch (btype)
  573. {
  574. case BINARY_POSIX32:
  575. bridgeBinary = fOptions.bridge_posix32.isNotEmpty() ? (const char*)fOptions.bridge_posix32 : nullptr;
  576. break;
  577. case BINARY_POSIX64:
  578. bridgeBinary = fOptions.bridge_posix64.isNotEmpty() ? (const char*)fOptions.bridge_posix64 : nullptr;
  579. break;
  580. case BINARY_WIN32:
  581. bridgeBinary = fOptions.bridge_win32.isNotEmpty() ? (const char*)fOptions.bridge_win32 : nullptr;
  582. break;
  583. case BINARY_WIN64:
  584. bridgeBinary = fOptions.bridge_win64.isNotEmpty() ? (const char*)fOptions.bridge_win64 : nullptr;
  585. break;
  586. default:
  587. bridgeBinary = nullptr;
  588. break;
  589. }
  590. #ifndef Q_OS_WIN
  591. if (btype == BINARY_NATIVE && fOptions.bridge_native.isNotEmpty())
  592. bridgeBinary = (const char*)fOptions.bridge_native;
  593. #endif
  594. if (bridgeBinary != nullptr && (btype != BINARY_NATIVE || fOptions.preferPluginBridges))
  595. {
  596. plugin = CarlaPlugin::newBridge(init, btype, ptype, bridgeBinary);
  597. }
  598. else
  599. #endif // BUILD_BRIDGE
  600. {
  601. switch (ptype)
  602. {
  603. case PLUGIN_NONE:
  604. break;
  605. case PLUGIN_INTERNAL:
  606. plugin = CarlaPlugin::newNative(init);
  607. break;
  608. case PLUGIN_LADSPA:
  609. plugin = CarlaPlugin::newLADSPA(init, (const LADSPA_RDF_Descriptor*)extra);
  610. break;
  611. case PLUGIN_DSSI:
  612. plugin = CarlaPlugin::newDSSI(init, (const char*)extra);
  613. break;
  614. case PLUGIN_LV2:
  615. plugin = CarlaPlugin::newLV2(init);
  616. break;
  617. case PLUGIN_VST:
  618. plugin = CarlaPlugin::newVST(init);
  619. break;
  620. case PLUGIN_VST3:
  621. plugin = CarlaPlugin::newVST3(init);
  622. break;
  623. case PLUGIN_GIG:
  624. plugin = CarlaPlugin::newGIG(init, (extra != nullptr));
  625. break;
  626. case PLUGIN_SF2:
  627. plugin = CarlaPlugin::newSF2(init, (extra != nullptr));
  628. break;
  629. case PLUGIN_SFZ:
  630. plugin = CarlaPlugin::newSFZ(init, (extra != nullptr));
  631. break;
  632. }
  633. }
  634. if (plugin == nullptr)
  635. return false;
  636. plugin->registerToOscClient();
  637. kData->plugins[id].plugin = plugin;
  638. kData->plugins[id].insPeak[0] = 0.0f;
  639. kData->plugins[id].insPeak[1] = 0.0f;
  640. kData->plugins[id].outsPeak[0] = 0.0f;
  641. kData->plugins[id].outsPeak[1] = 0.0f;
  642. kData->curPluginCount += 1;
  643. callback(CALLBACK_PLUGIN_ADDED, id, 0, 0, 0.0f, plugin->name());
  644. return true;
  645. }
  646. bool CarlaEngine::removePlugin(const unsigned int id)
  647. {
  648. CARLA_ASSERT(kData->curPluginCount > 0);
  649. CARLA_ASSERT(id < kData->curPluginCount);
  650. CARLA_ASSERT(kData->plugins != nullptr);
  651. carla_debug("CarlaEngine::removePlugin(%i)", id);
  652. if (kData->plugins == nullptr)
  653. {
  654. setLastError("Critical error: no plugins are currently loaded!");
  655. return false;
  656. }
  657. CarlaPlugin* const plugin = kData->plugins[id].plugin;
  658. if (plugin == nullptr)
  659. {
  660. setLastError("Could not find plugin to remove");
  661. return false;
  662. }
  663. CARLA_ASSERT(plugin->id() == id);
  664. kData->thread.stopNow();
  665. kData->nextAction.pluginId = id;
  666. kData->nextAction.opcode = EnginePostActionRemovePlugin;
  667. kData->nextAction.mutex.lock();
  668. if (isRunning())
  669. {
  670. carla_stderr("CarlaEngine::removePlugin(%i) - remove blocking START", id);
  671. // block wait for unlock on proccessing side
  672. kData->nextAction.mutex.lock();
  673. carla_stderr("CarlaEngine::removePlugin(%i) - remove blocking DONE", id);
  674. }
  675. else
  676. {
  677. doPluginRemove(kData, false);
  678. }
  679. #ifndef BUILD_BRIDGE
  680. if (isOscControlRegistered())
  681. osc_send_control_remove_plugin(id);
  682. #endif
  683. delete plugin;
  684. kData->nextAction.mutex.unlock();
  685. if (isRunning() && ! kData->aboutToClose)
  686. kData->thread.startNow();
  687. callback(CALLBACK_PLUGIN_REMOVED, id, 0, 0, 0.0f, nullptr);
  688. return true;
  689. }
  690. void CarlaEngine::removeAllPlugins()
  691. {
  692. carla_debug("CarlaEngine::removeAllPlugins() - START");
  693. kData->thread.stopNow();
  694. if (kData->curPluginCount > 0)
  695. {
  696. const unsigned int oldCount = kData->curPluginCount;
  697. kData->curPluginCount = 0;
  698. for (unsigned int i=0; i < oldCount; ++i)
  699. {
  700. CarlaPlugin* const plugin = kData->plugins[i].plugin;
  701. CARLA_ASSERT(plugin != nullptr);
  702. kData->plugins[i].plugin = nullptr;
  703. if (plugin != nullptr)
  704. delete plugin;
  705. // clear this plugin
  706. kData->plugins[i].insPeak[0] = 0.0f;
  707. kData->plugins[i].insPeak[1] = 0.0f;
  708. kData->plugins[i].outsPeak[0] = 0.0f;
  709. kData->plugins[i].outsPeak[1] = 0.0f;
  710. }
  711. }
  712. if (isRunning() && ! kData->aboutToClose)
  713. kData->thread.startNow();
  714. carla_debug("CarlaEngine::removeAllPlugins() - END");
  715. }
  716. const char* CarlaEngine::renamePlugin(const unsigned int id, const char* const newName)
  717. {
  718. CARLA_ASSERT(kData->curPluginCount > 0);
  719. CARLA_ASSERT(id < kData->curPluginCount);
  720. CARLA_ASSERT(kData->plugins != nullptr);
  721. CARLA_ASSERT(newName != nullptr);
  722. carla_debug("CarlaEngine::renamePlugin(%i, \"%s\")", id, newName);
  723. if (kData->plugins == nullptr)
  724. {
  725. setLastError("Critical error: no plugins are currently loaded!");
  726. return nullptr;
  727. }
  728. CarlaPlugin* const plugin = kData->plugins[id].plugin;
  729. if (plugin == nullptr)
  730. {
  731. carla_stderr("CarlaEngine::clonePlugin(%i) - could not find plugin", id);
  732. return nullptr;
  733. }
  734. CARLA_ASSERT(plugin->id() == id);
  735. if (const char* const name = getUniquePluginName(newName))
  736. {
  737. plugin->setName(name);
  738. return name;
  739. }
  740. return nullptr;
  741. }
  742. bool CarlaEngine::clonePlugin(const unsigned int id)
  743. {
  744. CARLA_ASSERT(kData->curPluginCount > 0);
  745. CARLA_ASSERT(id < kData->curPluginCount);
  746. CARLA_ASSERT(kData->plugins != nullptr);
  747. carla_debug("CarlaEngine::clonePlugin(%i)", id);
  748. if (kData->plugins == nullptr)
  749. {
  750. setLastError("Critical error: no plugins are currently loaded!");
  751. return false;
  752. }
  753. CarlaPlugin* const plugin = kData->plugins[id].plugin;
  754. if (plugin == nullptr)
  755. {
  756. carla_stderr("CarlaEngine::clonePlugin(%i) - could not find plugin", id);
  757. return false;
  758. }
  759. CARLA_ASSERT(plugin->id() == id);
  760. const SaveState& saveState(plugin->getSaveState());
  761. char label[STR_MAX+1] = { '\0' };
  762. plugin->getLabel(label);
  763. BinaryType binaryType = BINARY_NATIVE;
  764. #ifndef BUILD_BRIDGE
  765. if (plugin->hints() & PLUGIN_IS_BRIDGE)
  766. binaryType = CarlaPluginGetBridgeBinaryType(plugin);
  767. #endif
  768. const unsigned int pluginsBefore(kData->curPluginCount);
  769. if (! addPlugin(binaryType, plugin->type(), plugin->filename(), plugin->name(), label, plugin->getExtraStuff()))
  770. return false;
  771. CARLA_ASSERT(pluginsBefore+1 == kData->curPluginCount);
  772. CarlaPlugin* const newPlugin = kData->plugins[kData->curPluginCount-1].plugin;
  773. CARLA_ASSERT(newPlugin != nullptr);
  774. newPlugin->loadSaveState(saveState);
  775. return true;
  776. }
  777. bool CarlaEngine::replacePlugin(const unsigned int id)
  778. {
  779. CARLA_ASSERT(kData->curPluginCount > 0);
  780. CARLA_ASSERT(id < kData->curPluginCount);
  781. CARLA_ASSERT(kData->plugins != nullptr);
  782. carla_debug("CarlaEngine::replacePlugin(%i)", id);
  783. setLastError("Not implemented yet");
  784. return false;
  785. }
  786. bool CarlaEngine::switchPlugins(const unsigned int idA, const unsigned int idB)
  787. {
  788. CARLA_ASSERT(kData->curPluginCount > 0);
  789. CARLA_ASSERT(idA < kData->curPluginCount);
  790. CARLA_ASSERT(idB < kData->curPluginCount);
  791. CARLA_ASSERT(kData->plugins != nullptr);
  792. carla_debug("CarlaEngine::switchPlugins(%i)", idA, idB);
  793. if (kData->plugins == nullptr)
  794. {
  795. setLastError("Critical error: no plugins are currently loaded!");
  796. return false;
  797. }
  798. kData->thread.stopNow();
  799. kData->nextAction.pluginId = idA;
  800. kData->nextAction.value = idB;
  801. kData->nextAction.opcode = EnginePostActionSwitchPlugins;
  802. kData->nextAction.mutex.lock();
  803. if (isRunning())
  804. {
  805. carla_stderr("CarlaEngine::switchPlugins(%i, %i) - switch blocking START", idA, idB);
  806. // block wait for unlock on proccessing side
  807. kData->nextAction.mutex.lock();
  808. carla_stderr("CarlaEngine::switchPlugins(%i, %i) - switch blocking DONE", idA, idB);
  809. }
  810. else
  811. {
  812. doPluginsSwitch(kData, false);
  813. }
  814. #ifndef BUILD_BRIDGE // TODO
  815. //if (isOscControlRegistered())
  816. // osc_send_control_remove_plugin(id);
  817. #endif
  818. kData->nextAction.mutex.unlock();
  819. if (isRunning() && ! kData->aboutToClose)
  820. kData->thread.startNow();
  821. return true;
  822. }
  823. CarlaPlugin* CarlaEngine::getPlugin(const unsigned int id) const
  824. {
  825. CARLA_ASSERT(kData->curPluginCount > 0);
  826. CARLA_ASSERT(id < kData->curPluginCount);
  827. CARLA_ASSERT(kData->plugins != nullptr);
  828. carla_debug("CarlaEngine::getPlugin(%i) [count:%i]", id, kData->curPluginCount);
  829. if (id < kData->curPluginCount && kData->plugins != nullptr)
  830. return kData->plugins[id].plugin;
  831. return nullptr;
  832. }
  833. CarlaPlugin* CarlaEngine::getPluginUnchecked(const unsigned int id) const
  834. {
  835. return kData->plugins[id].plugin;
  836. }
  837. const char* CarlaEngine::getUniquePluginName(const char* const name)
  838. {
  839. CARLA_ASSERT(kData->maxPluginNumber > 0);
  840. CARLA_ASSERT(kData->plugins != nullptr);
  841. CARLA_ASSERT(name != nullptr);
  842. carla_debug("CarlaEngine::getUniquePluginName(\"%s\")", name);
  843. static CarlaString sname;
  844. sname = name;
  845. if (sname.isEmpty() || kData->plugins == nullptr)
  846. {
  847. sname = "(No name)";
  848. return (const char*)sname;
  849. }
  850. sname.truncate(maxClientNameSize()-5-1); // 5 = strlen(" (10)")
  851. sname.replace(':', '.'); // ':' is used in JACK1 to split client/port names
  852. for (unsigned short i=0; i < kData->curPluginCount; ++i)
  853. {
  854. CARLA_ASSERT(kData->plugins[i].plugin);
  855. if (kData->plugins[i].plugin == nullptr)
  856. continue;
  857. // Check if unique name doesn't exist
  858. if (const char* const pluginName = kData->plugins[i].plugin->name())
  859. {
  860. if (sname != pluginName)
  861. continue;
  862. }
  863. // Check if string has already been modified
  864. {
  865. const size_t len = sname.length();
  866. // 1 digit, ex: " (2)"
  867. if (sname[len-4] == ' ' && sname[len-3] == '(' && sname.isDigit(len-2) && sname[len-1] == ')')
  868. {
  869. int number = sname[len-2] - '0';
  870. if (number == 9)
  871. {
  872. // next number is 10, 2 digits
  873. sname.truncate(len-4);
  874. sname += " (10)";
  875. //sname.replace(" (9)", " (10)");
  876. }
  877. else
  878. sname[len-2] = char('0' + number + 1);
  879. continue;
  880. }
  881. // 2 digits, ex: " (11)"
  882. if (sname[len-5] == ' ' && sname[len-4] == '(' && sname.isDigit(len-3) && sname.isDigit(len-2) && sname[len-1] == ')')
  883. {
  884. char n2 = sname[len-2];
  885. char n3 = sname[len-3];
  886. if (n2 == '9')
  887. {
  888. n2 = '0';
  889. n3 += 1;
  890. }
  891. else
  892. n2 += 1;
  893. sname[len-2] = n2;
  894. sname[len-3] = n3;
  895. continue;
  896. }
  897. }
  898. // Modify string if not
  899. sname += " (2)";
  900. }
  901. return (const char*)sname;
  902. }
  903. // -----------------------------------------------------------------------
  904. // Project management
  905. bool CarlaEngine::loadFilename(const char* const filename)
  906. {
  907. CARLA_ASSERT(filename != nullptr);
  908. carla_debug("CarlaEngine::loadFilename(\"%s\")", filename);
  909. QFileInfo fileInfo(filename);
  910. if (! fileInfo.exists())
  911. {
  912. setLastError("File does not exist");
  913. return false;
  914. }
  915. if (! fileInfo.isFile())
  916. {
  917. setLastError("Not a file");
  918. return false;
  919. }
  920. if (! fileInfo.isReadable())
  921. {
  922. setLastError("File is not readable");
  923. return false;
  924. }
  925. CarlaString baseName(fileInfo.baseName().toUtf8().constData());
  926. CarlaString extension(fileInfo.suffix().toLower().toUtf8().constData());
  927. // -------------------------------------------------------------------
  928. if (extension == "carxp" || extension == "carxs")
  929. return loadProject(filename);
  930. // -------------------------------------------------------------------
  931. if (extension == "gig")
  932. return addPlugin(PLUGIN_GIG, filename, baseName, baseName);
  933. if (extension == "sf2")
  934. return addPlugin(PLUGIN_SF2, filename, baseName, baseName);
  935. if (extension == "sfz")
  936. return addPlugin(PLUGIN_SFZ, filename, baseName, baseName);
  937. // -------------------------------------------------------------------
  938. if (extension == "aiff" || extension == "flac" || extension == "oga" || extension == "ogg" || extension == "w64" || extension == "wav")
  939. {
  940. #ifdef WANT_AUDIOFILE
  941. if (addPlugin(PLUGIN_INTERNAL, nullptr, baseName, "audiofile"))
  942. {
  943. if (CarlaPlugin* const plugin = getPlugin(kData->curPluginCount-1))
  944. plugin->setCustomData(CUSTOM_DATA_STRING, "file00", filename, true);
  945. return true;
  946. }
  947. return false;
  948. #else
  949. setLastError("This Carla build does not have Audio file support");
  950. return false;
  951. #endif
  952. }
  953. if (extension == "3g2" || extension == "3gp" || extension == "aac" || extension == "ac3" || extension == "amr" || extension == "ape" ||
  954. extension == "mp2" || extension == "mp3" || extension == "mpc" || extension == "wma")
  955. {
  956. #ifdef WANT_AUDIOFILE
  957. # ifdef HAVE_FFMPEG
  958. if (addPlugin(PLUGIN_INTERNAL, nullptr, baseName, "audiofile"))
  959. {
  960. if (CarlaPlugin* const plugin = getPlugin(kData->curPluginCount-1))
  961. plugin->setCustomData(CUSTOM_DATA_STRING, "file00", filename, true);
  962. return true;
  963. }
  964. return false;
  965. # else
  966. setLastError("This Carla build has Audio file support, but not libav/ffmpeg");
  967. return false;
  968. # endif
  969. #else
  970. setLastError("This Carla build does not have Audio file support");
  971. return false;
  972. #endif
  973. }
  974. // -------------------------------------------------------------------
  975. if (extension == "mid" || extension == "midi")
  976. {
  977. #ifdef WANT_MIDIFILE
  978. if (addPlugin(PLUGIN_INTERNAL, nullptr, baseName, "midifile"))
  979. {
  980. if (CarlaPlugin* const plugin = getPlugin(kData->curPluginCount-1))
  981. plugin->setCustomData(CUSTOM_DATA_STRING, "file", filename, true);
  982. return true;
  983. }
  984. return false;
  985. #else
  986. setLastError("This Carla build does not have MIDI file support");
  987. return false;
  988. #endif
  989. }
  990. // -------------------------------------------------------------------
  991. // ZynAddSubFX
  992. if (extension == "xmz" || extension == "xiz")
  993. {
  994. #ifdef WANT_ZYNADDSUBFX
  995. if (addPlugin(PLUGIN_INTERNAL, nullptr, baseName, "zynaddsubfx"))
  996. {
  997. if (CarlaPlugin* const plugin = getPlugin(kData->curPluginCount-1))
  998. plugin->setCustomData(CUSTOM_DATA_STRING, (extension == "xmz") ? "CarlaAlternateFile1" : "CarlaAlternateFile2", filename, true);
  999. return true;
  1000. }
  1001. return false;
  1002. #else
  1003. setLastError("This Carla build does not have ZynAddSubFX support");
  1004. return false;
  1005. #endif
  1006. }
  1007. // -------------------------------------------------------------------
  1008. setLastError("Unknown file extension");
  1009. return false;
  1010. }
  1011. bool CarlaEngine::loadProject(const char* const filename)
  1012. {
  1013. CARLA_ASSERT(filename != nullptr);
  1014. carla_debug("CarlaEngine::loadProject(\"%s\")", filename);
  1015. QFile file(filename);
  1016. if (! file.open(QIODevice::ReadOnly | QIODevice::Text))
  1017. return false;
  1018. QDomDocument xml;
  1019. xml.setContent(file.readAll());
  1020. file.close();
  1021. QDomNode xmlNode(xml.documentElement());
  1022. if (xmlNode.toElement().tagName() != "CARLA-PROJECT" && xmlNode.toElement().tagName() != "CARLA-PRESET")
  1023. {
  1024. setLastError("Not a valid Carla project or preset file");
  1025. return false;
  1026. }
  1027. const bool isPreset(xmlNode.toElement().tagName() == "CARLA-PRESET");
  1028. QDomNode node(xmlNode.firstChild());
  1029. while (! node.isNull())
  1030. {
  1031. if (isPreset || node.toElement().tagName() == "Plugin")
  1032. {
  1033. const SaveState& saveState(getSaveStateDictFromXML(isPreset ? xmlNode : node));
  1034. CARLA_ASSERT(saveState.type != nullptr);
  1035. if (saveState.type == nullptr)
  1036. continue;
  1037. const void* extraStuff = nullptr;
  1038. if (std::strcmp(saveState.type, "DSSI") == 0)
  1039. extraStuff = findDSSIGUI(saveState.binary, saveState.label);
  1040. // TODO - proper find&load plugins
  1041. if (addPlugin(getPluginTypeFromString(saveState.type), saveState.binary, saveState.name, saveState.label, extraStuff))
  1042. {
  1043. if (CarlaPlugin* plugin = getPlugin(kData->curPluginCount-1))
  1044. plugin->loadSaveState(saveState);
  1045. }
  1046. }
  1047. if (isPreset)
  1048. break;
  1049. node = node.nextSibling();
  1050. }
  1051. // prevent wrong leak detection on close
  1052. getSaveStateDictFromXML(QDomNode());
  1053. return true;
  1054. }
  1055. bool CarlaEngine::saveProject(const char* const filename)
  1056. {
  1057. CARLA_ASSERT(filename != nullptr);
  1058. carla_debug("CarlaEngine::saveProject(\"%s\")", filename);
  1059. QFile file(filename);
  1060. if (! file.open(QIODevice::WriteOnly | QIODevice::Text))
  1061. return false;
  1062. QTextStream out(&file);
  1063. out << "<?xml version='1.0' encoding='UTF-8'?>\n";
  1064. out << "<!DOCTYPE CARLA-PROJECT>\n";
  1065. out << "<CARLA-PROJECT VERSION='1.0'>\n";
  1066. bool firstPlugin = true;
  1067. char strBuf[STR_MAX+1];
  1068. for (unsigned int i=0; i < kData->curPluginCount; ++i)
  1069. {
  1070. CarlaPlugin* const plugin = kData->plugins[i].plugin;
  1071. if (plugin != nullptr && plugin->enabled())
  1072. {
  1073. if (! firstPlugin)
  1074. out << "\n";
  1075. plugin->getRealName(strBuf);
  1076. if (*strBuf != 0)
  1077. out << QString(" <!-- %1 -->\n").arg(xmlSafeString(strBuf, true));
  1078. out << " <Plugin>\n";
  1079. out << getXMLFromSaveState(plugin->getSaveState());
  1080. out << " </Plugin>\n";
  1081. firstPlugin = false;
  1082. }
  1083. }
  1084. out << "</CARLA-PROJECT>\n";
  1085. file.close();
  1086. return true;
  1087. }
  1088. // -----------------------------------------------------------------------
  1089. // Information (peaks)
  1090. float CarlaEngine::getInputPeak(const unsigned int pluginId, const unsigned short id) const
  1091. {
  1092. CARLA_ASSERT(pluginId < kData->curPluginCount);
  1093. CARLA_ASSERT(id-1 < MAX_PEAKS);
  1094. if (id == 0 || id > MAX_PEAKS)
  1095. return 0.0f;
  1096. return kData->plugins[pluginId].insPeak[id-1];
  1097. }
  1098. float CarlaEngine::getOutputPeak(const unsigned int pluginId, const unsigned short id) const
  1099. {
  1100. CARLA_ASSERT(pluginId < kData->curPluginCount);
  1101. CARLA_ASSERT(id-1 < MAX_PEAKS);
  1102. if (id == 0 || id > MAX_PEAKS)
  1103. return 0.0f;
  1104. return kData->plugins[pluginId].outsPeak[id-1];
  1105. }
  1106. // -----------------------------------------------------------------------
  1107. // Callback
  1108. void CarlaEngine::callback(const CallbackType action, const unsigned int pluginId, const int value1, const int value2, const float value3, const char* const valueStr)
  1109. {
  1110. carla_debug("CarlaEngine::callback(%s, %i, %i, %i, %f, \"%s\")", CallbackType2Str(action), pluginId, value1, value2, value3, valueStr);
  1111. if (kData->callback)
  1112. kData->callback(kData->callbackPtr, action, pluginId, value1, value2, value3, valueStr);
  1113. }
  1114. void CarlaEngine::setCallback(const CallbackFunc func, void* const ptr)
  1115. {
  1116. CARLA_ASSERT(func != nullptr);
  1117. carla_debug("CarlaEngine::setCallback(%p, %p)", func, ptr);
  1118. kData->callback = func;
  1119. kData->callbackPtr = ptr;
  1120. }
  1121. // -----------------------------------------------------------------------
  1122. // Patchbay
  1123. bool CarlaEngine::patchbayConnect(int, int)
  1124. {
  1125. setLastError("Unsupported operation");
  1126. return false;
  1127. }
  1128. bool CarlaEngine::patchbayDisconnect(int)
  1129. {
  1130. setLastError("Unsupported operation");
  1131. return false;
  1132. }
  1133. void CarlaEngine::patchbayRefresh()
  1134. {
  1135. // nothing
  1136. }
  1137. // -----------------------------------------------------------------------
  1138. // Transport
  1139. void CarlaEngine::transportPlay()
  1140. {
  1141. kData->time.playing = true;
  1142. }
  1143. void CarlaEngine::transportPause()
  1144. {
  1145. kData->time.playing = false;
  1146. }
  1147. void CarlaEngine::transportRelocate(const uint32_t frame)
  1148. {
  1149. kData->time.frame = frame;
  1150. }
  1151. // -----------------------------------------------------------------------
  1152. // Error handling
  1153. const char* CarlaEngine::getLastError() const
  1154. {
  1155. return (const char*)kData->lastError;
  1156. }
  1157. void CarlaEngine::setLastError(const char* const error)
  1158. {
  1159. kData->lastError = error;
  1160. }
  1161. void CarlaEngine::setAboutToClose()
  1162. {
  1163. carla_debug("CarlaEngine::setAboutToClose()");
  1164. kData->aboutToClose = true;
  1165. }
  1166. // -----------------------------------------------------------------------
  1167. // Global options
  1168. #define CARLA_ENGINE_SET_OPTION_RUNNING_CHECK \
  1169. if (isRunning()) \
  1170. return carla_stderr("CarlaEngine::setOption(%s, %i, \"%s\") - Cannot set this option while engine is running!", OptionsType2Str(option), value, valueStr);
  1171. void CarlaEngine::setOption(const OptionsType option, const int value, const char* const valueStr)
  1172. {
  1173. carla_debug("CarlaEngine::setOption(%s, %i, \"%s\")", OptionsType2Str(option), value, valueStr);
  1174. switch (option)
  1175. {
  1176. case OPTION_PROCESS_NAME:
  1177. carla_setprocname(valueStr);
  1178. break;
  1179. case OPTION_PROCESS_MODE:
  1180. CARLA_ENGINE_SET_OPTION_RUNNING_CHECK
  1181. if (value < PROCESS_MODE_SINGLE_CLIENT || value > PROCESS_MODE_BRIDGE)
  1182. return carla_stderr("CarlaEngine::setOption(%s, %i, \"%s\") - invalid value", OptionsType2Str(option), value, valueStr);
  1183. fOptions.processMode = static_cast<ProcessMode>(value);
  1184. break;
  1185. case OPTION_TRANSPORT_MODE:
  1186. // FIXME: Always enable JACK transport for now
  1187. #if 0
  1188. if (value < CarlaBackend::TRANSPORT_MODE_INTERNAL || value > CarlaBackend::TRANSPORT_MODE_BRIDGE)
  1189. return carla_stderr2("carla_set_engine_option(OPTION_TRANSPORT_MODE, %i, \"%s\") - invalid value", value, valueStr);
  1190. fOptions.transportMode = static_cast<CarlaBackend::TransportMode>(value);
  1191. #endif
  1192. break;
  1193. case OPTION_MAX_PARAMETERS:
  1194. CARLA_ENGINE_SET_OPTION_RUNNING_CHECK
  1195. if (value < 0)
  1196. return; // TODO error here
  1197. fOptions.maxParameters = static_cast<uint>(value);
  1198. break;
  1199. case OPTION_FORCE_STEREO:
  1200. CARLA_ENGINE_SET_OPTION_RUNNING_CHECK
  1201. fOptions.forceStereo = (value != 0);
  1202. break;
  1203. #ifdef WANT_DSSI
  1204. case OPTION_USE_DSSI_VST_CHUNKS:
  1205. CARLA_ENGINE_SET_OPTION_RUNNING_CHECK
  1206. fOptions.useDssiVstChunks = (value != 0);
  1207. break;
  1208. #endif
  1209. case OPTION_PREFER_PLUGIN_BRIDGES:
  1210. CARLA_ENGINE_SET_OPTION_RUNNING_CHECK
  1211. fOptions.preferPluginBridges = (value != 0);
  1212. break;
  1213. case OPTION_PREFER_UI_BRIDGES:
  1214. CARLA_ENGINE_SET_OPTION_RUNNING_CHECK
  1215. fOptions.preferUiBridges = (value != 0);
  1216. break;
  1217. case OPTION_OSC_UI_TIMEOUT:
  1218. CARLA_ENGINE_SET_OPTION_RUNNING_CHECK
  1219. fOptions.oscUiTimeout = static_cast<uint>(value);
  1220. break;
  1221. case OPTION_JACK_AUTOCONNECT:
  1222. CARLA_ENGINE_SET_OPTION_RUNNING_CHECK
  1223. fOptions.jackAutoConnect = (value != 0);
  1224. break;
  1225. case OPTION_JACK_TIMEMASTER:
  1226. CARLA_ENGINE_SET_OPTION_RUNNING_CHECK
  1227. fOptions.jackTimeMaster = (value != 0);
  1228. break;
  1229. #ifdef WANT_RTAUDIO
  1230. case OPTION_RTAUDIO_BUFFER_SIZE:
  1231. CARLA_ENGINE_SET_OPTION_RUNNING_CHECK
  1232. fOptions.rtaudioBufferSize = static_cast<uint>(value);
  1233. break;
  1234. case OPTION_RTAUDIO_SAMPLE_RATE:
  1235. CARLA_ENGINE_SET_OPTION_RUNNING_CHECK
  1236. fOptions.rtaudioSampleRate = static_cast<uint>(value);
  1237. break;
  1238. case OPTION_RTAUDIO_DEVICE:
  1239. CARLA_ENGINE_SET_OPTION_RUNNING_CHECK
  1240. fOptions.rtaudioDevice = valueStr;
  1241. break;
  1242. #endif
  1243. #ifndef BUILD_BRIDGE
  1244. case OPTION_PATH_BRIDGE_NATIVE:
  1245. fOptions.bridge_native = valueStr;
  1246. break;
  1247. case OPTION_PATH_BRIDGE_POSIX32:
  1248. fOptions.bridge_posix32 = valueStr;
  1249. break;
  1250. case OPTION_PATH_BRIDGE_POSIX64:
  1251. fOptions.bridge_posix64 = valueStr;
  1252. break;
  1253. case OPTION_PATH_BRIDGE_WIN32:
  1254. fOptions.bridge_win32 = valueStr;
  1255. break;
  1256. case OPTION_PATH_BRIDGE_WIN64:
  1257. fOptions.bridge_win64 = valueStr;
  1258. break;
  1259. #endif
  1260. #ifdef WANT_LV2
  1261. case OPTION_PATH_BRIDGE_LV2_GTK2:
  1262. fOptions.bridge_lv2Gtk2 = valueStr;
  1263. break;
  1264. case OPTION_PATH_BRIDGE_LV2_GTK3:
  1265. fOptions.bridge_lv2Gtk3 = valueStr;
  1266. break;
  1267. case OPTION_PATH_BRIDGE_LV2_QT4:
  1268. fOptions.bridge_lv2Qt4 = valueStr;
  1269. break;
  1270. case OPTION_PATH_BRIDGE_LV2_QT5:
  1271. fOptions.bridge_lv2Qt5 = valueStr;
  1272. break;
  1273. case OPTION_PATH_BRIDGE_LV2_COCOA:
  1274. fOptions.bridge_lv2Cocoa = valueStr;
  1275. break;
  1276. case OPTION_PATH_BRIDGE_LV2_WINDOWS:
  1277. fOptions.bridge_lv2Win = valueStr;
  1278. break;
  1279. case OPTION_PATH_BRIDGE_LV2_X11:
  1280. fOptions.bridge_lv2X11 = valueStr;
  1281. break;
  1282. #endif
  1283. #ifdef WANT_VST
  1284. case OPTION_PATH_BRIDGE_VST_COCOA:
  1285. fOptions.bridge_vstCocoa = valueStr;
  1286. break;
  1287. case OPTION_PATH_BRIDGE_VST_HWND:
  1288. fOptions.bridge_vstHWND = valueStr;
  1289. break;
  1290. case OPTION_PATH_BRIDGE_VST_X11:
  1291. fOptions.bridge_vstX11 = valueStr;
  1292. break;
  1293. #endif
  1294. }
  1295. }
  1296. // -----------------------------------------------------------------------
  1297. // OSC Stuff
  1298. #ifdef BUILD_BRIDGE
  1299. bool CarlaEngine::isOscBridgeRegistered() const
  1300. {
  1301. return (kData->oscData != nullptr);
  1302. }
  1303. #else
  1304. bool CarlaEngine::isOscControlRegistered() const
  1305. {
  1306. return kData->osc.isControlRegistered();
  1307. }
  1308. #endif
  1309. void CarlaEngine::idleOsc()
  1310. {
  1311. kData->osc.idle();
  1312. }
  1313. const char* CarlaEngine::getOscServerPathTCP() const
  1314. {
  1315. return kData->osc.getServerPathTCP();
  1316. }
  1317. const char* CarlaEngine::getOscServerPathUDP() const
  1318. {
  1319. return kData->osc.getServerPathUDP();
  1320. }
  1321. #ifdef BUILD_BRIDGE
  1322. void CarlaEngine::setOscBridgeData(const CarlaOscData* const oscData)
  1323. {
  1324. kData->oscData = oscData;
  1325. }
  1326. #endif
  1327. // -----------------------------------------------------------------------
  1328. // protected calls
  1329. void CarlaEngine::bufferSizeChanged(const uint32_t newBufferSize)
  1330. {
  1331. carla_debug("CarlaEngine::bufferSizeChanged(%i)", newBufferSize);
  1332. for (unsigned int i=0; i < kData->curPluginCount; ++i)
  1333. {
  1334. CarlaPlugin* const plugin = kData->plugins[i].plugin;
  1335. if (plugin != nullptr && plugin->enabled())
  1336. plugin->bufferSizeChanged(newBufferSize);
  1337. }
  1338. callback(CALLBACK_BUFFER_SIZE_CHANGED, 0, newBufferSize, 0, 0.0f, nullptr);
  1339. }
  1340. void CarlaEngine::sampleRateChanged(const double newSampleRate)
  1341. {
  1342. carla_debug("CarlaEngine::sampleRateChanged(%g)", newSampleRate);
  1343. for (unsigned int i=0; i < kData->curPluginCount; ++i)
  1344. {
  1345. CarlaPlugin* const plugin = kData->plugins[i].plugin;
  1346. if (plugin != nullptr && plugin->enabled())
  1347. plugin->sampleRateChanged(newSampleRate);
  1348. }
  1349. callback(CALLBACK_SAMPLE_RATE_CHANGED, 0, 0, 0, newSampleRate, nullptr);
  1350. }
  1351. void CarlaEngine::proccessPendingEvents()
  1352. {
  1353. //carla_stderr("proccessPendingEvents(%i)", kData->nextAction.opcode);
  1354. switch (kData->nextAction.opcode)
  1355. {
  1356. case EnginePostActionNull:
  1357. break;
  1358. case EnginePostActionRemovePlugin:
  1359. doPluginRemove(kData, true);
  1360. break;
  1361. case EnginePostActionSwitchPlugins:
  1362. doPluginsSwitch(kData, true);
  1363. break;
  1364. }
  1365. if (kData->time.playing)
  1366. kData->time.frame += fBufferSize;
  1367. if (fOptions.transportMode == CarlaBackend::TRANSPORT_MODE_INTERNAL)
  1368. {
  1369. fTimeInfo.playing = kData->time.playing;
  1370. fTimeInfo.frame = kData->time.frame;
  1371. }
  1372. for (unsigned int i=0; i < kData->curPluginCount; ++i)
  1373. {
  1374. // TODO - peak values?
  1375. }
  1376. }
  1377. void CarlaEngine::setPeaks(const unsigned int pluginId, float const inPeaks[MAX_PEAKS], float const outPeaks[MAX_PEAKS])
  1378. {
  1379. kData->plugins[pluginId].insPeak[0] = inPeaks[0];
  1380. kData->plugins[pluginId].insPeak[1] = inPeaks[1];
  1381. kData->plugins[pluginId].outsPeak[0] = outPeaks[0];
  1382. kData->plugins[pluginId].outsPeak[1] = outPeaks[1];
  1383. }
  1384. #ifndef BUILD_BRIDGE
  1385. EngineEvent* CarlaEngine::getRackEventBuffer(const bool isInput)
  1386. {
  1387. return isInput ? kData->rack.in : kData->rack.out;
  1388. }
  1389. void setValueIfHigher(float& value, const float& compare)
  1390. {
  1391. if (value < compare)
  1392. value = compare;
  1393. }
  1394. void CarlaEngine::processRack(float* inBuf[2], float* outBuf[2], const uint32_t frames)
  1395. {
  1396. // initialize outputs (zero)
  1397. carla_zeroFloat(outBuf[0], frames);
  1398. carla_zeroFloat(outBuf[1], frames);
  1399. carla_zeroMem(kData->rack.out, sizeof(EngineEvent)*RACK_EVENT_COUNT);
  1400. bool processed = false;
  1401. // process plugins
  1402. for (unsigned int i=0; i < kData->curPluginCount; ++i)
  1403. {
  1404. CarlaPlugin* const plugin = kData->plugins[i].plugin;
  1405. if (plugin == nullptr || ! plugin->enabled() || ! plugin->tryLock())
  1406. continue;
  1407. if (processed)
  1408. {
  1409. // initialize inputs (from previous outputs)
  1410. carla_copyFloat(inBuf[0], outBuf[0], frames);
  1411. carla_copyFloat(inBuf[1], outBuf[1], frames);
  1412. std::memcpy(kData->rack.in, kData->rack.out, sizeof(EngineEvent)*RACK_EVENT_COUNT);
  1413. // initialize outputs (zero)
  1414. carla_zeroFloat(outBuf[0], frames);
  1415. carla_zeroFloat(outBuf[1], frames);
  1416. carla_zeroMem(kData->rack.out, sizeof(EngineEvent)*RACK_EVENT_COUNT);
  1417. }
  1418. // process
  1419. plugin->initBuffers();
  1420. plugin->process(inBuf, outBuf, frames);
  1421. plugin->unlock();
  1422. #if 0
  1423. // if plugin has no audio inputs, add previous buffers
  1424. if (plugin->audioInCount() == 0)
  1425. {
  1426. for (uint32_t j=0; j < frames; ++j)
  1427. {
  1428. outBuf[0][j] += inBuf[0][j];
  1429. outBuf[1][j] += inBuf[1][j];
  1430. }
  1431. }
  1432. // if plugin has no midi output, add previous events
  1433. if (plugin->midiOutCount() == 0)
  1434. {
  1435. for (uint32_t j=0, k=0; j < frames; ++j)
  1436. {
  1437. }
  1438. std::memcpy(kData->rack.out, kData->rack.in, sizeof(EngineEvent)*RACK_EVENT_COUNT);
  1439. }
  1440. #endif
  1441. // set peaks
  1442. {
  1443. float inPeak1 = 0.0f;
  1444. float inPeak2 = 0.0f;
  1445. float outPeak1 = 0.0f;
  1446. float outPeak2 = 0.0f;
  1447. for (uint32_t k=0; k < frames; ++k)
  1448. {
  1449. setValueIfHigher(inPeak1, std::fabs(inBuf[0][k]));
  1450. setValueIfHigher(inPeak2, std::fabs(inBuf[1][k]));
  1451. setValueIfHigher(outPeak1, std::fabs(outBuf[0][k]));
  1452. setValueIfHigher(outPeak2, std::fabs(outBuf[1][k]));
  1453. }
  1454. kData->plugins[i].insPeak[0] = inPeak1;
  1455. kData->plugins[i].insPeak[1] = inPeak2;
  1456. kData->plugins[i].outsPeak[0] = outPeak1;
  1457. kData->plugins[i].outsPeak[1] = outPeak2;
  1458. }
  1459. processed = true;
  1460. }
  1461. }
  1462. void CarlaEngine::processPatchbay(float** inBuf, float** outBuf, const uint32_t bufCount[2], const uint32_t frames)
  1463. {
  1464. // TODO
  1465. return;
  1466. // unused, for now
  1467. (void)inBuf;
  1468. (void)outBuf;
  1469. (void)bufCount;
  1470. (void)frames;
  1471. }
  1472. #endif
  1473. // -------------------------------------------------------------------------------------------------------------------
  1474. // Carla Engine OSC stuff
  1475. #ifndef BUILD_BRIDGE
  1476. void CarlaEngine::osc_send_control_add_plugin_start(const int32_t pluginId, const char* const pluginName)
  1477. {
  1478. CARLA_ASSERT(kData->oscData != nullptr);
  1479. CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)kData->curPluginCount);
  1480. CARLA_ASSERT(pluginName);
  1481. carla_debug("CarlaEngine::osc_send_control_add_plugin_start(%i, \"%s\")", pluginId, pluginName);
  1482. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1483. {
  1484. char targetPath[std::strlen(kData->oscData->path)+18];
  1485. std::strcpy(targetPath, kData->oscData->path);
  1486. std::strcat(targetPath, "/add_plugin_start");
  1487. lo_send(kData->oscData->target, targetPath, "is", pluginId, pluginName);
  1488. }
  1489. }
  1490. void CarlaEngine::osc_send_control_add_plugin_end(const int32_t pluginId)
  1491. {
  1492. carla_debug("CarlaEngine::osc_send_control_add_plugin_end(%i)", pluginId);
  1493. CARLA_ASSERT(kData->oscData != nullptr);
  1494. CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)kData->curPluginCount);
  1495. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1496. {
  1497. char targetPath[std::strlen(kData->oscData->path)+16];
  1498. std::strcpy(targetPath, kData->oscData->path);
  1499. std::strcat(targetPath, "/add_plugin_end");
  1500. lo_send(kData->oscData->target, targetPath, "i", pluginId);
  1501. }
  1502. }
  1503. void CarlaEngine::osc_send_control_remove_plugin(const int32_t pluginId)
  1504. {
  1505. carla_debug("CarlaEngine::osc_send_control_remove_plugin(%i)", pluginId);
  1506. CARLA_ASSERT(kData->oscData != nullptr);
  1507. CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)kData->curPluginCount);
  1508. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1509. {
  1510. char targetPath[std::strlen(kData->oscData->path)+15];
  1511. std::strcpy(targetPath, kData->oscData->path);
  1512. std::strcat(targetPath, "/remove_plugin");
  1513. lo_send(kData->oscData->target, targetPath, "i", pluginId);
  1514. }
  1515. }
  1516. void CarlaEngine::osc_send_control_set_plugin_data(const int32_t pluginId, const int32_t type, const int32_t category, const int32_t hints, const char* const realName, const char* const label, const char* const maker, const char* const copyright, const int64_t uniqueId)
  1517. {
  1518. carla_debug("CarlaEngine::osc_send_control_set_plugin_data(%i, %i, %i, %i, \"%s\", \"%s\", \"%s\", \"%s\", " P_INT64 ")", pluginId, type, category, hints, realName, label, maker, copyright, uniqueId);
  1519. CARLA_ASSERT(kData->oscData != nullptr);
  1520. CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)kData->curPluginCount);
  1521. CARLA_ASSERT(type != PLUGIN_NONE);
  1522. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1523. {
  1524. char targetPath[std::strlen(kData->oscData->path)+17];
  1525. std::strcpy(targetPath, kData->oscData->path);
  1526. std::strcat(targetPath, "/set_plugin_data");
  1527. lo_send(kData->oscData->target, targetPath, "iiiissssh", pluginId, type, category, hints, realName, label, maker, copyright, uniqueId);
  1528. }
  1529. }
  1530. void CarlaEngine::osc_send_control_set_plugin_ports(const int32_t pluginId, const int32_t audioIns, const int32_t audioOuts, const int32_t midiIns, const int32_t midiOuts, const int32_t cIns, const int32_t cOuts, const int32_t cTotals)
  1531. {
  1532. carla_debug("CarlaEngine::osc_send_control_set_plugin_ports(%i, %i, %i, %i, %i, %i, %i, %i)", pluginId, audioIns, audioOuts, midiIns, midiOuts, cIns, cOuts, cTotals);
  1533. CARLA_ASSERT(kData->oscData != nullptr);
  1534. CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)kData->curPluginCount);
  1535. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1536. {
  1537. char targetPath[std::strlen(kData->oscData->path)+18];
  1538. std::strcpy(targetPath, kData->oscData->path);
  1539. std::strcat(targetPath, "/set_plugin_ports");
  1540. lo_send(kData->oscData->target, targetPath, "iiiiiiii", pluginId, audioIns, audioOuts, midiIns, midiOuts, cIns, cOuts, cTotals);
  1541. }
  1542. }
  1543. void CarlaEngine::osc_send_control_set_parameter_data(const int32_t pluginId, const int32_t index, const int32_t type, const int32_t hints, const char* const name, const char* const label, const float current)
  1544. {
  1545. carla_debug("CarlaEngine::osc_send_control_set_parameter_data(%i, %i, %i, %i, \"%s\", \"%s\", %g)", pluginId, index, type, hints, name, label, current);
  1546. CARLA_ASSERT(kData->oscData != nullptr);
  1547. CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)kData->curPluginCount);
  1548. CARLA_ASSERT(index >= 0);
  1549. CARLA_ASSERT(type != PARAMETER_UNKNOWN);
  1550. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1551. {
  1552. char targetPath[std::strlen(kData->oscData->path)+20];
  1553. std::strcpy(targetPath, kData->oscData->path);
  1554. std::strcat(targetPath, "/set_parameter_data");
  1555. lo_send(kData->oscData->target, targetPath, "iiiissd", pluginId, index, type, hints, name, label, current);
  1556. }
  1557. }
  1558. void CarlaEngine::osc_send_control_set_parameter_ranges(const int32_t pluginId, const int32_t index, const float min, const float max, const float def, const float step, const float stepSmall, const float stepLarge)
  1559. {
  1560. carla_debug("CarlaEngine::osc_send_control_set_parameter_ranges(%i, %i, %g, %g, %g, %g, %g, %g)", pluginId, index, min, max, def, step, stepSmall, stepLarge);
  1561. CARLA_ASSERT(kData->oscData != nullptr);
  1562. CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)kData->curPluginCount);
  1563. CARLA_ASSERT(index >= 0);
  1564. CARLA_ASSERT(min < max);
  1565. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1566. {
  1567. char targetPath[std::strlen(kData->oscData->path)+22];
  1568. std::strcpy(targetPath, kData->oscData->path);
  1569. std::strcat(targetPath, "/set_parameter_ranges");
  1570. lo_send(kData->oscData->target, targetPath, "iidddddd", pluginId, index, min, max, def, step, stepSmall, stepLarge);
  1571. }
  1572. }
  1573. void CarlaEngine::osc_send_control_set_parameter_midi_cc(const int32_t pluginId, const int32_t index, const int32_t cc)
  1574. {
  1575. carla_debug("CarlaEngine::osc_send_control_set_parameter_midi_cc(%i, %i, %i)", pluginId, index, cc);
  1576. CARLA_ASSERT(kData->oscData != nullptr);
  1577. CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)kData->curPluginCount);
  1578. CARLA_ASSERT(index >= 0);
  1579. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1580. {
  1581. char targetPath[std::strlen(kData->oscData->path)+23];
  1582. std::strcpy(targetPath, kData->oscData->path);
  1583. std::strcat(targetPath, "/set_parameter_midi_cc");
  1584. lo_send(kData->oscData->target, targetPath, "iii", pluginId, index, cc);
  1585. }
  1586. }
  1587. void CarlaEngine::osc_send_control_set_parameter_midi_channel(const int32_t pluginId, const int32_t index, const int32_t channel)
  1588. {
  1589. carla_debug("CarlaEngine::osc_send_control_set_parameter_midi_channel(%i, %i, %i)", pluginId, index, channel);
  1590. CARLA_ASSERT(kData->oscData != nullptr);
  1591. CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)kData->curPluginCount);
  1592. CARLA_ASSERT(index >= 0);
  1593. CARLA_ASSERT(channel >= 0 && channel < 16);
  1594. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1595. {
  1596. char targetPath[std::strlen(kData->oscData->path)+28];
  1597. std::strcpy(targetPath, kData->oscData->path);
  1598. std::strcat(targetPath, "/set_parameter_midi_channel");
  1599. lo_send(kData->oscData->target, targetPath, "iii", pluginId, index, channel);
  1600. }
  1601. }
  1602. void CarlaEngine::osc_send_control_set_parameter_value(const int32_t pluginId, const int32_t index, const float value)
  1603. {
  1604. #if 0 //DEBUG
  1605. CARLA_ASSERT(kData->oscData != nullptr);
  1606. CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)kData->curPluginCount);
  1607. if (index < 0)
  1608. carla_debug("CarlaEngine::osc_send_control_set_parameter_value(%i, %s, %g)", pluginId, InternalParametersIndex2Str((InternalParametersIndex)index), value);
  1609. else
  1610. carla_debug("CarlaEngine::osc_send_control_set_parameter_value(%i, %i, %g)", pluginId, index, value);
  1611. #endif
  1612. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1613. {
  1614. char targetPath[std::strlen(kData->oscData->path)+21];
  1615. std::strcpy(targetPath, kData->oscData->path);
  1616. std::strcat(targetPath, "/set_parameter_value");
  1617. lo_send(kData->oscData->target, targetPath, "iid", pluginId, index, value);
  1618. }
  1619. }
  1620. void CarlaEngine::osc_send_control_set_default_value(const int32_t pluginId, const int32_t index, const float value)
  1621. {
  1622. carla_debug("CarlaEngine::osc_send_control_set_default_value(%i, %i, %g)", pluginId, index, value);
  1623. CARLA_ASSERT(kData->oscData != nullptr);
  1624. CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)kData->maxPluginNumber);
  1625. CARLA_ASSERT(index >= 0);
  1626. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1627. {
  1628. char targetPath[std::strlen(kData->oscData->path)+19];
  1629. std::strcpy(targetPath, kData->oscData->path);
  1630. std::strcat(targetPath, "/set_default_value");
  1631. lo_send(kData->oscData->target, targetPath, "iid", pluginId, index, value);
  1632. }
  1633. }
  1634. void CarlaEngine::osc_send_control_set_program(const int32_t pluginId, const int32_t index)
  1635. {
  1636. carla_debug("CarlaEngine::osc_send_control_set_program(%i, %i)", pluginId, index);
  1637. CARLA_ASSERT(kData->oscData != nullptr);
  1638. CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)kData->maxPluginNumber);
  1639. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1640. {
  1641. char targetPath[std::strlen(kData->oscData->path)+13];
  1642. std::strcpy(targetPath, kData->oscData->path);
  1643. std::strcat(targetPath, "/set_program");
  1644. lo_send(kData->oscData->target, targetPath, "ii", pluginId, index);
  1645. }
  1646. }
  1647. void CarlaEngine::osc_send_control_set_program_count(const int32_t pluginId, const int32_t count)
  1648. {
  1649. carla_debug("CarlaEngine::osc_send_control_set_program_count(%i, %i)", pluginId, count);
  1650. CARLA_ASSERT(kData->oscData != nullptr);
  1651. CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)kData->maxPluginNumber);
  1652. CARLA_ASSERT(count >= 0);
  1653. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1654. {
  1655. char targetPath[std::strlen(kData->oscData->path)+19];
  1656. std::strcpy(targetPath, kData->oscData->path);
  1657. std::strcat(targetPath, "/set_program_count");
  1658. lo_send(kData->oscData->target, targetPath, "ii", pluginId, count);
  1659. }
  1660. }
  1661. void CarlaEngine::osc_send_control_set_program_name(const int32_t pluginId, const int32_t index, const char* const name)
  1662. {
  1663. carla_debug("CarlaEngine::osc_send_control_set_program_name(%i, %i, \"%s\")", pluginId, index, name);
  1664. CARLA_ASSERT(kData->oscData != nullptr);
  1665. CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)kData->maxPluginNumber);
  1666. CARLA_ASSERT(index >= 0);
  1667. CARLA_ASSERT(name);
  1668. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1669. {
  1670. char targetPath[std::strlen(kData->oscData->path)+18];
  1671. std::strcpy(targetPath, kData->oscData->path);
  1672. std::strcat(targetPath, "/set_program_name");
  1673. lo_send(kData->oscData->target, targetPath, "iis", pluginId, index, name);
  1674. }
  1675. }
  1676. void CarlaEngine::osc_send_control_set_midi_program(const int32_t pluginId, const int32_t index)
  1677. {
  1678. carla_debug("CarlaEngine::osc_send_control_set_midi_program(%i, %i)", pluginId, index);
  1679. CARLA_ASSERT(kData->oscData != nullptr);
  1680. CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)kData->maxPluginNumber);
  1681. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1682. {
  1683. char targetPath[std::strlen(kData->oscData->path)+18];
  1684. std::strcpy(targetPath, kData->oscData->path);
  1685. std::strcat(targetPath, "/set_midi_program");
  1686. lo_send(kData->oscData->target, targetPath, "ii", pluginId, index);
  1687. }
  1688. }
  1689. void CarlaEngine::osc_send_control_set_midi_program_count(const int32_t pluginId, const int32_t count)
  1690. {
  1691. carla_debug("CarlaEngine::osc_send_control_set_midi_program_count(%i, %i)", pluginId, count);
  1692. CARLA_ASSERT(kData->oscData != nullptr);
  1693. CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)kData->maxPluginNumber);
  1694. CARLA_ASSERT(count >= 0);
  1695. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1696. {
  1697. char targetPath[std::strlen(kData->oscData->path)+24];
  1698. std::strcpy(targetPath, kData->oscData->path);
  1699. std::strcat(targetPath, "/set_midi_program_count");
  1700. lo_send(kData->oscData->target, targetPath, "ii", pluginId, count);
  1701. }
  1702. }
  1703. void CarlaEngine::osc_send_control_set_midi_program_data(const int32_t pluginId, const int32_t index, const int32_t bank, const int32_t program, const char* const name)
  1704. {
  1705. carla_debug("CarlaEngine::osc_send_control_set_midi_program_data(%i, %i, %i, %i, \"%s\")", pluginId, index, bank, program, name);
  1706. CARLA_ASSERT(kData->oscData != nullptr);
  1707. CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)kData->maxPluginNumber);
  1708. CARLA_ASSERT(index >= 0);
  1709. CARLA_ASSERT(bank >= 0);
  1710. CARLA_ASSERT(program >= 0);
  1711. CARLA_ASSERT(name);
  1712. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1713. {
  1714. char targetPath[std::strlen(kData->oscData->path)+23];
  1715. std::strcpy(targetPath, kData->oscData->path);
  1716. std::strcat(targetPath, "/set_midi_program_data");
  1717. lo_send(kData->oscData->target, targetPath, "iiiis", pluginId, index, bank, program, name);
  1718. }
  1719. }
  1720. void CarlaEngine::osc_send_control_note_on(const int32_t pluginId, const int32_t channel, const int32_t note, const int32_t velo)
  1721. {
  1722. carla_debug("CarlaEngine::osc_send_control_note_on(%i, %i, %i, %i)", pluginId, channel, note, velo);
  1723. CARLA_ASSERT(kData->oscData != nullptr);
  1724. CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)kData->maxPluginNumber);
  1725. CARLA_ASSERT(channel >= 0 && channel < 16);
  1726. CARLA_ASSERT(note >= 0 && note < 128);
  1727. CARLA_ASSERT(velo > 0 && velo < 128);
  1728. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1729. {
  1730. char targetPath[std::strlen(kData->oscData->path)+9];
  1731. std::strcpy(targetPath, kData->oscData->path);
  1732. std::strcat(targetPath, "/note_on");
  1733. lo_send(kData->oscData->target, targetPath, "iiii", pluginId, channel, note, velo);
  1734. }
  1735. }
  1736. void CarlaEngine::osc_send_control_note_off(const int32_t pluginId, const int32_t channel, const int32_t note)
  1737. {
  1738. carla_debug("CarlaEngine::osc_send_control_note_off(%i, %i, %i)", pluginId, channel, note);
  1739. CARLA_ASSERT(kData->oscData != nullptr);
  1740. CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)kData->maxPluginNumber);
  1741. CARLA_ASSERT(channel >= 0 && channel < 16);
  1742. CARLA_ASSERT(note >= 0 && note < 128);
  1743. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1744. {
  1745. char targetPath[std::strlen(kData->oscData->path)+10];
  1746. std::strcpy(targetPath, kData->oscData->path);
  1747. std::strcat(targetPath, "/note_off");
  1748. lo_send(kData->oscData->target, targetPath, "iii", pluginId, channel, note);
  1749. }
  1750. }
  1751. void CarlaEngine::osc_send_control_set_peaks(const int32_t pluginId)
  1752. {
  1753. CARLA_ASSERT(kData->oscData != nullptr);
  1754. CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)kData->maxPluginNumber);
  1755. const EnginePluginData& pData = kData->plugins[pluginId];
  1756. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1757. {
  1758. char targetPath[std::strlen(kData->oscData->path)+22];
  1759. std::strcpy(targetPath, kData->oscData->path);
  1760. std::strcat(targetPath, "/set_peaks");
  1761. lo_send(kData->oscData->target, targetPath, "iffff", pluginId, pData.insPeak[0], pData.insPeak[1], pData.outsPeak[0], pData.outsPeak[1]);
  1762. }
  1763. }
  1764. void CarlaEngine::osc_send_control_exit()
  1765. {
  1766. carla_debug("CarlaEngine::osc_send_control_exit()");
  1767. CARLA_ASSERT(kData->oscData != nullptr);
  1768. if (kData->oscData && kData->oscData->target)
  1769. {
  1770. char targetPath[std::strlen(kData->oscData->path)+6];
  1771. std::strcpy(targetPath, kData->oscData->path);
  1772. std::strcat(targetPath, "/exit");
  1773. lo_send(kData->oscData->target, targetPath, "");
  1774. }
  1775. }
  1776. #else
  1777. void CarlaEngine::osc_send_bridge_audio_count(const int32_t ins, const int32_t outs, const int32_t total)
  1778. {
  1779. CARLA_ASSERT(kData->oscData != nullptr);
  1780. CARLA_ASSERT(total >= 0 && total >= ins + outs);
  1781. carla_debug("CarlaEngine::osc_send_bridge_audio_count(%i, %i, %i)", ins, outs, total);
  1782. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1783. {
  1784. char targetPath[std::strlen(kData->oscData->path)+20];
  1785. std::strcpy(targetPath, kData->oscData->path);
  1786. std::strcat(targetPath, "/bridge_audio_count");
  1787. lo_send(kData->oscData->target, targetPath, "iii", ins, outs, total);
  1788. }
  1789. }
  1790. void CarlaEngine::osc_send_bridge_midi_count(const int32_t ins, const int32_t outs, const int32_t total)
  1791. {
  1792. CARLA_ASSERT(kData->oscData != nullptr);
  1793. CARLA_ASSERT(total >= 0 && total >= ins + outs);
  1794. carla_debug("CarlaEngine::osc_send_bridge_midi_count(%i, %i, %i)", ins, outs, total);
  1795. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1796. {
  1797. char targetPath[std::strlen(kData->oscData->path)+19];
  1798. std::strcpy(targetPath, kData->oscData->path);
  1799. std::strcat(targetPath, "/bridge_midi_count");
  1800. lo_send(kData->oscData->target, targetPath, "iii", ins, outs, total);
  1801. }
  1802. }
  1803. void CarlaEngine::osc_send_bridge_parameter_count(const int32_t ins, const int32_t outs, const int32_t total)
  1804. {
  1805. CARLA_ASSERT(kData->oscData != nullptr);
  1806. CARLA_ASSERT(total >= 0 && total >= ins + outs);
  1807. carla_debug("CarlaEngine::osc_send_bridge_parameter_count(%i, %i, %i)", ins, outs, total);
  1808. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1809. {
  1810. char targetPath[std::strlen(kData->oscData->path)+24];
  1811. std::strcpy(targetPath, kData->oscData->path);
  1812. std::strcat(targetPath, "/bridge_parameter_count");
  1813. lo_send(kData->oscData->target, targetPath, "iii", ins, outs, total);
  1814. }
  1815. }
  1816. void CarlaEngine::osc_send_bridge_program_count(const int32_t count)
  1817. {
  1818. CARLA_ASSERT(kData->oscData != nullptr);
  1819. CARLA_ASSERT(count >= 0);
  1820. carla_debug("CarlaEngine::osc_send_bridge_program_count(%i)", count);
  1821. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1822. {
  1823. char targetPath[std::strlen(kData->oscData->path)+22];
  1824. std::strcpy(targetPath, kData->oscData->path);
  1825. std::strcat(targetPath, "/bridge_program_count");
  1826. lo_send(kData->oscData->target, targetPath, "i", count);
  1827. }
  1828. }
  1829. void CarlaEngine::osc_send_bridge_midi_program_count(const int32_t count)
  1830. {
  1831. CARLA_ASSERT(kData->oscData != nullptr);
  1832. CARLA_ASSERT(count >= 0);
  1833. carla_debug("CarlaEngine::osc_send_bridge_midi_program_count(%i)", count);
  1834. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1835. {
  1836. char targetPath[std::strlen(kData->oscData->path)+27];
  1837. std::strcpy(targetPath, kData->oscData->path);
  1838. std::strcat(targetPath, "/bridge_midi_program_count");
  1839. lo_send(kData->oscData->target, targetPath, "i", count);
  1840. }
  1841. }
  1842. void CarlaEngine::osc_send_bridge_plugin_info(const int32_t category, const int32_t hints, const char* const name, const char* const label, const char* const maker, const char* const copyright, const int64_t uniqueId)
  1843. {
  1844. CARLA_ASSERT(kData->oscData != nullptr);
  1845. CARLA_ASSERT(name != nullptr);
  1846. CARLA_ASSERT(label != nullptr);
  1847. CARLA_ASSERT(maker != nullptr);
  1848. CARLA_ASSERT(copyright != nullptr);
  1849. carla_debug("CarlaEngine::osc_send_bridge_plugin_info(%i, %i, \"%s\", \"%s\", \"%s\", \"%s\", " P_INT64 ")", category, hints, name, label, maker, copyright, uniqueId);
  1850. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1851. {
  1852. char targetPath[std::strlen(kData->oscData->path)+20];
  1853. std::strcpy(targetPath, kData->oscData->path);
  1854. std::strcat(targetPath, "/bridge_plugin_info");
  1855. lo_send(kData->oscData->target, targetPath, "iissssh", category, hints, name, label, maker, copyright, uniqueId);
  1856. }
  1857. }
  1858. void CarlaEngine::osc_send_bridge_parameter_info(const int32_t index, const char* const name, const char* const unit)
  1859. {
  1860. CARLA_ASSERT(kData->oscData != nullptr);
  1861. CARLA_ASSERT(name != nullptr);
  1862. CARLA_ASSERT(unit != nullptr);
  1863. carla_debug("CarlaEngine::osc_send_bridge_parameter_info(%i, \"%s\", \"%s\")", index, name, unit);
  1864. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1865. {
  1866. char targetPath[std::strlen(kData->oscData->path)+23];
  1867. std::strcpy(targetPath, kData->oscData->path);
  1868. std::strcat(targetPath, "/bridge_parameter_info");
  1869. lo_send(kData->oscData->target, targetPath, "iss", index, name, unit);
  1870. }
  1871. }
  1872. void CarlaEngine::osc_send_bridge_parameter_data(const int32_t index, const int32_t type, const int32_t rindex, const int32_t hints, const int32_t midiChannel, const int32_t midiCC)
  1873. {
  1874. CARLA_ASSERT(kData->oscData != nullptr);
  1875. carla_debug("CarlaEngine::osc_send_bridge_parameter_data(%i, %i, %i, %i, %i, %i)", index, type, rindex, hints, midiChannel, midiCC);
  1876. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1877. {
  1878. char targetPath[std::strlen(kData->oscData->path)+23];
  1879. std::strcpy(targetPath, kData->oscData->path);
  1880. std::strcat(targetPath, "/bridge_parameter_data");
  1881. lo_send(kData->oscData->target, targetPath, "iiiiii", index, type, rindex, hints, midiChannel, midiCC);
  1882. }
  1883. }
  1884. void CarlaEngine::osc_send_bridge_parameter_ranges(const int32_t index, const float def, const float min, const float max, const float step, const float stepSmall, const float stepLarge)
  1885. {
  1886. CARLA_ASSERT(kData->oscData != nullptr);
  1887. carla_debug("CarlaEngine::osc_send_bridge_parameter_ranges(%i, %f, %f, %f, %f, %f, %f)", index, def, min, max, step, stepSmall, stepLarge);
  1888. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1889. {
  1890. char targetPath[std::strlen(kData->oscData->path)+25];
  1891. std::strcpy(targetPath, kData->oscData->path);
  1892. std::strcat(targetPath, "/bridge_parameter_ranges");
  1893. lo_send(kData->oscData->target, targetPath, "iffffff", index, def, min, max, step, stepSmall, stepLarge);
  1894. }
  1895. }
  1896. void CarlaEngine::osc_send_bridge_program_info(const int32_t index, const char* const name)
  1897. {
  1898. CARLA_ASSERT(kData->oscData != nullptr);
  1899. carla_debug("CarlaEngine::osc_send_bridge_program_info(%i, \"%s\")", index, name);
  1900. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1901. {
  1902. char targetPath[std::strlen(kData->oscData->path)+21];
  1903. std::strcpy(targetPath, kData->oscData->path);
  1904. std::strcat(targetPath, "/bridge_program_info");
  1905. lo_send(kData->oscData->target, targetPath, "is", index, name);
  1906. }
  1907. }
  1908. void CarlaEngine::osc_send_bridge_midi_program_info(const int32_t index, const int32_t bank, const int32_t program, const char* const label)
  1909. {
  1910. CARLA_ASSERT(kData->oscData != nullptr);
  1911. carla_debug("CarlaEngine::osc_send_bridge_midi_program_info(%i, %i, %i, \"%s\")", index, bank, program, label);
  1912. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1913. {
  1914. char targetPath[std::strlen(kData->oscData->path)+26];
  1915. std::strcpy(targetPath, kData->oscData->path);
  1916. std::strcat(targetPath, "/bridge_midi_program_info");
  1917. lo_send(kData->oscData->target, targetPath, "iiis", index, bank, program, label);
  1918. }
  1919. }
  1920. void CarlaEngine::osc_send_bridge_configure(const char* const key, const char* const value)
  1921. {
  1922. CARLA_ASSERT(kData->oscData != nullptr);
  1923. CARLA_ASSERT(key != nullptr);
  1924. CARLA_ASSERT(value != nullptr);
  1925. carla_debug("CarlaEngine::osc_send_bridge_configure(\"%s\", \"%s\")", key, value);
  1926. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1927. {
  1928. char targetPath[std::strlen(kData->oscData->path)+18];
  1929. std::strcpy(targetPath, kData->oscData->path);
  1930. std::strcat(targetPath, "/bridge_configure");
  1931. lo_send(kData->oscData->target, targetPath, "ss", key, value);
  1932. }
  1933. }
  1934. void CarlaEngine::osc_send_bridge_set_parameter_value(const int32_t index, const float value)
  1935. {
  1936. CARLA_ASSERT(kData->oscData != nullptr);
  1937. carla_debug("CarlaEngine::osc_send_bridge_set_parameter_value(%i, %f)", index, value);
  1938. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1939. {
  1940. char targetPath[std::strlen(kData->oscData->path)+28];
  1941. std::strcpy(targetPath, kData->oscData->path);
  1942. std::strcat(targetPath, "/bridge_set_parameter_value");
  1943. lo_send(kData->oscData->target, targetPath, "if", index, value);
  1944. }
  1945. }
  1946. void CarlaEngine::osc_send_bridge_set_default_value(const int32_t index, const float value)
  1947. {
  1948. CARLA_ASSERT(kData->oscData != nullptr);
  1949. carla_debug("CarlaEngine::osc_send_bridge_set_default_value(%i, %f)", index, value);
  1950. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1951. {
  1952. char targetPath[std::strlen(kData->oscData->path)+26];
  1953. std::strcpy(targetPath, kData->oscData->path);
  1954. std::strcat(targetPath, "/bridge_set_default_value");
  1955. lo_send(kData->oscData->target, targetPath, "if", index, value);
  1956. }
  1957. }
  1958. void CarlaEngine::osc_send_bridge_set_program(const int32_t index)
  1959. {
  1960. CARLA_ASSERT(kData->oscData != nullptr);
  1961. carla_debug("CarlaEngine::osc_send_bridge_set_program(%i)", index);
  1962. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1963. {
  1964. char targetPath[std::strlen(kData->oscData->path)+20];
  1965. std::strcpy(targetPath, kData->oscData->path);
  1966. std::strcat(targetPath, "/bridge_set_program");
  1967. lo_send(kData->oscData->target, targetPath, "i", index);
  1968. }
  1969. }
  1970. void CarlaEngine::osc_send_bridge_set_midi_program(const int32_t index)
  1971. {
  1972. CARLA_ASSERT(kData->oscData != nullptr);
  1973. carla_debug("CarlaEngine::osc_send_bridge_set_midi_program(%i)", index);
  1974. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1975. {
  1976. char targetPath[std::strlen(kData->oscData->path)+25];
  1977. std::strcpy(targetPath, kData->oscData->path);
  1978. std::strcat(targetPath, "/bridge_set_midi_program");
  1979. lo_send(kData->oscData->target, targetPath, "i", index);
  1980. }
  1981. }
  1982. void CarlaEngine::osc_send_bridge_set_custom_data(const char* const type, const char* const key, const char* const value)
  1983. {
  1984. CARLA_ASSERT(kData->oscData != nullptr);
  1985. carla_debug("CarlaEngine::osc_send_bridge_set_custom_data(\"%s\", \"%s\", \"%s\")", type, key, value);
  1986. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1987. {
  1988. char targetPath[std::strlen(kData->oscData->path)+24];
  1989. std::strcpy(targetPath, kData->oscData->path);
  1990. std::strcat(targetPath, "/bridge_set_custom_data");
  1991. lo_send(kData->oscData->target, targetPath, "sss", type, key, value);
  1992. }
  1993. }
  1994. void CarlaEngine::osc_send_bridge_set_chunk_data(const char* const chunkFile)
  1995. {
  1996. CARLA_ASSERT(kData->oscData != nullptr);
  1997. carla_debug("CarlaEngine::osc_send_bridge_set_chunk_data(\"%s\")", chunkFile);
  1998. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1999. {
  2000. char targetPath[std::strlen(kData->oscData->path)+23];
  2001. std::strcpy(targetPath, kData->oscData->path);
  2002. std::strcat(targetPath, "/bridge_set_chunk_data");
  2003. lo_send(kData->oscData->target, targetPath, "s", chunkFile);
  2004. }
  2005. }
  2006. #endif
  2007. CARLA_BACKEND_END_NAMESPACE