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

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