Add poorly tested appsink functionality for JACK MIDI.
[calfbox.git] / sampler.h
blob9f72814e46bc2619ff019dd457bd86f99a0aded3
1 /*
2 Calf Box, an open source musical instrument.
3 Copyright (C) 2010-2013 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_H
20 #define CBOX_SAMPLER_H
22 #include "biquad-float.h"
23 #include "envelope.h"
24 #include "module.h"
25 #include "sampler_layer.h"
26 #include "sampler_prg.h"
27 #include "wavebank.h"
28 #include <stdint.h>
30 #define MAX_SAMPLER_VOICES 128
32 #define CBOX_SAMPLER_ERROR cbox_sampler_error_quark()
34 enum CboxSamplerError
36 CBOX_SAMPLER_ERROR_FAILED,
37 CBOX_SAMPLER_ERROR_INVALID_LAYER,
38 CBOX_SAMPLER_ERROR_INVALID_WAVEFORM,
39 CBOX_SAMPLER_ERROR_NO_PROGRAMS
42 struct sampler_noteinitfunc;
43 struct sampler_voice;
45 #define GET_RT_FROM_sampler_channel(channel) ((channel)->module->module.rt)
47 struct sampler_channel
49 struct sampler_module *module;
50 int pitchwheel;
51 uint32_t switchmask[4];
52 uint32_t sustainmask[4];
53 uint32_t sostenutomask[4];
54 int previous_note;
55 uint8_t cc[smsrc_perchan_count];
56 struct sampler_program *program;
57 struct sampler_voice *voices_running;
58 int active_voices;
59 uint8_t prev_note_velocity[128];
60 uint32_t prev_note_start_time[128];
63 struct sampler_lfo
65 uint32_t phase, delta;
66 uint32_t age, delay, fade;
69 struct sampler_gen
71 enum sampler_player_type mode;
72 int16_t *sample_data;
74 uint32_t pos, delta, loop_start, loop_end, cur_sample_end;
75 uint32_t frac_pos, frac_delta;
76 uint32_t loop_overlap;
77 float loop_overlap_step;
78 float lgain, rgain;
79 float last_lgain, last_rgain;
82 struct sampler_voice
84 struct sampler_voice *prev, *next;
85 struct sampler_layer_data *layer;
86 // Note: may be NULL when program is being deleted
87 struct sampler_program *program;
88 struct cbox_waveform *last_waveform;
89 struct sampler_gen gen;
90 int note;
91 int vel;
92 int released, released_with_sustain, released_with_sostenuto, captured_sostenuto;
93 int off_by;
94 int delay;
95 int age;
96 int play_count;
97 float pitch_shift;
98 float cutoff_shift;
99 float gain_shift, gain_fromvel;
100 struct cbox_biquadf_state filter_left, filter_right;
101 struct cbox_biquadf_state filter_left2, filter_right2;
102 struct cbox_biquadf_coeffs filter_coeffs;
103 struct sampler_channel *channel;
104 struct cbox_envelope amp_env, filter_env, pitch_env;
105 struct sampler_lfo amp_lfo, filter_lfo, pitch_lfo;
106 enum sampler_loop_mode loop_mode;
107 int output_pair_no;
108 int send1bus, send2bus;
109 float send1gain, send2gain;
110 int serial_no;
111 struct cbox_envelope_shape dyn_envs[3]; // amp, filter, pitch
114 struct sampler_module
116 struct cbox_module module;
118 struct sampler_voice *voices_free, voices_all[MAX_SAMPLER_VOICES];
119 struct sampler_channel channels[16];
120 struct sampler_program **programs;
121 int program_count;
122 int active_voices, max_voices;
123 int serial_no;
124 int output_pairs, aux_pairs;
125 uint32_t current_time;
126 gboolean deleting;
129 extern GQuark cbox_sampler_error_quark(void);
131 extern gboolean sampler_select_program(struct sampler_module *m, int channel, const gchar *preset, GError **error);
132 extern void sampler_update_layer(struct sampler_module *m, struct sampler_layer *l);
133 extern void sampler_update_program_layers(struct sampler_module *m, struct sampler_program *prg);
134 extern void sampler_unselect_program(struct sampler_module *m, struct sampler_program *prg);
135 // This function may only be called from RT thread!
136 extern void sampler_channel_set_program_RT(struct sampler_channel *c, struct sampler_program *prg);
137 // ... and this one is RT-safe
138 extern void sampler_channel_set_program(struct sampler_channel *c, struct sampler_program *prg);
140 #endif