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.

CarlaUtils.cpp 28KB

9 years ago
9 years ago
9 years ago
9 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828
  1. /*
  2. * Carla Plugin Host
  3. * Copyright (C) 2011-2014 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 "CarlaBackendUtils.hpp"
  20. #include "CarlaLv2Utils.hpp"
  21. #include "CarlaPipeUtils.hpp"
  22. #include "CarlaThread.hpp"
  23. #include "LinkedList.hpp"
  24. #include "juce_audio_formats.h"
  25. #ifdef CARLA_OS_MAC
  26. # include "juce_audio_processors.h"
  27. #endif
  28. #include "../native-plugins/_data.cpp"
  29. namespace CB = CarlaBackend;
  30. static const char* const gNullCharPtr = "";
  31. #ifdef CARLA_OS_MAC
  32. static juce::StringArray gCachedAuPluginResults;
  33. #endif
  34. // -------------------------------------------------------------------------------------------------------------------
  35. _CarlaCachedPluginInfo::_CarlaCachedPluginInfo() noexcept
  36. : category(CB::PLUGIN_CATEGORY_NONE),
  37. hints(0x0),
  38. audioIns(0),
  39. audioOuts(0),
  40. midiIns(0),
  41. midiOuts(0),
  42. parameterIns(0),
  43. parameterOuts(0),
  44. name(gNullCharPtr),
  45. label(gNullCharPtr),
  46. maker(gNullCharPtr),
  47. copyright(gNullCharPtr) {}
  48. // -------------------------------------------------------------------------------------------------------------------
  49. const char* carla_get_complete_license_text()
  50. {
  51. carla_debug("carla_get_complete_license_text()");
  52. static CarlaString retText;
  53. if (retText.isEmpty())
  54. {
  55. retText =
  56. "<p>This current Carla build is using the following features and 3rd-party code:</p>"
  57. "<ul>"
  58. #if defined(CARLA_OS_MAC) || defined(CARLA_OS_WIN) || ! defined(VESTIGE_HEADER)
  59. # define LS_NOTE_NO "2"
  60. #else
  61. # define LS_NOTE_NO "1"
  62. #endif
  63. // Plugin formats
  64. "<li>LADSPA plugin support</li>"
  65. "<li>DSSI plugin support</li>"
  66. "<li>LV2 plugin support</li>"
  67. #ifdef VESTIGE_HEADER
  68. "<li>VST2 plugin support using VeSTige header by Javier Serrano Polo</li>"
  69. #else
  70. "<li>VST2 plugin support using official VST SDK 2.4 [1]</li>"
  71. #endif
  72. #if defined(CARLA_OS_MAC) || defined(CARLA_OS_WIN)
  73. "<li>VST3 plugin support using official VST SDK 3.6 [1]</li>"
  74. #endif
  75. #ifdef CARLA_OS_MAC
  76. "<li>AU plugin support</li>"
  77. #endif
  78. // Sample kit libraries
  79. #ifdef HAVE_FLUIDSYNTH
  80. "<li>FluidSynth library for SF2 support</li>"
  81. #endif
  82. #ifdef HAVE_LINUXSAMPLER
  83. "<li>LinuxSampler library for GIG and SFZ support [" LS_NOTE_NO "]</li>"
  84. #endif
  85. // misc libs
  86. "<li>base64 utilities based on code by Ren\u00E9 Nyffenegger</li>"
  87. #ifdef CARLA_OS_MAC
  88. "<li>sem_timedwait for Mac OS by Keith Shortridge</li>"
  89. #endif
  90. "<li>liblo library for OSC support</li>"
  91. "<li>rtmempool library by Nedko Arnaudov"
  92. "<li>serd, sord, sratom and lilv libraries for LV2 discovery</li>"
  93. #if ! (defined(CARLA_OS_MAC) || defined(CARLA_OS_WIN))
  94. "<li>RtAudio and RtMidi libraries for extra Audio and MIDI support</li>"
  95. #endif
  96. // Internal plugins
  97. #ifdef HAVE_EXPERIMENTAL_PLUGINS
  98. "<li>AT1, BLS1 and REV1 plugin code by Fons Adriaensen</li>"
  99. #endif
  100. "<li>MIDI Sequencer UI code by Perry Nguyen</li>"
  101. "<li>MVerb plugin code by Martin Eastwood</li>"
  102. "<li>Nekobi plugin code based on nekobee by Sean Bolton and others</li>"
  103. "<li>NekoFilter plugin code based on lv2fil by Nedko Arnaudov and Fons Adriaensen</li>"
  104. #ifdef HAVE_ZYN_DEPS
  105. "<li>ZynAddSubFX plugin code by Mark McCurry and Nasca Octavian Paul</li>"
  106. #endif
  107. // end
  108. "</ul>"
  109. "<p>"
  110. #if defined(CARLA_OS_MAC) || defined(CARLA_OS_WIN) || ! defined(VESTIGE_HEADER)
  111. // Required by VST SDK
  112. "&nbsp;[1] Trademark of Steinberg Media Technologies GmbH.<br/>"
  113. #endif
  114. #ifdef HAVE_LINUXSAMPLER
  115. // LinuxSampler GPL exception
  116. "&nbsp;[" LS_NOTE_NO "] Using LinuxSampler code in commercial hardware or software products is not allowed without prior written authorization by the authors."
  117. #endif
  118. "</p>"
  119. ;
  120. }
  121. return retText;
  122. }
  123. const char* carla_get_juce_version()
  124. {
  125. carla_debug("carla_get_juce_version()");
  126. static CarlaString retVersion;
  127. if (retVersion.isEmpty())
  128. {
  129. if (const char* const version = juce::SystemStats::getJUCEVersion().toRawUTF8())
  130. retVersion = version+6;
  131. else
  132. retVersion = "3.0";
  133. }
  134. return retVersion;
  135. }
  136. const char* carla_get_supported_file_extensions()
  137. {
  138. carla_debug("carla_get_supported_file_extensions()");
  139. static CarlaString retText;
  140. if (retText.isEmpty())
  141. {
  142. retText =
  143. // Base types
  144. "*.carxp;*.carxs"
  145. // MIDI files
  146. ";*.mid;*.midi"
  147. #ifdef HAVE_FLUIDSYNTH
  148. // fluidsynth (sf2)
  149. ";*.sf2"
  150. #endif
  151. #ifdef HAVE_LINUXSAMPLER
  152. // linuxsampler (gig and sfz)
  153. ";*.gig;*.sfz"
  154. #endif
  155. #ifdef HAVE_ZYN_DEPS
  156. // zynaddsubfx presets
  157. ";*.xmz;*.xiz"
  158. #endif
  159. ;
  160. // Audio files
  161. {
  162. using namespace juce;
  163. AudioFormatManager afm;
  164. afm.registerBasicFormats();
  165. String juceFormats;
  166. for (AudioFormat **it=afm.begin(), **end=afm.end(); it != end; ++it)
  167. {
  168. const StringArray& exts((*it)->getFileExtensions());
  169. for (String *eit=exts.begin(), *eend=exts.end(); eit != eend; ++eit)
  170. juceFormats += String(";*" + (*eit)).toRawUTF8();
  171. }
  172. retText += juceFormats.toRawUTF8();
  173. }
  174. }
  175. return retText;
  176. }
  177. // -------------------------------------------------------------------------------------------------------------------
  178. uint carla_get_cached_plugin_count(CB::PluginType ptype, const char* pluginPath)
  179. {
  180. CARLA_SAFE_ASSERT_RETURN(ptype == CB::PLUGIN_INTERNAL || ptype == CB::PLUGIN_LV2 || ptype == CB::PLUGIN_AU, 0);
  181. carla_debug("carla_get_cached_plugin_count(%i:%s)", ptype, CB::PluginType2Str(ptype));
  182. switch (ptype)
  183. {
  184. case CB::PLUGIN_INTERNAL: {
  185. uint32_t count = 0;
  186. carla_get_native_plugins_data(&count);
  187. return count;
  188. }
  189. case CB::PLUGIN_LV2: {
  190. Lv2WorldClass& lv2World(Lv2WorldClass::getInstance());
  191. lv2World.initIfNeeded(pluginPath);
  192. return lv2World.getPluginCount();
  193. }
  194. case CB::PLUGIN_AU: {
  195. #ifdef CARLA_OS_MAC
  196. static bool initiated = false;
  197. if (initiated)
  198. return static_cast<uint>(gCachedAuPluginResults.size());
  199. using namespace juce;
  200. initiated = true;
  201. AudioUnitPluginFormat auFormat;
  202. gCachedAuPluginResults = auFormat.searchPathsForPlugins(juce::FileSearchPath(), false);
  203. return static_cast<uint>(gCachedAuPluginResults.size());
  204. #else
  205. return 0;
  206. #endif
  207. }
  208. default:
  209. return 0;
  210. }
  211. }
  212. const CarlaCachedPluginInfo* carla_get_cached_plugin_info(CB::PluginType ptype, uint index)
  213. {
  214. carla_debug("carla_get_cached_plugin_info(%i:%s, %i)", ptype, CB::PluginType2Str(ptype), index);
  215. static CarlaCachedPluginInfo info;
  216. switch (ptype)
  217. {
  218. case CB::PLUGIN_INTERNAL: {
  219. uint32_t count = 0;
  220. const NativePluginDescriptor* const descs(carla_get_native_plugins_data(&count));
  221. CARLA_SAFE_ASSERT_BREAK(index < count);
  222. CARLA_SAFE_ASSERT_BREAK(descs != nullptr);
  223. const NativePluginDescriptor& desc(descs[index]);
  224. info.category = static_cast<CB::PluginCategory>(desc.category);
  225. info.hints = 0x0;
  226. if (desc.hints & NATIVE_PLUGIN_IS_RTSAFE)
  227. info.hints |= CB::PLUGIN_IS_RTSAFE;
  228. if (desc.hints & NATIVE_PLUGIN_IS_SYNTH)
  229. info.hints |= CB::PLUGIN_IS_SYNTH;
  230. if (desc.hints & NATIVE_PLUGIN_HAS_UI)
  231. info.hints |= CB::PLUGIN_HAS_CUSTOM_UI;
  232. if (desc.hints & NATIVE_PLUGIN_NEEDS_FIXED_BUFFERS)
  233. info.hints |= CB::PLUGIN_NEEDS_FIXED_BUFFERS;
  234. if (desc.hints & NATIVE_PLUGIN_NEEDS_UI_MAIN_THREAD)
  235. info.hints |= CB::PLUGIN_NEEDS_UI_MAIN_THREAD;
  236. if (desc.hints & NATIVE_PLUGIN_USES_MULTI_PROGS)
  237. info.hints |= CB::PLUGIN_USES_MULTI_PROGS;
  238. info.audioIns = desc.audioIns;
  239. info.audioOuts = desc.audioOuts;
  240. info.midiIns = desc.midiIns;
  241. info.midiOuts = desc.midiOuts;
  242. info.parameterIns = desc.paramIns;
  243. info.parameterOuts = desc.paramOuts;
  244. info.name = desc.name;
  245. info.label = desc.label;
  246. info.maker = desc.maker;
  247. info.copyright = desc.copyright;
  248. return &info;
  249. }
  250. case CB::PLUGIN_LV2: {
  251. Lv2WorldClass& lv2World(Lv2WorldClass::getInstance());
  252. const LilvPlugin* const cPlugin(lv2World.getPluginFromIndex(index));
  253. CARLA_SAFE_ASSERT_BREAK(cPlugin != nullptr);
  254. Lilv::Plugin lilvPlugin(cPlugin);
  255. CARLA_SAFE_ASSERT_BREAK(lilvPlugin.get_uri().is_uri());
  256. carla_stdout("Filling info for LV2 with URI '%s'", lilvPlugin.get_uri().as_uri());
  257. // features
  258. info.hints = 0x0;
  259. if (lilvPlugin.get_uis().size() > 0 || lilvPlugin.get_modgui_resources_directory().as_uri() != nullptr)
  260. info.hints |= CB::PLUGIN_HAS_CUSTOM_UI;
  261. {
  262. Lilv::Nodes lilvFeatureNodes(lilvPlugin.get_supported_features());
  263. LILV_FOREACH(nodes, it, lilvFeatureNodes)
  264. {
  265. Lilv::Node lilvFeatureNode(lilvFeatureNodes.get(it));
  266. const char* const featureURI(lilvFeatureNode.as_uri());
  267. CARLA_SAFE_ASSERT_CONTINUE(featureURI != nullptr);
  268. if (std::strcmp(featureURI, LV2_CORE__hardRTCapable) == 0)
  269. info.hints |= CB::PLUGIN_IS_RTSAFE;
  270. }
  271. lilv_nodes_free(const_cast<LilvNodes*>(lilvFeatureNodes.me));
  272. }
  273. // category
  274. info.category = CB::PLUGIN_CATEGORY_NONE;
  275. {
  276. Lilv::Nodes typeNodes(lilvPlugin.get_value(lv2World.rdf_type));
  277. if (typeNodes.size() > 0)
  278. {
  279. if (typeNodes.contains(lv2World.class_allpass))
  280. info.category = CB::PLUGIN_CATEGORY_FILTER;
  281. if (typeNodes.contains(lv2World.class_amplifier))
  282. info.category = CB::PLUGIN_CATEGORY_DYNAMICS;
  283. if (typeNodes.contains(lv2World.class_analyzer))
  284. info.category = CB::PLUGIN_CATEGORY_UTILITY;
  285. if (typeNodes.contains(lv2World.class_bandpass))
  286. info.category = CB::PLUGIN_CATEGORY_FILTER;
  287. if (typeNodes.contains(lv2World.class_chorus))
  288. info.category = CB::PLUGIN_CATEGORY_MODULATOR;
  289. if (typeNodes.contains(lv2World.class_comb))
  290. info.category = CB::PLUGIN_CATEGORY_FILTER;
  291. if (typeNodes.contains(lv2World.class_compressor))
  292. info.category = CB::PLUGIN_CATEGORY_DYNAMICS;
  293. if (typeNodes.contains(lv2World.class_constant))
  294. info.category = CB::PLUGIN_CATEGORY_OTHER;
  295. if (typeNodes.contains(lv2World.class_converter))
  296. info.category = CB::PLUGIN_CATEGORY_UTILITY;
  297. if (typeNodes.contains(lv2World.class_delay))
  298. info.category = CB::PLUGIN_CATEGORY_DELAY;
  299. if (typeNodes.contains(lv2World.class_distortion))
  300. info.category = CB::PLUGIN_CATEGORY_DISTORTION;
  301. if (typeNodes.contains(lv2World.class_dynamics))
  302. info.category = CB::PLUGIN_CATEGORY_DYNAMICS;
  303. if (typeNodes.contains(lv2World.class_eq))
  304. info.category = CB::PLUGIN_CATEGORY_EQ;
  305. if (typeNodes.contains(lv2World.class_envelope))
  306. info.category = CB::PLUGIN_CATEGORY_DYNAMICS;
  307. if (typeNodes.contains(lv2World.class_expander))
  308. info.category = CB::PLUGIN_CATEGORY_DYNAMICS;
  309. if (typeNodes.contains(lv2World.class_filter))
  310. info.category = CB::PLUGIN_CATEGORY_FILTER;
  311. if (typeNodes.contains(lv2World.class_flanger))
  312. info.category = CB::PLUGIN_CATEGORY_MODULATOR;
  313. if (typeNodes.contains(lv2World.class_function))
  314. info.category = CB::PLUGIN_CATEGORY_UTILITY;
  315. if (typeNodes.contains(lv2World.class_gate))
  316. info.category = CB::PLUGIN_CATEGORY_DYNAMICS;
  317. if (typeNodes.contains(lv2World.class_generator))
  318. info.category = CB::PLUGIN_CATEGORY_OTHER;
  319. if (typeNodes.contains(lv2World.class_highpass))
  320. info.category = CB::PLUGIN_CATEGORY_FILTER;
  321. if (typeNodes.contains(lv2World.class_limiter))
  322. info.category = CB::PLUGIN_CATEGORY_DYNAMICS;
  323. if (typeNodes.contains(lv2World.class_lowpass))
  324. info.category = CB::PLUGIN_CATEGORY_FILTER;
  325. if (typeNodes.contains(lv2World.class_mixer))
  326. info.category = CB::PLUGIN_CATEGORY_UTILITY;
  327. if (typeNodes.contains(lv2World.class_modulator))
  328. info.category = CB::PLUGIN_CATEGORY_MODULATOR;
  329. if (typeNodes.contains(lv2World.class_multiEQ))
  330. info.category = CB::PLUGIN_CATEGORY_EQ;
  331. if (typeNodes.contains(lv2World.class_oscillator))
  332. info.category = CB::PLUGIN_CATEGORY_OTHER;
  333. if (typeNodes.contains(lv2World.class_paraEQ))
  334. info.category = CB::PLUGIN_CATEGORY_EQ;
  335. if (typeNodes.contains(lv2World.class_phaser))
  336. info.category = CB::PLUGIN_CATEGORY_MODULATOR;
  337. if (typeNodes.contains(lv2World.class_pitch))
  338. info.category = CB::PLUGIN_CATEGORY_OTHER;
  339. if (typeNodes.contains(lv2World.class_reverb))
  340. info.category = CB::PLUGIN_CATEGORY_DELAY;
  341. if (typeNodes.contains(lv2World.class_simulator))
  342. info.category = CB::PLUGIN_CATEGORY_OTHER;
  343. if (typeNodes.contains(lv2World.class_spatial))
  344. info.category = CB::PLUGIN_CATEGORY_OTHER;
  345. if (typeNodes.contains(lv2World.class_spectral))
  346. info.category = CB::PLUGIN_CATEGORY_OTHER;
  347. if (typeNodes.contains(lv2World.class_utility))
  348. info.category = CB::PLUGIN_CATEGORY_UTILITY;
  349. if (typeNodes.contains(lv2World.class_waveshaper))
  350. info.category = CB::PLUGIN_CATEGORY_DISTORTION;
  351. if (typeNodes.contains(lv2World.class_instrument))
  352. {
  353. info.category = CB::PLUGIN_CATEGORY_SYNTH;
  354. info.hints |= CB::PLUGIN_IS_SYNTH;
  355. }
  356. }
  357. lilv_nodes_free(const_cast<LilvNodes*>(typeNodes.me));
  358. }
  359. // number data
  360. info.audioIns = 0;
  361. info.audioOuts = 0;
  362. info.midiIns = 0;
  363. info.midiOuts = 0;
  364. info.parameterIns = 0;
  365. info.parameterOuts = 0;
  366. for (uint i=0, count=lilvPlugin.get_num_ports(); i<count; ++i)
  367. {
  368. Lilv::Port lilvPort(lilvPlugin.get_port_by_index(i));
  369. bool isInput;
  370. /**/ if (lilvPort.is_a(lv2World.port_input))
  371. isInput = true;
  372. else if (lilvPort.is_a(lv2World.port_output))
  373. isInput = false;
  374. else
  375. continue;
  376. /**/ if (lilvPort.is_a(lv2World.port_control))
  377. {
  378. // skip some control ports
  379. if (lilvPort.has_property(lv2World.reportsLatency))
  380. continue;
  381. if (LilvNode* const designationNode = lilv_port_get(lilvPort.parent, lilvPort.me, lv2World.designation.me))
  382. {
  383. bool skip = false;
  384. if (const char* const designation = lilv_node_as_string(designationNode))
  385. {
  386. /**/ if (std::strcmp(designation, LV2_CORE__control) == 0)
  387. skip = true;
  388. else if (std::strcmp(designation, LV2_CORE__freeWheeling) == 0)
  389. skip = true;
  390. else if (std::strcmp(designation, LV2_CORE__latency) == 0)
  391. skip = true;
  392. else if (std::strcmp(designation, LV2_PARAMETERS__sampleRate) == 0)
  393. skip = true;
  394. else if (std::strcmp(designation, LV2_TIME__bar) == 0)
  395. skip = true;
  396. else if (std::strcmp(designation, LV2_TIME__barBeat) == 0)
  397. skip = true;
  398. else if (std::strcmp(designation, LV2_TIME__beat) == 0)
  399. skip = true;
  400. else if (std::strcmp(designation, LV2_TIME__beatUnit) == 0)
  401. skip = true;
  402. else if (std::strcmp(designation, LV2_TIME__beatsPerBar) == 0)
  403. skip = true;
  404. else if (std::strcmp(designation, LV2_TIME__beatsPerMinute) == 0)
  405. skip = true;
  406. else if (std::strcmp(designation, LV2_TIME__frame) == 0)
  407. skip = true;
  408. else if (std::strcmp(designation, LV2_TIME__framesPerSecond) == 0)
  409. skip = true;
  410. else if (std::strcmp(designation, LV2_TIME__speed) == 0)
  411. skip = true;
  412. else if (std::strcmp(designation, LV2_KXSTUDIO_PROPERTIES__TimePositionTicksPerBeat) == 0)
  413. skip = true;
  414. }
  415. lilv_node_free(designationNode);
  416. if (skip)
  417. continue;
  418. }
  419. if (isInput)
  420. ++(info.parameterIns);
  421. else
  422. ++(info.parameterOuts);
  423. }
  424. else if (lilvPort.is_a(lv2World.port_audio))
  425. {
  426. if (isInput)
  427. ++(info.audioIns);
  428. else
  429. ++(info.audioOuts);
  430. }
  431. else if (lilvPort.is_a(lv2World.port_cv))
  432. {
  433. }
  434. else if (lilvPort.is_a(lv2World.port_atom))
  435. {
  436. Lilv::Nodes supportNodes(lilvPort.get_value(lv2World.atom_supports));
  437. for (LilvIter *it = lilv_nodes_begin(supportNodes.me); ! lilv_nodes_is_end(supportNodes.me, it); it = lilv_nodes_next(supportNodes.me, it))
  438. {
  439. const Lilv::Node node(lilv_nodes_get(supportNodes.me, it));
  440. CARLA_SAFE_ASSERT_CONTINUE(node.is_uri());
  441. if (node.equals(lv2World.midi_event))
  442. {
  443. if (isInput)
  444. ++(info.midiIns);
  445. else
  446. ++(info.midiOuts);
  447. }
  448. }
  449. lilv_nodes_free(const_cast<LilvNodes*>(supportNodes.me));
  450. }
  451. else if (lilvPort.is_a(lv2World.port_event))
  452. {
  453. if (lilvPort.supports_event(lv2World.midi_event))
  454. {
  455. if (isInput)
  456. ++(info.midiIns);
  457. else
  458. ++(info.midiOuts);
  459. }
  460. }
  461. else if (lilvPort.is_a(lv2World.port_midi))
  462. {
  463. if (isInput)
  464. ++(info.midiIns);
  465. else
  466. ++(info.midiOuts);
  467. }
  468. }
  469. // text data
  470. static CarlaString suri, sname, smaker, slicense;
  471. suri.clear(); sname.clear(); smaker.clear(); slicense.clear();
  472. suri = lilvPlugin.get_uri().as_uri();
  473. if (const char* const name = lilvPlugin.get_name().as_string())
  474. sname = name;
  475. else
  476. sname.clear();
  477. if (const char* const author = lilvPlugin.get_author_name().as_string())
  478. smaker = author;
  479. else
  480. smaker.clear();
  481. Lilv::Nodes licenseNodes(lilvPlugin.get_value(lv2World.doap_license));
  482. if (licenseNodes.size() > 0)
  483. {
  484. if (const char* const license = licenseNodes.get_first().as_string())
  485. slicense = license;
  486. }
  487. lilv_nodes_free(const_cast<LilvNodes*>(licenseNodes.me));
  488. info.name = sname;
  489. info.label = suri;
  490. info.maker = smaker;
  491. info.copyright = slicense;
  492. return &info;
  493. }
  494. case CB::PLUGIN_AU: {
  495. #ifdef CARLA_OS_MAC
  496. const int indexi(static_cast<int>(index));
  497. CARLA_SAFE_ASSERT_BREAK(indexi < gCachedAuPluginResults.size());
  498. using namespace juce;
  499. String pluginId(gCachedAuPluginResults[indexi]);
  500. OwnedArray<PluginDescription> results;
  501. AudioUnitPluginFormat auFormat;
  502. auFormat.findAllTypesForFile(results, pluginId);
  503. CARLA_SAFE_ASSERT_BREAK(results.size() > 0);
  504. CARLA_SAFE_ASSERT(results.size() == 1);
  505. PluginDescription* const desc(results[0]);
  506. CARLA_SAFE_ASSERT_BREAK(desc != nullptr);
  507. info.category = CB::getPluginCategoryFromName(desc->category.toRawUTF8());
  508. info.hints = 0x0;
  509. if (desc->isInstrument)
  510. info.hints |= CB::PLUGIN_IS_SYNTH;
  511. if (true)
  512. info.hints |= CB::PLUGIN_HAS_CUSTOM_UI;
  513. info.audioIns = static_cast<uint32_t>(desc->numInputChannels);
  514. info.audioOuts = static_cast<uint32_t>(desc->numOutputChannels);
  515. info.midiIns = desc->isInstrument ? 1 : 0;
  516. info.midiOuts = 0;
  517. info.parameterIns = 0;
  518. info.parameterOuts = 0;
  519. static CarlaString sname, slabel, smaker;
  520. sname = desc->name.toRawUTF8();
  521. slabel = desc->fileOrIdentifier.toRawUTF8();
  522. smaker = desc->manufacturerName.toRawUTF8();
  523. info.name = sname;
  524. info.label = slabel;
  525. info.maker = smaker;
  526. info.copyright = gNullCharPtr;
  527. return &info;
  528. #else
  529. break;
  530. #endif
  531. }
  532. default:
  533. break;
  534. }
  535. info.category = CB::PLUGIN_CATEGORY_NONE;
  536. info.hints = 0x0;
  537. info.audioIns = 0;
  538. info.audioOuts = 0;
  539. info.midiIns = 0;
  540. info.midiOuts = 0;
  541. info.parameterIns = 0;
  542. info.parameterOuts = 0;
  543. info.name = gNullCharPtr;
  544. info.label = gNullCharPtr;
  545. info.maker = gNullCharPtr;
  546. info.copyright = gNullCharPtr;
  547. return &info;
  548. }
  549. // -------------------------------------------------------------------------------------------------------------------
  550. void carla_set_process_name(const char* name)
  551. {
  552. carla_debug("carla_set_process_name(\"%s\")", name);
  553. CarlaThread::setCurrentThreadName(name);
  554. juce::Thread::setCurrentThreadName(name);
  555. }
  556. // -------------------------------------------------------------------------------------------------------------------
  557. class CarlaPipeClientPlugin : public CarlaPipeClient
  558. {
  559. public:
  560. CarlaPipeClientPlugin(const CarlaPipeCallbackFunc callbackFunc, void* const callbackPtr) noexcept
  561. : CarlaPipeClient(),
  562. fCallbackFunc(callbackFunc),
  563. fCallbackPtr(callbackPtr)
  564. {
  565. CARLA_SAFE_ASSERT(fCallbackFunc != nullptr);
  566. }
  567. const char* readlineblock(const uint timeout) noexcept
  568. {
  569. return CarlaPipeClient::_readlineblock(timeout);
  570. }
  571. bool msgReceived(const char* const msg) noexcept
  572. {
  573. if (fCallbackFunc != nullptr)
  574. {
  575. try {
  576. fCallbackFunc(fCallbackPtr, msg);
  577. } CARLA_SAFE_EXCEPTION("msgReceived");
  578. }
  579. return true;
  580. }
  581. private:
  582. const CarlaPipeCallbackFunc fCallbackFunc;
  583. void* const fCallbackPtr;
  584. CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(CarlaPipeClientPlugin)
  585. };
  586. CarlaPipeClientHandle carla_pipe_client_new(const char* argv[], CarlaPipeCallbackFunc callbackFunc, void* callbackPtr)
  587. {
  588. carla_debug("carla_pipe_client_new(%p, %p, %p)", argv, callbackFunc, callbackPtr);
  589. CarlaPipeClientPlugin* const pipe(new CarlaPipeClientPlugin(callbackFunc, callbackPtr));
  590. if (! pipe->initPipeClient(argv))
  591. {
  592. delete pipe;
  593. return nullptr;
  594. }
  595. return pipe;
  596. }
  597. void carla_pipe_client_idle(CarlaPipeClientHandle handle)
  598. {
  599. CARLA_SAFE_ASSERT_RETURN(handle != nullptr,);
  600. ((CarlaPipeClientPlugin*)handle)->idlePipe();
  601. }
  602. bool carla_pipe_client_is_running(CarlaPipeClientHandle handle)
  603. {
  604. CARLA_SAFE_ASSERT_RETURN(handle != nullptr, false);
  605. return ((CarlaPipeClientPlugin*)handle)->isPipeRunning();
  606. }
  607. void carla_pipe_client_lock(CarlaPipeClientHandle handle)
  608. {
  609. CARLA_SAFE_ASSERT_RETURN(handle != nullptr,);
  610. return ((CarlaPipeClientPlugin*)handle)->lockPipe();
  611. }
  612. void carla_pipe_client_unlock(CarlaPipeClientHandle handle)
  613. {
  614. CARLA_SAFE_ASSERT_RETURN(handle != nullptr,);
  615. return ((CarlaPipeClientPlugin*)handle)->unlockPipe();
  616. }
  617. const char* carla_pipe_client_readlineblock(CarlaPipeClientHandle handle, uint timeout)
  618. {
  619. CARLA_SAFE_ASSERT_RETURN(handle != nullptr, nullptr);
  620. return ((CarlaPipeClientPlugin*)handle)->readlineblock(timeout);
  621. }
  622. bool carla_pipe_client_write_msg(CarlaPipeClientHandle handle, const char* msg)
  623. {
  624. CARLA_SAFE_ASSERT_RETURN(handle != nullptr, false);
  625. return ((CarlaPipeClientPlugin*)handle)->writeMessage(msg);
  626. }
  627. bool carla_pipe_client_write_and_fix_msg(CarlaPipeClientHandle handle, const char* msg)
  628. {
  629. CARLA_SAFE_ASSERT_RETURN(handle != nullptr, false);
  630. return ((CarlaPipeClientPlugin*)handle)->writeAndFixMessage(msg);
  631. }
  632. bool carla_pipe_client_flush(CarlaPipeClientHandle handle)
  633. {
  634. CARLA_SAFE_ASSERT_RETURN(handle != nullptr, false);
  635. return ((CarlaPipeClientPlugin*)handle)->flushMessages();
  636. }
  637. bool carla_pipe_client_flush_and_unlock(CarlaPipeClientHandle handle)
  638. {
  639. CARLA_SAFE_ASSERT_RETURN(handle != nullptr, false);
  640. CarlaPipeClientPlugin* const pipe((CarlaPipeClientPlugin*)handle);
  641. const bool ret(pipe->flushMessages());
  642. pipe->unlockPipe();
  643. return ret;
  644. }
  645. void carla_pipe_client_destroy(CarlaPipeClientHandle handle)
  646. {
  647. CARLA_SAFE_ASSERT_RETURN(handle != nullptr,);
  648. carla_debug("carla_pipe_client_destroy(%p)", handle);
  649. CarlaPipeClientPlugin* const pipe((CarlaPipeClientPlugin*)handle);
  650. pipe->closePipeClient();
  651. delete pipe;
  652. }
  653. // -------------------------------------------------------------------------------------------------------------------
  654. const char* carla_get_library_filename()
  655. {
  656. carla_debug("carla_get_library_filename()");
  657. static CarlaString ret;
  658. if (ret.isEmpty())
  659. {
  660. using juce::File;
  661. ret = File(File::getSpecialLocation(File::currentExecutableFile)).getFullPathName().toRawUTF8();
  662. }
  663. return ret;
  664. }
  665. const char* carla_get_library_folder()
  666. {
  667. carla_debug("carla_get_library_folder()");
  668. static CarlaString ret;
  669. if (ret.isEmpty())
  670. {
  671. using juce::File;
  672. ret = File(File::getSpecialLocation(File::currentExecutableFile).getParentDirectory()).getFullPathName().toRawUTF8();
  673. }
  674. return ret;
  675. }
  676. // -------------------------------------------------------------------------------------------------------------------
  677. #include "CarlaPipeUtils.cpp"
  678. // -------------------------------------------------------------------------------------------------------------------