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

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