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.

526 lines
14KB

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