|
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393 |
- /*
- * Carla Standalone
- * Copyright (C) 2011-2021 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 "CarlaHostImpl.hpp"
- #include "CarlaMIDI.h"
-
- #include "CarlaEngineInit.hpp"
- #include "CarlaPlugin.hpp"
-
- #include "CarlaBackendUtils.hpp"
- #include "CarlaBase64Utils.hpp"
- #include "ThreadSafeFFTW.hpp"
- #ifndef BUILD_BRIDGE
- # include "CarlaLogThread.hpp"
- #endif
-
- #include "water/files/File.h"
-
- #define CARLA_SAFE_ASSERT_WITH_LAST_ERROR_RETURN(cond, msg, ret) \
- if (! (cond)) { \
- carla_stderr2("%s: " msg, __FUNCTION__); \
- if (handle->isStandalone) \
- ((CarlaHostStandalone*)handle)->lastError = msg; \
- return ret; \
- }
-
- // --------------------------------------------------------------------------------------------------------------------
-
- #ifdef USING_JUCE
- static void carla_standalone_juce_init(void);
- static void carla_standalone_juce_idle(void);
- static void carla_standalone_juce_cleanup(void);
- # define carla_juce_init carla_standalone_juce_init
- # define carla_juce_idle carla_standalone_juce_idle
- # define carla_juce_cleanup carla_standalone_juce_cleanup
- # include "utils/JUCE.cpp"
- # undef carla_juce_init
- # undef carla_juce_idle
- # undef carla_juce_cleanup
- #endif
-
- // -------------------------------------------------------------------------------------------------------------------
- // Always return a valid string ptr for standalone functions
-
- static const char* const gNullCharPtr = "";
-
- static void checkStringPtr(const char*& charPtr) noexcept
- {
- if (charPtr == nullptr)
- charPtr = gNullCharPtr;
- }
-
- // -------------------------------------------------------------------------------------------------------------------
- // Constructors
-
- _CarlaPluginInfo::_CarlaPluginInfo() noexcept
- : type(CB::PLUGIN_NONE),
- category(CB::PLUGIN_CATEGORY_NONE),
- hints(0x0),
- optionsAvailable(0x0),
- optionsEnabled(0x0),
- filename(gNullCharPtr),
- name(gNullCharPtr),
- label(gNullCharPtr),
- maker(gNullCharPtr),
- copyright(gNullCharPtr),
- iconName(gNullCharPtr),
- uniqueId(0) {}
-
- _CarlaPluginInfo::~_CarlaPluginInfo() noexcept
- {
- if (label != gNullCharPtr)
- delete[] label;
- if (maker != gNullCharPtr)
- delete[] maker;
- if (copyright != gNullCharPtr)
- delete[] copyright;
- }
-
- _CarlaParameterInfo::_CarlaParameterInfo() noexcept
- : name(gNullCharPtr),
- symbol(gNullCharPtr),
- unit(gNullCharPtr),
- comment(gNullCharPtr),
- groupName(gNullCharPtr),
- scalePointCount(0) {}
-
- _CarlaParameterInfo::~_CarlaParameterInfo() noexcept
- {
- if (name != gNullCharPtr)
- delete[] name;
- if (symbol != gNullCharPtr)
- delete[] symbol;
- if (unit != gNullCharPtr)
- delete[] unit;
- if (comment != gNullCharPtr)
- delete[] comment;
- if (groupName != gNullCharPtr)
- delete[] groupName;
- }
-
- _CarlaScalePointInfo::_CarlaScalePointInfo() noexcept
- : value(0.0f),
- label(gNullCharPtr) {}
-
- _CarlaScalePointInfo::~_CarlaScalePointInfo() noexcept
- {
- if (label != gNullCharPtr)
- delete[] label;
- }
-
- _CarlaTransportInfo::_CarlaTransportInfo() noexcept
- : playing(false),
- frame(0),
- bar(0),
- beat(0),
- tick(0),
- bpm(0.0) {}
-
- void _CarlaTransportInfo::clear() noexcept
- {
- playing = false;
- frame = 0;
- bar = 0;
- beat = 0;
- tick = 0;
- bpm = 0.0;
- }
-
- // --------------------------------------------------------------------------------------------------------------------
-
- using CarlaBackend::CarlaPluginPtr;
-
- // --------------------------------------------------------------------------------------------------------------------
-
- uint carla_get_engine_driver_count()
- {
- carla_debug("carla_get_engine_driver_count()");
-
- return CarlaEngine::getDriverCount();
- }
-
- const char* carla_get_engine_driver_name(uint index)
- {
- carla_debug("carla_get_engine_driver_name(%i)", index);
-
- return CarlaEngine::getDriverName(index);
- }
-
- const char* const* carla_get_engine_driver_device_names(uint index)
- {
- carla_debug("carla_get_engine_driver_device_names(%i)", index);
-
- return CarlaEngine::getDriverDeviceNames(index);
- }
-
- const EngineDriverDeviceInfo* carla_get_engine_driver_device_info(uint index, const char* name)
- {
- CARLA_SAFE_ASSERT_RETURN(name != nullptr, nullptr);
-
- static EngineDriverDeviceInfo retDevInfo;
- static const uint32_t nullBufferSizes[] = { 0 };
- static const double nullSampleRates[] = { 0.0 };
-
- carla_debug("carla_get_engine_driver_device_info(%i, \"%s\")", index, name);
-
- if (const EngineDriverDeviceInfo* const devInfo = CarlaEngine::getDriverDeviceInfo(index, name))
- {
- retDevInfo.hints = devInfo->hints;
- retDevInfo.bufferSizes = (devInfo->bufferSizes != nullptr) ? devInfo->bufferSizes : nullBufferSizes;
- retDevInfo.sampleRates = (devInfo->sampleRates != nullptr) ? devInfo->sampleRates : nullSampleRates;
- }
- else
- {
- retDevInfo.hints = 0x0;
- retDevInfo.bufferSizes = nullBufferSizes;
- retDevInfo.sampleRates = nullSampleRates;
- }
-
- return &retDevInfo;
- }
-
- bool carla_show_engine_driver_device_control_panel(uint index, const char* name)
- {
- return CarlaEngine::showDriverDeviceControlPanel(index, name);
- }
-
- // --------------------------------------------------------------------------------------------------------------------
-
- CarlaHostHandle carla_standalone_host_init(void)
- {
- #ifdef CARLA_OS_UNIX
- static const ThreadSafeFFTW sThreadSafeFFTW;
- #endif
-
- static CarlaHostStandalone gStandalone;
-
- return &gStandalone;
- }
-
- CarlaEngine* carla_get_engine_from_handle(CarlaHostHandle handle)
- {
- carla_debug("carla_get_engine(%p)", handle);
-
- return handle->engine;
- }
-
- // --------------------------------------------------------------------------------------------------------------------
-
- static void carla_engine_init_common(const CarlaHostStandalone& standalone, CarlaEngine* const engine)
- {
- engine->setCallback(standalone.engineCallback, standalone.engineCallbackPtr);
- engine->setFileCallback(standalone.fileCallback, standalone.fileCallbackPtr);
-
- using water::File;
- const File waterBinaryDir(File::getSpecialLocation(File::currentExecutableFile).getParentDirectory());
-
- #ifdef BUILD_BRIDGE
- /*
- if (const char* const forceStereo = std::getenv("ENGINE_OPTION_FORCE_STEREO"))
- engine->setOption(CB::ENGINE_OPTION_FORCE_STEREO, (std::strcmp(forceStereo, "true") == 0) ? 1 : 0, nullptr);
-
- if (const char* const preferPluginBridges = std::getenv("ENGINE_OPTION_PREFER_PLUGIN_BRIDGES"))
- engine->setOption(CB::ENGINE_OPTION_PREFER_PLUGIN_BRIDGES, (std::strcmp(preferPluginBridges, "true") == 0) ? 1 : 0, nullptr);
-
- if (const char* const preferUiBridges = std::getenv("ENGINE_OPTION_PREFER_UI_BRIDGES"))
- engine->setOption(CB::ENGINE_OPTION_PREFER_UI_BRIDGES, (std::strcmp(preferUiBridges, "true") == 0) ? 1 : 0, nullptr);
- */
-
- if (const char* const uisAlwaysOnTop = std::getenv("ENGINE_OPTION_UIS_ALWAYS_ON_TOP"))
- engine->setOption(CB::ENGINE_OPTION_UIS_ALWAYS_ON_TOP, (std::strcmp(uisAlwaysOnTop, "true") == 0) ? 1 : 0, nullptr);
-
- if (const char* const maxParameters = std::getenv("ENGINE_OPTION_MAX_PARAMETERS"))
- engine->setOption(CB::ENGINE_OPTION_MAX_PARAMETERS, std::atoi(maxParameters), nullptr);
-
- if (const char* const resetXruns = std::getenv("ENGINE_OPTION_RESET_XRUNS"))
- engine->setOption(CB::ENGINE_OPTION_RESET_XRUNS, (std::strcmp(resetXruns, "true") == 0) ? 1 : 0, nullptr);
-
- if (const char* const uiBridgesTimeout = std::getenv("ENGINE_OPTION_UI_BRIDGES_TIMEOUT"))
- engine->setOption(CB::ENGINE_OPTION_UI_BRIDGES_TIMEOUT, std::atoi(uiBridgesTimeout), nullptr);
-
- if (const char* const pathAudio = std::getenv("ENGINE_OPTION_FILE_PATH_AUDIO"))
- engine->setOption(CB::ENGINE_OPTION_FILE_PATH, CB::FILE_AUDIO, pathAudio);
-
- if (const char* const pathMIDI = std::getenv("ENGINE_OPTION_FILE_PATH_MIDI"))
- engine->setOption(CB::ENGINE_OPTION_FILE_PATH, CB::FILE_MIDI, pathMIDI);
-
- if (const char* const pathLADSPA = std::getenv("ENGINE_OPTION_PLUGIN_PATH_LADSPA"))
- engine->setOption(CB::ENGINE_OPTION_PLUGIN_PATH, CB::PLUGIN_LADSPA, pathLADSPA);
-
- if (const char* const pathDSSI = std::getenv("ENGINE_OPTION_PLUGIN_PATH_DSSI"))
- engine->setOption(CB::ENGINE_OPTION_PLUGIN_PATH, CB::PLUGIN_DSSI, pathDSSI);
-
- if (const char* const pathLV2 = std::getenv("ENGINE_OPTION_PLUGIN_PATH_LV2"))
- engine->setOption(CB::ENGINE_OPTION_PLUGIN_PATH, CB::PLUGIN_LV2, pathLV2);
-
- if (const char* const pathVST2 = std::getenv("ENGINE_OPTION_PLUGIN_PATH_VST2"))
- engine->setOption(CB::ENGINE_OPTION_PLUGIN_PATH, CB::PLUGIN_VST2, pathVST2);
-
- if (const char* const pathVST3 = std::getenv("ENGINE_OPTION_PLUGIN_PATH_VST3"))
- engine->setOption(CB::ENGINE_OPTION_PLUGIN_PATH, CB::PLUGIN_VST3, pathVST3);
-
- if (const char* const pathSF2 = std::getenv("ENGINE_OPTION_PLUGIN_PATH_SF2"))
- engine->setOption(CB::ENGINE_OPTION_PLUGIN_PATH, CB::PLUGIN_SF2, pathSF2);
-
- if (const char* const pathSFZ = std::getenv("ENGINE_OPTION_PLUGIN_PATH_SFZ"))
- engine->setOption(CB::ENGINE_OPTION_PLUGIN_PATH, CB::PLUGIN_SFZ, pathSFZ);
-
- if (const char* const binaryDir = std::getenv("ENGINE_OPTION_PATH_BINARIES"))
- engine->setOption(CB::ENGINE_OPTION_PATH_BINARIES, 0, binaryDir);
- else
- engine->setOption(CB::ENGINE_OPTION_PATH_BINARIES, 0, waterBinaryDir.getFullPathName().toRawUTF8());
-
- if (const char* const resourceDir = std::getenv("ENGINE_OPTION_PATH_RESOURCES"))
- engine->setOption(CB::ENGINE_OPTION_PATH_RESOURCES, 0, resourceDir);
- else
- engine->setOption(CB::ENGINE_OPTION_PATH_RESOURCES, 0, waterBinaryDir.getChildFile("resources").getFullPathName().toRawUTF8());
-
- if (const char* const preventBadBehaviour = std::getenv("ENGINE_OPTION_PREVENT_BAD_BEHAVIOUR"))
- engine->setOption(CB::ENGINE_OPTION_PREVENT_BAD_BEHAVIOUR, (std::strcmp(preventBadBehaviour, "true") == 0) ? 1 : 0, nullptr);
-
- if (const char* const frontendWinId = std::getenv("ENGINE_OPTION_FRONTEND_WIN_ID"))
- engine->setOption(CB::ENGINE_OPTION_FRONTEND_WIN_ID, 0, frontendWinId);
- #else
- engine->setOption(CB::ENGINE_OPTION_FORCE_STEREO, standalone.engineOptions.forceStereo ? 1 : 0, nullptr);
- engine->setOption(CB::ENGINE_OPTION_PREFER_PLUGIN_BRIDGES, standalone.engineOptions.preferPluginBridges ? 1 : 0, nullptr);
- engine->setOption(CB::ENGINE_OPTION_PREFER_UI_BRIDGES, standalone.engineOptions.preferUiBridges ? 1 : 0, nullptr);
- engine->setOption(CB::ENGINE_OPTION_UIS_ALWAYS_ON_TOP, standalone.engineOptions.uisAlwaysOnTop ? 1 : 0, nullptr);
- engine->setOption(CB::ENGINE_OPTION_MAX_PARAMETERS, static_cast<int>(standalone.engineOptions.maxParameters), nullptr);
- engine->setOption(CB::ENGINE_OPTION_RESET_XRUNS, standalone.engineOptions.resetXruns ? 1 : 0, nullptr);
- engine->setOption(CB::ENGINE_OPTION_UI_BRIDGES_TIMEOUT, static_cast<int>(standalone.engineOptions.uiBridgesTimeout), nullptr);
- engine->setOption(CB::ENGINE_OPTION_AUDIO_BUFFER_SIZE, static_cast<int>(standalone.engineOptions.audioBufferSize), nullptr);
- engine->setOption(CB::ENGINE_OPTION_AUDIO_SAMPLE_RATE, static_cast<int>(standalone.engineOptions.audioSampleRate), nullptr);
- engine->setOption(CB::ENGINE_OPTION_AUDIO_TRIPLE_BUFFER, standalone.engineOptions.audioTripleBuffer ? 1 : 0, nullptr);
-
- if (standalone.engineOptions.audioDriver != nullptr)
- engine->setOption(CB::ENGINE_OPTION_AUDIO_DRIVER, 0, standalone.engineOptions.audioDriver);
-
- if (standalone.engineOptions.audioDevice != nullptr)
- engine->setOption(CB::ENGINE_OPTION_AUDIO_DEVICE, 0, standalone.engineOptions.audioDevice);
-
- engine->setOption(CB::ENGINE_OPTION_OSC_ENABLED, standalone.engineOptions.oscEnabled, nullptr);
- engine->setOption(CB::ENGINE_OPTION_OSC_PORT_TCP, standalone.engineOptions.oscPortTCP, nullptr);
- engine->setOption(CB::ENGINE_OPTION_OSC_PORT_UDP, standalone.engineOptions.oscPortUDP, nullptr);
-
- if (standalone.engineOptions.pathAudio != nullptr)
- engine->setOption(CB::ENGINE_OPTION_FILE_PATH, CB::FILE_AUDIO, standalone.engineOptions.pathAudio);
-
- if (standalone.engineOptions.pathMIDI != nullptr)
- engine->setOption(CB::ENGINE_OPTION_FILE_PATH, CB::FILE_MIDI, standalone.engineOptions.pathMIDI);
-
- if (standalone.engineOptions.pathLADSPA != nullptr)
- engine->setOption(CB::ENGINE_OPTION_PLUGIN_PATH, CB::PLUGIN_LADSPA, standalone.engineOptions.pathLADSPA);
-
- if (standalone.engineOptions.pathDSSI != nullptr)
- engine->setOption(CB::ENGINE_OPTION_PLUGIN_PATH, CB::PLUGIN_DSSI, standalone.engineOptions.pathDSSI);
-
- if (standalone.engineOptions.pathLV2 != nullptr)
- engine->setOption(CB::ENGINE_OPTION_PLUGIN_PATH, CB::PLUGIN_LV2, standalone.engineOptions.pathLV2);
-
- if (standalone.engineOptions.pathVST2 != nullptr)
- engine->setOption(CB::ENGINE_OPTION_PLUGIN_PATH, CB::PLUGIN_VST2, standalone.engineOptions.pathVST2);
-
- if (standalone.engineOptions.pathVST3 != nullptr)
- engine->setOption(CB::ENGINE_OPTION_PLUGIN_PATH, CB::PLUGIN_VST3, standalone.engineOptions.pathVST3);
-
- if (standalone.engineOptions.pathSF2 != nullptr)
- engine->setOption(CB::ENGINE_OPTION_PLUGIN_PATH, CB::PLUGIN_SF2, standalone.engineOptions.pathSF2);
-
- if (standalone.engineOptions.pathSFZ != nullptr)
- engine->setOption(CB::ENGINE_OPTION_PLUGIN_PATH, CB::PLUGIN_SFZ, standalone.engineOptions.pathSFZ);
-
- if (standalone.engineOptions.binaryDir != nullptr && standalone.engineOptions.binaryDir[0] != '\0')
- engine->setOption(CB::ENGINE_OPTION_PATH_BINARIES, 0, standalone.engineOptions.binaryDir);
- else
- engine->setOption(CB::ENGINE_OPTION_PATH_BINARIES, 0, waterBinaryDir.getFullPathName().toRawUTF8());
-
- if (standalone.engineOptions.resourceDir != nullptr && standalone.engineOptions.resourceDir[0] != '\0')
- engine->setOption(CB::ENGINE_OPTION_PATH_RESOURCES, 0, standalone.engineOptions.resourceDir);
-
- engine->setOption(CB::ENGINE_OPTION_PREVENT_BAD_BEHAVIOUR, standalone.engineOptions.preventBadBehaviour ? 1 : 0, nullptr);
-
- engine->setOption(CB::ENGINE_OPTION_FRONTEND_BACKGROUND_COLOR, static_cast<int>(standalone.engineOptions.bgColor), nullptr);
- engine->setOption(CB::ENGINE_OPTION_FRONTEND_FOREGROUND_COLOR, static_cast<int>(standalone.engineOptions.fgColor), nullptr);
- engine->setOption(CB::ENGINE_OPTION_FRONTEND_UI_SCALE, static_cast<int>(standalone.engineOptions.uiScale * 1000.0f), nullptr);
-
- if (standalone.engineOptions.frontendWinId != 0)
- {
- char strBuf[STR_MAX+1];
- strBuf[STR_MAX] = '\0';
- std::snprintf(strBuf, STR_MAX, P_UINTPTR, standalone.engineOptions.frontendWinId);
- engine->setOption(CB::ENGINE_OPTION_FRONTEND_WIN_ID, 0, strBuf);
- }
- else
- {
- engine->setOption(CB::ENGINE_OPTION_FRONTEND_WIN_ID, 0, "0");
- }
-
- # ifndef CARLA_OS_WIN
- if (standalone.engineOptions.wine.executable != nullptr && standalone.engineOptions.wine.executable[0] != '\0')
- engine->setOption(CB::ENGINE_OPTION_WINE_EXECUTABLE, 0, standalone.engineOptions.wine.executable);
-
- engine->setOption(CB::ENGINE_OPTION_WINE_AUTO_PREFIX, standalone.engineOptions.wine.autoPrefix ? 1 : 0, nullptr);
-
- if (standalone.engineOptions.wine.fallbackPrefix != nullptr && standalone.engineOptions.wine.fallbackPrefix[0] != '\0')
- engine->setOption(CB::ENGINE_OPTION_WINE_FALLBACK_PREFIX, 0, standalone.engineOptions.wine.fallbackPrefix);
-
- engine->setOption(CB::ENGINE_OPTION_WINE_RT_PRIO_ENABLED, standalone.engineOptions.wine.rtPrio ? 1 : 0, nullptr);
- engine->setOption(CB::ENGINE_OPTION_WINE_BASE_RT_PRIO, standalone.engineOptions.wine.baseRtPrio, nullptr);
- engine->setOption(CB::ENGINE_OPTION_WINE_SERVER_RT_PRIO, standalone.engineOptions.wine.serverRtPrio, nullptr);
- # endif
-
- engine->setOption(CB::ENGINE_OPTION_CLIENT_NAME_PREFIX, 0, standalone.engineOptions.clientNamePrefix);
-
- engine->setOption(CB::ENGINE_OPTION_PLUGINS_ARE_STANDALONE, standalone.engineOptions.pluginsAreStandalone, nullptr);
- #endif // BUILD_BRIDGE
- }
-
- bool carla_engine_init(CarlaHostHandle handle, 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(%p, \"%s\", \"%s\")", handle, driverName, clientName);
-
- CARLA_SAFE_ASSERT_WITH_LAST_ERROR_RETURN(handle->isStandalone, "Must be a standalone host handle", false);
- CARLA_SAFE_ASSERT_WITH_LAST_ERROR_RETURN(handle->engine == nullptr, "Engine is already initialized", false);
-
- #ifdef CARLA_OS_WIN
- carla_setenv("WINEASIO_CLIENT_NAME", clientName);
- #endif
-
- #ifdef USING_JUCE
- carla_standalone_juce_init();
- #endif
-
- CarlaHostStandalone& shandle((CarlaHostStandalone&)*handle);
-
- CarlaEngine* const engine = CarlaEngine::newDriverByName(driverName);
- CARLA_SAFE_ASSERT_WITH_LAST_ERROR_RETURN(engine != nullptr, "The selected audio driver is not available", false);
-
- shandle.engine = engine;
-
- #ifdef BUILD_BRIDGE
- if (std::getenv("CARLA_BRIDGE_DUMMY") != nullptr)
- {
- // engine->setOption(CB::ENGINE_OPTION_PROCESS_MODE, CB::ENGINE_PROCESS_MODE_PATCHBAY, nullptr);
- engine->setOption(CB::ENGINE_OPTION_PROCESS_MODE, CB::ENGINE_PROCESS_MODE_CONTINUOUS_RACK, nullptr);
- engine->setOption(CB::ENGINE_OPTION_TRANSPORT_MODE, CB::ENGINE_TRANSPORT_MODE_INTERNAL, nullptr);
-
- engine->setOption(CB::ENGINE_OPTION_AUDIO_BUFFER_SIZE, 4096, nullptr);
- engine->setOption(CB::ENGINE_OPTION_AUDIO_SAMPLE_RATE, 48000, nullptr);
- }
- else
- {
- engine->setOption(CB::ENGINE_OPTION_PROCESS_MODE, CB::ENGINE_PROCESS_MODE_MULTIPLE_CLIENTS, nullptr);
- engine->setOption(CB::ENGINE_OPTION_TRANSPORT_MODE, CB::ENGINE_TRANSPORT_MODE_JACK, nullptr);
- }
- engine->setOption(CB::ENGINE_OPTION_FORCE_STEREO, false, nullptr);
- engine->setOption(CB::ENGINE_OPTION_PREFER_PLUGIN_BRIDGES, false, nullptr);
- engine->setOption(CB::ENGINE_OPTION_PREFER_UI_BRIDGES, false, nullptr);
- #else
- engine->setOption(CB::ENGINE_OPTION_PROCESS_MODE, static_cast<int>(shandle.engineOptions.processMode), nullptr);
- engine->setOption(CB::ENGINE_OPTION_TRANSPORT_MODE, static_cast<int>(shandle.engineOptions.transportMode), shandle.engineOptions.transportExtra);
- #endif
-
- carla_engine_init_common(shandle, engine);
-
- if (engine->init(clientName))
- {
- #ifndef BUILD_BRIDGE
- if (shandle.logThreadEnabled && std::getenv("CARLA_LOGS_DISABLED") == nullptr)
- shandle.logThread.init();
- #endif
- shandle.lastError = "No error";
- return true;
- }
- else
- {
- shandle.lastError = engine->getLastError();
- shandle.engine = nullptr;
- delete engine;
- #ifdef USING_JUCE
- carla_standalone_juce_cleanup();
- #endif
- return false;
- }
- }
-
- #ifdef BUILD_BRIDGE
- bool carla_engine_init_bridge(CarlaHostHandle handle,
- const char audioBaseName[6+1],
- const char rtClientBaseName[6+1],
- const char nonRtClientBaseName[6+1],
- const char nonRtServerBaseName[6+1],
- const char* const clientName)
- {
- CARLA_SAFE_ASSERT_RETURN(audioBaseName != nullptr && audioBaseName[0] != '\0', false);
- CARLA_SAFE_ASSERT_RETURN(rtClientBaseName != nullptr && rtClientBaseName[0] != '\0', false);
- CARLA_SAFE_ASSERT_RETURN(nonRtClientBaseName != nullptr && nonRtClientBaseName[0] != '\0', false);
- CARLA_SAFE_ASSERT_RETURN(nonRtServerBaseName != nullptr && nonRtServerBaseName[0] != '\0', false);
- CARLA_SAFE_ASSERT_RETURN(clientName != nullptr && clientName[0] != '\0', false);
- carla_debug("carla_engine_init_bridge(%p, \"%s\", \"%s\", \"%s\", \"%s\", \"%s\")",
- handle, audioBaseName, rtClientBaseName, nonRtClientBaseName, nonRtServerBaseName, clientName);
-
- CARLA_SAFE_ASSERT_WITH_LAST_ERROR_RETURN(handle->isStandalone, "Must be a standalone host handle", false);
- CARLA_SAFE_ASSERT_WITH_LAST_ERROR_RETURN(handle->engine == nullptr, "Engine is already initialized", false);
-
- CarlaScopedPointer<CarlaEngine> engine(CB::EngineInit::newBridge(audioBaseName,
- rtClientBaseName,
- nonRtClientBaseName,
- nonRtServerBaseName));
-
- CARLA_SAFE_ASSERT_WITH_LAST_ERROR_RETURN(engine != nullptr, "The selected audio driver is not available", false);
-
- engine->setOption(CB::ENGINE_OPTION_PROCESS_MODE, CB::ENGINE_PROCESS_MODE_BRIDGE, nullptr);
- engine->setOption(CB::ENGINE_OPTION_TRANSPORT_MODE, CB::ENGINE_TRANSPORT_MODE_BRIDGE, nullptr);
-
- CarlaHostStandalone& shandle((CarlaHostStandalone&)*handle);
-
- carla_engine_init_common(shandle, engine);
-
- if (engine->init(clientName))
- {
- shandle.lastError = "No error";
- shandle.engine = engine.release();
- return true;
- }
- else
- {
- shandle.lastError = engine->getLastError();
- return false;
- }
- }
- #endif
-
- bool carla_engine_close(CarlaHostHandle handle)
- {
- carla_debug("carla_engine_close(%p)", handle);
-
- CARLA_SAFE_ASSERT_WITH_LAST_ERROR_RETURN(handle->isStandalone, "Must be a standalone host handle", false);
- CARLA_SAFE_ASSERT_WITH_LAST_ERROR_RETURN(handle->engine != nullptr, "Engine is not initialized", false);
-
- CarlaHostStandalone& shandle((CarlaHostStandalone&)*handle);
-
- CarlaEngine* const engine = shandle.engine;
-
- engine->setAboutToClose();
- engine->removeAllPlugins();
-
- const bool closed = engine->close();
-
- if (! closed)
- shandle.lastError = engine->getLastError();
-
- #ifndef BUILD_BRIDGE
- shandle.logThread.stop();
- #endif
-
- shandle.engine = nullptr;
- delete engine;
-
- #ifdef USING_JUCE
- carla_standalone_juce_cleanup();
- #endif
- return closed;
- }
-
- void carla_engine_idle(CarlaHostHandle handle)
- {
- CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr && handle->isStandalone,);
-
- handle->engine->idle();
-
- #ifdef USING_JUCE
- if (handle->isStandalone)
- carla_standalone_juce_idle();
- #endif
- }
-
- bool carla_is_engine_running(CarlaHostHandle handle)
- {
- return (handle->engine != nullptr && handle->engine->isRunning());
- }
-
- const CarlaRuntimeEngineInfo* carla_get_runtime_engine_info(CarlaHostHandle handle)
- {
- static CarlaRuntimeEngineInfo retInfo;
-
- // reset
- retInfo.load = 0.0f;
- retInfo.xruns = 0;
-
- CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, &retInfo);
-
- retInfo.load = handle->engine->getDSPLoad();
- retInfo.xruns = handle->engine->getTotalXruns();
-
- return &retInfo;
- }
-
- #ifndef BUILD_BRIDGE
- const CarlaRuntimeEngineDriverDeviceInfo* carla_get_runtime_engine_driver_device_info(CarlaHostHandle handle)
- {
- static CarlaRuntimeEngineDriverDeviceInfo retInfo;
-
- // reset
- retInfo.name = gNullCharPtr;
- retInfo.hints = 0x0;
- retInfo.bufferSize = 0;
- retInfo.bufferSizes = nullptr;
- retInfo.sampleRate = 0.0;
- retInfo.sampleRates = nullptr;
-
- const char* audioDriver;
- const char* audioDevice;
-
- if (CarlaEngine* const engine = handle->engine)
- {
- audioDriver = engine->getCurrentDriverName();
- audioDevice = engine->getOptions().audioDevice;
-
- retInfo.bufferSize = engine->getBufferSize();
- retInfo.sampleRate = engine->getSampleRate();
- }
- else if (handle->isStandalone)
- {
- CarlaHostStandalone& shandle((CarlaHostStandalone&)*handle);
-
- audioDriver = shandle.engineOptions.audioDriver;
- audioDevice = shandle.engineOptions.audioDevice;
-
- retInfo.bufferSize = shandle.engineOptions.audioBufferSize;
- retInfo.sampleRate = shandle.engineOptions.audioSampleRate;
- }
- else
- {
- return &retInfo;
- }
- CARLA_SAFE_ASSERT_RETURN(audioDriver != nullptr, &retInfo);
- CARLA_SAFE_ASSERT_RETURN(audioDevice != nullptr, &retInfo);
-
- uint index = 0;
- uint count = CarlaEngine::getDriverCount();
- for (; index<count; ++index)
- {
- const char* const testDriverName = CarlaEngine::getDriverName(index);
- CARLA_SAFE_ASSERT_CONTINUE(testDriverName != nullptr);
-
- if (std::strcmp(testDriverName, audioDriver) == 0)
- break;
- }
- CARLA_SAFE_ASSERT_RETURN(index != count, &retInfo);
-
- const EngineDriverDeviceInfo* const devInfo = CarlaEngine::getDriverDeviceInfo(index, audioDevice);
- CARLA_SAFE_ASSERT_RETURN(devInfo != nullptr, &retInfo);
-
- retInfo.name = audioDevice;
- retInfo.hints = devInfo->hints;
- retInfo.bufferSizes = devInfo->bufferSizes;
- retInfo.sampleRates = devInfo->sampleRates;
-
- return &retInfo;
- }
-
- bool carla_set_engine_buffer_size_and_sample_rate(CarlaHostHandle handle, uint bufferSize, double sampleRate)
- {
- CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, false);
- carla_debug("carla_set_engine_buffer_size_and_sample_rate(%p, %u, %f)", handle, bufferSize, sampleRate);
-
- return handle->engine->setBufferSizeAndSampleRate(bufferSize, sampleRate);
- }
-
- bool carla_show_engine_device_control_panel(CarlaHostHandle handle)
- {
- CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, false);
- carla_debug("carla_show_engine_device_control_panel(%p)", handle);
-
- return handle->engine->showDeviceControlPanel();
- }
- #endif // BUILD_BRIDGE
-
- void carla_clear_engine_xruns(CarlaHostHandle handle)
- {
- if (handle->engine != nullptr)
- handle->engine->clearXruns();
- }
-
- void carla_cancel_engine_action(CarlaHostHandle handle)
- {
- if (handle->engine != nullptr)
- handle->engine->setActionCanceled(true);
- }
-
- bool carla_set_engine_about_to_close(CarlaHostHandle handle)
- {
- CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, true);
- carla_debug("carla_set_engine_about_to_close(%p)", handle);
-
- return handle->engine->setAboutToClose();
- }
-
- void carla_set_engine_callback(CarlaHostHandle handle, EngineCallbackFunc func, void* ptr)
- {
- carla_debug("carla_set_engine_callback(%p, %p, %p)", handle, func, ptr);
-
- if (handle->isStandalone)
- {
- CarlaHostStandalone& shandle((CarlaHostStandalone&)*handle);
-
- shandle.engineCallback = func;
- shandle.engineCallbackPtr = ptr;
-
- #ifndef BUILD_BRIDGE
- shandle.logThread.setCallback(func, ptr);
- #endif
- }
-
- if (handle->engine != nullptr)
- handle->engine->setCallback(func, ptr);
- }
-
- void carla_set_engine_option(CarlaHostHandle handle, EngineOption option, int value, const char* valueStr)
- {
- carla_debug("carla_set_engine_option(%p, %i:%s, %i, \"%s\")",
- handle, option, CB::EngineOption2Str(option), value, valueStr);
-
- if (handle->isStandalone)
- {
- CarlaHostStandalone& shandle((CarlaHostStandalone&)*handle);
-
- switch (option)
- {
- case CB::ENGINE_OPTION_DEBUG:
- break;
-
- case CB::ENGINE_OPTION_PROCESS_MODE:
- CARLA_SAFE_ASSERT_RETURN(value >= CB::ENGINE_PROCESS_MODE_SINGLE_CLIENT && value < CB::ENGINE_PROCESS_MODE_BRIDGE,);
- shandle.engineOptions.processMode = static_cast<CB::EngineProcessMode>(value);
- break;
-
- case CB::ENGINE_OPTION_TRANSPORT_MODE:
- CARLA_SAFE_ASSERT_RETURN(value >= CB::ENGINE_TRANSPORT_MODE_DISABLED && value <= CB::ENGINE_TRANSPORT_MODE_BRIDGE,);
-
- // jack transport cannot be disabled in multi-client
- if (shandle.engineOptions.processMode == CB::ENGINE_PROCESS_MODE_MULTIPLE_CLIENTS
- && value != CB::ENGINE_TRANSPORT_MODE_JACK)
- {
- shandle.engineOptions.transportMode = CB::ENGINE_TRANSPORT_MODE_JACK;
-
- if (shandle.engineCallback != nullptr)
- shandle.engineCallback(shandle.engineCallbackPtr,
- CB::ENGINE_CALLBACK_TRANSPORT_MODE_CHANGED,
- 0,
- CB::ENGINE_TRANSPORT_MODE_JACK,
- 0, 0, 0.0f,
- shandle.engineOptions.transportExtra);
- }
- else
- {
- shandle.engineOptions.transportMode = static_cast<CB::EngineTransportMode>(value);
- }
-
- delete[] shandle.engineOptions.transportExtra;
- if (value != CB::ENGINE_TRANSPORT_MODE_DISABLED && valueStr != nullptr)
- shandle.engineOptions.transportExtra = carla_strdup_safe(valueStr);
- else
- shandle.engineOptions.transportExtra = nullptr;
- break;
-
- case CB::ENGINE_OPTION_FORCE_STEREO:
- CARLA_SAFE_ASSERT_RETURN(value == 0 || value == 1,);
- shandle.engineOptions.forceStereo = (value != 0);
- break;
-
- case CB::ENGINE_OPTION_PREFER_PLUGIN_BRIDGES:
- CARLA_SAFE_ASSERT_RETURN(value == 0 || value == 1,);
- shandle.engineOptions.preferPluginBridges = (value != 0);
- break;
-
- case CB::ENGINE_OPTION_PREFER_UI_BRIDGES:
- CARLA_SAFE_ASSERT_RETURN(value == 0 || value == 1,);
- shandle.engineOptions.preferUiBridges = (value != 0);
- break;
-
- case CB::ENGINE_OPTION_UIS_ALWAYS_ON_TOP:
- CARLA_SAFE_ASSERT_RETURN(value == 0 || value == 1,);
- shandle.engineOptions.uisAlwaysOnTop = (value != 0);
- break;
-
- case CB::ENGINE_OPTION_MAX_PARAMETERS:
- CARLA_SAFE_ASSERT_RETURN(value >= 0,);
- shandle.engineOptions.maxParameters = static_cast<uint>(value);
- break;
-
- case CB::ENGINE_OPTION_RESET_XRUNS:
- CARLA_SAFE_ASSERT_RETURN(value == 0 || value == 1,);
- shandle.engineOptions.resetXruns = (value != 0);
- break;
-
- case CB::ENGINE_OPTION_UI_BRIDGES_TIMEOUT:
- CARLA_SAFE_ASSERT_RETURN(value >= 0,);
- shandle.engineOptions.uiBridgesTimeout = static_cast<uint>(value);
- break;
-
- case CB::ENGINE_OPTION_AUDIO_BUFFER_SIZE:
- CARLA_SAFE_ASSERT_RETURN(value >= 8,);
- shandle.engineOptions.audioBufferSize = static_cast<uint>(value);
- break;
-
- case CB::ENGINE_OPTION_AUDIO_SAMPLE_RATE:
- CARLA_SAFE_ASSERT_RETURN(value >= 22050,);
- shandle.engineOptions.audioSampleRate = static_cast<uint>(value);
- break;
-
- case CB::ENGINE_OPTION_AUDIO_TRIPLE_BUFFER:
- CARLA_SAFE_ASSERT_RETURN(value == 0 || value == 1,);
- shandle.engineOptions.audioTripleBuffer = (value != 0);
- break;
-
- case CB::ENGINE_OPTION_AUDIO_DRIVER:
- CARLA_SAFE_ASSERT_RETURN(valueStr != nullptr,);
-
- if (shandle.engineOptions.audioDriver != nullptr)
- delete[] shandle.engineOptions.audioDriver;
-
- shandle.engineOptions.audioDriver = carla_strdup_safe(valueStr);
- break;
-
- case CB::ENGINE_OPTION_AUDIO_DEVICE:
- CARLA_SAFE_ASSERT_RETURN(valueStr != nullptr,);
-
- if (shandle.engineOptions.audioDevice != nullptr)
- delete[] shandle.engineOptions.audioDevice;
-
- shandle.engineOptions.audioDevice = carla_strdup_safe(valueStr);
- break;
-
- #ifndef BUILD_BRIDGE
- case CB::ENGINE_OPTION_OSC_ENABLED:
- CARLA_SAFE_ASSERT_RETURN(value == 0 || value == 1,);
- shandle.engineOptions.oscEnabled = (value != 0);
- break;
-
- case CB::ENGINE_OPTION_OSC_PORT_TCP:
- CARLA_SAFE_ASSERT_RETURN(value <= 0 || value >= 1024,);
- shandle.engineOptions.oscPortTCP = value;
- break;
-
- case CB::ENGINE_OPTION_OSC_PORT_UDP:
- CARLA_SAFE_ASSERT_RETURN(value <= 0 || value >= 1024,);
- shandle.engineOptions.oscPortUDP = value;
- break;
- #endif
-
- case CB::ENGINE_OPTION_FILE_PATH:
- CARLA_SAFE_ASSERT_RETURN(value > CB::FILE_NONE,);
- CARLA_SAFE_ASSERT_RETURN(value <= CB::FILE_MIDI,);
- CARLA_SAFE_ASSERT_RETURN(valueStr != nullptr,);
-
- switch (value)
- {
- case CB::FILE_AUDIO:
- if (shandle.engineOptions.pathAudio != nullptr)
- delete[] shandle.engineOptions.pathAudio;
- shandle.engineOptions.pathAudio = carla_strdup_safe(valueStr);
- break;
- case CB::FILE_MIDI:
- if (shandle.engineOptions.pathMIDI != nullptr)
- delete[] shandle.engineOptions.pathMIDI;
- shandle.engineOptions.pathMIDI = carla_strdup_safe(valueStr);
- break;
- }
- break;
-
- case CB::ENGINE_OPTION_PLUGIN_PATH:
- CARLA_SAFE_ASSERT_RETURN(value > CB::PLUGIN_NONE,);
- CARLA_SAFE_ASSERT_RETURN(value <= CB::PLUGIN_SFZ,);
- CARLA_SAFE_ASSERT_RETURN(valueStr != nullptr,);
-
- switch (value)
- {
- case CB::PLUGIN_LADSPA:
- if (shandle.engineOptions.pathLADSPA != nullptr)
- delete[] shandle.engineOptions.pathLADSPA;
- shandle.engineOptions.pathLADSPA = carla_strdup_safe(valueStr);
- break;
- case CB::PLUGIN_DSSI:
- if (shandle.engineOptions.pathDSSI != nullptr)
- delete[] shandle.engineOptions.pathDSSI;
- shandle.engineOptions.pathDSSI = carla_strdup_safe(valueStr);
- break;
- case CB::PLUGIN_LV2:
- if (shandle.engineOptions.pathLV2 != nullptr)
- delete[] shandle.engineOptions.pathLV2;
- shandle.engineOptions.pathLV2 = carla_strdup_safe(valueStr);
- break;
- case CB::PLUGIN_VST2:
- if (shandle.engineOptions.pathVST2 != nullptr)
- delete[] shandle.engineOptions.pathVST2;
- shandle.engineOptions.pathVST2 = carla_strdup_safe(valueStr);
- break;
- case CB::PLUGIN_VST3:
- if (shandle.engineOptions.pathVST3 != nullptr)
- delete[] shandle.engineOptions.pathVST3;
- shandle.engineOptions.pathVST3 = carla_strdup_safe(valueStr);
- break;
- case CB::PLUGIN_SF2:
- if (shandle.engineOptions.pathSF2 != nullptr)
- delete[] shandle.engineOptions.pathSF2;
- shandle.engineOptions.pathSF2 = carla_strdup_safe(valueStr);
- break;
- case CB::PLUGIN_SFZ:
- if (shandle.engineOptions.pathSFZ != nullptr)
- delete[] shandle.engineOptions.pathSFZ;
- shandle.engineOptions.pathSFZ = carla_strdup_safe(valueStr);
- break;
- }
- break;
-
- case CB::ENGINE_OPTION_PATH_BINARIES:
- CARLA_SAFE_ASSERT_RETURN(valueStr != nullptr && valueStr[0] != '\0',);
-
- if (shandle.engineOptions.binaryDir != nullptr)
- delete[] shandle.engineOptions.binaryDir;
-
- shandle.engineOptions.binaryDir = carla_strdup_safe(valueStr);
- break;
-
- case CB::ENGINE_OPTION_PATH_RESOURCES:
- CARLA_SAFE_ASSERT_RETURN(valueStr != nullptr && valueStr[0] != '\0',);
-
- if (shandle.engineOptions.resourceDir != nullptr)
- delete[] shandle.engineOptions.resourceDir;
-
- shandle.engineOptions.resourceDir = carla_strdup_safe(valueStr);
- break;
-
- case CB::ENGINE_OPTION_PREVENT_BAD_BEHAVIOUR:
- CARLA_SAFE_ASSERT_RETURN(value == 0 || value == 1,);
- shandle.engineOptions.preventBadBehaviour = (value != 0);
- break;
-
- case CB::ENGINE_OPTION_FRONTEND_BACKGROUND_COLOR:
- shandle.engineOptions.bgColor = static_cast<uint>(value);
- break;
-
- case CB::ENGINE_OPTION_FRONTEND_FOREGROUND_COLOR:
- shandle.engineOptions.fgColor = static_cast<uint>(value);
- break;
-
- case CB::ENGINE_OPTION_FRONTEND_UI_SCALE:
- CARLA_SAFE_ASSERT_RETURN(value > 0,);
- shandle.engineOptions.uiScale = static_cast<float>(value) / 1000;
- break;
-
- case CB::ENGINE_OPTION_FRONTEND_WIN_ID: {
- CARLA_SAFE_ASSERT_RETURN(valueStr != nullptr && valueStr[0] != '\0',);
- const long long winId(std::strtoll(valueStr, nullptr, 16));
- CARLA_SAFE_ASSERT_RETURN(winId >= 0,);
- shandle.engineOptions.frontendWinId = static_cast<uintptr_t>(winId);
- } break;
-
- #if !defined(BUILD_BRIDGE_ALTERNATIVE_ARCH) && !defined(CARLA_OS_WIN)
- case CB::ENGINE_OPTION_WINE_EXECUTABLE:
- CARLA_SAFE_ASSERT_RETURN(valueStr != nullptr && valueStr[0] != '\0',);
-
- if (shandle.engineOptions.wine.executable != nullptr)
- delete[] shandle.engineOptions.wine.executable;
-
- shandle.engineOptions.wine.executable = carla_strdup_safe(valueStr);
- break;
-
- case CB::ENGINE_OPTION_WINE_AUTO_PREFIX:
- CARLA_SAFE_ASSERT_RETURN(value == 0 || value == 1,);
- shandle.engineOptions.wine.autoPrefix = (value != 0);
- break;
-
- case CB::ENGINE_OPTION_WINE_FALLBACK_PREFIX:
- CARLA_SAFE_ASSERT_RETURN(valueStr != nullptr && valueStr[0] != '\0',);
-
- if (shandle.engineOptions.wine.fallbackPrefix != nullptr)
- delete[] shandle.engineOptions.wine.fallbackPrefix;
-
- shandle.engineOptions.wine.fallbackPrefix = carla_strdup_safe(valueStr);
- break;
-
- case CB::ENGINE_OPTION_WINE_RT_PRIO_ENABLED:
- CARLA_SAFE_ASSERT_RETURN(value == 0 || value == 1,);
- shandle.engineOptions.wine.rtPrio = (value != 0);
- break;
-
- case CB::ENGINE_OPTION_WINE_BASE_RT_PRIO:
- CARLA_SAFE_ASSERT_RETURN(value >= 1 && value <= 89,);
- shandle.engineOptions.wine.baseRtPrio = value;
- break;
-
- case CB::ENGINE_OPTION_WINE_SERVER_RT_PRIO:
- CARLA_SAFE_ASSERT_RETURN(value >= 1 && value <= 99,);
- shandle.engineOptions.wine.serverRtPrio = value;
- break;
- #endif
-
- #ifndef BUILD_BRIDGE
- case CB::ENGINE_OPTION_DEBUG_CONSOLE_OUTPUT:
- shandle.logThreadEnabled = (value != 0);
- break;
- #endif
-
- case CB::ENGINE_OPTION_CLIENT_NAME_PREFIX:
- if (shandle.engineOptions.clientNamePrefix != nullptr)
- delete[] shandle.engineOptions.clientNamePrefix;
-
- shandle.engineOptions.clientNamePrefix = valueStr != nullptr && valueStr[0] != '\0'
- ? carla_strdup_safe(valueStr)
- : nullptr;
- break;
-
- case CB::ENGINE_OPTION_PLUGINS_ARE_STANDALONE:
- CARLA_SAFE_ASSERT_RETURN(value == 0 || value == 1,);
- shandle.engineOptions.pluginsAreStandalone = (value != 0);
- break;
- }
- }
-
- if (handle->engine != nullptr)
- handle->engine->setOption(option, value, valueStr);
- }
-
- void carla_set_file_callback(CarlaHostHandle handle, FileCallbackFunc func, void* ptr)
- {
- carla_debug("carla_set_file_callback(%p, %p, %p)", handle, func, ptr);
-
- if (handle->isStandalone)
- {
- CarlaHostStandalone& shandle((CarlaHostStandalone&)*handle);
-
- shandle.fileCallback = func;
- shandle.fileCallbackPtr = ptr;
- }
-
- if (handle->engine != nullptr)
- handle->engine->setFileCallback(func, ptr);
- }
-
- // --------------------------------------------------------------------------------------------------------------------
-
- bool carla_load_file(CarlaHostHandle handle, const char* filename)
- {
- CARLA_SAFE_ASSERT_RETURN(filename != nullptr && filename[0] != '\0', false);
- CARLA_SAFE_ASSERT_WITH_LAST_ERROR_RETURN(handle->engine != nullptr, "Engine is not initialized", false);
-
- carla_debug("carla_load_file(%p, \"%s\")", handle, filename);
-
- return handle->engine->loadFile(filename);
- }
-
- bool carla_load_project(CarlaHostHandle handle, const char* filename)
- {
- CARLA_SAFE_ASSERT_RETURN(filename != nullptr && filename[0] != '\0', false);
- CARLA_SAFE_ASSERT_WITH_LAST_ERROR_RETURN(handle->engine != nullptr, "Engine is not initialized", false);
-
- carla_debug("carla_load_project(%p, \"%s\")", handle, filename);
-
- return handle->engine->loadProject(filename, true);
- }
-
- bool carla_save_project(CarlaHostHandle handle, const char* filename)
- {
- CARLA_SAFE_ASSERT_RETURN(filename != nullptr && filename[0] != '\0', false);
- CARLA_SAFE_ASSERT_WITH_LAST_ERROR_RETURN(handle->engine != nullptr, "Engine is not initialized", false);
-
- carla_debug("carla_save_project(%p, \"%s\")", handle, filename);
-
- return handle->engine->saveProject(filename, true);
- }
-
- #ifndef BUILD_BRIDGE
- const char* carla_get_current_project_folder(CarlaHostHandle handle)
- {
- CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, gNullCharPtr);
-
- carla_debug("carla_get_current_project_folder(%p)", handle);
-
- if (const char* const ret = handle->engine->getCurrentProjectFolder())
- return ret;
-
- return gNullCharPtr;
- }
-
- const char* carla_get_current_project_filename(CarlaHostHandle handle)
- {
- CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr && handle->isStandalone, gNullCharPtr);
-
- carla_debug("carla_get_current_project_filename(%p)", handle);
-
- if (const char* const ret = handle->engine->getCurrentProjectFilename())
- return ret;
-
- return gNullCharPtr;
- }
-
- void carla_clear_project_filename(CarlaHostHandle handle)
- {
- CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr,);
-
- carla_debug("carla_clear_project_filename(%p)", handle);
-
- handle->engine->clearCurrentProjectFilename();
- }
-
- // --------------------------------------------------------------------------------------------------------------------
-
- bool carla_patchbay_connect(CarlaHostHandle handle, bool external, uint groupIdA, uint portIdA, uint groupIdB, uint portIdB)
- {
- CARLA_SAFE_ASSERT_WITH_LAST_ERROR_RETURN(handle->engine != nullptr, "Engine is not initialized", false);
-
- carla_debug("carla_patchbay_connect(%p, %s, %u, %u, %u, %u)",
- handle, bool2str(external), groupIdA, portIdA, groupIdB, portIdB);
-
- return handle->engine->patchbayConnect(external, groupIdA, portIdA, groupIdB, portIdB);
- }
-
- bool carla_patchbay_disconnect(CarlaHostHandle handle, bool external, uint connectionId)
- {
- CARLA_SAFE_ASSERT_WITH_LAST_ERROR_RETURN(handle->engine != nullptr, "Engine is not initialized", false);
-
- carla_debug("carla_patchbay_disconnect(%p, %s, %i)", handle, bool2str(external), connectionId);
-
- return handle->engine->patchbayDisconnect(external, connectionId);
- }
-
- bool carla_patchbay_set_group_pos(CarlaHostHandle handle, bool external, uint groupId, int x1, int y1, int x2, int y2)
- {
- CARLA_SAFE_ASSERT_WITH_LAST_ERROR_RETURN(handle->engine != nullptr && handle->engine->isRunning(),
- "Engine is not running", false);
-
- carla_debug("carla_patchbay_set_group_pos(%p, %s, %u, %i, %i, %i, %i)",
- handle, bool2str(external), groupId, x1, y1, x2, y2);
-
- if (handle->engine->isAboutToClose())
- return true;
-
- return handle->engine->patchbaySetGroupPos(false, true, external, groupId, x1, y1, x2, y2);
- }
-
- bool carla_patchbay_refresh(CarlaHostHandle handle, bool external)
- {
- CARLA_SAFE_ASSERT_WITH_LAST_ERROR_RETURN(handle->engine != nullptr, "Engine is not initialized", false);
-
- carla_debug("carla_patchbay_refresh(%p, %s)", handle, bool2str(external));
-
- return handle->engine->patchbayRefresh(true, false, external);
- }
-
- // --------------------------------------------------------------------------------------------------------------------
-
- void carla_transport_play(CarlaHostHandle handle)
- {
- CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr && handle->engine->isRunning(),);
-
- carla_debug("carla_transport_play(%p)", handle);
-
- handle->engine->transportPlay();
- }
-
- void carla_transport_pause(CarlaHostHandle handle)
- {
- CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr && handle->engine->isRunning(),);
-
- carla_debug("carla_transport_pause(%p)", handle);
-
- handle->engine->transportPause();
- }
-
- void carla_transport_bpm(CarlaHostHandle handle, double bpm)
- {
- CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr && handle->engine->isRunning(),);
-
- carla_debug("carla_transport_bpm(%p, %f)", handle, bpm);
-
- handle->engine->transportBPM(bpm);
- }
-
- void carla_transport_relocate(CarlaHostHandle handle, uint64_t frame)
- {
- CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr && handle->engine->isRunning(),);
-
- carla_debug("carla_transport_relocate(%p, %i)", handle, frame);
-
- handle->engine->transportRelocate(frame);
- }
-
- uint64_t carla_get_current_transport_frame(CarlaHostHandle handle)
- {
- CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr && handle->engine->isRunning(), 0);
-
- return handle->engine->getTimeInfo().frame;
- }
-
- const CarlaTransportInfo* carla_get_transport_info(CarlaHostHandle handle)
- {
- static CarlaTransportInfo retTransInfo;
- retTransInfo.clear();
-
- CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr && handle->engine->isRunning(), &retTransInfo);
-
- const CB::EngineTimeInfo& timeInfo(handle->engine->getTimeInfo());
-
- retTransInfo.playing = timeInfo.playing;
- retTransInfo.frame = timeInfo.frame;
-
- if (timeInfo.bbt.valid)
- {
- retTransInfo.bar = timeInfo.bbt.bar;
- retTransInfo.beat = timeInfo.bbt.beat;
- retTransInfo.tick = static_cast<int32_t>(timeInfo.bbt.tick + 0.5);
- retTransInfo.bpm = timeInfo.bbt.beatsPerMinute;
- }
-
- return &retTransInfo;
- }
- #endif
-
- // --------------------------------------------------------------------------------------------------------------------
-
- uint32_t carla_get_current_plugin_count(CarlaHostHandle handle)
- {
- CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, 0);
-
- carla_debug("carla_get_current_plugin_count(%p)", handle);
-
- return handle->engine->getCurrentPluginCount();
- }
-
- uint32_t carla_get_max_plugin_number(CarlaHostHandle handle)
- {
- CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, 0);
-
- carla_debug("carla_get_max_plugin_number(%p)", handle);
-
- return handle->engine->getMaxPluginNumber();
- }
-
- // --------------------------------------------------------------------------------------------------------------------
-
- bool carla_add_plugin(CarlaHostHandle handle,
- BinaryType btype, PluginType ptype,
- const char* filename, const char* name, const char* label, int64_t uniqueId,
- const void* extraPtr, uint options)
- {
- CARLA_SAFE_ASSERT_WITH_LAST_ERROR_RETURN(handle->engine != nullptr, "Engine is not initialized", false);
-
- carla_debug("carla_add_plugin(%p, %i:%s, %i:%s, \"%s\", \"%s\", \"%s\", " P_INT64 ", %p, %u)",
- handle,
- btype, CB::BinaryType2Str(btype),
- ptype, CB::PluginType2Str(ptype),
- filename, name, label, uniqueId, extraPtr, options);
-
- return handle->engine->addPlugin(btype, ptype, filename, name, label, uniqueId, extraPtr, options);
- }
-
- bool carla_remove_plugin(CarlaHostHandle handle, uint pluginId)
- {
- CARLA_SAFE_ASSERT_WITH_LAST_ERROR_RETURN(handle->engine != nullptr, "Engine is not initialized", false);
-
- carla_debug("carla_remove_plugin(%p, %i)", handle, pluginId);
-
- return handle->engine->removePlugin(pluginId);
- }
-
- bool carla_remove_all_plugins(CarlaHostHandle handle)
- {
- CARLA_SAFE_ASSERT_WITH_LAST_ERROR_RETURN(handle->engine != nullptr, "Engine is not initialized", false);
-
- carla_debug("carla_remove_all_plugins(%p)", handle);
-
- return handle->engine->removeAllPlugins();
- }
-
- #ifndef BUILD_BRIDGE
- bool carla_rename_plugin(CarlaHostHandle handle, uint pluginId, const char* newName)
- {
- CARLA_SAFE_ASSERT_RETURN(newName != nullptr && newName[0] != '\0', false);
- CARLA_SAFE_ASSERT_WITH_LAST_ERROR_RETURN(handle->engine != nullptr, "Engine is not initialized", false);
-
- carla_debug("carla_rename_plugin(%p, %i, \"%s\")", handle, pluginId, newName);
-
- return handle->engine->renamePlugin(pluginId, newName);
- }
-
- bool carla_clone_plugin(CarlaHostHandle handle, uint pluginId)
- {
- CARLA_SAFE_ASSERT_WITH_LAST_ERROR_RETURN(handle->engine != nullptr, "Engine is not initialized", false);
-
- carla_debug("carla_clone_plugin(%p, %i)", handle, pluginId);
-
- return handle->engine->clonePlugin(pluginId);
- }
-
- bool carla_replace_plugin(CarlaHostHandle handle, uint pluginId)
- {
- CARLA_SAFE_ASSERT_WITH_LAST_ERROR_RETURN(handle->engine != nullptr, "Engine is not initialized", false);
-
- carla_debug("carla_replace_plugin(%p, %i)", handle, pluginId);
-
- return handle->engine->replacePlugin(pluginId);
- }
-
- bool carla_switch_plugins(CarlaHostHandle handle, uint pluginIdA, uint pluginIdB)
- {
- CARLA_SAFE_ASSERT_RETURN(pluginIdA != pluginIdB, false);
- CARLA_SAFE_ASSERT_WITH_LAST_ERROR_RETURN(handle->engine != nullptr, "Engine is not initialized", false);
-
- carla_debug("carla_switch_plugins(%p, %i, %i)", handle, pluginIdA, pluginIdB);
-
- return handle->engine->switchPlugins(pluginIdA, pluginIdB);
- }
- #endif
-
- // --------------------------------------------------------------------------------------------------------------------
-
- bool carla_load_plugin_state(CarlaHostHandle handle, uint pluginId, const char* filename)
- {
- CARLA_SAFE_ASSERT_RETURN(filename != nullptr && filename[0] != '\0', false);
- CARLA_SAFE_ASSERT_WITH_LAST_ERROR_RETURN(handle->engine != nullptr
- && handle->engine->isRunning(), "Engine is not running", false);
-
- if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
- return plugin->loadStateFromFile(filename);
-
- return false;
- }
-
- bool carla_save_plugin_state(CarlaHostHandle handle, uint pluginId, const char* filename)
- {
- CARLA_SAFE_ASSERT_RETURN(filename != nullptr && filename[0] != '\0', false);
- CARLA_SAFE_ASSERT_WITH_LAST_ERROR_RETURN(handle->engine != nullptr, "Engine is not initialized", false);
-
- if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
- return plugin->saveStateToFile(filename);
-
- return false;
- }
-
- bool carla_export_plugin_lv2(CarlaHostHandle handle, uint pluginId, const char* lv2path)
- {
- CARLA_SAFE_ASSERT_RETURN(lv2path != nullptr && lv2path[0] != '\0', false);
- CARLA_SAFE_ASSERT_WITH_LAST_ERROR_RETURN(handle->engine != nullptr, "Engine is not initialized", false);
-
- if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
- return plugin->exportAsLV2(lv2path);
-
- return false;
- }
-
- // --------------------------------------------------------------------------------------------------------------------
-
- const CarlaPluginInfo* carla_get_plugin_info(CarlaHostHandle handle, uint pluginId)
- {
- static CarlaPluginInfo retInfo;
-
- // reset
- retInfo.type = CB::PLUGIN_NONE;
- retInfo.category = CB::PLUGIN_CATEGORY_NONE;
- retInfo.hints = 0x0;
- retInfo.optionsAvailable = 0x0;
- retInfo.optionsEnabled = 0x0;
- retInfo.filename = gNullCharPtr;
- retInfo.name = gNullCharPtr;
- retInfo.iconName = gNullCharPtr;
- retInfo.uniqueId = 0;
-
- // cleanup
- if (retInfo.label != gNullCharPtr)
- {
- delete[] retInfo.label;
- retInfo.label = gNullCharPtr;
- }
-
- if (retInfo.maker != gNullCharPtr)
- {
- delete[] retInfo.maker;
- retInfo.maker = gNullCharPtr;
- }
-
- if (retInfo.copyright != gNullCharPtr)
- {
- delete[] retInfo.copyright;
- retInfo.copyright = gNullCharPtr;
- }
-
- CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, &retInfo);
-
- if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
- {
- char strBuf[STR_MAX+1];
- carla_zeroChars(strBuf, STR_MAX+1);
-
- retInfo.type = plugin->getType();
- retInfo.category = plugin->getCategory();
- retInfo.hints = plugin->getHints();
- retInfo.filename = plugin->getFilename();
- retInfo.name = plugin->getName();
- retInfo.iconName = plugin->getIconName();
- retInfo.uniqueId = plugin->getUniqueId();
-
- retInfo.optionsAvailable = plugin->getOptionsAvailable();
- retInfo.optionsEnabled = plugin->getOptionsEnabled();
-
- if (plugin->getLabel(strBuf))
- retInfo.label = carla_strdup_safe(strBuf);
- if (plugin->getMaker(strBuf))
- retInfo.maker = carla_strdup_safe(strBuf);
- if (plugin->getCopyright(strBuf))
- retInfo.copyright = carla_strdup_safe(strBuf);
-
- checkStringPtr(retInfo.filename);
- checkStringPtr(retInfo.name);
- checkStringPtr(retInfo.iconName);
- checkStringPtr(retInfo.label);
- checkStringPtr(retInfo.maker);
- checkStringPtr(retInfo.copyright);
- }
-
- return &retInfo;
- }
-
- const CarlaPortCountInfo* carla_get_audio_port_count_info(CarlaHostHandle handle, uint pluginId)
- {
- static CarlaPortCountInfo retInfo;
- carla_zeroStruct(retInfo);
-
- CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, &retInfo);
-
- if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
- {
- retInfo.ins = plugin->getAudioInCount();
- retInfo.outs = plugin->getAudioOutCount();
- }
-
- return &retInfo;
- }
-
- const CarlaPortCountInfo* carla_get_midi_port_count_info(CarlaHostHandle handle, uint pluginId)
- {
- static CarlaPortCountInfo retInfo;
- carla_zeroStruct(retInfo);
-
- CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, &retInfo);
-
- if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
- {
- retInfo.ins = plugin->getMidiInCount();
- retInfo.outs = plugin->getMidiOutCount();
- }
-
- return &retInfo;
- }
-
- const CarlaPortCountInfo* carla_get_parameter_count_info(CarlaHostHandle handle, uint pluginId)
- {
- static CarlaPortCountInfo retInfo;
- carla_zeroStruct(retInfo);
-
- CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, &retInfo);
-
- if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
- plugin->getParameterCountInfo(retInfo.ins, retInfo.outs);
-
- return &retInfo;
- }
-
- const CarlaParameterInfo* carla_get_parameter_info(CarlaHostHandle handle, uint pluginId, uint32_t parameterId)
- {
- static CarlaParameterInfo retInfo;
-
- // reset
- retInfo.scalePointCount = 0;
-
- // cleanup
- if (retInfo.name != gNullCharPtr)
- {
- delete[] retInfo.name;
- retInfo.name = gNullCharPtr;
- }
-
- if (retInfo.symbol != gNullCharPtr)
- {
- delete[] retInfo.symbol;
- retInfo.symbol = gNullCharPtr;
- }
-
- if (retInfo.unit != gNullCharPtr)
- {
- delete[] retInfo.unit;
- retInfo.unit = gNullCharPtr;
- }
-
- if (retInfo.comment != gNullCharPtr)
- {
- delete[] retInfo.comment;
- retInfo.comment = gNullCharPtr;
- }
-
- if (retInfo.groupName != gNullCharPtr)
- {
- delete[] retInfo.groupName;
- retInfo.groupName = gNullCharPtr;
- }
-
- CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, &retInfo);
-
- if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
- {
- char strBuf[STR_MAX+1];
- carla_zeroChars(strBuf, STR_MAX+1);
-
- retInfo.scalePointCount = plugin->getParameterScalePointCount(parameterId);
-
- if (plugin->getParameterName(parameterId, strBuf))
- {
- retInfo.name = carla_strdup_safe(strBuf);
- carla_zeroChars(strBuf, STR_MAX+1);
- }
-
- if (plugin->getParameterSymbol(parameterId, strBuf))
- {
- retInfo.symbol = carla_strdup_safe(strBuf);
- carla_zeroChars(strBuf, STR_MAX+1);
- }
-
- if (plugin->getParameterUnit(parameterId, strBuf))
- {
- retInfo.unit = carla_strdup_safe(strBuf);
- carla_zeroChars(strBuf, STR_MAX+1);
- }
-
- if (plugin->getParameterComment(parameterId, strBuf))
- {
- retInfo.comment = carla_strdup_safe(strBuf);
- carla_zeroChars(strBuf, STR_MAX+1);
- }
-
- if (plugin->getParameterGroupName(parameterId, strBuf))
- {
- retInfo.groupName = carla_strdup_safe(strBuf);
- carla_zeroChars(strBuf, STR_MAX+1);
- }
-
- checkStringPtr(retInfo.name);
- checkStringPtr(retInfo.symbol);
- checkStringPtr(retInfo.unit);
- checkStringPtr(retInfo.comment);
- checkStringPtr(retInfo.groupName);
- }
-
- return &retInfo;
- }
-
- const CarlaScalePointInfo* carla_get_parameter_scalepoint_info(CarlaHostHandle handle,
- uint pluginId,
- uint32_t parameterId,
- uint32_t scalePointId)
- {
- CARLA_ASSERT(handle->engine != nullptr);
-
- static CarlaScalePointInfo retInfo;
-
- // reset
- retInfo.value = 0.0f;
-
- // cleanup
- if (retInfo.label != gNullCharPtr)
- {
- delete[] retInfo.label;
- retInfo.label = gNullCharPtr;
- }
-
- CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, &retInfo);
-
- if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
- {
- char strBuf[STR_MAX+1];
-
- retInfo.value = plugin->getParameterScalePointValue(parameterId, scalePointId);
-
- carla_zeroChars(strBuf, STR_MAX+1);
- if (plugin->getParameterScalePointLabel(parameterId, scalePointId, strBuf))
- retInfo.label = carla_strdup_safe(strBuf);
-
- checkStringPtr(retInfo.label);
- }
-
- return &retInfo;
- }
-
- // --------------------------------------------------------------------------------------------------------------------
-
- const ParameterData* carla_get_parameter_data(CarlaHostHandle handle, uint pluginId, uint32_t parameterId)
- {
- static ParameterData retParamData;
-
- // reset
- retParamData.type = CB::PARAMETER_UNKNOWN;
- retParamData.hints = 0x0;
- retParamData.index = CB::PARAMETER_NULL;
- retParamData.rindex = -1;
- retParamData.midiChannel = 0;
- retParamData.mappedControlIndex = CB::CONTROL_INDEX_NONE;
- retParamData.mappedMinimum = 0.0f;
- retParamData.mappedMaximum = 0.0f;
-
- CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, &retParamData);
-
- if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
- {
- CARLA_SAFE_ASSERT_RETURN(parameterId < plugin->getParameterCount(), &retParamData);
-
- const ParameterData& pluginParamData(plugin->getParameterData(parameterId));
- retParamData.type = pluginParamData.type;
- retParamData.hints = pluginParamData.hints;
- retParamData.index = pluginParamData.index;
- retParamData.rindex = pluginParamData.rindex;
- retParamData.midiChannel = pluginParamData.midiChannel;
- retParamData.mappedControlIndex = pluginParamData.mappedControlIndex;
- retParamData.mappedMinimum = pluginParamData.mappedMinimum;
- retParamData.mappedMaximum = pluginParamData.mappedMaximum;
- }
-
- return &retParamData;
- }
-
- const ParameterRanges* carla_get_parameter_ranges(CarlaHostHandle handle, uint pluginId, uint32_t parameterId)
- {
- static ParameterRanges retParamRanges;
-
- // reset
- retParamRanges.def = 0.0f;
- retParamRanges.min = 0.0f;
- retParamRanges.max = 1.0f;
- retParamRanges.step = 0.01f;
- retParamRanges.stepSmall = 0.0001f;
- retParamRanges.stepLarge = 0.1f;
-
- CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, &retParamRanges);
-
- if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
- {
- CARLA_SAFE_ASSERT_RETURN(parameterId < plugin->getParameterCount(), &retParamRanges);
-
- const ParameterRanges& pluginParamRanges(plugin->getParameterRanges(parameterId));
- retParamRanges.def = pluginParamRanges.def;
- retParamRanges.min = pluginParamRanges.min;
- retParamRanges.max = pluginParamRanges.max;
- retParamRanges.step = pluginParamRanges.step;
- retParamRanges.stepSmall = pluginParamRanges.stepSmall;
- retParamRanges.stepLarge = pluginParamRanges.stepLarge;
- }
-
- return &retParamRanges;
- }
-
- const MidiProgramData* carla_get_midi_program_data(CarlaHostHandle handle, uint pluginId, uint32_t midiProgramId)
- {
- static MidiProgramData retMidiProgData = { 0, 0, gNullCharPtr };
-
- // reset
- retMidiProgData.bank = 0;
- retMidiProgData.program = 0;
-
- if (retMidiProgData.name != gNullCharPtr)
- {
- delete[] retMidiProgData.name;
- retMidiProgData.name = gNullCharPtr;
- }
-
- CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, &retMidiProgData);
-
- if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
- {
- CARLA_SAFE_ASSERT_RETURN(midiProgramId < plugin->getMidiProgramCount(), &retMidiProgData);
-
- const MidiProgramData& pluginMidiProgData(plugin->getMidiProgramData(midiProgramId));
- retMidiProgData.bank = pluginMidiProgData.bank;
- retMidiProgData.program = pluginMidiProgData.program;
-
- if (pluginMidiProgData.name != nullptr)
- {
- retMidiProgData.name = carla_strdup_safe(pluginMidiProgData.name);
- checkStringPtr(retMidiProgData.name);
- }
- else
- {
- retMidiProgData.name = gNullCharPtr;
- }
- }
-
- return &retMidiProgData;
- }
-
- const CustomData* carla_get_custom_data(CarlaHostHandle handle, uint pluginId, uint32_t customDataId)
- {
- static CustomData retCustomData = { gNullCharPtr, gNullCharPtr, gNullCharPtr };
-
- // reset
- if (retCustomData.type != gNullCharPtr)
- {
- delete[] retCustomData.type;
- retCustomData.type = gNullCharPtr;
- }
-
- if (retCustomData.key != gNullCharPtr)
- {
- delete[] retCustomData.key;
- retCustomData.key = gNullCharPtr;
- }
-
- if (retCustomData.value != gNullCharPtr)
- {
- delete[] retCustomData.value;
- retCustomData.value = gNullCharPtr;
- }
-
- CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, &retCustomData);
-
- if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
- {
- CARLA_SAFE_ASSERT_RETURN(customDataId < plugin->getCustomDataCount(), &retCustomData)
-
- const CustomData& pluginCustomData(plugin->getCustomData(customDataId));
- retCustomData.type = carla_strdup_safe(pluginCustomData.type);
- retCustomData.key = carla_strdup_safe(pluginCustomData.key);
- retCustomData.value = carla_strdup_safe(pluginCustomData.value);
- checkStringPtr(retCustomData.type);
- checkStringPtr(retCustomData.key);
- checkStringPtr(retCustomData.value);
- }
-
- return &retCustomData;
- }
-
- const char* carla_get_custom_data_value(CarlaHostHandle handle, uint pluginId, const char* type, const char* key)
- {
- CARLA_SAFE_ASSERT_RETURN(type != nullptr && type[0] != '\0', gNullCharPtr);
- CARLA_SAFE_ASSERT_RETURN(key != nullptr && key[0] != '\0', gNullCharPtr);
- CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, gNullCharPtr);
-
- if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
- {
- const uint32_t count = plugin->getCustomDataCount();
-
- if (count == 0)
- return gNullCharPtr;
-
- static CarlaString customDataValue;
-
- for (uint32_t i=0; i<count; ++i)
- {
- const CustomData& pluginCustomData(plugin->getCustomData(i));
-
- if (std::strcmp(pluginCustomData.type, type) != 0)
- continue;
- if (std::strcmp(pluginCustomData.key, key) != 0)
- continue;
-
- customDataValue = pluginCustomData.value;
- return customDataValue.buffer();
- }
- }
-
- return gNullCharPtr;
- }
-
- const char* carla_get_chunk_data(CarlaHostHandle handle, uint pluginId)
- {
- CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, gNullCharPtr);
-
- if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
- {
- CARLA_SAFE_ASSERT_RETURN(plugin->getOptionsEnabled() & CB::PLUGIN_OPTION_USE_CHUNKS, gNullCharPtr);
-
- void* data = nullptr;
- const std::size_t dataSize(plugin->getChunkData(&data));
- CARLA_SAFE_ASSERT_RETURN(data != nullptr && dataSize > 0, gNullCharPtr);
-
- static CarlaString chunkData;
-
- chunkData = CarlaString::asBase64(data, static_cast<std::size_t>(dataSize));
- return chunkData.buffer();
- }
-
- return gNullCharPtr;
- }
-
- // --------------------------------------------------------------------------------------------------------------------
-
- uint32_t carla_get_parameter_count(CarlaHostHandle handle, uint pluginId)
- {
- CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, 0);
-
- if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
- return plugin->getParameterCount();
-
- return 0;
- }
-
- uint32_t carla_get_program_count(CarlaHostHandle handle, uint pluginId)
- {
- CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, 0);
-
- if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
- return plugin->getProgramCount();
-
- return 0;
- }
-
- uint32_t carla_get_midi_program_count(CarlaHostHandle handle, uint pluginId)
- {
- CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, 0);
-
- if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
- return plugin->getMidiProgramCount();
-
- return 0;
- }
-
- uint32_t carla_get_custom_data_count(CarlaHostHandle handle, uint pluginId)
- {
- CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, 0);
-
- if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
- return plugin->getCustomDataCount();
-
- return 0;
- }
-
- // --------------------------------------------------------------------------------------------------------------------
-
- const char* carla_get_parameter_text(CarlaHostHandle handle, uint pluginId, uint32_t parameterId)
- {
- CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, gNullCharPtr);
-
- if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
- {
- CARLA_SAFE_ASSERT_RETURN(parameterId < plugin->getParameterCount(), gNullCharPtr);
-
- static char textBuf[STR_MAX+1];
- carla_zeroChars(textBuf, STR_MAX+1);
-
- if (! plugin->getParameterText(parameterId, textBuf))
- textBuf[0] = '\0';
-
- return textBuf;
- }
-
- return gNullCharPtr;
- }
-
- const char* carla_get_program_name(CarlaHostHandle handle, uint pluginId, uint32_t programId)
- {
- CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, nullptr);
-
- if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
- {
- CARLA_SAFE_ASSERT_RETURN(programId < plugin->getProgramCount(), gNullCharPtr);
-
- static char programName[STR_MAX+1];
- carla_zeroChars(programName, STR_MAX+1);
-
- if (! plugin->getProgramName(programId, programName))
- programName[0] = '\0';
-
- return programName;
- }
-
- return gNullCharPtr;
- }
-
- const char* carla_get_midi_program_name(CarlaHostHandle handle, uint pluginId, uint32_t midiProgramId)
- {
- CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, gNullCharPtr);
-
- if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
- {
- CARLA_SAFE_ASSERT_RETURN(midiProgramId < plugin->getMidiProgramCount(), gNullCharPtr);
-
- static char midiProgramName[STR_MAX+1];
- carla_zeroChars(midiProgramName, STR_MAX+1);
-
- if (! plugin->getMidiProgramName(midiProgramId, midiProgramName))
- midiProgramName[0] = '\0';
-
- return midiProgramName;
- }
-
- return gNullCharPtr;
- }
-
- const char* carla_get_real_plugin_name(CarlaHostHandle handle, uint pluginId)
- {
- CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, gNullCharPtr);
-
- if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
- {
- static char realPluginName[STR_MAX+1];
- carla_zeroChars(realPluginName, STR_MAX+1);
-
- if (! plugin->getRealName(realPluginName))
- realPluginName[0] = '\0';
-
- return realPluginName;
- }
-
- return gNullCharPtr;
- }
-
- // --------------------------------------------------------------------------------------------------------------------
-
- int32_t carla_get_current_program_index(CarlaHostHandle handle, uint pluginId)
- {
- CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, -1);
-
- if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
- return plugin->getCurrentProgram();
-
- return -1;
- }
-
- int32_t carla_get_current_midi_program_index(CarlaHostHandle handle, uint pluginId)
- {
- CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, -1);
-
- if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
- return plugin->getCurrentMidiProgram();
-
- return -1;
- }
-
- // --------------------------------------------------------------------------------------------------------------------
-
- float carla_get_default_parameter_value(CarlaHostHandle handle, uint pluginId, uint32_t parameterId)
- {
- CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, 0.0f);
-
- if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
- {
- CARLA_SAFE_ASSERT_RETURN(parameterId < plugin->getParameterCount(), 0.0f);
-
- return plugin->getParameterRanges(parameterId).def;
- }
-
- return 0.0f;
- }
-
- float carla_get_current_parameter_value(CarlaHostHandle handle, uint pluginId, uint32_t parameterId)
- {
- CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, 0.0f);
-
- if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
- {
- CARLA_SAFE_ASSERT_RETURN(parameterId < plugin->getParameterCount(), 0.0f);
-
- return plugin->getParameterValue(parameterId);
- }
-
- return 0.0f;
- }
-
- float carla_get_internal_parameter_value(CarlaHostHandle handle, uint pluginId, int32_t parameterId)
- {
- #ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH
- CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, (parameterId == CB::PARAMETER_CTRL_CHANNEL) ? -1.0f : 0.0f);
- #else
- CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, 0.0f);
- #endif
- CARLA_SAFE_ASSERT_RETURN(parameterId != CB::PARAMETER_NULL && parameterId > CB::PARAMETER_MAX, 0.0f);
-
- if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
- return plugin->getInternalParameterValue(parameterId);
-
- return 0.0f;
- }
-
- // --------------------------------------------------------------------------------------------------------------------
-
- uint32_t carla_get_plugin_latency(CarlaHostHandle handle, uint pluginId)
- {
- CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, 0);
-
- if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
- return plugin->getLatencyInFrames();
-
- return 0;
- }
-
- // --------------------------------------------------------------------------------------------------------------------
-
- const float* carla_get_peak_values(CarlaHostHandle handle, uint pluginId)
- {
- CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, nullptr);
-
- return handle->engine->getPeaks(pluginId);
- }
-
- float carla_get_input_peak_value(CarlaHostHandle handle, uint pluginId, bool isLeft)
- {
- CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, 0.0f);
-
- return handle->engine->getInputPeak(pluginId, isLeft);
- }
-
- float carla_get_output_peak_value(CarlaHostHandle handle, uint pluginId, bool isLeft)
- {
- CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, 0.0f);
-
- return handle->engine->getOutputPeak(pluginId, isLeft);
- }
-
- // --------------------------------------------------------------------------------------------------------------------
-
- CARLA_BACKEND_START_NAMESPACE
-
- #ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH
- // defined in CarlaPluginInternal.cpp
- const void* carla_render_inline_display_internal(const CarlaPluginPtr& plugin, uint32_t width, uint32_t height);
- #endif
-
- // defined in CarlaPluginLV2.cpp
- const void* carla_render_inline_display_lv2(const CarlaPluginPtr& plugin, uint32_t width, uint32_t height);
-
- CARLA_BACKEND_END_NAMESPACE
-
- const CarlaInlineDisplayImageSurface* carla_render_inline_display(CarlaHostHandle handle,
- uint pluginId,
- uint32_t width, uint32_t height)
- {
- CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr && handle->engine->isRunning(), nullptr);
-
- if (handle->engine->isAboutToClose())
- return nullptr;
-
- if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
- {
- switch (plugin->getType())
- {
- #ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH
- case CB::PLUGIN_INTERNAL:
- return (const CarlaInlineDisplayImageSurface*)CB::carla_render_inline_display_internal(plugin, width, height);
- #endif
- case CB::PLUGIN_LV2:
- return (const CarlaInlineDisplayImageSurface*)CB::carla_render_inline_display_lv2(plugin, width, height);
- default:
- return nullptr;
- }
- }
-
- return nullptr;
- }
-
- // --------------------------------------------------------------------------------------------------------------------
-
- void carla_set_active(CarlaHostHandle handle, uint pluginId, bool onOff)
- {
- CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr,);
-
- if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
- plugin->setActive(onOff, true, false);
- }
-
- #ifndef BUILD_BRIDGE
- void carla_set_drywet(CarlaHostHandle handle, uint pluginId, float value)
- {
- CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr,);
-
- if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
- plugin->setDryWet(value, true, false);
- }
-
- void carla_set_volume(CarlaHostHandle handle, uint pluginId, float value)
- {
- CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr,);
-
- if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
- plugin->setVolume(value, true, false);
- }
-
- void carla_set_balance_left(CarlaHostHandle handle, uint pluginId, float value)
- {
- CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr,);
-
- if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
- plugin->setBalanceLeft(value, true, false);
- }
-
- void carla_set_balance_right(CarlaHostHandle handle, uint pluginId, float value)
- {
- CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr,);
-
- if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
- plugin->setBalanceRight(value, true, false);
- }
-
- void carla_set_panning(CarlaHostHandle handle, uint pluginId, float value)
- {
- CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr,);
-
- if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
- plugin->setPanning(value, true, false);
- }
-
- void carla_set_ctrl_channel(CarlaHostHandle handle, uint pluginId, int8_t channel)
- {
- CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr,);
- CARLA_SAFE_ASSERT_RETURN(channel >= -1 && channel < MAX_MIDI_CHANNELS,);
-
- if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
- plugin->setCtrlChannel(channel, true, false);
- }
- #endif
-
- void carla_set_option(CarlaHostHandle handle, uint pluginId, uint option, bool yesNo)
- {
- CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr,);
-
- if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
- plugin->setOption(option, yesNo, false);
- }
-
- // --------------------------------------------------------------------------------------------------------------------
-
- void carla_set_parameter_value(CarlaHostHandle handle, uint pluginId, uint32_t parameterId, float value)
- {
- CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr,);
-
- if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
- {
- CARLA_SAFE_ASSERT_RETURN(parameterId < plugin->getParameterCount(),);
-
- plugin->setParameterValue(parameterId, value, true, true, false);
- }
- }
-
- #ifndef BUILD_BRIDGE
-
- void carla_set_parameter_midi_channel(CarlaHostHandle handle, uint pluginId, uint32_t parameterId, uint8_t channel)
- {
- CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr,);
- CARLA_SAFE_ASSERT_RETURN(channel < MAX_MIDI_CHANNELS,);
-
- if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
- {
- CARLA_SAFE_ASSERT_RETURN(parameterId < plugin->getParameterCount(),);
-
- plugin->setParameterMidiChannel(parameterId, channel, true, false);
- }
- }
-
- void carla_set_parameter_mapped_control_index(CarlaHostHandle handle, uint pluginId, uint32_t parameterId, int16_t index)
- {
- CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr,);
- CARLA_SAFE_ASSERT_RETURN(index >= CB::CONTROL_INDEX_NONE && index <= CB::CONTROL_INDEX_MAX_ALLOWED,);
-
- if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
- {
- CARLA_SAFE_ASSERT_RETURN(parameterId < plugin->getParameterCount(),);
-
- plugin->setParameterMappedControlIndex(parameterId, index, true, false, true);
- }
- }
-
- void carla_set_parameter_mapped_range(CarlaHostHandle handle, uint pluginId, uint32_t parameterId, float minimum, float maximum)
- {
- CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr,);
-
- if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
- {
- CARLA_SAFE_ASSERT_RETURN(parameterId < plugin->getParameterCount(),);
-
- plugin->setParameterMappedRange(parameterId, minimum, maximum, true, false);
- }
- }
-
- void carla_set_parameter_touch(CarlaHostHandle handle, uint pluginId, uint32_t parameterId, bool touch)
- {
- CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr,);
-
- carla_debug("carla_set_parameter_touch(%p, %i, %i, %s)", handle, pluginId, parameterId, bool2str(touch));
- return handle->engine->touchPluginParameter(pluginId, parameterId, touch);
- }
- #endif
-
- // --------------------------------------------------------------------------------------------------------------------
-
- void carla_set_program(CarlaHostHandle handle, uint pluginId, uint32_t programId)
- {
- CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr,);
-
- if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
- {
- CARLA_SAFE_ASSERT_RETURN(programId < plugin->getProgramCount(),);
-
- plugin->setProgram(static_cast<int32_t>(programId), true, true, false);
- }
- }
-
- void carla_set_midi_program(CarlaHostHandle handle, uint pluginId, uint32_t midiProgramId)
- {
- CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr,);
-
- if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
- {
- CARLA_SAFE_ASSERT_RETURN(midiProgramId < plugin->getMidiProgramCount(),);
-
- plugin->setMidiProgram(static_cast<int32_t>(midiProgramId), true, true, false);
- }
- }
-
- // --------------------------------------------------------------------------------------------------------------------
-
- void carla_set_custom_data(CarlaHostHandle handle, uint pluginId, const char* type, const char* key, const char* value)
- {
- CARLA_SAFE_ASSERT_RETURN(handle->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,);
-
- if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
- plugin->setCustomData(type, key, value, true);
- }
-
- void carla_set_chunk_data(CarlaHostHandle handle, uint pluginId, const char* chunkData)
- {
- CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr,);
- CARLA_SAFE_ASSERT_RETURN(chunkData != nullptr && chunkData[0] != '\0',);
-
- if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
- {
- CARLA_SAFE_ASSERT_RETURN(plugin->getOptionsEnabled() & CB::PLUGIN_OPTION_USE_CHUNKS,);
-
- std::vector<uint8_t> chunk(carla_getChunkFromBase64String(chunkData));
- #ifdef CARLA_PROPER_CPP11_SUPPORT
- plugin->setChunkData(chunk.data(), chunk.size());
- #else
- plugin->setChunkData(&chunk.front(), chunk.size());
- #endif
- }
- }
-
- // --------------------------------------------------------------------------------------------------------------------
-
- void carla_prepare_for_save(CarlaHostHandle handle, uint pluginId)
- {
- CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr,);
-
- if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
- plugin->prepareForSave(false);
- }
-
- void carla_reset_parameters(CarlaHostHandle handle, uint pluginId)
- {
- CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr,);
-
- if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
- plugin->resetParameters();
- }
-
- void carla_randomize_parameters(CarlaHostHandle handle, uint pluginId)
- {
- CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr,);
-
- if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
- plugin->randomizeParameters();
- }
-
- #ifndef BUILD_BRIDGE
- void carla_send_midi_note(CarlaHostHandle handle, uint pluginId, uint8_t channel, uint8_t note, uint8_t velocity)
- {
- CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr && handle->engine->isRunning(),);
-
- if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
- plugin->sendMidiSingleNote(channel, note, velocity, true, true, false);
- }
- #endif
-
- void carla_set_custom_ui_title(CarlaHostHandle handle, uint pluginId, const char* title)
- {
- CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr,);
- CARLA_SAFE_ASSERT_RETURN(title != nullptr,);
-
- if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
- plugin->setCustomUITitle(title);
- }
-
- void carla_show_custom_ui(CarlaHostHandle handle, uint pluginId, bool yesNo)
- {
- CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr,);
-
- if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
- plugin->showCustomUI(yesNo);
- }
-
- void* carla_embed_custom_ui(CarlaHostHandle handle, uint pluginId, void* ptr)
- {
- CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, nullptr);
-
- if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
- return plugin->embedCustomUI(ptr);
-
- return nullptr;
- }
-
- // --------------------------------------------------------------------------------------------------------------------
-
- uint32_t carla_get_buffer_size(CarlaHostHandle handle)
- {
- CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, 0);
-
- carla_debug("carla_get_buffer_size(%p)", handle);
- return handle->engine->getBufferSize();
- }
-
- double carla_get_sample_rate(CarlaHostHandle handle)
- {
- CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, 0.0);
-
- carla_debug("carla_get_sample_rate(%p)", handle);
- return handle->engine->getSampleRate();
- }
-
- // --------------------------------------------------------------------------------------------------------------------
-
- const char* carla_get_last_error(CarlaHostHandle handle)
- {
- carla_debug("carla_get_last_error(%p)", handle);
-
- if (handle->engine != nullptr)
- return handle->engine->getLastError();
-
- return handle->isStandalone
- ? ((CarlaHostStandalone*)handle)->lastError.buffer()
- : gNullCharPtr;
- }
-
- const char* carla_get_host_osc_url_tcp(CarlaHostHandle handle)
- {
- carla_debug("carla_get_host_osc_url_tcp(%p)", handle);
-
- #if defined(HAVE_LIBLO) && !defined(BUILD_BRIDGE)
- if (handle->engine == nullptr)
- {
- carla_stderr2("carla_get_host_osc_url_tcp() failed, engine is not running");
- if (handle->isStandalone)
- ((CarlaHostStandalone*)handle)->lastError = "Engine is not running";
- return gNullCharPtr;
- }
-
- const char* const path = handle->engine->getOscServerPathTCP();
-
- if (path != nullptr && path[0] != '\0')
- return path;
-
- static const char* const notAvailable = "(OSC TCP port not available)";
- return notAvailable;
- #else
- return "(OSC support not available in this build)";
-
- // unused
- (void)handle;
- #endif
- }
-
- const char* carla_get_host_osc_url_udp(CarlaHostHandle handle)
- {
- carla_debug("carla_get_host_osc_url_udp(%p)", handle);
-
- #if defined(HAVE_LIBLO) && !defined(BUILD_BRIDGE)
- if (handle->engine == nullptr)
- {
- carla_stderr2("carla_get_host_osc_url_udp() failed, engine is not running");
- if (handle->isStandalone)
- ((CarlaHostStandalone*)handle)->lastError = "Engine is not running";
- return gNullCharPtr;
- }
-
- const char* const path = handle->engine->getOscServerPathUDP();
-
- if (path != nullptr && path[0] != '\0')
- return path;
-
- static const char* const notAvailable = "(OSC UDP port not available)";
- return notAvailable;
- #else
- return "(OSC support not available in this build)";
-
- // unused
- (void)handle;
- #endif
- }
-
- // --------------------------------------------------------------------------------------------------------------------
-
- #ifndef CARLA_PLUGIN_EXPORT
- # define CARLA_PLUGIN_UI_CLASS_PREFIX Standalone
- # include "CarlaPluginUI.cpp"
- # undef CARLA_PLUGIN_UI_CLASS_PREFIX
- # include "CarlaDssiUtils.cpp"
- # include "CarlaMacUtils.cpp"
- # include "CarlaPatchbayUtils.cpp"
- # include "CarlaPipeUtils.cpp"
- # include "CarlaProcessUtils.cpp"
- # include "CarlaStateUtils.cpp"
- # include "utils/Information.cpp"
- # include "utils/Windows.cpp"
- #endif /* CARLA_PLUGIN_EXPORT */
-
- // --------------------------------------------------------------------------------------------------------------------
|