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.

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