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

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