|
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227 |
- /*
- * Carla Standalone
- * Copyright (C) 2011-2013 Filipe Coelho <falktx@falktx.com>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of
- * the License, or any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * For a full copy of the GNU General Public License see the doc/GPL.txt file.
- */
-
- // TODO:
- // Check carla_stderr2("Engine is not running"); <= prepend func name and args
-
- #include "CarlaHost.hpp"
- #include "CarlaEngine.hpp"
- #include "CarlaPlugin.hpp"
-
- #include "CarlaBackendUtils.hpp"
- #include "CarlaOscUtils.hpp"
- #include "CarlaNative.h"
-
- #include "juce_gui_basics.h"
-
- //#include "CarlaLogThread.hpp"
- //#if ! (defined(DEBUG) || defined(WANT_LOGS) || defined(BUILD_ANSI_TEST))
- //# define WANT_LOGS
- //#endif
-
- namespace CB = CarlaBackend;
-
- using CB::CarlaEngine;
- using CB::CarlaPlugin;
- using CB::CallbackFunc;
- using CB::EngineOptions;
- using CB::EngineTimeInfo;
-
- //using juce::MessageManager;
-
- using namespace juce;
-
- // -----------------------------------------------------------------------
- // Juce Message Thread
-
- class JuceMessageThread : public Thread
- {
- public:
- JuceMessageThread()
- : Thread("JuceMessageThread"),
- fInitialised(false)
- {
- startThread(7);
-
- while (! fInitialised)
- sleep(1);
- }
-
- ~JuceMessageThread()
- {
- signalThreadShouldExit();
- JUCEApplication::quit();
- waitForThreadToExit(5000);
- clearSingletonInstance();
- }
-
- void run()
- {
- initialiseJuce_GUI();
- fInitialised = true;
-
- MessageManager::getInstance()->setCurrentThreadAsMessageThread();
-
- while ((! threadShouldExit()) && MessageManager::getInstance()->runDispatchLoopUntil(250))
- {}
- }
-
- juce_DeclareSingleton(JuceMessageThread, false);
-
- private:
- bool fInitialised;
- };
-
- juce_ImplementSingleton(JuceMessageThread)
-
- // -------------------------------------------------------------------------------------------------------------------
- // Single, standalone engine
-
- struct CarlaBackendStandalone {
- CallbackFunc callback;
- void* callbackPtr;
- CarlaEngine* engine;
- CarlaString lastError;
- EngineOptions options;
-
- CarlaBackendStandalone()
- : callback(nullptr),
- callbackPtr(nullptr),
- engine(nullptr) {}
-
- ~CarlaBackendStandalone()
- {
- CARLA_ASSERT(engine == nullptr);
- //CARLA_ASSERT(MessageManager::getInstanceWithoutCreating() == nullptr);
- }
-
- #if 1
- void init()
- {
- JUCE_AUTORELEASEPOOL
-
- initialiseJuce_GUI();
- JuceMessageThread::getInstance();
- }
-
- void idle() {}
-
- void close()
- {
- JUCE_AUTORELEASEPOOL
-
- JuceMessageThread::deleteInstance();
- shutdownJuce_GUI();
- }
- #else
- void init()
- {
- juce::initialiseJuce_GUI();
-
- if (MessageManager* const mgr = MessageManager::getInstance())
- mgr->setCurrentThreadAsMessageThread();
- }
-
- void idle()
- {
- if (MessageManager* const mgr = MessageManager::getInstanceWithoutCreating())
- mgr->runDispatchLoopUntil(5);
- }
-
- void close()
- {
- if (MessageManager* const mgr = MessageManager::getInstanceWithoutCreating())
- mgr->stopDispatchLoop();
-
- juce::shutdownJuce_GUI();
- }
- #endif
-
- CARLA_DECLARE_NON_COPY_STRUCT(CarlaBackendStandalone)
- };
-
- //#ifdef WANT_LOGS
- //static CarlaLogThread gLogThread;
- //#endif
- static CarlaBackendStandalone gStandalone;
-
- // -------------------------------------------------------------------------------------------------------------------
- // API
-
- const char* carla_get_extended_license_text()
- {
- carla_debug("carla_get_extended_license_text()");
-
- static CarlaString retText;
-
- if (retText.isEmpty())
- {
- CarlaString text1, text2, text3, text4, text5;
-
- text1 += "<p>This current Carla build is using the following features and 3rd-party code:</p>";
- text1 += "<ul>";
-
- // Plugin formats
- #ifdef WANT_LADSPA
- text2 += "<li>LADSPA plugin support, http://www.ladspa.org/</li>";
- #endif
- #ifdef WANT_DSSI
- text2 += "<li>DSSI plugin support, http://dssi.sourceforge.net/</li>";
- #endif
- #ifdef WANT_LV2
- text2 += "<li>LV2 plugin support, http://lv2plug.in/</li>";
- #endif
- #ifdef WANT_VST
- # ifdef VESTIGE_HEADER
- text2 += "<li>VST plugin support, using VeSTige header by Javier Serrano Polo</li>";
- # else
- text2 += "<li>VST plugin support, using official VST SDK 2.4 (trademark of Steinberg Media Technologies GmbH)</li>";
- # endif
- #endif
- #ifdef WANT_AU
- text2 += "<li>AU plugin support</li>"; // FIXME
- #endif
-
- // Files
- #ifdef WANT_CSOUND
- text2 += "<li>CSound library for csd support</li>"; // FIXME
- #endif
-
- // Sample kit libraries
- #ifdef WANT_FLUIDSYNTH
- text2 += "<li>FluidSynth library for SF2 support, http://www.fluidsynth.org/</li>";
- #endif
- #ifdef WANT_LINUXSAMPLER
- text2 += "<li>LinuxSampler library for GIG and SFZ support*, http://www.linuxsampler.org/</li>";
- #endif
-
- // Internal plugins
- #ifdef WANT_OPENGL
- text3 += "<li>DISTRHO Mini-Series plugin code, based on LOSER-dev suite by Michael Gruhn</li>";
- #endif
- text3 += "<li>NekoFilter plugin code, based on lv2fil by Nedko Arnaudov and Fons Adriaensen</li>";
- //text1 += "<li>SunVox library file support, http://www.warmplace.ru/soft/sunvox/</li>"; // unfinished
-
- #ifdef WANT_AUDIOFILE
- text3 += "<li>AudioDecoder library for Audio file support, by Robin Gareus</li>";
- #endif
- #ifdef WANT_MIDIFILE
- text3 += "<li>LibSMF library for MIDI file support, http://libsmf.sourceforge.net/</li>";
- #endif
- #ifdef WANT_ZYNADDSUBFX
- text3 += "<li>ZynAddSubFX plugin code, http://zynaddsubfx.sf.net/</li>";
- # ifdef WANT_ZYNADDSUBFX_UI
- text3 += "<li>ZynAddSubFX UI using NTK, http://non.tuxfamily.org/wiki/NTK</li>";
- # endif
- #endif
-
- // misc libs
- text4 += "<li>liblo library for OSC support, http://liblo.sourceforge.net/</li>";
- #ifdef WANT_LV2
- text4 += "<li>serd, sord, sratom and lilv libraries for LV2 discovery, http://drobilla.net/software/lilv/</li>";
- #endif
- text4 += "<li>RtAudio+RtMidi libraries for extra Audio and MIDI support, http://www.music.mcgill.ca/~gary/rtaudio/</li>";
-
- // end
- text4 += "</ul>";
-
- // code snippets
- text5 += "<p>Additionally, Carla uses code snippets from the following projects:</p>";
- text5 += "<ul>";
- text5 += "<li>Pointer and data leak utils from JUCE, http://www.rawmaterialsoftware.com/juce.php</li>";
- text5 += "<li>Shared memory utils from dssi-vst, http://www.breakfastquay.com/dssi-vst/</li>";
- text5 += "<li>Real-time memory pool, by Nedko Arnaudov</li>";
- text5 += "</ul>";
-
- // LinuxSampler GPL exception
- #ifdef WANT_LINUXSAMPLER
- text5 += "<p>(*) Using LinuxSampler code in commercial hardware or software products is not allowed without prior written authorization by the authors.</p>";
- #endif
-
- retText = text1 + text2 + text3 + text4 + text5;
- }
-
- return retText;
- }
-
- const char* carla_get_supported_file_types()
- {
- carla_debug("carla_get_supported_file_types()");
-
- static CarlaString retText;
-
- if (retText.isEmpty())
- {
- // Base types
- retText += "*.carxp;*.carxs";
-
- // CSound
- #ifdef WANT_CSOUND
- retText += ";*.csd";
- #endif
-
- // Sample kits
- #ifdef WANT_FLUIDSYNTH
- retText += ";*.sf2";
- #endif
- #ifdef WANT_LINUXSAMPLER
- retText += ";*.gig;*.sfz";
- #endif
-
- // Files provided by internal plugins
- #ifdef WANT_AUDIOFILE
- retText += ";*.aiff;*.flac;*.oga;*.ogg;*.w64;*.wav";
- # ifdef HAVE_FFMPEG
- retText += ";*.3g2;*.3gp;*.aac;*.ac3;*.amr;*.ape;*.mp2;*.mp3;*.mpc;*.wma";
- # endif
- #endif
- #ifdef WANT_MIDIFILE
- retText += ";*.mid;*.midi";
- #endif
-
- // Plugin presets
- #ifdef WANT_ZYNADDSUBFX
- retText += ";*.xmz;*.xiz";
- #endif
- }
-
- return retText;
- }
-
- // -------------------------------------------------------------------------------------------------------------------
-
- unsigned int carla_get_engine_driver_count()
- {
- carla_debug("carla_get_engine_driver_count()");
-
- return CarlaEngine::getDriverCount();
- }
-
- const char* carla_get_engine_driver_name(unsigned int index)
- {
- carla_debug("carla_get_engine_driver_name(%i)", index);
-
- return CarlaEngine::getDriverName(index);
- }
-
- const char** carla_get_engine_driver_device_names(unsigned int index)
- {
- carla_debug("carla_get_engine_driver_device_names(%i)", index);
-
- return CarlaEngine::getDriverDeviceNames(index);
- }
-
- // -------------------------------------------------------------------------------------------------------------------
-
- unsigned int carla_get_internal_plugin_count()
- {
- carla_debug("carla_get_internal_plugin_count()");
-
- #ifdef WANT_NATIVE
- return static_cast<unsigned int>(CarlaPlugin::getNativePluginCount());
- #else
- return 0;
- #endif
- }
-
- const CarlaNativePluginInfo* carla_get_internal_plugin_info(unsigned int internalPluginId)
- {
- carla_debug("carla_get_internal_plugin_info(%i)", internalPluginId);
-
- static CarlaNativePluginInfo info;
-
- #ifdef WANT_NATIVE
- const PluginDescriptor* const nativePlugin(CarlaPlugin::getNativePluginDescriptor(internalPluginId));
-
- // as internal plugin, this must never fail
- CARLA_SAFE_ASSERT_RETURN(nativePlugin != nullptr, nullptr);
-
- info.category = static_cast<CarlaPluginCategory>(nativePlugin->category);
- info.hints = 0x0;
-
- if (nativePlugin->hints & PLUGIN_IS_RTSAFE)
- info.hints |= CB::PLUGIN_IS_RTSAFE;
- if (nativePlugin->hints & PLUGIN_HAS_GUI)
- info.hints |= CB::PLUGIN_HAS_GUI;
- if (nativePlugin->hints & PLUGIN_NEEDS_SINGLE_THREAD)
- info.hints |= CB::PLUGIN_NEEDS_SINGLE_THREAD;
- if (nativePlugin->hints & PLUGIN_NEEDS_FIXED_BUFFERS)
- info.hints |= CB::PLUGIN_NEEDS_FIXED_BUFFERS;
-
- info.audioIns = nativePlugin->audioIns;
- info.audioOuts = nativePlugin->audioOuts;
- info.midiIns = nativePlugin->midiIns;
- info.midiOuts = nativePlugin->midiOuts;
- info.parameterIns = nativePlugin->paramIns;
- info.parameterOuts = nativePlugin->paramOuts;
-
- info.name = nativePlugin->name;
- info.label = nativePlugin->label;
- info.maker = nativePlugin->maker;
- info.copyright = nativePlugin->copyright;
- #endif
-
- return &info;
-
- #ifndef WANT_NATIVE
- // unused
- (void)internalPluginId;
- #endif
- }
-
- // -------------------------------------------------------------------------------------------------------------------
-
- bool carla_engine_init(const char* driverName, const char* clientName)
- {
- CARLA_SAFE_ASSERT_RETURN(driverName != nullptr && driverName[0] != '\0', false);
- CARLA_SAFE_ASSERT_RETURN(clientName != nullptr && clientName[0] != '\0', false);
- carla_debug("carla_engine_init(\"%s\", \"%s\")", driverName, clientName);
-
- if (gStandalone.engine != nullptr)
- {
- carla_stderr2("Engine is already running");
- gStandalone.lastError = "Engine is already running";
- return false;
- }
-
- #ifdef Q_OS_WIN
- carla_setenv("WINEASIO_CLIENT_NAME", clientName);
- #endif
-
- // TODO: make this an option, put somewhere else
- if (getenv("WINE_RT") == nullptr)
- {
- carla_setenv("WINE_RT", "15");
- carla_setenv("WINE_SVR_RT", "10");
- }
-
- gStandalone.engine = CarlaEngine::newDriverByName(driverName);
-
- if (gStandalone.engine == nullptr)
- {
- carla_stderr2("The seleted audio driver is not available");
- gStandalone.lastError = "The seleted audio driver is not available";
- return false;
- }
-
- if (gStandalone.callback != nullptr)
- gStandalone.engine->setCallback(gStandalone.callback, gStandalone.callbackPtr);
-
- #ifndef BUILD_BRIDGE
- gStandalone.engine->setOption(CB::OPTION_PROCESS_MODE, static_cast<int>(gStandalone.options.processMode), nullptr);
- gStandalone.engine->setOption(CB::OPTION_TRANSPORT_MODE, static_cast<int>(gStandalone.options.transportMode), nullptr);
- #endif
- gStandalone.engine->setOption(CB::OPTION_FORCE_STEREO, gStandalone.options.forceStereo ? 1 : 0, nullptr);
- gStandalone.engine->setOption(CB::OPTION_PREFER_PLUGIN_BRIDGES, gStandalone.options.preferPluginBridges ? 1 : 0, nullptr);
- gStandalone.engine->setOption(CB::OPTION_PREFER_UI_BRIDGES, gStandalone.options.preferUiBridges ? 1 : 0, nullptr);
- gStandalone.engine->setOption(CB::OPTION_UIS_ALWAYS_ON_TOP, gStandalone.options.uisAlwaysOnTop ? 1 : 0, nullptr);
- gStandalone.engine->setOption(CB::OPTION_MAX_PARAMETERS, static_cast<int>(gStandalone.options.maxParameters), nullptr);
- gStandalone.engine->setOption(CB::OPTION_UI_BRIDGES_TIMEOUT, static_cast<int>(gStandalone.options.uiBridgesTimeout), nullptr);
- gStandalone.engine->setOption(CB::OPTION_AUDIO_NUM_PERIODS, static_cast<int>(gStandalone.options.audioNumPeriods), nullptr);
- gStandalone.engine->setOption(CB::OPTION_AUDIO_BUFFER_SIZE, static_cast<int>(gStandalone.options.audioBufferSize), nullptr);
- gStandalone.engine->setOption(CB::OPTION_AUDIO_SAMPLE_RATE, static_cast<int>(gStandalone.options.audioSampleRate), nullptr);
- gStandalone.engine->setOption(CB::OPTION_AUDIO_DEVICE, 0, (const char*)gStandalone.options.audioDevice);
- gStandalone.engine->setOption(CB::OPTION_PATH_RESOURCES, 0, (const char*)gStandalone.options.resourceDir);
- #ifndef BUILD_BRIDGE
- gStandalone.engine->setOption(CB::OPTION_PATH_BRIDGE_NATIVE, 0, (const char*)gStandalone.options.bridge_native);
- gStandalone.engine->setOption(CB::OPTION_PATH_BRIDGE_POSIX32, 0, (const char*)gStandalone.options.bridge_posix32);
- gStandalone.engine->setOption(CB::OPTION_PATH_BRIDGE_POSIX64, 0, (const char*)gStandalone.options.bridge_posix64);
- gStandalone.engine->setOption(CB::OPTION_PATH_BRIDGE_WIN32, 0, (const char*)gStandalone.options.bridge_win32);
- gStandalone.engine->setOption(CB::OPTION_PATH_BRIDGE_WIN64, 0, (const char*)gStandalone.options.bridge_win64);
- #endif
- #ifdef WANT_LV2
- gStandalone.engine->setOption(CB::OPTION_PATH_BRIDGE_LV2_EXTERNAL, 0, (const char*)gStandalone.options.bridge_lv2Extrn);
- gStandalone.engine->setOption(CB::OPTION_PATH_BRIDGE_LV2_GTK2, 0, (const char*)gStandalone.options.bridge_lv2Gtk2);
- gStandalone.engine->setOption(CB::OPTION_PATH_BRIDGE_LV2_GTK3, 0, (const char*)gStandalone.options.bridge_lv2Gtk3);
- gStandalone.engine->setOption(CB::OPTION_PATH_BRIDGE_LV2_QT4, 0, (const char*)gStandalone.options.bridge_lv2Qt4);
- gStandalone.engine->setOption(CB::OPTION_PATH_BRIDGE_LV2_QT5, 0, (const char*)gStandalone.options.bridge_lv2Qt5);
- gStandalone.engine->setOption(CB::OPTION_PATH_BRIDGE_LV2_COCOA, 0, (const char*)gStandalone.options.bridge_lv2Cocoa);
- gStandalone.engine->setOption(CB::OPTION_PATH_BRIDGE_LV2_WINDOWS, 0, (const char*)gStandalone.options.bridge_lv2Win);
- gStandalone.engine->setOption(CB::OPTION_PATH_BRIDGE_LV2_X11, 0, (const char*)gStandalone.options.bridge_lv2X11);
- #endif
- #ifdef WANT_VST
- gStandalone.engine->setOption(CB::OPTION_PATH_BRIDGE_VST_MAC, 0, (const char*)gStandalone.options.bridge_vstMac);
- gStandalone.engine->setOption(CB::OPTION_PATH_BRIDGE_VST_HWND, 0, (const char*)gStandalone.options.bridge_vstHWND);
- gStandalone.engine->setOption(CB::OPTION_PATH_BRIDGE_VST_X11, 0, (const char*)gStandalone.options.bridge_vstX11);
- #endif
-
- if (gStandalone.engine->init(clientName))
- {
- gStandalone.lastError = "no error";
- gStandalone.init();
- return true;
- }
- else
- {
- gStandalone.lastError = gStandalone.engine->getLastError();
- delete gStandalone.engine;
- gStandalone.engine = nullptr;
- return false;
- }
- }
-
- #ifdef BUILD_BRIDGE
- bool carla_engine_init_bridge(const char* audioBaseName, const char* controlBaseName, const char* clientName)
- {
- CARLA_SAFE_ASSERT_RETURN(audioBaseName != nullptr && audioBaseName[0] != '\0', false);
- CARLA_SAFE_ASSERT_RETURN(controlBaseName != nullptr && controlBaseName[0] != '\0', false);
- CARLA_SAFE_ASSERT_RETURN(clientName != nullptr && clientName[0] != '\0', false);
- carla_debug("carla_engine_init_bridge(\"%s\", %s, %s)", audioBaseName, controlBaseName, clientName);
-
- if (gStandalone.engine != nullptr)
- {
- carla_stderr2("Engine is already running");
- gStandalone.lastError = "Engine is already running";
- return false;
- }
-
- gStandalone.engine = CarlaEngine::newBridge(audioBaseName, controlBaseName);
-
- if (gStandalone.engine == nullptr)
- {
- carla_stderr2("The seleted audio driver is not available!");
- gStandalone.lastError = "The seleted audio driver is not available!";
- return false;
- }
-
- if (gStandalone.callback != nullptr)
- gStandalone.engine->setCallback(gStandalone.callback, gStandalone.callbackPtr);
-
- gStandalone.engine->setOption(CB::OPTION_PROCESS_MODE, CB::PROCESS_MODE_BRIDGE, nullptr);
- gStandalone.engine->setOption(CB::OPTION_TRANSPORT_MODE, CB::TRANSPORT_MODE_BRIDGE, nullptr);
- gStandalone.engine->setOption(CB::OPTION_FORCE_STEREO, false, nullptr);
- gStandalone.engine->setOption(CB::OPTION_PREFER_PLUGIN_BRIDGES, false, nullptr);
- gStandalone.engine->setOption(CB::OPTION_PREFER_UI_BRIDGES, false, nullptr);
- //gStandalone.engine->setOption(CB::OPTION_UIS_ALWAYS_ON_TOP, gStandalone.options.uisAlwaysOnTop ? 1 : 0, nullptr);
- //gStandalone.engine->setOption(CB::OPTION_MAX_PARAMETERS, static_cast<int>(gStandalone.options.maxParameters), nullptr);
- //gStandalone.engine->setOption(CB::OPTION_UI_BRIDGES_TIMEOUT, static_cast<int>(gStandalone.options.uiBridgesTimeout), nullptr);
-
- if (gStandalone.engine->init(clientName))
- {
- gStandalone.lastError = "no error";
- gStandalone.init();
- return true;
- }
- else
- {
- gStandalone.lastError = gStandalone.engine->getLastError();
- delete gStandalone.engine;
- gStandalone.engine = nullptr;
- return false;
- }
- }
- #endif
-
- bool carla_engine_close()
- {
- carla_debug("carla_engine_close()");
-
- if (gStandalone.engine == nullptr)
- {
- carla_stderr2("Engine is not running");
- gStandalone.lastError = "Engine is not running";
- return false;
- }
-
- gStandalone.engine->setAboutToClose();
- gStandalone.engine->removeAllPlugins();
-
- const bool closed(gStandalone.engine->close());
-
- if (! closed)
- gStandalone.lastError = gStandalone.engine->getLastError();
-
- gStandalone.close();
-
- delete gStandalone.engine;
- gStandalone.engine = nullptr;
-
- return closed;
- }
-
- void carla_engine_idle()
- {
- CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr,);
-
- gStandalone.idle();
- gStandalone.engine->idle();
- }
-
- bool carla_is_engine_running()
- {
- return (gStandalone.engine != nullptr && gStandalone.engine->isRunning());
- }
-
- void carla_set_engine_about_to_close()
- {
- CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr,);
- carla_debug("carla_set_engine_about_to_close()");
-
- gStandalone.engine->setAboutToClose();
- }
-
- void carla_set_engine_callback(CarlaCallbackFunc func, void* ptr)
- {
- carla_debug("carla_set_engine_callback(%p, %p)", func, ptr);
-
- gStandalone.callback = func;
- gStandalone.callbackPtr = ptr;
-
- if (gStandalone.engine != nullptr)
- gStandalone.engine->setCallback(func, ptr);
-
- //#ifdef WANT_LOGS
- // gLogThread.setCallback(func, ptr);
- //#endif
- }
-
- void carla_set_engine_option(CarlaOptionsType option, int value, const char* valueStr)
- {
- carla_debug("carla_set_engine_option(%i:%s, %i, \"%s\")", option, CB::OptionsType2Str(option), value, valueStr);
-
- switch (option)
- {
- case CB::OPTION_PROCESS_NAME:
- CARLA_SAFE_ASSERT_RETURN(valueStr != nullptr && valueStr[0] != '\0',);
- juce::Thread::setCurrentThreadName(valueStr);
- break;
-
- case CB::OPTION_PROCESS_MODE:
- CARLA_SAFE_ASSERT_RETURN(value >= CB::PROCESS_MODE_SINGLE_CLIENT && value <= CB::PROCESS_MODE_BRIDGE,);
- gStandalone.options.processMode = static_cast<CB::ProcessMode>(value);
- break;
-
- case CB::OPTION_TRANSPORT_MODE:
- CARLA_SAFE_ASSERT_RETURN(value >= CB::TRANSPORT_MODE_INTERNAL && value <= CB::TRANSPORT_MODE_BRIDGE,);
- gStandalone.options.transportMode = static_cast<CB::TransportMode>(value);
- break;
-
- case CB::OPTION_FORCE_STEREO:
- CARLA_SAFE_ASSERT_RETURN(value == 0 || value == 1,);
- gStandalone.options.forceStereo = (value != 0);
- break;
-
- case CB::OPTION_PREFER_PLUGIN_BRIDGES:
- CARLA_SAFE_ASSERT_RETURN(value == 0 || value == 1,);
- gStandalone.options.preferPluginBridges = (value != 0);
- break;
-
- case CB::OPTION_PREFER_UI_BRIDGES:
- CARLA_SAFE_ASSERT_RETURN(value == 0 || value == 1,);
- gStandalone.options.preferUiBridges = (value != 0);
- break;
-
- case CB::OPTION_UIS_ALWAYS_ON_TOP:
- CARLA_SAFE_ASSERT_RETURN(value == 0 || value == 1,);
- gStandalone.options.uisAlwaysOnTop = (value != 0);
- break;
-
- case CB::OPTION_MAX_PARAMETERS:
- CARLA_SAFE_ASSERT_RETURN(value >= 0,);
- gStandalone.options.maxParameters = static_cast<unsigned int>(value);
- break;
-
- case CB::OPTION_UI_BRIDGES_TIMEOUT:
- CARLA_SAFE_ASSERT_RETURN(value >= 0,);
- gStandalone.options.uiBridgesTimeout = static_cast<unsigned int>(value);
- break;
-
- case CB::OPTION_AUDIO_NUM_PERIODS:
- CARLA_SAFE_ASSERT_RETURN(value == 2 || value == 3,);
- gStandalone.options.audioNumPeriods = static_cast<unsigned int>(value);
- break;
-
- case CB::OPTION_AUDIO_BUFFER_SIZE:
- CARLA_SAFE_ASSERT_RETURN(value >= 8,);
- gStandalone.options.audioBufferSize = static_cast<unsigned int>(value);
- break;
-
- case CB::OPTION_AUDIO_SAMPLE_RATE:
- CARLA_SAFE_ASSERT_RETURN(value >= 22050,);
- gStandalone.options.audioSampleRate = static_cast<unsigned int>(value);
- break;
-
- case CB::OPTION_AUDIO_DEVICE:
- CARLA_SAFE_ASSERT_RETURN(valueStr != nullptr && valueStr[0] != '\0',);
- gStandalone.options.audioDevice = valueStr;
- break;
-
- case CB::OPTION_PATH_RESOURCES:
- CARLA_SAFE_ASSERT_RETURN(valueStr != nullptr && valueStr[0] != '\0',);
- gStandalone.options.resourceDir = valueStr;
- break;
-
- #ifndef BUILD_BRIDGE
- case CB::OPTION_PATH_BRIDGE_NATIVE:
- CARLA_SAFE_ASSERT_RETURN(valueStr != nullptr && valueStr[0] != '\0',);
- gStandalone.options.bridge_native = valueStr;
- break;
-
- case CB::OPTION_PATH_BRIDGE_POSIX32:
- CARLA_SAFE_ASSERT_RETURN(valueStr != nullptr && valueStr[0] != '\0',);
- gStandalone.options.bridge_posix32 = valueStr;
- break;
-
- case CB::OPTION_PATH_BRIDGE_POSIX64:
- CARLA_SAFE_ASSERT_RETURN(valueStr != nullptr && valueStr[0] != '\0',);
- gStandalone.options.bridge_posix64 = valueStr;
- break;
-
- case CB::OPTION_PATH_BRIDGE_WIN32:
- CARLA_SAFE_ASSERT_RETURN(valueStr != nullptr && valueStr[0] != '\0',);
- gStandalone.options.bridge_win32 = valueStr;
- break;
-
- case CB::OPTION_PATH_BRIDGE_WIN64:
- CARLA_SAFE_ASSERT_RETURN(valueStr != nullptr && valueStr[0] != '\0',);
- gStandalone.options.bridge_win64 = valueStr;
- break;
- #endif
-
- #ifdef WANT_LV2
- case CB::OPTION_PATH_BRIDGE_LV2_EXTERNAL:
- CARLA_SAFE_ASSERT_RETURN(valueStr != nullptr && valueStr[0] != '\0',);
- gStandalone.options.bridge_lv2Extrn = valueStr;
- break;
-
- case CB::OPTION_PATH_BRIDGE_LV2_GTK2:
- CARLA_SAFE_ASSERT_RETURN(valueStr != nullptr && valueStr[0] != '\0',);
- gStandalone.options.bridge_lv2Gtk2 = valueStr;
- break;
-
- case CB::OPTION_PATH_BRIDGE_LV2_GTK3:
- CARLA_SAFE_ASSERT_RETURN(valueStr != nullptr && valueStr[0] != '\0',);
- gStandalone.options.bridge_lv2Gtk3 = valueStr;
- break;
-
- case CB::OPTION_PATH_BRIDGE_LV2_QT4:
- CARLA_SAFE_ASSERT_RETURN(valueStr != nullptr && valueStr[0] != '\0',);
- gStandalone.options.bridge_lv2Qt4 = valueStr;
- break;
-
- case CB::OPTION_PATH_BRIDGE_LV2_QT5:
- CARLA_SAFE_ASSERT_RETURN(valueStr != nullptr && valueStr[0] != '\0',);
- gStandalone.options.bridge_lv2Qt5 = valueStr;
- break;
-
- case CB::OPTION_PATH_BRIDGE_LV2_COCOA:
- CARLA_SAFE_ASSERT_RETURN(valueStr != nullptr && valueStr[0] != '\0',);
- gStandalone.options.bridge_lv2Cocoa = valueStr;
- break;
-
- case CB::OPTION_PATH_BRIDGE_LV2_WINDOWS:
- CARLA_SAFE_ASSERT_RETURN(valueStr != nullptr && valueStr[0] != '\0',);
- gStandalone.options.bridge_lv2Win = valueStr;
- break;
-
- case CB::OPTION_PATH_BRIDGE_LV2_X11:
- CARLA_SAFE_ASSERT_RETURN(valueStr != nullptr && valueStr[0] != '\0',);
- gStandalone.options.bridge_lv2X11 = valueStr;
- break;
- #endif
-
- #ifdef WANT_VST
- case CB::OPTION_PATH_BRIDGE_VST_MAC:
- CARLA_SAFE_ASSERT_RETURN(valueStr != nullptr && valueStr[0] != '\0',);
- gStandalone.options.bridge_vstMac = valueStr;
- break;
-
- case CB::OPTION_PATH_BRIDGE_VST_HWND:
- CARLA_SAFE_ASSERT_RETURN(valueStr != nullptr && valueStr[0] != '\0',);
- gStandalone.options.bridge_vstHWND = valueStr;
- break;
-
- case CB::OPTION_PATH_BRIDGE_VST_X11:
- CARLA_SAFE_ASSERT_RETURN(valueStr != nullptr && valueStr[0] != '\0',);
- gStandalone.options.bridge_vstX11 = valueStr;
- break;
- #endif
- }
-
- if (gStandalone.engine != nullptr)
- gStandalone.engine->setOption(option, value, valueStr);
- }
-
- // -------------------------------------------------------------------------------------------------------------------
-
- bool carla_load_filename(const char* filename)
- {
- CARLA_SAFE_ASSERT_RETURN(filename != nullptr && filename[0] != '\0', false);
- carla_debug("carla_load_filename(\"%s\")", filename);
-
- if (gStandalone.engine != nullptr && gStandalone.engine->isRunning())
- return gStandalone.engine->loadFilename(filename);
-
- carla_stderr2("Engine is not running");
- gStandalone.lastError = "Engine is not running";
- return false;
- }
-
- bool carla_load_project(const char* filename)
- {
- CARLA_SAFE_ASSERT_RETURN(filename != nullptr && filename[0] != '\0', false);
- carla_debug("carla_load_project(\"%s\")", filename);
-
- if (gStandalone.engine != nullptr && gStandalone.engine->isRunning())
- return gStandalone.engine->loadProject(filename);
-
- carla_stderr2("Engine is not running");
- gStandalone.lastError = "Engine is not running";
- return false;
- }
-
- bool carla_save_project(const char* filename)
- {
- CARLA_SAFE_ASSERT_RETURN(filename != nullptr && filename[0] != '\0', false);
- carla_debug("carla_save_project(\"%s\")", filename);
-
- // allow to save even if engine isn't running
- if (gStandalone.engine != nullptr)
- return gStandalone.engine->saveProject(filename);
-
- carla_stderr2("Engine was never initiated");
- gStandalone.lastError = "Engine was never initiated";
- return false;
- }
-
- // -------------------------------------------------------------------------------------------------------------------
-
- bool carla_patchbay_connect(int portA, int portB)
- {
- CARLA_SAFE_ASSERT_RETURN(portA != portB, false);
- carla_debug("carla_patchbay_connect(%i, %i)", portA, portB);
-
- if (gStandalone.engine != nullptr && gStandalone.engine->isRunning())
- return gStandalone.engine->patchbayConnect(portA, portB);
-
- carla_stderr2("Engine is not running");
- gStandalone.lastError = "Engine is not running";
- return false;
- }
-
- bool carla_patchbay_disconnect(int connectionId)
- {
- carla_debug("carla_patchbay_disconnect(%i)", connectionId);
-
- if (gStandalone.engine != nullptr && gStandalone.engine->isRunning())
- return gStandalone.engine->patchbayDisconnect(connectionId);
-
- carla_stderr2("Engine is not running");
- gStandalone.lastError = "Engine is not running";
- return false;
- }
-
- bool carla_patchbay_refresh()
- {
- carla_debug("carla_patchbay_refresh()");
-
- if (gStandalone.engine != nullptr && gStandalone.engine->isRunning())
- {
- gStandalone.engine->patchbayRefresh();
- return true;
- }
-
- carla_stderr2("Engine is not running");
- gStandalone.lastError = "Engine is not running";
- return false;
- }
-
- // -------------------------------------------------------------------------------------------------------------------
-
- void carla_transport_play()
- {
- CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr && gStandalone.engine->isRunning(),);
- carla_debug("carla_transport_play()");
-
- gStandalone.engine->transportPlay();
- }
-
- void carla_transport_pause()
- {
- CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr && gStandalone.engine->isRunning(),);
- carla_debug("carla_transport_pause()");
-
- gStandalone.engine->transportPause();
- }
-
- void carla_transport_relocate(uint32_t frames)
- {
- CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr && gStandalone.engine->isRunning(),);
- carla_debug("carla_transport_relocate(%i)", frames);
-
- gStandalone.engine->transportRelocate(frames);
- }
-
- uint64_t carla_get_current_transport_frame()
- {
- CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr, 0);
-
- const EngineTimeInfo& timeInfo(gStandalone.engine->getTimeInfo());
- return timeInfo.frame;
- }
-
- const CarlaTransportInfo* carla_get_transport_info()
- {
- static CarlaTransportInfo info;
-
- // reset
- info.playing = false;
- info.frame = 0;
- info.bar = 0;
- info.beat = 0;
- info.tick = 0;
- info.bpm = 0.0;
-
- CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr, &info);
-
- const EngineTimeInfo& timeInfo(gStandalone.engine->getTimeInfo());
-
- info.playing = timeInfo.playing;
- info.frame = timeInfo.frame;
-
- if (timeInfo.valid & timeInfo.ValidBBT)
- {
- info.bar = timeInfo.bbt.bar;
- info.beat = timeInfo.bbt.beat;
- info.tick = timeInfo.bbt.tick;
- info.bpm = timeInfo.bbt.beatsPerMinute;
- }
-
- return &info;
- }
-
- // -------------------------------------------------------------------------------------------------------------------
-
- bool carla_add_plugin(CarlaBinaryType btype, CarlaPluginType ptype, const char* filename, const char* const name, const char* label, const void* extraStuff)
- {
- CARLA_SAFE_ASSERT_RETURN(label != nullptr && label[0] != '\0', false);
- carla_debug("carla_add_plugin(%i:%s, %i:%s, \"%s\", \"%s\", \"%s\", %p)", btype, CB::BinaryType2Str(btype), ptype, CB::PluginType2Str(ptype), filename, name, label, extraStuff);
-
- if (gStandalone.engine != nullptr && gStandalone.engine->isRunning())
- return gStandalone.engine->addPlugin(btype, ptype, filename, name, label, extraStuff);
-
- carla_stderr2("Engine is not running");
- gStandalone.lastError = "Engine is not running";
- return false;
- }
-
- bool carla_remove_plugin(unsigned int pluginId)
- {
- carla_debug("carla_remove_plugin(%i)", pluginId);
-
- if (gStandalone.engine != nullptr && gStandalone.engine->isRunning())
- return gStandalone.engine->removePlugin(pluginId);
-
- carla_stderr2("Engine is not running");
- gStandalone.lastError = "Engine is not running";
- return false;
- }
-
- bool carla_remove_all_plugins()
- {
- carla_debug("carla_remove_all_plugins()");
-
- if (gStandalone.engine != nullptr && gStandalone.engine->isRunning())
- {
- gStandalone.engine->removeAllPlugins();
- return true;
- }
-
- carla_stderr2("Engine is not running");
- gStandalone.lastError = "Engine is not running";
- return false;
- }
-
- const char* carla_rename_plugin(unsigned int pluginId, const char* newName)
- {
- CARLA_SAFE_ASSERT_RETURN(newName != nullptr && newName[0] != '\0', nullptr);
- carla_debug("carla_rename_plugin(%i, \"%s\")", pluginId, newName);
-
- if (gStandalone.engine != nullptr && gStandalone.engine->isRunning())
- return gStandalone.engine->renamePlugin(pluginId, newName);
-
- carla_stderr2("Engine is not running");
- gStandalone.lastError = "Engine is not running";
- return nullptr;
- }
-
- bool carla_clone_plugin(unsigned int pluginId)
- {
- carla_debug("carla_clone_plugin(%i)", pluginId);
-
- if (gStandalone.engine != nullptr && gStandalone.engine->isRunning())
- return gStandalone.engine->clonePlugin(pluginId);
-
- carla_stderr2("Engine is not running");
- gStandalone.lastError = "Engine is not running";
- return false;
- }
-
- bool carla_replace_plugin(unsigned int pluginId)
- {
- carla_debug("carla_replace_plugin(%i)", pluginId);
-
- if (gStandalone.engine != nullptr && gStandalone.engine->isRunning())
- return gStandalone.engine->replacePlugin(pluginId);
-
- carla_stderr2("Engine is not running");
- gStandalone.lastError = "Engine is not running";
- return false;
- }
-
- bool carla_switch_plugins(unsigned int pluginIdA, unsigned int pluginIdB)
- {
- CARLA_SAFE_ASSERT_RETURN(pluginIdA != pluginIdB, false);
- carla_debug("carla_switch_plugins(%i, %i)", pluginIdA, pluginIdB);
-
- if (gStandalone.engine != nullptr && gStandalone.engine->isRunning())
- return gStandalone.engine->switchPlugins(pluginIdA, pluginIdB);
-
- carla_stderr2("Engine is not running");
- gStandalone.lastError = "Engine is not running";
- return false;
- }
-
- // -------------------------------------------------------------------------------------------------------------------
-
- bool carla_load_plugin_state(unsigned int pluginId, const char* filename)
- {
- CARLA_SAFE_ASSERT_RETURN(filename != nullptr && filename[0] != '\0', false);
- carla_debug("carla_load_plugin_state(%i, \"%s\")", pluginId, filename);
-
- if (gStandalone.engine == nullptr || ! gStandalone.engine->isRunning())
- {
- carla_stderr2("Engine is not running");
- gStandalone.lastError = "Engine is not running";
- return false;
- }
-
- if (CarlaPlugin* const plugin = gStandalone.engine->getPlugin(pluginId))
- return plugin->loadStateFromFile(filename);
-
- carla_stderr2("carla_load_plugin_state(%i, \"%s\") - could not find plugin", pluginId, filename);
- return false;
- }
-
- bool carla_save_plugin_state(unsigned int pluginId, const char* filename)
- {
- CARLA_SAFE_ASSERT_RETURN(filename != nullptr && filename[0] != '\0', false);
- carla_debug("carla_save_plugin_state(%i, \"%s\")", pluginId, filename);
-
- if (gStandalone.engine == nullptr)
- {
- carla_stderr2("Engine is not running");
- gStandalone.lastError = "Engine is not running";
- return false;
- }
-
- // allow to save even if engine isn't running
-
- if (CarlaPlugin* const plugin = gStandalone.engine->getPlugin(pluginId))
- return plugin->saveStateToFile(filename);
-
- carla_stderr2("carla_save_plugin_state(%i, \"%s\") - could not find plugin", pluginId, filename);
- return false;
- }
-
- // -------------------------------------------------------------------------------------------------------------------
-
- const CarlaPluginInfo* carla_get_plugin_info(unsigned int pluginId)
- {
- carla_debug("carla_get_plugin_info(%i)", pluginId);
-
- static CarlaPluginInfo info;
-
- // reset
- info.type = CB::PLUGIN_NONE;
- info.category = CB::PLUGIN_CATEGORY_NONE;
- info.hints = 0x0;
- info.hints = 0x0;
- info.binary = nullptr;
- info.name = nullptr;
- info.iconName = nullptr;
- info.uniqueId = 0;
- info.latency = 0;
- info.optionsAvailable = 0x0;
- info.optionsEnabled = 0x0;
-
- // cleanup
- if (info.label != nullptr)
- {
- delete[] info.label;
- info.label = nullptr;
- }
-
- if (info.maker != nullptr)
- {
- delete[] info.maker;
- info.maker = nullptr;
- }
-
- if (info.copyright != nullptr)
- {
- delete[] info.copyright;
- info.copyright = nullptr;
- }
-
- CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr, &info);
-
- if (CarlaPlugin* const plugin = gStandalone.engine->getPlugin(pluginId))
- {
- char strBufLabel[STR_MAX+1];
- char strBufMaker[STR_MAX+1];
- char strBufCopyright[STR_MAX+1];
-
- carla_zeroChar(strBufLabel, STR_MAX+1);
- carla_zeroChar(strBufMaker, STR_MAX+1);
- carla_zeroChar(strBufCopyright, STR_MAX+1);
-
- info.type = plugin->getType();
- info.category = plugin->getCategory();
- info.hints = plugin->getHints();
- info.binary = plugin->getFilename();
- info.name = plugin->getName();
- info.iconName = plugin->getIconName();
- info.uniqueId = plugin->getUniqueId();
- info.latency = plugin->getLatencyInFrames();
-
- info.optionsAvailable = plugin->getAvailableOptions();
- info.optionsEnabled = plugin->getOptions();
-
- plugin->getLabel(strBufLabel);
- info.label = carla_strdup(strBufLabel);
-
- plugin->getMaker(strBufMaker);
- info.maker = carla_strdup(strBufMaker);
-
- plugin->getCopyright(strBufCopyright);
- info.copyright = carla_strdup(strBufCopyright);
-
- return &info;
- }
-
- carla_stderr2("carla_get_plugin_info(%i) - could not find plugin", pluginId);
- return &info;
- }
-
- const CarlaPortCountInfo* carla_get_audio_port_count_info(unsigned int pluginId)
- {
- carla_debug("carla_get_audio_port_count_info(%i)", pluginId);
-
- static CarlaPortCountInfo info;
-
- // reset
- info.ins = 0;
- info.outs = 0;
- info.total = 0;
-
- CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr, &info);
-
- if (CarlaPlugin* const plugin = gStandalone.engine->getPlugin(pluginId))
- {
- info.ins = plugin->getAudioInCount();
- info.outs = plugin->getAudioOutCount();
- info.total = info.ins + info.outs;
- return &info;
- }
-
- carla_stderr2("carla_get_audio_port_count_info(%i) - could not find plugin", pluginId);
- return &info;
- }
-
- const CarlaPortCountInfo* carla_get_midi_port_count_info(unsigned int pluginId)
- {
- carla_debug("carla_get_midi_port_count_info(%i)", pluginId);
-
- static CarlaPortCountInfo info;
-
- // reset
- info.ins = 0;
- info.outs = 0;
- info.total = 0;
-
- CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr, &info);
-
- if (CarlaPlugin* const plugin = gStandalone.engine->getPlugin(pluginId))
- {
- info.ins = plugin->getMidiInCount();
- info.outs = plugin->getMidiOutCount();
- info.total = info.ins + info.outs;
- return &info;
- }
-
- carla_stderr2("carla_get_midi_port_count_info(%i) - could not find plugin", pluginId);
- return &info;
- }
-
- const CarlaPortCountInfo* carla_get_parameter_count_info(unsigned int pluginId)
- {
- carla_debug("carla_get_parameter_count_info(%i)", pluginId);
-
- static CarlaPortCountInfo info;
-
- // reset
- info.ins = 0;
- info.outs = 0;
- info.total = 0;
-
- CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr, &info);
-
- if (CarlaPlugin* const plugin = gStandalone.engine->getPlugin(pluginId))
- {
- plugin->getParameterCountInfo(info.ins, info.outs, info.total);
- return &info;
- }
-
- carla_stderr2("carla_get_parameter_count_info(%i) - could not find plugin", pluginId);
- return &info;
- }
-
- const CarlaParameterInfo* carla_get_parameter_info(unsigned int pluginId, uint32_t parameterId)
- {
- carla_debug("carla_get_parameter_info(%i, %i)", pluginId, parameterId);
-
- static CarlaParameterInfo info;
-
- // reset
- info.scalePointCount = 0;
-
- // cleanup
- if (info.name != nullptr)
- {
- delete[] info.name;
- info.name = nullptr;
- }
-
- if (info.symbol != nullptr)
- {
- delete[] info.symbol;
- info.symbol = nullptr;
- }
-
- if (info.unit != nullptr)
- {
- delete[] info.unit;
- info.unit = nullptr;
- }
-
- CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr, &info);
-
- if (CarlaPlugin* const plugin = gStandalone.engine->getPlugin(pluginId))
- {
- if (parameterId < plugin->getParameterCount())
- {
- char strBufName[STR_MAX+1];
- char strBufSymbol[STR_MAX+1];
- char strBufUnit[STR_MAX+1];
-
- carla_zeroChar(strBufName, STR_MAX+1);
- carla_zeroChar(strBufSymbol, STR_MAX+1);
- carla_zeroChar(strBufUnit, STR_MAX+1);
-
- info.scalePointCount = plugin->getParameterScalePointCount(parameterId);
-
- plugin->getParameterName(parameterId, strBufName);
- info.name = carla_strdup(strBufName);
-
- plugin->getParameterSymbol(parameterId, strBufSymbol);
- info.symbol = carla_strdup(strBufSymbol);
-
- plugin->getParameterUnit(parameterId, strBufUnit);
- info.unit = carla_strdup(strBufUnit);
- }
- else
- carla_stderr2("carla_get_parameter_info(%i, %i) - parameterId out of bounds", pluginId, parameterId);
-
- return &info;
- }
-
- carla_stderr2("carla_get_parameter_info(%i, %i) - could not find plugin", pluginId, parameterId);
- return &info;
- }
-
- const CarlaScalePointInfo* carla_get_parameter_scalepoint_info(unsigned int pluginId, uint32_t parameterId, uint32_t scalePointId)
- {
- carla_debug("carla_get_parameter_scalepoint_info(%i, %i, %i)", pluginId, parameterId, scalePointId);
- CARLA_ASSERT(gStandalone.engine != nullptr);
-
- static CarlaScalePointInfo info;
-
- // reset
- info.value = 0.0f;
-
- // cleanup
- if (info.label != nullptr)
- {
- delete[] info.label;
- info.label = nullptr;
- }
-
- CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr, &info);
-
- if (CarlaPlugin* const plugin = gStandalone.engine->getPlugin(pluginId))
- {
- if (parameterId < plugin->getParameterCount())
- {
- if (scalePointId < plugin->getParameterScalePointCount(parameterId))
- {
- char strBufLabel[STR_MAX+1];
- carla_zeroChar(strBufLabel, STR_MAX+1);
-
- info.value = plugin->getParameterScalePointValue(parameterId, scalePointId);
-
- plugin->getParameterScalePointLabel(parameterId, scalePointId, strBufLabel);
- info.label = carla_strdup(strBufLabel);
- }
- else
- carla_stderr2("carla_get_parameter_scalepoint_info(%i, %i, %i) - scalePointId out of bounds", pluginId, parameterId, scalePointId);
- }
- else
- carla_stderr2("carla_get_parameter_scalepoint_info(%i, %i, %i) - parameterId out of bounds", pluginId, parameterId, scalePointId);
-
- return &info;
- }
-
- carla_stderr2("carla_get_parameter_scalepoint_info(%i, %i, %i) - could not find plugin", pluginId, parameterId, scalePointId);
- return &info;
- }
-
- // -------------------------------------------------------------------------------------------------------------------
-
- const CarlaParameterData* carla_get_parameter_data(unsigned int pluginId, uint32_t parameterId)
- {
- carla_debug("carla_get_parameter_data(%i, %i)", pluginId, parameterId);
-
- static CarlaParameterData fallbackParamData;
-
- CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr, &fallbackParamData);
-
- if (CarlaPlugin* const plugin = gStandalone.engine->getPlugin(pluginId))
- {
- if (parameterId < plugin->getParameterCount())
- return &plugin->getParameterData(parameterId);
-
- carla_stderr2("carla_get_parameter_data(%i, %i) - parameterId out of bounds", pluginId, parameterId);
- return &fallbackParamData;
- }
-
- carla_stderr2("carla_get_parameter_data(%i, %i) - could not find plugin", pluginId, parameterId);
- return &fallbackParamData;
- }
-
- const CarlaParameterRanges* carla_get_parameter_ranges(unsigned int pluginId, uint32_t parameterId)
- {
- carla_debug("carla_get_parameter_ranges(%i, %i)", pluginId, parameterId);
-
- static CarlaParameterRanges fallbackParamRanges;
-
- CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr, &fallbackParamRanges);
-
- if (CarlaPlugin* const plugin = gStandalone.engine->getPlugin(pluginId))
- {
- if (parameterId < plugin->getParameterCount())
- return &plugin->getParameterRanges(parameterId);
-
- carla_stderr2("carla_get_parameter_ranges(%i, %i) - parameterId out of bounds", pluginId, parameterId);
- return &fallbackParamRanges;
- }
-
- carla_stderr2("carla_get_parameter_ranges(%i, %i) - could not find plugin", pluginId, parameterId);
- return &fallbackParamRanges;
- }
-
- const CarlaMidiProgramData* carla_get_midi_program_data(unsigned int pluginId, uint32_t midiProgramId)
- {
- carla_debug("carla_get_midi_program_data(%i, %i)", pluginId, midiProgramId);
-
- static CarlaMidiProgramData fallbackMidiProgData;
-
- CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr, &fallbackMidiProgData);
-
- if (CarlaPlugin* const plugin = gStandalone.engine->getPlugin(pluginId))
- {
- if (midiProgramId < plugin->getMidiProgramCount())
- return &plugin->getMidiProgramData(midiProgramId);
-
- carla_stderr2("carla_get_midi_program_data(%i, %i) - midiProgramId out of bounds", pluginId, midiProgramId);
- return &fallbackMidiProgData;
- }
-
- carla_stderr2("carla_get_midi_program_data(%i, %i) - could not find plugin", pluginId, midiProgramId);
- return &fallbackMidiProgData;
- }
-
- const CarlaCustomData* carla_get_custom_data(unsigned int pluginId, uint32_t customDataId)
- {
- carla_debug("carla_get_custom_data(%i, %i)", pluginId, customDataId);
-
- static CarlaCustomData fallbackCustomData;
-
- CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr, &fallbackCustomData);
-
- if (CarlaPlugin* const plugin = gStandalone.engine->getPlugin(pluginId))
- {
- if (customDataId < plugin->getCustomDataCount())
- return &plugin->getCustomData(customDataId);
-
- carla_stderr2("carla_get_custom_data(%i, %i) - customDataId out of bounds", pluginId, customDataId);
- return &fallbackCustomData;
- }
-
- carla_stderr2("carla_get_custom_data(%i, %i) - could not find plugin", pluginId, customDataId);
- return &fallbackCustomData;
- }
-
- const char* carla_get_chunk_data(unsigned int pluginId)
- {
- carla_debug("carla_get_chunk_data(%i)", pluginId);
-
- CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr, nullptr);
-
- static CarlaString chunkData;
-
- // cleanup
- chunkData.clear();
-
- if (CarlaPlugin* const plugin = gStandalone.engine->getPlugin(pluginId))
- {
- if (plugin->getOptions() & CB::PLUGIN_OPTION_USE_CHUNKS)
- {
- void* data = nullptr;
- const int32_t dataSize(plugin->getChunkData(&data));
-
- if (data != nullptr && dataSize > 0)
- {
- juce::MemoryBlock memBlock(data, dataSize);
- chunkData = memBlock.toBase64Encoding().toRawUTF8();
- return (const char*)chunkData;
- }
- else
- carla_stderr2("carla_get_chunk_data(%i) - got invalid chunk data", pluginId);
- }
- else
- carla_stderr2("carla_get_chunk_data(%i) - plugin does not use chunks", pluginId);
-
- return nullptr;
- }
-
- carla_stderr2("carla_get_chunk_data(%i) - could not find plugin", pluginId);
- return nullptr;
- }
-
- // -------------------------------------------------------------------------------------------------------------------
-
- uint32_t carla_get_parameter_count(unsigned int pluginId)
- {
- CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr, 0);
- carla_debug("carla_get_parameter_count(%i)", pluginId);
-
- if (CarlaPlugin* const plugin = gStandalone.engine->getPlugin(pluginId))
- return plugin->getParameterCount();
-
- carla_stderr2("carla_get_parameter_count(%i) - could not find plugin", pluginId);
- return 0;
- }
-
- uint32_t carla_get_program_count(unsigned int pluginId)
- {
- CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr, 0);
- carla_debug("carla_get_program_count(%i)", pluginId);
-
- if (CarlaPlugin* const plugin = gStandalone.engine->getPlugin(pluginId))
- return plugin->getProgramCount();
-
- carla_stderr2("carla_get_program_count(%i) - could not find plugin", pluginId);
- return 0;
- }
-
- uint32_t carla_get_midi_program_count(unsigned int pluginId)
- {
- CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr, 0);
- carla_debug("carla_get_midi_program_count(%i)", pluginId);
-
- if (CarlaPlugin* const plugin = gStandalone.engine->getPlugin(pluginId))
- return plugin->getMidiProgramCount();
-
- carla_stderr2("carla_get_midi_program_count(%i) - could not find plugin", pluginId);
- return 0;
- }
-
- uint32_t carla_get_custom_data_count(unsigned int pluginId)
- {
- CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr, 0);
- carla_debug("carla_get_custom_data_count(%i)", pluginId);
-
- if (CarlaPlugin* const plugin = gStandalone.engine->getPlugin(pluginId))
- return plugin->getCustomDataCount();
-
- carla_stderr2("carla_get_custom_data_count(%i) - could not find plugin", pluginId);
- return 0;
- }
-
- // -------------------------------------------------------------------------------------------------------------------
-
- const char* carla_get_parameter_text(unsigned int pluginId, uint32_t parameterId)
- {
- CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr, nullptr);
- carla_debug("carla_get_parameter_text(%i, %i)", pluginId, parameterId);
-
- static char textBuf[STR_MAX+1];
- carla_zeroChar(textBuf, STR_MAX+1);
-
- if (CarlaPlugin* const plugin = gStandalone.engine->getPlugin(pluginId))
- {
- if (parameterId < plugin->getParameterCount())
- {
- plugin->getParameterText(parameterId, textBuf);
- return textBuf;
- }
-
- carla_stderr2("carla_get_parameter_text(%i, %i) - parameterId out of bounds", pluginId, parameterId);
- return nullptr;
- }
-
- carla_stderr2("carla_get_parameter_text(%i, %i) - could not find plugin", pluginId, parameterId);
- return nullptr;
- }
-
- const char* carla_get_program_name(unsigned int pluginId, uint32_t programId)
- {
- CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr, nullptr);
- carla_debug("carla_get_program_name(%i, %i)", pluginId, programId);
-
- static char programName[STR_MAX+1];
- carla_zeroChar(programName, STR_MAX+1);
-
- if (CarlaPlugin* const plugin = gStandalone.engine->getPlugin(pluginId))
- {
- if (programId < plugin->getProgramCount())
- {
- plugin->getProgramName(programId, programName);
- return programName;
- }
-
- carla_stderr2("carla_get_program_name(%i, %i) - programId out of bounds", pluginId, programId);
- return nullptr;
- }
-
- carla_stderr2("carla_get_program_name(%i, %i) - could not find plugin", pluginId, programId);
- return nullptr;
- }
-
- const char* carla_get_midi_program_name(unsigned int pluginId, uint32_t midiProgramId)
- {
- CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr, nullptr);
- carla_debug("carla_get_midi_program_name(%i, %i)", pluginId, midiProgramId);
-
- static char midiProgramName[STR_MAX+1];
- carla_zeroChar(midiProgramName, STR_MAX+1);
-
- if (CarlaPlugin* const plugin = gStandalone.engine->getPlugin(pluginId))
- {
- if (midiProgramId < plugin->getMidiProgramCount())
- {
- plugin->getMidiProgramName(midiProgramId, midiProgramName);
- return midiProgramName;
- }
-
- carla_stderr2("carla_get_midi_program_name(%i, %i) - midiProgramId out of bounds", pluginId, midiProgramId);
- return nullptr;
- }
-
- carla_stderr2("carla_get_midi_program_name(%i, %i) - could not find plugin", pluginId, midiProgramId);
- return nullptr;
- }
-
- const char* carla_get_real_plugin_name(unsigned int pluginId)
- {
- CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr, nullptr);
- carla_debug("carla_get_real_plugin_name(%i)", pluginId);
-
- static char realPluginName[STR_MAX+1];
- carla_zeroChar(realPluginName, STR_MAX+1);
-
- if (CarlaPlugin* const plugin = gStandalone.engine->getPlugin(pluginId))
- {
- plugin->getRealName(realPluginName);
- return realPluginName;
- }
-
- carla_stderr2("carla_get_real_plugin_name(%i) - could not find plugin", pluginId);
- return nullptr;
- }
-
- // -------------------------------------------------------------------------------------------------------------------
-
- int32_t carla_get_current_program_index(unsigned int pluginId)
- {
- CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr, -1);
- carla_debug("carla_get_current_program_index(%i)", pluginId);
-
- if (CarlaPlugin* const plugin = gStandalone.engine->getPlugin(pluginId))
- return plugin->getCurrentProgram();
-
- carla_stderr2("carla_get_current_program_index(%i) - could not find plugin", pluginId);
- return -1;
- }
-
- int32_t carla_get_current_midi_program_index(unsigned int pluginId)
- {
- CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr, -1);
- carla_debug("carla_get_current_midi_program_index(%i)", pluginId);
-
- if (CarlaPlugin* const plugin = gStandalone.engine->getPlugin(pluginId))
- return plugin->getCurrentMidiProgram();
-
- carla_stderr2("carla_get_current_midi_program_index(%i) - could not find plugin", pluginId);
- return -1;
- }
-
- // -------------------------------------------------------------------------------------------------------------------
-
- float carla_get_default_parameter_value(unsigned int pluginId, uint32_t parameterId)
- {
- CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr, 0.0f);
- carla_debug("carla_get_default_parameter_value(%i, %i)", pluginId, parameterId);
-
- if (CarlaPlugin* const plugin = gStandalone.engine->getPlugin(pluginId))
- {
- if (parameterId < plugin->getParameterCount())
- return plugin->getParameterRanges(parameterId).def;
-
- carla_stderr2("carla_get_default_parameter_value(%i, %i) - parameterId out of bounds", pluginId, parameterId);
- return 0.0f;
- }
-
- carla_stderr2("carla_get_default_parameter_value(%i, %i) - could not find plugin", pluginId, parameterId);
- return 0.0f;
- }
-
- float carla_get_current_parameter_value(unsigned int pluginId, uint32_t parameterId)
- {
- CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr, 0.0f);
- carla_debug("carla_get_current_parameter_value(%i, %i)", pluginId, parameterId);
-
- if (CarlaPlugin* const plugin = gStandalone.engine->getPlugin(pluginId))
- {
- if (parameterId < plugin->getParameterCount())
- return plugin->getParameterValue(parameterId);
-
- carla_stderr2("carla_get_current_parameter_value(%i, %i) - parameterId out of bounds", pluginId, parameterId);
- return 0.0f;
- }
-
- carla_stderr2("carla_get_current_parameter_value(%i, %i) - could not find plugin", pluginId, parameterId);
- return 0.0f;
- }
-
- // -------------------------------------------------------------------------------------------------------------------
-
- float carla_get_input_peak_value(unsigned int pluginId, unsigned short portId)
- {
- CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr, 0.0f);
- CARLA_SAFE_ASSERT_RETURN(portId == 1 || portId == 2, 0.0f);
-
- return gStandalone.engine->getInputPeak(pluginId, portId);
- }
-
- float carla_get_output_peak_value(unsigned int pluginId, unsigned short portId)
- {
- CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr, 0.0f);
- CARLA_SAFE_ASSERT_RETURN(portId == 1 || portId == 2, 0.0f);
-
- return gStandalone.engine->getOutputPeak(pluginId, portId);
- }
-
- // -------------------------------------------------------------------------------------------------------------------
-
- void carla_set_option(unsigned int pluginId, unsigned int option, bool yesNo)
- {
- CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr,);
- carla_debug("carla_set_option(%i, %i, %s)", pluginId, option, bool2str(yesNo));
-
- if (CarlaPlugin* const plugin = gStandalone.engine->getPlugin(pluginId))
- return plugin->setOption(option, yesNo);
-
- carla_stderr2("carla_set_option(%i, %i, %s) - could not find plugin", pluginId, option, bool2str(yesNo));
- }
-
- void carla_set_active(unsigned int pluginId, bool onOff)
- {
- CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr,);
- carla_debug("carla_set_active(%i, %s)", pluginId, bool2str(onOff));
-
- if (CarlaPlugin* const plugin = gStandalone.engine->getPlugin(pluginId))
- return plugin->setActive(onOff, true, false);
-
- carla_stderr2("carla_set_active(%i, %s) - could not find plugin", pluginId, bool2str(onOff));
- }
-
- #ifndef BUILD_BRIDGE
- void carla_set_drywet(unsigned int pluginId, float value)
- {
- CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr,);
- carla_debug("carla_set_drywet(%i, %f)", pluginId, value);
-
- if (CarlaPlugin* const plugin = gStandalone.engine->getPlugin(pluginId))
- return plugin->setDryWet(value, true, false);
-
- carla_stderr2("carla_set_drywet(%i, %f) - could not find plugin", pluginId, value);
- }
-
- void carla_set_volume(unsigned int pluginId, float value)
- {
- CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr,);
- carla_debug("carla_set_volume(%i, %f)", pluginId, value);
-
- if (CarlaPlugin* const plugin = gStandalone.engine->getPlugin(pluginId))
- return plugin->setVolume(value, true, false);
-
- carla_stderr2("carla_set_volume(%i, %f) - could not find plugin", pluginId, value);
- }
-
- void carla_set_balance_left(unsigned int pluginId, float value)
- {
- CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr,);
- carla_debug("carla_set_balance_left(%i, %f)", pluginId, value);
-
- if (CarlaPlugin* const plugin = gStandalone.engine->getPlugin(pluginId))
- return plugin->setBalanceLeft(value, true, false);
-
- carla_stderr2("carla_set_balance_left(%i, %f) - could not find plugin", pluginId, value);
- }
-
- void carla_set_balance_right(unsigned int pluginId, float value)
- {
- CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr,);
- carla_debug("carla_set_balance_right(%i, %f)", pluginId, value);
-
- if (CarlaPlugin* const plugin = gStandalone.engine->getPlugin(pluginId))
- return plugin->setBalanceRight(value, true, false);
-
- carla_stderr2("carla_set_balance_right(%i, %f) - could not find plugin", pluginId, value);
- }
-
- void carla_set_panning(unsigned int pluginId, float value)
- {
- CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr,);
- carla_debug("carla_set_panning(%i, %f)", pluginId, value);
-
- if (CarlaPlugin* const plugin = gStandalone.engine->getPlugin(pluginId))
- return plugin->setPanning(value, true, false);
-
- carla_stderr2("carla_set_panning(%i, %f) - could not find plugin", pluginId, value);
- }
- #endif
-
- void carla_set_ctrl_channel(unsigned int pluginId, int8_t channel)
- {
- CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr,);
- carla_debug("carla_set_ctrl_channel(%i, %i)", pluginId, channel);
-
- if (CarlaPlugin* const plugin = gStandalone.engine->getPlugin(pluginId))
- return plugin->setCtrlChannel(channel, true, false);
-
- carla_stderr2("carla_set_ctrl_channel(%i, %i) - could not find plugin", pluginId, channel);
- }
-
- // -------------------------------------------------------------------------------------------------------------------
-
- void carla_set_parameter_value(unsigned int pluginId, uint32_t parameterId, float value)
- {
- CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr,);
- carla_debug("carla_set_parameter_value(%i, %i, %f)", pluginId, parameterId, value);
-
- if (CarlaPlugin* const plugin = gStandalone.engine->getPlugin(pluginId))
- {
- if (parameterId < plugin->getParameterCount())
- return plugin->setParameterValue(parameterId, value, true, true, false);
-
- carla_stderr2("carla_set_parameter_value(%i, %i, %f) - parameterId out of bounds", pluginId, parameterId, value);
- return;
- }
-
- carla_stderr2("carla_set_parameter_value(%i, %i, %f) - could not find plugin", pluginId, parameterId, value);
- }
-
- #ifndef BUILD_BRIDGE
- void carla_set_parameter_midi_channel(unsigned int pluginId, uint32_t parameterId, uint8_t channel)
- {
- CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr,);
- CARLA_SAFE_ASSERT_RETURN(channel >= MAX_MIDI_CHANNELS,);
- carla_debug("carla_set_parameter_midi_channel(%i, %i, %i)", pluginId, parameterId, channel);
-
- if (CarlaPlugin* const plugin = gStandalone.engine->getPlugin(pluginId))
- {
- if (parameterId < plugin->getParameterCount())
- return plugin->setParameterMidiChannel(parameterId, channel, true, false);
-
- carla_stderr2("carla_set_parameter_midi_channel(%i, %i, %i) - parameterId out of bounds", pluginId, parameterId, channel);
- return;
- }
-
- carla_stderr2("carla_set_parameter_midi_channel(%i, %i, %i) - could not find plugin", pluginId, parameterId, channel);
- }
-
- void carla_set_parameter_midi_cc(unsigned int pluginId, uint32_t parameterId, int16_t cc)
- {
- CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr,);
- CARLA_SAFE_ASSERT_RETURN(cc >= -1 && cc <= 0x5F,);
- carla_debug("carla_set_parameter_midi_cc(%i, %i, %i)", pluginId, parameterId, cc);
-
- if (CarlaPlugin* const plugin = gStandalone.engine->getPlugin(pluginId))
- {
- if (parameterId < plugin->getParameterCount())
- return plugin->setParameterMidiCC(parameterId, cc, true, false);
-
- carla_stderr2("carla_set_parameter_midi_cc(%i, %i, %i) - parameterId out of bounds", pluginId, parameterId, cc);
- return;
- }
-
- carla_stderr2("carla_set_parameter_midi_cc(%i, %i, %i) - could not find plugin", pluginId, parameterId, cc);
- }
- #endif
-
- // -------------------------------------------------------------------------------------------------------------------
-
- void carla_set_program(unsigned int pluginId, uint32_t programId)
- {
- CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr,);
- carla_debug("carla_set_program(%i, %i)", pluginId, programId);
-
- if (CarlaPlugin* const plugin = gStandalone.engine->getPlugin(pluginId))
- {
- if (programId < plugin->getProgramCount())
- return plugin->setProgram(static_cast<int32_t>(programId), true, true, false);
-
- carla_stderr2("carla_set_program(%i, %i) - programId out of bounds", pluginId, programId);
- return;
- }
-
- carla_stderr2("carla_set_program(%i, %i) - could not find plugin", pluginId, programId);
- }
-
- void carla_set_midi_program(unsigned int pluginId, uint32_t midiProgramId)
- {
- CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr,);
- carla_debug("carla_set_midi_program(%i, %i)", pluginId, midiProgramId);
-
- if (CarlaPlugin* const plugin = gStandalone.engine->getPlugin(pluginId))
- {
- if (midiProgramId < plugin->getMidiProgramCount())
- return plugin->setMidiProgram(static_cast<int32_t>(midiProgramId), true, true, false);
-
- carla_stderr2("carla_set_midi_program(%i, %i) - midiProgramId out of bounds", pluginId, midiProgramId);
- return;
- }
-
- carla_stderr2("carla_set_midi_program(%i, %i) - could not find plugin", pluginId, midiProgramId);
- }
-
- // -------------------------------------------------------------------------------------------------------------------
-
- void carla_set_custom_data(unsigned int pluginId, const char* type, const char* key, const char* value)
- {
- CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != 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("carla_set_custom_data(%i, \"%s\", \"%s\", \"%s\")", pluginId, type, key, value);
-
- if (CarlaPlugin* const plugin = gStandalone.engine->getPlugin(pluginId))
- return plugin->setCustomData(type, key, value, true);
-
- carla_stderr2("carla_set_custom_data(%i, \"%s\", \"%s\", \"%s\") - could not find plugin", pluginId, type, key, value);
- }
-
- void carla_set_chunk_data(unsigned int pluginId, const char* chunkData)
- {
- CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr,);
- CARLA_SAFE_ASSERT_RETURN(chunkData != nullptr && chunkData[0] != '\0',);
- carla_debug("carla_set_chunk_data(%i, \"%s\")", pluginId, chunkData);
-
- if (CarlaPlugin* const plugin = gStandalone.engine->getPlugin(pluginId))
- {
- if (plugin->getOptions() & CB::PLUGIN_OPTION_USE_CHUNKS)
- return plugin->setChunkData(chunkData);
-
- carla_stderr2("carla_set_chunk_data(%i, \"%s\") - plugin does not use chunks", pluginId, chunkData);
- return;
- }
-
- carla_stderr2("carla_set_chunk_data(%i, \"%s\") - could not find plugin", pluginId, chunkData);
- }
-
- // -------------------------------------------------------------------------------------------------------------------
-
- void carla_prepare_for_save(unsigned int pluginId)
- {
- CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr,);
- carla_debug("carla_prepare_for_save(%i)", pluginId);
-
- if (CarlaPlugin* const plugin = gStandalone.engine->getPlugin(pluginId))
- return plugin->prepareForSave();
-
- carla_stderr2("carla_prepare_for_save(%i) - could not find plugin", pluginId);
- }
-
- #ifndef BUILD_BRIDGE
- void carla_send_midi_note(unsigned int pluginId, uint8_t channel, uint8_t note, uint8_t velocity)
- {
- CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr && gStandalone.engine->isRunning(),);
- carla_debug("carla_send_midi_note(%i, %i, %i, %i)", pluginId, channel, note, velocity);
-
- if (CarlaPlugin* const plugin = gStandalone.engine->getPlugin(pluginId))
- return plugin->sendMidiSingleNote(channel, note, velocity, true, true, false);
-
- carla_stderr2("carla_send_midi_note(%i, %i, %i, %i) - could not find plugin", pluginId, channel, note, velocity);
- }
- #endif
-
- void carla_show_gui(unsigned int pluginId, bool yesno)
- {
- CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr,);
- carla_debug("carla_show_gui(%i, %s)", pluginId, bool2str(yesno));
-
- if (CarlaPlugin* const plugin = gStandalone.engine->getPlugin(pluginId))
- return plugin->showGui(yesno);
-
- carla_stderr2("carla_show_gui(%i, %s) - could not find plugin", pluginId, bool2str(yesno));
- }
-
- // -------------------------------------------------------------------------------------------------------------------
-
- uint32_t carla_get_buffer_size()
- {
- CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr, 0);
- carla_debug("carla_get_buffer_size()");
-
- return gStandalone.engine->getBufferSize();
- }
-
- double carla_get_sample_rate()
- {
- CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr, 0.0);
- carla_debug("carla_get_sample_rate()");
-
- return gStandalone.engine->getSampleRate();
- }
-
- // -------------------------------------------------------------------------------------------------------------------
-
- const char* carla_get_last_error()
- {
- carla_debug("carla_get_last_error()");
-
- if (gStandalone.engine != nullptr)
- return gStandalone.engine->getLastError();
-
- return gStandalone.lastError;
- }
-
- const char* carla_get_host_osc_url_tcp()
- {
- carla_debug("carla_get_host_osc_url_tcp()");
-
- if (gStandalone.engine == nullptr)
- {
- carla_stderr2("Engine is not running");
- gStandalone.lastError = "Engine is not running";
- return nullptr;
- }
-
- return gStandalone.engine->getOscServerPathTCP();
- }
-
- const char* carla_get_host_osc_url_udp()
- {
- carla_debug("carla_get_host_osc_url_udp()");
-
- if (gStandalone.engine == nullptr)
- {
- carla_stderr2("Engine is not running");
- gStandalone.lastError = "Engine is not running";
- return nullptr;
- }
-
- return gStandalone.engine->getOscServerPathUDP();
- }
-
- // -------------------------------------------------------------------------------------------------------------------
-
- #define NSM_API_VERSION_MAJOR 1
- #define NSM_API_VERSION_MINOR 2
-
- class CarlaNSM
- {
- public:
- CarlaNSM()
- : fServerThread(nullptr),
- fReplyAddr(nullptr),
- fIsReady(false),
- fIsOpened(false),
- fIsSaved(false)
- {
- }
-
- ~CarlaNSM()
- {
- if (fReplyAddr != nullptr)
- lo_address_free(fReplyAddr);
-
- if (fServerThread != nullptr)
- {
- lo_server_thread_stop(fServerThread);
- lo_server_thread_del_method(fServerThread, "/reply", "ssss");
- lo_server_thread_del_method(fServerThread, "/nsm/client/open", "sss");
- lo_server_thread_del_method(fServerThread, "/nsm/client/save", "");
- lo_server_thread_free(fServerThread);
- }
- }
-
- void announce(const char* const url, const char* appName, const int pid)
- {
- lo_address const addr = lo_address_new_from_url(url);
-
- if (addr == nullptr)
- return;
-
- const int proto = lo_address_get_protocol(addr);
-
- if (fServerThread == nullptr)
- {
- // create new OSC thread
- fServerThread = lo_server_thread_new_with_proto(nullptr, proto, error_handler);
-
- // register message handlers and start OSC thread
- lo_server_thread_add_method(fServerThread, "/reply", "ssss", _reply_handler, this);
- lo_server_thread_add_method(fServerThread, "/nsm/client/open", "sss", _open_handler, this);
- lo_server_thread_add_method(fServerThread, "/nsm/client/save", "", _save_handler, this);
- lo_server_thread_start(fServerThread);
- }
-
- #ifndef BUILD_ANSI_TEST
- lo_send_from(addr, lo_server_thread_get_server(fServerThread), LO_TT_IMMEDIATE, "/nsm/server/announce", "sssiii",
- "Carla", ":switch:", appName, NSM_API_VERSION_MAJOR, NSM_API_VERSION_MINOR, pid);
- #endif
-
- lo_address_free(addr);
- }
-
- void ready()
- {
- fIsReady = true;
- }
-
- void replyOpen()
- {
- fIsOpened = true;
- }
-
- void replySave()
- {
- fIsSaved = true;
- }
-
- protected:
- int handleReply(const char* const path, const char* const types, lo_arg** const argv, const int argc, const lo_message msg)
- {
- carla_debug("CarlaNSM::handleReply(%s, %i, %p, %s, %p)", path, argc, argv, types, msg);
-
- if (fReplyAddr != nullptr)
- lo_address_free(fReplyAddr);
-
- fIsOpened = false;
- fIsSaved = false;
-
- char* const url = lo_address_get_url(lo_message_get_source(msg));
- fReplyAddr = lo_address_new_from_url(url);
- std::free(url);
-
- const char* const method = &argv[0]->s;
- const char* const smName = &argv[2]->s;
-
- // wait max 6 secs for host to init
- for (int i=0; i < 60 && ! fIsReady; ++i)
- carla_msleep(100);
-
- if (std::strcmp(method, "/nsm/server/announce") == 0 && gStandalone.callback != nullptr)
- gStandalone.callback(gStandalone.callbackPtr, CB::CALLBACK_NSM_ANNOUNCE, 0, 0, 0, 0.0f, smName);
-
- return 0;
-
- #ifndef DEBUG
- // unused
- (void)path;
- (void)types;
- (void)argc;
- #endif
- }
-
- int handleOpen(const char* const path, const char* const types, lo_arg** const argv, const int argc, const lo_message msg)
- {
- carla_debug("CarlaNSM::handleOpen(\"%s\", \"%s\", %p, %i, %p)", path, types, argv, argc, msg);
-
- if (gStandalone.callback == nullptr)
- return 1;
- if (fServerThread == nullptr)
- return 1;
- if (fReplyAddr == nullptr)
- return 1;
-
- const char* const projectPath = &argv[0]->s;
- const char* const clientId = &argv[2]->s;
-
- char data[std::strlen(projectPath)+std::strlen(clientId)+2];
- std::strcpy(data, projectPath);
- std::strcat(data, ":");
- std::strcat(data, clientId);
-
- fIsOpened = false;
-
- gStandalone.callback(nullptr, CB::CALLBACK_NSM_OPEN, 0, 0, 0, 0.0f, data);
-
- // wait max 10 secs to open
- for (int i=0; i < 100 && ! fIsOpened; ++i)
- carla_msleep(100);
-
- #ifndef BUILD_ANSI_TEST
- if (fIsOpened)
- lo_send_from(fReplyAddr, lo_server_thread_get_server(fServerThread), LO_TT_IMMEDIATE, "/reply", "ss", "/nsm/client/open", "OK");
- #endif
-
- return 0;
-
- #ifndef DEBUG
- // unused
- (void)path;
- (void)types;
- (void)argc;
- (void)msg;
- #endif
- }
-
- int handleSave(const char* const path, const char* const types, lo_arg** const argv, const int argc, const lo_message msg)
- {
- carla_debug("CarlaNSM::handleSave(\"%s\", \"%s\", %p, %i, %p)", path, types, argv, argc, msg);
-
- if (gStandalone.callback == nullptr)
- return 1;
- if (fServerThread == nullptr)
- return 1;
- if (fReplyAddr == nullptr)
- return 1;
-
- fIsSaved = false;
-
- gStandalone.callback(nullptr, CB::CALLBACK_NSM_SAVE, 0, 0, 0, 0.0f, nullptr);
-
- // wait max 10 secs to save
- for (int i=0; i < 100 && ! fIsSaved; ++i)
- carla_msleep(100);
-
- #ifndef BUILD_ANSI_TEST
- if (fIsSaved)
- lo_send_from(fReplyAddr, lo_server_thread_get_server(fServerThread), LO_TT_IMMEDIATE, "/reply", "ss", "/nsm/client/save", "OK");
- #endif
-
- return 0;
-
- #ifndef DEBUG
- // unused
- (void)path;
- (void)types;
- (void)argv;
- (void)argc;
- (void)msg;
- #endif
- }
-
- private:
- lo_server_thread fServerThread;
- lo_address fReplyAddr;
-
- bool fIsReady; // used to startup, only once
- bool fIsOpened;
- bool fIsSaved;
-
- #define handlePtr ((CarlaNSM*)data)
-
- static int _reply_handler(const char* path, const char* types, lo_arg** argv, int argc, lo_message msg, void* data)
- {
- return handlePtr->handleReply(path, types, argv, argc, msg);
- }
-
- static int _open_handler(const char* path, const char* types, lo_arg** argv, int argc, lo_message msg, void* data)
- {
- return handlePtr->handleOpen(path, types, argv, argc, msg);
- }
-
- static int _save_handler(const char* path, const char* types, lo_arg** argv, int argc, lo_message msg, void* data)
- {
- return handlePtr->handleSave(path, types, argv, argc, msg);
- }
-
- #undef handlePtr
-
- static void error_handler(int num, const char* msg, const char* path)
- {
- carla_stderr2("CarlaNSM::error_handler(%i, \"%s\", \"%s\")", num, msg, path);
- }
- };
-
- static CarlaNSM gCarlaNSM;
-
- void carla_nsm_announce(const char* url, const char* appName, int pid)
- {
- CARLA_SAFE_ASSERT_RETURN(url != nullptr && url[0] != '\0',);
- CARLA_SAFE_ASSERT_RETURN(appName != nullptr && appName[0] != '\0',);
- CARLA_SAFE_ASSERT_RETURN(pid != 0,);
- carla_debug("carla_nsm_announce(\"%s\", \"%s\", %i)", url, appName, pid);
-
- gCarlaNSM.announce(url, appName, pid);
- }
-
- void carla_nsm_ready()
- {
- carla_debug("carla_nsm_ready()");
-
- gCarlaNSM.ready();
- }
-
- void carla_nsm_reply_open()
- {
- carla_debug("carla_nsm_reply_open()");
-
- gCarlaNSM.replyOpen();
- }
-
- void carla_nsm_reply_save()
- {
- carla_debug("carla_nsm_reply_save()");
-
- gCarlaNSM.replySave();
- }
-
- // -------------------------------------------------------------------------------------------------------------------
-
- #ifdef BUILD_BRIDGE
- CarlaEngine* carla_get_standalone_engine()
- {
- return gStandalone.engine;
- }
- #endif
|