1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236
|
#ifndef AUDIO_EFFECT_H
#define AUDIO_EFFECT_H
#include "dsp/frame.h"
#include "dsp/midi_event.h"
#include "globals/json.h"
#include "rstring.h"
#include "vector.h"
#include <memory>
class AudioEffect;
class AudioEffectFactory;
struct AudioEffectInfo;
class AudioEffectProvider {
public:
enum {
MAX_SCAN_PATHS = 256
};
private:
static String scan_paths[MAX_SCAN_PATHS];
public:
typedef void (*ScanCallback)(const String &, void *);
static void set_scan_path(int p_index, const String &p_path);
static String get_scan_path(int p_index);
virtual AudioEffect *instantiate_effect(const AudioEffectInfo *p_info) = 0;
virtual void scan_effects(AudioEffectFactory *p_factory, ScanCallback p_callback, void *p_userdata) = 0;
virtual String get_id() const = 0;
virtual String get_name() const = 0;
};
struct AudioEffectInfo {
String caption; ///< Caption of the Node (for node browser menu)
String description; ///< Short description of the node (for node browser / node info )
String author; ///< plugin author
String unique_ID; ///< Unique String ID of node (so it is reconizable when saving)
String provider_caption;
String category; ///< String to categorize this node (for node browser)
String icon_string; ///< icon string (to look up for an bundled icon - internal nodes)
String version;
bool synth;
bool has_ui;
bool internal;
String provider_id;
String path;
AudioEffectInfo() {
has_ui = false;
synth = false;
internal = false;
}
};
struct PortRangeHint {
float min, max, def;
String max_str, min_str;
};
class ControlPort {
public:
typedef void (*UIChangedCallback)(void *);
private:
UIChangedCallback changed_callback;
void *changed_userdata;
char command;
public:
enum Hint {
HINT_RANGE, ///< just a range, trust min and max
HINT_RANGE_NORMALIZED, // just a range, but min and max are normalized, so ask text somewhere else
HINT_TOGGLE, ///< valid values 0.0f , 1.0f
HINT_ENUM, ///< asking integer values to get_Value_as_text will return them
};
virtual String get_name() const = 0;
virtual String get_identifier() const = 0;
virtual float get_min() const = 0;
virtual float get_max() const = 0;
virtual float get_step() const = 0;
virtual float get() const = 0;
virtual bool is_visible() const = 0;
virtual void set(float p_val) = 0; //set, optionally make the value the default too
virtual void set_normalized(float p_val); // set in range 0-1, internally converted to range
virtual float get_normalized() const;
virtual String get_value_as_text() const;
virtual Hint get_hint() const;
void ui_changed_notify();
void set_ui_changed_callback(UIChangedCallback p_callback, void *p_userdata);
void set_command(char p_command);
char get_command() const;
ControlPort();
virtual ~ControlPort();
};
class AudioEffect {
bool skip;
public:
struct Event {
enum Type {
TYPE_NOTE,
TYPE_NOTE_OFF,
TYPE_AFTERTOUCH,
TYPE_BPM,
};
enum {
NOTE_MAX = 0x7F //for note
};
Type type;
uint32_t param8; //for note, BPM
float paramf; // for note volume (0-1)
uint32_t offset; //offset in samples (for anything that supports it)
};
//process
virtual bool has_secondary_input() const = 0;
virtual void process(const Event *p_events, int p_event_count, const AudioFrame *p_in, AudioFrame *p_out, bool p_prev_active) = 0;
virtual void process_with_secondary(const Event *p_events, int p_event_count, const AudioFrame *p_in, const AudioFrame *p_secondary, AudioFrame *p_out, bool p_prev_active) = 0;
virtual void set_process_block_size(int p_size) = 0;
virtual void set_sampling_rate(int p_hz) = 0;
//info
virtual String get_name() const = 0;
virtual String get_unique_id() const = 0;
virtual String get_provider_id() const = 0;
virtual int get_control_port_count() const = 0;
virtual ControlPort *get_control_port(int p_port) = 0;
virtual void reset() = 0;
/* Load/Save */
virtual String get_shared_data_key() const;
virtual std::shared_ptr<Vector<uint8_t> > get_shared_data() const;
virtual void set_shared_data(const std::shared_ptr<Vector<uint8_t> > &p_shared_data);
virtual JSON::Node to_json() const = 0;
virtual Error from_json(const JSON::Node &node) = 0;
void set_skip(bool p_skip);
bool is_skipped() const;
AudioEffect();
virtual ~AudioEffect();
};
class ControlPortDefault : public ControlPort {
public:
String name;
String identifier;
float min, max, step;
float value;
Hint hint;
bool visible;
bool was_set;
Vector<String> enum_values;
virtual String get_name() const { return name; }
virtual String get_identifier() const { return identifier; }
virtual float get_min() const { return min; }
virtual float get_max() const { return max; }
virtual float get_step() const { return step; }
virtual float get() const { return value; }
virtual void set(float p_val) {
value = p_val;
was_set = true;
}
virtual Hint get_hint() const { return hint; }
virtual bool is_visible() const { return visible; }
virtual String get_value_as_text() const {
if (hint == HINT_RANGE || hint == HINT_RANGE_NORMALIZED) {
return String::num(value);
} else if (hint == HINT_ENUM) {
int v = int(value);
if (v >= 0 && v < enum_values.size()) {
return enum_values[v];
} else {
String::num(v);
}
} else {
if (value > 0.5) {
return "Enabled";
} else {
return "Disabled";
}
}
return String();
}
ControlPortDefault() {
value = 0;
hint = HINT_RANGE;
min = 0;
max = 1;
step = 1;
visible = true;
was_set = false;
}
};
class AudioEffectFactory {
Vector<AudioEffectInfo> audio_effects;
Vector<AudioEffectProvider *> providers;
public:
void add_audio_effect(AudioEffectInfo p_info);
int get_audio_effect_count();
const AudioEffectInfo *get_audio_effect(int p_idx);
AudioEffect *instantiate_effect(int p_idx);
void add_provider(AudioEffectProvider *p_provider);
void rescan_effects(AudioEffectProvider::ScanCallback p_callback = NULL, void *p_userdata = NULL);
};
#endif // AUDIO_EFFECT_H
|