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.

781 lines
26KB

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