Audio plugin host https://kx.studio/carla
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

CarlaEngine.cpp 109KB

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