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.

771 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.all.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. // Audio files
  441. #ifdef HAVE_SNDFILE
  442. retText += ";*.aiff;*.flac;*.oga;*.ogg;*.w64;*.wav";
  443. #endif
  444. #ifdef HAVE_FFMPEG
  445. retText += ";*.3g2;*.3gp;*.aac;*.ac3;*.amr;*.ape;*.mp2;*.mp3;*.mpc;*.wma";
  446. #endif
  447. }
  448. return retText;
  449. }
  450. // -------------------------------------------------------------------------------------------------------------------
  451. void carla_fflush(bool err)
  452. {
  453. std::fflush(err ? stderr : stdout);
  454. }
  455. void carla_fputs(bool err, const char* string)
  456. {
  457. std::fputs(string, err ? stderr : stdout);
  458. }
  459. void carla_set_process_name(const char* name)
  460. {
  461. carla_debug("carla_set_process_name(\"%s\")", name);
  462. CarlaThread::setCurrentThreadName(name);
  463. }
  464. // -------------------------------------------------------------------------------------------------------------------
  465. class CarlaPipeClientPlugin : public CarlaPipeClient
  466. {
  467. public:
  468. CarlaPipeClientPlugin(const CarlaPipeCallbackFunc callbackFunc, void* const callbackPtr) noexcept
  469. : CarlaPipeClient(),
  470. fCallbackFunc(callbackFunc),
  471. fCallbackPtr(callbackPtr)
  472. {
  473. CARLA_SAFE_ASSERT(fCallbackFunc != nullptr);
  474. }
  475. const char* readlineblock(const uint timeout) noexcept
  476. {
  477. return CarlaPipeClient::_readlineblock(timeout);
  478. }
  479. bool msgReceived(const char* const msg) noexcept
  480. {
  481. if (fCallbackFunc != nullptr)
  482. {
  483. try {
  484. fCallbackFunc(fCallbackPtr, msg);
  485. } CARLA_SAFE_EXCEPTION("msgReceived");
  486. }
  487. return true;
  488. }
  489. private:
  490. const CarlaPipeCallbackFunc fCallbackFunc;
  491. void* const fCallbackPtr;
  492. CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(CarlaPipeClientPlugin)
  493. };
  494. CarlaPipeClientHandle carla_pipe_client_new(const char* argv[], CarlaPipeCallbackFunc callbackFunc, void* callbackPtr)
  495. {
  496. carla_debug("carla_pipe_client_new(%p, %p, %p)", argv, callbackFunc, callbackPtr);
  497. CarlaPipeClientPlugin* const pipe(new CarlaPipeClientPlugin(callbackFunc, callbackPtr));
  498. if (! pipe->initPipeClient(argv))
  499. {
  500. delete pipe;
  501. return nullptr;
  502. }
  503. return pipe;
  504. }
  505. void carla_pipe_client_idle(CarlaPipeClientHandle handle)
  506. {
  507. CARLA_SAFE_ASSERT_RETURN(handle != nullptr,);
  508. ((CarlaPipeClientPlugin*)handle)->idlePipe();
  509. }
  510. bool carla_pipe_client_is_running(CarlaPipeClientHandle handle)
  511. {
  512. CARLA_SAFE_ASSERT_RETURN(handle != nullptr, false);
  513. return ((CarlaPipeClientPlugin*)handle)->isPipeRunning();
  514. }
  515. void carla_pipe_client_lock(CarlaPipeClientHandle handle)
  516. {
  517. CARLA_SAFE_ASSERT_RETURN(handle != nullptr,);
  518. return ((CarlaPipeClientPlugin*)handle)->lockPipe();
  519. }
  520. void carla_pipe_client_unlock(CarlaPipeClientHandle handle)
  521. {
  522. CARLA_SAFE_ASSERT_RETURN(handle != nullptr,);
  523. return ((CarlaPipeClientPlugin*)handle)->unlockPipe();
  524. }
  525. const char* carla_pipe_client_readlineblock(CarlaPipeClientHandle handle, uint timeout)
  526. {
  527. CARLA_SAFE_ASSERT_RETURN(handle != nullptr, nullptr);
  528. return ((CarlaPipeClientPlugin*)handle)->readlineblock(timeout);
  529. }
  530. bool carla_pipe_client_write_msg(CarlaPipeClientHandle handle, const char* msg)
  531. {
  532. CARLA_SAFE_ASSERT_RETURN(handle != nullptr, false);
  533. return ((CarlaPipeClientPlugin*)handle)->writeMessage(msg);
  534. }
  535. bool carla_pipe_client_write_and_fix_msg(CarlaPipeClientHandle handle, const char* msg)
  536. {
  537. CARLA_SAFE_ASSERT_RETURN(handle != nullptr, false);
  538. return ((CarlaPipeClientPlugin*)handle)->writeAndFixMessage(msg);
  539. }
  540. bool carla_pipe_client_flush(CarlaPipeClientHandle handle)
  541. {
  542. CARLA_SAFE_ASSERT_RETURN(handle != nullptr, false);
  543. return ((CarlaPipeClientPlugin*)handle)->flushMessages();
  544. }
  545. bool carla_pipe_client_flush_and_unlock(CarlaPipeClientHandle handle)
  546. {
  547. CARLA_SAFE_ASSERT_RETURN(handle != nullptr, false);
  548. CarlaPipeClientPlugin* const pipe((CarlaPipeClientPlugin*)handle);
  549. const bool ret(pipe->flushMessages());
  550. pipe->unlockPipe();
  551. return ret;
  552. }
  553. void carla_pipe_client_destroy(CarlaPipeClientHandle handle)
  554. {
  555. CARLA_SAFE_ASSERT_RETURN(handle != nullptr,);
  556. carla_debug("carla_pipe_client_destroy(%p)", handle);
  557. CarlaPipeClientPlugin* const pipe((CarlaPipeClientPlugin*)handle);
  558. pipe->closePipeClient();
  559. delete pipe;
  560. }
  561. // -------------------------------------------------------------------------------------------------------------------
  562. const char* carla_get_library_filename()
  563. {
  564. carla_debug("carla_get_library_filename()");
  565. static CarlaString ret;
  566. if (ret.isEmpty())
  567. {
  568. using water::File;
  569. ret = File(File::getSpecialLocation(File::currentExecutableFile)).getFullPathName().toRawUTF8();
  570. }
  571. return ret;
  572. }
  573. const char* carla_get_library_folder()
  574. {
  575. carla_debug("carla_get_library_folder()");
  576. static CarlaString ret;
  577. if (ret.isEmpty())
  578. {
  579. using water::File;
  580. ret = File(File::getSpecialLocation(File::currentExecutableFile).getParentDirectory()).getFullPathName().toRawUTF8();
  581. }
  582. return ret;
  583. }
  584. // -------------------------------------------------------------------------------------------------------------------
  585. void carla_x11_reparent_window(uintptr_t winId1, uintptr_t winId2)
  586. {
  587. carla_debug("carla_x11_reparent_window()");
  588. #ifdef HAVE_X11
  589. if (::Display* const disp = XOpenDisplay(nullptr))
  590. {
  591. XReparentWindow(disp, winId1, winId2, 0, 0);
  592. XMapWindow(disp, winId1);
  593. XCloseDisplay(disp);
  594. }
  595. #endif
  596. }
  597. void carla_x11_move_window(uintptr_t winId, int x, int y)
  598. {
  599. #ifdef HAVE_X11
  600. if (::Display* const disp = XOpenDisplay(nullptr))
  601. {
  602. XMoveWindow(disp, winId, x, y);
  603. XCloseDisplay(disp);
  604. }
  605. #endif
  606. }
  607. int* carla_x11_get_window_pos(uintptr_t winId)
  608. {
  609. carla_debug("carla_x11_get_window_pos()");
  610. static int pos[2];
  611. #ifdef HAVE_X11
  612. if (::Display* const disp = XOpenDisplay(nullptr))
  613. {
  614. int x, y;
  615. Window child;
  616. XWindowAttributes xwa;
  617. XTranslateCoordinates(disp, winId, XRootWindow(disp, 0), 0, 0, &x, &y, &child);
  618. XGetWindowAttributes(disp, winId, &xwa);
  619. XCloseDisplay(disp);
  620. pos[0] = x - xwa.x;
  621. pos[1] = y - xwa.y;
  622. }
  623. else
  624. #endif
  625. {
  626. pos[0] = 0;
  627. pos[1] = 0;
  628. }
  629. return pos;
  630. }
  631. // -------------------------------------------------------------------------------------------------------------------
  632. #include "CarlaPipeUtils.cpp"
  633. #if defined(CARLA_OS_MAC) || defined(CARLA_OS_WIN)
  634. # include "water/misc/Time.cpp"
  635. #endif
  636. // -------------------------------------------------------------------------------------------------------------------
  637. #endif // CARLA_UTILS_CACHED_PLUGINS_ONLY