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

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