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

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