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.

976 lines
34KB

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