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.

529 lines
14KB

  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. PluginType ptype,
  257. const char* pluginPath,
  258. CarlaPluginDiscoveryCallback discoveryCb,
  259. CarlaPluginCheckCacheCallback checkCacheCb,
  260. void* callbackPtr);
  261. /*!
  262. * Continue discovering plugins, triggering callbacks along the way.
  263. * Returns false when there is nothing else to scan, then you MUST call @a carla_plugin_discovery_stop.
  264. */
  265. CARLA_PLUGIN_EXPORT bool carla_plugin_discovery_idle(CarlaPluginDiscoveryHandle handle);
  266. /*!
  267. * Skip the current plugin being discovered.
  268. * Carla automatically skips a plugin if 30s have passed without a reply from the discovery side,
  269. * this function allows to manually abort earlier than that.
  270. */
  271. CARLA_PLUGIN_EXPORT void carla_plugin_discovery_skip(CarlaPluginDiscoveryHandle handle);
  272. /*!
  273. * Stop plugin discovery.
  274. * Can be called early while the scanning is still active.
  275. */
  276. CARLA_PLUGIN_EXPORT void carla_plugin_discovery_stop(CarlaPluginDiscoveryHandle handle);
  277. /* --------------------------------------------------------------------------------------------------------------------
  278. * cached plugins */
  279. /*!
  280. * Get how many cached plugins are available.
  281. * Internal and LV2 plugin formats are cached and need to be discovered via this function.
  282. * Do not call this for any other plugin formats.
  283. *
  284. * @note if this carla build uses JUCE, then you must call carla_juce_init beforehand
  285. * @note for AU plugins, you cannot call this outside the main thread
  286. */
  287. CARLA_PLUGIN_EXPORT uint carla_get_cached_plugin_count(PluginType ptype, const char* pluginPath);
  288. /*!
  289. * Get information about a cached plugin.
  290. *
  291. * @note if this carla build uses JUCE, then you must call carla_juce_init beforehand
  292. * @note for AU plugins, you cannot call this outside the main thread
  293. */
  294. CARLA_PLUGIN_EXPORT const CarlaCachedPluginInfo* carla_get_cached_plugin_info(PluginType ptype, uint index);
  295. #ifndef CARLA_HOST_H_INCLUDED
  296. /* --------------------------------------------------------------------------------------------------------------------
  297. * information */
  298. /*!
  299. * Get the complete license text of used third-party code and features.
  300. * Returned string is in basic html format.
  301. */
  302. CARLA_PLUGIN_EXPORT const char* carla_get_complete_license_text(void);
  303. /*!
  304. * Get the juce version used in the current Carla build.
  305. */
  306. CARLA_PLUGIN_EXPORT const char* carla_get_juce_version(void);
  307. /*!
  308. * Get the list of supported file extensions in carla_load_file().
  309. */
  310. CARLA_PLUGIN_EXPORT const char* const* carla_get_supported_file_extensions(void);
  311. /*!
  312. * Get the list of supported features in the current Carla build.
  313. */
  314. CARLA_PLUGIN_EXPORT const char* const* carla_get_supported_features(void);
  315. /*!
  316. * Get the absolute filename of this carla library.
  317. */
  318. CARLA_PLUGIN_EXPORT const char* carla_get_library_filename(void);
  319. /*!
  320. * Get the folder where this carla library resides.
  321. */
  322. CARLA_PLUGIN_EXPORT const char* carla_get_library_folder(void);
  323. #endif
  324. /* --------------------------------------------------------------------------------------------------------------------
  325. * JUCE */
  326. /*!
  327. * Initialize data structures and GUI support for JUCE.
  328. * This is only needed when carla builds use JUCE and you call cached-plugin related APIs.
  329. *
  330. * Idle must then be called at somewhat regular intervals, though in practice there is no reason for it yet.
  331. *
  332. * Make sure to call carla_juce_cleanup after you are done with APIs that need JUCE.
  333. */
  334. CARLA_PLUGIN_EXPORT void carla_juce_init(void);
  335. /*!
  336. * Give idle time to JUCE stuff.
  337. * Currently only used for Linux.
  338. */
  339. CARLA_PLUGIN_EXPORT void carla_juce_idle(void);
  340. /*!
  341. * Cleanup the JUCE stuff that was initialized by carla_juce_init.
  342. */
  343. CARLA_PLUGIN_EXPORT void carla_juce_cleanup(void);
  344. /* --------------------------------------------------------------------------------------------------------------------
  345. * pipes */
  346. /*!
  347. * TODO.
  348. */
  349. typedef void* CarlaPipeClientHandle;
  350. /*!
  351. * TODO.
  352. */
  353. typedef void (*CarlaPipeCallbackFunc)(void* ptr, const char* msg);
  354. /*!
  355. * TODO.
  356. */
  357. CARLA_PLUGIN_EXPORT CarlaPipeClientHandle carla_pipe_client_new(const char* argv[], CarlaPipeCallbackFunc callbackFunc, void* callbackPtr);
  358. /*!
  359. * TODO.
  360. */
  361. CARLA_PLUGIN_EXPORT void carla_pipe_client_idle(CarlaPipeClientHandle handle);
  362. /*!
  363. * TODO.
  364. */
  365. CARLA_PLUGIN_EXPORT bool carla_pipe_client_is_running(CarlaPipeClientHandle handle);
  366. /*!
  367. * TODO.
  368. */
  369. CARLA_PLUGIN_EXPORT void carla_pipe_client_lock(CarlaPipeClientHandle handle);
  370. /*!
  371. * TODO.
  372. */
  373. CARLA_PLUGIN_EXPORT void carla_pipe_client_unlock(CarlaPipeClientHandle handle);
  374. /*!
  375. * TODO.
  376. */
  377. CARLA_PLUGIN_EXPORT const char* carla_pipe_client_readlineblock(CarlaPipeClientHandle handle, uint timeout);
  378. /*!
  379. * Extras.
  380. * TODO.
  381. */
  382. CARLA_PLUGIN_EXPORT bool carla_pipe_client_readlineblock_bool(CarlaPipeClientHandle handle, uint timeout);
  383. CARLA_PLUGIN_EXPORT int carla_pipe_client_readlineblock_int(CarlaPipeClientHandle handle, uint timeout);
  384. CARLA_PLUGIN_EXPORT double carla_pipe_client_readlineblock_float(CarlaPipeClientHandle handle, uint timeout);
  385. /*!
  386. * TODO.
  387. */
  388. CARLA_PLUGIN_EXPORT bool carla_pipe_client_write_msg(CarlaPipeClientHandle handle, const char* msg);
  389. /*!
  390. * TODO.
  391. */
  392. CARLA_PLUGIN_EXPORT bool carla_pipe_client_write_and_fix_msg(CarlaPipeClientHandle handle, const char* msg);
  393. /*!
  394. * TODO.
  395. */
  396. CARLA_PLUGIN_EXPORT bool carla_pipe_client_flush(CarlaPipeClientHandle handle);
  397. /*!
  398. * TODO.
  399. */
  400. CARLA_PLUGIN_EXPORT bool carla_pipe_client_flush_and_unlock(CarlaPipeClientHandle handle);
  401. /*!
  402. * TODO.
  403. */
  404. CARLA_PLUGIN_EXPORT void carla_pipe_client_destroy(CarlaPipeClientHandle handle);
  405. /* --------------------------------------------------------------------------------------------------------------------
  406. * system stuff */
  407. /*!
  408. * Flush stdout or stderr.
  409. */
  410. CARLA_PLUGIN_EXPORT void carla_fflush(bool err);
  411. /*!
  412. * Print the string @a string to stdout or stderr.
  413. */
  414. CARLA_PLUGIN_EXPORT void carla_fputs(bool err, const char* string);
  415. /*!
  416. * Set the current process name to @a name.
  417. */
  418. CARLA_PLUGIN_EXPORT void carla_set_process_name(const char* name);
  419. /* --------------------------------------------------------------------------------------------------------------------
  420. * window control */
  421. /*!
  422. * Get the global/desktop scale factor.
  423. */
  424. CARLA_PLUGIN_EXPORT double carla_get_desktop_scale_factor(void);
  425. CARLA_PLUGIN_EXPORT int carla_cocoa_get_window(void* nsViewPtr);
  426. CARLA_PLUGIN_EXPORT void carla_cocoa_set_transient_window_for(void* nsViewChild, void* nsViewParent);
  427. CARLA_PLUGIN_EXPORT void carla_x11_reparent_window(uintptr_t winId1, uintptr_t winId2);
  428. CARLA_PLUGIN_EXPORT void carla_x11_move_window(uintptr_t winId, int x, int y);
  429. CARLA_PLUGIN_EXPORT int* carla_x11_get_window_pos(uintptr_t winId);
  430. /* ----------------------------------------------------------------------------------------------------------------- */
  431. /** @} */
  432. #endif /* CARLA_UTILS_H_INCLUDED */