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.

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