|
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031 |
- /*
- * Carla Plugin Host
- * Copyright (C) 2011-2020 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.
- */
-
- #include "CarlaEngineGraph.hpp"
- #include "CarlaEngineInternal.hpp"
- #include "CarlaPlugin.hpp"
-
- #include "CarlaMathUtils.hpp"
- #include "CarlaScopeUtils.hpp"
-
- #include "CarlaMIDI.h"
-
- using water::jmax;
- using water::jmin;
- using water::AudioProcessor;
- using water::MidiBuffer;
- using water::String;
- using water::StringArray;
-
- CARLA_BACKEND_START_NAMESPACE
-
- // -----------------------------------------------------------------------
- // Fallback data
-
- static const PortNameToId kPortNameToIdFallback = { 0, 0, { '\0' }, { '\0' } };
- static /* */ PortNameToId kPortNameToIdFallbackNC = { 0, 0, { '\0' }, { '\0' } };
-
- // -----------------------------------------------------------------------
- // External Graph stuff
-
- static inline
- uint getExternalGraphPortIdFromName(const char* const shortname) noexcept
- {
- if (std::strcmp(shortname, "AudioIn1") == 0 || std::strcmp(shortname, "audio-in1") == 0)
- return kExternalGraphCarlaPortAudioIn1;
- if (std::strcmp(shortname, "AudioIn2") == 0 || std::strcmp(shortname, "audio-in2") == 0)
- return kExternalGraphCarlaPortAudioIn2;
- if (std::strcmp(shortname, "AudioOut1") == 0 || std::strcmp(shortname, "audio-out1") == 0)
- return kExternalGraphCarlaPortAudioOut1;
- if (std::strcmp(shortname, "AudioOut2") == 0 || std::strcmp(shortname, "audio-out2") == 0)
- return kExternalGraphCarlaPortAudioOut2;
- if (std::strcmp(shortname, "MidiIn") == 0 || std::strcmp(shortname, "midi-in") == 0)
- return kExternalGraphCarlaPortMidiIn;
- if (std::strcmp(shortname, "MidiOut") == 0 || std::strcmp(shortname, "midi-out") == 0)
- return kExternalGraphCarlaPortMidiOut;
-
- carla_stderr("CarlaBackend::getExternalGraphPortIdFromName(%s) - invalid short name", shortname);
- return kExternalGraphCarlaPortNull;
- }
-
- static inline
- const char* getExternalGraphFullPortNameFromId(const /*RackGraphCarlaPortIds*/ uint portId)
- {
- switch (portId)
- {
- case kExternalGraphCarlaPortAudioIn1:
- return "Carla:AudioIn1";
- case kExternalGraphCarlaPortAudioIn2:
- return "Carla:AudioIn2";
- case kExternalGraphCarlaPortAudioOut1:
- return "Carla:AudioOut1";
- case kExternalGraphCarlaPortAudioOut2:
- return "Carla:AudioOut2";
- case kExternalGraphCarlaPortMidiIn:
- return "Carla:MidiIn";
- case kExternalGraphCarlaPortMidiOut:
- return "Carla:MidiOut";
- //case kExternalGraphCarlaPortNull:
- //case kExternalGraphCarlaPortMax:
- // break;
- }
-
- carla_stderr("CarlaBackend::getExternalGraphFullPortNameFromId(%i) - invalid port id", portId);
- return nullptr;
- }
-
- // -----------------------------------------------------------------------
-
- ExternalGraphPorts::ExternalGraphPorts() noexcept
- : ins(),
- outs() {}
-
- const char* ExternalGraphPorts::getName(const bool isInput, const uint portId) const noexcept
- {
- for (LinkedList<PortNameToId>::Itenerator it = isInput ? ins.begin2() : outs.begin2(); it.valid(); it.next())
- {
- const PortNameToId& portNameToId(it.getValue(kPortNameToIdFallback));
- CARLA_SAFE_ASSERT_CONTINUE(portNameToId.group > 0);
-
- if (portNameToId.port == portId)
- return portNameToId.name;
- }
-
- return nullptr;
- }
-
- uint ExternalGraphPorts::getPortId(const bool isInput, const char portName[], bool* const ok) const noexcept
- {
- for (LinkedList<PortNameToId>::Itenerator it = isInput ? ins.begin2() : outs.begin2(); it.valid(); it.next())
- {
- const PortNameToId& portNameToId(it.getValue(kPortNameToIdFallback));
- CARLA_SAFE_ASSERT_CONTINUE(portNameToId.group > 0);
-
- if (std::strncmp(portNameToId.name, portName, STR_MAX) == 0)
- {
- if (ok != nullptr)
- *ok = true;
- return portNameToId.port;
- }
- }
-
- if (ok != nullptr)
- *ok = false;
- return 0;
- }
-
- // -----------------------------------------------------------------------
-
- ExternalGraph::ExternalGraph(CarlaEngine* const engine) noexcept
- : connections(),
- audioPorts(),
- midiPorts(),
- positions(),
- retCon(),
- kEngine(engine)
- {
- carla_zeroStruct(positions);
- }
-
- void ExternalGraph::clear() noexcept
- {
- connections.clear();
- audioPorts.ins.clear();
- audioPorts.outs.clear();
- midiPorts.ins.clear();
- midiPorts.outs.clear();
- }
-
- bool ExternalGraph::connect(const bool sendHost, const bool sendOSC,
- const uint groupA, const uint portA, const uint groupB, const uint portB) noexcept
- {
- uint otherGroup, otherPort, carlaPort;
-
- if (groupA == kExternalGraphGroupCarla)
- {
- CARLA_SAFE_ASSERT_RETURN(groupB != kExternalGraphGroupCarla, false);
-
- carlaPort = portA;
- otherGroup = groupB;
- otherPort = portB;
- }
- else
- {
- CARLA_SAFE_ASSERT_RETURN(groupB == kExternalGraphGroupCarla, false);
-
- carlaPort = portB;
- otherGroup = groupA;
- otherPort = portA;
- }
-
- CARLA_SAFE_ASSERT_RETURN(carlaPort > kExternalGraphCarlaPortNull && carlaPort < kExternalGraphCarlaPortMax, false);
- CARLA_SAFE_ASSERT_RETURN(otherGroup > kExternalGraphGroupCarla && otherGroup < kExternalGraphGroupMax, false);
-
- bool makeConnection = false;
-
- switch (carlaPort)
- {
- case kExternalGraphCarlaPortAudioIn1:
- CARLA_SAFE_ASSERT_RETURN(otherGroup == kExternalGraphGroupAudioIn, false);
- makeConnection = kEngine->connectExternalGraphPort(kExternalGraphConnectionAudioIn1, otherPort, nullptr);
- break;
-
- case kExternalGraphCarlaPortAudioIn2:
- CARLA_SAFE_ASSERT_RETURN(otherGroup == kExternalGraphGroupAudioIn, false);
- makeConnection = kEngine->connectExternalGraphPort(kExternalGraphConnectionAudioIn2, otherPort, nullptr);
- break;
-
- case kExternalGraphCarlaPortAudioOut1:
- CARLA_SAFE_ASSERT_RETURN(otherGroup == kExternalGraphGroupAudioOut, false);
- makeConnection = kEngine->connectExternalGraphPort(kExternalGraphConnectionAudioOut1, otherPort, nullptr);
- break;
-
- case kExternalGraphCarlaPortAudioOut2:
- CARLA_SAFE_ASSERT_RETURN(otherGroup == kExternalGraphGroupAudioOut, false);
- makeConnection = kEngine->connectExternalGraphPort(kExternalGraphConnectionAudioOut2, otherPort, nullptr);
- break;
-
- case kExternalGraphCarlaPortMidiIn:
- CARLA_SAFE_ASSERT_RETURN(otherGroup == kExternalGraphGroupMidiIn, false);
- if (const char* const portName = midiPorts.getName(true, otherPort))
- makeConnection = kEngine->connectExternalGraphPort(kExternalGraphConnectionMidiInput, 0, portName);
- break;
-
- case kExternalGraphCarlaPortMidiOut:
- CARLA_SAFE_ASSERT_RETURN(otherGroup == kExternalGraphGroupMidiOut, false);
- if (const char* const portName = midiPorts.getName(false, otherPort))
- makeConnection = kEngine->connectExternalGraphPort(kExternalGraphConnectionMidiOutput, 0, portName);
- break;
- }
-
- if (! makeConnection)
- {
- kEngine->setLastError("Invalid rack connection");
- return false;
- }
-
- ConnectionToId connectionToId;
- connectionToId.setData(++connections.lastId, groupA, portA, groupB, portB);
-
- char strBuf[STR_MAX+1];
- strBuf[STR_MAX] = '\0';
- std::snprintf(strBuf, STR_MAX, "%u:%u:%u:%u", groupA, portA, groupB, portB);
-
- kEngine->callback(sendHost, sendOSC,
- ENGINE_CALLBACK_PATCHBAY_CONNECTION_ADDED, connectionToId.id, 0, 0, 0, 0.0f, strBuf);
-
- connections.list.append(connectionToId);
- return true;
- }
-
- bool ExternalGraph::disconnect(const bool sendHost, const bool sendOSC,
- const uint connectionId) noexcept
- {
- CARLA_SAFE_ASSERT_RETURN(connections.list.count() > 0, false);
-
- for (LinkedList<ConnectionToId>::Itenerator it=connections.list.begin2(); it.valid(); it.next())
- {
- static const ConnectionToId fallback = { 0, 0, 0, 0, 0 };
-
- const ConnectionToId& connectionToId(it.getValue(fallback));
- CARLA_SAFE_ASSERT_CONTINUE(connectionToId.id > 0);
-
- if (connectionToId.id != connectionId)
- continue;
-
- uint otherGroup, otherPort, carlaPort;
-
- if (connectionToId.groupA == kExternalGraphGroupCarla)
- {
- CARLA_SAFE_ASSERT_RETURN(connectionToId.groupB != kExternalGraphGroupCarla, false);
-
- carlaPort = connectionToId.portA;
- otherGroup = connectionToId.groupB;
- otherPort = connectionToId.portB;
- }
- else
- {
- CARLA_SAFE_ASSERT_RETURN(connectionToId.groupB == kExternalGraphGroupCarla, false);
-
- carlaPort = connectionToId.portB;
- otherGroup = connectionToId.groupA;
- otherPort = connectionToId.portA;
- }
-
- CARLA_SAFE_ASSERT_RETURN(carlaPort > kExternalGraphCarlaPortNull && carlaPort < kExternalGraphCarlaPortMax, false);
- CARLA_SAFE_ASSERT_RETURN(otherGroup > kExternalGraphGroupCarla && otherGroup < kExternalGraphGroupMax, false);
-
- bool makeDisconnection = false;
-
- switch (carlaPort)
- {
- case kExternalGraphCarlaPortAudioIn1:
- makeDisconnection = kEngine->disconnectExternalGraphPort(kExternalGraphConnectionAudioIn1, otherPort, nullptr);
- break;
-
- case kExternalGraphCarlaPortAudioIn2:
- makeDisconnection = kEngine->disconnectExternalGraphPort(kExternalGraphConnectionAudioIn2, otherPort, nullptr);
- break;
-
- case kExternalGraphCarlaPortAudioOut1:
- makeDisconnection = kEngine->disconnectExternalGraphPort(kExternalGraphConnectionAudioOut1, otherPort, nullptr);
- break;
-
- case kExternalGraphCarlaPortAudioOut2:
- makeDisconnection = kEngine->disconnectExternalGraphPort(kExternalGraphConnectionAudioOut2, otherPort, nullptr);
- break;
-
- case kExternalGraphCarlaPortMidiIn:
- if (const char* const portName = midiPorts.getName(true, otherPort))
- makeDisconnection = kEngine->disconnectExternalGraphPort(kExternalGraphConnectionMidiInput, 0, portName);
- break;
-
- case kExternalGraphCarlaPortMidiOut:
- if (const char* const portName = midiPorts.getName(false, otherPort))
- makeDisconnection = kEngine->disconnectExternalGraphPort(kExternalGraphConnectionMidiOutput, 0, portName);
- break;
- }
-
- if (! makeDisconnection)
- {
- kEngine->setLastError("Invalid rack connection");
- return false;
- }
-
- kEngine->callback(sendHost, sendOSC,
- ENGINE_CALLBACK_PATCHBAY_CONNECTION_REMOVED, connectionToId.id, 0, 0, 0, 0.0f, nullptr);
-
- connections.list.remove(it);
- return true;
- }
-
- kEngine->setLastError("Failed to find connection");
- return false;
- }
-
- void ExternalGraph::setGroupPos(const bool sendHost, const bool sendOSC,
- const uint groupId, const int x1, const int y1, const int x2, const int y2)
- {
- CARLA_SAFE_ASSERT_UINT_RETURN(groupId >= kExternalGraphGroupCarla && groupId < kExternalGraphGroupMax, groupId,);
-
- const PatchbayPosition ppos = { true, x1, y1, x2, y2 };
- positions[groupId] = ppos;
-
- kEngine->callback(sendHost, sendOSC,
- ENGINE_CALLBACK_PATCHBAY_CLIENT_POSITION_CHANGED,
- groupId, x1, y1, x2, static_cast<float>(y2),
- nullptr);
- }
-
- void ExternalGraph::refresh(const bool sendHost, const bool sendOSC, const char* const deviceName)
- {
- CARLA_SAFE_ASSERT_RETURN(deviceName != nullptr,);
-
- const bool isRack = kEngine->getOptions().processMode == ENGINE_PROCESS_MODE_CONTINUOUS_RACK;
-
- // Main
- {
- kEngine->callback(sendHost, sendOSC,
- ENGINE_CALLBACK_PATCHBAY_CLIENT_ADDED,
- kExternalGraphGroupCarla,
- PATCHBAY_ICON_CARLA,
- MAIN_CARLA_PLUGIN_ID,
- 0, 0.0f,
- kEngine->getName());
-
- if (isRack)
- {
- kEngine->callback(sendHost, sendOSC,
- ENGINE_CALLBACK_PATCHBAY_PORT_ADDED,
- kExternalGraphGroupCarla,
- kExternalGraphCarlaPortAudioIn1,
- PATCHBAY_PORT_TYPE_AUDIO|PATCHBAY_PORT_IS_INPUT,
- 0, 0.0f,
- "audio-in1");
-
- kEngine->callback(sendHost, sendOSC,
- ENGINE_CALLBACK_PATCHBAY_PORT_ADDED,
- kExternalGraphGroupCarla,
- kExternalGraphCarlaPortAudioIn2,
- PATCHBAY_PORT_TYPE_AUDIO|PATCHBAY_PORT_IS_INPUT,
- 0, 0.0f,
- "audio-in2");
-
- kEngine->callback(sendHost, sendOSC,
- ENGINE_CALLBACK_PATCHBAY_PORT_ADDED,
- kExternalGraphGroupCarla,
- kExternalGraphCarlaPortAudioOut1,
- PATCHBAY_PORT_TYPE_AUDIO,
- 0, 0.0f,
- "audio-out1");
-
- kEngine->callback(sendHost, sendOSC,
- ENGINE_CALLBACK_PATCHBAY_PORT_ADDED,
- kExternalGraphGroupCarla,
- kExternalGraphCarlaPortAudioOut2,
- PATCHBAY_PORT_TYPE_AUDIO,
- 0, 0.0f,
- "audio-out2");
- }
-
- kEngine->callback(sendHost, sendOSC,
- ENGINE_CALLBACK_PATCHBAY_PORT_ADDED,
- kExternalGraphGroupCarla,
- kExternalGraphCarlaPortMidiIn,
- PATCHBAY_PORT_TYPE_MIDI|PATCHBAY_PORT_IS_INPUT,
- 0, 0.0f,
- "midi-in");
-
- kEngine->callback(sendHost, sendOSC,
- ENGINE_CALLBACK_PATCHBAY_PORT_ADDED,
- kExternalGraphGroupCarla,
- kExternalGraphCarlaPortMidiOut,
- PATCHBAY_PORT_TYPE_MIDI,
- 0, 0.0f,
- "midi-out");
- }
-
- char strBuf[STR_MAX+1];
- strBuf[STR_MAX] = '\0';
-
- if (isRack)
- {
- // Audio In
- if (deviceName[0] != '\0')
- std::snprintf(strBuf, STR_MAX, "Capture (%s)", deviceName);
- else
- std::strncpy(strBuf, "Capture", STR_MAX);
-
- kEngine->callback(sendHost, sendOSC,
- ENGINE_CALLBACK_PATCHBAY_CLIENT_ADDED,
- kExternalGraphGroupAudioIn,
- PATCHBAY_ICON_HARDWARE,
- -1,
- 0, 0.0f,
- strBuf);
-
- const CarlaString groupNameIn(strBuf);
-
- int h = 0;
- for (LinkedList<PortNameToId>::Itenerator it = audioPorts.ins.begin2(); it.valid(); it.next())
- {
- PortNameToId& portNameToId(it.getValue(kPortNameToIdFallbackNC));
- CARLA_SAFE_ASSERT_CONTINUE(portNameToId.group > 0);
-
- portNameToId.setFullName(groupNameIn + portNameToId.name);
-
- kEngine->callback(sendHost, sendOSC,
- ENGINE_CALLBACK_PATCHBAY_PORT_ADDED,
- kExternalGraphGroupAudioIn,
- ++h,
- PATCHBAY_PORT_TYPE_AUDIO,
- 0, 0.0f,
- portNameToId.name);
- }
-
- // Audio Out
- if (deviceName[0] != '\0')
- std::snprintf(strBuf, STR_MAX, "Playback (%s)", deviceName);
- else
- std::strncpy(strBuf, "Playback", STR_MAX);
-
- kEngine->callback(sendHost, sendOSC,
- ENGINE_CALLBACK_PATCHBAY_CLIENT_ADDED,
- kExternalGraphGroupAudioOut,
- PATCHBAY_ICON_HARDWARE,
- -1,
- 0, 0.0f,
- strBuf);
-
- const CarlaString groupNameOut(strBuf);
-
- h = 0;
- for (LinkedList<PortNameToId>::Itenerator it = audioPorts.outs.begin2(); it.valid(); it.next())
- {
- PortNameToId& portNameToId(it.getValue(kPortNameToIdFallbackNC));
- CARLA_SAFE_ASSERT_CONTINUE(portNameToId.group > 0);
-
- portNameToId.setFullName(groupNameOut + portNameToId.name);
-
- kEngine->callback(sendHost, sendOSC,
- ENGINE_CALLBACK_PATCHBAY_PORT_ADDED,
- kExternalGraphGroupAudioOut,
- ++h,
- PATCHBAY_PORT_TYPE_AUDIO|PATCHBAY_PORT_IS_INPUT,
- 0, 0.0f,
- portNameToId.name);
- }
- }
-
- // MIDI In
- {
- kEngine->callback(sendHost, sendOSC,
- ENGINE_CALLBACK_PATCHBAY_CLIENT_ADDED,
- kExternalGraphGroupMidiIn,
- PATCHBAY_ICON_HARDWARE,
- -1,
- 0, 0.0f,
- "Readable MIDI ports");
-
- const CarlaString groupNamePlus("Readable MIDI ports:");
-
- int h = 0;
- for (LinkedList<PortNameToId>::Itenerator it = midiPorts.ins.begin2(); it.valid(); it.next())
- {
- PortNameToId& portNameToId(it.getValue(kPortNameToIdFallbackNC));
- CARLA_SAFE_ASSERT_CONTINUE(portNameToId.group > 0);
-
- portNameToId.setFullName(groupNamePlus + portNameToId.name);
-
- kEngine->callback(sendHost, sendOSC,
- ENGINE_CALLBACK_PATCHBAY_PORT_ADDED,
- kExternalGraphGroupMidiIn,
- ++h,
- PATCHBAY_PORT_TYPE_MIDI,
- 0, 0.0f,
- portNameToId.name);
- }
- }
-
- // MIDI Out
- {
- kEngine->callback(sendHost, sendOSC,
- ENGINE_CALLBACK_PATCHBAY_CLIENT_ADDED,
- kExternalGraphGroupMidiOut,
- PATCHBAY_ICON_HARDWARE,
- -1,
- 0, 0.0f,
- "Writable MIDI ports");
-
- const CarlaString groupNamePlus("Writable MIDI ports:");
-
- int h = 0;
- for (LinkedList<PortNameToId>::Itenerator it = midiPorts.outs.begin2(); it.valid(); it.next())
- {
- PortNameToId& portNameToId(it.getValue(kPortNameToIdFallbackNC));
- CARLA_SAFE_ASSERT_CONTINUE(portNameToId.group > 0);
-
- portNameToId.setFullName(groupNamePlus + portNameToId.name);
-
- kEngine->callback(sendHost, sendOSC,
- ENGINE_CALLBACK_PATCHBAY_PORT_ADDED,
- kExternalGraphGroupMidiOut,
- ++h,
- PATCHBAY_PORT_TYPE_MIDI|PATCHBAY_PORT_IS_INPUT,
- 0, 0.0f,
- portNameToId.name);
- }
- }
- }
-
- const char* const* ExternalGraph::getConnections() const noexcept
- {
- if (connections.list.count() == 0)
- return nullptr;
-
- CarlaStringList connList;
-
- char strBuf[STR_MAX+1];
- strBuf[STR_MAX] = '\0';
-
- for (LinkedList<ConnectionToId>::Itenerator it=connections.list.begin2(); it.valid(); it.next())
- {
- static const ConnectionToId fallback = { 0, 0, 0, 0, 0 };
-
- const ConnectionToId& connectionToId(it.getValue(fallback));
- CARLA_SAFE_ASSERT_CONTINUE(connectionToId.id > 0);
-
- uint otherGroup, otherPort, carlaPort;
-
- if (connectionToId.groupA == kExternalGraphGroupCarla)
- {
- CARLA_SAFE_ASSERT_CONTINUE(connectionToId.groupB != kExternalGraphGroupCarla);
-
- carlaPort = connectionToId.portA;
- otherGroup = connectionToId.groupB;
- otherPort = connectionToId.portB;
- }
- else
- {
- CARLA_SAFE_ASSERT_CONTINUE(connectionToId.groupB == kExternalGraphGroupCarla);
-
- carlaPort = connectionToId.portB;
- otherGroup = connectionToId.groupA;
- otherPort = connectionToId.portA;
- }
-
- CARLA_SAFE_ASSERT_CONTINUE(carlaPort > kExternalGraphCarlaPortNull && carlaPort < kExternalGraphCarlaPortMax);
- CARLA_SAFE_ASSERT_CONTINUE(otherGroup > kExternalGraphGroupCarla && otherGroup < kExternalGraphGroupMax);
-
- switch (carlaPort)
- {
- case kExternalGraphCarlaPortAudioIn1:
- case kExternalGraphCarlaPortAudioIn2:
- std::snprintf(strBuf, STR_MAX, "AudioIn:%s", audioPorts.getName(true, otherPort));
- connList.append(strBuf);
- connList.append(getExternalGraphFullPortNameFromId(carlaPort));
- break;
-
- case kExternalGraphCarlaPortAudioOut1:
- case kExternalGraphCarlaPortAudioOut2:
- std::snprintf(strBuf, STR_MAX, "AudioOut:%s", audioPorts.getName(false, otherPort));
- connList.append(getExternalGraphFullPortNameFromId(carlaPort));
- connList.append(strBuf);
- break;
-
- case kExternalGraphCarlaPortMidiIn:
- std::snprintf(strBuf, STR_MAX, "MidiIn:%s", midiPorts.getName(true, otherPort));
- connList.append(strBuf);
- connList.append(getExternalGraphFullPortNameFromId(carlaPort));
- break;
-
- case kExternalGraphCarlaPortMidiOut:
- std::snprintf(strBuf, STR_MAX, "MidiOut:%s", midiPorts.getName(false, otherPort));
- connList.append(getExternalGraphFullPortNameFromId(carlaPort));
- connList.append(strBuf);
- break;
- }
- }
-
- if (connList.count() == 0)
- return nullptr;
-
- retCon = connList.toCharStringListPtr();
-
- return retCon;
- }
-
- bool ExternalGraph::getGroupFromName(const char* groupName, uint& groupId) const noexcept
- {
- CARLA_SAFE_ASSERT_RETURN(groupName != nullptr && groupName[0] != '\0', false);
-
- if (std::strcmp(groupName, "Carla") == 0)
- {
- groupId = kExternalGraphGroupCarla;
- return true;
- }
- if (std::strcmp(groupName, "AudioIn") == 0)
- {
- groupId = kExternalGraphGroupAudioIn;
- return true;
- }
- if (std::strcmp(groupName, "AudioOut") == 0)
- {
- groupId = kExternalGraphGroupAudioOut;
- return true;
- }
- if (std::strcmp(groupName, "MidiIn") == 0)
- {
- groupId = kExternalGraphGroupMidiIn;
- return true;
- }
- if (std::strcmp(groupName, "MidiOut") == 0)
- {
- groupId = kExternalGraphGroupMidiOut;
- return true;
- }
-
- return false;
- }
-
- bool ExternalGraph::getGroupAndPortIdFromFullName(const char* const fullPortName, uint& groupId, uint& portId) const noexcept
- {
- CARLA_SAFE_ASSERT_RETURN(fullPortName != nullptr && fullPortName[0] != '\0', false);
-
- if (std::strncmp(fullPortName, "Carla:", 6) == 0)
- {
- groupId = kExternalGraphGroupCarla;
- portId = getExternalGraphPortIdFromName(fullPortName+6);
-
- if (portId > kExternalGraphCarlaPortNull && portId < kExternalGraphCarlaPortMax)
- return true;
- }
- else if (std::strncmp(fullPortName, "AudioIn:", 8) == 0)
- {
- groupId = kExternalGraphGroupAudioIn;
-
- if (const char* const portName = fullPortName+8)
- {
- bool ok;
- portId = audioPorts.getPortId(true, portName, &ok);
- return ok;
- }
- }
- else if (std::strncmp(fullPortName, "AudioOut:", 9) == 0)
- {
- groupId = kExternalGraphGroupAudioOut;
-
- if (const char* const portName = fullPortName+9)
- {
- bool ok;
- portId = audioPorts.getPortId(false, portName, &ok);
- return ok;
- }
- }
- else if (std::strncmp(fullPortName, "MidiIn:", 7) == 0)
- {
- groupId = kExternalGraphGroupMidiIn;
-
- if (const char* const portName = fullPortName+7)
- {
- bool ok;
- portId = midiPorts.getPortId(true, portName, &ok);
- return ok;
- }
- }
- else if (std::strncmp(fullPortName, "MidiOut:", 8) == 0)
- {
- groupId = kExternalGraphGroupMidiOut;
-
- if (const char* const portName = fullPortName+8)
- {
- bool ok;
- portId = midiPorts.getPortId(false, portName, &ok);
- return ok;
- }
- }
-
- return false;
- }
-
- // -----------------------------------------------------------------------
- // RackGraph Buffers
-
- RackGraph::Buffers::Buffers() noexcept
- : mutex(),
- connectedIn1(),
- connectedIn2(),
- connectedOut1(),
- connectedOut2(),
- #ifdef CARLA_PROPER_CPP11_SUPPORT
- inBuf{nullptr, nullptr},
- inBufTmp{nullptr, nullptr},
- outBuf{nullptr, nullptr},
- #endif
- unusedBuf(nullptr)
- {
- #ifndef CARLA_PROPER_CPP11_SUPPORT
- inBuf[0] = inBuf[1] = nullptr;
- inBufTmp[0] = inBufTmp[1] = nullptr;
- outBuf[0] = outBuf[1] = nullptr;
- #endif
- }
-
- RackGraph::Buffers::~Buffers() noexcept
- {
- const CarlaRecursiveMutexLocker cml(mutex);
-
- if (inBuf[0] != nullptr) { delete[] inBuf[0]; inBuf[0] = nullptr; }
- if (inBuf[1] != nullptr) { delete[] inBuf[1]; inBuf[1] = nullptr; }
- if (inBufTmp[0] != nullptr) { delete[] inBufTmp[0]; inBufTmp[0] = nullptr; }
- if (inBufTmp[1] != nullptr) { delete[] inBufTmp[1]; inBufTmp[1] = nullptr; }
- if (outBuf[0] != nullptr) { delete[] outBuf[0]; outBuf[0] = nullptr; }
- if (outBuf[1] != nullptr) { delete[] outBuf[1]; outBuf[1] = nullptr; }
- if (unusedBuf != nullptr) { delete[] unusedBuf; unusedBuf = nullptr; }
-
- connectedIn1.clear();
- connectedIn2.clear();
- connectedOut1.clear();
- connectedOut2.clear();
- }
-
- void RackGraph::Buffers::setBufferSize(const uint32_t bufferSize, const bool createBuffers) noexcept
- {
- const CarlaRecursiveMutexLocker cml(mutex);
-
- if (inBuf[0] != nullptr) { delete[] inBuf[0]; inBuf[0] = nullptr; }
- if (inBuf[1] != nullptr) { delete[] inBuf[1]; inBuf[1] = nullptr; }
- if (inBufTmp[0] != nullptr) { delete[] inBufTmp[0]; inBufTmp[0] = nullptr; }
- if (inBufTmp[1] != nullptr) { delete[] inBufTmp[1]; inBufTmp[1] = nullptr; }
- if (outBuf[0] != nullptr) { delete[] outBuf[0]; outBuf[0] = nullptr; }
- if (outBuf[1] != nullptr) { delete[] outBuf[1]; outBuf[1] = nullptr; }
- if (unusedBuf != nullptr) { delete[] unusedBuf; unusedBuf = nullptr; }
-
- CARLA_SAFE_ASSERT_RETURN(bufferSize > 0,);
-
- try {
- inBufTmp[0] = new float[bufferSize];
- inBufTmp[1] = new float[bufferSize];
- unusedBuf = new float[bufferSize];
-
- if (createBuffers)
- {
- inBuf[0] = new float[bufferSize];
- inBuf[1] = new float[bufferSize];
- outBuf[0] = new float[bufferSize];
- outBuf[1] = new float[bufferSize];
- }
- }
- catch(...) {
- if (inBufTmp[0] != nullptr) { delete[] inBufTmp[0]; inBufTmp[0] = nullptr; }
- if (inBufTmp[1] != nullptr) { delete[] inBufTmp[1]; inBufTmp[1] = nullptr; }
- if (unusedBuf != nullptr) { delete[] unusedBuf; unusedBuf = nullptr; }
-
- if (createBuffers)
- {
- if (inBuf[0] != nullptr) { delete[] inBuf[0]; inBuf[0] = nullptr; }
- if (inBuf[1] != nullptr) { delete[] inBuf[1]; inBuf[1] = nullptr; }
- if (outBuf[0] != nullptr) { delete[] outBuf[0]; outBuf[0] = nullptr; }
- if (outBuf[1] != nullptr) { delete[] outBuf[1]; outBuf[1] = nullptr; }
- }
- return;
- }
-
- carla_zeroFloats(inBufTmp[0], bufferSize);
- carla_zeroFloats(inBufTmp[1], bufferSize);
-
- if (createBuffers)
- {
- carla_zeroFloats(inBuf[0], bufferSize);
- carla_zeroFloats(inBuf[1], bufferSize);
- carla_zeroFloats(outBuf[0], bufferSize);
- carla_zeroFloats(outBuf[1], bufferSize);
- }
- }
-
- // -----------------------------------------------------------------------
- // RackGraph
-
- RackGraph::RackGraph(CarlaEngine* const engine, const uint32_t ins, const uint32_t outs) noexcept
- : extGraph(engine),
- inputs(ins),
- outputs(outs),
- isOffline(false),
- audioBuffers(),
- kEngine(engine)
- {
- setBufferSize(engine->getBufferSize());
- }
-
- RackGraph::~RackGraph() noexcept
- {
- extGraph.clear();
- }
-
- void RackGraph::setBufferSize(const uint32_t bufferSize) noexcept
- {
- audioBuffers.setBufferSize(bufferSize, (inputs > 0 || outputs > 0));
- }
-
- void RackGraph::setOffline(const bool offline) noexcept
- {
- isOffline = offline;
- }
-
- bool RackGraph::connect(const uint groupA, const uint portA, const uint groupB, const uint portB) noexcept
- {
- return extGraph.connect(true, true, groupA, portA, groupB, portB);
- }
-
- bool RackGraph::disconnect(const uint connectionId) noexcept
- {
- return extGraph.disconnect(true, true, connectionId);
- }
-
- void RackGraph::refresh(const bool sendHost, const bool sendOSC, const bool, const char* const deviceName)
- {
- extGraph.refresh(sendHost, sendOSC, deviceName);
-
- char strBuf[STR_MAX+1];
- strBuf[STR_MAX] = '\0';
-
- // Connections
- const CarlaRecursiveMutexLocker cml(audioBuffers.mutex);
-
- for (LinkedList<uint>::Itenerator it = audioBuffers.connectedIn1.begin2(); it.valid(); it.next())
- {
- const uint& portId(it.getValue(0));
- CARLA_SAFE_ASSERT_CONTINUE(portId > 0);
- CARLA_SAFE_ASSERT_CONTINUE(portId <= extGraph.audioPorts.ins.count());
-
- ConnectionToId connectionToId;
- connectionToId.setData(++(extGraph.connections.lastId), kExternalGraphGroupAudioIn, portId, kExternalGraphGroupCarla, kExternalGraphCarlaPortAudioIn1);
-
- std::snprintf(strBuf, STR_MAX, "%i:%i:%i:%i", connectionToId.groupA, connectionToId.portA, connectionToId.groupB, connectionToId.portB);
-
- kEngine->callback(sendHost, sendOSC,
- ENGINE_CALLBACK_PATCHBAY_CONNECTION_ADDED,
- connectionToId.id,
- 0, 0, 0, 0.0f,
- strBuf);
-
- extGraph.connections.list.append(connectionToId);
- }
-
- for (LinkedList<uint>::Itenerator it = audioBuffers.connectedIn2.begin2(); it.valid(); it.next())
- {
- const uint& portId(it.getValue(0));
- CARLA_SAFE_ASSERT_CONTINUE(portId > 0);
- CARLA_SAFE_ASSERT_CONTINUE(portId <= extGraph.audioPorts.ins.count());
-
- ConnectionToId connectionToId;
- connectionToId.setData(++(extGraph.connections.lastId), kExternalGraphGroupAudioIn, portId, kExternalGraphGroupCarla, kExternalGraphCarlaPortAudioIn2);
-
- std::snprintf(strBuf, STR_MAX, "%i:%i:%i:%i", connectionToId.groupA, connectionToId.portA, connectionToId.groupB, connectionToId.portB);
-
- kEngine->callback(sendHost, sendOSC,
- ENGINE_CALLBACK_PATCHBAY_CONNECTION_ADDED,
- connectionToId.id,
- 0, 0, 0, 0.0f,
- strBuf);
-
- extGraph.connections.list.append(connectionToId);
- }
-
- for (LinkedList<uint>::Itenerator it = audioBuffers.connectedOut1.begin2(); it.valid(); it.next())
- {
- const uint& portId(it.getValue(0));
- CARLA_SAFE_ASSERT_CONTINUE(portId > 0);
- CARLA_SAFE_ASSERT_CONTINUE(portId <= extGraph.audioPorts.outs.count());
-
- ConnectionToId connectionToId;
- connectionToId.setData(++(extGraph.connections.lastId), kExternalGraphGroupCarla, kExternalGraphCarlaPortAudioOut1, kExternalGraphGroupAudioOut, portId);
-
- std::snprintf(strBuf, STR_MAX, "%i:%i:%i:%i", connectionToId.groupA, connectionToId.portA, connectionToId.groupB, connectionToId.portB);
-
- kEngine->callback(sendHost, sendOSC,
- ENGINE_CALLBACK_PATCHBAY_CONNECTION_ADDED,
- connectionToId.id,
- 0, 0, 0, 0.0f,
- strBuf);
-
- extGraph.connections.list.append(connectionToId);
- }
-
- for (LinkedList<uint>::Itenerator it = audioBuffers.connectedOut2.begin2(); it.valid(); it.next())
- {
- const uint& portId(it.getValue(0));
- CARLA_SAFE_ASSERT_CONTINUE(portId > 0);
- CARLA_SAFE_ASSERT_CONTINUE(portId <= extGraph.audioPorts.outs.count());
-
- ConnectionToId connectionToId;
- connectionToId.setData(++(extGraph.connections.lastId), kExternalGraphGroupCarla, kExternalGraphCarlaPortAudioOut2, kExternalGraphGroupAudioOut, portId);
-
- std::snprintf(strBuf, STR_MAX, "%i:%i:%i:%i", connectionToId.groupA, connectionToId.portA, connectionToId.groupB, connectionToId.portB);
-
- kEngine->callback(sendHost, sendOSC,
- ENGINE_CALLBACK_PATCHBAY_CONNECTION_ADDED,
- connectionToId.id,
- 0, 0, 0, 0.0f,
- strBuf);
-
- extGraph.connections.list.append(connectionToId);
- }
- }
-
- const char* const* RackGraph::getConnections() const noexcept
- {
- return extGraph.getConnections();
- }
-
- bool RackGraph::getGroupAndPortIdFromFullName(const char* const fullPortName, uint& groupId, uint& portId) const noexcept
- {
- return extGraph.getGroupAndPortIdFromFullName(fullPortName, groupId, portId);
- }
-
- void RackGraph::process(CarlaEngine::ProtectedData* const data, const float* inBufReal[2], float* outBufReal[2], const uint32_t frames)
- {
- CARLA_SAFE_ASSERT_RETURN(data != nullptr,);
- CARLA_SAFE_ASSERT_RETURN(data->events.in != nullptr,);
- CARLA_SAFE_ASSERT_RETURN(data->events.out != nullptr,);
-
- // safe copy
- float* const dummyBuf = audioBuffers.unusedBuf;
- float* const inBuf0 = audioBuffers.inBufTmp[0];
- float* const inBuf1 = audioBuffers.inBufTmp[1];
-
- // initialize audio inputs
- carla_copyFloats(inBuf0, inBufReal[0], frames);
- carla_copyFloats(inBuf1, inBufReal[1], frames);
-
- // initialize audio outputs (zero)
- carla_zeroFloats(outBufReal[0], frames);
- carla_zeroFloats(outBufReal[1], frames);
-
- // initialize event outputs (zero)
- carla_zeroStructs(data->events.out, kMaxEngineEventInternalCount);
-
- uint32_t oldAudioInCount = 0;
- uint32_t oldAudioOutCount = 0;
- uint32_t oldMidiOutCount = 0;
- bool processed = false;
-
- // process plugins
- for (uint i=0; i < data->curPluginCount; ++i)
- {
- CarlaPlugin* const plugin = data->plugins[i].plugin;
-
- if (plugin == nullptr || ! plugin->isEnabled() || ! plugin->tryLock(isOffline))
- continue;
-
- if (processed)
- {
- // initialize audio inputs (from previous outputs)
- carla_copyFloats(inBuf0, outBufReal[0], frames);
- carla_copyFloats(inBuf1, outBufReal[1], frames);
-
- // initialize audio outputs (zero)
- carla_zeroFloats(outBufReal[0], frames);
- carla_zeroFloats(outBufReal[1], frames);
-
- // if plugin has no midi out, add previous events
- if (oldMidiOutCount == 0 && data->events.in[0].type != kEngineEventTypeNull)
- {
- if (data->events.out[0].type != kEngineEventTypeNull)
- {
- // TODO: carefully add to input, sorted events
- //carla_stderr("TODO midi event mixing here %s", plugin->getName());
- }
- // else nothing needed
- }
- else
- {
- // initialize event inputs from previous outputs
- carla_copyStructs(data->events.in, data->events.out, kMaxEngineEventInternalCount);
-
- // initialize event outputs (zero)
- carla_zeroStructs(data->events.out, kMaxEngineEventInternalCount);
- }
- }
-
- oldAudioInCount = plugin->getAudioInCount();
- oldAudioOutCount = plugin->getAudioOutCount();
- oldMidiOutCount = plugin->getMidiOutCount();
-
- const uint32_t numInBufs = std::max(oldAudioInCount, 2U);
- const uint32_t numOutBufs = std::max(oldAudioOutCount, 2U);
-
- const float* inBuf[numInBufs];
- inBuf[0] = inBuf0;
- inBuf[1] = inBuf1;
-
- float* outBuf[numOutBufs];
- outBuf[0] = outBufReal[0];
- outBuf[1] = outBufReal[1];
-
- if (numInBufs > 2 || numOutBufs > 2)
- {
- carla_zeroFloats(dummyBuf, frames);
-
- for (uint32_t j=2; j<numInBufs; ++j)
- inBuf[j] = dummyBuf;
-
- for (uint32_t j=2; j<numOutBufs; ++j)
- outBuf[j] = dummyBuf;
- }
-
- // process
- plugin->initBuffers();
- plugin->process(inBuf, outBuf, nullptr, nullptr, frames);
- plugin->unlock();
-
- // if plugin has no audio inputs, add input buffer
- if (oldAudioInCount == 0)
- {
- carla_addFloats(outBufReal[0], inBuf0, frames);
- carla_addFloats(outBufReal[1], inBuf1, frames);
- }
-
- // if plugin only has 1 output, copy it to the 2nd
- if (oldAudioOutCount == 1)
- {
- carla_copyFloats(outBufReal[1], outBufReal[0], frames);
- }
-
- // set peaks
- {
- EnginePluginData& pluginData(data->plugins[i]);
-
- if (oldAudioInCount > 0)
- {
- pluginData.peaks[0] = carla_findMaxNormalizedFloat(inBuf0, frames);
- pluginData.peaks[1] = carla_findMaxNormalizedFloat(inBuf1, frames);
- }
- else
- {
- pluginData.peaks[0] = 0.0f;
- pluginData.peaks[1] = 0.0f;
- }
-
- if (oldAudioOutCount > 0)
- {
- pluginData.peaks[2] = carla_findMaxNormalizedFloat(outBufReal[0], frames);
- pluginData.peaks[3] = carla_findMaxNormalizedFloat(outBufReal[1], frames);
- }
- else
- {
- pluginData.peaks[2] = 0.0f;
- pluginData.peaks[3] = 0.0f;
- }
- }
-
- processed = true;
- }
- }
-
- void RackGraph::processHelper(CarlaEngine::ProtectedData* const data, const float* const* const inBuf, float* const* const outBuf, const uint32_t frames)
- {
- CARLA_SAFE_ASSERT_RETURN(audioBuffers.outBuf[1] != nullptr,);
-
- const CarlaRecursiveMutexLocker _cml(audioBuffers.mutex);
-
- if (inBuf != nullptr && inputs > 0)
- {
- bool noConnections = true;
-
- // connect input buffers
- for (LinkedList<uint>::Itenerator it = audioBuffers.connectedIn1.begin2(); it.valid(); it.next())
- {
- const uint& port(it.getValue(0));
- CARLA_SAFE_ASSERT_CONTINUE(port > 0);
- CARLA_SAFE_ASSERT_CONTINUE(port <= inputs);
-
- if (noConnections)
- {
- carla_copyFloats(audioBuffers.inBuf[0], inBuf[port], frames);
- noConnections = false;
- }
- else
- {
- carla_addFloats(audioBuffers.inBuf[0], inBuf[port], frames);
- }
- }
-
- if (noConnections)
- carla_zeroFloats(audioBuffers.inBuf[0], frames);
-
- noConnections = true;
-
- for (LinkedList<uint>::Itenerator it = audioBuffers.connectedIn2.begin2(); it.valid(); it.next())
- {
- const uint& port(it.getValue(0));
- CARLA_SAFE_ASSERT_CONTINUE(port > 0);
- CARLA_SAFE_ASSERT_CONTINUE(port <= inputs);
-
- if (noConnections)
- {
- carla_copyFloats(audioBuffers.inBuf[1], inBuf[port-1], frames);
- noConnections = false;
- }
- else
- {
- carla_addFloats(audioBuffers.inBuf[1], inBuf[port-1], frames);
- }
- }
-
- if (noConnections)
- carla_zeroFloats(audioBuffers.inBuf[1], frames);
- }
- else
- {
- carla_zeroFloats(audioBuffers.inBuf[0], frames);
- carla_zeroFloats(audioBuffers.inBuf[1], frames);
- }
-
- carla_zeroFloats(audioBuffers.outBuf[0], frames);
- carla_zeroFloats(audioBuffers.outBuf[1], frames);
-
- // process
- process(data, const_cast<const float**>(audioBuffers.inBuf), audioBuffers.outBuf, frames);
-
- // connect output buffers
- if (audioBuffers.connectedOut1.count() != 0)
- {
- for (LinkedList<uint>::Itenerator it = audioBuffers.connectedOut1.begin2(); it.valid(); it.next())
- {
- const uint& port(it.getValue(0));
- CARLA_SAFE_ASSERT_CONTINUE(port > 0);
- CARLA_SAFE_ASSERT_CONTINUE(port <= outputs);
-
- carla_addFloats(outBuf[port-1], audioBuffers.outBuf[0], frames);
- }
- }
-
- if (audioBuffers.connectedOut2.count() != 0)
- {
- for (LinkedList<uint>::Itenerator it = audioBuffers.connectedOut2.begin2(); it.valid(); it.next())
- {
- const uint& port(it.getValue(0));
- CARLA_SAFE_ASSERT_CONTINUE(port > 0);
- CARLA_SAFE_ASSERT_CONTINUE(port <= outputs);
-
- carla_addFloats(outBuf[port-1], audioBuffers.outBuf[1], frames);
- }
- }
- }
-
- // -----------------------------------------------------------------------
- // Patchbay Graph stuff
-
- static const uint32_t kMaxPortsPerPlugin = 255;
- static const uint32_t kAudioInputPortOffset = kMaxPortsPerPlugin*1;
- static const uint32_t kAudioOutputPortOffset = kMaxPortsPerPlugin*2;
- static const uint32_t kCVInputPortOffset = kMaxPortsPerPlugin*3;
- static const uint32_t kCVOutputPortOffset = kMaxPortsPerPlugin*4;
- static const uint32_t kMidiInputPortOffset = kMaxPortsPerPlugin*5;
- static const uint32_t kMidiOutputPortOffset = kMaxPortsPerPlugin*6;
- static const uint32_t kMaxPortOffset = kMaxPortsPerPlugin*7;
-
- static inline
- bool adjustPatchbayPortIdForWater(AudioProcessor::ChannelType& channelType, uint& portId)
- {
- CARLA_SAFE_ASSERT_RETURN(portId >= kAudioInputPortOffset, false);
- CARLA_SAFE_ASSERT_RETURN(portId < kMaxPortOffset, false);
-
- if (portId >= kMidiOutputPortOffset)
- {
- portId -= kMidiOutputPortOffset;
- channelType = AudioProcessor::ChannelTypeMIDI;
- return true;
- }
- if (portId >= kMidiInputPortOffset)
- {
- portId -= kMidiInputPortOffset;
- channelType = AudioProcessor::ChannelTypeMIDI;
- return true;
- }
- if (portId >= kCVOutputPortOffset)
- {
- portId -= kCVOutputPortOffset;
- channelType = AudioProcessor::ChannelTypeCV;
- return true;
- }
- if (portId >= kCVInputPortOffset)
- {
- portId -= kCVInputPortOffset;
- channelType = AudioProcessor::ChannelTypeCV;
- return true;
- }
- if (portId >= kAudioOutputPortOffset)
- {
- portId -= kAudioOutputPortOffset;
- channelType = AudioProcessor::ChannelTypeAudio;
- return true;
- }
- if (portId >= kAudioInputPortOffset)
- {
- portId -= kAudioInputPortOffset;
- channelType = AudioProcessor::ChannelTypeAudio;
- return true;
- }
-
- return false;
- }
-
- static inline
- const String getProcessorFullPortName(AudioProcessor* const proc, const uint32_t portId)
- {
- CARLA_SAFE_ASSERT_RETURN(proc != nullptr, String());
- CARLA_SAFE_ASSERT_RETURN(portId >= kAudioInputPortOffset, String());
- CARLA_SAFE_ASSERT_RETURN(portId < kMaxPortOffset, String());
-
- String fullPortName(proc->getName());
-
- /**/ if (portId >= kMidiOutputPortOffset)
- {
- CARLA_SAFE_ASSERT_RETURN(proc->getTotalNumOutputChannels(AudioProcessor::ChannelTypeMIDI) > 0, String());
- fullPortName += ":" + proc->getOutputChannelName(AudioProcessor::ChannelTypeMIDI,
- portId-kMidiOutputPortOffset);
- }
- else if (portId >= kMidiInputPortOffset)
- {
- CARLA_SAFE_ASSERT_RETURN(proc->getTotalNumInputChannels(AudioProcessor::ChannelTypeMIDI) > 0, String());
- fullPortName += ":" + proc->getInputChannelName(AudioProcessor::ChannelTypeMIDI,
- portId-kMidiInputPortOffset);
- }
- else if (portId >= kCVOutputPortOffset)
- {
- CARLA_SAFE_ASSERT_RETURN(proc->getTotalNumOutputChannels(AudioProcessor::ChannelTypeCV) > 0, String());
- fullPortName += ":" + proc->getOutputChannelName(AudioProcessor::ChannelTypeCV,
- portId-kCVOutputPortOffset);
- }
- else if (portId >= kCVInputPortOffset)
- {
- CARLA_SAFE_ASSERT_RETURN(proc->getTotalNumInputChannels(AudioProcessor::ChannelTypeCV) > 0, String());
- fullPortName += ":" + proc->getInputChannelName(AudioProcessor::ChannelTypeCV,
- portId-kCVInputPortOffset);
- }
- else if (portId >= kAudioOutputPortOffset)
- {
- CARLA_SAFE_ASSERT_RETURN(proc->getTotalNumOutputChannels(AudioProcessor::ChannelTypeAudio) > 0, String());
- fullPortName += ":" + proc->getOutputChannelName(AudioProcessor::ChannelTypeAudio,
- portId-kAudioOutputPortOffset);
- }
- else if (portId >= kAudioInputPortOffset)
- {
- CARLA_SAFE_ASSERT_RETURN(proc->getTotalNumInputChannels(AudioProcessor::ChannelTypeAudio) > 0, String());
- fullPortName += ":" + proc->getInputChannelName(AudioProcessor::ChannelTypeAudio,
- portId-kAudioInputPortOffset);
- }
- else
- {
- return String();
- }
-
- return fullPortName;
- }
-
- static inline
- void addNodeToPatchbay(const bool sendHost, const bool sendOSC, CarlaEngine* const engine,
- AudioProcessorGraph::Node* const node, const int pluginId, const AudioProcessor* const proc)
- {
- CARLA_SAFE_ASSERT_RETURN(engine != nullptr,);
- CARLA_SAFE_ASSERT_RETURN(node != nullptr,);
- CARLA_SAFE_ASSERT_RETURN(proc != nullptr,);
-
- const uint groupId = node->nodeId;
-
- engine->callback(sendHost, sendOSC,
- ENGINE_CALLBACK_PATCHBAY_CLIENT_ADDED,
- groupId,
- pluginId >= 0 ? PATCHBAY_ICON_PLUGIN : PATCHBAY_ICON_HARDWARE,
- pluginId,
- 0, 0.0f,
- proc->getName().toRawUTF8());
-
- for (uint i=0, numInputs=proc->getTotalNumInputChannels(AudioProcessor::ChannelTypeAudio); i<numInputs; ++i)
- {
- engine->callback(sendHost, sendOSC,
- ENGINE_CALLBACK_PATCHBAY_PORT_ADDED,
- groupId,
- static_cast<int>(kAudioInputPortOffset+i),
- PATCHBAY_PORT_TYPE_AUDIO|PATCHBAY_PORT_IS_INPUT,
- 0, 0.0f,
- proc->getInputChannelName(AudioProcessor::ChannelTypeAudio, i).toRawUTF8());
- }
-
- for (uint i=0, numOutputs=proc->getTotalNumOutputChannels(AudioProcessor::ChannelTypeAudio); i<numOutputs; ++i)
- {
- engine->callback(sendHost, sendOSC,
- ENGINE_CALLBACK_PATCHBAY_PORT_ADDED,
- groupId,
- static_cast<int>(kAudioOutputPortOffset+i),
- PATCHBAY_PORT_TYPE_AUDIO,
- 0, 0.0f,
- proc->getOutputChannelName(AudioProcessor::ChannelTypeAudio, i).toRawUTF8());
- }
-
- for (uint i=0, numInputs=proc->getTotalNumInputChannels(AudioProcessor::ChannelTypeCV); i<numInputs; ++i)
- {
- engine->callback(sendHost, sendOSC,
- ENGINE_CALLBACK_PATCHBAY_PORT_ADDED,
- groupId,
- static_cast<int>(kCVInputPortOffset+i),
- PATCHBAY_PORT_TYPE_CV|PATCHBAY_PORT_IS_INPUT,
- 0, 0.0f,
- proc->getInputChannelName(AudioProcessor::ChannelTypeCV, i).toRawUTF8());
- }
-
- for (uint i=0, numOutputs=proc->getTotalNumOutputChannels(AudioProcessor::ChannelTypeCV); i<numOutputs; ++i)
- {
- engine->callback(sendHost, sendOSC,
- ENGINE_CALLBACK_PATCHBAY_PORT_ADDED,
- groupId,
- static_cast<int>(kCVOutputPortOffset+i),
- PATCHBAY_PORT_TYPE_CV,
- 0, 0.0f,
- proc->getOutputChannelName(AudioProcessor::ChannelTypeCV, i).toRawUTF8());
- }
-
- for (uint i=0, numInputs=proc->getTotalNumInputChannels(AudioProcessor::ChannelTypeMIDI); i<numInputs; ++i)
- {
- engine->callback(sendHost, sendOSC,
- ENGINE_CALLBACK_PATCHBAY_PORT_ADDED,
- groupId,
- static_cast<int>(kMidiInputPortOffset+i),
- PATCHBAY_PORT_TYPE_MIDI|PATCHBAY_PORT_IS_INPUT,
- 0, 0.0f,
- proc->getInputChannelName(AudioProcessor::ChannelTypeMIDI, i).toRawUTF8());
- }
-
- for (uint i=0, numOutputs=proc->getTotalNumOutputChannels(AudioProcessor::ChannelTypeMIDI); i<numOutputs; ++i)
- {
- engine->callback(sendHost, sendOSC,
- ENGINE_CALLBACK_PATCHBAY_PORT_ADDED,
- groupId,
- static_cast<int>(kMidiOutputPortOffset+i),
- PATCHBAY_PORT_TYPE_MIDI,
- 0, 0.0f,
- proc->getOutputChannelName(AudioProcessor::ChannelTypeMIDI, i).toRawUTF8());
- }
-
- if (node->properties.contains("x1"))
- {
- engine->callback(sendHost, sendOSC,
- ENGINE_CALLBACK_PATCHBAY_CLIENT_POSITION_CHANGED,
- groupId,
- node->properties.getWithDefault("x1", 0),
- node->properties.getWithDefault("y1", 0),
- node->properties.getWithDefault("x2", 0),
- static_cast<float>(node->properties.getWithDefault("y2", 0)),
- nullptr);
- }
- }
-
- static inline
- void removeNodeFromPatchbay(const bool sendHost, const bool sendOSC, CarlaEngine* const engine,
- const uint32_t groupId, const AudioProcessor* const proc)
- {
- CARLA_SAFE_ASSERT_RETURN(engine != nullptr,);
- CARLA_SAFE_ASSERT_RETURN(proc != nullptr,);
-
- for (uint i=0, numInputs=proc->getTotalNumInputChannels(AudioProcessor::ChannelTypeAudio); i<numInputs; ++i)
- {
- engine->callback(sendHost, sendOSC,
- ENGINE_CALLBACK_PATCHBAY_PORT_REMOVED,
- groupId,
- static_cast<int>(kAudioInputPortOffset+i),
- 0, 0, 0.0f, nullptr);
- }
-
- for (uint i=0, numOutputs=proc->getTotalNumOutputChannels(AudioProcessor::ChannelTypeAudio); i<numOutputs; ++i)
- {
- engine->callback(sendHost, sendOSC,
- ENGINE_CALLBACK_PATCHBAY_PORT_REMOVED,
- groupId,
- static_cast<int>(kAudioOutputPortOffset+i),
- 0, 0, 0.0f,
- nullptr);
- }
-
- for (uint i=0, numInputs=proc->getTotalNumInputChannels(AudioProcessor::ChannelTypeCV); i<numInputs; ++i)
- {
- engine->callback(sendHost, sendOSC,
- ENGINE_CALLBACK_PATCHBAY_PORT_REMOVED,
- groupId,
- static_cast<int>(kCVInputPortOffset+i),
- 0, 0, 0.0f, nullptr);
- }
-
- for (uint i=0, numOutputs=proc->getTotalNumOutputChannels(AudioProcessor::ChannelTypeCV); i<numOutputs; ++i)
- {
- engine->callback(sendHost, sendOSC,
- ENGINE_CALLBACK_PATCHBAY_PORT_REMOVED,
- groupId,
- static_cast<int>(kCVOutputPortOffset+i),
- 0, 0, 0.0f,
- nullptr);
- }
-
- for (uint i=0, numInputs=proc->getTotalNumInputChannels(AudioProcessor::ChannelTypeMIDI); i<numInputs; ++i)
- {
- engine->callback(sendHost, sendOSC,
- ENGINE_CALLBACK_PATCHBAY_PORT_REMOVED,
- groupId,
- static_cast<int>(kMidiInputPortOffset+i),
- 0, 0, 0.0f, nullptr);
- }
-
- for (uint i=0, numOutputs=proc->getTotalNumOutputChannels(AudioProcessor::ChannelTypeMIDI); i<numOutputs; ++i)
- {
- engine->callback(sendHost, sendOSC,
- ENGINE_CALLBACK_PATCHBAY_PORT_REMOVED,
- groupId,
- static_cast<int>(kMidiOutputPortOffset+i),
- 0, 0, 0.0f, nullptr);
- }
-
- engine->callback(sendHost, sendOSC,
- ENGINE_CALLBACK_PATCHBAY_CLIENT_REMOVED,
- groupId,
- 0, 0, 0, 0.0f, nullptr);
- }
-
- // -----------------------------------------------------------------------
-
- class CarlaPluginInstance : public AudioProcessor
- {
- public:
- CarlaPluginInstance(CarlaEngine* const engine, CarlaPlugin* const plugin)
- : kEngine(engine),
- fPlugin(plugin)
- {
- CarlaEngineClient* const client = plugin->getEngineClient();
-
- setPlayConfigDetails(client->getPortCount(kEnginePortTypeAudio, true),
- client->getPortCount(kEnginePortTypeAudio, false),
- client->getPortCount(kEnginePortTypeCV, true),
- client->getPortCount(kEnginePortTypeCV, false),
- client->getPortCount(kEnginePortTypeEvent, true),
- client->getPortCount(kEnginePortTypeEvent, false),
- getSampleRate(), getBlockSize());
- }
-
- ~CarlaPluginInstance() override
- {
- }
-
- void reconfigure() override
- {
- CARLA_SAFE_ASSERT_RETURN(fPlugin != nullptr,);
-
- CarlaEngineClient* const client = fPlugin->getEngineClient();
- CARLA_SAFE_ASSERT_RETURN(client != nullptr,);
-
- carla_stdout("reconfigure called");
-
- setPlayConfigDetails(client->getPortCount(kEnginePortTypeAudio, true),
- client->getPortCount(kEnginePortTypeAudio, false),
- client->getPortCount(kEnginePortTypeCV, true),
- client->getPortCount(kEnginePortTypeCV, false),
- client->getPortCount(kEnginePortTypeEvent, true),
- client->getPortCount(kEnginePortTypeEvent, false),
- getSampleRate(), getBlockSize());
- }
-
- void invalidatePlugin() noexcept
- {
- fPlugin = nullptr;
- }
-
- // -------------------------------------------------------------------
-
- const String getName() const override
- {
- return fPlugin->getName();
- }
-
- void processBlockWithCV(AudioSampleBuffer& audio,
- const AudioSampleBuffer& cvIn,
- AudioSampleBuffer& cvOut,
- MidiBuffer& midi) override
- {
- if (fPlugin == nullptr || ! fPlugin->isEnabled() || ! fPlugin->tryLock(kEngine->isOffline()))
- {
- audio.clear();
- cvOut.clear();
- midi.clear();
- return;
- }
-
- if (CarlaEngineEventPort* const port = fPlugin->getDefaultEventInPort())
- {
- EngineEvent* const engineEvents(port->fBuffer);
- CARLA_SAFE_ASSERT_RETURN(engineEvents != nullptr,);
-
- carla_zeroStructs(engineEvents, kMaxEngineEventInternalCount);
- fillEngineEventsFromWaterMidiBuffer(engineEvents, midi);
- }
-
- midi.clear();
-
- fPlugin->initBuffers();
-
- const uint32_t numSamples = audio.getNumSamples();
- const uint32_t numAudioChan = audio.getNumChannels();
- const uint32_t numCVInChan = cvIn.getNumChannels();
- const uint32_t numCVOutChan = cvOut.getNumChannels();
-
- if (numAudioChan+numCVInChan+numCVOutChan == 0)
- {
- // nothing to process
- fPlugin->process(nullptr, nullptr, nullptr, nullptr, numSamples);
- }
- else if (numAudioChan != 0)
- {
- // processing audio, include code for peaks
- const uint32_t numChan2 = jmin(numAudioChan, 2U);
-
- if (fPlugin->getAudioInCount() == 0)
- audio.clear();
-
- float* audioBuffers[numAudioChan];
- float* cvOutBuffers[numCVOutChan];
- const float* cvInBuffers[numCVInChan];
-
- for (uint32_t i=0; i<numAudioChan; ++i)
- audioBuffers[i] = audio.getWritePointer(i);
- for (uint32_t i=0; i<numCVOutChan; ++i)
- cvOutBuffers[i] = cvOut.getWritePointer(i);
- for (uint32_t i=0; i<numCVInChan; ++i)
- cvInBuffers[i] = cvIn.getReadPointer(i);
-
- float inPeaks[2] = { 0.0f };
- float outPeaks[2] = { 0.0f };
-
- for (uint32_t i=0, count=jmin(fPlugin->getAudioInCount(), numChan2); i<count; ++i)
- inPeaks[i] = carla_findMaxNormalizedFloat(audioBuffers[i], numSamples);
-
- fPlugin->process(const_cast<const float**>(audioBuffers), audioBuffers,
- cvInBuffers, cvOutBuffers,
- numSamples);
-
- for (uint32_t i=0, count=jmin(fPlugin->getAudioOutCount(), numChan2); i<count; ++i)
- outPeaks[i] = carla_findMaxNormalizedFloat(audioBuffers[i], numSamples);
-
- kEngine->setPluginPeaksRT(fPlugin->getId(), inPeaks, outPeaks);
- }
- else
- {
- // processing CV only, skip audiopeaks
- float* cvOutBuffers[numCVOutChan];
- const float* cvInBuffers[numCVInChan];
-
- for (uint32_t i=0; i<numCVOutChan; ++i)
- cvOutBuffers[i] = cvOut.getWritePointer(i);
- for (uint32_t i=0; i<numCVInChan; ++i)
- cvInBuffers[i] = cvIn.getReadPointer(i);
-
- fPlugin->process(nullptr, nullptr,
- cvInBuffers, cvOutBuffers,
- numSamples);
- }
-
- midi.clear();
-
- if (CarlaEngineEventPort* const port = fPlugin->getDefaultEventOutPort())
- {
- /*const*/ EngineEvent* const engineEvents(port->fBuffer);
- CARLA_SAFE_ASSERT_RETURN(engineEvents != nullptr,);
-
- fillWaterMidiBufferFromEngineEvents(midi, engineEvents);
- carla_zeroStructs(engineEvents, kMaxEngineEventInternalCount);
- }
-
- fPlugin->unlock();
- }
-
- const String getInputChannelName(ChannelType t, uint i) const override
- {
- CarlaEngineClient* const client = fPlugin->getEngineClient();
-
- switch (t)
- {
- case ChannelTypeAudio:
- return client->getAudioPortName(true, i);
- case ChannelTypeCV:
- return client->getCVPortName(true, i);
- case ChannelTypeMIDI:
- return client->getEventPortName(true, i);
- }
-
- return String();
- }
-
- const String getOutputChannelName(ChannelType t, uint i) const override
- {
- CarlaEngineClient* const client(fPlugin->getEngineClient());
-
- switch (t)
- {
- case ChannelTypeAudio:
- return client->getAudioPortName(false, i);
- case ChannelTypeCV:
- return client->getCVPortName(false, i);
- case ChannelTypeMIDI:
- return client->getEventPortName(false, i);
- }
-
- return String();
- }
-
- void prepareToPlay(double, int) override {}
- void releaseResources() override {}
-
- bool acceptsMidi() const override { return fPlugin->getDefaultEventInPort() != nullptr; }
- bool producesMidi() const override { return fPlugin->getDefaultEventOutPort() != nullptr; }
-
- private:
- CarlaEngine* const kEngine;
- CarlaPlugin* fPlugin;
-
- CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(CarlaPluginInstance)
- };
-
- // -----------------------------------------------------------------------
- // Patchbay Graph
-
- class NamedAudioGraphIOProcessor : public AudioProcessorGraph::AudioGraphIOProcessor
- {
- public:
- NamedAudioGraphIOProcessor(const IODeviceType iotype)
- : AudioProcessorGraph::AudioGraphIOProcessor(iotype),
- inputNames(),
- outputNames() {}
-
- const String getInputChannelName (ChannelType, uint _index) const override
- {
- const int index = static_cast<int>(_index); // FIXME
- if (index < inputNames.size())
- return inputNames[index];
- return String("Playback ") + String(index+1);
- }
-
- const String getOutputChannelName (ChannelType, uint _index) const override
- {
- const int index = static_cast<int>(_index); // FIXME
- if (index < outputNames.size())
- return outputNames[index];
- return String("Capture ") + String(index+1);
- }
-
- void setNames(const bool setInputNames, const StringArray& names)
- {
- if (setInputNames)
- inputNames = names;
- else
- outputNames = names;
- }
-
- private:
- StringArray inputNames;
- StringArray outputNames;
- };
-
- PatchbayGraph::PatchbayGraph(CarlaEngine* const engine,
- const uint32_t audioIns, const uint32_t audioOuts,
- const uint32_t cvIns, const uint32_t cvOuts)
- : CarlaThread("PatchbayReorderThread"),
- connections(),
- graph(),
- audioBuffer(),
- cvInBuffer(),
- cvOutBuffer(),
- midiBuffer(),
- numAudioIns(carla_fixedValue(0U, 64U, audioIns)),
- numAudioOuts(carla_fixedValue(0U, 64U, audioOuts)),
- numCVIns(carla_fixedValue(0U, 8U, cvIns)),
- numCVOuts(carla_fixedValue(0U, 8U, cvOuts)),
- retCon(),
- usingExternalHost(false),
- usingExternalOSC(false),
- extGraph(engine),
- kEngine(engine)
- {
- const uint32_t bufferSize(engine->getBufferSize());
- const double sampleRate(engine->getSampleRate());
-
- graph.setPlayConfigDetails(numAudioIns, numAudioOuts,
- numCVIns, numCVOuts,
- 1, 1,
- sampleRate, static_cast<int>(bufferSize));
- graph.prepareToPlay(sampleRate, static_cast<int>(bufferSize));
-
- audioBuffer.setSize(jmax(numAudioIns, numAudioOuts), bufferSize);
- cvInBuffer.setSize(numCVIns, bufferSize);
- cvOutBuffer.setSize(numCVOuts, bufferSize);
-
- midiBuffer.ensureSize(kMaxEngineEventInternalCount*2);
- midiBuffer.clear();
-
- StringArray channelNames;
-
- switch (numAudioIns)
- {
- case 2:
- channelNames.add("Left");
- channelNames.add("Right");
- break;
- case 3:
- channelNames.add("Left");
- channelNames.add("Right");
- channelNames.add("Sidechain");
- break;
- }
-
- if (numAudioIns != 0)
- {
- NamedAudioGraphIOProcessor* const proc(
- new NamedAudioGraphIOProcessor(NamedAudioGraphIOProcessor::audioInputNode));
- proc->setNames(false, channelNames);
-
- AudioProcessorGraph::Node* const node(graph.addNode(proc));
- node->properties.set("isPlugin", false);
- node->properties.set("isOutput", false);
- node->properties.set("isAudio", true);
- node->properties.set("isCV", false);
- node->properties.set("isMIDI", false);
- node->properties.set("isOSC", false);
- }
-
- if (numAudioOuts != 0)
- {
- NamedAudioGraphIOProcessor* const proc(
- new NamedAudioGraphIOProcessor(NamedAudioGraphIOProcessor::audioOutputNode));
- proc->setNames(true, channelNames);
-
- AudioProcessorGraph::Node* const node(graph.addNode(proc));
- node->properties.set("isPlugin", false);
- node->properties.set("isOutput", false);
- node->properties.set("isAudio", true);
- node->properties.set("isCV", false);
- node->properties.set("isMIDI", false);
- node->properties.set("isOSC", false);
- }
-
- if (numCVIns != 0)
- {
- NamedAudioGraphIOProcessor* const proc(
- new NamedAudioGraphIOProcessor(NamedAudioGraphIOProcessor::cvInputNode));
- // proc->setNames(false, channelNames);
-
- AudioProcessorGraph::Node* const node(graph.addNode(proc));
- node->properties.set("isPlugin", false);
- node->properties.set("isOutput", false);
- node->properties.set("isAudio", false);
- node->properties.set("isCV", true);
- node->properties.set("isMIDI", false);
- node->properties.set("isOSC", false);
- }
-
- if (numCVOuts != 0)
- {
- NamedAudioGraphIOProcessor* const proc(
- new NamedAudioGraphIOProcessor(NamedAudioGraphIOProcessor::cvOutputNode));
- // proc->setNames(true, channelNames);
-
- AudioProcessorGraph::Node* const node(graph.addNode(proc));
- node->properties.set("isPlugin", false);
- node->properties.set("isOutput", false);
- node->properties.set("isAudio", false);
- node->properties.set("isCV", true);
- node->properties.set("isMIDI", false);
- node->properties.set("isOSC", false);
- }
-
- {
- NamedAudioGraphIOProcessor* const proc(
- new NamedAudioGraphIOProcessor(NamedAudioGraphIOProcessor::midiInputNode));
- AudioProcessorGraph::Node* const node(graph.addNode(proc));
- node->properties.set("isPlugin", false);
- node->properties.set("isOutput", false);
- node->properties.set("isAudio", false);
- node->properties.set("isCV", false);
- node->properties.set("isMIDI", true);
- node->properties.set("isOSC", false);
- }
-
- {
- NamedAudioGraphIOProcessor* const proc(
- new NamedAudioGraphIOProcessor(NamedAudioGraphIOProcessor::midiOutputNode));
- AudioProcessorGraph::Node* const node(graph.addNode(proc));
- node->properties.set("isPlugin", false);
- node->properties.set("isOutput", true);
- node->properties.set("isAudio", false);
- node->properties.set("isCV", false);
- node->properties.set("isMIDI", true);
- node->properties.set("isOSC", false);
- }
-
- startThread();
- }
-
- PatchbayGraph::~PatchbayGraph()
- {
- stopThread(-1);
-
- connections.clear();
- extGraph.clear();
-
- graph.releaseResources();
- graph.clear();
- audioBuffer.clear();
- cvInBuffer.clear();
- cvOutBuffer.clear();
- }
-
- void PatchbayGraph::setBufferSize(const uint32_t bufferSize)
- {
- const CarlaRecursiveMutexLocker cml1(graph.getReorderMutex());
-
- graph.releaseResources();
- graph.prepareToPlay(kEngine->getSampleRate(), static_cast<int>(bufferSize));
- audioBuffer.setSize(audioBuffer.getNumChannels(), bufferSize);
- cvInBuffer.setSize(numCVIns, bufferSize);
- cvOutBuffer.setSize(numCVOuts, bufferSize);
- }
-
- void PatchbayGraph::setSampleRate(const double sampleRate)
- {
- const CarlaRecursiveMutexLocker cml1(graph.getReorderMutex());
-
- graph.releaseResources();
- graph.prepareToPlay(sampleRate, static_cast<int>(kEngine->getBufferSize()));
- }
-
- void PatchbayGraph::setOffline(const bool offline)
- {
- graph.setNonRealtime(offline);
- }
-
- void PatchbayGraph::addPlugin(CarlaPlugin* const plugin)
- {
- CARLA_SAFE_ASSERT_RETURN(plugin != nullptr,);
- carla_debug("PatchbayGraph::addPlugin(%p)", plugin);
-
- CarlaPluginInstance* const instance(new CarlaPluginInstance(kEngine, plugin));
- AudioProcessorGraph::Node* const node(graph.addNode(instance));
- CARLA_SAFE_ASSERT_RETURN(node != nullptr,);
-
- const bool sendHost = !usingExternalHost;
- const bool sendOSC = !usingExternalOSC;
-
- plugin->setPatchbayNodeId(node->nodeId);
-
- node->properties.set("isPlugin", true);
- node->properties.set("pluginId", static_cast<int>(plugin->getId()));
-
- addNodeToPatchbay(sendHost, sendOSC, kEngine, node, static_cast<int>(plugin->getId()), instance);
- }
-
- void PatchbayGraph::replacePlugin(CarlaPlugin* const oldPlugin, CarlaPlugin* const newPlugin)
- {
- CARLA_SAFE_ASSERT_RETURN(oldPlugin != nullptr,);
- CARLA_SAFE_ASSERT_RETURN(newPlugin != nullptr,);
- CARLA_SAFE_ASSERT_RETURN(oldPlugin != newPlugin,);
- CARLA_SAFE_ASSERT_RETURN(oldPlugin->getId() == newPlugin->getId(),);
-
- AudioProcessorGraph::Node* const oldNode(graph.getNodeForId(oldPlugin->getPatchbayNodeId()));
- CARLA_SAFE_ASSERT_RETURN(oldNode != nullptr,);
-
- const bool sendHost = !usingExternalHost;
- const bool sendOSC = !usingExternalOSC;
-
- disconnectInternalGroup(oldNode->nodeId);
- removeNodeFromPatchbay(sendHost, sendOSC, kEngine, oldNode->nodeId, oldNode->getProcessor());
-
- ((CarlaPluginInstance*)oldNode->getProcessor())->invalidatePlugin();
-
- graph.removeNode(oldNode->nodeId);
-
- CarlaPluginInstance* const instance(new CarlaPluginInstance(kEngine, newPlugin));
- AudioProcessorGraph::Node* const node(graph.addNode(instance));
- CARLA_SAFE_ASSERT_RETURN(node != nullptr,);
-
- newPlugin->setPatchbayNodeId(node->nodeId);
-
- node->properties.set("isPlugin", true);
- node->properties.set("pluginId", static_cast<int>(newPlugin->getId()));
-
- addNodeToPatchbay(sendHost, sendOSC, kEngine, node, static_cast<int>(newPlugin->getId()), instance);
- }
-
- void PatchbayGraph::renamePlugin(CarlaPlugin* const plugin, const char* const newName)
- {
- CARLA_SAFE_ASSERT_RETURN(plugin != nullptr,);
- carla_debug("PatchbayGraph::renamePlugin(%p)", plugin, newName);
-
- AudioProcessorGraph::Node* const node(graph.getNodeForId(plugin->getPatchbayNodeId()));
- CARLA_SAFE_ASSERT_RETURN(node != nullptr,);
-
- const bool sendHost = !usingExternalHost;
- const bool sendOSC = !usingExternalOSC;
-
- kEngine->callback(sendHost, sendOSC,
- ENGINE_CALLBACK_PATCHBAY_CLIENT_RENAMED,
- node->nodeId,
- 0, 0, 0, 0.0f,
- newName);
- }
-
- void PatchbayGraph::reconfigureForCV(CarlaPlugin* const plugin, const uint portIndex, bool added)
- {
- CARLA_SAFE_ASSERT_RETURN(plugin != nullptr,);
- carla_debug("PatchbayGraph::reconfigureForCV(%p, %u, %s)", plugin, portIndex, bool2str(added));
-
- AudioProcessorGraph::Node* const node = graph.getNodeForId(plugin->getPatchbayNodeId());
- CARLA_SAFE_ASSERT_RETURN(node != nullptr,);
-
- CarlaPluginInstance* const proc = dynamic_cast<CarlaPluginInstance*>(node->getProcessor());
- CARLA_SAFE_ASSERT_RETURN(proc != nullptr,);
-
- const bool sendHost = !usingExternalHost;
- const bool sendOSC = !usingExternalOSC;
-
- const uint oldCvIn = proc->getTotalNumInputChannels(AudioProcessor::ChannelTypeCV);
- // const uint oldCvOut = proc->getTotalNumOutputChannels(AudioProcessor::ChannelTypeCV);
-
- {
- const CarlaRecursiveMutexLocker crml(graph.getCallbackLock());
-
- proc->reconfigure();
-
- graph.buildRenderingSequence();
- }
-
- const uint newCvIn = proc->getTotalNumInputChannels(AudioProcessor::ChannelTypeCV);
- // const uint newCvOut = proc->getTotalNumOutputChannels(AudioProcessor::ChannelTypeCV);
-
- if (added)
- {
- CARLA_SAFE_ASSERT_UINT2_RETURN(newCvIn > oldCvIn, newCvIn, oldCvIn,);
- // CARLA_SAFE_ASSERT_UINT2_RETURN(newCvOut >= oldCvOut, newCvOut, oldCvOut,);
-
- kEngine->callback(sendHost, sendOSC,
- ENGINE_CALLBACK_PATCHBAY_PORT_ADDED,
- node->nodeId,
- static_cast<int>(kCVInputPortOffset + plugin->getCVInCount() + portIndex),
- PATCHBAY_PORT_TYPE_CV|PATCHBAY_PORT_IS_INPUT,
- 0, 0.0f,
- proc->getInputChannelName(AudioProcessor::ChannelTypeCV, portIndex).toRawUTF8());
- }
- else
- {
- CARLA_SAFE_ASSERT_UINT2_RETURN(newCvIn < oldCvIn, newCvIn, oldCvIn,);
- // CARLA_SAFE_ASSERT_UINT2_RETURN(newCvOut <= oldCvOut, newCvOut, oldCvOut,);
-
- kEngine->callback(sendHost, sendOSC,
- ENGINE_CALLBACK_PATCHBAY_PORT_REMOVED,
- node->nodeId,
- static_cast<int>(kCVInputPortOffset + plugin->getCVInCount() + portIndex),
- 0, 0, 0.0f, nullptr);
- }
- }
-
- void PatchbayGraph::removePlugin(CarlaPlugin* const plugin)
- {
- CARLA_SAFE_ASSERT_RETURN(plugin != nullptr,);
- carla_debug("PatchbayGraph::removePlugin(%p)", plugin);
-
- AudioProcessorGraph::Node* const node(graph.getNodeForId(plugin->getPatchbayNodeId()));
- CARLA_SAFE_ASSERT_RETURN(node != nullptr,);
-
- const bool sendHost = !usingExternalHost;
- const bool sendOSC = !usingExternalOSC;
-
- disconnectInternalGroup(node->nodeId);
- removeNodeFromPatchbay(sendHost, sendOSC, kEngine, node->nodeId, node->getProcessor());
-
- ((CarlaPluginInstance*)node->getProcessor())->invalidatePlugin();
-
- // Fix plugin Ids properties
- for (uint i=plugin->getId()+1, count=kEngine->getCurrentPluginCount(); i<count; ++i)
- {
- CarlaPlugin* const plugin2(kEngine->getPlugin(i));
- CARLA_SAFE_ASSERT_BREAK(plugin2 != nullptr);
-
- if (AudioProcessorGraph::Node* const node2 = graph.getNodeForId(plugin2->getPatchbayNodeId()))
- {
- CARLA_SAFE_ASSERT_CONTINUE(node2->properties.getWithDefault("pluginId", -1) != water::var(-1));
- node2->properties.set("pluginId", static_cast<int>(i-1));
- }
- }
-
- CARLA_SAFE_ASSERT_RETURN(graph.removeNode(node->nodeId),);
- }
-
- void PatchbayGraph::removeAllPlugins()
- {
- carla_debug("PatchbayGraph::removeAllPlugins()");
-
- const bool sendHost = !usingExternalHost;
- const bool sendOSC = !usingExternalOSC;
-
- for (uint i=0, count=kEngine->getCurrentPluginCount(); i<count; ++i)
- {
- CarlaPlugin* const plugin(kEngine->getPlugin(i));
- CARLA_SAFE_ASSERT_CONTINUE(plugin != nullptr);
-
- AudioProcessorGraph::Node* const node(graph.getNodeForId(plugin->getPatchbayNodeId()));
- CARLA_SAFE_ASSERT_CONTINUE(node != nullptr);
-
- disconnectInternalGroup(node->nodeId);
- removeNodeFromPatchbay(sendHost, sendOSC, kEngine, node->nodeId, node->getProcessor());
-
- ((CarlaPluginInstance*)node->getProcessor())->invalidatePlugin();
-
- graph.removeNode(node->nodeId);
- }
- }
-
- bool PatchbayGraph::connect(const bool external,
- const uint groupA, const uint portA, const uint groupB, const uint portB)
- {
- if (external)
- return extGraph.connect(usingExternalHost, usingExternalOSC, groupA, portA, groupB, portB);
-
- uint adjustedPortA = portA;
- uint adjustedPortB = portB;
-
- AudioProcessor::ChannelType channelType;
- if (! adjustPatchbayPortIdForWater(channelType, adjustedPortA))
- return false;
- if (! adjustPatchbayPortIdForWater(channelType, adjustedPortB))
- return false;
-
- if (! graph.addConnection(channelType, groupA, adjustedPortA, groupB, adjustedPortB))
- {
- kEngine->setLastError("Failed from water");
- return false;
- }
-
- ConnectionToId connectionToId;
- connectionToId.setData(++connections.lastId, groupA, portA, groupB, portB);
-
- char strBuf[STR_MAX+1];
- strBuf[STR_MAX] = '\0';
- std::snprintf(strBuf, STR_MAX, "%u:%u:%u:%u", groupA, portA, groupB, portB);
-
- kEngine->callback(!usingExternalHost, !usingExternalOSC,
- ENGINE_CALLBACK_PATCHBAY_CONNECTION_ADDED,
- connectionToId.id,
- 0, 0, 0, 0.0f,
- strBuf);
-
- connections.list.append(connectionToId);
- return true;
- }
-
- bool PatchbayGraph::disconnect(const bool external, const uint connectionId)
- {
- if (external)
- return extGraph.disconnect(usingExternalHost, usingExternalOSC, connectionId);
-
- for (LinkedList<ConnectionToId>::Itenerator it=connections.list.begin2(); it.valid(); it.next())
- {
- static const ConnectionToId fallback = { 0, 0, 0, 0, 0 };
-
- const ConnectionToId& connectionToId(it.getValue(fallback));
- CARLA_SAFE_ASSERT_CONTINUE(connectionToId.id > 0);
-
- if (connectionToId.id != connectionId)
- continue;
-
- uint adjustedPortA = connectionToId.portA;
- uint adjustedPortB = connectionToId.portB;
-
- AudioProcessor::ChannelType channelType;
- if (! adjustPatchbayPortIdForWater(channelType, adjustedPortA))
- return false;
- if (! adjustPatchbayPortIdForWater(channelType, adjustedPortB))
- return false;
-
- if (! graph.removeConnection(channelType,
- connectionToId.groupA, adjustedPortA,
- connectionToId.groupB, adjustedPortB))
- return false;
-
- kEngine->callback(!usingExternalHost, !usingExternalOSC,
- ENGINE_CALLBACK_PATCHBAY_CONNECTION_REMOVED,
- connectionToId.id,
- 0, 0, 0, 0.0f,
- nullptr);
-
- connections.list.remove(it);
- return true;
- }
-
- kEngine->setLastError("Failed to find connection");
- return false;
- }
-
- void PatchbayGraph::disconnectInternalGroup(const uint groupId) noexcept
- {
- for (LinkedList<ConnectionToId>::Itenerator it=connections.list.begin2(); it.valid(); it.next())
- {
- static const ConnectionToId fallback = { 0, 0, 0, 0, 0 };
-
- const ConnectionToId& connectionToId(it.getValue(fallback));
- CARLA_SAFE_ASSERT_CONTINUE(connectionToId.id > 0);
-
- if (connectionToId.groupA != groupId && connectionToId.groupB != groupId)
- continue;
-
- /*
- uint adjustedPortA = connectionToId.portA;
- uint adjustedPortB = connectionToId.portB;
-
- AudioProcessor::ChannelType channelType;
- if (! adjustPatchbayPortIdForWater(adjustedPortA))
- return false;
- if (! adjustPatchbayPortIdForWater(adjustedPortB))
- return false;
-
- graph.removeConnection(connectionToId.groupA, static_cast<int>(adjustedPortA),
- connectionToId.groupB, static_cast<int>(adjustedPortB));
- */
-
- kEngine->callback(!usingExternalHost, !usingExternalOSC,
- ENGINE_CALLBACK_PATCHBAY_CONNECTION_REMOVED,
- connectionToId.id,
- 0, 0, 0, 0.0f,
- nullptr);
-
- connections.list.remove(it);
- }
- }
-
- void PatchbayGraph::setGroupPos(const bool sendHost, const bool sendOSC, const bool external,
- uint groupId, int x1, int y1, int x2, int y2)
- {
- if (external)
- return extGraph.setGroupPos(sendHost, sendOSC, groupId, x1, y1, x2, y2);
-
- AudioProcessorGraph::Node* const node(graph.getNodeForId(groupId));
- CARLA_SAFE_ASSERT_RETURN(node != nullptr,);
-
- node->properties.set("x1", x1);
- node->properties.set("y1", y1);
- node->properties.set("x2", x2);
- node->properties.set("y2", y2);
-
- kEngine->callback(sendHost, sendOSC,
- ENGINE_CALLBACK_PATCHBAY_CLIENT_POSITION_CHANGED,
- groupId, x1, y1, x2, static_cast<float>(y2),
- nullptr);
- }
-
- void PatchbayGraph::refresh(const bool sendHost, const bool sendOSC, const bool external, const char* const deviceName)
- {
- if (external)
- return extGraph.refresh(sendHost, sendOSC, deviceName);
-
- CARLA_SAFE_ASSERT_RETURN(deviceName != nullptr,);
-
- connections.clear();
- graph.removeIllegalConnections();
-
- for (int i=0, count=graph.getNumNodes(); i<count; ++i)
- {
- AudioProcessorGraph::Node* const node(graph.getNode(i));
- CARLA_SAFE_ASSERT_CONTINUE(node != nullptr);
-
- AudioProcessor* const proc(node->getProcessor());
- CARLA_SAFE_ASSERT_CONTINUE(proc != nullptr);
-
- int pluginId = -1;
-
- // plugin node
- if (node->properties.getWithDefault("isPlugin", false) == water::var(true))
- pluginId = node->properties.getWithDefault("pluginId", -1);
-
- addNodeToPatchbay(sendHost, sendOSC, kEngine, node, pluginId, proc);
- }
-
- char strBuf[STR_MAX+1];
- strBuf[STR_MAX] = '\0';
-
- for (size_t i=0, count=graph.getNumConnections(); i<count; ++i)
- {
- const AudioProcessorGraph::Connection* const conn(graph.getConnection(i));
- CARLA_SAFE_ASSERT_CONTINUE(conn != nullptr);
-
- const uint groupA = conn->sourceNodeId;
- const uint groupB = conn->destNodeId;
-
- uint portA = conn->sourceChannelIndex;
- uint portB = conn->destChannelIndex;
-
- switch (conn->channelType)
- {
- case AudioProcessor::ChannelTypeAudio:
- portA += kAudioOutputPortOffset;
- portB += kAudioInputPortOffset;
- break;
- case AudioProcessor::ChannelTypeCV:
- portA += kCVOutputPortOffset;
- portB += kCVInputPortOffset;
- break;
- case AudioProcessor::ChannelTypeMIDI:
- portA += kMidiOutputPortOffset;
- portB += kMidiInputPortOffset;
- break;
- }
-
- ConnectionToId connectionToId;
- connectionToId.setData(++connections.lastId, groupA, portA, groupB, portB);
-
- std::snprintf(strBuf, STR_MAX, "%i:%i:%i:%i", groupA, portA, groupB, portB);
-
- kEngine->callback(sendHost, sendOSC,
- ENGINE_CALLBACK_PATCHBAY_CONNECTION_ADDED,
- connectionToId.id,
- 0, 0, 0, 0.0f,
- strBuf);
-
- connections.list.append(connectionToId);
- }
- }
-
- const char* const* PatchbayGraph::getConnections(const bool external) const
- {
- if (external)
- return extGraph.getConnections();
-
- if (connections.list.count() == 0)
- return nullptr;
-
- CarlaStringList connList;
-
- for (LinkedList<ConnectionToId>::Itenerator it=connections.list.begin2(); it.valid(); it.next())
- {
- static const ConnectionToId fallback = { 0, 0, 0, 0, 0 };
-
- const ConnectionToId& connectionToId(it.getValue(fallback));
- CARLA_SAFE_ASSERT_CONTINUE(connectionToId.id > 0);
-
- AudioProcessorGraph::Node* const nodeA(graph.getNodeForId(connectionToId.groupA));
- CARLA_SAFE_ASSERT_CONTINUE(nodeA != nullptr);
-
- AudioProcessorGraph::Node* const nodeB(graph.getNodeForId(connectionToId.groupB));
- CARLA_SAFE_ASSERT_CONTINUE(nodeB != nullptr);
-
- AudioProcessor* const procA(nodeA->getProcessor());
- CARLA_SAFE_ASSERT_CONTINUE(procA != nullptr);
-
- AudioProcessor* const procB(nodeB->getProcessor());
- CARLA_SAFE_ASSERT_CONTINUE(procB != nullptr);
-
- String fullPortNameA(getProcessorFullPortName(procA, connectionToId.portA));
- CARLA_SAFE_ASSERT_CONTINUE(fullPortNameA.isNotEmpty());
-
- String fullPortNameB(getProcessorFullPortName(procB, connectionToId.portB));
- CARLA_SAFE_ASSERT_CONTINUE(fullPortNameB.isNotEmpty());
-
- connList.append(fullPortNameA.toRawUTF8());
- connList.append(fullPortNameB.toRawUTF8());
- }
-
- if (connList.count() == 0)
- return nullptr;
-
- retCon = connList.toCharStringListPtr();
-
- return retCon;
- }
-
- const CarlaEngine::PatchbayPosition* PatchbayGraph::getPositions(bool external, uint& count) const
- {
- CarlaEngine::PatchbayPosition* ret;
-
- if (external)
- {
- try {
- ret = new CarlaEngine::PatchbayPosition[kExternalGraphGroupMax];
- } CARLA_SAFE_EXCEPTION_RETURN("new CarlaEngine::PatchbayPosition", nullptr);
-
- count = 0;
-
- for (uint i=kExternalGraphGroupCarla; i<kExternalGraphGroupMax; ++i)
- {
- const PatchbayPosition& eppos(extGraph.positions[i]);
-
- if (! eppos.active)
- continue;
-
- CarlaEngine::PatchbayPosition& ppos(ret[count++]);
-
- switch (i)
- {
- case kExternalGraphGroupCarla:
- ppos.name = "Carla";
- break;
- case kExternalGraphGroupAudioIn:
- ppos.name = "AudioIn";
- break;
- case kExternalGraphGroupAudioOut:
- ppos.name = "AudioOut";
- break;
- case kExternalGraphGroupMidiIn:
- ppos.name = "MidiIn";
- break;
- case kExternalGraphGroupMidiOut:
- ppos.name = "MidiOut";
- break;
- }
- ppos.dealloc = false;
- ppos.pluginId = -1;
-
- ppos.x1 = eppos.x1;
- ppos.y1 = eppos.y1;
- ppos.x2 = eppos.x2;
- ppos.y2 = eppos.y2;
- }
-
- return ret;
- }
- else
- {
- const int numNodes = graph.getNumNodes();
- CARLA_SAFE_ASSERT_RETURN(numNodes > 0, nullptr);
-
- try {
- ret = new CarlaEngine::PatchbayPosition[numNodes];
- } CARLA_SAFE_EXCEPTION_RETURN("new CarlaEngine::PatchbayPosition", nullptr);
-
- count = 0;
-
- for (int i=numNodes; --i >= 0;)
- {
- AudioProcessorGraph::Node* const node(graph.getNode(i));
- CARLA_SAFE_ASSERT_CONTINUE(node != nullptr);
-
- if (! node->properties.contains("x1"))
- continue;
-
- AudioProcessor* const proc(node->getProcessor());
- CARLA_SAFE_ASSERT_CONTINUE(proc != nullptr);
-
- CarlaEngine::PatchbayPosition& ppos(ret[count++]);
-
- ppos.name = carla_strdup(proc->getName().toRawUTF8());
- ppos.dealloc = true;
- ppos.pluginId = node->properties.getWithDefault("pluginId", -1);
-
- ppos.x1 = node->properties.getWithDefault("x1", 0);
- ppos.y1 = node->properties.getWithDefault("y1", 0);
- ppos.x2 = node->properties.getWithDefault("x2", 0);
- ppos.y2 = node->properties.getWithDefault("y2", 0);
- }
-
- return ret;
- }
- }
-
- bool PatchbayGraph::getGroupFromName(bool external, const char* groupName, uint& groupId) const
- {
- if (external)
- return extGraph.getGroupFromName(groupName, groupId);
-
- for (int i=0, count=graph.getNumNodes(); i<count; ++i)
- {
- AudioProcessorGraph::Node* const node(graph.getNode(i));
- CARLA_SAFE_ASSERT_CONTINUE(node != nullptr);
-
- AudioProcessor* const proc(node->getProcessor());
- CARLA_SAFE_ASSERT_CONTINUE(proc != nullptr);
-
- if (proc->getName() != groupName)
- continue;
-
- groupId = node->nodeId;
- return true;
- }
-
- return false;
- }
-
- bool PatchbayGraph::getGroupAndPortIdFromFullName(const bool external, const char* const fullPortName, uint& groupId, uint& portId) const
- {
- if (external)
- return extGraph.getGroupAndPortIdFromFullName(fullPortName, groupId, portId);
-
- String groupName(String(fullPortName).upToFirstOccurrenceOf(":", false, false));
- String portName(String(fullPortName).fromFirstOccurrenceOf(":", false, false));
-
- for (int i=0, count=graph.getNumNodes(); i<count; ++i)
- {
- AudioProcessorGraph::Node* const node(graph.getNode(i));
- CARLA_SAFE_ASSERT_CONTINUE(node != nullptr);
-
- AudioProcessor* const proc(node->getProcessor());
- CARLA_SAFE_ASSERT_CONTINUE(proc != nullptr);
-
- if (proc->getName() != groupName)
- continue;
-
- groupId = node->nodeId;
-
- for (uint j=0, numInputs=proc->getTotalNumInputChannels(AudioProcessor::ChannelTypeAudio); j<numInputs; ++j)
- {
- if (proc->getInputChannelName(AudioProcessor::ChannelTypeAudio, j) != portName)
- continue;
-
- portId = kAudioInputPortOffset+j;
- return true;
- }
-
- for (uint j=0, numOutputs=proc->getTotalNumOutputChannels(AudioProcessor::ChannelTypeAudio); j<numOutputs; ++j)
- {
- if (proc->getOutputChannelName(AudioProcessor::ChannelTypeAudio, j) != portName)
- continue;
-
- portId = kAudioOutputPortOffset+j;
- return true;
- }
-
- for (uint j=0, numInputs=proc->getTotalNumInputChannels(AudioProcessor::ChannelTypeCV); j<numInputs; ++j)
- {
- if (proc->getInputChannelName(AudioProcessor::ChannelTypeCV, j) != portName)
- continue;
-
- portId = kCVInputPortOffset+j;
- return true;
- }
-
- for (uint j=0, numOutputs=proc->getTotalNumOutputChannels(AudioProcessor::ChannelTypeCV); j<numOutputs; ++j)
- {
- if (proc->getOutputChannelName(AudioProcessor::ChannelTypeCV, j) != portName)
- continue;
-
- portId = kCVOutputPortOffset+j;
- return true;
- }
-
- for (uint j=0, numInputs=proc->getTotalNumInputChannels(AudioProcessor::ChannelTypeMIDI); j<numInputs; ++j)
- {
- if (proc->getInputChannelName(AudioProcessor::ChannelTypeMIDI, j) != portName)
- continue;
-
- portId = kMidiInputPortOffset+j;
- return true;
- }
-
- for (uint j=0, numOutputs=proc->getTotalNumOutputChannels(AudioProcessor::ChannelTypeMIDI); j<numOutputs; ++j)
- {
- if (proc->getOutputChannelName(AudioProcessor::ChannelTypeMIDI, j) != portName)
- continue;
-
- portId = kMidiOutputPortOffset+j;
- return true;
- }
- }
-
- return false;
- }
-
- void PatchbayGraph::process(CarlaEngine::ProtectedData* const data,
- const float* const* const inBuf,
- float* const* const outBuf,
- const uint32_t frames)
- {
- CARLA_SAFE_ASSERT_RETURN(data != nullptr,);
- CARLA_SAFE_ASSERT_RETURN(data->events.in != nullptr,);
- CARLA_SAFE_ASSERT_RETURN(data->events.out != nullptr,);
- CARLA_SAFE_ASSERT_RETURN(frames > 0,);
-
- // put events in water buffer
- {
- midiBuffer.clear();
- fillWaterMidiBufferFromEngineEvents(midiBuffer, data->events.in);
- }
-
- // set audio and cv buffer size, needed for water internals
- if (! audioBuffer.setSizeRT(frames))
- return;
- if (! cvInBuffer.setSizeRT(frames))
- return;
- if (! cvOutBuffer.setSizeRT(frames))
- return;
-
- // put carla audio and cv in water buffer
- {
- uint32_t i=0;
-
- for (; i < numAudioIns; ++i) {
- CARLA_SAFE_ASSERT_BREAK(inBuf[i]);
- audioBuffer.copyFrom(i, 0, inBuf[i], frames);
- }
-
- for (uint32_t j=0; j < numCVIns; ++j, ++i) {
- CARLA_SAFE_ASSERT_BREAK(inBuf[i]);
- cvInBuffer.copyFrom(j, 0, inBuf[i], frames);
- }
-
- // clear remaining channels
- for (uint32_t j=numAudioIns, count=audioBuffer.getNumChannels(); j < count; ++j)
- audioBuffer.clear(j, 0, frames);
-
- for (uint32_t j=0; j < numCVOuts; ++j)
- cvOutBuffer.clear(j, 0, frames);
- }
-
- // ready to go!
- graph.processBlockWithCV(audioBuffer, cvInBuffer, cvOutBuffer, midiBuffer);
-
- // put water audio and cv in carla buffer
- {
- uint32_t i=0;
-
- for (; i < numAudioOuts; ++i)
- carla_copyFloats(outBuf[i], audioBuffer.getReadPointer(i), frames);
-
- for (uint32_t j=0; j < numCVOuts; ++j, ++i)
- carla_copyFloats(outBuf[i], cvOutBuffer.getReadPointer(j), frames);
- }
-
- // put water events in carla buffer
- {
- carla_zeroStructs(data->events.out, kMaxEngineEventInternalCount);
- fillEngineEventsFromWaterMidiBuffer(data->events.out, midiBuffer);
- midiBuffer.clear();
- }
- }
-
- void PatchbayGraph::run()
- {
- while (! shouldThreadExit())
- {
- carla_msleep(100);
- graph.reorderNowIfNeeded();
- }
- }
-
- // -----------------------------------------------------------------------
- // InternalGraph
-
- EngineInternalGraph::EngineInternalGraph(CarlaEngine* const engine) noexcept
- : fIsRack(false),
- fIsReady(false),
- fRack(nullptr),
- kEngine(engine) {}
-
- EngineInternalGraph::~EngineInternalGraph() noexcept
- {
- CARLA_SAFE_ASSERT(! fIsReady);
- CARLA_SAFE_ASSERT(fRack == nullptr);
- }
-
- void EngineInternalGraph::create(const uint32_t audioIns, const uint32_t audioOuts,
- const uint32_t cvIns, const uint32_t cvOuts)
- {
- fIsRack = (kEngine->getOptions().processMode == ENGINE_PROCESS_MODE_CONTINUOUS_RACK);
-
- if (fIsRack)
- {
- CARLA_SAFE_ASSERT_RETURN(fRack == nullptr,);
- fRack = new RackGraph(kEngine, audioIns, audioOuts);
- }
- else
- {
- CARLA_SAFE_ASSERT_RETURN(fPatchbay == nullptr,);
- fPatchbay = new PatchbayGraph(kEngine, audioIns, audioOuts, cvIns, cvOuts);
- }
-
- fIsReady = true;
- }
-
- void EngineInternalGraph::destroy() noexcept
- {
- if (! fIsReady)
- {
- CARLA_SAFE_ASSERT(fRack == nullptr);
- return;
- }
-
- if (fIsRack)
- {
- CARLA_SAFE_ASSERT_RETURN(fRack != nullptr,);
- delete fRack;
- fRack = nullptr;
- }
- else
- {
- CARLA_SAFE_ASSERT_RETURN(fPatchbay != nullptr,);
- delete fPatchbay;
- fPatchbay = nullptr;
- }
-
- fIsReady = false;
- }
-
- void EngineInternalGraph::setBufferSize(const uint32_t bufferSize)
- {
- CarlaScopedValueSetter<volatile bool> svs(fIsReady, false, true);
-
- if (fIsRack)
- {
- CARLA_SAFE_ASSERT_RETURN(fRack != nullptr,);
- fRack->setBufferSize(bufferSize);
- }
- else
- {
- CARLA_SAFE_ASSERT_RETURN(fPatchbay != nullptr,);
- fPatchbay->setBufferSize(bufferSize);
- }
- }
-
- void EngineInternalGraph::setSampleRate(const double sampleRate)
- {
- CarlaScopedValueSetter<volatile bool> svs(fIsReady, false, true);
-
- if (fIsRack)
- {
- CARLA_SAFE_ASSERT_RETURN(fRack != nullptr,);
- }
- else
- {
- CARLA_SAFE_ASSERT_RETURN(fPatchbay != nullptr,);
- fPatchbay->setSampleRate(sampleRate);
- }
- }
-
- void EngineInternalGraph::setOffline(const bool offline)
- {
- CarlaScopedValueSetter<volatile bool> svs(fIsReady, false, true);
-
- if (fIsRack)
- {
- CARLA_SAFE_ASSERT_RETURN(fRack != nullptr,);
- fRack->setOffline(offline);
- }
- else
- {
- CARLA_SAFE_ASSERT_RETURN(fPatchbay != nullptr,);
- fPatchbay->setOffline(offline);
- }
- }
-
- bool EngineInternalGraph::isReady() const noexcept
- {
- return fIsReady;
- }
-
- RackGraph* EngineInternalGraph::getRackGraph() const noexcept
- {
- CARLA_SAFE_ASSERT_RETURN(fIsRack, nullptr);
- return fRack;
- }
-
- PatchbayGraph* EngineInternalGraph::getPatchbayGraph() const noexcept
- {
- CARLA_SAFE_ASSERT_RETURN(! fIsRack, nullptr);
- return fPatchbay;
- }
-
- PatchbayGraph* EngineInternalGraph::getPatchbayGraphOrNull() const noexcept
- {
- return fIsRack ? nullptr : fPatchbay;
- }
-
- void EngineInternalGraph::process(CarlaEngine::ProtectedData* const data, const float* const* const inBuf, float* const* const outBuf, const uint32_t frames)
- {
- if (fIsRack)
- {
- CARLA_SAFE_ASSERT_RETURN(fRack != nullptr,);
- fRack->processHelper(data, inBuf, outBuf, frames);
- }
- else
- {
- CARLA_SAFE_ASSERT_RETURN(fPatchbay != nullptr,);
- fPatchbay->process(data, inBuf, outBuf, frames);
- }
- }
-
- void EngineInternalGraph::processRack(CarlaEngine::ProtectedData* const data, const float* inBuf[2], float* outBuf[2], const uint32_t frames)
- {
- CARLA_SAFE_ASSERT_RETURN(fIsRack,);
- CARLA_SAFE_ASSERT_RETURN(fRack != nullptr,);
-
- fRack->process(data, inBuf, outBuf, frames);
- }
-
- // -----------------------------------------------------------------------
- // used for internal patchbay mode
-
- void EngineInternalGraph::addPlugin(CarlaPlugin* const plugin)
- {
- CARLA_SAFE_ASSERT_RETURN(fPatchbay != nullptr,);
- fPatchbay->addPlugin(plugin);
- }
-
- void EngineInternalGraph::replacePlugin(CarlaPlugin* const oldPlugin, CarlaPlugin* const newPlugin)
- {
- CARLA_SAFE_ASSERT_RETURN(fPatchbay != nullptr,);
- fPatchbay->replacePlugin(oldPlugin, newPlugin);
- }
-
- void EngineInternalGraph::renamePlugin(CarlaPlugin* const plugin, const char* const newName)
- {
- CARLA_SAFE_ASSERT_RETURN(fPatchbay != nullptr,);
- fPatchbay->renamePlugin(plugin, newName);
- }
-
- void EngineInternalGraph::removePlugin(CarlaPlugin* const plugin)
- {
- CARLA_SAFE_ASSERT_RETURN(fPatchbay != nullptr,);
- fPatchbay->removePlugin(plugin);
- }
-
- void EngineInternalGraph::removeAllPlugins()
- {
- CARLA_SAFE_ASSERT_RETURN(fPatchbay != nullptr,);
- fPatchbay->removeAllPlugins();
- }
-
- bool EngineInternalGraph::isUsingExternalHost() const noexcept
- {
- if (fIsRack)
- return true;
-
- CARLA_SAFE_ASSERT_RETURN(fPatchbay != nullptr, false);
- return fPatchbay->usingExternalHost;
- }
-
- bool EngineInternalGraph::isUsingExternalOSC() const noexcept
- {
- if (fIsRack)
- return true;
-
- CARLA_SAFE_ASSERT_RETURN(fPatchbay != nullptr, false);
- return fPatchbay->usingExternalOSC;
- }
-
- void EngineInternalGraph::setUsingExternalHost(const bool usingExternal) noexcept
- {
- CARLA_SAFE_ASSERT_RETURN(! fIsRack,);
- CARLA_SAFE_ASSERT_RETURN(fPatchbay != nullptr,);
- fPatchbay->usingExternalHost = usingExternal;
- }
-
- void EngineInternalGraph::setUsingExternalOSC(const bool usingExternal) noexcept
- {
- CARLA_SAFE_ASSERT_RETURN(! fIsRack,);
- CARLA_SAFE_ASSERT_RETURN(fPatchbay != nullptr,);
- fPatchbay->usingExternalOSC = usingExternal;
- }
-
- // -----------------------------------------------------------------------
- // CarlaEngine Patchbay stuff
-
- bool CarlaEngine::patchbayConnect(const bool external,
- const uint groupA, const uint portA,
- const uint groupB, const uint portB)
- {
- CARLA_SAFE_ASSERT_RETURN(pData->options.processMode == ENGINE_PROCESS_MODE_CONTINUOUS_RACK || pData->options.processMode == ENGINE_PROCESS_MODE_PATCHBAY, false);
- CARLA_SAFE_ASSERT_RETURN(pData->graph.isReady(), false);
- carla_debug("CarlaEngine::patchbayConnect(%u, %u, %u, %u)", groupA, portA, groupB, portB);
-
- if (pData->options.processMode == ENGINE_PROCESS_MODE_CONTINUOUS_RACK)
- {
- RackGraph* const graph = pData->graph.getRackGraph();
- CARLA_SAFE_ASSERT_RETURN(graph != nullptr, false);
-
- return graph->connect(groupA, portA, groupB, portB);
- }
- else
- {
- PatchbayGraph* const graph = pData->graph.getPatchbayGraph();
- CARLA_SAFE_ASSERT_RETURN(graph != nullptr, false);
-
- return graph->connect(external, groupA, portA, groupB, portB);
- }
- }
-
- bool CarlaEngine::patchbayDisconnect(const bool external, const uint connectionId)
- {
- CARLA_SAFE_ASSERT_RETURN(pData->options.processMode == ENGINE_PROCESS_MODE_CONTINUOUS_RACK || pData->options.processMode == ENGINE_PROCESS_MODE_PATCHBAY, false);
- CARLA_SAFE_ASSERT_RETURN(pData->graph.isReady(), false);
- carla_debug("CarlaEngine::patchbayDisconnect(%u)", connectionId);
-
- if (pData->options.processMode == ENGINE_PROCESS_MODE_CONTINUOUS_RACK)
- {
- RackGraph* const graph = pData->graph.getRackGraph();
- CARLA_SAFE_ASSERT_RETURN(graph != nullptr, false);
-
- return graph->disconnect(connectionId);
- }
- else
- {
- PatchbayGraph* const graph = pData->graph.getPatchbayGraph();
- CARLA_SAFE_ASSERT_RETURN(graph != nullptr, false);
-
- return graph->disconnect(external, connectionId);
- }
- }
-
- bool CarlaEngine::patchbaySetGroupPos(const bool sendHost, const bool sendOSC, const bool external,
- const uint groupId, const int x1, const int y1, const int x2, const int y2)
- {
- CARLA_SAFE_ASSERT_RETURN(pData->options.processMode == ENGINE_PROCESS_MODE_CONTINUOUS_RACK || pData->options.processMode == ENGINE_PROCESS_MODE_PATCHBAY, false);
- CARLA_SAFE_ASSERT_RETURN(pData->graph.isReady(), false);
- carla_debug("CarlaEngine::patchbaySetGroupPos(%u, %i, %i, %i, %i)", groupId, x1, y1, x2, y2);
-
- if (pData->options.processMode == ENGINE_PROCESS_MODE_CONTINUOUS_RACK)
- {
- // we don't bother to save position in this case, there is only midi in/out
- return true;
- }
- else
- {
- PatchbayGraph* const graph = pData->graph.getPatchbayGraph();
- CARLA_SAFE_ASSERT_RETURN(graph != nullptr, false);
-
- graph->setGroupPos(sendHost, sendOSC, external, groupId, x1, y1, x2, y2);
- return true;
- }
- }
-
- bool CarlaEngine::patchbayRefresh(const bool sendHost, const bool sendOSC, const bool external)
- {
- // subclasses should handle this
- CARLA_SAFE_ASSERT_RETURN(! external, false);
-
- if (pData->options.processMode == ENGINE_PROCESS_MODE_CONTINUOUS_RACK)
- {
- // This is implemented in engine subclasses
- setLastError("Unsupported operation");
- return false;
- }
-
- if (pData->options.processMode == ENGINE_PROCESS_MODE_PATCHBAY)
- {
- PatchbayGraph* const graph = pData->graph.getPatchbayGraph();
- CARLA_SAFE_ASSERT_RETURN(graph != nullptr, false);
-
- graph->refresh(sendHost, sendOSC, external, "");
- return true;
- }
-
- setLastError("Unsupported operation");
- return false;
- }
-
- // -----------------------------------------------------------------------
- // Patchbay stuff
-
- const char* const* CarlaEngine::getPatchbayConnections(const bool external) const
- {
- CARLA_SAFE_ASSERT_RETURN(pData->graph.isReady(), nullptr);
- carla_debug("CarlaEngine::getPatchbayConnections(%s)", bool2str(external));
-
- if (pData->options.processMode == ENGINE_PROCESS_MODE_CONTINUOUS_RACK)
- {
- RackGraph* const graph = pData->graph.getRackGraph();
- CARLA_SAFE_ASSERT_RETURN(graph != nullptr, nullptr);
- CARLA_SAFE_ASSERT_RETURN(external, nullptr);
-
- return graph->getConnections();
- }
- else
- {
- PatchbayGraph* const graph = pData->graph.getPatchbayGraph();
- CARLA_SAFE_ASSERT_RETURN(graph != nullptr, nullptr);
-
- return graph->getConnections(external);
- }
-
- return nullptr;
- }
-
- const CarlaEngine::PatchbayPosition* CarlaEngine::getPatchbayPositions(bool external, uint& count) const
- {
- CARLA_SAFE_ASSERT_RETURN(pData->graph.isReady(), nullptr);
- carla_debug("CarlaEngine::getPatchbayPositions(%s)", bool2str(external));
-
- if (pData->options.processMode == ENGINE_PROCESS_MODE_PATCHBAY)
- {
- PatchbayGraph* const graph = pData->graph.getPatchbayGraph();
- CARLA_SAFE_ASSERT_RETURN(graph != nullptr, nullptr);
-
- return graph->getPositions(external, count);
- }
-
- return nullptr;
- }
-
- void CarlaEngine::restorePatchbayConnection(const bool external,
- const char* const sourcePort,
- const char* const targetPort)
- {
- CARLA_SAFE_ASSERT_RETURN(pData->graph.isReady(),);
- CARLA_SAFE_ASSERT_RETURN(sourcePort != nullptr && sourcePort[0] != '\0',);
- CARLA_SAFE_ASSERT_RETURN(targetPort != nullptr && targetPort[0] != '\0',);
- carla_debug("CarlaEngine::restorePatchbayConnection(%s, \"%s\", \"%s\")", bool2str(external), sourcePort, targetPort);
-
- uint groupA, portA;
- uint groupB, portB;
-
- if (pData->options.processMode == ENGINE_PROCESS_MODE_CONTINUOUS_RACK)
- {
- RackGraph* const graph = pData->graph.getRackGraph();
- CARLA_SAFE_ASSERT_RETURN(graph != nullptr,);
- CARLA_SAFE_ASSERT_RETURN(external,);
-
- if (! graph->getGroupAndPortIdFromFullName(sourcePort, groupA, portA))
- return;
- if (! graph->getGroupAndPortIdFromFullName(targetPort, groupB, portB))
- return;
-
- graph->connect(groupA, portA, groupB, portB);
- }
- else
- {
- PatchbayGraph* const graph = pData->graph.getPatchbayGraph();
- CARLA_SAFE_ASSERT_RETURN(graph != nullptr,);
-
- if (! graph->getGroupAndPortIdFromFullName(external, sourcePort, groupA, portA))
- return;
- if (! graph->getGroupAndPortIdFromFullName(external, targetPort, groupB, portB))
- return;
-
- graph->connect(external, groupA, portA, groupB, portB);
- }
- }
-
- void CarlaEngine::restorePatchbayGroupPosition(const bool external, const PatchbayPosition& ppos)
- {
- CARLA_SAFE_ASSERT_RETURN(pData->graph.isReady(),);
- CARLA_SAFE_ASSERT_RETURN(ppos.name != nullptr && ppos.name[0] != '\0',);
-
- if (pData->options.processMode == ENGINE_PROCESS_MODE_PATCHBAY)
- {
- PatchbayGraph* const graph = pData->graph.getPatchbayGraph();
- CARLA_SAFE_ASSERT_RETURN(graph != nullptr,);
-
- uint groupId;
- CARLA_SAFE_ASSERT_RETURN(graph->getGroupFromName(external, ppos.name, groupId),);
-
- graph->setGroupPos(true, true, external, groupId, ppos.x1, ppos.y1, ppos.x2, ppos.y2);
- }
- }
-
- // -----------------------------------------------------------------------
-
- bool CarlaEngine::connectExternalGraphPort(const uint connectionType, const uint portId, const char* const portName)
- {
- CARLA_SAFE_ASSERT_RETURN(connectionType != 0 || (portName != nullptr && portName[0] != '\0'), false);
- CARLA_SAFE_ASSERT_RETURN(pData->options.processMode == ENGINE_PROCESS_MODE_CONTINUOUS_RACK, false);
-
- RackGraph* const graph(pData->graph.getRackGraph());
- CARLA_SAFE_ASSERT_RETURN(graph != nullptr, false);
-
- const CarlaRecursiveMutexLocker cml(graph->audioBuffers.mutex);
-
- switch (connectionType)
- {
- case kExternalGraphConnectionAudioIn1:
- return graph->audioBuffers.connectedIn1.append(portId);
- case kExternalGraphConnectionAudioIn2:
- return graph->audioBuffers.connectedIn2.append(portId);
- case kExternalGraphConnectionAudioOut1:
- return graph->audioBuffers.connectedOut1.append(portId);
- case kExternalGraphConnectionAudioOut2:
- return graph->audioBuffers.connectedOut2.append(portId);
- }
-
- return false;
- }
-
- bool CarlaEngine::disconnectExternalGraphPort(const uint connectionType, const uint portId, const char* const portName)
- {
- CARLA_SAFE_ASSERT_RETURN(connectionType != 0 || (portName != nullptr && portName[0] != '\0'), false);
- CARLA_SAFE_ASSERT_RETURN(pData->options.processMode == ENGINE_PROCESS_MODE_CONTINUOUS_RACK, false);
-
- RackGraph* const graph(pData->graph.getRackGraph());
- CARLA_SAFE_ASSERT_RETURN(graph != nullptr, false);
-
- const CarlaRecursiveMutexLocker cml(graph->audioBuffers.mutex);
-
- switch (connectionType)
- {
- case kExternalGraphConnectionAudioIn1:
- return graph->audioBuffers.connectedIn1.removeOne(portId);
- case kExternalGraphConnectionAudioIn2:
- return graph->audioBuffers.connectedIn2.removeOne(portId);
- case kExternalGraphConnectionAudioOut1:
- return graph->audioBuffers.connectedOut1.removeOne(portId);
- case kExternalGraphConnectionAudioOut2:
- return graph->audioBuffers.connectedOut2.removeOne(portId);
- }
-
- return false;
- }
-
- // -----------------------------------------------------------------------
-
- CARLA_BACKEND_END_NAMESPACE
|