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.

779 lines
26KB

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