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

6 years ago
10 years ago
6 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
11 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
11 years ago
11 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
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
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
10 years ago
10 years ago
10 years ago
10 years ago
10 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
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393
  1. /*
  2. * Carla Standalone
  3. * Copyright (C) 2011-2021 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 "CarlaHostImpl.hpp"
  20. #include "CarlaMIDI.h"
  21. #include "CarlaEngineInit.hpp"
  22. #include "CarlaPlugin.hpp"
  23. #include "CarlaBackendUtils.hpp"
  24. #include "CarlaBase64Utils.hpp"
  25. #include "ThreadSafeFFTW.hpp"
  26. #ifndef BUILD_BRIDGE
  27. # include "CarlaLogThread.hpp"
  28. #endif
  29. #include "water/files/File.h"
  30. #define CARLA_SAFE_ASSERT_WITH_LAST_ERROR_RETURN(cond, msg, ret) \
  31. if (! (cond)) { \
  32. carla_stderr2("%s: " msg, __FUNCTION__); \
  33. if (handle->isStandalone) \
  34. ((CarlaHostStandalone*)handle)->lastError = msg; \
  35. return ret; \
  36. }
  37. // --------------------------------------------------------------------------------------------------------------------
  38. #ifdef USING_JUCE
  39. static void carla_standalone_juce_init(void);
  40. static void carla_standalone_juce_idle(void);
  41. static void carla_standalone_juce_cleanup(void);
  42. # define carla_juce_init carla_standalone_juce_init
  43. # define carla_juce_idle carla_standalone_juce_idle
  44. # define carla_juce_cleanup carla_standalone_juce_cleanup
  45. # include "utils/JUCE.cpp"
  46. # undef carla_juce_init
  47. # undef carla_juce_idle
  48. # undef carla_juce_cleanup
  49. #endif
  50. // -------------------------------------------------------------------------------------------------------------------
  51. // Always return a valid string ptr for standalone functions
  52. static const char* const gNullCharPtr = "";
  53. static void checkStringPtr(const char*& charPtr) noexcept
  54. {
  55. if (charPtr == nullptr)
  56. charPtr = gNullCharPtr;
  57. }
  58. // -------------------------------------------------------------------------------------------------------------------
  59. // Constructors
  60. _CarlaPluginInfo::_CarlaPluginInfo() noexcept
  61. : type(CB::PLUGIN_NONE),
  62. category(CB::PLUGIN_CATEGORY_NONE),
  63. hints(0x0),
  64. optionsAvailable(0x0),
  65. optionsEnabled(0x0),
  66. filename(gNullCharPtr),
  67. name(gNullCharPtr),
  68. label(gNullCharPtr),
  69. maker(gNullCharPtr),
  70. copyright(gNullCharPtr),
  71. iconName(gNullCharPtr),
  72. uniqueId(0) {}
  73. _CarlaPluginInfo::~_CarlaPluginInfo() noexcept
  74. {
  75. if (label != gNullCharPtr)
  76. delete[] label;
  77. if (maker != gNullCharPtr)
  78. delete[] maker;
  79. if (copyright != gNullCharPtr)
  80. delete[] copyright;
  81. }
  82. _CarlaParameterInfo::_CarlaParameterInfo() noexcept
  83. : name(gNullCharPtr),
  84. symbol(gNullCharPtr),
  85. unit(gNullCharPtr),
  86. comment(gNullCharPtr),
  87. groupName(gNullCharPtr),
  88. scalePointCount(0) {}
  89. _CarlaParameterInfo::~_CarlaParameterInfo() noexcept
  90. {
  91. if (name != gNullCharPtr)
  92. delete[] name;
  93. if (symbol != gNullCharPtr)
  94. delete[] symbol;
  95. if (unit != gNullCharPtr)
  96. delete[] unit;
  97. if (comment != gNullCharPtr)
  98. delete[] comment;
  99. if (groupName != gNullCharPtr)
  100. delete[] groupName;
  101. }
  102. _CarlaScalePointInfo::_CarlaScalePointInfo() noexcept
  103. : value(0.0f),
  104. label(gNullCharPtr) {}
  105. _CarlaScalePointInfo::~_CarlaScalePointInfo() noexcept
  106. {
  107. if (label != gNullCharPtr)
  108. delete[] label;
  109. }
  110. _CarlaTransportInfo::_CarlaTransportInfo() noexcept
  111. : playing(false),
  112. frame(0),
  113. bar(0),
  114. beat(0),
  115. tick(0),
  116. bpm(0.0) {}
  117. void _CarlaTransportInfo::clear() noexcept
  118. {
  119. playing = false;
  120. frame = 0;
  121. bar = 0;
  122. beat = 0;
  123. tick = 0;
  124. bpm = 0.0;
  125. }
  126. // --------------------------------------------------------------------------------------------------------------------
  127. using CarlaBackend::CarlaPluginPtr;
  128. // --------------------------------------------------------------------------------------------------------------------
  129. uint carla_get_engine_driver_count()
  130. {
  131. carla_debug("carla_get_engine_driver_count()");
  132. return CarlaEngine::getDriverCount();
  133. }
  134. const char* carla_get_engine_driver_name(uint index)
  135. {
  136. carla_debug("carla_get_engine_driver_name(%i)", index);
  137. return CarlaEngine::getDriverName(index);
  138. }
  139. const char* const* carla_get_engine_driver_device_names(uint index)
  140. {
  141. carla_debug("carla_get_engine_driver_device_names(%i)", index);
  142. return CarlaEngine::getDriverDeviceNames(index);
  143. }
  144. const EngineDriverDeviceInfo* carla_get_engine_driver_device_info(uint index, const char* name)
  145. {
  146. CARLA_SAFE_ASSERT_RETURN(name != nullptr, nullptr);
  147. static EngineDriverDeviceInfo retDevInfo;
  148. static const uint32_t nullBufferSizes[] = { 0 };
  149. static const double nullSampleRates[] = { 0.0 };
  150. carla_debug("carla_get_engine_driver_device_info(%i, \"%s\")", index, name);
  151. if (const EngineDriverDeviceInfo* const devInfo = CarlaEngine::getDriverDeviceInfo(index, name))
  152. {
  153. retDevInfo.hints = devInfo->hints;
  154. retDevInfo.bufferSizes = (devInfo->bufferSizes != nullptr) ? devInfo->bufferSizes : nullBufferSizes;
  155. retDevInfo.sampleRates = (devInfo->sampleRates != nullptr) ? devInfo->sampleRates : nullSampleRates;
  156. }
  157. else
  158. {
  159. retDevInfo.hints = 0x0;
  160. retDevInfo.bufferSizes = nullBufferSizes;
  161. retDevInfo.sampleRates = nullSampleRates;
  162. }
  163. return &retDevInfo;
  164. }
  165. bool carla_show_engine_driver_device_control_panel(uint index, const char* name)
  166. {
  167. return CarlaEngine::showDriverDeviceControlPanel(index, name);
  168. }
  169. // --------------------------------------------------------------------------------------------------------------------
  170. CarlaHostHandle carla_standalone_host_init(void)
  171. {
  172. #ifdef CARLA_OS_UNIX
  173. static const ThreadSafeFFTW sThreadSafeFFTW;
  174. #endif
  175. static CarlaHostStandalone gStandalone;
  176. return &gStandalone;
  177. }
  178. CarlaEngine* carla_get_engine_from_handle(CarlaHostHandle handle)
  179. {
  180. carla_debug("carla_get_engine(%p)", handle);
  181. return handle->engine;
  182. }
  183. // --------------------------------------------------------------------------------------------------------------------
  184. static void carla_engine_init_common(const CarlaHostStandalone& standalone, CarlaEngine* const engine)
  185. {
  186. engine->setCallback(standalone.engineCallback, standalone.engineCallbackPtr);
  187. engine->setFileCallback(standalone.fileCallback, standalone.fileCallbackPtr);
  188. using water::File;
  189. const File waterBinaryDir(File::getSpecialLocation(File::currentExecutableFile).getParentDirectory());
  190. #ifdef BUILD_BRIDGE
  191. /*
  192. if (const char* const forceStereo = std::getenv("ENGINE_OPTION_FORCE_STEREO"))
  193. engine->setOption(CB::ENGINE_OPTION_FORCE_STEREO, (std::strcmp(forceStereo, "true") == 0) ? 1 : 0, nullptr);
  194. if (const char* const preferPluginBridges = std::getenv("ENGINE_OPTION_PREFER_PLUGIN_BRIDGES"))
  195. engine->setOption(CB::ENGINE_OPTION_PREFER_PLUGIN_BRIDGES, (std::strcmp(preferPluginBridges, "true") == 0) ? 1 : 0, nullptr);
  196. if (const char* const preferUiBridges = std::getenv("ENGINE_OPTION_PREFER_UI_BRIDGES"))
  197. engine->setOption(CB::ENGINE_OPTION_PREFER_UI_BRIDGES, (std::strcmp(preferUiBridges, "true") == 0) ? 1 : 0, nullptr);
  198. */
  199. if (const char* const uisAlwaysOnTop = std::getenv("ENGINE_OPTION_UIS_ALWAYS_ON_TOP"))
  200. engine->setOption(CB::ENGINE_OPTION_UIS_ALWAYS_ON_TOP, (std::strcmp(uisAlwaysOnTop, "true") == 0) ? 1 : 0, nullptr);
  201. if (const char* const maxParameters = std::getenv("ENGINE_OPTION_MAX_PARAMETERS"))
  202. engine->setOption(CB::ENGINE_OPTION_MAX_PARAMETERS, std::atoi(maxParameters), nullptr);
  203. if (const char* const resetXruns = std::getenv("ENGINE_OPTION_RESET_XRUNS"))
  204. engine->setOption(CB::ENGINE_OPTION_RESET_XRUNS, (std::strcmp(resetXruns, "true") == 0) ? 1 : 0, nullptr);
  205. if (const char* const uiBridgesTimeout = std::getenv("ENGINE_OPTION_UI_BRIDGES_TIMEOUT"))
  206. engine->setOption(CB::ENGINE_OPTION_UI_BRIDGES_TIMEOUT, std::atoi(uiBridgesTimeout), nullptr);
  207. if (const char* const pathAudio = std::getenv("ENGINE_OPTION_FILE_PATH_AUDIO"))
  208. engine->setOption(CB::ENGINE_OPTION_FILE_PATH, CB::FILE_AUDIO, pathAudio);
  209. if (const char* const pathMIDI = std::getenv("ENGINE_OPTION_FILE_PATH_MIDI"))
  210. engine->setOption(CB::ENGINE_OPTION_FILE_PATH, CB::FILE_MIDI, pathMIDI);
  211. if (const char* const pathLADSPA = std::getenv("ENGINE_OPTION_PLUGIN_PATH_LADSPA"))
  212. engine->setOption(CB::ENGINE_OPTION_PLUGIN_PATH, CB::PLUGIN_LADSPA, pathLADSPA);
  213. if (const char* const pathDSSI = std::getenv("ENGINE_OPTION_PLUGIN_PATH_DSSI"))
  214. engine->setOption(CB::ENGINE_OPTION_PLUGIN_PATH, CB::PLUGIN_DSSI, pathDSSI);
  215. if (const char* const pathLV2 = std::getenv("ENGINE_OPTION_PLUGIN_PATH_LV2"))
  216. engine->setOption(CB::ENGINE_OPTION_PLUGIN_PATH, CB::PLUGIN_LV2, pathLV2);
  217. if (const char* const pathVST2 = std::getenv("ENGINE_OPTION_PLUGIN_PATH_VST2"))
  218. engine->setOption(CB::ENGINE_OPTION_PLUGIN_PATH, CB::PLUGIN_VST2, pathVST2);
  219. if (const char* const pathVST3 = std::getenv("ENGINE_OPTION_PLUGIN_PATH_VST3"))
  220. engine->setOption(CB::ENGINE_OPTION_PLUGIN_PATH, CB::PLUGIN_VST3, pathVST3);
  221. if (const char* const pathSF2 = std::getenv("ENGINE_OPTION_PLUGIN_PATH_SF2"))
  222. engine->setOption(CB::ENGINE_OPTION_PLUGIN_PATH, CB::PLUGIN_SF2, pathSF2);
  223. if (const char* const pathSFZ = std::getenv("ENGINE_OPTION_PLUGIN_PATH_SFZ"))
  224. engine->setOption(CB::ENGINE_OPTION_PLUGIN_PATH, CB::PLUGIN_SFZ, pathSFZ);
  225. if (const char* const binaryDir = std::getenv("ENGINE_OPTION_PATH_BINARIES"))
  226. engine->setOption(CB::ENGINE_OPTION_PATH_BINARIES, 0, binaryDir);
  227. else
  228. engine->setOption(CB::ENGINE_OPTION_PATH_BINARIES, 0, waterBinaryDir.getFullPathName().toRawUTF8());
  229. if (const char* const resourceDir = std::getenv("ENGINE_OPTION_PATH_RESOURCES"))
  230. engine->setOption(CB::ENGINE_OPTION_PATH_RESOURCES, 0, resourceDir);
  231. else
  232. engine->setOption(CB::ENGINE_OPTION_PATH_RESOURCES, 0, waterBinaryDir.getChildFile("resources").getFullPathName().toRawUTF8());
  233. if (const char* const preventBadBehaviour = std::getenv("ENGINE_OPTION_PREVENT_BAD_BEHAVIOUR"))
  234. engine->setOption(CB::ENGINE_OPTION_PREVENT_BAD_BEHAVIOUR, (std::strcmp(preventBadBehaviour, "true") == 0) ? 1 : 0, nullptr);
  235. if (const char* const frontendWinId = std::getenv("ENGINE_OPTION_FRONTEND_WIN_ID"))
  236. engine->setOption(CB::ENGINE_OPTION_FRONTEND_WIN_ID, 0, frontendWinId);
  237. #else
  238. engine->setOption(CB::ENGINE_OPTION_FORCE_STEREO, standalone.engineOptions.forceStereo ? 1 : 0, nullptr);
  239. engine->setOption(CB::ENGINE_OPTION_PREFER_PLUGIN_BRIDGES, standalone.engineOptions.preferPluginBridges ? 1 : 0, nullptr);
  240. engine->setOption(CB::ENGINE_OPTION_PREFER_UI_BRIDGES, standalone.engineOptions.preferUiBridges ? 1 : 0, nullptr);
  241. engine->setOption(CB::ENGINE_OPTION_UIS_ALWAYS_ON_TOP, standalone.engineOptions.uisAlwaysOnTop ? 1 : 0, nullptr);
  242. engine->setOption(CB::ENGINE_OPTION_MAX_PARAMETERS, static_cast<int>(standalone.engineOptions.maxParameters), nullptr);
  243. engine->setOption(CB::ENGINE_OPTION_RESET_XRUNS, standalone.engineOptions.resetXruns ? 1 : 0, nullptr);
  244. engine->setOption(CB::ENGINE_OPTION_UI_BRIDGES_TIMEOUT, static_cast<int>(standalone.engineOptions.uiBridgesTimeout), nullptr);
  245. engine->setOption(CB::ENGINE_OPTION_AUDIO_BUFFER_SIZE, static_cast<int>(standalone.engineOptions.audioBufferSize), nullptr);
  246. engine->setOption(CB::ENGINE_OPTION_AUDIO_SAMPLE_RATE, static_cast<int>(standalone.engineOptions.audioSampleRate), nullptr);
  247. engine->setOption(CB::ENGINE_OPTION_AUDIO_TRIPLE_BUFFER, standalone.engineOptions.audioTripleBuffer ? 1 : 0, nullptr);
  248. if (standalone.engineOptions.audioDriver != nullptr)
  249. engine->setOption(CB::ENGINE_OPTION_AUDIO_DRIVER, 0, standalone.engineOptions.audioDriver);
  250. if (standalone.engineOptions.audioDevice != nullptr)
  251. engine->setOption(CB::ENGINE_OPTION_AUDIO_DEVICE, 0, standalone.engineOptions.audioDevice);
  252. engine->setOption(CB::ENGINE_OPTION_OSC_ENABLED, standalone.engineOptions.oscEnabled, nullptr);
  253. engine->setOption(CB::ENGINE_OPTION_OSC_PORT_TCP, standalone.engineOptions.oscPortTCP, nullptr);
  254. engine->setOption(CB::ENGINE_OPTION_OSC_PORT_UDP, standalone.engineOptions.oscPortUDP, nullptr);
  255. if (standalone.engineOptions.pathAudio != nullptr)
  256. engine->setOption(CB::ENGINE_OPTION_FILE_PATH, CB::FILE_AUDIO, standalone.engineOptions.pathAudio);
  257. if (standalone.engineOptions.pathMIDI != nullptr)
  258. engine->setOption(CB::ENGINE_OPTION_FILE_PATH, CB::FILE_MIDI, standalone.engineOptions.pathMIDI);
  259. if (standalone.engineOptions.pathLADSPA != nullptr)
  260. engine->setOption(CB::ENGINE_OPTION_PLUGIN_PATH, CB::PLUGIN_LADSPA, standalone.engineOptions.pathLADSPA);
  261. if (standalone.engineOptions.pathDSSI != nullptr)
  262. engine->setOption(CB::ENGINE_OPTION_PLUGIN_PATH, CB::PLUGIN_DSSI, standalone.engineOptions.pathDSSI);
  263. if (standalone.engineOptions.pathLV2 != nullptr)
  264. engine->setOption(CB::ENGINE_OPTION_PLUGIN_PATH, CB::PLUGIN_LV2, standalone.engineOptions.pathLV2);
  265. if (standalone.engineOptions.pathVST2 != nullptr)
  266. engine->setOption(CB::ENGINE_OPTION_PLUGIN_PATH, CB::PLUGIN_VST2, standalone.engineOptions.pathVST2);
  267. if (standalone.engineOptions.pathVST3 != nullptr)
  268. engine->setOption(CB::ENGINE_OPTION_PLUGIN_PATH, CB::PLUGIN_VST3, standalone.engineOptions.pathVST3);
  269. if (standalone.engineOptions.pathSF2 != nullptr)
  270. engine->setOption(CB::ENGINE_OPTION_PLUGIN_PATH, CB::PLUGIN_SF2, standalone.engineOptions.pathSF2);
  271. if (standalone.engineOptions.pathSFZ != nullptr)
  272. engine->setOption(CB::ENGINE_OPTION_PLUGIN_PATH, CB::PLUGIN_SFZ, standalone.engineOptions.pathSFZ);
  273. if (standalone.engineOptions.binaryDir != nullptr && standalone.engineOptions.binaryDir[0] != '\0')
  274. engine->setOption(CB::ENGINE_OPTION_PATH_BINARIES, 0, standalone.engineOptions.binaryDir);
  275. else
  276. engine->setOption(CB::ENGINE_OPTION_PATH_BINARIES, 0, waterBinaryDir.getFullPathName().toRawUTF8());
  277. if (standalone.engineOptions.resourceDir != nullptr && standalone.engineOptions.resourceDir[0] != '\0')
  278. engine->setOption(CB::ENGINE_OPTION_PATH_RESOURCES, 0, standalone.engineOptions.resourceDir);
  279. engine->setOption(CB::ENGINE_OPTION_PREVENT_BAD_BEHAVIOUR, standalone.engineOptions.preventBadBehaviour ? 1 : 0, nullptr);
  280. engine->setOption(CB::ENGINE_OPTION_FRONTEND_BACKGROUND_COLOR, static_cast<int>(standalone.engineOptions.bgColor), nullptr);
  281. engine->setOption(CB::ENGINE_OPTION_FRONTEND_FOREGROUND_COLOR, static_cast<int>(standalone.engineOptions.fgColor), nullptr);
  282. engine->setOption(CB::ENGINE_OPTION_FRONTEND_UI_SCALE, static_cast<int>(standalone.engineOptions.uiScale * 1000.0f), nullptr);
  283. if (standalone.engineOptions.frontendWinId != 0)
  284. {
  285. char strBuf[STR_MAX+1];
  286. strBuf[STR_MAX] = '\0';
  287. std::snprintf(strBuf, STR_MAX, P_UINTPTR, standalone.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 (standalone.engineOptions.wine.executable != nullptr && standalone.engineOptions.wine.executable[0] != '\0')
  296. engine->setOption(CB::ENGINE_OPTION_WINE_EXECUTABLE, 0, standalone.engineOptions.wine.executable);
  297. engine->setOption(CB::ENGINE_OPTION_WINE_AUTO_PREFIX, standalone.engineOptions.wine.autoPrefix ? 1 : 0, nullptr);
  298. if (standalone.engineOptions.wine.fallbackPrefix != nullptr && standalone.engineOptions.wine.fallbackPrefix[0] != '\0')
  299. engine->setOption(CB::ENGINE_OPTION_WINE_FALLBACK_PREFIX, 0, standalone.engineOptions.wine.fallbackPrefix);
  300. engine->setOption(CB::ENGINE_OPTION_WINE_RT_PRIO_ENABLED, standalone.engineOptions.wine.rtPrio ? 1 : 0, nullptr);
  301. engine->setOption(CB::ENGINE_OPTION_WINE_BASE_RT_PRIO, standalone.engineOptions.wine.baseRtPrio, nullptr);
  302. engine->setOption(CB::ENGINE_OPTION_WINE_SERVER_RT_PRIO, standalone.engineOptions.wine.serverRtPrio, nullptr);
  303. # endif
  304. engine->setOption(CB::ENGINE_OPTION_CLIENT_NAME_PREFIX, 0, standalone.engineOptions.clientNamePrefix);
  305. engine->setOption(CB::ENGINE_OPTION_PLUGINS_ARE_STANDALONE, standalone.engineOptions.pluginsAreStandalone, nullptr);
  306. #endif // BUILD_BRIDGE
  307. }
  308. bool carla_engine_init(CarlaHostHandle handle, const char* driverName, const char* clientName)
  309. {
  310. CARLA_SAFE_ASSERT_RETURN(driverName != nullptr && driverName[0] != '\0', false);
  311. CARLA_SAFE_ASSERT_RETURN(clientName != nullptr && clientName[0] != '\0', false);
  312. carla_debug("carla_engine_init(%p, \"%s\", \"%s\")", handle, driverName, clientName);
  313. CARLA_SAFE_ASSERT_WITH_LAST_ERROR_RETURN(handle->isStandalone, "Must be a standalone host handle", false);
  314. CARLA_SAFE_ASSERT_WITH_LAST_ERROR_RETURN(handle->engine == nullptr, "Engine is already initialized", false);
  315. #ifdef CARLA_OS_WIN
  316. carla_setenv("WINEASIO_CLIENT_NAME", clientName);
  317. #endif
  318. #ifdef USING_JUCE
  319. carla_standalone_juce_init();
  320. #endif
  321. CarlaHostStandalone& shandle((CarlaHostStandalone&)*handle);
  322. CarlaEngine* const engine = CarlaEngine::newDriverByName(driverName);
  323. CARLA_SAFE_ASSERT_WITH_LAST_ERROR_RETURN(engine != nullptr, "The selected audio driver is not available", false);
  324. shandle.engine = engine;
  325. #ifdef BUILD_BRIDGE
  326. if (std::getenv("CARLA_BRIDGE_DUMMY") != nullptr)
  327. {
  328. // engine->setOption(CB::ENGINE_OPTION_PROCESS_MODE, CB::ENGINE_PROCESS_MODE_PATCHBAY, nullptr);
  329. engine->setOption(CB::ENGINE_OPTION_PROCESS_MODE, CB::ENGINE_PROCESS_MODE_CONTINUOUS_RACK, nullptr);
  330. engine->setOption(CB::ENGINE_OPTION_TRANSPORT_MODE, CB::ENGINE_TRANSPORT_MODE_INTERNAL, nullptr);
  331. engine->setOption(CB::ENGINE_OPTION_AUDIO_BUFFER_SIZE, 4096, nullptr);
  332. engine->setOption(CB::ENGINE_OPTION_AUDIO_SAMPLE_RATE, 48000, nullptr);
  333. }
  334. else
  335. {
  336. engine->setOption(CB::ENGINE_OPTION_PROCESS_MODE, CB::ENGINE_PROCESS_MODE_MULTIPLE_CLIENTS, nullptr);
  337. engine->setOption(CB::ENGINE_OPTION_TRANSPORT_MODE, CB::ENGINE_TRANSPORT_MODE_JACK, nullptr);
  338. }
  339. engine->setOption(CB::ENGINE_OPTION_FORCE_STEREO, false, nullptr);
  340. engine->setOption(CB::ENGINE_OPTION_PREFER_PLUGIN_BRIDGES, false, nullptr);
  341. engine->setOption(CB::ENGINE_OPTION_PREFER_UI_BRIDGES, false, nullptr);
  342. #else
  343. engine->setOption(CB::ENGINE_OPTION_PROCESS_MODE, static_cast<int>(shandle.engineOptions.processMode), nullptr);
  344. engine->setOption(CB::ENGINE_OPTION_TRANSPORT_MODE, static_cast<int>(shandle.engineOptions.transportMode), shandle.engineOptions.transportExtra);
  345. #endif
  346. carla_engine_init_common(shandle, engine);
  347. if (engine->init(clientName))
  348. {
  349. #ifndef BUILD_BRIDGE
  350. if (shandle.logThreadEnabled && std::getenv("CARLA_LOGS_DISABLED") == nullptr)
  351. shandle.logThread.init();
  352. #endif
  353. shandle.lastError = "No error";
  354. return true;
  355. }
  356. else
  357. {
  358. shandle.lastError = engine->getLastError();
  359. shandle.engine = nullptr;
  360. delete engine;
  361. #ifdef USING_JUCE
  362. carla_standalone_juce_cleanup();
  363. #endif
  364. return false;
  365. }
  366. }
  367. #ifdef BUILD_BRIDGE
  368. bool carla_engine_init_bridge(CarlaHostHandle handle,
  369. const char audioBaseName[6+1],
  370. const char rtClientBaseName[6+1],
  371. const char nonRtClientBaseName[6+1],
  372. const char nonRtServerBaseName[6+1],
  373. const char* const clientName)
  374. {
  375. CARLA_SAFE_ASSERT_RETURN(audioBaseName != nullptr && audioBaseName[0] != '\0', false);
  376. CARLA_SAFE_ASSERT_RETURN(rtClientBaseName != nullptr && rtClientBaseName[0] != '\0', false);
  377. CARLA_SAFE_ASSERT_RETURN(nonRtClientBaseName != nullptr && nonRtClientBaseName[0] != '\0', false);
  378. CARLA_SAFE_ASSERT_RETURN(nonRtServerBaseName != nullptr && nonRtServerBaseName[0] != '\0', false);
  379. CARLA_SAFE_ASSERT_RETURN(clientName != nullptr && clientName[0] != '\0', false);
  380. carla_debug("carla_engine_init_bridge(%p, \"%s\", \"%s\", \"%s\", \"%s\", \"%s\")",
  381. handle, audioBaseName, rtClientBaseName, nonRtClientBaseName, nonRtServerBaseName, clientName);
  382. CARLA_SAFE_ASSERT_WITH_LAST_ERROR_RETURN(handle->isStandalone, "Must be a standalone host handle", false);
  383. CARLA_SAFE_ASSERT_WITH_LAST_ERROR_RETURN(handle->engine == nullptr, "Engine is already initialized", false);
  384. CarlaScopedPointer<CarlaEngine> engine(CB::EngineInit::newBridge(audioBaseName,
  385. rtClientBaseName,
  386. nonRtClientBaseName,
  387. nonRtServerBaseName));
  388. CARLA_SAFE_ASSERT_WITH_LAST_ERROR_RETURN(engine != nullptr, "The selected audio driver is not available", false);
  389. engine->setOption(CB::ENGINE_OPTION_PROCESS_MODE, CB::ENGINE_PROCESS_MODE_BRIDGE, nullptr);
  390. engine->setOption(CB::ENGINE_OPTION_TRANSPORT_MODE, CB::ENGINE_TRANSPORT_MODE_BRIDGE, nullptr);
  391. CarlaHostStandalone& shandle((CarlaHostStandalone&)*handle);
  392. carla_engine_init_common(shandle, engine);
  393. if (engine->init(clientName))
  394. {
  395. shandle.lastError = "No error";
  396. shandle.engine = engine.release();
  397. return true;
  398. }
  399. else
  400. {
  401. shandle.lastError = engine->getLastError();
  402. return false;
  403. }
  404. }
  405. #endif
  406. bool carla_engine_close(CarlaHostHandle handle)
  407. {
  408. carla_debug("carla_engine_close(%p)", handle);
  409. CARLA_SAFE_ASSERT_WITH_LAST_ERROR_RETURN(handle->isStandalone, "Must be a standalone host handle", false);
  410. CARLA_SAFE_ASSERT_WITH_LAST_ERROR_RETURN(handle->engine != nullptr, "Engine is not initialized", false);
  411. CarlaHostStandalone& shandle((CarlaHostStandalone&)*handle);
  412. CarlaEngine* const engine = shandle.engine;
  413. engine->setAboutToClose();
  414. engine->removeAllPlugins();
  415. const bool closed = engine->close();
  416. if (! closed)
  417. shandle.lastError = engine->getLastError();
  418. #ifndef BUILD_BRIDGE
  419. shandle.logThread.stop();
  420. #endif
  421. shandle.engine = nullptr;
  422. delete engine;
  423. #ifdef USING_JUCE
  424. carla_standalone_juce_cleanup();
  425. #endif
  426. return closed;
  427. }
  428. void carla_engine_idle(CarlaHostHandle handle)
  429. {
  430. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr && handle->isStandalone,);
  431. handle->engine->idle();
  432. #ifdef USING_JUCE
  433. if (handle->isStandalone)
  434. carla_standalone_juce_idle();
  435. #endif
  436. }
  437. bool carla_is_engine_running(CarlaHostHandle handle)
  438. {
  439. return (handle->engine != nullptr && handle->engine->isRunning());
  440. }
  441. const CarlaRuntimeEngineInfo* carla_get_runtime_engine_info(CarlaHostHandle handle)
  442. {
  443. static CarlaRuntimeEngineInfo retInfo;
  444. // reset
  445. retInfo.load = 0.0f;
  446. retInfo.xruns = 0;
  447. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, &retInfo);
  448. retInfo.load = handle->engine->getDSPLoad();
  449. retInfo.xruns = handle->engine->getTotalXruns();
  450. return &retInfo;
  451. }
  452. #ifndef BUILD_BRIDGE
  453. const CarlaRuntimeEngineDriverDeviceInfo* carla_get_runtime_engine_driver_device_info(CarlaHostHandle handle)
  454. {
  455. static CarlaRuntimeEngineDriverDeviceInfo retInfo;
  456. // reset
  457. retInfo.name = gNullCharPtr;
  458. retInfo.hints = 0x0;
  459. retInfo.bufferSize = 0;
  460. retInfo.bufferSizes = nullptr;
  461. retInfo.sampleRate = 0.0;
  462. retInfo.sampleRates = nullptr;
  463. const char* audioDriver;
  464. const char* audioDevice;
  465. if (CarlaEngine* const engine = handle->engine)
  466. {
  467. audioDriver = engine->getCurrentDriverName();
  468. audioDevice = engine->getOptions().audioDevice;
  469. retInfo.bufferSize = engine->getBufferSize();
  470. retInfo.sampleRate = engine->getSampleRate();
  471. }
  472. else if (handle->isStandalone)
  473. {
  474. CarlaHostStandalone& shandle((CarlaHostStandalone&)*handle);
  475. audioDriver = shandle.engineOptions.audioDriver;
  476. audioDevice = shandle.engineOptions.audioDevice;
  477. retInfo.bufferSize = shandle.engineOptions.audioBufferSize;
  478. retInfo.sampleRate = shandle.engineOptions.audioSampleRate;
  479. }
  480. else
  481. {
  482. return &retInfo;
  483. }
  484. CARLA_SAFE_ASSERT_RETURN(audioDriver != nullptr, &retInfo);
  485. CARLA_SAFE_ASSERT_RETURN(audioDevice != nullptr, &retInfo);
  486. uint index = 0;
  487. uint count = CarlaEngine::getDriverCount();
  488. for (; index<count; ++index)
  489. {
  490. const char* const testDriverName = CarlaEngine::getDriverName(index);
  491. CARLA_SAFE_ASSERT_CONTINUE(testDriverName != nullptr);
  492. if (std::strcmp(testDriverName, audioDriver) == 0)
  493. break;
  494. }
  495. CARLA_SAFE_ASSERT_RETURN(index != count, &retInfo);
  496. const EngineDriverDeviceInfo* const devInfo = CarlaEngine::getDriverDeviceInfo(index, audioDevice);
  497. CARLA_SAFE_ASSERT_RETURN(devInfo != nullptr, &retInfo);
  498. retInfo.name = audioDevice;
  499. retInfo.hints = devInfo->hints;
  500. retInfo.bufferSizes = devInfo->bufferSizes;
  501. retInfo.sampleRates = devInfo->sampleRates;
  502. return &retInfo;
  503. }
  504. bool carla_set_engine_buffer_size_and_sample_rate(CarlaHostHandle handle, uint bufferSize, double sampleRate)
  505. {
  506. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, false);
  507. carla_debug("carla_set_engine_buffer_size_and_sample_rate(%p, %u, %f)", handle, bufferSize, sampleRate);
  508. return handle->engine->setBufferSizeAndSampleRate(bufferSize, sampleRate);
  509. }
  510. bool carla_show_engine_device_control_panel(CarlaHostHandle handle)
  511. {
  512. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, false);
  513. carla_debug("carla_show_engine_device_control_panel(%p)", handle);
  514. return handle->engine->showDeviceControlPanel();
  515. }
  516. #endif // BUILD_BRIDGE
  517. void carla_clear_engine_xruns(CarlaHostHandle handle)
  518. {
  519. if (handle->engine != nullptr)
  520. handle->engine->clearXruns();
  521. }
  522. void carla_cancel_engine_action(CarlaHostHandle handle)
  523. {
  524. if (handle->engine != nullptr)
  525. handle->engine->setActionCanceled(true);
  526. }
  527. bool carla_set_engine_about_to_close(CarlaHostHandle handle)
  528. {
  529. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, true);
  530. carla_debug("carla_set_engine_about_to_close(%p)", handle);
  531. return handle->engine->setAboutToClose();
  532. }
  533. void carla_set_engine_callback(CarlaHostHandle handle, EngineCallbackFunc func, void* ptr)
  534. {
  535. carla_debug("carla_set_engine_callback(%p, %p, %p)", handle, func, ptr);
  536. if (handle->isStandalone)
  537. {
  538. CarlaHostStandalone& shandle((CarlaHostStandalone&)*handle);
  539. shandle.engineCallback = func;
  540. shandle.engineCallbackPtr = ptr;
  541. #ifndef BUILD_BRIDGE
  542. shandle.logThread.setCallback(func, ptr);
  543. #endif
  544. }
  545. if (handle->engine != nullptr)
  546. handle->engine->setCallback(func, ptr);
  547. }
  548. void carla_set_engine_option(CarlaHostHandle handle, EngineOption option, int value, const char* valueStr)
  549. {
  550. carla_debug("carla_set_engine_option(%p, %i:%s, %i, \"%s\")",
  551. handle, option, CB::EngineOption2Str(option), value, valueStr);
  552. if (handle->isStandalone)
  553. {
  554. CarlaHostStandalone& shandle((CarlaHostStandalone&)*handle);
  555. switch (option)
  556. {
  557. case CB::ENGINE_OPTION_DEBUG:
  558. break;
  559. case CB::ENGINE_OPTION_PROCESS_MODE:
  560. CARLA_SAFE_ASSERT_RETURN(value >= CB::ENGINE_PROCESS_MODE_SINGLE_CLIENT && value < CB::ENGINE_PROCESS_MODE_BRIDGE,);
  561. shandle.engineOptions.processMode = static_cast<CB::EngineProcessMode>(value);
  562. break;
  563. case CB::ENGINE_OPTION_TRANSPORT_MODE:
  564. CARLA_SAFE_ASSERT_RETURN(value >= CB::ENGINE_TRANSPORT_MODE_DISABLED && value <= CB::ENGINE_TRANSPORT_MODE_BRIDGE,);
  565. // jack transport cannot be disabled in multi-client
  566. if (shandle.engineOptions.processMode == CB::ENGINE_PROCESS_MODE_MULTIPLE_CLIENTS
  567. && value != CB::ENGINE_TRANSPORT_MODE_JACK)
  568. {
  569. shandle.engineOptions.transportMode = CB::ENGINE_TRANSPORT_MODE_JACK;
  570. if (shandle.engineCallback != nullptr)
  571. shandle.engineCallback(shandle.engineCallbackPtr,
  572. CB::ENGINE_CALLBACK_TRANSPORT_MODE_CHANGED,
  573. 0,
  574. CB::ENGINE_TRANSPORT_MODE_JACK,
  575. 0, 0, 0.0f,
  576. shandle.engineOptions.transportExtra);
  577. }
  578. else
  579. {
  580. shandle.engineOptions.transportMode = static_cast<CB::EngineTransportMode>(value);
  581. }
  582. delete[] shandle.engineOptions.transportExtra;
  583. if (value != CB::ENGINE_TRANSPORT_MODE_DISABLED && valueStr != nullptr)
  584. shandle.engineOptions.transportExtra = carla_strdup_safe(valueStr);
  585. else
  586. shandle.engineOptions.transportExtra = nullptr;
  587. break;
  588. case CB::ENGINE_OPTION_FORCE_STEREO:
  589. CARLA_SAFE_ASSERT_RETURN(value == 0 || value == 1,);
  590. shandle.engineOptions.forceStereo = (value != 0);
  591. break;
  592. case CB::ENGINE_OPTION_PREFER_PLUGIN_BRIDGES:
  593. CARLA_SAFE_ASSERT_RETURN(value == 0 || value == 1,);
  594. shandle.engineOptions.preferPluginBridges = (value != 0);
  595. break;
  596. case CB::ENGINE_OPTION_PREFER_UI_BRIDGES:
  597. CARLA_SAFE_ASSERT_RETURN(value == 0 || value == 1,);
  598. shandle.engineOptions.preferUiBridges = (value != 0);
  599. break;
  600. case CB::ENGINE_OPTION_UIS_ALWAYS_ON_TOP:
  601. CARLA_SAFE_ASSERT_RETURN(value == 0 || value == 1,);
  602. shandle.engineOptions.uisAlwaysOnTop = (value != 0);
  603. break;
  604. case CB::ENGINE_OPTION_MAX_PARAMETERS:
  605. CARLA_SAFE_ASSERT_RETURN(value >= 0,);
  606. shandle.engineOptions.maxParameters = static_cast<uint>(value);
  607. break;
  608. case CB::ENGINE_OPTION_RESET_XRUNS:
  609. CARLA_SAFE_ASSERT_RETURN(value == 0 || value == 1,);
  610. shandle.engineOptions.resetXruns = (value != 0);
  611. break;
  612. case CB::ENGINE_OPTION_UI_BRIDGES_TIMEOUT:
  613. CARLA_SAFE_ASSERT_RETURN(value >= 0,);
  614. shandle.engineOptions.uiBridgesTimeout = static_cast<uint>(value);
  615. break;
  616. case CB::ENGINE_OPTION_AUDIO_BUFFER_SIZE:
  617. CARLA_SAFE_ASSERT_RETURN(value >= 8,);
  618. shandle.engineOptions.audioBufferSize = static_cast<uint>(value);
  619. break;
  620. case CB::ENGINE_OPTION_AUDIO_SAMPLE_RATE:
  621. CARLA_SAFE_ASSERT_RETURN(value >= 22050,);
  622. shandle.engineOptions.audioSampleRate = static_cast<uint>(value);
  623. break;
  624. case CB::ENGINE_OPTION_AUDIO_TRIPLE_BUFFER:
  625. CARLA_SAFE_ASSERT_RETURN(value == 0 || value == 1,);
  626. shandle.engineOptions.audioTripleBuffer = (value != 0);
  627. break;
  628. case CB::ENGINE_OPTION_AUDIO_DRIVER:
  629. CARLA_SAFE_ASSERT_RETURN(valueStr != nullptr,);
  630. if (shandle.engineOptions.audioDriver != nullptr)
  631. delete[] shandle.engineOptions.audioDriver;
  632. shandle.engineOptions.audioDriver = carla_strdup_safe(valueStr);
  633. break;
  634. case CB::ENGINE_OPTION_AUDIO_DEVICE:
  635. CARLA_SAFE_ASSERT_RETURN(valueStr != nullptr,);
  636. if (shandle.engineOptions.audioDevice != nullptr)
  637. delete[] shandle.engineOptions.audioDevice;
  638. shandle.engineOptions.audioDevice = carla_strdup_safe(valueStr);
  639. break;
  640. #ifndef BUILD_BRIDGE
  641. case CB::ENGINE_OPTION_OSC_ENABLED:
  642. CARLA_SAFE_ASSERT_RETURN(value == 0 || value == 1,);
  643. shandle.engineOptions.oscEnabled = (value != 0);
  644. break;
  645. case CB::ENGINE_OPTION_OSC_PORT_TCP:
  646. CARLA_SAFE_ASSERT_RETURN(value <= 0 || value >= 1024,);
  647. shandle.engineOptions.oscPortTCP = value;
  648. break;
  649. case CB::ENGINE_OPTION_OSC_PORT_UDP:
  650. CARLA_SAFE_ASSERT_RETURN(value <= 0 || value >= 1024,);
  651. shandle.engineOptions.oscPortUDP = value;
  652. break;
  653. #endif
  654. case CB::ENGINE_OPTION_FILE_PATH:
  655. CARLA_SAFE_ASSERT_RETURN(value > CB::FILE_NONE,);
  656. CARLA_SAFE_ASSERT_RETURN(value <= CB::FILE_MIDI,);
  657. CARLA_SAFE_ASSERT_RETURN(valueStr != nullptr,);
  658. switch (value)
  659. {
  660. case CB::FILE_AUDIO:
  661. if (shandle.engineOptions.pathAudio != nullptr)
  662. delete[] shandle.engineOptions.pathAudio;
  663. shandle.engineOptions.pathAudio = carla_strdup_safe(valueStr);
  664. break;
  665. case CB::FILE_MIDI:
  666. if (shandle.engineOptions.pathMIDI != nullptr)
  667. delete[] shandle.engineOptions.pathMIDI;
  668. shandle.engineOptions.pathMIDI = carla_strdup_safe(valueStr);
  669. break;
  670. }
  671. break;
  672. case CB::ENGINE_OPTION_PLUGIN_PATH:
  673. CARLA_SAFE_ASSERT_RETURN(value > CB::PLUGIN_NONE,);
  674. CARLA_SAFE_ASSERT_RETURN(value <= CB::PLUGIN_SFZ,);
  675. CARLA_SAFE_ASSERT_RETURN(valueStr != nullptr,);
  676. switch (value)
  677. {
  678. case CB::PLUGIN_LADSPA:
  679. if (shandle.engineOptions.pathLADSPA != nullptr)
  680. delete[] shandle.engineOptions.pathLADSPA;
  681. shandle.engineOptions.pathLADSPA = carla_strdup_safe(valueStr);
  682. break;
  683. case CB::PLUGIN_DSSI:
  684. if (shandle.engineOptions.pathDSSI != nullptr)
  685. delete[] shandle.engineOptions.pathDSSI;
  686. shandle.engineOptions.pathDSSI = carla_strdup_safe(valueStr);
  687. break;
  688. case CB::PLUGIN_LV2:
  689. if (shandle.engineOptions.pathLV2 != nullptr)
  690. delete[] shandle.engineOptions.pathLV2;
  691. shandle.engineOptions.pathLV2 = carla_strdup_safe(valueStr);
  692. break;
  693. case CB::PLUGIN_VST2:
  694. if (shandle.engineOptions.pathVST2 != nullptr)
  695. delete[] shandle.engineOptions.pathVST2;
  696. shandle.engineOptions.pathVST2 = carla_strdup_safe(valueStr);
  697. break;
  698. case CB::PLUGIN_VST3:
  699. if (shandle.engineOptions.pathVST3 != nullptr)
  700. delete[] shandle.engineOptions.pathVST3;
  701. shandle.engineOptions.pathVST3 = carla_strdup_safe(valueStr);
  702. break;
  703. case CB::PLUGIN_SF2:
  704. if (shandle.engineOptions.pathSF2 != nullptr)
  705. delete[] shandle.engineOptions.pathSF2;
  706. shandle.engineOptions.pathSF2 = carla_strdup_safe(valueStr);
  707. break;
  708. case CB::PLUGIN_SFZ:
  709. if (shandle.engineOptions.pathSFZ != nullptr)
  710. delete[] shandle.engineOptions.pathSFZ;
  711. shandle.engineOptions.pathSFZ = carla_strdup_safe(valueStr);
  712. break;
  713. }
  714. break;
  715. case CB::ENGINE_OPTION_PATH_BINARIES:
  716. CARLA_SAFE_ASSERT_RETURN(valueStr != nullptr && valueStr[0] != '\0',);
  717. if (shandle.engineOptions.binaryDir != nullptr)
  718. delete[] shandle.engineOptions.binaryDir;
  719. shandle.engineOptions.binaryDir = carla_strdup_safe(valueStr);
  720. break;
  721. case CB::ENGINE_OPTION_PATH_RESOURCES:
  722. CARLA_SAFE_ASSERT_RETURN(valueStr != nullptr && valueStr[0] != '\0',);
  723. if (shandle.engineOptions.resourceDir != nullptr)
  724. delete[] shandle.engineOptions.resourceDir;
  725. shandle.engineOptions.resourceDir = carla_strdup_safe(valueStr);
  726. break;
  727. case CB::ENGINE_OPTION_PREVENT_BAD_BEHAVIOUR:
  728. CARLA_SAFE_ASSERT_RETURN(value == 0 || value == 1,);
  729. shandle.engineOptions.preventBadBehaviour = (value != 0);
  730. break;
  731. case CB::ENGINE_OPTION_FRONTEND_BACKGROUND_COLOR:
  732. shandle.engineOptions.bgColor = static_cast<uint>(value);
  733. break;
  734. case CB::ENGINE_OPTION_FRONTEND_FOREGROUND_COLOR:
  735. shandle.engineOptions.fgColor = static_cast<uint>(value);
  736. break;
  737. case CB::ENGINE_OPTION_FRONTEND_UI_SCALE:
  738. CARLA_SAFE_ASSERT_RETURN(value > 0,);
  739. shandle.engineOptions.uiScale = static_cast<float>(value) / 1000;
  740. break;
  741. case CB::ENGINE_OPTION_FRONTEND_WIN_ID: {
  742. CARLA_SAFE_ASSERT_RETURN(valueStr != nullptr && valueStr[0] != '\0',);
  743. const long long winId(std::strtoll(valueStr, nullptr, 16));
  744. CARLA_SAFE_ASSERT_RETURN(winId >= 0,);
  745. shandle.engineOptions.frontendWinId = static_cast<uintptr_t>(winId);
  746. } break;
  747. #if !defined(BUILD_BRIDGE_ALTERNATIVE_ARCH) && !defined(CARLA_OS_WIN)
  748. case CB::ENGINE_OPTION_WINE_EXECUTABLE:
  749. CARLA_SAFE_ASSERT_RETURN(valueStr != nullptr && valueStr[0] != '\0',);
  750. if (shandle.engineOptions.wine.executable != nullptr)
  751. delete[] shandle.engineOptions.wine.executable;
  752. shandle.engineOptions.wine.executable = carla_strdup_safe(valueStr);
  753. break;
  754. case CB::ENGINE_OPTION_WINE_AUTO_PREFIX:
  755. CARLA_SAFE_ASSERT_RETURN(value == 0 || value == 1,);
  756. shandle.engineOptions.wine.autoPrefix = (value != 0);
  757. break;
  758. case CB::ENGINE_OPTION_WINE_FALLBACK_PREFIX:
  759. CARLA_SAFE_ASSERT_RETURN(valueStr != nullptr && valueStr[0] != '\0',);
  760. if (shandle.engineOptions.wine.fallbackPrefix != nullptr)
  761. delete[] shandle.engineOptions.wine.fallbackPrefix;
  762. shandle.engineOptions.wine.fallbackPrefix = carla_strdup_safe(valueStr);
  763. break;
  764. case CB::ENGINE_OPTION_WINE_RT_PRIO_ENABLED:
  765. CARLA_SAFE_ASSERT_RETURN(value == 0 || value == 1,);
  766. shandle.engineOptions.wine.rtPrio = (value != 0);
  767. break;
  768. case CB::ENGINE_OPTION_WINE_BASE_RT_PRIO:
  769. CARLA_SAFE_ASSERT_RETURN(value >= 1 && value <= 89,);
  770. shandle.engineOptions.wine.baseRtPrio = value;
  771. break;
  772. case CB::ENGINE_OPTION_WINE_SERVER_RT_PRIO:
  773. CARLA_SAFE_ASSERT_RETURN(value >= 1 && value <= 99,);
  774. shandle.engineOptions.wine.serverRtPrio = value;
  775. break;
  776. #endif
  777. #ifndef BUILD_BRIDGE
  778. case CB::ENGINE_OPTION_DEBUG_CONSOLE_OUTPUT:
  779. shandle.logThreadEnabled = (value != 0);
  780. break;
  781. #endif
  782. case CB::ENGINE_OPTION_CLIENT_NAME_PREFIX:
  783. if (shandle.engineOptions.clientNamePrefix != nullptr)
  784. delete[] shandle.engineOptions.clientNamePrefix;
  785. shandle.engineOptions.clientNamePrefix = valueStr != nullptr && valueStr[0] != '\0'
  786. ? carla_strdup_safe(valueStr)
  787. : nullptr;
  788. break;
  789. case CB::ENGINE_OPTION_PLUGINS_ARE_STANDALONE:
  790. CARLA_SAFE_ASSERT_RETURN(value == 0 || value == 1,);
  791. shandle.engineOptions.pluginsAreStandalone = (value != 0);
  792. break;
  793. }
  794. }
  795. if (handle->engine != nullptr)
  796. handle->engine->setOption(option, value, valueStr);
  797. }
  798. void carla_set_file_callback(CarlaHostHandle handle, FileCallbackFunc func, void* ptr)
  799. {
  800. carla_debug("carla_set_file_callback(%p, %p, %p)", handle, func, ptr);
  801. if (handle->isStandalone)
  802. {
  803. CarlaHostStandalone& shandle((CarlaHostStandalone&)*handle);
  804. shandle.fileCallback = func;
  805. shandle.fileCallbackPtr = ptr;
  806. }
  807. if (handle->engine != nullptr)
  808. handle->engine->setFileCallback(func, ptr);
  809. }
  810. // --------------------------------------------------------------------------------------------------------------------
  811. bool carla_load_file(CarlaHostHandle handle, const char* filename)
  812. {
  813. CARLA_SAFE_ASSERT_RETURN(filename != nullptr && filename[0] != '\0', false);
  814. CARLA_SAFE_ASSERT_WITH_LAST_ERROR_RETURN(handle->engine != nullptr, "Engine is not initialized", false);
  815. carla_debug("carla_load_file(%p, \"%s\")", handle, filename);
  816. return handle->engine->loadFile(filename);
  817. }
  818. bool carla_load_project(CarlaHostHandle handle, const char* filename)
  819. {
  820. CARLA_SAFE_ASSERT_RETURN(filename != nullptr && filename[0] != '\0', false);
  821. CARLA_SAFE_ASSERT_WITH_LAST_ERROR_RETURN(handle->engine != nullptr, "Engine is not initialized", false);
  822. carla_debug("carla_load_project(%p, \"%s\")", handle, filename);
  823. return handle->engine->loadProject(filename, true);
  824. }
  825. bool carla_save_project(CarlaHostHandle handle, const char* filename)
  826. {
  827. CARLA_SAFE_ASSERT_RETURN(filename != nullptr && filename[0] != '\0', false);
  828. CARLA_SAFE_ASSERT_WITH_LAST_ERROR_RETURN(handle->engine != nullptr, "Engine is not initialized", false);
  829. carla_debug("carla_save_project(%p, \"%s\")", handle, filename);
  830. return handle->engine->saveProject(filename, true);
  831. }
  832. #ifndef BUILD_BRIDGE
  833. const char* carla_get_current_project_folder(CarlaHostHandle handle)
  834. {
  835. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, gNullCharPtr);
  836. carla_debug("carla_get_current_project_folder(%p)", handle);
  837. if (const char* const ret = handle->engine->getCurrentProjectFolder())
  838. return ret;
  839. return gNullCharPtr;
  840. }
  841. const char* carla_get_current_project_filename(CarlaHostHandle handle)
  842. {
  843. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr && handle->isStandalone, gNullCharPtr);
  844. carla_debug("carla_get_current_project_filename(%p)", handle);
  845. if (const char* const ret = handle->engine->getCurrentProjectFilename())
  846. return ret;
  847. return gNullCharPtr;
  848. }
  849. void carla_clear_project_filename(CarlaHostHandle handle)
  850. {
  851. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr,);
  852. carla_debug("carla_clear_project_filename(%p)", handle);
  853. handle->engine->clearCurrentProjectFilename();
  854. }
  855. // --------------------------------------------------------------------------------------------------------------------
  856. bool carla_patchbay_connect(CarlaHostHandle handle, bool external, uint groupIdA, uint portIdA, uint groupIdB, uint portIdB)
  857. {
  858. CARLA_SAFE_ASSERT_WITH_LAST_ERROR_RETURN(handle->engine != nullptr, "Engine is not initialized", false);
  859. carla_debug("carla_patchbay_connect(%p, %s, %u, %u, %u, %u)",
  860. handle, bool2str(external), groupIdA, portIdA, groupIdB, portIdB);
  861. return handle->engine->patchbayConnect(external, groupIdA, portIdA, groupIdB, portIdB);
  862. }
  863. bool carla_patchbay_disconnect(CarlaHostHandle handle, bool external, uint connectionId)
  864. {
  865. CARLA_SAFE_ASSERT_WITH_LAST_ERROR_RETURN(handle->engine != nullptr, "Engine is not initialized", false);
  866. carla_debug("carla_patchbay_disconnect(%p, %s, %i)", handle, bool2str(external), connectionId);
  867. return handle->engine->patchbayDisconnect(external, connectionId);
  868. }
  869. bool carla_patchbay_set_group_pos(CarlaHostHandle handle, bool external, uint groupId, int x1, int y1, int x2, int y2)
  870. {
  871. CARLA_SAFE_ASSERT_WITH_LAST_ERROR_RETURN(handle->engine != nullptr && handle->engine->isRunning(),
  872. "Engine is not running", false);
  873. carla_debug("carla_patchbay_set_group_pos(%p, %s, %u, %i, %i, %i, %i)",
  874. handle, bool2str(external), groupId, x1, y1, x2, y2);
  875. if (handle->engine->isAboutToClose())
  876. return true;
  877. return handle->engine->patchbaySetGroupPos(false, true, external, groupId, x1, y1, x2, y2);
  878. }
  879. bool carla_patchbay_refresh(CarlaHostHandle handle, bool external)
  880. {
  881. CARLA_SAFE_ASSERT_WITH_LAST_ERROR_RETURN(handle->engine != nullptr, "Engine is not initialized", false);
  882. carla_debug("carla_patchbay_refresh(%p, %s)", handle, bool2str(external));
  883. return handle->engine->patchbayRefresh(true, false, external);
  884. }
  885. // --------------------------------------------------------------------------------------------------------------------
  886. void carla_transport_play(CarlaHostHandle handle)
  887. {
  888. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr && handle->engine->isRunning(),);
  889. carla_debug("carla_transport_play(%p)", handle);
  890. handle->engine->transportPlay();
  891. }
  892. void carla_transport_pause(CarlaHostHandle handle)
  893. {
  894. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr && handle->engine->isRunning(),);
  895. carla_debug("carla_transport_pause(%p)", handle);
  896. handle->engine->transportPause();
  897. }
  898. void carla_transport_bpm(CarlaHostHandle handle, double bpm)
  899. {
  900. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr && handle->engine->isRunning(),);
  901. carla_debug("carla_transport_bpm(%p, %f)", handle, bpm);
  902. handle->engine->transportBPM(bpm);
  903. }
  904. void carla_transport_relocate(CarlaHostHandle handle, uint64_t frame)
  905. {
  906. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr && handle->engine->isRunning(),);
  907. carla_debug("carla_transport_relocate(%p, %i)", handle, frame);
  908. handle->engine->transportRelocate(frame);
  909. }
  910. uint64_t carla_get_current_transport_frame(CarlaHostHandle handle)
  911. {
  912. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr && handle->engine->isRunning(), 0);
  913. return handle->engine->getTimeInfo().frame;
  914. }
  915. const CarlaTransportInfo* carla_get_transport_info(CarlaHostHandle handle)
  916. {
  917. static CarlaTransportInfo retTransInfo;
  918. retTransInfo.clear();
  919. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr && handle->engine->isRunning(), &retTransInfo);
  920. const CB::EngineTimeInfo& timeInfo(handle->engine->getTimeInfo());
  921. retTransInfo.playing = timeInfo.playing;
  922. retTransInfo.frame = timeInfo.frame;
  923. if (timeInfo.bbt.valid)
  924. {
  925. retTransInfo.bar = timeInfo.bbt.bar;
  926. retTransInfo.beat = timeInfo.bbt.beat;
  927. retTransInfo.tick = static_cast<int32_t>(timeInfo.bbt.tick + 0.5);
  928. retTransInfo.bpm = timeInfo.bbt.beatsPerMinute;
  929. }
  930. return &retTransInfo;
  931. }
  932. #endif
  933. // --------------------------------------------------------------------------------------------------------------------
  934. uint32_t carla_get_current_plugin_count(CarlaHostHandle handle)
  935. {
  936. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, 0);
  937. carla_debug("carla_get_current_plugin_count(%p)", handle);
  938. return handle->engine->getCurrentPluginCount();
  939. }
  940. uint32_t carla_get_max_plugin_number(CarlaHostHandle handle)
  941. {
  942. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, 0);
  943. carla_debug("carla_get_max_plugin_number(%p)", handle);
  944. return handle->engine->getMaxPluginNumber();
  945. }
  946. // --------------------------------------------------------------------------------------------------------------------
  947. bool carla_add_plugin(CarlaHostHandle handle,
  948. BinaryType btype, PluginType ptype,
  949. const char* filename, const char* name, const char* label, int64_t uniqueId,
  950. const void* extraPtr, uint options)
  951. {
  952. CARLA_SAFE_ASSERT_WITH_LAST_ERROR_RETURN(handle->engine != nullptr, "Engine is not initialized", false);
  953. carla_debug("carla_add_plugin(%p, %i:%s, %i:%s, \"%s\", \"%s\", \"%s\", " P_INT64 ", %p, %u)",
  954. handle,
  955. btype, CB::BinaryType2Str(btype),
  956. ptype, CB::PluginType2Str(ptype),
  957. filename, name, label, uniqueId, extraPtr, options);
  958. return handle->engine->addPlugin(btype, ptype, filename, name, label, uniqueId, extraPtr, options);
  959. }
  960. bool carla_remove_plugin(CarlaHostHandle handle, uint pluginId)
  961. {
  962. CARLA_SAFE_ASSERT_WITH_LAST_ERROR_RETURN(handle->engine != nullptr, "Engine is not initialized", false);
  963. carla_debug("carla_remove_plugin(%p, %i)", handle, pluginId);
  964. return handle->engine->removePlugin(pluginId);
  965. }
  966. bool carla_remove_all_plugins(CarlaHostHandle handle)
  967. {
  968. CARLA_SAFE_ASSERT_WITH_LAST_ERROR_RETURN(handle->engine != nullptr, "Engine is not initialized", false);
  969. carla_debug("carla_remove_all_plugins(%p)", handle);
  970. return handle->engine->removeAllPlugins();
  971. }
  972. #ifndef BUILD_BRIDGE
  973. bool carla_rename_plugin(CarlaHostHandle handle, uint pluginId, const char* newName)
  974. {
  975. CARLA_SAFE_ASSERT_RETURN(newName != nullptr && newName[0] != '\0', false);
  976. CARLA_SAFE_ASSERT_WITH_LAST_ERROR_RETURN(handle->engine != nullptr, "Engine is not initialized", false);
  977. carla_debug("carla_rename_plugin(%p, %i, \"%s\")", handle, pluginId, newName);
  978. return handle->engine->renamePlugin(pluginId, newName);
  979. }
  980. bool carla_clone_plugin(CarlaHostHandle handle, uint pluginId)
  981. {
  982. CARLA_SAFE_ASSERT_WITH_LAST_ERROR_RETURN(handle->engine != nullptr, "Engine is not initialized", false);
  983. carla_debug("carla_clone_plugin(%p, %i)", handle, pluginId);
  984. return handle->engine->clonePlugin(pluginId);
  985. }
  986. bool carla_replace_plugin(CarlaHostHandle handle, uint pluginId)
  987. {
  988. CARLA_SAFE_ASSERT_WITH_LAST_ERROR_RETURN(handle->engine != nullptr, "Engine is not initialized", false);
  989. carla_debug("carla_replace_plugin(%p, %i)", handle, pluginId);
  990. return handle->engine->replacePlugin(pluginId);
  991. }
  992. bool carla_switch_plugins(CarlaHostHandle handle, uint pluginIdA, uint pluginIdB)
  993. {
  994. CARLA_SAFE_ASSERT_RETURN(pluginIdA != pluginIdB, false);
  995. CARLA_SAFE_ASSERT_WITH_LAST_ERROR_RETURN(handle->engine != nullptr, "Engine is not initialized", false);
  996. carla_debug("carla_switch_plugins(%p, %i, %i)", handle, pluginIdA, pluginIdB);
  997. return handle->engine->switchPlugins(pluginIdA, pluginIdB);
  998. }
  999. #endif
  1000. // --------------------------------------------------------------------------------------------------------------------
  1001. bool carla_load_plugin_state(CarlaHostHandle handle, uint pluginId, const char* filename)
  1002. {
  1003. CARLA_SAFE_ASSERT_RETURN(filename != nullptr && filename[0] != '\0', false);
  1004. CARLA_SAFE_ASSERT_WITH_LAST_ERROR_RETURN(handle->engine != nullptr
  1005. && handle->engine->isRunning(), "Engine is not running", false);
  1006. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1007. return plugin->loadStateFromFile(filename);
  1008. return false;
  1009. }
  1010. bool carla_save_plugin_state(CarlaHostHandle handle, uint pluginId, const char* filename)
  1011. {
  1012. CARLA_SAFE_ASSERT_RETURN(filename != nullptr && filename[0] != '\0', false);
  1013. CARLA_SAFE_ASSERT_WITH_LAST_ERROR_RETURN(handle->engine != nullptr, "Engine is not initialized", false);
  1014. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1015. return plugin->saveStateToFile(filename);
  1016. return false;
  1017. }
  1018. bool carla_export_plugin_lv2(CarlaHostHandle handle, uint pluginId, const char* lv2path)
  1019. {
  1020. CARLA_SAFE_ASSERT_RETURN(lv2path != nullptr && lv2path[0] != '\0', false);
  1021. CARLA_SAFE_ASSERT_WITH_LAST_ERROR_RETURN(handle->engine != nullptr, "Engine is not initialized", false);
  1022. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1023. return plugin->exportAsLV2(lv2path);
  1024. return false;
  1025. }
  1026. // --------------------------------------------------------------------------------------------------------------------
  1027. const CarlaPluginInfo* carla_get_plugin_info(CarlaHostHandle handle, uint pluginId)
  1028. {
  1029. static CarlaPluginInfo retInfo;
  1030. // reset
  1031. retInfo.type = CB::PLUGIN_NONE;
  1032. retInfo.category = CB::PLUGIN_CATEGORY_NONE;
  1033. retInfo.hints = 0x0;
  1034. retInfo.optionsAvailable = 0x0;
  1035. retInfo.optionsEnabled = 0x0;
  1036. retInfo.filename = gNullCharPtr;
  1037. retInfo.name = gNullCharPtr;
  1038. retInfo.iconName = gNullCharPtr;
  1039. retInfo.uniqueId = 0;
  1040. // cleanup
  1041. if (retInfo.label != gNullCharPtr)
  1042. {
  1043. delete[] retInfo.label;
  1044. retInfo.label = gNullCharPtr;
  1045. }
  1046. if (retInfo.maker != gNullCharPtr)
  1047. {
  1048. delete[] retInfo.maker;
  1049. retInfo.maker = gNullCharPtr;
  1050. }
  1051. if (retInfo.copyright != gNullCharPtr)
  1052. {
  1053. delete[] retInfo.copyright;
  1054. retInfo.copyright = gNullCharPtr;
  1055. }
  1056. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, &retInfo);
  1057. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1058. {
  1059. char strBuf[STR_MAX+1];
  1060. carla_zeroChars(strBuf, STR_MAX+1);
  1061. retInfo.type = plugin->getType();
  1062. retInfo.category = plugin->getCategory();
  1063. retInfo.hints = plugin->getHints();
  1064. retInfo.filename = plugin->getFilename();
  1065. retInfo.name = plugin->getName();
  1066. retInfo.iconName = plugin->getIconName();
  1067. retInfo.uniqueId = plugin->getUniqueId();
  1068. retInfo.optionsAvailable = plugin->getOptionsAvailable();
  1069. retInfo.optionsEnabled = plugin->getOptionsEnabled();
  1070. if (plugin->getLabel(strBuf))
  1071. retInfo.label = carla_strdup_safe(strBuf);
  1072. if (plugin->getMaker(strBuf))
  1073. retInfo.maker = carla_strdup_safe(strBuf);
  1074. if (plugin->getCopyright(strBuf))
  1075. retInfo.copyright = carla_strdup_safe(strBuf);
  1076. checkStringPtr(retInfo.filename);
  1077. checkStringPtr(retInfo.name);
  1078. checkStringPtr(retInfo.iconName);
  1079. checkStringPtr(retInfo.label);
  1080. checkStringPtr(retInfo.maker);
  1081. checkStringPtr(retInfo.copyright);
  1082. }
  1083. return &retInfo;
  1084. }
  1085. const CarlaPortCountInfo* carla_get_audio_port_count_info(CarlaHostHandle handle, uint pluginId)
  1086. {
  1087. static CarlaPortCountInfo retInfo;
  1088. carla_zeroStruct(retInfo);
  1089. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, &retInfo);
  1090. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1091. {
  1092. retInfo.ins = plugin->getAudioInCount();
  1093. retInfo.outs = plugin->getAudioOutCount();
  1094. }
  1095. return &retInfo;
  1096. }
  1097. const CarlaPortCountInfo* carla_get_midi_port_count_info(CarlaHostHandle handle, uint pluginId)
  1098. {
  1099. static CarlaPortCountInfo retInfo;
  1100. carla_zeroStruct(retInfo);
  1101. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, &retInfo);
  1102. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1103. {
  1104. retInfo.ins = plugin->getMidiInCount();
  1105. retInfo.outs = plugin->getMidiOutCount();
  1106. }
  1107. return &retInfo;
  1108. }
  1109. const CarlaPortCountInfo* carla_get_parameter_count_info(CarlaHostHandle handle, uint pluginId)
  1110. {
  1111. static CarlaPortCountInfo retInfo;
  1112. carla_zeroStruct(retInfo);
  1113. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, &retInfo);
  1114. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1115. plugin->getParameterCountInfo(retInfo.ins, retInfo.outs);
  1116. return &retInfo;
  1117. }
  1118. const CarlaParameterInfo* carla_get_parameter_info(CarlaHostHandle handle, uint pluginId, uint32_t parameterId)
  1119. {
  1120. static CarlaParameterInfo retInfo;
  1121. // reset
  1122. retInfo.scalePointCount = 0;
  1123. // cleanup
  1124. if (retInfo.name != gNullCharPtr)
  1125. {
  1126. delete[] retInfo.name;
  1127. retInfo.name = gNullCharPtr;
  1128. }
  1129. if (retInfo.symbol != gNullCharPtr)
  1130. {
  1131. delete[] retInfo.symbol;
  1132. retInfo.symbol = gNullCharPtr;
  1133. }
  1134. if (retInfo.unit != gNullCharPtr)
  1135. {
  1136. delete[] retInfo.unit;
  1137. retInfo.unit = gNullCharPtr;
  1138. }
  1139. if (retInfo.comment != gNullCharPtr)
  1140. {
  1141. delete[] retInfo.comment;
  1142. retInfo.comment = gNullCharPtr;
  1143. }
  1144. if (retInfo.groupName != gNullCharPtr)
  1145. {
  1146. delete[] retInfo.groupName;
  1147. retInfo.groupName = gNullCharPtr;
  1148. }
  1149. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, &retInfo);
  1150. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1151. {
  1152. char strBuf[STR_MAX+1];
  1153. carla_zeroChars(strBuf, STR_MAX+1);
  1154. retInfo.scalePointCount = plugin->getParameterScalePointCount(parameterId);
  1155. if (plugin->getParameterName(parameterId, strBuf))
  1156. {
  1157. retInfo.name = carla_strdup_safe(strBuf);
  1158. carla_zeroChars(strBuf, STR_MAX+1);
  1159. }
  1160. if (plugin->getParameterSymbol(parameterId, strBuf))
  1161. {
  1162. retInfo.symbol = carla_strdup_safe(strBuf);
  1163. carla_zeroChars(strBuf, STR_MAX+1);
  1164. }
  1165. if (plugin->getParameterUnit(parameterId, strBuf))
  1166. {
  1167. retInfo.unit = carla_strdup_safe(strBuf);
  1168. carla_zeroChars(strBuf, STR_MAX+1);
  1169. }
  1170. if (plugin->getParameterComment(parameterId, strBuf))
  1171. {
  1172. retInfo.comment = carla_strdup_safe(strBuf);
  1173. carla_zeroChars(strBuf, STR_MAX+1);
  1174. }
  1175. if (plugin->getParameterGroupName(parameterId, strBuf))
  1176. {
  1177. retInfo.groupName = carla_strdup_safe(strBuf);
  1178. carla_zeroChars(strBuf, STR_MAX+1);
  1179. }
  1180. checkStringPtr(retInfo.name);
  1181. checkStringPtr(retInfo.symbol);
  1182. checkStringPtr(retInfo.unit);
  1183. checkStringPtr(retInfo.comment);
  1184. checkStringPtr(retInfo.groupName);
  1185. }
  1186. return &retInfo;
  1187. }
  1188. const CarlaScalePointInfo* carla_get_parameter_scalepoint_info(CarlaHostHandle handle,
  1189. uint pluginId,
  1190. uint32_t parameterId,
  1191. uint32_t scalePointId)
  1192. {
  1193. CARLA_ASSERT(handle->engine != nullptr);
  1194. static CarlaScalePointInfo retInfo;
  1195. // reset
  1196. retInfo.value = 0.0f;
  1197. // cleanup
  1198. if (retInfo.label != gNullCharPtr)
  1199. {
  1200. delete[] retInfo.label;
  1201. retInfo.label = gNullCharPtr;
  1202. }
  1203. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, &retInfo);
  1204. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1205. {
  1206. char strBuf[STR_MAX+1];
  1207. retInfo.value = plugin->getParameterScalePointValue(parameterId, scalePointId);
  1208. carla_zeroChars(strBuf, STR_MAX+1);
  1209. if (plugin->getParameterScalePointLabel(parameterId, scalePointId, strBuf))
  1210. retInfo.label = carla_strdup_safe(strBuf);
  1211. checkStringPtr(retInfo.label);
  1212. }
  1213. return &retInfo;
  1214. }
  1215. // --------------------------------------------------------------------------------------------------------------------
  1216. const ParameterData* carla_get_parameter_data(CarlaHostHandle handle, uint pluginId, uint32_t parameterId)
  1217. {
  1218. static ParameterData retParamData;
  1219. // reset
  1220. retParamData.type = CB::PARAMETER_UNKNOWN;
  1221. retParamData.hints = 0x0;
  1222. retParamData.index = CB::PARAMETER_NULL;
  1223. retParamData.rindex = -1;
  1224. retParamData.midiChannel = 0;
  1225. retParamData.mappedControlIndex = CB::CONTROL_INDEX_NONE;
  1226. retParamData.mappedMinimum = 0.0f;
  1227. retParamData.mappedMaximum = 0.0f;
  1228. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, &retParamData);
  1229. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1230. {
  1231. CARLA_SAFE_ASSERT_RETURN(parameterId < plugin->getParameterCount(), &retParamData);
  1232. const ParameterData& pluginParamData(plugin->getParameterData(parameterId));
  1233. retParamData.type = pluginParamData.type;
  1234. retParamData.hints = pluginParamData.hints;
  1235. retParamData.index = pluginParamData.index;
  1236. retParamData.rindex = pluginParamData.rindex;
  1237. retParamData.midiChannel = pluginParamData.midiChannel;
  1238. retParamData.mappedControlIndex = pluginParamData.mappedControlIndex;
  1239. retParamData.mappedMinimum = pluginParamData.mappedMinimum;
  1240. retParamData.mappedMaximum = pluginParamData.mappedMaximum;
  1241. }
  1242. return &retParamData;
  1243. }
  1244. const ParameterRanges* carla_get_parameter_ranges(CarlaHostHandle handle, uint pluginId, uint32_t parameterId)
  1245. {
  1246. static ParameterRanges retParamRanges;
  1247. // reset
  1248. retParamRanges.def = 0.0f;
  1249. retParamRanges.min = 0.0f;
  1250. retParamRanges.max = 1.0f;
  1251. retParamRanges.step = 0.01f;
  1252. retParamRanges.stepSmall = 0.0001f;
  1253. retParamRanges.stepLarge = 0.1f;
  1254. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, &retParamRanges);
  1255. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1256. {
  1257. CARLA_SAFE_ASSERT_RETURN(parameterId < plugin->getParameterCount(), &retParamRanges);
  1258. const ParameterRanges& pluginParamRanges(plugin->getParameterRanges(parameterId));
  1259. retParamRanges.def = pluginParamRanges.def;
  1260. retParamRanges.min = pluginParamRanges.min;
  1261. retParamRanges.max = pluginParamRanges.max;
  1262. retParamRanges.step = pluginParamRanges.step;
  1263. retParamRanges.stepSmall = pluginParamRanges.stepSmall;
  1264. retParamRanges.stepLarge = pluginParamRanges.stepLarge;
  1265. }
  1266. return &retParamRanges;
  1267. }
  1268. const MidiProgramData* carla_get_midi_program_data(CarlaHostHandle handle, uint pluginId, uint32_t midiProgramId)
  1269. {
  1270. static MidiProgramData retMidiProgData = { 0, 0, gNullCharPtr };
  1271. // reset
  1272. retMidiProgData.bank = 0;
  1273. retMidiProgData.program = 0;
  1274. if (retMidiProgData.name != gNullCharPtr)
  1275. {
  1276. delete[] retMidiProgData.name;
  1277. retMidiProgData.name = gNullCharPtr;
  1278. }
  1279. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, &retMidiProgData);
  1280. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1281. {
  1282. CARLA_SAFE_ASSERT_RETURN(midiProgramId < plugin->getMidiProgramCount(), &retMidiProgData);
  1283. const MidiProgramData& pluginMidiProgData(plugin->getMidiProgramData(midiProgramId));
  1284. retMidiProgData.bank = pluginMidiProgData.bank;
  1285. retMidiProgData.program = pluginMidiProgData.program;
  1286. if (pluginMidiProgData.name != nullptr)
  1287. {
  1288. retMidiProgData.name = carla_strdup_safe(pluginMidiProgData.name);
  1289. checkStringPtr(retMidiProgData.name);
  1290. }
  1291. else
  1292. {
  1293. retMidiProgData.name = gNullCharPtr;
  1294. }
  1295. }
  1296. return &retMidiProgData;
  1297. }
  1298. const CustomData* carla_get_custom_data(CarlaHostHandle handle, uint pluginId, uint32_t customDataId)
  1299. {
  1300. static CustomData retCustomData = { gNullCharPtr, gNullCharPtr, gNullCharPtr };
  1301. // reset
  1302. if (retCustomData.type != gNullCharPtr)
  1303. {
  1304. delete[] retCustomData.type;
  1305. retCustomData.type = gNullCharPtr;
  1306. }
  1307. if (retCustomData.key != gNullCharPtr)
  1308. {
  1309. delete[] retCustomData.key;
  1310. retCustomData.key = gNullCharPtr;
  1311. }
  1312. if (retCustomData.value != gNullCharPtr)
  1313. {
  1314. delete[] retCustomData.value;
  1315. retCustomData.value = gNullCharPtr;
  1316. }
  1317. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, &retCustomData);
  1318. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1319. {
  1320. CARLA_SAFE_ASSERT_RETURN(customDataId < plugin->getCustomDataCount(), &retCustomData)
  1321. const CustomData& pluginCustomData(plugin->getCustomData(customDataId));
  1322. retCustomData.type = carla_strdup_safe(pluginCustomData.type);
  1323. retCustomData.key = carla_strdup_safe(pluginCustomData.key);
  1324. retCustomData.value = carla_strdup_safe(pluginCustomData.value);
  1325. checkStringPtr(retCustomData.type);
  1326. checkStringPtr(retCustomData.key);
  1327. checkStringPtr(retCustomData.value);
  1328. }
  1329. return &retCustomData;
  1330. }
  1331. const char* carla_get_custom_data_value(CarlaHostHandle handle, uint pluginId, const char* type, const char* key)
  1332. {
  1333. CARLA_SAFE_ASSERT_RETURN(type != nullptr && type[0] != '\0', gNullCharPtr);
  1334. CARLA_SAFE_ASSERT_RETURN(key != nullptr && key[0] != '\0', gNullCharPtr);
  1335. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, gNullCharPtr);
  1336. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1337. {
  1338. const uint32_t count = plugin->getCustomDataCount();
  1339. if (count == 0)
  1340. return gNullCharPtr;
  1341. static CarlaString customDataValue;
  1342. for (uint32_t i=0; i<count; ++i)
  1343. {
  1344. const CustomData& pluginCustomData(plugin->getCustomData(i));
  1345. if (std::strcmp(pluginCustomData.type, type) != 0)
  1346. continue;
  1347. if (std::strcmp(pluginCustomData.key, key) != 0)
  1348. continue;
  1349. customDataValue = pluginCustomData.value;
  1350. return customDataValue.buffer();
  1351. }
  1352. }
  1353. return gNullCharPtr;
  1354. }
  1355. const char* carla_get_chunk_data(CarlaHostHandle handle, uint pluginId)
  1356. {
  1357. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, gNullCharPtr);
  1358. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1359. {
  1360. CARLA_SAFE_ASSERT_RETURN(plugin->getOptionsEnabled() & CB::PLUGIN_OPTION_USE_CHUNKS, gNullCharPtr);
  1361. void* data = nullptr;
  1362. const std::size_t dataSize(plugin->getChunkData(&data));
  1363. CARLA_SAFE_ASSERT_RETURN(data != nullptr && dataSize > 0, gNullCharPtr);
  1364. static CarlaString chunkData;
  1365. chunkData = CarlaString::asBase64(data, static_cast<std::size_t>(dataSize));
  1366. return chunkData.buffer();
  1367. }
  1368. return gNullCharPtr;
  1369. }
  1370. // --------------------------------------------------------------------------------------------------------------------
  1371. uint32_t carla_get_parameter_count(CarlaHostHandle handle, uint pluginId)
  1372. {
  1373. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, 0);
  1374. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1375. return plugin->getParameterCount();
  1376. return 0;
  1377. }
  1378. uint32_t carla_get_program_count(CarlaHostHandle handle, uint pluginId)
  1379. {
  1380. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, 0);
  1381. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1382. return plugin->getProgramCount();
  1383. return 0;
  1384. }
  1385. uint32_t carla_get_midi_program_count(CarlaHostHandle handle, uint pluginId)
  1386. {
  1387. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, 0);
  1388. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1389. return plugin->getMidiProgramCount();
  1390. return 0;
  1391. }
  1392. uint32_t carla_get_custom_data_count(CarlaHostHandle handle, uint pluginId)
  1393. {
  1394. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, 0);
  1395. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1396. return plugin->getCustomDataCount();
  1397. return 0;
  1398. }
  1399. // --------------------------------------------------------------------------------------------------------------------
  1400. const char* carla_get_parameter_text(CarlaHostHandle handle, uint pluginId, uint32_t parameterId)
  1401. {
  1402. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, gNullCharPtr);
  1403. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1404. {
  1405. CARLA_SAFE_ASSERT_RETURN(parameterId < plugin->getParameterCount(), gNullCharPtr);
  1406. static char textBuf[STR_MAX+1];
  1407. carla_zeroChars(textBuf, STR_MAX+1);
  1408. if (! plugin->getParameterText(parameterId, textBuf))
  1409. textBuf[0] = '\0';
  1410. return textBuf;
  1411. }
  1412. return gNullCharPtr;
  1413. }
  1414. const char* carla_get_program_name(CarlaHostHandle handle, uint pluginId, uint32_t programId)
  1415. {
  1416. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, nullptr);
  1417. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1418. {
  1419. CARLA_SAFE_ASSERT_RETURN(programId < plugin->getProgramCount(), gNullCharPtr);
  1420. static char programName[STR_MAX+1];
  1421. carla_zeroChars(programName, STR_MAX+1);
  1422. if (! plugin->getProgramName(programId, programName))
  1423. programName[0] = '\0';
  1424. return programName;
  1425. }
  1426. return gNullCharPtr;
  1427. }
  1428. const char* carla_get_midi_program_name(CarlaHostHandle handle, uint pluginId, uint32_t midiProgramId)
  1429. {
  1430. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, gNullCharPtr);
  1431. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1432. {
  1433. CARLA_SAFE_ASSERT_RETURN(midiProgramId < plugin->getMidiProgramCount(), gNullCharPtr);
  1434. static char midiProgramName[STR_MAX+1];
  1435. carla_zeroChars(midiProgramName, STR_MAX+1);
  1436. if (! plugin->getMidiProgramName(midiProgramId, midiProgramName))
  1437. midiProgramName[0] = '\0';
  1438. return midiProgramName;
  1439. }
  1440. return gNullCharPtr;
  1441. }
  1442. const char* carla_get_real_plugin_name(CarlaHostHandle handle, uint pluginId)
  1443. {
  1444. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, gNullCharPtr);
  1445. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1446. {
  1447. static char realPluginName[STR_MAX+1];
  1448. carla_zeroChars(realPluginName, STR_MAX+1);
  1449. if (! plugin->getRealName(realPluginName))
  1450. realPluginName[0] = '\0';
  1451. return realPluginName;
  1452. }
  1453. return gNullCharPtr;
  1454. }
  1455. // --------------------------------------------------------------------------------------------------------------------
  1456. int32_t carla_get_current_program_index(CarlaHostHandle handle, uint pluginId)
  1457. {
  1458. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, -1);
  1459. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1460. return plugin->getCurrentProgram();
  1461. return -1;
  1462. }
  1463. int32_t carla_get_current_midi_program_index(CarlaHostHandle handle, uint pluginId)
  1464. {
  1465. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, -1);
  1466. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1467. return plugin->getCurrentMidiProgram();
  1468. return -1;
  1469. }
  1470. // --------------------------------------------------------------------------------------------------------------------
  1471. float carla_get_default_parameter_value(CarlaHostHandle handle, uint pluginId, uint32_t parameterId)
  1472. {
  1473. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, 0.0f);
  1474. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1475. {
  1476. CARLA_SAFE_ASSERT_RETURN(parameterId < plugin->getParameterCount(), 0.0f);
  1477. return plugin->getParameterRanges(parameterId).def;
  1478. }
  1479. return 0.0f;
  1480. }
  1481. float carla_get_current_parameter_value(CarlaHostHandle handle, uint pluginId, uint32_t parameterId)
  1482. {
  1483. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, 0.0f);
  1484. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1485. {
  1486. CARLA_SAFE_ASSERT_RETURN(parameterId < plugin->getParameterCount(), 0.0f);
  1487. return plugin->getParameterValue(parameterId);
  1488. }
  1489. return 0.0f;
  1490. }
  1491. float carla_get_internal_parameter_value(CarlaHostHandle handle, uint pluginId, int32_t parameterId)
  1492. {
  1493. #ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH
  1494. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, (parameterId == CB::PARAMETER_CTRL_CHANNEL) ? -1.0f : 0.0f);
  1495. #else
  1496. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, 0.0f);
  1497. #endif
  1498. CARLA_SAFE_ASSERT_RETURN(parameterId != CB::PARAMETER_NULL && parameterId > CB::PARAMETER_MAX, 0.0f);
  1499. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1500. return plugin->getInternalParameterValue(parameterId);
  1501. return 0.0f;
  1502. }
  1503. // --------------------------------------------------------------------------------------------------------------------
  1504. uint32_t carla_get_plugin_latency(CarlaHostHandle handle, uint pluginId)
  1505. {
  1506. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, 0);
  1507. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1508. return plugin->getLatencyInFrames();
  1509. return 0;
  1510. }
  1511. // --------------------------------------------------------------------------------------------------------------------
  1512. const float* carla_get_peak_values(CarlaHostHandle handle, uint pluginId)
  1513. {
  1514. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, nullptr);
  1515. return handle->engine->getPeaks(pluginId);
  1516. }
  1517. float carla_get_input_peak_value(CarlaHostHandle handle, uint pluginId, bool isLeft)
  1518. {
  1519. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, 0.0f);
  1520. return handle->engine->getInputPeak(pluginId, isLeft);
  1521. }
  1522. float carla_get_output_peak_value(CarlaHostHandle handle, uint pluginId, bool isLeft)
  1523. {
  1524. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, 0.0f);
  1525. return handle->engine->getOutputPeak(pluginId, isLeft);
  1526. }
  1527. // --------------------------------------------------------------------------------------------------------------------
  1528. CARLA_BACKEND_START_NAMESPACE
  1529. #ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH
  1530. // defined in CarlaPluginInternal.cpp
  1531. const void* carla_render_inline_display_internal(const CarlaPluginPtr& plugin, uint32_t width, uint32_t height);
  1532. #endif
  1533. // defined in CarlaPluginLV2.cpp
  1534. const void* carla_render_inline_display_lv2(const CarlaPluginPtr& plugin, uint32_t width, uint32_t height);
  1535. CARLA_BACKEND_END_NAMESPACE
  1536. const CarlaInlineDisplayImageSurface* carla_render_inline_display(CarlaHostHandle handle,
  1537. uint pluginId,
  1538. uint32_t width, uint32_t height)
  1539. {
  1540. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr && handle->engine->isRunning(), nullptr);
  1541. if (handle->engine->isAboutToClose())
  1542. return nullptr;
  1543. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1544. {
  1545. switch (plugin->getType())
  1546. {
  1547. #ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH
  1548. case CB::PLUGIN_INTERNAL:
  1549. return (const CarlaInlineDisplayImageSurface*)CB::carla_render_inline_display_internal(plugin, width, height);
  1550. #endif
  1551. case CB::PLUGIN_LV2:
  1552. return (const CarlaInlineDisplayImageSurface*)CB::carla_render_inline_display_lv2(plugin, width, height);
  1553. default:
  1554. return nullptr;
  1555. }
  1556. }
  1557. return nullptr;
  1558. }
  1559. // --------------------------------------------------------------------------------------------------------------------
  1560. void carla_set_active(CarlaHostHandle handle, uint pluginId, bool onOff)
  1561. {
  1562. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr,);
  1563. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1564. plugin->setActive(onOff, true, false);
  1565. }
  1566. #ifndef BUILD_BRIDGE
  1567. void carla_set_drywet(CarlaHostHandle handle, uint pluginId, float value)
  1568. {
  1569. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr,);
  1570. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1571. plugin->setDryWet(value, true, false);
  1572. }
  1573. void carla_set_volume(CarlaHostHandle handle, uint pluginId, float value)
  1574. {
  1575. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr,);
  1576. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1577. plugin->setVolume(value, true, false);
  1578. }
  1579. void carla_set_balance_left(CarlaHostHandle handle, uint pluginId, float value)
  1580. {
  1581. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr,);
  1582. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1583. plugin->setBalanceLeft(value, true, false);
  1584. }
  1585. void carla_set_balance_right(CarlaHostHandle handle, uint pluginId, float value)
  1586. {
  1587. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr,);
  1588. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1589. plugin->setBalanceRight(value, true, false);
  1590. }
  1591. void carla_set_panning(CarlaHostHandle handle, uint pluginId, float value)
  1592. {
  1593. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr,);
  1594. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1595. plugin->setPanning(value, true, false);
  1596. }
  1597. void carla_set_ctrl_channel(CarlaHostHandle handle, uint pluginId, int8_t channel)
  1598. {
  1599. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr,);
  1600. CARLA_SAFE_ASSERT_RETURN(channel >= -1 && channel < MAX_MIDI_CHANNELS,);
  1601. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1602. plugin->setCtrlChannel(channel, true, false);
  1603. }
  1604. #endif
  1605. void carla_set_option(CarlaHostHandle handle, uint pluginId, uint option, bool yesNo)
  1606. {
  1607. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr,);
  1608. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1609. plugin->setOption(option, yesNo, false);
  1610. }
  1611. // --------------------------------------------------------------------------------------------------------------------
  1612. void carla_set_parameter_value(CarlaHostHandle handle, uint pluginId, uint32_t parameterId, float value)
  1613. {
  1614. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr,);
  1615. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1616. {
  1617. CARLA_SAFE_ASSERT_RETURN(parameterId < plugin->getParameterCount(),);
  1618. plugin->setParameterValue(parameterId, value, true, true, false);
  1619. }
  1620. }
  1621. #ifndef BUILD_BRIDGE
  1622. void carla_set_parameter_midi_channel(CarlaHostHandle handle, uint pluginId, uint32_t parameterId, uint8_t channel)
  1623. {
  1624. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr,);
  1625. CARLA_SAFE_ASSERT_RETURN(channel < MAX_MIDI_CHANNELS,);
  1626. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1627. {
  1628. CARLA_SAFE_ASSERT_RETURN(parameterId < plugin->getParameterCount(),);
  1629. plugin->setParameterMidiChannel(parameterId, channel, true, false);
  1630. }
  1631. }
  1632. void carla_set_parameter_mapped_control_index(CarlaHostHandle handle, uint pluginId, uint32_t parameterId, int16_t index)
  1633. {
  1634. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr,);
  1635. CARLA_SAFE_ASSERT_RETURN(index >= CB::CONTROL_INDEX_NONE && index <= CB::CONTROL_INDEX_MAX_ALLOWED,);
  1636. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1637. {
  1638. CARLA_SAFE_ASSERT_RETURN(parameterId < plugin->getParameterCount(),);
  1639. plugin->setParameterMappedControlIndex(parameterId, index, true, false, true);
  1640. }
  1641. }
  1642. void carla_set_parameter_mapped_range(CarlaHostHandle handle, uint pluginId, uint32_t parameterId, float minimum, float maximum)
  1643. {
  1644. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr,);
  1645. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1646. {
  1647. CARLA_SAFE_ASSERT_RETURN(parameterId < plugin->getParameterCount(),);
  1648. plugin->setParameterMappedRange(parameterId, minimum, maximum, true, false);
  1649. }
  1650. }
  1651. void carla_set_parameter_touch(CarlaHostHandle handle, uint pluginId, uint32_t parameterId, bool touch)
  1652. {
  1653. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr,);
  1654. carla_debug("carla_set_parameter_touch(%p, %i, %i, %s)", handle, pluginId, parameterId, bool2str(touch));
  1655. return handle->engine->touchPluginParameter(pluginId, parameterId, touch);
  1656. }
  1657. #endif
  1658. // --------------------------------------------------------------------------------------------------------------------
  1659. void carla_set_program(CarlaHostHandle handle, uint pluginId, uint32_t programId)
  1660. {
  1661. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr,);
  1662. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1663. {
  1664. CARLA_SAFE_ASSERT_RETURN(programId < plugin->getProgramCount(),);
  1665. plugin->setProgram(static_cast<int32_t>(programId), true, true, false);
  1666. }
  1667. }
  1668. void carla_set_midi_program(CarlaHostHandle handle, uint pluginId, uint32_t midiProgramId)
  1669. {
  1670. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr,);
  1671. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1672. {
  1673. CARLA_SAFE_ASSERT_RETURN(midiProgramId < plugin->getMidiProgramCount(),);
  1674. plugin->setMidiProgram(static_cast<int32_t>(midiProgramId), true, true, false);
  1675. }
  1676. }
  1677. // --------------------------------------------------------------------------------------------------------------------
  1678. void carla_set_custom_data(CarlaHostHandle handle, uint pluginId, const char* type, const char* key, const char* value)
  1679. {
  1680. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr,);
  1681. CARLA_SAFE_ASSERT_RETURN(type != nullptr && type[0] != '\0',);
  1682. CARLA_SAFE_ASSERT_RETURN(key != nullptr && key[0] != '\0',);
  1683. CARLA_SAFE_ASSERT_RETURN(value != nullptr,);
  1684. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1685. plugin->setCustomData(type, key, value, true);
  1686. }
  1687. void carla_set_chunk_data(CarlaHostHandle handle, uint pluginId, const char* chunkData)
  1688. {
  1689. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr,);
  1690. CARLA_SAFE_ASSERT_RETURN(chunkData != nullptr && chunkData[0] != '\0',);
  1691. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1692. {
  1693. CARLA_SAFE_ASSERT_RETURN(plugin->getOptionsEnabled() & CB::PLUGIN_OPTION_USE_CHUNKS,);
  1694. std::vector<uint8_t> chunk(carla_getChunkFromBase64String(chunkData));
  1695. #ifdef CARLA_PROPER_CPP11_SUPPORT
  1696. plugin->setChunkData(chunk.data(), chunk.size());
  1697. #else
  1698. plugin->setChunkData(&chunk.front(), chunk.size());
  1699. #endif
  1700. }
  1701. }
  1702. // --------------------------------------------------------------------------------------------------------------------
  1703. void carla_prepare_for_save(CarlaHostHandle handle, uint pluginId)
  1704. {
  1705. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr,);
  1706. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1707. plugin->prepareForSave(false);
  1708. }
  1709. void carla_reset_parameters(CarlaHostHandle handle, uint pluginId)
  1710. {
  1711. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr,);
  1712. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1713. plugin->resetParameters();
  1714. }
  1715. void carla_randomize_parameters(CarlaHostHandle handle, uint pluginId)
  1716. {
  1717. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr,);
  1718. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1719. plugin->randomizeParameters();
  1720. }
  1721. #ifndef BUILD_BRIDGE
  1722. void carla_send_midi_note(CarlaHostHandle handle, uint pluginId, uint8_t channel, uint8_t note, uint8_t velocity)
  1723. {
  1724. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr && handle->engine->isRunning(),);
  1725. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1726. plugin->sendMidiSingleNote(channel, note, velocity, true, true, false);
  1727. }
  1728. #endif
  1729. void carla_set_custom_ui_title(CarlaHostHandle handle, uint pluginId, const char* title)
  1730. {
  1731. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr,);
  1732. CARLA_SAFE_ASSERT_RETURN(title != nullptr,);
  1733. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1734. plugin->setCustomUITitle(title);
  1735. }
  1736. void carla_show_custom_ui(CarlaHostHandle handle, uint pluginId, bool yesNo)
  1737. {
  1738. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr,);
  1739. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1740. plugin->showCustomUI(yesNo);
  1741. }
  1742. void* carla_embed_custom_ui(CarlaHostHandle handle, uint pluginId, void* ptr)
  1743. {
  1744. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, nullptr);
  1745. if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId))
  1746. return plugin->embedCustomUI(ptr);
  1747. return nullptr;
  1748. }
  1749. // --------------------------------------------------------------------------------------------------------------------
  1750. uint32_t carla_get_buffer_size(CarlaHostHandle handle)
  1751. {
  1752. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, 0);
  1753. carla_debug("carla_get_buffer_size(%p)", handle);
  1754. return handle->engine->getBufferSize();
  1755. }
  1756. double carla_get_sample_rate(CarlaHostHandle handle)
  1757. {
  1758. CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr, 0.0);
  1759. carla_debug("carla_get_sample_rate(%p)", handle);
  1760. return handle->engine->getSampleRate();
  1761. }
  1762. // --------------------------------------------------------------------------------------------------------------------
  1763. const char* carla_get_last_error(CarlaHostHandle handle)
  1764. {
  1765. carla_debug("carla_get_last_error(%p)", handle);
  1766. if (handle->engine != nullptr)
  1767. return handle->engine->getLastError();
  1768. return handle->isStandalone
  1769. ? ((CarlaHostStandalone*)handle)->lastError.buffer()
  1770. : gNullCharPtr;
  1771. }
  1772. const char* carla_get_host_osc_url_tcp(CarlaHostHandle handle)
  1773. {
  1774. carla_debug("carla_get_host_osc_url_tcp(%p)", handle);
  1775. #if defined(HAVE_LIBLO) && !defined(BUILD_BRIDGE)
  1776. if (handle->engine == nullptr)
  1777. {
  1778. carla_stderr2("carla_get_host_osc_url_tcp() failed, engine is not running");
  1779. if (handle->isStandalone)
  1780. ((CarlaHostStandalone*)handle)->lastError = "Engine is not running";
  1781. return gNullCharPtr;
  1782. }
  1783. const char* const path = handle->engine->getOscServerPathTCP();
  1784. if (path != nullptr && path[0] != '\0')
  1785. return path;
  1786. static const char* const notAvailable = "(OSC TCP port not available)";
  1787. return notAvailable;
  1788. #else
  1789. return "(OSC support not available in this build)";
  1790. // unused
  1791. (void)handle;
  1792. #endif
  1793. }
  1794. const char* carla_get_host_osc_url_udp(CarlaHostHandle handle)
  1795. {
  1796. carla_debug("carla_get_host_osc_url_udp(%p)", handle);
  1797. #if defined(HAVE_LIBLO) && !defined(BUILD_BRIDGE)
  1798. if (handle->engine == nullptr)
  1799. {
  1800. carla_stderr2("carla_get_host_osc_url_udp() failed, engine is not running");
  1801. if (handle->isStandalone)
  1802. ((CarlaHostStandalone*)handle)->lastError = "Engine is not running";
  1803. return gNullCharPtr;
  1804. }
  1805. const char* const path = handle->engine->getOscServerPathUDP();
  1806. if (path != nullptr && path[0] != '\0')
  1807. return path;
  1808. static const char* const notAvailable = "(OSC UDP port not available)";
  1809. return notAvailable;
  1810. #else
  1811. return "(OSC support not available in this build)";
  1812. // unused
  1813. (void)handle;
  1814. #endif
  1815. }
  1816. // --------------------------------------------------------------------------------------------------------------------
  1817. #ifndef CARLA_PLUGIN_EXPORT
  1818. # define CARLA_PLUGIN_UI_CLASS_PREFIX Standalone
  1819. # include "CarlaPluginUI.cpp"
  1820. # undef CARLA_PLUGIN_UI_CLASS_PREFIX
  1821. # include "CarlaDssiUtils.cpp"
  1822. # include "CarlaMacUtils.cpp"
  1823. # include "CarlaPatchbayUtils.cpp"
  1824. # include "CarlaPipeUtils.cpp"
  1825. # include "CarlaProcessUtils.cpp"
  1826. # include "CarlaStateUtils.cpp"
  1827. # include "utils/Information.cpp"
  1828. # include "utils/Windows.cpp"
  1829. #endif /* CARLA_PLUGIN_EXPORT */
  1830. // --------------------------------------------------------------------------------------------------------------------