|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064 |
- /*
- * Carla Plugin JACK
- * Copyright (C) 2016-2020 Filipe Coelho <falktx@falktx.com>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of
- * the License, or any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * For a full copy of the GNU General Public License see the doc/GPL.txt file.
- */
-
- #include "CarlaPluginInternal.hpp"
- #include "CarlaEngine.hpp"
-
- #ifdef CARLA_OS_LINUX
-
- #include "CarlaLibJackHints.h"
- #include "CarlaBackendUtils.hpp"
- #include "CarlaBridgeUtils.hpp"
- #include "CarlaEngineUtils.hpp"
- #include "CarlaMathUtils.hpp"
- #include "CarlaPipeUtils.hpp"
- #include "CarlaScopeUtils.hpp"
- #include "CarlaShmUtils.hpp"
- #include "CarlaThread.hpp"
-
- #ifdef HAVE_LIBLO
- # include "CarlaOscUtils.hpp"
- #else
- # warning No liblo support, NSM (session state) will not be available
- #endif
-
- #include "water/files/File.h"
- #include "water/misc/Time.h"
- #include "water/text/StringArray.h"
- #include "water/threads/ChildProcess.h"
-
- #include "jackbridge/JackBridge.hpp"
-
- #include <ctime>
- #include <vector>
-
- // -------------------------------------------------------------------------------------------------------------------
-
- using water::ChildProcess;
- using water::File;
- using water::String;
- using water::StringArray;
- using water::Time;
-
- CARLA_BACKEND_START_NAMESPACE
-
- static size_t safe_rand(const size_t limit)
- {
- const int r = std::rand();
- CARLA_SAFE_ASSERT_RETURN(r >= 0, 0);
-
- return static_cast<uint>(r) % limit;
- }
-
- // -------------------------------------------------------------------------------------------------------------------
- // Fallback data
-
- static const ExternalMidiNote kExternalMidiNoteFallback = { -1, 0, 0 };
-
- // -------------------------------------------------------------------------------------------------------------------
-
- struct Announcer {
- virtual ~Announcer() {}
- virtual void nsmAnnounced(bool hasGui) = 0;
- };
-
- class CarlaPluginJackThread : public CarlaThread
- {
- public:
- CarlaPluginJackThread(Announcer* const ann, CarlaEngine* const engine, CarlaPlugin* const plugin) noexcept
- : CarlaThread("CarlaPluginJackThread"),
- kAnnouncer(ann),
- kEngine(engine),
- kPlugin(plugin),
- fShmIds(),
- fSetupLabel(),
- #ifdef HAVE_LIBLO
- fOscClientAddress(nullptr),
- fOscServer(nullptr),
- fHasOptionalGui(false),
- fProject(),
- #endif
- fProcess() {}
-
- void setData(const char* const shmIds, const char* const setupLabel) noexcept
- {
- CARLA_SAFE_ASSERT_RETURN(shmIds != nullptr && shmIds[0] != '\0',);
- CARLA_SAFE_ASSERT_RETURN(setupLabel != nullptr && setupLabel[0] != '\0',);
- CARLA_SAFE_ASSERT(! isThreadRunning());
-
- fShmIds = shmIds;
- fSetupLabel = setupLabel;
- }
-
- uintptr_t getProcessID() const noexcept
- {
- CARLA_SAFE_ASSERT_RETURN(fProcess != nullptr, 0);
-
- return (uintptr_t)fProcess->getPID();
- }
-
- #ifdef HAVE_LIBLO
- void nsmSave(const char* const setupLabel)
- {
- if (fOscClientAddress == nullptr)
- return;
-
- if (fSetupLabel != setupLabel)
- fSetupLabel = setupLabel;
-
- maybeOpenFirstTime(false);
-
- lo_send_from(fOscClientAddress, fOscServer, LO_TT_IMMEDIATE, "/nsm/client/save", "");
- }
-
- bool nsmShowGui(const bool yesNo)
- {
- if (fOscClientAddress == nullptr || ! fHasOptionalGui)
- return false;
-
- lo_send_from(fOscClientAddress, fOscServer, LO_TT_IMMEDIATE,
- yesNo ? "/nsm/client/show_optional_gui"
- : "/nsm/client/hide_optional_gui", "");
-
- return true;
- }
- #endif
-
- char* getEnvVarsToExport()
- {
- const EngineOptions& options(kEngine->getOptions());
- CarlaString binaryDir(options.binaryDir);
- #ifdef HAVE_LIBLO
- const int sessionManager = fSetupLabel[4U] - '0';
- #endif
-
- CarlaString ret;
- ret += "export LD_LIBRARY_PATH=" + binaryDir + "/jack\n";
- ret += "export LD_PRELOAD=" + binaryDir + "/libcarla_interposer-jack-x11.so\n";
- #ifdef HAVE_LIBLO
- if (sessionManager == LIBJACK_SESSION_MANAGER_NSM)
- {
- for (int i=50; fOscServer == nullptr && --i>=0;)
- carla_msleep(100);
-
- ret += "export NSM_URL=";
- ret += lo_server_get_url(fOscServer);
- ret += "\n";
- }
- #endif
-
- if (kPlugin->getHints() & PLUGIN_HAS_CUSTOM_UI)
- ret += "export CARLA_FRONTEND_WIN_ID=" + CarlaString(options.frontendWinId) + "\n";
-
- ret += "export CARLA_LIBJACK_SETUP=" + fSetupLabel + "\n";
- ret += "export CARLA_SHM_IDS=" + fShmIds + "\n";
-
- return ret.releaseBufferPointer();
- }
-
- protected:
- #ifdef HAVE_LIBLO
- static void _osc_error_handler(int num, const char* msg, const char* path)
- {
- carla_stderr2("CarlaPluginJackThread::_osc_error_handler(%i, \"%s\", \"%s\")", num, msg, path);
- }
-
- static int _broadcast_handler(const char* path, const char* types, lo_arg** argv, int argc, lo_message msg, void* data)
- {
- CARLA_SAFE_ASSERT_RETURN(data != nullptr, 0);
- carla_stdout("CarlaPluginJackThread::_broadcast_handler(%s, %s, %p, %i)", path, types, argv, argc);
-
- return ((CarlaPluginJackThread*)data)->handleBroadcast(path, types, argv, msg);
- }
-
- void maybeOpenFirstTime(const bool announced)
- {
- if (fSetupLabel.length() <= 6)
- return;
-
- if ((announced || fProject.path.isEmpty()) && fProject.init(kPlugin->getName(),
- kEngine->getCurrentProjectFolder(),
- &fSetupLabel[6U]))
- {
- carla_stdout("Sending open signal %s %s %s",
- fProject.path.buffer(), fProject.display.buffer(), fProject.clientName.buffer());
-
- lo_send_from(fOscClientAddress, fOscServer, LO_TT_IMMEDIATE, "/nsm/client/open", "sss",
- fProject.path.buffer(), fProject.display.buffer(), fProject.clientName.buffer());
- }
- }
-
- int handleBroadcast(const char* path, const char* types, lo_arg** argv, lo_message msg)
- {
- if (std::strcmp(path, "/nsm/server/announce") == 0)
- {
- CARLA_SAFE_ASSERT_RETURN(std::strcmp(types, "sssiii") == 0, 0);
-
- const lo_address msgAddress(lo_message_get_source(msg));
- CARLA_SAFE_ASSERT_RETURN(msgAddress != nullptr, 0);
-
- char* const msgURL(lo_address_get_url(msgAddress));
- CARLA_SAFE_ASSERT_RETURN(msgURL != nullptr, 0);
-
- if (fOscClientAddress != nullptr)
- lo_address_free(fOscClientAddress);
-
- fOscClientAddress = lo_address_new_from_url(msgURL);
- CARLA_SAFE_ASSERT_RETURN(fOscClientAddress != nullptr, 0);
-
- fProject.appName = &argv[0]->s;
- fHasOptionalGui = std::strstr(&argv[1]->s, ":optional-gui:") != nullptr;
-
- kAnnouncer->nsmAnnounced(fHasOptionalGui);
-
- static const char* const featuresG = ":server-control:optional-gui:";
- static const char* const featuresN = ":server-control:";
-
- static const char* const method = "/nsm/server/announce";
- static const char* const message = "Howdy, what took you so long?";
- static const char* const smName = "Carla";
-
- const char* const features = ((fSetupLabel[5U] - '0') & LIBJACK_FLAG_CONTROL_WINDOW)
- ? featuresG : featuresN;
-
- lo_send_from(fOscClientAddress, fOscServer, LO_TT_IMMEDIATE, "/reply", "ssss",
- method, message, smName, features);
-
- maybeOpenFirstTime(true);
- return 0;
- }
-
- CARLA_SAFE_ASSERT_RETURN(fOscClientAddress != nullptr, 0);
-
- if (std::strcmp(path, "/reply") == 0)
- {
- CARLA_SAFE_ASSERT_RETURN(std::strcmp(types, "ss") == 0, 0);
-
- const char* const method = &argv[0]->s;
- const char* const message = &argv[1]->s;
-
- carla_stdout("Got reply of '%s' as '%s'", method, message);
-
- if (std::strcmp(method, "/nsm/client/open") == 0)
- {
- carla_stdout("Sending 'Session is loaded' to %s", fProject.appName.buffer());
- lo_send_from(fOscClientAddress, fOscServer, LO_TT_IMMEDIATE, "/nsm/client/session_is_loaded", "");
- }
- }
-
- else if (std::strcmp(path, "/nsm/client/gui_is_shown") == 0)
- {
- CARLA_SAFE_ASSERT_RETURN(std::strcmp(types, "") == 0, 0);
-
- kEngine->callback(true, true,
- ENGINE_CALLBACK_UI_STATE_CHANGED,
- kPlugin->getId(),
- 1,
- 0, 0, 0.0f, nullptr);
- }
-
- else if (std::strcmp(path, "/nsm/client/gui_is_hidden") == 0)
- {
- CARLA_SAFE_ASSERT_RETURN(std::strcmp(types, "") == 0, 0);
-
- kEngine->callback(true, true,
- ENGINE_CALLBACK_UI_STATE_CHANGED,
- kPlugin->getId(),
- 0,
- 0, 0, 0.0f, nullptr);
- }
-
- // special messages
- else if (std::strcmp(path, "/nsm/gui/client/save") == 0)
- {
- CARLA_SAFE_ASSERT_RETURN(std::strcmp(types, "s") == 0, 0);
-
- lo_send_from(fOscClientAddress, fOscServer, LO_TT_IMMEDIATE, "/nsm/client/save", "");
- }
-
- else if (std::strcmp(path, "/nsm/server/stop") == 0)
- {
- CARLA_SAFE_ASSERT_RETURN(std::strcmp(types, "s") == 0, 0);
-
- lo_send_from(fOscClientAddress, fOscServer, LO_TT_IMMEDIATE, "/nsm/client/hide_optional_gui", "");
-
- kEngine->callback(true, true,
- ENGINE_CALLBACK_UI_STATE_CHANGED,
- kPlugin->getId(),
- 0,
- 0, 0, 0.0f, nullptr);
- }
-
- return 0;
- }
- #endif
-
- void run()
- {
- #ifdef HAVE_LIBLO
- if (fOscClientAddress != nullptr)
- {
- lo_address_free(fOscClientAddress);
- fOscClientAddress = nullptr;
- }
-
- const int sessionManager = fSetupLabel[4U] - '0';
-
- if (sessionManager == LIBJACK_SESSION_MANAGER_NSM)
- {
- // NSM support
- fOscServer = lo_server_new_with_proto(nullptr, LO_UDP, _osc_error_handler);
- CARLA_SAFE_ASSERT_RETURN(fOscServer != nullptr,);
-
- lo_server_add_method(fOscServer, nullptr, nullptr, _broadcast_handler, this);
- }
- #endif
-
- const bool externalProcess = ((fSetupLabel[5U] - '0') & LIBJACK_FLAG_EXTERNAL_START)
- && ! kEngine->isLoadingProject();
-
- if (! externalProcess)
- {
- if (fProcess == nullptr)
- {
- fProcess = new ChildProcess();
- }
- else if (fProcess->isRunning())
- {
- carla_stderr("CarlaPluginJackThread::run() - already running");
- }
-
- String name(kPlugin->getName());
- String filename(kPlugin->getFilename());
-
- if (name.isEmpty())
- name = "(none)";
-
- CARLA_SAFE_ASSERT_RETURN(filename.isNotEmpty(),);
-
- StringArray arguments;
-
- // binary
- arguments.addTokens(filename, true);
-
- const EngineOptions& options(kEngine->getOptions());
-
- char winIdStr[STR_MAX+1];
- std::snprintf(winIdStr, STR_MAX, P_UINTPTR, options.frontendWinId);
- winIdStr[STR_MAX] = '\0';
-
- const CarlaString libjackdir(CarlaString(options.binaryDir) + "/jack");
- const CarlaString ldpreload(CarlaString(options.binaryDir) + "/libcarla_interposer-jack-x11.so");
-
- const ScopedEngineEnvironmentLocker _seel(kEngine);
-
- const CarlaScopedEnvVar sev2("LD_LIBRARY_PATH", libjackdir.buffer());
- const CarlaScopedEnvVar sev1("LD_PRELOAD", ldpreload.isNotEmpty() ? ldpreload.buffer() : nullptr);
- #ifdef HAVE_LIBLO
- const CarlaScopedEnvVar sev3("NSM_URL", lo_server_get_url(fOscServer));
- #endif
-
- if (kPlugin->getHints() & PLUGIN_HAS_CUSTOM_UI)
- carla_setenv("CARLA_FRONTEND_WIN_ID", winIdStr);
- else
- carla_unsetenv("CARLA_FRONTEND_WIN_ID");
-
- carla_setenv("CARLA_LIBJACK_SETUP", fSetupLabel.buffer());
- carla_setenv("CARLA_SHM_IDS", fShmIds.buffer());
-
- if (! fProcess->start(arguments))
- {
- carla_stdout("failed!");
- fProcess = nullptr;
- return;
- }
- }
-
- for (; (externalProcess || fProcess->isRunning()) && ! shouldThreadExit();)
- {
- #ifdef HAVE_LIBLO
- if (sessionManager == LIBJACK_SESSION_MANAGER_NSM)
- {
- lo_server_recv_noblock(fOscServer, 50);
- }
- else
- #endif
- {
- carla_msleep(50);
- }
- }
-
- #ifdef HAVE_LIBLO
- if (sessionManager == LIBJACK_SESSION_MANAGER_NSM)
- {
- lo_server_free(fOscServer);
- fOscServer = nullptr;
-
- if (fOscClientAddress != nullptr)
- {
- lo_address_free(fOscClientAddress);
- fOscClientAddress = nullptr;
- }
- }
- #endif
-
- if (! externalProcess)
- {
- // we only get here if bridge crashed or thread asked to exit
- if (fProcess->isRunning() && shouldThreadExit())
- {
- fProcess->waitForProcessToFinish(2000);
-
- if (fProcess->isRunning())
- {
- carla_stdout("CarlaPluginJackThread::run() - application refused to close, force kill now");
- fProcess->kill();
- }
- }
- else
- {
- // forced quit, may have crashed
- if (fProcess->getExitCodeAndClearPID() != 0)
- {
- carla_stderr("CarlaPluginJackThread::run() - application crashed");
-
- CarlaString errorString("Plugin '" + CarlaString(kPlugin->getName()) + "' has crashed!\n"
- "Saving now will lose its current settings.\n"
- "Please remove this plugin, and not rely on it from this point.");
- kEngine->callback(true, true,
- ENGINE_CALLBACK_ERROR,
- kPlugin->getId(),
- 0, 0, 0, 0.0f,
- errorString);
- }
- }
- }
-
- fProcess = nullptr;
- }
-
- private:
- Announcer* const kAnnouncer;
- CarlaEngine* const kEngine;
- CarlaPlugin* const kPlugin;
-
- CarlaString fShmIds;
- CarlaString fSetupLabel;
-
- #ifdef HAVE_LIBLO
- lo_address fOscClientAddress;
- lo_server fOscServer;
- bool fHasOptionalGui;
-
- struct ProjectData {
- CarlaString appName;
- CarlaString path;
- CarlaString display;
- CarlaString clientName;
-
- ProjectData()
- : appName(),
- path(),
- display(),
- clientName() {}
-
- bool init(const char* const pluginName,
- const char* const engineProjectFolder,
- const char* const uniqueCodeID)
- {
- CARLA_SAFE_ASSERT_RETURN(engineProjectFolder != nullptr && engineProjectFolder[0] != '\0', false);
- CARLA_SAFE_ASSERT_RETURN(uniqueCodeID != nullptr && uniqueCodeID[0] != '\0', false);
- CARLA_SAFE_ASSERT_RETURN(appName.isNotEmpty(), false);
-
- String child(pluginName);
- child += ".";
- child += uniqueCodeID;
-
- const File file(File(engineProjectFolder).getChildFile(child));
-
- clientName = appName + "." + uniqueCodeID;
- path = file.getFullPathName().toRawUTF8();
- display = file.getFileNameWithoutExtension().toRawUTF8();
-
- return true;
- }
-
- CARLA_DECLARE_NON_COPY_STRUCT(ProjectData)
- } fProject;
- #endif
-
- CarlaScopedPointer<ChildProcess> fProcess;
-
- CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(CarlaPluginJackThread)
- };
-
- // -------------------------------------------------------------------------------------------------------------------
-
- class CarlaPluginJack : public CarlaPlugin,
- public Announcer
- {
- public:
- CarlaPluginJack(CarlaEngine* const engine, const uint id)
- : CarlaPlugin(engine, id),
- fInitiated(false),
- fInitError(false),
- fTimedOut(false),
- fTimedError(false),
- fProcCanceled(false),
- fBufferSize(engine->getBufferSize()),
- fProcWaitTime(0),
- fSetupHints(0x0),
- fBridgeThread(this, engine, this),
- fShmAudioPool(),
- fShmRtClientControl(),
- fShmNonRtClientControl(),
- fShmNonRtServerControl(),
- fInfo()
- {
- carla_debug("CarlaPluginJack::CarlaPluginJack(%p, %i)", engine, id);
-
- pData->hints |= PLUGIN_IS_BRIDGE;
- }
-
- ~CarlaPluginJack() override
- {
- carla_debug("CarlaPluginJack::~CarlaPluginJack()");
-
- #ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH
- // close UI
- if (pData->hints & PLUGIN_HAS_CUSTOM_UI)
- pData->transientTryCounter = 0;
- #endif
-
- pData->singleMutex.lock();
- pData->masterMutex.lock();
-
- if (pData->client != nullptr && pData->client->isActive())
- pData->client->deactivate(true);
-
- if (pData->active)
- {
- deactivate();
- pData->active = false;
- }
-
- if (fBridgeThread.isThreadRunning())
- {
- fShmRtClientControl.writeOpcode(kPluginBridgeRtClientQuit);
- fShmRtClientControl.commitWrite();
-
- fShmNonRtClientControl.writeOpcode(kPluginBridgeNonRtClientQuit);
- fShmNonRtClientControl.commitWrite();
-
- if (! fTimedOut)
- waitForClient("stopping", 3000);
- }
-
- fBridgeThread.stopThread(3000);
-
- fShmNonRtServerControl.clear();
- fShmNonRtClientControl.clear();
- fShmRtClientControl.clear();
- fShmAudioPool.clear();
-
- clearBuffers();
-
- fInfo.chunk.clear();
- }
-
- // -------------------------------------------------------------------
-
- void nsmAnnounced(bool hasGui) override
- {
- if (hasGui || (pData->hints & PLUGIN_HAS_CUSTOM_UI) == 0x0)
- return;
-
- {
- const CarlaMutexLocker _cml(fShmNonRtClientControl.mutex);
-
- fShmNonRtClientControl.writeOpcode(kPluginBridgeNonRtClientShowUI);
- fShmNonRtClientControl.commitWrite();
- }
-
- pData->engine->callback(true, true,
- ENGINE_CALLBACK_UI_STATE_CHANGED,
- pData->id,
- 1,
- 0, 0, 0.0f, nullptr);
- }
-
- // -------------------------------------------------------------------
- // Information (base)
-
- PluginType getType() const noexcept override
- {
- return PLUGIN_JACK;
- }
-
- PluginCategory getCategory() const noexcept override
- {
- return PLUGIN_CATEGORY_NONE;
- }
-
- // -------------------------------------------------------------------
- // Information (count)
-
- uint32_t getMidiInCount() const noexcept override
- {
- return fInfo.mIns;
- }
-
- uint32_t getMidiOutCount() const noexcept override
- {
- return fInfo.mOuts;
- }
-
- // -------------------------------------------------------------------
- // Information (current data)
-
- // -------------------------------------------------------------------
- // Information (per-plugin data)
-
- uint getOptionsAvailable() const noexcept override
- {
- uint options = 0x0;
-
- if (fInfo.mIns > 0)
- {
- 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;
- options |= PLUGIN_OPTION_SEND_PROGRAM_CHANGES;
- options |= PLUGIN_OPTION_SKIP_SENDING_NOTES;
- }
-
- return options;
- }
-
- bool getLabel(char* const strBuf) const noexcept override
- {
- std::strncpy(strBuf, fInfo.setupLabel, STR_MAX);
- return true;
- }
-
- bool getMaker(char* const) const noexcept override
- {
- return false;
- }
-
- bool getCopyright(char* const) const noexcept override
- {
- return false;
- }
-
- bool getRealName(char* const strBuf) const noexcept override
- {
- // FIXME
- std::strncpy(strBuf, "Carla's libjack", STR_MAX);
- return true;
- }
-
- // -------------------------------------------------------------------
- // Set data (state)
-
- void prepareForSave(bool) noexcept override
- {
- #ifdef HAVE_LIBLO
- if (fInfo.setupLabel.length() == 6)
- setupUniqueProjectID();
- #endif
-
- {
- const CarlaMutexLocker _cml(fShmNonRtClientControl.mutex);
-
- fShmNonRtClientControl.writeOpcode(kPluginBridgeNonRtClientPrepareForSave);
- fShmNonRtClientControl.commitWrite();
- }
-
- #ifdef HAVE_LIBLO
- fBridgeThread.nsmSave(fInfo.setupLabel);
- #endif
- }
-
- // -------------------------------------------------------------------
- // Set data (internal stuff)
-
- void setOption(const uint option, const bool yesNo, const bool sendCallback) override
- {
- {
- const CarlaMutexLocker _cml(fShmNonRtClientControl.mutex);
-
- fShmNonRtClientControl.writeOpcode(kPluginBridgeNonRtClientSetOption);
- fShmNonRtClientControl.writeUInt(option);
- fShmNonRtClientControl.writeBool(yesNo);
- fShmNonRtClientControl.commitWrite();
- }
-
- CarlaPlugin::setOption(option, yesNo, sendCallback);
- }
-
- void setCtrlChannel(const int8_t channel, const bool sendOsc, const bool sendCallback) noexcept override
- {
- CARLA_SAFE_ASSERT_RETURN(sendOsc || sendCallback,); // never call this from RT
-
- {
- const CarlaMutexLocker _cml(fShmNonRtClientControl.mutex);
-
- fShmNonRtClientControl.writeOpcode(kPluginBridgeNonRtClientSetCtrlChannel);
- fShmNonRtClientControl.writeShort(channel);
- fShmNonRtClientControl.commitWrite();
- }
-
- CarlaPlugin::setCtrlChannel(channel, sendOsc, sendCallback);
- }
-
- // -------------------------------------------------------------------
- // Set data (plugin-specific stuff)
-
- void setCustomData(const char* const type, const char* const key, const char* const value, const bool sendGui) override
- {
- CARLA_SAFE_ASSERT_RETURN(type != nullptr && type[0] != '\0',);
- CARLA_SAFE_ASSERT_RETURN(key != nullptr && key[0] != '\0',);
- CARLA_SAFE_ASSERT_RETURN(value != nullptr,);
-
- if (std::strcmp(type, CUSTOM_DATA_TYPE_PROPERTY) == 0)
- return CarlaPlugin::setCustomData(type, key, value, sendGui);
-
- if (std::strcmp(type, CUSTOM_DATA_TYPE_STRING) == 0 && std::strcmp(key, "__CarlaPingOnOff__") == 0)
- {
- #if 0
- const CarlaMutexLocker _cml(fShmNonRtClientControl.mutex);
-
- fShmNonRtClientControl.writeOpcode(kPluginBridgeNonRtClientPingOnOff);
- fShmNonRtClientControl.writeBool(std::strcmp(value, "true") == 0);
- fShmNonRtClientControl.commitWrite();
- #endif
- return;
- }
-
- CarlaPlugin::setCustomData(type, key, value, sendGui);
- }
-
- // -------------------------------------------------------------------
- // Set ui stuff
-
- void showCustomUI(const bool yesNo) override
- {
- if (yesNo && ! fBridgeThread.isThreadRunning()) {
- CARLA_SAFE_ASSERT_RETURN(restartBridgeThread(),);
- }
-
- #ifdef HAVE_LIBLO
- if (! fBridgeThread.nsmShowGui(yesNo))
- #endif
- {
- const CarlaMutexLocker _cml(fShmNonRtClientControl.mutex);
-
- fShmNonRtClientControl.writeOpcode(yesNo ? kPluginBridgeNonRtClientShowUI : kPluginBridgeNonRtClientHideUI);
- fShmNonRtClientControl.commitWrite();
- }
- }
-
- void idle() override
- {
- if (fBridgeThread.isThreadRunning())
- {
- if (fInitiated && fTimedOut && pData->active)
- setActive(false, true, true);
-
- {
- const CarlaMutexLocker _cml(fShmNonRtClientControl.mutex);
-
- fShmNonRtClientControl.writeOpcode(kPluginBridgeNonRtClientPing);
- fShmNonRtClientControl.commitWrite();
- }
-
- try {
- handleNonRtData();
- } CARLA_SAFE_EXCEPTION("handleNonRtData");
- }
- else if (fInitiated)
- {
- fTimedOut = true;
- fTimedError = true;
- fInitiated = false;
- handleProcessStopped();
- }
- else if (fProcCanceled)
- {
- handleProcessStopped();
- fProcCanceled = false;
- }
-
- CarlaPlugin::idle();
- }
-
- // -------------------------------------------------------------------
- // Plugin state
-
- void reload() override
- {
- CARLA_SAFE_ASSERT_RETURN(pData->engine != nullptr,);
- carla_debug("CarlaPluginJack::reload() - start");
-
- const EngineProcessMode processMode(pData->engine->getProccessMode());
-
- // Safely disable plugin for reload
- const ScopedDisabler sd(this);
-
- // cleanup of previous data
- pData->audioIn.clear();
- pData->audioOut.clear();
- pData->event.clear();
-
- bool needsCtrlIn, needsCtrlOut;
- needsCtrlIn = needsCtrlOut = false;
-
- if (fInfo.aIns > 0)
- {
- pData->audioIn.createNew(fInfo.aIns);
- }
-
- if (fInfo.aOuts > 0)
- {
- pData->audioOut.createNew(fInfo.aOuts);
- needsCtrlIn = true;
- }
-
- if (fInfo.mIns > 0)
- needsCtrlIn = true;
-
- if (fInfo.mOuts > 0)
- needsCtrlOut = true;
-
- const uint portNameSize(pData->engine->getMaxPortNameSize());
- CarlaString portName;
-
- // Audio Ins
- for (uint8_t j=0; j < fInfo.aIns; ++j)
- {
- portName.clear();
-
- if (processMode == ENGINE_PROCESS_MODE_SINGLE_CLIENT)
- {
- portName = pData->name;
- portName += ":";
- }
-
- if (fInfo.aIns > 1)
- {
- portName += "audio_in_";
- portName += CarlaString(j+1);
- }
- else
- {
- portName += "audio_in";
- }
-
- portName.truncate(portNameSize);
-
- pData->audioIn.ports[j].port = (CarlaEngineAudioPort*)pData->client->addPort(kEnginePortTypeAudio, portName, true, j);
- pData->audioIn.ports[j].rindex = j;
- }
-
- // Audio Outs
- for (uint8_t j=0; j < fInfo.aOuts; ++j)
- {
- portName.clear();
-
- if (processMode == ENGINE_PROCESS_MODE_SINGLE_CLIENT)
- {
- portName = pData->name;
- portName += ":";
- }
-
- if (fInfo.aOuts > 1)
- {
- portName += "audio_out_";
- portName += CarlaString(j+1);
- }
- else
- {
- portName += "audio_out";
- }
-
- portName.truncate(portNameSize);
-
- pData->audioOut.ports[j].port = (CarlaEngineAudioPort*)pData->client->addPort(kEnginePortTypeAudio, portName, false, j);
- pData->audioOut.ports[j].rindex = j;
- }
-
- if (needsCtrlIn)
- {
- portName.clear();
-
- if (processMode == ENGINE_PROCESS_MODE_SINGLE_CLIENT)
- {
- portName = pData->name;
- portName += ":";
- }
-
- portName += "event-in";
- portName.truncate(portNameSize);
-
- pData->event.portIn = (CarlaEngineEventPort*)pData->client->addPort(kEnginePortTypeEvent, portName, true, 0);
- }
-
- if (needsCtrlOut)
- {
- portName.clear();
-
- if (processMode == ENGINE_PROCESS_MODE_SINGLE_CLIENT)
- {
- portName = pData->name;
- portName += ":";
- }
-
- portName += "event-out";
- portName.truncate(portNameSize);
-
- pData->event.portOut = (CarlaEngineEventPort*)pData->client->addPort(kEnginePortTypeEvent, portName, false, 0);
- }
-
- // extra plugin hints
- pData->extraHints = 0x0;
-
- if (fInfo.mIns > 0)
- pData->extraHints |= PLUGIN_EXTRA_HINT_HAS_MIDI_IN;
-
- if (fInfo.mOuts > 0)
- pData->extraHints |= PLUGIN_EXTRA_HINT_HAS_MIDI_OUT;
-
- bufferSizeChanged(pData->engine->getBufferSize());
- reloadPrograms(true);
-
- carla_debug("CarlaPluginJack::reload() - end");
- }
-
- // -------------------------------------------------------------------
- // Plugin processing
-
- void activate() noexcept override
- {
- if (! fBridgeThread.isThreadRunning())
- {
- CARLA_SAFE_ASSERT_RETURN(restartBridgeThread(),);
- }
-
- CARLA_SAFE_ASSERT_RETURN(! fTimedError,);
-
- {
- const CarlaMutexLocker _cml(fShmNonRtClientControl.mutex);
-
- fShmNonRtClientControl.writeOpcode(kPluginBridgeNonRtClientActivate);
- fShmNonRtClientControl.commitWrite();
- }
-
- fTimedOut = false;
-
- try {
- waitForClient("activate", 2000);
- } CARLA_SAFE_EXCEPTION("activate - waitForClient");
- }
-
- void deactivate() noexcept override
- {
- if (! fBridgeThread.isThreadRunning())
- return;
-
- CARLA_SAFE_ASSERT_RETURN(! fTimedError,);
-
- {
- const CarlaMutexLocker _cml(fShmNonRtClientControl.mutex);
-
- fShmNonRtClientControl.writeOpcode(kPluginBridgeNonRtClientDeactivate);
- fShmNonRtClientControl.commitWrite();
- }
-
- fTimedOut = false;
-
- try {
- waitForClient("deactivate", 2000);
- } CARLA_SAFE_EXCEPTION("deactivate - waitForClient");
- }
-
- void process(const float* const* const audioIn, float** const audioOut,
- const float* const*, float**, const uint32_t frames) override
- {
- // --------------------------------------------------------------------------------------------------------
- // Check if active
-
- if (fProcCanceled || fTimedOut || fTimedError || ! pData->active)
- {
- // disable any output sound
- for (uint32_t i=0; i < pData->audioOut.count; ++i)
- carla_zeroFloats(audioOut[i], frames);
- return;
- }
-
- // --------------------------------------------------------------------------------------------------------
- // Check if needs reset
-
- if (pData->needsReset)
- {
- // TODO
-
- pData->needsReset = false;
- }
-
- // --------------------------------------------------------------------------------------------------------
- // Event Input
-
- if (pData->event.portIn != nullptr)
- {
- // ----------------------------------------------------------------------------------------------------
- // MIDI Input (External)
-
- if (pData->extNotes.mutex.tryLock())
- {
- for (RtLinkedList<ExternalMidiNote>::Itenerator it = pData->extNotes.data.begin2(); it.valid(); it.next())
- {
- const ExternalMidiNote& note(it.getValue(kExternalMidiNoteFallback));
- CARLA_SAFE_ASSERT_CONTINUE(note.channel >= 0 && note.channel < MAX_MIDI_CHANNELS);
-
- uint8_t data1, data2, data3;
- data1 = uint8_t((note.velo > 0 ? MIDI_STATUS_NOTE_ON : MIDI_STATUS_NOTE_OFF) | (note.channel & MIDI_CHANNEL_BIT));
- data2 = note.note;
- data3 = note.velo;
-
- fShmRtClientControl.writeOpcode(kPluginBridgeRtClientMidiEvent);
- fShmRtClientControl.writeUInt(0); // time
- fShmRtClientControl.writeByte(0); // port
- fShmRtClientControl.writeByte(3); // size
- fShmRtClientControl.writeByte(data1);
- fShmRtClientControl.writeByte(data2);
- fShmRtClientControl.writeByte(data3);
- fShmRtClientControl.commitWrite();
- }
-
- pData->extNotes.data.clear();
- pData->extNotes.mutex.unlock();
-
- } // End of MIDI Input (External)
-
- // ----------------------------------------------------------------------------------------------------
- // Event Input (System)
-
- #ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH
- bool allNotesOffSent = false;
- #endif
- for (uint32_t i=0, numEvents=pData->event.portIn->getEventCount(); i < numEvents; ++i)
- {
- const EngineEvent& event(pData->event.portIn->getEvent(i));
-
- // 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_ALTERNATIVE_ARCH
- // 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.normalizedValue;
- setDryWetRT(value, true);
- }
-
- if (MIDI_IS_CONTROL_CHANNEL_VOLUME(ctrlEvent.param) && (pData->hints & PLUGIN_CAN_VOLUME) != 0)
- {
- value = ctrlEvent.normalizedValue*127.0f/100.0f;
- setVolumeRT(value, true);
- }
-
- if (MIDI_IS_CONTROL_BALANCE(ctrlEvent.param) && (pData->hints & PLUGIN_CAN_BALANCE) != 0)
- {
- float left, right;
- value = ctrlEvent.normalizedValue/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;
- }
-
- setBalanceLeftRT(left, true);
- setBalanceRightRT(right, true);
- }
- }
- #endif
- if ((pData->options & PLUGIN_OPTION_SEND_CONTROL_CHANGES) != 0 && ctrlEvent.param < MAX_MIDI_VALUE)
- {
- fShmRtClientControl.writeOpcode(kPluginBridgeRtClientMidiEvent);
- fShmRtClientControl.writeUInt(event.time);
- fShmRtClientControl.writeByte(0); // port
- fShmRtClientControl.writeByte(3); // size
- fShmRtClientControl.writeByte(uint8_t(MIDI_STATUS_CONTROL_CHANGE | (event.channel & MIDI_CHANNEL_BIT)));
- fShmRtClientControl.writeByte(uint8_t(ctrlEvent.param));
- fShmRtClientControl.writeByte(uint8_t(ctrlEvent.normalizedValue*127.0f));
- }
- break;
-
- case kEngineControlEventTypeMidiBank:
- if (pData->options & PLUGIN_OPTION_MAP_PROGRAM_CHANGES)
- {
- fShmRtClientControl.writeOpcode(kPluginBridgeRtClientControlEventMidiBank);
- fShmRtClientControl.writeUInt(event.time);
- fShmRtClientControl.writeByte(event.channel);
- fShmRtClientControl.writeUShort(event.ctrl.param);
- fShmRtClientControl.commitWrite();
- }
- break;
-
- case kEngineControlEventTypeMidiProgram:
- if (pData->options & PLUGIN_OPTION_MAP_PROGRAM_CHANGES)
- {
- fShmRtClientControl.writeOpcode(kPluginBridgeRtClientControlEventMidiProgram);
- fShmRtClientControl.writeUInt(event.time);
- fShmRtClientControl.writeByte(event.channel);
- fShmRtClientControl.writeUShort(event.ctrl.param);
- fShmRtClientControl.commitWrite();
- }
- break;
-
- case kEngineControlEventTypeAllSoundOff:
- if (pData->options & PLUGIN_OPTION_SEND_ALL_SOUND_OFF)
- {
- fShmRtClientControl.writeOpcode(kPluginBridgeRtClientControlEventAllSoundOff);
- fShmRtClientControl.writeUInt(event.time);
- fShmRtClientControl.writeByte(event.channel);
- fShmRtClientControl.commitWrite();
- }
- break;
-
- case kEngineControlEventTypeAllNotesOff:
- if (pData->options & PLUGIN_OPTION_SEND_ALL_SOUND_OFF)
- {
- #ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH
- if (event.channel == pData->ctrlChannel && ! allNotesOffSent)
- {
- allNotesOffSent = true;
- postponeRtAllNotesOff();
- }
- #endif
-
- fShmRtClientControl.writeOpcode(kPluginBridgeRtClientControlEventAllNotesOff);
- fShmRtClientControl.writeUInt(event.time);
- fShmRtClientControl.writeByte(event.channel);
- fShmRtClientControl.commitWrite();
- }
- break;
- } // switch (ctrlEvent.type)
- break;
- } // case kEngineEventTypeControl
-
- case kEngineEventTypeMidi: {
- const EngineMidiEvent& midiEvent(event.midi);
-
- if (midiEvent.size == 0 || midiEvent.size >= MAX_MIDI_VALUE)
- continue;
-
- const uint8_t* const midiData(midiEvent.size > EngineMidiEvent::kDataSize ? midiEvent.dataExt : midiEvent.data);
-
- uint8_t status = uint8_t(MIDI_GET_STATUS_FROM_DATA(midiData));
-
- if ((status == MIDI_STATUS_NOTE_OFF || status == MIDI_STATUS_NOTE_ON) && (pData->options & PLUGIN_OPTION_SKIP_SENDING_NOTES))
- continue;
- if (status == MIDI_STATUS_CHANNEL_PRESSURE && (pData->options & PLUGIN_OPTION_SEND_CHANNEL_PRESSURE) == 0)
- continue;
- if (status == MIDI_STATUS_CONTROL_CHANGE && (pData->options & PLUGIN_OPTION_SEND_CONTROL_CHANGES) == 0)
- continue;
- if (status == MIDI_STATUS_POLYPHONIC_AFTERTOUCH && (pData->options & PLUGIN_OPTION_SEND_NOTE_AFTERTOUCH) == 0)
- continue;
- if (status == MIDI_STATUS_PITCH_WHEEL_CONTROL && (pData->options & PLUGIN_OPTION_SEND_PITCHBEND) == 0)
- continue;
-
- // Fix bad note-off
- if (status == MIDI_STATUS_NOTE_ON && midiData[2] == 0)
- status = MIDI_STATUS_NOTE_OFF;
-
- fShmRtClientControl.writeOpcode(kPluginBridgeRtClientMidiEvent);
- fShmRtClientControl.writeUInt(event.time);
- fShmRtClientControl.writeByte(midiEvent.port);
- fShmRtClientControl.writeByte(midiEvent.size);
-
- fShmRtClientControl.writeByte(uint8_t(midiData[0] | (event.channel & MIDI_CHANNEL_BIT)));
-
- for (uint8_t j=1; j < midiEvent.size; ++j)
- fShmRtClientControl.writeByte(midiData[j]);
-
- fShmRtClientControl.commitWrite();
-
- if (status == MIDI_STATUS_NOTE_ON)
- {
- pData->postponeNoteOnRtEvent(true, event.channel, midiData[1], midiData[2]);
- }
- else if (status == MIDI_STATUS_NOTE_OFF)
- {
- pData->postponeNoteOffRtEvent(true, event.channel, midiData[1]);
- }
- } break;
- }
- }
-
- pData->postRtEvents.trySplice();
-
- } // End of Event Input
-
- if (! processSingle(audioIn, audioOut, frames))
- return;
-
- // --------------------------------------------------------------------------------------------------------
- // MIDI Output
-
- if (pData->event.portOut != nullptr)
- {
- uint32_t time;
- uint8_t port, size;
- const uint8_t* midiData(fShmRtClientControl.data->midiOut);
-
- for (std::size_t read=0; read<kBridgeRtClientDataMidiOutSize-kBridgeBaseMidiOutHeaderSize;)
- {
- // get time
- time = *(const uint32_t*)midiData;
- midiData += 4;
-
- // get port and size
- port = *midiData++;
- size = *midiData++;
-
- if (size == 0)
- break;
-
- // store midi data advancing as needed
- uint8_t data[size];
-
- for (uint8_t j=0; j<size; ++j)
- data[j] = *midiData++;
-
- pData->event.portOut->writeMidiEvent(time, size, data);
-
- read += kBridgeBaseMidiOutHeaderSize + size;
- }
-
- // TODO
- (void)port;
-
- } // End of Control and MIDI Output
- }
-
- bool processSingle(const float* const* const audioIn, float** const audioOut, const uint32_t frames)
- {
- CARLA_SAFE_ASSERT_RETURN(! fTimedError, false);
- CARLA_SAFE_ASSERT_RETURN(frames > 0, false);
- CARLA_SAFE_ASSERT_RETURN(frames <= fBufferSize, false);
-
- if (pData->audioIn.count > 0)
- {
- CARLA_SAFE_ASSERT_RETURN(audioIn != nullptr, false);
- }
- if (pData->audioOut.count > 0)
- {
- CARLA_SAFE_ASSERT_RETURN(audioOut != nullptr, false);
- }
-
- // --------------------------------------------------------------------------------------------------------
- // Try lock, silence otherwise
-
- #ifndef STOAT_TEST_BUILD
- if (pData->engine->isOffline())
- {
- pData->singleMutex.lock();
- }
- else
- #endif
- if (! pData->singleMutex.tryLock())
- {
- for (uint32_t i=0; i < pData->audioOut.count; ++i)
- carla_zeroFloats(audioOut[i], frames);
- return false;
- }
-
- // --------------------------------------------------------------------------------------------------------
- // Reset audio buffers
-
- for (uint32_t i=0; i < fInfo.aIns; ++i)
- carla_copyFloats(fShmAudioPool.data + (i * fBufferSize), audioIn[i], frames);
-
- // --------------------------------------------------------------------------------------------------------
- // TimeInfo
-
- const EngineTimeInfo timeInfo(pData->engine->getTimeInfo());
- BridgeTimeInfo& bridgeTimeInfo(fShmRtClientControl.data->timeInfo);
-
- bridgeTimeInfo.playing = timeInfo.playing;
- bridgeTimeInfo.frame = timeInfo.frame;
- bridgeTimeInfo.usecs = timeInfo.usecs;
- bridgeTimeInfo.validFlags = timeInfo.bbt.valid ? kPluginBridgeTimeInfoValidBBT : 0x0;
-
- if (timeInfo.bbt.valid)
- {
- bridgeTimeInfo.bar = timeInfo.bbt.bar;
- bridgeTimeInfo.beat = timeInfo.bbt.beat;
- bridgeTimeInfo.tick = timeInfo.bbt.tick;
-
- bridgeTimeInfo.beatsPerBar = timeInfo.bbt.beatsPerBar;
- bridgeTimeInfo.beatType = timeInfo.bbt.beatType;
-
- bridgeTimeInfo.ticksPerBeat = timeInfo.bbt.ticksPerBeat;
- bridgeTimeInfo.beatsPerMinute = timeInfo.bbt.beatsPerMinute;
- bridgeTimeInfo.barStartTick = timeInfo.bbt.barStartTick;
- }
-
- // --------------------------------------------------------------------------------------------------------
- // Run plugin
-
- {
- fShmRtClientControl.writeOpcode(kPluginBridgeRtClientProcess);
- fShmRtClientControl.writeUInt(frames);
- fShmRtClientControl.commitWrite();
- }
-
- waitForClient("process", fProcWaitTime);
-
- if (fTimedOut)
- {
- pData->singleMutex.unlock();
- return false;
- }
-
- if (fShmRtClientControl.data->procFlags)
- {
- fInitiated = false;
- fProcCanceled = true;
- }
-
- for (uint32_t i=0; i < fInfo.aOuts; ++i)
- carla_copyFloats(audioOut[i], fShmAudioPool.data + ((i + fInfo.aIns) * fBufferSize), frames);
-
- #ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH
- // --------------------------------------------------------------------------------------------------------
- // Post-processing (dry/wet, volume and balance)
-
- {
- const bool doVolume = (pData->hints & PLUGIN_CAN_VOLUME) != 0 && carla_isNotEqual(pData->postProc.volume, 1.0f);
- const bool doDryWet = (pData->hints & PLUGIN_CAN_DRYWET) != 0 && carla_isNotEqual(pData->postProc.dryWet, 1.0f);
- const bool doBalance = (pData->hints & PLUGIN_CAN_BALANCE) != 0 && ! (carla_isEqual(pData->postProc.balanceLeft, -1.0f) && carla_isEqual(pData->postProc.balanceRight, 1.0f));
- const bool isMono = (pData->audioIn.count == 1);
-
- bool isPair;
- float bufValue, oldBufLeft[doBalance ? frames : 1];
-
- for (uint32_t i=0; i < pData->audioOut.count; ++i)
- {
- // Dry/Wet
- if (doDryWet)
- {
- const uint32_t c = isMono ? 0 : i;
-
- for (uint32_t k=0; k < frames; ++k)
- {
- bufValue = audioIn[c][k];
- audioOut[i][k] = (audioOut[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_copyFloats(oldBufLeft, audioOut[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
- audioOut[i][k] = oldBufLeft[k] * (1.0f - balRangeL);
- audioOut[i][k] += audioOut[i+1][k] * (1.0f - balRangeR);
- }
- else
- {
- // right
- audioOut[i][k] = audioOut[i][k] * balRangeR;
- audioOut[i][k] += oldBufLeft[k] * balRangeL;
- }
- }
- }
-
- // Volume (and buffer copy)
- if (doVolume)
- {
- for (uint32_t k=0; k < frames; ++k)
- audioOut[i][k] *= pData->postProc.volume;
- }
- }
-
- } // End of Post-processing
- #endif
- // --------------------------------------------------------------------------------------------------------
-
- pData->singleMutex.unlock();
- return true;
- }
-
- void bufferSizeChanged(const uint32_t newBufferSize) override
- {
- fBufferSize = newBufferSize;
- resizeAudioPool(newBufferSize);
-
- {
- fShmRtClientControl.writeOpcode(kPluginBridgeRtClientSetBufferSize);
- fShmRtClientControl.writeUInt(newBufferSize);
- fShmRtClientControl.commitWrite();
- }
-
- //fProcWaitTime = newBufferSize*1000/pData->engine->getSampleRate();
- fProcWaitTime = 1000;
-
- waitForClient("buffersize", 1000);
- }
-
- void sampleRateChanged(const double newSampleRate) override
- {
- {
- fShmRtClientControl.writeOpcode(kPluginBridgeRtClientSetSampleRate);
- fShmRtClientControl.writeDouble(newSampleRate);
- fShmRtClientControl.commitWrite();
- }
-
- //fProcWaitTime = pData->engine->getBufferSize()*1000/newSampleRate;
- fProcWaitTime = 1000;
-
- waitForClient("samplerate", 1000);
- }
-
- void offlineModeChanged(const bool isOffline) override
- {
- {
- fShmRtClientControl.writeOpcode(kPluginBridgeRtClientSetOnline);
- fShmRtClientControl.writeBool(isOffline);
- fShmRtClientControl.commitWrite();
- }
-
- waitForClient("offline", 1000);
- }
-
- // -------------------------------------------------------------------
- // Post-poned UI Stuff
-
- // -------------------------------------------------------------------
-
- void handleNonRtData()
- {
- for (; fShmNonRtServerControl.isDataAvailableForReading();)
- {
- const PluginBridgeNonRtServerOpcode opcode(fShmNonRtServerControl.readOpcode());
- //#ifdef DEBUG
- if (opcode != kPluginBridgeNonRtServerPong)
- {
- carla_debug("CarlaPluginJack::handleNonRtData() - got opcode: %s", PluginBridgeNonRtServerOpcode2str(opcode));
- }
- //#endif
- switch (opcode)
- {
- case kPluginBridgeNonRtServerNull:
- case kPluginBridgeNonRtServerPong:
- case kPluginBridgeNonRtServerPluginInfo1:
- case kPluginBridgeNonRtServerPluginInfo2:
- case kPluginBridgeNonRtServerAudioCount:
- case kPluginBridgeNonRtServerMidiCount:
- case kPluginBridgeNonRtServerCvCount:
- case kPluginBridgeNonRtServerParameterCount:
- case kPluginBridgeNonRtServerProgramCount:
- case kPluginBridgeNonRtServerMidiProgramCount:
- case kPluginBridgeNonRtServerPortName:
- case kPluginBridgeNonRtServerParameterData1:
- case kPluginBridgeNonRtServerParameterData2:
- case kPluginBridgeNonRtServerParameterRanges:
- case kPluginBridgeNonRtServerParameterValue:
- case kPluginBridgeNonRtServerParameterValue2:
- case kPluginBridgeNonRtServerParameterTouch:
- case kPluginBridgeNonRtServerDefaultValue:
- case kPluginBridgeNonRtServerCurrentProgram:
- case kPluginBridgeNonRtServerCurrentMidiProgram:
- case kPluginBridgeNonRtServerProgramName:
- case kPluginBridgeNonRtServerMidiProgramData:
- case kPluginBridgeNonRtServerSetCustomData:
- case kPluginBridgeNonRtServerVersion:
- break;
-
- case kPluginBridgeNonRtServerSetChunkDataFile:
- // uint/size, str[] (filename)
- if (const uint32_t chunkFilePathSize = fShmNonRtServerControl.readUInt())
- {
- char chunkFilePath[chunkFilePathSize];
- fShmNonRtServerControl.readCustomData(chunkFilePath, chunkFilePathSize);
- }
- break;
-
- case kPluginBridgeNonRtServerSetLatency:
- case kPluginBridgeNonRtServerSetParameterText:
- break;
-
- case kPluginBridgeNonRtServerReady:
- fInitiated = true;
- break;
-
- case kPluginBridgeNonRtServerSaved:
- break;
-
- case kPluginBridgeNonRtServerUiClosed:
- pData->engine->callback(true, true,
- ENGINE_CALLBACK_UI_STATE_CHANGED,
- pData->id,
- 0,
- 0, 0, 0.0f, nullptr);
- break;
-
- case kPluginBridgeNonRtServerError: {
- // error
- const uint32_t errorSize(fShmNonRtServerControl.readUInt());
- char error[errorSize+1];
- carla_zeroChars(error, errorSize+1);
- fShmNonRtServerControl.readCustomData(error, errorSize);
-
- if (fInitiated)
- {
- pData->engine->callback(true, true, ENGINE_CALLBACK_ERROR, pData->id, 0, 0, 0, 0.0f, error);
-
- // just in case
- pData->engine->setLastError(error);
- fInitError = true;
- }
- else
- {
- pData->engine->setLastError(error);
- fInitError = true;
- fInitiated = true;
- }
- } break;
- }
- }
- }
-
- // -------------------------------------------------------------------
-
- uintptr_t getUiBridgeProcessId() const noexcept override
- {
- return fBridgeThread.getProcessID();
- }
-
- // -------------------------------------------------------------------
-
- bool init(const CarlaPluginPtr plugin,
- const char* const filename, const char* const name, const char* const label, const uint options)
- {
- 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;
- }
-
- // ---------------------------------------------------------------
- // check setup
-
- if (std::strlen(label) < 6)
- {
- pData->engine->setLastError("invalid application setup received");
- return false;
- }
-
- for (int i=4; --i >= 0;) {
- CARLA_SAFE_ASSERT_INT2_RETURN(label[i] >= '0' && label[i] <= '0'+64, i, label[i], false);
- }
- CARLA_SAFE_ASSERT_INT2_RETURN(label[4] >= '0' && label[4] < '0'+0x4f, 4, label[4], false);
- CARLA_SAFE_ASSERT_UINT2_RETURN(static_cast<uchar>(label[5]) >= '0' &&
- static_cast<uchar>(label[5]) <= '0'+0x73,
- static_cast<uchar>(label[5]),
- static_cast<uchar>('0'+0x73),
- false);
-
- fInfo.aIns = static_cast<uint8_t>(label[0] - '0');
- fInfo.aOuts = static_cast<uint8_t>(label[1] - '0');
- fInfo.mIns = static_cast<uint8_t>(carla_minPositive(label[2] - '0', 1));
- fInfo.mOuts = static_cast<uint8_t>(carla_minPositive(label[3] - '0', 1));
-
- fInfo.setupLabel = label;
-
- // ---------------------------------------------------------------
- // set project unique id
-
- if (label[6] == '\0')
- setupUniqueProjectID();
-
- // ---------------------------------------------------------------
- // set icon
-
- pData->iconName = carla_strdup_safe("application");
-
- // ---------------------------------------------------------------
- // set info
-
- pData->filename = carla_strdup(filename);
-
- if (name != nullptr && name[0] != '\0')
- pData->name = pData->engine->getUniquePluginName(name);
- else
- pData->name = pData->engine->getUniquePluginName("Jack Application");
-
- std::srand(static_cast<uint>(std::time(nullptr)));
-
- // ---------------------------------------------------------------
- // init sem/shm
-
- if (! fShmAudioPool.initializeServer())
- {
- carla_stderr("Failed to initialize shared memory audio pool");
- return false;
- }
-
- if (! fShmRtClientControl.initializeServer())
- {
- carla_stderr("Failed to initialize RT client control");
- fShmAudioPool.clear();
- return false;
- }
-
- if (! fShmNonRtClientControl.initializeServer())
- {
- carla_stderr("Failed to initialize Non-RT client control");
- fShmRtClientControl.clear();
- fShmAudioPool.clear();
- return false;
- }
-
- if (! fShmNonRtServerControl.initializeServer())
- {
- carla_stderr("Failed to initialize Non-RT server control");
- fShmNonRtClientControl.clear();
- fShmRtClientControl.clear();
- fShmAudioPool.clear();
- return false;
- }
-
- // ---------------------------------------------------------------
- // setup hints and options
-
- fSetupHints = static_cast<uint>(static_cast<uchar>(label[5]) - '0');
-
- // FIXME dryWet broken
- pData->hints = PLUGIN_IS_BRIDGE;
- #ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH
- pData->hints |= /*PLUGIN_CAN_DRYWET |*/ PLUGIN_CAN_VOLUME | PLUGIN_CAN_BALANCE;
- #endif
-
- if (fSetupHints & LIBJACK_FLAG_CONTROL_WINDOW)
- pData->hints |= PLUGIN_HAS_CUSTOM_UI;
-
- // ---------------------------------------------------------------
- // init bridge thread
-
- {
- char shmIdsStr[6*4+1];
- carla_zeroChars(shmIdsStr, 6*4+1);
-
- std::strncpy(shmIdsStr+6*0, &fShmAudioPool.filename[fShmAudioPool.filename.length()-6], 6);
- std::strncpy(shmIdsStr+6*1, &fShmRtClientControl.filename[fShmRtClientControl.filename.length()-6], 6);
- std::strncpy(shmIdsStr+6*2, &fShmNonRtClientControl.filename[fShmNonRtClientControl.filename.length()-6], 6);
- std::strncpy(shmIdsStr+6*3, &fShmNonRtServerControl.filename[fShmNonRtServerControl.filename.length()-6], 6);
-
- fBridgeThread.setData(shmIdsStr, fInfo.setupLabel);
- }
-
- if (! restartBridgeThread())
- return false;
-
- // ---------------------------------------------------------------
- // register client
-
- if (pData->name == nullptr)
- pData->name = pData->engine->getUniquePluginName("unknown");
-
- pData->client = pData->engine->addClient(plugin);
-
- if (pData->client == nullptr || ! pData->client->isOk())
- {
- pData->engine->setLastError("Failed to register plugin client");
- return false;
- }
-
- // remove unprintable characters if needed
- if (fSetupHints & LIBJACK_FLAG_EXTERNAL_START)
- fInfo.setupLabel[5U] = static_cast<char>('0' + (fSetupHints ^ LIBJACK_FLAG_EXTERNAL_START));
-
- // ---------------------------------------------------------------
- // set options
-
- pData->options = PLUGIN_OPTION_FIXED_BUFFERS;
-
- if (isPluginOptionEnabled(options, PLUGIN_OPTION_SEND_CONTROL_CHANGES))
- pData->options |= PLUGIN_OPTION_SEND_CONTROL_CHANGES;
-
- if (isPluginOptionEnabled(options, PLUGIN_OPTION_SEND_CHANNEL_PRESSURE))
- pData->options |= PLUGIN_OPTION_SEND_CHANNEL_PRESSURE;
-
- if (isPluginOptionEnabled(options, PLUGIN_OPTION_SEND_NOTE_AFTERTOUCH))
- pData->options |= PLUGIN_OPTION_SEND_NOTE_AFTERTOUCH;
-
- if (isPluginOptionEnabled(options, PLUGIN_OPTION_SEND_PITCHBEND))
- pData->options |= PLUGIN_OPTION_SEND_PITCHBEND;
-
- if (isPluginOptionEnabled(options, PLUGIN_OPTION_SEND_ALL_SOUND_OFF))
- pData->options |= PLUGIN_OPTION_SEND_ALL_SOUND_OFF;
-
- if (isPluginOptionEnabled(options, PLUGIN_OPTION_SEND_PROGRAM_CHANGES))
- pData->options |= PLUGIN_OPTION_SEND_PROGRAM_CHANGES;
-
- if (isPluginOptionInverseEnabled(options, PLUGIN_OPTION_SKIP_SENDING_NOTES))
- pData->options |= PLUGIN_OPTION_SKIP_SENDING_NOTES;
-
- return true;
- }
-
- private:
- bool fInitiated;
- bool fInitError;
- bool fTimedOut;
- bool fTimedError;
- bool fProcCanceled;
- uint fBufferSize;
- uint fProcWaitTime;
- uint fSetupHints;
-
- CarlaPluginJackThread fBridgeThread;
-
- BridgeAudioPool fShmAudioPool;
- BridgeRtClientControl fShmRtClientControl;
- BridgeNonRtClientControl fShmNonRtClientControl;
- BridgeNonRtServerControl fShmNonRtServerControl;
-
- struct Info {
- uint8_t aIns, aOuts;
- uint8_t mIns, mOuts;
- CarlaString setupLabel;
- std::vector<uint8_t> chunk;
-
- Info()
- : aIns(0),
- aOuts(0),
- mIns(0),
- mOuts(0),
- setupLabel(),
- chunk() {}
-
- CARLA_DECLARE_NON_COPY_STRUCT(Info)
- } fInfo;
-
- void handleProcessStopped() noexcept
- {
- const bool wasActive = pData->active;
- pData->active = false;
-
- if (wasActive)
- {
- pData->engine->callback(true, true,
- ENGINE_CALLBACK_PARAMETER_VALUE_CHANGED,
- pData->id,
- PARAMETER_ACTIVE,
- 0, 0,
- 0.0f,
- nullptr);
- }
-
- if (pData->hints & PLUGIN_HAS_CUSTOM_UI)
- pData->engine->callback(true, true,
- ENGINE_CALLBACK_UI_STATE_CHANGED,
- pData->id,
- 0,
- 0, 0, 0.0f, nullptr);
- }
-
- void resizeAudioPool(const uint32_t bufferSize)
- {
- fShmAudioPool.resize(bufferSize, static_cast<uint32_t>(fInfo.aIns+fInfo.aOuts), 0);
-
- fShmRtClientControl.writeOpcode(kPluginBridgeRtClientSetAudioPool);
- fShmRtClientControl.writeULong(static_cast<uint64_t>(fShmAudioPool.dataSize));
- fShmRtClientControl.commitWrite();
-
- waitForClient("resize-pool", 5000);
- }
-
- void setupUniqueProjectID()
- {
- const char* const engineProjectFolder = pData->engine->getCurrentProjectFolder();
- carla_stdout("setupUniqueProjectID %s", engineProjectFolder);
-
- if (engineProjectFolder == nullptr || engineProjectFolder[0] == '\0')
- return;
-
- const File file(engineProjectFolder);
- CARLA_SAFE_ASSERT_RETURN(file.exists(),);
-
- char code[6];
- code[5] = '\0';
-
- String child;
-
- for (;;)
- {
- static const char* const kValidChars =
- "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
- "abcdefghijklmnopqrstuvwxyz"
- "0123456789";
-
- static const size_t kValidCharsLen(std::strlen(kValidChars)-1U);
-
- code[0] = kValidChars[safe_rand(kValidCharsLen)];
- code[1] = kValidChars[safe_rand(kValidCharsLen)];
- code[2] = kValidChars[safe_rand(kValidCharsLen)];
- code[3] = kValidChars[safe_rand(kValidCharsLen)];
- code[4] = kValidChars[safe_rand(kValidCharsLen)];
-
- child = pData->name;
- child += ".";
- child += code;
- const File newFile(file.getChildFile(child));
-
- if (newFile.existsAsFile())
- continue;
-
- fInfo.setupLabel += code;
- carla_stdout("new label %s", fInfo.setupLabel.buffer());
- break;
- }
- }
-
- bool restartBridgeThread()
- {
- fInitiated = false;
- fInitError = false;
- fTimedError = false;
-
- // reset memory
- fProcCanceled = false;
- fShmRtClientControl.data->procFlags = 0;
- carla_zeroStruct(fShmRtClientControl.data->timeInfo);
- carla_zeroBytes(fShmRtClientControl.data->midiOut, kBridgeRtClientDataMidiOutSize);
-
- fShmRtClientControl.clearData();
- fShmNonRtClientControl.clearData();
- fShmNonRtServerControl.clearData();
-
- // initial values
- fShmNonRtClientControl.writeOpcode(kPluginBridgeNonRtClientVersion);
- fShmNonRtClientControl.writeUInt(CARLA_PLUGIN_BRIDGE_API_VERSION_CURRENT);
-
- fShmNonRtClientControl.writeUInt(static_cast<uint32_t>(sizeof(BridgeRtClientData)));
- fShmNonRtClientControl.writeUInt(static_cast<uint32_t>(sizeof(BridgeNonRtClientData)));
- fShmNonRtClientControl.writeUInt(static_cast<uint32_t>(sizeof(BridgeNonRtServerData)));
-
- fShmNonRtClientControl.writeOpcode(kPluginBridgeNonRtClientInitialSetup);
- fShmNonRtClientControl.writeUInt(pData->engine->getBufferSize());
- fShmNonRtClientControl.writeDouble(pData->engine->getSampleRate());
-
- fShmNonRtClientControl.commitWrite();
-
- if (fShmAudioPool.dataSize != 0)
- {
- fShmRtClientControl.writeOpcode(kPluginBridgeRtClientSetAudioPool);
- fShmRtClientControl.writeULong(static_cast<uint64_t>(fShmAudioPool.dataSize));
- fShmRtClientControl.commitWrite();
- }
- else
- {
- // testing dummy message
- fShmRtClientControl.writeOpcode(kPluginBridgeRtClientNull);
- fShmRtClientControl.commitWrite();
- }
-
- fBridgeThread.startThread();
-
- const bool needsCancelableAction = ! pData->engine->isLoadingProject();
- const bool needsEngineIdle = pData->engine->getType() != kEngineTypePlugin;
-
- CarlaString actionName;
-
- if (needsCancelableAction)
- {
- if (fSetupHints & LIBJACK_FLAG_EXTERNAL_START)
- {
- const EngineOptions& options(pData->engine->getOptions());
- CarlaString binaryDir(options.binaryDir);
-
- char* const hwVars = fBridgeThread.getEnvVarsToExport();
-
- actionName = "Waiting for external JACK application start, please use the following environment variables:\n";
- actionName += hwVars;
-
- delete[] hwVars;
- }
- else
- {
- actionName = "Loading JACK application";
- }
-
- pData->engine->setActionCanceled(false);
- pData->engine->callback(true, true,
- ENGINE_CALLBACK_CANCELABLE_ACTION,
- pData->id,
- 1,
- 0, 0, 0.0f,
- actionName.buffer());
- }
-
- for (;fBridgeThread.isThreadRunning();)
- {
- pData->engine->callback(true, false, ENGINE_CALLBACK_IDLE, 0, 0, 0, 0, 0.0f, nullptr);
-
- if (needsEngineIdle)
- pData->engine->idle();
-
- idle();
-
- if (fInitiated)
- break;
- if (pData->engine->isAboutToClose() || pData->engine->wasActionCanceled())
- break;
-
- carla_msleep(5);
- }
-
- if (needsCancelableAction)
- {
- pData->engine->callback(true, true,
- ENGINE_CALLBACK_CANCELABLE_ACTION,
- pData->id,
- 0,
- 0, 0, 0.0f,
- actionName.buffer());
- }
-
- if (fInitError || ! fInitiated)
- {
- fBridgeThread.stopThread(6000);
-
- if (! fInitError)
- pData->engine->setLastError("Timeout while waiting for a response from plugin-bridge\n"
- "(or the plugin crashed on initialization?)");
-
- return false;
- }
-
- return true;
- }
-
- void waitForClient(const char* const action, const uint msecs)
- {
- CARLA_SAFE_ASSERT_RETURN(! fTimedOut,);
- CARLA_SAFE_ASSERT_RETURN(! fTimedError,);
-
- if (fShmRtClientControl.waitForClient(msecs))
- return;
-
- fTimedOut = true;
- carla_stderr2("waitForClient(%s) timed out", action);
- }
-
- CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(CarlaPluginJack)
- };
-
- CARLA_BACKEND_END_NAMESPACE
-
- #endif // CARLA_OS_LINUX
-
- // -------------------------------------------------------------------------------------------------------------------
-
- CARLA_BACKEND_START_NAMESPACE
-
- CarlaPluginPtr CarlaPlugin::newJackApp(const Initializer& init)
- {
- carla_debug("CarlaPlugin::newJackApp({%p, \"%s\", \"%s\", \"%s\"})",
- init.engine, init.filename, init.name, init.label);
-
- #ifdef CARLA_OS_LINUX
- std::shared_ptr<CarlaPluginJack> plugin(new CarlaPluginJack(init.engine, init.id));
-
- if (! plugin->init(plugin, init.filename, init.name, init.label, init.options))
- return nullptr;
-
- return plugin;
- #else
- init.engine->setLastError("JACK Application support not available");
- return nullptr;
- #endif
- }
-
- CARLA_BACKEND_END_NAMESPACE
-
- // -------------------------------------------------------------------------------------------------------------------
|