| 1 | /* Copyright 2012 Kjetil S. Matheussen |
| 2 | |
| 3 | This program is free software; you can redistribute it and/or |
| 4 | modify it under the terms of the GNU General Public License |
| 5 | as published by the Free Software Foundation; either version 2 |
| 6 | of the License, or (at your option) any later version. |
| 7 | |
| 8 | This program is distributed in the hope that it will be useful, |
| 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | GNU General Public License for more details. |
| 12 | |
| 13 | You should have received a copy of the GNU General Public License |
| 14 | along with this program; if not, write to the Free Software |
| 15 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ |
| 16 | |
| 17 | |
| 18 | |
| 19 | #ifndef AUDIO_SOUNDPLUGIN_H |
| 20 | #define AUDIO_SOUNDPLUGIN_Hcxx . . $ `audio/SoundPlugin.h:20:9`! |
| 21 | |
| 22 | #include "../common/hashmap_proc.h"cxx . . $ `<file>/common/hashmap_proc.h`/ |
| 23 | #include "Smooth_proc.h"cxx . . $ `<file>/audio/Smooth_proc.h`/ |
| 24 | |
| 25 | /* |
| 26 | get_effect_value / set_effect value is screwed up. |
| 27 | All the horrible code and hacks stems from the bad decision of scaling values between 0 and 1. |
| 28 | This must be fixed. |
| 29 | */ |
| 30 | |
| 31 | |
| 32 | #ifdef __cpluspluscxx . . $ `<built-in>:472:9`! |
| 33 | extern "C"{ |
| 34 | #endif |
| 35 | |
| 36 | enum{ |
| 37 | EFFNUM_INPUT_VOLUME = 0, // This one must be first. |
| 38 | EFFNUM_INPUT_VOLUME_ONOFF, |
| 39 | |
| 40 | EFFNUM_VOLUME, |
| 41 | EFFNUM_VOLUME_ONOFF, |
| 42 | |
| 43 | EFFNUM_OUTPUT_VOLUME, |
| 44 | EFFNUM_OUTPUT_VOLUME_ONOFF, |
| 45 | |
| 46 | EFFNUM_BUS1, |
| 47 | EFFNUM_BUS1_ONOFF, |
| 48 | |
| 49 | EFFNUM_BUS2, |
| 50 | EFFNUM_BUS2_ONOFF, |
| 51 | |
| 52 | EFFNUM_PAN, |
| 53 | EFFNUM_PAN_ONOFF, |
| 54 | |
| 55 | EFFNUM_DRYWET, |
| 56 | EFFNUM_EFFECTS_ONOFF, |
| 57 | |
| 58 | EFFNUM_LOWPASS_FREQ, |
| 59 | EFFNUM_LOWPASS_ONOFF, |
| 60 | |
| 61 | EFFNUM_EQ1_FREQ, |
| 62 | EFFNUM_EQ1_GAIN, |
| 63 | EFFNUM_EQ1_ONOFF, |
| 64 | |
| 65 | EFFNUM_EQ2_FREQ, |
| 66 | EFFNUM_EQ2_GAIN, |
| 67 | EFFNUM_EQ2_ONOFF, |
| 68 | |
| 69 | EFFNUM_LOWSHELF_FREQ, |
| 70 | EFFNUM_LOWSHELF_GAIN, |
| 71 | EFFNUM_LOWSHELF_ONOFF, |
| 72 | |
| 73 | EFFNUM_HIGHSHELF_FREQ, |
| 74 | EFFNUM_HIGHSHELF_GAIN, |
| 75 | EFFNUM_HIGHSHELF_ONOFF, |
| 76 | |
| 77 | EFFNUM_EQ_SHOW_GUI, |
| 78 | |
| 79 | EFFNUM_COMP_RATIO, // Note that the order for the compressor parameters must be the same as the compressor parameters in system_compresssor_wrapper_proc.h |
| 80 | EFFNUM_COMP_THRESHOLD, |
| 81 | EFFNUM_COMP_ATTACK, |
| 82 | EFFNUM_COMP_RELEASE, |
| 83 | EFFNUM_COMP_OUTPUT_VOLUME, |
| 84 | EFFNUM_COMP_ONOFF, |
| 85 | |
| 86 | EFFNUM_COMP_SHOW_GUI, |
| 87 | |
| 88 | EFFNUM_DELAY_TIME, |
| 89 | EFFNUM_DELAY_ONOFF, |
| 90 | |
| 91 | NUM_SYSTEM_EFFECTS |
| 92 | }; |
| 93 | |
| 94 | |
| 95 | |
| 96 | enum{ |
| 97 | EFFECT_FORMAT_FLOAT, |
| 98 | EFFECT_FORMAT_INT, |
| 99 | EFFECT_FORMAT_BOOL, |
| 100 | EFFECT_FORMAT_RADIO |
| 101 | }; |
| 102 | |
| 103 | enum ValueFormat{ |
| 104 | PLUGIN_FORMAT_NATIVE, |
| 105 | PLUGIN_FORMAT_SCALED // scaled between 0 and 1 |
| 106 | }; |
| 107 | |
| 108 | struct SoundPlugin; |
| 109 | |
| 110 | #if 0 |
| 111 | // maybe |
| 112 | struct SoundPluginEffect{ |
| 113 | float (*get_effect_display_min_value)(const struct SoundPluginType *plugin_type); |
| 114 | float (*get_effect_display_max_value)(const struct SoundPluginType *plugin_type); |
| 115 | int (*get_effect_format)(const struct SoundPluginType *plugin_type); // Must return one of the EFFECT_* values above. |
| 116 | |
| 117 | const char *(*get_effect_name)(const struct SoundPluginType *plugin_type); |
| 118 | const char *(*get_effect_description)(const struct SoundPluginType *plugin_type); |
| 119 | |
| 120 | void (*get_display_value_string)(struct SoundPlugin *plugin, char *buffer, int buffersize); |
| 121 | |
| 122 | // Returns true if you want to call SP_RT_get_effect_value_array to get effect values for this effect. |
| 123 | // If not, set_effect_value will be called instead. |
| 124 | bool (*effect_is_RT)(const struct SoundPluginType *plugin_type); |
| 125 | |
| 126 | // This functions is called if SoundPluginType->effect_is_RT(effect_num) returns false |
| 127 | void (*set_effect_value)(struct SoundPlugin *plugin, int64_t time, float value); |
| 128 | |
| 129 | float (*get_effect_value)(struct SoundPlugin *plugin_type); |
| 130 | }; |
| 131 | #endif |
| 132 | |
| 133 | |
| 134 | // Note that only the fields 'name' and 'is_instrument' will be accessed before the call to 'create_plugin_data'. |
| 135 | // The 'is_instrument' field will also be re-read after a call to 'create_plugin_data', in case it had the wrong value before. |
| 136 | typedef struct SoundPluginType{ |
| 137 | const char *type_name; // I.e. Ladspa / Vst / FluidSynth / etc. Must be unique. |
| 138 | const char *name; // i.e. zita-reverb / low-pass filter / etc. Must be unique within plugins with the same type_name. |
| 139 | |
| 140 | const char *info; // Contains text inside the info box which appear when pressing the button with the name of the plugin. Can be NULL. |
| 141 | |
| 142 | int num_inputs; |
| 143 | int num_outputs; |
| 144 | |
| 145 | bool is_instrument; // Should be set to true if it is not known until instantiation whether it is an instrument. |
| 146 | |
| 147 | bool note_handling_is_RT; |
| 148 | |
| 149 | int num_effects; |
| 150 | |
| 151 | bool plugin_takes_care_of_savable_values; // For instance, if a VST plugin has it's own editor, we ask the plugin for values instead of using savable_effect_values (which contains the last set value). Then this value is true. |
| 152 | |
| 153 | int (*get_effect_format)(const struct SoundPluginType *plugin_type, int effect_num); // Must return one of the EFFECT_* values above. |
| 154 | |
| 155 | int (*get_effect_num)(const struct SoundPluginType *plugin_type, const char *effect_name); // Necessary to implement this if the order of effects may change in the future. |
| 156 | const char *(*get_effect_name)(const struct SoundPluginType *plugin_type, int effect_num); // The effect name is used as effect id. Two effects can not have the same name. |
| 157 | const char *(*get_effect_description)(const struct SoundPluginType *plugin_type, int effect_num); |
| 158 | |
| 159 | void (*get_display_value_string)(struct SoundPlugin *plugin, int effect_num, char *buffer, int buffersize); |
| 160 | |
| 161 | // Returns true if you want to call SP_RT_get_effect_value_array to get effect values for this effect. |
| 162 | // If not, set_effect_value will be called instead. |
| 163 | bool (*effect_is_RT)(const struct SoundPluginType *plugin_type, int effect_num); |
| 164 | |
| 165 | void *(*create_plugin_data)(const struct SoundPluginType *plugin_type, struct SoundPlugin *plugin, float sample_rate, int block_size); // Called by Radium during the instantiation of a plugin. The function returns plugin->data. |
| 166 | void (*cleanup_plugin_data)(struct SoundPlugin *plugin); |
| 167 | |
| 168 | // If set, this callback will be called when the 'num_frames' argument to RT_process changes. The audio thread is suspended while this function is called. |
| 169 | void (*buffer_size_is_changed)(struct SoundPlugin *plugin, int new_buffer_size); |
| 170 | |
| 171 | // The sound processing function. Note that the inputs and outputs arrays are likely to point to the same sound buffers. |
| 172 | // For instance, if the plugin has one input and one output, inputs[0] and outputs[0] are very likely to be equal. |
| 173 | void (*RT_process)(struct SoundPlugin *plugin, int64_t time, int num_frames, float **inputs, float **outputs); |
| 174 | |
| 175 | // These two functions are not used if SoundPluginType->note_handling_is_RT is false (currently, these two functions are note used at all) |
| 176 | void (*RT_play_note)(struct SoundPlugin *plugin, int64_t time, int note_num, float volume, float pan); |
| 177 | void (*RT_stop_note)(struct SoundPlugin *plugin, int64_t time, int note_num, float volume); |
| 178 | |
| 179 | // These three functions are not used if SoundPluginType->note_handling_is_RT is true |
| 180 | void (*play_note)(struct SoundPlugin *plugin, int64_t time, int note_num, float volume, float pan); |
| 181 | void (*set_note_volume)(struct SoundPlugin *plugin, int64_t time, int note_num, float volume); |
| 182 | void (*stop_note)(struct SoundPlugin *plugin, int64_t time, int note_num, float volume); |
| 183 | |
| 184 | // Returns the number of channels it can provide peaks for. (calling this function with ch=-1 is considered a dummy operation, except that the return value is correct) |
| 185 | int (*get_peaks)(struct SoundPlugin *plugin, int note_num, int ch, float pan, int64_t start_time, int64_t end_time, float *min_value, float *max_value); |
| 186 | |
| 187 | // This functions is called if SoundPluginType->effect_is_RT(effect_num) returns false |
| 188 | void (*set_effect_value)(struct SoundPlugin *plugin, int64_t time, int effect_num, float value, enum ValueFormat value_format); |
| 189 | |
| 190 | float (*get_effect_value)(struct SoundPlugin *plugin, int effect_num, enum ValueFormat value_format); |
| 191 | |
| 192 | void (*show_gui)(struct SoundPlugin *plugin); |
| 193 | void (*hide_gui)(struct SoundPlugin *plugin); |
| 194 | |
| 195 | void (*recreate_from_state)(struct SoundPlugin *plugin, hash_tcxx . . $ hash_t# *state); |
| 196 | void (*create_state)(struct SoundPlugin *plugin, hash_tcxx . . $ hash_t# *state); |
| 197 | |
| 198 | // Free use by the plugin |
| 199 | void *data; |
| 200 | |
| 201 | // Used by Radium |
| 202 | int instance_num; // Only used to autocreate a name |
| 203 | |
| 204 | } SoundPluginType; |
| 205 | |
| 206 | typedef struct SystemFilter{ |
| 207 | struct SoundPlugin **plugins; |
| 208 | bool is_on; |
| 209 | bool was_on; |
| 210 | bool was_off; |
| 211 | } SystemFilter; |
| 212 | |
| 213 | enum BusDescendantType{ |
| 214 | IS_BUS_DESCENDANT, |
| 215 | IS_NOT_A_BUS_DESCENDANT, |
| 216 | MAYBE_A_BUS_DESCENDANT, |
| 217 | }; |
| 218 | |
| 219 | typedef struct SoundPlugin{ |
| 220 | const SoundPluginType *type; |
| 221 | |
| 222 | // Data used by the plugin (the value returned by 'create_plugin_data') |
| 223 | void *data; |
| 224 | |
| 225 | // Data below handled by Radium. |
| 226 | |
| 227 | struct Patchcxx . . $ Patch# *patch; // The patch points to the plugin and the plugin points to the patch. However, the patch outlives the plugin. Plugin comes and goes, while the patch stays. |
| 228 | // Beware that this value might be NULL. |
| 229 | |
| 230 | float *savable_effect_values; // When dragging a slider, we want to save that value. But we don't want to save the last sent out automation value. (saving to disk, that is) |
| 231 | float *initial_effect_values; // Used when resetting. |
| 232 | |
| 233 | bool editor_is_on; |
| 234 | |
| 235 | // Data used by SoundProducer |
| 236 | Smoothcxx . . $ Smooth# input_volume; |
| 237 | bool input_volume_is_on; |
| 238 | |
| 239 | float volume; |
| 240 | bool volume_is_on; |
| 241 | |
| 242 | Smoothcxx . . $ Smooth# output_volume; |
| 243 | bool output_volume_is_on; |
| 244 | |
| 245 | Smoothcxx . . $ Smooth# bus_volume[2]; |
| 246 | bool bus_volume_is_on[2]; |
| 247 | |
| 248 | Smoothcxx . . $ Smooth# pan; // between 0 and 1 |
| 249 | bool pan_is_on; |
| 250 | |
| 251 | Smoothcxx . . $ Smooth# drywet; |
| 252 | bool effects_are_on; |
| 253 | |
| 254 | SystemFilter lowpass; |
| 255 | float lowpass_freq; |
| 256 | |
| 257 | SystemFilter eq1; |
| 258 | float eq1_freq; |
| 259 | float eq1_db; |
| 260 | |
| 261 | SystemFilter eq2; |
| 262 | float eq2_freq; |
| 263 | float eq2_db; |
| 264 | |
| 265 | SystemFilter lowshelf; |
| 266 | float lowshelf_freq; |
| 267 | float lowshelf_db; |
| 268 | |
| 269 | SystemFilter highshelf; |
| 270 | float highshelf_freq; |
| 271 | float highshelf_db; |
| 272 | |
| 273 | SystemFilter delay; |
| 274 | float delay_time; |
| 275 | |
| 276 | bool show_equalizer_gui; |
| 277 | |
| 278 | SystemFilter comp; |
| 279 | void *compressor; |
| 280 | |
| 281 | bool show_compressor_gui; |
| 282 | |
| 283 | float *volume_peak_values; |
| 284 | float *volume_peak_values_for_chip; |
| 285 | |
| 286 | float *output_volume_peak_values; |
| 287 | |
| 288 | float *input_volume_peak_values; |
| 289 | float *input_volume_peak_values_for_chip; |
| 290 | |
| 291 | float *system_volume_peak_values; // The one in the status bar. (Only if this is the system out plugin.) Set in Jack_plugin.c |
| 292 | float *bus_volume_peak_values[2]; |
| 293 | |
| 294 | enum BusDescendantType bus_descendant_type; // Is 'IS_BUS_DESCENDANT' for all descendants of bus plugins. To prevent accidental feedback loops. |
| 295 | |
| 296 | } SoundPlugin; |
| 297 | |
| 298 | |
| 299 | // Call this function to get effects from the realtime process. |
| 300 | // For instance, if there is a volume starting from 0.5, and ending at 1.0, in the current block of 1024 frames, |
| 301 | // then the function will return {0.5, 0.50048828125, 0.5009765625, ..., 1.0} |
| 302 | // |
| 303 | // This functions can only be called if SoundPluginType->effect_is_RT(effect_num) returns true |
| 304 | float *RT_get_effect_value_array(SoundPlugin *plugin, int effect_num); |
| 305 | |
| 306 | // RT_get_note_volume_array works the same way, but for note volumes. If several similar note_nums (i.e. same note_num value) |
| 307 | // are playing at the same time, the returned array will contain the values for one of those notes. It is undefined |
| 308 | // which of them. |
| 309 | // |
| 310 | // The functions can only be called if SoundPluginType->note_handling_is_RT is true |
| 311 | float *RT_get_note_volume_array(SoundPlugin *plugin, int note_num); |
| 312 | |
| 313 | |
| 314 | #ifdef __cpluspluscxx . . $ `<built-in>:472:9`! |
| 315 | } |
| 316 | #endif |
| 317 | |
| 318 | #endif // AUDIO_SOUNDPLUGIN_H |