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

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