-
Notifications
You must be signed in to change notification settings - Fork 3
/
ds10.cpp
304 lines (263 loc) · 11.4 KB
/
ds10.cpp
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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
#include "ds10.h"
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wmain"
#include "IPlug_include_in_plug_src.h"
#pragma clang diagnostic pop
#include "IControl.h"
#include "IKeyboardControl.h"
#include "resource.h"
#include <math.h>
#include <algorithm>
#include <functional>
extern "C" {
#include "ds10-core.h"
}
const int kNumPrograms = 32;
enum EParams
{
kNumParams = 26 + 7 - 1 + 3,
kMetaParams = 31,
mPolySwitch = 31,
mOversampleSwitch,
mDistractKnob,
mResampleSwitch,
};
typedef struct Property Property;
struct Property {
const int type;
const char *name;
const int x;
const int y;
const int ds_id;
const int def;
const int min;
const int max;
};
enum {
PKnob,
PKnob4,
PKnob5,
PSwitch2,
PSwitch3,
PModsrc7,
PVoices4,
PNumTypes
};
const Property parameterProperties[kNumParams] = {
{ PKnob5, "octave", 20, 58, 0, 0, -2, 2 },
{ PKnob, "vco.int", 20, 222, 1, 0, -63, 63 },
{ PKnob, "porta", 20, 140, 2, 0, 0, 127 },
{ PKnob, "pitch.in", 98, 537, 3, 0, -63, 63 },
{ PKnob, "pitch1.in",184, 537, 4, 0, -63, 63 },
{ PKnob, "pitch2.in",270, 537, 5, 0, -63, 63 },
{ PKnob4, "vco1", 126, 58, 6, 1, 0, 3 },
{ PKnob4, "vco2", 220, 58, 7, 1, 0, 3 },
{ PKnob, "vco2pitch",220, 140, 8, 0, -63, 63 },
{ PKnob, "balance", 126, 140, 9, 0, 0, 127 },
{ PSwitch2, "vco2sync", 232, 218, 10, 1, 0, 1 },
{ PKnob, "cutoff", 324, 58, 11, 127, 0, 127 },
{ PKnob, "peak", 324, 140, 12, 0, 0, 127 },
{ PSwitch3, "vcf.type", 338, 306, 13, 0, 0, 2 },
{ PKnob, "eg.int", 324, 222, 14, 0, -63, 63 },
{ PKnob, "cutoff.in",356, 537, 15, 0, -63, 63 },
{ PSwitch2, "vca.eg", 232, 306, 16, 0, 0, 1 },
{ PKnob, "vca.in", 442, 537, 17, 0, -63, 63 },
{ PKnob, "drive", 126, 304, 18, 0, 0, 127 },
{ PKnob, "level", 20, 304, 19, 100, 0, 127 },
{ PKnob, "attack", 426, 58, 20, 0, 0, 127 },
{ PKnob, "decay", 426, 140, 21, 127, 0, 127 },
{ PKnob, "sustain", 426, 222, 22, 127, 0, 127 },
{ PKnob, "release", 426, 304, 23, 0, 0, 127 },
{ PKnob, "mg.freq", 12, 537, 24, 50, 0, 127 },
{ PSwitch2, "mg.bpm", 20, 458, 25, 1, 0, 1 },
{ PModsrc7, "modsrc0", 112, 628, 26, 0, 0, 6 },
{ PModsrc7, "modsrc1", 198, 628, 27, 0, 0, 6 },
{ PModsrc7, "modsrc2", 284, 628, 28, 0, 0, 6 },
{ PModsrc7, "modsrc3", 370, 628, 29, 0, 0, 6 },
{ PModsrc7, "modsrc4", 458, 628, 30, 0, 0, 6 },
{ PVoices4, "poly", 19, 712, -1, 0, 0, 3 },
{ PSwitch2, "oversample",368, 700, -1, 0, 0, 1 },
{ PKnob, "distract", 432, 696, -1, 127, 0, 127 },
{ PSwitch2, "resample", 226, 700, -1, 1, 0, 1 },
};
enum ELayout
{
kWidth = GUI_WIDTH,
kHeight = GUI_HEIGHT,
kKeybX = 62,
kKeybY = 425
};
ds10::ds10(IPlugInstanceInfo instanceInfo) : IPLUG_CTOR(kNumParams, kNumPrograms, instanceInfo), lastVirtualKeyboardNoteNumber(virtualKeyboardMinimumNoteNumber - 1) {
TRACE;
print2_init();
ds10state = ds10_init();
mOversample = 1;
mExtraRatio = 1;
mPitchByResampling = 0;
mSampleRate = 44100;
CreateParams();
CreateGraphics();
CreatePresets();
mMIDIReceiver.noteOn.Connect(this, &ds10::onNoteOn);
mMIDIReceiver.noteOff.Connect(this, &ds10::onNoteOff);
}
ds10::~ds10() {
ds10_exit(ds10state);
}
void ds10::onNoteOn(int noteNumber, int velocity) {
if (mPitchByResampling) {
noteNumber = -noteNumber;
}
ds10_noteon(ds10state, noteNumber, velocity);
}
void ds10::onNoteOff(int noteNumber, int velocity) {
if (mPitchByResampling) {
noteNumber = -noteNumber;
}
ds10_noteoff(ds10state, noteNumber);
}
void ds10::CreateParams() {
for (int i = 0; i < kNumParams; i++) {
IParam *param = GetParam(i);
const Property *prop = ¶meterProperties[i];
switch (prop->type) {
default:
case PKnob:
param->InitDouble(prop->name, prop->def, prop->min, prop->max, 0.01);
break;
case PSwitch2:
case PSwitch3:
case PKnob4:
case PKnob5:
case PVoices4:
case PModsrc7:
param->InitEnum(prop->name, prop->def - prop->min, prop->max - prop->min + 1);
param->SetDisplayText(0, prop->name);
break;
}
}
for (int i = 0; i < kNumParams; i++) {
OnParamChange(i);
}
}
void ds10::CreateGraphics() {
IGraphics* pGraphics = MakeGraphics(this, kWidth, kHeight);
pGraphics->AttachBackground(BG_ID, BG_FN);
#if 0
IBitmap waveformBitmap = pGraphics->LoadIBitmap(WAVEFORM_ID, WAVEFORM_FN, 4);
IBitmap filterModeBitmap = pGraphics->LoadIBitmap(FILTERMODE_ID, FILTERMODE_FN, 3);
#endif
IBitmap bitmaps[PNumTypes];
bitmaps[PKnob] = pGraphics->LoadIBitmap(KNOB_ID, KNOB_FN, 128);
bitmaps[PKnob4] = pGraphics->LoadIBitmap(KNOB4_ID, KNOB4_FN, 4);
bitmaps[PKnob5] = pGraphics->LoadIBitmap(KNOB5_ID, KNOB5_FN, 5);
bitmaps[PSwitch2] = pGraphics->LoadIBitmap(SWITCH2_ID, SWITCH2_FN, 2);
bitmaps[PSwitch3] = pGraphics->LoadIBitmap(SWITCH3_ID, SWITCH3_FN, 3);
bitmaps[PVoices4] = pGraphics->LoadIBitmap(VOICES4_ID, VOICES4_FN, 4);
bitmaps[PModsrc7] = pGraphics->LoadIBitmap(MODSRC7_ID, MODSRC7_FN, 7);
for (int i = 0; i < kNumParams; i++) {
IControl* control;
const Property *param = ¶meterProperties[i];
switch (param->type) {
case PKnob:
case PKnob4:
case PKnob5:
default:
control = new IKnobMultiControl(this, param->x, param->y, i, &bitmaps[param->type]);
break;
case PSwitch2:
case PSwitch3:
case PModsrc7:
case PVoices4:
control = new ISwitchControl(this, param->x, param->y, i, &bitmaps[param->type]);
break;
}
pGraphics->AttachControl(control);
}
AttachGraphics(pGraphics);
}
void ds10::CreatePresets() {
MakePreset("Init", 2, 0.0, 14.0, 4.0, 0.0, 0.0, 2, 1, 32.0, 60.0, 1, 57.0, 51.0, 0, 14.0, 0.0, 0, 0.0, 32.0, 105.0, 0.0, 66.0, 127.0, 74.0, 77.0, 1, 1, 0, 0, 0, 0, 0, 0, 127.0, 1);
MakePreset("XLEAD_", 2, 0.0, 14.0, 4.0, 0.0, 0.0, 2, 1, 32.0, 60.0, 1, 57.0, 51.0, 0, 14.0, 0.0, 0, 0.0, 32.0, 105.0, 0.0, 66.0, 127.0, 74.0, 77.0, 1, 1, 0, 0, 0, 0, 0, 0, 127.0, 1);
MakePreset("BASS01", 1, 0.0, 0.0, 0.0, 0.0, 0.0, 2, 1, 20.0, 41.0, 0, 15.0, 81.0, 0, 25.0, 0.0, 0, 0.0, 110.0, 105.0, 35.0, 71.0, 0.0, 64.0, 19.0, 1, 0, 0, 0, 0, 0, 0, 0, 127.0, 1);
MakePreset("WOUWOU", 1, 0.0, 0.0, 0.0, 0.0, 0.0, 1, 1, 20.0, 41.0, 0, 30.0, 93.0, 0, 25.0, 14.0, 0, 0.0, 41.0, 105.0, 38.0, 66.0, 127.0, 64.0, 19.0, 1, 0, 0, 0, 1, 0, 0, 0, 127.0, 1);
MakePreset("ABASS_", 1, 3.0, 0.0, 4.0, 0.0, 14.0, 2, 1, 25.0, 0.0, 1, 36.0, 33.0, 0, 11.0, 4.0, 0, 7.0, 38.0, 105.0, 0.0, 80.0, 0.0, 91.0, 48.0, 1, 1, 0, 0, 0, 0, 0, 0, 127.0, 1);
MakePreset("THROAT", 2, 0.0, 0.0, 0.0, 0.0, -6.0, 1, 1, 39.0, 61.0, 0, 26.0, 93.0, 0, 10.0, 6.0, 0, 0.0, 41.0, 105.0, 46.0, 72.0, 19.0, 77.0, 19.0, 1, 0, 0, 2, 1, 0, 0, 0, 127.0, 1);
MakePreset("SUBOSC", 1, 0.0, 0.0, 0.0, 0.0, 0.0, 2, 1, 32.0, 67.0, 1, 37.0, 71.0, 0, 13.0, 2.0, 0, -63.0, 47.0, 105.0, 0.0, 66.0, 127.0, 88.0, 77.0, 1, 0, 0, 0, 0, 0, 0, 0, 127.0, 1);
MakePreset("RESO__", 2, 0.0, 0.0, 7.0, 0.0, 0.0, 3, 3, 63.0, 0.0, 1, 21.0, 127.0, 2, 0.0, -4.0, 0, 0.0, 40.0, 105.0, 0.0, 62.0, 127.0, 79.0, 0.0, 1, 0, 0, 0, 0, 0, 0, 0, 127.0, 1);
MakePreset("JUNKTT", 2, 0.0, 0.0, 3.0, 0.0, 0.0, 1, 2, -32.0, 32.0, 1, 27.0, 79.0, 0, 19.0, 9.0, 1, 0.0, 3.0, 105.0, 70.0, 66.0, 127.0, 0.0, 45.0, 1, 1, 0, 0, 0, 0, 0, 0, 127.0, 1);
MakePreset("NFBASS", 1, 0.0, 0.0, 0.0, 0.0, 0.0, 1, 1, 20.0, 41.0, 0, 25.0, 93.0, 0, 25.0, 14.0, 0, 0.0, 41.0, 105.0, 38.0, 66.0, 127.0, 64.0, 19.0, 1, 0, 0, 0, 1, 0, 0, 0, 127.0, 1);
MakePreset("RESBAR", 2, 0.0, 0.0, 0.0, 0.0, 0.0, 1, 1, 3.0, 0.0, 1, 88.0, 86.0, 2, -23.0, 0.0, 0, 0.0, 0.0, 105.0, 0.0, 66.0, 127.0, 75.0, 19.0, 1, 0, 0, 0, 0, 0, 0, 0, 127.0, 1);
MakePreset("SQP___", 2, 0.0, 0.0, 0.0, 0.0, 0.0, 1, 1, 20.0, 0.0, 0, 29.0, 93.0, 0, 25.0, 6.0, 0, 0.0, 41.0, 105.0, 38.0, 66.0, 127.0, 64.0, 19.0, 1, 0, 0, 0, 1, 0, 0, 0, 127.0, 1);
MakePreset("BOC___", 2, 3.0, 0.0, 4.0, 0.0, 14.0, 2, 1, 25.0, 82.0, 1, 62.0, 0.0, 0, 11.0, 4.0, 0, 7.0, 38.0, 105.0, 0.0, 80.0, 0.0, 91.0, 48.0, 1, 1, 0, 0, 0, 0, 0, 0, 127.0, 1);
MakePreset("FATLED", 1, 2.0, 14.0, 5.0, 0.0, 0.0, 1, 1, 45.0, 58.0, 1, 79.0, 38.0, 0, 19.0, 5.0, 0, 0.0, 55.0, 105.0, 0.0, 45.0, 72.0, 99.0, 72.0, 1, 1, 0, 0, 0, 0, 0, 0, 127.0, 1);
MakePreset("FLYPOL", 2, 0.0, 15.0, 0.0, 0.0, 0.0, 1, 1, 3.0, 0.0, 1, 40.0, 35.0, 0, 28.0, 0.0, 0, 0.0, 28.0, 94.0, 0.0, 66.0, 127.0, 72.0, 19.0, 1, 0, 0, 0, 0, 0, 0, 0, 127.0, 1);
MakePreset("303AKO", 1, 1.0, 22.0, 37.0, 0.0, 0.0, 1, 1, 37.0, 0.0, 1, 12.0, 98.0, 0, 30.0, 11.0, 0, 0.0, 33.0, 105.0, 0.0, 96.0, 0.0, 85.0, 90.0, 0, 3, 0, 0, 0, 0, 0, 0, 127.0, 1);
MakePreset("THRMIN", 2, 1.0, 29.0, 5.0, 5.0, 0.0, 0, 1, 28.0, 0.0, 1, 127.0, 0.0, 0, 0.0, 0.0, 0, 0.0, 0.0, 105.0, 49.0, 66.0, 127.0, 69.0, 86.0, 1, 0, 1, 0, 0, 0, 0, 0, 127.0, 1);
MakePreset("DCHRD1", 3, 5.0, 0.0, 24.0, 6.0, 0.0, 1, 1, 16.0, 62.0, 1, 83.0, 74.0, 0, -41.0, 12.0, 0, 0.0, 0.0, 79.0, 0.0, 64.0, 0.0, 64.0, 93.0, 1, 3, 0, 0, 1, 0, 0, 0, 127.0, 1);
MakePreset("DCHRD2", 4, 0.0, 0.0, 25.0, 0.0, 0.0, 1, 1, 19.0, 49.0, 1, 41.0, 0.0, 0, 37.0, 3.0, 0, 0.0, 0.0, 105.0, 0.0, 72.0, 0.0, 0.0, 86.0, 1, 3, 0, 0, 1, 0, 0, 0, 127.0, 1);
MakePreset("DCHRD3", 2, 3.0, 0.0, 44.0, 0.0, 14.0, 2, 1, 40.0, 46.0, 1, 69.0, 87.0, 0, 20.0, 4.0, 0, 7.0, 38.0, 105.0, 0.0, 78.0, 0.0, 91.0, 95.0, 1, 3, 0, 0, 0, 0, 0, 0, 127.0, 1);
MakePreset("SCIFIZ", 2, 0.0, 0.0, 63.0, 0.0, 0.0, 2, 1, 17.0, 0.0, 1, 29.0, 98.0, 2, 35.0, 0.0, 0, 0.0, 0.0, 62.0, 49.0, 65.0, 0.0, 21.0, 49.0, 1, 5, 0, 0, 0, 0, 0, 0, 127.0, 1);
MakePreset("SCIFI1", 3, 0.0, 0.0, 21.0, 0.0, 0.0, 0, 1, 3.0, 0.0, 0, 42.0, 78.0, 0, 32.0, 0.0, 0, 0.0, 0.0, 105.0, 0.0, 94.0, 0.0, 0.0, 84.0, 1, 1, 0, 0, 0, 0, 0, 0, 127.0, 1);
MakePreset("SCIFI3", 1, 1.0, 0.0, 10.0, 0.0, 17.0, 2, 2, -1.0, 58.0, 1, 31.0, 103.0, 0, 39.0, 9.0, 1, 63.0, 0.0, 127.0, 0.0, 44.0, 0.0, 21.0, 34.0, 1, 6, 0, 4, 1, 0, 0, 0, 127.0, 1);
MakePreset("DOBREJ", 1, 0.0, 0.0, 0.0, 0.0, 0.0, 2, 1, 37.0, 53.0, 1, 16.0, 82.0, 1, 0.0, 23.0, 0, 0.0, 0.0, 105.0, 0.0, 66.0, 127.0, 64.0, 19.0, 1, 0, 0, 0, 1, 0, 0, 0, 127.0, 1);
MakePreset("TMP___", 2, 0.0, 20.0, 0.0, 0.0, 0.0, 1, 2, 37.0, 0.0, 1, 31.0, 72.0, 0, 27.0, 0.0, 0, 0.0, 28.0, 105.0, 34.0, 66.0, 127.0, 67.0, 19.0, 1, 0, 0, 0, 0, 0, 0, 0, 127.0, 1);
}
void ds10::ProcessDoubleReplacing(
double** inputs,
double** outputs,
int nFrames)
{
// Mutex is already locked for us.
double *leftOutput = outputs[0];
double *rightOutput = outputs[1];
for (int i = 0; i < nFrames; ++i) {
mMIDIReceiver.advance();
leftOutput[i] = rightOutput[i] = ds10_get_sample0(ds10state);
}
mMIDIReceiver.Flush(nFrames);
}
void ds10::SetSampleRate(void)
{
ds10_set_resampler(ds10state, mOversample, mSampleRate, mExtraRatio);
}
void ds10::Reset()
{
TRACE;
IMutexLock lock(this);
mSampleRate = GetSampleRate();
SetSampleRate();
}
void ds10::OnParamChange(int paramIdx)
{
IMutexLock lock(this);
IParam *param = GetParam(paramIdx);
const Property *prop = ¶meterProperties[paramIdx];
int val = param->Value();
if (paramIdx < kMetaParams) {
/* mg.bpm has off in lower position */
if (prop->ds_id == 25 || prop->ds_id == 10)
val = !val;
printf("set %d to %d\n", prop->ds_id, val);
ds10_knob_all(ds10state, prop->ds_id, val);
} else switch (paramIdx) {
case mPolySwitch:
ds10_set_polyphony(ds10state, val + 1);
break;
case mOversampleSwitch:
mOversample = !param->Int();
SetSampleRate();
break;
case mResampleSwitch:
mPitchByResampling = !param->Int();
SetSampleRate();
break;
case mDistractKnob:
mExtraRatio = pow(2, -(127 - param->Value()) / 127 * 4);
SetSampleRate();
break;
}
}
void ds10::ProcessMidiMsg(IMidiMsg* pMsg) {
mMIDIReceiver.onMessageReceived(pMsg);
}