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

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