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.

822 lines
27KB

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