|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085 |
- /*
- * Carla DSSI Plugin
- * Copyright (C) 2011-2014 Filipe Coelho <falktx@falktx.com>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of
- * the License, or any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * For a full copy of the GNU General Public License see the doc/GPL.txt file.
- */
-
- #include "CarlaPluginInternal.hpp"
- #include "CarlaEngine.hpp"
-
- #ifdef WANT_DSSI
-
- #include "CarlaDssiUtils.hpp"
- #include "CarlaMathUtils.hpp"
-
- #include <QtCore/QByteArray>
-
- // -----------------------------------------------------
-
- CARLA_BACKEND_START_NAMESPACE
-
- #if 0
- }
- #endif
-
- // -----------------------------------------------------
-
- class DssiPlugin : public CarlaPlugin
- {
- public:
- DssiPlugin(CarlaEngine* const engine, const unsigned int id)
- : CarlaPlugin(engine, id),
- fHandle(nullptr),
- fHandle2(nullptr),
- fDescriptor(nullptr),
- fDssiDescriptor(nullptr),
- fUsesCustomData(false),
- fUiFilename(nullptr),
- fAudioInBuffers(nullptr),
- fAudioOutBuffers(nullptr),
- fParamBuffers(nullptr)
- {
- carla_debug("DssiPlugin::DssiPlugin(%p, %i)", engine, id);
-
- pData->osc.thread.setMode(CarlaPluginThread::PLUGIN_THREAD_DSSI_GUI);
- }
-
- ~DssiPlugin() override
- {
- carla_debug("DssiPlugin::~DssiPlugin()");
-
- // close UI
- if (pData->hints & PLUGIN_HAS_CUSTOM_UI)
- {
- showCustomUI(false);
-
- pData->osc.thread.stopThread(static_cast<int>(pData->engine->getOptions().uiBridgesTimeout * 2));
- }
-
- 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 (pData->name != nullptr && fDssiDescriptor != nullptr && fDssiDescriptor->run_synth == nullptr && fDssiDescriptor->run_multiple_synths != nullptr)
- removeUniqueMultiSynth(fDescriptor->Label);
-
- if (fDescriptor->cleanup != nullptr)
- {
- if (fHandle != nullptr)
- fDescriptor->cleanup(fHandle);
- if (fHandle2 != nullptr)
- fDescriptor->cleanup(fHandle2);
- }
-
- fHandle = nullptr;
- fHandle2 = nullptr;
- fDescriptor = nullptr;
- fDssiDescriptor = nullptr;
- }
-
- if (fUiFilename != nullptr)
- {
- delete[] fUiFilename;
- fUiFilename = nullptr;
- }
-
- clearBuffers();
- }
-
- // -------------------------------------------------------------------
- // Information (base)
-
- PluginType getType() const noexcept override
- {
- return PLUGIN_DSSI;
- }
-
- PluginCategory getCategory() const noexcept override
- {
- CARLA_SAFE_ASSERT_RETURN(fDssiDescriptor != nullptr, PLUGIN_CATEGORY_NONE);
-
- if (pData->audioIn.count == 0 && pData->audioOut.count > 0 && (fDssiDescriptor->run_synth != nullptr || fDssiDescriptor->run_multiple_synths != nullptr))
- return PLUGIN_CATEGORY_SYNTH;
-
- return CarlaPlugin::getCategory();
- }
-
- int64_t getUniqueId() const noexcept override
- {
- CARLA_SAFE_ASSERT_RETURN(fDescriptor != nullptr, 0);
-
- return static_cast<int64_t>(fDescriptor->UniqueID);
- }
-
- // -------------------------------------------------------------------
- // Information (count)
-
- // nothing
-
- // -------------------------------------------------------------------
- // Information (current data)
-
- int32_t getChunkData(void** const dataPtr) const noexcept override
- {
- CARLA_SAFE_ASSERT_RETURN(fUsesCustomData, 0);
- CARLA_SAFE_ASSERT_RETURN(pData->options & PLUGIN_OPTION_USE_CHUNKS, 0);
- CARLA_SAFE_ASSERT_RETURN(fDssiDescriptor != nullptr, 0);
- CARLA_SAFE_ASSERT_RETURN(fDssiDescriptor->get_custom_data != nullptr, 0);
- CARLA_SAFE_ASSERT_RETURN(fHandle != nullptr, 0);
- CARLA_SAFE_ASSERT_RETURN(fHandle2 == nullptr, 0);
- CARLA_SAFE_ASSERT_RETURN(dataPtr != nullptr, 0);
-
- int ret = 0;
- unsigned long dataSize = 0;
-
- try {
- ret = fDssiDescriptor->get_custom_data(fHandle, dataPtr, &dataSize);
- } catch(...) {}
-
- return (ret != 0) ? static_cast<int32_t>(dataSize) : 0;
- }
-
- // -------------------------------------------------------------------
- // Information (per-plugin data)
-
- unsigned int getOptionsAvailable() const noexcept override
- {
- #ifdef __USE_GNU
- const bool isAmSynth(strcasestr(pData->filename, "amsynth"));
- const bool isDssiVst(strcasestr(pData->filename, "dssi-vst"));
- #else
- const bool isAmSynth(std::strstr(pData->filename, "amsynth"));
- const bool isDssiVst(std::strstr(pData->filename, "dssi-vst"));
- #endif
-
- unsigned int options = 0x0;
-
- options |= PLUGIN_OPTION_MAP_PROGRAM_CHANGES;
-
- if (! (isAmSynth || isDssiVst))
- {
- options |= PLUGIN_OPTION_FIXED_BUFFERS;
-
- if (pData->engine->getProccessMode() != ENGINE_PROCESS_MODE_CONTINUOUS_RACK)
- {
- if (pData->options & 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;
- }
- }
-
- if (fUsesCustomData)
- options |= PLUGIN_OPTION_USE_CHUNKS;
-
- if (fDssiDescriptor->run_synth != nullptr || fDssiDescriptor->run_multiple_synths != nullptr)
- {
- options |= PLUGIN_OPTION_SEND_CONTROL_CHANGES;
- options |= PLUGIN_OPTION_SEND_CHANNEL_PRESSURE;
- options |= PLUGIN_OPTION_SEND_NOTE_AFTERTOUCH;
- options |= PLUGIN_OPTION_SEND_PITCHBEND;
- options |= PLUGIN_OPTION_SEND_ALL_SOUND_OFF;
- }
-
- return options;
- }
-
- float getParameterValue(const uint32_t parameterId) const noexcept override
- {
- CARLA_SAFE_ASSERT_RETURN(fParamBuffers != nullptr, 0.0f);
- CARLA_SAFE_ASSERT_RETURN(parameterId < pData->param.count, 0.0f);
-
- return fParamBuffers[parameterId];
- }
-
- void getLabel(char* const strBuf) const noexcept override
- {
- CARLA_SAFE_ASSERT_RETURN(fDescriptor != nullptr,);
-
- if (fDescriptor->Label != nullptr)
- std::strncpy(strBuf, fDescriptor->Label, STR_MAX);
- else
- CarlaPlugin::getLabel(strBuf);
- }
-
- void getMaker(char* const strBuf) const noexcept override
- {
- CARLA_SAFE_ASSERT_RETURN(fDescriptor != nullptr,);
-
- if (fDescriptor->Maker != nullptr)
- std::strncpy(strBuf, fDescriptor->Maker, STR_MAX);
- else
- CarlaPlugin::getMaker(strBuf);
- }
-
- void getCopyright(char* const strBuf) const noexcept override
- {
- CARLA_SAFE_ASSERT_RETURN(fDescriptor != nullptr,);
-
- if (fDescriptor->Copyright != nullptr)
- std::strncpy(strBuf, fDescriptor->Copyright, STR_MAX);
- else
- CarlaPlugin::getCopyright(strBuf);
- }
-
- void getRealName(char* const strBuf) const noexcept override
- {
- CARLA_SAFE_ASSERT_RETURN(fDescriptor != nullptr,);
-
- 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 noexcept override
- {
- CARLA_SAFE_ASSERT_RETURN(fDescriptor != nullptr,);
- CARLA_SAFE_ASSERT_RETURN(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);
- }
-
- // -------------------------------------------------------------------
- // 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) noexcept override
- {
- CARLA_SAFE_ASSERT_RETURN(fParamBuffers != nullptr,);
- CARLA_SAFE_ASSERT_RETURN(parameterId < pData->param.count,);
-
- const float fixedValue(pData->param.getFixedValue(parameterId, value));
- fParamBuffers[parameterId] = fixedValue;
-
- CarlaPlugin::setParameterValue(parameterId, fixedValue, sendGui, sendOsc, sendCallback);
- }
-
- void setCustomData(const char* const type, const char* const key, const char* const value, const bool sendGui) override
- {
- CARLA_SAFE_ASSERT_RETURN(fDssiDescriptor != nullptr,);
- CARLA_SAFE_ASSERT_RETURN(fHandle != nullptr,);
- CARLA_SAFE_ASSERT_RETURN(type != nullptr && type[0] != '\0',);
- CARLA_SAFE_ASSERT_RETURN(key != nullptr && key[0] != '\0',);
- CARLA_SAFE_ASSERT_RETURN(value != nullptr,);
- carla_debug("DssiPlugin::setCustomData(%s, %s, %s, %s)", type, key, value, bool2str(sendGui));
-
- if (std::strcmp(type, CUSTOM_DATA_TYPE_STRING) != 0)
- return carla_stderr2("DssiPlugin::setCustomData(\"%s\", \"%s\", \"%s\", %s) - type is not string", type, key, value, bool2str(sendGui));
-
- if (fDssiDescriptor->configure != nullptr)
- {
- try {
- fDssiDescriptor->configure(fHandle, key, value);
- } catch(...) {}
-
- if (fHandle2 != nullptr)
- {
- try {
- fDssiDescriptor->configure(fHandle2, key, value);
- } catch(...) {}
- }
- }
-
- if (sendGui && pData->osc.data.target != nullptr)
- osc_send_configure(pData->osc.data, key, value);
-
- if (std::strcmp(key, "reloadprograms") == 0 || std::strcmp(key, "load") == 0 || std::strncmp(key, "patches", 7) == 0)
- {
- const ScopedSingleProcessLocker spl(this, true);
- reloadPrograms(false);
- }
-
- CarlaPlugin::setCustomData(type, key, value, sendGui);
- }
-
- void setChunkData(const char* const stringData) override
- {
- CARLA_SAFE_ASSERT_RETURN(fUsesCustomData,);
- CARLA_SAFE_ASSERT_RETURN(pData->options & PLUGIN_OPTION_USE_CHUNKS,);
- CARLA_SAFE_ASSERT_RETURN(fDssiDescriptor != nullptr,);
- CARLA_SAFE_ASSERT_RETURN(fDssiDescriptor->set_custom_data != nullptr,);
- CARLA_SAFE_ASSERT_RETURN(fHandle != nullptr,);
- CARLA_SAFE_ASSERT_RETURN(fHandle2 == nullptr,);
- CARLA_SAFE_ASSERT_RETURN(stringData != nullptr,);
-
- QByteArray chunk(QByteArray::fromBase64(stringData));
-
- CARLA_SAFE_ASSERT_RETURN(chunk.size() > 0,);
-
- const ScopedSingleProcessLocker spl(this, true);
-
- try {
- fDssiDescriptor->set_custom_data(fHandle, chunk.data(), static_cast<ulong>(chunk.size()));
- } catch(...) {}
- }
-
- void setMidiProgram(const int32_t index, const bool sendGui, const bool sendOsc, const bool sendCallback) noexcept override
- {
- CARLA_SAFE_ASSERT_RETURN(fDssiDescriptor != nullptr,);
- CARLA_SAFE_ASSERT_RETURN(fDssiDescriptor->select_program != nullptr,);
- CARLA_SAFE_ASSERT_RETURN(fHandle != nullptr,);
- CARLA_SAFE_ASSERT_RETURN(index >= -1 && index < static_cast<int32_t>(pData->midiprog.count),);
-
- if (index >= 0)
- {
- const uint32_t bank(pData->midiprog.data[index].bank);
- const uint32_t program(pData->midiprog.data[index].program);
-
- const ScopedSingleProcessLocker spl(this, (sendGui || sendOsc || sendCallback));
-
- try {
- fDssiDescriptor->select_program(fHandle, bank, program);
- } catch(...) {}
-
- if (fHandle2 != nullptr)
- {
- try {
- fDssiDescriptor->select_program(fHandle2, bank, program);
- } catch(...) {}
- }
- }
-
- CarlaPlugin::setMidiProgram(index, sendGui, sendOsc, sendCallback);
- }
-
- // -------------------------------------------------------------------
- // Set ui stuff
-
- void showCustomUI(const bool yesNo) override
- {
- if (yesNo)
- {
- pData->osc.data.free();
- pData->osc.thread.startThread();
- }
- else
- {
- pData->transientTryCounter = 0;
-
- if (pData->osc.data.target != nullptr)
- {
- osc_send_hide(pData->osc.data);
- osc_send_quit(pData->osc.data);
- pData->osc.data.free();
- }
-
- pData->osc.thread.stopThread(static_cast<int>(pData->engine->getOptions().uiBridgesTimeout * 2));
- }
- }
-
- // -------------------------------------------------------------------
- // Plugin state
-
- void reload() override
- {
- CARLA_SAFE_ASSERT_RETURN(pData->engine != nullptr,);
- CARLA_SAFE_ASSERT_RETURN(fDescriptor != nullptr,);
- CARLA_SAFE_ASSERT_RETURN(fDssiDescriptor != nullptr,);
- CARLA_SAFE_ASSERT_RETURN(fHandle != nullptr,);
- carla_debug("DssiPlugin::reload() - start");
-
- const EngineProcessMode 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, mIns, params;
- aIns = aOuts = mIns = 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 ((pData->options & PLUGIN_OPTION_FORCE_STEREO) != 0 && (aIns == 1 || aOuts == 1))
- {
- if (fHandle2 == nullptr)
- {
- try {
- fHandle2 = fDescriptor->instantiate(fDescriptor, (unsigned long)sampleRate);
- } catch(...) {}
- }
-
- if (fHandle2 != nullptr)
- {
- if (aIns == 1)
- {
- aIns = 2;
- forcedStereoIn = true;
- }
-
- if (aOuts == 1)
- {
- aOuts = 2;
- forcedStereoOut = true;
- }
- }
- }
-
- if (fDssiDescriptor->run_synth != nullptr || fDssiDescriptor->run_multiple_synths != nullptr)
- {
- mIns = 1;
- needsCtrlIn = 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, true, false);
-
- fParamBuffers = new float[params];
- FLOAT_CLEAR(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];
-
- CARLA_ASSERT(fDescriptor->PortNames[i] != nullptr);
-
- if (LADSPA_IS_PORT_AUDIO(portType))
- {
- portName.clear();
-
- if (processMode == ENGINE_PROCESS_MODE_SINGLE_CLIENT)
- {
- portName = pData->name;
- portName += ":";
- }
-
- portName += fDescriptor->PortNames[i];
- portName.truncate(portNameSize);
-
- if (LADSPA_IS_PORT_INPUT(portType))
- {
- uint32_t 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))
- {
- uint32_t 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))
- {
- uint32_t j = iCtrl++;
- pData->param.data[j].hints = 0x0;
- pData->param.data[j].index = static_cast<int32_t>(j);
- pData->param.data[j].rindex = static_cast<int32_t>(i);
- pData->param.data[j].midiCC = -1;
- pData->param.data[j].midiChannel = 0;
- pData->param.special[j] = PARAMETER_SPECIAL_NULL;
-
- 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;
-
- 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
- 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;
-
- // MIDI CC value
- if (fDssiDescriptor->get_midi_controller_for_port != nullptr)
- {
- int controller = fDssiDescriptor->get_midi_controller_for_port(fHandle, i);
- if (DSSI_CONTROLLER_IS_SET(controller) && DSSI_IS_CC(controller))
- {
- int16_t cc = DSSI_CC_NUMBER(controller);
- if (! MIDI_IS_CONTROL_BANK_SELECT(cc))
- pData->param.data[j].midiCC = cc;
- }
- }
- }
- else if (LADSPA_IS_PORT_OUTPUT(portType))
- {
- pData->param.data[j].type = PARAMETER_OUTPUT;
-
- 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.special[j] = PARAMETER_SPECIAL_LATENCY;
- }
- else
- {
- 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;
-
- 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 == ENGINE_PROCESS_MODE_SINGLE_CLIENT)
- {
- portName = pData->name;
- portName += ":";
- }
-
- portName += "events-in";
- portName.truncate(portNameSize);
-
- pData->event.portIn = (CarlaEngineEventPort*)pData->client->addPort(kEnginePortTypeEvent, portName, true);
- }
-
- if (needsCtrlOut)
- {
- portName.clear();
-
- if (processMode == ENGINE_PROCESS_MODE_SINGLE_CLIENT)
- {
- portName = pData->name;
- portName += ":";
- }
-
- portName += "events-out";
- portName.truncate(portNameSize);
-
- pData->event.portOut = (CarlaEngineEventPort*)pData->client->addPort(kEnginePortTypeEvent, portName, false);
- }
-
- if (forcedStereoIn || forcedStereoOut)
- pData->options |= PLUGIN_OPTION_FORCE_STEREO;
- else
- pData->options &= ~PLUGIN_OPTION_FORCE_STEREO;
-
- // plugin hints
- pData->hints = 0x0;
-
- if (LADSPA_IS_HARD_RT_CAPABLE(fDescriptor->Properties))
- pData->hints |= PLUGIN_IS_RTSAFE;
-
- if (fUiFilename != nullptr)
- pData->hints |= PLUGIN_HAS_CUSTOM_UI;
-
- if (aOuts > 0 && (aIns == aOuts || aIns == 1))
- pData->hints |= PLUGIN_CAN_DRYWET;
-
- if (aOuts > 0)
- pData->hints |= PLUGIN_CAN_VOLUME;
-
- if (aOuts >= 2 && aOuts % 2 == 0)
- pData->hints |= PLUGIN_CAN_BALANCE;
-
- // extra plugin hints
- pData->extraHints = 0x0;
-
- if (mIns > 0)
- pData->extraHints |= PLUGIN_EXTRA_HINT_HAS_MIDI_IN;
-
- if (aIns <= 2 && aOuts <= 2 && (aIns == aOuts || aIns == 0 || aOuts == 0))
- pData->extraHints |= PLUGIN_EXTRA_HINT_CAN_RUN_RACK;
-
- // check latency
- if (pData->hints & PLUGIN_CAN_DRYWET)
- {
- for (uint32_t i=0; i < pData->param.count; ++i)
- {
- if (pData->param.special[i] != PARAMETER_SPECIAL_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 (uint32_t 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 (uint32_t 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());
- reloadPrograms(true);
-
- if (pData->active)
- activate();
-
- carla_debug("DssiPlugin::reload() - end");
- }
-
- void reloadPrograms(const bool doInit) override
- {
- carla_debug("DssiPlugin::reloadPrograms(%s)", bool2str(doInit));
- const uint32_t oldCount = pData->midiprog.count;
- const int32_t current = pData->midiprog.current;
-
- // Delete old programs
- pData->midiprog.clear();
-
- // Query new programs
- uint32_t newCount = 0;
- if (fDssiDescriptor->get_program != nullptr && fDssiDescriptor->select_program != nullptr)
- {
- for (; fDssiDescriptor->get_program(fHandle, newCount) != nullptr;)
- ++newCount;
- }
-
- if (newCount > 0)
- {
- pData->midiprog.createNew(newCount);
-
- // Update data
- for (uint32_t i=0; i < newCount; ++i)
- {
- const DSSI_Program_Descriptor* const pdesc(fDssiDescriptor->get_program(fHandle, i));
- CARLA_SAFE_ASSERT_CONTINUE(pdesc != nullptr);
- CARLA_SAFE_ASSERT(pdesc->Name != nullptr);
-
- pData->midiprog.data[i].bank = static_cast<uint32_t>(pdesc->Bank);
- pData->midiprog.data[i].program = static_cast<uint32_t>(pdesc->Program);
- pData->midiprog.data[i].name = carla_strdup(pdesc->Name);
- }
- }
-
- #ifndef BUILD_BRIDGE
- // Update OSC Names
- if (pData->engine->isOscControlRegistered())
- {
- pData->engine->oscSend_control_set_midi_program_count(pData->id, newCount);
-
- for (uint32_t i=0; i < newCount; ++i)
- pData->engine->oscSend_control_set_midi_program_data(pData->id, i, pData->midiprog.data[i].bank, pData->midiprog.data[i].program, pData->midiprog.data[i].name);
- }
- #endif
-
- if (doInit)
- {
- if (newCount > 0)
- setMidiProgram(0, false, false, false);
- }
- else
- {
- // Check if current program is invalid
- bool programChanged = false;
-
- if (newCount == oldCount+1)
- {
- // one midi program added, probably created by user
- pData->midiprog.current = static_cast<int32_t>(oldCount);
- programChanged = true;
- }
- else if (current < 0 && newCount > 0)
- {
- // programs exist now, but not before
- pData->midiprog.current = 0;
- programChanged = true;
- }
- else if (current >= 0 && newCount == 0)
- {
- // programs existed before, but not anymore
- pData->midiprog.current = -1;
- programChanged = true;
- }
- else if (current >= static_cast<int32_t>(newCount))
- {
- // current midi program > count
- pData->midiprog.current = 0;
- programChanged = true;
- }
- else
- {
- // no change
- pData->midiprog.current = current;
- }
-
- if (programChanged)
- setMidiProgram(pData->midiprog.current, true, true, true);
-
- pData->engine->callback(ENGINE_CALLBACK_RELOAD_PROGRAMS, pData->id, 0, 0, 0.0f, nullptr);
- }
- }
-
- // -------------------------------------------------------------------
- // Plugin processing
-
- void activate() noexcept override
- {
- CARLA_SAFE_ASSERT_RETURN(fDescriptor != nullptr,);
- CARLA_SAFE_ASSERT_RETURN(fHandle != nullptr,);
-
- if (fDescriptor->activate != nullptr)
- {
- try {
- fDescriptor->activate(fHandle);
- } catch(...) {}
-
- if (fHandle2 != nullptr)
- {
- try {
- fDescriptor->activate(fHandle2);
- } catch(...) {}
- }
- }
- }
-
- void deactivate() noexcept override
- {
- CARLA_SAFE_ASSERT_RETURN(fDescriptor != nullptr,);
- CARLA_SAFE_ASSERT_RETURN(fHandle != nullptr,);
-
- if (fDescriptor->deactivate != nullptr)
- {
- try {
- fDescriptor->deactivate(fHandle);
- } catch(...) {}
-
- if (fHandle2 != nullptr)
- {
- try {
- fDescriptor->deactivate(fHandle2);
- } catch(...) {}
- }
- }
- }
-
- void process(float** const inBuffer, float** const outBuffer, const uint32_t frames) override
- {
- // --------------------------------------------------------------------------------------------------------
- // Check if active
-
- if (! pData->active)
- {
- // disable any output sound
- for (uint32_t i=0; i < pData->audioOut.count; ++i)
- FLOAT_CLEAR(outBuffer[i], frames);
- return;
- }
-
- unsigned long midiEventCount = 0;
-
- // --------------------------------------------------------------------------------------------------------
- // Check if needs reset
-
- if (pData->needsReset)
- {
- if (pData->options & PLUGIN_OPTION_SEND_ALL_SOUND_OFF)
- {
- midiEventCount = MAX_MIDI_CHANNELS*2;
- carla_zeroStruct<snd_seq_event_t>(fMidiEvents, midiEventCount);
-
- for (unsigned char i=0, k=MAX_MIDI_CHANNELS; i < MAX_MIDI_CHANNELS; ++i)
- {
- fMidiEvents[i].type = SND_SEQ_EVENT_CONTROLLER;
- fMidiEvents[i].data.control.channel = i;
- fMidiEvents[i].data.control.param = MIDI_CONTROL_ALL_NOTES_OFF;
-
- fMidiEvents[k+i].type = SND_SEQ_EVENT_CONTROLLER;
- fMidiEvents[k+i].data.control.channel = i;
- fMidiEvents[k+i].data.control.param = MIDI_CONTROL_ALL_SOUND_OFF;
- }
- }
- else if (pData->ctrlChannel >= 0 && pData->ctrlChannel < MAX_MIDI_CHANNELS)
- {
- midiEventCount = MAX_MIDI_NOTE;
- carla_zeroStruct<snd_seq_event_t>(fMidiEvents, midiEventCount);
-
- for (unsigned char i=0; i < MAX_MIDI_NOTE; ++i)
- {
- fMidiEvents[i].type = SND_SEQ_EVENT_NOTEOFF;
- fMidiEvents[i].data.note.channel = static_cast<uchar>(pData->ctrlChannel);
- fMidiEvents[i].data.note.note = i;
- }
- }
-
- if (pData->latency > 0)
- {
- for (uint32_t i=0; i < pData->audioIn.count; ++i)
- FLOAT_CLEAR(pData->latencyBuffers[i], pData->latency);
- }
-
- pData->needsReset = false;
- }
-
- // --------------------------------------------------------------------------------------------------------
- // Event Input and Processing
-
- if (pData->event.portIn != nullptr)
- {
- // ----------------------------------------------------------------------------------------------------
- // MIDI Input (External)
-
- if (pData->extNotes.mutex.tryLock())
- {
- for (; midiEventCount < kPluginMaxMidiEvents && ! pData->extNotes.data.isEmpty();)
- {
- const ExternalMidiNote& note(pData->extNotes.data.getFirst(true));
-
- CARLA_SAFE_ASSERT_CONTINUE(note.channel >= 0 && note.channel < MAX_MIDI_CHANNELS);
-
- snd_seq_event_t& midiEvent(fMidiEvents[midiEventCount++]);
- carla_zeroStruct<snd_seq_event_t>(midiEvent);
-
- midiEvent.type = (note.velo > 0) ? SND_SEQ_EVENT_NOTEON : SND_SEQ_EVENT_NOTEOFF;
- midiEvent.data.note.channel = static_cast<uchar>(note.channel);
- midiEvent.data.note.note = note.note;
- midiEvent.data.note.velocity = note.velo;
- }
-
- pData->extNotes.mutex.unlock();
-
- } // End of MIDI Input (External)
-
- // ----------------------------------------------------------------------------------------------------
- // Event Input (System)
-
- bool allNotesOffSent = false;
- bool isSampleAccurate = (pData->options & PLUGIN_OPTION_FIXED_BUFFERS) == 0;
-
- uint32_t numEvents = pData->event.portIn->getEventCount();
- uint32_t startTime = 0;
- uint32_t timeOffset = 0;
- uint32_t nextBankId;
-
- if (pData->midiprog.current >= 0 && pData->midiprog.count > 0)
- nextBankId = pData->midiprog.data[pData->midiprog.current].bank;
- else
- nextBankId = 0;
-
- for (uint32_t i=0; i < numEvents; ++i)
- {
- const EngineEvent& event(pData->event.portIn->getEvent(i));
-
- if (event.time >= frames)
- continue;
-
- CARLA_ASSERT_INT2(event.time >= timeOffset, event.time, timeOffset);
-
- if (isSampleAccurate && event.time > timeOffset)
- {
- if (processSingle(inBuffer, outBuffer, event.time - timeOffset, timeOffset, midiEventCount))
- {
- startTime = 0;
- timeOffset = event.time;
- midiEventCount = 0;
-
- if (pData->midiprog.current >= 0 && pData->midiprog.count > 0)
- nextBankId = pData->midiprog.data[pData->midiprog.current].bank;
- else
- nextBankId = 0;
- }
- else
- startTime += timeOffset;
- }
-
- 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) && (pData->hints & PLUGIN_CAN_DRYWET) != 0)
- {
- value = ctrlEvent.value;
- setDryWet(value, false, false);
- pData->postponeRtEvent(kPluginPostRtEventParameterChange, PARAMETER_DRYWET, 0, value);
- break;
- }
-
- if (MIDI_IS_CONTROL_CHANNEL_VOLUME(ctrlEvent.param) && (pData->hints & PLUGIN_CAN_VOLUME) != 0)
- {
- value = ctrlEvent.value*127.0f/100.0f;
- setVolume(value, false, false);
- pData->postponeRtEvent(kPluginPostRtEventParameterChange, PARAMETER_VOLUME, 0, value);
- break;
- }
-
- if (MIDI_IS_CONTROL_BALANCE(ctrlEvent.param) && (pData->hints & 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);
- break;
- }
- }
- #endif
-
- // Control plugin parameters
- uint32_t k;
- 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;
- }
-
- // check if event is already handled
- if (k != pData->param.count)
- break;
-
- if ((pData->options & PLUGIN_OPTION_SEND_CONTROL_CHANGES) != 0 && ctrlEvent.param <= 0x5F)
- {
- if (midiEventCount >= kPluginMaxMidiEvents)
- continue;
-
- snd_seq_event_t& midiEvent(fMidiEvents[midiEventCount++]);
- carla_zeroStruct<snd_seq_event_t>(midiEvent);
-
- midiEvent.time.tick = isSampleAccurate ? startTime : event.time;
-
- midiEvent.type = SND_SEQ_EVENT_CONTROLLER;
- midiEvent.data.control.channel = event.channel;
- midiEvent.data.control.param = ctrlEvent.param;
- midiEvent.data.control.value = int8_t(ctrlEvent.value*127.0f);
- }
- break;
- } // case kEngineControlEventTypeParameter
-
- case kEngineControlEventTypeMidiBank:
- if (event.channel == pData->ctrlChannel && (pData->options & PLUGIN_OPTION_MAP_PROGRAM_CHANGES) != 0)
- nextBankId = ctrlEvent.param;
- break;
-
- case kEngineControlEventTypeMidiProgram:
- if (event.channel == pData->ctrlChannel && (pData->options & PLUGIN_OPTION_MAP_PROGRAM_CHANGES) != 0)
- {
- const uint32_t nextProgramId = ctrlEvent.param;
-
- for (uint32_t k=0; k < pData->midiprog.count; ++k)
- {
- if (pData->midiprog.data[k].bank == nextBankId && pData->midiprog.data[k].program == nextProgramId)
- {
- const int32_t index(static_cast<int32_t>(k));
- setMidiProgram(index, false, false, false);
- pData->postponeRtEvent(kPluginPostRtEventMidiProgramChange, index, 0, 0.0f);
- break;
- }
- }
- }
- break;
-
- case kEngineControlEventTypeAllSoundOff:
- if (pData->options & PLUGIN_OPTION_SEND_ALL_SOUND_OFF)
- {
- if (midiEventCount >= kPluginMaxMidiEvents)
- continue;
-
- snd_seq_event_t& midiEvent(fMidiEvents[midiEventCount++]);
- carla_zeroStruct<snd_seq_event_t>(midiEvent);
-
- midiEvent.time.tick = isSampleAccurate ? startTime : event.time;
-
- midiEvent.type = SND_SEQ_EVENT_CONTROLLER;
- midiEvent.data.control.channel = event.channel;
- midiEvent.data.control.param = MIDI_CONTROL_ALL_SOUND_OFF;
- }
- break;
-
- case kEngineControlEventTypeAllNotesOff:
- if (pData->options & PLUGIN_OPTION_SEND_ALL_SOUND_OFF)
- {
- if (event.channel == pData->ctrlChannel && ! allNotesOffSent)
- {
- allNotesOffSent = true;
- sendMidiAllNotesOffToCallback();
- }
-
- if (midiEventCount >= kPluginMaxMidiEvents)
- continue;
-
- snd_seq_event_t& midiEvent(fMidiEvents[midiEventCount++]);
- carla_zeroStruct<snd_seq_event_t>(midiEvent);
-
- midiEvent.time.tick = isSampleAccurate ? startTime : event.time;
-
- midiEvent.type = SND_SEQ_EVENT_CONTROLLER;
- midiEvent.data.control.channel = event.channel;
- midiEvent.data.control.param = MIDI_CONTROL_ALL_NOTES_OFF;
-
- midiEventCount += 1;
- }
- break;
- } // switch (ctrlEvent.type)
- break;
- } // case kEngineEventTypeControl
-
- case kEngineEventTypeMidi: {
- if (midiEventCount >= kPluginMaxMidiEvents)
- continue;
-
- const EngineMidiEvent& engineEvent(event.midi);
-
- uint8_t status = uint8_t(MIDI_GET_STATUS_FROM_DATA(engineEvent.data));
- uint8_t channel = event.channel;
-
- // Fix bad note-off (per DSSI spec)
- if (MIDI_IS_STATUS_NOTE_ON(status) && engineEvent.data[2] == 0)
- status = MIDI_STATUS_NOTE_OFF;
-
- snd_seq_event_t& midiEvent(fMidiEvents[midiEventCount]);
- carla_zeroStruct<snd_seq_event_t>(midiEvent);
-
- midiEvent.time.tick = isSampleAccurate ? startTime : event.time;
-
- switch (status)
- {
- case MIDI_STATUS_NOTE_OFF: {
- const uint8_t note = engineEvent.data[1];
-
- midiEvent.type = SND_SEQ_EVENT_NOTEOFF;
- midiEvent.data.note.channel = channel;
- midiEvent.data.note.note = note;
-
- pData->postponeRtEvent(kPluginPostRtEventNoteOff, channel, note, 0.0f);
- break;
- }
-
- case MIDI_STATUS_NOTE_ON: {
- const uint8_t note = engineEvent.data[1];
- const uint8_t velo = engineEvent.data[2];
-
- midiEvent.type = SND_SEQ_EVENT_NOTEON;
- midiEvent.data.note.channel = channel;
- midiEvent.data.note.note = note;
- midiEvent.data.note.velocity = velo;
-
- pData->postponeRtEvent(kPluginPostRtEventNoteOn, channel, note, velo);
- break;
- }
-
- case MIDI_STATUS_POLYPHONIC_AFTERTOUCH:
- if (pData->options & PLUGIN_OPTION_SEND_NOTE_AFTERTOUCH)
- {
- const uint8_t note = engineEvent.data[1];
- const uint8_t pressure = engineEvent.data[2];
-
- midiEvent.type = SND_SEQ_EVENT_KEYPRESS;
- midiEvent.data.note.channel = channel;
- midiEvent.data.note.note = note;
- midiEvent.data.note.velocity = pressure;
- }
- break;
-
- case MIDI_STATUS_CONTROL_CHANGE:
- if (pData->options & PLUGIN_OPTION_SEND_CONTROL_CHANGES)
- {
- const uint8_t control = engineEvent.data[1];
- const uint8_t value = engineEvent.data[2];
-
- midiEvent.type = SND_SEQ_EVENT_CONTROLLER;
- midiEvent.data.control.channel = channel;
- midiEvent.data.control.param = control;
- midiEvent.data.control.value = value;
- }
- break;
-
- case MIDI_STATUS_CHANNEL_PRESSURE:
- if (pData->options & PLUGIN_OPTION_SEND_CHANNEL_PRESSURE)
- {
- const uint8_t pressure = engineEvent.data[1];
-
- midiEvent.type = SND_SEQ_EVENT_CHANPRESS;
- midiEvent.data.control.channel = channel;
- midiEvent.data.control.value = pressure;
- }
- break;
-
- case MIDI_STATUS_PITCH_WHEEL_CONTROL:
- if (pData->options & PLUGIN_OPTION_SEND_PITCHBEND)
- {
- const uint8_t lsb = engineEvent.data[1];
- const uint8_t msb = engineEvent.data[2];
-
- midiEvent.type = SND_SEQ_EVENT_PITCHBEND;
- midiEvent.data.control.channel = channel;
- midiEvent.data.control.value = ((msb << 7) | lsb) - 8192;
- }
- break;
-
- default:
- continue;
- break;
- } // switch (status)
-
- midiEventCount += 1;
- break;
- } // case kEngineEventTypeMidi
- } // switch (event.type)
- }
-
- pData->postRtEvents.trySplice();
-
- if (frames > timeOffset)
- processSingle(inBuffer, outBuffer, frames - timeOffset, timeOffset, midiEventCount);
-
- } // End of Event Input and Processing
-
- // --------------------------------------------------------------------------------------------------------
- // Plugin processing (no events)
-
- else
- {
- processSingle(inBuffer, outBuffer, frames, 0, midiEventCount);
-
- } // 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 (uint32_t 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, const unsigned long midiEventCount)
- {
- CARLA_SAFE_ASSERT_RETURN(frames > 0, false);
-
- if (pData->audioIn.count > 0)
- {
- CARLA_SAFE_ASSERT_RETURN(inBuffer != nullptr, false);
- }
- if (pData->audioOut.count > 0)
- {
- CARLA_SAFE_ASSERT_RETURN(outBuffer != nullptr, false);
- }
-
- // --------------------------------------------------------------------------------------------------------
- // Try lock, silence otherwise
-
- if (pData->engine->isOffline())
- {
- pData->singleMutex.lock();
- }
- else if (! pData->singleMutex.tryLock())
- {
- for (uint32_t i=0; i < pData->audioOut.count; ++i)
- {
- for (uint32_t k=0; k < frames; ++k)
- outBuffer[i][k+timeOffset] = 0.0f;
- }
-
- return false;
- }
-
- // --------------------------------------------------------------------------------------------------------
- // Reset audio buffers
-
- for (uint32_t i=0; i < pData->audioIn.count; ++i)
- FLOAT_COPY(fAudioInBuffers[i], inBuffer[i]+timeOffset, frames);
-
- for (uint32_t i=0; i < pData->audioOut.count; ++i)
- FLOAT_CLEAR(fAudioOutBuffers[i], frames);
-
- // --------------------------------------------------------------------------------------------------------
- // Run plugin
-
- if (fDssiDescriptor->run_synth != nullptr)
- {
- fDssiDescriptor->run_synth(fHandle, frames, fMidiEvents, midiEventCount);
-
- if (fHandle2 != nullptr)
- fDssiDescriptor->run_synth(fHandle2, frames, fMidiEvents, midiEventCount);
- }
- else if (fDssiDescriptor->run_multiple_synths != nullptr)
- {
- unsigned long instances = (fHandle2 != nullptr) ? 2 : 1;
- LADSPA_Handle handlePtr[2] = { fHandle, fHandle2 };
- snd_seq_event_t* midiEventsPtr[2] = { fMidiEvents, fMidiEvents };
- unsigned long midiEventCountPtr[2] = { midiEventCount, midiEventCount };
- fDssiDescriptor->run_multiple_synths(instances, handlePtr, frames, midiEventsPtr, midiEventCountPtr);
- }
- else
- {
- fDescriptor->run(fHandle, frames);
-
- if (fHandle2 != nullptr)
- fDescriptor->run(fHandle2, frames);
- }
-
- #ifndef BUILD_BRIDGE
- // --------------------------------------------------------------------------------------------------------
- // Post-processing (dry/wet, volume and balance)
-
- {
- const bool doDryWet = (pData->hints & PLUGIN_CAN_DRYWET) != 0 && pData->postProc.dryWet != 1.0f;
- const bool doBalance = (pData->hints & PLUGIN_CAN_BALANCE) != 0 && (pData->postProc.balanceLeft != -1.0f || pData->postProc.balanceRight != 1.0f);
-
- bool isPair;
- float bufValue, oldBufLeft[doBalance ? frames : 1];
-
- for (uint32_t i=0; i < pData->audioOut.count; ++i)
- {
- // Dry/Wet
- if (doDryWet)
- {
- for (uint32_t 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);
- FLOAT_COPY(oldBufLeft, fAudioOutBuffers[i], frames);
- }
-
- float balRangeL = (pData->postProc.balanceLeft + 1.0f)/2.0f;
- float balRangeR = (pData->postProc.balanceRight + 1.0f)/2.0f;
-
- for (uint32_t 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 (uint32_t 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)
- FLOAT_COPY(pData->latencyBuffers[i], inBuffer[i] + (frames - pData->latency), pData->latency);
- }
- #endif
- } // End of Post-processing
-
- #else // BUILD_BRIDGE
- for (uint32_t i=0; i < pData->audioOut.count; ++i)
- {
- for (uint32_t 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("DssiPlugin::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("DssiPlugin::bufferSizeChanged(%i) - end", newBufferSize);
- }
-
- void sampleRateChanged(const double newSampleRate) override
- {
- CARLA_ASSERT_INT(newSampleRate > 0.0, newSampleRate);
- carla_debug("DssiPlugin::sampleRateChanged(%g) - start", newSampleRate);
-
- // TODO
- (void)newSampleRate;
-
- carla_debug("DssiPlugin::sampleRateChanged(%g) - end", newSampleRate);
- }
-
- // -------------------------------------------------------------------
- // Plugin buffers
-
- void clearBuffers() override
- {
- carla_debug("DssiPlugin::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("DssiPlugin::clearBuffers() - end");
- }
-
- // -------------------------------------------------------------------
- // Post-poned UI Stuff
-
- void uiParameterChange(const uint32_t index, const float value) noexcept override
- {
- CARLA_SAFE_ASSERT_RETURN(index < pData->param.count,);
-
- if (pData->osc.data.target == nullptr)
- return;
-
- osc_send_control(pData->osc.data, pData->param.data[index].rindex, value);
- }
-
- void uiMidiProgramChange(const uint32_t index) noexcept override
- {
- CARLA_SAFE_ASSERT_RETURN(index < pData->midiprog.count,);
-
- if (pData->osc.data.target == nullptr)
- return;
-
- osc_send_program(pData->osc.data, pData->midiprog.data[index].bank, pData->midiprog.data[index].program);
- }
-
- void uiNoteOn(const uint8_t channel, const uint8_t note, const uint8_t velo) noexcept override
- {
- CARLA_SAFE_ASSERT_RETURN(channel < MAX_MIDI_CHANNELS,);
- CARLA_SAFE_ASSERT_RETURN(note < MAX_MIDI_NOTE,);
- CARLA_SAFE_ASSERT_RETURN(velo > 0 && velo < MAX_MIDI_VALUE,);
-
- if (pData->osc.data.target == nullptr)
- return;
-
- #if 0
- uint8_t midiData[4];
- midiData[0] = 0;
- midiData[1] = static_cast<uint8_t>(MIDI_STATUS_NOTE_ON + channel);
- midiData[2] = note;
- midiData[3] = velo;
-
- osc_send_midi(pData->osc.data, midiData);
- #endif
- }
-
- void uiNoteOff(const uint8_t channel, const uint8_t note) noexcept override
- {
- CARLA_SAFE_ASSERT_RETURN(channel < MAX_MIDI_CHANNELS,);
- CARLA_SAFE_ASSERT_RETURN(note < MAX_MIDI_NOTE,);
-
- if (pData->osc.data.target == nullptr)
- return;
-
- #if 0
- uint8_t midiData[4];
- midiData[0] = 0;
- midiData[1] = static_cast<uint8_t>(MIDI_STATUS_NOTE_OFF + channel);
- midiData[2] = note;
- midiData[3] = 0;
-
- osc_send_midi(pData->osc.data, midiData);
- #endif
- }
-
- // -------------------------------------------------------------------
-
- const void* getExtraStuff() const noexcept override
- {
- return fUiFilename;
- }
-
- bool init(const char* const filename, const char* const name, const char* const label)
- {
- CARLA_SAFE_ASSERT_RETURN(pData->engine != nullptr, false);
-
- // ---------------------------------------------------------------
- // first checks
-
- if (pData->client != nullptr)
- {
- pData->engine->setLastError("Plugin client is already registered");
- return false;
- }
-
- if (filename == nullptr || filename[0] == '\0')
- {
- pData->engine->setLastError("null filename");
- return false;
- }
-
- if (label == nullptr || label[0] == '\0')
- {
- 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 DSSI_Descriptor_Function descFn = (DSSI_Descriptor_Function)pData->libSymbol("dssi_descriptor");
-
- if (descFn == nullptr)
- {
- pData->engine->setLastError("Could not find the DSSI Descriptor in the plugin library");
- return false;
- }
-
- // ---------------------------------------------------------------
- // get descriptor that matches label
-
- unsigned long i = 0;
- while ((fDssiDescriptor = descFn(i++)) != nullptr)
- {
- fDescriptor = fDssiDescriptor->LADSPA_Plugin;
- if (fDescriptor != nullptr && fDescriptor->Label != nullptr && std::strcmp(fDescriptor->Label, label) == 0)
- break;
- }
-
- if (fDescriptor == nullptr || fDssiDescriptor == nullptr)
- {
- pData->engine->setLastError("Could not find the requested plugin label in the plugin library");
- return false;
- }
-
- // ---------------------------------------------------------------
- // check if uses global instance
-
- if (fDssiDescriptor->run_synth == nullptr && fDssiDescriptor->run_multiple_synths != nullptr)
- {
- if (! addUniqueMultiSynth(fDescriptor->Label))
- {
- pData->engine->setLastError("This plugin uses a global instance and can't be used more than once safely");
- return false;
- }
- }
-
- // ---------------------------------------------------------------
- // get info
-
- if (name != nullptr && name[0] != '\0')
- pData->name = pData->engine->getUniquePluginName(name);
- else if (fDescriptor->Name != nullptr && fDescriptor->Name[0] != '\0')
- pData->name = pData->engine->getUniquePluginName(fDescriptor->Name);
- else
- pData->name = pData->engine->getUniquePluginName(fDescriptor->Label);
-
- pData->filename = carla_strdup(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
-
- try {
- fHandle = fDescriptor->instantiate(fDescriptor, (unsigned long)pData->engine->getSampleRate());
- } catch(...) {}
-
- if (fHandle == nullptr)
- {
- pData->engine->setLastError("Plugin failed to initialize");
- return false;
- }
-
- // ---------------------------------------------------------------
- // check for custom data extension
-
- if (fDssiDescriptor->configure != nullptr)
- {
- if (char* const error = fDssiDescriptor->configure(fHandle, DSSI_CUSTOMDATA_EXTENSION_KEY, ""))
- {
- if (std::strcmp(error, "true") == 0 && fDssiDescriptor->get_custom_data != nullptr && fDssiDescriptor->set_custom_data != nullptr)
- fUsesCustomData = true;
-
- std::free(error);
- }
- }
-
- // ---------------------------------------------------------------
- // gui stuff
-
- if (const char* const guiFilename = find_dssi_ui(filename, fDescriptor->Label))
- {
- pData->osc.thread.setOscData(guiFilename, fDescriptor->Label);
- fUiFilename = guiFilename;
- }
-
- // ---------------------------------------------------------------
- // load plugin settings
-
- {
- #ifdef __USE_GNU
- const bool isAmSynth(strcasestr(pData->filename, "amsynth"));
- const bool isDssiVst(strcasestr(pData->filename, "dssi-vst"));
- #else
- const bool isAmSynth(std::strstr(pData->filename, "amsynth"));
- const bool isDssiVst(std::strstr(pData->filename, "dssi-vst"));
- #endif
-
- // set default options
- pData->options = 0x0;
-
- pData->options |= PLUGIN_OPTION_MAP_PROGRAM_CHANGES;
-
- if (isAmSynth || isDssiVst)
- pData->options |= PLUGIN_OPTION_FIXED_BUFFERS;
-
- if (pData->engine->getOptions().forceStereo)
- pData->options |= PLUGIN_OPTION_FORCE_STEREO;
-
- if (fUsesCustomData)
- pData->options |= PLUGIN_OPTION_USE_CHUNKS;
-
- if (fDssiDescriptor->run_synth != nullptr || fDssiDescriptor->run_multiple_synths != nullptr)
- {
- pData->options |= PLUGIN_OPTION_SEND_CHANNEL_PRESSURE;
- pData->options |= PLUGIN_OPTION_SEND_NOTE_AFTERTOUCH;
- pData->options |= PLUGIN_OPTION_SEND_PITCHBEND;
- pData->options |= PLUGIN_OPTION_SEND_ALL_SOUND_OFF;
-
- if (fDssiDescriptor->run_synth == nullptr)
- carla_stderr("WARNING: Plugin can ONLY use run_multiple_synths!");
- }
-
- // set identifier string
- CarlaString identifier("DSSI/");
-
- if (const char* const shortname = std::strrchr(filename, OS_SEP))
- {
- identifier += shortname+1;
- identifier += ",";
- }
-
- identifier += label;
- pData->identifier = identifier.dup();
-
- // load settings
- pData->options = pData->loadSettings(pData->options, getOptionsAvailable());
-
- // ignore settings, we need this anyway
- if (isAmSynth || isDssiVst)
- pData->options |= PLUGIN_OPTION_FIXED_BUFFERS;
- }
-
- return true;
- }
-
- // -------------------------------------------------------------------
-
- private:
- LADSPA_Handle fHandle;
- LADSPA_Handle fHandle2;
- const LADSPA_Descriptor* fDescriptor;
- const DSSI_Descriptor* fDssiDescriptor;
-
- bool fUsesCustomData;
- const char* fUiFilename;
-
- float** fAudioInBuffers;
- float** fAudioOutBuffers;
- float* fParamBuffers;
- snd_seq_event_t fMidiEvents[kPluginMaxMidiEvents];
-
- // -------------------------------------------------------------------
-
- static LinkedList<const char*> sMultiSynthList;
-
- static bool addUniqueMultiSynth(const char* const label) noexcept
- {
- CARLA_SAFE_ASSERT_RETURN(label != nullptr && label[0] != '\0', false);
-
- const char* dlabel = nullptr;
-
- try {
- dlabel = carla_strdup(label);
- } catch(...) { return false; }
-
- for (LinkedList<const char*>::Itenerator it = sMultiSynthList.begin(); it.valid(); it.next())
- {
- const char* const itLabel(it.getValue());
-
- if (std::strcmp(dlabel, itLabel) == 0)
- {
- delete[] dlabel;
- return false;
- }
- }
-
- return sMultiSynthList.append(dlabel);
- }
-
- static void removeUniqueMultiSynth(const char* const label) noexcept
- {
- CARLA_SAFE_ASSERT_RETURN(label != nullptr && label[0] != '\0',);
-
- for (LinkedList<const char*>::Itenerator it = sMultiSynthList.begin(); it.valid(); it.next())
- {
- const char* const itLabel(it.getValue());
-
- if (std::strcmp(label, itLabel) == 0)
- {
- sMultiSynthList.remove(it);
- delete[] itLabel;
- break;
- }
- }
- }
-
- CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(DssiPlugin)
- };
-
- LinkedList<const char*> DssiPlugin::sMultiSynthList;
-
- CARLA_BACKEND_END_NAMESPACE
-
- #endif // WANT_DSSI
-
- // -------------------------------------------------------------------------------------------------------------------
-
- CARLA_BACKEND_START_NAMESPACE
-
- CarlaPlugin* CarlaPlugin::newDSSI(const Initializer& init)
- {
- carla_debug("CarlaPlugin::newDSSI({%p, \"%s\", \"%s\", \"%s\", " P_INT64 "})", init.engine, init.filename, init.name, init.label, init.uniqueId);
-
- #ifdef WANT_DSSI
- DssiPlugin* const plugin(new DssiPlugin(init.engine, init.id));
-
- if (! plugin->init(init.filename, init.name, init.label))
- {
- delete plugin;
- return nullptr;
- }
-
- plugin->reload();
-
- if (init.engine->getProccessMode() == ENGINE_PROCESS_MODE_CONTINUOUS_RACK && ! plugin->canRunInRack())
- {
- init.engine->setLastError("Carla's rack mode can only work with Mono or Stereo DSSI plugins, sorry!");
- delete plugin;
- return nullptr;
- }
-
- return plugin;
- #else
- init.engine->setLastError("DSSI support not available");
- return nullptr;
- #endif
- }
-
- CARLA_BACKEND_END_NAMESPACE
-
- // -------------------------------------------------------------------------------------------------------------------
|