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.

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