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.

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