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

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