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.

828 lines
28KB

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