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(int, count, 0) \
234 MACRO(int, bend_up, 200) \
235 MACRO(int, bend_down, 200) \
236 MACRO(float, rt_decay, 0) \
237 MACRO##_dahdsr(amp_env, ampeg, 0) \
238 MACRO##_dahdsr(filter_env, fileg, 1) \
239 MACRO##_dahdsr(pitch_env, pitcheg, 2) \
240 MACRO##_lfo(amp_lfo, amplfo, 0) \
241 MACRO##_lfo(filter_lfo, fillfo, 1) \
242 MACRO##_lfo(pitch_lfo, pitchlfo, 2) \
243 MACRO##_ccrange(on_) \
246 // XXXKF: consider making send1gain the dBamp type... except it's
247 // a linear percentage value in SFZ spec - bit weird!
249 #define DAHDSR_FIELDS(MACRO, ...) \
250 MACRO(start, 0, 0, ## __VA_ARGS__) \
251 MACRO(delay, 1, 0, ## __VA_ARGS__) \
252 MACRO(attack, 2, 0, ## __VA_ARGS__) \
253 MACRO(hold, 3, 0, ## __VA_ARGS__) \
254 MACRO(decay, 4, 0, ## __VA_ARGS__) \
255 MACRO(sustain, 5, 100, ## __VA_ARGS__) \
256 MACRO(release, 6, 0.05, ## __VA_ARGS__) \
258 #define LFO_FIELDS(MACRO, ...) \
259 MACRO(freq, 0, 0, ## __VA_ARGS__) \
260 MACRO(delay, 1, 0, ## __VA_ARGS__) \
261 MACRO(fade, 2, 0, ## __VA_ARGS__) \
263 #define PROC_SUBSTRUCT_HAS_FIELD(name, index, param, def_value) \
265 #define PROC_SUBSTRUCT_RESET_FIELD(name, index, def_value, param, dst) \
266 dst->param.name = def_value;
267 #define PROC_SUBSTRUCT_RESET_HAS_FIELD(name, index, def_value, param, dst) \
268 dst->has_##param.name = 0;
269 #define PROC_SUBSTRUCT_CLONE(name, index, def_value, param, dst, src) \
270 dst->param.name = src->param.name;
271 #define PROC_SUBSTRUCT_CLONEPARENT(name, index, def_value, param, l) \
272 if (!l->has_##param.name) \
273 l->param.name = parent ? parent->param.name : def_value;
274 struct sampler_dahdsr_has_fields
276 DAHDSR_FIELDS(PROC_SUBSTRUCT_HAS_FIELD
, name
)
279 struct sampler_lfo_has_fields
281 LFO_FIELDS(PROC_SUBSTRUCT_HAS_FIELD
, name
)
284 #define PROC_FIELDS_TO_STRUCT(type, name, def_value) \
286 #define PROC_FIELDS_TO_STRUCT_dBamp(type, name, def_value) \
288 type name##_linearized;
289 #define PROC_FIELDS_TO_STRUCT_enum(enumtype, name, def_value) \
291 #define PROC_FIELDS_TO_STRUCT_dahdsr(name, parname, index) \
292 struct cbox_dahdsr name; \
293 struct cbox_envelope_shape name##_shape;
294 #define PROC_FIELDS_TO_STRUCT_lfo(name, parname, index) \
295 struct sampler_lfo_params name;
296 #define PROC_FIELDS_TO_STRUCT_ccrange(name) \
299 int8_t name##cc_number;
301 #define PROC_HAS_FIELD(type, name, def_value) \
302 unsigned int has_##name:1;
303 #define PROC_HAS_FIELD_dBamp(type, name, def_value) \
304 PROC_HAS_FIELD(type, name, def_value)
305 #define PROC_HAS_FIELD_enum(enumtype, name, def_value) \
306 PROC_HAS_FIELD(type, name, def_value)
308 #define PROC_HAS_FIELD_dahdsr(name, parname, index) \
309 struct sampler_dahdsr_has_fields has_##name;
311 #define PROC_HAS_FIELD_lfo(name, parname, index) \
312 struct sampler_lfo_has_fields has_##name;
314 #define PROC_HAS_FIELD_ccrange(name) \
315 unsigned int has_##name##locc:1; \
316 unsigned int has_##name##hicc:1;
318 CBOX_EXTERN_CLASS(sampler_layer
)
320 struct sampler_layer_data
322 struct cbox_waveform
*waveform
;
323 gboolean has_waveform
;
325 SAMPLER_FIXED_FIELDS(PROC_FIELDS_TO_STRUCT
)
326 SAMPLER_FIXED_FIELDS(PROC_HAS_FIELD
)
329 float eff_velcurve
[128];
336 int eff_use_keyswitch
;
342 struct cbox_command_target cmd_target
;
344 struct sampler_layer_data data
, *runtime
;
346 struct sampler_module
*module
;
347 struct sampler_program
*parent_program
;
348 struct sampler_layer
*parent_group
;
350 int last_key
, current_seq_position
;
352 GHashTable
*unknown_keys
;
353 GHashTable
*child_layers
;
356 extern struct sampler_layer
*sampler_layer_new(struct sampler_module
*m
, struct sampler_program
*parent_program
, struct sampler_layer
*parent_group
);
357 extern struct sampler_layer
*sampler_layer_new_from_section(struct sampler_module
*m
, struct sampler_program
*parent_program
, const char *cfg_section
);
358 extern void sampler_layer_set_waveform(struct sampler_layer
*l
, struct cbox_waveform
*waveform
);
359 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
);
360 extern void sampler_layer_set_modulation1(struct sampler_layer
*l
, enum sampler_modsrc src
, enum sampler_moddest dest
, float amount
, int flags
);
361 extern void sampler_layer_add_nif(struct sampler_layer
*l
, SamplerNoteInitFunc notefunc
, int variant
, float param
);
362 extern void sampler_layer_load_overrides(struct sampler_layer
*l
, const char *cfg_section
);
363 extern void sampler_layer_data_finalize(struct sampler_layer_data
*l
, struct sampler_layer_data
*parent
, struct sampler_module
*m
);
364 extern void sampler_layer_reset_switches(struct sampler_layer
*l
, struct sampler_module
*m
);
365 extern gboolean
sampler_layer_apply_param(struct sampler_layer
*l
, const char *key
, const char *value
, GError
**error
);
366 extern gchar
*sampler_layer_to_string(struct sampler_layer
*l
, gboolean show_inherited
);
367 extern void sampler_layer_dump(struct sampler_layer
*l
, FILE *f
);
368 extern void sampler_layer_data_clone(struct sampler_layer_data
*dst
, const struct sampler_layer_data
*src
, gboolean copy_hasattr
);
369 extern void sampler_layer_data_close(struct sampler_layer_data
*l
);
370 extern void sampler_layer_data_destroy(struct sampler_layer_data
*l
);
372 extern void sampler_nif_vel2pitch(struct sampler_noteinitfunc
*nif
, struct sampler_voice
*v
);
373 extern void sampler_nif_vel2env(struct sampler_noteinitfunc
*nif
, struct sampler_voice
*v
);
374 extern void sampler_nif_cc2delay(struct sampler_noteinitfunc
*nif
, struct sampler_voice
*v
);
375 extern void sampler_nif_addrandom(struct sampler_noteinitfunc
*nif
, struct sampler_voice
*v
);