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
27 struct sampler_program
;
29 struct sampler_noteinitfunc
;
30 struct sampler_module
;
32 enum sampler_player_type
40 enum sampler_loop_mode
46 slm_loop_sustain
, // unsupported
47 slm_one_shot_chokeable
,
51 #define ENUM_VALUES_sampler_loop_mode(MACRO) \
52 MACRO("no_loop", slm_no_loop) \
53 MACRO("one_shot", slm_one_shot) \
54 MACRO("loop_continuous", slm_loop_continuous) \
55 MACRO("loop_sustain", slm_loop_sustain) \
56 MACRO("one_shot_chokeable", slm_one_shot_chokeable)
65 #define ENUM_VALUES_sampler_off_mode(MACRO) \
66 MACRO("normal", som_normal) \
67 MACRO("fast", som_fast)
77 #define ENUM_VALUES_sampler_trigger(MACRO) \
78 MACRO("attack", stm_attack) \
79 MACRO("release", stm_release) \
80 MACRO("first", stm_first) \
81 MACRO("legato", stm_legato)
83 enum sampler_filter_type
96 #define ENUM_VALUES_sampler_filter_type(MACRO) \
97 MACRO("lpf_2p", sft_lp12) \
98 MACRO("hpf_2p", sft_hp12) \
99 MACRO("bpf_2p", sft_bp6) \
100 MACRO("lpf_4p", sft_lp24) \
101 MACRO("hpf_4p", sft_hp24) \
102 MACRO("bpf_4p", sft_bp12) \
103 MACRO("lpf_1p", sft_lp6) \
104 MACRO("hpf_1p", sft_hp6)
106 #define ENUM_LIST(MACRO) \
107 MACRO(sampler_loop_mode) \
108 MACRO(sampler_off_mode) \
109 MACRO(sampler_trigger) \
110 MACRO(sampler_filter_type) \
112 #define MAKE_FROM_TO_STRING_EXTERN(enumtype) \
113 extern const char *enumtype##_to_string(enum enumtype value); \
114 extern gboolean enumtype##_from_string(const char *name, enum enumtype *value);
116 ENUM_LIST(MAKE_FROM_TO_STRING_EXTERN
)
123 // those are per-note, not per-channel
136 smsrc_perchan_offset
= 0,
137 smsrc_perchan_count
= smsrc_vel
,
138 smsrc_pernote_offset
= smsrc_vel
,
139 smsrc_pernote_count
= smsrccount
- smsrc_pernote_offset
,
152 struct sampler_modulation
154 enum sampler_modsrc src
;
155 enum sampler_modsrc src2
;
156 enum sampler_moddest dest
;
159 unsigned int has_value
:1;
162 typedef void (*SamplerNoteInitFunc
)(struct sampler_noteinitfunc
*nif
, struct sampler_voice
*voice
);
164 struct sampler_noteinitfunc
166 SamplerNoteInitFunc notefunc
;
168 unsigned int has_value
:1;
170 // XXXKF no destructor for now - might not be necessary
173 struct sampler_lfo_params
180 typedef int midi_note_t
;
184 * notransform - self-explanatory
185 * dBamp - amplitude/gain stored as dB
188 #define SAMPLER_FIXED_FIELDS(MACRO) \
189 MACRO##_string(sample) \
190 MACRO(uint32_t, offset, 0) \
191 MACRO(uint32_t, offset_random, 0) \
192 MACRO(uint32_t, loop_start, 0) \
193 MACRO(uint32_t, loop_end, 0) \
194 MACRO(uint32_t, end, 0) \
195 MACRO(uint32_t, loop_overlap, -1) \
196 MACRO##_enum(sampler_loop_mode, loop_mode, slm_unknown) \
197 MACRO##_enum(sampler_trigger, trigger, stm_attack) \
198 MACRO##_dBamp(float, volume, 0) \
199 MACRO(float, pan, 0) \
200 MACRO(float, tune, 0) \
201 MACRO(int, transpose, 0) \
202 MACRO(int, lochan, 1) \
203 MACRO(int, hichan, 16) \
204 MACRO(float, lorand, 0) \
205 MACRO(float, hirand, 1) \
206 MACRO(midi_note_t, key, -1) \
207 MACRO(midi_note_t, lokey, 0) \
208 MACRO(midi_note_t, hikey, 127) \
209 MACRO(midi_note_t, pitch_keycenter, 60) \
210 MACRO(int, pitch_keytrack, 100) \
211 MACRO(midi_note_t, fil_keycenter, 60) \
212 MACRO(int, fil_keytrack, 0) \
213 MACRO(int, fil_veltrack, 0) \
214 MACRO(int, amp_veltrack, 100) \
215 MACRO(int, lovel, 0) \
216 MACRO(int, hivel, 127) \
217 MACRO(int, velcurve_quadratic, -1) \
218 MACRO##_enum(sampler_filter_type, fil_type, sft_lp12) \
219 MACRO##_enum(sampler_off_mode, off_mode, som_unknown) \
220 MACRO(float, cutoff, -1) \
221 MACRO##_dBamp(float, resonance, 0) \
222 MACRO(midi_note_t, sw_lokey, 0) \
223 MACRO(midi_note_t, sw_hikey, 127) \
224 MACRO(midi_note_t, sw_last, -1) \
225 MACRO(midi_note_t, sw_down, -1) \
226 MACRO(midi_note_t, sw_up, -1) \
227 MACRO(midi_note_t, sw_previous, -1) \
228 MACRO(int, seq_position, 1) \
229 MACRO(int, seq_length, 1) \
230 MACRO(int, effect1bus, 1) \
231 MACRO(int, effect2bus, 2) \
232 MACRO(float, effect1, 0) \
233 MACRO(float, effect2, 0) \
234 MACRO(float, delay, 0) \
235 MACRO(float, delay_random, 0) \
236 MACRO(int, output, 0) \
237 MACRO(int, group, 0) \
238 MACRO(int, off_by, 0) \
239 MACRO(int, count, 0) \
240 MACRO(int, bend_up, 200) \
241 MACRO(int, bend_down, 200) \
242 MACRO(float, rt_decay, 0) \
243 MACRO##_dahdsr(amp_env, ampeg, 0) \
244 MACRO##_dahdsr(filter_env, fileg, 1) \
245 MACRO##_dahdsr(pitch_env, pitcheg, 2) \
246 MACRO##_lfo(amp_lfo, amplfo, 0) \
247 MACRO##_lfo(filter_lfo, fillfo, 1) \
248 MACRO##_lfo(pitch_lfo, pitchlfo, 2) \
249 MACRO##_ccrange(on_) \
252 // XXXKF: consider making send1gain the dBamp type... except it's
253 // a linear percentage value in SFZ spec - bit weird!
255 #define DAHDSR_FIELDS(MACRO, ...) \
256 MACRO(start, 0, 0, ## __VA_ARGS__) \
257 MACRO(delay, 1, 0, ## __VA_ARGS__) \
258 MACRO(attack, 2, 0, ## __VA_ARGS__) \
259 MACRO(hold, 3, 0, ## __VA_ARGS__) \
260 MACRO(decay, 4, 0, ## __VA_ARGS__) \
261 MACRO(sustain, 5, 100, ## __VA_ARGS__) \
262 MACRO(release, 6, 0.05, ## __VA_ARGS__) \
264 #define LFO_FIELDS(MACRO, ...) \
265 MACRO(freq, 0, 0, ## __VA_ARGS__) \
266 MACRO(delay, 1, 0, ## __VA_ARGS__) \
267 MACRO(fade, 2, 0, ## __VA_ARGS__) \
269 #define PROC_SUBSTRUCT_HAS_FIELD(name, index, param, def_value) \
271 #define PROC_SUBSTRUCT_RESET_FIELD(name, index, def_value, param, dst) \
272 dst->param.name = def_value;
273 #define PROC_SUBSTRUCT_RESET_HAS_FIELD(name, index, def_value, param, dst) \
274 dst->has_##param.name = 0;
275 #define PROC_SUBSTRUCT_CLONE(name, index, def_value, param, dst, src) \
276 dst->param.name = src->param.name;
277 #define PROC_SUBSTRUCT_CLONEPARENT(name, index, def_value, param, l) \
278 if (!l->has_##param.name) \
279 l->param.name = parent ? parent->param.name : def_value;
280 struct sampler_dahdsr_has_fields
282 DAHDSR_FIELDS(PROC_SUBSTRUCT_HAS_FIELD
, name
)
285 struct sampler_lfo_has_fields
287 LFO_FIELDS(PROC_SUBSTRUCT_HAS_FIELD
, name
)
290 #define PROC_FIELDS_TO_STRUCT(type, name, def_value) \
292 #define PROC_FIELDS_TO_STRUCT_string(name) \
294 gboolean name##_changed;
295 #define PROC_FIELDS_TO_STRUCT_dBamp(type, name, def_value) \
297 type name##_linearized;
298 #define PROC_FIELDS_TO_STRUCT_enum(enumtype, name, def_value) \
300 #define PROC_FIELDS_TO_STRUCT_dahdsr(name, parname, index) \
301 struct cbox_dahdsr name; \
302 struct cbox_envelope_shape name##_shape;
303 #define PROC_FIELDS_TO_STRUCT_lfo(name, parname, index) \
304 struct sampler_lfo_params name;
305 #define PROC_FIELDS_TO_STRUCT_ccrange(name) \
308 int8_t name##cc_number;
310 #define PROC_HAS_FIELD(type, name, def_value) \
311 unsigned int has_##name:1;
312 #define PROC_HAS_FIELD_string(name) \
313 unsigned int has_##name:1;
314 #define PROC_HAS_FIELD_dBamp(type, name, def_value) \
315 PROC_HAS_FIELD(type, name, def_value)
316 #define PROC_HAS_FIELD_enum(enumtype, name, def_value) \
317 PROC_HAS_FIELD(type, name, def_value)
319 #define PROC_HAS_FIELD_dahdsr(name, parname, index) \
320 struct sampler_dahdsr_has_fields has_##name;
322 #define PROC_HAS_FIELD_lfo(name, parname, index) \
323 struct sampler_lfo_has_fields has_##name;
325 #define PROC_HAS_FIELD_ccrange(name) \
326 unsigned int has_##name##locc:1; \
327 unsigned int has_##name##hicc:1;
329 CBOX_EXTERN_CLASS(sampler_layer
)
331 struct sampler_layer_data
333 SAMPLER_FIXED_FIELDS(PROC_FIELDS_TO_STRUCT
)
334 SAMPLER_FIXED_FIELDS(PROC_HAS_FIELD
)
337 float eff_velcurve
[128];
344 int eff_use_keyswitch
;
345 struct cbox_waveform
*eff_waveform
;
346 int16_t scratch_loop
[2 * MAX_INTERPOLATION_ORDER
* 2];
347 int16_t scratch_end
[2 * MAX_INTERPOLATION_ORDER
* 2];
353 struct cbox_command_target cmd_target
;
355 struct sampler_layer_data data
, *runtime
;
357 struct sampler_module
*module
;
358 struct sampler_program
*parent_program
;
359 struct sampler_layer
*parent_group
;
361 int last_key
, current_seq_position
;
363 GHashTable
*unknown_keys
;
364 GHashTable
*child_layers
;
367 extern struct sampler_layer
*sampler_layer_new(struct sampler_module
*m
, struct sampler_program
*parent_program
, struct sampler_layer
*parent_group
);
368 extern struct sampler_layer
*sampler_layer_new_from_section(struct sampler_module
*m
, struct sampler_program
*parent_program
, const char *cfg_section
);
369 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
);
370 extern void sampler_layer_set_modulation1(struct sampler_layer
*l
, enum sampler_modsrc src
, enum sampler_moddest dest
, float amount
, int flags
);
371 extern void sampler_layer_add_nif(struct sampler_layer
*l
, SamplerNoteInitFunc notefunc
, int variant
, float param
);
372 extern void sampler_layer_load_overrides(struct sampler_layer
*l
, const char *cfg_section
);
373 extern void sampler_layer_data_finalize(struct sampler_layer_data
*l
, struct sampler_layer_data
*parent
, struct sampler_program
*p
);
374 extern void sampler_layer_reset_switches(struct sampler_layer
*l
, struct sampler_module
*m
);
375 extern gboolean
sampler_layer_apply_param(struct sampler_layer
*l
, const char *key
, const char *value
, GError
**error
);
376 extern gchar
*sampler_layer_to_string(struct sampler_layer
*l
, gboolean show_inherited
);
377 extern void sampler_layer_dump(struct sampler_layer
*l
, FILE *f
);
378 extern void sampler_layer_update(struct sampler_layer
*l
);
380 extern void sampler_layer_data_clone(struct sampler_layer_data
*dst
, const struct sampler_layer_data
*src
, gboolean copy_hasattr
);
381 extern void sampler_layer_data_close(struct sampler_layer_data
*l
);
382 extern void sampler_layer_data_destroy(struct sampler_layer_data
*l
);
384 extern void sampler_nif_vel2pitch(struct sampler_noteinitfunc
*nif
, struct sampler_voice
*v
);
385 extern void sampler_nif_vel2env(struct sampler_noteinitfunc
*nif
, struct sampler_voice
*v
);
386 extern void sampler_nif_cc2delay(struct sampler_noteinitfunc
*nif
, struct sampler_voice
*v
);
387 extern void sampler_nif_addrandom(struct sampler_noteinitfunc
*nif
, struct sampler_voice
*v
);