2 Calf Box, an open source musical instrument.
3 Copyright (C) 2010-2011 Krzysztof Foltman
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
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.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
19 #ifndef CBOX_SAMPLER_LAYER_H
20 #define CBOX_SAMPLER_LAYER_H
26 struct sampler_program
;
28 struct sampler_noteinitfunc
;
29 struct sampler_module
;
31 enum sampler_player_type
39 enum sampler_loop_mode
45 slm_loop_sustain
, // unsupported
46 slm_one_shot_chokeable
,
50 #define ENUM_VALUES_sampler_loop_mode(MACRO) \
51 MACRO("no_loop", slm_no_loop) \
52 MACRO("one_shot", slm_one_shot) \
53 MACRO("loop_continuous", slm_loop_continuous) \
54 MACRO("loop_sustain", slm_loop_sustain) \
55 MACRO("one_shot_chokeable", slm_one_shot_chokeable)
64 #define ENUM_VALUES_sampler_off_mode(MACRO) \
65 MACRO("normal", som_normal) \
66 MACRO("fast", som_fast)
74 #define ENUM_VALUES_sampler_trigger(MACRO) \
75 MACRO("attack", stm_attack) \
76 MACRO("release", stm_release)
78 enum sampler_filter_type
91 #define ENUM_VALUES_sampler_filter_type(MACRO) \
92 MACRO("lpf_2p", sft_lp12) \
93 MACRO("hpf_2p", sft_hp12) \
94 MACRO("bpf_2p", sft_bp6) \
95 MACRO("lpf_4p", sft_lp24) \
96 MACRO("hpf_4p", sft_hp24) \
97 MACRO("bpf_4p", sft_bp12) \
98 MACRO("lpf_1p", sft_lp6) \
99 MACRO("hpf_1p", sft_hp6)
101 #define ENUM_LIST(MACRO) \
102 MACRO(sampler_loop_mode) \
103 MACRO(sampler_off_mode) \
104 MACRO(sampler_trigger) \
105 MACRO(sampler_filter_type) \
107 #define MAKE_FROM_TO_STRING_EXTERN(enumtype) \
108 extern const char *enumtype##_to_string(enum enumtype value); \
109 extern gboolean enumtype##_from_string(const char *name, enum enumtype *value);
111 ENUM_LIST(MAKE_FROM_TO_STRING_EXTERN
)
118 // those are per-note, not per-channel
131 smsrc_perchan_offset
= 0,
132 smsrc_perchan_count
= smsrc_vel
,
133 smsrc_pernote_offset
= smsrc_vel
,
134 smsrc_pernote_count
= smsrccount
- smsrc_pernote_offset
,
147 struct sampler_modulation
149 enum sampler_modsrc src
;
150 enum sampler_modsrc src2
;
151 enum sampler_moddest dest
;
154 unsigned int has_value
:1;
157 typedef void (*SamplerNoteInitFunc
)(struct sampler_noteinitfunc
*nif
, struct sampler_voice
*voice
);
159 struct sampler_noteinitfunc
161 SamplerNoteInitFunc notefunc
;
163 unsigned int has_value
:1;
165 // XXXKF no destructor for now - might not be necessary
168 struct sampler_lfo_params
175 typedef int midi_note_t
;
179 * notransform - self-explanatory
180 * dBamp - amplitude/gain stored as dB
183 #define SAMPLER_FIXED_FIELDS(MACRO) \
184 MACRO(uint32_t, offset, 0) \
185 MACRO(uint32_t, offset_random, 0) \
186 MACRO(uint32_t, loop_start, 0) \
187 MACRO(uint32_t, loop_end, 0) \
188 MACRO(uint32_t, end, 0) \
189 MACRO(uint32_t, loop_overlap, -1) \
190 MACRO##_enum(sampler_loop_mode, loop_mode, slm_unknown) \
191 MACRO##_enum(sampler_trigger, trigger, stm_attack) \
192 MACRO##_dBamp(float, volume, 0) \
193 MACRO(float, pan, 0) \
194 MACRO(float, tune, 0) \
195 MACRO(int, transpose, 0) \
196 MACRO(int, lochan, 1) \
197 MACRO(int, hichan, 16) \
198 MACRO(float, lorand, 0) \
199 MACRO(float, hirand, 1) \
200 MACRO(midi_note_t, key, -1) \
201 MACRO(midi_note_t, lokey, 0) \
202 MACRO(midi_note_t, hikey, 127) \
203 MACRO(midi_note_t, pitch_keycenter, 60) \
204 MACRO(int, pitch_keytrack, 100) \
205 MACRO(midi_note_t, fil_keycenter, 60) \
206 MACRO(int, fil_keytrack, 0) \
207 MACRO(int, fil_veltrack, 0) \
208 MACRO(int, amp_veltrack, 100) \
209 MACRO(int, lovel, 0) \
210 MACRO(int, hivel, 127) \
211 MACRO(int, velcurve_quadratic, -1) \
212 MACRO##_enum(sampler_filter_type, fil_type, sft_lp12) \
213 MACRO##_enum(sampler_off_mode, off_mode, som_unknown) \
214 MACRO(float, cutoff, -1) \
215 MACRO##_dBamp(float, resonance, 0) \
216 MACRO(midi_note_t, sw_lokey, 0) \
217 MACRO(midi_note_t, sw_hikey, 127) \
218 MACRO(midi_note_t, sw_last, -1) \
219 MACRO(midi_note_t, sw_down, -1) \
220 MACRO(midi_note_t, sw_up, -1) \
221 MACRO(midi_note_t, sw_previous, -1) \
222 MACRO(int, seq_position, 1) \
223 MACRO(int, seq_length, 1) \
224 MACRO(int, effect1bus, 1) \
225 MACRO(int, effect2bus, 2) \
226 MACRO(float, effect1, 0) \
227 MACRO(float, effect2, 0) \
228 MACRO(float, delay, 0) \
229 MACRO(float, delay_random, 0) \
230 MACRO(int, output, 0) \
231 MACRO(int, group, 0) \
232 MACRO(int, off_by, 0) \
233 MACRO(float, rt_decay, 0) \
234 MACRO##_dahdsr(amp_env, ampeg, 0) \
235 MACRO##_dahdsr(filter_env, fileg, 1) \
236 MACRO##_dahdsr(pitch_env, pitcheg, 2) \
237 MACRO##_lfo(amp_lfo, amplfo, 0) \
238 MACRO##_lfo(filter_lfo, fillfo, 1) \
239 MACRO##_lfo(pitch_lfo, pitchlfo, 2) \
241 // XXXKF: consider making send1gain the dBamp type... except it's
242 // a linear percentage value in SFZ spec - bit weird!
244 #define DAHDSR_FIELDS(MACRO, ...) \
245 MACRO(start, 0, 0, ## __VA_ARGS__) \
246 MACRO(delay, 1, 0, ## __VA_ARGS__) \
247 MACRO(attack, 2, 0, ## __VA_ARGS__) \
248 MACRO(hold, 3, 0, ## __VA_ARGS__) \
249 MACRO(decay, 4, 0, ## __VA_ARGS__) \
250 MACRO(sustain, 5, 100, ## __VA_ARGS__) \
251 MACRO(release, 6, 0.05, ## __VA_ARGS__) \
253 #define LFO_FIELDS(MACRO, ...) \
254 MACRO(freq, 0, 0, ## __VA_ARGS__) \
255 MACRO(delay, 1, 0, ## __VA_ARGS__) \
256 MACRO(fade, 2, 0, ## __VA_ARGS__) \
258 #define PROC_SUBSTRUCT_HAS_FIELD(name, index, param, def_value) \
260 #define PROC_SUBSTRUCT_RESET_FIELD(name, index, def_value, param, dst) \
261 dst->param.name = def_value;
262 #define PROC_SUBSTRUCT_RESET_HAS_FIELD(name, index, def_value, param, dst) \
263 dst->has_##param.name = 0;
264 #define PROC_SUBSTRUCT_CLONE(name, index, def_value, param, dst, src) \
265 dst->param.name = src->param.name;
266 #define PROC_SUBSTRUCT_CLONEPARENT(name, index, def_value, param, l) \
267 if (!l->has_##param.name) \
268 l->param.name = parent ? parent->param.name : def_value;
269 struct sampler_dahdsr_has_fields
271 DAHDSR_FIELDS(PROC_SUBSTRUCT_HAS_FIELD
, name
)
274 struct sampler_lfo_has_fields
276 LFO_FIELDS(PROC_SUBSTRUCT_HAS_FIELD
, name
)
279 #define PROC_FIELDS_TO_STRUCT(type, name, def_value) \
281 #define PROC_FIELDS_TO_STRUCT_dBamp(type, name, def_value) \
283 type name##_linearized;
284 #define PROC_FIELDS_TO_STRUCT_enum(enumtype, name, def_value) \
286 #define PROC_FIELDS_TO_STRUCT_dahdsr(name, parname, index) \
287 struct cbox_dahdsr name; \
288 struct cbox_envelope_shape name##_shape;
289 #define PROC_FIELDS_TO_STRUCT_lfo(name, parname, index) \
290 struct sampler_lfo_params name; \
292 #define PROC_HAS_FIELD(type, name, def_value) \
293 unsigned int has_##name:1;
294 #define PROC_HAS_FIELD_dBamp(type, name, def_value) \
295 PROC_HAS_FIELD(type, name, def_value)
296 #define PROC_HAS_FIELD_enum(enumtype, name, def_value) \
297 PROC_HAS_FIELD(type, name, def_value)
299 #define PROC_HAS_FIELD_dahdsr(name, parname, index) \
300 struct sampler_dahdsr_has_fields has_##name;
302 #define PROC_HAS_FIELD_lfo(name, parname, index) \
303 struct sampler_lfo_has_fields has_##name;
305 CBOX_EXTERN_CLASS(sampler_layer
)
307 struct sampler_layer_data
309 struct cbox_waveform
*waveform
;
310 gboolean has_waveform
;
312 SAMPLER_FIXED_FIELDS(PROC_FIELDS_TO_STRUCT
)
313 SAMPLER_FIXED_FIELDS(PROC_HAS_FIELD
)
316 float eff_velcurve
[128];
323 int eff_use_keyswitch
;
329 struct cbox_command_target cmd_target
;
331 struct sampler_layer_data data
, *runtime
;
333 struct sampler_module
*module
;
334 struct sampler_program
*parent_program
;
335 struct sampler_layer
*parent_group
;
337 int last_key
, current_seq_position
;
339 GHashTable
*unknown_keys
;
340 GHashTable
*child_layers
;
343 extern struct sampler_layer
*sampler_layer_new(struct sampler_module
*m
, struct sampler_program
*parent_program
, struct sampler_layer
*parent_group
);
344 extern struct sampler_layer
*sampler_layer_new_from_section(struct sampler_module
*m
, struct sampler_program
*parent_program
, const char *cfg_section
);
345 extern void sampler_layer_set_waveform(struct sampler_layer
*l
, struct cbox_waveform
*waveform
);
346 extern void sampler_layer_set_modulation(struct sampler_layer
*l
, enum sampler_modsrc src
, enum sampler_modsrc src2
, enum sampler_moddest dest
, float amount
, int flags
);
347 extern void sampler_layer_set_modulation1(struct sampler_layer
*l
, enum sampler_modsrc src
, enum sampler_moddest dest
, float amount
, int flags
);
348 extern void sampler_layer_add_nif(struct sampler_layer
*l
, SamplerNoteInitFunc notefunc
, int variant
, float param
);
349 extern void sampler_layer_load_overrides(struct sampler_layer
*l
, const char *cfg_section
);
350 extern void sampler_layer_data_finalize(struct sampler_layer_data
*l
, struct sampler_layer_data
*parent
, struct sampler_module
*m
);
351 extern void sampler_layer_reset_switches(struct sampler_layer
*l
, struct sampler_module
*m
);
352 extern gboolean
sampler_layer_apply_param(struct sampler_layer
*l
, const char *key
, const char *value
, GError
**error
);
353 extern gchar
*sampler_layer_to_string(struct sampler_layer
*l
, gboolean show_inherited
);
354 extern void sampler_layer_dump(struct sampler_layer
*l
, FILE *f
);
355 extern void sampler_layer_data_clone(struct sampler_layer_data
*dst
, const struct sampler_layer_data
*src
, gboolean copy_hasattr
);
356 extern void sampler_layer_data_destroy(struct sampler_layer_data
*l
);
358 extern void sampler_nif_vel2pitch(struct sampler_noteinitfunc
*nif
, struct sampler_voice
*v
);
359 extern void sampler_nif_vel2env(struct sampler_noteinitfunc
*nif
, struct sampler_voice
*v
);
360 extern void sampler_nif_cc2delay(struct sampler_noteinitfunc
*nif
, struct sampler_voice
*v
);
361 extern void sampler_nif_addrandom(struct sampler_noteinitfunc
*nif
, struct sampler_voice
*v
);