|
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780 |
- /*
- * Carla Engine
- * Copyright (C) 2012-2013 Filipe Coelho <falktx@falktx.com>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of
- * the License, or any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * For a full copy of the GNU General Public License see the doc/GPL.txt file.
- */
-
- /* TODO:
- * - add more checks to oscSend_* stuff
- * - complete processRack(): carefully add to input, sorted events
- * - implement processPatchbay()
- * - implement oscSend_control_switch_plugins()
- * - proper find&load plugins
- * - uncomment CarlaPlugin::newAU and newCSOUND
- * - something about the peaks?
- */
-
- #include "CarlaEngineInternal.hpp"
- #include "CarlaBackendUtils.hpp"
- #include "CarlaStateUtils.hpp"
- #include "CarlaMIDI.h"
-
- #include <cmath>
-
- #include <QtCore/QFile>
- #include <QtCore/QFileInfo>
- #include <QtCore/QTextStream>
-
- CARLA_BACKEND_START_NAMESPACE
-
- #if 0
- } // Fix editor indentation
- #endif
-
- // -----------------------------------------------------------------------
- // Fallback data
-
- static const EngineEvent kFallbackEngineEvent = { kEngineEventTypeNull, 0, 0, { kEngineControlEventTypeNull, 0, 0.0f } };
-
- // -----------------------------------------------------------------------
-
- void EngineControlEvent::dumpToMidiData(const uint8_t channel, uint8_t& size, uint8_t data[3]) const noexcept
- {
- switch (type)
- {
- case kEngineControlEventTypeNull:
- break;
-
- case kEngineControlEventTypeParameter:
- if (MIDI_IS_CONTROL_BANK_SELECT(param))
- {
- size = 3;
- data[0] = static_cast<uint8_t>(MIDI_STATUS_CONTROL_CHANGE + channel);
- data[1] = MIDI_CONTROL_BANK_SELECT;
- data[2] = static_cast<uint8_t>(value);
- }
- else
- {
- size = 3;
- data[0] = static_cast<uint8_t>(MIDI_STATUS_CONTROL_CHANGE + channel);
- data[1] = static_cast<uint8_t>(param);
- data[2] = uint8_t(value * 127.0f);
- }
- break;
-
- case kEngineControlEventTypeMidiBank:
- size = 3;
- data[0] = static_cast<uint8_t>(MIDI_STATUS_CONTROL_CHANGE + channel);
- data[1] = MIDI_CONTROL_BANK_SELECT;
- data[2] = static_cast<uint8_t>(param);
- break;
-
- case kEngineControlEventTypeMidiProgram:
- size = 2;
- data[0] = static_cast<uint8_t>(MIDI_STATUS_PROGRAM_CHANGE + channel);
- data[1] = static_cast<uint8_t>(param);
- break;
-
- case kEngineControlEventTypeAllSoundOff:
- size = 2;
- data[0] = static_cast<uint8_t>(MIDI_STATUS_CONTROL_CHANGE + channel);
- data[1] = MIDI_CONTROL_ALL_SOUND_OFF;
- break;
-
- case kEngineControlEventTypeAllNotesOff:
- size = 2;
- data[0] = static_cast<uint8_t>(MIDI_STATUS_CONTROL_CHANGE + channel);
- data[1] = MIDI_CONTROL_ALL_NOTES_OFF;
- break;
- }
- }
-
- void EngineEvent::fillFromMidiData(const uint8_t size, uint8_t* const data)
- {
- // get channel
- channel = MIDI_GET_CHANNEL_FROM_DATA(data);
-
- // get status
- const uint8_t midiStatus(MIDI_GET_STATUS_FROM_DATA(data));
-
- // remove channel bit from data
- data[0] = midiStatus;
-
- if (midiStatus == MIDI_STATUS_CONTROL_CHANGE)
- {
- type = kEngineEventTypeControl;
-
- const uint8_t midiControl(data[1]);
-
- if (MIDI_IS_CONTROL_BANK_SELECT(midiControl))
- {
- CARLA_SAFE_ASSERT_INT(size == 3, size);
-
- const uint8_t midiBank(data[2]);
-
- ctrl.type = kEngineControlEventTypeMidiBank;
- ctrl.param = midiBank;
- ctrl.value = 0.0f;
- }
- else if (midiControl == MIDI_CONTROL_ALL_SOUND_OFF)
- {
- CARLA_SAFE_ASSERT_INT(size == 2, size);
-
- ctrl.type = kEngineControlEventTypeAllSoundOff;
- ctrl.param = 0;
- ctrl.value = 0.0f;
- }
- else if (midiControl == MIDI_CONTROL_ALL_NOTES_OFF)
- {
- CARLA_SAFE_ASSERT_INT(size == 2, size);
-
- ctrl.type = kEngineControlEventTypeAllNotesOff;
- ctrl.param = 0;
- ctrl.value = 0.0f;
- }
- else
- {
- CARLA_SAFE_ASSERT_INT2(size == 3, size, midiControl);
-
- const uint8_t midiValue(data[2]);
-
- ctrl.type = kEngineControlEventTypeParameter;
- ctrl.param = midiControl;
- ctrl.value = float(midiValue)/127.0f;
- }
- }
- else if (midiStatus == MIDI_STATUS_PROGRAM_CHANGE)
- {
- CARLA_SAFE_ASSERT_INT2(size == 2, size, data[1]);
-
- type = kEngineEventTypeControl;
-
- const uint8_t midiProgram(data[1]);
-
- ctrl.type = kEngineControlEventTypeMidiProgram;
- ctrl.param = midiProgram;
- ctrl.value = 0.0f;
- }
- else
- {
- type = kEngineEventTypeMidi;
-
- midi.port = 0;
- midi.size = size;
-
- if (size > EngineMidiEvent::kDataSize)
- {
- midi.dataExt = data;
- std::memset(midi.data, 0, sizeof(uint8_t)*EngineMidiEvent::kDataSize);
- }
- else
- {
- midi.data[0] = midiStatus;
-
- uint8_t i=1;
- for (; i < midi.size; ++i)
- midi.data[i] = data[i];
- for (; i < EngineMidiEvent::kDataSize; ++i)
- midi.data[i] = 0;
-
- midi.dataExt = nullptr;
- }
- }
- }
-
- // -----------------------------------------------------------------------
- // Carla Engine port (Abstract)
-
- CarlaEnginePort::CarlaEnginePort(const CarlaEngine& engine, const bool isInput)
- : fEngine(engine),
- fIsInput(isInput)
- {
- carla_debug("CarlaEnginePort::CarlaEnginePort(%s)", bool2str(isInput));
- }
-
- CarlaEnginePort::~CarlaEnginePort()
- {
- carla_debug("CarlaEnginePort::~CarlaEnginePort()");
- }
-
- // -----------------------------------------------------------------------
- // Carla Engine Audio port
-
- CarlaEngineAudioPort::CarlaEngineAudioPort(const CarlaEngine& engine, const bool isInput)
- : CarlaEnginePort(engine, isInput),
- fBuffer(nullptr)
- {
- carla_debug("CarlaEngineAudioPort::CarlaEngineAudioPort(%s)", bool2str(isInput));
- }
-
- CarlaEngineAudioPort::~CarlaEngineAudioPort()
- {
- carla_debug("CarlaEngineAudioPort::~CarlaEngineAudioPort()");
- }
-
- void CarlaEngineAudioPort::initBuffer()
- {
- }
-
- // -----------------------------------------------------------------------
- // Carla Engine CV port
-
- CarlaEngineCVPort::CarlaEngineCVPort(const CarlaEngine& engine, const bool isInput)
- : CarlaEnginePort(engine, isInput),
- fBuffer(nullptr),
- fProcessMode(engine.getProccessMode())
- {
- carla_debug("CarlaEngineCVPort::CarlaEngineCVPort(%s)", bool2str(isInput));
-
- if (fProcessMode != ENGINE_PROCESS_MODE_SINGLE_CLIENT && fProcessMode != ENGINE_PROCESS_MODE_MULTIPLE_CLIENTS)
- fBuffer = new float[engine.getBufferSize()];
- }
-
- CarlaEngineCVPort::~CarlaEngineCVPort()
- {
- carla_debug("CarlaEngineCVPort::~CarlaEngineCVPort()");
-
- if (fProcessMode != ENGINE_PROCESS_MODE_SINGLE_CLIENT && fProcessMode != ENGINE_PROCESS_MODE_MULTIPLE_CLIENTS)
- {
- CARLA_SAFE_ASSERT_RETURN(fBuffer != nullptr,);
-
- delete[] fBuffer;
- fBuffer = nullptr;
- }
- }
-
- void CarlaEngineCVPort::initBuffer()
- {
- CARLA_SAFE_ASSERT_RETURN(fBuffer != nullptr,);
- CARLA_SAFE_ASSERT_RETURN(fProcessMode != ENGINE_PROCESS_MODE_SINGLE_CLIENT && fProcessMode != ENGINE_PROCESS_MODE_MULTIPLE_CLIENTS,);
-
- FLOAT_CLEAR(fBuffer, fEngine.getBufferSize());
- }
-
- void CarlaEngineCVPort::setBufferSize(const uint32_t bufferSize)
- {
- CARLA_SAFE_ASSERT_RETURN(fBuffer != nullptr,);
- CARLA_SAFE_ASSERT_RETURN(fProcessMode != ENGINE_PROCESS_MODE_SINGLE_CLIENT && fProcessMode != ENGINE_PROCESS_MODE_MULTIPLE_CLIENTS,);
-
- delete[] fBuffer;
- fBuffer = new float[bufferSize];
- }
-
- // -----------------------------------------------------------------------
- // Carla Engine Event port
-
- CarlaEngineEventPort::CarlaEngineEventPort(const CarlaEngine& engine, const bool isInput)
- : CarlaEnginePort(engine, isInput),
- fBuffer(nullptr),
- fProcessMode(engine.getProccessMode())
- {
- carla_debug("CarlaEngineEventPort::CarlaEngineEventPort(%s)", bool2str(isInput));
-
- if (fProcessMode == ENGINE_PROCESS_MODE_PATCHBAY)
- fBuffer = new EngineEvent[kEngineMaxInternalEventCount];
- }
-
- CarlaEngineEventPort::~CarlaEngineEventPort()
- {
- carla_debug("CarlaEngineEventPort::~CarlaEngineEventPort()");
-
- if (fProcessMode == ENGINE_PROCESS_MODE_PATCHBAY)
- {
- CARLA_SAFE_ASSERT_RETURN(fBuffer != nullptr,);
-
- delete[] fBuffer;
- fBuffer = nullptr;
- }
- }
-
- void CarlaEngineEventPort::initBuffer()
- {
- if (fProcessMode == ENGINE_PROCESS_MODE_CONTINUOUS_RACK || fProcessMode == ENGINE_PROCESS_MODE_BRIDGE)
- fBuffer = fEngine.getInternalEventBuffer(fIsInput);
- else if (fProcessMode == ENGINE_PROCESS_MODE_PATCHBAY && ! fIsInput)
- carla_zeroStruct<EngineEvent>(fBuffer, kEngineMaxInternalEventCount);
- }
-
- uint32_t CarlaEngineEventPort::getEventCount() const
- {
- CARLA_SAFE_ASSERT_RETURN(fIsInput, 0);
- CARLA_SAFE_ASSERT_RETURN(fBuffer != nullptr, 0);
- CARLA_SAFE_ASSERT_RETURN(fProcessMode != ENGINE_PROCESS_MODE_SINGLE_CLIENT && fProcessMode != ENGINE_PROCESS_MODE_MULTIPLE_CLIENTS, 0);
-
- uint32_t i=0;
-
- for (; i < kEngineMaxInternalEventCount; ++i)
- {
- if (fBuffer[i].type == kEngineEventTypeNull)
- break;
- }
-
- return i;
- }
-
- const EngineEvent& CarlaEngineEventPort::getEvent(const uint32_t index)
- {
- CARLA_SAFE_ASSERT_RETURN(fIsInput, kFallbackEngineEvent);
- CARLA_SAFE_ASSERT_RETURN(fBuffer != nullptr, kFallbackEngineEvent);
- CARLA_SAFE_ASSERT_RETURN(fProcessMode != ENGINE_PROCESS_MODE_SINGLE_CLIENT && fProcessMode != ENGINE_PROCESS_MODE_MULTIPLE_CLIENTS, kFallbackEngineEvent);
- CARLA_SAFE_ASSERT_RETURN(index < kEngineMaxInternalEventCount, kFallbackEngineEvent);
-
- return fBuffer[index];
- }
-
- const EngineEvent& CarlaEngineEventPort::getEventUnchecked(const uint32_t index)
- {
- return fBuffer[index];
- }
-
- bool CarlaEngineEventPort::writeControlEvent(const uint32_t time, const uint8_t channel, const EngineControlEventType type, const uint16_t param, const float value)
- {
- CARLA_SAFE_ASSERT_RETURN(! fIsInput, false);
- CARLA_SAFE_ASSERT_RETURN(fBuffer != nullptr, false);
- CARLA_SAFE_ASSERT_RETURN(fProcessMode != ENGINE_PROCESS_MODE_SINGLE_CLIENT && fProcessMode != ENGINE_PROCESS_MODE_MULTIPLE_CLIENTS, false);
- CARLA_SAFE_ASSERT_RETURN(type != kEngineControlEventTypeNull, false);
- CARLA_SAFE_ASSERT_RETURN(channel < MAX_MIDI_CHANNELS, false);
- CARLA_SAFE_ASSERT(value >= 0.0f && value <= 1.0f);
-
- if (type == kEngineControlEventTypeParameter)
- {
- CARLA_ASSERT(! MIDI_IS_CONTROL_BANK_SELECT(param));
- }
-
- const float fixedValue(carla_fixValue<float>(0.0f, 1.0f, value));
-
- for (uint32_t i=0; i < kEngineMaxInternalEventCount; ++i)
- {
- if (fBuffer[i].type != kEngineEventTypeNull)
- continue;
-
- EngineEvent& event(fBuffer[i]);
-
- event.type = kEngineEventTypeControl;
- event.time = time;
- event.channel = channel;
-
- event.ctrl.type = type;
- event.ctrl.param = param;
- event.ctrl.value = fixedValue;
-
- return true;
- }
-
- carla_stderr2("CarlaEngineEventPort::writeControlEvent() - buffer full");
- return false;
- }
-
- bool CarlaEngineEventPort::writeMidiEvent(const uint32_t time, const uint8_t channel, const uint8_t port, const uint8_t size, const uint8_t* const data)
- {
- CARLA_SAFE_ASSERT_RETURN(! fIsInput, false);
- CARLA_SAFE_ASSERT_RETURN(fBuffer != nullptr, false);
- CARLA_SAFE_ASSERT_RETURN(fProcessMode != ENGINE_PROCESS_MODE_SINGLE_CLIENT && fProcessMode != ENGINE_PROCESS_MODE_MULTIPLE_CLIENTS, false);
- CARLA_SAFE_ASSERT_RETURN(channel < MAX_MIDI_CHANNELS, false);
- CARLA_SAFE_ASSERT_RETURN(size > 0 && size <= EngineMidiEvent::kDataSize, false);
- CARLA_SAFE_ASSERT_RETURN(data != nullptr, false);
-
- for (uint32_t i=0; i < kEngineMaxInternalEventCount; ++i)
- {
- if (fBuffer[i].type != kEngineEventTypeNull)
- continue;
-
- EngineEvent& event(fBuffer[i]);
-
- event.type = kEngineEventTypeMidi;
- event.time = time;
- event.channel = channel;
-
- event.midi.port = port;
- event.midi.size = size;
-
- event.midi.data[0] = MIDI_GET_STATUS_FROM_DATA(data);
-
- uint8_t j=1;
- for (; j < size; ++j)
- event.midi.data[j] = data[j];
- for (; j < EngineMidiEvent::kDataSize; ++j)
- event.midi.data[j] = 0;
-
- return true;
- }
-
- carla_stderr2("CarlaEngineEventPort::writeMidiEvent() - buffer full");
- return false;
- }
-
- // -----------------------------------------------------------------------
- // Carla Engine client (Abstract)
-
- CarlaEngineClient::CarlaEngineClient(const CarlaEngine& engine)
- : fEngine(engine),
- fActive(false),
- fLatency(0)
- {
- carla_debug("CarlaEngineClient::CarlaEngineClient()");
- }
-
- CarlaEngineClient::~CarlaEngineClient()
- {
- CARLA_ASSERT(! fActive);
- carla_debug("CarlaEngineClient::~CarlaEngineClient()");
- }
-
- void CarlaEngineClient::activate()
- {
- CARLA_ASSERT(! fActive);
- carla_debug("CarlaEngineClient::activate()");
-
- fActive = true;
- }
-
- void CarlaEngineClient::deactivate()
- {
- CARLA_ASSERT(fActive);
- carla_debug("CarlaEngineClient::deactivate()");
-
- fActive = false;
- }
-
- bool CarlaEngineClient::isActive() const noexcept
- {
- return fActive;
- }
-
- bool CarlaEngineClient::isOk() const noexcept
- {
- return true;
- }
-
- uint32_t CarlaEngineClient::getLatency() const noexcept
- {
- return fLatency;
- }
-
- void CarlaEngineClient::setLatency(const uint32_t samples) noexcept
- {
- fLatency = samples;
- }
-
- CarlaEnginePort* CarlaEngineClient::addPort(const EnginePortType portType, const char* const name, const bool isInput)
- {
- CARLA_SAFE_ASSERT_RETURN(name != nullptr && name[0] != '\0', nullptr);
- carla_debug("CarlaEngineClient::addPort(%i:%s, \"%s\", %s)", portType, EnginePortType2Str(portType), name, bool2str(isInput));
-
- switch (portType)
- {
- case kEnginePortTypeNull:
- break;
- case kEnginePortTypeAudio:
- return new CarlaEngineAudioPort(fEngine, isInput);
- case kEnginePortTypeCV:
- return new CarlaEngineCVPort(fEngine, isInput);
- case kEnginePortTypeEvent:
- return new CarlaEngineEventPort(fEngine, isInput);
- }
-
- carla_stderr("CarlaEngineClient::addPort(%i, \"%s\", %s) - invalid type", portType, name, bool2str(isInput));
- return nullptr;
- }
-
- // -----------------------------------------------------------------------
- // Carla Engine
-
- CarlaEngine::CarlaEngine()
- : pData(new CarlaEngineProtectedData(this))
- {
- carla_debug("CarlaEngine::CarlaEngine()");
- }
-
- CarlaEngine::~CarlaEngine()
- {
- carla_debug("CarlaEngine::~CarlaEngine()");
-
- delete pData;
- }
-
- // -----------------------------------------------------------------------
- // Static calls
-
- unsigned int CarlaEngine::getDriverCount()
- {
- carla_debug("CarlaEngine::getDriverCount()");
-
- unsigned int count = 1; // JACK
-
- #ifndef BUILD_BRIDGE
- count += getRtAudioApiCount();
- # ifdef HAVE_JUCE
- count += getJuceApiCount();
- # endif
- #endif
-
- return count;
- }
-
- const char* CarlaEngine::getDriverName(const unsigned int index)
- {
- carla_debug("CarlaEngine::getDriverName(%i)", index);
-
- if (index == 0)
- return "JACK";
-
- #ifndef BUILD_BRIDGE
- const unsigned int rtAudioIndex(index-1);
-
- if (rtAudioIndex < getRtAudioApiCount())
- return getRtAudioApiName(rtAudioIndex);
-
- # ifdef HAVE_JUCE
- const unsigned int juceIndex(index-rtAudioIndex-1);
-
- if (juceIndex < getJuceApiCount())
- return getJuceApiName(juceIndex);
- # endif
- #endif
-
- carla_stderr("CarlaEngine::getDriverName(%i) - invalid index", index);
- return nullptr;
- }
-
- const char* const* CarlaEngine::getDriverDeviceNames(const unsigned int index)
- {
- carla_debug("CarlaEngine::getDriverDeviceNames(%i)", index);
-
- if (index == 0) // JACK
- {
- static const char* ret[3] = { "Auto-Connect OFF", "Auto-Connect ON", nullptr };
- return ret;
- }
-
- #ifndef BUILD_BRIDGE
- const unsigned int rtAudioIndex(index-1);
-
- if (rtAudioIndex < getRtAudioApiCount())
- return getRtAudioApiDeviceNames(rtAudioIndex);
-
- # ifdef HAVE_JUCE
- const unsigned int juceIndex(index-rtAudioIndex-1);
-
- if (juceIndex < getJuceApiCount())
- return getJuceApiDeviceNames(juceIndex);
- # endif
- #endif
-
- carla_stderr("CarlaEngine::getDriverDeviceNames(%i) - invalid index", index);
- return nullptr;
- }
-
- const EngineDriverDeviceInfo* CarlaEngine::getDriverDeviceInfo(const unsigned int index, const char* const deviceName)
- {
- carla_debug("CarlaEngine::getDriverDeviceInfo(%i, \"%s\")", index, deviceName);
-
- if (index == 0) // JACK
- {
- static uint32_t bufSizes[11] = { 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 0 };
- static EngineDriverDeviceInfo devInfo;
- devInfo.hints = ENGINE_DRIVER_DEVICE_VARIABLE_BUFFER_SIZE;
- devInfo.bufferSizes = bufSizes;
- devInfo.sampleRates = nullptr;
- return &devInfo;
- }
-
- #ifndef BUILD_BRIDGE
- const unsigned int rtAudioIndex(index-1);
-
- if (rtAudioIndex < getRtAudioApiCount())
- return getRtAudioDeviceInfo(rtAudioIndex, deviceName);
-
- # ifdef HAVE_JUCE
- const unsigned int juceIndex(index-rtAudioIndex-1);
-
- if (juceIndex < getJuceApiCount())
- return getJuceDeviceInfo(juceIndex, deviceName);
- # endif
- #endif
-
- carla_stderr("CarlaEngine::getDriverDeviceNames(%i, \"%s\") - invalid index", index, deviceName);
- return nullptr;
- }
-
- CarlaEngine* CarlaEngine::newDriverByName(const char* const driverName)
- {
- CARLA_SAFE_ASSERT_RETURN(driverName != nullptr && driverName[0] != '\0', nullptr);
- carla_debug("CarlaEngine::newDriverByName(\"%s\")", driverName);
-
- if (std::strcmp(driverName, "JACK") == 0)
- return newJack();
-
- #ifndef BUILD_BRIDGE
- // common
- if (std::strncmp(driverName, "JACK ", 5) == 0)
- return newRtAudio(AUDIO_API_JACK);
-
- // linux
- if (std::strcmp(driverName, "ALSA") == 0)
- return newRtAudio(AUDIO_API_ALSA);
- if (std::strcmp(driverName, "OSS") == 0)
- return newRtAudio(AUDIO_API_OSS);
- if (std::strcmp(driverName, "PulseAudio") == 0)
- return newRtAudio(AUDIO_API_PULSE);
-
- // macos
- if (std::strcmp(driverName, "CoreAudio") == 0)
- return newRtAudio(AUDIO_API_CORE);
-
- // windows
- if (std::strcmp(driverName, "ASIO") == 0)
- return newRtAudio(AUDIO_API_ASIO);
- if (std::strcmp(driverName, "DirectSound") == 0)
- return newRtAudio(AUDIO_API_DS);
- #endif
-
- carla_stderr("CarlaEngine::newDriverByName(\"%s\") - invalid driver name", driverName);
- return nullptr;
- }
-
- // -----------------------------------------------------------------------
- // Maximum values
-
- unsigned int CarlaEngine::getMaxClientNameSize() const noexcept
- {
- return STR_MAX/2;
- }
-
- unsigned int CarlaEngine::getMaxPortNameSize() const noexcept
- {
- return STR_MAX;
- }
-
- unsigned int CarlaEngine::getCurrentPluginCount() const noexcept
- {
- return pData->curPluginCount;
- }
-
- unsigned int CarlaEngine::getMaxPluginNumber() const noexcept
- {
- return pData->maxPluginNumber;
- }
-
- // -----------------------------------------------------------------------
- // Virtual, per-engine type calls
-
- bool CarlaEngine::init(const char* const clientName)
- {
- CARLA_SAFE_ASSERT_RETURN_ERR(pData->name.isEmpty(), "Invalid engine internal data (err #1)");
- CARLA_SAFE_ASSERT_RETURN_ERR(pData->oscData == nullptr, "Invalid engine internal data (err #2)");
- CARLA_SAFE_ASSERT_RETURN_ERR(pData->plugins == nullptr, "Invalid engine internal data (err #3)");
- CARLA_SAFE_ASSERT_RETURN_ERR(pData->bufEvents.in == nullptr, "Invalid engine internal data (err #4)");
- CARLA_SAFE_ASSERT_RETURN_ERR(pData->bufEvents.out == nullptr, "Invalid engine internal data (err #5)");
- CARLA_SAFE_ASSERT_RETURN_ERR(clientName != nullptr && clientName[0] != '\0', "Invalid client name");
- carla_debug("CarlaEngine::init(\"%s\")", clientName);
-
- pData->aboutToClose = false;
- pData->curPluginCount = 0;
- pData->maxPluginNumber = 0;
- pData->nextPluginId = 0;
-
- switch (pData->options.processMode)
- {
- case ENGINE_PROCESS_MODE_SINGLE_CLIENT:
- case ENGINE_PROCESS_MODE_MULTIPLE_CLIENTS:
- pData->maxPluginNumber = MAX_DEFAULT_PLUGINS;
- break;
-
- case ENGINE_PROCESS_MODE_CONTINUOUS_RACK:
- pData->maxPluginNumber = MAX_RACK_PLUGINS;
- pData->bufEvents.in = new EngineEvent[kEngineMaxInternalEventCount];
- pData->bufEvents.out = new EngineEvent[kEngineMaxInternalEventCount];
- break;
-
- case ENGINE_PROCESS_MODE_PATCHBAY:
- pData->maxPluginNumber = MAX_PATCHBAY_PLUGINS;
- break;
-
- case ENGINE_PROCESS_MODE_BRIDGE:
- pData->maxPluginNumber = 1;
- pData->bufEvents.in = new EngineEvent[kEngineMaxInternalEventCount];
- pData->bufEvents.out = new EngineEvent[kEngineMaxInternalEventCount];
- break;
- }
-
- CARLA_SAFE_ASSERT_RETURN_ERR(pData->maxPluginNumber != 0, "Invalid engine process mode");
-
- pData->nextPluginId = pData->maxPluginNumber;
-
- pData->name = clientName;
- pData->name.toBasic();
-
- pData->timeInfo.clear();
-
- pData->plugins = new EnginePluginData[pData->maxPluginNumber];
-
- for (uint i=0; i < pData->maxPluginNumber; ++i)
- pData->plugins[i].clear();
-
- pData->osc.init(clientName);
- #ifndef BUILD_BRIDGE
- pData->oscData = pData->osc.getControlData();
- #endif
-
- pData->nextAction.ready();
- pData->thread.start();
-
- callback(ENGINE_CALLBACK_ENGINE_STARTED, 0, 0, 0, 0.0f, getCurrentDriverName());
-
- return true;
- }
-
- bool CarlaEngine::close()
- {
- CARLA_SAFE_ASSERT_RETURN_ERR(pData->name.isNotEmpty(), "Invalid engine internal data (err #6)");
- CARLA_SAFE_ASSERT_RETURN_ERR(pData->plugins != nullptr, "Invalid engine internal data (err #7)");
- CARLA_SAFE_ASSERT_RETURN_ERR(pData->nextPluginId == pData->maxPluginNumber, "Invalid engine internal data (err #8)");
- CARLA_SAFE_ASSERT_RETURN_ERR(pData->nextAction.opcode == kEnginePostActionNull, "Invalid engine internal data (err #9)");
- carla_debug("CarlaEngine::close()");
-
- pData->thread.stop(500);
- pData->nextAction.ready();
-
- #ifndef BUILD_BRIDGE
- oscSend_control_exit();
- #endif
- pData->osc.close();
- pData->oscData = nullptr;
-
- pData->aboutToClose = true;
- pData->curPluginCount = 0;
- pData->maxPluginNumber = 0;
- pData->nextPluginId = 0;
-
- if (pData->plugins != nullptr)
- {
- delete[] pData->plugins;
- pData->plugins = nullptr;
- }
-
- if (pData->bufEvents.in != nullptr)
- {
- delete[] pData->bufEvents.in;
- pData->bufEvents.in = nullptr;
- }
-
- if (pData->bufEvents.out != nullptr)
- {
- delete[] pData->bufEvents.out;
- pData->bufEvents.out = nullptr;
- }
-
- pData->name.clear();
-
- callback(ENGINE_CALLBACK_ENGINE_STOPPED, 0, 0, 0, 0.0f, nullptr);
-
- return true;
- }
-
- void CarlaEngine::idle()
- {
- CARLA_ASSERT(pData->nextAction.opcode == kEnginePostActionNull); // TESTING, remove later
- CARLA_ASSERT(pData->nextPluginId == pData->maxPluginNumber); // TESTING, remove later
- CARLA_ASSERT(pData->plugins != nullptr); // this one too maybe
-
- for (unsigned int i=0; i < pData->curPluginCount; ++i)
- {
- CarlaPlugin* const plugin(pData->plugins[i].plugin);
-
- if (plugin != nullptr && plugin->isEnabled())
- plugin->idle();
- }
- }
-
- CarlaEngineClient* CarlaEngine::addClient(CarlaPlugin* const)
- {
- return new CarlaEngineClient(*this);
- }
-
- // -----------------------------------------------------------------------
- // Plugin management
-
- 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)
- {
- CARLA_SAFE_ASSERT_RETURN_ERR(pData->plugins != nullptr, "Invalid engine internal data (err #10)");
- CARLA_SAFE_ASSERT_RETURN_ERR(pData->nextPluginId <= pData->maxPluginNumber, "Invalid engine internal data (err #11)");
- CARLA_SAFE_ASSERT_RETURN_ERR(pData->nextAction.opcode == kEnginePostActionNull, "Invalid engine internal data (err #12)");
- CARLA_SAFE_ASSERT_RETURN_ERR(btype != BINARY_NONE, "Invalid plugin params (err #1)");
- CARLA_SAFE_ASSERT_RETURN_ERR(ptype != PLUGIN_NONE, "Invalid plugin params (err #2)");
- CARLA_SAFE_ASSERT_RETURN_ERR((filename != nullptr && filename[0] != '\0') || (label != nullptr && label[0] != '\0'), "Invalid plugin params (err #3)");
- carla_debug("CarlaEngine::addPlugin(%i:%s, %i:%s, \"%s\", \"%s\", \"%s\", %p)", btype, BinaryType2Str(btype), ptype, PluginType2Str(ptype), filename, name, label, extra);
-
- unsigned int id;
- CarlaPlugin* oldPlugin = nullptr;
-
- if (pData->nextPluginId < pData->curPluginCount)
- {
- id = pData->nextPluginId;
- pData->nextPluginId = pData->maxPluginNumber;
-
- oldPlugin = pData->plugins[id].plugin;
-
- CARLA_SAFE_ASSERT_RETURN_ERR(oldPlugin != nullptr, "Invalid replace plugin Id");
- }
- else
- {
- id = pData->curPluginCount;
-
- if (id == pData->maxPluginNumber)
- {
- setLastError("Maximum number of plugins reached");
- return false;
- }
-
- CARLA_SAFE_ASSERT_RETURN_ERR(pData->plugins[id].plugin == nullptr, "Invalid engine internal data (err #13)");
- }
-
- CarlaPlugin::Initializer init = {
- this,
- id,
- filename,
- name,
- label
- };
-
- CarlaPlugin* plugin = nullptr;
-
- #if 0 //ndef BUILD_BRIDGE
- const char* bridgeBinary;
-
- switch (btype)
- {
- case BINARY_POSIX32:
- bridgeBinary = pData->options.bridge_posix32.isNotEmpty() ? (const char*)pData->options.bridge_posix32 : nullptr;
- break;
- case BINARY_POSIX64:
- bridgeBinary = pData->options.bridge_posix64.isNotEmpty() ? (const char*)pData->options.bridge_posix64 : nullptr;
- break;
- case BINARY_WIN32:
- bridgeBinary = pData->options.bridge_win32.isNotEmpty() ? (const char*)pData->options.bridge_win32 : nullptr;
- break;
- case BINARY_WIN64:
- bridgeBinary = pData->options.bridge_win64.isNotEmpty() ? (const char*)pData->options.bridge_win64 : nullptr;
- break;
- default:
- bridgeBinary = nullptr;
- break;
- }
-
- # ifndef CARLA_OS_WIN
- if (btype == BINARY_NATIVE && pData->options.bridge_native.isNotEmpty())
- bridgeBinary = (const char*)pData->options.bridge_native;
- # endif
-
- if (btype != BINARY_NATIVE || (pData->options.preferPluginBridges && bridgeBinary != nullptr))
- {
- if (bridgeBinary != nullptr)
- {
- plugin = CarlaPlugin::newBridge(init, btype, ptype, bridgeBinary);
- }
- # ifdef CARLA_OS_LINUX
- else if (btype == BINARY_WIN32)
- {
- // fallback to dssi-vst
- QFileInfo fileInfo(filename);
-
- CarlaString label2(fileInfo.fileName().toUtf8().constData());
- label2.replace(' ', '*');
-
- CarlaPlugin::Initializer init2 = {
- this,
- id,
- "/usr/lib/dssi/dssi-vst.so",
- name,
- (const char*)label2
- };
-
- char* const oldVstPath(getenv("VST_PATH"));
- carla_setenv("VST_PATH", fileInfo.absoluteDir().absolutePath().toUtf8().constData());
-
- plugin = CarlaPlugin::newDSSI(init2);
-
- if (oldVstPath != nullptr)
- carla_setenv("VST_PATH", oldVstPath);
- }
- # endif
- else
- {
- setLastError("This Carla build cannot handle this binary");
- return false;
- }
- }
- else
- #endif // BUILD_BRIDGE
- {
- setLastError("Invalid or unsupported plugin type");
-
- switch (ptype)
- {
- case PLUGIN_NONE:
- break;
-
- case PLUGIN_INTERNAL:
- plugin = CarlaPlugin::newNative(init);
- break;
-
- case PLUGIN_LADSPA:
- plugin = CarlaPlugin::newLADSPA(init, (const LADSPA_RDF_Descriptor*)extra);
- break;
-
- case PLUGIN_DSSI:
- plugin = CarlaPlugin::newDSSI(init);
- break;
-
- case PLUGIN_LV2:
- plugin = CarlaPlugin::newLV2(init);
- break;
-
- case PLUGIN_VST:
- plugin = CarlaPlugin::newVST(init);
- break;
-
- case PLUGIN_AU:
- //plugin = CarlaPlugin::newAU(init);
- break;
-
- case PLUGIN_CSOUND:
- //plugin = CarlaPlugin::newCSOUND(init);
- break;
-
- case PLUGIN_GIG:
- plugin = CarlaPlugin::newGIG(init, (extra != nullptr));
- break;
-
- case PLUGIN_SF2:
- plugin = CarlaPlugin::newSF2(init, (extra != nullptr));
- break;
-
- case PLUGIN_SFZ:
- plugin = CarlaPlugin::newSFZ(init, (extra != nullptr));
- break;
- }
- }
-
- if (plugin == nullptr)
- return false;
-
- plugin->registerToOscClient();
-
- EnginePluginData& pluginData(pData->plugins[id]);
- pluginData.plugin = plugin;
- pluginData.insPeak[0] = 0.0f;
- pluginData.insPeak[1] = 0.0f;
- pluginData.outsPeak[0] = 0.0f;
- pluginData.outsPeak[1] = 0.0f;
-
- if (oldPlugin != nullptr)
- {
- delete oldPlugin;
- callback(ENGINE_CALLBACK_RELOAD_ALL, id, 0, 0, 0.0f, plugin->getName());
- }
- else
- {
- ++pData->curPluginCount;
- callback(ENGINE_CALLBACK_PLUGIN_ADDED, id, 0, 0, 0.0f, plugin->getName());
- }
-
- return true;
- }
-
- bool CarlaEngine::removePlugin(const unsigned int id)
- {
- CARLA_SAFE_ASSERT_RETURN_ERR(pData->plugins != nullptr, "Invalid engine internal data (err #14)");
- CARLA_SAFE_ASSERT_RETURN_ERR(pData->curPluginCount != 0, "Invalid engine internal data (err #15)");
- CARLA_SAFE_ASSERT_RETURN_ERR(pData->nextAction.opcode == kEnginePostActionNull, "Invalid engine internal data (err #16)");
- CARLA_SAFE_ASSERT_RETURN_ERR(id < pData->curPluginCount, "Invalid plugin Id (err #1)");
- carla_debug("CarlaEngine::removePlugin(%i)", id);
-
- CarlaPlugin* const plugin(pData->plugins[id].plugin);
-
- CARLA_SAFE_ASSERT_RETURN_ERR(plugin != nullptr, "Could not find plugin to remove");
- CARLA_SAFE_ASSERT_RETURN_ERR(plugin->getId() == id, "Invalid engine internal data (err #17)");
-
- pData->thread.stop(500);
-
- const bool lockWait(isRunning() && pData->options.processMode != ENGINE_PROCESS_MODE_MULTIPLE_CLIENTS);
- const CarlaEngineProtectedData::ScopedActionLock sal(pData, kEnginePostActionRemovePlugin, id, 0, lockWait);
-
- #ifndef BUILD_BRIDGE
- if (isOscControlRegistered())
- oscSend_control_remove_plugin(id);
- #endif
-
- delete plugin;
-
- if (isRunning() && ! pData->aboutToClose)
- pData->thread.start();
-
- callback(ENGINE_CALLBACK_PLUGIN_REMOVED, id, 0, 0, 0.0f, nullptr);
- return true;
- }
-
- bool CarlaEngine::removeAllPlugins()
- {
- CARLA_SAFE_ASSERT_RETURN_ERR(pData->plugins != nullptr, "Invalid engine internal data (err #18)");
- CARLA_SAFE_ASSERT_RETURN_ERR(pData->nextPluginId == pData->maxPluginNumber, "Invalid engine internal data (err #19)");
- CARLA_SAFE_ASSERT_RETURN_ERR(pData->nextAction.opcode == kEnginePostActionNull, "Invalid engine internal data (err #20)");
- carla_debug("CarlaEngine::removeAllPlugins()");
-
- if (pData->curPluginCount == 0)
- return true;
-
- pData->thread.stop(500);
-
- const bool lockWait(isRunning());
- const CarlaEngineProtectedData::ScopedActionLock sal(pData, kEnginePostActionZeroCount, 0, 0, lockWait);
-
- for (unsigned int i=0; i < pData->maxPluginNumber; ++i)
- {
- EnginePluginData& pluginData(pData->plugins[i]);
-
- if (pluginData.plugin != nullptr)
- {
- delete pluginData.plugin;
- pluginData.plugin = nullptr;
- }
-
- pluginData.insPeak[0] = 0.0f;
- pluginData.insPeak[1] = 0.0f;
- pluginData.outsPeak[0] = 0.0f;
- pluginData.outsPeak[1] = 0.0f;
- }
-
- if (isRunning() && ! pData->aboutToClose)
- pData->thread.start();
-
- return true;
- }
-
- const char* CarlaEngine::renamePlugin(const unsigned int id, const char* const newName)
- {
- CARLA_SAFE_ASSERT_RETURN_ERRN(pData->plugins != nullptr, "Invalid engine internal data (err #21)");
- CARLA_SAFE_ASSERT_RETURN_ERRN(pData->curPluginCount != 0, "Invalid engine internal data (err #22)");
- CARLA_SAFE_ASSERT_RETURN_ERRN(pData->nextAction.opcode == kEnginePostActionNull, "Invalid engine internal data (err #23)");
- CARLA_SAFE_ASSERT_RETURN_ERRN(id < pData->curPluginCount, "Invalid plugin Id (err #2)");
- CARLA_SAFE_ASSERT_RETURN_ERRN(newName != nullptr && newName[0] != '\0', "Invalid plugin name");
- carla_debug("CarlaEngine::renamePlugin(%i, \"%s\")", id, newName);
-
- CarlaPlugin* const plugin(pData->plugins[id].plugin);
-
- CARLA_SAFE_ASSERT_RETURN_ERRN(plugin != nullptr, "Could not find plugin to rename");
- CARLA_SAFE_ASSERT_RETURN_ERRN(plugin->getId() == id, "Invalid engine internal data (err #24)");
-
- if (const char* const name = getUniquePluginName(newName))
- {
- plugin->setName(name);
- return name;
- }
-
- setLastError("Unable to get new unique plugin name");
- return nullptr;
- }
-
- bool CarlaEngine::clonePlugin(const unsigned int id)
- {
- CARLA_SAFE_ASSERT_RETURN_ERR(pData->plugins != nullptr, "Invalid engine internal data (err #25)");
- CARLA_SAFE_ASSERT_RETURN_ERR(pData->curPluginCount != 0, "Invalid engine internal data (err #26)");
- CARLA_SAFE_ASSERT_RETURN_ERR(pData->nextAction.opcode == kEnginePostActionNull, "Invalid engine internal data (err #27)");
- CARLA_SAFE_ASSERT_RETURN_ERR(id < pData->curPluginCount, "Invalid plugin Id (err #3)");
- carla_debug("CarlaEngine::clonePlugin(%i)", id);
-
- CarlaPlugin* const plugin(pData->plugins[id].plugin);
-
- CARLA_SAFE_ASSERT_RETURN_ERR(plugin != nullptr, "Could not find plugin to clone");
- CARLA_SAFE_ASSERT_RETURN_ERR(plugin->getId() == id, "Invalid engine internal data (err #28)");
-
- char label[STR_MAX+1];
- carla_zeroChar(label, STR_MAX+1);
- plugin->getLabel(label);
-
- const unsigned int pluginCountBefore(pData->curPluginCount);
-
- if (! addPlugin(plugin->getBinaryType(), plugin->getType(), plugin->getFilename(), plugin->getName(), label, plugin->getExtraStuff()))
- return false;
-
- CARLA_ASSERT(pluginCountBefore+1 == pData->curPluginCount);
-
- if (CarlaPlugin* const newPlugin = pData->plugins[pluginCountBefore].plugin)
- newPlugin->loadSaveState(plugin->getSaveState());
-
- return true;
- }
-
- bool CarlaEngine::replacePlugin(const unsigned int id)
- {
- CARLA_SAFE_ASSERT_RETURN_ERR(pData->plugins != nullptr, "Invalid engine internal data (err #29)");
- CARLA_SAFE_ASSERT_RETURN_ERR(pData->curPluginCount != 0, "Invalid engine internal data (err #30)");
- CARLA_SAFE_ASSERT_RETURN_ERR(pData->nextAction.opcode == kEnginePostActionNull, "Invalid engine internal data (err #31)");
- CARLA_SAFE_ASSERT_RETURN_ERR(id < pData->curPluginCount, "Invalid plugin Id (err #4)");
- carla_debug("CarlaEngine::replacePlugin(%i)", id);
-
- CarlaPlugin* const plugin(pData->plugins[id].plugin);
-
- CARLA_SAFE_ASSERT_RETURN_ERR(plugin != nullptr, "Could not find plugin to replace");
- CARLA_SAFE_ASSERT_RETURN_ERR(plugin->getId() == id, "Invalid engine internal data (err #32)");
-
- pData->nextPluginId = id;
-
- return true;
- }
-
- bool CarlaEngine::switchPlugins(const unsigned int idA, const unsigned int idB)
- {
- CARLA_SAFE_ASSERT_RETURN_ERR(pData->plugins != nullptr, "Invalid engine internal data (err #33)");
- CARLA_SAFE_ASSERT_RETURN_ERR(pData->curPluginCount >= 2, "Invalid engine internal data (err #34)");
- CARLA_SAFE_ASSERT_RETURN_ERR(pData->nextAction.opcode == kEnginePostActionNull, "Invalid engine internal data (err #35)");
- CARLA_SAFE_ASSERT_RETURN_ERR(idA != idB, "Invalid operation, cannot switch plugin with itself");
- CARLA_SAFE_ASSERT_RETURN_ERR(idA < pData->curPluginCount, "Invalid plugin Id (err #5)");
- CARLA_SAFE_ASSERT_RETURN_ERR(idB < pData->curPluginCount, "Invalid plugin Id (err #6)");
- carla_debug("CarlaEngine::switchPlugins(%i)", idA, idB);
-
- CarlaPlugin* const pluginA(pData->plugins[idA].plugin);
- CarlaPlugin* const pluginB(pData->plugins[idB].plugin);
-
- CARLA_SAFE_ASSERT_RETURN_ERR(pluginA != nullptr, "Could not find plugin to switch (err #1)");
- CARLA_SAFE_ASSERT_RETURN_ERR(pluginA != nullptr, "Could not find plugin to switch (err #2)");
- CARLA_SAFE_ASSERT_RETURN_ERR(pluginA->getId() == idA, "Invalid engine internal data (err #36)");
- CARLA_SAFE_ASSERT_RETURN_ERR(pluginB->getId() == idB, "Invalid engine internal data (err #37)");
-
- pData->thread.stop(500);
-
- const bool lockWait(isRunning() && pData->options.processMode != ENGINE_PROCESS_MODE_MULTIPLE_CLIENTS);
- const CarlaEngineProtectedData::ScopedActionLock sal(pData, kEnginePostActionSwitchPlugins, idA, idB, lockWait);
-
- #ifndef BUILD_BRIDGE // TODO
- //if (isOscControlRegistered())
- // oscSend_control_switch_plugins(idA, idB);
- #endif
-
- if (isRunning() && ! pData->aboutToClose)
- pData->thread.start();
-
- return true;
- }
-
- CarlaPlugin* CarlaEngine::getPlugin(const unsigned int id) const
- {
- CARLA_SAFE_ASSERT_RETURN_ERRN(pData->plugins != nullptr, "Invalid engine internal data (err #38)");
- CARLA_SAFE_ASSERT_RETURN_ERRN(pData->curPluginCount != 0, "Invalid engine internal data (err #39)");
- CARLA_SAFE_ASSERT_RETURN_ERRN(pData->nextAction.opcode == kEnginePostActionNull, "Invalid engine internal data (err #40)");
- CARLA_SAFE_ASSERT_RETURN_ERRN(id < pData->curPluginCount, "Invalid plugin Id (err #7)");
- carla_debug("CarlaEngine::getPlugin(%i) [count:%i]", id, pData->curPluginCount);
-
- return pData->plugins[id].plugin;
- }
-
- CarlaPlugin* CarlaEngine::getPluginUnchecked(const unsigned int id) const noexcept
- {
- return pData->plugins[id].plugin;
- }
-
- const char* CarlaEngine::getUniquePluginName(const char* const name) const
- {
- CARLA_SAFE_ASSERT_RETURN(pData->plugins != nullptr, nullptr);
- CARLA_SAFE_ASSERT_RETURN(pData->maxPluginNumber != 0, nullptr);
- CARLA_SAFE_ASSERT_RETURN(pData->nextAction.opcode == kEnginePostActionNull, nullptr);
- CARLA_SAFE_ASSERT_RETURN(name != nullptr && name[0] != '\0', nullptr);
- carla_debug("CarlaEngine::getUniquePluginName(\"%s\")", name);
-
- CarlaString sname;
- sname = name;
-
- if (sname.isEmpty())
- {
- sname = "(No name)";
- return sname.dup();
- }
-
- sname.truncate(getMaxClientNameSize()-5-1); // 5 = strlen(" (10)")
- sname.replace(':', '.'); // ':' is used in JACK1 to split client/port names
-
- for (unsigned short i=0; i < pData->curPluginCount; ++i)
- {
- CARLA_SAFE_ASSERT_BREAK(pData->plugins[i].plugin != nullptr);
-
- // Check if unique name doesn't exist
- if (const char* const pluginName = pData->plugins[i].plugin->getName())
- {
- if (sname != pluginName)
- continue;
- }
-
- // Check if string has already been modified
- {
- const size_t len(sname.length());
-
- // 1 digit, ex: " (2)"
- if (sname[len-4] == ' ' && sname[len-3] == '(' && sname.isDigit(len-2) && sname[len-1] == ')')
- {
- int number = sname[len-2] - '0';
-
- if (number == 9)
- {
- // next number is 10, 2 digits
- sname.truncate(len-4);
- sname += " (10)";
- //sname.replace(" (9)", " (10)");
- }
- else
- sname[len-2] = char('0' + number + 1);
-
- continue;
- }
-
- // 2 digits, ex: " (11)"
- if (sname[len-5] == ' ' && sname[len-4] == '(' && sname.isDigit(len-3) && sname.isDigit(len-2) && sname[len-1] == ')')
- {
- char n2 = sname[len-2];
- char n3 = sname[len-3];
-
- if (n2 == '9')
- {
- n2 = '0';
- n3 = static_cast<char>(n3 + 1);
- }
- else
- n2 = static_cast<char>(n2 + 1);
-
- sname[len-2] = n2;
- sname[len-3] = n3;
-
- continue;
- }
- }
-
- // Modify string if not
- sname += " (2)";
- }
-
- return sname.dup();
- }
-
- // -----------------------------------------------------------------------
- // Project management
-
- bool CarlaEngine::loadFile(const char* const filename)
- {
- CARLA_SAFE_ASSERT_RETURN_ERR(filename != nullptr && filename[0] != '\0', "Invalid filename (err #1)");
- carla_debug("CarlaEngine::loadFile(\"%s\")", filename);
-
- QFileInfo fileInfo(filename);
-
- if (! fileInfo.exists())
- {
- setLastError("File does not exist");
- return false;
- }
-
- if (! fileInfo.isFile())
- {
- setLastError("Not a file");
- return false;
- }
-
- if (! fileInfo.isReadable())
- {
- setLastError("File is not readable");
- return false;
- }
-
- CarlaString baseName(fileInfo.baseName().toUtf8().constData());
- CarlaString extension(fileInfo.suffix().toLower().toUtf8().constData());
- extension.toLower();
-
- // -------------------------------------------------------------------
-
- if (extension == "carxp" || extension == "carxs")
- return loadProject(filename);
-
- // -------------------------------------------------------------------
-
- if (extension == "csd")
- return addPlugin(PLUGIN_CSOUND, filename, baseName, baseName);
-
- if (extension == "gig")
- return addPlugin(PLUGIN_GIG, filename, baseName, baseName);
-
- if (extension == "sf2")
- return addPlugin(PLUGIN_SF2, filename, baseName, baseName);
-
- if (extension == "sfz")
- return addPlugin(PLUGIN_SFZ, filename, baseName, baseName);
-
- // -------------------------------------------------------------------
-
- if (extension == "aiff" || extension == "flac" || extension == "oga" || extension == "ogg" || extension == "w64" || extension == "wav")
- {
- #ifdef WANT_AUDIOFILE
- if (addPlugin(PLUGIN_INTERNAL, nullptr, baseName, "audiofile"))
- {
- if (CarlaPlugin* const plugin = getPlugin(pData->curPluginCount-1))
- plugin->setCustomData(CUSTOM_DATA_TYPE_STRING, "file", filename, true);
- return true;
- }
- return false;
- #else
- setLastError("This Carla build does not have Audio file support");
- return false;
- #endif
- }
-
- if (extension == "3g2" || extension == "3gp" || extension == "aac" || extension == "ac3" || extension == "amr" || extension == "ape" ||
- extension == "mp2" || extension == "mp3" || extension == "mpc" || extension == "wma")
- {
- #ifdef WANT_AUDIOFILE
- # ifdef HAVE_FFMPEG
- if (addPlugin(PLUGIN_INTERNAL, nullptr, baseName, "audiofile"))
- {
- if (CarlaPlugin* const plugin = getPlugin(pData->curPluginCount-1))
- plugin->setCustomData(CUSTOM_DATA_TYPE_STRING, "file", filename, true);
- return true;
- }
- return false;
- # else
- setLastError("This Carla build has Audio file support, but not libav/ffmpeg");
- return false;
- # endif
- #else
- setLastError("This Carla build does not have Audio file support");
- return false;
- #endif
- }
-
- // -------------------------------------------------------------------
-
- if (extension == "mid" || extension == "midi")
- {
- #ifdef WANT_MIDIFILE
- if (addPlugin(PLUGIN_INTERNAL, nullptr, baseName, "midifile"))
- {
- if (CarlaPlugin* const plugin = getPlugin(pData->curPluginCount-1))
- plugin->setCustomData(CUSTOM_DATA_TYPE_STRING, "file", filename, true);
- return true;
- }
- return false;
- #else
- setLastError("This Carla build does not have MIDI file support");
- return false;
- #endif
- }
-
- // -------------------------------------------------------------------
- // ZynAddSubFX
-
- if (extension == "xmz" || extension == "xiz")
- {
- #ifdef WANT_ZYNADDSUBFX
- if (addPlugin(PLUGIN_INTERNAL, nullptr, baseName, "zynaddsubfx"))
- {
- if (CarlaPlugin* const plugin = getPlugin(pData->curPluginCount-1))
- plugin->setCustomData(CUSTOM_DATA_TYPE_STRING, (extension == "xmz") ? "CarlaAlternateFile1" : "CarlaAlternateFile2", filename, true);
- return true;
- }
- return false;
- #else
- setLastError("This Carla build does not have ZynAddSubFX support");
- return false;
- #endif
- }
-
- // -------------------------------------------------------------------
-
- setLastError("Unknown file extension");
- return false;
- }
-
- bool CarlaEngine::loadProject(const char* const filename)
- {
- CARLA_SAFE_ASSERT_RETURN_ERR(filename != nullptr && filename[0] != '\0', "Invalid filename (err #2)");
- carla_debug("CarlaEngine::loadProject(\"%s\")", filename);
-
- QFile file(filename);
-
- if (! file.open(QIODevice::ReadOnly | QIODevice::Text))
- return false;
-
- QDomDocument xml;
- xml.setContent(file.readAll());
- file.close();
-
- QDomNode xmlNode(xml.documentElement());
-
- const bool isPreset(xmlNode.toElement().tagName().compare("carla-preset", Qt::CaseInsensitive) == 0);
-
- if (xmlNode.toElement().tagName().compare("carla-project", Qt::CaseInsensitive) != 0 && ! isPreset)
- {
- setLastError("Not a valid Carla project or preset file");
- return false;
- }
-
- for (QDomNode node = xmlNode.firstChild(); ! node.isNull(); node = node.nextSibling())
- {
- if (isPreset || node.toElement().tagName().compare("plugin", Qt::CaseInsensitive) == 0)
- {
- SaveState saveState;
- fillSaveStateFromXmlNode(saveState, isPreset ? xmlNode : node);
-
- CARLA_SAFE_ASSERT_CONTINUE(saveState.type != nullptr);
-
- const void* extraStuff = nullptr;
-
- // check if using GIG, SF2 or SFZ 16outs
- static const char kUse16OutsSuffix[] = " (16 outs)";
-
- if (CarlaString(saveState.label).endsWith(kUse16OutsSuffix))
- {
- if (std::strcmp(saveState.type, "GIG") == 0 || std::strcmp(saveState.type, "SF2") == 0 || std::strcmp(saveState.type, "SFZ") == 0)
- extraStuff = (void*)0x1; // non-null
- }
-
- // TODO - proper find&load plugins
-
- if (addPlugin(getPluginTypeFromString(saveState.type), saveState.binary, saveState.name, saveState.label, extraStuff))
- {
- if (CarlaPlugin* plugin = getPlugin(pData->curPluginCount-1))
- plugin->loadSaveState(saveState);
- }
- }
-
- if (isPreset)
- break;
- }
-
- return true;
- }
-
- bool CarlaEngine::saveProject(const char* const filename)
- {
- CARLA_SAFE_ASSERT_RETURN_ERR(filename != nullptr && filename[0] != '\0', "Invalid filename (err #3)");
- carla_debug("CarlaEngine::saveProject(\"%s\")", filename);
-
- QFile file(filename);
-
- if (! file.open(QIODevice::WriteOnly | QIODevice::Text))
- return false;
-
- QTextStream out(&file);
- out << "<?xml version='1.0' encoding='UTF-8'?>\n";
- out << "<!DOCTYPE CARLA-PROJECT>\n";
- out << "<CARLA-PROJECT VERSION='2.0'>\n";
-
- bool firstPlugin = true;
- char strBuf[STR_MAX+1];
-
- for (unsigned int i=0; i < pData->curPluginCount; ++i)
- {
- CarlaPlugin* const plugin = pData->plugins[i].plugin;
-
- if (plugin != nullptr && plugin->isEnabled())
- {
- if (! firstPlugin)
- out << "\n";
-
- strBuf[0] = '\0';
-
- plugin->getRealName(strBuf);
-
- if (strBuf[0] != '\0')
- out << QString(" <!-- %1 -->\n").arg(xmlSafeString(strBuf, true));
-
- QString content;
- fillXmlStringFromSaveState(content, plugin->getSaveState());
-
- out << " <Plugin>\n";
- out << content;
- out << " </Plugin>\n";
-
- firstPlugin = false;
- }
- }
-
- out << "</CARLA-PROJECT>\n";
-
- file.close();
- return true;
- }
-
- // -----------------------------------------------------------------------
- // Information (base)
-
- /*!
- * Get the current engine driver hints.
- */
- unsigned int CarlaEngine::getHints() const noexcept
- {
- return pData->hints;
- }
-
- /*!
- * Get the current buffer size.
- */
- uint32_t CarlaEngine::getBufferSize() const noexcept
- {
- return pData->bufferSize;
- }
-
- /*!
- * Get the current sample rate.
- */
- double CarlaEngine::getSampleRate() const noexcept
- {
- return pData->sampleRate;
- }
-
- /*!
- * Get the current engine name.
- */
- const char* CarlaEngine::getName() const noexcept
- {
- return (const char*)pData->name;
- }
-
- /*!
- * Get the current engine proccess mode.
- */
- EngineProcessMode CarlaEngine::getProccessMode() const noexcept
- {
- return pData->options.processMode;
- }
-
- /*!
- * Get the current engine options (read-only).
- */
- const EngineOptions& CarlaEngine::getOptions() const noexcept
- {
- return pData->options;
- }
-
- /*!
- * Get the current Time information (read-only).
- */
- const EngineTimeInfo& CarlaEngine::getTimeInfo() const noexcept
- {
- return pData->timeInfo;
- }
-
- // -----------------------------------------------------------------------
- // Information (peaks)
-
- float CarlaEngine::getInputPeak(const unsigned int pluginId, const bool isLeft) const
- {
- CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount, 0.0f);
-
- return pData->plugins[pluginId].insPeak[isLeft ? 0 : 1];
- }
-
- float CarlaEngine::getOutputPeak(const unsigned int pluginId, const bool isLeft) const
- {
- CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount, 0.0f);
-
- return pData->plugins[pluginId].outsPeak[isLeft ? 0 : 1];
- }
-
- // -----------------------------------------------------------------------
- // Callback
-
- void CarlaEngine::callback(const EngineCallbackOpcode action, const unsigned int pluginId, const int value1, const int value2, const float value3, const char* const valueStr)
- {
- carla_debug("CarlaEngine::callback(%s, %i, %i, %i, %f, \"%s\")", EngineCallbackOpcode2Str(action), pluginId, value1, value2, value3, valueStr);
-
- if (pData->callback != nullptr)
- pData->callback(pData->callbackPtr, action, pluginId, value1, value2, value3, valueStr);
- }
-
- void CarlaEngine::setCallback(const EngineCallbackFunc func, void* const ptr)
- {
- carla_debug("CarlaEngine::setCallback(%p, %p)", func, ptr);
-
- pData->callback = func;
- pData->callbackPtr = ptr;
- }
-
- // -----------------------------------------------------------------------
- // Patchbay
-
- bool CarlaEngine::patchbayConnect(int, int)
- {
- setLastError("Unsupported operation");
- return false;
- }
-
- bool CarlaEngine::patchbayDisconnect(int)
- {
- setLastError("Unsupported operation");
- return false;
- }
-
- bool CarlaEngine::patchbayRefresh()
- {
- setLastError("Unsupported operation");
- return false;
- }
-
- // -----------------------------------------------------------------------
- // Transport
-
- void CarlaEngine::transportPlay()
- {
- pData->time.playing = true;
- }
-
- void CarlaEngine::transportPause()
- {
- pData->time.playing = false;
- }
-
- void CarlaEngine::transportRelocate(const uint64_t frame)
- {
- pData->time.frame = frame;
- }
-
- // -----------------------------------------------------------------------
- // Error handling
-
- const char* CarlaEngine::getLastError() const noexcept
- {
- return (const char*)pData->lastError;
- }
-
- void CarlaEngine::setLastError(const char* const error) const
- {
- pData->lastError = error;
- }
-
- void CarlaEngine::setAboutToClose()
- {
- carla_debug("CarlaEngine::setAboutToClose()");
-
- pData->aboutToClose = true;
- }
-
- // -----------------------------------------------------------------------
- // Global options
-
- void CarlaEngine::setOption(const EngineOption option, const int value, const char* const valueStr)
- {
- carla_debug("CarlaEngine::setOption(%i:%s, %i, \"%s\")", option, EngineOption2Str(option), value, valueStr);
-
- if (isRunning() && (option == ENGINE_OPTION_PROCESS_MODE || option == ENGINE_OPTION_AUDIO_NUM_PERIODS || option == ENGINE_OPTION_AUDIO_DEVICE))
- return carla_stderr("CarlaEngine::setOption(%i:%s, %i, \"%s\") - Cannot set this option while engine is running!", option, EngineOption2Str(option), value, valueStr);
-
- switch (option)
- {
- case ENGINE_OPTION_DEBUG:
- break;
-
- case ENGINE_OPTION_PROCESS_MODE:
- CARLA_SAFE_ASSERT_RETURN(value >= ENGINE_PROCESS_MODE_SINGLE_CLIENT && value <= ENGINE_PROCESS_MODE_BRIDGE,);
- pData->options.processMode = static_cast<EngineProcessMode>(value);
- break;
-
- case ENGINE_OPTION_TRANSPORT_MODE:
- CARLA_SAFE_ASSERT_RETURN(value >= ENGINE_TRANSPORT_MODE_INTERNAL && value <= ENGINE_TRANSPORT_MODE_BRIDGE,);
- pData->options.transportMode = static_cast<EngineTransportMode>(value);
- break;
-
- case ENGINE_OPTION_FORCE_STEREO:
- CARLA_SAFE_ASSERT_RETURN(value == 0 || value == 1,);
- pData->options.forceStereo = (value != 0);
- break;
-
- case ENGINE_OPTION_PREFER_PLUGIN_BRIDGES:
- CARLA_SAFE_ASSERT_RETURN(value == 0 || value == 1,);
- pData->options.preferPluginBridges = (value != 0);
- break;
-
- case ENGINE_OPTION_PREFER_UI_BRIDGES:
- CARLA_SAFE_ASSERT_RETURN(value == 0 || value == 1,);
- pData->options.preferUiBridges = (value != 0);
- break;
-
- case ENGINE_OPTION_UIS_ALWAYS_ON_TOP:
- CARLA_SAFE_ASSERT_RETURN(value == 0 || value == 1,);
- pData->options.uisAlwaysOnTop = (value != 0);
- break;
-
- case ENGINE_OPTION_MAX_PARAMETERS:
- CARLA_SAFE_ASSERT_RETURN(value >= 0,);
- pData->options.maxParameters = static_cast<uint>(value);
- break;
-
- case ENGINE_OPTION_UI_BRIDGES_TIMEOUT:
- CARLA_SAFE_ASSERT_RETURN(value >= 0,);
- pData->options.uiBridgesTimeout = static_cast<uint>(value);
- break;
-
- case ENGINE_OPTION_AUDIO_NUM_PERIODS:
- CARLA_SAFE_ASSERT_RETURN(value >= 2 && value <= 3,);
- pData->options.audioNumPeriods = static_cast<uint>(value);
- break;
-
- case ENGINE_OPTION_AUDIO_BUFFER_SIZE:
- CARLA_SAFE_ASSERT_RETURN(value >= 8,);
- pData->options.audioBufferSize = static_cast<uint>(value);
- break;
-
- case ENGINE_OPTION_AUDIO_SAMPLE_RATE:
- CARLA_SAFE_ASSERT_RETURN(value >= 22050,);
- pData->options.audioSampleRate = static_cast<uint>(value);
- break;
-
- case ENGINE_OPTION_AUDIO_DEVICE:
- CARLA_SAFE_ASSERT_RETURN(valueStr != nullptr && valueStr[0] != '\0',);
-
- if (pData->options.audioDevice != nullptr)
- delete[] pData->options.audioDevice;
-
- pData->options.audioDevice = carla_strdup(valueStr);
- break;
-
- case ENGINE_OPTION_PATH_BINARIES:
- CARLA_SAFE_ASSERT_RETURN(valueStr != nullptr && valueStr[0] != '\0',);
-
- if (pData->options.binaryDir != nullptr)
- delete[] pData->options.binaryDir;
-
- pData->options.binaryDir = carla_strdup(valueStr);
- break;
-
- case ENGINE_OPTION_PATH_RESOURCES:
- CARLA_SAFE_ASSERT_RETURN(valueStr != nullptr && valueStr[0] != '\0',);
-
- if (pData->options.resourceDir != nullptr)
- delete[] pData->options.resourceDir;
-
- pData->options.resourceDir = carla_strdup(valueStr);
- break;
- }
- }
-
- // -----------------------------------------------------------------------
- // OSC Stuff
-
- #ifdef BUILD_BRIDGE
- bool CarlaEngine::isOscBridgeRegistered() const noexcept
- {
- return (pData->oscData != nullptr);
- }
- #else
- bool CarlaEngine::isOscControlRegistered() const noexcept
- {
- return pData->osc.isControlRegistered();
- }
- #endif
-
- void CarlaEngine::idleOsc()
- {
- pData->osc.idle();
- }
-
- const char* CarlaEngine::getOscServerPathTCP() const noexcept
- {
- return pData->osc.getServerPathTCP();
- }
-
- const char* CarlaEngine::getOscServerPathUDP() const noexcept
- {
- return pData->osc.getServerPathUDP();
- }
-
- #ifdef BUILD_BRIDGE
- void CarlaEngine::setOscBridgeData(const CarlaOscData* const oscData) const noexcept
- {
- pData->oscData = oscData;
- }
- #endif
-
- // -----------------------------------------------------------------------
- // Helper functions
-
- EngineEvent* CarlaEngine::getInternalEventBuffer(const bool isInput) const noexcept
- {
- return isInput ? pData->bufEvents.in : pData->bufEvents.out;
- }
-
- void CarlaEngine::registerEnginePlugin(const unsigned int id, CarlaPlugin* const plugin)
- {
- CARLA_SAFE_ASSERT_RETURN(id == pData->curPluginCount,);
- carla_debug("CarlaEngine::registerEnginePlugin(%i, %p)", id, plugin);
-
- pData->plugins[id].plugin = plugin;
- }
-
- // -----------------------------------------------------------------------
- // Internal stuff
-
- void CarlaEngine::bufferSizeChanged(const uint32_t newBufferSize)
- {
- carla_debug("CarlaEngine::bufferSizeChanged(%i)", newBufferSize);
-
- for (unsigned int i=0; i < pData->curPluginCount; ++i)
- {
- CarlaPlugin* const plugin(pData->plugins[i].plugin);
-
- if (plugin != nullptr && plugin->isEnabled())
- plugin->bufferSizeChanged(newBufferSize);
- }
-
- callback(ENGINE_CALLBACK_BUFFER_SIZE_CHANGED, 0, newBufferSize, 0, 0.0f, nullptr);
- }
-
- void CarlaEngine::sampleRateChanged(const double newSampleRate)
- {
- carla_debug("CarlaEngine::sampleRateChanged(%g)", newSampleRate);
-
- for (unsigned int i=0; i < pData->curPluginCount; ++i)
- {
- CarlaPlugin* const plugin(pData->plugins[i].plugin);
-
- if (plugin != nullptr && plugin->isEnabled())
- plugin->sampleRateChanged(newSampleRate);
- }
-
- callback(ENGINE_CALLBACK_SAMPLE_RATE_CHANGED, 0, 0, 0, static_cast<float>(newSampleRate), nullptr);
- }
-
- void CarlaEngine::offlineModeChanged(const bool isOffline)
- {
- carla_debug("CarlaEngine::offlineModeChanged(%s)", bool2str(isOffline));
-
- for (unsigned int i=0; i < pData->curPluginCount; ++i)
- {
- CarlaPlugin* const plugin(pData->plugins[i].plugin);
-
- if (plugin != nullptr && plugin->isEnabled())
- plugin->offlineModeChanged(isOffline);
- }
- }
-
- void CarlaEngine::runPendingRtEvents()
- {
- pData->doNextPluginAction(true);
-
- if (pData->time.playing)
- pData->time.frame += pData->bufferSize;
-
- if (pData->options.transportMode == ENGINE_TRANSPORT_MODE_INTERNAL)
- {
- pData->timeInfo.playing = pData->time.playing;
- pData->timeInfo.frame = pData->time.frame;
- }
- }
-
- void CarlaEngine::setPluginPeaks(const unsigned int pluginId, float const inPeaks[2], float const outPeaks[2]) noexcept
- {
- EnginePluginData& pluginData(pData->plugins[pluginId]);
-
- pluginData.insPeak[0] = inPeaks[0];
- pluginData.insPeak[1] = inPeaks[1];
- pluginData.outsPeak[0] = outPeaks[0];
- pluginData.outsPeak[1] = outPeaks[1];
- }
-
- #ifndef BUILD_BRIDGE
- void CarlaEngine::processRack(float* inBufReal[2], float* outBuf[2], const uint32_t frames)
- {
- CARLA_SAFE_ASSERT_RETURN(pData->bufEvents.in != nullptr,);
- CARLA_SAFE_ASSERT_RETURN(pData->bufEvents.out != nullptr,);
-
- // safe copy
- float inBuf0[frames];
- float inBuf1[frames];
- float* inBuf[2] = { inBuf0, inBuf1 };
-
- // initialize audio inputs
- FLOAT_COPY(inBuf0, inBufReal[0], frames);
- FLOAT_COPY(inBuf1, inBufReal[1], frames);
-
- // initialize audio outputs (zero)
- FLOAT_CLEAR(outBuf[0], frames);
- FLOAT_CLEAR(outBuf[1], frames);
-
- // initialize event outputs (zero)
- carla_zeroStruct<EngineEvent>(pData->bufEvents.out, kEngineMaxInternalEventCount);
-
- bool processed = false;
-
- uint32_t oldAudioInCount = 0;
- uint32_t oldMidiOutCount = 0;
-
- const bool forcedOffline(isOffline());
-
- // process plugins
- for (unsigned int i=0; i < pData->curPluginCount; ++i)
- {
- CarlaPlugin* const plugin = pData->plugins[i].plugin;
-
- if (plugin == nullptr || ! plugin->isEnabled() || ! plugin->tryLock(forcedOffline))
- continue;
-
- if (processed)
- {
- // initialize audio inputs (from previous outputs)
- FLOAT_COPY(inBuf0, outBuf[0], frames);
- FLOAT_COPY(inBuf1, outBuf[1], frames);
-
- // initialize audio outputs (zero)
- FLOAT_CLEAR(outBuf[0], frames);
- FLOAT_CLEAR(outBuf[1], frames);
-
- // if plugin has no midi out, add previous events
- if (oldMidiOutCount == 0 && pData->bufEvents.in[0].type != kEngineEventTypeNull)
- {
- if (pData->bufEvents.out[0].type != kEngineEventTypeNull)
- {
- // TODO: carefully add to input, sorted events
- }
- // else nothing needed
- }
- else
- {
- // initialize event inputs from previous outputs
- std::memcpy(pData->bufEvents.in, pData->bufEvents.out, sizeof(EngineEvent)*kEngineMaxInternalEventCount);
-
- // initialize event outputs (zero)
- std::memset(pData->bufEvents.out, 0, sizeof(EngineEvent)*kEngineMaxInternalEventCount);
- }
- }
-
- oldAudioInCount = plugin->getAudioInCount();
- oldMidiOutCount = plugin->getMidiOutCount();
-
- // process
- plugin->initBuffers();
- plugin->process(inBuf, outBuf, frames);
- plugin->unlock();
-
- // if plugin has no audio inputs, add input buffer
- if (oldAudioInCount == 0)
- {
- FLOAT_ADD(outBuf[0], inBuf0, frames);
- FLOAT_ADD(outBuf[1], inBuf1, frames);
- }
-
- // set peaks
- {
- EnginePluginData& pluginData(pData->plugins[i]);
-
- #ifdef HAVE_JUCE
- float tmpMin, tmpMax;
-
- if (oldAudioInCount > 0)
- {
- FloatVectorOperations::findMinAndMax(inBuf0, frames, tmpMin, tmpMax);
- pluginData.insPeak[0] = carla_max<float>(std::abs(tmpMin), std::abs(tmpMax), 1.0f);
-
- FloatVectorOperations::findMinAndMax(inBuf1, frames, tmpMin, tmpMax);
- pluginData.insPeak[1] = carla_max<float>(std::abs(tmpMin), std::abs(tmpMax), 1.0f);
- }
- else
- {
- pluginData.insPeak[0] = 0.0f;
- pluginData.insPeak[1] = 0.0f;
- }
-
- if (plugin->getAudioOutCount() > 0)
- {
- FloatVectorOperations::findMinAndMax(outBuf[0], frames, tmpMin, tmpMax);
- pluginData.outsPeak[0] = carla_max<float>(std::abs(tmpMin), std::abs(tmpMax), 1.0f);
-
- FloatVectorOperations::findMinAndMax(outBuf[1], frames, tmpMin, tmpMax);
- pluginData.outsPeak[1] = carla_max<float>(std::abs(tmpMin), std::abs(tmpMax), 1.0f);
- }
- else
- {
- pluginData.outsPeak[0] = 0.0f;
- pluginData.outsPeak[1] = 0.0f;
- }
- #else
- float peak1, peak2;
-
- if (oldAudioInCount > 0)
- {
- peak1 = peak2 = 0.0f;
-
- for (uint32_t k=0; k < frames; ++k)
- {
- peak1 = carla_max<float>(peak1, std::fabs(inBuf0[k]), 1.0f);
- peak2 = carla_max<float>(peak2, std::fabs(inBuf1[k]), 1.0f);
- }
-
- pluginData.insPeak[0] = peak1;
- pluginData.insPeak[1] = peak2;
- }
- else
- {
- pluginData.insPeak[0] = 0.0f;
- pluginData.insPeak[1] = 0.0f;
- }
-
- if (plugin->getAudioOutCount() > 0)
- {
- peak1 = peak2 = 0.0f;
-
- for (uint32_t k=0; k < frames; ++k)
- {
- peak1 = carla_max<float>(peak1, std::fabs(outBuf[0][k]), 1.0f);
- peak2 = carla_max<float>(peak2, std::fabs(outBuf[1][k]), 1.0f);
- }
-
- pluginData.outsPeak[0] = peak1;
- pluginData.outsPeak[1] = peak2;
- }
- else
- {
- pluginData.outsPeak[0] = 0.0f;
- pluginData.outsPeak[1] = 0.0f;
- }
- #endif
- }
-
- processed = true;
- }
- }
-
- void CarlaEngine::processPatchbay(float** inBuf, float** outBuf, const uint32_t bufCount[2], const uint32_t frames)
- {
- // TODO
- return;
-
- // unused, for now
- (void)inBuf;
- (void)outBuf;
- (void)bufCount;
- (void)frames;
- }
- #endif
-
- // -----------------------------------------------------------------------
- // Bridge/Controller OSC stuff
-
- #ifdef BUILD_BRIDGE
- void CarlaEngine::oscSend_bridge_plugin_info1(const PluginCategory category, const uint hints, const long uniqueId) const
- {
- CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
- carla_debug("CarlaEngine::oscSend_bridge_plugin_info1(%i:%s, %X, %l)", category, PluginCategory2Str(category), hints, uniqueId);
-
- if (pData->oscData->target != nullptr)
- {
- char targetPath[std::strlen(pData->oscData->path)+21];
- std::strcpy(targetPath, pData->oscData->path);
- std::strcat(targetPath, "/bridge_plugin_info1");
- lo_send(pData->oscData->target, targetPath, "iih", static_cast<int32_t>(category), static_cast<int32_t>(hints), static_cast<int64_t>(uniqueId));
- }
- }
-
- void CarlaEngine::oscSend_bridge_plugin_info2(const char* const realName, const char* const label, const char* const maker, const char* const copyright) const
- {
- CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
- CARLA_SAFE_ASSERT_RETURN(realName != nullptr && realName[0] != '\0',);
- CARLA_SAFE_ASSERT_RETURN(label != nullptr && label[0] != '\0',);
- CARLA_SAFE_ASSERT_RETURN(maker != nullptr,);
- CARLA_SAFE_ASSERT_RETURN(copyright != nullptr,);
- carla_debug("CarlaEngine::oscSend_bridge_plugin_info2(\"%s\", \"%s\", \"%s\", \"%s\")", realName, label, maker, copyright);
-
- if (pData->oscData->target != nullptr)
- {
- char targetPath[std::strlen(pData->oscData->path)+21];
- std::strcpy(targetPath, pData->oscData->path);
- std::strcat(targetPath, "/bridge_plugin_info2");
- lo_send(pData->oscData->target, targetPath, "ssss", realName, label, maker, copyright);
- }
- }
-
- void CarlaEngine::oscSend_bridge_audio_count(const uint32_t ins, const uint32_t outs) const
- {
- CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
- carla_debug("CarlaEngine::oscSend_bridge_audio_count(%i, %i)", ins, outs);
-
- if (pData->oscData->target != nullptr)
- {
- char targetPath[std::strlen(pData->oscData->path)+20];
- std::strcpy(targetPath, pData->oscData->path);
- std::strcat(targetPath, "/bridge_audio_count");
- lo_send(pData->oscData->target, targetPath, "iii", static_cast<int32_t>(ins), static_cast<int32_t>(outs));
- }
- }
-
- void CarlaEngine::oscSend_bridge_midi_count(const uint32_t ins, const uint32_t outs) const
- {
- CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
- carla_debug("CarlaEngine::oscSend_bridge_midi_count(%i, %i)", ins, outs);
-
- if (pData->oscData->target != nullptr)
- {
- char targetPath[std::strlen(pData->oscData->path)+19];
- std::strcpy(targetPath, pData->oscData->path);
- std::strcat(targetPath, "/bridge_midi_count");
- lo_send(pData->oscData->target, targetPath, "ii", static_cast<int32_t>(ins), static_cast<int32_t>(outs));
- }
- }
-
- void CarlaEngine::oscSend_bridge_parameter_count(const uint32_t ins, const uint32_t outs) const
- {
- CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
- carla_debug("CarlaEngine::oscSend_bridge_parameter_count(%i, %i)", ins, outs);
-
- if (pData->oscData->target != nullptr)
- {
- char targetPath[std::strlen(pData->oscData->path)+24];
- std::strcpy(targetPath, pData->oscData->path);
- std::strcat(targetPath, "/bridge_parameter_count");
- lo_send(pData->oscData->target, targetPath, "ii", static_cast<int32_t>(ins), static_cast<int32_t>(outs));
- }
- }
-
- void CarlaEngine::oscSend_bridge_program_count(const uint32_t count) const
- {
- CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
- carla_debug("CarlaEngine::oscSend_bridge_program_count(%i)", count);
-
- if (pData->oscData->target != nullptr)
- {
- char targetPath[std::strlen(pData->oscData->path)+22];
- std::strcpy(targetPath, pData->oscData->path);
- std::strcat(targetPath, "/bridge_program_count");
- lo_send(pData->oscData->target, targetPath, "i", static_cast<int32_t>(count));
- }
- }
-
- void CarlaEngine::oscSend_bridge_midi_program_count(const uint32_t count) const
- {
- CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
- carla_debug("CarlaEngine::oscSend_bridge_midi_program_count(%i)", count);
-
- if (pData->oscData->target != nullptr)
- {
- char targetPath[std::strlen(pData->oscData->path)+27];
- std::strcpy(targetPath, pData->oscData->path);
- std::strcat(targetPath, "/bridge_midi_program_count");
- lo_send(pData->oscData->target, targetPath, "i", static_cast<int32_t>(count));
- }
- }
-
- 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
- {
- CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
- CARLA_SAFE_ASSERT_RETURN(name != nullptr && name[0] != '\0',);
- CARLA_SAFE_ASSERT_RETURN(unit != nullptr,);
- carla_debug("CarlaEngine::oscSend_bridge_parameter_data(%i, %i, %i:%s, %X, \"%s\", \"%s\")", index, rindex, type, ParameterType2Str(type), hints, name, unit);
-
- if (pData->oscData->target != nullptr)
- {
- char targetPath[std::strlen(pData->oscData->path)+23];
- std::strcpy(targetPath, pData->oscData->path);
- std::strcat(targetPath, "/bridge_parameter_data");
- 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);
- }
- }
-
- void CarlaEngine::oscSend_bridge_parameter_ranges1(const uint32_t index, const float def, const float min, const float max) const
- {
- CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
- carla_debug("CarlaEngine::oscSend_bridge_parameter_ranges(%i, %f, %f, %f)", index, def, min, max);
-
- if (pData->oscData->target != nullptr)
- {
- char targetPath[std::strlen(pData->oscData->path)+26];
- std::strcpy(targetPath, pData->oscData->path);
- std::strcat(targetPath, "/bridge_parameter_ranges1");
- lo_send(pData->oscData->target, targetPath, "ifff", static_cast<int32_t>(index), def, min, max);
- }
- }
-
- void CarlaEngine::oscSend_bridge_parameter_ranges2(const uint32_t index, const float step, const float stepSmall, const float stepLarge) const
- {
- CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
- carla_debug("CarlaEngine::oscSend_bridge_parameter_ranges(%i, %f, %f, %f)", index, step, stepSmall, stepLarge);
-
- if (pData->oscData->target != nullptr)
- {
- char targetPath[std::strlen(pData->oscData->path)+26];
- std::strcpy(targetPath, pData->oscData->path);
- std::strcat(targetPath, "/bridge_parameter_ranges2");
- lo_send(pData->oscData->target, targetPath, "ifff", static_cast<int32_t>(index), step, stepSmall, stepLarge);
- }
- }
-
- void CarlaEngine::oscSend_bridge_parameter_midi_cc(const uint32_t index, const int16_t cc) const
- {
- CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
- carla_debug("CarlaEngine::oscSend_bridge_parameter_midi_cc(%i, %i)", index, cc);
-
- if (pData->oscData->target != nullptr)
- {
- char targetPath[std::strlen(pData->oscData->path)+26];
- std::strcpy(targetPath, pData->oscData->path);
- std::strcat(targetPath, "/bridge_parameter_midi_cc");
- lo_send(pData->oscData->target, targetPath, "ii", static_cast<int32_t>(index), static_cast<int32_t>(cc));
- }
- }
-
- void CarlaEngine::oscSend_bridge_parameter_midi_channel(const uint32_t index, const uint8_t channel) const
- {
- CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
- carla_debug("CarlaEngine::oscSend_bridge_parameter_midi_channel(%i, %i)", index, channel);
-
- if (pData->oscData->target != nullptr)
- {
- char targetPath[std::strlen(pData->oscData->path)+31];
- std::strcpy(targetPath, pData->oscData->path);
- std::strcat(targetPath, "/bridge_parameter_midi_channel");
- lo_send(pData->oscData->target, targetPath, "ii", static_cast<int32_t>(index), static_cast<int32_t>(channel));
- }
- }
-
- void CarlaEngine::oscSend_bridge_parameter_value(const int32_t index, const float value) const
- {
- CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
- CARLA_SAFE_ASSERT_RETURN(index != PARAMETER_NULL,);
- carla_debug("CarlaEngine::oscSend_bridge_parameter_value(%i, %f)", index, value);
-
- if (pData->oscData->target != nullptr)
- {
- char targetPath[std::strlen(pData->oscData->path)+24];
- std::strcpy(targetPath, pData->oscData->path);
- std::strcat(targetPath, "/bridge_parameter_value");
- lo_send(pData->oscData->target, targetPath, "if", index, value);
- }
- }
-
- void CarlaEngine::oscSend_bridge_default_value(const uint32_t index, const float value) const
- {
- CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
- carla_debug("CarlaEngine::oscSend_bridge_default_value(%i, %f)", index, value);
-
- if (pData->oscData->target != nullptr)
- {
- char targetPath[std::strlen(pData->oscData->path)+22];
- std::strcpy(targetPath, pData->oscData->path);
- std::strcat(targetPath, "/bridge_default_value");
- lo_send(pData->oscData->target, targetPath, "if", static_cast<int32_t>(index), value);
- }
- }
-
- void CarlaEngine::oscSend_bridge_current_program(const int32_t index) const
- {
- CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
- carla_debug("CarlaEngine::oscSend_bridge_current_program(%i)", index);
-
- if (pData->oscData->target != nullptr)
- {
- char targetPath[std::strlen(pData->oscData->path)+20];
- std::strcpy(targetPath, pData->oscData->path);
- std::strcat(targetPath, "/bridge_current_program");
- lo_send(pData->oscData->target, targetPath, "i", index);
- }
- }
-
- void CarlaEngine::oscSend_bridge_current_midi_program(const int32_t index) const
- {
- CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
- carla_debug("CarlaEngine::oscSend_bridge_current_midi_program(%i)", index);
-
- if (pData->oscData->target != nullptr)
- {
- char targetPath[std::strlen(pData->oscData->path)+25];
- std::strcpy(targetPath, pData->oscData->path);
- std::strcat(targetPath, "/bridge_current_midi_program");
- lo_send(pData->oscData->target, targetPath, "i", index);
- }
- }
-
- void CarlaEngine::oscSend_bridge_program_name(const uint32_t index, const char* const name) const
- {
- CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
- carla_debug("CarlaEngine::oscSend_bridge_program_name(%i, \"%s\")", index, name);
-
- if (pData->oscData->target != nullptr)
- {
- char targetPath[std::strlen(pData->oscData->path)+21];
- std::strcpy(targetPath, pData->oscData->path);
- std::strcat(targetPath, "/bridge_program_name");
- lo_send(pData->oscData->target, targetPath, "is", static_cast<int32_t>(index), name);
- }
- }
-
- void CarlaEngine::oscSend_bridge_midi_program_data(const uint32_t index, const uint32_t bank, const uint32_t program, const char* const name) const
- {
- CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
- CARLA_SAFE_ASSERT_RETURN(name != nullptr,);
- carla_debug("CarlaEngine::oscSend_bridge_midi_program_data(%i, %i, %i, \"%s\")", index, bank, program, name);
-
- if (pData->oscData->target != nullptr)
- {
- char targetPath[std::strlen(pData->oscData->path)+26];
- std::strcpy(targetPath, pData->oscData->path);
- std::strcat(targetPath, "/bridge_midi_program_data");
- lo_send(pData->oscData->target, targetPath, "iiis", static_cast<int32_t>(index), static_cast<int32_t>(bank), static_cast<int32_t>(program), name);
- }
- }
-
- void CarlaEngine::oscSend_bridge_configure(const char* const key, const char* const value) const
- {
- CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
- CARLA_SAFE_ASSERT_RETURN(key != nullptr && key[0] != '\0',);
- CARLA_SAFE_ASSERT_RETURN(value != nullptr,);
- carla_debug("CarlaEngine::oscSend_bridge_configure(\"%s\", \"%s\")", key, value);
-
- if (pData->oscData->target != nullptr)
- {
- char targetPath[std::strlen(pData->oscData->path)+18];
- std::strcpy(targetPath, pData->oscData->path);
- std::strcat(targetPath, "/bridge_configure");
- lo_send(pData->oscData->target, targetPath, "ss", key, value);
- }
- }
-
- void CarlaEngine::oscSend_bridge_set_custom_data(const char* const type, const char* const key, const char* const value) const
- {
- CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
- carla_debug("CarlaEngine::oscSend_bridge_set_custom_data(\"%s\", \"%s\", \"%s\")", type, key, value);
-
- if (pData->oscData->target != nullptr)
- {
- char targetPath[std::strlen(pData->oscData->path)+24];
- std::strcpy(targetPath, pData->oscData->path);
- std::strcat(targetPath, "/bridge_set_custom_data");
- lo_send(pData->oscData->target, targetPath, "sss", type, key, value);
- }
- }
-
- void CarlaEngine::oscSend_bridge_set_chunk_data(const char* const chunkFile) const
- {
- CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
- carla_debug("CarlaEngine::oscSend_bridge_set_chunk_data(\"%s\")", chunkFile);
-
- if (pData->oscData->target != nullptr)
- {
- char targetPath[std::strlen(pData->oscData->path)+23];
- std::strcpy(targetPath, pData->oscData->path);
- std::strcat(targetPath, "/bridge_set_chunk_data");
- lo_send(pData->oscData->target, targetPath, "s", chunkFile);
- }
- }
-
- // TODO?
- //void oscSend_bridge_set_peaks() const;
-
- #else
- void CarlaEngine::oscSend_control_add_plugin_start(const uint pluginId, const char* const pluginName) const
- {
- CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
- CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
- CARLA_SAFE_ASSERT_RETURN(pluginName != nullptr && pluginName[0] != '\0',);
- carla_debug("CarlaEngine::oscSend_control_add_plugin_start(%i, \"%s\")", pluginId, pluginName);
-
- if (pData->oscData->target != nullptr)
- {
- char targetPath[std::strlen(pData->oscData->path)+18];
- std::strcpy(targetPath, pData->oscData->path);
- std::strcat(targetPath, "/add_plugin_start");
- lo_send(pData->oscData->target, targetPath, "is", static_cast<int32_t>(pluginId), pluginName);
- }
- }
-
- void CarlaEngine::oscSend_control_add_plugin_end(const uint pluginId) const
- {
- CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
- CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
- carla_debug("CarlaEngine::oscSend_control_add_plugin_end(%i)", pluginId);
-
- if (pData->oscData->target != nullptr)
- {
- char targetPath[std::strlen(pData->oscData->path)+16];
- std::strcpy(targetPath, pData->oscData->path);
- std::strcat(targetPath, "/add_plugin_end");
- lo_send(pData->oscData->target, targetPath, "i", static_cast<int32_t>(pluginId));
- }
- }
-
- void CarlaEngine::oscSend_control_remove_plugin(const uint pluginId) const
- {
- CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
- CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
- carla_debug("CarlaEngine::oscSend_control_remove_plugin(%i)", pluginId);
-
- if (pData->oscData->target != nullptr)
- {
- char targetPath[std::strlen(pData->oscData->path)+15];
- std::strcpy(targetPath, pData->oscData->path);
- std::strcat(targetPath, "/remove_plugin");
- lo_send(pData->oscData->target, targetPath, "i", static_cast<int32_t>(pluginId));
- }
- }
-
- void CarlaEngine::oscSend_control_set_plugin_info1(const uint pluginId, const PluginType type, const PluginCategory category, const uint hints, const long uniqueId) const
- {
- CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
- CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
- CARLA_SAFE_ASSERT_RETURN(type != PLUGIN_NONE,);
- carla_debug("CarlaEngine::oscSend_control_set_plugin_data(%i, %i:%s, %i:%s, %X, %l)", pluginId, type, PluginType2Str(type), category, PluginCategory2Str(category), hints, uniqueId);
-
- if (pData->oscData->target != nullptr)
- {
- char targetPath[std::strlen(pData->oscData->path)+18];
- std::strcpy(targetPath, pData->oscData->path);
- std::strcat(targetPath, "/set_plugin_info1");
- 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));
- }
- }
-
- 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
- {
- CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
- CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
- CARLA_SAFE_ASSERT_RETURN(realName != nullptr && realName[0] != '\0',);
- CARLA_SAFE_ASSERT_RETURN(label != nullptr && label[0] != '\0',);
- CARLA_SAFE_ASSERT_RETURN(maker != nullptr,);
- CARLA_SAFE_ASSERT_RETURN(copyright != nullptr,);
- carla_debug("CarlaEngine::oscSend_control_set_plugin_data(%i, \"%s\", \"%s\", \"%s\", \"%s\")", pluginId, realName, label, maker, copyright);
-
- if (pData->oscData->target != nullptr)
- {
- char targetPath[std::strlen(pData->oscData->path)+18];
- std::strcpy(targetPath, pData->oscData->path);
- std::strcat(targetPath, "/set_plugin_info2");
- lo_send(pData->oscData->target, targetPath, "issss", static_cast<int32_t>(pluginId), realName, label, maker, copyright);
- }
- }
-
- void CarlaEngine::oscSend_control_set_audio_count(const uint pluginId, const uint32_t ins, const uint32_t outs) const
- {
- CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
- CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
- carla_debug("CarlaEngine::oscSend_control_set_audio_count(%i, %i, %i)", pluginId, ins, outs);
-
- if (pData->oscData->target != nullptr)
- {
- char targetPath[std::strlen(pData->oscData->path)+18];
- std::strcpy(targetPath, pData->oscData->path);
- std::strcat(targetPath, "/set_audio_count");
- lo_send(pData->oscData->target, targetPath, "iii", static_cast<int32_t>(pluginId), static_cast<int32_t>(ins), static_cast<int32_t>(outs));
- }
- }
-
- void CarlaEngine::oscSend_control_set_midi_count(const uint pluginId, const uint32_t ins, const uint32_t outs) const
- {
- CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
- CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
- carla_debug("CarlaEngine::oscSend_control_set_midi_count(%i, %i, %i)", pluginId, ins, outs);
-
- if (pData->oscData->target != nullptr)
- {
- char targetPath[std::strlen(pData->oscData->path)+18];
- std::strcpy(targetPath, pData->oscData->path);
- std::strcat(targetPath, "/set_midi_count");
- lo_send(pData->oscData->target, targetPath, "iii", static_cast<int32_t>(pluginId), static_cast<int32_t>(ins), static_cast<int32_t>(outs));
- }
- }
-
- void CarlaEngine::oscSend_control_set_parameter_count(const uint pluginId, const uint32_t ins, const uint32_t outs) const
- {
- CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
- CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
- carla_debug("CarlaEngine::oscSend_control_set_parameter_count(%i, %i, %i)", pluginId, ins, outs);
-
- if (pData->oscData->target != nullptr)
- {
- char targetPath[std::strlen(pData->oscData->path)+18];
- std::strcpy(targetPath, pData->oscData->path);
- std::strcat(targetPath, "/set_parameter_count");
- lo_send(pData->oscData->target, targetPath, "iii", static_cast<int32_t>(pluginId), static_cast<int32_t>(ins), static_cast<int32_t>(outs));
- }
- }
-
- void CarlaEngine::oscSend_control_set_program_count(const uint pluginId, const uint32_t count) const
- {
- CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
- CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
- carla_debug("CarlaEngine::oscSend_control_set_program_count(%i, %i)", pluginId, count);
-
- if (pData->oscData->target != nullptr)
- {
- char targetPath[std::strlen(pData->oscData->path)+19];
- std::strcpy(targetPath, pData->oscData->path);
- std::strcat(targetPath, "/set_program_count");
- lo_send(pData->oscData->target, targetPath, "ii", static_cast<int32_t>(pluginId), static_cast<int32_t>(count));
- }
- }
-
- void CarlaEngine::oscSend_control_set_midi_program_count(const uint pluginId, const uint32_t count) const
- {
- CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
- CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
- carla_debug("CarlaEngine::oscSend_control_set_midi_program_count(%i, %i)", pluginId, count);
-
- if (pData->oscData->target != nullptr)
- {
- char targetPath[std::strlen(pData->oscData->path)+24];
- std::strcpy(targetPath, pData->oscData->path);
- std::strcat(targetPath, "/set_midi_program_count");
- lo_send(pData->oscData->target, targetPath, "ii", static_cast<int32_t>(pluginId), static_cast<int32_t>(count));
- }
- }
-
- 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
- {
- CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
- CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
- CARLA_SAFE_ASSERT_RETURN(name != nullptr && name[0] != '\0',);
- CARLA_SAFE_ASSERT_RETURN(unit != nullptr,);
- carla_debug("CarlaEngine::oscSend_control_set_parameter_data(%i, %i, %i:%s, %X, \"%s\", \"%s\")", pluginId, index, type, ParameterType2Str(type), hints, name, unit);
-
- if (pData->oscData->target != nullptr)
- {
- char targetPath[std::strlen(pData->oscData->path)+20];
- std::strcpy(targetPath, pData->oscData->path);
- std::strcat(targetPath, "/set_parameter_data");
- 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);
- }
- }
-
- void CarlaEngine::oscSend_control_set_parameter_ranges1(const uint pluginId, const uint32_t index, const float def, const float min, const float max) const
- {
- CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
- CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
- CARLA_SAFE_ASSERT_RETURN(def <= min && def >= max,);
- CARLA_SAFE_ASSERT_RETURN(min < max,);
- carla_debug("CarlaEngine::oscSend_control_set_parameter_ranges1(%i, %i, %f, %f, %f)", pluginId, index, def, min, max, def);
-
- if (pData->oscData->target != nullptr)
- {
- char targetPath[std::strlen(pData->oscData->path)+23];
- std::strcpy(targetPath, pData->oscData->path);
- std::strcat(targetPath, "/set_parameter_ranges1");
- lo_send(pData->oscData->target, targetPath, "iifff", static_cast<int32_t>(pluginId), static_cast<int32_t>(index), def, min, max);
- }
- }
-
- void CarlaEngine::oscSend_control_set_parameter_ranges2(const uint pluginId, const uint32_t index, const float step, const float stepSmall, const float stepLarge) const
- {
- CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
- CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
- CARLA_SAFE_ASSERT_RETURN(step <= stepSmall && step >= stepLarge,);
- CARLA_SAFE_ASSERT_RETURN(stepSmall <= stepLarge,);
- carla_debug("CarlaEngine::oscSend_control_set_parameter_ranges2(%i, %i, %f, %f, %f)", pluginId, index, step, stepSmall, stepLarge);
-
- if (pData->oscData->target != nullptr)
- {
- char targetPath[std::strlen(pData->oscData->path)+23];
- std::strcpy(targetPath, pData->oscData->path);
- std::strcat(targetPath, "/set_parameter_ranges");
- lo_send(pData->oscData->target, targetPath, "iifff", static_cast<int32_t>(pluginId), static_cast<int32_t>(index), step, stepSmall, stepLarge);
- }
- }
-
- void CarlaEngine::oscSend_control_set_parameter_midi_cc(const uint pluginId, const uint32_t index, const int16_t cc) const
- {
- CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
- CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
- CARLA_SAFE_ASSERT_RETURN(cc <= 0x5F,);
- carla_debug("CarlaEngine::oscSend_control_set_parameter_midi_cc(%i, %i, %i)", pluginId, index, cc);
-
- if (pData->oscData->target != nullptr)
- {
- char targetPath[std::strlen(pData->oscData->path)+23];
- std::strcpy(targetPath, pData->oscData->path);
- std::strcat(targetPath, "/set_parameter_midi_cc");
- lo_send(pData->oscData->target, targetPath, "iii", static_cast<int32_t>(pluginId), static_cast<int32_t>(index), static_cast<int32_t>(cc));
- }
- }
-
- void CarlaEngine::oscSend_control_set_parameter_midi_channel(const uint pluginId, const uint32_t index, const uint8_t channel) const
- {
- CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
- CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
- CARLA_SAFE_ASSERT_RETURN(channel < MAX_MIDI_CHANNELS,);
- carla_debug("CarlaEngine::oscSend_control_set_parameter_midi_channel(%i, %i, %i)", pluginId, index, channel);
-
- if (pData->oscData->target != nullptr)
- {
- char targetPath[std::strlen(pData->oscData->path)+28];
- std::strcpy(targetPath, pData->oscData->path);
- std::strcat(targetPath, "/set_parameter_midi_channel");
- lo_send(pData->oscData->target, targetPath, "iii", static_cast<int32_t>(pluginId), static_cast<int32_t>(index), static_cast<int32_t>(channel));
- }
- }
-
- void CarlaEngine::oscSend_control_set_parameter_value(const uint pluginId, const int32_t index, const float value) const
- {
- CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
- CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
- CARLA_SAFE_ASSERT_RETURN(index != PARAMETER_NULL,);
- carla_debug("CarlaEngine::oscSend_control_set_parameter_value(%i, %i:%s, %f)", pluginId, index, (index < 0) ? InternalParameterIndex2Str(static_cast<InternalParameterIndex>(index)) : "(none)", value);
-
- if (pData->oscData->target != nullptr)
- {
- char targetPath[std::strlen(pData->oscData->path)+21];
- std::strcpy(targetPath, pData->oscData->path);
- std::strcat(targetPath, "/set_parameter_value");
- lo_send(pData->oscData->target, targetPath, "iif", static_cast<int32_t>(pluginId), index, value);
- }
- }
-
- void CarlaEngine::oscSend_control_set_default_value(const uint pluginId, const uint32_t index, const float value) const
- {
- CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
- CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
- carla_debug("CarlaEngine::oscSend_control_set_default_value(%i, %i, %f)", pluginId, index, value);
-
- if (pData->oscData->target != nullptr)
- {
- char targetPath[std::strlen(pData->oscData->path)+19];
- std::strcpy(targetPath, pData->oscData->path);
- std::strcat(targetPath, "/set_default_value");
- lo_send(pData->oscData->target, targetPath, "iif", static_cast<int32_t>(pluginId), static_cast<int32_t>(index), value);
- }
- }
-
- void CarlaEngine::oscSend_control_set_current_program(const uint pluginId, const int32_t index) const
- {
- CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
- CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
- carla_debug("CarlaEngine::oscSend_control_set_current_program(%i, %i)", pluginId, index);
-
- if (pData->oscData->target != nullptr)
- {
- char targetPath[std::strlen(pData->oscData->path)+21];
- std::strcpy(targetPath, pData->oscData->path);
- std::strcat(targetPath, "/set_current_program");
- lo_send(pData->oscData->target, targetPath, "ii", static_cast<int32_t>(pluginId), index);
- }
- }
-
- void CarlaEngine::oscSend_control_set_current_midi_program(const uint pluginId, const int32_t index) const
- {
- CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
- CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
- carla_debug("CarlaEngine::oscSend_control_set_current_midi_program(%i, %i)", pluginId, index);
-
- if (pData->oscData->target != nullptr)
- {
- char targetPath[std::strlen(pData->oscData->path)+26];
- std::strcpy(targetPath, pData->oscData->path);
- std::strcat(targetPath, "/set_current_midi_program");
- lo_send(pData->oscData->target, targetPath, "ii", static_cast<int32_t>(pluginId), index);
- }
- }
-
- void CarlaEngine::oscSend_control_set_program_name(const uint pluginId, const uint32_t index, const char* const name) const
- {
- CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
- CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
- CARLA_SAFE_ASSERT_RETURN(name != nullptr,);
- carla_debug("CarlaEngine::oscSend_control_set_program_name(%i, %i, \"%s\")", pluginId, index, name);
-
- if (pData->oscData->target != nullptr)
- {
- char targetPath[std::strlen(pData->oscData->path)+18];
- std::strcpy(targetPath, pData->oscData->path);
- std::strcat(targetPath, "/set_program_name");
- lo_send(pData->oscData->target, targetPath, "iis", static_cast<int32_t>(pluginId), static_cast<int32_t>(index), name);
- }
- }
-
- 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
- {
- CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
- CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
- CARLA_SAFE_ASSERT_RETURN(name != nullptr,);
- carla_debug("CarlaEngine::oscSend_control_set_midi_program_data(%i, %i, %i, %i, \"%s\")", pluginId, index, bank, program, name);
-
- if (pData->oscData->target != nullptr)
- {
- char targetPath[std::strlen(pData->oscData->path)+23];
- std::strcpy(targetPath, pData->oscData->path);
- std::strcat(targetPath, "/set_midi_program_data");
- 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);
- }
- }
-
- void CarlaEngine::oscSend_control_note_on(const uint pluginId, const uint8_t channel, const uint8_t note, const uint8_t velo) const
- {
- CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
- CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
- CARLA_SAFE_ASSERT_RETURN(channel < MAX_MIDI_CHANNELS,);
- CARLA_SAFE_ASSERT_RETURN(note < MAX_MIDI_NOTE,);
- CARLA_SAFE_ASSERT_RETURN(velo < MAX_MIDI_VALUE,);
- carla_debug("CarlaEngine::oscSend_control_note_on(%i, %i, %i, %i)", pluginId, channel, note, velo);
-
- if (pData->oscData->target != nullptr)
- {
- char targetPath[std::strlen(pData->oscData->path)+9];
- std::strcpy(targetPath, pData->oscData->path);
- std::strcat(targetPath, "/note_on");
- 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));
- }
- }
-
- void CarlaEngine::oscSend_control_note_off(const uint pluginId, const uint8_t channel, const uint8_t note) const
- {
- CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
- CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
- CARLA_SAFE_ASSERT_RETURN(channel < MAX_MIDI_CHANNELS,);
- CARLA_SAFE_ASSERT_RETURN(note < MAX_MIDI_NOTE,);
- carla_debug("CarlaEngine::oscSend_control_note_off(%i, %i, %i)", pluginId, channel, note);
-
- if (pData->oscData->target != nullptr)
- {
- char targetPath[std::strlen(pData->oscData->path)+10];
- std::strcpy(targetPath, pData->oscData->path);
- std::strcat(targetPath, "/note_off");
- lo_send(pData->oscData->target, targetPath, "iii", static_cast<int32_t>(pluginId), static_cast<int32_t>(channel), static_cast<int32_t>(note));
- }
- }
-
- void CarlaEngine::oscSend_control_set_peaks(const uint pluginId) const
- {
- CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
- CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
-
- // TODO - try and see if we can get peaks[4] ref
- const EnginePluginData& epData(pData->plugins[pluginId]);
-
- if (pData->oscData->target != nullptr)
- {
- char targetPath[std::strlen(pData->oscData->path)+11];
- std::strcpy(targetPath, pData->oscData->path);
- std::strcat(targetPath, "/set_peaks");
- lo_send(pData->oscData->target, targetPath, "iffff", static_cast<int32_t>(pluginId), epData.insPeak[0], epData.insPeak[1], epData.outsPeak[0], epData.outsPeak[1]);
- }
- }
-
- void CarlaEngine::oscSend_control_exit() const
- {
- CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
- carla_debug("CarlaEngine::oscSend_control_exit()");
-
- if (pData->oscData->target != nullptr)
- {
- char targetPath[std::strlen(pData->oscData->path)+6];
- std::strcpy(targetPath, pData->oscData->path);
- std::strcat(targetPath, "/exit");
- lo_send(pData->oscData->target, targetPath, "");
- }
- }
- #endif
-
- // -----------------------------------------------------------------------
-
- #undef CARLA_SAFE_ASSERT_RETURN_ERR
-
- CARLA_BACKEND_END_NAMESPACE
|