|
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125 |
- /*
- * Carla Plugin
- * Copyright (C) 2011-2013 Filipe Coelho <falktx@falktx.com>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of
- * the License, or any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * For a full copy of the GNU General Public License see the doc/GPL.txt file.
- */
-
- #include "CarlaPluginInternal.hpp"
- #include "CarlaLibCounter.hpp"
-
- #include <QtCore/QFile>
- #include <QtCore/QTextStream>
- #include <QtCore/QSettings>
-
- CARLA_BACKEND_START_NAMESPACE
-
- // -------------------------------------------------------------------
- // Fallback data
-
- static const ParameterData kParameterDataNull = { PARAMETER_UNKNOWN, 0x0, PARAMETER_NULL, -1, -1, 0 };
- 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 kCustomDataNull = { nullptr, nullptr, nullptr };
-
- static bool gIsLoadingProject = false;
-
- // -------------------------------------------------------------------
- // ParamSymbol struct, needed for CarlaPlugin::loadSaveState()
-
- struct ParamSymbol {
- uint32_t index;
- const char* symbol;
-
- ParamSymbol(uint32_t i, const char* s)
- : index(i),
- symbol(carla_strdup(s)) {}
-
- ~ParamSymbol()
- {
- CARLA_SAFE_ASSERT_RETURN(symbol != nullptr,)
-
- delete[] symbol;
- symbol = nullptr;
- }
-
- #ifdef CARLA_PROPER_CPP11_SUPPORT
- ParamSymbol() = delete;
- CARLA_DECLARE_NON_COPY_STRUCT(ParamSymbol)
- #endif
- };
-
- // -------------------------------------------------------------------
- // Library functions, defined in CarlaPluginInternal.hpp
-
- static LibCounter sLibCounter;
-
- bool CarlaPluginProtectedData::libOpen(const char* const filename)
- {
- lib = sLibCounter.open(filename);
- return (lib != nullptr);
- }
-
- bool CarlaPluginProtectedData::libClose()
- {
- const bool ret = sLibCounter.close(lib);
- lib = nullptr;
- return ret;
- }
-
- void* CarlaPluginProtectedData::libSymbol(const char* const symbol)
- {
- return lib_symbol(lib, symbol);
- }
-
- bool CarlaPluginProtectedData::uiLibOpen(const char* const filename)
- {
- uiLib = sLibCounter.open(filename);
- return (uiLib != nullptr);
- }
-
- bool CarlaPluginProtectedData::uiLibClose()
- {
- const bool ret = sLibCounter.close(uiLib);
- uiLib = nullptr;
- return ret;
- }
-
- void* CarlaPluginProtectedData::uiLibSymbol(const char* const symbol)
- {
- return lib_symbol(uiLib, symbol);
- }
-
- // -------------------------------------------------------------------
- // Settings functions, defined in CarlaPluginInternal.hpp
-
- void CarlaPluginProtectedData::saveSetting(const unsigned int option, const bool yesNo)
- {
- CARLA_SAFE_ASSERT_RETURN(identifier != nullptr && identifier[0] != '\0',);
-
- QSettings settings("falkTX", "CarlaPluginSettings");
- settings.beginGroup(identifier);
-
- switch (option)
- {
- case PLUGIN_OPTION_FIXED_BUFFERS:
- settings.setValue("FixedBuffers", yesNo);
- break;
- case PLUGIN_OPTION_FORCE_STEREO:
- settings.setValue("ForceStereo", yesNo);
- break;
- case PLUGIN_OPTION_MAP_PROGRAM_CHANGES:
- settings.setValue("MapProgramChanges", yesNo);
- break;
- case PLUGIN_OPTION_USE_CHUNKS:
- settings.setValue("UseChunks", yesNo);
- break;
- case PLUGIN_OPTION_SEND_CONTROL_CHANGES:
- settings.setValue("SendControlChanges", yesNo);
- break;
- case PLUGIN_OPTION_SEND_CHANNEL_PRESSURE:
- settings.setValue("SendChannelPressure", yesNo);
- break;
- case PLUGIN_OPTION_SEND_NOTE_AFTERTOUCH:
- settings.setValue("SendNoteAftertouch", yesNo);
- break;
- case PLUGIN_OPTION_SEND_PITCHBEND:
- settings.setValue("SendPitchbend", yesNo);
- break;
- case PLUGIN_OPTION_SEND_ALL_SOUND_OFF:
- settings.setValue("SendAllSoundOff", yesNo);
- break;
- default:
- break;
- }
-
- settings.endGroup();
- }
-
- unsigned int CarlaPluginProtectedData::loadSettings(const unsigned int options, const unsigned int availOptions)
- {
- CARLA_SAFE_ASSERT_RETURN(identifier != nullptr && identifier[0] != '\0', 0x0);
-
- QSettings settings("falkTX", "CarlaPluginSettings");
- settings.beginGroup(identifier);
-
- unsigned int newOptions = 0x0;
-
- #define CHECK_AND_SET_OPTION(STR, BIT) \
- if ((availOptions & BIT) != 0 || BIT == PLUGIN_OPTION_FORCE_STEREO) \
- { \
- if (settings.contains(STR)) \
- { \
- if (settings.value(STR, (options & BIT) != 0).toBool()) \
- newOptions |= BIT; \
- } \
- else if (options & BIT) \
- newOptions |= BIT; \
- }
-
- CHECK_AND_SET_OPTION("FixedBuffers", PLUGIN_OPTION_FIXED_BUFFERS);
- CHECK_AND_SET_OPTION("ForceStereo", PLUGIN_OPTION_FORCE_STEREO);
- CHECK_AND_SET_OPTION("MapProgramChanges", PLUGIN_OPTION_MAP_PROGRAM_CHANGES);
- CHECK_AND_SET_OPTION("UseChunks", PLUGIN_OPTION_USE_CHUNKS);
- CHECK_AND_SET_OPTION("SendControlChanges", PLUGIN_OPTION_SEND_CONTROL_CHANGES);
- CHECK_AND_SET_OPTION("SendChannelPressure", PLUGIN_OPTION_SEND_CHANNEL_PRESSURE);
- CHECK_AND_SET_OPTION("SendNoteAftertouch", PLUGIN_OPTION_SEND_NOTE_AFTERTOUCH);
- CHECK_AND_SET_OPTION("SendPitchbend", PLUGIN_OPTION_SEND_PITCHBEND);
- CHECK_AND_SET_OPTION("SendAllSoundOff", PLUGIN_OPTION_SEND_ALL_SOUND_OFF);
-
- #undef CHECK_AND_SET_OPTION
-
- settings.endGroup();
-
- return newOptions;
- }
-
- // -------------------------------------------------------------------
- // Constructor and destructor
-
- CarlaPlugin::CarlaPlugin(CarlaEngine* const engine, const unsigned int id)
- : pData(new CarlaPluginProtectedData(engine, id, this))
- {
- CARLA_SAFE_ASSERT_RETURN(engine != nullptr,);
- CARLA_ASSERT(id < engine->getMaxPluginNumber());
- CARLA_ASSERT(id == engine->getCurrentPluginCount());
- carla_debug("CarlaPlugin::CarlaPlugin(%p, %i)", engine, id);
-
- switch (engine->getProccessMode())
- {
- case ENGINE_PROCESS_MODE_SINGLE_CLIENT:
- case ENGINE_PROCESS_MODE_MULTIPLE_CLIENTS:
- CARLA_ASSERT(id < MAX_DEFAULT_PLUGINS);
- break;
-
- case ENGINE_PROCESS_MODE_CONTINUOUS_RACK:
- CARLA_ASSERT(id < MAX_RACK_PLUGINS);
- break;
-
- case ENGINE_PROCESS_MODE_PATCHBAY:
- CARLA_ASSERT(id < MAX_PATCHBAY_PLUGINS);
- break;
-
- case ENGINE_PROCESS_MODE_BRIDGE:
- CARLA_ASSERT(id == 0);
- break;
- }
- }
-
- CarlaPlugin::~CarlaPlugin()
- {
- carla_debug("CarlaPlugin::~CarlaPlugin()");
-
- delete pData;
- }
-
- // -------------------------------------------------------------------
- // Information (base)
-
- unsigned int CarlaPlugin::getId() const noexcept
- {
- return pData->id;
- }
-
- unsigned int CarlaPlugin::getHints() const noexcept
- {
- return pData->hints;
- }
-
- unsigned int 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;
- }
-
- uint32_t CarlaPlugin::getLatencyInFrames() const noexcept
- {
- return pData->latency;
- }
-
- // -------------------------------------------------------------------
- // 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::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
- {
- 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;
- }
-
- const ParameterData& CarlaPlugin::getParameterData(const uint32_t parameterId) const
- {
- CARLA_SAFE_ASSERT_RETURN(parameterId < pData->param.count, kParameterDataNull);
- return pData->param.data[parameterId];
- }
-
- const ParameterRanges& CarlaPlugin::getParameterRanges(const uint32_t parameterId) const
- {
- CARLA_SAFE_ASSERT_RETURN(parameterId < pData->param.count, kParameterRangesNull);
- return pData->param.ranges[parameterId];
- }
-
- bool CarlaPlugin::isParameterOutput(const uint32_t parameterId) const
- {
- 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
- {
- CARLA_SAFE_ASSERT_RETURN(index < pData->midiprog.count, kMidiProgramDataNull);
- return pData->midiprog.data[index];
- }
-
- const CustomData& CarlaPlugin::getCustomData(const uint32_t index) const
- {
- CARLA_SAFE_ASSERT_RETURN(index < pData->custom.count(), kCustomDataNull);
- return pData->custom.getAt(index);
- }
-
- int32_t CarlaPlugin::getChunkData(void** const dataPtr) const
- {
- CARLA_SAFE_ASSERT_RETURN(dataPtr != nullptr, 0);
- CARLA_ASSERT(false); // this should never happen
- return 0;
- }
-
- // -------------------------------------------------------------------
- // Information (per-plugin data)
-
- unsigned int CarlaPlugin::getOptionsAvailable() const
- {
- CARLA_ASSERT(false); // this should never happen
- return 0x0;
- }
-
- float CarlaPlugin::getParameterValue(const uint32_t parameterId) const
- {
- CARLA_SAFE_ASSERT_RETURN(parameterId < getParameterCount(), 0.0f);
- CARLA_ASSERT(false); // this should never happen
- return 0.0f;
- }
-
- float CarlaPlugin::getParameterScalePointValue(const uint32_t parameterId, const uint32_t scalePointId) const
- {
- CARLA_SAFE_ASSERT_RETURN(parameterId < getParameterCount(), 0.0f);
- CARLA_SAFE_ASSERT_RETURN(scalePointId < getParameterScalePointCount(parameterId), 0.0f);
- CARLA_ASSERT(false); // this should never happen
- return 0.0f;
- }
-
- void CarlaPlugin::getLabel(char* const strBuf) const
- {
- strBuf[0] = '\0';
- }
-
- void CarlaPlugin::getMaker(char* const strBuf) const
- {
- strBuf[0] = '\0';
- }
-
- void CarlaPlugin::getCopyright(char* const strBuf) const
- {
- strBuf[0] = '\0';
- }
-
- void CarlaPlugin::getRealName(char* const strBuf) const
- {
- strBuf[0] = '\0';
- }
-
- void CarlaPlugin::getParameterName(const uint32_t parameterId, char* const strBuf) const
- {
- CARLA_SAFE_ASSERT_RETURN(parameterId < getParameterCount(),);
- CARLA_ASSERT(false); // this should never happen
- strBuf[0] = '\0';
- }
-
- void CarlaPlugin::getParameterSymbol(const uint32_t parameterId, char* const strBuf) const
- {
- CARLA_SAFE_ASSERT_RETURN(parameterId < getParameterCount(),);
- strBuf[0] = '\0';
- }
-
- void CarlaPlugin::getParameterText(const uint32_t parameterId, const float, char* const strBuf) const
- {
- CARLA_SAFE_ASSERT_RETURN(parameterId < getParameterCount(),);
- CARLA_ASSERT(false); // this should never happen
- strBuf[0] = '\0';
- }
-
- void CarlaPlugin::getParameterUnit(const uint32_t parameterId, char* const strBuf) const
- {
- CARLA_SAFE_ASSERT_RETURN(parameterId < getParameterCount(),);
- strBuf[0] = '\0';
- }
-
- void CarlaPlugin::getParameterScalePointLabel(const uint32_t parameterId, const uint32_t scalePointId, char* const strBuf) const
- {
- CARLA_SAFE_ASSERT_RETURN(parameterId < getParameterCount(),);
- CARLA_SAFE_ASSERT_RETURN(scalePointId < getParameterScalePointCount(parameterId),);
- CARLA_ASSERT(false); // this should never happen
- strBuf[0] = '\0';
- }
-
- void CarlaPlugin::getProgramName(const uint32_t index, char* const strBuf) const
- {
- CARLA_SAFE_ASSERT_RETURN(index < pData->prog.count,);
- CARLA_SAFE_ASSERT_RETURN(pData->prog.names[index] != nullptr,);
- std::strncpy(strBuf, pData->prog.names[index], STR_MAX);
- }
-
- void CarlaPlugin::getMidiProgramName(const uint32_t index, char* const strBuf) const
- {
- CARLA_SAFE_ASSERT_RETURN(index < pData->midiprog.count,);
- CARLA_SAFE_ASSERT_RETURN(pData->midiprog.data[index].name != nullptr,);
- std::strncpy(strBuf, pData->midiprog.data[index].name, STR_MAX);
- }
-
- 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()
- {
- }
-
- const SaveState& CarlaPlugin::getSaveState()
- {
- pData->saveState.reset();
- prepareForSave();
-
- char strBuf[STR_MAX+1];
-
- // ---------------------------------------------------------------
- // Basic info
-
- getLabel(strBuf);
-
- pData->saveState.type = carla_strdup(getPluginTypeAsString(getType()));
- pData->saveState.name = carla_strdup(pData->name);
- pData->saveState.label = carla_strdup(strBuf);
- pData->saveState.binary = carla_strdup(pData->filename);
- pData->saveState.uniqueID = getUniqueId();
-
- // ---------------------------------------------------------------
- // Internals
-
- pData->saveState.active = pData->active;
-
- #ifndef BUILD_BRIDGE
- pData->saveState.dryWet = pData->postProc.dryWet;
- pData->saveState.volume = pData->postProc.volume;
- pData->saveState.balanceLeft = pData->postProc.balanceLeft;
- pData->saveState.balanceRight = pData->postProc.balanceRight;
- pData->saveState.panning = pData->postProc.panning;
- pData->saveState.ctrlChannel = pData->ctrlChannel;
- #endif
-
- // ---------------------------------------------------------------
- // Chunk
-
- if (pData->options & PLUGIN_OPTION_USE_CHUNKS)
- {
- void* data = nullptr;
- const int32_t dataSize(getChunkData(&data));
-
- if (data != nullptr && dataSize > 0)
- {
- pData->saveState.chunk = carla_strdup(QByteArray((char*)data, dataSize).toBase64().constData());
-
- // Don't save anything else if using chunks
- return pData->saveState;
- }
- }
-
- // ---------------------------------------------------------------
- // Current Program
-
- if (pData->prog.current >= 0 && getType() != PLUGIN_LV2)
- {
- pData->saveState.currentProgramIndex = pData->prog.current;
- pData->saveState.currentProgramName = carla_strdup(pData->prog.names[pData->prog.current]);
- }
-
- // ---------------------------------------------------------------
- // Current MIDI Program
-
- if (pData->midiprog.current >= 0 && getType() != PLUGIN_LV2)
- {
- const MidiProgramData& mpData(pData->midiprog.getCurrent());
-
- pData->saveState.currentMidiBank = mpData.bank;
- pData->saveState.currentMidiProgram = 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.type != PARAMETER_INPUT || (paramData.hints & PARAMETER_IS_ENABLED) == 0)
- continue;
-
- StateParameter* stateParameter(new StateParameter());
-
- stateParameter->index = paramData.index;
- stateParameter->midiCC = paramData.midiCC;
- stateParameter->midiChannel = paramData.midiChannel;
-
- getParameterName(i, strBuf);
- stateParameter->name = carla_strdup(strBuf);
-
- getParameterSymbol(i, strBuf);
- stateParameter->symbol = carla_strdup(strBuf);;
-
- stateParameter->value = getParameterValue(i);
-
- if (paramData.hints & PARAMETER_USES_SAMPLERATE)
- stateParameter->value /= sampleRate;
-
- pData->saveState.parameters.append(stateParameter);
- }
-
- // ---------------------------------------------------------------
- // Custom Data
-
- for (List<CustomData>::Itenerator it = pData->custom.begin(); it.valid(); it.next())
- {
- const CustomData& cData(it.getConstValue());
-
- StateCustomData* stateCustomData(new StateCustomData());
-
- stateCustomData->type = carla_strdup(cData.type);
- stateCustomData->key = carla_strdup(cData.key);
- stateCustomData->value = carla_strdup(cData.value);
-
- pData->saveState.customData.append(stateCustomData);
- }
-
- return pData->saveState;
- }
-
- void CarlaPlugin::loadSaveState(const SaveState& saveState)
- {
- char strBuf[STR_MAX+1];
- const bool usesMultiProgs(getType() == PLUGIN_SF2 || (getType() == PLUGIN_INTERNAL && getCategory() == PLUGIN_CATEGORY_SYNTH));
-
- gIsLoadingProject = true;
- ScopedValueSetter<bool>(gIsLoadingProject, false);
-
- // ---------------------------------------------------------------
- // Part 1 - PRE-set custom data (only that which reload programs)
-
- for (List<StateCustomData*>::Itenerator it = saveState.customData.begin(); it.valid(); it.next())
- {
- const StateCustomData* const stateCustomData(it.getConstValue());
- const char* const key(stateCustomData->key);
-
- bool wantData = false;
-
- if (getType() == PLUGIN_DSSI && (std::strcmp(key, "reloadprograms") == 0 || std::strcmp(key, "load") == 0 || std::strncmp(key, "patches", 7) == 0))
- wantData = true;
- else if (usesMultiProgs && std::strcmp(key, "midiPrograms") == 0)
- wantData = true;
-
- if (wantData)
- setCustomData(stateCustomData->type, stateCustomData->key, stateCustomData->value, true);
- }
-
- // ---------------------------------------------------------------
- // Part 2 - set program
-
- if (saveState.currentProgramIndex >= 0 && saveState.currentProgramName != nullptr)
- {
- int32_t programId = -1;
-
- // index < count
- if (saveState.currentProgramIndex < static_cast<int32_t>(pData->prog.count))
- {
- programId = saveState.currentProgramIndex;
- }
- // index not valid, try to find by name
- else
- {
- for (uint32_t i=0; i < pData->prog.count; ++i)
- {
- strBuf[0] = '\0';
- getProgramName(i, strBuf);
-
- if (strBuf[0] != '\0' && std::strcmp(saveState.currentProgramName, strBuf) == 0)
- {
- programId = i;
- break;
- }
- }
- }
-
- // set program now, if valid
- if (programId >= 0)
- setProgram(programId, true, true, true);
- }
-
- // ---------------------------------------------------------------
- // Part 3 - set midi program
-
- if (saveState.currentMidiBank >= 0 && saveState.currentMidiProgram >= 0 && ! usesMultiProgs)
- setMidiProgramById(saveState.currentMidiBank, saveState.currentMidiProgram, true, true, true);
-
- // ---------------------------------------------------------------
- // Part 4a - get plugin parameter symbols
-
- List<ParamSymbol*> paramSymbols;
-
- if (getType() == PLUGIN_LADSPA || getType() == PLUGIN_LV2)
- {
- for (uint32_t i=0; i < pData->param.count; ++i)
- {
- strBuf[0] = '\0';
- getParameterSymbol(i, strBuf);
-
- if (strBuf[0] != '\0')
- {
- 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 (List<StateParameter*>::Itenerator it = saveState.parameters.begin(); it.valid(); it.next())
- {
- StateParameter* const stateParameter(it.getValue());
-
- int32_t index = -1;
-
- if (getType() == PLUGIN_LADSPA)
- {
- // Try to set by symbol, otherwise use index
- if (stateParameter->symbol != nullptr && stateParameter->symbol[0] != '\0')
- {
- for (List<ParamSymbol*>::Itenerator it = paramSymbols.begin(); it.valid(); it.next())
- {
- ParamSymbol* const paramSymbol(it.getValue());
-
- if (std::strcmp(stateParameter->symbol, paramSymbol->symbol) == 0)
- {
- index = paramSymbol->index;
- break;
- }
- }
- if (index == -1)
- index = stateParameter->index;
- }
- else
- index = stateParameter->index;
- }
- else if (getType() == PLUGIN_LV2)
- {
- // Symbol only
- if (stateParameter->symbol != nullptr && stateParameter->symbol[0] != '\0')
- {
- for (List<ParamSymbol*>::Itenerator it = paramSymbols.begin(); it.valid(); it.next())
- {
- ParamSymbol* const paramSymbol(it.getValue());
-
- if (std::strcmp(stateParameter->symbol, paramSymbol->symbol) == 0)
- {
- index = paramSymbol->index;
- break;
- }
- }
- if (index == -1)
- carla_stderr("Failed to find LV2 parameter symbol '%s')", stateParameter->symbol);
- }
- else
- carla_stderr("LV2 Plugin parameter '%s' has no symbol", stateParameter->name);
- }
- else
- {
- // Index only
- index = stateParameter->index;
- }
-
- // Now set parameter
- if (index >= 0 && index < static_cast<int32_t>(pData->param.count))
- {
- if (pData->param.data[index].hints & PARAMETER_USES_SAMPLERATE)
- stateParameter->value *= sampleRate;
-
- setParameterValue(index, stateParameter->value, true, true, true);
- #ifndef BUILD_BRIDGE
- setParameterMidiCC(index, stateParameter->midiCC, true, true);
- setParameterMidiChannel(index, stateParameter->midiChannel, true, true);
- #endif
- }
- else
- carla_stderr("Could not set parameter data for '%s'", stateParameter->name);
- }
-
- // ---------------------------------------------------------------
- // Part 4c - clear
-
- for (List<ParamSymbol*>::Itenerator it = paramSymbols.begin(); it.valid(); it.next())
- {
- ParamSymbol* const paramSymbol(it.getValue());
- delete paramSymbol;
- }
-
- paramSymbols.clear();
-
- // ---------------------------------------------------------------
- // Part 5 - set custom data
-
- for (List<StateCustomData*>::Itenerator it = saveState.customData.begin(); it.valid(); it.next())
- {
- const StateCustomData* const stateCustomData(it.getConstValue());
- const char* const key(stateCustomData->key);
-
- if (getType() == 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, stateCustomData->key, stateCustomData->value, true);
- }
-
- // ---------------------------------------------------------------
- // Part 6 - set chunk
-
- if (saveState.chunk != nullptr && (pData->options & PLUGIN_OPTION_USE_CHUNKS) != 0)
- setChunkData(saveState.chunk);
-
- // ---------------------------------------------------------------
- // Part 6 - set internal stuff
-
- #ifndef BUILD_BRIDGE
- setDryWet(saveState.dryWet, true, true);
- setVolume(saveState.volume, true, true);
- setBalanceLeft(saveState.balanceLeft, true, true);
- setBalanceRight(saveState.balanceRight, true, true);
- setPanning(saveState.panning, true, true);
- setCtrlChannel(saveState.ctrlChannel, true, true);
- #endif
-
- setActive(saveState.active, true, true);
- }
-
- bool CarlaPlugin::saveStateToFile(const char* const filename)
- {
- CARLA_SAFE_ASSERT_RETURN(filename != nullptr && filename[0] != '\0', false);
- carla_debug("CarlaPlugin::saveStateToFile(\"%s\")", filename);
-
- QFile file(filename);
-
- if (! file.open(QIODevice::WriteOnly | QIODevice::Text))
- return false;
-
- QString content;
- fillXmlStringFromSaveState(content, getSaveState());
-
- QTextStream out(&file);
- out << "<?xml version='1.0' encoding='UTF-8'?>\n";
- out << "<!DOCTYPE CARLA-PRESET>\n";
- out << "<CARLA-PRESET VERSION='2.0'>\n";
- out << content;
- out << "</CARLA-PRESET>\n";
-
- file.close();
- return true;
- }
-
- bool CarlaPlugin::loadStateFromFile(const char* const filename)
- {
- CARLA_SAFE_ASSERT_RETURN(filename != nullptr && filename[0] != '\0', false);
- carla_debug("CarlaPlugin::loadStateFromFile(\"%s\")", filename);
-
- QFile file(filename);
-
- if (! file.open(QIODevice::ReadOnly | QIODevice::Text))
- return false;
-
- QDomDocument xml;
- xml.setContent(file.readAll());
- file.close();
-
- QDomNode xmlNode(xml.documentElement());
-
- if (xmlNode.toElement().tagName().compare("carla-preset", Qt::CaseInsensitive) == 0)
- {
- pData->engine->setLastError("Not a valid Carla preset file");
- return false;
- }
-
- pData->saveState.reset();
- fillSaveStateFromXmlNode(pData->saveState, xmlNode);
- loadSaveState(pData->saveState);
-
- return true;
- }
-
- // -------------------------------------------------------------------
- // Set data (internal stuff)
-
- void CarlaPlugin::setId(const unsigned int newId) noexcept
- {
- pData->id = newId;
- }
-
- void CarlaPlugin::setName(const char* const newName)
- {
- CARLA_ASSERT(newName != nullptr && newName[0] != '\0');
-
- pData->name = newName;
- }
-
- void CarlaPlugin::setOption(const unsigned int option, const bool yesNo)
- {
- CARLA_ASSERT(getOptionsAvailable() & option);
-
- if (yesNo)
- pData->options |= option;
- else
- pData->options &= ~option;
-
- pData->saveSetting(option, yesNo);
- }
-
- void CarlaPlugin::setEnabled(const bool yesNo)
- {
- if (pData->enabled == yesNo)
- return;
-
- pData->enabled = yesNo;
-
- pData->masterMutex.lock();
- pData->masterMutex.unlock();
- }
-
- // -------------------------------------------------------------------
- // Set data (internal stuff)
-
- void CarlaPlugin::setActive(const bool active, const bool sendOsc, const bool sendCallback)
- {
- #ifndef BUILD_BRIDGE
- CARLA_ASSERT(sendOsc || sendCallback); // never call this from RT
- #endif
-
- if (pData->active == active)
- return;
-
- {
- const ScopedSingleProcessLocker spl(this, true);
-
- if (active)
- activate();
- else
- deactivate();
- }
-
- pData->active = active;
-
- #ifndef BUILD_BRIDGE
- const float value(active ? 1.0f : 0.0f);
-
- if (sendOsc)
- pData->engine->oscSend_control_set_parameter_value(pData->id, PARAMETER_ACTIVE, value);
-
- if (sendCallback)
- pData->engine->callback(ENGINE_CALLBACK_PARAMETER_VALUE_CHANGED, pData->id, PARAMETER_ACTIVE, 0, value, nullptr);
- #else
- return;
-
- // unused
- (void)sendOsc;
- (void)sendCallback;
- #endif
- }
-
- #ifndef BUILD_BRIDGE
- void CarlaPlugin::setDryWet(const float value, const bool sendOsc, const bool sendCallback)
- {
- CARLA_ASSERT(value >= 0.0f && value <= 1.0f);
-
- const float fixedValue(carla_fixValue<float>(0.0f, 1.0f, value));
-
- if (pData->postProc.dryWet == fixedValue)
- return;
-
- pData->postProc.dryWet = fixedValue;
-
- if (sendOsc)
- pData->engine->oscSend_control_set_parameter_value(pData->id, PARAMETER_DRYWET, fixedValue);
-
- if (sendCallback)
- pData->engine->callback(ENGINE_CALLBACK_PARAMETER_VALUE_CHANGED, pData->id, PARAMETER_DRYWET, 0, fixedValue, nullptr);
- }
-
- void CarlaPlugin::setVolume(const float value, const bool sendOsc, const bool sendCallback)
- {
- CARLA_ASSERT(value >= 0.0f && value <= 1.27f);
-
- const float fixedValue(carla_fixValue<float>(0.0f, 1.27f, value));
-
- if (pData->postProc.volume == fixedValue)
- return;
-
- pData->postProc.volume = fixedValue;
-
- if (sendOsc)
- pData->engine->oscSend_control_set_parameter_value(pData->id, PARAMETER_VOLUME, fixedValue);
-
- if (sendCallback)
- pData->engine->callback(ENGINE_CALLBACK_PARAMETER_VALUE_CHANGED, pData->id, PARAMETER_VOLUME, 0, fixedValue, nullptr);
- }
-
- void CarlaPlugin::setBalanceLeft(const float value, const bool sendOsc, const bool sendCallback)
- {
- CARLA_ASSERT(value >= -1.0f && value <= 1.0f);
-
- const float fixedValue(carla_fixValue<float>(-1.0f, 1.0f, value));
-
- if (pData->postProc.balanceLeft == fixedValue)
- return;
-
- pData->postProc.balanceLeft = fixedValue;
-
- if (sendOsc)
- pData->engine->oscSend_control_set_parameter_value(pData->id, PARAMETER_BALANCE_LEFT, fixedValue);
-
- if (sendCallback)
- pData->engine->callback(ENGINE_CALLBACK_PARAMETER_VALUE_CHANGED, pData->id, PARAMETER_BALANCE_LEFT, 0, fixedValue, nullptr);
- }
-
- void CarlaPlugin::setBalanceRight(const float value, const bool sendOsc, const bool sendCallback)
- {
- CARLA_ASSERT(value >= -1.0f && value <= 1.0f);
-
- const float fixedValue(carla_fixValue<float>(-1.0f, 1.0f, value));
-
- if (pData->postProc.balanceRight == fixedValue)
- return;
-
- pData->postProc.balanceRight = fixedValue;
-
- if (sendOsc)
- pData->engine->oscSend_control_set_parameter_value(pData->id, PARAMETER_BALANCE_RIGHT, fixedValue);
-
- if (sendCallback)
- pData->engine->callback(ENGINE_CALLBACK_PARAMETER_VALUE_CHANGED, pData->id, PARAMETER_BALANCE_RIGHT, 0, fixedValue, nullptr);
- }
-
- void CarlaPlugin::setPanning(const float value, const bool sendOsc, const bool sendCallback)
- {
- CARLA_ASSERT(value >= -1.0f && value <= 1.0f);
-
- const float fixedValue(carla_fixValue<float>(-1.0f, 1.0f, value));
-
- if (pData->postProc.panning == fixedValue)
- return;
-
- pData->postProc.panning = fixedValue;
-
- if (sendOsc)
- pData->engine->oscSend_control_set_parameter_value(pData->id, PARAMETER_PANNING, fixedValue);
-
- if (sendCallback)
- pData->engine->callback(ENGINE_CALLBACK_PARAMETER_VALUE_CHANGED, pData->id, PARAMETER_PANNING, 0, fixedValue, nullptr);
- }
- #endif
-
- void CarlaPlugin::setCtrlChannel(const int8_t channel, const bool sendOsc, const bool sendCallback)
- {
- #ifndef BUILD_BRIDGE
- CARLA_ASSERT(sendOsc || sendCallback); // never call this from RT
- #endif
- CARLA_ASSERT_INT(channel >= -1 && channel < MAX_MIDI_CHANNELS, channel);
-
- if (pData->ctrlChannel == channel)
- return;
-
- pData->ctrlChannel = channel;
-
- #ifndef BUILD_BRIDGE
- const float ctrlf(channel);
-
- if (sendOsc)
- pData->engine->oscSend_control_set_parameter_value(pData->id, PARAMETER_CTRL_CHANNEL, ctrlf);
-
- if (sendCallback)
- pData->engine->callback(ENGINE_CALLBACK_PARAMETER_VALUE_CHANGED, pData->id, PARAMETER_CTRL_CHANNEL, 0, ctrlf, nullptr);
-
- if (pData->hints & PLUGIN_IS_BRIDGE)
- osc_send_control(pData->osc.data, PARAMETER_CTRL_CHANNEL, ctrlf);
- #else
- return;
-
- // unused
- (void)sendOsc;
- (void)sendCallback;
- #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)
- {
- CARLA_ASSERT(parameterId < pData->param.count);
- #ifdef BUILD_BRIDGE
- if (! gIsLoadingProject)
- {
- CARLA_ASSERT(! sendGui); // this should never happen
- }
- #endif
-
- #ifndef BUILD_BRIDGE
- if (sendGui)
- uiParameterChange(parameterId, value);
-
- if (sendOsc)
- pData->engine->oscSend_control_set_parameter_value(pData->id, parameterId, value);
- #endif
-
- if (sendCallback)
- pData->engine->callback(ENGINE_CALLBACK_PARAMETER_VALUE_CHANGED, pData->id, parameterId, 0, value, nullptr);
-
- #ifdef BUILD_BRIDGE
- return;
-
- // unused
- (void)sendGui;
- (void)sendOsc;
- #endif
- }
-
- void CarlaPlugin::setParameterValueByRealIndex(const int32_t rindex, const float value, const bool sendGui, const bool sendOsc, const bool sendCallback)
- {
- CARLA_ASSERT(rindex > PARAMETER_MAX && rindex != PARAMETER_NULL);
-
- if (rindex <= PARAMETER_MAX)
- return;
- if (rindex == PARAMETER_NULL)
- return;
- if (rindex == PARAMETER_ACTIVE)
- return setActive((value > 0.0f), sendOsc, sendCallback);
- if (rindex == PARAMETER_CTRL_CHANNEL)
- return setCtrlChannel(int8_t(value), sendOsc, sendCallback);
-
- #ifndef BUILD_BRIDGE
- if (rindex == PARAMETER_DRYWET)
- return setDryWet(value, sendOsc, sendCallback);
- if (rindex == PARAMETER_VOLUME)
- return setVolume(value, sendOsc, sendCallback);
- if (rindex == PARAMETER_BALANCE_LEFT)
- return setBalanceLeft(value, sendOsc, sendCallback);
- if (rindex == PARAMETER_BALANCE_RIGHT)
- return setBalanceRight(value, sendOsc, sendCallback);
- if (rindex == PARAMETER_PANNING)
- return setPanning(value, sendOsc, sendCallback);
- #endif
-
- for (uint32_t i=0; i < pData->param.count; ++i)
- {
- if (pData->param.data[i].rindex == rindex)
- {
- if (getParameterValue(i) != value)
- setParameterValue(i, value, sendGui, sendOsc, sendCallback);
- break;
- }
- }
- }
-
- void CarlaPlugin::setParameterMidiChannel(const uint32_t parameterId, uint8_t channel, const bool sendOsc, const bool sendCallback)
- {
- CARLA_ASSERT(sendOsc || sendCallback); // never call this from RT
- CARLA_ASSERT(parameterId < pData->param.count);
- CARLA_ASSERT_INT(channel < MAX_MIDI_CHANNELS, channel);
-
- if (channel >= MAX_MIDI_CHANNELS)
- channel = MAX_MIDI_CHANNELS;
-
- pData->param.data[parameterId].midiChannel = channel;
-
- #ifndef BUILD_BRIDGE
- if (sendOsc)
- pData->engine->oscSend_control_set_parameter_midi_channel(pData->id, parameterId, channel);
-
- if (sendCallback)
- pData->engine->callback(ENGINE_CALLBACK_PARAMETER_MIDI_CHANNEL_CHANGED, pData->id, parameterId, channel, 0.0f, nullptr);
-
- if (pData->hints & PLUGIN_IS_BRIDGE)
- {} // TODO
- #else
- return;
-
- // unused
- (void)sendOsc;
- (void)sendCallback;
- #endif
- }
-
- void CarlaPlugin::setParameterMidiCC(const uint32_t parameterId, int16_t cc, const bool sendOsc, const bool sendCallback)
- {
- CARLA_ASSERT(sendOsc || sendCallback); // never call this from RT
- CARLA_ASSERT(parameterId < pData->param.count);
- CARLA_ASSERT_INT(cc >= -1 && cc <= 0x5F, cc);
-
- if (cc < -1 || cc > 0x5F)
- cc = -1;
-
- pData->param.data[parameterId].midiCC = cc;
-
- #ifndef BUILD_BRIDGE
- if (sendOsc)
- pData->engine->oscSend_control_set_parameter_midi_cc(pData->id, parameterId, cc);
-
- if (sendCallback)
- pData->engine->callback(ENGINE_CALLBACK_PARAMETER_MIDI_CC_CHANGED, pData->id, parameterId, cc, 0.0f, nullptr);
-
- if (pData->hints & PLUGIN_IS_BRIDGE)
- {} // TODO
- #else
- return;
-
- // unused
- (void)sendOsc;
- (void)sendCallback;
- #endif
- }
-
- void CarlaPlugin::setCustomData(const char* const type, const char* const key, const char* const value, const bool sendGui)
- {
- CARLA_ASSERT(type != nullptr);
- CARLA_ASSERT(key != nullptr);
- CARLA_ASSERT(value != nullptr);
- #ifdef BUILD_BRIDGE
- if (! gIsLoadingProject)
- {
- CARLA_ASSERT(! sendGui); // this should never happen
- }
- #endif
-
- if (type == nullptr)
- return carla_stderr2("CarlaPlugin::setCustomData(\"%s\", \"%s\", \"%s\", %s) - type is null", type, key, value, bool2str(sendGui));
-
- if (key == nullptr)
- return carla_stderr2("CarlaPlugin::setCustomData(\"%s\", \"%s\", \"%s\", %s) - key is null", type, key, value, bool2str(sendGui));
-
- if (value == nullptr)
- return carla_stderr2("CarlaPlugin::setCustomData(\"%s\", \"%s\", \"%s\", %s) - value is null", type, key, value, bool2str(sendGui));
-
- bool saveData = true;
-
- if (std::strcmp(type, CUSTOM_DATA_TYPE_STRING) == 0)
- {
- // Ignore some keys
- if (std::strncmp(key, "OSC:", 4) == 0 || std::strncmp(key, "CarlaAlternateFile", 18) == 0 || std::strcmp(key, "guiVisible") == 0)
- saveData = false;
- //else if (std::strcmp(key, CARLA_BRIDGE_MSG_SAVE_NOW) == 0 || std::strcmp(key, CARLA_BRIDGE_MSG_SET_CHUNK) == 0 || std::strcmp(key, CARLA_BRIDGE_MSG_SET_CUSTOM) == 0)
- // saveData = false;
- }
-
- if (! saveData)
- return;
-
- // Check if we already have this key
- for (List<CustomData>::Itenerator it = pData->custom.begin(); it.valid(); it.next())
- {
- CustomData& cData(it.getValue());
-
- CARLA_ASSERT(cData.type != nullptr);
- CARLA_ASSERT(cData.key != nullptr);
- CARLA_ASSERT(cData.value != nullptr);
-
- if (cData.type == nullptr)
- return;
- if (cData.key == nullptr)
- return;
-
- if (std::strcmp(cData.key, key) == 0)
- {
- if (cData.value != nullptr)
- delete[] cData.value;
-
- cData.value = carla_strdup(value);
- return;
- }
- }
-
- // Otherwise store it
- CustomData newData;
- newData.type = carla_strdup(type);
- newData.key = carla_strdup(key);
- newData.value = carla_strdup(value);
- pData->custom.append(newData);
- }
-
- void CarlaPlugin::setChunkData(const char* const stringData)
- {
- CARLA_ASSERT(stringData != nullptr);
- CARLA_ASSERT(false); // this should never happen
- return;
-
- // unused
- (void)stringData;
- }
-
- void CarlaPlugin::setProgram(int32_t index, const bool sendGui, const bool sendOsc, const bool sendCallback)
- {
- CARLA_ASSERT(index >= -1 && index < static_cast<int32_t>(pData->prog.count));
- #ifdef BUILD_BRIDGE
- if (! gIsLoadingProject)
- {
- CARLA_ASSERT(! sendGui); // this should never happen
- }
- #endif
-
- if (index > static_cast<int32_t>(pData->prog.count))
- return;
-
- const int32_t fixedIndex(carla_fixValue<int32_t>(-1, pData->prog.count, index));
-
- pData->prog.current = fixedIndex;
-
- #ifndef BUILD_BRIDGE
- if (sendOsc)
- pData->engine->oscSend_control_set_current_program(pData->id, fixedIndex);
- #endif
-
- if (sendCallback)
- pData->engine->callback(ENGINE_CALLBACK_PROGRAM_CHANGED, pData->id, fixedIndex, 0, 0.0f, nullptr);
-
- // Change default parameter values
- if (fixedIndex >= 0)
- {
- #ifndef BUILD_BRIDGE
- if (sendGui)
- uiProgramChange(fixedIndex);
- #endif
-
- if (getType() == PLUGIN_GIG || getType() == PLUGIN_SF2 || getType() == PLUGIN_SFZ)
- return;
-
- for (uint32_t i=0; i < pData->param.count; ++i)
- {
- const float value(pData->param.ranges[i].getFixedValue(getParameterValue(i)));
-
- pData->param.ranges[i].def = value;
-
- if (sendOsc || sendCallback)
- {
- #ifndef BUILD_BRIDGE
- pData->engine->oscSend_control_set_default_value(pData->id, i, value);
- pData->engine->oscSend_control_set_parameter_value(pData->id, i, value);
- #endif
-
- pData->engine->callback(ENGINE_CALLBACK_PARAMETER_VALUE_CHANGED, pData->id, i, 0, value, nullptr);
- pData->engine->callback(ENGINE_CALLBACK_PARAMETER_DEFAULT_CHANGED, pData->id, i, 0, value, nullptr);
- }
- }
- }
-
- #ifdef BUILD_BRIDGE
- return;
-
- // unused
- (void)sendGui;
- #endif
- }
-
- void CarlaPlugin::setMidiProgram(int32_t index, const bool sendGui, const bool sendOsc, const bool sendCallback)
- {
- CARLA_ASSERT(index >= -1 && index < static_cast<int32_t>(pData->midiprog.count));
- #ifdef BUILD_BRIDGE
- if (! gIsLoadingProject)
- {
- CARLA_ASSERT(! sendGui); // this should never happen
- }
- #endif
-
- if (index > static_cast<int32_t>(pData->midiprog.count))
- return;
-
- const int32_t fixedIndex(carla_fixValue<int32_t>(-1, pData->midiprog.count, index));
-
- pData->midiprog.current = fixedIndex;
-
- #ifndef BUILD_BRIDGE
- if (sendOsc)
- pData->engine->oscSend_control_set_current_midi_program(pData->id, fixedIndex);
- #endif
-
- if (sendCallback)
- pData->engine->callback(ENGINE_CALLBACK_MIDI_PROGRAM_CHANGED, pData->id, fixedIndex, 0, 0.0f, nullptr);
-
- if (fixedIndex >= 0)
- {
- #ifndef BUILD_BRIDGE
- if (sendGui)
- uiMidiProgramChange(fixedIndex);
- #endif
-
- if (getType() == PLUGIN_GIG || getType() == PLUGIN_SF2 || getType() == PLUGIN_SFZ)
- return;
-
- for (uint32_t i=0; i < pData->param.count; ++i)
- {
- const float value(pData->param.ranges[i].getFixedValue(getParameterValue(i)));
-
- pData->param.ranges[i].def = value;
-
- if (sendOsc || sendCallback)
- {
- #ifndef BUILD_BRIDGE
- pData->engine->oscSend_control_set_default_value(pData->id, i, value);
- pData->engine->oscSend_control_set_parameter_value(pData->id, i, value);
- #endif
-
- pData->engine->callback(ENGINE_CALLBACK_PARAMETER_VALUE_CHANGED, pData->id, i, 0, value, nullptr);
- pData->engine->callback(ENGINE_CALLBACK_PARAMETER_DEFAULT_CHANGED, pData->id, i, 0, value, nullptr);
- }
- }
- }
-
- #ifdef BUILD_BRIDGE
- return;
-
- // unused
- (void)sendGui;
- #endif
- }
-
- void CarlaPlugin::setMidiProgramById(const uint32_t bank, const uint32_t program, const bool sendGui, const bool sendOsc, const bool sendCallback)
- {
- 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(i, sendGui, sendOsc, sendCallback);
- }
- }
-
- // -------------------------------------------------------------------
- // Set gui stuff
-
- void CarlaPlugin::showCustomUI(const bool yesNo)
- {
- CARLA_ASSERT(false);
- return;
-
- // unused
- (void)yesNo;
- }
-
- void CarlaPlugin::idle()
- {
- if (! pData->enabled)
- return;
-
- if (pData->hints & PLUGIN_NEEDS_SINGLE_THREAD)
- {
- // Process postponed events
- postRtEventsRun();
-
- // 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));
- }
- }
- }
-
- // -------------------------------------------------------------------
- // Plugin state
-
- void CarlaPlugin::reloadPrograms(const bool)
- {
- }
-
- // -------------------------------------------------------------------
- // Plugin processing
-
- void CarlaPlugin::activate()
- {
- CARLA_ASSERT(! pData->active);
- }
-
- void CarlaPlugin::deactivate()
- {
- CARLA_ASSERT(pData->active);
- }
-
- void CarlaPlugin::bufferSizeChanged(const uint32_t)
- {
- }
-
- void CarlaPlugin::sampleRateChanged(const double)
- {
- }
-
- void CarlaPlugin::offlineModeChanged(const bool)
- {
- }
-
- bool CarlaPlugin::tryLock(const bool forcedOffline)
- {
- if (forcedOffline)
- {
- pData->masterMutex.lock();
- return true;
- }
-
- return pData->masterMutex.tryLock();
- }
-
- void CarlaPlugin::unlock()
- {
- pData->masterMutex.unlock();
- }
-
- // -------------------------------------------------------------------
- // Plugin buffers
-
- void CarlaPlugin::initBuffers()
- {
- pData->audioIn.initBuffers();
- pData->audioOut.initBuffers();
- pData->event.initBuffers();
- }
-
- void CarlaPlugin::clearBuffers()
- {
- pData->clearBuffers();
- }
-
- // -------------------------------------------------------------------
- // OSC stuff
-
- void CarlaPlugin::registerToOscClient()
- {
- #ifdef BUILD_BRIDGE
- if (! pData->engine->isOscBridgeRegistered())
- #else
- if (! pData->engine->isOscControlRegistered())
- #endif
- return;
-
-
- #ifndef BUILD_BRIDGE
- pData->engine->oscSend_control_add_plugin_start(pData->id, pData->name);
- #endif
-
- // Base data
- {
- // TODO - clear buf
- char bufName[STR_MAX+1] = { '\0' };
- char bufLabel[STR_MAX+1] = { '\0' };
- char bufMaker[STR_MAX+1] = { '\0' };
- char bufCopyright[STR_MAX+1] = { '\0' };
- getRealName(bufName);
- getLabel(bufLabel);
- getMaker(bufMaker);
- getCopyright(bufCopyright);
-
- #ifdef BUILD_BRIDGE
- pData->engine->oscSend_bridge_plugin_info1(getCategory(), pData->hints, getUniqueId());
- pData->engine->oscSend_bridge_plugin_info2(bufName, bufLabel, bufMaker, bufCopyright);
- #else
- pData->engine->oscSend_control_set_plugin_info1(pData->id, getType(), getCategory(), pData->hints, getUniqueId());
- pData->engine->oscSend_control_set_plugin_info2(pData->id, bufName, bufLabel, bufMaker, bufCopyright);
- #endif
- }
-
- // Base count
- {
- uint32_t paramIns, paramOuts;
- getParameterCountInfo(paramIns, paramOuts);
-
- #ifdef BUILD_BRIDGE
- pData->engine->oscSend_bridge_audio_count(getAudioInCount(), getAudioOutCount());
- pData->engine->oscSend_bridge_midi_count(getMidiInCount(), getMidiOutCount());
- pData->engine->oscSend_bridge_parameter_count(paramIns, paramOuts);
- #else
- pData->engine->oscSend_control_set_audio_count(pData->id, getAudioInCount(), getAudioOutCount());
- pData->engine->oscSend_control_set_midi_count(pData->id, getMidiInCount(), getMidiOutCount());
- pData->engine->oscSend_control_set_parameter_count(pData->id, paramIns, paramOuts);
- #endif
- }
-
- // Plugin Parameters
- if (pData->param.count > 0 && pData->param.count < pData->engine->getOptions().maxParameters)
- {
- char bufName[STR_MAX+1], bufUnit[STR_MAX+1];
-
- for (uint32_t i=0; i < pData->param.count; ++i)
- {
- carla_fill<char>(bufName, STR_MAX, '\0');
- carla_fill<char>(bufUnit, STR_MAX, '\0');
-
- getParameterName(i, bufName);
- getParameterUnit(i, bufUnit);
-
- const ParameterData& paramData(pData->param.data[i]);
- const ParameterRanges& paramRanges(pData->param.ranges[i]);
-
- #ifdef BUILD_BRIDGE
- pData->engine->oscSend_bridge_parameter_data(i, paramData.rindex, paramData.type, paramData.hints, bufName, bufUnit);
- pData->engine->oscSend_bridge_parameter_ranges1(i, paramRanges.def, paramRanges.min, paramRanges.max);
- pData->engine->oscSend_bridge_parameter_ranges2(i, paramRanges.step, paramRanges.stepSmall, paramRanges.stepLarge);
- pData->engine->oscSend_bridge_parameter_value(i, getParameterValue(i));
- pData->engine->oscSend_bridge_parameter_midi_cc(i, paramData.midiCC);
- pData->engine->oscSend_bridge_parameter_midi_channel(i, paramData.midiChannel);
- #else
- pData->engine->oscSend_control_set_parameter_data(pData->id, i, paramData.type, paramData.hints, bufName, bufUnit);
- pData->engine->oscSend_control_set_parameter_ranges1(pData->id, i, paramRanges.def, paramRanges.min, paramRanges.max);
- pData->engine->oscSend_control_set_parameter_ranges2(pData->id, i, paramRanges.step, paramRanges.stepSmall, paramRanges.stepLarge);
- pData->engine->oscSend_control_set_parameter_value(pData->id, i, getParameterValue(i));
- pData->engine->oscSend_control_set_parameter_midi_cc(pData->id, i, paramData.midiCC);
- pData->engine->oscSend_control_set_parameter_midi_channel(pData->id, i, paramData.midiChannel);
- #endif
- }
- }
-
- // Programs
- if (pData->prog.count > 0)
- {
- #ifdef BUILD_BRIDGE
- pData->engine->oscSend_bridge_program_count(pData->prog.count);
-
- for (uint32_t i=0; i < pData->prog.count; ++i)
- pData->engine->oscSend_bridge_program_name(i, pData->prog.names[i]);
-
- pData->engine->oscSend_bridge_current_program(pData->prog.current);
- #else
- pData->engine->oscSend_control_set_program_count(pData->id, pData->prog.count);
-
- for (uint32_t i=0; i < pData->prog.count; ++i)
- pData->engine->oscSend_control_set_program_name(pData->id, i, pData->prog.names[i]);
-
- pData->engine->oscSend_control_set_current_program(pData->id, pData->prog.current);
- #endif
- }
-
- // MIDI Programs
- if (pData->midiprog.count > 0)
- {
- #ifdef BUILD_BRIDGE
- pData->engine->oscSend_bridge_midi_program_count(pData->midiprog.count);
-
- for (uint32_t i=0; i < pData->midiprog.count; ++i)
- {
- const MidiProgramData& mpData(pData->midiprog.data[i]);
-
- pData->engine->oscSend_bridge_midi_program_data(i, mpData.bank, mpData.program, mpData.name);
- }
-
- pData->engine->oscSend_bridge_current_midi_program(pData->midiprog.current);
- #else
- pData->engine->oscSend_control_set_midi_program_count(pData->id, pData->midiprog.count);
-
- for (uint32_t i=0; i < pData->midiprog.count; ++i)
- {
- const MidiProgramData& mpData(pData->midiprog.data[i]);
-
- pData->engine->oscSend_control_set_midi_program_data(pData->id, i, mpData.bank, mpData.program, mpData.name);
- }
-
- pData->engine->oscSend_control_set_current_midi_program(pData->id, pData->midiprog.current);
- #endif
- }
-
- #ifndef BUILD_BRIDGE
- pData->engine->oscSend_control_add_plugin_end(pData->id);
-
- // Internal Parameters
- {
- pData->engine->oscSend_control_set_parameter_value(pData->id, PARAMETER_DRYWET, pData->postProc.dryWet);
- pData->engine->oscSend_control_set_parameter_value(pData->id, PARAMETER_VOLUME, pData->postProc.volume);
- pData->engine->oscSend_control_set_parameter_value(pData->id, PARAMETER_BALANCE_LEFT, pData->postProc.balanceLeft);
- pData->engine->oscSend_control_set_parameter_value(pData->id, PARAMETER_BALANCE_RIGHT, pData->postProc.balanceRight);
- pData->engine->oscSend_control_set_parameter_value(pData->id, PARAMETER_PANNING, pData->postProc.panning);
- pData->engine->oscSend_control_set_parameter_value(pData->id, PARAMETER_CTRL_CHANNEL, pData->ctrlChannel);
- pData->engine->oscSend_control_set_parameter_value(pData->id, PARAMETER_ACTIVE, pData->active ? 1.0f : 0.0f);
- }
- #endif
- }
-
- void CarlaPlugin::updateOscData(const lo_address& source, const char* const url)
- {
- // FIXME - remove debug prints later
- carla_stdout("CarlaPlugin::updateOscData(%p, \"%s\")", source, url);
-
- pData->osc.data.free();
-
- const int proto = lo_address_get_protocol(source);
-
- {
- const char* host = lo_address_get_hostname(source);
- const char* port = lo_address_get_port(source);
- pData->osc.data.source = lo_address_new_with_proto(proto, host, port);
-
- carla_stdout("CarlaPlugin::updateOscData() - source: host \"%s\", port \"%s\"", host, port);
- }
-
- {
- char* host = lo_url_get_hostname(url);
- char* port = lo_url_get_port(url);
- pData->osc.data.path = carla_strdup_free(lo_url_get_path(url));
- pData->osc.data.target = lo_address_new_with_proto(proto, host, port);
- carla_stdout("CarlaPlugin::updateOscData() - target: host \"%s\", port \"%s\", path \"%s\"", host, port, pData->osc.data.path);
-
- std::free(host);
- std::free(port);
- }
-
- #ifndef BUILD_BRIDGE
- if (pData->hints & PLUGIN_IS_BRIDGE)
- return;
- #endif
-
- osc_send_sample_rate(pData->osc.data, static_cast<float>(pData->engine->getSampleRate()));
-
- for (List<CustomData>::Itenerator it = pData->custom.begin(); it.valid(); it.next())
- {
- const CustomData& cData(it.getConstValue());
-
- CARLA_ASSERT(cData.type != nullptr);
- CARLA_ASSERT(cData.key != nullptr);
- CARLA_ASSERT(cData.value != nullptr);
-
- if (std::strcmp(cData.type, CUSTOM_DATA_TYPE_STRING) == 0)
- osc_send_configure(pData->osc.data, cData.key, cData.value);
- }
-
- if (pData->prog.current >= 0)
- osc_send_program(pData->osc.data, pData->prog.current);
-
- if (pData->midiprog.current >= 0)
- {
- const MidiProgramData& curMidiProg(pData->midiprog.getCurrent());
-
- if (getType() == PLUGIN_DSSI)
- osc_send_program(pData->osc.data, curMidiProg.bank, curMidiProg.program);
- else
- osc_send_midi_program(pData->osc.data, curMidiProg.bank, curMidiProg.program);
- }
-
- for (uint32_t i=0; i < pData->param.count; ++i)
- osc_send_control(pData->osc.data, pData->param.data[i].rindex, getParameterValue(i));
-
- carla_stdout("CarlaPlugin::updateOscData() - done");
- }
-
- // void CarlaPlugin::freeOscData()
- // {
- // pData->osc.data.free();
- // }
-
- bool CarlaPlugin::waitForOscGuiShow()
- {
- carla_stdout("CarlaPlugin::waitForOscGuiShow()");
- uint i=0, oscUiTimeout = pData->engine->getOptions().uiBridgesTimeout;
-
- // wait for UI 'update' call
- for (; i < oscUiTimeout/100; ++i)
- {
- if (pData->osc.data.target != nullptr)
- {
- carla_stdout("CarlaPlugin::waitForOscGuiShow() - got response, asking UI to show itself now");
- osc_send_show(pData->osc.data);
- return true;
- }
- else
- carla_msleep(100);
- }
-
- carla_stdout("CarlaPlugin::waitForOscGuiShow() - Timeout while waiting for UI to respond (waited %u msecs)", oscUiTimeout);
- return false;
- }
-
- // -------------------------------------------------------------------
- // MIDI events
-
- #ifndef BUILD_BRIDGE
- 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_ASSERT(channel < MAX_MIDI_CHANNELS);
- CARLA_ASSERT(note < MAX_MIDI_NOTE);
- CARLA_ASSERT(velo < MAX_MIDI_VALUE);
-
- if (! pData->active)
- return;
-
- ExternalMidiNote extNote;
- extNote.channel = channel;
- extNote.note = note;
- extNote.velo = velo;
-
- pData->extNotes.append(extNote);
-
- if (sendGui)
- {
- if (velo > 0)
- uiNoteOn(channel, note, velo);
- else
- uiNoteOff(channel, note);
- }
-
- if (sendOsc)
- {
- if (velo > 0)
- pData->engine->oscSend_control_note_on(pData->id, channel, note, velo);
- else
- pData->engine->oscSend_control_note_off(pData->id, channel, note);
- }
-
- if (sendCallback)
- pData->engine->callback((velo > 0) ? ENGINE_CALLBACK_NOTE_ON : ENGINE_CALLBACK_NOTE_OFF, pData->id, channel, note, velo, nullptr);
- }
- #endif
-
- void CarlaPlugin::sendMidiAllNotesOffToCallback()
- {
- if (pData->ctrlChannel < 0 || pData->ctrlChannel >= MAX_MIDI_CHANNELS)
- return;
-
- PluginPostRtEvent postEvent;
- postEvent.type = kPluginPostRtEventNoteOff;
- postEvent.value1 = pData->ctrlChannel;
- postEvent.value2 = 0;
- postEvent.value3 = 0.0f;
-
- for (unsigned short i=0; i < MAX_MIDI_NOTE; ++i)
- {
- postEvent.value2 = i;
- pData->postRtEvents.appendRT(postEvent);
- }
- }
-
- // -------------------------------------------------------------------
- // Post-poned events
-
- void CarlaPlugin::postRtEventsRun()
- {
- const CarlaMutex::ScopedLocker sl(pData->postRtEvents.mutex);
-
- while (! pData->postRtEvents.data.isEmpty())
- {
- const PluginPostRtEvent& event(pData->postRtEvents.data.getFirst(true));
-
- switch (event.type)
- {
- case kPluginPostRtEventNull:
- break;
-
- case kPluginPostRtEventDebug:
- #ifndef BUILD_BRIDGE
- pData->engine->callback(ENGINE_CALLBACK_DEBUG, pData->id, event.value1, event.value2, event.value3, nullptr);
- #endif
- break;
-
- case kPluginPostRtEventParameterChange:
- // Update UI
- if (event.value1 >= 0)
- uiParameterChange(event.value1, event.value3);
-
- #ifndef BUILD_BRIDGE
- if (event.value2 != 1)
- {
- // Update OSC control client
- if (pData->engine->isOscControlRegistered())
- pData->engine->oscSend_control_set_parameter_value(pData->id, event.value1, event.value3);
-
- // Update Host
- pData->engine->callback(ENGINE_CALLBACK_PARAMETER_VALUE_CHANGED, pData->id, event.value1, 0, event.value3, nullptr);
- }
- #endif
- break;
-
- case kPluginPostRtEventProgramChange:
- // Update UI
- if (event.value1 >= 0)
- uiProgramChange(event.value1);
-
- #ifndef BUILD_BRIDGE
- // Update OSC control client
- if (pData->engine->isOscControlRegistered())
- pData->engine->oscSend_control_set_current_program(pData->id, event.value1);
-
- // Update Host
- pData->engine->callback(ENGINE_CALLBACK_PROGRAM_CHANGED, pData->id, event.value1, 0, 0.0f, nullptr);
-
- // Update param values
- {
- const bool sendOsc(pData->engine->isOscControlRegistered());
-
- for (uint32_t j=0; j < pData->param.count; ++j)
- {
- const float value(getParameterValue(j));
-
- if (sendOsc)
- {
- pData->engine->oscSend_control_set_parameter_value(pData->id, j, value);
- pData->engine->oscSend_control_set_default_value(pData->id, j, pData->param.ranges[j].def);
- }
-
- pData->engine->callback(ENGINE_CALLBACK_PARAMETER_VALUE_CHANGED, pData->id, j, 0, value, nullptr);
- pData->engine->callback(ENGINE_CALLBACK_PARAMETER_DEFAULT_CHANGED, pData->id, j, 0, pData->param.ranges[j].def, nullptr);
- }
- }
- #endif
- break;
-
- case kPluginPostRtEventMidiProgramChange:
- // Update UI
- if (event.value1 >= 0)
- uiMidiProgramChange(event.value1);
-
- #ifndef BUILD_BRIDGE
- // Update OSC control client
- if (pData->engine->isOscControlRegistered())
- pData->engine->oscSend_control_set_current_midi_program(pData->id, event.value1);
-
- // Update Host
- pData->engine->callback(ENGINE_CALLBACK_MIDI_PROGRAM_CHANGED, pData->id, event.value1, 0, 0.0f, nullptr);
-
- // Update param values
- {
- const bool sendOsc(pData->engine->isOscControlRegistered());
-
- for (uint32_t j=0; j < pData->param.count; ++j)
- {
- const float value(getParameterValue(j));
-
- if (sendOsc)
- {
- pData->engine->oscSend_control_set_parameter_value(pData->id, j, value);
- pData->engine->oscSend_control_set_default_value(pData->id, j, pData->param.ranges[j].def);
- }
-
- pData->engine->callback(ENGINE_CALLBACK_PARAMETER_VALUE_CHANGED, pData->id, j, 0, value, nullptr);
- pData->engine->callback(ENGINE_CALLBACK_PARAMETER_DEFAULT_CHANGED, pData->id, j, 0, pData->param.ranges[j].def, nullptr);
- }
- }
- #endif
- break;
-
- case kPluginPostRtEventNoteOn:
- {
- CARLA_SAFE_ASSERT_BREAK(event.value1 < MAX_MIDI_CHANNELS);
- CARLA_SAFE_ASSERT_BREAK(event.value2 < MAX_MIDI_NOTE);
- CARLA_SAFE_ASSERT_BREAK(event.value3 < MAX_MIDI_VALUE);
-
- const uint8_t channel = static_cast<uint8_t>(event.value1);
- const uint8_t note = static_cast<uint8_t>(event.value2);
- const uint8_t velocity = uint8_t(event.value3);
-
- // Update UI
- uiNoteOn(channel, note, velocity);
-
- #ifndef BUILD_BRIDGE
- // Update OSC control client
- if (pData->engine->isOscControlRegistered())
- pData->engine->oscSend_control_note_on(pData->id, channel, note, velocity);
-
- // Update Host
- pData->engine->callback(ENGINE_CALLBACK_NOTE_ON, pData->id, event.value1, event.value2, event.value3, nullptr);
- #endif
- break;
- }
-
- case kPluginPostRtEventNoteOff:
- {
- CARLA_SAFE_ASSERT_BREAK(event.value1 < MAX_MIDI_CHANNELS);
- CARLA_SAFE_ASSERT_BREAK(event.value2 < MAX_MIDI_NOTE);
-
- const uint8_t channel = static_cast<uint8_t>(event.value1);
- const uint8_t note = static_cast<uint8_t>(event.value2);
-
- // Update UI
- uiNoteOff(channel, note);
-
- #ifndef BUILD_BRIDGE
- // Update OSC control client
- if (pData->engine->isOscControlRegistered())
- pData->engine->oscSend_control_note_off(pData->id, channel, note);
-
- // Update Host
- pData->engine->callback(ENGINE_CALLBACK_NOTE_OFF, pData->id, event.value1, event.value2, 0.0f, nullptr);
- #endif
- break;
- }
- }
- }
- }
-
- // -------------------------------------------------------------------
- // Post-poned UI Stuff
-
- void CarlaPlugin::uiParameterChange(const uint32_t index, const float value)
- {
- CARLA_ASSERT(index < getParameterCount());
- return;
-
- // unused
- (void)index;
- (void)value;
- }
-
- void CarlaPlugin::uiProgramChange(const uint32_t index)
- {
- CARLA_ASSERT(index < getProgramCount());
- return;
-
- // unused
- (void)index;
- }
-
- void CarlaPlugin::uiMidiProgramChange(const uint32_t index)
- {
- CARLA_ASSERT(index < getMidiProgramCount());
- return;
-
- // unused
- (void)index;
- }
-
- void CarlaPlugin::uiNoteOn(const uint8_t channel, const uint8_t note, const uint8_t velo)
- {
- CARLA_ASSERT(channel < MAX_MIDI_CHANNELS);
- CARLA_ASSERT(note < MAX_MIDI_NOTE);
- CARLA_ASSERT(velo > 0 && velo < MAX_MIDI_VALUE);
- return;
-
- // unused
- (void)channel;
- (void)note;
- (void)velo;
- }
-
- void CarlaPlugin::uiNoteOff(const uint8_t channel, const uint8_t note)
- {
- CARLA_ASSERT(channel < MAX_MIDI_CHANNELS);
- CARLA_ASSERT(note < MAX_MIDI_NOTE);
- return;
-
- // unused
- (void)channel;
- (void)note;
- }
-
- bool CarlaPlugin::canRunInRack() const noexcept
- {
- return (pData->extraHints & PLUGIN_EXTRA_HINT_CAN_RUN_RACK) != 0;
- }
-
- 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;
- }
-
- // -------------------------------------------------------------------
- // Scoped Disabler
-
- CarlaPlugin::ScopedDisabler::ScopedDisabler(CarlaPlugin* const plugin)
- : fPlugin(plugin)
- {
- 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)
- plugin->pData->enabled = false;
-
- if (plugin->pData->client->isActive())
- plugin->pData->client->deactivate();
- }
-
- CarlaPlugin::ScopedDisabler::~ScopedDisabler()
- {
- 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()");
-
- fPlugin->pData->enabled = true;
- fPlugin->pData->client->activate();
- fPlugin->pData->masterMutex.unlock();
- }
-
- // -------------------------------------------------------------------
- // Scoped Process Locker
-
- CarlaPlugin::ScopedSingleProcessLocker::ScopedSingleProcessLocker(CarlaPlugin* const plugin, const bool block)
- : 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()
- {
- CARLA_SAFE_ASSERT_RETURN(fPlugin != nullptr,);
- CARLA_SAFE_ASSERT_RETURN(fPlugin->pData != nullptr,);
- carla_debug("CarlaPlugin::~ScopedSingleProcessLocker()");
-
- if (! fBlock)
- return;
-
- #ifndef BUILD_BRIDGE
- if (fPlugin->pData->singleMutex.wasTryLockCalled())
- fPlugin->pData->needsReset = true;
- #endif
-
- fPlugin->pData->singleMutex.unlock();
- }
-
- // #ifdef BUILD_BRIDGE
- // CarlaPlugin* newFailAsBridge(const CarlaPlugin::Initializer& init)
- // {
- // init.engine->setLastError("Can't use this in plugin bridges");
- // return nullptr;
- // }
- //
- // CarlaPlugin* CarlaPlugin::newNative(const Initializer& init) { return newFailAsBridge(init); }
- // CarlaPlugin* CarlaPlugin::newGIG(const Initializer& init, const bool) { return newFailAsBridge(init); }
- // CarlaPlugin* CarlaPlugin::newSF2(const Initializer& init, const bool) { return newFailAsBridge(init); }
- // CarlaPlugin* CarlaPlugin::newSFZ(const Initializer& init, const bool) { return newFailAsBridge(init); }
- //
- // # ifdef WANT_NATIVE
- // size_t CarlaPlugin::getNativePluginCount() { return 0; }
- // const PluginDescriptor* CarlaPlugin::getNativePluginDescriptor(const size_t) { return nullptr; }
- // # endif
- // #endif
-
- // -------------------------------------------------------------------
-
- CARLA_BACKEND_END_NAMESPACE
|