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

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