|
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755 |
- /*
- * Carla Plugin
- * Copyright (C) 2011-2023 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 "CarlaPluginInternal.hpp"
- #include "CarlaEngine.hpp"
-
- #include "CarlaBackendUtils.hpp"
- #include "CarlaBase64Utils.hpp"
- #include "CarlaMathUtils.hpp"
- #include "CarlaMIDI.h"
- #include "CarlaPluginUI.hpp"
- #include "CarlaScopeUtils.hpp"
- #include "CarlaStringList.hpp"
-
- #include <ctime>
-
- #include "water/files/File.h"
- #include "water/streams/MemoryOutputStream.h"
- #include "water/xml/XmlDocument.h"
- #include "water/xml/XmlElement.h"
-
- using water::CharPointer_UTF8;
- using water::File;
- using water::MemoryOutputStream;
- using water::Result;
- using water::String;
- using water::XmlDocument;
- using water::XmlElement;
-
- CARLA_BACKEND_START_NAMESPACE
-
- // -------------------------------------------------------------------------------------------------------------------
- // Fallback data
-
- static const ParameterData kParameterDataNull = { PARAMETER_UNKNOWN, 0x0, PARAMETER_NULL, -1, 0, CONTROL_INDEX_NONE, 0.0f, 1.0f, 0x0 };
- static const ParameterRanges kParameterRangesNull = { 0.0f, 0.0f, 1.0f, 0.01f, 0.0001f, 0.1f };
- static const MidiProgramData kMidiProgramDataNull = { 0, 0, nullptr };
-
- static const CustomData kCustomDataFallback = { nullptr, nullptr, nullptr };
- static /* */ CustomData kCustomDataFallbackNC = { nullptr, nullptr, nullptr };
- static const PluginPostRtEvent kPluginPostRtEventFallback = { kPluginPostRtEventNull, false, {} };
-
- // -------------------------------------------------------------------------------------------------------------------
- // ParamSymbol struct, needed for CarlaPlugin::loadStateSave()
-
- struct ParamSymbol {
- int32_t index;
- const char* symbol;
-
- ParamSymbol(const uint32_t i, const char* const s)
- : index(static_cast<int32_t>(i)),
- symbol(carla_strdup(s)) {}
-
- ~ParamSymbol() noexcept
- {
- CARLA_SAFE_ASSERT_RETURN(symbol != nullptr,)
-
- delete[] symbol;
- symbol = nullptr;
- }
-
- #ifdef CARLA_PROPER_CPP11_SUPPORT
- ParamSymbol() = delete;
- CARLA_DECLARE_NON_COPYABLE(ParamSymbol)
- #endif
- };
-
- // -------------------------------------------------------------------------------------------------------------------
- // Constructor and destructor
-
- CarlaPlugin::CarlaPlugin(CarlaEngine* const engine, const uint id)
- : pData(new ProtectedData(engine, id))
- {
- CARLA_SAFE_ASSERT_RETURN(engine != nullptr,);
- CARLA_SAFE_ASSERT(id < engine->getMaxPluginNumber());
- carla_debug("CarlaPlugin::CarlaPlugin(%p, %i)", engine, id);
-
- switch (engine->getProccessMode())
- {
- case ENGINE_PROCESS_MODE_SINGLE_CLIENT:
- case ENGINE_PROCESS_MODE_MULTIPLE_CLIENTS:
- CARLA_SAFE_ASSERT(id < MAX_DEFAULT_PLUGINS);
- break;
-
- case ENGINE_PROCESS_MODE_CONTINUOUS_RACK:
- CARLA_SAFE_ASSERT(id < MAX_RACK_PLUGINS);
- break;
-
- case ENGINE_PROCESS_MODE_PATCHBAY:
- CARLA_SAFE_ASSERT(id < MAX_PATCHBAY_PLUGINS);
- break;
-
- case ENGINE_PROCESS_MODE_BRIDGE:
- CARLA_SAFE_ASSERT(id == 0);
- break;
- }
- }
-
- CarlaPlugin::~CarlaPlugin()
- {
- carla_debug("CarlaPlugin::~CarlaPlugin()");
-
- delete pData;
- }
-
- // -------------------------------------------------------------------
- // Information (base)
-
- uint CarlaPlugin::getId() const noexcept
- {
- return pData->id;
- }
-
- uint CarlaPlugin::getHints() const noexcept
- {
- return pData->hints;
- }
-
- uint CarlaPlugin::getOptionsEnabled() const noexcept
- {
- return pData->options;
- }
-
- bool CarlaPlugin::isEnabled() const noexcept
- {
- return pData->enabled;
- }
-
- const char* CarlaPlugin::getName() const noexcept
- {
- return pData->name;
- }
-
- const char* CarlaPlugin::getFilename() const noexcept
- {
- return pData->filename;
- }
-
- const char* CarlaPlugin::getIconName() const noexcept
- {
- return pData->iconName;
- }
-
- PluginCategory CarlaPlugin::getCategory() const noexcept
- {
- return getPluginCategoryFromName(pData->name);
- }
-
- int64_t CarlaPlugin::getUniqueId() const noexcept
- {
- return 0;
- }
-
- uint32_t CarlaPlugin::getLatencyInFrames() const noexcept
- {
- return 0;
- }
-
- // -------------------------------------------------------------------
- // Information (count)
-
- uint32_t CarlaPlugin::getAudioInCount() const noexcept
- {
- return pData->audioIn.count;
- }
-
- uint32_t CarlaPlugin::getAudioOutCount() const noexcept
- {
- return pData->audioOut.count;
- }
-
- uint32_t CarlaPlugin::getCVInCount() const noexcept
- {
- return pData->cvIn.count;
- }
-
- uint32_t CarlaPlugin::getCVOutCount() const noexcept
- {
- return pData->cvOut.count;
- }
-
- uint32_t CarlaPlugin::getMidiInCount() const noexcept
- {
- return (pData->extraHints & PLUGIN_EXTRA_HINT_HAS_MIDI_IN) ? 1 : 0;
- }
-
- uint32_t CarlaPlugin::getMidiOutCount() const noexcept
- {
- return (pData->extraHints & PLUGIN_EXTRA_HINT_HAS_MIDI_OUT) ? 1 : 0;
- }
-
- uint32_t CarlaPlugin::getParameterCount() const noexcept
- {
- return pData->param.count;
- }
-
- uint32_t CarlaPlugin::getParameterScalePointCount(const uint32_t parameterId) const noexcept
- {
- CARLA_SAFE_ASSERT_RETURN(parameterId < pData->param.count, 0);
- return 0;
- }
-
- uint32_t CarlaPlugin::getProgramCount() const noexcept
- {
- return pData->prog.count;
- }
-
- uint32_t CarlaPlugin::getMidiProgramCount() const noexcept
- {
- return pData->midiprog.count;
- }
-
- uint32_t CarlaPlugin::getCustomDataCount() const noexcept
- {
- return static_cast<uint32_t>(pData->custom.count());
- }
-
- // -------------------------------------------------------------------
- // Information (current data)
-
- int32_t CarlaPlugin::getCurrentProgram() const noexcept
- {
- return pData->prog.current;
- }
-
- int32_t CarlaPlugin::getCurrentMidiProgram() const noexcept
- {
- return pData->midiprog.current;
- }
-
- uint CarlaPlugin::getAudioPortHints(bool, uint32_t) const noexcept
- {
- return 0x0;
- }
-
- const ParameterData& CarlaPlugin::getParameterData(const uint32_t parameterId) const noexcept
- {
- CARLA_SAFE_ASSERT_RETURN(parameterId < pData->param.count, kParameterDataNull);
- return pData->param.data[parameterId];
- }
-
- const ParameterRanges& CarlaPlugin::getParameterRanges(const uint32_t parameterId) const noexcept
- {
- CARLA_SAFE_ASSERT_RETURN(parameterId < pData->param.count, kParameterRangesNull);
- return pData->param.ranges[parameterId];
- }
-
- bool CarlaPlugin::isParameterOutput(const uint32_t parameterId) const noexcept
- {
- CARLA_SAFE_ASSERT_RETURN(parameterId < pData->param.count, false);
- return (pData->param.data[parameterId].type == PARAMETER_OUTPUT);
- }
-
- const MidiProgramData& CarlaPlugin::getMidiProgramData(const uint32_t index) const noexcept
- {
- CARLA_SAFE_ASSERT_RETURN(index < pData->midiprog.count, kMidiProgramDataNull);
- return pData->midiprog.data[index];
- }
-
- const CustomData& CarlaPlugin::getCustomData(const uint32_t index) const noexcept
- {
- return pData->custom.getAt(index, kCustomDataFallback);
- }
-
- std::size_t CarlaPlugin::getChunkData(void** const dataPtr) noexcept
- {
- CARLA_SAFE_ASSERT_RETURN(dataPtr != nullptr, 0);
- CARLA_SAFE_ASSERT(false); // this should never happen
- return 0;
- }
-
- // -------------------------------------------------------------------
- // Information (per-plugin data)
-
- uint CarlaPlugin::getOptionsAvailable() const noexcept
- {
- CARLA_SAFE_ASSERT(false); // this should never happen
- return 0x0;
- }
-
- float CarlaPlugin::getParameterValue(const uint32_t parameterId) const noexcept
- {
- CARLA_SAFE_ASSERT_RETURN(parameterId < getParameterCount(), 0.0f);
- CARLA_SAFE_ASSERT(false); // this should never happen
- return 0.0f;
- }
-
- float CarlaPlugin::getParameterScalePointValue(const uint32_t parameterId, const uint32_t scalePointId) const noexcept
- {
- CARLA_SAFE_ASSERT_RETURN(parameterId < getParameterCount(), 0.0f);
- CARLA_SAFE_ASSERT_RETURN(scalePointId < getParameterScalePointCount(parameterId), 0.0f);
- CARLA_SAFE_ASSERT(false); // this should never happen
- return 0.0f;
- }
-
- bool CarlaPlugin::getLabel(char* const strBuf) const noexcept
- {
- strBuf[0] = '\0';
- return false;
- }
-
- bool CarlaPlugin::getMaker(char* const strBuf) const noexcept
- {
- strBuf[0] = '\0';
- return false;
- }
-
- bool CarlaPlugin::getCopyright(char* const strBuf) const noexcept
- {
- strBuf[0] = '\0';
- return false;
- }
-
- bool CarlaPlugin::getRealName(char* const strBuf) const noexcept
- {
- strBuf[0] = '\0';
- return false;
- }
-
- bool CarlaPlugin::getParameterName(const uint32_t parameterId, char* const strBuf) const noexcept
- {
- CARLA_SAFE_ASSERT_RETURN(parameterId < getParameterCount(), false);
- CARLA_SAFE_ASSERT(false); // this should never happen
- strBuf[0] = '\0';
- return false;
- }
-
- bool CarlaPlugin::getParameterSymbol(const uint32_t parameterId, char* const strBuf) const noexcept
- {
- CARLA_SAFE_ASSERT_RETURN(parameterId < getParameterCount(), false);
- strBuf[0] = '\0';
- return false;
- }
-
- bool CarlaPlugin::getParameterText(const uint32_t parameterId, char* const strBuf) noexcept
- {
- CARLA_SAFE_ASSERT_RETURN(parameterId < getParameterCount(), false);
- CARLA_SAFE_ASSERT(false); // this should never happen
- strBuf[0] = '\0';
- return false;
- }
-
- bool CarlaPlugin::getParameterUnit(const uint32_t parameterId, char* const strBuf) const noexcept
- {
- CARLA_SAFE_ASSERT_RETURN(parameterId < getParameterCount(), false);
- strBuf[0] = '\0';
- return false;
- }
-
- bool CarlaPlugin::getParameterComment(const uint32_t parameterId, char* const strBuf) const noexcept
- {
- CARLA_SAFE_ASSERT_RETURN(parameterId < getParameterCount(), false);
- strBuf[0] = '\0';
- return false;
- }
-
- bool CarlaPlugin::getParameterGroupName(const uint32_t parameterId, char* const strBuf) const noexcept
- {
- CARLA_SAFE_ASSERT_RETURN(parameterId < getParameterCount(), false);
- strBuf[0] = '\0';
- return false;
- }
-
- bool CarlaPlugin::getParameterScalePointLabel(const uint32_t parameterId, const uint32_t scalePointId, char* const strBuf) const noexcept
- {
- CARLA_SAFE_ASSERT_RETURN(parameterId < getParameterCount(), false);
- CARLA_SAFE_ASSERT_RETURN(scalePointId < getParameterScalePointCount(parameterId), false);
- CARLA_SAFE_ASSERT(false); // this should never happen
- strBuf[0] = '\0';
- return false;
- }
-
- float CarlaPlugin::getInternalParameterValue(const int32_t parameterId) const noexcept
- {
- #ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH
- CARLA_SAFE_ASSERT_RETURN(parameterId != PARAMETER_NULL && parameterId > PARAMETER_MAX, 0.0f);
-
- switch (parameterId)
- {
- case PARAMETER_ACTIVE:
- return pData->active;
- case PARAMETER_CTRL_CHANNEL:
- return pData->ctrlChannel;
- case PARAMETER_DRYWET:
- return pData->postProc.dryWet;
- case PARAMETER_VOLUME:
- return pData->postProc.volume;
- case PARAMETER_BALANCE_LEFT:
- return pData->postProc.balanceLeft;
- case PARAMETER_BALANCE_RIGHT:
- return pData->postProc.balanceRight;
- case PARAMETER_PANNING:
- return pData->postProc.panning;
- };
- #endif
- CARLA_SAFE_ASSERT_RETURN(parameterId >= 0, 0.0f);
-
- return getParameterValue(static_cast<uint32_t>(parameterId));
- }
-
- bool CarlaPlugin::getProgramName(const uint32_t index, char* const strBuf) const noexcept
- {
- CARLA_SAFE_ASSERT_RETURN(index < pData->prog.count, false);
- CARLA_SAFE_ASSERT_RETURN(pData->prog.names[index] != nullptr, false);
- std::strncpy(strBuf, pData->prog.names[index], STR_MAX);
- return true;
- }
-
- bool CarlaPlugin::getMidiProgramName(const uint32_t index, char* const strBuf) const noexcept
- {
- CARLA_SAFE_ASSERT_RETURN(index < pData->midiprog.count, false);
- CARLA_SAFE_ASSERT_RETURN(pData->midiprog.data[index].name != nullptr, false);
- std::strncpy(strBuf, pData->midiprog.data[index].name, STR_MAX);
- return true;
- }
-
- void CarlaPlugin::getParameterCountInfo(uint32_t& ins, uint32_t& outs) const noexcept
- {
- ins = 0;
- outs = 0;
-
- for (uint32_t i=0; i < pData->param.count; ++i)
- {
- if (pData->param.data[i].type == PARAMETER_INPUT)
- ++ins;
- else if (pData->param.data[i].type == PARAMETER_OUTPUT)
- ++outs;
- }
- }
-
- // -------------------------------------------------------------------
- // Set data (state)
-
- void CarlaPlugin::prepareForSave(bool)
- {
- }
-
- void CarlaPlugin::resetParameters() noexcept
- {
- for (uint i=0; i < pData->param.count; ++i)
- {
- const ParameterData& paramData(pData->param.data[i]);
- const ParameterRanges& paramRanges(pData->param.ranges[i]);
-
- if (paramData.type != PARAMETER_INPUT)
- continue;
- if ((paramData.hints & PARAMETER_IS_ENABLED) == 0)
- continue;
-
- setParameterValue(i, paramRanges.def, true, true, true);
- }
- }
-
- void CarlaPlugin::randomizeParameters() noexcept
- {
- float value, random;
-
- char strBuf[STR_MAX+1];
- strBuf[STR_MAX] = '\0';
-
- std::srand(static_cast<uint>(std::time(nullptr)));
-
- for (uint i=0; i < pData->param.count; ++i)
- {
- const ParameterData& paramData(pData->param.data[i]);
-
- if (paramData.type != PARAMETER_INPUT)
- continue;
- if ((paramData.hints & PARAMETER_IS_ENABLED) == 0)
- continue;
-
- if (! getParameterName(i, strBuf))
- strBuf[0] = '\0';
-
- if (std::strstr(strBuf, "olume") != nullptr)
- continue;
- if (std::strstr(strBuf, "Master") != nullptr)
- continue;
-
- const ParameterRanges& paramRanges(pData->param.ranges[i]);
-
- if (paramData.hints & PARAMETER_IS_BOOLEAN)
- {
- random = static_cast<float>(std::rand()) / static_cast<float>(RAND_MAX);
- value = random > 0.5f ? paramRanges.max : paramRanges.min;
- }
- else
- {
- random = static_cast<float>(std::rand()) / static_cast<float>(RAND_MAX);
- value = random * (paramRanges.max - paramRanges.min) + paramRanges.min;
-
- if (paramData.hints & PARAMETER_IS_INTEGER)
- value = std::rint(value);
- }
-
- setParameterValue(i, value, true, true, true);
- }
- }
-
- const CarlaStateSave& CarlaPlugin::getStateSave(const bool callPrepareForSave)
- {
- pData->stateSave.clear();
-
- if (callPrepareForSave)
- {
- pData->stateSave.temporary = true;
- prepareForSave(true);
- }
-
- const PluginType pluginType = getType();
-
- char strBuf[STR_MAX+1];
- carla_zeroChars(strBuf, STR_MAX+1);
-
- // ---------------------------------------------------------------
- // Basic info
-
- if (! getLabel(strBuf))
- strBuf[0] = '\0';
-
- pData->stateSave.type = carla_strdup(getPluginTypeAsString(pluginType));
- pData->stateSave.name = carla_strdup(pData->name);
- pData->stateSave.label = carla_strdup(strBuf);
- pData->stateSave.uniqueId = getUniqueId();
- // #ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH
- pData->stateSave.options = pData->options;
- // #endif
-
- if (pData->filename != nullptr)
- pData->stateSave.binary = carla_strdup(pData->filename);
-
- #ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH
- // ---------------------------------------------------------------
- // Internals
-
- pData->stateSave.active = pData->active;
- pData->stateSave.dryWet = pData->postProc.dryWet;
- pData->stateSave.volume = pData->postProc.volume;
- pData->stateSave.balanceLeft = pData->postProc.balanceLeft;
- pData->stateSave.balanceRight = pData->postProc.balanceRight;
- pData->stateSave.panning = pData->postProc.panning;
- pData->stateSave.ctrlChannel = pData->ctrlChannel;
- #endif
-
- if (pData->hints & PLUGIN_IS_BRIDGE)
- waitForBridgeSaveSignal();
-
- // ---------------------------------------------------------------
- // Chunk
-
- bool usingChunk = false;
-
- if (pData->options & PLUGIN_OPTION_USE_CHUNKS)
- {
- void* data = nullptr;
- const std::size_t dataSize = getChunkData(&data);
-
- if (data != nullptr && dataSize > 0)
- {
- pData->stateSave.chunk = CarlaString::asBase64(data, dataSize).dup();
-
- if (pluginType != PLUGIN_INTERNAL && pluginType != PLUGIN_JSFX)
- usingChunk = true;
- }
- }
-
- // ---------------------------------------------------------------
- // Current Program
-
- if (pData->prog.current >= 0 && pluginType != PLUGIN_LV2)
- {
- pData->stateSave.currentProgramIndex = pData->prog.current;
- pData->stateSave.currentProgramName = carla_strdup(pData->prog.names[pData->prog.current]);
- }
-
- // ---------------------------------------------------------------
- // Current MIDI Program
-
- if (pData->midiprog.current >= 0 && pluginType != PLUGIN_LV2 && pluginType != PLUGIN_SF2)
- {
- const MidiProgramData& mpData(pData->midiprog.getCurrent());
-
- pData->stateSave.currentMidiBank = static_cast<int32_t>(mpData.bank);
- pData->stateSave.currentMidiProgram = static_cast<int32_t>(mpData.program);
- }
-
- // ---------------------------------------------------------------
- // Parameters
-
- const float sampleRate = static_cast<float>(pData->engine->getSampleRate());
-
- for (uint32_t i=0; i < pData->param.count; ++i)
- {
- const ParameterData& paramData(pData->param.data[i]);
-
- if ((paramData.hints & PARAMETER_IS_ENABLED) == 0)
- continue;
- if (paramData.hints & PARAMETER_IS_NOT_SAVED)
- continue;
-
- const bool dummy = paramData.type != PARAMETER_INPUT || usingChunk;
-
- if (dummy && paramData.mappedControlIndex <= CONTROL_INDEX_NONE)
- continue;
-
- CarlaStateSave::Parameter* const stateParameter(new CarlaStateSave::Parameter());
-
- stateParameter->dummy = dummy;
- stateParameter->index = paramData.index;
- #ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH
- if (paramData.mappedControlIndex != CONTROL_INDEX_MIDI_LEARN)
- {
- stateParameter->mappedControlIndex = paramData.mappedControlIndex;
- stateParameter->midiChannel = paramData.midiChannel;
-
- if (paramData.hints & PARAMETER_MAPPED_RANGES_SET)
- {
- stateParameter->mappedMinimum = paramData.mappedMinimum;
- stateParameter->mappedMaximum = paramData.mappedMaximum;
- stateParameter->mappedRangeValid = true;
-
- if (paramData.hints & PARAMETER_USES_SAMPLERATE)
- {
- stateParameter->mappedMinimum /= sampleRate;
- stateParameter->mappedMaximum /= sampleRate;
- }
- }
- }
- #endif
-
- if (! getParameterName(i, strBuf))
- strBuf[0] = '\0';
- stateParameter->name = carla_strdup(strBuf);
-
- if (! getParameterSymbol(i, strBuf))
- strBuf[0] = '\0';
- stateParameter->symbol = carla_strdup(strBuf);;
-
- if (! dummy)
- {
- stateParameter->value = getParameterValue(i);
-
- if (paramData.hints & PARAMETER_USES_SAMPLERATE)
- stateParameter->value /= sampleRate;
- }
-
- pData->stateSave.parameters.append(stateParameter);
- }
-
- // ---------------------------------------------------------------
- // Custom Data
-
- for (LinkedList<CustomData>::Itenerator it = pData->custom.begin2(); it.valid(); it.next())
- {
- const CustomData& cData(it.getValue(kCustomDataFallback));
- CARLA_SAFE_ASSERT_CONTINUE(cData.isValid());
-
- CarlaStateSave::CustomData* stateCustomData(new CarlaStateSave::CustomData());
-
- stateCustomData->type = carla_strdup(cData.type);
- stateCustomData->key = carla_strdup(cData.key);
- stateCustomData->value = carla_strdup(cData.value);
-
- pData->stateSave.customData.append(stateCustomData);
- }
-
- return pData->stateSave;
- }
-
- void CarlaPlugin::loadStateSave(const CarlaStateSave& stateSave)
- {
- const bool usesMultiProgs = pData->hints & PLUGIN_USES_MULTI_PROGS;
- const PluginType pluginType = getType();
-
- char strBuf[STR_MAX+1];
- carla_zeroChars(strBuf, STR_MAX+1);
-
- // ---------------------------------------------------------------
- // Part 1 - PRE-set custom data (only those which reload programs)
-
- for (CarlaStateSave::CustomDataItenerator it = stateSave.customData.begin2(); it.valid(); it.next())
- {
- const CarlaStateSave::CustomData* const stateCustomData(it.getValue(nullptr));
- CARLA_SAFE_ASSERT_CONTINUE(stateCustomData != nullptr);
- CARLA_SAFE_ASSERT_CONTINUE(stateCustomData->isValid());
-
- const char* const key(stateCustomData->key);
-
- /**/ if (pluginType == PLUGIN_DSSI && (std::strcmp (key, "reloadprograms") == 0 ||
- std::strcmp (key, "load" ) == 0 ||
- std::strncmp(key, "patches", 7) == 0 ))
- pass();
- else if (usesMultiProgs && std::strcmp(key, "midiPrograms") == 0)
- pass();
- else
- continue;
-
- setCustomData(stateCustomData->type, key, stateCustomData->value, true);
- }
-
- // ---------------------------------------------------------------
- // Part 2 - set program
-
- if (stateSave.currentProgramIndex >= 0 && stateSave.currentProgramName != nullptr)
- {
- int32_t programId = -1;
-
- // index < count
- if (stateSave.currentProgramIndex < static_cast<int32_t>(pData->prog.count))
- {
- programId = stateSave.currentProgramIndex;
- }
- // index not valid, try to find by name
- else
- {
- for (uint32_t i=0; i < pData->prog.count; ++i)
- {
- if (getProgramName(i, strBuf) && std::strcmp(stateSave.currentProgramName, strBuf) == 0)
- {
- programId = static_cast<int32_t>(i);
- break;
- }
- }
- }
-
- // set program now, if valid
- if (programId >= 0)
- setProgram(programId, true, true, true);
- }
-
- // ---------------------------------------------------------------
- // Part 3 - set midi program
-
- if (stateSave.currentMidiBank >= 0 && stateSave.currentMidiProgram >= 0 && ! usesMultiProgs)
- setMidiProgramById(static_cast<uint32_t>(stateSave.currentMidiBank), static_cast<uint32_t>(stateSave.currentMidiProgram), true, true, true);
-
- // ---------------------------------------------------------------
- // Part 4a - get plugin parameter symbols
-
- LinkedList<ParamSymbol*> paramSymbols;
-
- if (pluginType == PLUGIN_LADSPA || pluginType == PLUGIN_LV2 || pluginType == PLUGIN_CLAP)
- {
- for (uint32_t i=0; i < pData->param.count; ++i)
- {
- if (pData->param.data[i].hints & PARAMETER_IS_NOT_SAVED)
- continue;
-
- if (getParameterSymbol(i, strBuf))
- {
- ParamSymbol* const paramSymbol(new ParamSymbol(i, strBuf));
- paramSymbols.append(paramSymbol);
- }
- }
- }
-
- // ---------------------------------------------------------------
- // Part 4b - set parameter values (carefully)
-
- const float sampleRate = static_cast<float>(pData->engine->getSampleRate());
-
- for (CarlaStateSave::ParameterItenerator it = stateSave.parameters.begin2(); it.valid(); it.next())
- {
- CarlaStateSave::Parameter* const stateParameter(it.getValue(nullptr));
- CARLA_SAFE_ASSERT_CONTINUE(stateParameter != nullptr);
-
- int32_t index = -1;
-
- if (pluginType == PLUGIN_LADSPA)
- {
- // Try to set by symbol, otherwise use index
- if (stateParameter->symbol != nullptr && stateParameter->symbol[0] != '\0')
- {
- for (LinkedList<ParamSymbol*>::Itenerator it2 = paramSymbols.begin2(); it2.valid(); it2.next())
- {
- ParamSymbol* const paramSymbol(it2.getValue(nullptr));
- CARLA_SAFE_ASSERT_CONTINUE(paramSymbol != nullptr);
- CARLA_SAFE_ASSERT_CONTINUE(paramSymbol->symbol != nullptr);
-
- if (std::strcmp(stateParameter->symbol, paramSymbol->symbol) == 0)
- {
- index = paramSymbol->index;
- break;
- }
- }
- if (index == -1)
- index = stateParameter->index;
- }
- else
- {
- index = stateParameter->index;
- }
- }
- else if (pluginType == PLUGIN_LV2 || pluginType == PLUGIN_CLAP)
- {
- // Symbol only
- if (stateParameter->symbol != nullptr && stateParameter->symbol[0] != '\0')
- {
- for (LinkedList<ParamSymbol*>::Itenerator it2 = paramSymbols.begin2(); it2.valid(); it2.next())
- {
- ParamSymbol* const paramSymbol(it2.getValue(nullptr));
- CARLA_SAFE_ASSERT_CONTINUE(paramSymbol != nullptr);
- CARLA_SAFE_ASSERT_CONTINUE(paramSymbol->symbol != nullptr);
-
- if (std::strcmp(stateParameter->symbol, paramSymbol->symbol) == 0)
- {
- index = paramSymbol->index;
- break;
- }
- }
- if (index == -1)
- {
- if (pluginType == PLUGIN_LV2)
- carla_stderr("Failed to find LV2 parameter symbol '%s' for '%s'",
- stateParameter->symbol, pData->name);
- else
- carla_stderr("Failed to find CLAP parameter id '%s' for '%s'",
- stateParameter->symbol, pData->name);
- }
- }
- else
- {
- if (pluginType == PLUGIN_LV2)
- carla_stderr("LV2 Plugin parameter '%s' has no symbol", stateParameter->name);
- else
- carla_stderr("CLAP Plugin parameter '%s' has no id", stateParameter->name);
- }
- }
- else
- {
- // Index only
- index = stateParameter->index;
- }
-
- // Now set parameter
- if (index >= 0 && index < static_cast<int32_t>(pData->param.count))
- {
- //CARLA_SAFE_ASSERT(stateParameter->isInput == (pData
-
- if (! stateParameter->dummy)
- {
- if (pData->param.data[index].hints & PARAMETER_USES_SAMPLERATE)
- stateParameter->value *= sampleRate;
-
- setParameterValue(static_cast<uint32_t>(index), stateParameter->value, true, true, true);
- }
-
- #ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH
- if (stateParameter->mappedRangeValid)
- {
- if (pData->param.data[index].hints & PARAMETER_USES_SAMPLERATE)
- {
- stateParameter->mappedMinimum *= sampleRate;
- stateParameter->mappedMaximum *= sampleRate;
- }
-
- setParameterMappedRange(static_cast<uint32_t>(index),
- stateParameter->mappedMinimum,
- stateParameter->mappedMaximum, true, true);
- }
-
- setParameterMappedControlIndex(static_cast<uint32_t>(index),
- stateParameter->mappedControlIndex, true, true, false);
- setParameterMidiChannel(static_cast<uint32_t>(index), stateParameter->midiChannel, true, true);
- #endif
- }
- else
- carla_stderr("Could not set parameter '%s' value for '%s'",
- stateParameter->name, pData->name);
- }
-
- // ---------------------------------------------------------------
- // Part 4c - clear
-
- for (LinkedList<ParamSymbol*>::Itenerator it = paramSymbols.begin2(); it.valid(); it.next())
- {
- ParamSymbol* const paramSymbol(it.getValue(nullptr));
- delete paramSymbol;
- }
-
- paramSymbols.clear();
-
- // ---------------------------------------------------------------
- // Part 5 - set custom data
-
- for (CarlaStateSave::CustomDataItenerator it = stateSave.customData.begin2(); it.valid(); it.next())
- {
- const CarlaStateSave::CustomData* const stateCustomData(it.getValue(nullptr));
- CARLA_SAFE_ASSERT_CONTINUE(stateCustomData != nullptr);
- CARLA_SAFE_ASSERT_CONTINUE(stateCustomData->isValid());
-
- const char* const key(stateCustomData->key);
-
- if (pluginType == PLUGIN_DSSI && (std::strcmp (key, "reloadprograms") == 0 ||
- std::strcmp (key, "load" ) == 0 ||
- std::strncmp(key, "patches", 7) == 0 ))
- continue;
- if (usesMultiProgs && std::strcmp(key, "midiPrograms") == 0)
- continue;
-
- setCustomData(stateCustomData->type, key, stateCustomData->value, true);
- }
-
- // ---------------------------------------------------------------
- // Part 5x - set lv2 state
-
- if (pluginType == PLUGIN_LV2)
- {
- for (LinkedList<CustomData>::Itenerator it = pData->custom.begin2(); it.valid(); it.next())
- {
- const CustomData& customData(it.getValue(kCustomDataFallback));
- CARLA_SAFE_ASSERT_CONTINUE(customData.isValid());
-
- if (std::strcmp(customData.type, CUSTOM_DATA_TYPE_PROPERTY) == 0)
- continue;
-
- restoreLV2State(stateSave.temporary);
- break;
- }
- }
-
- // ---------------------------------------------------------------
- // Part 6 - set chunk
-
- if (stateSave.chunk != nullptr && (pData->options & PLUGIN_OPTION_USE_CHUNKS) != 0)
- {
- std::vector<uint8_t> chunk(carla_getChunkFromBase64String(stateSave.chunk));
- #ifdef CARLA_PROPER_CPP11_SUPPORT
- setChunkData(chunk.data(), chunk.size());
- #else
- setChunkData(&chunk.front(), chunk.size());
- #endif
- }
-
- #ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH
- // ---------------------------------------------------------------
- // Part 6 - set internal stuff
-
- const uint availOptions = getOptionsAvailable();
-
- for (uint i=0; i<10; ++i) // FIXME - get this value somehow...
- {
- const uint option(1u << i);
-
- if (availOptions & option)
- setOption(option, (stateSave.options & option) != 0, true);
- }
-
- setDryWet(stateSave.dryWet, true, true);
- setVolume(stateSave.volume, true, true);
- setBalanceLeft(stateSave.balanceLeft, true, true);
- setBalanceRight(stateSave.balanceRight, true, true);
- setPanning(stateSave.panning, true, true);
- setCtrlChannel(stateSave.ctrlChannel, true, true);
- setActive(stateSave.active, true, true);
-
- if (! pData->engine->isLoadingProject())
- pData->engine->callback(true, true, ENGINE_CALLBACK_UPDATE, pData->id, 0, 0, 0, 0.0f, nullptr);
- #endif
- }
-
- bool CarlaPlugin::saveStateToFile(const char* const filename)
- {
- CARLA_SAFE_ASSERT_RETURN(filename != nullptr && filename[0] != '\0', false);
- carla_debug("CarlaPlugin::saveStateToFile(\"%s\")", filename);
-
- MemoryOutputStream out, streamState;
- getStateSave().dumpToMemoryStream(streamState);
-
- out << "<?xml version='1.0' encoding='UTF-8'?>\n";
- out << "<!DOCTYPE CARLA-PRESET>\n";
- out << "<CARLA-PRESET VERSION='2.0'>\n";
- out << streamState;
- out << "</CARLA-PRESET>\n";
-
- const String jfilename = String(CharPointer_UTF8(filename));
- File file(jfilename);
-
- if (file.replaceWithData(out.getData(), out.getDataSize()))
- return true;
-
- pData->engine->setLastError("Failed to write file");
- return false;
- }
-
- bool CarlaPlugin::loadStateFromFile(const char* const filename)
- {
- // TODO set errors
-
- CARLA_SAFE_ASSERT_RETURN(filename != nullptr && filename[0] != '\0', false);
- carla_debug("CarlaPlugin::loadStateFromFile(\"%s\")", filename);
-
- const String jfilename = String(CharPointer_UTF8(filename));
- File file(jfilename);
- CARLA_SAFE_ASSERT_RETURN(file.existsAsFile(), false);
-
- XmlDocument xml(file);
- CarlaScopedPointer<XmlElement> xmlElement(xml.getDocumentElement(true));
- CARLA_SAFE_ASSERT_RETURN(xmlElement != nullptr, false);
- CARLA_SAFE_ASSERT_RETURN(xmlElement->getTagName().equalsIgnoreCase("carla-preset"), false);
-
- // completely load file
- xmlElement = xml.getDocumentElement(false);
- CARLA_SAFE_ASSERT_RETURN(xmlElement != nullptr, false);
-
- if (pData->stateSave.fillFromXmlElement(xmlElement))
- {
- loadStateSave(pData->stateSave);
- return true;
- }
-
- return false;
- }
-
- #ifndef CARLA_PLUGIN_ONLY_BRIDGE
- bool CarlaPlugin::exportAsLV2(const char* const lv2path)
- {
- CARLA_SAFE_ASSERT_RETURN(lv2path != nullptr && lv2path[0] != '\0', false);
- carla_debug("CarlaPlugin::exportAsLV2(\"%s\")", lv2path);
-
- CarlaString bundlepath(lv2path);
-
- if (! bundlepath.endsWith(".lv2"))
- bundlepath += ".lv2";
-
- const File bundlefolder(bundlepath.buffer());
-
- if (bundlefolder.existsAsFile())
- {
- pData->engine->setLastError("Requested filename already exists as file, use a folder instead");
- return false;
- }
-
- if (! bundlefolder.exists())
- {
- const Result res(bundlefolder.createDirectory());
-
- if (res.failed())
- {
- pData->engine->setLastError(res.getErrorMessage().c_str());
- return false;
- }
- }
-
- CarlaString symbol(pData->name);
- symbol.toBasic();
-
- {
- const CarlaString pluginFilename(bundlepath + CARLA_OS_SEP_STR + symbol + ".xml");
-
- if (! saveStateToFile(pluginFilename))
- return false;
- }
-
- {
- MemoryOutputStream manifestStream;
-
- manifestStream << "@prefix lv2: <http://lv2plug.in/ns/lv2core#> .\n";
- manifestStream << "@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .\n";
- manifestStream << "@prefix ui: <http://lv2plug.in/ns/extensions/ui#> .\n";
- manifestStream << "\n";
- manifestStream << "<" << symbol.buffer() << ".ttl>\n";
- manifestStream << " a lv2:Plugin ;\n";
- manifestStream << " lv2:binary <" << symbol.buffer() << CARLA_LIB_EXT "> ;\n";
- manifestStream << " rdfs:seeAlso <" << symbol.buffer() << ".ttl> .\n";
- manifestStream << "\n";
- manifestStream << "<ext-ui>\n";
- manifestStream << " a <http://kxstudio.sf.net/ns/lv2ext/external-ui#Widget> ;\n";
- manifestStream << " ui:binary <" << symbol.buffer() << CARLA_LIB_EXT "> ;\n";
- manifestStream << " lv2:extensionData <http://lv2plug.in/ns/extensions/ui#idleInterface> ,\n";
- manifestStream << " <http://lv2plug.in/ns/extensions/ui#showInterface> ;\n";
- manifestStream << " lv2:requiredFeature <http://lv2plug.in/ns/ext/instance-access> .\n";
- manifestStream << "\n";
-
- const CarlaString manifestFilename(bundlepath + CARLA_OS_SEP_STR "manifest.ttl");
- const File manifestFile(manifestFilename.buffer());
-
- if (! manifestFile.replaceWithData(manifestStream.getData(), manifestStream.getDataSize()))
- {
- pData->engine->setLastError("Failed to write manifest.ttl file");
- return false;
- }
- }
-
- {
- MemoryOutputStream mainStream;
-
- mainStream << "@prefix atom: <http://lv2plug.in/ns/ext/atom#> .\n";
- mainStream << "@prefix doap: <http://usefulinc.com/ns/doap#> .\n";
- mainStream << "@prefix foaf: <http://xmlns.com/foaf/0.1/> .\n";
- mainStream << "@prefix lv2: <http://lv2plug.in/ns/lv2core#> .\n";
- mainStream << "@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .\n";
- mainStream << "@prefix ui: <http://lv2plug.in/ns/extensions/ui#> .\n";
- mainStream << "\n";
- mainStream << "<>\n";
- mainStream << " a lv2:Plugin ;\n";
- mainStream << "\n";
- mainStream << " lv2:requiredFeature <http://lv2plug.in/ns/ext/buf-size#boundedBlockLength> ,\n";
- mainStream << " <http://lv2plug.in/ns/ext/options#options> ,\n";
- mainStream << " <http://lv2plug.in/ns/ext/urid#map> ;\n";
- mainStream << "\n";
-
- if (pData->hints & PLUGIN_HAS_CUSTOM_UI)
- {
- mainStream << " ui:ui <ext-ui> ;\n";
- mainStream << "\n";
- }
-
- const uint32_t midiIns = getMidiInCount();
- const uint32_t midiOuts = getMidiOutCount();
-
- int portIndex = 0;
-
- if (midiIns > 0)
- {
- mainStream << " lv2:port [\n";
- mainStream << " a lv2:InputPort, atom:AtomPort ;\n";
- mainStream << " lv2:index 0 ;\n";
- mainStream << " lv2:symbol \"clv2_events_in\" ;\n";
- mainStream << " lv2:name \"Events Input\" ;\n";
- mainStream << " atom:bufferType atom:Sequence ;\n";
- mainStream << " atom:supports <http://lv2plug.in/ns/ext/midi#MidiEvent> ,\n";
- mainStream << " <http://lv2plug.in/ns/ext/time#Position> ;\n";
- mainStream << " ] ;\n";
- ++portIndex;
-
- for (uint32_t i=1; i<midiIns; ++i)
- {
- const String portIndexNum(portIndex++);
- const String portIndexLabel(portIndex);
-
- mainStream << " lv2:port [\n";
- mainStream << " a lv2:InputPort, atom:AtomPort ;\n";
- mainStream << " lv2:index " << portIndexNum << " ;\n";
- mainStream << " lv2:symbol \"clv2_midi_in_" << portIndexLabel << "\" ;\n";
- mainStream << " lv2:name \"MIDI Input " << portIndexLabel << "\" ;\n";
- mainStream << " ] ;\n";
- }
- }
- else
- {
- mainStream << " lv2:port [\n";
- mainStream << " a lv2:InputPort, atom:AtomPort ;\n";
- mainStream << " lv2:index 0 ;\n";
- mainStream << " lv2:symbol \"clv2_time_info\" ;\n";
- mainStream << " lv2:name \"Time Info\" ;\n";
- mainStream << " atom:bufferType atom:Sequence ;\n";
- mainStream << " atom:supports <http://lv2plug.in/ns/ext/time#Position> ;\n";
- mainStream << " ] ;\n";
- ++portIndex;
- }
-
- for (uint32_t i=0; i<midiOuts; ++i)
- {
- const String portIndexNum(portIndex++);
- const String portIndexLabel(portIndex);
-
- mainStream << " lv2:port [\n";
- mainStream << " a lv2:InputPort, atom:AtomPort ;\n";
- mainStream << " lv2:index " << portIndexNum << " ;\n";
- mainStream << " lv2:symbol \"clv2_midi_out_" << portIndexLabel << "\" ;\n";
- mainStream << " lv2:name \"MIDI Output " << portIndexLabel << "\" ;\n";
- mainStream << " atom:bufferType atom:Sequence ;\n";
- mainStream << " atom:supports <http://lv2plug.in/ns/ext/midi#MidiEvent> ;\n";
- mainStream << " ] ;\n";
- }
-
- mainStream << " lv2:port [\n";
- mainStream << " a lv2:InputPort, lv2:ControlPort ;\n";
- mainStream << " lv2:index " << String(portIndex++) << " ;\n";
- mainStream << " lv2:name \"freewheel\" ;\n";
- mainStream << " lv2:symbol \"clv2_freewheel\" ;\n";
- mainStream << " lv2:default 0 ;\n";
- mainStream << " lv2:minimum 0 ;\n";
- mainStream << " lv2:maximum 1 ;\n";
- mainStream << " lv2:designation lv2:freeWheeling ;\n";
- mainStream << " lv2:portProperty lv2:toggled , lv2:integer ;\n";
- mainStream << " lv2:portProperty <http://lv2plug.in/ns/ext/port-props#notOnGUI> ;\n";
- mainStream << " ] ;\n";
-
- for (uint32_t i=0; i<pData->audioIn.count; ++i)
- {
- const String portIndexNum(portIndex++);
- const String portIndexLabel(i+1);
-
- mainStream << " lv2:port [\n";
- mainStream << " a lv2:InputPort, lv2:AudioPort ;\n";
- mainStream << " lv2:index " << portIndexNum << " ;\n";
- mainStream << " lv2:symbol \"clv2_audio_in_" << portIndexLabel << "\" ;\n";
- mainStream << " lv2:name \"Audio Input " << portIndexLabel << "\" ;\n";
- mainStream << " ] ;\n";
- }
-
- for (uint32_t i=0; i<pData->audioOut.count; ++i)
- {
- const String portIndexNum(portIndex++);
- const String portIndexLabel(i+1);
-
- mainStream << " lv2:port [\n";
- mainStream << " a lv2:OutputPort, lv2:AudioPort ;\n";
- mainStream << " lv2:index " << portIndexNum << " ;\n";
- mainStream << " lv2:symbol \"clv2_audio_out_" << portIndexLabel << "\" ;\n";
- mainStream << " lv2:name \"Audio Output " << portIndexLabel << "\" ;\n";
- mainStream << " ] ;\n";
- }
-
- CarlaStringList uniqueSymbolNames;
-
- char strBufName[STR_MAX+1];
- char strBufSymbol[STR_MAX+1];
- carla_zeroChars(strBufName, STR_MAX+1);
- carla_zeroChars(strBufSymbol, STR_MAX+1);
-
- for (uint32_t i=0; i<pData->param.count; ++i)
- {
- const ParameterData& paramData(pData->param.data[i]);
- const ParameterRanges& paramRanges(pData->param.ranges[i]);
-
- const String portIndexNum(portIndex++);
-
- mainStream << " lv2:port [\n";
-
- if (paramData.type == PARAMETER_INPUT)
- mainStream << " a lv2:InputPort, lv2:ControlPort ;\n";
- else
- mainStream << " a lv2:OutputPort, lv2:ControlPort ;\n";
-
- if (paramData.hints & PARAMETER_IS_BOOLEAN)
- mainStream << " lv2:portProperty lv2:toggled ;\n";
-
- if (paramData.hints & PARAMETER_IS_INTEGER)
- mainStream << " lv2:portProperty lv2:integer ;\n";
-
- // TODO logarithmic, enabled (not on gui), automatable, samplerate, scalepoints
-
- if (! getParameterName(i, strBufName))
- strBufName[0] = '\0';
- if (! getParameterSymbol(i, strBufSymbol))
- strBufSymbol[0] = '\0';
-
- if (strBufSymbol[0] == '\0')
- {
- CarlaString s(strBufName);
- s.toBasic();
- std::memcpy(strBufSymbol, s.buffer(), s.length()+1);
-
- if (strBufSymbol[0] >= '0' && strBufSymbol[0] <= '9')
- {
- const size_t len(std::strlen(strBufSymbol));
- std::memmove(strBufSymbol+1, strBufSymbol, len);
- strBufSymbol[0] = '_';
- strBufSymbol[len+1] = '\0';
- }
- }
-
- if (uniqueSymbolNames.contains(strBufSymbol))
- std::snprintf(strBufSymbol, STR_MAX, "clv2_param_%d", i+1);
-
- mainStream << " lv2:index " << portIndexNum << " ;\n";
- mainStream << " lv2:symbol \"" << strBufSymbol << "\" ;\n";
- mainStream << " lv2:name \"\"\"" << strBufName << "\"\"\" ;\n";
- mainStream << " lv2:default " << String(paramRanges.def) << " ;\n";
- mainStream << " lv2:minimum " << String(paramRanges.min) << " ;\n";
- mainStream << " lv2:maximum " << String(paramRanges.max) << " ;\n";
-
- // TODO midiCC, midiChannel
-
- mainStream << " ] ;\n";
- }
-
- char strBuf[STR_MAX+1];
- carla_zeroChars(strBuf, STR_MAX+1);
-
- if (! getMaker(strBuf))
- strBuf[0] = '\0';
-
- mainStream << " rdfs:comment \"Plugin generated using Carla LV2 export.\" ;\n";
- mainStream << " doap:name \"\"\"" << getName() << "\"\"\" ;\n";
- mainStream << " doap:maintainer [ foaf:name \"\"\"" << strBuf << "\"\"\" ] .\n";
- mainStream << "\n";
-
- const CarlaString mainFilename(bundlepath + CARLA_OS_SEP_STR + symbol + ".ttl");
- const File mainFile(mainFilename.buffer());
-
- if (! mainFile.replaceWithData(mainStream.getData(), mainStream.getDataSize()))
- {
- pData->engine->setLastError("Failed to write main plugin ttl file");
- return false;
- }
- }
-
- const CarlaString binaryFilename(bundlepath + CARLA_OS_SEP_STR + symbol + CARLA_LIB_EXT);
-
- const File binaryFileSource(File::getSpecialLocation(File::currentExecutableFile).getSiblingFile("carla-bridge-lv2" CARLA_LIB_EXT));
- const File binaryFileTarget(binaryFilename.buffer());
-
- const EngineOptions& opts(pData->engine->getOptions());
-
- const CarlaString binFolderTarget(bundlepath + CARLA_OS_SEP_STR + "bin");
- const CarlaString resFolderTarget(bundlepath + CARLA_OS_SEP_STR + "res");
-
- if (! binaryFileSource.copyFileTo(binaryFileTarget))
- {
- pData->engine->setLastError("Failed to copy plugin binary");
- return false;
- }
-
- #ifdef CARLA_OS_WIN
- File(opts.resourceDir).copyDirectoryTo(File(resFolderTarget.buffer()));
-
- // Copying all the binaries is pointless, just go through the expected needed bits
- const File binFolder1(opts.binaryDir);
- const File binFolder2(binFolderTarget.buffer());
- binFolder2.createDirectory();
-
- static const char* files[] = {
- "carla-bridge-native.exe",
- "carla-bridge-win32.exe",
- "carla-discovery-win32.exe",
- "carla-discovery-win64.exe",
- "libcarla_utils.dll"
- };
-
- for (int i=0; i<5; ++i)
- binFolder1.getChildFile(files[i]).copyFileTo(binFolder2.getChildFile(files[i]));;
- #else
- File(opts.binaryDir).createSymbolicLink(File(binFolderTarget.buffer()), true);
- File(opts.resourceDir).createSymbolicLink(File(resFolderTarget.buffer()), true);
- #endif
-
- return true;
- }
- #endif
-
- // -------------------------------------------------------------------
- // Set data (internal stuff)
-
- void CarlaPlugin::setId(const uint newId) noexcept
- {
- pData->id = newId;
- }
-
- void CarlaPlugin::setName(const char* const newName)
- {
- CARLA_SAFE_ASSERT_RETURN(newName != nullptr && newName[0] != '\0',);
-
- if (pData->name != nullptr)
- delete[] pData->name;
-
- pData->name = carla_strdup(newName);
- }
-
- void CarlaPlugin::setOption(const uint option, const bool yesNo, const bool sendCallback)
- {
- CARLA_SAFE_ASSERT_UINT2_RETURN(getOptionsAvailable() & option, getOptionsAvailable(), option,);
-
- if (yesNo)
- pData->options |= option;
- else
- pData->options &= ~option;
-
- #ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH
- if (sendCallback)
- pData->engine->callback(true, true,
- ENGINE_CALLBACK_OPTION_CHANGED,
- pData->id,
- static_cast<int>(option),
- yesNo ? 1 : 0,
- 0, 0.0f, nullptr);
- #else
- // unused
- return; (void)sendCallback;
- #endif
- }
-
- void CarlaPlugin::setEnabled(const bool yesNo) noexcept
- {
- if (pData->enabled == yesNo)
- return;
-
- pData->masterMutex.lock();
- pData->enabled = yesNo;
-
- if (yesNo && ! pData->client->isActive())
- pData->client->activate();
-
- pData->masterMutex.unlock();
- }
-
- void CarlaPlugin::setActive(const bool active, const bool sendOsc, const bool sendCallback) noexcept
- {
- if (pData->engineBridged) {
- CARLA_SAFE_ASSERT_RETURN(!sendOsc && !sendCallback,);
- } else if (pData->enginePlugin) {
- // nothing here
- } else {
- CARLA_SAFE_ASSERT_RETURN(sendOsc || sendCallback,); // never call this from RT
- }
-
- if (pData->active == active)
- return;
-
- {
- const ScopedSingleProcessLocker spl(this, true);
-
- if (active)
- activate();
- else
- deactivate();
- }
-
- pData->active = active;
-
- #ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH
- const float value = active ? 1.0f : 0.0f;
-
- pData->engine->callback(sendCallback, sendOsc,
- ENGINE_CALLBACK_PARAMETER_VALUE_CHANGED,
- pData->id,
- PARAMETER_ACTIVE,
- 0, 0,
- value,
- nullptr);
- #endif
- }
-
- #ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH
- void CarlaPlugin::setDryWet(const float value, const bool sendOsc, const bool sendCallback) noexcept
- {
- if (pData->engineBridged) {
- CARLA_SAFE_ASSERT_RETURN(!sendOsc && !sendCallback,);
- } else {
- CARLA_SAFE_ASSERT_RETURN(sendOsc || sendCallback,); // never call this from RT
- }
- CARLA_SAFE_ASSERT(value >= 0.0f && value <= 1.0f);
-
- const float fixedValue(carla_fixedValue<float>(0.0f, 1.0f, value));
-
- if (carla_isEqual(pData->postProc.dryWet, fixedValue))
- return;
-
- pData->postProc.dryWet = fixedValue;
-
- pData->engine->callback(sendCallback, sendOsc,
- ENGINE_CALLBACK_PARAMETER_VALUE_CHANGED,
- pData->id,
- PARAMETER_DRYWET,
- 0, 0,
- fixedValue,
- nullptr);
- }
-
- void CarlaPlugin::setVolume(const float value, const bool sendOsc, const bool sendCallback) noexcept
- {
- if (pData->engineBridged) {
- CARLA_SAFE_ASSERT_RETURN(!sendOsc && !sendCallback,);
- } else {
- CARLA_SAFE_ASSERT_RETURN(sendOsc || sendCallback,); // never call this from RT
- }
- CARLA_SAFE_ASSERT(value >= 0.0f && value <= 1.27f);
-
- const float fixedValue(carla_fixedValue<float>(0.0f, 1.27f, value));
-
- if (carla_isEqual(pData->postProc.volume, fixedValue))
- return;
-
- pData->postProc.volume = fixedValue;
-
- pData->engine->callback(sendCallback, sendOsc,
- ENGINE_CALLBACK_PARAMETER_VALUE_CHANGED,
- pData->id,
- PARAMETER_VOLUME,
- 0, 0,
- fixedValue,
- nullptr);
- }
-
- void CarlaPlugin::setBalanceLeft(const float value, const bool sendOsc, const bool sendCallback) noexcept
- {
- if (pData->engineBridged) {
- CARLA_SAFE_ASSERT_RETURN(!sendOsc && !sendCallback,);
- } else {
- CARLA_SAFE_ASSERT_RETURN(sendOsc || sendCallback,); // never call this from RT
- }
- CARLA_SAFE_ASSERT(value >= -1.0f && value <= 1.0f);
-
- const float fixedValue(carla_fixedValue<float>(-1.0f, 1.0f, value));
-
- if (carla_isEqual(pData->postProc.balanceLeft, fixedValue))
- return;
-
- pData->postProc.balanceLeft = fixedValue;
-
- pData->engine->callback(sendCallback, sendOsc,
- ENGINE_CALLBACK_PARAMETER_VALUE_CHANGED,
- pData->id,
- PARAMETER_BALANCE_LEFT,
- 0, 0,
- fixedValue,
- nullptr);
- }
-
- void CarlaPlugin::setBalanceRight(const float value, const bool sendOsc, const bool sendCallback) noexcept
- {
- if (pData->engineBridged) {
- CARLA_SAFE_ASSERT_RETURN(!sendOsc && !sendCallback,);
- } else {
- CARLA_SAFE_ASSERT_RETURN(sendOsc || sendCallback,); // never call this from RT
- }
- CARLA_SAFE_ASSERT(value >= -1.0f && value <= 1.0f);
-
- const float fixedValue(carla_fixedValue<float>(-1.0f, 1.0f, value));
-
- if (carla_isEqual(pData->postProc.balanceRight, fixedValue))
- return;
-
- pData->postProc.balanceRight = fixedValue;
-
- pData->engine->callback(sendCallback, sendOsc,
- ENGINE_CALLBACK_PARAMETER_VALUE_CHANGED,
- pData->id,
- PARAMETER_BALANCE_RIGHT,
- 0, 0,
- fixedValue,
- nullptr);
- }
-
- void CarlaPlugin::setPanning(const float value, const bool sendOsc, const bool sendCallback) noexcept
- {
- if (pData->engineBridged) {
- CARLA_SAFE_ASSERT_RETURN(!sendOsc && !sendCallback,);
- } else {
- CARLA_SAFE_ASSERT_RETURN(sendOsc || sendCallback,); // never call this from RT
- }
- CARLA_SAFE_ASSERT(value >= -1.0f && value <= 1.0f);
-
- const float fixedValue(carla_fixedValue<float>(-1.0f, 1.0f, value));
-
- if (carla_isEqual(pData->postProc.panning, fixedValue))
- return;
-
- pData->postProc.panning = fixedValue;
-
- pData->engine->callback(sendCallback, sendOsc,
- ENGINE_CALLBACK_PARAMETER_VALUE_CHANGED,
- pData->id,
- PARAMETER_PANNING,
- 0, 0,
- fixedValue,
- nullptr);
- }
-
- void CarlaPlugin::setDryWetRT(const float value, const bool sendCallbackLater) noexcept
- {
- CARLA_SAFE_ASSERT(value >= 0.0f && value <= 1.0f);
-
- const float fixedValue(carla_fixedValue<float>(0.0f, 1.0f, value));
-
- if (carla_isEqual(pData->postProc.dryWet, fixedValue))
- return;
-
- pData->postProc.dryWet = fixedValue;
- pData->postponeParameterChangeRtEvent(sendCallbackLater, PARAMETER_DRYWET, fixedValue);
- }
-
- void CarlaPlugin::setVolumeRT(const float value, const bool sendCallbackLater) noexcept
- {
- CARLA_SAFE_ASSERT(value >= 0.0f && value <= 1.27f);
-
- const float fixedValue(carla_fixedValue<float>(0.0f, 1.27f, value));
-
- if (carla_isEqual(pData->postProc.volume, fixedValue))
- return;
-
- pData->postProc.volume = fixedValue;
- pData->postponeParameterChangeRtEvent(sendCallbackLater, PARAMETER_VOLUME, fixedValue);
- }
-
- void CarlaPlugin::setBalanceLeftRT(const float value, const bool sendCallbackLater) noexcept
- {
- CARLA_SAFE_ASSERT(value >= -1.0f && value <= 1.0f);
-
- const float fixedValue(carla_fixedValue<float>(-1.0f, 1.0f, value));
-
- if (carla_isEqual(pData->postProc.balanceLeft, fixedValue))
- return;
-
- pData->postProc.balanceLeft = fixedValue;
- pData->postponeParameterChangeRtEvent(sendCallbackLater, PARAMETER_BALANCE_LEFT, fixedValue);
- }
-
- void CarlaPlugin::setBalanceRightRT(const float value, const bool sendCallbackLater) noexcept
- {
- CARLA_SAFE_ASSERT(value >= -1.0f && value <= 1.0f);
-
- const float fixedValue(carla_fixedValue<float>(-1.0f, 1.0f, value));
-
- if (carla_isEqual(pData->postProc.balanceRight, fixedValue))
- return;
-
- pData->postProc.balanceRight = fixedValue;
- pData->postponeParameterChangeRtEvent(sendCallbackLater, PARAMETER_BALANCE_RIGHT, fixedValue);
- }
-
- void CarlaPlugin::setPanningRT(const float value, const bool sendCallbackLater) noexcept
- {
- CARLA_SAFE_ASSERT(value >= -1.0f && value <= 1.0f);
-
- const float fixedValue(carla_fixedValue<float>(-1.0f, 1.0f, value));
-
- if (carla_isEqual(pData->postProc.panning, fixedValue))
- return;
-
- pData->postProc.panning = fixedValue;
- pData->postponeParameterChangeRtEvent(sendCallbackLater, PARAMETER_PANNING, fixedValue);
- }
- #endif // ! BUILD_BRIDGE_ALTERNATIVE_ARCH
-
- void CarlaPlugin::setCtrlChannel(const int8_t channel, const bool sendOsc, const bool sendCallback) noexcept
- {
- if (pData->engineBridged) {
- CARLA_SAFE_ASSERT_RETURN(!sendOsc && !sendCallback,);
- } else {
- CARLA_SAFE_ASSERT_RETURN(sendOsc || sendCallback,); // never call this from RT
- }
- CARLA_SAFE_ASSERT_RETURN(channel >= -1 && channel < MAX_MIDI_CHANNELS,);
-
- if (pData->ctrlChannel == channel)
- return;
-
- pData->ctrlChannel = channel;
-
- #ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH
- const float channelf = static_cast<float>(channel);
-
- pData->engine->callback(sendCallback, sendOsc,
- ENGINE_CALLBACK_PARAMETER_VALUE_CHANGED,
- pData->id,
- PARAMETER_CTRL_CHANNEL,
- 0, 0,
- channelf, nullptr);
- #endif
- }
-
- // -------------------------------------------------------------------
- // Set data (plugin-specific stuff)
-
- void CarlaPlugin::setParameterValue(const uint32_t parameterId, const float value, const bool sendGui, const bool sendOsc, const bool sendCallback) noexcept
- {
- if (pData->engineBridged) {
- // NOTE: some LV2 plugins feedback messages to UI on purpose
- CARLA_SAFE_ASSERT_RETURN(getType() == PLUGIN_LV2 || !sendGui,);
- } else if (pData->enginePlugin) {
- // nothing here
- } else {
- CARLA_SAFE_ASSERT_RETURN(sendGui || sendOsc || sendCallback,); // never call this from RT
- }
- CARLA_SAFE_ASSERT_RETURN(parameterId < pData->param.count,);
-
- if (sendGui && (pData->hints & PLUGIN_HAS_CUSTOM_UI) != 0)
- uiParameterChange(parameterId, value);
-
- pData->engine->callback(sendCallback, sendOsc,
- ENGINE_CALLBACK_PARAMETER_VALUE_CHANGED,
- pData->id,
- static_cast<int>(parameterId),
- 0, 0,
- value,
- nullptr);
- }
-
- void CarlaPlugin::setParameterValueRT(const uint32_t parameterId, const float value, uint32_t, const bool sendCallbackLater) noexcept
- {
- pData->postponeParameterChangeRtEvent(sendCallbackLater, static_cast<int32_t>(parameterId), value);
- }
-
- void CarlaPlugin::setParameterValueByRealIndex(const int32_t rindex, const float value, const bool sendGui, const bool sendOsc, const bool sendCallback) noexcept
- {
- #ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH
- CARLA_SAFE_ASSERT_RETURN(rindex > PARAMETER_MAX && rindex != PARAMETER_NULL,);
-
- switch (rindex)
- {
- case PARAMETER_ACTIVE:
- return setActive((value > 0.0f), sendOsc, sendCallback);
- case PARAMETER_CTRL_CHANNEL:
- return setCtrlChannel(int8_t(value), sendOsc, sendCallback);
- case PARAMETER_DRYWET:
- return setDryWet(value, sendOsc, sendCallback);
- case PARAMETER_VOLUME:
- return setVolume(value, sendOsc, sendCallback);
- case PARAMETER_BALANCE_LEFT:
- return setBalanceLeft(value, sendOsc, sendCallback);
- case PARAMETER_BALANCE_RIGHT:
- return setBalanceRight(value, sendOsc, sendCallback);
- case PARAMETER_PANNING:
- return setPanning(value, sendOsc, sendCallback);
- }
- #endif
- CARLA_SAFE_ASSERT_RETURN(rindex >= 0,);
-
- for (uint32_t i=0; i < pData->param.count; ++i)
- {
- if (pData->param.data[i].rindex == rindex)
- {
- //if (carla_isNotEqual(getParameterValue(i), value))
- setParameterValue(i, value, sendGui, sendOsc, sendCallback);
- break;
- }
- }
- }
-
- void CarlaPlugin::setParameterMidiChannel(const uint32_t parameterId, const uint8_t channel, const bool sendOsc, const bool sendCallback) noexcept
- {
- if (pData->engineBridged) {
- CARLA_SAFE_ASSERT_RETURN(!sendOsc && !sendCallback,);
- } else {
- CARLA_SAFE_ASSERT_RETURN(sendOsc || sendCallback,); // never call this from RT
- }
- CARLA_SAFE_ASSERT_RETURN(parameterId < pData->param.count,);
- CARLA_SAFE_ASSERT_RETURN(channel < MAX_MIDI_CHANNELS,);
-
- if (pData->param.data[parameterId].midiChannel == channel)
- return;
-
- pData->param.data[parameterId].midiChannel = channel;
-
- #ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH
- pData->engine->callback(sendCallback, sendOsc,
- ENGINE_CALLBACK_PARAMETER_MIDI_CHANNEL_CHANGED,
- pData->id,
- static_cast<int>(parameterId),
- channel,
- 0, 0.0f, nullptr);
- #endif
- }
-
- void CarlaPlugin::setParameterMappedControlIndex(const uint32_t parameterId, const int16_t index,
- const bool sendOsc, const bool sendCallback,
- const bool reconfigureNow) noexcept
- {
- if (pData->engineBridged) {
- CARLA_SAFE_ASSERT_RETURN(!sendOsc && !sendCallback,);
- } else {
- CARLA_SAFE_ASSERT_RETURN(sendOsc || sendCallback,); // never call this from RT
- }
- CARLA_SAFE_ASSERT_RETURN(parameterId < pData->param.count,);
- CARLA_SAFE_ASSERT_RETURN(index >= CONTROL_INDEX_NONE && index <= CONTROL_INDEX_MAX_ALLOWED,);
-
- ParameterData& paramData(pData->param.data[parameterId]);
-
- if (paramData.mappedControlIndex == index)
- return;
-
- const ParameterRanges& paramRanges(pData->param.ranges[parameterId]);
-
- if ((paramData.hints & PARAMETER_MAPPED_RANGES_SET) == 0x0)
- setParameterMappedRange(parameterId, paramRanges.min, paramRanges.max, true, true);
-
- #ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH
- char strBuf[STR_MAX+1];
- carla_zeroChars(strBuf, STR_MAX+1);
- if (! getParameterName(parameterId, strBuf))
- std::snprintf(strBuf, STR_MAX, "Param %u", parameterId);
-
- const uint portNameSize = pData->engine->getMaxPortNameSize();
- if (portNameSize < STR_MAX)
- strBuf[portNameSize] = '\0';
-
- // was learning something else before, stop that first
- if (pData->midiLearnParameterIndex >= 0 && pData->midiLearnParameterIndex != static_cast<int32_t>(parameterId))
- {
- const int32_t oldParameterId = pData->midiLearnParameterIndex;
- pData->midiLearnParameterIndex = -1;
-
- CARLA_SAFE_ASSERT_RETURN(oldParameterId < static_cast<int32_t>(pData->param.count),);
-
- pData->param.data[oldParameterId].mappedControlIndex = CONTROL_INDEX_NONE;
- pData->engine->callback(true, true,
- ENGINE_CALLBACK_PARAMETER_MAPPED_CONTROL_INDEX_CHANGED,
- pData->id,
- oldParameterId,
- CONTROL_INDEX_NONE,
- 0, 0.0f, nullptr);
- }
-
- // mapping new parameter to CV
- if (index == CONTROL_INDEX_CV)
- {
- CARLA_SAFE_ASSERT_RETURN(pData->event.cvSourcePorts != nullptr,);
- CARLA_SAFE_ASSERT_RETURN(paramData.type == PARAMETER_INPUT,);
- CARLA_SAFE_ASSERT_RETURN(paramData.hints & PARAMETER_CAN_BE_CV_CONTROLLED,);
-
- CarlaEngineCVPort* const cvPort =
- (CarlaEngineCVPort*)pData->client->addPort(kEnginePortTypeCV, strBuf, true, parameterId);
- cvPort->setRange(paramData.mappedMinimum, paramData.mappedMaximum);
- pData->event.cvSourcePorts->addCVSource(cvPort, parameterId, reconfigureNow);
- }
- // unmapping from CV
- else if (paramData.mappedControlIndex == CONTROL_INDEX_CV)
- {
- CARLA_SAFE_ASSERT_RETURN(pData->event.cvSourcePorts != nullptr,);
-
- CARLA_SAFE_ASSERT(pData->client->removePort(kEnginePortTypeCV, strBuf, true));
- CARLA_SAFE_ASSERT(pData->event.cvSourcePorts->removeCVSource(parameterId));
- }
- // mapping to something new
- else if (paramData.mappedControlIndex == CONTROL_INDEX_NONE)
- {
- // when doing MIDI CC mapping, ensure ranges are within bounds
- if (paramData.mappedMinimum < paramRanges.min || paramData.mappedMaximum > paramRanges.max)
- setParameterMappedRange(parameterId,
- std::max(paramData.mappedMinimum, paramRanges.min),
- std::min(paramData.mappedMaximum, paramRanges.max),
- true, true);
- }
- #endif
-
- paramData.mappedControlIndex = index;
-
- #ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH
- if (index == CONTROL_INDEX_MIDI_LEARN)
- pData->midiLearnParameterIndex = static_cast<int32_t>(parameterId);
- else
- pData->midiLearnParameterIndex = -1;
-
- pData->engine->callback(sendCallback, sendOsc,
- ENGINE_CALLBACK_PARAMETER_MAPPED_CONTROL_INDEX_CHANGED,
- pData->id,
- static_cast<int>(parameterId),
- index,
- 0, 0.0f, nullptr);
- #else
- return;
- // unused
- (void)reconfigureNow;
- #endif
- }
-
- void CarlaPlugin::setParameterMappedRange(const uint32_t parameterId, const float minimum, const float maximum,
- const bool sendOsc, const bool sendCallback) noexcept
- {
- if (pData->engineBridged) {
- CARLA_SAFE_ASSERT_RETURN(!sendOsc && !sendCallback,);
- } else {
- CARLA_SAFE_ASSERT_RETURN(sendOsc || sendCallback,); // never call this from RT
- }
- CARLA_SAFE_ASSERT_RETURN(parameterId < pData->param.count,);
-
- ParameterData& paramData(pData->param.data[parameterId]);
-
- if (carla_isEqual(paramData.mappedMinimum, minimum) &&
- carla_isEqual(paramData.mappedMaximum, maximum) &&
- (paramData.hints & PARAMETER_MAPPED_RANGES_SET) != 0x0)
- return;
-
- if (paramData.mappedControlIndex != CONTROL_INDEX_NONE && paramData.mappedControlIndex != CONTROL_INDEX_CV)
- {
- const ParameterRanges& paramRanges(pData->param.ranges[parameterId]);
- CARLA_SAFE_ASSERT_RETURN(minimum >= paramRanges.min,);
- CARLA_SAFE_ASSERT_RETURN(maximum <= paramRanges.max,);
- }
-
- paramData.hints |= PARAMETER_MAPPED_RANGES_SET;
- paramData.mappedMinimum = minimum;
- paramData.mappedMaximum = maximum;
-
- #ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH
- if (pData->event.cvSourcePorts != nullptr && paramData.mappedControlIndex == CONTROL_INDEX_CV)
- pData->event.cvSourcePorts->setCVSourceRange(parameterId, minimum, maximum);
-
- char strBuf[STR_MAX+1];
- carla_zeroChars(strBuf, STR_MAX+1);
- std::snprintf(strBuf, STR_MAX, "%.12g:%.12g", static_cast<double>(minimum), static_cast<double>(maximum));
-
- pData->engine->callback(sendCallback, sendOsc,
- ENGINE_CALLBACK_PARAMETER_MAPPED_RANGE_CHANGED,
- pData->id,
- static_cast<int>(parameterId),
- 0, 0, 0.0f,
- strBuf);
- #endif
- }
-
- void CarlaPlugin::setCustomData(const char* const type, const char* const key, const char* const value, const bool)
- {
- CARLA_SAFE_ASSERT_RETURN(type != nullptr && type[0] != '\0',);
- CARLA_SAFE_ASSERT_RETURN(key != nullptr && key[0] != '\0',);
- CARLA_SAFE_ASSERT_RETURN(value != nullptr,);
-
- // Ignore some keys
- if (std::strcmp(type, CUSTOM_DATA_TYPE_STRING) == 0)
- {
- const PluginType ptype = getType();
-
- if ((ptype == PLUGIN_INTERNAL && std::strncmp(key, "CarlaAlternateFile", 18) == 0) ||
- (ptype == PLUGIN_DSSI && std::strcmp (key, "guiVisible") == 0) ||
- (ptype == PLUGIN_LV2 && std::strncmp(key, "OSC:", 4) == 0))
- return;
- }
-
- // Check if we already have this key
- for (LinkedList<CustomData>::Itenerator it = pData->custom.begin2(); it.valid(); it.next())
- {
- CustomData& customData(it.getValue(kCustomDataFallbackNC));
- CARLA_SAFE_ASSERT_CONTINUE(customData.isValid());
-
- if (std::strcmp(customData.key, key) == 0)
- {
- if (customData.value != nullptr)
- delete[] customData.value;
-
- customData.value = carla_strdup(value);
- return;
- }
- }
-
- // Otherwise store it
- CustomData customData;
- customData.type = carla_strdup(type);
- customData.key = carla_strdup(key);
- customData.value = carla_strdup(value);
- pData->custom.append(customData);
- }
-
- void CarlaPlugin::setChunkData(const void* const data, const std::size_t dataSize)
- {
- CARLA_SAFE_ASSERT_RETURN(data != nullptr,);
- CARLA_SAFE_ASSERT_RETURN(dataSize > 0,);
- CARLA_SAFE_ASSERT(false); // this should never happen
- }
-
- void CarlaPlugin::setProgram(const int32_t index,
- const bool sendGui, const bool sendOsc, const bool sendCallback, const bool) noexcept
- {
- CARLA_SAFE_ASSERT_RETURN(index >= -1 && index < static_cast<int32_t>(pData->prog.count),);
-
- pData->prog.current = index;
-
- pData->engine->callback(sendCallback, sendOsc,
- ENGINE_CALLBACK_PROGRAM_CHANGED,
- pData->id,
- index,
- 0, 0, 0.0f, nullptr);
-
- // Change default parameter values
- if (index >= 0)
- {
- if (sendGui && (pData->hints & PLUGIN_HAS_CUSTOM_UI) != 0)
- uiProgramChange(static_cast<uint32_t>(index));
-
- switch (getType())
- {
- case PLUGIN_SF2:
- case PLUGIN_SFZ:
- break;
-
- default:
- pData->updateParameterValues(this, sendCallback, sendOsc, true);
- break;
- }
- }
- }
-
- void CarlaPlugin::setMidiProgram(const int32_t index,
- const bool sendGui, const bool sendOsc, const bool sendCallback, const bool) noexcept
- {
- CARLA_SAFE_ASSERT_RETURN(index >= -1 && index < static_cast<int32_t>(pData->midiprog.count),);
-
- pData->midiprog.current = index;
-
- pData->engine->callback(sendCallback, sendOsc,
- ENGINE_CALLBACK_MIDI_PROGRAM_CHANGED,
- pData->id,
- index,
- 0, 0, 0.0f, nullptr);
-
- // Change default parameter values
- if (index >= 0)
- {
- if (sendGui && (pData->hints & PLUGIN_HAS_CUSTOM_UI) != 0)
- uiMidiProgramChange(static_cast<uint32_t>(index));
-
- switch (getType())
- {
- case PLUGIN_SF2:
- case PLUGIN_SFZ:
- break;
-
- default:
- pData->updateParameterValues(this, sendCallback, sendOsc, true);
- break;
- }
- }
- }
-
- void CarlaPlugin::setMidiProgramById(const uint32_t bank, const uint32_t program, const bool sendGui, const bool sendOsc, const bool sendCallback) noexcept
- {
- for (uint32_t i=0; i < pData->midiprog.count; ++i)
- {
- if (pData->midiprog.data[i].bank == bank && pData->midiprog.data[i].program == program)
- return setMidiProgram(static_cast<int32_t>(i), sendGui, sendOsc, sendCallback);
- }
- }
-
- void CarlaPlugin::setProgramRT(const uint32_t uindex, const bool sendCallbackLater) noexcept
- {
- CARLA_SAFE_ASSERT_RETURN(uindex < pData->prog.count,);
-
- const int32_t index = static_cast<int32_t>(uindex);
- pData->prog.current = index;
-
- // Change default parameter values
- switch (getType())
- {
- case PLUGIN_SF2:
- case PLUGIN_SFZ:
- break;
-
- default:
- pData->updateDefaultParameterValues(this);
- break;
- }
-
- pData->postponeProgramChangeRtEvent(sendCallbackLater, uindex);
- }
-
- void CarlaPlugin::setMidiProgramRT(const uint32_t uindex, const bool sendCallbackLater) noexcept
- {
- CARLA_SAFE_ASSERT_RETURN(uindex < pData->midiprog.count,);
-
- const int32_t index = static_cast<int32_t>(uindex);
- pData->midiprog.current = index;
-
- // Change default parameter values
- switch (getType())
- {
- case PLUGIN_SF2:
- case PLUGIN_SFZ:
- break;
-
- default:
- pData->updateDefaultParameterValues(this);
- break;
- }
-
- pData->postponeMidiProgramChangeRtEvent(sendCallbackLater, uindex);
- }
-
- // -------------------------------------------------------------------
- // Plugin state
-
- void CarlaPlugin::reloadPrograms(const bool)
- {
- }
-
- // -------------------------------------------------------------------
- // Plugin processing
-
- void CarlaPlugin::activate() noexcept
- {
- CARLA_SAFE_ASSERT(! pData->active);
- }
-
- void CarlaPlugin::deactivate() noexcept
- {
- CARLA_SAFE_ASSERT(pData->active);
- }
-
- void CarlaPlugin::bufferSizeChanged(const uint32_t newBufferSize)
- {
- #ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH
- delete[] pData->postProc.extraBuffer;
- pData->postProc.extraBuffer = new float[newBufferSize];
- #else
- // unused
- (void)newBufferSize;
- #endif
- }
-
- void CarlaPlugin::sampleRateChanged(const double)
- {
- }
-
- void CarlaPlugin::offlineModeChanged(const bool)
- {
- }
-
- // -------------------------------------------------------------------
- // Misc
-
- void CarlaPlugin::idle()
- {
- if (! pData->enabled)
- return;
-
- const bool hasUI = pData->hints & PLUGIN_HAS_CUSTOM_UI;
- const bool needsUiMainThread = pData->hints & PLUGIN_NEEDS_UI_MAIN_THREAD;
- const uint32_t latency = getLatencyInFrames();
-
- if (pData->latency.frames != latency)
- {
- carla_stdout("latency changed to %i samples", latency);
-
- const ScopedSingleProcessLocker sspl(this, true);
-
- pData->client->setLatency(latency);
- #ifndef BUILD_BRIDGE
- pData->latency.recreateBuffers(pData->latency.channels, latency);
- #else
- pData->latency.frames = latency;
- #endif
- }
-
- ProtectedData::PostRtEvents::Access rtEvents(pData->postRtEvents);
-
- if (rtEvents.isEmpty())
- return;
-
- for (RtLinkedList<PluginPostRtEvent>::Itenerator it = rtEvents.getDataIterator(); it.valid(); it.next())
- {
- const PluginPostRtEvent& event(it.getValue(kPluginPostRtEventFallback));
- CARLA_SAFE_ASSERT_CONTINUE(event.type != kPluginPostRtEventNull);
-
- switch (event.type)
- {
- case kPluginPostRtEventNull: {
- } break;
-
- case kPluginPostRtEventParameterChange: {
- // Update UI
- if (event.parameter.index >= 0 && hasUI)
- {
- if (needsUiMainThread)
- pData->postUiEvents.append(event);
- else
- uiParameterChange(static_cast<uint32_t>(event.parameter.index), event.parameter.value);
- }
-
- if (event.sendCallback)
- {
- // Update Host
- pData->engine->callback(true, true,
- ENGINE_CALLBACK_PARAMETER_VALUE_CHANGED,
- pData->id,
- event.parameter.index,
- 0, 0,
- event.parameter.value,
- nullptr);
- }
- } break;
-
- case kPluginPostRtEventProgramChange: {
- // Update UI
- if (hasUI)
- {
- if (needsUiMainThread)
- pData->postUiEvents.append(event);
- else
- uiProgramChange(event.program.index);
- }
-
- // Update param values
- for (uint32_t j=0; j < pData->param.count; ++j)
- {
- const float paramDefault(pData->param.ranges[j].def);
- const float paramValue(getParameterValue(j));
-
- pData->engine->callback(true, true,
- ENGINE_CALLBACK_PARAMETER_VALUE_CHANGED,
- pData->id,
- static_cast<int>(j),
- 0, 0,
- paramValue,
- nullptr);
- pData->engine->callback(true, true,
- ENGINE_CALLBACK_PARAMETER_DEFAULT_CHANGED,
- pData->id,
- static_cast<int>(j),
- 0, 0,
- paramDefault,
- nullptr);
- }
-
- if (event.sendCallback)
- {
- // Update Host
- pData->engine->callback(true, true,
- ENGINE_CALLBACK_PROGRAM_CHANGED,
- pData->id,
- static_cast<int>(event.program.index),
- 0, 0, 0.0f, nullptr);
- }
- } break;
-
- case kPluginPostRtEventMidiProgramChange: {
- // Update UI
- if (hasUI)
- {
- if (needsUiMainThread)
- pData->postUiEvents.append(event);
- else
- uiMidiProgramChange(event.program.index);
- }
-
- // Update param values
- for (uint32_t j=0; j < pData->param.count; ++j)
- {
- const float paramDefault(pData->param.ranges[j].def);
- const float paramValue(getParameterValue(j));
-
- pData->engine->callback(true, true,
- ENGINE_CALLBACK_PARAMETER_VALUE_CHANGED,
- pData->id,
- static_cast<int>(j),
- 0, 0,
- paramValue,
- nullptr);
- pData->engine->callback(true, true,
- ENGINE_CALLBACK_PARAMETER_DEFAULT_CHANGED,
- pData->id,
- static_cast<int>(j),
- 0, 0,
- paramDefault,
- nullptr);
- }
-
- if (event.sendCallback)
- {
- // Update Host
- pData->engine->callback(true, true,
- ENGINE_CALLBACK_MIDI_PROGRAM_CHANGED,
- pData->id,
- static_cast<int>(event.program.index),
- 0, 0, 0.0f, nullptr);
- }
- } break;
-
- case kPluginPostRtEventNoteOn: {
- CARLA_SAFE_ASSERT_BREAK(event.note.channel < MAX_MIDI_CHANNELS);
- CARLA_SAFE_ASSERT_BREAK(event.note.note < MAX_MIDI_NOTE);
- CARLA_SAFE_ASSERT_BREAK(event.note.velocity < MAX_MIDI_VALUE);
-
- // Update UI
- if (hasUI)
- {
- if (needsUiMainThread)
- pData->postUiEvents.append(event);
- else
- uiNoteOn(event.note.channel, event.note.note, event.note.velocity);
- }
-
- if (event.sendCallback)
- {
- // Update Host
- pData->engine->callback(true, true,
- ENGINE_CALLBACK_NOTE_ON,
- pData->id,
- static_cast<int>(event.note.channel),
- static_cast<int>(event.note.note),
- static_cast<int>(event.note.velocity),
- 0.0f, nullptr);
- }
- } break;
-
- case kPluginPostRtEventNoteOff: {
- CARLA_SAFE_ASSERT_BREAK(event.note.channel < MAX_MIDI_CHANNELS);
- CARLA_SAFE_ASSERT_BREAK(event.note.note < MAX_MIDI_NOTE);
-
- // Update UI
- if (hasUI)
- {
- if (needsUiMainThread)
- pData->postUiEvents.append(event);
- else
- uiNoteOff(event.note.channel, event.note.note);
- }
-
- if (event.sendCallback)
- {
- // Update Host
- pData->engine->callback(true, true,
- ENGINE_CALLBACK_NOTE_OFF,
- pData->id,
- static_cast<int>(event.note.channel),
- static_cast<int>(event.note.note),
- 0, 0.0f, nullptr);
- }
- } break;
-
- case kPluginPostRtEventMidiLearn: {
- CARLA_SAFE_ASSERT_BREAK(event.midiLearn.cc < MAX_MIDI_VALUE);
- CARLA_SAFE_ASSERT_BREAK(event.midiLearn.channel < MAX_MIDI_CHANNELS);
-
- #ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH
- if (event.sendCallback)
- {
- pData->engine->callback(true, true,
- ENGINE_CALLBACK_PARAMETER_MAPPED_CONTROL_INDEX_CHANGED,
- pData->id,
- static_cast<int>(event.midiLearn.parameter),
- static_cast<int>(event.midiLearn.cc),
- 0, 0.0f, nullptr);
-
- pData->engine->callback(true, true,
- ENGINE_CALLBACK_PARAMETER_MIDI_CHANNEL_CHANGED,
- pData->id,
- static_cast<int>(event.midiLearn.parameter),
- static_cast<int>(event.midiLearn.channel),
- 0, 0.0f, nullptr);
- }
- #endif
- } break;
- }
- }
- }
-
- bool CarlaPlugin::tryLock(const bool forcedOffline) noexcept
- {
- if (forcedOffline)
- {
- #ifndef STOAT_TEST_BUILD
- pData->masterMutex.lock();
- return true;
- #endif
- }
-
- return pData->masterMutex.tryLock();
- }
-
- void CarlaPlugin::unlock() noexcept
- {
- pData->masterMutex.unlock();
- }
-
- // -------------------------------------------------------------------
- // Plugin buffers
-
- void CarlaPlugin::initBuffers() const noexcept
- {
- pData->audioIn.initBuffers();
- pData->audioOut.initBuffers();
- pData->cvIn.initBuffers();
- pData->cvOut.initBuffers();
- pData->event.initBuffers();
- }
-
- void CarlaPlugin::clearBuffers() noexcept
- {
- pData->clearBuffers();
- }
-
- // -------------------------------------------------------------------
- // OSC stuff
-
- // FIXME
- void CarlaPlugin::handleOscMessage(const char* const, const int, const void* const, const char* const, const lo_message)
- {
- // do nothing
- }
-
- // -------------------------------------------------------------------
- // MIDI events
-
- void CarlaPlugin::sendMidiSingleNote(const uint8_t channel, const uint8_t note, const uint8_t velo, const bool sendGui, const bool sendOsc, const bool sendCallback)
- {
- CARLA_SAFE_ASSERT_RETURN(channel < MAX_MIDI_CHANNELS,);
- CARLA_SAFE_ASSERT_RETURN(note < MAX_MIDI_NOTE,);
- CARLA_SAFE_ASSERT_RETURN(velo < MAX_MIDI_VALUE,);
-
- if (! pData->active)
- return;
-
- ExternalMidiNote extNote;
- extNote.channel = static_cast<int8_t>(channel);
- extNote.note = note;
- extNote.velo = velo;
-
- pData->extNotes.appendNonRT(extNote);
-
- if (sendGui && (pData->hints & PLUGIN_HAS_CUSTOM_UI) != 0)
- {
- if (velo > 0)
- uiNoteOn(channel, note, velo);
- else
- uiNoteOff(channel, note);
- }
-
- pData->engine->callback(sendCallback, sendOsc,
- (velo > 0) ? ENGINE_CALLBACK_NOTE_ON : ENGINE_CALLBACK_NOTE_OFF,
- pData->id,
- channel,
- note,
- velo,
- 0.0f, nullptr);
- }
-
- #ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH
- void CarlaPlugin::postponeRtAllNotesOff()
- {
- if (pData->ctrlChannel < 0 || pData->ctrlChannel >= MAX_MIDI_CHANNELS)
- return;
-
- PluginPostRtEvent postEvent = { kPluginPostRtEventNoteOff, true, {} };
- postEvent.note.channel = static_cast<uint8_t>(pData->ctrlChannel);
-
- for (uint8_t i=0; i < MAX_MIDI_NOTE; ++i)
- {
- postEvent.note.note = i;
- pData->postRtEvents.appendRT(postEvent);
- }
- }
- #endif
-
- // -------------------------------------------------------------------
- // UI Stuff
-
- void CarlaPlugin::setCustomUITitle(const char* const title) noexcept
- {
- pData->uiTitle = title;
- }
-
- void CarlaPlugin::showCustomUI(const bool yesNo)
- {
- if (yesNo) {
- CARLA_SAFE_ASSERT(false);
- }
- }
-
- void* CarlaPlugin::embedCustomUI(void*)
- {
- return nullptr;
- }
-
- void CarlaPlugin::uiIdle()
- {
- if (pData->hints & PLUGIN_NEEDS_UI_MAIN_THREAD)
- {
- // Update parameter outputs
- for (uint32_t i=0; i < pData->param.count; ++i)
- {
- if (pData->param.data[i].type == PARAMETER_OUTPUT)
- uiParameterChange(i, getParameterValue(i));
- }
-
- const CarlaMutexLocker sl(pData->postUiEvents.mutex);
-
- for (LinkedList<PluginPostRtEvent>::Itenerator it = pData->postUiEvents.data.begin2(); it.valid(); it.next())
- {
- const PluginPostRtEvent& event(it.getValue(kPluginPostRtEventFallback));
- CARLA_SAFE_ASSERT_CONTINUE(event.type != kPluginPostRtEventNull);
-
- switch (event.type)
- {
- case kPluginPostRtEventNull:
- case kPluginPostRtEventMidiLearn:
- break;
-
- case kPluginPostRtEventParameterChange:
- uiParameterChange(static_cast<uint32_t>(event.parameter.index), event.parameter.value);
- break;
-
- case kPluginPostRtEventProgramChange:
- uiProgramChange(event.program.index);
- break;
-
- case kPluginPostRtEventMidiProgramChange:
- uiMidiProgramChange(event.program.index);
- break;
-
- case kPluginPostRtEventNoteOn:
- uiNoteOn(event.note.channel, event.note.note, event.note.velocity);
- break;
-
- case kPluginPostRtEventNoteOff:
- uiNoteOff(event.note.channel, event.note.note);
- break;
- }
- }
-
- pData->postUiEvents.data.clear();
- }
-
- #ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH
- if (pData->transientTryCounter == 0)
- return;
- if (++pData->transientTryCounter % 10 != 0)
- return;
- if (pData->transientTryCounter >= 200)
- return;
-
- carla_stdout("Trying to get window...");
-
- CarlaString uiTitle;
-
- if (pData->uiTitle.isNotEmpty())
- {
- uiTitle = pData->uiTitle;
- }
- else
- {
- uiTitle = pData->name;
- uiTitle += " (GUI)";
- }
-
- if (CarlaPluginUI::tryTransientWinIdMatch(getUiBridgeProcessId(), uiTitle,
- pData->engine->getOptions().frontendWinId, pData->transientFirstTry))
- {
- pData->transientTryCounter = 0;
- pData->transientFirstTry = false;
- }
- #endif
- }
-
- void CarlaPlugin::uiParameterChange(const uint32_t index, const float value) noexcept
- {
- CARLA_SAFE_ASSERT_RETURN(index < getParameterCount(),);
- return;
-
- // unused
- (void)value;
- }
-
- void CarlaPlugin::uiProgramChange(const uint32_t index) noexcept
- {
- CARLA_SAFE_ASSERT_RETURN(index < getProgramCount(),);
- }
-
- void CarlaPlugin::uiMidiProgramChange(const uint32_t index) noexcept
- {
- CARLA_SAFE_ASSERT_RETURN(index < getMidiProgramCount(),);
- }
-
- void CarlaPlugin::uiNoteOn(const uint8_t channel, const uint8_t note, const uint8_t velo) noexcept
- {
- CARLA_SAFE_ASSERT_RETURN(channel < MAX_MIDI_CHANNELS,);
- CARLA_SAFE_ASSERT_RETURN(note < MAX_MIDI_NOTE,);
- CARLA_SAFE_ASSERT_RETURN(velo > 0 && velo < MAX_MIDI_VALUE,);
- }
-
- void CarlaPlugin::uiNoteOff(const uint8_t channel, const uint8_t note) noexcept
- {
- CARLA_SAFE_ASSERT_RETURN(channel < MAX_MIDI_CHANNELS,);
- CARLA_SAFE_ASSERT_RETURN(note < MAX_MIDI_NOTE,);
- }
-
- CarlaEngine* CarlaPlugin::getEngine() const noexcept
- {
- return pData->engine;
- }
-
- CarlaEngineClient* CarlaPlugin::getEngineClient() const noexcept
- {
- return pData->client;
- }
-
- CarlaEngineAudioPort* CarlaPlugin::getAudioInPort(const uint32_t index) const noexcept
- {
- return pData->audioIn.ports[index].port;
- }
-
- CarlaEngineAudioPort* CarlaPlugin::getAudioOutPort(const uint32_t index) const noexcept
- {
- return pData->audioOut.ports[index].port;
- }
-
- CarlaEngineCVPort* CarlaPlugin::getCVInPort(const uint32_t index) const noexcept
- {
- return pData->cvIn.ports[index].port;
- }
-
- CarlaEngineCVPort* CarlaPlugin::getCVOutPort(const uint32_t index) const noexcept
- {
- return pData->cvOut.ports[index].port;
- }
-
- CarlaEngineEventPort* CarlaPlugin::getDefaultEventInPort() const noexcept
- {
- return pData->event.portIn;
- }
-
- CarlaEngineEventPort* CarlaPlugin::getDefaultEventOutPort() const noexcept
- {
- return pData->event.portOut;
- }
-
- #ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH
- void CarlaPlugin::checkForMidiLearn(EngineEvent& event) noexcept
- {
- if (pData->midiLearnParameterIndex < 0)
- return;
- if (event.ctrl.param == MIDI_CONTROL_BANK_SELECT || event.ctrl.param == MIDI_CONTROL_BANK_SELECT__LSB)
- return;
- if (event.ctrl.param >= MAX_MIDI_CONTROL)
- return;
-
- const uint32_t parameterId = static_cast<uint32_t>(pData->midiLearnParameterIndex);
- CARLA_SAFE_ASSERT_UINT2_RETURN(parameterId < pData->param.count, parameterId, pData->param.count,);
-
- ParameterData& paramData(pData->param.data[parameterId]);
- CARLA_SAFE_ASSERT_INT_RETURN(paramData.mappedControlIndex == CONTROL_INDEX_MIDI_LEARN,
- paramData.mappedControlIndex,);
-
- event.ctrl.handled = true;
- paramData.mappedControlIndex = static_cast<int16_t>(event.ctrl.param);
- paramData.midiChannel = event.channel;
-
- pData->postponeMidiLearnRtEvent(true, parameterId, static_cast<uint8_t>(event.ctrl.param), event.channel);
- pData->midiLearnParameterIndex = -1;
- }
- #endif
-
- void* CarlaPlugin::getNativeHandle() const noexcept
- {
- return nullptr;
- }
-
- const void* CarlaPlugin::getNativeDescriptor() const noexcept
- {
- return nullptr;
- }
-
- uintptr_t CarlaPlugin::getUiBridgeProcessId() const noexcept
- {
- return 0;
- }
-
- // -------------------------------------------------------------------
-
- uint32_t CarlaPlugin::getPatchbayNodeId() const noexcept
- {
- return pData->nodeId;
- }
-
- void CarlaPlugin::setPatchbayNodeId(const uint32_t nodeId) noexcept
- {
- pData->nodeId = nodeId;
- }
-
- // -------------------------------------------------------------------
-
- void CarlaPlugin::cloneLV2Files(const CarlaPlugin&)
- {
- carla_stderr2("Warning: cloneLV2Files() called for non-implemented type");
- }
-
- void CarlaPlugin::restoreLV2State(const bool temporary) noexcept
- {
- carla_stderr2("Warning: restoreLV2State(%s) called for non-implemented type", bool2str(temporary));
- }
-
- void CarlaPlugin::prepareForDeletion() noexcept
- {
- carla_debug("CarlaPlugin::prepareForDeletion");
-
- const CarlaMutexLocker cml(pData->masterMutex);
-
- pData->client->deactivate(true);
- }
-
- void CarlaPlugin::waitForBridgeSaveSignal() noexcept
- {
- }
-
- // -------------------------------------------------------------------
- // Scoped Disabler
-
- CarlaPlugin::ScopedDisabler::ScopedDisabler(CarlaPlugin* const plugin) noexcept
- : fPlugin(plugin),
- fWasEnabled(false)
- {
- CARLA_SAFE_ASSERT_RETURN(plugin != nullptr,);
- CARLA_SAFE_ASSERT_RETURN(plugin->pData != nullptr,);
- CARLA_SAFE_ASSERT_RETURN(plugin->pData->client != nullptr,);
- carla_debug("CarlaPlugin::ScopedDisabler(%p)", plugin);
-
- plugin->pData->masterMutex.lock();
-
- if (plugin->pData->enabled)
- {
- fWasEnabled = true;
- plugin->pData->enabled = false;
-
- if (plugin->pData->client->isActive())
- plugin->pData->client->deactivate(false);
- }
- }
-
- CarlaPlugin::ScopedDisabler::~ScopedDisabler() noexcept
- {
- CARLA_SAFE_ASSERT_RETURN(fPlugin != nullptr,);
- CARLA_SAFE_ASSERT_RETURN(fPlugin->pData != nullptr,);
- CARLA_SAFE_ASSERT_RETURN(fPlugin->pData->client != nullptr,);
- carla_debug("CarlaPlugin::~ScopedDisabler()");
-
- if (fWasEnabled)
- {
- fPlugin->pData->enabled = true;
- fPlugin->pData->client->activate();
- }
-
- fPlugin->pData->masterMutex.unlock();
- }
-
- // -------------------------------------------------------------------
- // Scoped Process Locker
-
- CarlaPlugin::ScopedSingleProcessLocker::ScopedSingleProcessLocker(CarlaPlugin* const plugin, const bool block) noexcept
- : fPlugin(plugin),
- fBlock(block)
- {
- CARLA_SAFE_ASSERT_RETURN(fPlugin != nullptr,);
- CARLA_SAFE_ASSERT_RETURN(fPlugin->pData != nullptr,);
- carla_debug("CarlaPlugin::ScopedSingleProcessLocker(%p, %s)", plugin, bool2str(block));
-
- if (! fBlock)
- return;
-
- plugin->pData->singleMutex.lock();
- }
-
- CarlaPlugin::ScopedSingleProcessLocker::~ScopedSingleProcessLocker() noexcept
- {
- CARLA_SAFE_ASSERT_RETURN(fPlugin != nullptr,);
- CARLA_SAFE_ASSERT_RETURN(fPlugin->pData != nullptr,);
- carla_debug("CarlaPlugin::~ScopedSingleProcessLocker()");
-
- if (! fBlock)
- return;
-
- #ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH
- if (fPlugin->pData->singleMutex.wasTryLockCalled())
- fPlugin->pData->needsReset = true;
- #endif
-
- fPlugin->pData->singleMutex.unlock();
- }
-
- // -------------------------------------------------------------------
-
- CARLA_BACKEND_END_NAMESPACE
|