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.

546 lines
15KB

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