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.

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