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-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. // 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>NekoFilter plugin code based on lv2fil by Nedko Arnaudov and Fons Adriaensen</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. return static_cast<uint>(gCachedAuPluginResults.size());
  199. using namespace juce;
  200. initiated = true;
  201. AudioUnitPluginFormat auFormat;
  202. gCachedAuPluginResults = auFormat.searchPathsForPlugins(juce::FileSearchPath(), false);
  203. return static_cast<uint>(gCachedAuPluginResults.size());
  204. #else
  205. return 0;
  206. #endif
  207. }
  208. default:
  209. return 0;
  210. }
  211. }
  212. const CarlaCachedPluginInfo* carla_get_cached_plugin_info(CB::PluginType ptype, uint index)
  213. {
  214. carla_debug("carla_get_cached_plugin_info(%i:%s, %i)", ptype, CB::PluginType2Str(ptype), index);
  215. static CarlaCachedPluginInfo info;
  216. switch (ptype)
  217. {
  218. case CB::PLUGIN_INTERNAL: {
  219. uint32_t count = 0;
  220. const NativePluginDescriptor* const descs(carla_get_native_plugins_data(&count));
  221. CARLA_SAFE_ASSERT_BREAK(index < count);
  222. CARLA_SAFE_ASSERT_BREAK(descs != nullptr);
  223. const NativePluginDescriptor& desc(descs[index]);
  224. info.category = static_cast<CB::PluginCategory>(desc.category);
  225. info.hints = 0x0;
  226. if (desc.hints & NATIVE_PLUGIN_IS_RTSAFE)
  227. info.hints |= CB::PLUGIN_IS_RTSAFE;
  228. if (desc.hints & NATIVE_PLUGIN_IS_SYNTH)
  229. info.hints |= CB::PLUGIN_IS_SYNTH;
  230. if (desc.hints & NATIVE_PLUGIN_HAS_UI)
  231. info.hints |= CB::PLUGIN_HAS_CUSTOM_UI;
  232. if (desc.hints & NATIVE_PLUGIN_NEEDS_FIXED_BUFFERS)
  233. info.hints |= CB::PLUGIN_NEEDS_FIXED_BUFFERS;
  234. if (desc.hints & NATIVE_PLUGIN_NEEDS_UI_MAIN_THREAD)
  235. info.hints |= CB::PLUGIN_NEEDS_UI_MAIN_THREAD;
  236. info.audioIns = desc.audioIns;
  237. info.audioOuts = desc.audioOuts;
  238. info.midiIns = desc.midiIns;
  239. info.midiOuts = desc.midiOuts;
  240. info.parameterIns = desc.paramIns;
  241. info.parameterOuts = desc.paramOuts;
  242. info.name = desc.name;
  243. info.label = desc.label;
  244. info.maker = desc.maker;
  245. info.copyright = desc.copyright;
  246. return &info;
  247. }
  248. case CB::PLUGIN_LV2: {
  249. Lv2WorldClass& lv2World(Lv2WorldClass::getInstance());
  250. const LilvPlugin* const cPlugin(lv2World.getPluginFromIndex(index));
  251. CARLA_SAFE_ASSERT_BREAK(cPlugin != nullptr);
  252. Lilv::Plugin lilvPlugin(cPlugin);
  253. CARLA_SAFE_ASSERT_BREAK(lilvPlugin.get_uri().is_uri());
  254. carla_stdout("Filling info for LV2 with URI '%s'", lilvPlugin.get_uri().as_uri());
  255. // features
  256. info.hints = 0x0;
  257. if (lilvPlugin.get_uis().size() > 0 || lilvPlugin.get_modgui_resources_directory().as_uri() != nullptr)
  258. info.hints |= CB::PLUGIN_HAS_CUSTOM_UI;
  259. {
  260. Lilv::Nodes lilvFeatureNodes(lilvPlugin.get_supported_features());
  261. LILV_FOREACH(nodes, it, lilvFeatureNodes)
  262. {
  263. Lilv::Node lilvFeatureNode(lilvFeatureNodes.get(it));
  264. const char* const featureURI(lilvFeatureNode.as_uri());
  265. CARLA_SAFE_ASSERT_CONTINUE(featureURI != nullptr);
  266. if (std::strcmp(featureURI, LV2_CORE__hardRTCapable) == 0)
  267. info.hints |= CB::PLUGIN_IS_RTSAFE;
  268. }
  269. lilv_nodes_free(const_cast<LilvNodes*>(lilvFeatureNodes.me));
  270. }
  271. // category
  272. info.category = CB::PLUGIN_CATEGORY_NONE;
  273. {
  274. Lilv::Nodes typeNodes(lilvPlugin.get_value(lv2World.rdf_type));
  275. if (typeNodes.size() > 0)
  276. {
  277. if (typeNodes.contains(lv2World.class_allpass))
  278. info.category = CB::PLUGIN_CATEGORY_FILTER;
  279. if (typeNodes.contains(lv2World.class_amplifier))
  280. info.category = CB::PLUGIN_CATEGORY_DYNAMICS;
  281. if (typeNodes.contains(lv2World.class_analyzer))
  282. info.category = CB::PLUGIN_CATEGORY_UTILITY;
  283. if (typeNodes.contains(lv2World.class_bandpass))
  284. info.category = CB::PLUGIN_CATEGORY_FILTER;
  285. if (typeNodes.contains(lv2World.class_chorus))
  286. info.category = CB::PLUGIN_CATEGORY_MODULATOR;
  287. if (typeNodes.contains(lv2World.class_comb))
  288. info.category = CB::PLUGIN_CATEGORY_FILTER;
  289. if (typeNodes.contains(lv2World.class_compressor))
  290. info.category = CB::PLUGIN_CATEGORY_DYNAMICS;
  291. if (typeNodes.contains(lv2World.class_constant))
  292. info.category = CB::PLUGIN_CATEGORY_OTHER;
  293. if (typeNodes.contains(lv2World.class_converter))
  294. info.category = CB::PLUGIN_CATEGORY_UTILITY;
  295. if (typeNodes.contains(lv2World.class_delay))
  296. info.category = CB::PLUGIN_CATEGORY_DELAY;
  297. if (typeNodes.contains(lv2World.class_distortion))
  298. info.category = CB::PLUGIN_CATEGORY_DISTORTION;
  299. if (typeNodes.contains(lv2World.class_dynamics))
  300. info.category = CB::PLUGIN_CATEGORY_DYNAMICS;
  301. if (typeNodes.contains(lv2World.class_eq))
  302. info.category = CB::PLUGIN_CATEGORY_EQ;
  303. if (typeNodes.contains(lv2World.class_envelope))
  304. info.category = CB::PLUGIN_CATEGORY_DYNAMICS;
  305. if (typeNodes.contains(lv2World.class_expander))
  306. info.category = CB::PLUGIN_CATEGORY_DYNAMICS;
  307. if (typeNodes.contains(lv2World.class_filter))
  308. info.category = CB::PLUGIN_CATEGORY_FILTER;
  309. if (typeNodes.contains(lv2World.class_flanger))
  310. info.category = CB::PLUGIN_CATEGORY_MODULATOR;
  311. if (typeNodes.contains(lv2World.class_function))
  312. info.category = CB::PLUGIN_CATEGORY_UTILITY;
  313. if (typeNodes.contains(lv2World.class_gate))
  314. info.category = CB::PLUGIN_CATEGORY_DYNAMICS;
  315. if (typeNodes.contains(lv2World.class_generator))
  316. info.category = CB::PLUGIN_CATEGORY_OTHER;
  317. if (typeNodes.contains(lv2World.class_highpass))
  318. info.category = CB::PLUGIN_CATEGORY_FILTER;
  319. if (typeNodes.contains(lv2World.class_limiter))
  320. info.category = CB::PLUGIN_CATEGORY_DYNAMICS;
  321. if (typeNodes.contains(lv2World.class_lowpass))
  322. info.category = CB::PLUGIN_CATEGORY_FILTER;
  323. if (typeNodes.contains(lv2World.class_mixer))
  324. info.category = CB::PLUGIN_CATEGORY_UTILITY;
  325. if (typeNodes.contains(lv2World.class_modulator))
  326. info.category = CB::PLUGIN_CATEGORY_MODULATOR;
  327. if (typeNodes.contains(lv2World.class_multiEQ))
  328. info.category = CB::PLUGIN_CATEGORY_EQ;
  329. if (typeNodes.contains(lv2World.class_oscillator))
  330. info.category = CB::PLUGIN_CATEGORY_OTHER;
  331. if (typeNodes.contains(lv2World.class_paraEQ))
  332. info.category = CB::PLUGIN_CATEGORY_EQ;
  333. if (typeNodes.contains(lv2World.class_phaser))
  334. info.category = CB::PLUGIN_CATEGORY_MODULATOR;
  335. if (typeNodes.contains(lv2World.class_pitch))
  336. info.category = CB::PLUGIN_CATEGORY_OTHER;
  337. if (typeNodes.contains(lv2World.class_reverb))
  338. info.category = CB::PLUGIN_CATEGORY_DELAY;
  339. if (typeNodes.contains(lv2World.class_simulator))
  340. info.category = CB::PLUGIN_CATEGORY_OTHER;
  341. if (typeNodes.contains(lv2World.class_spatial))
  342. info.category = CB::PLUGIN_CATEGORY_OTHER;
  343. if (typeNodes.contains(lv2World.class_spectral))
  344. info.category = CB::PLUGIN_CATEGORY_OTHER;
  345. if (typeNodes.contains(lv2World.class_utility))
  346. info.category = CB::PLUGIN_CATEGORY_UTILITY;
  347. if (typeNodes.contains(lv2World.class_waveshaper))
  348. info.category = CB::PLUGIN_CATEGORY_DISTORTION;
  349. if (typeNodes.contains(lv2World.class_instrument))
  350. {
  351. info.category = CB::PLUGIN_CATEGORY_SYNTH;
  352. info.hints |= CB::PLUGIN_IS_SYNTH;
  353. }
  354. }
  355. lilv_nodes_free(const_cast<LilvNodes*>(typeNodes.me));
  356. }
  357. // number data
  358. info.audioIns = 0;
  359. info.audioOuts = 0;
  360. info.midiIns = 0;
  361. info.midiOuts = 0;
  362. info.parameterIns = 0;
  363. info.parameterOuts = 0;
  364. for (uint i=0, count=lilvPlugin.get_num_ports(); i<count; ++i)
  365. {
  366. Lilv::Port lilvPort(lilvPlugin.get_port_by_index(i));
  367. bool isInput;
  368. /**/ if (lilvPort.is_a(lv2World.port_input))
  369. isInput = true;
  370. else if (lilvPort.is_a(lv2World.port_output))
  371. isInput = false;
  372. else
  373. continue;
  374. /**/ if (lilvPort.is_a(lv2World.port_control))
  375. {
  376. // skip some control ports
  377. if (lilvPort.has_property(lv2World.reportsLatency))
  378. continue;
  379. if (LilvNode* const designationNode = lilv_port_get(lilvPort.parent, lilvPort.me, lv2World.designation.me))
  380. {
  381. bool skip = false;
  382. if (const char* const designation = lilv_node_as_string(designationNode))
  383. {
  384. /**/ if (std::strcmp(designation, LV2_CORE__control) == 0)
  385. skip = true;
  386. else if (std::strcmp(designation, LV2_CORE__freeWheeling) == 0)
  387. skip = true;
  388. else if (std::strcmp(designation, LV2_CORE__latency) == 0)
  389. skip = true;
  390. else if (std::strcmp(designation, LV2_PARAMETERS__sampleRate) == 0)
  391. skip = true;
  392. else if (std::strcmp(designation, LV2_TIME__bar) == 0)
  393. skip = true;
  394. else if (std::strcmp(designation, LV2_TIME__barBeat) == 0)
  395. skip = true;
  396. else if (std::strcmp(designation, LV2_TIME__beat) == 0)
  397. skip = true;
  398. else if (std::strcmp(designation, LV2_TIME__beatUnit) == 0)
  399. skip = true;
  400. else if (std::strcmp(designation, LV2_TIME__beatsPerBar) == 0)
  401. skip = true;
  402. else if (std::strcmp(designation, LV2_TIME__beatsPerMinute) == 0)
  403. skip = true;
  404. else if (std::strcmp(designation, LV2_TIME__frame) == 0)
  405. skip = true;
  406. else if (std::strcmp(designation, LV2_TIME__framesPerSecond) == 0)
  407. skip = true;
  408. else if (std::strcmp(designation, LV2_TIME__speed) == 0)
  409. skip = true;
  410. else if (std::strcmp(designation, LV2_KXSTUDIO_PROPERTIES__TimePositionTicksPerBeat) == 0)
  411. skip = true;
  412. }
  413. lilv_node_free(designationNode);
  414. if (skip)
  415. continue;
  416. }
  417. if (isInput)
  418. ++(info.parameterIns);
  419. else
  420. ++(info.parameterOuts);
  421. }
  422. else if (lilvPort.is_a(lv2World.port_audio))
  423. {
  424. if (isInput)
  425. ++(info.audioIns);
  426. else
  427. ++(info.audioOuts);
  428. }
  429. else if (lilvPort.is_a(lv2World.port_cv))
  430. {
  431. }
  432. else if (lilvPort.is_a(lv2World.port_atom))
  433. {
  434. Lilv::Nodes supportNodes(lilvPort.get_value(lv2World.atom_supports));
  435. for (LilvIter *it = lilv_nodes_begin(supportNodes.me); ! lilv_nodes_is_end(supportNodes.me, it); it = lilv_nodes_next(supportNodes.me, it))
  436. {
  437. const Lilv::Node node(lilv_nodes_get(supportNodes.me, it));
  438. CARLA_SAFE_ASSERT_CONTINUE(node.is_uri());
  439. if (node.equals(lv2World.midi_event))
  440. {
  441. if (isInput)
  442. ++(info.midiIns);
  443. else
  444. ++(info.midiOuts);
  445. }
  446. }
  447. lilv_nodes_free(const_cast<LilvNodes*>(supportNodes.me));
  448. }
  449. else if (lilvPort.is_a(lv2World.port_event))
  450. {
  451. if (lilvPort.supports_event(lv2World.midi_event))
  452. {
  453. if (isInput)
  454. ++(info.midiIns);
  455. else
  456. ++(info.midiOuts);
  457. }
  458. }
  459. else if (lilvPort.is_a(lv2World.port_midi))
  460. {
  461. if (isInput)
  462. ++(info.midiIns);
  463. else
  464. ++(info.midiOuts);
  465. }
  466. }
  467. // text data
  468. static CarlaString suri, sname, smaker, slicense;
  469. suri.clear(); sname.clear(); smaker.clear(); slicense.clear();
  470. suri = lilvPlugin.get_uri().as_uri();
  471. if (const char* const name = lilvPlugin.get_name().as_string())
  472. sname = name;
  473. else
  474. sname.clear();
  475. if (const char* const author = lilvPlugin.get_author_name().as_string())
  476. smaker = author;
  477. else
  478. smaker.clear();
  479. Lilv::Nodes licenseNodes(lilvPlugin.get_value(lv2World.doap_license));
  480. if (licenseNodes.size() > 0)
  481. {
  482. if (const char* const license = licenseNodes.get_first().as_string())
  483. slicense = license;
  484. }
  485. lilv_nodes_free(const_cast<LilvNodes*>(licenseNodes.me));
  486. info.name = sname;
  487. info.label = suri;
  488. info.maker = smaker;
  489. info.copyright = slicense;
  490. return &info;
  491. }
  492. case CB::PLUGIN_AU: {
  493. #ifdef CARLA_OS_MAC
  494. const int indexi(static_cast<int>(index));
  495. CARLA_SAFE_ASSERT_BREAK(indexi < gCachedAuPluginResults.size());
  496. using namespace juce;
  497. String pluginId(gCachedAuPluginResults[indexi]);
  498. OwnedArray<PluginDescription> results;
  499. AudioUnitPluginFormat auFormat;
  500. auFormat.findAllTypesForFile(results, pluginId);
  501. CARLA_SAFE_ASSERT_BREAK(results.size() > 0);
  502. CARLA_SAFE_ASSERT(results.size() == 1);
  503. PluginDescription* const desc(results[0]);
  504. CARLA_SAFE_ASSERT_BREAK(desc != nullptr);
  505. info.category = CB::getPluginCategoryFromName(desc->category.toRawUTF8());
  506. info.hints = 0x0;
  507. if (desc->isInstrument)
  508. info.hints |= CB::PLUGIN_IS_SYNTH;
  509. if (true)
  510. info.hints |= CB::PLUGIN_HAS_CUSTOM_UI;
  511. info.audioIns = static_cast<uint32_t>(desc->numInputChannels);
  512. info.audioOuts = static_cast<uint32_t>(desc->numOutputChannels);
  513. info.midiIns = desc->isInstrument ? 1 : 0;
  514. info.midiOuts = 0;
  515. info.parameterIns = 0;
  516. info.parameterOuts = 0;
  517. static CarlaString sname, slabel, smaker;
  518. sname = desc->name.toRawUTF8();
  519. slabel = desc->fileOrIdentifier.toRawUTF8();
  520. smaker = desc->manufacturerName.toRawUTF8();
  521. info.name = sname;
  522. info.label = slabel;
  523. info.maker = smaker;
  524. info.copyright = gNullCharPtr;
  525. return &info;
  526. #else
  527. break;
  528. #endif
  529. }
  530. default:
  531. break;
  532. }
  533. info.category = CB::PLUGIN_CATEGORY_NONE;
  534. info.hints = 0x0;
  535. info.audioIns = 0;
  536. info.audioOuts = 0;
  537. info.midiIns = 0;
  538. info.midiOuts = 0;
  539. info.parameterIns = 0;
  540. info.parameterOuts = 0;
  541. info.name = gNullCharPtr;
  542. info.label = gNullCharPtr;
  543. info.maker = gNullCharPtr;
  544. info.copyright = gNullCharPtr;
  545. return &info;
  546. }
  547. // -------------------------------------------------------------------------------------------------------------------
  548. void carla_set_process_name(const char* name)
  549. {
  550. carla_debug("carla_set_process_name(\"%s\")", name);
  551. CarlaThread::setCurrentThreadName(name);
  552. juce::Thread::setCurrentThreadName(name);
  553. }
  554. // -------------------------------------------------------------------------------------------------------------------
  555. class CarlaPipeClientPlugin : public CarlaPipeClient
  556. {
  557. public:
  558. CarlaPipeClientPlugin(const CarlaPipeCallbackFunc callbackFunc, void* const callbackPtr) noexcept
  559. : CarlaPipeClient(),
  560. fCallbackFunc(callbackFunc),
  561. fCallbackPtr(callbackPtr),
  562. leakDetector_CarlaPipeClientPlugin()
  563. {
  564. CARLA_SAFE_ASSERT(fCallbackFunc != nullptr);
  565. }
  566. const char* readlineblock(const uint timeout) noexcept
  567. {
  568. return CarlaPipeClient::_readlineblock(timeout);
  569. }
  570. bool msgReceived(const char* const msg) noexcept
  571. {
  572. if (fCallbackFunc != nullptr)
  573. {
  574. try {
  575. fCallbackFunc(fCallbackPtr, msg);
  576. } CARLA_SAFE_EXCEPTION("msgReceived");
  577. }
  578. return true;
  579. }
  580. private:
  581. const CarlaPipeCallbackFunc fCallbackFunc;
  582. void* const fCallbackPtr;
  583. CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(CarlaPipeClientPlugin)
  584. };
  585. CarlaPipeClientHandle carla_pipe_client_new(const char* argv[], CarlaPipeCallbackFunc callbackFunc, void* callbackPtr)
  586. {
  587. carla_debug("carla_pipe_client_new(%p, %p, %p)", argv, callbackFunc, callbackPtr);
  588. CarlaPipeClientPlugin* const pipe(new CarlaPipeClientPlugin(callbackFunc, callbackPtr));
  589. if (! pipe->initPipeClient(argv))
  590. {
  591. delete pipe;
  592. return nullptr;
  593. }
  594. return pipe;
  595. }
  596. void carla_pipe_client_idle(CarlaPipeClientHandle handle)
  597. {
  598. CARLA_SAFE_ASSERT_RETURN(handle != nullptr,);
  599. ((CarlaPipeClientPlugin*)handle)->idlePipe();
  600. }
  601. bool carla_pipe_client_is_running(CarlaPipeClientHandle handle)
  602. {
  603. CARLA_SAFE_ASSERT_RETURN(handle != nullptr, false);
  604. return ((CarlaPipeClientPlugin*)handle)->isPipeRunning();
  605. }
  606. void carla_pipe_client_lock(CarlaPipeClientHandle handle)
  607. {
  608. CARLA_SAFE_ASSERT_RETURN(handle != nullptr,);
  609. return ((CarlaPipeClientPlugin*)handle)->lockPipe();
  610. }
  611. void carla_pipe_client_unlock(CarlaPipeClientHandle handle)
  612. {
  613. CARLA_SAFE_ASSERT_RETURN(handle != nullptr,);
  614. return ((CarlaPipeClientPlugin*)handle)->unlockPipe();
  615. }
  616. const char* carla_pipe_client_readlineblock(CarlaPipeClientHandle handle, uint timeout)
  617. {
  618. CARLA_SAFE_ASSERT_RETURN(handle != nullptr, nullptr);
  619. return ((CarlaPipeClientPlugin*)handle)->readlineblock(timeout);
  620. }
  621. bool carla_pipe_client_write_msg(CarlaPipeClientHandle handle, const char* msg)
  622. {
  623. CARLA_SAFE_ASSERT_RETURN(handle != nullptr, false);
  624. return ((CarlaPipeClientPlugin*)handle)->writeMessage(msg);
  625. }
  626. bool carla_pipe_client_write_and_fix_msg(CarlaPipeClientHandle handle, const char* msg)
  627. {
  628. CARLA_SAFE_ASSERT_RETURN(handle != nullptr, false);
  629. return ((CarlaPipeClientPlugin*)handle)->writeAndFixMessage(msg);
  630. }
  631. bool carla_pipe_client_flush(CarlaPipeClientHandle handle)
  632. {
  633. CARLA_SAFE_ASSERT_RETURN(handle != nullptr, false);
  634. return ((CarlaPipeClientPlugin*)handle)->flushMessages();
  635. }
  636. bool carla_pipe_client_flush_and_unlock(CarlaPipeClientHandle handle)
  637. {
  638. CARLA_SAFE_ASSERT_RETURN(handle != nullptr, false);
  639. CarlaPipeClientPlugin* const pipe((CarlaPipeClientPlugin*)handle);
  640. const bool ret(pipe->flushMessages());
  641. pipe->unlockPipe();
  642. return ret;
  643. }
  644. void carla_pipe_client_destroy(CarlaPipeClientHandle handle)
  645. {
  646. CARLA_SAFE_ASSERT_RETURN(handle != nullptr,);
  647. carla_debug("carla_pipe_client_destroy(%p)", handle);
  648. CarlaPipeClientPlugin* const pipe((CarlaPipeClientPlugin*)handle);
  649. pipe->closePipeClient();
  650. delete pipe;
  651. }
  652. // -------------------------------------------------------------------------------------------------------------------
  653. const char* carla_get_library_filename()
  654. {
  655. carla_debug("carla_get_library_filename()");
  656. static CarlaString ret;
  657. if (ret.isEmpty())
  658. {
  659. using juce::File;
  660. ret = File(File::getSpecialLocation(File::currentExecutableFile)).getFullPathName().toRawUTF8();
  661. }
  662. return ret;
  663. }
  664. const char* carla_get_library_folder()
  665. {
  666. carla_debug("carla_get_library_folder()");
  667. static CarlaString ret;
  668. if (ret.isEmpty())
  669. {
  670. using juce::File;
  671. ret = File(File::getSpecialLocation(File::currentExecutableFile).getParentDirectory()).getFullPathName().toRawUTF8();
  672. }
  673. return ret;
  674. }
  675. // -------------------------------------------------------------------------------------------------------------------
  676. #include "CarlaPipeUtils.cpp"
  677. // -------------------------------------------------------------------------------------------------------------------