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 74KB

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