Audio plugin host https://kx.studio/carla
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

CarlaStandalone.cpp 85KB

6 years ago
10 years ago
6 years ago
6 years ago
6 years ago
6 years ago
10 years ago
10 years ago
11 years ago
10 years ago
11 years ago
11 years ago
11 years ago
10 years ago
11 years ago
6 years ago
11 years ago
6 years ago
6 years ago
6 years ago
11 years ago
6 years ago
11 years ago
11 years ago
11 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
11 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
6 years ago
11 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
6 years ago
11 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
6 years ago
10 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379
  1. /*
  2. * Carla Standalone
  3. * Copyright (C) 2011-2021 Filipe Coelho <falktx@falktx.com>
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License as
  7. * published by the Free Software Foundation; either version 2 of
  8. * the License, or any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * For a full copy of the GNU General Public License see the doc/GPL.txt file.
  16. */
  17. // TODO:
  18. // Check carla_stderr2("Engine is not running"); <= prepend func name and args
  19. #include "CarlaHostImpl.hpp"
  20. #include "CarlaMIDI.h"
  21. #include "CarlaEngineInit.hpp"
  22. #include "CarlaPlugin.hpp"
  23. #include "CarlaBackendUtils.hpp"
  24. #include "CarlaBase64Utils.hpp"
  25. #include "ThreadSafeFFTW.hpp"
  26. #ifndef BUILD_BRIDGE
  27. # include "CarlaLogThread.hpp"
  28. #endif
  29. #include "water/files/File.h"
  30. #define CARLA_SAFE_ASSERT_WITH_LAST_ERROR_RETURN(cond, msg, ret) \
  31. if (! (cond)) { \
  32. carla_stderr2("%s: " msg, __FUNCTION__); \
  33. if (handle->isStandalone) \
  34. ((CarlaHostStandalone*)handle)->lastError = msg; \
  35. return ret; \
  36. }
  37. // --------------------------------------------------------------------------------------------------------------------
  38. static void carla_standalone_juce_init(void);
  39. static void carla_standalone_juce_idle(void);
  40. static void carla_standalone_juce_cleanup(void);
  41. #define carla_juce_init carla_standalone_juce_init
  42. #define carla_juce_idle carla_standalone_juce_idle
  43. #define carla_juce_cleanup carla_standalone_juce_cleanup
  44. #include "utils/JUCE.cpp"
  45. #undef carla_juce_init
  46. #undef carla_juce_idle
  47. #undef carla_juce_cleanup
  48. // -------------------------------------------------------------------------------------------------------------------
  49. // Always return a valid string ptr for standalone functions
  50. static const char* const gNullCharPtr = "";
  51. static void checkStringPtr(const char*& charPtr) noexcept
  52. {
  53. if (charPtr == nullptr)
  54. charPtr = gNullCharPtr;
  55. }
  56. // -------------------------------------------------------------------------------------------------------------------
  57. // Constructors
  58. _CarlaPluginInfo::_CarlaPluginInfo() noexcept
  59. : type(CB::PLUGIN_NONE),
  60. category(CB::PLUGIN_CATEGORY_NONE),
  61. hints(0x0),
  62. optionsAvailable(0x0),
  63. optionsEnabled(0x0),
  64. filename(gNullCharPtr),
  65. name(gNullCharPtr),
  66. label(gNullCharPtr),
  67. maker(gNullCharPtr),
  68. copyright(gNullCharPtr),
  69. iconName(gNullCharPtr),
  70. uniqueId(0) {}
  71. _CarlaPluginInfo::~_CarlaPluginInfo() noexcept
  72. {
  73. if (label != gNullCharPtr)
  74. delete[] label;
  75. if (maker != gNullCharPtr)
  76. delete[] maker;
  77. if (copyright != gNullCharPtr)
  78. delete[] copyright;
  79. }
  80. _CarlaParameterInfo::_CarlaParameterInfo() noexcept
  81. : name(gNullCharPtr),
  82. symbol(gNullCharPtr),
  83. unit(gNullCharPtr),
  84. comment(gNullCharPtr),
  85. groupName(gNullCharPtr),
  86. scalePointCount(0) {}
  87. _CarlaParameterInfo::~_CarlaParameterInfo() noexcept
  88. {
  89. if (name != gNullCharPtr)
  90. delete[] name;
  91. if (symbol != gNullCharPtr)
  92. delete[] symbol;
  93. if (unit != gNullCharPtr)
  94. delete[] unit;
  95. if (comment != gNullCharPtr)
  96. delete[] comment;
  97. if (groupName != gNullCharPtr)
  98. delete[] groupName;
  99. }
  100. _CarlaScalePointInfo::_CarlaScalePointInfo() noexcept
  101. : value(0.0f),
  102. label(gNullCharPtr) {}
  103. _CarlaScalePointInfo::~_CarlaScalePointInfo() noexcept
  104. {
  105. if (label != gNullCharPtr)
  106. delete[] label;
  107. }
  108. _CarlaTransportInfo::_CarlaTransportInfo() noexcept
  109. : playing(false),
  110. frame(0),
  111. bar(0),
  112. beat(0),
  113. tick(0),
  114. bpm(0.0) {}
  115. void _CarlaTransportInfo::clear() noexcept
  116. {
  117. playing = false;
  118. frame = 0;
  119. bar = 0;
  120. beat = 0;
  121. tick = 0;
  122. bpm = 0.0;
  123. }
  124. // --------------------------------------------------------------------------------------------------------------------
  125. using CarlaBackend::CarlaPluginPtr;
  126. // --------------------------------------------------------------------------------------------------------------------
  127. uint carla_get_engine_driver_count()
  128. {
  129. carla_debug("carla_get_engine_driver_count()");
  130. return CarlaEngine::getDriverCount();
  131. }
  132. const char* carla_get_engine_driver_name(uint index)
  133. {
  134. carla_debug("carla_get_engine_driver_name(%i)", index);
  135. return CarlaEngine::getDriverName(index);
  136. }
  137. const char* const* carla_get_engine_driver_device_names(uint index)
  138. {
  139. carla_debug("carla_get_engine_driver_device_names(%i)", index);
  140. return CarlaEngine::getDriverDeviceNames(index);
  141. }
  142. const EngineDriverDeviceInfo* carla_get_engine_driver_device_info(uint index, const char* name)
  143. {
  144. CARLA_SAFE_ASSERT_RETURN(name != nullptr, nullptr);
  145. static EngineDriverDeviceInfo retDevInfo;
  146. static const uint32_t nullBufferSizes[] = { 0 };
  147. static const double nullSampleRates[] = { 0.0 };
  148. carla_debug("carla_get_engine_driver_device_info(%i, \"%s\")", index, name);
  149. if (const EngineDriverDeviceInfo* const devInfo = CarlaEngine::getDriverDeviceInfo(index, name))
  150. {
  151. retDevInfo.hints = devInfo->hints;
  152. retDevInfo.bufferSizes = (devInfo->bufferSizes != nullptr) ? devInfo->bufferSizes : nullBufferSizes;
  153. retDevInfo.sampleRates = (devInfo->sampleRates != nullptr) ? devInfo->sampleRates : nullSampleRates;
  154. }
  155. else
  156. {
  157. retDevInfo.hints = 0x0;
  158. retDevInfo.bufferSizes = nullBufferSizes;
  159. retDevInfo.sampleRates = nullSampleRates;
  160. }
  161. return &retDevInfo;
  162. }
  163. bool carla_show_engine_driver_device_control_panel(uint index, const char* name)
  164. {
  165. return CarlaEngine::showDriverDeviceControlPanel(index, name);
  166. }
  167. // --------------------------------------------------------------------------------------------------------------------
  168. CarlaHostHandle carla_standalone_host_init(void)
  169. {
  170. #ifdef CARLA_OS_UNIX
  171. static const ThreadSafeFFTW sThreadSafeFFTW;
  172. #endif
  173. static CarlaHostStandalone gStandalone;
  174. return &gStandalone;
  175. }
  176. CarlaEngine* carla_get_engine_from_handle(CarlaHostHandle handle)
  177. {
  178. carla_debug("carla_get_engine(%p)", handle);
  179. return handle->engine;
  180. }
  181. // --------------------------------------------------------------------------------------------------------------------
  182. static void carla_engine_init_common(const CarlaHostStandalone& standalone, CarlaEngine* const engine)
  183. {
  184. engine->setCallback(standalone.engineCallback, standalone.engineCallbackPtr);
  185. engine->setFileCallback(standalone.fileCallback, standalone.fileCallbackPtr);
  186. using water::File;
  187. const File waterBinaryDir(File::getSpecialLocation(File::currentExecutableFile).getParentDirectory());
  188. #ifdef BUILD_BRIDGE
  189. /*
  190. if (const char* const forceStereo = std::getenv("ENGINE_OPTION_FORCE_STEREO"))
  191. engine->setOption(CB::ENGINE_OPTION_FORCE_STEREO, (std::strcmp(forceStereo, "true") == 0) ? 1 : 0, nullptr);
  192. if (const char* const preferPluginBridges = std::getenv("ENGINE_OPTION_PREFER_PLUGIN_BRIDGES"))
  193. engine->setOption(CB::ENGINE_OPTION_PREFER_PLUGIN_BRIDGES, (std::strcmp(preferPluginBridges, "true") == 0) ? 1 : 0, nullptr);
  194. if (const char* const preferUiBridges = std::getenv("ENGINE_OPTION_PREFER_UI_BRIDGES"))
  195. engine->setOption(CB::ENGINE_OPTION_PREFER_UI_BRIDGES, (std::strcmp(preferUiBridges, "true") == 0) ? 1 : 0, nullptr);
  196. */
  197. if (const char* const uisAlwaysOnTop = std::getenv("ENGINE_OPTION_UIS_ALWAYS_ON_TOP"))
  198. engine->setOption(CB::ENGINE_OPTION_UIS_ALWAYS_ON_TOP, (std::strcmp(uisAlwaysOnTop, "true") == 0) ? 1 : 0, nullptr);
  199. if (const char* const maxParameters = std::getenv("ENGINE_OPTION_MAX_PARAMETERS"))
  200. engine->setOption(CB::ENGINE_OPTION_MAX_PARAMETERS, std::atoi(maxParameters), nullptr);
  201. if (const char* const resetXruns = std::getenv("ENGINE_OPTION_RESET_XRUNS"))
  202. engine->setOption(CB::ENGINE_OPTION_RESET_XRUNS, (std::strcmp(resetXruns, "true") == 0) ? 1 : 0, nullptr);
  203. if (const char* const uiBridgesTimeout = std::getenv("ENGINE_OPTION_UI_BRIDGES_TIMEOUT"))
  204. engine->setOption(CB::ENGINE_OPTION_UI_BRIDGES_TIMEOUT, std::atoi(uiBridgesTimeout), nullptr);
  205. if (const char* const pathAudio = std::getenv("ENGINE_OPTION_FILE_PATH_AUDIO"))
  206. engine->setOption(CB::ENGINE_OPTION_FILE_PATH, CB::FILE_AUDIO, pathAudio);
  207. if (const char* const pathMIDI = std::getenv("ENGINE_OPTION_FILE_PATH_MIDI"))
  208. engine->setOption(CB::ENGINE_OPTION_FILE_PATH, CB::FILE_MIDI, pathMIDI);
  209. if (const char* const pathLADSPA = std::getenv("ENGINE_OPTION_PLUGIN_PATH_LADSPA"))
  210. engine->setOption(CB::ENGINE_OPTION_PLUGIN_PATH, CB::PLUGIN_LADSPA, pathLADSPA);
  211. if (const char* const pathDSSI = std::getenv("ENGINE_OPTION_PLUGIN_PATH_DSSI"))
  212. engine->setOption(CB::ENGINE_OPTION_PLUGIN_PATH, CB::PLUGIN_DSSI, pathDSSI);
  213. if (const char* const pathLV2 = std::getenv("ENGINE_OPTION_PLUGIN_PATH_LV2"))
  214. engine->setOption(CB::ENGINE_OPTION_PLUGIN_PATH, CB::PLUGIN_LV2, pathLV2);
  215. if (const char* const pathVST2 = std::getenv("ENGINE_OPTION_PLUGIN_PATH_VST2"))
  216. engine->setOption(CB::ENGINE_OPTION_PLUGIN_PATH, CB::PLUGIN_VST2, pathVST2);
  217. if (const char* const pathVST3 = std::getenv("ENGINE_OPTION_PLUGIN_PATH_VST3"))
  218. engine->setOption(CB::ENGINE_OPTION_PLUGIN_PATH, CB::PLUGIN_VST3, pathVST3);
  219. if (const char* const pathSF2 = std::getenv("ENGINE_OPTION_PLUGIN_PATH_SF2"))
  220. engine->setOption(CB::ENGINE_OPTION_PLUGIN_PATH, CB::PLUGIN_SF2, pathSF2);
  221. if (const char* const pathSFZ = std::getenv("ENGINE_OPTION_PLUGIN_PATH_SFZ"))
  222. engine->setOption(CB::ENGINE_OPTION_PLUGIN_PATH, CB::PLUGIN_SFZ, pathSFZ);
  223. if (const char* const binaryDir = std::getenv("ENGINE_OPTION_PATH_BINARIES"))
  224. engine->setOption(CB::ENGINE_OPTION_PATH_BINARIES, 0, binaryDir);
  225. else
  226. engine->setOption(CB::ENGINE_OPTION_PATH_BINARIES, 0, waterBinaryDir.getFullPathName().toRawUTF8());
  227. if (const char* const resourceDir = std::getenv("ENGINE_OPTION_PATH_RESOURCES"))
  228. engine->setOption(CB::ENGINE_OPTION_PATH_RESOURCES, 0, resourceDir);
  229. else
  230. engine->setOption(CB::ENGINE_OPTION_PATH_RESOURCES, 0, waterBinaryDir.getChildFile("resources").getFullPathName().toRawUTF8());
  231. if (const char* const preventBadBehaviour = std::getenv("ENGINE_OPTION_PREVENT_BAD_BEHAVIOUR"))
  232. engine->setOption(CB::ENGINE_OPTION_PREVENT_BAD_BEHAVIOUR, (std::strcmp(preventBadBehaviour, "true") == 0) ? 1 : 0, nullptr);
  233. if (const char* const frontendWinId = std::getenv("ENGINE_OPTION_FRONTEND_WIN_ID"))
  234. engine->setOption(CB::ENGINE_OPTION_FRONTEND_WIN_ID, 0, frontendWinId);
  235. #else
  236. engine->setOption(CB::ENGINE_OPTION_FORCE_STEREO, standalone.engineOptions.forceStereo ? 1 : 0, nullptr);
  237. engine->setOption(CB::ENGINE_OPTION_PREFER_PLUGIN_BRIDGES, standalone.engineOptions.preferPluginBridges ? 1 : 0, nullptr);
  238. engine->setOption(CB::ENGINE_OPTION_PREFER_UI_BRIDGES, standalone.engineOptions.preferUiBridges ? 1 : 0, nullptr);
  239. engine->setOption(CB::ENGINE_OPTION_UIS_ALWAYS_ON_TOP, standalone.engineOptions.uisAlwaysOnTop ? 1 : 0, nullptr);
  240. engine->setOption(CB::ENGINE_OPTION_MAX_PARAMETERS, static_cast<int>(standalone.engineOptions.maxParameters), nullptr);
  241. engine->setOption(CB::ENGINE_OPTION_RESET_XRUNS, standalone.engineOptions.resetXruns ? 1 : 0, nullptr);
  242. engine->setOption(CB::ENGINE_OPTION_UI_BRIDGES_TIMEOUT, static_cast<int>(standalone.engineOptions.uiBridgesTimeout), nullptr);
  243. engine->setOption(CB::ENGINE_OPTION_AUDIO_BUFFER_SIZE, static_cast<int>(standalone.engineOptions.audioBufferSize), nullptr);
  244. engine->setOption(CB::ENGINE_OPTION_AUDIO_SAMPLE_RATE, static_cast<int>(standalone.engineOptions.audioSampleRate), nullptr);
  245. engine->setOption(CB::ENGINE_OPTION_AUDIO_TRIPLE_BUFFER, standalone.engineOptions.audioTripleBuffer ? 1 : 0, nullptr);
  246. if (standalone.engineOptions.audioDriver != nullptr)
  247. engine->setOption(CB::ENGINE_OPTION_AUDIO_DRIVER, 0, standalone.engineOptions.audioDriver);
  248. if (standalone.engineOptions.audioDevice != nullptr)
  249. engine->setOption(CB::ENGINE_OPTION_AUDIO_DEVICE, 0, standalone.engineOptions.audioDevice);
  250. engine->setOption(CB::ENGINE_OPTION_OSC_ENABLED, standalone.engineOptions.oscEnabled, nullptr);
  251. engine->setOption(CB::ENGINE_OPTION_OSC_PORT_TCP, standalone.engineOptions.oscPortTCP, nullptr);
  252. engine->setOption(CB::ENGINE_OPTION_OSC_PORT_UDP, standalone.engineOptions.oscPortUDP, nullptr);
  253. if (standalone.engineOptions.pathAudio != nullptr)
  254. engine->setOption(CB::ENGINE_OPTION_FILE_PATH, CB::FILE_AUDIO, standalone.engineOptions.pathAudio);
  255. if (standalone.engineOptions.pathMIDI != nullptr)
  256. engine->setOption(CB::ENGINE_OPTION_FILE_PATH, CB::FILE_MIDI, standalone.engineOptions.pathMIDI);
  257. if (standalone.engineOptions.pathLADSPA != nullptr)
  258. engine->setOption(CB::ENGINE_OPTION_PLUGIN_PATH, CB::PLUGIN_LADSPA, standalone.engineOptions.pathLADSPA);
  259. if (standalone.engineOptions.pathDSSI != nullptr)
  260. engine->setOption(CB::ENGINE_OPTION_PLUGIN_PATH, CB::PLUGIN_DSSI, standalone.engineOptions.pathDSSI);
  261. if (standalone.engineOptions.pathLV2 != nullptr)
  262. engine->setOption(CB::ENGINE_OPTION_PLUGIN_PATH, CB::PLUGIN_LV2, standalone.engineOptions.pathLV2);
  263. if (standalone.engineOptions.pathVST2 != nullptr)
  264. engine->setOption(CB::ENGINE_OPTION_PLUGIN_PATH, CB::PLUGIN_VST2, standalone.engineOptions.pathVST2);
  265. if (standalone.engineOptions.pathVST3 != nullptr)
  266. engine->setOption(CB::ENGINE_OPTION_PLUGIN_PATH, CB::PLUGIN_VST3, standalone.engineOptions.pathVST3);
  267. if (standalone.engineOptions.pathSF2 != nullptr)
  268. engine->setOption(CB::ENGINE_OPTION_PLUGIN_PATH, CB::PLUGIN_SF2, standalone.engineOptions.pathSF2);
  269. if (standalone.engineOptions.pathSFZ != nullptr)
  270. engine->setOption(CB::ENGINE_OPTION_PLUGIN_PATH, CB::PLUGIN_SFZ, standalone.engineOptions.pathSFZ);
  271. if (standalone.engineOptions.binaryDir != nullptr && standalone.engineOptions.binaryDir[0] != '\0')
  272. engine->setOption(CB::ENGINE_OPTION_PATH_BINARIES, 0, standalone.engineOptions.binaryDir);
  273. else
  274. engine->setOption(CB::ENGINE_OPTION_PATH_BINARIES, 0, waterBinaryDir.getFullPathName().toRawUTF8());
  275. if (standalone.engineOptions.resourceDir != nullptr && standalone.engineOptions.resourceDir[0] != '\0')
  276. engine->setOption(CB::ENGINE_OPTION_PATH_RESOURCES, 0, standalone.engineOptions.resourceDir);
  277. engine->setOption(CB::ENGINE_OPTION_PREVENT_BAD_BEHAVIOUR, standalone.engineOptions.preventBadBehaviour ? 1 : 0, nullptr);
  278. engine->setOption(CB::ENGINE_OPTION_FRONTEND_BACKGROUND_COLOR, static_cast<int>(standalone.engineOptions.bgColor), nullptr);
  279. engine->setOption(CB::ENGINE_OPTION_FRONTEND_FOREGROUND_COLOR, static_cast<int>(standalone.engineOptions.fgColor), nullptr);
  280. engine->setOption(CB::ENGINE_OPTION_FRONTEND_UI_SCALE, static_cast<int>(standalone.engineOptions.uiScale * 1000.0f), nullptr);
  281. if (standalone.engineOptions.frontendWinId != 0)
  282. {
  283. char strBuf[STR_MAX+1];
  284. strBuf[STR_MAX] = '\0';
  285. std::snprintf(strBuf, STR_MAX, P_UINTPTR, standalone.engineOptions.frontendWinId);
  286. engine->setOption(CB::ENGINE_OPTION_FRONTEND_WIN_ID, 0, strBuf);
  287. }
  288. else
  289. {
  290. engine->setOption(CB::ENGINE_OPTION_FRONTEND_WIN_ID, 0, "0");
  291. }
  292. # ifndef CARLA_OS_WIN
  293. if (standalone.engineOptions.wine.executable != nullptr && standalone.engineOptions.wine.executable[0] != '\0')
  294. engine->setOption(CB::ENGINE_OPTION_WINE_EXECUTABLE, 0, standalone.engineOptions.wine.executable);
  295. engine->setOption(CB::ENGINE_OPTION_WINE_AUTO_PREFIX, standalone.engineOptions.wine.autoPrefix ? 1 : 0, nullptr);
  296. if (standalone.engineOptions.wine.fallbackPrefix != nullptr && standalone.engineOptions.wine.fallbackPrefix[0] != '\0')
  297. engine->setOption(CB::ENGINE_OPTION_WINE_FALLBACK_PREFIX, 0, standalone.engineOptions.wine.fallbackPrefix);
  298. engine->setOption(CB::ENGINE_OPTION_WINE_RT_PRIO_ENABLED, standalone.engineOptions.wine.rtPrio ? 1 : 0, nullptr);
  299. engine->setOption(CB::ENGINE_OPTION_WINE_BASE_RT_PRIO, standalone.engineOptions.wine.baseRtPrio, nullptr);
  300. engine->setOption(CB::ENGINE_OPTION_WINE_SERVER_RT_PRIO, standalone.engineOptions.wine.serverRtPrio, nullptr);
  301. # endif
  302. engine->setOption(CB::ENGINE_OPTION_CLIENT_NAME_PREFIX, 0, standalone.engineOptions.clientNamePrefix);
  303. engine->setOption(CB::ENGINE_OPTION_PLUGINS_ARE_STANDALONE, standalone.engineOptions.pluginsAreStandalone, nullptr);
  304. #endif // BUILD_BRIDGE
  305. }
  306. bool carla_engine_init(CarlaHostHandle handle, const char* driverName, const char* clientName)
  307. {
  308. CARLA_SAFE_ASSERT_RETURN(driverName != nullptr && driverName[0] != '\0', false);
  309. CARLA_SAFE_ASSERT_RETURN(clientName != nullptr && clientName[0] != '\0', false);
  310. carla_debug("carla_engine_init(%p, \"%s\", \"%s\")", handle, driverName, clientName);
  311. CARLA_SAFE_ASSERT_WITH_LAST_ERROR_RETURN(handle->isStandalone, "Must be a standalone host handle", false);
  312. CARLA_SAFE_ASSERT_WITH_LAST_ERROR_RETURN(handle->engine == nullptr, "Engine is already initialized", false);
  313. #ifdef CARLA_OS_WIN
  314. carla_setenv("WINEASIO_CLIENT_NAME", clientName);
  315. #endif
  316. #ifdef USING_JUCE
  317. carla_standalone_juce_init();
  318. #endif
  319. CarlaHostStandalone& shandle((CarlaHostStandalone&)*handle);
  320. CarlaEngine* const engine = CarlaEngine::newDriverByName(driverName);
  321. CARLA_SAFE_ASSERT_WITH_LAST_ERROR_RETURN(engine != nullptr, "The selected audio driver is not available", false);
  322. shandle.engine = engine;
  323. #ifdef BUILD_BRIDGE
  324. if (std::getenv("CARLA_BRIDGE_DUMMY") != nullptr)
  325. {
  326. // engine->setOption(CB::ENGINE_OPTION_PROCESS_MODE, CB::ENGINE_PROCESS_MODE_PATCHBAY, nullptr);
  327. engine->setOption(CB::ENGINE_OPTION_PROCESS_MODE, CB::ENGINE_PROCESS_MODE_CONTINUOUS_RACK, nullptr);
  328. engine->setOption(CB::ENGINE_OPTION_TRANSPORT_MODE, CB::ENGINE_TRANSPORT_MODE_INTERNAL, nullptr);
  329. engine->setOption(CB::ENGINE_OPTION_AUDIO_BUFFER_SIZE, 4096, nullptr);
  330. engine->setOption(CB::ENGINE_OPTION_AUDIO_SAMPLE_RATE, 48000, nullptr);
  331. }
  332. else
  333. {
  334. engine->setOption(CB::ENGINE_OPTION_PROCESS_MODE, CB::ENGINE_PROCESS_MODE_MULTIPLE_CLIENTS, nullptr);
  335. engine->setOption(CB::ENGINE_OPTION_TRANSPORT_MODE, CB::ENGINE_TRANSPORT_MODE_JACK, nullptr);
  336. }
  337. engine->setOption(CB::ENGINE_OPTION_FORCE_STEREO, false, nullptr);
  338. engine->setOption(CB::ENGINE_OPTION_PREFER_PLUGIN_BRIDGES, false, nullptr);
  339. engine->setOption(CB::ENGINE_OPTION_PREFER_UI_BRIDGES, false, nullptr);
  340. #else
  341. engine->setOption(CB::ENGINE_OPTION_PROCESS_MODE, static_cast<int>(shandle.engineOptions.processMode), nullptr);
  342. engine->setOption(CB::ENGINE_OPTION_TRANSPORT_MODE, static_cast<int>(shandle.engineOptions.transportMode), shandle.engineOptions.transportExtra);
  343. #endif
  344. carla_engine_init_common(shandle, engine);
  345. if (engine->init(clientName))
  346. {
  347. #ifndef BUILD_BRIDGE
  348. if (shandle.logThreadEnabled && std::getenv("CARLA_LOGS_DISABLED") == nullptr)
  349. shandle.logThread.init();
  350. #endif
  351. shandle.lastError = "No error";
  352. return true;
  353. }
  354. else
  355. {
  356. shandle.lastError = engine->getLastError();
  357. shandle.engine = nullptr;
  358. delete engine;
  359. #ifdef USING_JUCE
  360. carla_standalone_juce_cleanup();
  361. #endif
  362. return false;
  363. }
  364. }
  365. #ifdef BUILD_BRIDGE
  366. bool carla_engine_init_bridge(CarlaHostHandle handle,
  367. const char audioBaseName[6+1],
  368. const char rtClientBaseName[6+1],
  369. const char nonRtClientBaseName[6+1],
  370. const char nonRtServerBaseName[6+1],
  371. const char* const clientName)
  372. {
  373. CARLA_SAFE_ASSERT_RETURN(audioBaseName != nullptr && audioBaseName[0] != '\0', false);
  374. CARLA_SAFE_ASSERT_RETURN(rtClientBaseName != nullptr && rtClientBaseName[0] != '\0', false);
  375. CARLA_SAFE_ASSERT_RETURN(nonRtClientBaseName != nullptr && nonRtClientBaseName[0] != '\0', false);
  376. CARLA_SAFE_ASSERT_RETURN(nonRtServerBaseName != nullptr && nonRtServerBaseName[0] != '\0', false);
  377. CARLA_SAFE_ASSERT_RETURN(clientName != nullptr && clientName[0] != '\0', false);
  378. carla_debug("carla_engine_init_bridge(%p, \"%s\", \"%s\", \"%s\", \"%s\", \"%s\")",
  379. handle, audioBaseName, rtClientBaseName, nonRtClientBaseName, nonRtServerBaseName, clientName);
  380. CARLA_SAFE_ASSERT_WITH_LAST_ERROR_RETURN(handle->isStandalone, "Must be a standalone host handle", false);
  381. CARLA_SAFE_ASSERT_WITH_LAST_ERROR_RETURN(handle->engine == nullptr, "Engine is already initialized", false);
  382. CarlaScopedPointer<CarlaEngine> engine(CB::EngineInit::newBridge(audioBaseName,
  383. rtClientBaseName,
  384. nonRtClientBaseName,
  385. nonRtServerBaseName));
  386. CARLA_SAFE_ASSERT_WITH_LAST_ERROR_RETURN(engine != nullptr, "The selected audio driver is not available", false);
  387. engine->setOption(CB::ENGINE_OPTION_PROCESS_MODE, CB::ENGINE_PROCESS_MODE_BRIDGE, nullptr);
  388. engine->setOption(CB::ENGINE_OPTION_TRANSPORT_MODE, CB::ENGINE_TRANSPORT_MODE_BRIDGE, nullptr);
  389. CarlaHostStandalone& shandle((CarlaHostStandalone&)*handle);
  390. carla_engine_init_common(shandle, engine);
  391. if (engine->init(clientName))
  392. {
  393. shandle.lastError = "No error";
  394. shandle.engine = engine.release();
  395. return true;
  396. }
  397. else
  398. {
  399. shandle.lastError = engine->getLastError();
  400. return false;
  401. }
  402. }
  403. #endif
  404. bool carla_engine_close(CarlaHostHandle handle)
  405. {
  406. carla_debug("carla_engine_close(%p)", handle);
  407. CARLA_SAFE_ASSERT_WITH_LAST_ERROR_RETURN(handle->isStandalone, "Must be a standalone host handle", false);
  408. CARLA_SAFE_ASSERT_WITH_LAST_ERROR_RETURN(handle->engine != nullptr, "Engine is not initialized", false);
  409. CarlaHostStandalone& shandle((CarlaHostStandalone&)*handle);
  410. CarlaEngine* const engine = shandle.engine;
  411. engine->setAboutToClose();
  412. engine->removeAllPlugins();
  413. const bool closed = engine->close();
  414. if (! closed)
  415. shandle.lastError = engine->getLastError();
  416. #ifndef BUILD_BRIDGE
  417. shandle.logThread.stop();
  418. #endif
  419. shandle.engine = nullptr;
  420. delete engine;
  421. #ifdef USING_JUCE
  422. carla_standalone_juce_cleanup();
  423. #endif
  424. return closed;
  425. }
  426. void carla_engine_idle(CarlaHostHandle handle)
  427. {
  428. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr && handle->isStandalone,);
  429. handle->engine->idle();
  430. #ifdef USING_JUCE
  431. if (handle->isStandalone)
  432. carla_standalone_juce_idle();
  433. #endif
  434. }
  435. bool carla_is_engine_running(CarlaHostHandle handle)
  436. {
  437. return (handle->engine != nullptr && handle->engine->isRunning());
  438. }
  439. const CarlaRuntimeEngineInfo* carla_get_runtime_engine_info(CarlaHostHandle handle)
  440. {
  441. static CarlaRuntimeEngineInfo retInfo;
  442. // reset
  443. retInfo.load = 0.0f;
  444. retInfo.xruns = 0;
  445. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, &retInfo);
  446. retInfo.load = handle->engine->getDSPLoad();
  447. retInfo.xruns = handle->engine->getTotalXruns();
  448. return &retInfo;
  449. }
  450. #ifndef BUILD_BRIDGE
  451. const CarlaRuntimeEngineDriverDeviceInfo* carla_get_runtime_engine_driver_device_info(CarlaHostHandle handle)
  452. {
  453. static CarlaRuntimeEngineDriverDeviceInfo retInfo;
  454. // reset
  455. retInfo.name = gNullCharPtr;
  456. retInfo.hints = 0x0;
  457. retInfo.bufferSize = 0;
  458. retInfo.bufferSizes = nullptr;
  459. retInfo.sampleRate = 0.0;
  460. retInfo.sampleRates = nullptr;
  461. const char* audioDriver;
  462. const char* audioDevice;
  463. if (CarlaEngine* const engine = handle->engine)
  464. {
  465. audioDriver = engine->getCurrentDriverName();
  466. audioDevice = engine->getOptions().audioDevice;
  467. retInfo.bufferSize = engine->getBufferSize();
  468. retInfo.sampleRate = engine->getSampleRate();
  469. }
  470. else if (handle->isStandalone)
  471. {
  472. CarlaHostStandalone& shandle((CarlaHostStandalone&)*handle);
  473. audioDriver = shandle.engineOptions.audioDriver;
  474. audioDevice = shandle.engineOptions.audioDevice;
  475. retInfo.bufferSize = shandle.engineOptions.audioBufferSize;
  476. retInfo.sampleRate = shandle.engineOptions.audioSampleRate;
  477. }
  478. else
  479. {
  480. return &retInfo;
  481. }
  482. CARLA_SAFE_ASSERT_RETURN(audioDriver != nullptr, &retInfo);
  483. CARLA_SAFE_ASSERT_RETURN(audioDevice != nullptr, &retInfo);
  484. uint index = 0;
  485. uint count = CarlaEngine::getDriverCount();
  486. for (; index<count; ++index)
  487. {
  488. const char* const testDriverName = CarlaEngine::getDriverName(index);
  489. CARLA_SAFE_ASSERT_CONTINUE(testDriverName != nullptr);
  490. if (std::strcmp(testDriverName, audioDriver) == 0)
  491. break;
  492. }
  493. CARLA_SAFE_ASSERT_RETURN(index != count, &retInfo);
  494. const EngineDriverDeviceInfo* const devInfo = CarlaEngine::getDriverDeviceInfo(index, audioDevice);
  495. CARLA_SAFE_ASSERT_RETURN(devInfo != nullptr, &retInfo);
  496. retInfo.name = audioDevice;
  497. retInfo.hints = devInfo->hints;
  498. retInfo.bufferSizes = devInfo->bufferSizes;
  499. retInfo.sampleRates = devInfo->sampleRates;
  500. return &retInfo;
  501. }
  502. bool carla_set_engine_buffer_size_and_sample_rate(CarlaHostHandle handle, uint bufferSize, double sampleRate)
  503. {
  504. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, false);
  505. carla_debug("carla_set_engine_buffer_size_and_sample_rate(%p, %u, %f)", handle, bufferSize, sampleRate);
  506. return handle->engine->setBufferSizeAndSampleRate(bufferSize, sampleRate);
  507. }
  508. bool carla_show_engine_device_control_panel(CarlaHostHandle handle)
  509. {
  510. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, false);
  511. carla_debug("carla_show_engine_device_control_panel(%p)", handle);
  512. return handle->engine->showDeviceControlPanel();
  513. }
  514. #endif // BUILD_BRIDGE
  515. void carla_clear_engine_xruns(CarlaHostHandle handle)
  516. {
  517. if (handle->engine != nullptr)
  518. handle->engine->clearXruns();
  519. }
  520. void carla_cancel_engine_action(CarlaHostHandle handle)
  521. {
  522. if (handle->engine != nullptr)
  523. handle->engine->setActionCanceled(true);
  524. }
  525. bool carla_set_engine_about_to_close(CarlaHostHandle handle)
  526. {
  527. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, true);
  528. carla_debug("carla_set_engine_about_to_close(%p)", handle);
  529. return handle->engine->setAboutToClose();
  530. }
  531. void carla_set_engine_callback(CarlaHostHandle handle, EngineCallbackFunc func, void* ptr)
  532. {
  533. carla_debug("carla_set_engine_callback(%p, %p, %p)", handle, func, ptr);
  534. if (handle->isStandalone)
  535. {
  536. CarlaHostStandalone& shandle((CarlaHostStandalone&)*handle);
  537. shandle.engineCallback = func;
  538. shandle.engineCallbackPtr = ptr;
  539. #ifndef BUILD_BRIDGE
  540. shandle.logThread.setCallback(func, ptr);
  541. #endif
  542. }
  543. if (handle->engine != nullptr)
  544. handle->engine->setCallback(func, ptr);
  545. }
  546. void carla_set_engine_option(CarlaHostHandle handle, EngineOption option, int value, const char* valueStr)
  547. {
  548. carla_debug("carla_set_engine_option(%p, %i:%s, %i, \"%s\")",
  549. handle, option, CB::EngineOption2Str(option), value, valueStr);
  550. if (handle->isStandalone)
  551. {
  552. CarlaHostStandalone& shandle((CarlaHostStandalone&)*handle);
  553. switch (option)
  554. {
  555. case CB::ENGINE_OPTION_DEBUG:
  556. break;
  557. case CB::ENGINE_OPTION_PROCESS_MODE:
  558. CARLA_SAFE_ASSERT_RETURN(value >= CB::ENGINE_PROCESS_MODE_SINGLE_CLIENT && value < CB::ENGINE_PROCESS_MODE_BRIDGE,);
  559. shandle.engineOptions.processMode = static_cast<CB::EngineProcessMode>(value);
  560. break;
  561. case CB::ENGINE_OPTION_TRANSPORT_MODE:
  562. CARLA_SAFE_ASSERT_RETURN(value >= CB::ENGINE_TRANSPORT_MODE_DISABLED && value <= CB::ENGINE_TRANSPORT_MODE_BRIDGE,);
  563. // jack transport cannot be disabled in multi-client
  564. if (shandle.engineOptions.processMode == CB::ENGINE_PROCESS_MODE_MULTIPLE_CLIENTS
  565. && value != CB::ENGINE_TRANSPORT_MODE_JACK)
  566. {
  567. shandle.engineOptions.transportMode = CB::ENGINE_TRANSPORT_MODE_JACK;
  568. if (shandle.engineCallback != nullptr)
  569. shandle.engineCallback(shandle.engineCallbackPtr,
  570. CB::ENGINE_CALLBACK_TRANSPORT_MODE_CHANGED,
  571. 0,
  572. CB::ENGINE_TRANSPORT_MODE_JACK,
  573. 0, 0, 0.0f,
  574. shandle.engineOptions.transportExtra);
  575. }
  576. else
  577. {
  578. shandle.engineOptions.transportMode = static_cast<CB::EngineTransportMode>(value);
  579. }
  580. delete[] shandle.engineOptions.transportExtra;
  581. if (value != CB::ENGINE_TRANSPORT_MODE_DISABLED && valueStr != nullptr)
  582. shandle.engineOptions.transportExtra = carla_strdup_safe(valueStr);
  583. else
  584. shandle.engineOptions.transportExtra = nullptr;
  585. break;
  586. case CB::ENGINE_OPTION_FORCE_STEREO:
  587. CARLA_SAFE_ASSERT_RETURN(value == 0 || value == 1,);
  588. shandle.engineOptions.forceStereo = (value != 0);
  589. break;
  590. case CB::ENGINE_OPTION_PREFER_PLUGIN_BRIDGES:
  591. CARLA_SAFE_ASSERT_RETURN(value == 0 || value == 1,);
  592. shandle.engineOptions.preferPluginBridges = (value != 0);
  593. break;
  594. case CB::ENGINE_OPTION_PREFER_UI_BRIDGES:
  595. CARLA_SAFE_ASSERT_RETURN(value == 0 || value == 1,);
  596. shandle.engineOptions.preferUiBridges = (value != 0);
  597. break;
  598. case CB::ENGINE_OPTION_UIS_ALWAYS_ON_TOP:
  599. CARLA_SAFE_ASSERT_RETURN(value == 0 || value == 1,);
  600. shandle.engineOptions.uisAlwaysOnTop = (value != 0);
  601. break;
  602. case CB::ENGINE_OPTION_MAX_PARAMETERS:
  603. CARLA_SAFE_ASSERT_RETURN(value >= 0,);
  604. shandle.engineOptions.maxParameters = static_cast<uint>(value);
  605. break;
  606. case CB::ENGINE_OPTION_RESET_XRUNS:
  607. CARLA_SAFE_ASSERT_RETURN(value == 0 || value == 1,);
  608. shandle.engineOptions.resetXruns = (value != 0);
  609. break;
  610. case CB::ENGINE_OPTION_UI_BRIDGES_TIMEOUT:
  611. CARLA_SAFE_ASSERT_RETURN(value >= 0,);
  612. shandle.engineOptions.uiBridgesTimeout = static_cast<uint>(value);
  613. break;
  614. case CB::ENGINE_OPTION_AUDIO_BUFFER_SIZE:
  615. CARLA_SAFE_ASSERT_RETURN(value >= 8,);
  616. shandle.engineOptions.audioBufferSize = static_cast<uint>(value);
  617. break;
  618. case CB::ENGINE_OPTION_AUDIO_SAMPLE_RATE:
  619. CARLA_SAFE_ASSERT_RETURN(value >= 22050,);
  620. shandle.engineOptions.audioSampleRate = static_cast<uint>(value);
  621. break;
  622. case CB::ENGINE_OPTION_AUDIO_TRIPLE_BUFFER:
  623. CARLA_SAFE_ASSERT_RETURN(value == 0 || value == 1,);
  624. shandle.engineOptions.audioTripleBuffer = (value != 0);
  625. break;
  626. case CB::ENGINE_OPTION_AUDIO_DRIVER:
  627. CARLA_SAFE_ASSERT_RETURN(valueStr != nullptr,);
  628. if (shandle.engineOptions.audioDriver != nullptr)
  629. delete[] shandle.engineOptions.audioDriver;
  630. shandle.engineOptions.audioDriver = carla_strdup_safe(valueStr);
  631. break;
  632. case CB::ENGINE_OPTION_AUDIO_DEVICE:
  633. CARLA_SAFE_ASSERT_RETURN(valueStr != nullptr,);
  634. if (shandle.engineOptions.audioDevice != nullptr)
  635. delete[] shandle.engineOptions.audioDevice;
  636. shandle.engineOptions.audioDevice = carla_strdup_safe(valueStr);
  637. break;
  638. #ifndef BUILD_BRIDGE
  639. case CB::ENGINE_OPTION_OSC_ENABLED:
  640. CARLA_SAFE_ASSERT_RETURN(value == 0 || value == 1,);
  641. shandle.engineOptions.oscEnabled = (value != 0);
  642. break;
  643. case CB::ENGINE_OPTION_OSC_PORT_TCP:
  644. CARLA_SAFE_ASSERT_RETURN(value <= 0 || value >= 1024,);
  645. shandle.engineOptions.oscPortTCP = value;
  646. break;
  647. case CB::ENGINE_OPTION_OSC_PORT_UDP:
  648. CARLA_SAFE_ASSERT_RETURN(value <= 0 || value >= 1024,);
  649. shandle.engineOptions.oscPortUDP = value;
  650. break;
  651. #endif
  652. case CB::ENGINE_OPTION_FILE_PATH:
  653. CARLA_SAFE_ASSERT_RETURN(value > CB::FILE_NONE,);
  654. CARLA_SAFE_ASSERT_RETURN(value <= CB::FILE_MIDI,);
  655. CARLA_SAFE_ASSERT_RETURN(valueStr != nullptr,);
  656. switch (value)
  657. {
  658. case CB::FILE_AUDIO:
  659. if (shandle.engineOptions.pathAudio != nullptr)
  660. delete[] shandle.engineOptions.pathAudio;
  661. shandle.engineOptions.pathAudio = carla_strdup_safe(valueStr);
  662. break;
  663. case CB::FILE_MIDI:
  664. if (shandle.engineOptions.pathMIDI != nullptr)
  665. delete[] shandle.engineOptions.pathMIDI;
  666. shandle.engineOptions.pathMIDI = carla_strdup_safe(valueStr);
  667. break;
  668. }
  669. break;
  670. case CB::ENGINE_OPTION_PLUGIN_PATH:
  671. CARLA_SAFE_ASSERT_RETURN(value > CB::PLUGIN_NONE,);
  672. CARLA_SAFE_ASSERT_RETURN(value <= CB::PLUGIN_SFZ,);
  673. CARLA_SAFE_ASSERT_RETURN(valueStr != nullptr,);
  674. switch (value)
  675. {
  676. case CB::PLUGIN_LADSPA:
  677. if (shandle.engineOptions.pathLADSPA != nullptr)
  678. delete[] shandle.engineOptions.pathLADSPA;
  679. shandle.engineOptions.pathLADSPA = carla_strdup_safe(valueStr);
  680. break;
  681. case CB::PLUGIN_DSSI:
  682. if (shandle.engineOptions.pathDSSI != nullptr)
  683. delete[] shandle.engineOptions.pathDSSI;
  684. shandle.engineOptions.pathDSSI = carla_strdup_safe(valueStr);
  685. break;
  686. case CB::PLUGIN_LV2:
  687. if (shandle.engineOptions.pathLV2 != nullptr)
  688. delete[] shandle.engineOptions.pathLV2;
  689. shandle.engineOptions.pathLV2 = carla_strdup_safe(valueStr);
  690. break;
  691. case CB::PLUGIN_VST2:
  692. if (shandle.engineOptions.pathVST2 != nullptr)
  693. delete[] shandle.engineOptions.pathVST2;
  694. shandle.engineOptions.pathVST2 = carla_strdup_safe(valueStr);
  695. break;
  696. case CB::PLUGIN_VST3:
  697. if (shandle.engineOptions.pathVST3 != nullptr)
  698. delete[] shandle.engineOptions.pathVST3;
  699. shandle.engineOptions.pathVST3 = carla_strdup_safe(valueStr);
  700. break;
  701. case CB::PLUGIN_SF2:
  702. if (shandle.engineOptions.pathSF2 != nullptr)
  703. delete[] shandle.engineOptions.pathSF2;
  704. shandle.engineOptions.pathSF2 = carla_strdup_safe(valueStr);
  705. break;
  706. case CB::PLUGIN_SFZ:
  707. if (shandle.engineOptions.pathSFZ != nullptr)
  708. delete[] shandle.engineOptions.pathSFZ;
  709. shandle.engineOptions.pathSFZ = carla_strdup_safe(valueStr);
  710. break;
  711. }
  712. break;
  713. case CB::ENGINE_OPTION_PATH_BINARIES:
  714. CARLA_SAFE_ASSERT_RETURN(valueStr != nullptr && valueStr[0] != '\0',);
  715. if (shandle.engineOptions.binaryDir != nullptr)
  716. delete[] shandle.engineOptions.binaryDir;
  717. shandle.engineOptions.binaryDir = carla_strdup_safe(valueStr);
  718. break;
  719. case CB::ENGINE_OPTION_PATH_RESOURCES:
  720. CARLA_SAFE_ASSERT_RETURN(valueStr != nullptr && valueStr[0] != '\0',);
  721. if (shandle.engineOptions.resourceDir != nullptr)
  722. delete[] shandle.engineOptions.resourceDir;
  723. shandle.engineOptions.resourceDir = carla_strdup_safe(valueStr);
  724. break;
  725. case CB::ENGINE_OPTION_PREVENT_BAD_BEHAVIOUR:
  726. CARLA_SAFE_ASSERT_RETURN(value == 0 || value == 1,);
  727. shandle.engineOptions.preventBadBehaviour = (value != 0);
  728. break;
  729. case CB::ENGINE_OPTION_FRONTEND_BACKGROUND_COLOR:
  730. shandle.engineOptions.bgColor = static_cast<uint>(value);
  731. break;
  732. case CB::ENGINE_OPTION_FRONTEND_FOREGROUND_COLOR:
  733. shandle.engineOptions.fgColor = static_cast<uint>(value);
  734. break;
  735. case CB::ENGINE_OPTION_FRONTEND_UI_SCALE:
  736. CARLA_SAFE_ASSERT_RETURN(value > 0,);
  737. shandle.engineOptions.uiScale = static_cast<float>(value) / 1000;
  738. break;
  739. case CB::ENGINE_OPTION_FRONTEND_WIN_ID: {
  740. CARLA_SAFE_ASSERT_RETURN(valueStr != nullptr && valueStr[0] != '\0',);
  741. const long long winId(std::strtoll(valueStr, nullptr, 16));
  742. CARLA_SAFE_ASSERT_RETURN(winId >= 0,);
  743. shandle.engineOptions.frontendWinId = static_cast<uintptr_t>(winId);
  744. } break;
  745. #if !defined(BUILD_BRIDGE_ALTERNATIVE_ARCH) && !defined(CARLA_OS_WIN)
  746. case CB::ENGINE_OPTION_WINE_EXECUTABLE:
  747. CARLA_SAFE_ASSERT_RETURN(valueStr != nullptr && valueStr[0] != '\0',);
  748. if (shandle.engineOptions.wine.executable != nullptr)
  749. delete[] shandle.engineOptions.wine.executable;
  750. shandle.engineOptions.wine.executable = carla_strdup_safe(valueStr);
  751. break;
  752. case CB::ENGINE_OPTION_WINE_AUTO_PREFIX:
  753. CARLA_SAFE_ASSERT_RETURN(value == 0 || value == 1,);
  754. shandle.engineOptions.wine.autoPrefix = (value != 0);
  755. break;
  756. case CB::ENGINE_OPTION_WINE_FALLBACK_PREFIX:
  757. CARLA_SAFE_ASSERT_RETURN(valueStr != nullptr && valueStr[0] != '\0',);
  758. if (shandle.engineOptions.wine.fallbackPrefix != nullptr)
  759. delete[] shandle.engineOptions.wine.fallbackPrefix;
  760. shandle.engineOptions.wine.fallbackPrefix = carla_strdup_safe(valueStr);
  761. break;
  762. case CB::ENGINE_OPTION_WINE_RT_PRIO_ENABLED:
  763. CARLA_SAFE_ASSERT_RETURN(value == 0 || value == 1,);
  764. shandle.engineOptions.wine.rtPrio = (value != 0);
  765. break;
  766. case CB::ENGINE_OPTION_WINE_BASE_RT_PRIO:
  767. CARLA_SAFE_ASSERT_RETURN(value >= 1 && value <= 89,);
  768. shandle.engineOptions.wine.baseRtPrio = value;
  769. break;
  770. case CB::ENGINE_OPTION_WINE_SERVER_RT_PRIO:
  771. CARLA_SAFE_ASSERT_RETURN(value >= 1 && value <= 99,);
  772. shandle.engineOptions.wine.serverRtPrio = value;
  773. break;
  774. #endif
  775. #ifndef BUILD_BRIDGE
  776. case CB::ENGINE_OPTION_DEBUG_CONSOLE_OUTPUT:
  777. shandle.logThreadEnabled = (value != 0);
  778. break;
  779. #endif
  780. case CB::ENGINE_OPTION_CLIENT_NAME_PREFIX:
  781. if (shandle.engineOptions.clientNamePrefix != nullptr)
  782. delete[] shandle.engineOptions.clientNamePrefix;
  783. shandle.engineOptions.clientNamePrefix = valueStr != nullptr && valueStr[0] != '\0'
  784. ? carla_strdup_safe(valueStr)
  785. : nullptr;
  786. break;
  787. case CB::ENGINE_OPTION_PLUGINS_ARE_STANDALONE:
  788. CARLA_SAFE_ASSERT_RETURN(value == 0 || value == 1,);
  789. shandle.engineOptions.pluginsAreStandalone = (value != 0);
  790. break;
  791. }
  792. }
  793. if (handle->engine != nullptr)
  794. handle->engine->setOption(option, value, valueStr);
  795. }
  796. void carla_set_file_callback(CarlaHostHandle handle, FileCallbackFunc func, void* ptr)
  797. {
  798. carla_debug("carla_set_file_callback(%p, %p, %p)", handle, func, ptr);
  799. if (handle->isStandalone)
  800. {
  801. CarlaHostStandalone& shandle((CarlaHostStandalone&)*handle);
  802. shandle.fileCallback = func;
  803. shandle.fileCallbackPtr = ptr;
  804. }
  805. if (handle->engine != nullptr)
  806. handle->engine->setFileCallback(func, ptr);
  807. }
  808. // --------------------------------------------------------------------------------------------------------------------
  809. bool carla_load_file(CarlaHostHandle handle, const char* filename)
  810. {
  811. CARLA_SAFE_ASSERT_RETURN(filename != nullptr && filename[0] != '\0', false);
  812. CARLA_SAFE_ASSERT_WITH_LAST_ERROR_RETURN(handle->engine != nullptr, "Engine is not initialized", false);
  813. carla_debug("carla_load_file(%p, \"%s\")", handle, filename);
  814. return handle->engine->loadFile(filename);
  815. }
  816. bool carla_load_project(CarlaHostHandle handle, const char* filename)
  817. {
  818. CARLA_SAFE_ASSERT_RETURN(filename != nullptr && filename[0] != '\0', false);
  819. CARLA_SAFE_ASSERT_WITH_LAST_ERROR_RETURN(handle->engine != nullptr, "Engine is not initialized", false);
  820. carla_debug("carla_load_project(%p, \"%s\")", handle, filename);
  821. return handle->engine->loadProject(filename, true);
  822. }
  823. bool carla_save_project(CarlaHostHandle handle, const char* filename)
  824. {
  825. CARLA_SAFE_ASSERT_RETURN(filename != nullptr && filename[0] != '\0', false);
  826. CARLA_SAFE_ASSERT_WITH_LAST_ERROR_RETURN(handle->engine != nullptr, "Engine is not initialized", false);
  827. carla_debug("carla_save_project(%p, \"%s\")", handle, filename);
  828. return handle->engine->saveProject(filename, true);
  829. }
  830. #ifndef BUILD_BRIDGE
  831. const char* carla_get_current_project_folder(CarlaHostHandle handle)
  832. {
  833. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, gNullCharPtr);
  834. carla_debug("carla_get_current_project_folder(%p)", handle);
  835. if (const char* const ret = handle->engine->getCurrentProjectFolder())
  836. return ret;
  837. return gNullCharPtr;
  838. }
  839. const char* carla_get_current_project_filename(CarlaHostHandle handle)
  840. {
  841. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr && handle->isStandalone, gNullCharPtr);
  842. carla_debug("carla_get_current_project_filename(%p)", handle);
  843. if (const char* const ret = handle->engine->getCurrentProjectFilename())
  844. return ret;
  845. return gNullCharPtr;
  846. }
  847. void carla_clear_project_filename(CarlaHostHandle handle)
  848. {
  849. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr,);
  850. carla_debug("carla_clear_project_filename(%p)", handle);
  851. handle->engine->clearCurrentProjectFilename();
  852. }
  853. // --------------------------------------------------------------------------------------------------------------------
  854. bool carla_patchbay_connect(CarlaHostHandle handle, bool external, uint groupIdA, uint portIdA, uint groupIdB, uint portIdB)
  855. {
  856. CARLA_SAFE_ASSERT_WITH_LAST_ERROR_RETURN(handle->engine != nullptr, "Engine is not initialized", false);
  857. carla_debug("carla_patchbay_connect(%p, %s, %u, %u, %u, %u)",
  858. handle, bool2str(external), groupIdA, portIdA, groupIdB, portIdB);
  859. return handle->engine->patchbayConnect(external, groupIdA, portIdA, groupIdB, portIdB);
  860. }
  861. bool carla_patchbay_disconnect(CarlaHostHandle handle, bool external, uint connectionId)
  862. {
  863. CARLA_SAFE_ASSERT_WITH_LAST_ERROR_RETURN(handle->engine != nullptr, "Engine is not initialized", false);
  864. carla_debug("carla_patchbay_disconnect(%p, %s, %i)", handle, bool2str(external), connectionId);
  865. return handle->engine->patchbayDisconnect(external, connectionId);
  866. }
  867. bool carla_patchbay_set_group_pos(CarlaHostHandle handle, bool external, uint groupId, int x1, int y1, int x2, int y2)
  868. {
  869. CARLA_SAFE_ASSERT_WITH_LAST_ERROR_RETURN(handle->engine != nullptr && handle->engine->isRunning(),
  870. "Engine is not running", false);
  871. carla_debug("carla_patchbay_set_group_pos(%p, %s, %u, %i, %i, %i, %i)",
  872. handle, bool2str(external), groupId, x1, y1, x2, y2);
  873. if (handle->engine->isAboutToClose())
  874. return true;
  875. return handle->engine->patchbaySetGroupPos(false, true, external, groupId, x1, y1, x2, y2);
  876. }
  877. bool carla_patchbay_refresh(CarlaHostHandle handle, bool external)
  878. {
  879. CARLA_SAFE_ASSERT_WITH_LAST_ERROR_RETURN(handle->engine != nullptr, "Engine is not initialized", false);
  880. carla_debug("carla_patchbay_refresh(%p, %s)", handle, bool2str(external));
  881. return handle->engine->patchbayRefresh(true, false, external);
  882. }
  883. // --------------------------------------------------------------------------------------------------------------------
  884. void carla_transport_play(CarlaHostHandle handle)
  885. {
  886. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr && handle->engine->isRunning(),);
  887. carla_debug("carla_transport_play(%p)", handle);
  888. handle->engine->transportPlay();
  889. }
  890. void carla_transport_pause(CarlaHostHandle handle)
  891. {
  892. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr && handle->engine->isRunning(),);
  893. carla_debug("carla_transport_pause(%p)", handle);
  894. handle->engine->transportPause();
  895. }
  896. void carla_transport_bpm(CarlaHostHandle handle, double bpm)
  897. {
  898. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr && handle->engine->isRunning(),);
  899. carla_debug("carla_transport_bpm(%p, %f)", handle, bpm);
  900. handle->engine->transportBPM(bpm);
  901. }
  902. void carla_transport_relocate(CarlaHostHandle handle, uint64_t frame)
  903. {
  904. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr && handle->engine->isRunning(),);
  905. carla_debug("carla_transport_relocate(%p, %i)", handle, frame);
  906. handle->engine->transportRelocate(frame);
  907. }
  908. uint64_t carla_get_current_transport_frame(CarlaHostHandle handle)
  909. {
  910. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr && handle->engine->isRunning(), 0);
  911. return handle->engine->getTimeInfo().frame;
  912. }
  913. const CarlaTransportInfo* carla_get_transport_info(CarlaHostHandle handle)
  914. {
  915. static CarlaTransportInfo retTransInfo;
  916. retTransInfo.clear();
  917. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr && handle->engine->isRunning(), &retTransInfo);
  918. const CB::EngineTimeInfo& timeInfo(handle->engine->getTimeInfo());
  919. retTransInfo.playing = timeInfo.playing;
  920. retTransInfo.frame = timeInfo.frame;
  921. if (timeInfo.bbt.valid)
  922. {
  923. retTransInfo.bar = timeInfo.bbt.bar;
  924. retTransInfo.beat = timeInfo.bbt.beat;
  925. retTransInfo.tick = static_cast<int32_t>(timeInfo.bbt.tick + 0.5);
  926. retTransInfo.bpm = timeInfo.bbt.beatsPerMinute;
  927. }
  928. return &retTransInfo;
  929. }
  930. #endif
  931. // --------------------------------------------------------------------------------------------------------------------
  932. uint32_t carla_get_current_plugin_count(CarlaHostHandle handle)
  933. {
  934. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, 0);
  935. carla_debug("carla_get_current_plugin_count(%p)", handle);
  936. return handle->engine->getCurrentPluginCount();
  937. }
  938. uint32_t carla_get_max_plugin_number(CarlaHostHandle handle)
  939. {
  940. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, 0);
  941. carla_debug("carla_get_max_plugin_number(%p)", handle);
  942. return handle->engine->getMaxPluginNumber();
  943. }
  944. // --------------------------------------------------------------------------------------------------------------------
  945. bool carla_add_plugin(CarlaHostHandle handle,
  946. BinaryType btype, PluginType ptype,
  947. const char* filename, const char* name, const char* label, int64_t uniqueId,
  948. const void* extraPtr, uint options)
  949. {
  950. CARLA_SAFE_ASSERT_WITH_LAST_ERROR_RETURN(handle->engine != nullptr, "Engine is not initialized", false);
  951. carla_debug("carla_add_plugin(%p, %i:%s, %i:%s, \"%s\", \"%s\", \"%s\", " P_INT64 ", %p, %u)",
  952. handle,
  953. btype, CB::BinaryType2Str(btype),
  954. ptype, CB::PluginType2Str(ptype),
  955. filename, name, label, uniqueId, extraPtr, options);
  956. return handle->engine->addPlugin(btype, ptype, filename, name, label, uniqueId, extraPtr, options);
  957. }
  958. bool carla_remove_plugin(CarlaHostHandle handle, uint pluginId)
  959. {
  960. CARLA_SAFE_ASSERT_WITH_LAST_ERROR_RETURN(handle->engine != nullptr, "Engine is not initialized", false);
  961. carla_debug("carla_remove_plugin(%p, %i)", handle, pluginId);
  962. return handle->engine->removePlugin(pluginId);
  963. }
  964. bool carla_remove_all_plugins(CarlaHostHandle handle)
  965. {
  966. CARLA_SAFE_ASSERT_WITH_LAST_ERROR_RETURN(handle->engine != nullptr, "Engine is not initialized", false);
  967. carla_debug("carla_remove_all_plugins(%p)", handle);
  968. return handle->engine->removeAllPlugins();
  969. }
  970. #ifndef BUILD_BRIDGE
  971. bool carla_rename_plugin(CarlaHostHandle handle, uint pluginId, const char* newName)
  972. {
  973. CARLA_SAFE_ASSERT_RETURN(newName != nullptr && newName[0] != '\0', false);
  974. CARLA_SAFE_ASSERT_WITH_LAST_ERROR_RETURN(handle->engine != nullptr, "Engine is not initialized", false);
  975. carla_debug("carla_rename_plugin(%p, %i, \"%s\")", handle, pluginId, newName);
  976. return handle->engine->renamePlugin(pluginId, newName);
  977. }
  978. bool carla_clone_plugin(CarlaHostHandle handle, uint pluginId)
  979. {
  980. CARLA_SAFE_ASSERT_WITH_LAST_ERROR_RETURN(handle->engine != nullptr, "Engine is not initialized", false);
  981. carla_debug("carla_clone_plugin(%p, %i)", handle, pluginId);
  982. return handle->engine->clonePlugin(pluginId);
  983. }
  984. bool carla_replace_plugin(CarlaHostHandle handle, uint pluginId)
  985. {
  986. CARLA_SAFE_ASSERT_WITH_LAST_ERROR_RETURN(handle->engine != nullptr, "Engine is not initialized", false);
  987. carla_debug("carla_replace_plugin(%p, %i)", handle, pluginId);
  988. return handle->engine->replacePlugin(pluginId);
  989. }
  990. bool carla_switch_plugins(CarlaHostHandle handle, uint pluginIdA, uint pluginIdB)
  991. {
  992. CARLA_SAFE_ASSERT_RETURN(pluginIdA != pluginIdB, false);
  993. CARLA_SAFE_ASSERT_WITH_LAST_ERROR_RETURN(handle->engine != nullptr, "Engine is not initialized", false);
  994. carla_debug("carla_switch_plugins(%p, %i, %i)", handle, pluginIdA, pluginIdB);
  995. return handle->engine->switchPlugins(pluginIdA, pluginIdB);
  996. }
  997. #endif
  998. // --------------------------------------------------------------------------------------------------------------------
  999. bool carla_load_plugin_state(CarlaHostHandle handle, uint pluginId, const char* filename)
  1000. {
  1001. CARLA_SAFE_ASSERT_RETURN(filename != nullptr && filename[0] != '\0', false);
  1002. CARLA_SAFE_ASSERT_WITH_LAST_ERROR_RETURN(handle->engine != nullptr
  1003. && handle->engine->isRunning(), "Engine is not running", false);
  1004. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1005. return plugin->loadStateFromFile(filename);
  1006. return false;
  1007. }
  1008. bool carla_save_plugin_state(CarlaHostHandle handle, uint pluginId, const char* filename)
  1009. {
  1010. CARLA_SAFE_ASSERT_RETURN(filename != nullptr && filename[0] != '\0', false);
  1011. CARLA_SAFE_ASSERT_WITH_LAST_ERROR_RETURN(handle->engine != nullptr, "Engine is not initialized", false);
  1012. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1013. return plugin->saveStateToFile(filename);
  1014. return false;
  1015. }
  1016. bool carla_export_plugin_lv2(CarlaHostHandle handle, uint pluginId, const char* lv2path)
  1017. {
  1018. CARLA_SAFE_ASSERT_RETURN(lv2path != nullptr && lv2path[0] != '\0', false);
  1019. CARLA_SAFE_ASSERT_WITH_LAST_ERROR_RETURN(handle->engine != nullptr, "Engine is not initialized", false);
  1020. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1021. return plugin->exportAsLV2(lv2path);
  1022. return false;
  1023. }
  1024. // --------------------------------------------------------------------------------------------------------------------
  1025. const CarlaPluginInfo* carla_get_plugin_info(CarlaHostHandle handle, uint pluginId)
  1026. {
  1027. static CarlaPluginInfo retInfo;
  1028. // reset
  1029. retInfo.type = CB::PLUGIN_NONE;
  1030. retInfo.category = CB::PLUGIN_CATEGORY_NONE;
  1031. retInfo.hints = 0x0;
  1032. retInfo.optionsAvailable = 0x0;
  1033. retInfo.optionsEnabled = 0x0;
  1034. retInfo.filename = gNullCharPtr;
  1035. retInfo.name = gNullCharPtr;
  1036. retInfo.iconName = gNullCharPtr;
  1037. retInfo.uniqueId = 0;
  1038. // cleanup
  1039. if (retInfo.label != gNullCharPtr)
  1040. {
  1041. delete[] retInfo.label;
  1042. retInfo.label = gNullCharPtr;
  1043. }
  1044. if (retInfo.maker != gNullCharPtr)
  1045. {
  1046. delete[] retInfo.maker;
  1047. retInfo.maker = gNullCharPtr;
  1048. }
  1049. if (retInfo.copyright != gNullCharPtr)
  1050. {
  1051. delete[] retInfo.copyright;
  1052. retInfo.copyright = gNullCharPtr;
  1053. }
  1054. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, &retInfo);
  1055. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1056. {
  1057. char strBuf[STR_MAX+1];
  1058. carla_zeroChars(strBuf, STR_MAX+1);
  1059. retInfo.type = plugin->getType();
  1060. retInfo.category = plugin->getCategory();
  1061. retInfo.hints = plugin->getHints();
  1062. retInfo.filename = plugin->getFilename();
  1063. retInfo.name = plugin->getName();
  1064. retInfo.iconName = plugin->getIconName();
  1065. retInfo.uniqueId = plugin->getUniqueId();
  1066. retInfo.optionsAvailable = plugin->getOptionsAvailable();
  1067. retInfo.optionsEnabled = plugin->getOptionsEnabled();
  1068. if (plugin->getLabel(strBuf))
  1069. retInfo.label = carla_strdup_safe(strBuf);
  1070. if (plugin->getMaker(strBuf))
  1071. retInfo.maker = carla_strdup_safe(strBuf);
  1072. if (plugin->getCopyright(strBuf))
  1073. retInfo.copyright = carla_strdup_safe(strBuf);
  1074. checkStringPtr(retInfo.filename);
  1075. checkStringPtr(retInfo.name);
  1076. checkStringPtr(retInfo.iconName);
  1077. checkStringPtr(retInfo.label);
  1078. checkStringPtr(retInfo.maker);
  1079. checkStringPtr(retInfo.copyright);
  1080. }
  1081. return &retInfo;
  1082. }
  1083. const CarlaPortCountInfo* carla_get_audio_port_count_info(CarlaHostHandle handle, uint pluginId)
  1084. {
  1085. static CarlaPortCountInfo retInfo;
  1086. carla_zeroStruct(retInfo);
  1087. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, &retInfo);
  1088. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1089. {
  1090. retInfo.ins = plugin->getAudioInCount();
  1091. retInfo.outs = plugin->getAudioOutCount();
  1092. }
  1093. return &retInfo;
  1094. }
  1095. const CarlaPortCountInfo* carla_get_midi_port_count_info(CarlaHostHandle handle, uint pluginId)
  1096. {
  1097. static CarlaPortCountInfo retInfo;
  1098. carla_zeroStruct(retInfo);
  1099. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, &retInfo);
  1100. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1101. {
  1102. retInfo.ins = plugin->getMidiInCount();
  1103. retInfo.outs = plugin->getMidiOutCount();
  1104. }
  1105. return &retInfo;
  1106. }
  1107. const CarlaPortCountInfo* carla_get_parameter_count_info(CarlaHostHandle handle, uint pluginId)
  1108. {
  1109. static CarlaPortCountInfo retInfo;
  1110. carla_zeroStruct(retInfo);
  1111. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, &retInfo);
  1112. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1113. plugin->getParameterCountInfo(retInfo.ins, retInfo.outs);
  1114. return &retInfo;
  1115. }
  1116. const CarlaParameterInfo* carla_get_parameter_info(CarlaHostHandle handle, uint pluginId, uint32_t parameterId)
  1117. {
  1118. static CarlaParameterInfo retInfo;
  1119. // reset
  1120. retInfo.scalePointCount = 0;
  1121. // cleanup
  1122. if (retInfo.name != gNullCharPtr)
  1123. {
  1124. delete[] retInfo.name;
  1125. retInfo.name = gNullCharPtr;
  1126. }
  1127. if (retInfo.symbol != gNullCharPtr)
  1128. {
  1129. delete[] retInfo.symbol;
  1130. retInfo.symbol = gNullCharPtr;
  1131. }
  1132. if (retInfo.unit != gNullCharPtr)
  1133. {
  1134. delete[] retInfo.unit;
  1135. retInfo.unit = gNullCharPtr;
  1136. }
  1137. if (retInfo.comment != gNullCharPtr)
  1138. {
  1139. delete[] retInfo.comment;
  1140. retInfo.comment = gNullCharPtr;
  1141. }
  1142. if (retInfo.groupName != gNullCharPtr)
  1143. {
  1144. delete[] retInfo.groupName;
  1145. retInfo.groupName = gNullCharPtr;
  1146. }
  1147. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, &retInfo);
  1148. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1149. {
  1150. char strBuf[STR_MAX+1];
  1151. carla_zeroChars(strBuf, STR_MAX+1);
  1152. retInfo.scalePointCount = plugin->getParameterScalePointCount(parameterId);
  1153. if (plugin->getParameterName(parameterId, strBuf))
  1154. {
  1155. retInfo.name = carla_strdup_safe(strBuf);
  1156. carla_zeroChars(strBuf, STR_MAX+1);
  1157. }
  1158. if (plugin->getParameterSymbol(parameterId, strBuf))
  1159. {
  1160. retInfo.symbol = carla_strdup_safe(strBuf);
  1161. carla_zeroChars(strBuf, STR_MAX+1);
  1162. }
  1163. if (plugin->getParameterUnit(parameterId, strBuf))
  1164. {
  1165. retInfo.unit = carla_strdup_safe(strBuf);
  1166. carla_zeroChars(strBuf, STR_MAX+1);
  1167. }
  1168. if (plugin->getParameterComment(parameterId, strBuf))
  1169. {
  1170. retInfo.comment = carla_strdup_safe(strBuf);
  1171. carla_zeroChars(strBuf, STR_MAX+1);
  1172. }
  1173. if (plugin->getParameterGroupName(parameterId, strBuf))
  1174. {
  1175. retInfo.groupName = carla_strdup_safe(strBuf);
  1176. carla_zeroChars(strBuf, STR_MAX+1);
  1177. }
  1178. checkStringPtr(retInfo.name);
  1179. checkStringPtr(retInfo.symbol);
  1180. checkStringPtr(retInfo.unit);
  1181. checkStringPtr(retInfo.comment);
  1182. checkStringPtr(retInfo.groupName);
  1183. }
  1184. return &retInfo;
  1185. }
  1186. const CarlaScalePointInfo* carla_get_parameter_scalepoint_info(CarlaHostHandle handle,
  1187. uint pluginId,
  1188. uint32_t parameterId,
  1189. uint32_t scalePointId)
  1190. {
  1191. CARLA_ASSERT(handle->engine != nullptr);
  1192. static CarlaScalePointInfo retInfo;
  1193. // reset
  1194. retInfo.value = 0.0f;
  1195. // cleanup
  1196. if (retInfo.label != gNullCharPtr)
  1197. {
  1198. delete[] retInfo.label;
  1199. retInfo.label = gNullCharPtr;
  1200. }
  1201. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, &retInfo);
  1202. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1203. {
  1204. char strBuf[STR_MAX+1];
  1205. retInfo.value = plugin->getParameterScalePointValue(parameterId, scalePointId);
  1206. carla_zeroChars(strBuf, STR_MAX+1);
  1207. if (plugin->getParameterScalePointLabel(parameterId, scalePointId, strBuf))
  1208. retInfo.label = carla_strdup_safe(strBuf);
  1209. checkStringPtr(retInfo.label);
  1210. }
  1211. return &retInfo;
  1212. }
  1213. // --------------------------------------------------------------------------------------------------------------------
  1214. const ParameterData* carla_get_parameter_data(CarlaHostHandle handle, uint pluginId, uint32_t parameterId)
  1215. {
  1216. static ParameterData retParamData;
  1217. // reset
  1218. retParamData.type = CB::PARAMETER_UNKNOWN;
  1219. retParamData.hints = 0x0;
  1220. retParamData.index = CB::PARAMETER_NULL;
  1221. retParamData.rindex = -1;
  1222. retParamData.midiChannel = 0;
  1223. retParamData.mappedControlIndex = CB::CONTROL_INDEX_NONE;
  1224. retParamData.mappedMinimum = 0.0f;
  1225. retParamData.mappedMaximum = 0.0f;
  1226. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, &retParamData);
  1227. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1228. {
  1229. CARLA_SAFE_ASSERT_RETURN(parameterId < plugin->getParameterCount(), &retParamData);
  1230. const ParameterData& pluginParamData(plugin->getParameterData(parameterId));
  1231. retParamData.type = pluginParamData.type;
  1232. retParamData.hints = pluginParamData.hints;
  1233. retParamData.index = pluginParamData.index;
  1234. retParamData.rindex = pluginParamData.rindex;
  1235. retParamData.midiChannel = pluginParamData.midiChannel;
  1236. retParamData.mappedControlIndex = pluginParamData.mappedControlIndex;
  1237. retParamData.mappedMinimum = pluginParamData.mappedMinimum;
  1238. retParamData.mappedMaximum = pluginParamData.mappedMaximum;
  1239. }
  1240. return &retParamData;
  1241. }
  1242. const ParameterRanges* carla_get_parameter_ranges(CarlaHostHandle handle, uint pluginId, uint32_t parameterId)
  1243. {
  1244. static ParameterRanges retParamRanges;
  1245. // reset
  1246. retParamRanges.def = 0.0f;
  1247. retParamRanges.min = 0.0f;
  1248. retParamRanges.max = 1.0f;
  1249. retParamRanges.step = 0.01f;
  1250. retParamRanges.stepSmall = 0.0001f;
  1251. retParamRanges.stepLarge = 0.1f;
  1252. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, &retParamRanges);
  1253. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1254. {
  1255. CARLA_SAFE_ASSERT_RETURN(parameterId < plugin->getParameterCount(), &retParamRanges);
  1256. const ParameterRanges& pluginParamRanges(plugin->getParameterRanges(parameterId));
  1257. retParamRanges.def = pluginParamRanges.def;
  1258. retParamRanges.min = pluginParamRanges.min;
  1259. retParamRanges.max = pluginParamRanges.max;
  1260. retParamRanges.step = pluginParamRanges.step;
  1261. retParamRanges.stepSmall = pluginParamRanges.stepSmall;
  1262. retParamRanges.stepLarge = pluginParamRanges.stepLarge;
  1263. }
  1264. return &retParamRanges;
  1265. }
  1266. const MidiProgramData* carla_get_midi_program_data(CarlaHostHandle handle, uint pluginId, uint32_t midiProgramId)
  1267. {
  1268. static MidiProgramData retMidiProgData = { 0, 0, gNullCharPtr };
  1269. // reset
  1270. retMidiProgData.bank = 0;
  1271. retMidiProgData.program = 0;
  1272. if (retMidiProgData.name != gNullCharPtr)
  1273. {
  1274. delete[] retMidiProgData.name;
  1275. retMidiProgData.name = gNullCharPtr;
  1276. }
  1277. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, &retMidiProgData);
  1278. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1279. {
  1280. CARLA_SAFE_ASSERT_RETURN(midiProgramId < plugin->getMidiProgramCount(), &retMidiProgData);
  1281. const MidiProgramData& pluginMidiProgData(plugin->getMidiProgramData(midiProgramId));
  1282. retMidiProgData.bank = pluginMidiProgData.bank;
  1283. retMidiProgData.program = pluginMidiProgData.program;
  1284. if (pluginMidiProgData.name != nullptr)
  1285. {
  1286. retMidiProgData.name = carla_strdup_safe(pluginMidiProgData.name);
  1287. checkStringPtr(retMidiProgData.name);
  1288. }
  1289. else
  1290. {
  1291. retMidiProgData.name = gNullCharPtr;
  1292. }
  1293. }
  1294. return &retMidiProgData;
  1295. }
  1296. const CustomData* carla_get_custom_data(CarlaHostHandle handle, uint pluginId, uint32_t customDataId)
  1297. {
  1298. static CustomData retCustomData = { gNullCharPtr, gNullCharPtr, gNullCharPtr };
  1299. // reset
  1300. if (retCustomData.type != gNullCharPtr)
  1301. {
  1302. delete[] retCustomData.type;
  1303. retCustomData.type = gNullCharPtr;
  1304. }
  1305. if (retCustomData.key != gNullCharPtr)
  1306. {
  1307. delete[] retCustomData.key;
  1308. retCustomData.key = gNullCharPtr;
  1309. }
  1310. if (retCustomData.value != gNullCharPtr)
  1311. {
  1312. delete[] retCustomData.value;
  1313. retCustomData.value = gNullCharPtr;
  1314. }
  1315. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, &retCustomData);
  1316. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1317. {
  1318. CARLA_SAFE_ASSERT_RETURN(customDataId < plugin->getCustomDataCount(), &retCustomData)
  1319. const CustomData& pluginCustomData(plugin->getCustomData(customDataId));
  1320. retCustomData.type = carla_strdup_safe(pluginCustomData.type);
  1321. retCustomData.key = carla_strdup_safe(pluginCustomData.key);
  1322. retCustomData.value = carla_strdup_safe(pluginCustomData.value);
  1323. checkStringPtr(retCustomData.type);
  1324. checkStringPtr(retCustomData.key);
  1325. checkStringPtr(retCustomData.value);
  1326. }
  1327. return &retCustomData;
  1328. }
  1329. const char* carla_get_custom_data_value(CarlaHostHandle handle, uint pluginId, const char* type, const char* key)
  1330. {
  1331. CARLA_SAFE_ASSERT_RETURN(type != nullptr && type[0] != '\0', gNullCharPtr);
  1332. CARLA_SAFE_ASSERT_RETURN(key != nullptr && key[0] != '\0', gNullCharPtr);
  1333. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, gNullCharPtr);
  1334. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1335. {
  1336. const uint32_t count = plugin->getCustomDataCount();
  1337. if (count == 0)
  1338. return gNullCharPtr;
  1339. static CarlaString customDataValue;
  1340. for (uint32_t i=0; i<count; ++i)
  1341. {
  1342. const CustomData& pluginCustomData(plugin->getCustomData(i));
  1343. if (std::strcmp(pluginCustomData.type, type) != 0)
  1344. continue;
  1345. if (std::strcmp(pluginCustomData.key, key) != 0)
  1346. continue;
  1347. customDataValue = pluginCustomData.value;
  1348. return customDataValue.buffer();
  1349. }
  1350. }
  1351. return gNullCharPtr;
  1352. }
  1353. const char* carla_get_chunk_data(CarlaHostHandle handle, uint pluginId)
  1354. {
  1355. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, gNullCharPtr);
  1356. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1357. {
  1358. CARLA_SAFE_ASSERT_RETURN(plugin->getOptionsEnabled() & CB::PLUGIN_OPTION_USE_CHUNKS, gNullCharPtr);
  1359. void* data = nullptr;
  1360. const std::size_t dataSize(plugin->getChunkData(&data));
  1361. CARLA_SAFE_ASSERT_RETURN(data != nullptr && dataSize > 0, gNullCharPtr);
  1362. static CarlaString chunkData;
  1363. chunkData = CarlaString::asBase64(data, static_cast<std::size_t>(dataSize));
  1364. return chunkData.buffer();
  1365. }
  1366. return gNullCharPtr;
  1367. }
  1368. // --------------------------------------------------------------------------------------------------------------------
  1369. uint32_t carla_get_parameter_count(CarlaHostHandle handle, uint pluginId)
  1370. {
  1371. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, 0);
  1372. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1373. return plugin->getParameterCount();
  1374. return 0;
  1375. }
  1376. uint32_t carla_get_program_count(CarlaHostHandle handle, uint pluginId)
  1377. {
  1378. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, 0);
  1379. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1380. return plugin->getProgramCount();
  1381. return 0;
  1382. }
  1383. uint32_t carla_get_midi_program_count(CarlaHostHandle handle, uint pluginId)
  1384. {
  1385. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, 0);
  1386. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1387. return plugin->getMidiProgramCount();
  1388. return 0;
  1389. }
  1390. uint32_t carla_get_custom_data_count(CarlaHostHandle handle, uint pluginId)
  1391. {
  1392. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, 0);
  1393. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1394. return plugin->getCustomDataCount();
  1395. return 0;
  1396. }
  1397. // --------------------------------------------------------------------------------------------------------------------
  1398. const char* carla_get_parameter_text(CarlaHostHandle handle, uint pluginId, uint32_t parameterId)
  1399. {
  1400. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, gNullCharPtr);
  1401. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1402. {
  1403. CARLA_SAFE_ASSERT_RETURN(parameterId < plugin->getParameterCount(), gNullCharPtr);
  1404. static char textBuf[STR_MAX+1];
  1405. carla_zeroChars(textBuf, STR_MAX+1);
  1406. if (! plugin->getParameterText(parameterId, textBuf))
  1407. textBuf[0] = '\0';
  1408. return textBuf;
  1409. }
  1410. return gNullCharPtr;
  1411. }
  1412. const char* carla_get_program_name(CarlaHostHandle handle, uint pluginId, uint32_t programId)
  1413. {
  1414. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, nullptr);
  1415. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1416. {
  1417. CARLA_SAFE_ASSERT_RETURN(programId < plugin->getProgramCount(), gNullCharPtr);
  1418. static char programName[STR_MAX+1];
  1419. carla_zeroChars(programName, STR_MAX+1);
  1420. if (! plugin->getProgramName(programId, programName))
  1421. programName[0] = '\0';
  1422. return programName;
  1423. }
  1424. return gNullCharPtr;
  1425. }
  1426. const char* carla_get_midi_program_name(CarlaHostHandle handle, uint pluginId, uint32_t midiProgramId)
  1427. {
  1428. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, gNullCharPtr);
  1429. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1430. {
  1431. CARLA_SAFE_ASSERT_RETURN(midiProgramId < plugin->getMidiProgramCount(), gNullCharPtr);
  1432. static char midiProgramName[STR_MAX+1];
  1433. carla_zeroChars(midiProgramName, STR_MAX+1);
  1434. if (! plugin->getMidiProgramName(midiProgramId, midiProgramName))
  1435. midiProgramName[0] = '\0';
  1436. return midiProgramName;
  1437. }
  1438. return gNullCharPtr;
  1439. }
  1440. const char* carla_get_real_plugin_name(CarlaHostHandle handle, uint pluginId)
  1441. {
  1442. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, gNullCharPtr);
  1443. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1444. {
  1445. static char realPluginName[STR_MAX+1];
  1446. carla_zeroChars(realPluginName, STR_MAX+1);
  1447. if (! plugin->getRealName(realPluginName))
  1448. realPluginName[0] = '\0';
  1449. return realPluginName;
  1450. }
  1451. return gNullCharPtr;
  1452. }
  1453. // --------------------------------------------------------------------------------------------------------------------
  1454. int32_t carla_get_current_program_index(CarlaHostHandle handle, uint pluginId)
  1455. {
  1456. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, -1);
  1457. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1458. return plugin->getCurrentProgram();
  1459. return -1;
  1460. }
  1461. int32_t carla_get_current_midi_program_index(CarlaHostHandle handle, uint pluginId)
  1462. {
  1463. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, -1);
  1464. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1465. return plugin->getCurrentMidiProgram();
  1466. return -1;
  1467. }
  1468. // --------------------------------------------------------------------------------------------------------------------
  1469. float carla_get_default_parameter_value(CarlaHostHandle handle, uint pluginId, uint32_t parameterId)
  1470. {
  1471. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, 0.0f);
  1472. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1473. {
  1474. CARLA_SAFE_ASSERT_RETURN(parameterId < plugin->getParameterCount(), 0.0f);
  1475. return plugin->getParameterRanges(parameterId).def;
  1476. }
  1477. return 0.0f;
  1478. }
  1479. float carla_get_current_parameter_value(CarlaHostHandle handle, uint pluginId, uint32_t parameterId)
  1480. {
  1481. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, 0.0f);
  1482. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1483. {
  1484. CARLA_SAFE_ASSERT_RETURN(parameterId < plugin->getParameterCount(), 0.0f);
  1485. return plugin->getParameterValue(parameterId);
  1486. }
  1487. return 0.0f;
  1488. }
  1489. float carla_get_internal_parameter_value(CarlaHostHandle handle, uint pluginId, int32_t parameterId)
  1490. {
  1491. #ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH
  1492. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, (parameterId == CB::PARAMETER_CTRL_CHANNEL) ? -1.0f : 0.0f);
  1493. #else
  1494. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, 0.0f);
  1495. #endif
  1496. CARLA_SAFE_ASSERT_RETURN(parameterId != CB::PARAMETER_NULL && parameterId > CB::PARAMETER_MAX, 0.0f);
  1497. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1498. return plugin->getInternalParameterValue(parameterId);
  1499. return 0.0f;
  1500. }
  1501. // --------------------------------------------------------------------------------------------------------------------
  1502. const float* carla_get_peak_values(CarlaHostHandle handle, uint pluginId)
  1503. {
  1504. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, nullptr);
  1505. return handle->engine->getPeaks(pluginId);
  1506. }
  1507. float carla_get_input_peak_value(CarlaHostHandle handle, uint pluginId, bool isLeft)
  1508. {
  1509. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, 0.0f);
  1510. return handle->engine->getInputPeak(pluginId, isLeft);
  1511. }
  1512. float carla_get_output_peak_value(CarlaHostHandle handle, uint pluginId, bool isLeft)
  1513. {
  1514. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, 0.0f);
  1515. return handle->engine->getOutputPeak(pluginId, isLeft);
  1516. }
  1517. // --------------------------------------------------------------------------------------------------------------------
  1518. CARLA_BACKEND_START_NAMESPACE
  1519. #ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH
  1520. // defined in CarlaPluginInternal.cpp
  1521. const void* carla_render_inline_display_internal(const CarlaPluginPtr& plugin, uint32_t width, uint32_t height);
  1522. #endif
  1523. // defined in CarlaPluginLV2.cpp
  1524. const void* carla_render_inline_display_lv2(const CarlaPluginPtr& plugin, uint32_t width, uint32_t height);
  1525. CARLA_BACKEND_END_NAMESPACE
  1526. const CarlaInlineDisplayImageSurface* carla_render_inline_display(CarlaHostHandle handle,
  1527. uint pluginId,
  1528. uint32_t width, uint32_t height)
  1529. {
  1530. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr && handle->engine->isRunning(), nullptr);
  1531. if (handle->engine->isAboutToClose())
  1532. return nullptr;
  1533. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1534. {
  1535. switch (plugin->getType())
  1536. {
  1537. #ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH
  1538. case CB::PLUGIN_INTERNAL:
  1539. return (const CarlaInlineDisplayImageSurface*)CB::carla_render_inline_display_internal(plugin, width, height);
  1540. #endif
  1541. case CB::PLUGIN_LV2:
  1542. return (const CarlaInlineDisplayImageSurface*)CB::carla_render_inline_display_lv2(plugin, width, height);
  1543. default:
  1544. return nullptr;
  1545. }
  1546. }
  1547. return nullptr;
  1548. }
  1549. // --------------------------------------------------------------------------------------------------------------------
  1550. void carla_set_active(CarlaHostHandle handle, uint pluginId, bool onOff)
  1551. {
  1552. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr,);
  1553. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1554. plugin->setActive(onOff, true, false);
  1555. }
  1556. #ifndef BUILD_BRIDGE
  1557. void carla_set_drywet(CarlaHostHandle handle, uint pluginId, float value)
  1558. {
  1559. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr,);
  1560. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1561. plugin->setDryWet(value, true, false);
  1562. }
  1563. void carla_set_volume(CarlaHostHandle handle, uint pluginId, float value)
  1564. {
  1565. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr,);
  1566. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1567. plugin->setVolume(value, true, false);
  1568. }
  1569. void carla_set_balance_left(CarlaHostHandle handle, uint pluginId, float value)
  1570. {
  1571. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr,);
  1572. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1573. plugin->setBalanceLeft(value, true, false);
  1574. }
  1575. void carla_set_balance_right(CarlaHostHandle handle, uint pluginId, float value)
  1576. {
  1577. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr,);
  1578. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1579. plugin->setBalanceRight(value, true, false);
  1580. }
  1581. void carla_set_panning(CarlaHostHandle handle, uint pluginId, float value)
  1582. {
  1583. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr,);
  1584. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1585. plugin->setPanning(value, true, false);
  1586. }
  1587. void carla_set_ctrl_channel(CarlaHostHandle handle, uint pluginId, int8_t channel)
  1588. {
  1589. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr,);
  1590. CARLA_SAFE_ASSERT_RETURN(channel >= -1 && channel < MAX_MIDI_CHANNELS,);
  1591. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1592. plugin->setCtrlChannel(channel, true, false);
  1593. }
  1594. #endif
  1595. void carla_set_option(CarlaHostHandle handle, uint pluginId, uint option, bool yesNo)
  1596. {
  1597. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr,);
  1598. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1599. plugin->setOption(option, yesNo, false);
  1600. }
  1601. // --------------------------------------------------------------------------------------------------------------------
  1602. void carla_set_parameter_value(CarlaHostHandle handle, uint pluginId, uint32_t parameterId, float value)
  1603. {
  1604. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr,);
  1605. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1606. {
  1607. CARLA_SAFE_ASSERT_RETURN(parameterId < plugin->getParameterCount(),);
  1608. plugin->setParameterValue(parameterId, value, true, true, false);
  1609. }
  1610. }
  1611. #ifndef BUILD_BRIDGE
  1612. void carla_set_parameter_midi_channel(CarlaHostHandle handle, uint pluginId, uint32_t parameterId, uint8_t channel)
  1613. {
  1614. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr,);
  1615. CARLA_SAFE_ASSERT_RETURN(channel < MAX_MIDI_CHANNELS,);
  1616. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1617. {
  1618. CARLA_SAFE_ASSERT_RETURN(parameterId < plugin->getParameterCount(),);
  1619. plugin->setParameterMidiChannel(parameterId, channel, true, false);
  1620. }
  1621. }
  1622. void carla_set_parameter_mapped_control_index(CarlaHostHandle handle, uint pluginId, uint32_t parameterId, int16_t index)
  1623. {
  1624. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr,);
  1625. CARLA_SAFE_ASSERT_RETURN(index >= CB::CONTROL_INDEX_NONE && index <= CB::CONTROL_INDEX_MAX_ALLOWED,);
  1626. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1627. {
  1628. CARLA_SAFE_ASSERT_RETURN(parameterId < plugin->getParameterCount(),);
  1629. plugin->setParameterMappedControlIndex(parameterId, index, true, false, true);
  1630. }
  1631. }
  1632. void carla_set_parameter_mapped_range(CarlaHostHandle handle, uint pluginId, uint32_t parameterId, float minimum, float maximum)
  1633. {
  1634. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr,);
  1635. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1636. {
  1637. CARLA_SAFE_ASSERT_RETURN(parameterId < plugin->getParameterCount(),);
  1638. plugin->setParameterMappedRange(parameterId, minimum, maximum, true, false);
  1639. }
  1640. }
  1641. void carla_set_parameter_touch(CarlaHostHandle handle, uint pluginId, uint32_t parameterId, bool touch)
  1642. {
  1643. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr,);
  1644. carla_debug("carla_set_parameter_touch(%p, %i, %i, %s)", handle, pluginId, parameterId, bool2str(touch));
  1645. return handle->engine->touchPluginParameter(pluginId, parameterId, touch);
  1646. }
  1647. #endif
  1648. // --------------------------------------------------------------------------------------------------------------------
  1649. void carla_set_program(CarlaHostHandle handle, uint pluginId, uint32_t programId)
  1650. {
  1651. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr,);
  1652. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1653. {
  1654. CARLA_SAFE_ASSERT_RETURN(programId < plugin->getProgramCount(),);
  1655. plugin->setProgram(static_cast<int32_t>(programId), true, true, false);
  1656. }
  1657. }
  1658. void carla_set_midi_program(CarlaHostHandle handle, uint pluginId, uint32_t midiProgramId)
  1659. {
  1660. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr,);
  1661. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1662. {
  1663. CARLA_SAFE_ASSERT_RETURN(midiProgramId < plugin->getMidiProgramCount(),);
  1664. plugin->setMidiProgram(static_cast<int32_t>(midiProgramId), true, true, false);
  1665. }
  1666. }
  1667. // --------------------------------------------------------------------------------------------------------------------
  1668. void carla_set_custom_data(CarlaHostHandle handle, uint pluginId, const char* type, const char* key, const char* value)
  1669. {
  1670. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr,);
  1671. CARLA_SAFE_ASSERT_RETURN(type != nullptr && type[0] != '\0',);
  1672. CARLA_SAFE_ASSERT_RETURN(key != nullptr && key[0] != '\0',);
  1673. CARLA_SAFE_ASSERT_RETURN(value != nullptr,);
  1674. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1675. plugin->setCustomData(type, key, value, true);
  1676. }
  1677. void carla_set_chunk_data(CarlaHostHandle handle, uint pluginId, const char* chunkData)
  1678. {
  1679. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr,);
  1680. CARLA_SAFE_ASSERT_RETURN(chunkData != nullptr && chunkData[0] != '\0',);
  1681. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1682. {
  1683. CARLA_SAFE_ASSERT_RETURN(plugin->getOptionsEnabled() & CB::PLUGIN_OPTION_USE_CHUNKS,);
  1684. std::vector<uint8_t> chunk(carla_getChunkFromBase64String(chunkData));
  1685. #ifdef CARLA_PROPER_CPP11_SUPPORT
  1686. plugin->setChunkData(chunk.data(), chunk.size());
  1687. #else
  1688. plugin->setChunkData(&chunk.front(), chunk.size());
  1689. #endif
  1690. }
  1691. }
  1692. // --------------------------------------------------------------------------------------------------------------------
  1693. void carla_prepare_for_save(CarlaHostHandle handle, uint pluginId)
  1694. {
  1695. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr,);
  1696. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1697. plugin->prepareForSave(false);
  1698. }
  1699. void carla_reset_parameters(CarlaHostHandle handle, uint pluginId)
  1700. {
  1701. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr,);
  1702. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1703. plugin->resetParameters();
  1704. }
  1705. void carla_randomize_parameters(CarlaHostHandle handle, uint pluginId)
  1706. {
  1707. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr,);
  1708. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1709. plugin->randomizeParameters();
  1710. }
  1711. #ifndef BUILD_BRIDGE
  1712. void carla_send_midi_note(CarlaHostHandle handle, uint pluginId, uint8_t channel, uint8_t note, uint8_t velocity)
  1713. {
  1714. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr && handle->engine->isRunning(),);
  1715. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1716. plugin->sendMidiSingleNote(channel, note, velocity, true, true, false);
  1717. }
  1718. #endif
  1719. void carla_set_custom_ui_title(CarlaHostHandle handle, uint pluginId, const char* title)
  1720. {
  1721. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr,);
  1722. CARLA_SAFE_ASSERT_RETURN(title != nullptr,);
  1723. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1724. plugin->setCustomUITitle(title);
  1725. }
  1726. void carla_show_custom_ui(CarlaHostHandle handle, uint pluginId, bool yesNo)
  1727. {
  1728. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr,);
  1729. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1730. plugin->showCustomUI(yesNo);
  1731. }
  1732. void* carla_embed_custom_ui(CarlaHostHandle handle, uint pluginId, void* ptr)
  1733. {
  1734. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, nullptr);
  1735. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1736. return plugin->embedCustomUI(ptr);
  1737. return nullptr;
  1738. }
  1739. // --------------------------------------------------------------------------------------------------------------------
  1740. uint32_t carla_get_buffer_size(CarlaHostHandle handle)
  1741. {
  1742. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, 0);
  1743. carla_debug("carla_get_buffer_size(%p)", handle);
  1744. return handle->engine->getBufferSize();
  1745. }
  1746. double carla_get_sample_rate(CarlaHostHandle handle)
  1747. {
  1748. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, 0.0);
  1749. carla_debug("carla_get_sample_rate(%p)", handle);
  1750. return handle->engine->getSampleRate();
  1751. }
  1752. // --------------------------------------------------------------------------------------------------------------------
  1753. const char* carla_get_last_error(CarlaHostHandle handle)
  1754. {
  1755. carla_debug("carla_get_last_error(%p)", handle);
  1756. if (handle->engine != nullptr)
  1757. return handle->engine->getLastError();
  1758. return handle->isStandalone
  1759. ? ((CarlaHostStandalone*)handle)->lastError.buffer()
  1760. : gNullCharPtr;
  1761. }
  1762. const char* carla_get_host_osc_url_tcp(CarlaHostHandle handle)
  1763. {
  1764. carla_debug("carla_get_host_osc_url_tcp(%p)", handle);
  1765. #if defined(HAVE_LIBLO) && !defined(BUILD_BRIDGE)
  1766. if (handle->engine == nullptr)
  1767. {
  1768. carla_stderr2("carla_get_host_osc_url_tcp() failed, engine is not running");
  1769. if (handle->isStandalone)
  1770. ((CarlaHostStandalone*)handle)->lastError = "Engine is not running";
  1771. return gNullCharPtr;
  1772. }
  1773. const char* const path = handle->engine->getOscServerPathTCP();
  1774. if (path != nullptr && path[0] != '\0')
  1775. return path;
  1776. static const char* const notAvailable = "(OSC TCP port not available)";
  1777. return notAvailable;
  1778. #else
  1779. return "(OSC support not available in this build)";
  1780. // unused
  1781. (void)handle;
  1782. #endif
  1783. }
  1784. const char* carla_get_host_osc_url_udp(CarlaHostHandle handle)
  1785. {
  1786. carla_debug("carla_get_host_osc_url_udp(%p)", handle);
  1787. #if defined(HAVE_LIBLO) && !defined(BUILD_BRIDGE)
  1788. if (handle->engine == nullptr)
  1789. {
  1790. carla_stderr2("carla_get_host_osc_url_udp() failed, engine is not running");
  1791. if (handle->isStandalone)
  1792. ((CarlaHostStandalone*)handle)->lastError = "Engine is not running";
  1793. return gNullCharPtr;
  1794. }
  1795. const char* const path = handle->engine->getOscServerPathUDP();
  1796. if (path != nullptr && path[0] != '\0')
  1797. return path;
  1798. static const char* const notAvailable = "(OSC UDP port not available)";
  1799. return notAvailable;
  1800. #else
  1801. return "(OSC support not available in this build)";
  1802. // unused
  1803. (void)handle;
  1804. #endif
  1805. }
  1806. // --------------------------------------------------------------------------------------------------------------------
  1807. #ifndef CARLA_PLUGIN_EXPORT
  1808. # define CARLA_PLUGIN_UI_CLASS_PREFIX Standalone
  1809. # include "CarlaPluginUI.cpp"
  1810. # undef CARLA_PLUGIN_UI_CLASS_PREFIX
  1811. # include "CarlaDssiUtils.cpp"
  1812. # include "CarlaMacUtils.cpp"
  1813. # include "CarlaPatchbayUtils.cpp"
  1814. # include "CarlaPipeUtils.cpp"
  1815. # include "CarlaProcessUtils.cpp"
  1816. # include "CarlaStateUtils.cpp"
  1817. # include "utils/Information.cpp"
  1818. # include "utils/Windows.cpp"
  1819. #endif /* CARLA_PLUGIN_EXPORT */
  1820. // --------------------------------------------------------------------------------------------------------------------