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.

CarlaUtils.h 15KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551
  1. /*
  2. * Carla Plugin Host
  3. * Copyright (C) 2011-2022 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. #ifndef CARLA_UTILS_H_INCLUDED
  18. #define CARLA_UTILS_H_INCLUDED
  19. #include "CarlaBackend.h"
  20. #ifdef __cplusplus
  21. using CARLA_BACKEND_NAMESPACE::BinaryType;
  22. using CARLA_BACKEND_NAMESPACE::EngineOption;
  23. using CARLA_BACKEND_NAMESPACE::PluginCategory;
  24. using CARLA_BACKEND_NAMESPACE::PluginType;
  25. #endif
  26. /*!
  27. * @defgroup CarlaUtilsAPI Carla Utils API
  28. *
  29. * The Carla Utils API.
  30. *
  31. * This API allows to call advanced features from Python.
  32. * @{
  33. */
  34. /* --------------------------------------------------------------------------------------------------------------------
  35. * plugin discovery */
  36. typedef void* CarlaPluginDiscoveryHandle;
  37. /*!
  38. * Plugin discovery meta-data.
  39. * These are extra fields not required for loading plugins but still useful for showing to the user.
  40. */
  41. typedef struct _CarlaPluginDiscoveryMetadata {
  42. /*!
  43. * Plugin name.
  44. */
  45. const char* name;
  46. /*!
  47. * Plugin author/maker.
  48. */
  49. const char* maker;
  50. /*!
  51. * Plugin category.
  52. */
  53. PluginCategory category;
  54. /*!
  55. * Plugin hints.
  56. * @see PluginHints
  57. */
  58. uint hints;
  59. #ifdef __cplusplus
  60. /*!
  61. * C++ constructor.
  62. */
  63. CARLA_API _CarlaPluginDiscoveryMetadata() noexcept;
  64. CARLA_DECLARE_NON_COPYABLE(_CarlaPluginDiscoveryMetadata)
  65. #endif
  66. } CarlaPluginDiscoveryMetadata;
  67. /*!
  68. * Plugin discovery input/output information.
  69. * These are extra fields not required for loading plugins but still useful for extra filtering.
  70. */
  71. typedef struct _CarlaPluginDiscoveryIO {
  72. /*!
  73. * Number of audio inputs.
  74. */
  75. uint32_t audioIns;
  76. /*!
  77. * Number of audio outputs.
  78. */
  79. uint32_t audioOuts;
  80. /*!
  81. * Number of CV inputs.
  82. */
  83. uint32_t cvIns;
  84. /*!
  85. * Number of CV outputs.
  86. */
  87. uint32_t cvOuts;
  88. /*!
  89. * Number of MIDI inputs.
  90. */
  91. uint32_t midiIns;
  92. /*!
  93. * Number of MIDI outputs.
  94. */
  95. uint32_t midiOuts;
  96. /*!
  97. * Number of input parameters.
  98. */
  99. uint32_t parameterIns;
  100. /*!
  101. * Number of output parameters.
  102. */
  103. uint32_t parameterOuts;
  104. #ifdef __cplusplus
  105. /*!
  106. * C++ constructor.
  107. */
  108. CARLA_API _CarlaPluginDiscoveryIO() noexcept;
  109. CARLA_DECLARE_NON_COPYABLE(_CarlaPluginDiscoveryIO)
  110. #endif
  111. } CarlaPluginDiscoveryIO;
  112. /*!
  113. * Plugin discovery information.
  114. */
  115. typedef struct _CarlaPluginDiscoveryInfo {
  116. /*!
  117. * Binary type.
  118. */
  119. BinaryType btype;
  120. /*!
  121. * Plugin type.
  122. */
  123. PluginType ptype;
  124. /*!
  125. * Plugin filename.
  126. */
  127. const char* filename;
  128. /*!
  129. * Plugin label/URI/Id.
  130. */
  131. const char* label;
  132. /*!
  133. * Plugin unique Id.
  134. */
  135. uint64_t uniqueId;
  136. /*!
  137. * Extra information, not required for load plugins.
  138. */
  139. CarlaPluginDiscoveryMetadata metadata;
  140. /*!
  141. * Extra information, not required for load plugins.
  142. */
  143. CarlaPluginDiscoveryIO io;
  144. #ifdef __cplusplus
  145. /*!
  146. * C++ constructor.
  147. */
  148. CARLA_API _CarlaPluginDiscoveryInfo() noexcept;
  149. CARLA_DECLARE_NON_COPYABLE(_CarlaPluginDiscoveryInfo)
  150. #endif
  151. } CarlaPluginDiscoveryInfo;
  152. /*!
  153. * Callback triggered when either a plugin has been found, or a scanned binary contains no plugins.
  154. *
  155. * For the case of plugins found while discovering @p info will be valid.
  156. * On formats where discovery is expensive, @p sha1 will contain a string hash related to the binary being scanned.
  157. *
  158. * When a plugin binary contains no actual plugins, @p info will be null but @p sha1 is valid.
  159. * This allows to mark a plugin binary as scanned, even without plugins, so we dont bother to check again next time.
  160. *
  161. * @note This callback might be triggered multiple times for a single binary, and thus for a single hash too.
  162. */
  163. typedef void (*CarlaPluginDiscoveryCallback)(void* ptr, const CarlaPluginDiscoveryInfo* info, const char* sha1);
  164. /*!
  165. * Optional callback triggered before starting to scan a plugin binary.
  166. * This allows to load plugin information from cache and skip scanning for that binary.
  167. * Return true to skip loading the binary specified by @p filename.
  168. */
  169. typedef bool (*CarlaPluginCheckCacheCallback)(void* ptr, const char* filename, const char* sha1);
  170. /*!
  171. * Start plugin discovery with the selected tool (must be absolute filename to executable file).
  172. * Different plugin types/formats must be scanned independently.
  173. * The path specified by @pluginPath can contain path separators (so ";" on Windows, ":" everywhere else).
  174. * The @p discoveryCb is required, while @p checkCacheCb is optional.
  175. *
  176. * Returns a non-null handle if there are plugins to be scanned.
  177. * @a carla_plugin_discovery_idle must be called at regular intervals afterwards.
  178. */
  179. CARLA_PLUGIN_EXPORT CarlaPluginDiscoveryHandle carla_plugin_discovery_start(const char* discoveryTool,
  180. BinaryType btype,
  181. PluginType ptype,
  182. const char* pluginPath,
  183. CarlaPluginDiscoveryCallback discoveryCb,
  184. CarlaPluginCheckCacheCallback checkCacheCb,
  185. void* callbackPtr);
  186. /*!
  187. * Continue discovering plugins, triggering callbacks along the way.
  188. * Returns false when there is nothing else to scan, then you MUST call @a carla_plugin_discovery_stop.
  189. */
  190. CARLA_PLUGIN_EXPORT bool carla_plugin_discovery_idle(CarlaPluginDiscoveryHandle handle);
  191. /*!
  192. * Skip the current plugin being discovered.
  193. * Carla automatically skips a plugin if 30s have passed without a reply from the discovery side,
  194. * this function allows to manually abort earlier than that.
  195. */
  196. CARLA_PLUGIN_EXPORT void carla_plugin_discovery_skip(CarlaPluginDiscoveryHandle handle);
  197. /*!
  198. * Stop plugin discovery.
  199. * Can be called early while the scanning is still active.
  200. */
  201. CARLA_PLUGIN_EXPORT void carla_plugin_discovery_stop(CarlaPluginDiscoveryHandle handle);
  202. /*!
  203. * Set a plugin discovery setting, to be applied globally.
  204. */
  205. CARLA_PLUGIN_EXPORT void carla_plugin_discovery_set_option(EngineOption option, int value, const char* valueStr);
  206. /* --------------------------------------------------------------------------------------------------------------------
  207. * cached plugins */
  208. /*!
  209. * Information about a cached plugin.
  210. * @see carla_get_cached_plugin_info()
  211. */
  212. typedef struct _CarlaCachedPluginInfo {
  213. /*!
  214. * Wherever the data in this struct is valid.
  215. * For performance reasons, plugins are only checked on request,
  216. * and as such, the count vs number of really valid plugins might not match.
  217. * Use this field to skip on plugins which cannot be loaded in Carla.
  218. */
  219. bool valid;
  220. /*!
  221. * Plugin category.
  222. */
  223. PluginCategory category;
  224. /*!
  225. * Plugin hints.
  226. * @see PluginHints
  227. */
  228. uint hints;
  229. /*!
  230. * Number of audio inputs.
  231. */
  232. uint32_t audioIns;
  233. /*!
  234. * Number of audio outputs.
  235. */
  236. uint32_t audioOuts;
  237. /*!
  238. * Number of CV inputs.
  239. */
  240. uint32_t cvIns;
  241. /*!
  242. * Number of CV outputs.
  243. */
  244. uint32_t cvOuts;
  245. /*!
  246. * Number of MIDI inputs.
  247. */
  248. uint32_t midiIns;
  249. /*!
  250. * Number of MIDI outputs.
  251. */
  252. uint32_t midiOuts;
  253. /*!
  254. * Number of input parameters.
  255. */
  256. uint32_t parameterIns;
  257. /*!
  258. * Number of output parameters.
  259. */
  260. uint32_t parameterOuts;
  261. /*!
  262. * Plugin name.
  263. */
  264. const char* name;
  265. /*!
  266. * Plugin label.
  267. */
  268. const char* label;
  269. /*!
  270. * Plugin author/maker.
  271. */
  272. const char* maker;
  273. /*!
  274. * Plugin copyright/license.
  275. */
  276. const char* copyright;
  277. #ifdef __cplusplus
  278. /*!
  279. * C++ constructor.
  280. */
  281. CARLA_API _CarlaCachedPluginInfo() noexcept;
  282. CARLA_DECLARE_NON_COPYABLE(_CarlaCachedPluginInfo)
  283. #endif
  284. } CarlaCachedPluginInfo;
  285. /*!
  286. * Get how many cached plugins are available.
  287. * Internal and LV2 plugin formats are cached and need to be discovered via this function.
  288. * Do not call this for any other plugin formats.
  289. *
  290. * @note if this carla build uses JUCE, then you must call carla_juce_init beforehand
  291. * @note for AU plugins, you cannot call this outside the main thread
  292. */
  293. CARLA_PLUGIN_EXPORT uint carla_get_cached_plugin_count(PluginType ptype, const char* pluginPath);
  294. /*!
  295. * Get information about a cached plugin.
  296. *
  297. * @note if this carla build uses JUCE, then you must call carla_juce_init beforehand
  298. * @note for AU plugins, you cannot call this outside the main thread
  299. */
  300. CARLA_PLUGIN_EXPORT const CarlaCachedPluginInfo* carla_get_cached_plugin_info(PluginType ptype, uint index);
  301. #ifndef CARLA_HOST_H_INCLUDED
  302. /* --------------------------------------------------------------------------------------------------------------------
  303. * information */
  304. /*!
  305. * Get the complete license text of used third-party code and features.
  306. * Returned string is in basic html format.
  307. */
  308. CARLA_PLUGIN_EXPORT const char* carla_get_complete_license_text(void);
  309. /*!
  310. * Get the juce version used in the current Carla build.
  311. */
  312. CARLA_PLUGIN_EXPORT const char* carla_get_juce_version(void);
  313. /*!
  314. * Get the list of supported file extensions in carla_load_file().
  315. */
  316. CARLA_PLUGIN_EXPORT const char* const* carla_get_supported_file_extensions(void);
  317. /*!
  318. * Get the list of supported features in the current Carla build.
  319. */
  320. CARLA_PLUGIN_EXPORT const char* const* carla_get_supported_features(void);
  321. /*!
  322. * Get the absolute filename of this carla library.
  323. */
  324. CARLA_PLUGIN_EXPORT const char* carla_get_library_filename(void);
  325. /*!
  326. * Get the folder where this carla library resides.
  327. */
  328. CARLA_PLUGIN_EXPORT const char* carla_get_library_folder(void);
  329. #endif
  330. /* --------------------------------------------------------------------------------------------------------------------
  331. * JUCE */
  332. /*!
  333. * Initialize data structures and GUI support for JUCE.
  334. * This is only needed when carla builds use JUCE and you call cached-plugin related APIs.
  335. *
  336. * Idle must then be called at somewhat regular intervals, though in practice there is no reason for it yet.
  337. *
  338. * Make sure to call carla_juce_cleanup after you are done with APIs that need JUCE.
  339. */
  340. CARLA_PLUGIN_EXPORT void carla_juce_init(void);
  341. /*!
  342. * Give idle time to JUCE stuff.
  343. * Currently only used for Linux.
  344. */
  345. CARLA_PLUGIN_EXPORT void carla_juce_idle(void);
  346. /*!
  347. * Cleanup the JUCE stuff that was initialized by carla_juce_init.
  348. */
  349. CARLA_PLUGIN_EXPORT void carla_juce_cleanup(void);
  350. /* --------------------------------------------------------------------------------------------------------------------
  351. * pipes */
  352. typedef void* CarlaPipeClientHandle;
  353. /*!
  354. * Callback for when a message has been received (in the context of carla_pipe_client_idle()).
  355. * If extra data is required, use any of the carla_pipe_client_readlineblock* functions.
  356. */
  357. typedef void (*CarlaPipeCallbackFunc)(void* ptr, const char* msg);
  358. /*!
  359. * Create and connect to pipes as used by a server.
  360. * @a argv must match the arguments set the by server.
  361. */
  362. CARLA_PLUGIN_EXPORT CarlaPipeClientHandle carla_pipe_client_new(const char* argv[],
  363. CarlaPipeCallbackFunc callbackFunc,
  364. void* callbackPtr);
  365. /*!
  366. * Check the pipe for new messages and send them to the callback function.
  367. */
  368. CARLA_PLUGIN_EXPORT void carla_pipe_client_idle(CarlaPipeClientHandle handle);
  369. /*!
  370. * Check if the pipe is running.
  371. */
  372. CARLA_PLUGIN_EXPORT bool carla_pipe_client_is_running(CarlaPipeClientHandle handle);
  373. /*!
  374. * Lock the pipe write mutex.
  375. */
  376. CARLA_PLUGIN_EXPORT void carla_pipe_client_lock(CarlaPipeClientHandle handle);
  377. /*!
  378. * Unlock the pipe write mutex.
  379. */
  380. CARLA_PLUGIN_EXPORT void carla_pipe_client_unlock(CarlaPipeClientHandle handle);
  381. /*!
  382. * Read the next line as a string.
  383. */
  384. CARLA_PLUGIN_EXPORT const char* carla_pipe_client_readlineblock(CarlaPipeClientHandle handle, uint timeout);
  385. /*!
  386. * Read the next line as a boolean.
  387. */
  388. CARLA_PLUGIN_EXPORT bool carla_pipe_client_readlineblock_bool(CarlaPipeClientHandle handle, uint timeout);
  389. /*!
  390. * Read the next line as an integer.
  391. */
  392. CARLA_PLUGIN_EXPORT int carla_pipe_client_readlineblock_int(CarlaPipeClientHandle handle, uint timeout);
  393. /*!
  394. * Read the next line as a floating point number (double precision).
  395. */
  396. CARLA_PLUGIN_EXPORT double carla_pipe_client_readlineblock_float(CarlaPipeClientHandle handle, uint timeout);
  397. /*!
  398. * Write a valid message.
  399. * A valid message has only one '\n' character and it's at the end.
  400. */
  401. CARLA_PLUGIN_EXPORT bool carla_pipe_client_write_msg(CarlaPipeClientHandle handle, const char* msg);
  402. /*!
  403. * Write and fix a message.
  404. */
  405. CARLA_PLUGIN_EXPORT bool carla_pipe_client_write_and_fix_msg(CarlaPipeClientHandle handle, const char* msg);
  406. /*!
  407. * Sync all messages currently in cache.
  408. * This call will forcely write any messages in cache to any relevant IO.
  409. */
  410. CARLA_PLUGIN_EXPORT bool carla_pipe_client_sync(CarlaPipeClientHandle handle);
  411. /*!
  412. * Convenience call for doing both sync and unlock in one-go.
  413. */
  414. CARLA_PLUGIN_EXPORT bool carla_pipe_client_sync_and_unlock(CarlaPipeClientHandle handle);
  415. /*!
  416. * Destroy a previously created pipes instance.
  417. */
  418. CARLA_PLUGIN_EXPORT void carla_pipe_client_destroy(CarlaPipeClientHandle handle);
  419. /* DEPRECATED use carla_pipe_client_sync */
  420. CARLA_PLUGIN_EXPORT bool carla_pipe_client_flush(CarlaPipeClientHandle handle);
  421. /* DEPRECATED use carla_pipe_client_sync_and_unlock */
  422. CARLA_PLUGIN_EXPORT bool carla_pipe_client_flush_and_unlock(CarlaPipeClientHandle handle);
  423. /* --------------------------------------------------------------------------------------------------------------------
  424. * system stuff */
  425. /*!
  426. * Flush stdout or stderr.
  427. */
  428. CARLA_PLUGIN_EXPORT void carla_fflush(bool err);
  429. /*!
  430. * Print the string @a string to stdout or stderr.
  431. */
  432. CARLA_PLUGIN_EXPORT void carla_fputs(bool err, const char* string);
  433. /*!
  434. * Set the current process name to @a name.
  435. */
  436. CARLA_PLUGIN_EXPORT void carla_set_process_name(const char* name);
  437. /* --------------------------------------------------------------------------------------------------------------------
  438. * window control */
  439. /*!
  440. * Get the global/desktop scale factor.
  441. */
  442. CARLA_PLUGIN_EXPORT double carla_get_desktop_scale_factor(void);
  443. CARLA_PLUGIN_EXPORT int carla_cocoa_get_window(void* nsViewPtr);
  444. CARLA_PLUGIN_EXPORT void carla_cocoa_set_transient_window_for(void* nsViewChild, void* nsViewParent);
  445. CARLA_PLUGIN_EXPORT void carla_x11_reparent_window(uintptr_t winId1, uintptr_t winId2);
  446. CARLA_PLUGIN_EXPORT void carla_x11_move_window(uintptr_t winId, int x, int y);
  447. CARLA_PLUGIN_EXPORT int* carla_x11_get_window_pos(uintptr_t winId);
  448. /* ----------------------------------------------------------------------------------------------------------------- */
  449. /** @} */
  450. #endif /* CARLA_UTILS_H_INCLUDED */