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.

969 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_UI_MAIN_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_UI_MAIN_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_UI_MAIN_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_UI_MAIN_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_UI_MAIN_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_UI_MAIN_THREAD)
  366. info.hints |= CB::PLUGIN_NEEDS_UI_MAIN_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 (lilvPlugin.get_uis().size() > 0 /*|| lilvPlugin.get_modgui_resources_directory().as_uri() != nullptr*/)
  389. info.hints |= CB::PLUGIN_HAS_CUSTOM_UI;
  390. {
  391. Lilv::Nodes lilvFeatureNodes(lilvPlugin.get_supported_features());
  392. LILV_FOREACH(nodes, it, lilvFeatureNodes)
  393. {
  394. Lilv::Node lilvFeatureNode(lilvFeatureNodes.get(it));
  395. const char* const featureURI(lilvFeatureNode.as_uri());
  396. CARLA_SAFE_ASSERT_CONTINUE(featureURI != nullptr);
  397. if (std::strcmp(featureURI, LV2_CORE__hardRTCapable) == 0)
  398. info.hints |= CB::PLUGIN_IS_RTSAFE;
  399. }
  400. lilv_nodes_free(const_cast<LilvNodes*>(lilvFeatureNodes.me));
  401. }
  402. // category
  403. info.category = CB::PLUGIN_CATEGORY_NONE;
  404. {
  405. Lilv::Nodes typeNodes(lilvPlugin.get_value(lv2World.rdf_type));
  406. if (typeNodes.size() > 0)
  407. {
  408. if (typeNodes.contains(lv2World.class_allpass))
  409. info.category = CB::PLUGIN_CATEGORY_FILTER;
  410. if (typeNodes.contains(lv2World.class_amplifier))
  411. info.category = CB::PLUGIN_CATEGORY_DYNAMICS;
  412. if (typeNodes.contains(lv2World.class_analyzer))
  413. info.category = CB::PLUGIN_CATEGORY_UTILITY;
  414. if (typeNodes.contains(lv2World.class_bandpass))
  415. info.category = CB::PLUGIN_CATEGORY_FILTER;
  416. if (typeNodes.contains(lv2World.class_chorus))
  417. info.category = CB::PLUGIN_CATEGORY_MODULATOR;
  418. if (typeNodes.contains(lv2World.class_comb))
  419. info.category = CB::PLUGIN_CATEGORY_FILTER;
  420. if (typeNodes.contains(lv2World.class_compressor))
  421. info.category = CB::PLUGIN_CATEGORY_DYNAMICS;
  422. if (typeNodes.contains(lv2World.class_constant))
  423. info.category = CB::PLUGIN_CATEGORY_OTHER;
  424. if (typeNodes.contains(lv2World.class_converter))
  425. info.category = CB::PLUGIN_CATEGORY_UTILITY;
  426. if (typeNodes.contains(lv2World.class_delay))
  427. info.category = CB::PLUGIN_CATEGORY_DELAY;
  428. if (typeNodes.contains(lv2World.class_distortion))
  429. info.category = CB::PLUGIN_CATEGORY_DISTORTION;
  430. if (typeNodes.contains(lv2World.class_dynamics))
  431. info.category = CB::PLUGIN_CATEGORY_DYNAMICS;
  432. if (typeNodes.contains(lv2World.class_eq))
  433. info.category = CB::PLUGIN_CATEGORY_EQ;
  434. if (typeNodes.contains(lv2World.class_envelope))
  435. info.category = CB::PLUGIN_CATEGORY_DYNAMICS;
  436. if (typeNodes.contains(lv2World.class_expander))
  437. info.category = CB::PLUGIN_CATEGORY_DYNAMICS;
  438. if (typeNodes.contains(lv2World.class_filter))
  439. info.category = CB::PLUGIN_CATEGORY_FILTER;
  440. if (typeNodes.contains(lv2World.class_flanger))
  441. info.category = CB::PLUGIN_CATEGORY_MODULATOR;
  442. if (typeNodes.contains(lv2World.class_function))
  443. info.category = CB::PLUGIN_CATEGORY_UTILITY;
  444. if (typeNodes.contains(lv2World.class_gate))
  445. info.category = CB::PLUGIN_CATEGORY_DYNAMICS;
  446. if (typeNodes.contains(lv2World.class_generator))
  447. info.category = CB::PLUGIN_CATEGORY_OTHER;
  448. if (typeNodes.contains(lv2World.class_highpass))
  449. info.category = CB::PLUGIN_CATEGORY_FILTER;
  450. if (typeNodes.contains(lv2World.class_limiter))
  451. info.category = CB::PLUGIN_CATEGORY_DYNAMICS;
  452. if (typeNodes.contains(lv2World.class_lowpass))
  453. info.category = CB::PLUGIN_CATEGORY_FILTER;
  454. if (typeNodes.contains(lv2World.class_mixer))
  455. info.category = CB::PLUGIN_CATEGORY_UTILITY;
  456. if (typeNodes.contains(lv2World.class_modulator))
  457. info.category = CB::PLUGIN_CATEGORY_MODULATOR;
  458. if (typeNodes.contains(lv2World.class_multiEQ))
  459. info.category = CB::PLUGIN_CATEGORY_EQ;
  460. if (typeNodes.contains(lv2World.class_oscillator))
  461. info.category = CB::PLUGIN_CATEGORY_OTHER;
  462. if (typeNodes.contains(lv2World.class_paraEQ))
  463. info.category = CB::PLUGIN_CATEGORY_EQ;
  464. if (typeNodes.contains(lv2World.class_phaser))
  465. info.category = CB::PLUGIN_CATEGORY_MODULATOR;
  466. if (typeNodes.contains(lv2World.class_pitch))
  467. info.category = CB::PLUGIN_CATEGORY_OTHER;
  468. if (typeNodes.contains(lv2World.class_reverb))
  469. info.category = CB::PLUGIN_CATEGORY_DELAY;
  470. if (typeNodes.contains(lv2World.class_simulator))
  471. info.category = CB::PLUGIN_CATEGORY_OTHER;
  472. if (typeNodes.contains(lv2World.class_spatial))
  473. info.category = CB::PLUGIN_CATEGORY_OTHER;
  474. if (typeNodes.contains(lv2World.class_spectral))
  475. info.category = CB::PLUGIN_CATEGORY_OTHER;
  476. if (typeNodes.contains(lv2World.class_utility))
  477. info.category = CB::PLUGIN_CATEGORY_UTILITY;
  478. if (typeNodes.contains(lv2World.class_waveshaper))
  479. info.category = CB::PLUGIN_CATEGORY_DISTORTION;
  480. if (typeNodes.contains(lv2World.class_instrument))
  481. {
  482. info.category = CB::PLUGIN_CATEGORY_SYNTH;
  483. info.hints |= CB::PLUGIN_IS_SYNTH;
  484. }
  485. }
  486. lilv_nodes_free(const_cast<LilvNodes*>(typeNodes.me));
  487. }
  488. // number data
  489. info.audioIns = 0;
  490. info.audioOuts = 0;
  491. info.midiIns = 0;
  492. info.midiOuts = 0;
  493. info.parameterIns = 0;
  494. info.parameterOuts = 0;
  495. for (uint i=0, count=lilvPlugin.get_num_ports(); i<count; ++i)
  496. {
  497. Lilv::Port lilvPort(lilvPlugin.get_port_by_index(i));
  498. bool isInput;
  499. /**/ if (lilvPort.is_a(lv2World.port_input))
  500. isInput = true;
  501. else if (lilvPort.is_a(lv2World.port_output))
  502. isInput = false;
  503. else
  504. continue;
  505. /**/ if (lilvPort.is_a(lv2World.port_control))
  506. {
  507. // skip some control ports
  508. if (lilvPort.has_property(lv2World.reportsLatency))
  509. continue;
  510. if (LilvNode* const designationNode = lilv_port_get(lilvPort.parent, lilvPort.me, lv2World.designation.me))
  511. {
  512. bool skip = false;
  513. if (const char* const designation = lilv_node_as_string(designationNode))
  514. {
  515. /**/ if (std::strcmp(designation, LV2_CORE__control) == 0)
  516. skip = true;
  517. else if (std::strcmp(designation, LV2_CORE__freeWheeling) == 0)
  518. skip = true;
  519. else if (std::strcmp(designation, LV2_CORE__latency) == 0)
  520. skip = true;
  521. else if (std::strcmp(designation, LV2_PARAMETERS__sampleRate) == 0)
  522. skip = true;
  523. else if (std::strcmp(designation, LV2_TIME__bar) == 0)
  524. skip = true;
  525. else if (std::strcmp(designation, LV2_TIME__barBeat) == 0)
  526. skip = true;
  527. else if (std::strcmp(designation, LV2_TIME__beat) == 0)
  528. skip = true;
  529. else if (std::strcmp(designation, LV2_TIME__beatUnit) == 0)
  530. skip = true;
  531. else if (std::strcmp(designation, LV2_TIME__beatsPerBar) == 0)
  532. skip = true;
  533. else if (std::strcmp(designation, LV2_TIME__beatsPerMinute) == 0)
  534. skip = true;
  535. else if (std::strcmp(designation, LV2_TIME__frame) == 0)
  536. skip = true;
  537. else if (std::strcmp(designation, LV2_TIME__framesPerSecond) == 0)
  538. skip = true;
  539. else if (std::strcmp(designation, LV2_TIME__speed) == 0)
  540. skip = true;
  541. else if (std::strcmp(designation, LV2_KXSTUDIO_PROPERTIES__TimePositionTicksPerBeat) == 0)
  542. skip = true;
  543. }
  544. lilv_node_free(designationNode);
  545. if (skip)
  546. continue;
  547. }
  548. if (isInput)
  549. ++(info.parameterIns);
  550. else
  551. ++(info.parameterOuts);
  552. }
  553. else if (lilvPort.is_a(lv2World.port_audio))
  554. {
  555. if (isInput)
  556. ++(info.audioIns);
  557. else
  558. ++(info.audioOuts);
  559. }
  560. else if (lilvPort.is_a(lv2World.port_cv))
  561. {
  562. }
  563. else if (lilvPort.is_a(lv2World.port_atom))
  564. {
  565. Lilv::Nodes supportNodes(lilvPort.get_value(lv2World.atom_supports));
  566. for (LilvIter *it = lilv_nodes_begin(supportNodes.me); ! lilv_nodes_is_end(supportNodes.me, it); it = lilv_nodes_next(supportNodes.me, it))
  567. {
  568. const Lilv::Node node(lilv_nodes_get(supportNodes.me, it));
  569. CARLA_SAFE_ASSERT_CONTINUE(node.is_uri());
  570. if (node.equals(lv2World.midi_event))
  571. {
  572. if (isInput)
  573. ++(info.midiIns);
  574. else
  575. ++(info.midiOuts);
  576. }
  577. }
  578. lilv_nodes_free(const_cast<LilvNodes*>(supportNodes.me));
  579. }
  580. else if (lilvPort.is_a(lv2World.port_event))
  581. {
  582. if (lilvPort.supports_event(lv2World.midi_event))
  583. {
  584. if (isInput)
  585. ++(info.midiIns);
  586. else
  587. ++(info.midiOuts);
  588. }
  589. }
  590. else if (lilvPort.is_a(lv2World.port_midi))
  591. {
  592. if (isInput)
  593. ++(info.midiIns);
  594. else
  595. ++(info.midiOuts);
  596. }
  597. }
  598. // text data
  599. static CarlaString suri, sname, smaker, slicense;
  600. suri.clear(); sname.clear(); smaker.clear(); slicense.clear();
  601. suri = lilvPlugin.get_uri().as_uri();
  602. if (const char* const name = lilvPlugin.get_name().as_string())
  603. sname = name;
  604. else
  605. sname.clear();
  606. if (const char* const author = lilvPlugin.get_author_name().as_string())
  607. smaker = author;
  608. else
  609. smaker.clear();
  610. Lilv::Nodes licenseNodes(lilvPlugin.get_value(lv2World.doap_license));
  611. if (licenseNodes.size() > 0)
  612. {
  613. if (const char* const license = licenseNodes.get_first().as_string())
  614. slicense = license;
  615. }
  616. lilv_nodes_free(const_cast<LilvNodes*>(licenseNodes.me));
  617. info.name = sname;
  618. info.label = suri;
  619. info.maker = smaker;
  620. info.copyright = slicense;
  621. return &info;
  622. }
  623. case CB::PLUGIN_AU: {
  624. #ifdef CARLA_OS_MAC
  625. const int indexi(static_cast<int>(index));
  626. CARLA_SAFE_ASSERT_BREAK(indexi < gCachedAuPluginResults.size());
  627. using namespace juce;
  628. String pluginId(gCachedAuPluginResults[indexi]);
  629. OwnedArray<PluginDescription> results;
  630. AudioUnitPluginFormat auFormat;
  631. auFormat.findAllTypesForFile(results, pluginId);
  632. CARLA_SAFE_ASSERT_BREAK(results.size() > 0);
  633. CARLA_SAFE_ASSERT(results.size() == 1);
  634. PluginDescription* const desc(results[0]);
  635. CARLA_SAFE_ASSERT_BREAK(desc != nullptr);
  636. info.category = CB::getPluginCategoryFromName(desc->category.toRawUTF8());
  637. info.hints = 0x0;
  638. if (desc->isInstrument)
  639. info.hints |= CB::PLUGIN_IS_SYNTH;
  640. if (true)
  641. info.hints |= CB::PLUGIN_HAS_CUSTOM_UI;
  642. info.audioIns = static_cast<uint32_t>(desc->numInputChannels);
  643. info.audioOuts = static_cast<uint32_t>(desc->numOutputChannels);
  644. info.midiIns = desc->isInstrument ? 1 : 0;
  645. info.midiOuts = 0;
  646. info.parameterIns = 0;
  647. info.parameterOuts = 0;
  648. static CarlaString sname, slabel, smaker;
  649. sname = desc->name.toRawUTF8();
  650. slabel = desc->fileOrIdentifier.toRawUTF8();
  651. smaker = desc->manufacturerName.toRawUTF8();
  652. info.name = sname;
  653. info.label = slabel;
  654. info.maker = smaker;
  655. info.copyright = gNullCharPtr;
  656. return &info;
  657. #else
  658. break;
  659. #endif
  660. }
  661. default:
  662. break;
  663. }
  664. info.category = CB::PLUGIN_CATEGORY_NONE;
  665. info.hints = 0x0;
  666. info.audioIns = 0;
  667. info.audioOuts = 0;
  668. info.midiIns = 0;
  669. info.midiOuts = 0;
  670. info.parameterIns = 0;
  671. info.parameterOuts = 0;
  672. info.name = gNullCharPtr;
  673. info.label = gNullCharPtr;
  674. info.maker = gNullCharPtr;
  675. info.copyright = gNullCharPtr;
  676. return &info;
  677. }
  678. // -------------------------------------------------------------------------------------------------------------------
  679. void carla_set_process_name(const char* name)
  680. {
  681. carla_debug("carla_set_process_name(\"%s\")", name);
  682. CarlaThread::setCurrentThreadName(name);
  683. juce::Thread::setCurrentThreadName(name);
  684. }
  685. // -------------------------------------------------------------------------------------------------------------------
  686. class CarlaPipeClientPlugin : public CarlaPipeClient
  687. {
  688. public:
  689. CarlaPipeClientPlugin(const CarlaPipeCallbackFunc callbackFunc, void* const callbackPtr) noexcept
  690. : CarlaPipeClient(),
  691. fCallbackFunc(callbackFunc),
  692. fCallbackPtr(callbackPtr),
  693. leakDetector_CarlaPipeClientPlugin()
  694. {
  695. CARLA_SAFE_ASSERT(fCallbackFunc != nullptr);
  696. }
  697. const char* readlineblock(const uint timeout) noexcept
  698. {
  699. return CarlaPipeClient::_readlineblock(timeout);
  700. }
  701. bool msgReceived(const char* const msg) noexcept
  702. {
  703. if (fCallbackFunc != nullptr)
  704. {
  705. try {
  706. fCallbackFunc(fCallbackPtr, msg);
  707. } CARLA_SAFE_EXCEPTION("msgReceived");
  708. }
  709. return true;
  710. }
  711. private:
  712. const CarlaPipeCallbackFunc fCallbackFunc;
  713. void* const fCallbackPtr;
  714. CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(CarlaPipeClientPlugin)
  715. };
  716. CarlaPipeClientHandle carla_pipe_client_new(const char* argv[], CarlaPipeCallbackFunc callbackFunc, void* callbackPtr)
  717. {
  718. carla_debug("carla_pipe_client_new(%p, %p, %p)", argv, callbackFunc, callbackPtr);
  719. CarlaPipeClientPlugin* const pipe(new CarlaPipeClientPlugin(callbackFunc, callbackPtr));
  720. if (! pipe->initPipeClient(argv))
  721. {
  722. delete pipe;
  723. return nullptr;
  724. }
  725. return pipe;
  726. }
  727. void carla_pipe_client_idle(CarlaPipeClientHandle handle)
  728. {
  729. CARLA_SAFE_ASSERT_RETURN(handle != nullptr,);
  730. ((CarlaPipeClientPlugin*)handle)->idlePipe();
  731. }
  732. bool carla_pipe_client_is_running(CarlaPipeClientHandle handle)
  733. {
  734. CARLA_SAFE_ASSERT_RETURN(handle != nullptr, false);
  735. return ((CarlaPipeClientPlugin*)handle)->isPipeRunning();
  736. }
  737. void carla_pipe_client_lock(CarlaPipeClientHandle handle)
  738. {
  739. CARLA_SAFE_ASSERT_RETURN(handle != nullptr,);
  740. return ((CarlaPipeClientPlugin*)handle)->lockPipe();
  741. }
  742. void carla_pipe_client_unlock(CarlaPipeClientHandle handle)
  743. {
  744. CARLA_SAFE_ASSERT_RETURN(handle != nullptr,);
  745. return ((CarlaPipeClientPlugin*)handle)->unlockPipe();
  746. }
  747. const char* carla_pipe_client_readlineblock(CarlaPipeClientHandle handle, uint timeout)
  748. {
  749. CARLA_SAFE_ASSERT_RETURN(handle != nullptr, nullptr);
  750. return ((CarlaPipeClientPlugin*)handle)->readlineblock(timeout);
  751. }
  752. bool carla_pipe_client_write_msg(CarlaPipeClientHandle handle, const char* msg)
  753. {
  754. CARLA_SAFE_ASSERT_RETURN(handle != nullptr, false);
  755. return ((CarlaPipeClientPlugin*)handle)->writeMessage(msg);
  756. }
  757. bool carla_pipe_client_write_and_fix_msg(CarlaPipeClientHandle handle, const char* msg)
  758. {
  759. CARLA_SAFE_ASSERT_RETURN(handle != nullptr, false);
  760. return ((CarlaPipeClientPlugin*)handle)->writeAndFixMessage(msg);
  761. }
  762. bool carla_pipe_client_flush(CarlaPipeClientHandle handle)
  763. {
  764. CARLA_SAFE_ASSERT_RETURN(handle != nullptr, false);
  765. return ((CarlaPipeClientPlugin*)handle)->flushMessages();
  766. }
  767. bool carla_pipe_client_flush_and_unlock(CarlaPipeClientHandle handle)
  768. {
  769. CARLA_SAFE_ASSERT_RETURN(handle != nullptr, false);
  770. CarlaPipeClientPlugin* const pipe((CarlaPipeClientPlugin*)handle);
  771. const bool ret(pipe->flushMessages());
  772. pipe->unlockPipe();
  773. return ret;
  774. }
  775. void carla_pipe_client_destroy(CarlaPipeClientHandle handle)
  776. {
  777. CARLA_SAFE_ASSERT_RETURN(handle != nullptr,);
  778. carla_debug("carla_pipe_client_destroy(%p)", handle);
  779. CarlaPipeClientPlugin* const pipe((CarlaPipeClientPlugin*)handle);
  780. pipe->closePipeClient();
  781. delete pipe;
  782. }
  783. // -------------------------------------------------------------------------------------------------------------------
  784. const char* carla_get_library_filename()
  785. {
  786. carla_debug("carla_get_library_filename()");
  787. static CarlaString ret;
  788. if (ret.isEmpty())
  789. {
  790. using juce::File;
  791. ret = File(File::getSpecialLocation(File::currentExecutableFile)).getFullPathName().toRawUTF8();
  792. }
  793. return ret;
  794. }
  795. const char* carla_get_library_folder()
  796. {
  797. carla_debug("carla_get_library_folder()");
  798. static CarlaString ret;
  799. if (ret.isEmpty())
  800. {
  801. using juce::File;
  802. ret = File(File::getSpecialLocation(File::currentExecutableFile).getParentDirectory()).getFullPathName().toRawUTF8();
  803. }
  804. return ret;
  805. }
  806. // -------------------------------------------------------------------------------------------------------------------
  807. #include "CarlaPipeUtils.cpp"
  808. // -------------------------------------------------------------------------------------------------------------------