|
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540 |
- /*
- * Carla LADSPA 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"
-
- #ifdef WANT_LADSPA
-
- #include "CarlaLadspaUtils.hpp"
-
- CARLA_BACKEND_START_NAMESPACE
-
- #if 0
- }
- #endif
-
- class LadspaPlugin : public CarlaPlugin
- {
- public:
- LadspaPlugin(CarlaEngine* const engine, const unsigned int id)
- : CarlaPlugin(engine, id),
- fHandle(nullptr),
- fHandle2(nullptr),
- fDescriptor(nullptr),
- fRdfDescriptor(nullptr),
- fAudioInBuffers(nullptr),
- fAudioOutBuffers(nullptr),
- fParamBuffers(nullptr)
- {
- carla_debug("LadspaPlugin::LadspaPlugin(%p, %i)", engine, id);
- }
-
- ~LadspaPlugin() override
- {
- carla_debug("LadspaPlugin::~LadspaPlugin()");
-
- pData->singleMutex.lock();
- pData->masterMutex.lock();
-
- if (pData->client != nullptr && pData->client->isActive())
- pData->client->deactivate();
-
- if (pData->active)
- {
- deactivate();
- pData->active = false;
- }
-
- if (fDescriptor != nullptr)
- {
- if (fDescriptor->cleanup != nullptr)
- {
- if (fHandle != nullptr)
- fDescriptor->cleanup(fHandle);
- if (fHandle2 != nullptr)
- fDescriptor->cleanup(fHandle2);
- }
-
- fHandle = nullptr;
- fHandle2 = nullptr;
- fDescriptor = nullptr;
- }
-
- if (fRdfDescriptor != nullptr)
- {
- delete fRdfDescriptor;
- fRdfDescriptor = nullptr;
- }
-
- clearBuffers();
- }
-
- // -------------------------------------------------------------------
- // Information (base)
-
- PluginType getType() const noexcept override
- {
- return PLUGIN_LADSPA;
- }
-
- PluginCategory getCategory() const override
- {
- if (fRdfDescriptor != nullptr)
- {
- const LADSPA_PluginType category(fRdfDescriptor->Type);
-
- // Specific Types
- if (category & (LADSPA_PLUGIN_DELAY|LADSPA_PLUGIN_REVERB))
- return PLUGIN_CATEGORY_DELAY;
- if (category & (LADSPA_PLUGIN_PHASER|LADSPA_PLUGIN_FLANGER|LADSPA_PLUGIN_CHORUS))
- return PLUGIN_CATEGORY_MODULATOR;
- if (category & (LADSPA_PLUGIN_AMPLIFIER))
- return PLUGIN_CATEGORY_DYNAMICS;
- if (category & (LADSPA_PLUGIN_UTILITY|LADSPA_PLUGIN_SPECTRAL|LADSPA_PLUGIN_FREQUENCY_METER))
- return PLUGIN_CATEGORY_UTILITY;
-
- // Pre-set LADSPA Types
- if (LADSPA_IS_PLUGIN_DYNAMICS(category))
- return PLUGIN_CATEGORY_DYNAMICS;
- if (LADSPA_IS_PLUGIN_AMPLITUDE(category))
- return PLUGIN_CATEGORY_MODULATOR;
- if (LADSPA_IS_PLUGIN_EQ(category))
- return PLUGIN_CATEGORY_EQ;
- if (LADSPA_IS_PLUGIN_FILTER(category))
- return PLUGIN_CATEGORY_FILTER;
- if (LADSPA_IS_PLUGIN_FREQUENCY(category))
- return PLUGIN_CATEGORY_UTILITY;
- if (LADSPA_IS_PLUGIN_SIMULATOR(category))
- return PLUGIN_CATEGORY_OTHER;
- if (LADSPA_IS_PLUGIN_TIME(category))
- return PLUGIN_CATEGORY_DELAY;
- if (LADSPA_IS_PLUGIN_GENERATOR(category))
- return PLUGIN_CATEGORY_SYNTH;
- }
-
- return getPluginCategoryFromName(fName);
- }
-
- long getUniqueId() const override
- {
- CARLA_ASSERT(fDescriptor != nullptr);
-
- return fDescriptor->UniqueID;
- }
-
- // -------------------------------------------------------------------
- // Information (count)
-
- uint32_t getParameterScalePointCount(const uint32_t parameterId) const override
- {
- CARLA_ASSERT(parameterId < pData->param.count);
-
- const int32_t rindex(pData->param.data[parameterId].rindex);
-
- if (fRdfDescriptor != nullptr && rindex < static_cast<int32_t>(fRdfDescriptor->PortCount))
- {
- const LADSPA_RDF_Port& port(fRdfDescriptor->Ports[rindex]);
- return port.ScalePointCount;
- }
-
- return 0;
- }
-
- // -------------------------------------------------------------------
- // Information (current data)
-
- // nothing
-
- // -------------------------------------------------------------------
- // Information (per-plugin data)
-
- unsigned int getAvailableOptions() const override
- {
- #ifdef __USE_GNU
- const bool isDssiVst = fFilename.contains("dssi-vst", true);
- #else
- const bool isDssiVst = fFilename.contains("dssi-vst");
- #endif
-
- unsigned int options = 0x0;
-
- if (! isDssiVst)
- options |= PLUGIN_OPTION_FIXED_BUFFERS;
-
- if (pData->engine->getProccessMode() != PROCESS_MODE_CONTINUOUS_RACK)
- {
- if (fOptions & PLUGIN_OPTION_FORCE_STEREO)
- options |= PLUGIN_OPTION_FORCE_STEREO;
- else if (pData->audioIn.count <= 1 && pData->audioOut.count <= 1 && (pData->audioIn.count != 0 || pData->audioOut.count != 0))
- options |= PLUGIN_OPTION_FORCE_STEREO;
- }
-
- return options;
- }
-
- float getParameterValue(const uint32_t parameterId) const override
- {
- CARLA_ASSERT(fParamBuffers != nullptr);
- CARLA_ASSERT(parameterId < pData->param.count);
-
- return fParamBuffers[parameterId];
- }
-
- float getParameterScalePointValue(const uint32_t parameterId, const uint32_t scalePointId) const override
- {
- CARLA_ASSERT(fRdfDescriptor != nullptr);
- CARLA_ASSERT(parameterId < pData->param.count);
- CARLA_ASSERT(scalePointId < getParameterScalePointCount(parameterId));
-
- const int32_t rindex(pData->param.data[parameterId].rindex);
-
- if (fRdfDescriptor != nullptr && rindex < static_cast<int32_t>(fRdfDescriptor->PortCount))
- {
- const LADSPA_RDF_Port& port(fRdfDescriptor->Ports[rindex]);
-
- if (scalePointId < port.ScalePointCount)
- {
- const LADSPA_RDF_ScalePoint& scalePoint(port.ScalePoints[scalePointId]);
- return scalePoint.Value;
- }
- }
-
- return 0.0f;
- }
-
- void getLabel(char* const strBuf) const override
- {
- CARLA_ASSERT(fDescriptor != nullptr);
-
- if (fDescriptor->Label != nullptr)
- std::strncpy(strBuf, fDescriptor->Label, STR_MAX);
- else
- CarlaPlugin::getLabel(strBuf);
- }
-
- void getMaker(char* const strBuf) const override
- {
- CARLA_ASSERT(fDescriptor != nullptr);
-
- if (fRdfDescriptor != nullptr && fRdfDescriptor->Creator != nullptr)
- std::strncpy(strBuf, fRdfDescriptor->Creator, STR_MAX);
- else if (fDescriptor->Maker != nullptr)
- std::strncpy(strBuf, fDescriptor->Maker, STR_MAX);
- else
- CarlaPlugin::getMaker(strBuf);
- }
-
- void getCopyright(char* const strBuf) const override
- {
- CARLA_ASSERT(fDescriptor != nullptr);
-
- if (fDescriptor->Copyright != nullptr)
- std::strncpy(strBuf, fDescriptor->Copyright, STR_MAX);
- else
- CarlaPlugin::getCopyright(strBuf);
- }
-
- void getRealName(char* const strBuf) const override
- {
- CARLA_ASSERT(fDescriptor != nullptr);
-
- if (fRdfDescriptor != nullptr && fRdfDescriptor->Title != nullptr)
- std::strncpy(strBuf, fRdfDescriptor->Title, STR_MAX);
- else if (fDescriptor->Name != nullptr)
- std::strncpy(strBuf, fDescriptor->Name, STR_MAX);
- else
- CarlaPlugin::getRealName(strBuf);
- }
-
- void getParameterName(const uint32_t parameterId, char* const strBuf) const override
- {
- CARLA_ASSERT(fDescriptor != nullptr);
- CARLA_ASSERT(parameterId < pData->param.count);
-
- const int32_t rindex(pData->param.data[parameterId].rindex);
-
- if (rindex < static_cast<int32_t>(fDescriptor->PortCount))
- std::strncpy(strBuf, fDescriptor->PortNames[rindex], STR_MAX);
- else
- CarlaPlugin::getParameterName(parameterId, strBuf);
- }
-
- void getParameterSymbol(const uint32_t parameterId, char* const strBuf) const override
- {
- CARLA_ASSERT(parameterId < pData->param.count);
-
- const int32_t rindex(pData->param.data[parameterId].rindex);
-
- if (fRdfDescriptor != nullptr && rindex < static_cast<int32_t>(fRdfDescriptor->PortCount))
- {
- const LADSPA_RDF_Port& port = fRdfDescriptor->Ports[rindex];
-
- if (LADSPA_PORT_HAS_LABEL(port.Hints) && port.Label != nullptr)
- {
- std::strncpy(strBuf, port.Label, STR_MAX);
- return;
- }
- }
-
- CarlaPlugin::getParameterSymbol(parameterId, strBuf);
- }
-
- void getParameterUnit(const uint32_t parameterId, char* const strBuf) const override
- {
- CARLA_ASSERT(parameterId < pData->param.count);
-
- const int32_t rindex(pData->param.data[parameterId].rindex);
-
- if (fRdfDescriptor != nullptr && rindex < static_cast<int32_t>(fRdfDescriptor->PortCount))
- {
- const LADSPA_RDF_Port& port(fRdfDescriptor->Ports[rindex]);
-
- if (LADSPA_PORT_HAS_UNIT(port.Hints))
- {
- switch (port.Unit)
- {
- case LADSPA_UNIT_DB:
- std::strncpy(strBuf, "dB", STR_MAX);
- return;
- case LADSPA_UNIT_COEF:
- std::strncpy(strBuf, "(coef)", STR_MAX);
- return;
- case LADSPA_UNIT_HZ:
- std::strncpy(strBuf, "Hz", STR_MAX);
- return;
- case LADSPA_UNIT_S:
- std::strncpy(strBuf, "s", STR_MAX);
- return;
- case LADSPA_UNIT_MS:
- std::strncpy(strBuf, "ms", STR_MAX);
- return;
- case LADSPA_UNIT_MIN:
- std::strncpy(strBuf, "min", STR_MAX);
- return;
- }
- }
- }
-
- CarlaPlugin::getParameterUnit(parameterId, strBuf);
- }
-
- void getParameterScalePointLabel(const uint32_t parameterId, const uint32_t scalePointId, char* const strBuf) const override
- {
- CARLA_ASSERT(fRdfDescriptor != nullptr);
- CARLA_ASSERT(parameterId < pData->param.count);
- CARLA_ASSERT(scalePointId < getParameterScalePointCount(parameterId));
-
- const int32_t rindex(pData->param.data[parameterId].rindex);
-
- if (fRdfDescriptor != nullptr && rindex < static_cast<int32_t>(fRdfDescriptor->PortCount))
- {
- const LADSPA_RDF_Port& port(fRdfDescriptor->Ports[rindex]);
-
- if (scalePointId < port.ScalePointCount)
- {
- const LADSPA_RDF_ScalePoint& scalePoint(port.ScalePoints[scalePointId]);
-
- if (scalePoint.Label != nullptr)
- {
- std::strncpy(strBuf, scalePoint.Label, STR_MAX);
- return;
- }
- }
- }
-
- CarlaPlugin::getParameterScalePointLabel(parameterId, scalePointId, strBuf);
- }
-
- // -------------------------------------------------------------------
- // Set data (state)
-
- // nothing
-
- // -------------------------------------------------------------------
- // Set data (internal stuff)
-
- // nothing
-
- // -------------------------------------------------------------------
- // Set data (plugin-specific stuff)
-
- void setParameterValue(const uint32_t parameterId, const float value, const bool sendGui, const bool sendOsc, const bool sendCallback) override
- {
- CARLA_ASSERT(parameterId < pData->param.count);
-
- const float fixedValue(pData->param.getFixedValue(parameterId, value));
- fParamBuffers[parameterId] = fixedValue;
-
- CarlaPlugin::setParameterValue(parameterId, fixedValue, sendGui, sendOsc, sendCallback);
- }
-
- // -------------------------------------------------------------------
- // Set gui stuff
-
- // nothing
-
- // -------------------------------------------------------------------
- // Plugin state
-
- void reload() override
- {
- carla_debug("LadspaPlugin::reload() - start");
- CARLA_ASSERT(pData->engine != nullptr);
- CARLA_ASSERT(fDescriptor != nullptr);
- CARLA_ASSERT(fHandle != nullptr);
-
- if (pData->engine == nullptr)
- return;
- if (fDescriptor == nullptr)
- return;
- if (fHandle == nullptr)
- return;
-
- const ProcessMode processMode(pData->engine->getProccessMode());
-
- // Safely disable plugin for reload
- const ScopedDisabler sd(this);
-
- if (pData->active)
- deactivate();
-
- clearBuffers();
-
- const float sampleRate(static_cast<float>(pData->engine->getSampleRate()));
- const uint32_t portCount(static_cast<uint32_t>(fDescriptor->PortCount));
-
- uint32_t aIns, aOuts, params, j;
- aIns = aOuts = params = 0;
-
- bool forcedStereoIn, forcedStereoOut;
- forcedStereoIn = forcedStereoOut = false;
-
- bool needsCtrlIn, needsCtrlOut;
- needsCtrlIn = needsCtrlOut = false;
-
- if (portCount > 0)
- {
- CARLA_ASSERT(fDescriptor->PortDescriptors != nullptr);
- CARLA_ASSERT(fDescriptor->PortRangeHints != nullptr);
- CARLA_ASSERT(fDescriptor->PortNames != nullptr);
-
- for (uint32_t i=0; i < portCount; ++i)
- {
- const LADSPA_PortDescriptor portType = fDescriptor->PortDescriptors[i];
-
- if (LADSPA_IS_PORT_AUDIO(portType))
- {
- if (LADSPA_IS_PORT_INPUT(portType))
- aIns += 1;
- else if (LADSPA_IS_PORT_OUTPUT(portType))
- aOuts += 1;
- }
- else if (LADSPA_IS_PORT_CONTROL(portType))
- params += 1;
- }
- }
-
- if ((fOptions & PLUGIN_OPTION_FORCE_STEREO) != 0 && (aIns == 1 || aOuts == 1))
- {
- if (fHandle2 == nullptr)
- fHandle2 = fDescriptor->instantiate(fDescriptor, (unsigned long)sampleRate);
-
- if (fHandle2 != nullptr)
- {
- if (aIns == 1)
- {
- aIns = 2;
- forcedStereoIn = true;
- }
-
- if (aOuts == 1)
- {
- aOuts = 2;
- forcedStereoOut = true;
- }
- }
- }
-
- if (aIns > 0)
- {
- pData->audioIn.createNew(aIns);
- fAudioInBuffers = new float*[aIns];
-
- for (uint32_t i=0; i < aIns; ++i)
- fAudioInBuffers[i] = nullptr;
- }
-
- if (aOuts > 0)
- {
- pData->audioOut.createNew(aOuts);
- fAudioOutBuffers = new float*[aOuts];
- needsCtrlIn = true;
-
- for (uint32_t i=0; i < aOuts; ++i)
- fAudioOutBuffers[i] = nullptr;
- }
-
- if (params > 0)
- {
- pData->param.createNew(params);
-
- fParamBuffers = new float[params];
- carla_zeroFloat(fParamBuffers, params);
- }
-
- const uint portNameSize(pData->engine->getMaxPortNameSize());
- CarlaString portName;
-
- for (uint32_t i=0, iAudioIn=0, iAudioOut=0, iCtrl=0; i < portCount; ++i)
- {
- const LADSPA_PortDescriptor portType = fDescriptor->PortDescriptors[i];
- const LADSPA_PortRangeHint portRangeHints = fDescriptor->PortRangeHints[i];
- const bool hasPortRDF = (fRdfDescriptor != nullptr && i < fRdfDescriptor->PortCount);
-
- CARLA_ASSERT(fDescriptor->PortNames[i] != nullptr);
-
- if (LADSPA_IS_PORT_AUDIO(portType))
- {
- portName.clear();
-
- if (processMode == PROCESS_MODE_SINGLE_CLIENT)
- {
- portName = fName;
- portName += ":";
- }
-
- portName += fDescriptor->PortNames[i];
- portName.truncate(portNameSize);
-
- if (LADSPA_IS_PORT_INPUT(portType))
- {
- j = iAudioIn++;
- pData->audioIn.ports[j].port = (CarlaEngineAudioPort*)pData->client->addPort(kEnginePortTypeAudio, portName, true);
- pData->audioIn.ports[j].rindex = i;
-
- if (forcedStereoIn)
- {
- portName += "_2";
- pData->audioIn.ports[1].port = (CarlaEngineAudioPort*)pData->client->addPort(kEnginePortTypeAudio, portName, true);
- pData->audioIn.ports[1].rindex = i;
- }
- }
- else if (LADSPA_IS_PORT_OUTPUT(portType))
- {
- j = iAudioOut++;
- pData->audioOut.ports[j].port = (CarlaEngineAudioPort*)pData->client->addPort(kEnginePortTypeAudio, portName, false);
- pData->audioOut.ports[j].rindex = i;
-
- if (forcedStereoOut)
- {
- portName += "_2";
- pData->audioOut.ports[1].port = (CarlaEngineAudioPort*)pData->client->addPort(kEnginePortTypeAudio, portName, false);
- pData->audioOut.ports[1].rindex = i;
- }
- }
- else
- carla_stderr2("WARNING - Got a broken Port (Audio, but not input or output)");
- }
- else if (LADSPA_IS_PORT_CONTROL(portType))
- {
- j = iCtrl++;
- pData->param.data[j].index = j;
- pData->param.data[j].rindex = i;
- pData->param.data[j].hints = 0x0;
- pData->param.data[j].midiChannel = 0;
- pData->param.data[j].midiCC = -1;
-
- float min, max, def, step, stepSmall, stepLarge;
-
- // min value
- if (LADSPA_IS_HINT_BOUNDED_BELOW(portRangeHints.HintDescriptor))
- min = portRangeHints.LowerBound;
- else
- min = 0.0f;
-
- // max value
- if (LADSPA_IS_HINT_BOUNDED_ABOVE(portRangeHints.HintDescriptor))
- max = portRangeHints.UpperBound;
- else
- max = 1.0f;
-
- if (min > max)
- max = min;
- else if (max < min)
- min = max;
-
- if (max - min == 0.0f)
- {
- carla_stderr2("WARNING - Broken plugin parameter '%s': max - min == 0.0f", fDescriptor->PortNames[i]);
- max = min + 0.1f;
- }
-
- // default value
- if (hasPortRDF && LADSPA_PORT_HAS_DEFAULT(fRdfDescriptor->Ports[i].Hints))
- def = fRdfDescriptor->Ports[i].Default;
- else
- def = get_default_ladspa_port_value(portRangeHints.HintDescriptor, min, max);
-
- if (def < min)
- def = min;
- else if (def > max)
- def = max;
-
- if (LADSPA_IS_HINT_SAMPLE_RATE(portRangeHints.HintDescriptor))
- {
- min *= sampleRate;
- max *= sampleRate;
- def *= sampleRate;
- pData->param.data[j].hints |= PARAMETER_USES_SAMPLERATE;
- }
-
- if (LADSPA_IS_HINT_TOGGLED(portRangeHints.HintDescriptor))
- {
- step = max - min;
- stepSmall = step;
- stepLarge = step;
- pData->param.data[j].hints |= PARAMETER_IS_BOOLEAN;
- }
- else if (LADSPA_IS_HINT_INTEGER(portRangeHints.HintDescriptor))
- {
- step = 1.0f;
- stepSmall = 1.0f;
- stepLarge = 10.0f;
- pData->param.data[j].hints |= PARAMETER_IS_INTEGER;
- }
- else
- {
- float range = max - min;
- step = range/100.0f;
- stepSmall = range/1000.0f;
- stepLarge = range/10.0f;
- }
-
- if (LADSPA_IS_PORT_INPUT(portType))
- {
- pData->param.data[j].type = PARAMETER_INPUT;
- pData->param.data[j].hints |= PARAMETER_IS_ENABLED;
- pData->param.data[j].hints |= PARAMETER_IS_AUTOMABLE;
- needsCtrlIn = true;
- }
- else if (LADSPA_IS_PORT_OUTPUT(portType))
- {
- if (std::strcmp(fDescriptor->PortNames[i], "latency") == 0 || std::strcmp(fDescriptor->PortNames[i], "_latency") == 0)
- {
- min = 0.0f;
- max = sampleRate;
- def = 0.0f;
- step = 1.0f;
- stepSmall = 1.0f;
- stepLarge = 1.0f;
-
- pData->param.data[j].type = PARAMETER_LATENCY;
- pData->param.data[j].hints = 0;
- }
- else if (std::strcmp(fDescriptor->PortNames[i], "_sample-rate") == 0)
- {
- def = sampleRate;
- step = 1.0f;
- stepSmall = 1.0f;
- stepLarge = 1.0f;
-
- pData->param.data[j].type = PARAMETER_SAMPLE_RATE;
- pData->param.data[j].hints = 0;
- }
- else
- {
- pData->param.data[j].type = PARAMETER_OUTPUT;
- pData->param.data[j].hints |= PARAMETER_IS_ENABLED;
- pData->param.data[j].hints |= PARAMETER_IS_AUTOMABLE;
- needsCtrlOut = true;
- }
- }
- else
- {
- pData->param.data[j].type = PARAMETER_UNKNOWN;
- carla_stderr2("WARNING - Got a broken Port (Control, but not input or output)");
- }
-
- // extra parameter hints
- if (LADSPA_IS_HINT_LOGARITHMIC(portRangeHints.HintDescriptor))
- pData->param.data[j].hints |= PARAMETER_IS_LOGARITHMIC;
-
- // check for scalepoints, require at least 2 to make it useful
- if (hasPortRDF && fRdfDescriptor->Ports[i].ScalePointCount > 1)
- pData->param.data[j].hints |= PARAMETER_USES_SCALEPOINTS;
-
- pData->param.ranges[j].min = min;
- pData->param.ranges[j].max = max;
- pData->param.ranges[j].def = def;
- pData->param.ranges[j].step = step;
- pData->param.ranges[j].stepSmall = stepSmall;
- pData->param.ranges[j].stepLarge = stepLarge;
-
- // Start parameters in their default values
- fParamBuffers[j] = def;
-
- fDescriptor->connect_port(fHandle, i, &fParamBuffers[j]);
-
- if (fHandle2 != nullptr)
- fDescriptor->connect_port(fHandle2, i, &fParamBuffers[j]);
- }
- else
- {
- // Not Audio or Control
- carla_stderr2("ERROR - Got a broken Port (neither Audio or Control)");
-
- fDescriptor->connect_port(fHandle, i, nullptr);
-
- if (fHandle2 != nullptr)
- fDescriptor->connect_port(fHandle2, i, nullptr);
- }
- }
-
- if (needsCtrlIn)
- {
- portName.clear();
-
- if (processMode == PROCESS_MODE_SINGLE_CLIENT)
- {
- portName = fName;
- portName += ":";
- }
-
- portName += "events-in";
- portName.truncate(portNameSize);
-
- pData->event.portIn = (CarlaEngineEventPort*)pData->client->addPort(kEnginePortTypeEvent, portName, true);
- }
-
- if (needsCtrlOut)
- {
- portName.clear();
-
- if (processMode == PROCESS_MODE_SINGLE_CLIENT)
- {
- portName = fName;
- portName += ":";
- }
-
- portName += "events-out";
- portName.truncate(portNameSize);
-
- pData->event.portOut = (CarlaEngineEventPort*)pData->client->addPort(kEnginePortTypeEvent, portName, false);
- }
-
- if (forcedStereoIn || forcedStereoOut)
- fOptions |= PLUGIN_OPTION_FORCE_STEREO;
- else
- fOptions &= ~PLUGIN_OPTION_FORCE_STEREO;
-
- // plugin hints
- fHints = 0x0;
-
- if (LADSPA_IS_HARD_RT_CAPABLE(fDescriptor->Properties))
- fHints |= PLUGIN_IS_RTSAFE;
-
- if (aOuts > 0 && (aIns == aOuts || aIns == 1))
- fHints |= PLUGIN_CAN_DRYWET;
-
- if (aOuts > 0)
- fHints |= PLUGIN_CAN_VOLUME;
-
- if (aOuts >= 2 && aOuts % 2 == 0)
- fHints |= PLUGIN_CAN_BALANCE;
-
- // extra plugin hints
- pData->extraHints = 0x0;
-
- if (aIns <= 2 && aOuts <= 2 && (aIns == aOuts || aIns == 0 || aOuts == 0))
- pData->extraHints |= PLUGIN_EXTRA_HINT_CAN_RUN_RACK;
-
- // check latency
- if (fHints & PLUGIN_CAN_DRYWET)
- {
- for (uint32_t i=0; i < pData->param.count; ++i)
- {
- if (pData->param.data[i].type != PARAMETER_LATENCY)
- continue;
-
- // we need to pre-run the plugin so it can update its latency control-port
-
- float tmpIn[aIns][2];
- float tmpOut[aOuts][2];
-
- for (j=0; j < aIns; ++j)
- {
- tmpIn[j][0] = 0.0f;
- tmpIn[j][1] = 0.0f;
-
- fDescriptor->connect_port(fHandle, pData->audioIn.ports[j].rindex, tmpIn[j]);
- }
-
- for (j=0; j < aOuts; ++j)
- {
- tmpOut[j][0] = 0.0f;
- tmpOut[j][1] = 0.0f;
-
- fDescriptor->connect_port(fHandle, pData->audioOut.ports[j].rindex, tmpOut[j]);
- }
-
- if (fDescriptor->activate != nullptr)
- fDescriptor->activate(fHandle);
-
- fDescriptor->run(fHandle, 2);
-
- if (fDescriptor->deactivate != nullptr)
- fDescriptor->deactivate(fHandle);
-
- const uint32_t latency = (uint32_t)fParamBuffers[i];
-
- if (pData->latency != latency)
- {
- pData->latency = latency;
- pData->client->setLatency(latency);
- pData->recreateLatencyBuffers();
- }
-
- break;
- }
- }
-
- bufferSizeChanged(pData->engine->getBufferSize());
-
- if (pData->active)
- activate();
-
- carla_debug("LadspaPlugin::reload() - end");
- }
-
- // -------------------------------------------------------------------
- // Plugin processing
-
- void activate() override
- {
- CARLA_ASSERT(fDescriptor != nullptr);
- CARLA_ASSERT(fHandle != nullptr);
-
- if (fDescriptor->activate != nullptr)
- {
- fDescriptor->activate(fHandle);
-
- if (fHandle2 != nullptr)
- fDescriptor->activate(fHandle2);
- }
- }
-
- void deactivate() override
- {
- CARLA_ASSERT(fDescriptor != nullptr);
- CARLA_ASSERT(fHandle != nullptr);
-
- if (fDescriptor->deactivate != nullptr)
- {
- fDescriptor->deactivate(fHandle);
-
- if (fHandle2 != nullptr)
- fDescriptor->deactivate(fHandle2);
- }
- }
-
- void process(float** const inBuffer, float** const outBuffer, const uint32_t frames) override
- {
- uint32_t i, k;
-
- // --------------------------------------------------------------------------------------------------------
- // Check if active
-
- if (! pData->active)
- {
- // disable any output sound
- for (i=0; i < pData->audioOut.count; ++i)
- carla_zeroFloat(outBuffer[i], frames);
-
- return;
- }
-
- // --------------------------------------------------------------------------------------------------------
- // Check if needs reset
-
- if (pData->needsReset)
- {
- if (pData->latency > 0)
- {
- for (i=0; i < pData->audioIn.count; ++i)
- carla_zeroFloat(pData->latencyBuffers[i], pData->latency);
- }
-
- pData->needsReset = false;
- }
-
- // --------------------------------------------------------------------------------------------------------
- // Event Input and Processing
-
- if (pData->event.portIn != nullptr)
- {
- // ----------------------------------------------------------------------------------------------------
- // Event Input (System)
-
- bool sampleAccurate = (fOptions & PLUGIN_OPTION_FIXED_BUFFERS) == 0;
-
- uint32_t time, nEvents = pData->event.portIn->getEventCount();
- uint32_t timeOffset = 0;
-
- for (i=0; i < nEvents; ++i)
- {
- const EngineEvent& event(pData->event.portIn->getEvent(i));
-
- time = event.time;
-
- if (time >= frames)
- continue;
-
- CARLA_ASSERT_INT2(time >= timeOffset, time, timeOffset);
-
- if (time > timeOffset && sampleAccurate)
- {
- if (processSingle(inBuffer, outBuffer, time - timeOffset, timeOffset))
- timeOffset = time;
- }
-
- // Control change
- switch (event.type)
- {
- case kEngineEventTypeNull:
- break;
-
- case kEngineEventTypeControl:
- {
- const EngineControlEvent& ctrlEvent = event.ctrl;
-
- switch (ctrlEvent.type)
- {
- case kEngineControlEventTypeNull:
- break;
-
- case kEngineControlEventTypeParameter:
- {
- #ifndef BUILD_BRIDGE
- // Control backend stuff
- if (event.channel == pData->ctrlChannel)
- {
- float value;
-
- if (MIDI_IS_CONTROL_BREATH_CONTROLLER(ctrlEvent.param) && (fHints & PLUGIN_CAN_DRYWET) > 0)
- {
- value = ctrlEvent.value;
- setDryWet(value, false, false);
- pData->postponeRtEvent(kPluginPostRtEventParameterChange, PARAMETER_DRYWET, 0, value);
- }
-
- if (MIDI_IS_CONTROL_CHANNEL_VOLUME(ctrlEvent.param) && (fHints & PLUGIN_CAN_VOLUME) > 0)
- {
- value = ctrlEvent.value*127.0f/100.0f;
- setVolume(value, false, false);
- pData->postponeRtEvent(kPluginPostRtEventParameterChange, PARAMETER_VOLUME, 0, value);
- }
-
- if (MIDI_IS_CONTROL_BALANCE(ctrlEvent.param) && (fHints & PLUGIN_CAN_BALANCE) > 0)
- {
- float left, right;
- value = ctrlEvent.value/0.5f - 1.0f;
-
- if (value < 0.0f)
- {
- left = -1.0f;
- right = (value*2.0f)+1.0f;
- }
- else if (value > 0.0f)
- {
- left = (value*2.0f)-1.0f;
- right = 1.0f;
- }
- else
- {
- left = -1.0f;
- right = 1.0f;
- }
-
- setBalanceLeft(left, false, false);
- setBalanceRight(right, false, false);
- pData->postponeRtEvent(kPluginPostRtEventParameterChange, PARAMETER_BALANCE_LEFT, 0, left);
- pData->postponeRtEvent(kPluginPostRtEventParameterChange, PARAMETER_BALANCE_RIGHT, 0, right);
- }
- }
- #endif
-
- // Control plugin parameters
- for (k=0; k < pData->param.count; ++k)
- {
- if (pData->param.data[k].midiChannel != event.channel)
- continue;
- if (pData->param.data[k].midiCC != ctrlEvent.param)
- continue;
- if (pData->param.data[k].type != PARAMETER_INPUT)
- continue;
- if ((pData->param.data[k].hints & PARAMETER_IS_AUTOMABLE) == 0)
- continue;
-
- float value;
-
- if (pData->param.data[k].hints & PARAMETER_IS_BOOLEAN)
- {
- value = (ctrlEvent.value < 0.5f) ? pData->param.ranges[k].min : pData->param.ranges[k].max;
- }
- else
- {
- value = pData->param.ranges[k].getUnnormalizedValue(ctrlEvent.value);
-
- if (pData->param.data[k].hints & PARAMETER_IS_INTEGER)
- value = std::rint(value);
- }
-
- setParameterValue(k, value, false, false, false);
- pData->postponeRtEvent(kPluginPostRtEventParameterChange, static_cast<int32_t>(k), 0, value);
- }
-
- break;
- }
-
- case kEngineControlEventTypeMidiBank:
- case kEngineControlEventTypeMidiProgram:
- case kEngineControlEventTypeAllSoundOff:
- case kEngineControlEventTypeAllNotesOff:
- break;
- }
-
- break;
- }
-
- case kEngineEventTypeMidi:
- // ignored in LADSPA
- break;
- }
- }
-
- pData->postRtEvents.trySplice();
-
- if (frames > timeOffset)
- processSingle(inBuffer, outBuffer, frames - timeOffset, timeOffset);
-
- } // End of Event Input and Processing
-
- // --------------------------------------------------------------------------------------------------------
- // Plugin processing (no events)
-
- else
- {
- processSingle(inBuffer, outBuffer, frames, 0);
-
- } // End of Plugin processing (no events)
-
- CARLA_PROCESS_CONTINUE_CHECK;
-
- // --------------------------------------------------------------------------------------------------------
- // Control Output
-
- if (pData->event.portOut != nullptr)
- {
- uint8_t channel;
- uint16_t param;
- float value;
-
- for (k=0; k < pData->param.count; ++k)
- {
- if (pData->param.data[k].type != PARAMETER_OUTPUT)
- continue;
-
- pData->param.ranges[k].fixValue(fParamBuffers[k]);
-
- if (pData->param.data[k].midiCC > 0)
- {
- channel = pData->param.data[k].midiChannel;
- param = static_cast<uint16_t>(pData->param.data[k].midiCC);
- value = pData->param.ranges[k].getNormalizedValue(fParamBuffers[k]);
- pData->event.portOut->writeControlEvent(0, channel, kEngineControlEventTypeParameter, param, value);
- }
- }
-
- } // End of Control Output
- }
-
- bool processSingle(float** const inBuffer, float** const outBuffer, const uint32_t frames, const uint32_t timeOffset)
- {
- CARLA_ASSERT(frames > 0);
-
- if (frames == 0)
- return false;
-
- if (pData->audioIn.count > 0)
- {
- CARLA_ASSERT(inBuffer != nullptr);
- if (inBuffer == nullptr)
- return false;
- }
- if (pData->audioOut.count > 0)
- {
- CARLA_ASSERT(outBuffer != nullptr);
- if (outBuffer == nullptr)
- return false;
- }
-
- uint32_t i, k;
-
- // --------------------------------------------------------------------------------------------------------
- // Try lock, silence otherwise
-
- if (pData->engine->isOffline())
- {
- pData->singleMutex.lock();
- }
- else if (! pData->singleMutex.tryLock())
- {
- for (i=0; i < pData->audioOut.count; ++i)
- {
- for (k=0; k < frames; ++k)
- outBuffer[i][k+timeOffset] = 0.0f;
- }
-
- return false;
- }
-
- // --------------------------------------------------------------------------------------------------------
- // Reset audio buffers
-
- for (i=0; i < pData->audioIn.count; ++i)
- carla_copyFloat(fAudioInBuffers[i], inBuffer[i]+timeOffset, frames);
- for (i=0; i < pData->audioOut.count; ++i)
- carla_zeroFloat(fAudioOutBuffers[i], frames);
-
- // --------------------------------------------------------------------------------------------------------
- // Run plugin
-
- fDescriptor->run(fHandle, frames);
-
- if (fHandle2 != nullptr)
- fDescriptor->run(fHandle2, frames);
-
- #ifndef BUILD_BRIDGE
- // --------------------------------------------------------------------------------------------------------
- // Post-processing (dry/wet, volume and balance)
-
- {
- const bool doDryWet = (fHints & PLUGIN_CAN_DRYWET) != 0 && pData->postProc.dryWet != 1.0f;
- const bool doBalance = (fHints & PLUGIN_CAN_BALANCE) != 0 && (pData->postProc.balanceLeft != -1.0f || pData->postProc.balanceRight != 1.0f);
-
- bool isPair;
- float bufValue, oldBufLeft[doBalance ? frames : 1];
-
- for (i=0; i < pData->audioOut.count; ++i)
- {
- // Dry/Wet
- if (doDryWet)
- {
- for (k=0; k < frames; ++k)
- {
- // TODO
- //if (k < pData->latency && pData->latency < frames)
- // bufValue = (pData->audioIn.count == 1) ? pData->latencyBuffers[0][k] : pData->latencyBuffers[i][k];
- //else
- // bufValue = (pData->audioIn.count == 1) ? inBuffer[0][k-m_latency] : inBuffer[i][k-m_latency];
-
- bufValue = fAudioInBuffers[(pData->audioIn.count == 1) ? 0 : i][k];
- fAudioOutBuffers[i][k] = (fAudioOutBuffers[i][k] * pData->postProc.dryWet) + (bufValue * (1.0f - pData->postProc.dryWet));
- }
- }
-
- // Balance
- if (doBalance)
- {
- isPair = (i % 2 == 0);
-
- if (isPair)
- {
- CARLA_ASSERT(i+1 < pData->audioOut.count);
- carla_copyFloat(oldBufLeft, fAudioOutBuffers[i], frames);
- }
-
- float balRangeL = (pData->postProc.balanceLeft + 1.0f)/2.0f;
- float balRangeR = (pData->postProc.balanceRight + 1.0f)/2.0f;
-
- for (k=0; k < frames; ++k)
- {
- if (isPair)
- {
- // left
- fAudioOutBuffers[i][k] = oldBufLeft[k] * (1.0f - balRangeL);
- fAudioOutBuffers[i][k] += fAudioOutBuffers[i+1][k] * (1.0f - balRangeR);
- }
- else
- {
- // right
- fAudioOutBuffers[i][k] = fAudioOutBuffers[i][k] * balRangeR;
- fAudioOutBuffers[i][k] += oldBufLeft[k] * balRangeL;
- }
- }
- }
-
- // Volume (and buffer copy)
- {
- for (k=0; k < frames; ++k)
- outBuffer[i][k+timeOffset] = fAudioOutBuffers[i][k] * pData->postProc.volume;
- }
- }
-
- #if 0
- // Latency, save values for next callback, TODO
- if (pData->latency > 0 && pData->latency < frames)
- {
- for (i=0; i < pData->audioIn.count; ++i)
- carla_copyFloat(pData->latencyBuffers[i], inBuffer[i] + (frames - pData->latency), pData->latency);
- }
- #endif
- } // End of Post-processing
- #else
- for (i=0; i < pData->audioOut.count; ++i)
- {
- for (k=0; k < frames; ++k)
- outBuffer[i][k+timeOffset] = fAudioOutBuffers[i][k];
- }
- #endif
-
- // --------------------------------------------------------------------------------------------------------
-
- pData->singleMutex.unlock();
- return true;
- }
-
- void bufferSizeChanged(const uint32_t newBufferSize) override
- {
- CARLA_ASSERT_INT(newBufferSize > 0, newBufferSize);
- carla_debug("LadspaPlugin::bufferSizeChanged(%i) - start", newBufferSize);
-
- for (uint32_t i=0; i < pData->audioIn.count; ++i)
- {
- if (fAudioInBuffers[i] != nullptr)
- delete[] fAudioInBuffers[i];
- fAudioInBuffers[i] = new float[newBufferSize];
- }
-
- for (uint32_t i=0; i < pData->audioOut.count; ++i)
- {
- if (fAudioOutBuffers[i] != nullptr)
- delete[] fAudioOutBuffers[i];
- fAudioOutBuffers[i] = new float[newBufferSize];
- }
-
- if (fHandle2 == nullptr)
- {
- for (uint32_t i=0; i < pData->audioIn.count; ++i)
- {
- CARLA_ASSERT(fAudioInBuffers[i] != nullptr);
- fDescriptor->connect_port(fHandle, pData->audioIn.ports[i].rindex, fAudioInBuffers[i]);
- }
-
- for (uint32_t i=0; i < pData->audioOut.count; ++i)
- {
- CARLA_ASSERT(fAudioOutBuffers[i] != nullptr);
- fDescriptor->connect_port(fHandle, pData->audioOut.ports[i].rindex, fAudioOutBuffers[i]);
- }
- }
- else
- {
- if (pData->audioIn.count > 0)
- {
- CARLA_ASSERT(pData->audioIn.count == 2);
- CARLA_ASSERT(fAudioInBuffers[0] != nullptr);
- CARLA_ASSERT(fAudioInBuffers[1] != nullptr);
-
- fDescriptor->connect_port(fHandle, pData->audioIn.ports[0].rindex, fAudioInBuffers[0]);
- fDescriptor->connect_port(fHandle2, pData->audioIn.ports[1].rindex, fAudioInBuffers[1]);
- }
-
- if (pData->audioOut.count > 0)
- {
- CARLA_ASSERT(pData->audioOut.count == 2);
- CARLA_ASSERT(fAudioOutBuffers[0] != nullptr);
- CARLA_ASSERT(fAudioOutBuffers[1] != nullptr);
-
- fDescriptor->connect_port(fHandle, pData->audioOut.ports[0].rindex, fAudioOutBuffers[0]);
- fDescriptor->connect_port(fHandle2, pData->audioOut.ports[1].rindex, fAudioOutBuffers[1]);
- }
- }
-
- carla_debug("LadspaPlugin::bufferSizeChanged(%i) - end", newBufferSize);
- }
-
- void sampleRateChanged(const double newSampleRate) override
- {
- CARLA_ASSERT_INT(newSampleRate > 0.0, newSampleRate);
- carla_debug("LadspaPlugin::sampleRateChanged(%g) - start", newSampleRate);
-
- // TODO
- (void)newSampleRate;
-
- carla_debug("LadspaPlugin::sampleRateChanged(%g) - end", newSampleRate);
- }
-
- // -------------------------------------------------------------------
- // Plugin buffers
-
- void clearBuffers() override
- {
- carla_debug("LadspaPlugin::clearBuffers() - start");
-
- if (fAudioInBuffers != nullptr)
- {
- for (uint32_t i=0; i < pData->audioIn.count; ++i)
- {
- if (fAudioInBuffers[i] != nullptr)
- {
- delete[] fAudioInBuffers[i];
- fAudioInBuffers[i] = nullptr;
- }
- }
-
- delete[] fAudioInBuffers;
- fAudioInBuffers = nullptr;
- }
-
- if (fAudioOutBuffers != nullptr)
- {
- for (uint32_t i=0; i < pData->audioOut.count; ++i)
- {
- if (fAudioOutBuffers[i] != nullptr)
- {
- delete[] fAudioOutBuffers[i];
- fAudioOutBuffers[i] = nullptr;
- }
- }
-
- delete[] fAudioOutBuffers;
- fAudioOutBuffers = nullptr;
- }
-
- if (fParamBuffers != nullptr)
- {
- delete[] fParamBuffers;
- fParamBuffers = nullptr;
- }
-
- CarlaPlugin::clearBuffers();
-
- carla_debug("LadspaPlugin::clearBuffers() - end");
- }
-
- // -------------------------------------------------------------------
-
- const void* getExtraStuff() const noexcept override
- {
- return fRdfDescriptor;
- }
-
- bool init(const char* const filename, const char* const name, const char* const label, const LADSPA_RDF_Descriptor* const rdfDescriptor)
- {
- CARLA_ASSERT(pData->engine != nullptr);
- CARLA_ASSERT(pData->client == nullptr);
- CARLA_ASSERT(filename != nullptr);
- CARLA_ASSERT(label != nullptr);
-
- // ---------------------------------------------------------------
- // first checks
-
- if (pData->engine == nullptr)
- {
- return false;
- }
-
- if (pData->client != nullptr)
- {
- pData->engine->setLastError("Plugin client is already registered");
- return false;
- }
-
- if (filename == nullptr)
- {
- pData->engine->setLastError("null filename");
- return false;
- }
-
- if (label == nullptr)
- {
- pData->engine->setLastError("null label");
- return false;
- }
-
- // ---------------------------------------------------------------
- // open DLL
-
- if (! pData->libOpen(filename))
- {
- pData->engine->setLastError(pData->libError(filename));
- return false;
- }
-
- // ---------------------------------------------------------------
- // get DLL main entry
-
- const LADSPA_Descriptor_Function descFn = (LADSPA_Descriptor_Function)pData->libSymbol("ladspa_descriptor");
-
- if (descFn == nullptr)
- {
- pData->engine->setLastError("Could not find the LASDPA Descriptor in the plugin library");
- return false;
- }
-
- // ---------------------------------------------------------------
- // get descriptor that matches label
-
- unsigned long i = 0;
- while ((fDescriptor = descFn(i++)) != nullptr)
- {
- if (fDescriptor->Label != nullptr && std::strcmp(fDescriptor->Label, label) == 0)
- break;
- }
-
- if (fDescriptor == nullptr)
- {
- pData->engine->setLastError("Could not find the requested plugin label in the plugin library");
- return false;
- }
-
- // ---------------------------------------------------------------
- // get info
-
- if (is_ladspa_rdf_descriptor_valid(rdfDescriptor, fDescriptor))
- fRdfDescriptor = ladspa_rdf_dup(rdfDescriptor);
-
- if (name != nullptr)
- fName = pData->engine->getUniquePluginName(name);
- else if (fRdfDescriptor != nullptr && fRdfDescriptor->Title != nullptr)
- fName = pData->engine->getUniquePluginName(fRdfDescriptor->Title);
- else if (fDescriptor->Name != nullptr)
- fName = pData->engine->getUniquePluginName(fDescriptor->Name);
- else
- fName = pData->engine->getUniquePluginName(fDescriptor->Label);
-
- fFilename = filename;
-
- // ---------------------------------------------------------------
- // register client
-
- pData->client = pData->engine->addClient(this);
-
- if (pData->client == nullptr || ! pData->client->isOk())
- {
- pData->engine->setLastError("Failed to register plugin client");
- return false;
- }
-
- // ---------------------------------------------------------------
- // initialize plugin
-
- fHandle = fDescriptor->instantiate(fDescriptor, (unsigned long)pData->engine->getSampleRate());
-
- if (fHandle == nullptr)
- {
- pData->engine->setLastError("Plugin failed to initialize");
- return false;
- }
-
- // ---------------------------------------------------------------
- // load plugin settings
-
- {
- #ifdef __USE_GNU
- const bool isDssiVst = fFilename.contains("dssi-vst", true);
- #else
- const bool isDssiVst = fFilename.contains("dssi-vst");
- #endif
-
- // set default options
- fOptions = 0x0;
-
- if (isDssiVst)
- fOptions |= PLUGIN_OPTION_FIXED_BUFFERS;
-
- if (pData->engine->getOptions().forceStereo)
- fOptions |= PLUGIN_OPTION_FORCE_STEREO;
-
- // load settings
- pData->idStr = "LADSPA/";
- pData->idStr += std::strrchr(filename, OS_SEP)+1;
- pData->idStr += "/";
- pData->idStr += CarlaString(getUniqueId());
- pData->idStr += "/";
- pData->idStr += label;
- fOptions = pData->loadSettings(fOptions, getAvailableOptions());
-
- // ignore settings, we need this anyway
- if (isDssiVst)
- fOptions |= PLUGIN_OPTION_FIXED_BUFFERS;
- }
-
- return true;
- }
-
- private:
- LADSPA_Handle fHandle;
- LADSPA_Handle fHandle2;
- const LADSPA_Descriptor* fDescriptor;
- const LADSPA_RDF_Descriptor* fRdfDescriptor;
-
- float** fAudioInBuffers;
- float** fAudioOutBuffers;
- float* fParamBuffers;
-
- CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(LadspaPlugin)
- };
-
- CARLA_BACKEND_END_NAMESPACE
-
- #else // WANT_LADSPA
- # warning Building without LADSPA support
- #endif
-
- CARLA_BACKEND_START_NAMESPACE
-
- CarlaPlugin* CarlaPlugin::newLADSPA(const Initializer& init, const LADSPA_RDF_Descriptor* const rdfDescriptor)
- {
- carla_debug("CarlaPlugin::newLADSPA({%p, \"%s\", \"%s\", \"%s\"}, %p)", init.engine, init.filename, init.name, init.label, rdfDescriptor);
-
- #ifdef WANT_LADSPA
- LadspaPlugin* const plugin(new LadspaPlugin(init.engine, init.id));
-
- if (! plugin->init(init.filename, init.name, init.label, rdfDescriptor))
- {
- delete plugin;
- return nullptr;
- }
-
- plugin->reload();
-
- if (init.engine->getProccessMode() == PROCESS_MODE_CONTINUOUS_RACK && ! plugin->canRunInRack())
- {
- init.engine->setLastError("Carla's rack mode can only work with Mono or Stereo LADSPA plugins, sorry!");
- delete plugin;
- return nullptr;
- }
-
- return plugin;
- #else
- init.engine->setLastError("LADSPA support not available");
- return nullptr;
- #endif
- }
-
- CARLA_BACKEND_END_NAMESPACE
|