utils.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489
  1. // SPDX-FileCopyrightText: 2012-2025 MOD Audio UG
  2. // SPDX-License-Identifier: AGPL-3.0-or-later
  3. #ifndef MOD_UTILS_H_INCLUDED
  4. #define MOD_UTILS_H_INCLUDED
  5. #ifdef __cplusplus
  6. #include <cstdint>
  7. extern "C" {
  8. #else
  9. #include <stdint.h>
  10. #endif
  11. #ifdef _WIN32
  12. #define MOD_API __declspec (dllexport)
  13. #else
  14. #define MOD_API __attribute__ ((visibility("default")))
  15. #endif
  16. typedef enum {
  17. kPluginLicenseNonCommercial = 0,
  18. kPluginLicenseTrial = -1,
  19. kPluginLicensePaid = 1,
  20. } PluginLicenseType;
  21. typedef enum {
  22. kPluginIONull = 0,
  23. kPluginIOAudioMono = 1,
  24. kPluginIOAudioStereo = 2,
  25. kPluginIOInstrument = 3,
  26. kPluginIOMIDI = 4,
  27. } PluginIOType;
  28. typedef enum {
  29. kPedalboardInfoUserOnly = 0,
  30. kPedalboardInfoFactoryOnly = 1,
  31. kPedalboardInfoBoth = 2,
  32. } PedalboardInfoType;
  33. typedef struct {
  34. const char* name;
  35. const char* homepage;
  36. const char* email;
  37. } PluginAuthor;
  38. typedef struct {
  39. bool valid;
  40. unsigned int index;
  41. const char* name;
  42. const char* symbol;
  43. } PluginGUIPort;
  44. typedef struct {
  45. const char* resourcesDirectory;
  46. const char* iconTemplate;
  47. const char* settingsTemplate;
  48. const char* javascript;
  49. const char* stylesheet;
  50. const char* screenshot;
  51. const char* thumbnail;
  52. const char* discussionURL;
  53. const char* documentation;
  54. const char* brand;
  55. const char* label;
  56. const char* model;
  57. const char* panel;
  58. const char* color;
  59. const char* knob;
  60. PluginGUIPort* ports;
  61. const char* const* monitoredOutputs;
  62. } PluginGUI;
  63. typedef struct {
  64. const char* resourcesDirectory;
  65. const char* screenshot;
  66. const char* thumbnail;
  67. } PluginGUI_Mini;
  68. typedef struct {
  69. bool valid;
  70. const char* uri;
  71. const char* symbol;
  72. const char* name;
  73. int index;
  74. } PluginPortGroup;
  75. typedef struct {
  76. float min;
  77. float max;
  78. float def;
  79. } PluginPortRanges;
  80. typedef struct {
  81. const char* label;
  82. const char* render;
  83. const char* symbol;
  84. bool _custom; // internal
  85. } PluginPortUnits;
  86. typedef struct {
  87. bool valid;
  88. float value;
  89. const char* label;
  90. } PluginPortScalePoint;
  91. typedef struct {
  92. bool valid;
  93. unsigned int index;
  94. const char* name;
  95. const char* symbol;
  96. PluginPortRanges ranges;
  97. PluginPortUnits units;
  98. const char* comment;
  99. const char* designation;
  100. const char* group;
  101. const char* const* properties;
  102. int rangeSteps;
  103. const PluginPortScalePoint* scalePoints;
  104. const char* shortName;
  105. } PluginPort;
  106. typedef struct {
  107. PluginPort* input;
  108. PluginPort* output;
  109. } PluginPortsI;
  110. typedef struct {
  111. PluginPortsI audio;
  112. PluginPortsI control;
  113. PluginPortsI cv;
  114. PluginPortsI midi;
  115. } PluginPorts;
  116. typedef struct {
  117. int64_t min;
  118. int64_t max;
  119. int64_t def;
  120. } PluginLongParameterRanges;
  121. typedef struct {
  122. char type;
  123. union {
  124. PluginPortRanges f;
  125. PluginLongParameterRanges l;
  126. const char* s;
  127. };
  128. } PluginParameterRanges;
  129. typedef struct {
  130. bool valid;
  131. bool readable;
  132. bool writable;
  133. const char* uri;
  134. const char* label;
  135. const char* type;
  136. // for regular controls
  137. PluginParameterRanges ranges;
  138. PluginPortUnits units;
  139. const char* comment;
  140. const char* shortName;
  141. // for path stuff
  142. const char* const* fileTypes;
  143. const char* const* supportedExtensions;
  144. } PluginParameter;
  145. typedef struct {
  146. bool valid;
  147. const char* uri;
  148. const char* label;
  149. const char* path;
  150. } PluginPreset;
  151. typedef struct {
  152. bool valid;
  153. const char* uri;
  154. const char* name;
  155. const char* binary;
  156. const char* brand;
  157. const char* label;
  158. const char* license;
  159. const char* comment;
  160. const char* buildEnvironment;
  161. const char* const* category;
  162. int microVersion;
  163. int minorVersion;
  164. int release;
  165. int builder;
  166. int licensed; // PluginLicenseType
  167. int iotype; // PluginIOType
  168. bool hasExternalUI;
  169. const char* version;
  170. const char* stability;
  171. PluginAuthor author;
  172. const char* const* bundles;
  173. PluginGUI gui;
  174. PluginPorts ports;
  175. const PluginPortGroup* portGroups;
  176. const PluginParameter* parameters;
  177. const PluginPreset* presets;
  178. } PluginInfo;
  179. typedef struct {
  180. int licensed; // PluginLicenseType
  181. const PluginPreset* presets;
  182. } NonCachedPluginInfo;
  183. typedef struct {
  184. const char* uri;
  185. const char* name;
  186. const char* brand;
  187. const char* label;
  188. const char* comment;
  189. const char* buildEnvironment;
  190. const char* const* category;
  191. int microVersion;
  192. int minorVersion;
  193. int release;
  194. int builder;
  195. int licensed; // PluginLicenseType
  196. int iotype; // PluginIOType
  197. PluginGUI_Mini gui;
  198. } PluginInfo_Mini;
  199. typedef struct {
  200. const PluginPort* controlInputs;
  201. const char* const* monitoredOutputs;
  202. const PluginParameter* parameters;
  203. const char* buildEnvironment;
  204. int microVersion;
  205. int minorVersion;
  206. int release;
  207. int builder;
  208. } PluginInfo_Essentials;
  209. typedef struct {
  210. int8_t channel;
  211. uint8_t control;
  212. // ranges added in v1.2, flag needed for old format compatibility
  213. bool hasRanges;
  214. float minimum;
  215. float maximum;
  216. } PedalboardMidiControl;
  217. typedef struct {
  218. bool valid;
  219. const char* symbol;
  220. float value;
  221. PedalboardMidiControl midiCC;
  222. } PedalboardPluginPort;
  223. typedef struct {
  224. bool visible;
  225. int index;
  226. } PerformancePluginInfo;
  227. typedef struct {
  228. bool valid;
  229. bool bypassed;
  230. int instanceNumber;
  231. const char* instance;
  232. const char* uri;
  233. PedalboardMidiControl bypassCC;
  234. float x;
  235. float y;
  236. const PedalboardPluginPort* ports;
  237. const char* preset;
  238. const char *label;
  239. PerformancePluginInfo performance;
  240. } PedalboardPlugin;
  241. typedef struct {
  242. bool valid;
  243. const char* source;
  244. const char* target;
  245. } PedalboardConnection;
  246. typedef struct {
  247. bool valid;
  248. const char* symbol;
  249. const char* name;
  250. } PedalboardHardwareMidiPort;
  251. typedef struct {
  252. unsigned int audio_ins;
  253. unsigned int audio_outs;
  254. unsigned int cv_ins;
  255. unsigned int cv_outs;
  256. const PedalboardHardwareMidiPort* midi_ins;
  257. const PedalboardHardwareMidiPort* midi_outs;
  258. bool serial_midi_in;
  259. bool serial_midi_out;
  260. bool midi_merger_out;
  261. bool midi_broadcaster_in;
  262. } PedalboardHardware;
  263. typedef enum {
  264. kPedalboardTimeAvailableBPB = 0x1,
  265. kPedalboardTimeAvailableBPM = 0x2,
  266. kPedalboardTimeAvailableRolling = 0x4,
  267. } PedalboardTimeInfoAvailableBits;
  268. typedef struct {
  269. unsigned int available;
  270. float bpb;
  271. PedalboardMidiControl bpbCC;
  272. float bpm;
  273. PedalboardMidiControl bpmCC;
  274. bool rolling;
  275. PedalboardMidiControl rollingCC;
  276. } PedalboardTimeInfo;
  277. typedef struct {
  278. const char* title;
  279. int width, height;
  280. bool factory;
  281. bool midi_separated_mode;
  282. bool midi_loopback;
  283. const PedalboardPlugin* plugins;
  284. const PedalboardConnection* connections;
  285. PedalboardHardware hardware;
  286. PedalboardTimeInfo timeInfo;
  287. unsigned int version;
  288. // modpedal:formatVersion, 1 when absent (files written up to MOD OS 1.14)
  289. unsigned int formatVersion;
  290. } PedalboardInfo;
  291. typedef struct {
  292. bool broken;
  293. bool factory;
  294. bool hasTrialPlugins;
  295. const char* uri;
  296. const char* bundle;
  297. const char* title;
  298. unsigned int version;
  299. } PedalboardInfo_Mini;
  300. typedef struct {
  301. bool valid;
  302. const char* symbol;
  303. float value;
  304. } StatePortValue;
  305. typedef struct {
  306. bool valid;
  307. bool bypassed;
  308. const char* instance;
  309. const char* preset;
  310. const StatePortValue* ports;
  311. } PedalboardPluginValues;
  312. typedef struct {
  313. float cpuLoad;
  314. unsigned xruns;
  315. bool rolling;
  316. double bpb;
  317. double bpm;
  318. } JackData;
  319. typedef void (*JackBufSizeChanged)(unsigned bufsize);
  320. typedef void (*JackPortAppeared)(const char* name, bool isOutput);
  321. typedef void (*JackPortDeleted)(const char* name);
  322. typedef void (*TrueBypassStateChanged)(bool left, bool right);
  323. typedef void (*CvExpInputModeChanged)(bool expPedalMode);
  324. // initialize
  325. MOD_API void init(void);
  326. // cleanup, cannot be used afterwards
  327. MOD_API void cleanup(void);
  328. // check if a bundle is loaded in our lilv world
  329. MOD_API bool is_bundle_loaded(const char* bundle);
  330. // add a bundle to our lilv world
  331. // returns uri list of added plugins (null for none)
  332. MOD_API const char* const* add_bundle_to_lilv_world(const char* bundle);
  333. // remove a bundle from our lilv world
  334. // returns uri list of removed plugins (null for none)
  335. MOD_API const char* const* remove_bundle_from_lilv_world(const char* bundle, const char* resource);
  336. // get list of all available plugins
  337. MOD_API const char* const* get_plugin_list(void);
  338. // get all available plugins
  339. // this triggers short scanning of all plugins
  340. MOD_API const PluginInfo_Mini* const* get_all_plugins(void);
  341. // get a specific plugin
  342. // NOTE: may return null
  343. MOD_API const PluginInfo* get_plugin_info(const char* uri);
  344. // get a specific plugin (non-cached specific info)
  345. // NOTE: may return null
  346. MOD_API const NonCachedPluginInfo* get_non_cached_plugin_info(const char* uri);
  347. // get a specific plugin's modgui
  348. // NOTE: may return null
  349. MOD_API const PluginGUI* get_plugin_gui(const char* uri);
  350. // get a specific plugin's modgui (mini)
  351. // NOTE: may return null
  352. MOD_API const PluginGUI_Mini* get_plugin_gui_mini(const char* uri);
  353. // get all control inputs for a specific plugin
  354. MOD_API const PluginPort* get_plugin_control_inputs(const char* uri);
  355. // get essential plugin info for host control (control inputs, monitored outputs, parameters and build environment)
  356. MOD_API const PluginInfo_Essentials* get_plugin_info_essentials(const char* uri);
  357. // check if a plugin preset is valid (must exist)
  358. MOD_API bool is_plugin_preset_valid(const char* plugin, const char* preset);
  359. // trigger a preset rescan for a plugin the next time it's loaded
  360. MOD_API void rescan_plugin_presets(const char* uri);
  361. // get all available pedalboards (ie, plugins with pedalboard type)
  362. MOD_API const PedalboardInfo_Mini* const* get_all_pedalboards(int ptype);
  363. // get all currently "broken" pedalboards (ie, pedalboards which contain unavailable plugins)
  364. MOD_API const char* const* get_broken_pedalboards(void);
  365. // Get a specific pedalboard
  366. // NOTE: may return null
  367. MOD_API const PedalboardInfo* get_pedalboard_info(const char* bundle);
  368. // Get the size of a specific pedalboard
  369. // Returns a 2-size array with width and height
  370. // NOTE: may return null
  371. MOD_API int* get_pedalboard_size(const char* bundle);
  372. // Get plugin port values of a pedalboard
  373. // NOTE: may return null
  374. MOD_API const PedalboardPluginValues* get_pedalboard_plugin_values(const char* bundle);
  375. // Reset pedalboards related cache
  376. // Needed when plugins are added, as previous "broken" PBs might have been fixed with the change.
  377. MOD_API void reset_get_all_pedalboards_cache(int ptype);
  378. // Get port values from a plugin state
  379. MOD_API const StatePortValue* get_state_port_values(const char* state);
  380. // list plugins present in a single bundle
  381. MOD_API const char* const* list_plugins_in_bundle(const char* bundle);
  382. // Convert a file URI to a local path string.
  383. MOD_API const char* file_uri_parse(const char* fileuri);
  384. // jack stuff
  385. MOD_API bool init_jack(void);
  386. MOD_API void close_jack(void);
  387. MOD_API JackData* get_jack_data(bool withTransport);
  388. MOD_API unsigned get_jack_buffer_size(void);
  389. MOD_API unsigned set_jack_buffer_size(unsigned size);
  390. MOD_API float get_jack_sample_rate(void);
  391. MOD_API const char* get_jack_port_alias(const char* portname);
  392. MOD_API const char* const* get_jack_hardware_ports(const bool isAudio, bool isOutput);
  393. MOD_API bool has_midi_beat_clock_sender_port(void);
  394. MOD_API bool has_serial_midi_input_port(void);
  395. MOD_API bool has_serial_midi_output_port(void);
  396. MOD_API bool has_midi_merger_output_port(void);
  397. MOD_API bool has_midi_broadcaster_input_port(void);
  398. MOD_API bool has_duox_split_spdif(void);
  399. MOD_API bool connect_jack_ports(const char* port1, const char* port2);
  400. MOD_API bool connect_jack_midi_output_ports(const char* port);
  401. MOD_API bool disconnect_jack_ports(const char* port1, const char* port2);
  402. MOD_API bool disconnect_all_jack_ports(const char* port);
  403. MOD_API void reset_xruns(void);
  404. // alsa stuff
  405. MOD_API void init_bypass(void);
  406. MOD_API bool get_truebypass_value(bool right);
  407. MOD_API bool set_truebypass_value(bool right, bool bypassed);
  408. MOD_API float get_master_volume(bool right);
  409. // callbacks
  410. MOD_API void set_util_callbacks(JackBufSizeChanged bufSizeChanged,
  411. JackPortAppeared portAppeared,
  412. JackPortDeleted portDeleted,
  413. TrueBypassStateChanged trueBypassChanged);
  414. // special case until HMI<->system comm is not in place yet
  415. MOD_API void set_extra_util_callbacks(CvExpInputModeChanged cvExpInputModeChanged);
  416. #ifdef __cplusplus
  417. } // extern "C"
  418. #endif
  419. #endif // MOD_UTILS_H_INCLUDED