-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathmultifxVST.cpp
452 lines (362 loc) · 11 KB
/
multifxVST.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
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
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
//------------------------------------------------------------------------
//-
//- Project : Use different Controls of VSTGUI
//- Filename : multifxVST.cpp
//- Created by : CTAF
//- Description :
//-
//- © 2000-1999, Steinberg Soft und Hardware GmbH, All Rights Reserved
//------------------------------------------------------------------------
#include "stdafx.h"
#ifndef __multifxVST__
#include "multifxVST.h"
#endif
#ifndef __multifxVSTeditor__
#include "multifxVSTeditor.h"
#endif
/*#include <stdio.h>
#include <string.h>*/
#include "controleurdlg.h"
#include "multifxVSTmain.h"
// global
extern bool oome;
#include "stockeffet.h"
#include "CCVSThost.h"
#include "ChainDlg.h"
#include "multifxVSTEditor.h"
#include "effectwnd.h"
#include "EffectTxTDlg.h"
#include "Chaindlg.h"
#include "maindlg.h"
#include "controleurlst.h"
//-----------------------------------------------------------------------------
multifxVST::multifxVST (audioMasterCallback audioMaster) :
AudioEffectX (audioMaster, 0, kNumParams+32)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
TRACE("multifxVST::multifxVST \n");
dat = NULL;
APP.effect = this;
APP.current_chaine = 0;
APP.parameter = new CParameterLst;
APP.controleur = new CControleurLst;
APP.chaine_eff = new CStockEffetLst;
APP.m_waitfade = new CEvent(0,0,"waitfade");
APP.host = &theApp.host;
APP.mnu = new CMenu;
APP.mnu->LoadMenu(IDR_MNUEFFECTS);
APP.parameter->Init(32);
APP.controleur->Init(32);
APP.controleur->Set_APP(&APP);
APP.parameter->Set_APP(&APP);
APP.chaine_eff->Set(&APP);
//setOfflineQualities();
//programsAreChunks();
//setInitialDelay();
//setRealtimeQualities();
//VST DEF
setNumInputs (2);
setNumOutputs (2);
hasVu (false);
canMono (true);
canProcessReplacing ();
programsAreChunks();
//canParameterBeAutomated(
setUniqueID (CCONST ('C', 'T', 'A', 'F'));
//needIdle();
// init programs
// programs = NULL;
//numPrograms = 0;
editor = new multifxVSTEditor (this);
ASSERT(editor);
((multifxVSTEditor *)editor)->SetAPP(&APP);
APP.editor = (multifxVSTEditor *)editor;
}
long multifxVST::getChunk(void **data,bool isPreset)
{
CMemFile f;
CArchive ar(&f,CArchive::store);
APP.chaine_eff->SaveParamsToMem(APP.current_chaine);
APP.chaine_eff->save(ar);
ar.Close();
long len =(long) f.GetLength();
if(dat)//data buffer for chunk file
{
delete dat;
dat = NULL;
}
dat = f.Detach();
*data = dat;
f.Close();
return len;
}
long multifxVST::setChunk(void *data,long byteSize,bool isPreset)
{
CMemFile f(0);
f.Attach((BYTE *)data,byteSize);
CArchive ar(&f,CArchive::load);
BOOL b;
if(APP.pMainDlg )
APP.pMainDlg->KillEffect();
if((b=APP.chaine_eff->m_processing))
{
APP.chaine_eff->suspend(APP.current_chaine);
}
APP.chaine_eff->RemoveAll(false);
int newchain = APP.chaine_eff->load(ar);
APP.chaine_eff->ChangeChaine(APP.current_chaine,newchain);
APP.chaine_eff->LoadParamsFromMem(newchain);
if(b)
{
APP.chaine_eff->resume(newchain);
}
ar.Close();
f.Detach();//sinon memory leak! car ca detruit le buffer et Boumm
f.Close();
return 1;
}
//-----------------------------------------------------------------------------
multifxVST::~multifxVST ()
{
//detruit la liste des effets qui reduit le nombre de lien des plug-ins
//si les plug-iins n'ont plus de lien,ca les détruits
if(APP.chaine_eff)
{
delete APP.chaine_eff;
APP.chaine_eff = NULL;
}
if(APP.controleur)
{
delete APP.controleur;
APP.controleur = NULL;
}
if(APP.parameter)
{
delete APP.parameter;
APP.controleur = NULL;
}
if(dat)//data buffer for chunk file
{
delete dat;
dat = NULL;
}
if(APP.mnu)
{
delete APP.mnu;
APP.mnu = NULL;
}
if(APP.m_waitfade)
{
//APP.m_waitfade->Unlock
delete APP.m_waitfade;
APP.m_waitfade = NULL;
}
CString buf;buf.Format("DESTROY :: multifxVST(%d) \n", this); TRACE(buf);
}
void multifxVST::setParameterAutomated(long index ,float value)
{
AudioEffect::setParameterAutomated(index,value);
}
//------------------------------------------------------------------------
long multifxVST::vendorSpecific (long lArg1, long lArg2, void* ptrArg, float floatArg)
{
if (editor && lArg1 == 'stCA' && lArg2 == 'Whee')
return editor->onWheel (floatArg) == true ? 1 : 0;
else
return AudioEffectX::vendorSpecific (lArg1, lArg2, ptrArg, floatArg);
}
//-----------------------------------------------------------------------------
void multifxVST::resume ()
{
wantEvents ();// on veut qu'il nous envoie du midi
APP.chaine_eff->resume(APP.current_chaine);
}
//-----------------------------------------------------------------------------
void multifxVST::suspend ()
{
APP.chaine_eff->suspend(APP.current_chaine);
}
long multifxVST::startProcess() // Called one time before the start of process call
{
// APP.chaine_eff->startProcess();
return 0; //default
}
long multifxVST::stopProcess() // Called after the stop of process call
{
// APP.chaine_eff->stopProcess();
return 0;//default
}
//-----------------------------------------------------------------------------
bool multifxVST::keysRequired ()
{
if (editor)
return ((multifxVSTEditor*)editor)->keysRequired ();
else
return false;
}
//-----------------------------------------------------------------------------
bool multifxVST::string2parameter (long index, char* text)
{
bool v = false;
int val;
switch (index)
{
case kChainTag :
if (text)
{
sscanf (text, "%d", &val);
float fSliderValue = float(val);
if (fSliderValue < 0.f)
fSliderValue = 0.f;
else if (fSliderValue > 1.f)
fSliderValue = 1.f;
APP.current_chaine = float2NBChaine(fSliderValue);
//Program* ap = programs + curProgram;
//ap->setValue (fSliderValue);
}
v = true;
break;
default:
v = false;
}
return v;
}
//-----------------------------------------------------------------------------
void multifxVST::setBlockSize (long size)
{
/*AFX_MANAGE_STATE(AfxGetStaticModuleState());
CChainApp * theApp =(CChainApp *) AfxGetApp();*/
//theApp->chaine_eff.setBlockSize(theApp->current_chaine,size);
//AF AF AF chaine_eff->set..
//host->SetBlockSize(size);
APP.chaine_eff->SetBlockSize(size);
AudioEffect::setBlockSize (size);
}
void multifxVST::setSampleRate(float sampleRate)
{
/*AFX_MANAGE_STATE(AfxGetStaticModuleState());
CChainApp * theApp =(CChainApp *) AfxGetApp();*/
//theApp->chaine_eff.setBlockSize(theApp->current_chaine,size);
APP.chaine_eff->SetSampleRate(sampleRate);
AudioEffect::setSampleRate (sampleRate);
}
//-----------------------------------------------------------------------------
void multifxVST::setParameter (long index, float value)
{
bool updateUI = true;
//change chaine
if (index == kChainTag)
{
//signale un debut de changement de chaine
APP.chaine_eff->ChangeChaine(APP.current_chaine,float2NBChaine(value));
/*BOOL b =APP.chaine_eff->m_processing;
//on arrete de les plugins
if(b)
APP.chaine_eff->suspend(APP.current_chaine);
//on sauvegarde les parametres de l'anciens chaine (de cq plug)
APP.chaine_eff->SaveParamsToMem(APP.current_chaine);
APP.current_chaine = float2NBChaine(value);
//on charge les params de l'autre chaine
APP.chaine_eff->LoadParamsFromMem(APP.current_chaine);
//on lance les autres
if(b)
APP.chaine_eff->resume(APP.current_chaine);*/
updateUI = false;
// si c'est un controleur
}else if((index >= kNumParams) && (index < kNumParams + APP.parameter->GetCount()))
{
APP.parameter->setParameter(index-kNumParams,value);
}
//on met l'affichage a jours
if (editor && updateUI)
((AEffGUIEditor*)editor)->setParameter (index, value);
}
//-----------------------------------------------------------------------------
float multifxVST::getParameter (long index)
{
float v = 1.0;
if (index == kChainTag )
v = NBChaine2float(APP.current_chaine);
else
{
v = APP.parameter->getParameter(index-kNumParams);
}
return v;
}
//-----------------------------------------------------------------------------
void multifxVST::getParameterDisplay (long index, char *text)
{
if (index == kChainTag )
sprintf (text, "%d",APP.current_chaine);
else
sprintf (text, "%f",getParameter(index));
}
//-----------------------------------------------------------------------------
void multifxVST::getParameterLabel (long index, char *text)
{
switch (index)
{
case kChainTag :
strcpy (text, "");
break;
default :
strcpy (text, "");
}
}
//-----------------------------------------------------------------------------
void multifxVST::getParameterName (long index, char *text)
{
if (index == kChainTag)
strcpy (text, "Chain number");
else
sprintf (text, "Param #%d",index - kNumParams +1);
}
//-----------------------------------------------------------------------------
void multifxVST::process (float **inputs, float **outputs, long sampleFrames)
{
APP.chaine_eff->process(APP.current_chaine,inputs,outputs,sampleFrames);
}
long multifxVST::processEvents(VstEvents *ev)
{
for (long i = 0; i < ev->numEvents; i++)
{
if ((ev->events[i])->type != kVstMidiType)
continue;
VstMidiEvent* event = (VstMidiEvent*)ev->events[i];
char* midiData = event->midiData;
long status = midiData[0] & 0xf0; // ignoring channel
if (status == 0xB0) // we only look at controleur
{
long controleur = midiData[1] & 0x7f;
long value = midiData[2] & 0x7f;
setParameterAutomated(controleur,NBChaine2float(value));
}
}
return 1; // want more
}
long multifxVST::canDo (char* text)
{
//if (!strcmp (text, "receiveVstEvents")) return 1;
//if (!strcmp (text, "sendVstEvents")) return 1;
if (!strcmp (text, "receiveVstMidiEvent"))return 1;
//if (!strcmp (text, "sendVstMidiEvent")) return 1;
/*if (!strcmp (text, "receiveVstTimeInfo")) return 1;
if (!strcmp (text, "sendVstTimeInfo")) return 1;*/
// if (!strcmp (text, "receiveVstEvents")) return 1;
//if (!strcmp (text, "midiProgramNames")) return 1;
return -1; // explicitly can't do; 0 => don't know
}
//-----------------------------------------------------------------------------
void multifxVST::processReplacing (float **inputs, float **outputs, long sampleFrames)
{
APP.chaine_eff->processReplace (APP.current_chaine,inputs,outputs,sampleFrames);
}
void multifxVST::close()
{
CString buf;buf.Format("DEBCLOSE :: multifxVST(%d) \n", this); TRACE(buf);
AudioEffectX::close();
buf.Format("CLOSE :: multifxVST(%d) \n", this); TRACE(buf);
};
void multifxVST::open()
{
}