1 /* 2 * Copyright (C) 2018-2021 Alexandros Theodotou <alex at zrythm dot org> 3 * 4 * This file is part of Zrythm 5 * 6 * Zrythm is free software: you can redistribute it and/or modify 7 * it under the terms of the GNU Affero General Public License as published by 8 * the Free Software Foundation, either version 3 of the License, or 9 * (at your option) any later version. 10 * 11 * Zrythm is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU Affero General Public License for more details. 15 * 16 * You should have received a copy of the GNU Affero General Public License 17 * along with Zrythm. If not, see <https://www.gnu.org/licenses/>. 18 */ 19 20 /** 21 * \file 22 * 23 * Base plugin. 24 */ 25 26 #ifndef __PLUGINS_PLUGIN_DESCRIPTOR_H__ 27 #define __PLUGINS_PLUGIN_DESCRIPTOR_H__ 28 29 #include "zrythm-config.h" 30 31 #include <stdbool.h> 32 33 #include "utils/yaml.h" 34 35 /** 36 * @addtogroup plugins 37 * 38 * @{ 39 */ 40 41 #define PLUGIN_DESCRIPTOR_SCHEMA_VERSION 1 42 43 /** 44 * Plugin category. 45 */ 46 typedef enum ZPluginCategory 47 { 48 /** None specified. */ 49 ZPLUGIN_CATEGORY_NONE, 50 PC_DELAY, 51 PC_REVERB, 52 PC_DISTORTION, 53 PC_WAVESHAPER, 54 PC_DYNAMICS, 55 PC_AMPLIFIER, 56 PC_COMPRESSOR, 57 PC_ENVELOPE, 58 PC_EXPANDER, 59 PC_GATE, 60 PC_LIMITER, 61 PC_FILTER, 62 PC_ALLPASS_FILTER, 63 PC_BANDPASS_FILTER, 64 PC_COMB_FILTER, 65 PC_EQ, 66 PC_MULTI_EQ, 67 PC_PARA_EQ, 68 PC_HIGHPASS_FILTER, 69 PC_LOWPASS_FILTER, 70 PC_GENERATOR, 71 PC_CONSTANT, 72 PC_INSTRUMENT, 73 PC_OSCILLATOR, 74 PC_MIDI, 75 PC_MODULATOR, 76 PC_CHORUS, 77 PC_FLANGER, 78 PC_PHASER, 79 PC_SIMULATOR, 80 PC_SIMULATOR_REVERB, 81 PC_SPATIAL, 82 PC_SPECTRAL, 83 PC_PITCH, 84 PC_UTILITY, 85 PC_ANALYZER, 86 PC_CONVERTER, 87 PC_FUNCTION, 88 PC_MIXER, 89 } ZPluginCategory; 90 91 static const cyaml_strval_t 92 plugin_descriptor_category_strings[] = 93 { 94 { "None", ZPLUGIN_CATEGORY_NONE }, 95 { "Delay", PC_DELAY }, 96 { "Reverb", PC_REVERB }, 97 { "Distortion", PC_DISTORTION }, 98 { "Waveshaper", PC_WAVESHAPER }, 99 { "Dynamics", PC_DYNAMICS }, 100 { "Amplifier", PC_AMPLIFIER }, 101 { "Compressor", PC_COMPRESSOR }, 102 { "Envelope", PC_ENVELOPE }, 103 { "Expander", PC_EXPANDER }, 104 { "Gate", PC_GATE }, 105 { "Limiter", PC_LIMITER }, 106 { "Filter", PC_FILTER }, 107 { "Allpass Filter", PC_ALLPASS_FILTER }, 108 { "Bandpass Filter", PC_BANDPASS_FILTER }, 109 { "Comb Filter", PC_COMB_FILTER }, 110 { "EQ", PC_EQ }, 111 { "Multi-EQ", PC_MULTI_EQ }, 112 { "Parametric EQ", PC_PARA_EQ }, 113 { "Highpass Filter", PC_HIGHPASS_FILTER }, 114 { "Lowpass Filter", PC_LOWPASS_FILTER }, 115 { "Generator", PC_GENERATOR }, 116 { "Constant", PC_CONSTANT }, 117 { "Instrument", PC_INSTRUMENT }, 118 { "Oscillator", PC_OSCILLATOR }, 119 { "MIDI", PC_MIDI }, 120 { "Modulator", PC_MODULATOR }, 121 { "Chorus", PC_CHORUS }, 122 { "Flanger", PC_FLANGER }, 123 { "Phaser", PC_PHASER }, 124 { "Simulator", PC_SIMULATOR }, 125 { "Simulator Reverb", PC_SIMULATOR_REVERB }, 126 { "Spatial", PC_SPATIAL }, 127 { "Spectral", PC_SPECTRAL }, 128 { "Pitch", PC_PITCH }, 129 { "Utility", PC_UTILITY }, 130 { "Analyzer", PC_ANALYZER }, 131 { "Converter", PC_CONVERTER }, 132 { "Function", PC_FUNCTION }, 133 { "Mixer", PC_MIXER }, 134 }; 135 136 /** 137 * Plugin protocol. 138 */ 139 typedef enum PluginProtocol 140 { 141 /** Dummy protocol for tests. */ 142 PROT_DUMMY, 143 PROT_LV2, 144 PROT_DSSI, 145 PROT_LADSPA, 146 PROT_VST, 147 PROT_VST3, 148 PROT_AU, 149 PROT_SFZ, 150 PROT_SF2, 151 } PluginProtocol; 152 153 static const cyaml_strval_t 154 plugin_protocol_strings[] = 155 { 156 { __("Dummy"), PROT_DUMMY }, 157 { "LV2", PROT_LV2 }, 158 { "DSSI", PROT_DSSI }, 159 { "LADSPA", PROT_LADSPA }, 160 { "VST", PROT_VST }, 161 { "VST3", PROT_VST3 }, 162 { "AU", PROT_AU }, 163 { "SFZ", PROT_SFZ }, 164 { "SF2", PROT_SF2 }, 165 }; 166 167 /** 168 * 32 or 64 bit. 169 */ 170 typedef enum PluginArchitecture 171 { 172 ARCH_32, 173 ARCH_64 174 } PluginArchitecture; 175 176 static const cyaml_strval_t 177 plugin_architecture_strings[] = 178 { 179 { "32-bit", ARCH_32 }, 180 { "64-bit", ARCH_64 }, 181 }; 182 183 /** 184 * Carla bridge mode. 185 */ 186 typedef enum CarlaBridgeMode 187 { 188 CARLA_BRIDGE_NONE, 189 CARLA_BRIDGE_UI, 190 CARLA_BRIDGE_FULL, 191 } CarlaBridgeMode; 192 193 static const cyaml_strval_t 194 carla_bridge_mode_strings[] = 195 { 196 { "None", CARLA_BRIDGE_NONE }, 197 { "UI", CARLA_BRIDGE_UI }, 198 { "Full", CARLA_BRIDGE_FULL }, 199 }; 200 201 /*** 202 * A descriptor to be implemented by all plugins 203 * This will be used throughout the UI 204 */ 205 typedef struct PluginDescriptor 206 { 207 int schema_version; 208 char * author; 209 char * name; 210 char * website; 211 ZPluginCategory category; 212 /** Lv2 plugin subcategory. */ 213 char * category_str; 214 /** Number of audio input ports. */ 215 int num_audio_ins; 216 /** Number of MIDI input ports. */ 217 int num_midi_ins; 218 /** Number of audio output ports. */ 219 int num_audio_outs; 220 /** Number of MIDI output ports. */ 221 int num_midi_outs; 222 /** Number of input control (plugin param) 223 * ports. */ 224 int num_ctrl_ins; 225 /** Number of output control (plugin param) 226 * ports. */ 227 int num_ctrl_outs; 228 /** Number of input CV ports. */ 229 int num_cv_ins; 230 /** Number of output CV ports. */ 231 int num_cv_outs; 232 /** Architecture (32/64bit). */ 233 PluginArchitecture arch; 234 /** Plugin protocol (Lv2/DSSI/LADSPA/VST/etc.). */ 235 PluginProtocol protocol; 236 /** Path, if not an Lv2Plugin which uses URIs. */ 237 char * path; 238 /** Lv2Plugin URI. */ 239 char * uri; 240 241 /** Used for VST. */ 242 int64_t unique_id; 243 244 /** Minimum required bridge mode. */ 245 CarlaBridgeMode min_bridge_mode; 246 247 bool has_custom_ui; 248 249 /** Hash of the plugin's bundle (.so/.ddl for VST) 250 * used when caching PluginDescriptor's, obtained 251 * using g_file_hash(). */ 252 unsigned int ghash; 253 } PluginDescriptor; 254 255 static const cyaml_schema_field_t 256 plugin_descriptor_fields_schema[] = 257 { 258 YAML_FIELD_INT ( 259 PluginDescriptor, schema_version), 260 YAML_FIELD_STRING_PTR_OPTIONAL ( 261 PluginDescriptor, author), 262 YAML_FIELD_STRING_PTR_OPTIONAL ( 263 PluginDescriptor, name), 264 YAML_FIELD_STRING_PTR_OPTIONAL ( 265 PluginDescriptor, website), 266 YAML_FIELD_ENUM ( 267 PluginDescriptor, category, 268 plugin_descriptor_category_strings), 269 YAML_FIELD_STRING_PTR_OPTIONAL ( 270 PluginDescriptor, category_str), 271 YAML_FIELD_INT ( 272 PluginDescriptor, num_audio_ins), 273 YAML_FIELD_INT ( 274 PluginDescriptor, num_audio_outs), 275 YAML_FIELD_INT ( 276 PluginDescriptor, num_midi_ins), 277 YAML_FIELD_INT ( 278 PluginDescriptor, num_midi_outs), 279 YAML_FIELD_INT ( 280 PluginDescriptor, num_ctrl_ins), 281 YAML_FIELD_INT ( 282 PluginDescriptor, num_ctrl_outs), 283 YAML_FIELD_INT ( 284 PluginDescriptor, num_cv_ins), 285 YAML_FIELD_UINT ( 286 PluginDescriptor, unique_id), 287 YAML_FIELD_INT ( 288 PluginDescriptor, num_cv_outs), 289 YAML_FIELD_ENUM ( 290 PluginDescriptor, arch, 291 plugin_architecture_strings), 292 YAML_FIELD_ENUM ( 293 PluginDescriptor, protocol, 294 plugin_protocol_strings), 295 YAML_FIELD_STRING_PTR_OPTIONAL ( 296 PluginDescriptor, path), 297 YAML_FIELD_STRING_PTR_OPTIONAL ( 298 PluginDescriptor, uri), 299 YAML_FIELD_ENUM ( 300 PluginDescriptor, min_bridge_mode, 301 carla_bridge_mode_strings), 302 YAML_FIELD_INT ( 303 PluginDescriptor, has_custom_ui), 304 YAML_FIELD_UINT ( 305 PluginDescriptor, ghash), 306 307 CYAML_FIELD_END 308 }; 309 310 static const cyaml_schema_value_t 311 plugin_descriptor_schema = 312 { 313 YAML_VALUE_PTR ( 314 PluginDescriptor, 315 plugin_descriptor_fields_schema), 316 }; 317 318 PluginDescriptor * 319 plugin_descriptor_new (void); 320 321 const char * 322 plugin_protocol_to_str ( 323 PluginProtocol prot); 324 325 /** 326 * Clones the plugin descriptor. 327 */ 328 NONNULL 329 void 330 plugin_descriptor_copy ( 331 PluginDescriptor * dest, 332 const PluginDescriptor * src); 333 334 /** 335 * Clones the plugin descriptor. 336 */ 337 NONNULL 338 PluginDescriptor * 339 plugin_descriptor_clone ( 340 const PluginDescriptor * src); 341 342 /** 343 * Returns if the Plugin is an instrument or not. 344 */ 345 NONNULL 346 bool 347 plugin_descriptor_is_instrument ( 348 const PluginDescriptor * descr); 349 350 /** 351 * Returns if the Plugin is an effect or not. 352 */ 353 NONNULL 354 bool 355 plugin_descriptor_is_effect ( 356 PluginDescriptor * descr); 357 358 /** 359 * Returns if the Plugin is a modulator or not. 360 */ 361 NONNULL 362 int 363 plugin_descriptor_is_modulator ( 364 PluginDescriptor * descr); 365 366 /** 367 * Returns if the Plugin is a midi modifier or not. 368 */ 369 NONNULL 370 int 371 plugin_descriptor_is_midi_modifier ( 372 PluginDescriptor * descr); 373 374 /** 375 * Returns the ZPluginCategory matching the given 376 * string. 377 */ 378 NONNULL 379 ZPluginCategory 380 plugin_descriptor_string_to_category ( 381 const char * str); 382 383 char * 384 plugin_descriptor_category_to_string ( 385 ZPluginCategory category); 386 387 /** 388 * Returns if the given plugin identifier can be 389 * dropped in a slot of the given type. 390 */ 391 bool 392 plugin_descriptor_is_valid_for_slot_type ( 393 PluginDescriptor * self, 394 int slot_type, 395 int track_type); 396 397 /** 398 * Returns whether the two descriptors describe 399 * the same plugin, ignoring irrelevant fields. 400 */ 401 NONNULL 402 bool 403 plugin_descriptor_is_same_plugin ( 404 const PluginDescriptor * a, 405 const PluginDescriptor * b); 406 407 /** 408 * Returns if the Plugin has a supported custom 409 * UI. 410 */ 411 NONNULL 412 bool 413 plugin_descriptor_has_custom_ui ( 414 const PluginDescriptor * self); 415 416 /** 417 * Returns the minimum bridge mode required for this 418 * plugin. 419 */ 420 NONNULL 421 CarlaBridgeMode 422 plugin_descriptor_get_min_bridge_mode ( 423 const PluginDescriptor * self); 424 425 NONNULL 426 void 427 plugin_descriptor_free ( 428 PluginDescriptor * self); 429 430 /** 431 * @} 432 */ 433 434 #endif 435