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

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