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.

CachedPlugins.cpp 30KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882
  1. /*
  2. * Carla Plugin Host
  3. * Copyright (C) 2011-2023 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. #include "CarlaUtils.h"
  18. #include "CarlaNative.h"
  19. #include "CarlaString.hpp"
  20. #include "CarlaBackendUtils.hpp"
  21. #include "CarlaLv2Utils.hpp"
  22. #if defined(USING_JUCE) && defined(CARLA_OS_MAC)
  23. # include "AppConfig.h"
  24. # include "juce_audio_processors/juce_audio_processors.h"
  25. #endif
  26. #ifndef STATIC_PLUGIN_TARGET
  27. # define HAVE_SFZ
  28. # include "water/containers/Array.h"
  29. #endif
  30. #ifdef HAVE_YSFX
  31. # include "CarlaJsfxUtils.hpp"
  32. #endif
  33. #include "water/files/File.h"
  34. namespace CB = CARLA_BACKEND_NAMESPACE;
  35. // -------------------------------------------------------------------------------------------------------------------
  36. static const char* const gCachedPluginsNullCharPtr = "";
  37. static bool isCachedPluginType(const CB::PluginType ptype)
  38. {
  39. switch (ptype)
  40. {
  41. case CB::PLUGIN_INTERNAL:
  42. case CB::PLUGIN_LV2:
  43. case CB::PLUGIN_AU:
  44. case CB::PLUGIN_SFZ:
  45. case CB::PLUGIN_JSFX:
  46. return true;
  47. default:
  48. return false;
  49. }
  50. }
  51. // -------------------------------------------------------------------------------------------------------------------
  52. _CarlaCachedPluginInfo::_CarlaCachedPluginInfo() noexcept
  53. : valid(false),
  54. category(CB::PLUGIN_CATEGORY_NONE),
  55. hints(0x0),
  56. audioIns(0),
  57. audioOuts(0),
  58. cvIns(0),
  59. cvOuts(0),
  60. midiIns(0),
  61. midiOuts(0),
  62. parameterIns(0),
  63. parameterOuts(0),
  64. name(gCachedPluginsNullCharPtr),
  65. label(gCachedPluginsNullCharPtr),
  66. maker(gCachedPluginsNullCharPtr),
  67. copyright(gCachedPluginsNullCharPtr) {}
  68. // -------------------------------------------------------------------------------------------------------------------
  69. #ifdef HAVE_SFZ
  70. static std::vector<water::File> gSFZs;
  71. static void findSFZs(const char* const sfzPaths)
  72. {
  73. gSFZs.clear();
  74. CARLA_SAFE_ASSERT_RETURN(sfzPaths != nullptr,);
  75. if (sfzPaths[0] == '\0')
  76. return;
  77. const water::StringArray splitPaths(water::StringArray::fromTokens(sfzPaths, CARLA_OS_SPLIT_STR, ""));
  78. for (water::String *it = splitPaths.begin(), *end = splitPaths.end(); it != end; ++it)
  79. {
  80. std::vector<water::File> results;
  81. if (water::File(*it).findChildFiles(results, water::File::findFiles|water::File::ignoreHiddenFiles, true, "*.sfz") > 0)
  82. {
  83. gSFZs.reserve(gSFZs.size() + results.size());
  84. gSFZs.insert(gSFZs.end(), results.begin(), results.end());
  85. }
  86. }
  87. }
  88. #endif
  89. // -------------------------------------------------------------------------------------------------------------------
  90. #ifdef HAVE_YSFX
  91. static std::vector<CB::CarlaJsfxUnit> gJSFXs;
  92. static void findJSFXs(const char* const jsfxPaths)
  93. {
  94. gJSFXs.clear();
  95. CARLA_SAFE_ASSERT_RETURN(jsfxPaths != nullptr,);
  96. if (jsfxPaths[0] == '\0')
  97. return;
  98. const water::StringArray splitPaths(water::StringArray::fromTokens(jsfxPaths, CARLA_OS_SPLIT_STR, ""));
  99. for (water::String *it = splitPaths.begin(), *end = splitPaths.end(); it != end; ++it)
  100. {
  101. std::vector<water::File> results;
  102. const water::File path(*it);
  103. if (path.findChildFiles(results, water::File::findFiles|water::File::ignoreHiddenFiles, true, "*") > 0)
  104. {
  105. gJSFXs.reserve(gJSFXs.size() + results.size());
  106. for (std::vector<water::File>::iterator it2=results.begin(), end2=results.end(); it2 != end2; ++it2)
  107. {
  108. const water::File& file(*it2);
  109. const water::String fileExt = file.getFileExtension();
  110. if (fileExt.isEmpty() || fileExt.equalsIgnoreCase(".jsfx"))
  111. gJSFXs.push_back(CB::CarlaJsfxUnit(path, file));
  112. }
  113. }
  114. }
  115. }
  116. #endif
  117. // -------------------------------------------------------------------------------------------------------------------
  118. static const CarlaCachedPluginInfo* get_cached_plugin_internal(const NativePluginDescriptor& desc)
  119. {
  120. static CarlaCachedPluginInfo info;
  121. info.category = static_cast<CB::PluginCategory>(desc.category);
  122. info.hints = 0x0;
  123. if (desc.hints & NATIVE_PLUGIN_IS_RTSAFE)
  124. info.hints |= CB::PLUGIN_IS_RTSAFE;
  125. if (desc.hints & NATIVE_PLUGIN_IS_SYNTH)
  126. info.hints |= CB::PLUGIN_IS_SYNTH;
  127. if (desc.hints & NATIVE_PLUGIN_HAS_UI)
  128. info.hints |= CB::PLUGIN_HAS_CUSTOM_UI;
  129. if (desc.hints & NATIVE_PLUGIN_HAS_INLINE_DISPLAY)
  130. info.hints |= CB::PLUGIN_HAS_INLINE_DISPLAY;
  131. if (desc.hints & NATIVE_PLUGIN_NEEDS_FIXED_BUFFERS)
  132. info.hints |= CB::PLUGIN_NEEDS_FIXED_BUFFERS;
  133. if (desc.hints & NATIVE_PLUGIN_NEEDS_UI_MAIN_THREAD)
  134. info.hints |= CB::PLUGIN_NEEDS_UI_MAIN_THREAD;
  135. if (desc.hints & NATIVE_PLUGIN_USES_MULTI_PROGS)
  136. info.hints |= CB::PLUGIN_USES_MULTI_PROGS;
  137. info.valid = true;
  138. info.audioIns = desc.audioIns;
  139. info.audioOuts = desc.audioOuts;
  140. info.cvIns = desc.cvIns;
  141. info.cvOuts = desc.cvOuts;
  142. info.midiIns = desc.midiIns;
  143. info.midiOuts = desc.midiOuts;
  144. info.parameterIns = desc.paramIns;
  145. info.parameterOuts = desc.paramOuts;
  146. info.name = desc.name;
  147. info.label = desc.label;
  148. info.maker = desc.maker;
  149. info.copyright = desc.copyright;
  150. return &info;
  151. }
  152. // -------------------------------------------------------------------------------------------------------------------
  153. static const CarlaCachedPluginInfo* get_cached_plugin_lv2(Lv2WorldClass& lv2World, Lilv::Plugin& lilvPlugin)
  154. {
  155. static CarlaCachedPluginInfo info;
  156. info.valid = false;
  157. bool supported = true;
  158. // ----------------------------------------------------------------------------------------------------------------
  159. // text data
  160. {
  161. static CarlaString suri, sname, smaker, slicense;
  162. suri.clear(); sname.clear(); smaker.clear(); slicense.clear();
  163. suri = lilvPlugin.get_uri().as_uri();
  164. if (char* const bundle = lilv_file_uri_parse(lilvPlugin.get_bundle_uri().as_uri(), nullptr))
  165. {
  166. const water::File fbundle(bundle);
  167. suri = (fbundle.getFileName() + CARLA_OS_SEP).toRawUTF8() + suri;
  168. lilv_free(bundle);
  169. }
  170. else
  171. {
  172. suri = CARLA_OS_SEP_STR + suri;
  173. }
  174. #if 0 // def HAVE_FLUIDSYNTH
  175. // If we have fluidsynth support built-in, loading these plugins will lead to issues
  176. if (suri == "urn:ardour:a-fluidsynth")
  177. return &info;
  178. if (suri == "http://calf.sourceforge.net/plugins/Fluidsynth")
  179. return &info;
  180. #endif
  181. if (LilvNode* const nameNode = lilv_plugin_get_name(lilvPlugin.me))
  182. {
  183. if (const char* const name = lilv_node_as_string(nameNode))
  184. sname = name;
  185. lilv_node_free(nameNode);
  186. }
  187. if (LilvNode* const authorNode = lilv_plugin_get_author_name(lilvPlugin.me))
  188. {
  189. if (const char* const author = lilv_node_as_string(authorNode))
  190. smaker = author;
  191. lilv_node_free(authorNode);
  192. }
  193. Lilv::Nodes licenseNodes(lilvPlugin.get_value(lv2World.doap_license));
  194. if (licenseNodes.size() > 0)
  195. {
  196. if (LilvNode* const licenseNode = lilv_nodes_get_first(licenseNodes.me))
  197. {
  198. if (const char* const license = lilv_node_as_string(licenseNode))
  199. slicense = license;
  200. // lilv_node_free(licenseNode);
  201. }
  202. }
  203. lilv_nodes_free(const_cast<LilvNodes*>(licenseNodes.me));
  204. info.name = sname.buffer();
  205. info.label = suri.buffer();
  206. info.maker = smaker.buffer();
  207. info.copyright = slicense.buffer();
  208. }
  209. // ----------------------------------------------------------------------------------------------------------------
  210. // features
  211. info.hints = 0x0;
  212. {
  213. Lilv::UIs lilvUIs(lilvPlugin.get_uis());
  214. if (lilvUIs.size() > 0)
  215. {
  216. info.hints |= CB::PLUGIN_HAS_CUSTOM_UI;
  217. LILV_FOREACH(uis, it, lilvUIs)
  218. {
  219. Lilv::UI lilvUI(lilvUIs.get(it));
  220. lv2World.load_resource(lilvUI.get_uri());
  221. #if defined(CARLA_OS_MAC)
  222. if (lilvUI.is_a(lv2World.ui_cocoa))
  223. #elif defined(CARLA_OS_WIN)
  224. if (lilvUI.is_a(lv2World.ui_windows))
  225. #elif defined(HAVE_X11)
  226. if (lilvUI.is_a(lv2World.ui_x11))
  227. #else
  228. if (false)
  229. #endif
  230. {
  231. info.hints |= CB::PLUGIN_HAS_CUSTOM_EMBED_UI;
  232. break;
  233. }
  234. }
  235. }
  236. #ifdef CARLA_OS_LINUX
  237. else if (lilvPlugin.get_modgui_resources_directory().as_uri() != nullptr)
  238. info.hints |= CB::PLUGIN_HAS_CUSTOM_UI;
  239. #endif
  240. lilv_nodes_free(const_cast<LilvNodes*>(lilvUIs.me));
  241. }
  242. {
  243. Lilv::Nodes lilvRequiredFeatureNodes(lilvPlugin.get_required_features());
  244. LILV_FOREACH(nodes, it, lilvRequiredFeatureNodes)
  245. {
  246. Lilv::Node lilvFeatureNode(lilvRequiredFeatureNodes.get(it));
  247. const char* const featureURI(lilvFeatureNode.as_uri());
  248. CARLA_SAFE_ASSERT_CONTINUE(featureURI != nullptr);
  249. if (! is_lv2_feature_supported(featureURI))
  250. {
  251. if (std::strcmp(featureURI, LV2_DATA_ACCESS_URI) == 0
  252. || std::strcmp(featureURI, LV2_INSTANCE_ACCESS_URI) == 0)
  253. {
  254. // we give a warning about this below
  255. continue;
  256. }
  257. supported = false;
  258. carla_stderr("LV2 plugin '%s' requires unsupported feature '%s'", info.label, featureURI);
  259. }
  260. }
  261. lilv_nodes_free(const_cast<LilvNodes*>(lilvRequiredFeatureNodes.me));
  262. }
  263. {
  264. Lilv::Nodes lilvSupportedFeatureNodes(lilvPlugin.get_supported_features());
  265. LILV_FOREACH(nodes, it, lilvSupportedFeatureNodes)
  266. {
  267. Lilv::Node lilvFeatureNode(lilvSupportedFeatureNodes.get(it));
  268. const char* const featureURI(lilvFeatureNode.as_uri());
  269. CARLA_SAFE_ASSERT_CONTINUE(featureURI != nullptr);
  270. /**/ if (std::strcmp(featureURI, LV2_CORE__hardRTCapable) == 0)
  271. {
  272. info.hints |= CB::PLUGIN_IS_RTSAFE;
  273. }
  274. else if (std::strcmp(featureURI, LV2_INLINEDISPLAY__queue_draw) == 0)
  275. {
  276. info.hints |= CB::PLUGIN_HAS_INLINE_DISPLAY;
  277. }
  278. else if (std::strcmp(featureURI, LV2_DATA_ACCESS_URI) == 0
  279. || std::strcmp(featureURI, LV2_INSTANCE_ACCESS_URI) == 0)
  280. {
  281. carla_stderr("LV2 plugin '%s' DSP wants UI feature '%s', ignoring this", info.label, featureURI);
  282. }
  283. }
  284. lilv_nodes_free(const_cast<LilvNodes*>(lilvSupportedFeatureNodes.me));
  285. }
  286. // ----------------------------------------------------------------------------------------------------------------
  287. // category
  288. info.category = CB::PLUGIN_CATEGORY_NONE;
  289. {
  290. Lilv::Nodes typeNodes(lilvPlugin.get_value(lv2World.rdf_type));
  291. if (typeNodes.size() > 0)
  292. {
  293. if (typeNodes.contains(lv2World.class_allpass))
  294. info.category = CB::PLUGIN_CATEGORY_FILTER;
  295. if (typeNodes.contains(lv2World.class_amplifier))
  296. info.category = CB::PLUGIN_CATEGORY_DYNAMICS;
  297. if (typeNodes.contains(lv2World.class_analyzer))
  298. info.category = CB::PLUGIN_CATEGORY_UTILITY;
  299. if (typeNodes.contains(lv2World.class_bandpass))
  300. info.category = CB::PLUGIN_CATEGORY_FILTER;
  301. if (typeNodes.contains(lv2World.class_chorus))
  302. info.category = CB::PLUGIN_CATEGORY_MODULATOR;
  303. if (typeNodes.contains(lv2World.class_comb))
  304. info.category = CB::PLUGIN_CATEGORY_FILTER;
  305. if (typeNodes.contains(lv2World.class_compressor))
  306. info.category = CB::PLUGIN_CATEGORY_DYNAMICS;
  307. if (typeNodes.contains(lv2World.class_constant))
  308. info.category = CB::PLUGIN_CATEGORY_OTHER;
  309. if (typeNodes.contains(lv2World.class_converter))
  310. info.category = CB::PLUGIN_CATEGORY_UTILITY;
  311. if (typeNodes.contains(lv2World.class_delay))
  312. info.category = CB::PLUGIN_CATEGORY_DELAY;
  313. if (typeNodes.contains(lv2World.class_distortion))
  314. info.category = CB::PLUGIN_CATEGORY_DISTORTION;
  315. if (typeNodes.contains(lv2World.class_dynamics))
  316. info.category = CB::PLUGIN_CATEGORY_DYNAMICS;
  317. if (typeNodes.contains(lv2World.class_eq))
  318. info.category = CB::PLUGIN_CATEGORY_EQ;
  319. if (typeNodes.contains(lv2World.class_envelope))
  320. info.category = CB::PLUGIN_CATEGORY_DYNAMICS;
  321. if (typeNodes.contains(lv2World.class_expander))
  322. info.category = CB::PLUGIN_CATEGORY_DYNAMICS;
  323. if (typeNodes.contains(lv2World.class_filter))
  324. info.category = CB::PLUGIN_CATEGORY_FILTER;
  325. if (typeNodes.contains(lv2World.class_flanger))
  326. info.category = CB::PLUGIN_CATEGORY_MODULATOR;
  327. if (typeNodes.contains(lv2World.class_function))
  328. info.category = CB::PLUGIN_CATEGORY_UTILITY;
  329. if (typeNodes.contains(lv2World.class_gate))
  330. info.category = CB::PLUGIN_CATEGORY_DYNAMICS;
  331. if (typeNodes.contains(lv2World.class_generator))
  332. info.category = CB::PLUGIN_CATEGORY_OTHER;
  333. if (typeNodes.contains(lv2World.class_highpass))
  334. info.category = CB::PLUGIN_CATEGORY_FILTER;
  335. if (typeNodes.contains(lv2World.class_limiter))
  336. info.category = CB::PLUGIN_CATEGORY_DYNAMICS;
  337. if (typeNodes.contains(lv2World.class_lowpass))
  338. info.category = CB::PLUGIN_CATEGORY_FILTER;
  339. if (typeNodes.contains(lv2World.class_mixer))
  340. info.category = CB::PLUGIN_CATEGORY_UTILITY;
  341. if (typeNodes.contains(lv2World.class_modulator))
  342. info.category = CB::PLUGIN_CATEGORY_MODULATOR;
  343. if (typeNodes.contains(lv2World.class_multiEQ))
  344. info.category = CB::PLUGIN_CATEGORY_EQ;
  345. if (typeNodes.contains(lv2World.class_oscillator))
  346. info.category = CB::PLUGIN_CATEGORY_OTHER;
  347. if (typeNodes.contains(lv2World.class_paraEQ))
  348. info.category = CB::PLUGIN_CATEGORY_EQ;
  349. if (typeNodes.contains(lv2World.class_phaser))
  350. info.category = CB::PLUGIN_CATEGORY_MODULATOR;
  351. if (typeNodes.contains(lv2World.class_pitch))
  352. info.category = CB::PLUGIN_CATEGORY_OTHER;
  353. if (typeNodes.contains(lv2World.class_reverb))
  354. info.category = CB::PLUGIN_CATEGORY_DELAY;
  355. if (typeNodes.contains(lv2World.class_simulator))
  356. info.category = CB::PLUGIN_CATEGORY_OTHER;
  357. if (typeNodes.contains(lv2World.class_spatial))
  358. info.category = CB::PLUGIN_CATEGORY_OTHER;
  359. if (typeNodes.contains(lv2World.class_spectral))
  360. info.category = CB::PLUGIN_CATEGORY_OTHER;
  361. if (typeNodes.contains(lv2World.class_utility))
  362. info.category = CB::PLUGIN_CATEGORY_UTILITY;
  363. if (typeNodes.contains(lv2World.class_waveshaper))
  364. info.category = CB::PLUGIN_CATEGORY_DISTORTION;
  365. if (typeNodes.contains(lv2World.class_instrument))
  366. {
  367. info.category = CB::PLUGIN_CATEGORY_SYNTH;
  368. info.hints |= CB::PLUGIN_IS_SYNTH;
  369. }
  370. }
  371. lilv_nodes_free(const_cast<LilvNodes*>(typeNodes.me));
  372. }
  373. // ----------------------------------------------------------------------------------------------------------------
  374. // number data
  375. info.audioIns = 0;
  376. info.audioOuts = 0;
  377. info.cvIns = 0;
  378. info.cvOuts = 0;
  379. info.midiIns = 0;
  380. info.midiOuts = 0;
  381. info.parameterIns = 0;
  382. info.parameterOuts = 0;
  383. for (uint i=0, count=lilvPlugin.get_num_ports(); i<count; ++i)
  384. {
  385. Lilv::Port lilvPort(lilvPlugin.get_port_by_index(i));
  386. bool isInput;
  387. /**/ if (lilvPort.is_a(lv2World.port_input))
  388. {
  389. isInput = true;
  390. }
  391. else if (lilvPort.is_a(lv2World.port_output))
  392. {
  393. isInput = false;
  394. }
  395. else
  396. {
  397. const LilvNode* const symbolNode = lilvPort.get_symbol();
  398. CARLA_SAFE_ASSERT_CONTINUE(symbolNode != nullptr && lilv_node_is_string(symbolNode));
  399. const char* const symbol = lilv_node_as_string(symbolNode);
  400. CARLA_SAFE_ASSERT_CONTINUE(symbol != nullptr);
  401. carla_stderr("LV2 plugin '%s' port '%s' is neither input or output", info.label, symbol);
  402. continue;
  403. }
  404. /**/ if (lilvPort.is_a(lv2World.port_control))
  405. {
  406. // skip some control ports
  407. if (lilvPort.has_property(lv2World.reportsLatency))
  408. continue;
  409. if (LilvNode* const designationNode = lilv_port_get(lilvPort.parent, lilvPort.me, lv2World.designation.me))
  410. {
  411. bool skip = false;
  412. if (const char* const designation = lilv_node_as_string(designationNode))
  413. {
  414. /**/ if (std::strcmp(designation, LV2_CORE__control) == 0)
  415. skip = true;
  416. else if (std::strcmp(designation, LV2_CORE__freeWheeling) == 0)
  417. skip = true;
  418. else if (std::strcmp(designation, LV2_CORE__latency) == 0)
  419. skip = true;
  420. else if (std::strcmp(designation, LV2_PARAMETERS__sampleRate) == 0)
  421. skip = true;
  422. else if (std::strcmp(designation, LV2_TIME__bar) == 0)
  423. skip = true;
  424. else if (std::strcmp(designation, LV2_TIME__barBeat) == 0)
  425. skip = true;
  426. else if (std::strcmp(designation, LV2_TIME__beat) == 0)
  427. skip = true;
  428. else if (std::strcmp(designation, LV2_TIME__beatUnit) == 0)
  429. skip = true;
  430. else if (std::strcmp(designation, LV2_TIME__beatsPerBar) == 0)
  431. skip = true;
  432. else if (std::strcmp(designation, LV2_TIME__beatsPerMinute) == 0)
  433. skip = true;
  434. else if (std::strcmp(designation, LV2_TIME__frame) == 0)
  435. skip = true;
  436. else if (std::strcmp(designation, LV2_TIME__framesPerSecond) == 0)
  437. skip = true;
  438. else if (std::strcmp(designation, LV2_TIME__speed) == 0)
  439. skip = true;
  440. else if (std::strcmp(designation, LV2_KXSTUDIO_PROPERTIES__TimePositionTicksPerBeat) == 0)
  441. skip = true;
  442. }
  443. lilv_node_free(designationNode);
  444. if (skip)
  445. continue;
  446. }
  447. if (isInput)
  448. ++(info.parameterIns);
  449. else
  450. ++(info.parameterOuts);
  451. }
  452. else if (lilvPort.is_a(lv2World.port_audio))
  453. {
  454. if (isInput)
  455. ++(info.audioIns);
  456. else
  457. ++(info.audioOuts);
  458. }
  459. else if (lilvPort.is_a(lv2World.port_cv))
  460. {
  461. if (isInput)
  462. ++(info.cvIns);
  463. else
  464. ++(info.cvOuts);
  465. }
  466. else if (lilvPort.is_a(lv2World.port_atom))
  467. {
  468. Lilv::Nodes supportNodes(lilvPort.get_value(lv2World.atom_supports));
  469. for (LilvIter *it = lilv_nodes_begin(supportNodes.me); ! lilv_nodes_is_end(supportNodes.me, it); it = lilv_nodes_next(supportNodes.me, it))
  470. {
  471. const Lilv::Node node(lilv_nodes_get(supportNodes.me, it));
  472. CARLA_SAFE_ASSERT_CONTINUE(node.is_uri());
  473. if (node.equals(lv2World.midi_event))
  474. {
  475. if (isInput)
  476. ++(info.midiIns);
  477. else
  478. ++(info.midiOuts);
  479. }
  480. }
  481. lilv_nodes_free(const_cast<LilvNodes*>(supportNodes.me));
  482. }
  483. else if (lilvPort.is_a(lv2World.port_event))
  484. {
  485. if (lilvPort.supports_event(lv2World.midi_event))
  486. {
  487. if (isInput)
  488. ++(info.midiIns);
  489. else
  490. ++(info.midiOuts);
  491. }
  492. }
  493. else if (lilvPort.is_a(lv2World.port_midi))
  494. {
  495. if (isInput)
  496. ++(info.midiIns);
  497. else
  498. ++(info.midiOuts);
  499. }
  500. else
  501. {
  502. const LilvNode* const symbolNode = lilvPort.get_symbol();
  503. CARLA_SAFE_ASSERT_CONTINUE(symbolNode != nullptr && lilv_node_is_string(symbolNode));
  504. const char* const symbol = lilv_node_as_string(symbolNode);
  505. CARLA_SAFE_ASSERT_CONTINUE(symbol != nullptr);
  506. supported = false;
  507. carla_stderr("LV2 plugin '%s' port '%s' is required but has unsupported type", info.label, symbol);
  508. }
  509. }
  510. if (supported)
  511. info.valid = true;
  512. return &info;
  513. }
  514. // -------------------------------------------------------------------------------------------------------------------
  515. #if defined(USING_JUCE) && defined(CARLA_OS_MAC)
  516. static juce::StringArray gCachedAuPluginResults;
  517. static void findAUs()
  518. {
  519. if (gCachedAuPluginResults.size() != 0)
  520. return;
  521. juce::AudioUnitPluginFormat auFormat;
  522. gCachedAuPluginResults = auFormat.searchPathsForPlugins(juce::FileSearchPath(), false, false);
  523. }
  524. static const CarlaCachedPluginInfo* get_cached_plugin_au(const juce::String pluginId)
  525. {
  526. static CarlaCachedPluginInfo info;
  527. static CarlaString sname, slabel, smaker;
  528. info.valid = false;
  529. juce::AudioUnitPluginFormat auFormat;
  530. juce::OwnedArray<juce::PluginDescription> results;
  531. auFormat.findAllTypesForFile(results, pluginId);
  532. CARLA_SAFE_ASSERT_RETURN(results.size() > 0, &info);
  533. CARLA_SAFE_ASSERT(results.size() == 1);
  534. juce::PluginDescription* const desc(results[0]);
  535. CARLA_SAFE_ASSERT_RETURN(desc != nullptr, &info);
  536. info.category = CB::getPluginCategoryFromName(desc->category.toRawUTF8());
  537. info.hints = 0x0;
  538. info.valid = true;
  539. if (desc->isInstrument)
  540. info.hints |= CB::PLUGIN_IS_SYNTH;
  541. if (true)
  542. info.hints |= CB::PLUGIN_HAS_CUSTOM_UI;
  543. info.audioIns = static_cast<uint32_t>(desc->numInputChannels);
  544. info.audioOuts = static_cast<uint32_t>(desc->numOutputChannels);
  545. info.cvIns = 0;
  546. info.cvOuts = 0;
  547. info.midiIns = desc->isInstrument ? 1 : 0;
  548. info.midiOuts = 0;
  549. info.parameterIns = 0;
  550. info.parameterOuts = 0;
  551. sname = desc->name.toRawUTF8();
  552. slabel = desc->fileOrIdentifier.toRawUTF8();
  553. smaker = desc->manufacturerName.toRawUTF8();
  554. info.name = sname;
  555. info.label = slabel;
  556. info.maker = smaker;
  557. info.copyright = gCachedPluginsNullCharPtr;
  558. return &info;
  559. }
  560. #endif
  561. // -------------------------------------------------------------------------------------------------------------------
  562. #ifdef HAVE_SFZ
  563. static const CarlaCachedPluginInfo* get_cached_plugin_sfz(const water::File& file)
  564. {
  565. static CarlaCachedPluginInfo info;
  566. static CarlaString name, filename;
  567. name = file.getFileNameWithoutExtension().toRawUTF8();
  568. name.replace('_',' ');
  569. filename = file.getFullPathName().toRawUTF8();
  570. info.category = CB::PLUGIN_CATEGORY_SYNTH;
  571. info.hints = CB::PLUGIN_IS_SYNTH;
  572. // CB::PLUGIN_IS_RTSAFE
  573. info.valid = true;
  574. info.audioIns = 0;
  575. info.audioOuts = 2;
  576. info.cvIns = 0;
  577. info.cvOuts = 0;
  578. info.midiIns = 1;
  579. info.midiOuts = 0;
  580. info.parameterIns = 0;
  581. info.parameterOuts = 1;
  582. info.name = name.buffer();
  583. info.label = filename.buffer();
  584. info.maker = gCachedPluginsNullCharPtr;
  585. info.copyright = gCachedPluginsNullCharPtr;
  586. return &info;
  587. }
  588. #endif
  589. // -------------------------------------------------------------------------------------------------------------------
  590. #ifdef HAVE_YSFX
  591. static const CarlaCachedPluginInfo* get_cached_plugin_jsfx(const CB::CarlaJsfxUnit& unit)
  592. {
  593. static CarlaCachedPluginInfo info;
  594. ysfx_config_u config(ysfx_config_new());
  595. const water::String rootPath = unit.getRootPath();
  596. const water::String filePath = unit.getFilePath();
  597. ysfx_register_builtin_audio_formats(config.get());
  598. ysfx_set_import_root(config.get(), rootPath.toRawUTF8());
  599. ysfx_guess_file_roots(config.get(), filePath.toRawUTF8());
  600. ysfx_set_log_reporter(config.get(), &CB::CarlaJsfxLogging::logErrorsOnly);
  601. ysfx_u effect(ysfx_new(config.get()));
  602. if (! ysfx_load_file(effect.get(), filePath.toRawUTF8(), 0))
  603. {
  604. info.valid = false;
  605. return &info;
  606. }
  607. // plugins with neither @block nor @sample are valid, but they are useless
  608. // also use this as a sanity check against misdetected files
  609. // since JSFX parsing is so permissive, it might accept lambda text files
  610. if (! ysfx_has_section(effect.get(), ysfx_section_block) &&
  611. ! ysfx_has_section(effect.get(), ysfx_section_sample))
  612. {
  613. info.valid = false;
  614. return &info;
  615. }
  616. static CarlaString name, label, maker;
  617. label = unit.getFileId().toRawUTF8();
  618. name = ysfx_get_name(effect.get());
  619. maker = ysfx_get_author(effect.get());
  620. info.valid = true;
  621. info.category = CB::CarlaJsfxCategories::getFromEffect(effect.get());
  622. info.audioIns = ysfx_get_num_inputs(effect.get());
  623. info.audioOuts = ysfx_get_num_outputs(effect.get());
  624. info.cvIns = 0;
  625. info.cvOuts = 0;
  626. info.midiIns = 1;
  627. info.midiOuts = 1;
  628. info.parameterIns = 0;
  629. info.parameterOuts = 0;
  630. for (uint32_t sliderIndex = 0; sliderIndex < ysfx_max_sliders; ++sliderIndex)
  631. {
  632. if (ysfx_slider_exists(effect.get(), sliderIndex))
  633. ++info.parameterIns;
  634. }
  635. info.hints = 0;
  636. #if 0 // TODO(jsfx) when supporting custom graphics
  637. if (ysfx_has_section(effect.get(), ysfx_section_gfx))
  638. info.hints |= CB::PLUGIN_HAS_CUSTOM_UI;
  639. #endif
  640. info.name = name.buffer();
  641. info.label = label.buffer();
  642. info.maker = maker.buffer();
  643. info.copyright = gCachedPluginsNullCharPtr;
  644. return &info;
  645. }
  646. #endif
  647. // -------------------------------------------------------------------------------------------------------------------
  648. uint carla_get_cached_plugin_count(CB::PluginType ptype, const char* pluginPath)
  649. {
  650. CARLA_SAFE_ASSERT_RETURN(isCachedPluginType(ptype), 0);
  651. carla_debug("carla_get_cached_plugin_count(%i:%s, %s)", ptype, CB::PluginType2Str(ptype), pluginPath);
  652. switch (ptype)
  653. {
  654. case CB::PLUGIN_INTERNAL: {
  655. uint32_t count = 0;
  656. carla_get_native_plugins_data(&count);
  657. return count;
  658. }
  659. case CB::PLUGIN_LV2: {
  660. Lv2WorldClass& lv2World(Lv2WorldClass::getInstance());
  661. lv2World.initIfNeeded(pluginPath);
  662. return lv2World.getPluginCount();
  663. }
  664. #if defined(USING_JUCE) && defined(CARLA_OS_MAC)
  665. case CB::PLUGIN_AU:
  666. findAUs();
  667. return static_cast<uint>(gCachedAuPluginResults.size());
  668. #endif
  669. #ifdef HAVE_SFZ
  670. case CB::PLUGIN_SFZ:
  671. findSFZs(pluginPath);
  672. return static_cast<uint>(gSFZs.size());
  673. #endif
  674. #ifdef HAVE_YSFX
  675. case CB::PLUGIN_JSFX:
  676. findJSFXs(pluginPath);
  677. return static_cast<uint>(gJSFXs.size());
  678. #endif
  679. default:
  680. return 0;
  681. }
  682. }
  683. const CarlaCachedPluginInfo* carla_get_cached_plugin_info(CB::PluginType ptype, uint index)
  684. {
  685. carla_debug("carla_get_cached_plugin_info(%i:%s, %i)", ptype, CB::PluginType2Str(ptype), index);
  686. switch (ptype)
  687. {
  688. case CB::PLUGIN_INTERNAL: {
  689. uint32_t count = 0;
  690. const NativePluginDescriptor* const descs(carla_get_native_plugins_data(&count));
  691. CARLA_SAFE_ASSERT_BREAK(index < count);
  692. CARLA_SAFE_ASSERT_BREAK(descs != nullptr);
  693. const NativePluginDescriptor& desc(descs[index]);
  694. return get_cached_plugin_internal(desc);
  695. }
  696. case CB::PLUGIN_LV2: {
  697. Lv2WorldClass& lv2World(Lv2WorldClass::getInstance());
  698. const LilvPlugin* const cPlugin(lv2World.getPluginFromIndex(index));
  699. CARLA_SAFE_ASSERT_BREAK(cPlugin != nullptr);
  700. Lilv::Plugin lilvPlugin(cPlugin);
  701. CARLA_SAFE_ASSERT_BREAK(lilvPlugin.get_uri().is_uri());
  702. return get_cached_plugin_lv2(lv2World, lilvPlugin);
  703. }
  704. #if defined(USING_JUCE) && defined(CARLA_OS_MAC)
  705. case CB::PLUGIN_AU:
  706. CARLA_SAFE_ASSERT_BREAK(index < static_cast<uint>(gCachedAuPluginResults.size()));
  707. return get_cached_plugin_au(gCachedAuPluginResults.strings.getUnchecked(static_cast<int>(index)));
  708. #endif
  709. #ifdef HAVE_SFZ
  710. case CB::PLUGIN_SFZ:
  711. CARLA_SAFE_ASSERT_BREAK(index < gSFZs.size());
  712. return get_cached_plugin_sfz(gSFZs[index]);
  713. #endif
  714. #ifdef HAVE_YSFX
  715. case CB::PLUGIN_JSFX:
  716. CARLA_SAFE_ASSERT_BREAK(index < static_cast<uint>(gJSFXs.size()));
  717. return get_cached_plugin_jsfx(gJSFXs[index]);
  718. #endif
  719. default:
  720. break;
  721. }
  722. static CarlaCachedPluginInfo info;
  723. return &info;
  724. }
  725. // -------------------------------------------------------------------------------------------------------------------
  726. #ifndef CARLA_PLUGIN_BUILD
  727. # include "../native-plugins/_data.cpp"
  728. #endif
  729. // -------------------------------------------------------------------------------------------------------------------