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

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