-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchipCoreBase.pas
More file actions
344 lines (289 loc) · 9.97 KB
/
chipCoreBase.pas
File metadata and controls
344 lines (289 loc) · 9.97 KB
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
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
unit chipCoreBase;
interface
uses DAEffect, DAEffectX, DAudioEffectX, math, baseInstrument, audiohelper;
const
kNumPrograms = 32;
kNumOutputs = 2;
kNumParams = 0;
type TchipCore = class(AudioEffectX)
private
instruments: Array[0..kNumPrograms] of TBaseInstrument;
currentDelta : longint;
procedure initProcess;
public
constructor Create(audioMaster: TAudioMasterCallbackFunc);
destructor Destroy; override;
procedure process(inputs, outputs: ppsingle; sampleframes: longint); override;
procedure processReplacing(inputs, outputs: ppsingle; sampleframes: longint); override;
function processEvents(ev: PVSTEvents): longint; override;
procedure setProgram(aProgram: longint); override;
procedure setProgramName(name: pchar); override;
procedure getProgramName(name: pchar); override;
procedure setParameter(index: longint; value: single); override;
function getParameter(index: longint): single; override;
procedure getParameterLabel(index: longint; aLabel: pchar); override;
procedure getParameterDisplay(index: longint; text: pchar); override;
procedure getParameterName(index: longint; aLabel: pchar); override;
procedure setSampleRate(sampleRate: single); override;
procedure setBlockSize(blockSize: longint); override;
procedure resume; override;
function getOutputProperties(index: longint; properties: PVstPinProperties): boolean; override;
function getProgramNameIndexed(category, index: longint; text: pchar): boolean; override;
function copyProgram(destination: longint): boolean; override;
function getEffectName(name: pchar): boolean; override;
function getVendorString(text: pchar): boolean; override;
function getProductString(text: pchar): boolean; override;
function getVendorVersion: longint; override; {return 1;}
function canDo(text: pchar): longint; override;
end;
implementation
uses
Windows, SysUtils, DVSTUtils, DAudioEffect;
//-----------------------------------------------------------------------------------------
// TchipCore
//-----------------------------------------------------------------------------------------
//-----------------------------------------------------------------------------------------
constructor TchipCore.Create(audioMaster: TAudioMasterCallbackFunc);
var
i: integer;
begin
inherited Create(audioMaster, kNumPrograms, kNumParams);
for i := 0 to kNumPrograms-1 do
begin
instruments[i] := TBaseInstrument.Create;
end;
if Assigned(audioMaster) then
begin
setNumInputs(0); // no inputs
setNumOutputs(kNumOutputs); // 2 outputs, 1 for each oscillator
canProcessReplacing(TRUE);
hasVu(FALSE);
hasClip(FALSE);
isSynth(TRUE);
setUniqueID(FourCharToLong('c', 'h', 'C', 'R')); // <<<! *must* change this!!!!
end;
initProcess;
suspend;
end;
//-----------------------------------------------------------------------------------------
destructor TchipCore.Destroy;
var
i: integer;
begin
for i := 0 to kNumPrograms-1 do
begin
FreeAndNil(instruments[i]);
end;
end;
//-----------------------------------------------------------------------------------------
procedure TchipCore.setProgram(aProgram: longint);
begin
end;
//-----------------------------------------------------------------------------------------
procedure TchipCore.setProgramName(name: pchar);
begin
end;
//-----------------------------------------------------------------------------------------
procedure TchipCore.getProgramName(name: pchar);
begin
StrCopy(name, '');
end;
//-----------------------------------------------------------------------------------------
procedure TchipCore.getParameterLabel(index: longint; aLabel: pchar);
begin
StrCopy(aLabel, '');
end;
//-----------------------------------------------------------------------------------------
procedure TchipCore.getParameterDisplay(index: longint; text: pchar);
begin
StrCopy(text, '');
end;
//-----------------------------------------------------------------------------------------
procedure TchipCore.getParameterName(index: longint; aLabel: pchar);
begin
StrCopy(aLabel, '');
end;
//-----------------------------------------------------------------------------------------
procedure TchipCore.setParameter(index: longint; value: single);
begin
end;
//-----------------------------------------------------------------------------------------
function TchipCore.getParameter(index: longint): single;
begin
Result := 0;
end;
//-----------------------------------------------------------------------------------------
function TchipCore.getOutputProperties(index: longint; properties: PVstPinProperties): boolean;
begin
Result := FALSE;
if (index < kNumOutputs) then
begin
StrCopy(properties^.vLabel, pchar(Format('Vstx %d', [index+1])));
properties^.flags := kVstPinIsActive;
if (index < 2) then
properties^.flags := properties^.flags or kVstPinIsStereo; // test, make channel 1+2 stereo
Result := TRUE;
end;
end;
//-----------------------------------------------------------------------------------------
function TchipCore.getProgramNameIndexed(category, index: longint; text: pchar): boolean;
begin
Result := FALSE;
if (index < kNumPrograms) then
begin
StrCopy(text, PChar(instruments[index].name));
Result := TRUE;
end;
end;
//-----------------------------------------------------------------------------------------
function TchipCore.copyProgram(destination: longint): boolean;
begin
Result := FALSE;
end;
//-----------------------------------------------------------------------------------------
function TchipCore.getEffectName(name: pchar): boolean;
begin
StrCopy(name, 'chipCore');
Result := TRUE;
end;
//-----------------------------------------------------------------------------------------
function TchipCore.getVendorString(text: pchar): boolean;
begin
StrCopy(text, 'nILS');
Result := TRUE;
end;
//-----------------------------------------------------------------------------------------
function TchipCore.getProductString(text: pchar): boolean;
begin
StrCopy(text, 'chipCore');
Result := TRUE;
end;
function TchipCore.getVendorVersion: longint;
begin
Result := 1;
end;
//-----------------------------------------------------------------------------------------
function TchipCore.canDo(text: pchar): longint;
begin
Result := -1; // explicitly can't do; 0 => don't know
if StrComp(text, 'receiveVstEvents') = 0 then
Result := 1;
if StrComp(text, 'receiveVstMidiEvent') = 0 then
Result := 1;
end;
//-----------------------------------------------------------------------------------------
//-----------------------------------------------------------------------------------------
procedure TchipCore.setSampleRate(sampleRate: single);
var
b: Byte;
begin
inherited setSampleRate(sampleRate);
for b := 0 to kNumPrograms-1 do
begin
instruments[b].SampleRate := sampleRate;
end;
end;
//-----------------------------------------------------------------------------------------
procedure TchipCore.setBlockSize(blockSize: longint);
begin
inherited setBlockSize(blockSize);
// you may need to have to do something here...
end;
//-----------------------------------------------------------------------------------------
procedure TchipCore.resume;
begin
wantEvents(1);
end;
//-----------------------------------------------------------------------------------------
procedure TchipCore.initProcess;
var
i : longint;
wh : longint;
k, a : double;
begin
currentDelta := 0;
end;
//-----------------------------------------------------------------------------------------
procedure TchipCore.process(inputs, outputs: ppsingle; sampleFrames: longint);
var
out1,
out2: psingle;
begin
begin
{
out1 := outputs^;
inc(outputs);
out2 := outputs^;
}
if (currentDelta >= 0) then
begin
if (currentDelta >= sampleFrames) // should never happen
then currentDelta := 0;
inc(out1, currentDelta);
inc(out2, currentDelta);
dec(sampleFrames, currentDelta);
currentDelta := 0;
end;
instruments[0].getSamples(sampleFrames, outputs);
{
// loop
dec(sampleFrames);
while (sampleFrames >= 0) do
begin
// this is all very raw, there is no means of interpolation,
// and we will certainly get aliasing due to non-bandlimited
// waveforms. don't use this for serious projects...
out1^ := out1^ + fPhase * fVolume * vol;
inc(out1);
out2^ := out2^ + fPhase * fVolume * vol;
inc(out2);
fPhase := fPhase + baseFreq;
if (fPhase > 1) then fPhase := frac(fPhase);
dec(sampleFrames);
end;
}
end;
end;
//-----------------------------------------------------------------------------------------
procedure TchipCore.processReplacing(inputs, outputs: ppsingle; sampleFrames: longint);
begin
process(inputs, outputs, sampleFrames);
end;
//-----------------------------------------------------------------------------------------
function TchipCore.processEvents(ev: PVstEvents): longint;
var
i : longint;
event : PVstMidiEvent;
status : longint;
note : longint;
velocity : longint;
begin
for i := 0 to ev^.numEvents-1 do
begin
if ((ev^.events[i])^.vType <> kVstMidiType) then
Continue;
event := PVstMidiEvent(ev^.events[i]);
status := event^.midiData[0] and $F0; // ignoring channel
if (status = $90) or (status = $80) then // we only look at notes
begin
note := event^.midiData[1] and $7F;
velocity := event^.midiData[2] and $7F;
if ((status = $90) and (velocity > 0)) then
begin
instruments[0].noteOn(note, velocity, event^.deltaFrames);
end
else
begin
instruments[0].noteOff(note, velocity);
end;
end
else
if (status = $B0) and (event^.midiData[1] = $7E) then // all notes off
begin
instruments[0].noteOff(0,0);
end;
inc(event);
end;
Result := 1; // want more
end;
end.