summaryrefslogtreecommitdiff
path: root/synth/programs.h
blob: 6a24db342a657b82a08103a5a284b61137767346 (plain)
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
#ifndef __PROGRAMS_H__
#define __PROGRAMS_H__


#include <map>
#include <set>
#include <list>

#include "fixed.h"
#include "note_funcs.h"
#include <jack/jack.h>

using namespace std;

struct term_t
{
	int c;
	fixed_t f;
};

enum parameter_enum
{
	MODULATION=0,
	OUTPUT,
	WAVEFORM,
	FACTOR,
	TREMOLO,
	TREM_LFO,
	VIBRATO,
	VIB_LFO,
	ATTACK,
	DECAY,
	SUSTAIN,
	RELEASE,
	HOLD,
	KSR,
	KSL,
	SYNC,
	FILTER_ENABLED,
	FILTER_ENV_AMOUNT,
	FILTER_ATTACK,
	FILTER_DECAY,
	FILTER_SUSTAIN,
	FILTER_RELEASE,
	FILTER_HOLD,
	FILTER_OFFSET,
	FILTER_RESONANCE,
	FILTER_TREMOLO,
	FILTER_TREM_LFO,
	SYNC_FACTOR,
	FREQ_ATTACK,
	FREQ_DECAY,
	FREQ_SUSTAIN,
	FREQ_RELEASE,
	FREQ_HOLD,
	FREQ_ENV_AMOUNT,

	PARAMETER_N_ENTRIES,
	UNKNOWN=-1
};

struct parameter_t
{
	int osc;
	int index;
	enum parameter_enum par;
	
	bool operator< (const struct parameter_t &b) const;
};



struct param_factor_t
{
	fixed_t offset;
	fixed_t vel_amount;
};

struct pfactor_formula_t
{
	param_factor_t **fm;
	param_factor_t *out;
	param_factor_t filter_env;
	param_factor_t filter_res;
	param_factor_t filter_offset;
};

struct pfactor_value_t
{
	fixed_t **fm;
	fixed_t *out;
	fixed_t filter_env;
	fixed_t filter_res;
	fixed_t filter_offset;
};

fixed_t calc_pfactor(param_factor_t &formula, fixed_t vel);



struct custom_wave_t
{
	fixed_t samp_rate;
	int wave_len;
	fixed_t* wave;
	
	custom_wave_t()
	{
		wave=NULL;
		wave_len=0;
		samp_rate=0;
	}
	
	~custom_wave_t()
	{
		if (wave) delete [] wave;
	}
};


struct env_settings_t
{
	jack_nframes_t attack;
	jack_nframes_t decay;
	fixed_t sustain;
	signed int release;
	bool hold;
};

struct oscillator_t
{
	fixed_t *fm_strength; //this osc gets modulated by osc #i by fm_strength[i].
	fixed_t output;       //NOT: osc #i gets modulated by this osc!
	int waveform;
	fixed_t factor;
	float freq_env_amount;
	env_settings_t freq_env;
	
	fixed_t phase;
	
	fixed_t tremolo_depth;
	int tremolo_lfo;
	fixed_t vibrato_depth;
	int vibrato_lfo;
	
	custom_wave_t *custom_wave;
	
	int n_osc;
	
	float ksl;
	float ksr;
	
	bool sync;
	
	oscillator_t();
	oscillator_t& operator=(const oscillator_t &that);
};

struct filter_params_t
{
	bool enabled;
	float resonance;
	float freqfactor_offset;
	float env_amount;	
	int trem_strength;
	int trem_lfo;
	env_settings_t env_settings;
};



struct program_t
{
	unsigned int n_osc;
	oscillator_t *osc_settings;
	env_settings_t *env_settings;
	set<parameter_t> controller_affects[128];
	map< parameter_t, list<term_t> > formula;
	int controller[128+1];
	filter_params_t filter_settings;
	fixed_t sync_factor;
	
	pfactor_formula_t pfactor;
		
	
	void *dl_handle;
	create_func_t *create_func;
	

	program_t();
	~program_t();
	
	void set_param(const parameter_t &p, fixed_t v);
	
	void cleanup();
	
	program_t& operator=(const program_t &that);
};




void init_default_program(program_t &p);

#endif