1 //===========================================================================
2 //
3 // DeicsOnze an emulator of the YAMAHA DX11 synthesizer
4 //
5 // Version 0.5.5
6 //
7 //
8 //
9 //
10 // Copyright (c) 2004-2006 Nil Geisweiller
11 //
12 //
13 //
14 // This program is free software; you can redistribute it and/or
15 // modify it under the terms of the GNU General Public License
16 // as published by the Free Software Foundation; either version 2
17 // of the License, or (at your option) any later version.
18 //
19 // This program is distributed in the hope that it will be useful,
20 // but WITHOUT ANY WARRANTY; without even the implied warranty of
21 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 // GNU General Public License for more details.
23 //
24 // You should have received a copy of the GNU General Public License
25 // along with this program; if not, write to the Free Software
26 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
27 // 02111-1301, USA or point your web browser to http://www.gnu.org.
28 //===========================================================================
29
30 #include <list>
31
32 #include <QDomDocument>
33 #include <QTemporaryFile>
34
35 #include "muse/midi_consts.h"
36 #include "libsynti/mess.h"
37 #include "deicsonze.h"
38 #include "libsimpleplugin/simpler_plugin.h"
39 #include "midictrl_consts.h"
40
41 #define ABS(x) (x>=0?x:-x)
42
43
44 float DeicsOnze::waveTable[NBRWAVES][RESOLUTION];
45 int DeicsOnze::useCount = 0;
46
47 QString DEI_hostConfigPath;
48 QString DEI_hostCachePath;
49 QString DEI_globalLibPath;
50 QString DEI_sharePath;
51 unsigned int DEI_segmentSize;
52 int DEI_sampleRate;
53 bool DEI_useDenormalBias;
54 float DEI_denormalBias;
55
56 //---------------------------------------------------------
57 // DeicsOnze
58 //---------------------------------------------------------
59
DeicsOnze()60 DeicsOnze::DeicsOnze() : Mess(2) {
61
62 MusESimplePlugin::SS_initPlugins(DEI_hostCachePath);
63
64 if (useCount++ == 0) {
65 // create sinus wave table, W1
66 for(int i = 0; i < RESOLUTION; i++)
67 waveTable[W1][i] =
68 (float)(sin((i * 2.0 * M_PI) / (double)RESOLUTION));
69 // create sinus*abs(sinus) wave table, W2
70 for(int i = 0; i < RESOLUTION; i++){
71 double t = (i * 2.0 * M_PI) / (double)RESOLUTION;
72 waveTable[W2][i] = (float)(ABS(sin(t))*sin(t));}
73 // create halfsinus_ wave table, W3
74 for(int i = 0; i < RESOLUTION; i++)
75 waveTable[W3][i] = (float)
76 (i<RESOLUTION/2?sin((i*2.0*M_PI)/(double)RESOLUTION):0.0);
77 // create halfsinus*abs(sinus)_ wave table, W4
78 for(int i = 0; i < RESOLUTION; i++){
79 double t = (i * 2.0 * M_PI) / (double)RESOLUTION;
80 waveTable[W4][i] = (float)(i<RESOLUTION/2?ABS(sin(t))*sin(t):0.0);}
81 // create sinus_ wave table, W5
82 for(int i = 0; i < RESOLUTION; i++)
83 waveTable[W5][i] = (float)
84 (i<RESOLUTION/2?sin((i*4.0*M_PI) / (double)RESOLUTION):0.0);
85 // create sinus*abs(sinus)_ wave table, W6
86 for(int i = 0; i < RESOLUTION; i++){
87 double t = (i*4.0*M_PI) / (double)RESOLUTION;
88 waveTable[W6][i] = (float)(i<RESOLUTION/2?ABS(sin(t))*sin(t):0.0);}
89 // create 2halfsinus_ wave table, W7
90 for(int i = 0; i < RESOLUTION; i++)
91 waveTable[W7][i] = (float)
92 (i<RESOLUTION/2?ABS(sin((i*4.0*M_PI)/(double)RESOLUTION)):0.0);
93 // create 2halfsinus*abs(sinus)_ wave table, W8
94 for(int i = 0; i < RESOLUTION; i++){
95 double t = (i * 4.0 * M_PI) / (double)RESOLUTION;
96 waveTable[W8][i] = (float)(i<RESOLUTION/2?sin(t)*sin(t):0.0);}
97 }
98
99 initBuffer = 0;
100 initLen = 0;
101
102 //alloc temp buffers chorus and reverb
103 tempInputChorus = (float**) malloc(sizeof(float*)*NBRFXINPUTS);
104 for(int i = 0; i < NBRFXINPUTS; i++)
105 tempInputChorus[i] = (float*) malloc(sizeof(float*)*MAXFXBUFFERSIZE);
106 tempOutputChorus = (float**) malloc(sizeof(float*)*NBRFXOUTPUTS);
107 for(int i = 0; i < NBRFXOUTPUTS; i++)
108 tempOutputChorus[i] = (float*) malloc(sizeof(float*)*MAXFXBUFFERSIZE);
109 tempInputReverb = (float**) malloc(sizeof(float*)*NBRFXINPUTS);
110 for(int i = 0; i < NBRFXINPUTS; i++)
111 tempInputReverb[i] = (float*) malloc(sizeof(float*)*MAXFXBUFFERSIZE);
112 tempOutputReverb = (float**) malloc(sizeof(float*)*NBRFXOUTPUTS);
113 for(int i = 0; i < NBRFXOUTPUTS; i++)
114 tempOutputReverb[i] = (float*) malloc(sizeof(float*)*MAXFXBUFFERSIZE);
115 tempInputDelay = (float**) malloc(sizeof(float*)*NBRFXINPUTS);
116 for(int i = 0; i < NBRFXINPUTS; i++)
117 tempInputDelay[i] = (float*) malloc(sizeof(float*)*MAXFXBUFFERSIZE);
118 tempOutputDelay = (float**) malloc(sizeof(float*)*NBRFXOUTPUTS);
119 for(int i = 0; i < NBRFXOUTPUTS; i++)
120 tempOutputDelay[i] = (float*) malloc(sizeof(float*)*MAXFXBUFFERSIZE);
121
122 srand(time(0)); // initialize random number generator
123
124 initCtrls();
125 initGlobal();
126
127 _numPatchProg = 0;
128 _saveOnlyUsed = true;
129 _saveConfig = true;
130 _isInitSet = true; //false if an initial bank must be download
131
132 _initSetPath = DEI_sharePath + QString("/presets/deicsonze/SutulaBank.dei");
133
134
135 //TODO
136 //INSTPREFIX + "/share/" + PACKAGEVERSION + "/presets/deicsonze/ARCH_ALIN";
137 _isBackgroundPix = true; //false if an initial bank must be download
138
139 //"/usr/local/share/muse-1.0pre1/wallpapers/abstractdeicsonze1.jpg";
140 _backgroundPixPath = DEI_sharePath + QString("/wallpapers/paper2.jpg"); // Tim.
141
142
143 //initialization GUI
144 _gui = new DeicsOnzeGui(this);
145 _gui->hide(); // to avoid flicker during MusE startup
146 _gui->setWindowTitle(QString("DeicsOnze"));
147
148 //FX
149 MusESimplePlugin::Plugin* p;
150 p = MusESimplePlugin::plugins.find("freeverb", "freeverb1");
151 _pluginIReverb = NULL;
152 if(p) initPluginReverb(p);
153 _pluginIChorus = NULL;
154 p = MusESimplePlugin::plugins.find("doublechorus", "doublechorus1");
155 if(p) initPluginChorus(p);
156 _pluginIDelay = NULL;
157 p = MusESimplePlugin::plugins.find("pandelay", "pandelay");
158 if(p) initPluginDelay(p);
159
160 //Filter
161 _dryFilter = new LowFilter();
162 _chorusFilter = new LowFilter();
163 _reverbFilter = new LowFilter();
164 _delayFilter = new LowFilter();
165
166 _initialPreset = new
167 Preset(new Subcategory(new Category(NULL, "NONE", 0), "NONE", 0), 0);
168 for(int c = 0; c < NBRCHANNELS; c++) {
169 _preset[c]=_initialPreset;
170 setPreset(c);
171 }
172
173 //Load configuration
174 QString defaultConf =
175 DEI_hostConfigPath + QString("/" DEICSONZESTR ".dco");
176 FILE* f;
177 f = fopen(defaultConf.toLatin1().data(), "r");
178 if(f) {
179 fclose(f);
180 loadConfiguration(defaultConf);
181 }
182
183 //load Set
184 _set=new Set("Initial Bank");
185 if(_isInitSet) loadSet(_initSetPath);
186
187 //loadSutulaPresets();
188
189 //update display gui
190 //update mastervol
191 unsigned char dataMasterVol[2];
192 dataMasterVol[0]=SYSEX_MASTERVOL;
193 dataMasterVol[1]=getMasterVol();
194 MusECore::MidiPlayEvent evSysexMasterVol(0, 0, MusECore::ME_SYSEX,
195 (const unsigned char*)dataMasterVol,
196 2);
197 _gui->writeEvent(evSysexMasterVol);
198 //update return fx
199 unsigned char *dataReverbRet = new unsigned char[2];
200 dataReverbRet[0]=SYSEX_REVERBRETURN;
201 dataReverbRet[1]=(unsigned char)getReverbReturn();
202 MusECore::MidiPlayEvent evReverbRet(0, 0, MusECore::ME_SYSEX,(const unsigned char*)dataReverbRet, 2);
203 _gui->writeEvent(evReverbRet);
204 unsigned char *dataChorusRet = new unsigned char[2];
205 dataChorusRet[0]=SYSEX_CHORUSRETURN;
206 dataChorusRet[1]=(unsigned char)getChorusReturn();
207 MusECore::MidiPlayEvent evChorusRet(0, 0, MusECore::ME_SYSEX,(const unsigned char*)dataChorusRet, 2);
208 _gui->writeEvent(evChorusRet);
209 unsigned char *dataDelayRet = new unsigned char[2];
210 dataDelayRet[0]=SYSEX_DELAYRETURN;
211 dataDelayRet[1]=(unsigned char)getDelayReturn();
212 //printf("DELAY RET = %d, REVERB RET = %d\n",
213 //getDelayReturn(), getReverbReturn());
214 MusECore::MidiPlayEvent evDelayRet(0, 0, MusECore::ME_SYSEX,(const unsigned char*)dataDelayRet, 2);
215 _gui->writeEvent(evDelayRet);
216 //update font size
217 unsigned char *dataFontSize = new unsigned char[2];
218 dataFontSize[0]=SYSEX_FONTSIZE;
219 dataFontSize[1]=(unsigned char)_global.fontSize;
220 MusECore::MidiPlayEvent evFontSize(0, 0, MusECore::ME_SYSEX, (const unsigned char*)dataFontSize, 2);
221 _gui->writeEvent(evFontSize);
222 //display load preset
223 unsigned char dataUpdateGuiSet[1];
224 dataUpdateGuiSet[0]=SYSEX_UPDATESETGUI;
225 MusECore::MidiPlayEvent evSysexUpdateGuiSet(0, 0, MusECore::ME_SYSEX,
226 (const unsigned char*)dataUpdateGuiSet,
227 1);
228 _gui->writeEvent(evSysexUpdateGuiSet);
229 }
230
231 //---------------------------------------------------------
232 // ~DeicsOnze
233 //---------------------------------------------------------
234
~DeicsOnze()235 DeicsOnze::~DeicsOnze()
236 {
237 if(_gui)
238 delete _gui;
239
240 if(_pluginIReverb)
241 delete _pluginIReverb;
242 if(_pluginIChorus)
243 delete _pluginIChorus;
244 if(_pluginIDelay)
245 delete _pluginIDelay;
246
247 //if (--useCount == 0)
248 //delete[] sine_table;
249 //dealloc temp buffers chorus and reverb
250 for(int i = 0; i < NBRFXINPUTS; i++) free(tempInputChorus[i]);
251 free(tempInputChorus);
252 for(int i = 0; i < NBRFXOUTPUTS; i++) free(tempOutputChorus[i]);
253 free(tempOutputChorus);
254 for(int i = 0; i < NBRFXINPUTS; i++) free(tempInputReverb[i]);
255 free(tempInputReverb);
256 for(int i = 0; i < NBRFXOUTPUTS; i++) free(tempOutputReverb[i]);
257 free(tempOutputReverb);
258 for(int i = 0; i < NBRFXINPUTS; i++) free(tempInputDelay[i]);
259 free(tempInputDelay);
260 for(int i = 0; i < NBRFXOUTPUTS; i++) free(tempOutputDelay[i]);
261 free(tempOutputDelay);
262
263 if (initBuffer)
264 delete [] initBuffer;
265 }
266
oldMidiStateHeader(const unsigned char ** data) const267 int DeicsOnze::oldMidiStateHeader(const unsigned char** data) const
268 {
269 static unsigned char const d[2] = {MUSE_SYNTH_SYSEX_MFG_ID, DEICSONZE_UNIQUE_ID};
270 *data = &d[0];
271 return 2;
272 }
273
274 //---------------------------------------------------------
275 // getSinusWaveTable
276 //---------------------------------------------------------
getSinusWaveTable()277 float* DeicsOnze::getSinusWaveTable() {
278 return waveTable[W1];
279 }
280
281 //---------------------------------------------------------
282 // guiVisible
283 //---------------------------------------------------------
nativeGuiVisible() const284 bool DeicsOnze::nativeGuiVisible() const
285 {
286 return _gui->isVisible();
287 }
288
289 //---------------------------------------------------------
290 // showGui
291 //---------------------------------------------------------
showNativeGui(bool val)292 void DeicsOnze::showNativeGui(bool val)
293 {
294 _gui->setVisible(val);
295 }
296
297 //---------------------------------------------------------
298 // getNativeGeometry
299 //---------------------------------------------------------
300
getNativeGeometry(int * x,int * y,int * w,int * h) const301 void DeicsOnze::getNativeGeometry(int* x, int* y, int* w, int* h) const {
302 QPoint pos(_gui->pos());
303 QSize size(_gui->size());
304 *x = pos.x();
305 *y = pos.y();
306 *w = size.width();
307 *h = size.height();
308 }
309
setSampleRate(int sr)310 void DeicsOnze::setSampleRate(int sr) {
311 Mess::setSampleRate(sr);
312 _dryFilter->setSamplerate(sr);
313 _chorusFilter->setSamplerate(sr);
314 _reverbFilter->setSamplerate(sr);
315 _delayFilter->setSamplerate(sr);
316 setQuality(_global.quality);
317 }
318
319 //---------------------------------------------------------
320 // setNativeGeometry
321 //---------------------------------------------------------
322
setNativeGeometry(int x,int y,int w,int h)323 void DeicsOnze::setNativeGeometry(int x, int y, int w, int h) {
324 _gui->resize(QSize(w, h));
325 _gui->move(QPoint(x, y));
326 }
327
328 //---------------------------------------------------------
329 // initCtrls
330 //---------------------------------------------------------
initCtrls()331 void DeicsOnze::initCtrls() {
332 int i=0;
333 for(int k=0; k<NBROP; k++) {
334 _ctrl[i].name=(QString(ARSTR)+QString::number(k+1)).toLatin1().data();
335 _ctrl[i].num=CTRL_AR+k*DECAPAR1;
336 _ctrl[i].min=0;
337 _ctrl[i++].max=MAXAR;
338 _ctrl[i].name=(QString(D1RSTR)+QString::number(k+1)).toLatin1().data();
339 _ctrl[i].num=CTRL_D1R+k*DECAPAR1;
340 _ctrl[i].min=0;
341 _ctrl[i++].max=MAXD1R;
342 _ctrl[i].name=(QString(D2RSTR)+QString::number(k+1)).toLatin1().data();
343 _ctrl[i].num=CTRL_D2R+k*DECAPAR1;
344 _ctrl[i].min=0;
345 _ctrl[i++].max=MAXD2R;
346 _ctrl[i].name=(QString(RRSTR)+QString::number(k+1)).toLatin1().data();
347 _ctrl[i].num=CTRL_RR+k*DECAPAR1;
348 _ctrl[i].min=0;
349 _ctrl[i++].max=MAXRR;
350 _ctrl[i].name=(QString(D1LSTR)+QString::number(k+1)).toLatin1().data();
351 _ctrl[i].num=CTRL_D1L+k*DECAPAR1;
352 _ctrl[i].min=0;
353 _ctrl[i++].max=MAXD1L;
354 _ctrl[i].name=(QString(LSSTR)+QString::number(k+1)).toLatin1().data();
355 _ctrl[i].num=CTRL_LS+k*DECAPAR1;
356 _ctrl[i].min=0;
357 _ctrl[i++].max=MAXLS;
358 _ctrl[i].name=(QString(RSSTR)+QString::number(k+1)).toLatin1().data();
359 _ctrl[i].num=CTRL_RS+k*DECAPAR1;
360 _ctrl[i].min=0;
361 _ctrl[i++].max=MAXRS;
362 _ctrl[i].name=(QString(EBSSTR)+QString::number(k+1)).toLatin1().data();
363 _ctrl[i].num=CTRL_EBS+k*DECAPAR1;
364 _ctrl[i].min=0;
365 _ctrl[i++].max=MAXEBS;
366 _ctrl[i].name=(QString(AMESTR)+QString::number(k+1)).toLatin1().data();
367 _ctrl[i].num=CTRL_AME+k*DECAPAR1;
368 _ctrl[i].min=0;
369 _ctrl[i++].max=1;
370 _ctrl[i].name=(QString(KVSSTR)+QString::number(k+1)).toLatin1().data();
371 _ctrl[i].num=CTRL_KVS+k*DECAPAR1;
372 _ctrl[i].min=0;
373 _ctrl[i++].max=MAXKVS;
374 _ctrl[i].name=(QString(OUTSTR)+QString::number(k+1)).toLatin1().data();
375 _ctrl[i].num=CTRL_OUT+k*DECAPAR1;
376 _ctrl[i].min=0;
377 _ctrl[i++].max=MAXOUT;
378 _ctrl[i].name=(QString("Centi")+QString(RATIOLONGSTR)+QString::number(k+1))
379 .toLatin1().data();
380 _ctrl[i].num=CTRL_RATIO+k*DECAPAR1;
381 _ctrl[i].min=0;
382 _ctrl[i++].max=MAXRATIO*100;
383 _ctrl[i].name=(QString(DETSTR)+QString::number(k+1)).toLatin1().data();
384 _ctrl[i].num=CTRL_DET+k*DECAPAR1;
385 _ctrl[i].min=-MAXDET;
386 _ctrl[i++].max=MAXDET;
387 }
388 _ctrl[i].name=ALGSTR;
389 _ctrl[i].num=CTRL_ALG;
390 _ctrl[i].min=0;
391 _ctrl[i++].max=MAXALG;
392 _ctrl[i].name=FEEDBACKSTR;
393 _ctrl[i].num=CTRL_FEEDBACK;
394 _ctrl[i].min=0;
395 _ctrl[i++].max=MAXFEEDBACK;
396 _ctrl[i].name=SPEEDSTR;
397 _ctrl[i].num=CTRL_SPEED;
398 _ctrl[i].min=0;
399 _ctrl[i++].max=MAXSPEED;
400 _ctrl[i].name=DELAYSTR;
401 _ctrl[i].num=CTRL_DELAY;
402 _ctrl[i].min=0;
403 _ctrl[i++].max=MAXDELAY;
404 _ctrl[i].name=PMODDEPTHSTR;
405 _ctrl[i].num=CTRL_PMODDEPTH;
406 _ctrl[i].min=0;
407 _ctrl[i++].max=MAXPMODDEPTH;
408 _ctrl[i].name=AMODDEPTHSTR;
409 _ctrl[i].num=CTRL_AMODDEPTH;
410 _ctrl[i].min=0;
411 _ctrl[i++].max=MAXAMODDEPTH;
412 _ctrl[i].name=SYNCSTR;
413 _ctrl[i].num=CTRL_SYNC;
414 _ctrl[i].min=0;
415 _ctrl[i++].max=1;
416 _ctrl[i].name=WAVESTR;
417 _ctrl[i].num=CTRL_WAVE;
418 _ctrl[i].min=0;
419 _ctrl[i++].max=MAXWAVE;
420 _ctrl[i].name=PMODSENSSTR;
421 _ctrl[i].num=CTRL_PMODSENS;
422 _ctrl[i].min=0;
423 _ctrl[i++].max=MAXPMODSENS;
424 _ctrl[i].name=AMSSTR;
425 _ctrl[i].num=CTRL_AMS;
426 _ctrl[i].min=0;
427 _ctrl[i++].max=MAXAMS;
428 _ctrl[i].name=TRANSPOSESTR;
429 _ctrl[i].num=CTRL_TRANSPOSE;
430 _ctrl[i].min=0;
431 _ctrl[i++].max=MAXTRANSPOSE;
432 _ctrl[i].name=POLYMODESTR;
433 _ctrl[i].num=CTRL_POLYMODE;
434 _ctrl[i].min=0;
435 _ctrl[i++].max=1;
436 _ctrl[i].name=PBENDRANGESTR;
437 _ctrl[i].num=CTRL_PBENDRANGE;
438 _ctrl[i].min=0;
439 _ctrl[i++].max=MAXPBENDRANGE;
440 _ctrl[i].name=PORTAMODESTR;
441 _ctrl[i].num=CTRL_PORTAMODE;
442 _ctrl[i].min=0;
443 _ctrl[i++].max=1;
444 _ctrl[i].name=PORTATIMESTR;
445 _ctrl[i].num=CTRL_PORTATIME;
446 _ctrl[i].min=0;
447 _ctrl[i++].max=MAXPROTATIME;
448 _ctrl[i].name=FCVOLUMESTR;
449 _ctrl[i].num=CTRL_FCVOLUME;
450 _ctrl[i].min=0;
451 _ctrl[i++].max=MAXFCVOLUME;
452 _ctrl[i].name=FSWSTR;
453 _ctrl[i].num=CTRL_FSW;
454 _ctrl[i].min=0;
455 _ctrl[i++].max=MAXFSW;
456 _ctrl[i].name=MWPITCHSTR;
457 _ctrl[i].num=CTRL_MWPITCH;
458 _ctrl[i].min=0;
459 _ctrl[i++].max=MAXMWPITCH;
460 _ctrl[i].name=MWAMPLITUDESTR;
461 _ctrl[i].num=CTRL_MWAMPLITUDE;
462 _ctrl[i].min=0;
463 _ctrl[i++].max=MAXMWAMPLITUDE;
464 _ctrl[i].name=BCPITCHSTR;
465 _ctrl[i].num=CTRL_BCPITCH;
466 _ctrl[i].min=0;
467 _ctrl[i++].max=MAXBCPITCH;
468 _ctrl[i].name=BCAMPLITUDESTR;
469 _ctrl[i].num=CTRL_BCAMPLITUDE;
470 _ctrl[i].min=0;
471 _ctrl[i++].max=MAXBCAMPLITUDE;
472 _ctrl[i].name=BCPITCHBIASSTR;
473 _ctrl[i].num=CTRL_BCPITCHBIAS;
474 _ctrl[i].min=-MAXBCPITCHBIAS;
475 _ctrl[i++].max=MAXBCPITCHBIAS;
476 _ctrl[i].name=BCEGBIASSTR;
477 _ctrl[i].num=CTRL_BCEGBIAS;
478 _ctrl[i].min=0;
479 _ctrl[i++].max=MAXBCEGBIAS;
480 _ctrl[i].name=ATPITCHSTR;
481 _ctrl[i].num=CTRL_ATPITCH;
482 _ctrl[i].min=0;
483 _ctrl[i++].max=MAXATPITCH;
484 _ctrl[i].name=ATAMPLITUDESTR;
485 _ctrl[i].num=CTRL_ATAMPLITUDE;
486 _ctrl[i].min=0;
487 _ctrl[i++].max=MAXATAMPLITUDE;
488 _ctrl[i].name=ATPITCHBIASSTR;
489 _ctrl[i].num=CTRL_ATPITCHBIAS;
490 _ctrl[i].min=-MAXATPITCHBIAS;
491 _ctrl[i++].max=MAXATPITCHBIAS;
492 _ctrl[i].name=ATEGBIASSTR;
493 _ctrl[i].num=CTRL_ATEGBIAS;
494 _ctrl[i].min=0;
495 _ctrl[i++].max=MAXATEGBIAS;
496 _ctrl[i].name=PR1STR;
497 _ctrl[i].num=CTRL_PR1;
498 _ctrl[i].min=0;
499 _ctrl[i++].max=MAXPR;
500 _ctrl[i].name=PR2STR;
501 _ctrl[i].num=CTRL_PR2;
502 _ctrl[i].min=0;
503 _ctrl[i++].max=MAXPR;
504 _ctrl[i].name=PR3STR;
505 _ctrl[i].num=CTRL_PR3;
506 _ctrl[i].min=0;
507 _ctrl[i++].max=MAXPR;
508 _ctrl[i].name=PL1STR;
509 _ctrl[i].num=CTRL_PL1;
510 _ctrl[i].min=0;
511 _ctrl[i++].max=MAXPL;
512 _ctrl[i].name=PL2STR;
513 _ctrl[i].num=CTRL_PL2;
514 _ctrl[i].min=0;
515 _ctrl[i++].max=MAXPL;
516 _ctrl[i].name=PL3STR;
517 _ctrl[i].num=CTRL_PL3;
518 _ctrl[i].min=0;
519 _ctrl[i++].max=MAXPL;
520 for(int k=0; k<NBROP; k++) {
521 _ctrl[i].name=(QString(FIXSTR)+QString::number(k+1)).toLatin1().data();
522 _ctrl[i].num=CTRL_FIX+k*DECAPAR2;
523 _ctrl[i].min=0;
524 _ctrl[i++].max=1;
525 _ctrl[i].name=(QString("Centi")+QString(FIXRANGESTR)
526 +QString::number(k+1)).toLatin1().data();
527 _ctrl[i].num=CTRL_FIXRANGE+k*DECAPAR2;
528 _ctrl[i].min=0;
529 _ctrl[i++].max=MAXFIXRANGE*100;
530 _ctrl[i].name=(QString(OSWSTR)+QString::number(k+1)).toLatin1().data();
531 _ctrl[i].num=CTRL_OSW+k*DECAPAR2;
532 _ctrl[i].min=0;
533 _ctrl[i++].max=MAXOSW;
534 _ctrl[i].name=(QString(SHFTSTR)+QString::number(k+1)).toLatin1().data();
535 _ctrl[i].num=CTRL_SHFT+k*DECAPAR2;
536 _ctrl[i].min=0;
537 _ctrl[i++].max=MAXSHFT;
538 }
539 _ctrl[i].name=REVERBRATESTR;
540 _ctrl[i].num=CTRL_REVERBRATE;
541 _ctrl[i].min=0;
542 _ctrl[i++].max=7;
543 _ctrl[i].name=FCPITCHSTR;
544 _ctrl[i].num=CTRL_FCPITCH;
545 _ctrl[i].min=0;
546 _ctrl[i++].max=MAXFCPITCH;
547 _ctrl[i].name=FCAMPLITUDESTR;
548 _ctrl[i].num=CTRL_FCAMPLITUDE;
549 _ctrl[i].min=0;
550 _ctrl[i++].max=MAXFCAMPLITUDE;
551 _ctrl[i].name=CHANNELPANSTR;
552 _ctrl[i].num=CTRL_CHANNELPAN;
553 _ctrl[i].min=-MAXCHANNELPAN;
554 _ctrl[i++].max=MAXCHANNELPAN;
555 _ctrl[i].name=CHANNELDETUNESTR;
556 _ctrl[i].num=CTRL_CHANNELDETUNE;
557 _ctrl[i].min=-MAXCHANNELDETUNE;
558 _ctrl[i++].max=MAXCHANNELDETUNE;
559 _ctrl[i].name=CHANNELVOLUMESTR;
560 _ctrl[i].num=CTRL_CHANNELVOLUME;
561 _ctrl[i].min=0;
562 _ctrl[i++].max=MAXCHANNELVOLUME;
563 _ctrl[i].name=FINEBRIGHTNESSSTR;
564 _ctrl[i].num=CTRL_FINEBRIGHTNESS;
565 _ctrl[i].min=0;
566 _ctrl[i++].max=MAXFINEBRIGHTNESS;
567 _ctrl[i].name=NBRVOICESSTR;
568 _ctrl[i].num=CTRL_NBRVOICES;
569 _ctrl[i].min=0;
570 _ctrl[i++].max=MAXNBRVOICES;
571 nbrCtrl=i;
572 }
573
574 //---------------------------------------------------------
575 // initGlobal
576 //---------------------------------------------------------
initGlobal()577 void DeicsOnze::initGlobal() {
578 setMasterVol(INITMASTERVOL);
579 _global.quality = high;
580 setFilter(false);
581 _global.fontSize = 9;
582 _global.isChorusActivated = false;
583 _global.chorusReturn = level2amp(INITFXRETURN);
584 _global.isReverbActivated = false;
585 _global.reverbReturn = level2amp(INITFXRETURN);
586 _global.isDelayActivated = false;
587 _global.delayReturn = level2amp(INITFXRETURN);
588 initChannels();
589 }
590
initChannels()591 void DeicsOnze::initChannels() {
592 for(int c=0; c<NBRCHANNELS; c++) initChannel(c);
593 _global.channel[0].isEnable = true; //the first one is enable
594 }
595
initChannel(int c)596 void DeicsOnze::initChannel(int c) {
597 _global.channel[c].isEnable = false;
598 _global.channel[c].sustain = false;
599 _global.channel[c].volume = DEFAULTVOL;
600 _global.channel[c].pan = 0;
601 _global.channel[c].modulation = 0;
602 _global.channel[c].detune = 0;
603 _global.channel[c].brightness = MIDFINEBRIGHTNESS;
604 _global.channel[c].attack = MIDATTACK;
605 _global.channel[c].release = MIDRELEASE;
606 _global.channel[c].pitchBendCoef = 1.0;
607 _global.channel[c].lfoIndex = 0;
608 _global.channel[c].lfoDelayIndex = 0.0;
609 _global.channel[c].nbrVoices = 8;
610 _global.channel[c].isLastNote = false;
611 _global.channel[c].chorusAmount = 0.0;
612 _global.channel[c].reverbAmount = 0.0;
613 _global.channel[c].delayAmount = 0.0;
614 applyChannelAmp(c);
615 initVoices(c);
616 }
617
618 //---------------------------------------------------------
619 // resetVoices
620 //---------------------------------------------------------
resetVoices()621 void DeicsOnze::resetVoices() {
622 for(int c = 0; c<NBRCHANNELS; c++) initVoices(c);
623 //take care of this if initVoices() changes
624 }
625
626 //---------------------------------------------------------
627 // initVoice
628 //---------------------------------------------------------
initVoice(int c,int v)629 void DeicsOnze::initVoice(int c /*channel*/, int v) {
630 _global.channel[c].voices[v].hasAttractor = false;
631 _global.channel[c].voices[v].isOn = false;
632 _global.channel[c].voices[v].keyOn = false;
633 _global.channel[c].voices[v].isSustained = false;
634 _global.channel[c].voices[v].pitchEnvCoefInct = 1.0;
635 _global.channel[c].voices[v].pitchEnvCoefInctInct = 1.0;
636 _global.channel[c].voices[v].pitchEnvState = OFF_PE;
637
638 }
639 //---------------------------------------------------------
640 // initVoices
641 //---------------------------------------------------------
initVoices(int c)642 void DeicsOnze::initVoices(int c) {
643 for(int v=0; v<MAXNBRVOICES; v++) {
644 initVoice(c, v);
645 _global.channel[c].lastVoiceKeyOn.clear();
646 }
647 }
648
649 //--------------------------------------------------------
650 // findPreset findSubcategory findCategory
651 //--------------------------------------------------------
findPreset(int hbank,int lbank,int prog) const652 Preset* DeicsOnze::findPreset(int hbank, int lbank, int prog) const {
653 return _set->findPreset(hbank, lbank, prog);
654 }
findSubcategory(int hbank,int lbank) const655 Subcategory* DeicsOnze::findSubcategory(int hbank, int lbank) const {
656 return _set->findSubcategory(hbank, lbank);
657 }
findCategory(int hbank) const658 Category* DeicsOnze::findCategory(int hbank) const {
659 return _set->findCategory(hbank);
660 }
661 //---------------------------------------------------------
662 // isPitchEnv
663 // return true iff all levels are in the middle
664 //---------------------------------------------------------
isPitchEnv(PitchEg * pe)665 inline bool isPitchEnv(PitchEg* pe) {
666 return(pe->pl1 != 50 || pe->pl2 != 50 || pe->pl3 != 50);
667 }
668 //---------------------------------------------------------
669 // getPitchEnvCoefInct
670 // returns the coefInct according to level pl
671 //---------------------------------------------------------
getPitchEnvCoefInct(int pl)672 inline double getPitchEnvCoefInct(int pl) {
673 /*
674 pl = 0 <--> -4oct, pl = 50 <--> 0oct, pl = 100 <--> 4oct
675
676 y = a * exp((pl - 50)/b)
677 1.0 = a*exp(0) ==> a = 1.0
678 8.0 = exp(50/b) ==> log 8.0 = 50/b ==> b = 50/log(8.0)
679 */
680 double b = 50.0/log(8.0);
681 return exp((pl-50.0)/b);
682 }
683
684 //---------------------------------------------------------
685 // getPitchEnvCoefInctInct
686 //---------------------------------------------------------
getPitchEnvCoefInctInct(int pl1,int pl2,int pr,double sr)687 inline double getPitchEnvCoefInctInct(int pl1, int pl2, int pr, double sr) {
688 //TODO : depending on the sampleRate
689 int a = pr;
690 double c = 1.0 + COEFPITCHENV*((double)(a*a)+1.0);
691 double inctInct = exp(log(c)*48000.0/sr);
692 if(pl1<pl2) return(inctInct);
693 else if(pl1>pl2)
694 return(1.0/inctInct);
695 else return 1.0;
696 }
697
698 //---------------------------------------------------------
699 // existsKeyOn
700 //---------------------------------------------------------
existsKeyOn(int ch)701 bool DeicsOnze::existsKeyOn(int ch) {
702 return !_global.channel[ch].lastVoiceKeyOn.empty();
703 }
704
705 //---------------------------------------------------------
706 // note2Amp
707 // return the Amp of a note depending on the level scaling
708 //---------------------------------------------------------
note2Amp(double note,int ls)709 inline double note2Amp(double note, int ls)
710 {
711 if(ls==0) return(1.0);
712 else return((note<LEVELSCALENOTE?1.0:exp((double)ls*COEFLEVELSCALE*
713 ((double)LEVELSCALENOTE-note))));
714 }
715
716 //---------------------------------------------------------
717 // delay2Time
718 // return the time in second corresponding to the LFO delay parameter
719 //---------------------------------------------------------
delay2Time(int d)720 inline double delay2Time(int d) {
721 double t;
722 //fitting
723 t=0.07617*(double)d-0.002695*(double)(d*d)+4.214e-05*(double)(d*d*d);
724 //printf("delay2Time : %f\n", t);
725 return(t);
726 }
727
728 //----------------------------------------------------------------
729 // setNbrVoices
730 //----------------------------------------------------------------
setNbrVoices(int c,int nv)731 void DeicsOnze::setNbrVoices(int c, int nv) {
732 nv=(nv>MAXNBRVOICES?MAXNBRVOICES:(nv<1?1:nv));
733 //we assume that any voices
734 //that is not included in the active voices is properly initialized
735 for(int v=nv; v<_global.channel[c].nbrVoices; v++)
736 initVoice(c, v);
737 _global.channel[c].nbrVoices=nv;
738 }
739
740 //----------------------------------------------------------------
741 // setMasterVol
742 //----------------------------------------------------------------
setMasterVol(int mv)743 void DeicsOnze::setMasterVol(int mv) {
744 _global.masterVolume=level2amp(mv); //watch out that MAXMASTERVOLUME==255
745 }
746 //----------------------------------------------------------------
747 // setChannelEnable
748 //----------------------------------------------------------------
setChannelEnable(int c,bool e)749 void DeicsOnze::setChannelEnable(int c, bool e) {
750 _global.channel[c].isEnable = e;
751 setLfo(c);
752 }
753
754 //----------------------------------------------------------------
755 // setChannelVol
756 //----------------------------------------------------------------
setChannelVol(int c,int v)757 void DeicsOnze::setChannelVol(int c, int v) {
758 _global.channel[c].volume = v;
759 }
760
applyChannelAmp(int c)761 void DeicsOnze::applyChannelAmp(int c) {
762 _global.channel[c].ampLeft =
763 level2amp(_global.channel[c].volume)
764 * ((double)(MAXCHANNELPAN - _global.channel[c].pan)
765 /(double)(2*MAXCHANNELPAN));
766 _global.channel[c].ampRight =
767 level2amp(_global.channel[c].volume)
768 * ((double)(MAXCHANNELPAN + _global.channel[c].pan)
769 /(double)(2*MAXCHANNELPAN));
770 }
771
772 //----------------------------------------------------------------
773 // setChannelPan
774 //----------------------------------------------------------------
setChannelPan(int c,int p)775 void DeicsOnze::setChannelPan(int c, int p) {
776 _global.channel[c].pan = p;
777 }
778 //----------------------------------------------------------------
779 // setChannelDetune
780 //----------------------------------------------------------------
setChannelDetune(int c,int p)781 void DeicsOnze::setChannelDetune(int c, int p) {
782 _global.channel[c].detune = p;
783 }
784 //----------------------------------------------------------------
785 // setChannelBrightness
786 //----------------------------------------------------------------
setChannelBrightness(int c,int b)787 void DeicsOnze::setChannelBrightness(int c, int b) {
788 _global.channel[c].brightness = b;
789 }
790 //----------------------------------------------------------------
791 // setChannelModulation
792 //----------------------------------------------------------------
setChannelModulation(int c,int m)793 void DeicsOnze::setChannelModulation(int c, int m) {
794 _global.channel[c].modulation = m;
795 }
796 //----------------------------------------------------------------
797 // setChannelAttack
798 //----------------------------------------------------------------
setChannelAttack(int c,int a)799 void DeicsOnze::setChannelAttack(int c, int a) {
800 _global.channel[c].attack = a;
801 }
802 //----------------------------------------------------------------
803 // setChannelRelease
804 //----------------------------------------------------------------
setChannelRelease(int c,int r)805 void DeicsOnze::setChannelRelease(int c, int r) {
806 _global.channel[c].release = r;
807 }
808 //----------------------------------------------------------------
809 // setChannelReverb
810 //----------------------------------------------------------------
setChannelReverb(int c,int r)811 void DeicsOnze::setChannelReverb(int c, int r) {
812 _global.channel[c].reverbAmount = (float)lowlevel2amp(r);
813 }
814 //----------------------------------------------------------------
815 // setChannelChorus
816 //----------------------------------------------------------------
setChannelChorus(int c,int val)817 void DeicsOnze::setChannelChorus(int c, int val) {
818 _global.channel[c].chorusAmount = (float)lowlevel2amp(val);
819 }
820 //----------------------------------------------------------------
821 // setChannelDelay
822 //----------------------------------------------------------------
setChannelDelay(int c,int val)823 void DeicsOnze::setChannelDelay(int c, int val) {
824 _global.channel[c].delayAmount = (float)lowlevel2amp(val);
825 }
826
827 //----------------------------------------------------------------
828 // setChorusReturn
829 //----------------------------------------------------------------
setChorusReturn(int val)830 void DeicsOnze::setChorusReturn(int val) {
831 _global.chorusReturn = 2.0*(float)level2amp(val); //beware MAXFXRETURN==255
832 }
833
834 //----------------------------------------------------------------
835 // setReverbReturn
836 //----------------------------------------------------------------
setReverbReturn(int val)837 void DeicsOnze::setReverbReturn(int val) {
838 _global.reverbReturn = 2.0*(float)level2amp(val); //beware MAXFXRETURN==255
839 }
840
841 //----------------------------------------------------------------
842 // setDelayReturn
843 //----------------------------------------------------------------
setDelayReturn(int val)844 void DeicsOnze::setDelayReturn(int val) {
845 _global.delayReturn = 2.0*(float)level2amp(val); //beware MAXFXRETURN==255
846 }
847
848 //----------------------------------------------------------------
849 // getNbrVoices
850 //----------------------------------------------------------------
getNbrVoices(int c) const851 int DeicsOnze::getNbrVoices(int c) const {
852 return(_global.channel[c].nbrVoices);
853 }
854 //----------------------------------------------------------------
855 // getMasterVol
856 //----------------------------------------------------------------
getMasterVol(void) const857 int DeicsOnze::getMasterVol(void) const {
858 return(amp2level(_global.masterVolume));
859 }
860 //----------------------------------------------------------------
861 // getFilter
862 //----------------------------------------------------------------
getFilter(void) const863 bool DeicsOnze::getFilter(void) const {
864 return _global.filter;
865 }
866 //----------------------------------------------------------------
867 // getChannelEnable
868 //----------------------------------------------------------------
getChannelEnable(int c) const869 bool DeicsOnze::getChannelEnable(int c) const {
870 return _global.channel[c].isEnable;
871 }
872
873 //----------------------------------------------------------------
874 // getChannelVol
875 //----------------------------------------------------------------
getChannelVol(int c) const876 int DeicsOnze::getChannelVol(int c) const { //TODO : to see if correct
877 //return((int)(MAX(_global.channel[c].ampLeft, _global.channel[c].ampRight)
878 //*(double)MAXCHANNELVOLUME));
879 return(_global.channel[c].volume);
880 }
881 //----------------------------------------------------------------
882 // getChannelPan
883 //----------------------------------------------------------------
getChannelPan(int c) const884 int DeicsOnze::getChannelPan(int c) const {
885 return(_global.channel[c].pan);
886 }
887 //----------------------------------------------------------------
888 // setChannelDetune
889 //----------------------------------------------------------------
getChannelDetune(int c) const890 int DeicsOnze::getChannelDetune(int c) const {
891 return _global.channel[c].detune;
892 }
893 //----------------------------------------------------------------
894 // getChannelBrightness
895 //----------------------------------------------------------------
getChannelBrightness(int c) const896 int DeicsOnze::getChannelBrightness(int c) const {
897 return(_global.channel[c].brightness);
898 }
899 //----------------------------------------------------------------
900 // getChannelModulation
901 //----------------------------------------------------------------
getChannelModulation(int c) const902 int DeicsOnze::getChannelModulation(int c) const {
903 return(_global.channel[c].modulation);
904 }
905 //----------------------------------------------------------------
906 // getChannelAttack
907 //----------------------------------------------------------------
getChannelAttack(int c) const908 int DeicsOnze::getChannelAttack(int c) const {
909 return(_global.channel[c].attack);
910 }
911 //----------------------------------------------------------------
912 // getChannelRelease
913 //----------------------------------------------------------------
getChannelRelease(int c) const914 int DeicsOnze::getChannelRelease(int c) const {
915 return(_global.channel[c].release);
916 }
917 //----------------------------------------------------------------
918 // getChannelReverb
919 //----------------------------------------------------------------
getChannelReverb(int c) const920 int DeicsOnze::getChannelReverb(int c) const {
921 return(amp2lowlevel(_global.channel[c].reverbAmount));
922 }
923 //----------------------------------------------------------------
924 // getChannelChorus
925 //----------------------------------------------------------------
getChannelChorus(int c) const926 int DeicsOnze::getChannelChorus(int c) const {
927 return(amp2lowlevel(_global.channel[c].chorusAmount));
928 }
929 //----------------------------------------------------------------
930 // getChannelDelay
931 //----------------------------------------------------------------
getChannelDelay(int c) const932 int DeicsOnze::getChannelDelay(int c) const {
933 return(amp2lowlevel(_global.channel[c].delayAmount));
934 }
935 //----------------------------------------------------------------
936 // getChorusReturn
937 //----------------------------------------------------------------
getChorusReturn() const938 int DeicsOnze::getChorusReturn() const {
939 return(amp2level(_global.chorusReturn/2.0));
940 }
941 //----------------------------------------------------------------
942 // getReverbReturn
943 //----------------------------------------------------------------
getReverbReturn() const944 int DeicsOnze::getReverbReturn() const {
945 return(amp2level(_global.reverbReturn/2.0));
946 }
947 //----------------------------------------------------------------
948 // getReverbReturn
949 //----------------------------------------------------------------
getDelayReturn() const950 int DeicsOnze::getDelayReturn() const {
951 return(amp2level(_global.delayReturn/2.0));
952 }
953
954 //----------------------------------------------------------------
955 // setLfo
956 //----------------------------------------------------------------
setLfo(int c)957 void DeicsOnze::setLfo(int c/*channel*/)
958 {
959 double x;
960 x=(double)_preset[c]->lfo.speed;
961 // lfoSpeed to Hz, obtained by fitting the actual curve by a polynomial
962 _global.channel[c].lfoFreq =
963 -1.9389e-08*x*x*x*x*x+2.8826e-06*x*x*x*x-9.0316e-05*x*x*x
964 +4.7453e-03*x*x-1.2295e-02*x+7.0347e-02;//a revoir
965 //Pitch LFO
966 _global.channel[c].lfoMaxIndex =
967 (_global.channel[c].lfoFreq==0?0:(int)((1.0/_global.channel[c].lfoFreq)
968 *(double)_global.deiSampleRate));
969 double totalpDepth =
970 ((double)_preset[c]->lfo.pModDepth +
971 (((double)_global.channel[c].modulation)/127.0)
972 * ((double)(MAXPMODDEPTH - _preset[c]->lfo.pModDepth))
973 )/(double)MAXPMODDEPTH;
974 _global.channel[c].lfoPitch =
975 totalpDepth * (COEFPLFO(_preset[c]->sensitivity.pitch));
976 //Amplitude LFO
977 double totalaDepth =
978 ((double)_preset[c]->lfo.aModDepth +
979 (((double)_global.channel[c].modulation)/127.0)
980 * ((double)(MAXAMODDEPTH - _preset[c]->lfo.aModDepth))
981 )/(double)MAXAMODDEPTH;
982 _global.channel[c].lfoMaxAmp =
983 totalaDepth * (COEFALFO(_preset[c]->sensitivity.amplitude));
984 //index is considered on the half of the frequency of the LFO
985 _global.channel[c].lfoDelayMaxIndex =
986 delay2Time(_preset[c]->lfo.delay)*_global.channel[c].lfoFreq*2;
987 _global.channel[c].lfoDelayInct =
988 (double)(RESOLUTION/4)/_global.channel[c].lfoDelayMaxIndex;
989
990 //update the actuall values controlling the modulation now
991 if(_global.channel[c].lfoDelayIndex<(double)(RESOLUTION/4)) {
992 double delayCoef =
993 (double)waveTable[W2][(int)_global.channel[c].lfoDelayIndex];
994 _global.channel[c].lfoMaxCoefInct =
995 exp((log(2.0)/12.0)*_global.channel[c].lfoPitch*delayCoef);
996 _global.channel[c].lfoCoefInctInct =
997 exp((log(2.0)/12.0)*((2*_global.channel[c].lfoPitch*delayCoef)
998 /_global.channel[c].lfoMaxIndex));
999 _global.channel[c].lfoMaxDAmp = delayCoef*_global.channel[c].lfoMaxAmp;
1000 }
1001 else
1002 if(_global.channel[c].delayPassed) {
1003 _global.channel[c].lfoMaxCoefInct =
1004 exp((log(2.0)/12.0)*_global.channel[c].lfoPitch);
1005 _global.channel[c].lfoCoefInctInct=
1006 exp((log(2.0)/12.0)*((2*_global.channel[c].lfoPitch)
1007 /_global.channel[c].lfoMaxIndex));
1008 _global.channel[c].lfoMaxDAmp=_global.channel[c].lfoMaxAmp;
1009 }
1010 }
1011
1012 //-----------------------------------------------------------------
1013 // setOutLevel
1014 //-----------------------------------------------------------------
setOutLevel(int c,int k)1015 void DeicsOnze::setOutLevel(int c, int k) {
1016 for(int v=0; v<_global.channel[c].nbrVoices; v++) {
1017 if(_global.channel[c].voices[v].op[k].envState!=OFF) {
1018 _global.channel[c].voices[v].op[k].amp =
1019 outLevel2Amp(_preset[c]->outLevel[k])
1020 * _global.channel[c].voices[v].op[k].ampVeloNote
1021 * brightness2Amp(c, k);
1022 }
1023 }
1024 }
setOutLevel(int c)1025 void DeicsOnze::setOutLevel(int c) {
1026 for(int k=0; k<NBROP; k++) {
1027 setOutLevel(c, k);
1028 }
1029 }
1030 //-----------------------------------------------------------------
1031 // setEnvAttack
1032 //-----------------------------------------------------------------
setEnvAttack(int c,int v,int k)1033 void DeicsOnze::setEnvAttack(int c, int v, int k) {
1034 if(_global.channel[c].voices[v].op[k].envState==ATTACK)
1035 _global.channel[c].voices[v].op[k].envInct=
1036 (_preset[c]->eg[k].ar==0?0:
1037 (double)(RESOLUTION/4)/(envAR2s(_preset[c]->eg[k].ar)
1038 *_global.deiSampleRate))
1039 *coefAttack(_global.channel[c].attack);
1040 }
setEnvAttack(int c,int k)1041 void DeicsOnze::setEnvAttack(int c, int k) {
1042 for(int v=0; v<_global.channel[c].nbrVoices; v++) setEnvAttack(c, v, k);
1043 }
setEnvAttack(int c)1044 void DeicsOnze::setEnvAttack(int c) {
1045 for(int k=0; k<NBROP; k++) setEnvAttack(c, k);
1046 }
1047 //-----------------------------------------------------------------
1048 // setEnvRelease
1049 //-----------------------------------------------------------------
setEnvRelease(int c,int v,int k)1050 void DeicsOnze::setEnvRelease(int c, int v, int k) {
1051 if(_global.channel[c].voices[v].op[k].envState==RELEASE)
1052 _global.channel[c].voices[v].op[k].coefVLevel =
1053 envRR2coef(_preset[c]->eg[k].rr, _global.deiSampleRate,
1054 _global.channel[c].release);
1055 }
setEnvRelease(int c,int k)1056 void DeicsOnze::setEnvRelease(int c, int k) {
1057 for(int v=0; v<_global.channel[c].nbrVoices; v++) setEnvRelease(c, v, k);
1058 }
setEnvRelease(int c)1059 void DeicsOnze::setEnvRelease(int c) {
1060 for(int k=0; k<NBROP; k++) setEnvRelease(c, k);
1061 }
1062 //-----------------------------------------------------------------
1063 // setPitchEnvRelease
1064 //-----------------------------------------------------------------
setPitchEnvRelease(int c,int v)1065 void DeicsOnze::setPitchEnvRelease(int c, int v) {
1066 if(isPitchEnv(&_preset[c]->pitchEg)) {
1067 if(_global.channel[c].voices[v].pitchEnvCoefInct
1068 > _global.channel[c].voices[v].pitchEnvCoefInctPhase1) {
1069 _global.channel[c].voices[v].pitchEnvCoefInctInct =
1070 getPitchEnvCoefInctInct(1, 0, _preset[c]->pitchEg.pr3,
1071 _global.deiSampleRate);
1072 _global.channel[c].voices[v].pitchEnvState = RELEASE_PE;
1073 }
1074 else if(_global.channel[c].voices[v].pitchEnvCoefInct
1075 < _global.channel[c].voices[v].pitchEnvCoefInctPhase1) {
1076 _global.channel[c].voices[v].pitchEnvCoefInctInct =
1077 getPitchEnvCoefInctInct(0, 1, _preset[c]->pitchEg.pr3,
1078 _global.deiSampleRate);
1079 _global.channel[c].voices[v].pitchEnvState = RELEASE_PE;
1080 }
1081 else {
1082 _global.channel[c].voices[v].pitchEnvCoefInctInct = 1.0;
1083 _global.channel[c].voices[v].pitchEnvState = OFF_PE;
1084 }
1085 }
1086 }
1087
1088 //-----------------------------------------------------------------
1089 // setQuality
1090 //-----------------------------------------------------------------
setQuality(Quality q)1091 void DeicsOnze::setQuality(Quality q) {
1092 _global.quality = q;
1093 switch(q) {
1094 case high :
1095 _global.qualityCounterTop = 1;
1096 break;
1097 case middle :
1098 _global.qualityCounterTop = 2;
1099 break;
1100 case low :
1101 _global.qualityCounterTop = 4;
1102 break;
1103 case ultralow :
1104 _global.qualityCounterTop = 6;
1105 break;
1106 default : printf("Error switch setQuality : out of value\n");
1107 break;
1108 }
1109 //calculate _global.deiSampleRate
1110 _global.deiSampleRate = (double)sampleRate()
1111 / (double)_global.qualityCounterTop;
1112 _global.qualityCounter = 0;
1113 //update lfo to consider the new samplerate
1114 for(int c = 0; c < 16; c++) if(_global.channel[c].isEnable) setLfo(c);
1115 //update the cutoffs of the filters
1116 _dryFilter->setCutoff(_global.deiSampleRate/4.0);
1117 _reverbFilter->setCutoff(_global.deiSampleRate/4.0);
1118 _chorusFilter->setCutoff(_global.deiSampleRate/4.0);
1119 _delayFilter->setCutoff(_global.deiSampleRate/4.0);
1120 }
1121
1122 //-----------------------------------------------------------------
1123 // setFilter
1124 //-----------------------------------------------------------------
setFilter(bool f)1125 void DeicsOnze::setFilter(bool f) {
1126 _global.filter = f;
1127 }
1128 //-----------------------------------------------------------------
1129 // brightness2Amp
1130 //-----------------------------------------------------------------
brightness2Amp(int c,int k)1131 double DeicsOnze::brightness2Amp(int c, int k) {
1132 if(
1133 (k==1 && (_preset[c]->algorithm!=SIXTH || _preset[c]->algorithm!=SEVENTH
1134 || _preset[c]->algorithm!=EIGHTH))
1135 ||
1136 (k==2 && (_preset[c]->algorithm==FIRST || _preset[c]->algorithm==SECOND
1137 || _preset[c]->algorithm==THIRD || _preset[c]->algorithm==FOURTH))
1138 ||
1139 (k==3 && (_preset[c]->algorithm!=EIGHTH))
1140 ) {
1141 double x = 2.0*(double)_global.channel[c].brightness
1142 / (double)MAXFINEBRIGHTNESS;
1143 double square_x = x*x;
1144 return(square_x*x);
1145 }
1146 else return(1.0);
1147 }
1148 //-----------------------------------------------------------------
1149 // setFeedback
1150 //-----------------------------------------------------------------
setFeedback(int c)1151 void DeicsOnze::setFeedback(int c) {
1152 _global.channel[c].feedbackAmp =
1153 COEFFEEDBACK*exp(log(2)*(double)(_preset[c]->feedback-MAXFEEDBACK));
1154 }
1155
1156 //-----------------------------------------------------------------
1157 // setPreset
1158 //-----------------------------------------------------------------
1159
setPreset(int c)1160 void DeicsOnze::setPreset(int c) {
1161 setFeedback(c);
1162 setLfo(c);
1163 setEnvAttack(c);
1164 setEnvRelease(c);
1165 setOutLevel(c);
1166 }
1167
1168
coarseFine2Ratio(int c,int f)1169 inline double coarseFine2Ratio(int c,int f) {
1170 double tab[64][16]=
1171 {
1172 {0.50,0.56,0.62,0.68,0.75,0.81,0.87,0.93,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0},
1173 {0.71,0.79,0.88,0.96,1.05,1.14,1.23,1.32,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0},
1174 {0.78,0.88,0.98,1.07,1.17,1.27,1.37,1.47,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0},
1175 {0.87,0.97,1.08,1.18,1.29,1.40,1.51,1.62,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0},
1176 {1.00,1.06,1.12,1.18,1.25,1.31,1.37,1.43,1.50,1.56,1.62,1.68,1.75,1.81,1.87,1.93},
1177 {1.41,1.49,1.58,1.67,1.76,1.85,1.93,2.02,2.11,2.20,2.29,2.37,2.46,2.55,2.64,2.73},
1178 {1.57,1.66,1.76,1.86,1.96,2.06,2.15,2.25,2.35,2.45,2.55,2.64,2.74,2.84,2.94,3.04},
1179 {1.73,1.83,1.94,2.05,2.16,2.27,2.37,2.48,2.59,2.70,2.81,2.91,3.02,3.13,3.24,3.35},
1180 {2.00,2.06,2.12,2.18,2.25,2.31,2.37,2.43,2.50,2.56,2.62,2.68,2.75,2.81,2.87,2.93},
1181 {2.82,2.90,2.99,3.08,3.17,3.26,3.34,3.43,3.52,3.61,3.70,3.78,3.87,3.96,4.05,3.14},
1182 {3.00,3.06,3.12,3.18,3.25,3.31,3.37,3.43,3.50,3.56,3.62,3.68,3.75,3.81,3.87,3.93} ,
1183 {3.14,3.23,3.33,3.43,3.53,3.63,3.72,3.82,3.92,4.02,4.12,4.21,4.31,4.41,4.51,4.61},
1184 {3.46,3.56,3.67,3.78,3.89,4.00,4.10,4.21,4.32,4.43,4.54,4.64,4.75,4.86,4.97,5.08},
1185 {4.00,4.06,4.12,4.18,4.25,4.31,4.37,4.43,4.50,4.56,4.62,4.68,4.75,4.81,4.87,4.93},
1186 {4.24,4.31,4.40,4.49,4.58,4.67,4.75,4.84,4.93,5.02,5.11,5.19,5.28,5.37,5.46,5.55},
1187 {4.71,4.80,4.90,5.00,5.10,5.20,5.29,5.39,5.49,5.59,5.69,5.78,5.88,5.98,6.08,6.18},
1188 {5.00,5.06,5.12,5.18,5.25,5.31,5.37,5.43,5.50,5.56,5.62,5.68,5.75,5.81,5.87,5.93},
1189 {5.19,5.29,5.40,5.51,5.62,5.73,5.83,5.94,6.05,6.16,6.27,6.37,6.48,6.59,6.70,6.81},
1190 {5.65,5.72,5.81,5.90,5.99,6.08,6.16,6.25,6.34,6.43,6.52,6.60,6.69,6.78,6.87,6.96},
1191 {6.00,6.06,6.12,6.18,6.25,6.31,6.37,6.43,6.50,6.56,6.62,6.68,6.75,6.81,6.87,6.93},
1192 {6.28,6.37,6.47,6.57,6.67,6.77,6.86,6.96,7.06,7.16,7.26,7.35,7.45,7.55,7.65,7.75},
1193 {6.92,7.02,7.13,7.24,7.35,7.46,7.56,7.67,7.78,7.89,8.00,8.10,8.21,8.32,8.43,8.54},
1194 {7.00,7.06,7.12,7.18,7.25,7.31,7.37,7.43,7.50,7.56,7.62,7.68,7.75,7.81,7.87,7.93},
1195 {7.07,7.13,7.22,7.31,7.40,7.49,7.57,7.66,7.75,7.84,7.93,8.01,8.10,8.19,8.28,8.37},
1196 {7.85,7.94,8.04,8.14,8.24,8.34,8.43,8.53,8.63,8.73,8.83,8.92,9.02,9.12,9.22,9.32},
1197 {8.00,8.06,8.12,8.18,8.25,8.31,8.37,8.43,8.50,8.56,8.62,8.68,8.75,8.81,8.87,8.93},
1198 {8.48,8.54,8.63,8.72,8.81,8.90,8.98,9.07,9.16,9.25,9.34,9.42,9.51,9.60,9.69,9.78},
1199 {8.65,8.75,8.86,8.97,9.08,9.19,9.29,9.40,9.51,9.62,9.73,9.83,9.94,10.05,10.16,10.27},
1200 {9.00,9.06,9.12,9.18,9.25,9.31,9.37,9.43,9.50,9.56,9.62,9.68,9.75,9.81,9.87,9.93},
1201 {9.42,9.51,9.61,9.71,9.81,9.91,10.00,10.10,10.20,10.30,10.40,10.49,10.59,10.69,10.79,10.89},
1202 {9.89,9.95,10.04,10.13,10.22,10.31,10.39,10.48,10.57,10.66,10.75,10.83,10.92,11.01,11.10,11.19},
1203 {10.00,10.06,10.12,10.18,10.25,10.31,10.37,10.43,10.50,10.56,10.62,10.68,10.75,10.81,10.87,10.93},
1204 {10.38,10.48,10.59,10.70,10.81,10.92,11.02,11.13,11.24,11.35,11.46,11.56,11.67,11.78,11.89,12.00},
1205 {10.99,11.08,11.18,11.28,11.38,11.48,11.57,11.67,11.77,11.87,11.97,12.06,12.16,12.26,12.36,12.46},
1206 {11.00,11.06,11.12,11.18,11.25,11.31,11.37,11.43,11.50,11.56,11.62,11.68,11.75,11.81,11.87,11.93},
1207 {11.30,11.36,11.45,11.54,11.63,11.72,11.80,11.89,11.98,12.07,12.16,12.24,12.33,12.42,12.51,12.60},
1208 {12.00,12.06,12.12,12.18,12.25,12.31,12.37,12.43,12.50,12.56,12.62,12.68,12.75,12.81,12.87,12.93},
1209 {12.11,12.21,12.32,12.43,12.54,12.65,12.75,12.86,12.97,13.08,13.19,13.29,13.40,13.51,13.62,13.73},
1210 {12.56,12.65,12.75,12.85,12.95,13.05,13.14,13.24,13.34,13.44,13.54,13.63,13.73,13.83,13.93,14.03},
1211 {12.72,12.77,12.86,12.95,13.04,13.13,13.21,13.30,13.39,13.48,13.57,13.65,13.74,13.83,13.92,14.01},
1212 {13.00,13.06,13.12,13.18,13.25,13.31,13.37,13.43,13.50,13.56,13.62,13.68,13.75,13.81,13.87,13.93},
1213 {13.84,13.94,14.05,14.16,14.27,14.38,14.48,14.59,14.70,14.81,14.92,15.02,15.13,15.24,15.35,15.46},
1214 {14.00,14.06,14.12,14.18,14.25,14.31,14.37,14.43,14.50,14.56,14.62,14.68,14.75,14.81,14.87,14.93},
1215 {14.10,14.18,14.27,14.36,14.45,14.54,14.62,14.71,14.80,14.89,14.98,15.06,15.15,15.24,15.33,15.42},
1216 {14.13,14.22,14.32,14.42,14.52,14.62,14.71,14.81,14.91,15.01,15.11,15.20,15.30,15.40,15.50,15.60},
1217 {15.00,15.06,15.12,15.18,15.25,15.31,15.37,15.43,15.50,15.56,15.62,15.68,15.75,15.81,15.87,15.93},
1218 {15.55,15.59,15.68,15.77,15.86,15.95,16.03,16.12,16.21,16.30,16.39,16.47,16.56,16.65,16.74,16.83},
1219 {15.57,15.67,15.78,15.89,16.00,16.11,16.21,16.32,16.43,16.54,16.65,16.75,16.86,16.97,17.08,17.19},
1220 {15.70,15.79,15.89,15.99,16.09,16.19,16.28,16.38,16.48,16.58,16.68,16.77,16.87,16.97,17.07,17.17},
1221 {16.96,17.00,17.09,17.18,17.27,17.36,17.44,17.53,17.62,17.71,17.80,17.88,17.97,18.06,18.15,18.24},
1222 {17.27,17.36,17.46,17.56,17.66,17.76,17.85,17.95,18.05,18.15,18.25,18.34,18.44,18.54,18.64,18.74},
1223 {17.30,17.40,17.51,17.62,17.73,17.84,17.94,18.05,18.16,18.27,18.38,18.48,18.59,18.70,18.81,18.92},
1224 {18.37,18.41,18.50,18.59,18.68,18.77,18.85,18.94,19.03,19.12,19.21,19.29,19.38,19.47,19.56,19.65},
1225 {18.84,18.93,19.03,19.13,19.23,19.33,19.42,19.52,19.62,19.72,19.82,19.91,20.01,20.11,20.21,20.31},
1226 {19.03,19.13,19.24,19.35,19.46,19.57,19.67,19.78,19.89,20.00,20.11,20.21,20.32,20.43,20.54,20.65},
1227 {19.78,19.82,19.91,20.00,20.09,20.18,20.26,20.35,20.44,20.53,20.62,20.70,20.79,20.88,20.97,21.06},
1228 {20.41,20.50,20.60,20.70,20.80,20.90,20.99,21.09,21.19,21.29,21.39,21.48,21.58,21.68,21.78,21.88},
1229 {20.76,20.86,20.97,21.08,21.19,21.30,21.40,21.51,21.62,21.73,21.84,21.94,22.05,22.16,22.27,22.38},
1230 {21.20,21.23,21.32,21.41,21.50,21.59,21.67,21.76,21.85,21.94,22.03,22.11,22.20,22.29,22.38,22.47},
1231 {21.98,22.07,22.17,22.17,22.37,22.47,22.56,22.66,22.76,22.86,22.96,23.05,23.15,23.25,23.35,23.45},
1232 {22.49,22.59,22.70,22.81,22.92,23.03,23.13,13.24,13.35,13.46,13.57,13.67,13.78,13.89,24.00,24.11},
1233 {23.55,23.64,23.74,23.84,23.94,24.04,24.13,24.23,24.33,24.43,24.53,24.62,24.72,24.82,24.92,25.02},
1234 {24.22,24.32,24.43,24.54,24.65,24.76,24.86,24.97,25.08,25.19,25.30,25.40,25.51,25.62,25.73,25.84},
1235 {25.95,26.05,26.16,26.27,26.38,26.49,26.59,26.70,26.81,26.92,27.03,27.13,27.24,27.35,27.46,27.57}
1236 };
1237 return(tab[c][f]);
1238 }
1239
1240 //---------------------------------------------------------------
1241 // loadSet
1242 //---------------------------------------------------------------
loadSet(QString fileName)1243 void DeicsOnze::loadSet(QString fileName) {
1244 // read the XML file and create DOM tree
1245 if(!fileName.isEmpty()) {
1246 QFile deicsonzeFile(fileName);
1247 if(!deicsonzeFile.open(QIODevice::ReadOnly)) {
1248 printf("Critical Error Cannot open file %s\n",
1249 fileName.toLatin1().data());
1250 return;
1251 }
1252 QDomDocument domTree;
1253 if (!domTree.setContent(&deicsonzeFile )) {
1254 printf("Critical Error Parsing error for file %s\n",
1255 fileName.toLatin1().data());
1256 deicsonzeFile.close();
1257 return;
1258 }
1259 deicsonzeFile.close();
1260
1261 QDomNode node = domTree.documentElement();
1262 while (!node.isNull()) {
1263 QDomElement e = node.toElement();
1264 if (e.isNull())
1265 continue;
1266 if (e.tagName() == "deicsOnzeSet") {
1267 QString version = e.attribute(QString("version"));
1268 if (version == "1.0") {
1269 for(int c = 0; c<NBRCHANNELS; c++) _preset[c]=_initialPreset;
1270 while(!_set->_categoryVector.empty())
1271 delete(*_set->_categoryVector.begin());
1272 _set->readSet(node.firstChild());
1273 //display load preset
1274 unsigned char dataUpdateGuiSet[1];
1275 dataUpdateGuiSet[0]=SYSEX_UPDATESETGUI;
1276 MusECore::MidiPlayEvent evSysexUpdateGuiSet(0, 0, MusECore::ME_SYSEX,
1277 (const unsigned char*)dataUpdateGuiSet,
1278 1);
1279 _gui->writeEvent(evSysexUpdateGuiSet);
1280 }
1281 else printf("unsupported *.dei file version %s\n",
1282 version.toLatin1().constData());
1283 }
1284 else printf("DeicsOnze: %s not supported\n",
1285 e.tagName().toLatin1().constData());
1286 node = node.nextSibling();
1287 }
1288 }
1289 }
1290 //---------------------------------------------------------------
1291 // loadSutulaPreset
1292 //---------------------------------------------------------------
1293
loadSutulaPresets()1294 void DeicsOnze::loadSutulaPresets()
1295 {
1296 FILE* file;
1297 int v;
1298 int crs[NBROP], fin[NBROP]; //coarse ratio, fine ratio
1299 char s[500];
1300 char sname[LENGTHNAME+1];
1301 char scategory[LENGTHCATEGORY+1];
1302 char ssubcategory[LENGTHSUBCATEGORY+1];
1303 int k;
1304 int nhBank, nlBank, nPreset;
1305 Preset* presetTemp;
1306 Subcategory* subcategoryTemp = NULL;
1307 Category* categoryTemp = NULL;
1308
1309 if(!_set) _set=new Set("Sutula Bank");
1310
1311 nhBank=0;
1312 nlBank=0;
1313 nPreset=0;
1314
1315 //QString presetPath(INSTPREFIX);
1316 //presetPath += "/share/" PACKAGEVERSION "/presets/deicsonze/ARCH_ALIN";
1317
1318 QString presetPath("/home/a-lin/sources/svnMusEDev/lmuse/muse/synti/deicsonze/ARCH_ALIN");
1319
1320 file = fopen (presetPath.toLatin1().constData(), "rt");
1321 if (file == NULL) {
1322 printf("can't open ");
1323 printf("%s", presetPath.toLatin1().constData());
1324 printf("\n");
1325 }
1326 else
1327 {
1328 while(fgets(s, 500, file) && !strstr(s, "** Source:"))
1329 {
1330 if (strstr(s,"* CATEGORY"))
1331 {
1332 sscanf(s, "* CATEGORY %s", scategory);
1333 categoryTemp=new Category(_set, scategory,0);
1334 }
1335 if (strstr(s,"* SUBCATEGORY"))
1336 {
1337 sscanf(s, "* SUBCATEGORY %s", ssubcategory);
1338 subcategoryTemp=new Subcategory(categoryTemp,ssubcategory,0);
1339 nlBank++;
1340 }
1341 }
1342 while(!feof(file))
1343 {
1344
1345 presetTemp=new Preset(subcategoryTemp);
1346 // Fill the preset
1347 //OP.4 to OP.1
1348 for(int kaka=(NBROP-1); kaka>=0; kaka--)
1349 {
1350 k=(kaka==2?1:(kaka==1?2:kaka));
1351
1352 fscanf(file, "%x", &v);//0
1353 presetTemp->eg[k].ar=v;
1354 fscanf(file, "%x", &v);//1
1355 presetTemp->eg[k].d1r=v;
1356 fscanf(file, "%x", &v);//2
1357 presetTemp->eg[k].d2r=v;
1358 fscanf(file, "%x", &v);//3
1359 presetTemp->eg[k].rr=v;
1360 fscanf(file, "%x", &v);//4
1361 presetTemp->eg[k].d1l=v;
1362 fscanf(file, "%x", &v);//5
1363 presetTemp->scaling.level[k]=v;
1364 fscanf(file, "%x", &v);//6
1365 presetTemp->sensitivity.keyVelocity[k]=
1366 v & 0x7;
1367 presetTemp->sensitivity.egBias[k]=
1368 (v & 0x38)>>3;
1369 presetTemp->sensitivity.ampOn[k]=
1370 (v & 0x40)>>6;
1371 fscanf(file, "%x", &v);//7
1372 presetTemp->outLevel[k]=v;
1373 fscanf(file, "%x", &v);//8
1374 crs[k]=v;
1375 fscanf(file, "%x", &v);//9
1376 presetTemp->detune[k]=(v & 0x7)-3;
1377 presetTemp->scaling.rate[k]=(v & 0x18)>>3;
1378 }
1379 fscanf(file, "%x", &v);//40
1380 presetTemp->algorithm=
1381 ((v & 0x7)==0?FIRST:
1382 ((v & 0x7)==1?SECOND:
1383 ((v & 0x7)==2?THIRD:
1384 ((v & 0x7)==3?FOURTH:
1385 ((v & 0x7)==4?FIFTH:
1386 ((v & 0x7)==5?SIXTH:
1387 ((v & 0x7)==6?SEVENTH:EIGHTH)))))));
1388 presetTemp->feedback=(v & 0x38)>>3;
1389 presetTemp->lfo.sync=(v & 0x40)>>6;
1390 fscanf(file, "%x", &v);//41
1391 presetTemp->lfo.speed=v;
1392 fscanf(file, "%x", &v);//42
1393 presetTemp->lfo.delay=v;
1394 fscanf(file, "%x", &v);//43
1395 presetTemp->lfo.pModDepth=v;
1396 fscanf(file, "%x", &v);//44
1397 presetTemp->lfo.aModDepth=v;
1398 fscanf(file, "%x", &v);//45
1399 presetTemp->lfo.wave=
1400 ((v & 0x3)==0?SAWUP:
1401 ((v & 0x3)==1?SQUARE:
1402 ((v & 0x3)==2?TRIANGL:SHOLD)));
1403 presetTemp->sensitivity.amplitude=(v & 0xc)>>2;
1404 presetTemp->sensitivity.pitch=(v & 0x70)>>4;
1405 fscanf(file, "%x", &v);//46
1406 presetTemp->function.transpose=v-24;
1407 fscanf(file, "%x", &v);//47
1408 presetTemp->function.pBendRange=v;
1409 fscanf(file, "%x", &v);//48
1410 presetTemp->function.portamento=
1411 ((v & 0x1)==0?FULL:FINGER);
1412 presetTemp->function.footSw=
1413 ((v & 0x4)==0?SUS:POR);
1414 presetTemp->function.mode=
1415 ((v & 0x8)==0?POLY:MONO);
1416 fscanf(file, "%x", &v);//49
1417 presetTemp->function.portamentoTime=v;
1418 fscanf(file, "%x", &v);//50
1419 presetTemp->function.fcVolume=v;
1420 fscanf(file, "%x", &v);//51
1421 presetTemp->function.mwPitch=v;
1422 fscanf(file, "%x", &v);//52
1423 presetTemp->function.mwAmplitude=v;
1424 fscanf(file, "%x", &v);//53
1425 presetTemp->function.bcPitch=v;
1426 fscanf(file, "%x", &v);//54
1427 presetTemp->function.bcAmplitude=v;
1428 fscanf(file, "%x", &v);//55
1429 presetTemp->function.bcPitchBias=v;
1430 fscanf(file, "%x", &v);//56
1431 presetTemp->function.bcEgBias=v;
1432 for(int l=0; l<10; l++)
1433 {
1434 fscanf(file, "%x", &v);//57 to 66
1435 sname[l]=(char)v;
1436 }
1437 sname[10]='\0';
1438 presetTemp->name=sname;
1439 fscanf(file, "%x", &v);//67
1440 presetTemp->pitchEg.pr1=v;
1441 fscanf(file, "%x", &v);//68
1442 presetTemp->pitchEg.pr2=v;
1443 fscanf(file, "%x", &v);//69
1444 presetTemp->pitchEg.pr3=v;
1445 fscanf(file, "%x", &v);//70
1446 presetTemp->pitchEg.pl1=v;
1447 fscanf(file, "%x", &v);//71
1448 presetTemp->pitchEg.pl1=v;
1449 fscanf(file, "%x", &v);//72
1450 presetTemp->pitchEg.pl1=v;
1451 for(int kaka=(NBROP-1); kaka>=0; kaka--)
1452 {
1453 k=(kaka==2?1:(kaka==1?2:kaka));
1454
1455 fscanf(file, "%x", &v);//73, 75, 77, 79
1456 presetTemp->frequency[k].isFix=(v & 0x8)>>3;
1457 presetTemp->frequency[k].freq=((v & 0x7)==0?8:(v & 0x7)*16);
1458 presetTemp->eg[k].egShift=
1459 (((v & 0x30)>>4)==0?VOF:
1460 (((v & 0x30)>>4)==1?V48:
1461 (((v & 0x30)>>4)==2?V24:V12)));
1462 fscanf(file, "%x", &v);//74, 76, 78, 80
1463 fin[k]=v & 0xF;
1464 presetTemp->frequency[k].freq+=fin[k];
1465 presetTemp->frequency[k].ratio=
1466 coarseFine2Ratio(crs[k],fin[k]);
1467 presetTemp->oscWave[k]=
1468 (((v & 0x70)>>4)==0?W1:
1469 (((v & 0x70)>>4)==1?W2:
1470 (((v & 0x70)>>4)==2?W3:
1471 (((v & 0x70)>>4)==3?W4:
1472 (((v & 0x70)>>4)==4?W5:
1473 (((v & 0x70)>>4)==5?W6:
1474 (((v & 0x70)>>4)==6?W7:W8)))))));
1475 }
1476 fscanf(file, "%x", &v);//81
1477 presetTemp->function.reverbRate=v;
1478 fscanf(file, "%x", &v);//82
1479 presetTemp->function.fcPitch=v;
1480 fscanf(file, "%x", &v);//83
1481 presetTemp->function.fcAmplitude=v;
1482 //presetTemp->globalDetune=0;
1483 presetTemp->prog=nPreset;
1484 // End of filling the preset
1485
1486 nPreset++;
1487 while(fgets(s, 500, file) && !strstr(s, "** Source:"))
1488 {
1489 if (strstr(s,"* CATEGORY"))
1490 {
1491 sscanf(s, "* CATEGORY %s", scategory);
1492 nhBank++;
1493 categoryTemp=new Category(_set,scategory,nhBank);
1494 nlBank=0;
1495 }
1496 if (strstr(s,"* SUBCATEGORY"))
1497 {
1498 sscanf(s, "* SUBCATEGORY %s", ssubcategory);
1499 subcategoryTemp=new
1500 Subcategory(categoryTemp,ssubcategory,nlBank);
1501 nlBank++;
1502 nPreset=0;
1503 }
1504 }
1505 }
1506 }
1507 fclose(file);
1508 }
1509
1510 //---------------------------------------------------------
1511 // minVolu2Voice
1512 // return the number of the voice which is the least aloud
1513 // and is not is the ATTACK state
1514 //---------------------------------------------------------
minVolu2Voice(int c)1515 int DeicsOnze::minVolu2Voice(int c) {
1516 int minVoice=0;
1517 double min=MAXVOLUME;
1518 for(int i=0; i<_global.channel[c].nbrVoices; i++)
1519 {
1520 min=((min>_global.channel[c].voices[i].volume
1521 && _global.channel[c].voices[i].op[0].envState!=ATTACK
1522 && _global.channel[c].voices[i].op[1].envState!=ATTACK
1523 && _global.channel[c].voices[i].op[2].envState!=ATTACK
1524 && _global.channel[c].voices[i].op[3].envState!=ATTACK)?
1525 _global.channel[c].voices[i].volume:min);
1526 minVoice=(min==_global.channel[c].voices[i].volume?i:minVoice);
1527 }
1528 return minVoice;
1529 }
1530
1531 //---------------------------------------------------------
1532 // noteOff2Voice
1533 // return the number of one off voice, MAXNBRVOICES otherwise
1534 //---------------------------------------------------------
noteOff2Voice(int c)1535 int DeicsOnze::noteOff2Voice(int c) {
1536 int offVoice=MAXNBRVOICES;
1537 for(int i=0; i<_global.channel[c].nbrVoices; i++)
1538 offVoice = (_global.channel[c].voices[i].isOn
1539 || _global.channel[c].voices[i].keyOn?
1540 offVoice:i);
1541 return offVoice;
1542 }
1543
1544 //---------------------------------------------------------
1545 // pitchOn2Voice
1546 // return the number of the voice which has the input
1547 // pitch and is keyOn
1548 //---------------------------------------------------------
pitchOn2Voice(int c,int pitch)1549 int DeicsOnze::pitchOn2Voice(int c, int pitch) {
1550 int pitchVoice=MAXNBRVOICES;
1551 for(int i=0; i<_global.channel[c].nbrVoices; i++) {
1552 if(_global.channel[c].voices[i].pitch==
1553 pitch && _global.channel[c].voices[i].keyOn
1554 && !_global.channel[c].voices[i].isSustained) {
1555 pitchVoice = i;
1556 return pitchVoice;
1557 }
1558 }
1559 return pitchVoice;
1560 }
1561
1562 //---------------------------------------------------------
1563 // getAttractor
1564 //---------------------------------------------------------
getAttractor(int portamentoTime,double sr)1565 inline double getAttractor(int portamentoTime, double sr) {
1566 /* some explanations
1567
1568 c(48000) = c > 1
1569
1570 f_sr(0) = 1000, f_sr(t) = 2000
1571
1572 f_sr*2(0) = 1000, f_sr*2(t*2) = 2000
1573
1574 f_sr(t) = exp(t*ln(c(sr))) * 1000
1575
1576 2000 = exp(t*ln(c(48000))) * 1000
1577
1578 2000 = exp(t*2*ln(c(48000*2))) * 1000
1579
1580 t*ln(c(48000)) = t*2*ln(c(48000*2))
1581
1582 c(48000*m) = exp(ln(c)/m)
1583
1584 sr = 48000*m
1585 */
1586 double c;
1587 c = 1.0 + COEFPORTA/(double)(portamentoTime*portamentoTime);
1588 return(exp(log(c)*48000.0/sr));
1589 }
1590
1591 //---------------------------------------------------------
1592 // pitch2freq
1593 //---------------------------------------------------------
pitch2freq(double p)1594 inline double pitch2freq(double p) {
1595 return(LOWERNOTEFREQ*exp(p*log(2.0)/12.0));
1596 }
1597
1598 //---------------------------------------------------------
1599 // lfoUpdate
1600 // update the coefficient which multiplies the current inct
1601 // in order to
1602 // get the right current frequency with respect to the lfo
1603 // update the coefficient which multiplies the amplitude.
1604 //---------------------------------------------------------
lfoUpdate(Preset * p,Channel * p_c,float * wt)1605 inline void lfoUpdate(Preset* p, Channel* p_c, float* wt) {
1606 double delayCoef;
1607
1608 //Manage LFO delay
1609 if(!p_c->delayPassed) {
1610 if(p_c->lfoIndex==0 || p_c->lfoIndex==p_c->lfoMaxIndex/2) {
1611 if(p_c->lfoDelayIndex<(double)(RESOLUTION/4)) {
1612 delayCoef=(double)wt[(int)p_c->lfoDelayIndex];
1613 p_c->lfoMaxCoefInct=exp((log(2.0)/12.0)*p_c->lfoPitch*delayCoef);
1614 p_c->lfoCoefInctInct=
1615 exp((log(2.0)/12.0)*((2*p_c->lfoPitch*delayCoef)/p_c->lfoMaxIndex));
1616 p_c->lfoDelayIndex+=p_c->lfoDelayInct;
1617 p_c->lfoMaxDAmp=delayCoef*p_c->lfoMaxAmp;
1618 }
1619 else {
1620 p_c->lfoMaxCoefInct=exp((log(2.0)/12.0)*p_c->lfoPitch);
1621 p_c->lfoCoefInctInct=
1622 exp((log(2.0)/12.0)*((2*p_c->lfoPitch)/p_c->lfoMaxIndex));
1623 p_c->delayPassed=true;
1624 p_c->lfoMaxDAmp=p_c->lfoMaxAmp;
1625 }
1626 }
1627 }
1628 switch(p->lfo.wave) {
1629 case SAWUP :
1630 if(p_c->lfoIndex==0) {
1631 p_c->lfoCoefInct=1.0/(p_c->lfoMaxCoefInct);
1632 p_c->lfoCoefAmp=p_c->lfoMaxDAmp/(double)p_c->lfoMaxIndex;
1633 p_c->lfoAmp=1.0;
1634 }
1635 else {
1636 p_c->lfoCoefInct*=p_c->lfoCoefInctInct;
1637 p_c->lfoAmp-=p_c->lfoCoefAmp;
1638 }
1639 break;
1640 case SQUARE :
1641 if(p_c->lfoIndex==0) {
1642 p_c->lfoCoefInct=p_c->lfoMaxCoefInct;
1643 p_c->lfoAmp=1.0;
1644 }
1645 if(p_c->lfoIndex==(p_c->lfoMaxIndex/2)) {
1646 p_c->lfoCoefInct=1.0/p_c->lfoMaxCoefInct;
1647 p_c->lfoAmp=1.0-p_c->lfoMaxDAmp;
1648 }
1649 break;
1650 case TRIANGL :
1651 if(p_c->lfoIndex==0) {
1652 p_c->lfoCoefInct=1.0;
1653 p_c->lfoCoefAmp=p_c->lfoMaxDAmp
1654 /(double)(p_c->lfoMaxIndex/2);
1655 p_c->lfoAmp=1.0-p_c->lfoMaxDAmp/2.0;
1656 }
1657 else if(p_c->lfoIndex<(p_c->lfoMaxIndex/4)) {
1658 p_c->lfoCoefInct*=p_c->lfoCoefInctInct;
1659 p_c->lfoAmp-=p_c->lfoCoefAmp;
1660 }
1661 else if(p_c->lfoIndex<((3*p_c->lfoMaxIndex)/4)) {
1662 p_c->lfoCoefInct/=p_c->lfoCoefInctInct;
1663 p_c->lfoAmp+=p_c->lfoCoefAmp;
1664 }
1665 else if(p_c->lfoIndex<p_c->lfoMaxIndex) {
1666 p_c->lfoCoefInct*=p_c->lfoCoefInctInct;
1667 p_c->lfoAmp-=p_c->lfoCoefAmp;
1668 }
1669 break;
1670 case SHOLD :
1671 if(p_c->lfoIndex==0||p_c->lfoIndex==(p_c->lfoMaxIndex/2)) {
1672 double r;//uniform random between -1.0 and 1.0
1673 r = (double)(2*rand()-RAND_MAX)/(double)RAND_MAX;
1674 p_c->lfoCoefInct=(r>=0.0?1.0+r*(p_c->lfoMaxCoefInct-1.0)
1675 :1.0/(1.0-r*(p_c->lfoMaxCoefInct-1.0)));
1676 p_c->lfoAmp=1.0-(r/2.0+0.5)*p_c->lfoMaxDAmp;
1677 }
1678 break;
1679 default : printf("Error : lfo wave does not exist\n");
1680 break;
1681 }
1682 p_c->lfoIndex=(p_c->lfoIndex<p_c->lfoMaxIndex?p_c->lfoIndex+1:0);
1683 }
1684
1685 //---------------------------------------------------------
1686 // portamento update
1687 //---------------------------------------------------------
portamentoUpdate(Channel * p_c,Voice * p_v)1688 inline void portamentoUpdate(Channel* p_c, Voice* p_v) {
1689 double inctTemp;
1690 bool allTargetReached;
1691 if(p_v->hasAttractor) {
1692 allTargetReached = true;
1693 for(int k = 0; k<NBROP; k++) {
1694 if(p_v->op[k].inct < p_v->op[k].targetInct) {
1695 inctTemp = p_v->op[k].inct * p_v->attractor;
1696 if(inctTemp < p_v->op[k].targetInct) {
1697 allTargetReached = false;
1698 p_v->op[k].inct = inctTemp;
1699 }
1700 else p_v->op[k].inct = p_v->op[k].targetInct;
1701 }
1702 else if(p_v->op[k].inct > p_v->op[k].targetInct) {
1703 inctTemp = p_v->op[k].inct / p_v->attractor;
1704 if(inctTemp > p_v->op[k].targetInct) {
1705 allTargetReached = false;
1706 p_v->op[k].inct = inctTemp;
1707 }
1708 else p_v->op[k].inct = p_v->op[k].targetInct;
1709 }
1710 p_c->lastInc[k] = p_v->op[k].inct;
1711 }
1712 if(allTargetReached) p_v->hasAttractor = false;
1713 }
1714 }
1715
1716
1717 //---------------------------------------------------------
1718 // pitchEnvelopeUpdate
1719 //---------------------------------------------------------
pitchEnvelopeUpdate(Voice * v,PitchEg * pe,double sr)1720 inline void pitchEnvelopeUpdate(Voice* v, PitchEg* pe, double sr) {
1721 if(v->pitchEnvState != OFF_PE) {
1722 switch(v->pitchEnvState) {
1723 case PHASE1 :
1724 if( //change to phase2
1725 (v->pitchEnvCoefInctInct == 1.0)
1726 || (v->pitchEnvCoefInctInct > 1.0 &&
1727 v->pitchEnvCoefInct > v->pitchEnvCoefInctPhase2)
1728 || (v->pitchEnvCoefInctInct < 1.0 &&
1729 v->pitchEnvCoefInct < v->pitchEnvCoefInctPhase2)
1730 ) {
1731 v->pitchEnvState = PHASE2;
1732 v->pitchEnvCoefInct = getPitchEnvCoefInct(pe->pl2);
1733 v->pitchEnvCoefInctInct =
1734 getPitchEnvCoefInctInct(pe->pl2, pe->pl3, pe->pr2, sr);
1735 }
1736 else v->pitchEnvCoefInct *= v->pitchEnvCoefInctInct;
1737 break;
1738 case PHASE2 :
1739 if( //change to off (temporarely)
1740 (v->pitchEnvCoefInctInct == 1.0)
1741 || (v->pitchEnvCoefInctInct > 1.0 &&
1742 v->pitchEnvCoefInct > v->pitchEnvCoefInctPhase3)
1743 || (v->pitchEnvCoefInctInct < 1.0 &&
1744 v->pitchEnvCoefInct < v->pitchEnvCoefInctPhase3)
1745 ) {
1746 v->pitchEnvState = OFF_PE;
1747 v->pitchEnvCoefInct = getPitchEnvCoefInct(pe->pl3);
1748 v->pitchEnvCoefInctInct = 1.0;
1749 }
1750 else v->pitchEnvCoefInct *= v->pitchEnvCoefInctInct;
1751 break;
1752 case RELEASE_PE :
1753 if( //change to release2
1754 (v->pitchEnvCoefInctInct == 1.0)
1755 || (v->pitchEnvCoefInctInct > 1.0 &&
1756 v->pitchEnvCoefInct > v->pitchEnvCoefInctPhase1)
1757 || (v->pitchEnvCoefInctInct < 1.0 &&
1758 v->pitchEnvCoefInct < v->pitchEnvCoefInctPhase1)
1759 ) {
1760 v->pitchEnvState = OFF_PE;
1761 v->pitchEnvCoefInct = getPitchEnvCoefInct(pe->pl1);
1762 v->pitchEnvCoefInctInct = 1.0;
1763 }
1764 else v->pitchEnvCoefInct *= v->pitchEnvCoefInctInct;
1765 break;
1766 case OFF_PE :
1767 //do nothing, should not appear anyway
1768 break;
1769 default :
1770 printf("Error switch pitchEnvelopeUpdate, no such case\n");
1771 break;
1772 }
1773 }
1774 }
1775
1776 //---------------------------------------------------------
1777 // outLevel2Amp, Amp for amplitude //between 0.0 and 2.0 or more
1778 // 100->2.0, 90->1.0, 80->0.5 ...
1779 //---------------------------------------------------------
outLevel2Amp(int ol)1780 inline double outLevel2Amp(int ol) {
1781 double a;
1782 double b;
1783 a = log(2)/10.0;
1784 b = -a*DB0LEVEL;
1785 return exp(a*(double)ol+b);
1786 }
1787
1788 //---------------------------------------------------------
1789 // lowlevel2amp,
1790 // 127->0dB->1.0, 0->-25dB->0
1791 //---------------------------------------------------------
lowlevel2amp(int l)1792 inline double lowlevel2amp(int l) {
1793 double a, b, c, db;
1794 if(l==0) return 0.0;
1795 else {
1796 a = DB_MIN/127.0;
1797 b = -DB_MIN;
1798 db = a*l+b;
1799 c = -log(2)/3;
1800 return exp(-c*db);
1801 }
1802 }
1803
1804 //---------------------------------------------------------
1805 // level2amp,
1806 // 255->0dB->1.0, 0->-25dB->0
1807 //---------------------------------------------------------
level2amp(int l)1808 inline double level2amp(int l) {
1809 double a, b, c, db;
1810 if(l==0) return 0.0;
1811 else {
1812 a = DB_MIN/255.0;
1813 b = -DB_MIN;
1814 db = a*l+b;
1815 c = -log(2.0)/3.0;
1816 return exp(-c*db);
1817 }
1818 }
1819
1820 //---------------------------------------------------------
1821 // amp2level
1822 // 1.0->0dB->255, 0->-25dB->0
1823 //---------------------------------------------------------
amp2level(double amp)1824 inline int amp2level(double amp){
1825 double a, b, c;
1826 a = 255.0/DB_MIN;
1827 b = 255.0;
1828 c = log(2.0)/3.0;
1829 return (int)(a*(log(amp)/c)+b);
1830 }
1831
1832 //---------------------------------------------------------
1833 // amp2lowlevel
1834 // 1.0->0dB->127, 0->-25dB->0
1835 //---------------------------------------------------------
amp2lowlevel(double amp)1836 inline int amp2lowlevel(double amp){
1837 double a, b, c;
1838 a = 127.0/DB_MIN;
1839 b = 127.0;
1840 c = log(2.0)/3.0;
1841 return (int)(a*(log(amp)/c)+b);
1842 }
1843
1844 //---------------------------------------------------------
1845 // velo2RAmp, AmpR between 0.0 and 1.0
1846 // return an amplitude ratio with respect to _preset->sensitivity.keyVelocity
1847 //---------------------------------------------------------
velo2AmpR(int velo,int kvs)1848 inline double velo2AmpR(int velo, int kvs) {
1849 double lev;
1850 lev = exp(-log(2)*kvs);
1851 return (lev+(1.0-lev)*((double)velo/(double)MAXVELO));
1852 }
1853
1854 //---------------------------------------------------------
1855 // envAR2s
1856 // return the time in second of the ATTACK duration
1857 //---------------------------------------------------------
envAR2s(int ar)1858 inline double envAR2s(int ar) {
1859 //determined using the fitting feature of gnuplot
1860 return 10.4423*exp(-0.353767*ar);
1861 }
1862
1863 //---------------------------------------------------------
1864 // envD1R2coef
1865 // return the coefficient for the exponential decrease
1866 // with respect to d1r and sampleRate, sr
1867 //---------------------------------------------------------
envD1R2coef(int d1r,double sr)1868 inline double envD1R2coef(int d1r, double sr) {
1869 double dt;//such that amp(t+dt)=amp(t)/2
1870 double alpha;//such that amp(t)=exp(alpha*t)
1871
1872 if(d1r==0) return 1.0;
1873 else
1874 {
1875 //dt has been determined with the fitting function of gnuplot
1876 dt=9.80715*exp(-0.356053*(double)d1r);
1877
1878 //amp(0)=1
1879 //amp(t+dt)=amp(t)/2
1880 //amp(t)=exp(alpha*t)
1881 //amp(t+mt)
1882 //following the above equational system we found :
1883 alpha=-log(2)/dt;
1884 return exp(alpha/sr);
1885 }
1886 }
1887
1888 //---------------------------------------------------------
1889 // coefRelease
1890 // convert the release value to a coef for coefVLevel
1891 //---------------------------------------------------------
coefRelease(unsigned char release)1892 inline double coefRelease(unsigned char release) {
1893 double x = COEFGRELEASE*(double)release/(double)MIDRELEASE+1.0-COEFGRELEASE;
1894 double square_x = x*x;
1895 return(1.0/(square_x*x));
1896 }
1897
1898 //---------------------------------------------------------
1899 // envRR2coef
1900 // return the coefficient for the exponential decrease
1901 // with respect to rr and sampleRate, sr
1902 //---------------------------------------------------------
envRR2coef(int rr,double sr,unsigned char release)1903 inline double envRR2coef(int rr, double sr, unsigned char release) {
1904 double dt;//such that amp(t+dt)=amp(t)/2
1905 double alpha;//such that amp(t)=exp(alpha*t)
1906
1907 //dt has been determined with the fitting function of gnuplot
1908 dt=7.06636*exp(-0.697606*(double)rr);
1909
1910 dt*=coefRelease(release);
1911 //printf("demi life = %e\n", dt);
1912 //amp(0)=1
1913 //amp(t+dt)=amp(t)/2
1914 //amp(t)=exp(alpha*t)
1915 //amp(t+mt)
1916 //following the above equational system we found :
1917 alpha=-log(2)/dt;
1918 return exp(alpha/sr);
1919 }
1920
1921 //---------------------------------------------------------
1922 // coefAttack
1923 // convert the attack value to a coef for envInct
1924 //---------------------------------------------------------
coefAttack(unsigned char attack)1925 inline double coefAttack(unsigned char attack) {
1926 double x = COEFGATTACK*(double)attack/(double)MIDATTACK + 1.0-COEFGATTACK;
1927 double square_x = x*x;
1928 return(square_x*square_x*x);
1929 }
1930
1931 //---------------------------------------------------------
1932 // env2RAmp
1933 // return the amplitude ratio with respect to an envelope and an
1934 // envelope state, making evoluate the envelope
1935 // sr is the sample rate and st the sine_table
1936 //---------------------------------------------------------
env2AmpR(double sr,float * wt,Eg eg,OpVoice * p_opVoice)1937 inline double env2AmpR(double sr, float* wt, Eg eg, OpVoice* p_opVoice) {
1938 switch(p_opVoice->envState) {
1939 case ATTACK:
1940 p_opVoice->envIndex+=p_opVoice->envInct;
1941 if (p_opVoice->envIndex<(RESOLUTION/4)) {
1942 p_opVoice->envLevel=wt[(int)p_opVoice->envIndex];
1943 }
1944 else {
1945 p_opVoice->envState=DECAY;
1946 p_opVoice->envLevel=1.0;
1947 p_opVoice->coefVLevel=envD1R2coef(eg.d1r, sr);
1948 }
1949 return p_opVoice->envLevel;
1950 break;
1951 case DECAY:
1952 if (p_opVoice->envLevel>((double)eg.d1l/(double)MAXD1L)+COEFERRDECSUS) {
1953 p_opVoice->envLevel*=p_opVoice->coefVLevel;
1954 }
1955 else {
1956 p_opVoice->envState=SUSTAIN;
1957 p_opVoice->envLevel=((double)eg.d1l/(double)MAXD1L);
1958 p_opVoice->coefVLevel=envD1R2coef(eg.d2r, sr);//probably the same
1959 }
1960 return p_opVoice->envLevel;
1961 break;
1962 case SUSTAIN:
1963 if (p_opVoice->envLevel>COEFERRSUSREL) {
1964 p_opVoice->envLevel*=p_opVoice->coefVLevel;
1965 }
1966 else {
1967 p_opVoice->envState=OFF;
1968 p_opVoice->envLevel=0.0;
1969 }
1970 return p_opVoice->envLevel;
1971 break;
1972 case RELEASE:
1973 if (p_opVoice->envLevel > COEFERRSUSREL) {
1974 p_opVoice->envLevel*=p_opVoice->coefVLevel;
1975 }
1976 else {
1977 p_opVoice->envState=OFF;
1978 p_opVoice->envLevel=0.0;
1979 }
1980 return p_opVoice->envLevel;
1981 break;
1982 case OFF: return 0.0;
1983 break;
1984 default: printf("Error case envelopeState");
1985 break;
1986 }
1987 return p_opVoice->envLevel;
1988 }
1989
1990 //---------------------------------------------------------
1991 // programSelect
1992 //---------------------------------------------------------
1993
programSelect(int c,int hbank,int lbank,int prog)1994 void DeicsOnze::programSelect(int c, int hbank, int lbank, int prog) {
1995 Preset* foundPreset;
1996 foundPreset=findPreset(hbank, lbank, prog);
1997 if (foundPreset) _preset[c]=foundPreset;
1998 else {
1999 _preset[c]=_initialPreset;
2000 _preset[c]->prog=prog;
2001 _preset[c]->_subcategory->_lbank=lbank; //TODO : real link
2002 _preset[c]->_subcategory->_category->_hbank=hbank;
2003 }
2004 setPreset(c);
2005 }
2006
2007 //---------------------------------------------------------
2008 // setModulation
2009 //---------------------------------------------------------
setModulation(int c,int val)2010 void DeicsOnze::setModulation(int c, int val) {
2011 _global.channel[c].modulation = (unsigned char) val;
2012 setLfo(c);
2013 }
2014 //---------------------------------------------------------
2015 // setPitchBendCoef
2016 //---------------------------------------------------------
setPitchBendCoef(int c,int val)2017 void DeicsOnze::setPitchBendCoef(int c, int val) {
2018 _global.channel[c].pitchBendCoef =
2019 exp(log(2)*((double)_preset[c]->function.pBendRange
2020 /(double)MAXPBENDRANGE)
2021 *((double)val/(double)MAXPITCHBENDVALUE));
2022 }
2023
2024 //---------------------------------------------------------
2025 // setSustain
2026 //---------------------------------------------------------
setSustain(int c,int val)2027 void DeicsOnze::setSustain(int c, int val) {
2028 _global.channel[c].sustain=(val>64);
2029 if(!_global.channel[c].sustain)
2030 for(int i=0; i<_global.channel[c].nbrVoices; i++)
2031 if(_global.channel[c].voices[i].isSustained) {
2032 for(int j=0; j<NBROP; j++) {
2033 _global.channel[c].voices[i].op[j].envState = RELEASE;
2034 setEnvRelease(c, i, j);
2035 }
2036 setPitchEnvRelease(c, i);
2037 _global.channel[c].voices[i].isSustained = false;
2038 _global.channel[c].voices[i].keyOn = false;
2039 }
2040 }
2041
2042 //---------------------------------------------------------
2043 // readColor
2044 //---------------------------------------------------------
readColor(QDomNode node)2045 QColor readColor(QDomNode node)
2046 {
2047 QDomElement e = node.toElement();
2048 int r = e.attribute("r","0").toInt();
2049 int g = e.attribute("g","0").toInt();
2050 int b = e.attribute("b","0").toInt();
2051 return QColor(r, g, b);
2052 }
2053
2054 //---------------------------------------------------------
2055 // readConfiguration
2056 //---------------------------------------------------------
readConfiguration(QDomNode qdn)2057 void DeicsOnze::readConfiguration(QDomNode qdn) {
2058 QColor textColor, backgroundColor, editTextColor, editBackgroundColor;
2059 while(!qdn.isNull()) {
2060 QDomElement qdEl = qdn.toElement();
2061 if(qdEl.isNull())
2062 continue;
2063 //nbrVoices
2064 //question? does the configurqtion has to save the number of
2065 //voices for each channel or not?
2066 //temporarly or definitely under comments
2067 /*
2068 if(qdEl.tagName()==NBRVOICESSTR) {
2069 setNbrVoices(qdEl.text().toInt());
2070 MusECore::MidiPlayEvent evNbrVoices(0, 0, 0, MusECore::ME_CONTROLLER,
2071 CTRL_NBRVOICES, _global.nbrVoices);
2072 _gui->writeEvent(evNbrVoices);
2073 }*/
2074 //channelNum
2075 /*
2076 if(qdEl.tagName()==CHANNELNUMSTR) {
2077 _global.channelNum = (qdEl.text()==ALLSTR?-1:qdEl.text().toInt()-1);
2078 unsigned char *dataChannelNum = new unsigned char[2];
2079 dataChannelNum[0]=SYSEX_CHANNELNUM;
2080 dataChannelNum[1]=(unsigned char)_global.channelNum;
2081 MusECore::MidiPlayEvent
2082 evChannelNum(0, 0, MusECore::ME_SYSEX, (const unsigned char*)dataChannelNum, 2);
2083 _gui->writeEvent(evChannelNum);
2084 }*/
2085 //quality
2086 if(qdEl.tagName()==QUALITYSTR) {
2087 _global.quality = (qdEl.text()==HIGHSTR?high:
2088 (qdEl.text()==MIDDLESTR?middle:
2089 (qdEl.text()==LOWSTR?low:ultralow)));
2090 setQuality(_global.quality);
2091 unsigned char *dataQuality = new unsigned char[2];
2092 dataQuality[0]=SYSEX_QUALITY;
2093 dataQuality[1]=(unsigned char)_global.quality;
2094 MusECore::MidiPlayEvent evQuality(0, 0, MusECore::ME_SYSEX, (const unsigned char*)dataQuality, 2);
2095 _gui->writeEvent(evQuality);
2096 }
2097 //filter
2098 if(qdEl.tagName()==FILTERSTR) {
2099 setFilter(qdEl.text()==YESSTRDEI?true:false);
2100 unsigned char *dataFilter = new unsigned char[2];
2101 dataFilter[0]=SYSEX_FILTER;
2102 dataFilter[1]=(unsigned char)getFilter();
2103 MusECore::MidiPlayEvent evFilter(0, 0, MusECore::ME_SYSEX, (const unsigned char*)dataFilter, 2);
2104 _gui->writeEvent(evFilter);
2105 }
2106 //font size
2107 if(qdEl.tagName()==FONTSIZESTR) {
2108 _global.fontSize = qdEl.text().toInt();
2109 unsigned char *dataFontSize = new unsigned char[2];
2110 dataFontSize[0]=SYSEX_FONTSIZE;
2111 dataFontSize[1]=(unsigned char)_global.fontSize;
2112 MusECore::MidiPlayEvent evFontSize(0, 0, MusECore::ME_SYSEX, (const unsigned char*)dataFontSize, 2);
2113 _gui->writeEvent(evFontSize);
2114 }
2115 //saveConfig
2116 if(qdEl.tagName()==SAVECONFIGSTR) {
2117 _saveConfig = (qdEl.text()==YESSTRDEI?true:false);
2118 unsigned char *dataSaveConfig = new unsigned char[2];
2119 dataSaveConfig[0]=SYSEX_SAVECONFIG;
2120 dataSaveConfig[1]=(unsigned char)_saveConfig;
2121 MusECore::MidiPlayEvent
2122 evSaveConfig(0, 0, MusECore::ME_SYSEX, (const unsigned char*)dataSaveConfig, 2);
2123 _gui->writeEvent(evSaveConfig);
2124 }
2125 //saveOnlyUsed
2126 if(qdEl.tagName()==SAVEONLYUSEDSTR) {
2127 _saveOnlyUsed = (qdEl.text()==YESSTRDEI?true:false);
2128 unsigned char *dataSaveOnlyUsed = new unsigned char[2];
2129 dataSaveOnlyUsed[0]=SYSEX_SAVEONLYUSED;
2130 dataSaveOnlyUsed[1]=(unsigned char)_saveOnlyUsed;
2131 MusECore::MidiPlayEvent
2132 evSaveOnlyUsed(0, 0, MusECore::ME_SYSEX, (const unsigned char*)dataSaveOnlyUsed, 2);
2133 _gui->writeEvent(evSaveOnlyUsed);
2134 }
2135 //colors
2136 if(qdEl.tagName()==TEXTCOLORSTR) textColor = readColor(qdn);
2137 if(qdEl.tagName()==BACKGROUNDCOLORSTR) backgroundColor = readColor(qdn);
2138 if(qdEl.tagName()==EDITTEXTCOLORSTR) editTextColor = readColor(qdn);
2139 if(qdEl.tagName()==EDITBACKGROUNDCOLORSTR)
2140 editBackgroundColor = readColor(qdn);
2141
2142 //must insert load image, later
2143
2144 //load init set
2145 if(qdEl.tagName()==ISINITSETSTR) {
2146 _isInitSet = (qdEl.text()==YESSTRDEI?true:false);
2147 unsigned char *dataIsInitSet = new unsigned char[2];
2148 dataIsInitSet[0]=SYSEX_ISINITSET;
2149 dataIsInitSet[1]=(unsigned char)_isInitSet;
2150 MusECore::MidiPlayEvent
2151 evIsInitSet(0, 0, MusECore::ME_SYSEX, (const unsigned char*)dataIsInitSet, 2);
2152 _gui->writeEvent(evIsInitSet);
2153 }
2154 if(qdEl.tagName()==INITSETPATHSTR) {
2155 _initSetPath = qdEl.text();
2156 unsigned char *dataInitSetPath =
2157 new unsigned char[1+MAXSTRLENGTHINITSETPATH];
2158 dataInitSetPath[0]=SYSEX_INITSETPATH;
2159 strncpy((char*)&dataInitSetPath[1], _initSetPath.toLatin1().constData(),
2160 MAXSTRLENGTHINITSETPATH);
2161 MusECore::MidiPlayEvent
2162 evInitSetPath(0, 0, MusECore::ME_SYSEX, (const unsigned char*)dataInitSetPath,
2163 1+MAXSTRLENGTHINITSETPATH);
2164 _gui->writeEvent(evInitSetPath);
2165 }
2166 //load background pix
2167 if(qdEl.tagName()==ISBACKGROUNDPIXSTR) {
2168 _isBackgroundPix = (qdEl.text()==YESSTRDEI?true:false);
2169 unsigned char *dataIsBackgroundPix = new unsigned char[2];
2170 dataIsBackgroundPix[0]=SYSEX_ISBACKGROUNDPIX;
2171 dataIsBackgroundPix[1]=(unsigned char)_isBackgroundPix;
2172 MusECore::MidiPlayEvent
2173 evIsBackgroundPix(0, 0, MusECore::ME_SYSEX,
2174 (const unsigned char*)dataIsBackgroundPix, 2);
2175 _gui->writeEvent(evIsBackgroundPix);
2176 }
2177 if(qdEl.tagName()==BACKGROUNDPIXPATHSTR) {
2178 _backgroundPixPath = qdEl.text();
2179 unsigned char *dataBackgroundPixPath =
2180 new unsigned char[1+MAXSTRLENGTHBACKGROUNDPIXPATH];
2181 dataBackgroundPixPath[0]=SYSEX_BACKGROUNDPIXPATH;
2182 strncpy((char*)&dataBackgroundPixPath[1],
2183 _backgroundPixPath.toLatin1().constData(),
2184 MAXSTRLENGTHBACKGROUNDPIXPATH);
2185 MusECore::MidiPlayEvent
2186 evBackgroundPixPath(0, 0, MusECore::ME_SYSEX,
2187 (const unsigned char*)dataBackgroundPixPath,
2188 1+MAXSTRLENGTHBACKGROUNDPIXPATH);
2189 _gui->writeEvent(evBackgroundPixPath);
2190 }
2191 qdn = qdn.nextSibling();
2192 }
2193 //send colors
2194 unsigned char dataColorGui[COLORSYSEXLENGTH+1];
2195 dataColorGui[0]=SYSEX_COLORGUI;
2196 dataColorGui[1]=(unsigned char)textColor.red();
2197 dataColorGui[2]=(unsigned char)textColor.green();
2198 dataColorGui[3]=(unsigned char)textColor.blue();
2199 dataColorGui[4]=(unsigned char)backgroundColor.red();
2200 dataColorGui[5]=(unsigned char)backgroundColor.green();
2201 dataColorGui[6]=(unsigned char)backgroundColor.blue();
2202 dataColorGui[7]=(unsigned char)editTextColor.red();
2203 dataColorGui[8]=(unsigned char)editTextColor.green();
2204 dataColorGui[9]=(unsigned char)editTextColor.blue();
2205 dataColorGui[10]=(unsigned char)editBackgroundColor.red();
2206 dataColorGui[11]=(unsigned char)editBackgroundColor.green();
2207 dataColorGui[12]=(unsigned char)editBackgroundColor.blue();
2208 MusECore::MidiPlayEvent evSysexColor(0, 0, MusECore::ME_SYSEX, (const unsigned char*)dataColorGui,
2209 COLORSYSEXLENGTH+1);
2210 _gui->writeEvent(evSysexColor);
2211 }
2212
2213 //-----------------------------------------------------------
2214 // loadConfiguration
2215 //-----------------------------------------------------------
loadConfiguration(QString fileName)2216 void DeicsOnze::loadConfiguration(QString fileName) {
2217 // read the XML file and create DOM tree
2218 if(!fileName.isEmpty()) {
2219 QFile confFile(fileName);
2220 if(!confFile.open(QIODevice::ReadOnly)) {
2221 printf("Critical Error. Cannot open file %s\n",
2222 fileName.toLatin1().data());
2223 return;
2224 }
2225 QDomDocument domTree;
2226 if (!domTree.setContent(&confFile )) {
2227 printf("Critical Error. Parsing error for file %s\n",
2228 fileName.toLatin1().data());
2229 confFile.close();
2230 return;
2231 }
2232
2233 confFile.close();
2234
2235 QDomNode node = domTree.documentElement();
2236 while (!node.isNull()) {
2237 QDomElement e = node.toElement();
2238 if (e.isNull())
2239 continue;
2240 if (e.tagName() == DEICSONZECONFIGURATIONSTR) {
2241 QString version = e.attribute(QString("version"));
2242 if (version == "1.0") {
2243 readConfiguration(node.firstChild());
2244 }
2245 else printf("unsupported *.dco file version %s\n",
2246 version.toLatin1().constData());
2247 }
2248 else printf("DeicsOnze: %s not supported\n",
2249 e.tagName().toLatin1().constData());
2250 node = node.nextSibling();
2251 }
2252 }
2253 }
2254
2255 //---------------------------------------------------------
2256 // writeConfiguration
2257 //---------------------------------------------------------
writeConfiguration(AL::Xml * xml)2258 void DeicsOnze::writeConfiguration(AL::Xml* xml) {
2259 QString str;
2260 xml->stag("deicsOnzeConfiguation version=\"1.0\"");
2261 //xml->intTag(NBRVOICESSTR, (int)_global.nbrVoices);
2262 //xml->strTag(CHANNELNUMSTR, (_global.channelNum==-1?ALLSTR:
2263 // str.setNum(_global.channelNum+1)));
2264 xml->tag(QUALITYSTR, QString((_global.quality==high?HIGHSTR:
2265 (_global.quality==middle?MIDDLESTR:
2266 (_global.quality==low?LOWSTR:ULTRALOWSTR)))));
2267 xml->tag(FILTERSTR, QString(getFilter()==true?YESSTRDEI:NOSTRDEI));
2268 xml->tag(FONTSIZESTR, _global.fontSize);
2269 xml->tag(SAVECONFIGSTR, QString((_saveConfig?YESSTRDEI:NOSTRDEI)));
2270 xml->tag(SAVEONLYUSEDSTR, QString((_saveOnlyUsed?YESSTRDEI:NOSTRDEI)));
2271 xml->tag(TEXTCOLORSTR,
2272 reinterpret_cast<const QColor &>(*_gui->tColor));
2273 xml->tag(BACKGROUNDCOLORSTR,
2274 reinterpret_cast<const QColor &>(*_gui->bColor));
2275 xml->tag(EDITTEXTCOLORSTR,
2276 reinterpret_cast<const QColor &>(*_gui->etColor));
2277 xml->tag(EDITBACKGROUNDCOLORSTR,
2278 reinterpret_cast<const QColor &>(*_gui->ebColor));
2279 xml->tag(ISINITSETSTR, QString((_isInitSet?YESSTRDEI:NOSTRDEI)));
2280 xml->tag(INITSETPATHSTR, QString(_initSetPath));
2281 xml->tag(ISBACKGROUNDPIXSTR, QString((_isBackgroundPix?YESSTRDEI:NOSTRDEI)));
2282 xml->tag(BACKGROUNDPIXPATHSTR, _backgroundPixPath);
2283
2284 xml->etag(DEICSONZECONFIGURATIONSTR);
2285 }
2286
2287 //---------------------------------------------------------
2288 // getInitBuffer
2289 //---------------------------------------------------------
setupInitBuffer(int len)2290 void DeicsOnze::setupInitBuffer(int len)
2291 {
2292 if (len > initLen) {
2293 if (initBuffer)
2294 delete [] initBuffer;
2295 initBuffer = new unsigned char[len];
2296 initLen = len;
2297 }
2298 }
2299
2300 //---------------------------------------------------------
2301 // getInitData
2302 //---------------------------------------------------------
getInitData(int * length,const unsigned char ** data)2303 void DeicsOnze::getInitData(int* length, const unsigned char** data) {
2304 //write the set in a temporary file and in a QByteArray
2305 QTemporaryFile file;
2306 file.open();
2307 AL::Xml* xml=new AL::Xml(&file);
2308 xml->header();
2309 _set->writeSet(xml, _saveOnlyUsed);
2310 file.reset(); //seek the start of the file
2311 QByteArray ba = file.readAll();
2312 file.close();
2313
2314 //compress the QByteArray at default rate
2315 QByteArray baComp = qCompress(ba);
2316
2317 int version = SYSEX_INIT_DATA_VERSION; //SYSEX_INIT_DATA_VERSION_2; // Not quite ready for ver 2 yet. Need delay wet/dry gui control.
2318
2319 //save the set
2320 //*length = (version == SYSEX_INIT_DATA_VERSION_2 ? NUM_CONFIGLENGTH : NUM_DELAY_WET_DRY_MIX) // HACK
2321 *length = NUM_CONFIGLENGTH
2322 + (_pluginIReverb?sizeof(float)*_pluginIReverb->plugin()->parameter():0)
2323 + (_pluginIChorus?sizeof(float)*_pluginIChorus->plugin()->parameter():0)
2324 + baComp.size();
2325
2326 setupInitBuffer(*length);
2327
2328 //save init data
2329
2330 initBuffer[0]=MUSE_SYNTH_SYSEX_MFG_ID;
2331 initBuffer[1]=DEICSONZE_UNIQUE_ID;
2332 initBuffer[2]=SYSEX_INIT_DATA;
2333 initBuffer[3]=version;
2334 //save global data
2335 initBuffer[NUM_MASTERVOL] = (unsigned char) getMasterVol();
2336 for(int c = 0; c < NBRCHANNELS; c++) {
2337 initBuffer[NUM_CHANNEL_ENABLE + c] = (unsigned char) getChannelEnable(c);
2338 initBuffer[NUM_CHANNEL_VOL + c] = (unsigned char) getChannelVol(c);
2339 initBuffer[NUM_CHANNEL_PAN + c] = (unsigned char) getChannelPan(c);
2340 int b = getChannelBrightness(c);
2341 initBuffer[NUM_CHANNEL_BRIGHTNESS + 2*c] = (unsigned char) (b%256);
2342 initBuffer[NUM_CHANNEL_BRIGHTNESS + 2*c + 1] = (unsigned char) (b/256);
2343 initBuffer[NUM_CHANNEL_MODULATION + c] =
2344 (unsigned char) getChannelModulation(c);
2345 initBuffer[NUM_CHANNEL_DETUNE + c] =
2346 (unsigned char) getChannelDetune(c) + MAXCHANNELDETUNE;
2347 initBuffer[NUM_CHANNEL_ATTACK + c] = (unsigned char) getChannelAttack(c);
2348 initBuffer[NUM_CHANNEL_RELEASE + c] = (unsigned char) getChannelRelease(c);
2349 initBuffer[NUM_CHANNEL_REVERB + c] = (unsigned char) getChannelReverb(c);
2350 initBuffer[NUM_CHANNEL_CHORUS + c] = (unsigned char) getChannelChorus(c);
2351 initBuffer[NUM_CHANNEL_DELAY + c] = (unsigned char) getChannelDelay(c);
2352 initBuffer[NUM_CURRENTPROG + c] = (unsigned char) _preset[c]->prog;
2353 initBuffer[NUM_CURRENTLBANK + c] =
2354 (unsigned char) _preset[c]->_subcategory->_lbank;
2355 initBuffer[NUM_CURRENTHBANK + c] =
2356 (unsigned char) _preset[c]->_subcategory->_category->_hbank;
2357 initBuffer[NUM_NBRVOICES + c] = (unsigned char) getNbrVoices(c);
2358 }
2359 initBuffer[NUM_SAVEONLYUSED]=(unsigned char) _saveOnlyUsed;
2360 initBuffer[NUM_SAVECONFIG]=(unsigned char) _saveConfig;
2361 //save config data
2362 if(_saveConfig) {
2363 initBuffer[NUM_QUALITY]=(unsigned char)_global.quality;
2364 initBuffer[NUM_FILTER]=(unsigned char)getFilter();
2365 initBuffer[NUM_FONTSIZE]=(unsigned char)_global.fontSize;
2366 initBuffer[NUM_RED_TEXT]=(unsigned char)_gui->tColor->red();
2367 initBuffer[NUM_GREEN_TEXT]=(unsigned char)_gui->tColor->green();
2368 initBuffer[NUM_BLUE_TEXT]=(unsigned char)_gui->tColor->blue();
2369 initBuffer[NUM_RED_BACKGROUND]=(unsigned char)_gui->bColor->red();
2370 initBuffer[NUM_GREEN_BACKGROUND]=(unsigned char)_gui->bColor->green();
2371 initBuffer[NUM_BLUE_BACKGROUND]=(unsigned char)_gui->bColor->blue();
2372 initBuffer[NUM_RED_EDITTEXT]=(unsigned char)_gui->etColor->red();
2373 initBuffer[NUM_GREEN_EDITTEXT]=(unsigned char)_gui->etColor->green();
2374 initBuffer[NUM_BLUE_EDITTEXT]=(unsigned char)_gui->etColor->blue();
2375 initBuffer[NUM_RED_EDITBACKGROUND]=(unsigned char)_gui->ebColor->red();
2376 initBuffer[NUM_GREEN_EDITBACKGROUND]=(unsigned char)_gui->ebColor->green();
2377 initBuffer[NUM_BLUE_EDITBACKGROUND]=(unsigned char)_gui->ebColor->blue();
2378 initBuffer[NUM_ISINITSET]=(unsigned char)_isInitSet;
2379 strncpy((char*)&initBuffer[NUM_INITSETPATH],
2380 _initSetPath.toLatin1().constData(), MAXSTRLENGTHINITSETPATH);
2381 initBuffer[NUM_ISBACKGROUNDPIX]=(unsigned char)_isBackgroundPix;
2382 strncpy((char*)&initBuffer[NUM_BACKGROUNDPIXPATH],
2383 _backgroundPixPath.toLatin1().constData(),
2384 MAXSTRLENGTHBACKGROUNDPIXPATH);
2385 }
2386 //FX
2387 //reverb
2388 initBuffer[NUM_IS_REVERB_ON]=(unsigned char)_global.isReverbActivated;
2389 initBuffer[NUM_REVERB_RETURN]=(unsigned char)getReverbReturn();
2390 initBuffer[NUM_REVERB_PARAM_NBR]=
2391 (_pluginIReverb?(unsigned char)_pluginIReverb->plugin()->parameter() : 0);
2392 strncpy((char*)&initBuffer[NUM_REVERB_LIB],
2393 (_pluginIReverb?
2394 _pluginIReverb->plugin()->lib().toLatin1().constData() : "\0"),
2395 MAXSTRLENGTHFXLIB);
2396 strncpy((char*)&initBuffer[NUM_REVERB_LABEL],
2397 (_pluginIReverb?
2398 _pluginIReverb->plugin()->label().toLatin1().constData() : "\0"),
2399 MAXSTRLENGTHFXLABEL);
2400 //chorus
2401 initBuffer[NUM_IS_CHORUS_ON]=(unsigned char)_global.isChorusActivated;
2402 initBuffer[NUM_CHORUS_RETURN]=(unsigned char)getChorusReturn();
2403 initBuffer[NUM_CHORUS_PARAM_NBR]=
2404 (_pluginIChorus?(unsigned char)_pluginIChorus->plugin()->parameter() : 0);
2405 strncpy((char*)&initBuffer[NUM_CHORUS_LIB],
2406 (_pluginIChorus?
2407 _pluginIChorus->plugin()->lib().toLatin1().constData() : "\0"),
2408 MAXSTRLENGTHFXLIB);
2409 strncpy((char*)&initBuffer[NUM_CHORUS_LABEL],
2410 (_pluginIChorus?
2411 _pluginIChorus->plugin()->label().toLatin1().constData() : "\0"),
2412 MAXSTRLENGTHFXLABEL);
2413 //delay
2414 initBuffer[NUM_IS_DELAY_ON]=(unsigned char)_global.isDelayActivated;
2415 initBuffer[NUM_DELAY_RETURN]=(unsigned char)getDelayReturn();
2416 //save FX parameters
2417 //reverb
2418 for(int i = 0; i < (int)initBuffer[NUM_REVERB_PARAM_NBR]; i++) {
2419 float val = getReverbParam(i);
2420 //memcpy(&initBuffer[(version == SYSEX_INIT_DATA_VERSION_2 ? NUM_CONFIGLENGTH : NUM_DELAY_WET_DRY_MIX) // HACK
2421 memcpy(&initBuffer[NUM_CONFIGLENGTH
2422 + sizeof(float)*i], &val, sizeof(float));
2423 }
2424 //chorus
2425 for(int i = 0; i < (int)initBuffer[NUM_CHORUS_PARAM_NBR]; i++) {
2426 float val = getChorusParam(i);
2427 //memcpy(&initBuffer[(version == SYSEX_INIT_DATA_VERSION_2 ? NUM_CONFIGLENGTH : NUM_DELAY_WET_DRY_MIX) // HACK
2428 memcpy(&initBuffer[NUM_CONFIGLENGTH
2429 + sizeof(float)*(int)initBuffer[NUM_REVERB_PARAM_NBR]
2430 + sizeof(float)*i], &val, sizeof(float));
2431 }
2432 //delay
2433 float delayfloat;
2434 delayfloat = getDelayBPM();
2435 memcpy(&initBuffer[NUM_DELAY_BPM], &delayfloat, 4);
2436 delayfloat = getDelayBeatRatio();
2437 memcpy(&initBuffer[NUM_DELAY_BEATRATIO], &delayfloat, sizeof(float));
2438 delayfloat = getDelayFeedback();
2439 memcpy(&initBuffer[NUM_DELAY_FEEDBACK], &delayfloat, sizeof(float));
2440 delayfloat = getDelayLFOFreq();
2441 memcpy(&initBuffer[NUM_DELAY_LFO_FREQ], &delayfloat, sizeof(float));
2442 delayfloat = getDelayLFODepth();
2443 memcpy(&initBuffer[NUM_DELAY_LFO_DEPTH], &delayfloat, sizeof(float));
2444 //if(version == SYSEX_INIT_DATA_VERSION_2)
2445 //{
2446 // delayfloat = getDelayDryWet();
2447 // memcpy(&initBuffer[NUM_DELAY_WET_DRY_MIX], &delayfloat, sizeof(float));
2448 //}
2449
2450 //save set data
2451 int offset =
2452 //(version == SYSEX_INIT_DATA_VERSION_2 ? NUM_CONFIGLENGTH : NUM_DELAY_WET_DRY_MIX) // HACK
2453 NUM_CONFIGLENGTH
2454 + sizeof(float)*(int)initBuffer[NUM_REVERB_PARAM_NBR]
2455 + sizeof(float)*(int)initBuffer[NUM_CHORUS_PARAM_NBR];
2456 for(int i = offset; i < *length; i++)
2457 initBuffer[i]=(unsigned char)baComp.at(i - offset);
2458
2459 *data=initBuffer;
2460 }
2461 //---------------------------------------------------------
2462 // parseInitData
2463 //---------------------------------------------------------
parseInitData(int length,const unsigned char * data)2464 void DeicsOnze::parseInitData(int length, const unsigned char* data) {
2465 //if(data[3]!=SYSEX_INIT_DATA_VERSION || data[3]!=SYSEX_INIT_DATA_VERSION_2)
2466 if(data[3]!=SYSEX_INIT_DATA_VERSION)
2467 {
2468 printf("Error: DeicsOnze::parseInitData: unknown sysex init data version:%d\n", data[3]);
2469 return;
2470 }
2471
2472 //load global parameters
2473 //master volume
2474 setMasterVol(data[NUM_MASTERVOL]);
2475 unsigned char *dataMasterVol = new unsigned char[2];
2476 dataMasterVol[0]=SYSEX_MASTERVOL;
2477 dataMasterVol[1]=(unsigned char) getMasterVol();
2478 MusECore::MidiPlayEvent
2479 evMasterVol(0, 0, MusECore::ME_SYSEX, (const unsigned char*)dataMasterVol, 2);
2480 _gui->writeEvent(evMasterVol);
2481 //channel configuration
2482 for(int c = 0; c < NBRCHANNELS; c++) {
2483 //isEnable
2484 setChannelEnable(c, data[NUM_CHANNEL_ENABLE + c]);
2485 MusECore::MidiPlayEvent
2486 evChEnable(0, 0, c, MusECore::ME_CONTROLLER,
2487 CTRL_CHANNELENABLE, data[NUM_CHANNEL_ENABLE + c]);
2488 _gui->writeEvent(evChEnable);
2489 //nbrVoices
2490 setNbrVoices(c, data[NUM_NBRVOICES + c]);
2491 MusECore::MidiPlayEvent
2492 evNbrVoices(0, 0, c,MusECore::ME_CONTROLLER,CTRL_NBRVOICES, data[NUM_NBRVOICES + c]);
2493 _gui->writeEvent(evNbrVoices);
2494 //channel volume
2495 setChannelVol(c, data[NUM_CHANNEL_VOL + c]);
2496 MusECore::MidiPlayEvent
2497 evChVol(0, 0, c, MusECore::ME_CONTROLLER,
2498 CTRL_CHANNELVOLUME, data[NUM_CHANNEL_VOL + c]);
2499 _gui->writeEvent(evChVol);
2500 //channel pan
2501 setChannelPan(c, data[NUM_CHANNEL_PAN + c]);
2502 MusECore::MidiPlayEvent
2503 evChPan(0, 0, c, MusECore::ME_CONTROLLER, CTRL_CHANNELPAN,
2504 data[NUM_CHANNEL_PAN + c]);
2505 _gui->writeEvent(evChPan);
2506 if(getChannelEnable(c)) applyChannelAmp(c);
2507 //channel detune
2508 setChannelDetune(c, data[NUM_CHANNEL_DETUNE + c]-MAXCHANNELDETUNE);
2509 MusECore::MidiPlayEvent
2510 evChDetune(0, 0, c, MusECore::ME_CONTROLLER, CTRL_CHANNELDETUNE,
2511 data[NUM_CHANNEL_DETUNE + c]-MAXCHANNELDETUNE);
2512 _gui->writeEvent(evChDetune);
2513 //channel brightness
2514 setChannelBrightness(c,
2515 data[NUM_CHANNEL_BRIGHTNESS + 2*c]
2516 + data[NUM_CHANNEL_BRIGHTNESS + 2*c + 1] * 256);
2517 MusECore::MidiPlayEvent
2518 evChBrightness(0, 0, c, MusECore::ME_CONTROLLER,
2519 CTRL_FINEBRIGHTNESS, getChannelBrightness(c));
2520 _gui->writeEvent(evChBrightness);
2521 //channel modulation
2522 setChannelModulation(c, data[NUM_CHANNEL_MODULATION + c]);
2523 MusECore::MidiPlayEvent
2524 evChMod(0, 0, c, MusECore::ME_CONTROLLER,
2525 MusECore::CTRL_MODULATION, data[NUM_CHANNEL_MODULATION + c]);
2526 _gui->writeEvent(evChMod);
2527 //channel attack
2528 setChannelAttack(c, data[NUM_CHANNEL_ATTACK + c]);
2529 MusECore::MidiPlayEvent
2530 evChAttack(0, 0, c, MusECore::ME_CONTROLLER,
2531 MusECore::CTRL_ATTACK_TIME, data[NUM_CHANNEL_ATTACK + c]);
2532 _gui->writeEvent(evChAttack);
2533 //channel release
2534 setChannelRelease(c, data[NUM_CHANNEL_RELEASE + c]);
2535 MusECore::MidiPlayEvent
2536 evChRelease(0, 0, c, MusECore::ME_CONTROLLER,
2537 MusECore::CTRL_RELEASE_TIME, data[NUM_CHANNEL_RELEASE + c]);
2538 _gui->writeEvent(evChRelease);
2539 //channel reverb
2540 setChannelReverb(c, data[NUM_CHANNEL_REVERB + c]);
2541 MusECore::MidiPlayEvent
2542 evChReverb(0, 0, c, MusECore::ME_CONTROLLER,
2543 MusECore::CTRL_REVERB_SEND, data[NUM_CHANNEL_REVERB + c]);
2544 _gui->writeEvent(evChReverb);
2545 //channel chorus
2546 setChannelChorus(c, data[NUM_CHANNEL_CHORUS + c]);
2547 MusECore::MidiPlayEvent
2548 evChChorus(0, 0, c, MusECore::ME_CONTROLLER,
2549 MusECore::CTRL_CHORUS_SEND, data[NUM_CHANNEL_CHORUS + c]);
2550 _gui->writeEvent(evChChorus);
2551 //channel delay
2552 setChannelDelay(c, data[NUM_CHANNEL_DELAY + c]);
2553 MusECore::MidiPlayEvent
2554 evChDelay(0, 0, c, MusECore::ME_CONTROLLER,
2555 MusECore::CTRL_VARIATION_SEND, data[NUM_CHANNEL_DELAY + c]);
2556 _gui->writeEvent(evChDelay);
2557 }
2558 //load configuration
2559 _saveConfig = (bool)data[NUM_SAVECONFIG];
2560 unsigned char *dataSaveConfig = new unsigned char[2];
2561 dataSaveConfig[0]=SYSEX_SAVECONFIG;
2562 dataSaveConfig[1]=(unsigned char)_saveConfig;
2563 MusECore::MidiPlayEvent
2564 evSaveConfig(0, 0, MusECore::ME_SYSEX, (const unsigned char*)dataSaveConfig, 2);
2565 _gui->writeEvent(evSaveConfig);
2566 if(_saveConfig) {
2567 //saveOnlyUsed
2568 _saveOnlyUsed = (bool)data[NUM_SAVEONLYUSED];
2569 unsigned char *dataSaveOnlyUsed = new unsigned char[2];
2570 dataSaveOnlyUsed[0]=SYSEX_SAVEONLYUSED;
2571 dataSaveOnlyUsed[1]=(unsigned char)_saveOnlyUsed;
2572 MusECore::MidiPlayEvent
2573 evSaveOnlyUsed(0, 0, MusECore::ME_SYSEX, (const unsigned char*)dataSaveOnlyUsed, 2);
2574 _gui->writeEvent(evSaveOnlyUsed);
2575 //colors
2576 unsigned char dataColorGui[COLORSYSEXLENGTH+1];
2577 dataColorGui[0]=SYSEX_COLORGUI;
2578 for (int i=0; i<COLORSYSEXLENGTH; i++)
2579 dataColorGui[i+1]=data[NUM_RED_TEXT+i];
2580 MusECore::MidiPlayEvent evSysexColor(0, 0, MusECore::ME_SYSEX, (const unsigned char*)dataColorGui,
2581 COLORSYSEXLENGTH+1);
2582 _gui->writeEvent(evSysexColor);
2583 //quality
2584 unsigned char dataQuality[2];
2585 dataQuality[0]=SYSEX_QUALITY;
2586 dataQuality[1]=data[NUM_QUALITY];
2587 setQuality((Quality)data[NUM_QUALITY]);
2588 MusECore::MidiPlayEvent evQuality(0, 0, MusECore::ME_SYSEX, (const unsigned char*)dataQuality, 2);
2589 _gui->writeEvent(evQuality);
2590 //filter
2591 unsigned char dataFilter[2];
2592 dataFilter[0]=SYSEX_FILTER;
2593 dataFilter[1]=data[NUM_FILTER];
2594 setFilter((bool)data[NUM_FILTER]);
2595 MusECore::MidiPlayEvent evFilter(0, 0, MusECore::ME_SYSEX, (const unsigned char*)dataFilter, 2);
2596 _gui->writeEvent(evFilter);
2597 //font size
2598 unsigned char dataFontSize[2];
2599 dataFontSize[0]=SYSEX_FONTSIZE;
2600 dataFontSize[1]=data[NUM_FONTSIZE];
2601 MusECore::MidiPlayEvent evFontSize(0, 0, MusECore::ME_SYSEX, (const unsigned char*)dataFontSize, 2);
2602 _gui->writeEvent(evFontSize);
2603 //load init set
2604 unsigned char dataIsInitSet[2];
2605 dataIsInitSet[0]=SYSEX_ISINITSET;
2606 dataIsInitSet[1]=data[NUM_ISINITSET];
2607 MusECore::MidiPlayEvent evIsInitSet(0, 0, MusECore::ME_SYSEX,
2608 (const unsigned char*)dataIsInitSet, 2);
2609 _gui->writeEvent(evIsInitSet);
2610 unsigned char dataInitSetPath[1+MAXSTRLENGTHINITSETPATH];
2611 dataInitSetPath[0]=SYSEX_INITSETPATH;
2612 for(int a = 0; a < MAXSTRLENGTHINITSETPATH; a++)
2613 dataInitSetPath[a+1] = data[a+NUM_INITSETPATH];
2614 MusECore::MidiPlayEvent evInitSetPath(0, 0, MusECore::ME_SYSEX,(const unsigned char*)dataInitSetPath,
2615 1+MAXSTRLENGTHINITSETPATH);
2616 _gui->writeEvent(evInitSetPath);
2617 //load background pix
2618 unsigned char dataIsBackgroundPix[2];
2619 dataIsBackgroundPix[0]=SYSEX_ISBACKGROUNDPIX;
2620 dataIsBackgroundPix[1]=data[NUM_ISBACKGROUNDPIX];
2621 MusECore::MidiPlayEvent evIsBackgroundPix(0, 0, MusECore::ME_SYSEX,
2622 (const unsigned char*)dataIsBackgroundPix, 2);
2623 _gui->writeEvent(evIsBackgroundPix);
2624 unsigned char dataBackgroundPixPath[1+MAXSTRLENGTHBACKGROUNDPIXPATH];
2625 dataBackgroundPixPath[0]=SYSEX_BACKGROUNDPIXPATH;
2626 for(int a = 0; a < MAXSTRLENGTHBACKGROUNDPIXPATH; a++)
2627 dataBackgroundPixPath[a+1] = data[a+NUM_BACKGROUNDPIXPATH];
2628 MusECore::MidiPlayEvent evBackgroundPixPath(0, 0, MusECore::ME_SYSEX,
2629 (const unsigned char*)dataBackgroundPixPath,
2630 1+MAXSTRLENGTHBACKGROUNDPIXPATH);
2631 _gui->writeEvent(evBackgroundPixPath);
2632 }
2633 else _gui->saveConfigCheckBox->setChecked(false);
2634 //load FX
2635 //reverb
2636 _global.isReverbActivated = (bool)data[NUM_IS_REVERB_ON];
2637 unsigned char *dataReverbAct = new unsigned char[2];
2638 dataReverbAct[0]=SYSEX_REVERBACTIV;
2639 dataReverbAct[1]=(unsigned char)_global.isReverbActivated;
2640 MusECore::MidiPlayEvent evReverbAct(0, 0, MusECore::ME_SYSEX,(const unsigned char*)dataReverbAct, 2);
2641 _gui->writeEvent(evReverbAct);
2642 setReverbReturn((int)data[NUM_REVERB_RETURN]);
2643 unsigned char *dataReverbRet = new unsigned char[2];
2644 dataReverbRet[0]=SYSEX_REVERBRETURN;
2645 dataReverbRet[1]=(unsigned char)getReverbReturn();
2646 MusECore::MidiPlayEvent evReverbRet(0, 0, MusECore::ME_SYSEX,(const unsigned char*)dataReverbRet, 2);
2647 _gui->writeEvent(evReverbRet);
2648 MusESimplePlugin::Plugin* p;
2649 p = MusESimplePlugin::plugins.find((const char*)&data[NUM_REVERB_LIB],
2650 (const char*)&data[NUM_REVERB_LABEL]);
2651 if(p) {
2652 initPluginReverb(p);
2653 for(int i = 0; i < (int)_pluginIReverb->plugin()->parameter(); i++) {
2654 float val;
2655 //memcpy(&val, &data[(data[3] == SYSEX_INIT_DATA_VERSION_2 ? NUM_CONFIGLENGTH : NUM_DELAY_WET_DRY_MIX) // HACK
2656 memcpy(&val, &data[NUM_CONFIGLENGTH
2657 + sizeof(float)*i], sizeof(float));
2658 _pluginIReverb->setParam(i, val);
2659 }
2660 char dataBuildRev;
2661 dataBuildRev = SYSEX_BUILDGUIREVERB;
2662 MusECore::MidiPlayEvent evSysexBuildRev(0, 0, MusECore::ME_SYSEX,
2663 (const unsigned char*)&dataBuildRev, 1);
2664 _gui->writeEvent(evSysexBuildRev);
2665 }
2666 else _pluginIReverb = NULL;
2667 //chorus
2668 _global.isChorusActivated = (bool)data[NUM_IS_CHORUS_ON];
2669 unsigned char *dataChorusAct = new unsigned char[2];
2670 dataChorusAct[0]=SYSEX_CHORUSACTIV;
2671 dataChorusAct[1]=(unsigned char)_global.isChorusActivated;
2672 MusECore::MidiPlayEvent evChorusAct(0, 0, MusECore::ME_SYSEX,(const unsigned char*)dataChorusAct, 2);
2673 _gui->writeEvent(evChorusAct);
2674 setChorusReturn((int)data[NUM_CHORUS_RETURN]);
2675 unsigned char *dataChorusRet = new unsigned char[2];
2676 dataChorusRet[0]=SYSEX_CHORUSRETURN;
2677 dataChorusRet[1]=(unsigned char)getChorusReturn();
2678 MusECore::MidiPlayEvent evChorusRet(0, 0, MusECore::ME_SYSEX,(const unsigned char*)dataChorusRet, 2);
2679 _gui->writeEvent(evChorusRet);
2680 p = MusESimplePlugin::plugins.find((const char*)&data[NUM_CHORUS_LIB],
2681 (const char*)&data[NUM_CHORUS_LABEL]);
2682 if(p) {
2683 initPluginChorus(p);
2684 for(int i = 0; i < (int)_pluginIChorus->plugin()->parameter(); i++) {
2685 float val;
2686 //memcpy(&val, &data[(data[3] == SYSEX_INIT_DATA_VERSION_2 ? NUM_CONFIGLENGTH : NUM_DELAY_WET_DRY_MIX) // HACK
2687 memcpy(&val, &data[NUM_CONFIGLENGTH
2688 + sizeof(float)*(int)data[NUM_REVERB_PARAM_NBR]
2689 + sizeof(float)*i],
2690 sizeof(float));
2691 _pluginIChorus->setParam(i, val);
2692 }
2693 char dataBuildCho;
2694 dataBuildCho = SYSEX_BUILDGUICHORUS;
2695 MusECore::MidiPlayEvent evSysexBuildCho(0, 0, MusECore::ME_SYSEX,
2696 (const unsigned char*)&dataBuildCho, 1);
2697 _gui->writeEvent(evSysexBuildCho);
2698 }
2699 else _pluginIChorus = NULL;
2700 //delay
2701 _global.isDelayActivated = (bool)data[NUM_IS_DELAY_ON];
2702 unsigned char *dataDelayAct = new unsigned char[2];
2703 dataDelayAct[0]=SYSEX_DELAYACTIV;
2704 dataDelayAct[1]=(unsigned char)_global.isDelayActivated;
2705 MusECore::MidiPlayEvent evDelayAct(0, 0, MusECore::ME_SYSEX,(const unsigned char*)dataDelayAct, 2);
2706 _gui->writeEvent(evDelayAct);
2707 setDelayReturn((int)data[NUM_DELAY_RETURN]);
2708 unsigned char *dataDelayRet = new unsigned char[2];
2709 dataDelayRet[0]=SYSEX_DELAYRETURN;
2710 dataDelayRet[1]=(unsigned char)getDelayReturn();
2711 MusECore::MidiPlayEvent evDelayRet(0, 0, MusECore::ME_SYSEX,(const unsigned char*)dataDelayRet, 2);
2712 _gui->writeEvent(evDelayRet);
2713 //initPluginDelay(MusEGlobal::plugins.find("pandelay", "pandelay"));
2714 float delayfloat;
2715 memcpy(&delayfloat, &data[NUM_DELAY_BPM], sizeof(float));
2716 //setDelayBPM(delayfloat);
2717 if(_pluginIDelay) _pluginIDelay->setParam(0, delayfloat);
2718 char dataDelayBPM[sizeof(float)+1];
2719 dataDelayBPM[0] = SYSEX_DELAYBPM;
2720 memcpy(&dataDelayBPM[1], &delayfloat, sizeof(float));
2721 MusECore::MidiPlayEvent evSysexDelayBPM(0, 0, MusECore::ME_SYSEX,
2722 (const unsigned char*)dataDelayBPM,
2723 sizeof(float)+1);
2724 _gui->writeEvent(evSysexDelayBPM);
2725 memcpy(&delayfloat, &data[NUM_DELAY_BEATRATIO], sizeof(float));
2726 //setDelayBeatRatio(delayfloat);
2727 if(_pluginIDelay) _pluginIDelay->setParam(1, delayfloat);
2728 char dataDelayBeatRatio[sizeof(float)+1];
2729 dataDelayBeatRatio[0] = SYSEX_DELAYBEATRATIO;
2730 memcpy(&dataDelayBeatRatio[1], &delayfloat, sizeof(float));
2731 MusECore::MidiPlayEvent evSysexDelayBeatRatio(0, 0, MusECore::ME_SYSEX,
2732 (const unsigned char*)dataDelayBeatRatio,
2733 sizeof(float)+1);
2734 _gui->writeEvent(evSysexDelayBeatRatio);
2735 memcpy(&delayfloat, &data[NUM_DELAY_FEEDBACK], sizeof(float));
2736 //setDelayFeedback(delayfloat);
2737 if(_pluginIDelay) _pluginIDelay->setParam(2, delayfloat);
2738 char dataDelayFeedback[sizeof(float)+1];
2739 dataDelayFeedback[0] = SYSEX_DELAYFEEDBACK;
2740 memcpy(&dataDelayFeedback[1], &delayfloat, sizeof(float));
2741 MusECore::MidiPlayEvent evSysexDelayFeedback(0, 0, MusECore::ME_SYSEX,
2742 (const unsigned char*)dataDelayFeedback,
2743 sizeof(float)+1);
2744 _gui->writeEvent(evSysexDelayFeedback);
2745 memcpy(&delayfloat, &data[NUM_DELAY_LFO_FREQ], sizeof(float));
2746 //setDelayLFOFreq(delayfloat);
2747 if(_pluginIDelay) _pluginIDelay->setParam(3, delayfloat);
2748 char dataDelayLFOFreq[sizeof(float)+1];
2749 dataDelayLFOFreq[0] = SYSEX_DELAYLFOFREQ;
2750 memcpy(&dataDelayLFOFreq[1], &delayfloat, sizeof(float));
2751 MusECore::MidiPlayEvent evSysexDelayLFOFreq(0, 0, MusECore::ME_SYSEX,
2752 (const unsigned char*)dataDelayLFOFreq,
2753 sizeof(float)+1);
2754 _gui->writeEvent(evSysexDelayLFOFreq);
2755 memcpy(&delayfloat, &data[NUM_DELAY_LFO_DEPTH], sizeof(float));
2756 //setDelayLFODepth(delayfloat);
2757 if(_pluginIDelay) _pluginIDelay->setParam(4, delayfloat);
2758 char dataDelayLFODepth[sizeof(float)+1];
2759 dataDelayLFODepth[0] = SYSEX_DELAYLFODEPTH;
2760 memcpy(&dataDelayLFODepth[1], &delayfloat, sizeof(float));
2761 MusECore::MidiPlayEvent evSysexDelayLFODepth(0, 0, MusECore::ME_SYSEX,
2762 (const unsigned char*)dataDelayLFODepth,
2763 sizeof(float)+1);
2764 _gui->writeEvent(evSysexDelayLFODepth);
2765
2766 // if(data[3] == SYSEX_INIT_DATA_VERSION_2)
2767 // {
2768 // memcpy(&delayfloat, &data[NUM_DELAY_WET_DRY_MIX], sizeof(float));
2769 // //setDelayLFODepth(delayfloat);
2770 // if(_pluginIDelay) _pluginIDelay->putParam(5, delayfloat);
2771 // char dataDelayWetDryMix[sizeof(float)+1];
2772 // dataDelayWetDryMix[0] = SYSEX_DELAYWETDRYMIX;
2773 // memcpy(&dataDelayWetDryMix[1], &delayfloat, sizeof(float));
2774 // MusECore::MidiPlayEvent evSysexDelayWetDryMix(0, 0, MusECore::ME_SYSEX,
2775 // (const unsigned char*)dataDelayWetDryMix,
2776 // sizeof(float)+1);
2777 // _gui->writeEvent(evSysexDelayWetDryMix);
2778 // }
2779
2780 //load the set compressed
2781 int offset =
2782 //(data[3] == SYSEX_INIT_DATA_VERSION_2 ? NUM_CONFIGLENGTH : NUM_DELAY_WET_DRY_MIX) // HACK
2783 NUM_CONFIGLENGTH
2784 + sizeof(float)*(int)data[NUM_REVERB_PARAM_NBR]
2785 + sizeof(float)*(int)data[NUM_CHORUS_PARAM_NBR];
2786 QByteArray baComp = QByteArray((const char*)&data[offset], length-offset);
2787
2788 //uncompress the set
2789 QByteArray baUncomp = qUncompress(baComp);
2790
2791 //save the set in a temporary file and
2792 // read the XML file and create DOM tree
2793 QTemporaryFile file;
2794 file.open();
2795 file.write(baUncomp);
2796 QDomDocument domTree;
2797 file.reset(); //seek the start of the file
2798 domTree.setContent(&file);
2799 file.close();
2800 QDomNode node = domTree.documentElement();
2801
2802 while (!node.isNull()) {
2803 QDomElement e = node.toElement();
2804 if (e.isNull())
2805 continue;
2806 if (e.tagName() == "deicsOnzeSet") {
2807 QString version = e.attribute(QString("version"));
2808 if (version == "1.0") {
2809 for(int c = 0; c < NBRCHANNELS; c++) _preset[c]=_initialPreset;
2810 //read the set
2811 if((bool)data[NUM_SAVEONLYUSED]) {
2812 //printf("Mini\n");
2813 //updateSaveOnlyUsed(true);
2814 }
2815 else {
2816 //printf("Huge\n");
2817 while(!_set->_categoryVector.empty())
2818 delete(*_set->_categoryVector.begin());
2819 //updateSaveOnlyUsed(false);
2820 }
2821 _set->readSet(node.firstChild());
2822 //display load preset
2823 //setSet();
2824 }
2825 else printf("Wrong set version : %s\n",
2826 version.toLatin1().constData());
2827 }
2828 node = node.nextSibling();
2829 }
2830 //send sysex to the gui to load the set (actually not because it doesn't
2831 //work -the code is just zapped in the middle???-, so it is done above
2832 //int dL=2+baUncomp.size();
2833 int dL = 2;
2834 char dataSend[dL];
2835 dataSend[0]=SYSEX_LOADSET;
2836 dataSend[1]=data[NUM_SAVEONLYUSED];
2837 //for(int i=2; i<dL; i++) dataSend[i]=baUncop.at(i-2);
2838 MusECore::MidiPlayEvent evSysex(0, 0, MusECore::ME_SYSEX,(const unsigned char*)dataSend, dL);
2839 _gui->writeEvent(evSysex);
2840
2841 //select programs per channel
2842 for(int c = 0; c < NBRCHANNELS; c++) {
2843 int hbank=(int)data[NUM_CURRENTHBANK+c];
2844 int lbank=(int)data[NUM_CURRENTLBANK+c];
2845 int prog=(int)data[NUM_CURRENTPROG+c];
2846 programSelect(c, hbank, lbank, prog);
2847 int val=prog+(lbank<<8)+(hbank<<16);
2848 MusECore::MidiPlayEvent evProgSel(0, 0, c, MusECore::ME_CONTROLLER, MusECore::CTRL_PROGRAM, val);
2849 _gui->writeEvent(evProgSel);
2850 }
2851
2852 }
2853 //---------------------------------------------------------
2854 // sysex
2855 //---------------------------------------------------------
sysex(int length,const unsigned char * data)2856 bool DeicsOnze::sysex(int length, const unsigned char* data) {
2857 sysex(length, data, false);
2858 return false;
2859 }
sysex(int length,const unsigned char * data,bool fromGui)2860 bool DeicsOnze::sysex(int length, const unsigned char* data, bool fromGui) {
2861
2862 if(length < 3 || data[0] != MUSE_SYNTH_SYSEX_MFG_ID
2863 || data[1] != DEICSONZE_UNIQUE_ID)
2864 {
2865 #ifdef DEICSONZE_DEBUG
2866 printf("MusE DeicsOnze: Unknown sysex header\n");
2867 #endif
2868 return false;
2869 }
2870
2871 int l = length - 2;
2872 const unsigned char* d = data + 2;
2873 int cmd=d[0];
2874 int index;
2875 float f;
2876 switch(cmd) {
2877 case SYSEX_INIT_DATA:
2878 parseInitData(length, data);
2879 //parseInitData(l, d);
2880 break;
2881 case SYSEX_MASTERVOL:
2882 setMasterVol((int)d[1]);
2883 if(!fromGui) {
2884 MusECore::MidiPlayEvent evSysex(0, 0, MusECore::ME_SYSEX, d, l);
2885 _gui->writeEvent(evSysex);
2886 }
2887 break;
2888 //case SYSEX_CHANNELNUM:
2889 //_global.channelNum = (char)d[1];
2890 //if(!fromGui) {
2891 // MusECore::MidiPlayEvent evSysex(0, 0, MusECore::ME_SYSEX, d, l);
2892 // _gui->writeEvent(evSysex);
2893 //}
2894 //break;
2895 case SYSEX_QUALITY:
2896 setQuality((Quality)d[1]);
2897 if(!fromGui) {
2898 MusECore::MidiPlayEvent evSysex(0, 0, MusECore::ME_SYSEX, d, l);
2899 _gui->writeEvent(evSysex);
2900 }
2901 break;
2902 case SYSEX_FILTER:
2903 setFilter((bool)d[1]);
2904 if(!fromGui) {
2905 MusECore::MidiPlayEvent evSysex(0, 0, MusECore::ME_SYSEX, d, l);
2906 _gui->writeEvent(evSysex);
2907 }
2908 break;
2909 case SYSEX_FONTSIZE:
2910 _global.fontSize = (int)d[1];
2911 if(!fromGui) {
2912 MusECore::MidiPlayEvent evSysex(0, 0, MusECore::ME_SYSEX, d, l);
2913 _gui->writeEvent(evSysex);
2914 }
2915 break;
2916 case SYSEX_SAVECONFIG:
2917 _saveConfig = (bool)d[1];
2918 if(!fromGui) {
2919 MusECore::MidiPlayEvent evSysex(0, 0, MusECore::ME_SYSEX, d, l);
2920 _gui->writeEvent(evSysex);
2921 }
2922 break;
2923 case SYSEX_SAVEONLYUSED:
2924 _saveOnlyUsed = (bool)d[1];
2925 if(!fromGui) {
2926 MusECore::MidiPlayEvent evSysex(0, 0, MusECore::ME_SYSEX, d, l);
2927 _gui->writeEvent(evSysex);
2928 }
2929 break;
2930 case SYSEX_ISINITSET:
2931 _isInitSet = (bool)d[1];
2932 if(!fromGui) {
2933 MusECore::MidiPlayEvent evSysex(0, 0, MusECore::ME_SYSEX, d, l);
2934 _gui->writeEvent(evSysex);
2935 }
2936 break;
2937 case SYSEX_INITSETPATH:
2938 _initSetPath = (char*)&d[1];
2939 if(!fromGui) {
2940 MusECore::MidiPlayEvent evSysex(0, 0, MusECore::ME_SYSEX, d, l);
2941 _gui->writeEvent(evSysex);
2942 }
2943 break;
2944 case SYSEX_ISBACKGROUNDPIX:
2945 _isBackgroundPix = (bool)d[1];
2946 if(!fromGui) {
2947 MusECore::MidiPlayEvent evSysex(0, 0, MusECore::ME_SYSEX, d, l);
2948 _gui->writeEvent(evSysex);
2949 }
2950 break;
2951 case SYSEX_BACKGROUNDPIXPATH:
2952 _backgroundPixPath = (char*)&d[1];
2953 if(!fromGui) {
2954 MusECore::MidiPlayEvent evSysex(0, 0, MusECore::ME_SYSEX, d, l);
2955 _gui->writeEvent(evSysex);
2956 }
2957 break;
2958 case SYSEX_PANIC:
2959 resetVoices();
2960 break;
2961 case SYSEX_CHORUSACTIV:
2962 _global.isChorusActivated = (bool)d[1];
2963 if(!fromGui) {
2964 MusECore::MidiPlayEvent evSysex(0, 0, MusECore::ME_SYSEX, d, l);
2965 _gui->writeEvent(evSysex);
2966 }
2967 break;
2968 case SYSEX_CHORUSPARAM:
2969 index = (int)d[1];
2970 memcpy(&f, &d[2], sizeof(float));
2971 setChorusParam(index, f);
2972 if(!fromGui) {
2973 MusECore::MidiPlayEvent evSysex(0, 0, MusECore::ME_SYSEX, d, l);
2974 _gui->writeEvent(evSysex);
2975 }
2976 break;
2977 case SYSEX_REVERBACTIV:
2978 _global.isReverbActivated = (bool)d[1];
2979 if(!fromGui) {
2980 MusECore::MidiPlayEvent evSysex(0, 0, MusECore::ME_SYSEX, d, l);
2981 _gui->writeEvent(evSysex);
2982 }
2983 break;
2984 case SYSEX_REVERBPARAM:
2985 index = (int)d[1];
2986 memcpy(&f, &d[2], sizeof(float));
2987 setReverbParam(index, f);
2988 if(!fromGui) {
2989 MusECore::MidiPlayEvent evSysex(0, 0, MusECore::ME_SYSEX, d, l);
2990 _gui->writeEvent(evSysex);
2991 }
2992 break;
2993 case SYSEX_DELAYACTIV:
2994 _global.isDelayActivated = (bool)d[1];
2995 if(!fromGui) {
2996 MusECore::MidiPlayEvent evSysex(0, 0, MusECore::ME_SYSEX, d, l);
2997 _gui->writeEvent(evSysex);
2998 }
2999 break;
3000 case SYSEX_CHORUSRETURN:
3001 setChorusReturn((int)d[1]);
3002 if(!fromGui) {
3003 MusECore::MidiPlayEvent evSysex(0, 0, MusECore::ME_SYSEX, d, l);
3004 _gui->writeEvent(evSysex);
3005 }
3006 break;
3007 case SYSEX_REVERBRETURN:
3008 setReverbReturn((int)d[1]);
3009 if(!fromGui) {
3010 MusECore::MidiPlayEvent evSysex(0, 0, MusECore::ME_SYSEX, d, l);
3011 _gui->writeEvent(evSysex);
3012 }
3013 break;
3014 case SYSEX_DELAYRETURN:
3015 setDelayReturn((int)d[1]);
3016 if(!fromGui) {
3017 MusECore::MidiPlayEvent evSysex(0, 0, MusECore::ME_SYSEX, d, l);
3018 _gui->writeEvent(evSysex);
3019 }
3020 break;
3021 case SYSEX_SELECTREVERB:
3022 MusESimplePlugin::Plugin* pluginReverb;
3023 memcpy(&pluginReverb, &d[1], sizeof(MusESimplePlugin::Plugin*));
3024 initPluginReverb(pluginReverb);
3025 break;
3026 case SYSEX_SELECTCHORUS:
3027 MusESimplePlugin::Plugin* pluginChorus;
3028 memcpy(&pluginChorus, &d[1], sizeof(MusESimplePlugin::Plugin*));
3029 initPluginChorus(pluginChorus);
3030 break;
3031 case SYSEX_DELAYBPM:
3032 memcpy(&f, &d[1], sizeof(float));
3033 setDelayBPM(f);
3034 if(!fromGui) {
3035 MusECore::MidiPlayEvent evSysex(0, 0, MusECore::ME_SYSEX, d, l);
3036 _gui->writeEvent(evSysex);
3037 }
3038 break;
3039 case SYSEX_DELAYBEATRATIO:
3040 memcpy(&f, &d[1], sizeof(float));
3041 setDelayBeatRatio(f);
3042 if(!fromGui) {
3043 MusECore::MidiPlayEvent evSysex(0, 0, MusECore::ME_SYSEX, d, l);
3044 _gui->writeEvent(evSysex);
3045 }
3046 break;
3047 case SYSEX_DELAYFEEDBACK:
3048 memcpy(&f, &d[1], sizeof(float));
3049 setDelayFeedback(f);
3050 if(!fromGui) {
3051 MusECore::MidiPlayEvent evSysex(0, 0, MusECore::ME_SYSEX, d, l);
3052 _gui->writeEvent(evSysex);
3053 }
3054 break;
3055 case SYSEX_DELAYLFOFREQ:
3056 memcpy(&f, &d[1], sizeof(float));
3057 setDelayLFOFreq(f);
3058 if(!fromGui) {
3059 MusECore::MidiPlayEvent evSysex(0, 0, MusECore::ME_SYSEX, d, l);
3060 _gui->writeEvent(evSysex);
3061 }
3062 break;
3063 case SYSEX_DELAYLFODEPTH:
3064 memcpy(&f, &d[1], sizeof(float));
3065 setDelayLFODepth(f);
3066 if(!fromGui) {
3067 MusECore::MidiPlayEvent evSysex(0, 0, MusECore::ME_SYSEX, d, l);
3068 _gui->writeEvent(evSysex);
3069 }
3070 break;
3071 case SYSEX_DELAYWETDRYMIX:
3072 memcpy(&f, &d[1], sizeof(float));
3073 setDelayDryWet(f);
3074 if(!fromGui) {
3075 MusECore::MidiPlayEvent evSysex(0, 0, MusECore::ME_SYSEX, d, l);
3076 _gui->writeEvent(evSysex);
3077 }
3078 break;
3079 default:
3080 break;
3081 }
3082 return false;
3083 }
3084 //---------------------------------------------------------
3085 // setController
3086 //---------------------------------------------------------
setController(int channel,int id,int val)3087 bool DeicsOnze::setController(int channel, int id, int val) {
3088 setController(channel, id, val, false);
3089 return false;
3090 }
setController(int ch,int ctrl,int val,bool fromGui)3091 bool DeicsOnze::setController(int ch, int ctrl, int val, bool fromGui) {
3092 int deiPan, k=0;
3093 if(_global.channel[ch].isEnable || ctrl==CTRL_CHANNELENABLE) {
3094 if(ctrl>=CTRL_AR && ctrl<CTRL_ALG) {
3095 k=(ctrl-CTRLOFFSET)/DECAPAR1;
3096 ctrl=ctrl-DECAPAR1*k;
3097 }
3098 else if(ctrl>CTRL_PL3 && ctrl<CTRL_REVERBRATE) {
3099 k=(ctrl-CTRLOFFSET-100)/DECAPAR2;
3100 ctrl=ctrl-DECAPAR2*k;
3101 }
3102 switch(ctrl) {
3103 case CTRL_AR:
3104 _preset[ch]->setIsUsed(true);
3105 _preset[ch]->eg[k].ar=val;
3106 if(!fromGui) {
3107 MusECore::MidiPlayEvent ev(0, 0, ch,MusECore::ME_CONTROLLER,CTRL_AR+k*DECAPAR1,val);
3108 _gui->writeEvent(ev);
3109 }
3110 break;
3111 case CTRL_D1R:
3112 _preset[ch]->setIsUsed(true);
3113 _preset[ch]->eg[k].d1r=val;
3114 if(!fromGui) {
3115 MusECore::MidiPlayEvent ev(0, 0, ch,MusECore::ME_CONTROLLER,CTRL_D1R+k*DECAPAR1,val);
3116 _gui->writeEvent(ev);
3117 }
3118 break;
3119 case CTRL_D2R:
3120 _preset[ch]->setIsUsed(true);
3121 _preset[ch]->eg[k].d2r=val;
3122 if(!fromGui) {
3123 MusECore::MidiPlayEvent ev(0, 0, ch,MusECore::ME_CONTROLLER,CTRL_D2R+k*DECAPAR1,val);
3124 _gui->writeEvent(ev);
3125 }
3126 break;
3127 case CTRL_RR:
3128 _preset[ch]->setIsUsed(true);
3129 _preset[ch]->eg[k].rr=val;
3130 if(!fromGui) {
3131 MusECore::MidiPlayEvent ev(0, 0, ch,MusECore::ME_CONTROLLER,CTRL_RR+k*DECAPAR1,val);
3132 _gui->writeEvent(ev);
3133 }
3134 break;
3135 case CTRL_D1L:
3136 _preset[ch]->setIsUsed(true);
3137 _preset[ch]->eg[k].d1l=val;
3138 if(!fromGui) {
3139 MusECore::MidiPlayEvent ev(0, 0, ch,MusECore::ME_CONTROLLER,CTRL_D1L+k*DECAPAR1,val);
3140 _gui->writeEvent(ev);
3141 }
3142 break;
3143 case CTRL_LS:
3144 _preset[ch]->setIsUsed(true);
3145 _preset[ch]->scaling.level[k]=val;
3146 if(!fromGui) {
3147 MusECore::MidiPlayEvent ev(0, 0, ch,MusECore::ME_CONTROLLER,CTRL_LS+k*DECAPAR1,val);
3148 _gui->writeEvent(ev);
3149 }
3150 break;
3151 case CTRL_RS:
3152 _preset[ch]->setIsUsed(true);
3153 _preset[ch]->scaling.rate[k]=val;
3154 if(!fromGui) {
3155 MusECore::MidiPlayEvent ev(0, 0, ch,MusECore::ME_CONTROLLER,CTRL_RS+k*DECAPAR1,val);
3156 _gui->writeEvent(ev);
3157 }
3158 break;
3159 case CTRL_EBS:
3160 _preset[ch]->setIsUsed(true);
3161 _preset[ch]->sensitivity.egBias[k]=val;
3162 if(!fromGui) {
3163 MusECore::MidiPlayEvent ev(0, 0, ch,MusECore::ME_CONTROLLER,CTRL_EBS+k*DECAPAR1,val);
3164 _gui->writeEvent(ev);
3165 }
3166 break;
3167 case CTRL_AME:
3168 _preset[ch]->setIsUsed(true);
3169 _preset[ch]->sensitivity.ampOn[k]=val==1;
3170 if(!fromGui) {
3171 MusECore::MidiPlayEvent ev(0, 0, ch,MusECore::ME_CONTROLLER,CTRL_AME+k*DECAPAR1,val);
3172 _gui->writeEvent(ev);
3173 }
3174 break;
3175 case CTRL_KVS:
3176 _preset[ch]->setIsUsed(true);
3177 _preset[ch]->sensitivity.keyVelocity[k]=val;
3178 if(!fromGui) {
3179 MusECore::MidiPlayEvent ev(0, 0, ch,MusECore::ME_CONTROLLER,CTRL_KVS+k*DECAPAR1,val);
3180 _gui->writeEvent(ev);
3181 }
3182 break;
3183 case CTRL_OUT:
3184 _preset[ch]->setIsUsed(true);
3185 _preset[ch]->outLevel[k]=val;
3186 setOutLevel(k);
3187 if(!fromGui) {
3188 MusECore::MidiPlayEvent ev(0, 0, ch,MusECore::ME_CONTROLLER,CTRL_OUT+k*DECAPAR1,val);
3189 _gui->writeEvent(ev);
3190 }
3191 break;
3192 case CTRL_RATIO:
3193 _preset[ch]->setIsUsed(true);
3194 _preset[ch]->frequency[k].ratio=((double)val)/100.0;
3195 if(!fromGui) {
3196 MusECore::MidiPlayEvent ev(0, 0, ch,MusECore::ME_CONTROLLER,
3197 CTRL_RATIO+k*DECAPAR1,val);
3198 _gui->writeEvent(ev);
3199 }
3200 break;
3201 case CTRL_DET:
3202 _preset[ch]->setIsUsed(true);
3203 _preset[ch]->detune[k]=val;
3204 if(!fromGui) {
3205 MusECore::MidiPlayEvent ev(0, 0, ch,MusECore::ME_CONTROLLER,CTRL_DET+k*DECAPAR1,val);
3206 _gui->writeEvent(ev);
3207 }
3208 break;
3209 case CTRL_ALG:
3210 _preset[ch]->setIsUsed(true);
3211 _preset[ch]->algorithm=(Algorithm)val;
3212 if(!fromGui) {
3213 MusECore::MidiPlayEvent ev(0, 0, ch,MusECore::ME_CONTROLLER,CTRL_ALG,val);
3214 _gui->writeEvent(ev);
3215 }
3216 break;
3217 case CTRL_FEEDBACK:
3218 _preset[ch]->setIsUsed(true);
3219 _preset[ch]->feedback=val;
3220 setFeedback(ch);
3221 if(!fromGui) {
3222 MusECore::MidiPlayEvent ev(0, 0, ch,MusECore::ME_CONTROLLER,CTRL_FEEDBACK,val);
3223 _gui->writeEvent(ev);
3224 }
3225 break;
3226 case CTRL_SPEED:
3227 _preset[ch]->setIsUsed(true);
3228 _preset[ch]->lfo.speed=val;
3229 setLfo(ch);
3230 if(!fromGui) {
3231 MusECore::MidiPlayEvent ev(0, 0, ch,MusECore::ME_CONTROLLER,CTRL_SPEED,val);
3232 _gui->writeEvent(ev);
3233 }
3234 break;
3235 case CTRL_DELAY:
3236 _preset[ch]->setIsUsed(true);
3237 _preset[ch]->lfo.delay=val;
3238 setLfo(ch);
3239 if(!fromGui) {
3240 MusECore::MidiPlayEvent ev(0, 0, ch,MusECore::ME_CONTROLLER,CTRL_DELAY,val);
3241 _gui->writeEvent(ev);
3242 }
3243 break;
3244 case CTRL_PMODDEPTH:
3245 _preset[ch]->setIsUsed(true);
3246 _preset[ch]->lfo.pModDepth=val;
3247 setLfo(ch);
3248 if(!fromGui) {
3249 MusECore::MidiPlayEvent ev(0, 0, ch,MusECore::ME_CONTROLLER,CTRL_PMODDEPTH,val);
3250 _gui->writeEvent(ev);
3251 }
3252 break;
3253 case CTRL_AMODDEPTH:
3254 _preset[ch]->setIsUsed(true);
3255 _preset[ch]->lfo.aModDepth=val;
3256 setLfo(ch);
3257 if(!fromGui) {
3258 MusECore::MidiPlayEvent ev(0, 0, ch,MusECore::ME_CONTROLLER,CTRL_AMODDEPTH,val);
3259 _gui->writeEvent(ev);
3260 }
3261 break;
3262 case CTRL_SYNC:
3263 _preset[ch]->setIsUsed(true);
3264 _preset[ch]->lfo.sync=val==1;
3265 setLfo(ch);
3266 if(!fromGui) {
3267 MusECore::MidiPlayEvent ev(0, 0, ch,MusECore::ME_CONTROLLER,CTRL_SYNC,val);
3268 _gui->writeEvent(ev);
3269 }
3270 break;
3271 case CTRL_WAVE:
3272 _preset[ch]->setIsUsed(true);
3273 _preset[ch]->lfo.wave=(Wave)val;
3274 setLfo(ch);
3275 if(!fromGui) {
3276 MusECore::MidiPlayEvent ev(0, 0, ch,MusECore::ME_CONTROLLER,CTRL_WAVE,val);
3277 _gui->writeEvent(ev);
3278 }
3279 break;
3280 case CTRL_PMODSENS:
3281 _preset[ch]->setIsUsed(true);
3282 _preset[ch]->sensitivity.pitch=val;
3283 setLfo(ch);
3284 if(!fromGui) {
3285 MusECore::MidiPlayEvent ev(0, 0, ch,MusECore::ME_CONTROLLER,CTRL_PMODSENS,val);
3286 _gui->writeEvent(ev);
3287 }
3288 break;
3289 case CTRL_AMS:
3290 _preset[ch]->setIsUsed(true);
3291 _preset[ch]->sensitivity.amplitude=val;
3292 setLfo(ch);
3293 if(!fromGui) {
3294 MusECore::MidiPlayEvent ev(0, 0, ch,MusECore::ME_CONTROLLER,CTRL_AMS,val);
3295 _gui->writeEvent(ev);
3296 }
3297 break;
3298 case CTRL_TRANSPOSE:
3299 _preset[ch]->setIsUsed(true);
3300 _preset[ch]->function.transpose=val;
3301 if(!fromGui) {
3302 MusECore::MidiPlayEvent ev(0, 0, ch,MusECore::ME_CONTROLLER,CTRL_TRANSPOSE,val);
3303 _gui->writeEvent(ev);
3304 }
3305 break;
3306 case CTRL_POLYMODE:
3307 _preset[ch]->setIsUsed(true);
3308 _preset[ch]->function.mode=(Mode)val;
3309 if(!fromGui) {
3310 MusECore::MidiPlayEvent ev(0, 0, ch,MusECore::ME_CONTROLLER,CTRL_POLYMODE,val);
3311 _gui->writeEvent(ev);
3312 }
3313 break;
3314 case CTRL_PBENDRANGE:
3315 _preset[ch]->setIsUsed(true);
3316 _preset[ch]->function.pBendRange=val;
3317 if(!fromGui) {
3318 MusECore::MidiPlayEvent ev(0, 0, ch,MusECore::ME_CONTROLLER,CTRL_PBENDRANGE,val);
3319 _gui->writeEvent(ev);
3320 }
3321 break;
3322 case CTRL_PORTAMODE:
3323 _preset[ch]->setIsUsed(true);
3324 _preset[ch]->function.portamento=(Portamento)val;
3325 if(!fromGui) {
3326 MusECore::MidiPlayEvent ev(0, 0, ch,MusECore::ME_CONTROLLER,CTRL_PORTAMODE,val);
3327 _gui->writeEvent(ev);
3328 }
3329 break;
3330 case CTRL_PORTATIME:
3331 _preset[ch]->setIsUsed(true);
3332 _preset[ch]->function.portamentoTime=val;
3333 if(!fromGui) {
3334 MusECore::MidiPlayEvent ev(0, 0, ch,MusECore::ME_CONTROLLER,CTRL_PORTATIME,val);
3335 _gui->writeEvent(ev);
3336 }
3337 break;
3338 case CTRL_FCVOLUME:
3339 _preset[ch]->setIsUsed(true);
3340 _preset[ch]->function.fcVolume=val;
3341 if(!fromGui) {
3342 MusECore::MidiPlayEvent ev(0, 0, ch,MusECore::ME_CONTROLLER,CTRL_FCVOLUME,val);
3343 _gui->writeEvent(ev);
3344 }
3345 break;
3346 case CTRL_FSW:
3347 _preset[ch]->setIsUsed(true);
3348 _preset[ch]->function.footSw=(FootSw)val;
3349 if(!fromGui) {
3350 MusECore::MidiPlayEvent ev(0, 0, ch,MusECore::ME_CONTROLLER,CTRL_FSW,val);
3351 _gui->writeEvent(ev);
3352 }
3353 break;
3354 case CTRL_MWPITCH:
3355 _preset[ch]->setIsUsed(true);
3356 _preset[ch]->function.mwPitch=val;
3357 if(!fromGui) {
3358 MusECore::MidiPlayEvent ev(0, 0, ch,MusECore::ME_CONTROLLER,CTRL_MWPITCH,val);
3359 _gui->writeEvent(ev);
3360 }
3361 break;
3362 case CTRL_MWAMPLITUDE:
3363 _preset[ch]->setIsUsed(true);
3364 _preset[ch]->function.mwAmplitude=val;
3365 if(!fromGui) {
3366 MusECore::MidiPlayEvent ev(0, 0, ch,MusECore::ME_CONTROLLER,CTRL_MWAMPLITUDE,val);
3367 _gui->writeEvent(ev);
3368 }
3369 break;
3370 case CTRL_BCPITCH:
3371 _preset[ch]->setIsUsed(true);
3372 _preset[ch]->function.bcPitch=val;
3373 if(!fromGui) {
3374 MusECore::MidiPlayEvent ev(0, 0, ch,MusECore::ME_CONTROLLER,CTRL_BCPITCH,val);
3375 _gui->writeEvent(ev);
3376 }
3377 break;
3378 case CTRL_BCAMPLITUDE:
3379 _preset[ch]->setIsUsed(true);
3380 _preset[ch]->function.bcAmplitude=val;
3381 if(!fromGui) {
3382 MusECore::MidiPlayEvent ev(0, 0, ch,MusECore::ME_CONTROLLER,CTRL_BCAMPLITUDE,val);
3383 _gui->writeEvent(ev);
3384 }
3385 break;
3386 case CTRL_BCPITCHBIAS:
3387 _preset[ch]->setIsUsed(true);
3388 _preset[ch]->function.bcPitchBias=val;
3389 if(!fromGui) {
3390 MusECore::MidiPlayEvent ev(0, 0, ch,MusECore::ME_CONTROLLER,CTRL_BCPITCHBIAS,val);
3391 _gui->writeEvent(ev);
3392 }
3393 break;
3394 case CTRL_BCEGBIAS:
3395 _preset[ch]->setIsUsed(true);
3396 _preset[ch]->function.bcEgBias=val;
3397 if(!fromGui) {
3398 MusECore::MidiPlayEvent ev(0, 0, ch,MusECore::ME_CONTROLLER,CTRL_BCEGBIAS,val);
3399 _gui->writeEvent(ev);
3400 }
3401 break;
3402 case CTRL_ATPITCH:
3403 _preset[ch]->setIsUsed(true);
3404 _preset[ch]->function.atPitch=val;
3405 if(!fromGui) {
3406 MusECore::MidiPlayEvent ev(0, 0, ch,MusECore::ME_CONTROLLER,CTRL_ATPITCH,val);
3407 _gui->writeEvent(ev);
3408 }
3409 break;
3410 case CTRL_ATAMPLITUDE:
3411 _preset[ch]->setIsUsed(true);
3412 _preset[ch]->function.atAmplitude=val;
3413 if(!fromGui) {
3414 MusECore::MidiPlayEvent ev(0, 0, ch,MusECore::ME_CONTROLLER,CTRL_ATAMPLITUDE,val);
3415 _gui->writeEvent(ev);
3416 }
3417 break;
3418 case CTRL_ATPITCHBIAS:
3419 _preset[ch]->setIsUsed(true);
3420 _preset[ch]->function.atPitchBias=val;
3421 if(!fromGui) {
3422 MusECore::MidiPlayEvent ev(0, 0, ch,MusECore::ME_CONTROLLER,CTRL_ATPITCHBIAS,val);
3423 _gui->writeEvent(ev);
3424 }
3425 break;
3426 case CTRL_ATEGBIAS:
3427 _preset[ch]->setIsUsed(true);
3428 _preset[ch]->function.atEgBias=val;
3429 if(!fromGui) {
3430 MusECore::MidiPlayEvent ev(0, 0, ch,MusECore::ME_CONTROLLER,CTRL_ATEGBIAS,val);
3431 _gui->writeEvent(ev);
3432 }
3433 break;
3434 case CTRL_PR1:
3435 _preset[ch]->setIsUsed(true);
3436 _preset[ch]->pitchEg.pr1=val;
3437 if(!fromGui) {
3438 MusECore::MidiPlayEvent ev(0, 0, ch,MusECore::ME_CONTROLLER,CTRL_PR1,val);
3439 _gui->writeEvent(ev);
3440 }
3441 break;
3442 case CTRL_PR2:
3443 _preset[ch]->setIsUsed(true);
3444 _preset[ch]->pitchEg.pr2=val;
3445 if(!fromGui) {
3446 MusECore::MidiPlayEvent ev(0, 0, ch,MusECore::ME_CONTROLLER,CTRL_PR2,val);
3447 _gui->writeEvent(ev);
3448 }
3449 break;
3450 case CTRL_PR3:
3451 _preset[ch]->setIsUsed(true);
3452 _preset[ch]->pitchEg.pr3=val;
3453 if(!fromGui) {
3454 MusECore::MidiPlayEvent ev(0, 0, ch,MusECore::ME_CONTROLLER,CTRL_PR3,val);
3455 _gui->writeEvent(ev);
3456 }
3457 break;
3458 case CTRL_PL1:
3459 _preset[ch]->setIsUsed(true);
3460 _preset[ch]->pitchEg.pl1=val;
3461 if(!fromGui) {
3462 MusECore::MidiPlayEvent ev(0, 0, ch,MusECore::ME_CONTROLLER,CTRL_PL1,val);
3463 _gui->writeEvent(ev);
3464 }
3465 break;
3466 case CTRL_PL2:
3467 _preset[ch]->setIsUsed(true);
3468 _preset[ch]->pitchEg.pl2=val;
3469 if(!fromGui) {
3470 MusECore::MidiPlayEvent ev(0, 0, ch,MusECore::ME_CONTROLLER,CTRL_PL2,val);
3471 _gui->writeEvent(ev);
3472 }
3473 break;
3474 case CTRL_PL3:
3475 _preset[ch]->setIsUsed(true);
3476 _preset[ch]->pitchEg.pl3=val;
3477 if(!fromGui) {
3478 MusECore::MidiPlayEvent ev(0, 0, ch,MusECore::ME_CONTROLLER,CTRL_PL3,val);
3479 _gui->writeEvent(ev);
3480 }
3481 break;
3482 case CTRL_FIX:
3483 _preset[ch]->setIsUsed(true);
3484 _preset[ch]->frequency[k].isFix=val==1;
3485 if(!fromGui) {
3486 MusECore::MidiPlayEvent ev(0, 0, ch,MusECore::ME_CONTROLLER,CTRL_FIX+k*DECAPAR2,val);
3487 _gui->writeEvent(ev);
3488 }
3489 break;
3490 case CTRL_FIXRANGE:
3491 _preset[ch]->setIsUsed(true);
3492 _preset[ch]->frequency[k].freq=((double)val)/100.0;
3493 if(!fromGui) {
3494 MusECore::MidiPlayEvent ev(0, 0, ch,MusECore::ME_CONTROLLER,
3495 CTRL_FIXRANGE+k*DECAPAR2,val);
3496 _gui->writeEvent(ev);
3497 }
3498 break;
3499 case CTRL_OSW:
3500 _preset[ch]->setIsUsed(true);
3501 _preset[ch]->oscWave[k]=(OscWave)val;
3502 if(!fromGui) {
3503 MusECore::MidiPlayEvent ev(0, 0, ch,MusECore::ME_CONTROLLER,CTRL_OSW+k*DECAPAR2,val);
3504 _gui->writeEvent(ev);
3505 }
3506 break;
3507 case CTRL_SHFT:
3508 _preset[ch]->setIsUsed(true);
3509 _preset[ch]->eg[k].egShift=(egShiftValue)val;
3510 if(!fromGui) {
3511 MusECore::MidiPlayEvent ev(0, 0, ch,MusECore::ME_CONTROLLER,CTRL_SHFT+k*DECAPAR2,val);
3512 _gui->writeEvent(ev);
3513 }
3514 break;
3515 case CTRL_REVERBRATE:
3516 _preset[ch]->setIsUsed(true);
3517 _preset[ch]->function.reverbRate=val;
3518 if(!fromGui) {
3519 MusECore::MidiPlayEvent ev(0, 0, ch,MusECore::ME_CONTROLLER,CTRL_REVERBRATE,val);
3520 _gui->writeEvent(ev);
3521 }
3522 break;
3523 case CTRL_FCPITCH:
3524 _preset[ch]->setIsUsed(true);
3525 _preset[ch]->function.fcPitch=val;
3526 if(!fromGui) {
3527 MusECore::MidiPlayEvent ev(0, 0, ch,MusECore::ME_CONTROLLER,CTRL_FCPITCH,val);
3528 _gui->writeEvent(ev);
3529 }
3530 break;
3531 case CTRL_FCAMPLITUDE:
3532 _preset[ch]->setIsUsed(true);
3533 _preset[ch]->function.fcAmplitude=val;
3534 if(!fromGui) {
3535 MusECore::MidiPlayEvent ev(0, 0, ch,MusECore::ME_CONTROLLER,CTRL_FCAMPLITUDE,val);
3536 _gui->writeEvent(ev);
3537 }
3538 break;
3539 case CTRL_CHANNELENABLE:
3540 setChannelEnable(ch, (bool)val);
3541 if(!fromGui) {
3542 MusECore::MidiPlayEvent ev(0, 0, ch,MusECore::ME_CONTROLLER,CTRL_CHANNELENABLE,val);
3543 _gui->writeEvent(ev);
3544 }
3545 break;
3546 case CTRL_CHANNELDETUNE:
3547 _preset[ch]->setIsUsed(true);
3548 setChannelDetune(ch, val);
3549 if(!fromGui) {
3550 MusECore::MidiPlayEvent ev(0, 0, ch,MusECore::ME_CONTROLLER,CTRL_CHANNELDETUNE,val);
3551 _gui->writeEvent(ev);
3552 }
3553 break;
3554 case CTRL_CHANNELVOLUME:
3555 setChannelVol(ch, val);
3556 applyChannelAmp(ch);
3557 if(!fromGui) {
3558 MusECore::MidiPlayEvent ev(0, 0, ch,MusECore::ME_CONTROLLER,CTRL_CHANNELVOLUME,val);
3559 _gui->writeEvent(ev);
3560 }
3561 break;
3562 case CTRL_NBRVOICES:
3563 setNbrVoices(ch, val);
3564 if(!fromGui) {
3565 MusECore::MidiPlayEvent ev(0, 0, ch, MusECore::ME_CONTROLLER, CTRL_NBRVOICES, val);
3566 _gui->writeEvent(ev);
3567 }
3568 break;
3569 case MusECore::CTRL_PROGRAM: {
3570 int hbank = (val & 0xff0000) >> 16;
3571 int lbank = (val & 0xff00) >> 8;
3572 int prog = val & 0x7f;
3573 if (hbank > 127) // map "dont care" to 0
3574 hbank = 0;
3575 if (lbank > 127)
3576 lbank = 0;
3577 programSelect(ch, hbank, lbank, prog);
3578 _preset[ch]->setIsUsed(true);//TODO : not sure to put that
3579 if(!fromGui) {
3580 MusECore::MidiPlayEvent ev(0, 0, ch, MusECore::ME_CONTROLLER, MusECore::CTRL_PROGRAM, val);
3581 _gui->writeEvent(ev);
3582 }
3583 } break;
3584 case MusECore::CTRL_MODULATION:
3585 setModulation(ch, val);
3586 if(!fromGui) {
3587 MusECore::MidiPlayEvent ev(0, 0, ch, MusECore::ME_CONTROLLER, MusECore::CTRL_MODULATION, val);
3588 _gui->writeEvent(ev);
3589 }
3590 break;
3591 case MusECore::CTRL_PITCH:
3592 setPitchBendCoef(ch, val);
3593 break;
3594 case MusECore::CTRL_PANPOT:
3595 _preset[ch]->setIsUsed(true);
3596 deiPan = val*2*MAXCHANNELPAN/127-MAXCHANNELPAN;
3597 setChannelPan(ch, deiPan);
3598 applyChannelAmp(ch);
3599 if(!fromGui) {
3600 MusECore::MidiPlayEvent ev(0, 0, ch, MusECore::ME_CONTROLLER, CTRL_CHANNELPAN, deiPan);
3601 _gui->writeEvent(ev);
3602 }
3603 break;
3604 case CTRL_CHANNELPAN:
3605 _preset[ch]->setIsUsed(true);
3606 setChannelPan(ch, val);
3607 applyChannelAmp(ch);
3608 if(!fromGui) {
3609 MusECore::MidiPlayEvent ev(0, 0, ch, MusECore::ME_CONTROLLER, CTRL_CHANNELPAN, val);
3610 _gui->writeEvent(ev);
3611 }
3612 break;
3613 case CTRL_FINEBRIGHTNESS:
3614 _preset[ch]->setIsUsed(true);
3615 setChannelBrightness(ch, val);
3616 setOutLevel(ch);
3617 if(!fromGui) {
3618 MusECore::MidiPlayEvent ev(0, 0, ch, MusECore::ME_CONTROLLER, CTRL_FINEBRIGHTNESS, val);
3619 _gui->writeEvent(ev);
3620 }
3621 break;
3622 case MusECore::CTRL_BRIGHTNESS:
3623 _preset[ch]->setIsUsed(true);
3624 setChannelBrightness(ch, val*(MIDFINEBRIGHTNESS/MIDBRIGHTNESS));
3625 setOutLevel(ch);
3626 if(!fromGui) {
3627 MusECore::MidiPlayEvent
3628 ev(0, 0, ch,MusECore::ME_CONTROLLER,CTRL_FINEBRIGHTNESS,getChannelBrightness(ch));
3629 _gui->writeEvent(ev);
3630 }
3631 break;
3632 case MusECore::CTRL_ATTACK_TIME:
3633 _preset[ch]->setIsUsed(true);
3634 setChannelAttack(ch, val);
3635 setEnvAttack(ch);
3636 if(!fromGui) {
3637 MusECore::MidiPlayEvent ev(0, 0, ch, MusECore::ME_CONTROLLER, MusECore::CTRL_ATTACK_TIME, val);
3638 _gui->writeEvent(ev);
3639 }
3640 break;
3641 case MusECore::CTRL_RELEASE_TIME:
3642 _preset[ch]->setIsUsed(true);
3643 setChannelRelease(ch, val);
3644 setEnvRelease(ch);
3645 if(!fromGui) {
3646 MusECore::MidiPlayEvent ev(0, 0, ch, MusECore::ME_CONTROLLER, MusECore::CTRL_RELEASE_TIME, val);
3647 _gui->writeEvent(ev);
3648 }
3649 break;
3650 case MusECore::CTRL_REVERB_SEND:
3651 setChannelReverb(ch, val);
3652 if(!fromGui) {
3653 MusECore::MidiPlayEvent ev(0, 0, ch, MusECore::ME_CONTROLLER, MusECore::CTRL_REVERB_SEND, val);
3654 _gui->writeEvent(ev);
3655 }
3656 break;
3657 case MusECore::CTRL_CHORUS_SEND:
3658 setChannelChorus(ch, val);
3659 if(!fromGui) {
3660 MusECore::MidiPlayEvent ev(0, 0, ch, MusECore::ME_CONTROLLER, MusECore::CTRL_CHORUS_SEND, val);
3661 _gui->writeEvent(ev);
3662 }
3663 break;
3664 case MusECore::CTRL_VARIATION_SEND:
3665 setChannelDelay(ch, val);
3666 if(!fromGui) {
3667 MusECore::MidiPlayEvent ev(0, 0, ch, MusECore::ME_CONTROLLER, MusECore::CTRL_VARIATION_SEND, val);
3668 _gui->writeEvent(ev);
3669 }
3670 break;
3671 case MusECore::CTRL_SUSTAIN:
3672 setSustain(ch, val);
3673 break;
3674 case MusECore::CTRL_VOLUME:
3675 setChannelVol(ch, val*(MAXCHANNELVOLUME/127));
3676 applyChannelAmp(ch);
3677 if(!fromGui) {
3678 MusECore::MidiPlayEvent
3679 ev(0, 0, ch, MusECore::ME_CONTROLLER, CTRL_CHANNELVOLUME, getChannelVol(ch));
3680 _gui->writeEvent(ev);
3681 }
3682 break;
3683 case MusECore::CTRL_ALL_SOUNDS_OFF:
3684 resetVoices();
3685 default:
3686 break;
3687 }
3688 }
3689 return false;
3690 }
3691
3692 //---------------------------------------------------------
3693 // getPatchName
3694 //---------------------------------------------------------
3695
getPatchName(int ch,int val,bool) const3696 const char* DeicsOnze::getPatchName(int ch, int val, bool) const {
3697 if(_global.channel[ch].isEnable) {
3698 Preset* p_preset;
3699 int hbank = (val & 0xff0000) >> 16;
3700 int lbank = (val & 0xff00) >> 8;
3701 if (hbank > 127)
3702 hbank = 0;
3703 if (lbank > 127)
3704 lbank = 0;
3705 if (lbank == 127) // drum HACK
3706 lbank = 128;
3707 int prog = val & 0x7f;
3708 const char* tempName="INITVOICE";
3709 p_preset=_set->findPreset(hbank, lbank, prog);
3710 if (p_preset) tempName=const_cast<char *>(p_preset->name.c_str());
3711 return tempName;
3712 }
3713 //return " "; // ??
3714 return "";
3715 }
3716
3717 //---------------------------------------------------------
3718 // getPatchInfo
3719 //---------------------------------------------------------
getPatchInfo(int,const MidiPatch * p) const3720 const MidiPatch* DeicsOnze::getPatchInfo(int /*ch*/, const MidiPatch* p) const {
3721 Preset* preset = NULL;
3722 Subcategory* sub = NULL;
3723 Category* cat = NULL;
3724 if(p) {
3725 _patch.hbank = p->hbank;
3726 _patch.lbank = p->lbank;
3727 _patch.prog = p->prog;
3728 switch(p->typ) {
3729 case MP_TYPE_HBANK :
3730 sub = findSubcategory(_patch.hbank, _patch.lbank);
3731 if(sub) {
3732 _patch.name = sub->_subcategoryName.c_str();
3733 _patch.typ = MP_TYPE_LBANK;
3734 return &_patch;
3735 }
3736 else {
3737 if(_patch.lbank + 1 < LBANK_NBR) {
3738 _patch.lbank++;
3739 return getPatchInfo(0, &_patch);
3740 }
3741 else {
3742 _patch.prog = PROG_NBR - 1; //hack to go faster
3743 _patch.typ = 0;
3744 return getPatchInfo(0, &_patch);
3745 }
3746 }
3747 break;
3748 case MP_TYPE_LBANK :
3749 preset = findPreset(_patch.hbank, _patch.lbank, _patch.prog);
3750 _patch.typ = 0;
3751 if(preset) {
3752 _patch.name = preset->name.c_str();
3753 return &_patch;
3754 }
3755 else return getPatchInfo(0, &_patch);
3756 break;
3757 default :
3758 if(_patch.prog + 1 < PROG_NBR) {
3759 _patch.prog++;
3760 preset = findPreset(_patch.hbank, _patch.lbank, _patch.prog);
3761 if(preset) {
3762 _patch.name = preset->name.c_str();
3763 return &_patch;
3764 }
3765 else return getPatchInfo(0, &_patch);
3766 }
3767 else {
3768 _patch.prog = 0;
3769 if(_patch.lbank + 1 < LBANK_NBR) {
3770 _patch.lbank++;
3771 _patch.typ = MP_TYPE_HBANK;
3772 return getPatchInfo(0, &_patch);
3773 }
3774 else {
3775 _patch.lbank = 0;
3776 if(_patch.hbank + 1 < HBANK_NBR) {
3777 _patch.hbank++;
3778 _patch.typ = MP_TYPE_HBANK;
3779 cat = findCategory(_patch.hbank);
3780 if(cat) {
3781 _patch.name = cat->_categoryName.c_str();
3782 return &_patch;
3783 }
3784 return getPatchInfo(0, &_patch);
3785 }
3786 else return NULL;
3787 }
3788 }
3789 }
3790 }
3791 else {
3792 _patch.typ = MP_TYPE_HBANK;
3793 _patch.hbank = 0;
3794 _patch.lbank = 0;
3795 _patch.prog = 0;
3796 cat = findCategory(_patch.hbank);
3797 if(cat) {
3798 _patch.name = cat->_categoryName.c_str();
3799 return &_patch;
3800 }
3801 else {
3802 _patch.hbank++;
3803 return getPatchInfo(0, &_patch);
3804 }
3805 }
3806 }
3807
3808 //---------------------------------------------------------
3809 // getControllerInfo
3810 /*!
3811 \fn SimpleSynth::getControllerInfo
3812 \brief Called from host to collect info about which controllers
3813 the synth supports
3814 \param index current controller number
3815 \param name pointer where name is stored
3816 \param controller int pointer where muse controller number is stored
3817 \param min int pointer where controller min value is stored
3818 \param max int pointer where controller max value is stored
3819 \return 0 when done, otherwise return next desired controller index
3820 */
3821 //---------------------------------------------------------
getControllerInfo(int index,const char ** name,int * controller,int * min,int * max,int * initval) const3822 int DeicsOnze::getControllerInfo(int index, const char** name,
3823 int* controller, int* min, int* max, int* initval) const
3824 {
3825 if (index >= nbrCtrl) {
3826 return 0;
3827 }
3828
3829 *name = _ctrl[index].name.c_str();
3830 *controller = _ctrl[index].num;
3831 *min = _ctrl[index].min;
3832 *max = _ctrl[index].max;
3833 *initval = 0; // p4.0.27 FIXME NOTE TODO
3834 return (index +1);
3835 }
3836
3837 //---------------------------------------------------------
3838 // playNote
3839 // process note on
3840 //---------------------------------------------------------
playNote(int ch,int pitch,int velo)3841 bool DeicsOnze::playNote(int ch, int pitch, int velo) {
3842 int newVoice;
3843 int nO2V;
3844 int p2V;
3845 double tempTargetFreq;
3846 if(_global.channel[ch].isEnable) {
3847 if(velo==0) {//Note off
3848 p2V=pitchOn2Voice(ch, pitch);
3849 //printf("Note Off : pitchOn2Voice = %d\n", p2V);
3850 if(p2V<_global.channel[ch].nbrVoices) {
3851 if(_global.channel[ch].sustain)
3852 _global.channel[ch].voices[p2V].isSustained = true;
3853 else {
3854 _global.channel[ch].voices[p2V].keyOn = false;
3855 _global.channel[ch].lastVoiceKeyOff = p2V;
3856 _global.channel[ch].lastVoiceKeyOn.remove(p2V);
3857 if(_preset[ch]->function.mode == MONO && existsKeyOn(ch)
3858 && _global.channel[ch].voices[p2V].isOn) {
3859 newVoice = _global.channel[ch].lastVoiceKeyOn.back();
3860 //portamento
3861 if(_preset[ch]->function.portamentoTime!=0) {
3862 _global.channel[ch].voices[newVoice].hasAttractor = true;
3863 _global.channel[ch].voices[newVoice].attractor =
3864 getAttractor(_preset[ch]->function.portamentoTime,
3865 _global.deiSampleRate);
3866 }
3867 else _global.channel[ch].voices[newVoice].hasAttractor = false;
3868 //feedback
3869 _global.channel[ch].voices[newVoice].sampleFeedback =
3870 _global.channel[ch].voices[p2V].sampleFeedback;
3871 //on/off
3872 _global.channel[ch].voices[p2V].isOn = false;
3873 _global.channel[ch].voices[newVoice].isOn = true;
3874 //per op
3875 for(int i = 0; i < NBROP; i++) {
3876 _global.channel[ch].voices[newVoice].op[i].index =
3877 _global.channel[ch].voices[p2V].op[i].index;
3878 _global.channel[ch].voices[newVoice].op[i].envState =
3879 _global.channel[ch].voices[p2V].op[i].envState;
3880 _global.channel[ch].voices[newVoice].op[i].envIndex =
3881 _global.channel[ch].voices[p2V].op[i].envIndex;
3882 _global.channel[ch].voices[newVoice].op[i].envInct =
3883 _global.channel[ch].voices[p2V].op[i].envInct;
3884 _global.channel[ch].voices[newVoice].op[i].envLevel =
3885 _global.channel[ch].voices[p2V].op[i].envLevel;
3886 _global.channel[ch].voices[newVoice].op[i].coefVLevel =
3887 _global.channel[ch].voices[p2V].op[i].coefVLevel;
3888 if(_global.channel[ch].voices[newVoice].hasAttractor)
3889 _global.channel[ch].voices[newVoice].op[i].inct =
3890 _global.channel[ch].voices[p2V].op[i].inct;
3891 }
3892 }
3893 else {
3894 setPitchEnvRelease(ch, p2V);
3895 for(int i=0; i<NBROP; i++) {
3896 _global.channel[ch].voices[p2V].op[i].envState = RELEASE;
3897 setEnvRelease(ch, p2V, i);
3898 }
3899 }
3900 }
3901 return false;
3902 }
3903 //else printf("error over NBRVOICES\n");
3904 }
3905 else //Note on
3906 {
3907 nO2V=noteOff2Voice(ch);
3908 newVoice=((nO2V==MAXNBRVOICES)?minVolu2Voice(ch):nO2V);
3909 //printf("Note On : ch = %d, v = %d, p = %d\n", ch, newVoice, pitch);
3910
3911 //----------
3912 //portamento
3913 //----------
3914 //if there is no previous note there is no portamento
3915 if(_preset[ch]->function.portamentoTime!=0
3916 && _global.channel[ch].isLastNote &&
3917 ((_preset[ch]->function.portamento==FULL) ||
3918 (_preset[ch]->function.portamento==FINGER && existsKeyOn(ch)))) {
3919 _global.channel[ch].voices[newVoice].hasAttractor = true;
3920 _global.channel[ch].voices[newVoice].attractor =
3921 getAttractor(_preset[ch]->function.portamentoTime,
3922 _global.deiSampleRate);
3923 }
3924 else _global.channel[ch].voices[newVoice].hasAttractor = false;
3925
3926 if(_preset[ch]->lfo.sync) _global.channel[ch].lfoIndex=0;
3927
3928 _global.channel[ch].lfoDelayIndex =
3929 (_preset[ch]->lfo.delay==0?(double)(RESOLUTION/4):0.0);
3930 _global.channel[ch].delayPassed = false;
3931
3932 //--------------
3933 //PITCH ENVELOPE
3934 //--------------
3935 if(isPitchEnv(&_preset[ch]->pitchEg)) {
3936 _global.channel[ch].voices[newVoice].pitchEnvState = PHASE1;
3937 _global.channel[ch].voices[newVoice].pitchEnvCoefInctPhase1 =
3938 getPitchEnvCoefInct(_preset[ch]->pitchEg.pl1);
3939 _global.channel[ch].voices[newVoice].pitchEnvCoefInctPhase2 =
3940 getPitchEnvCoefInct(_preset[ch]->pitchEg.pl2);
3941 _global.channel[ch].voices[newVoice].pitchEnvCoefInctPhase3 =
3942 getPitchEnvCoefInct(_preset[ch]->pitchEg.pl3);
3943 _global.channel[ch].voices[newVoice].pitchEnvCoefInct =
3944 _global.channel[ch].voices[newVoice].pitchEnvCoefInctPhase1;
3945 _global.channel[ch].voices[newVoice].pitchEnvCoefInctInct =
3946 getPitchEnvCoefInctInct(_preset[ch]->pitchEg.pl1,
3947 _preset[ch]->pitchEg.pl2,
3948 _preset[ch]->pitchEg.pr1,
3949 _global.deiSampleRate);
3950 }
3951 else {
3952 _global.channel[ch].voices[newVoice].pitchEnvState = OFF_PE;
3953 _global.channel[ch].voices[newVoice].pitchEnvCoefInct = 1.0;
3954 }
3955 //per operator
3956 for(int i=0; i<NBROP; i++) {
3957 //------
3958 //VOLUME
3959 //------
3960 _global.channel[ch].voices[newVoice].op[i].ampVeloNote =
3961 velo2AmpR(velo, _preset[ch]->sensitivity.keyVelocity[i])
3962 *note2Amp((double) (pitch+_preset[ch]->function.transpose),
3963 _preset[ch]->scaling.level[i]);
3964 _global.channel[ch].voices[newVoice].op[i].amp =
3965 outLevel2Amp(_preset[ch]->outLevel[i])
3966 *_global.channel[ch].voices[newVoice].op[i].ampVeloNote
3967 * brightness2Amp(ch, i);
3968 //----------------
3969 //INDEX & ENVELOPE
3970 //----------------
3971 //if index get 0.0, it means that the offset is 0
3972 if(existsKeyOn(ch)) {
3973 int lastVoice = _global.channel[ch].lastVoiceKeyOn.back();
3974 if(_preset[ch]->function.mode == MONO) {
3975 _global.channel[ch].voices[newVoice].op[i].index =
3976 _global.channel[ch].voices[lastVoice].op[i].index;
3977 _global.channel[ch].voices[newVoice].sampleFeedback =
3978 _global.channel[ch].voices[lastVoice].sampleFeedback;
3979 _global.channel[ch].voices[newVoice].op[i].envState =
3980 _global.channel[ch].voices[lastVoice].op[i].envState;
3981 _global.channel[ch].voices[newVoice].op[i].envIndex =
3982 _global.channel[ch].voices[lastVoice].op[i].envIndex;
3983 _global.channel[ch].voices[newVoice].op[i].envInct =
3984 _global.channel[ch].voices[lastVoice].op[i].envInct;
3985 _global.channel[ch].voices[newVoice].op[i].envLevel =
3986 _global.channel[ch].voices[lastVoice].op[i].envLevel;
3987 _global.channel[ch].voices[newVoice].op[i].coefVLevel =
3988 _global.channel[ch].voices[lastVoice].op[i].coefVLevel;
3989 _global.channel[ch].voices[lastVoice].isOn = false;
3990 }
3991 else {
3992 _global.channel[ch].voices[newVoice].op[i].index = 0.0;
3993 _global.channel[ch].voices[newVoice].sampleFeedback = 0.0;
3994 _global.channel[ch].voices[newVoice].op[i].envState = ATTACK;
3995 _global.channel[ch].voices[newVoice].op[i].envIndex = 0.0;
3996 setEnvAttack(ch, newVoice, i);
3997 }
3998 }
3999 else {
4000 _global.channel[ch].voices[newVoice].op[i].index = 0.0;
4001 _global.channel[ch].voices[newVoice].sampleFeedback = 0.0;
4002 _global.channel[ch].voices[newVoice].op[i].envState = ATTACK;
4003 _global.channel[ch].voices[newVoice].op[i].envIndex = 0.0;
4004 setEnvAttack(ch, newVoice, i);
4005 if(_preset[ch]->function.mode == MONO &&
4006 _global.channel[ch].isLastNote) {
4007 _global.channel[ch].voices[_global.channel[ch].lastVoiceKeyOff]
4008 .isOn = false;
4009 }
4010 }
4011
4012 //----
4013 //FREQ
4014 //----
4015 //the frequence for each operator is calculated
4016 //and is used later to calculate inct
4017 tempTargetFreq =
4018 (pitch2freq((double)getChannelDetune(ch)
4019 /(double)MAXCHANNELDETUNE)
4020 /LOWERNOTEFREQ)*
4021 (_preset[ch]->frequency[i].isFix?
4022 _preset[ch]->frequency[i].freq:
4023 (_preset[ch]->frequency[i].ratio
4024 *pitch2freq((double)(pitch+_preset[ch]->function.transpose)
4025 +(double)_preset[ch]->detune[i]*COEFDETUNE)));
4026 //----
4027 //INCT
4028 //----
4029 //compute inct
4030 _global.channel[ch].voices[newVoice].op[i].targetInct =
4031 (double)RESOLUTION / ( _global.deiSampleRate / tempTargetFreq );
4032 if(_global.channel[ch].voices[newVoice].hasAttractor &&
4033 !_preset[ch]->frequency[i].isFix)
4034 _global.channel[ch].voices[newVoice].op[i].inct =
4035 _global.channel[ch].lastInc[i];
4036 else _global.channel[ch].voices[newVoice].op[i].inct =
4037 _global.channel[ch].voices[newVoice].op[i].targetInct;
4038 }
4039 //--------------------
4040 //some initializations
4041 //--------------------
4042 _global.channel[ch].voices[newVoice].keyOn = true;
4043 _global.channel[ch].voices[newVoice].isSustained = false;
4044 _global.channel[ch].voices[newVoice].isOn = true;
4045 _global.channel[ch].voices[newVoice].pitch = pitch;
4046 _global.channel[ch].isLastNote = true;
4047 _global.channel[ch].lastVoiceKeyOn.push_back(newVoice);
4048 for(int k = 0; k < NBROP; k++)
4049 _global.channel[ch].lastInc[k] =
4050 _global.channel[ch].voices[newVoice].op[k].inct;
4051 return false;
4052 }
4053 }
4054 return false;
4055 }
4056
4057 //---------------------------------------------------------
4058 // plusMod
4059 // add two doubles modulo RESOLUTION
4060 //---------------------------------------------------------
plusMod(double x,double y)4061 inline double plusMod(double x, double y) {
4062 double res;
4063 res=x+y;
4064 if (res>=0) while (res >= (double)RESOLUTION) res-=(double)RESOLUTION;
4065 else while (res < 0) res+=(double)RESOLUTION;
4066 return res;
4067 }
4068
4069
4070 //---------------------------------------------------------
4071 // processMessages
4072 // Called from host always, even if output path is unconnected.
4073 //---------------------------------------------------------
4074
processMessages()4075 void DeicsOnze::processMessages()
4076 {
4077 //Process messages from the gui
4078 while (_gui->fifoSize()) {
4079 MusECore::MidiPlayEvent ev = _gui->readEvent();
4080 if (ev.type() == MusECore::ME_SYSEX) {
4081 sysex(ev.len(), ev.data(), true);
4082 sendEvent(ev);
4083 }
4084 else if (ev.type() == MusECore::ME_CONTROLLER) {
4085 setController(ev.channel(), ev.dataA(), ev.dataB(), true);
4086 sendEvent(ev);
4087 }
4088 }
4089 }
4090
4091 //---------------------------------------------------------
4092 // write
4093 // synthesize n samples into buffer+offset
4094 //---------------------------------------------------------
process(unsigned pos,float ** buffer,int offset,int n)4095 void DeicsOnze::process(unsigned pos, float** buffer, int offset, int n) {
4096 /*
4097 //Process messages from the gui
4098 while (_gui->fifoSize()) {
4099 MusECore::MidiPlayEvent ev = _gui->readEvent();
4100 if (ev.type() == MusECore::ME_SYSEX) {
4101 sysex(ev.len(), ev.data(), true);
4102 sendEvent(ev);
4103 }
4104 else if (ev.type() == MusECore::ME_CONTROLLER) {
4105 setController(ev.channel(), ev.dataA(), ev.dataB(), true);
4106 sendEvent(ev);
4107 }
4108 }
4109 */
4110
4111 float* leftOutput = buffer[0] + offset;
4112 float* rightOutput = buffer[1] + offset;
4113
4114 float sample[MAXNBRVOICES];
4115 float tempLeftOutput;
4116 float tempRightOutput;
4117 float tempChannelOutput;
4118 float tempChannelLeftOutput;
4119 float tempChannelRightOutput;
4120 float tempIncChannel; //for optimization
4121 float sampleOp[NBROP];
4122 for(int i = 0; i < NBROP; i++) sampleOp[i] = 0.0;
4123 float ampOp[NBROP];
4124 for(int i = 0; i < n; i++) {
4125 if(_global.qualityCounter == 0) {
4126 tempLeftOutput = 0.0;
4127 tempRightOutput = 0.0;
4128 _global.lastInputLeftChorusSample = 0.0;
4129 _global.lastInputRightChorusSample = 0.0;
4130 _global.lastInputLeftReverbSample = 0.0;
4131 _global.lastInputRightReverbSample = 0.0;
4132 _global.lastInputLeftDelaySample = 0.0;
4133 _global.lastInputRightDelaySample = 0.0;
4134 //per channel
4135 for(int c = 0; c < NBRCHANNELS; c++) {
4136 tempChannelOutput = 0.0;
4137 if(_global.channel[c].isEnable) {
4138 //lfo, trick : we use the first quater of the wave W2
4139 lfoUpdate(_preset[c], &_global.channel[c], waveTable[W2]);
4140
4141 //optimization
4142 tempIncChannel =
4143 _global.channel[c].lfoCoefInct * _global.channel[c].pitchBendCoef;
4144
4145 //per voice
4146 for(int j=0; j<_global.channel[c].nbrVoices; j++) {
4147 if (_global.channel[c].voices[j].isOn) {
4148 //portamento
4149 portamentoUpdate(&_global.channel[c],
4150 &_global.channel[c].voices[j]);
4151 //pitch envelope
4152 pitchEnvelopeUpdate(&_global.channel[c].voices[j],
4153 &_preset[c]->pitchEg, _global.deiSampleRate);
4154 //per op
4155 for(int k=0; k<NBROP; k++) {
4156 //compute the next index on the wavetable,
4157 //without taking account of the feedback and FM modulation
4158 _global.channel[c].voices[j].op[k].index=
4159 plusMod(_global.channel[c].voices[j].op[k].index,
4160 _global.channel[c].voices[j].op[k].inct
4161 * tempIncChannel
4162 * _global.channel[c].voices[j].pitchEnvCoefInct);
4163
4164 ampOp[k]=_global.channel[c].voices[j].op[k].amp*COEFLEVEL
4165 *(_preset[c]->sensitivity.ampOn[k]?
4166 _global.channel[c].lfoAmp:1.0)
4167 *env2AmpR(_global.deiSampleRate, waveTable[W2],
4168 _preset[c]->eg[k],
4169 &_global.channel[c].voices[j].op[k]);
4170 }
4171 switch(_preset[c]->algorithm) {
4172 case FIRST :
4173 sampleOp[3]=ampOp[3]
4174 *waveTable[_preset[c]->oscWave[3]]
4175 [(int)plusMod(_global.channel[c].voices[j].op[3].index,
4176 (float)RESOLUTION
4177 *_global.channel[c].voices[j].sampleFeedback)];
4178 sampleOp[2]=ampOp[2]
4179 *waveTable[_preset[c]->oscWave[2]]
4180 [(int)plusMod(_global.channel[c].voices[j].op[2].index,
4181 (float)RESOLUTION*sampleOp[3])];
4182 sampleOp[1]=ampOp[1]
4183 *waveTable[_preset[c]->oscWave[1]]
4184 [(int)plusMod(_global.channel[c].voices[j].op[1].index,
4185 (float)RESOLUTION*sampleOp[2])];
4186 sampleOp[0]=ampOp[0]
4187 *waveTable[_preset[c]->oscWave[0]]
4188 [(int)plusMod(_global.channel[c].voices[j].op[0].index,
4189 (float)RESOLUTION*sampleOp[1])];
4190
4191 sample[j]=sampleOp[0];///COEFLEVEL;
4192
4193 _global.channel[c].voices[j].isOn =
4194 (_global.channel[c].voices[j].op[0].envState!=OFF);
4195 break;
4196 case SECOND :
4197 sampleOp[3]=ampOp[3]
4198 *waveTable[_preset[c]->oscWave[3]]
4199 [(int)plusMod(_global.channel[c].voices[j].op[3].index,
4200 (float)RESOLUTION
4201 *_global.channel[c].voices[j].sampleFeedback)];
4202 sampleOp[2]=ampOp[2]
4203 *waveTable[_preset[c]->oscWave[2]]
4204 [(int)_global.channel[c].voices[j].op[2].index];
4205 sampleOp[1]=ampOp[1]
4206 *waveTable[_preset[c]->oscWave[1]]
4207 [(int)plusMod(_global.channel[c].voices[j].op[1].index,
4208 (float)RESOLUTION
4209 *(sampleOp[2]+sampleOp[3])/2.0)];
4210 sampleOp[0]=ampOp[0]
4211 *waveTable[_preset[c]->oscWave[0]]
4212 [(int)plusMod(_global.channel[c].voices[j].op[0].index,
4213 (float)RESOLUTION
4214 *sampleOp[1])];
4215
4216 sample[j]=sampleOp[0];///COEFLEVEL;
4217
4218 _global.channel[c].voices[j].isOn =
4219 (_global.channel[c].voices[j].op[0].envState!=OFF);
4220 break;
4221 case THIRD :
4222 sampleOp[3]=ampOp[3]
4223 *waveTable[_preset[c]->oscWave[3]]
4224 [(int)plusMod(_global.channel[c].voices[j].op[3].index,
4225 (float)RESOLUTION
4226 *_global.channel[c].voices[j].sampleFeedback)];
4227 sampleOp[2]=ampOp[2]
4228 *waveTable[_preset[c]->oscWave[2]]
4229 [(int)_global.channel[c].voices[j].op[2].index];
4230 sampleOp[1]=ampOp[1]
4231 *waveTable[_preset[c]->oscWave[1]]
4232 [(int)plusMod(_global.channel[c].voices[j].op[1].index,
4233 (float)RESOLUTION*sampleOp[2])];
4234 sampleOp[0]=ampOp[0]
4235 *waveTable[_preset[c]->oscWave[0]]
4236 [(int)plusMod(_global.channel[c].voices[j].op[0].index,
4237 (float)RESOLUTION
4238 *(sampleOp[3]+sampleOp[1])/2.0)];
4239
4240 sample[j]=sampleOp[0];///COEFLEVEL;
4241
4242 _global.channel[c].voices[j].isOn =
4243 (_global.channel[c].voices[j].op[0].envState!=OFF);
4244 break;
4245 case FOURTH :
4246 sampleOp[3]=ampOp[3]
4247 *waveTable[_preset[c]->oscWave[3]]
4248 [(int)plusMod(_global.channel[c].voices[j].op[3].index,
4249 (float)RESOLUTION
4250 *_global.channel[c].voices[j].sampleFeedback)];
4251 sampleOp[2]=ampOp[2]
4252 *waveTable[_preset[c]->oscWave[2]]
4253 [(int)plusMod(_global.channel[c].voices[j].op[2].index,
4254 (float)RESOLUTION
4255 *sampleOp[3])];
4256 sampleOp[1]=ampOp[1]
4257 *waveTable[_preset[c]->oscWave[1]]
4258 [(int)_global.channel[c].voices[j].op[1].index];
4259 sampleOp[0]=ampOp[0]
4260 *waveTable[_preset[c]->oscWave[0]]
4261 [(int)plusMod(_global.channel[c].voices[j].op[0].index,
4262 (float)RESOLUTION
4263 *(sampleOp[1]+sampleOp[2])/2.0)];
4264
4265 sample[j]=sampleOp[0];///COEFLEVEL;
4266
4267 _global.channel[c].voices[j].isOn =
4268 (_global.channel[c].voices[j].op[0].envState!=OFF);
4269 break;
4270 case FIFTH :
4271 sampleOp[3]=ampOp[3]
4272 *waveTable[_preset[c]->oscWave[3]]
4273 [(int)plusMod(_global.channel[c].voices[j].op[3].index,
4274 (float)RESOLUTION
4275 *_global.channel[c].voices[j].sampleFeedback)];
4276 sampleOp[2]=ampOp[2]
4277 *waveTable[_preset[c]->oscWave[2]]
4278 [(int)plusMod(_global.channel[c].voices[j].op[2].index,
4279 (float)RESOLUTION*sampleOp[3])];
4280 sampleOp[1]=ampOp[1]
4281 *waveTable[_preset[c]->oscWave[1]]
4282 [(int)_global.channel[c].voices[j].op[1].index];
4283 sampleOp[0]=ampOp[0]
4284 *waveTable[_preset[c]->oscWave[0]]
4285 [(int)plusMod(_global.channel[c].voices[j].op[0].index,
4286 (float)RESOLUTION*sampleOp[1])];
4287
4288 sample[j]=(sampleOp[0]+sampleOp[2])/2.0;///COEFLEVEL;
4289
4290 _global.channel[c].voices[j].isOn =
4291 (_global.channel[c].voices[j].op[0].envState!=OFF
4292 ||_global.channel[c].voices[j].op[2].envState!=OFF);
4293 break;
4294 case SIXTH :
4295 sampleOp[3]=ampOp[3]
4296 *waveTable[_preset[c]->oscWave[3]]
4297 [(int)plusMod(_global.channel[c].voices[j].op[3].index,
4298 (float)RESOLUTION
4299 *_global.channel[c].voices[j].sampleFeedback)];
4300 sampleOp[2]=ampOp[2]
4301 *waveTable[_preset[c]->oscWave[2]]
4302 [(int)plusMod(_global.channel[c].voices[j].op[2].index,
4303 (float)RESOLUTION*sampleOp[3])];
4304 sampleOp[1]=ampOp[1]
4305 *waveTable[_preset[c]->oscWave[1]]
4306 [(int)plusMod(_global.channel[c].voices[j].op[1].index,
4307 (float)RESOLUTION*sampleOp[3])];
4308 sampleOp[0]=ampOp[0]
4309 *waveTable[_preset[c]->oscWave[0]]
4310 [(int)plusMod(_global.channel[c].voices[j].op[0].index,
4311 (float)RESOLUTION*sampleOp[3])];
4312
4313 sample[j]=(sampleOp[0]+sampleOp[1]+sampleOp[2])/3.0;
4314
4315 _global.channel[c].voices[j].isOn =
4316 (_global.channel[c].voices[j].op[0].envState!=OFF);
4317 break;
4318 case SEVENTH :
4319 sampleOp[3]=ampOp[3]
4320 *waveTable[_preset[c]->oscWave[3]]
4321 [(int)plusMod(_global.channel[c].voices[j].op[3].index,
4322 (float)RESOLUTION
4323 *_global.channel[c].voices[j].sampleFeedback)];
4324 sampleOp[2]=ampOp[2]
4325 *waveTable[_preset[c]->oscWave[2]]
4326 [(int)plusMod(_global.channel[c].voices[j].op[2].index,
4327 (float)RESOLUTION*sampleOp[3])];
4328 sampleOp[1]=ampOp[1]
4329 *waveTable[_preset[c]->oscWave[1]]
4330 [(int)_global.channel[c].voices[j].op[1].index];
4331 sampleOp[0]=ampOp[0]*waveTable[_preset[c]->oscWave[0]]
4332 [(int)_global.channel[c].voices[j].op[0].index];
4333
4334 sample[j]=(sampleOp[0]+sampleOp[1]+sampleOp[2])/3.0;
4335
4336 _global.channel[c].voices[j].isOn =
4337 (_global.channel[c].voices[j].op[0].envState!=OFF);
4338 break;
4339 case EIGHTH :
4340 sampleOp[3]=ampOp[3]
4341 *waveTable[_preset[c]->oscWave[3]]
4342 [(int)plusMod(_global.channel[c].voices[j].op[3].index,
4343 (float)RESOLUTION
4344 *_global.channel[c].voices[j].sampleFeedback)];
4345 sampleOp[2]=ampOp[2]
4346 *waveTable[_preset[c]->oscWave[2]]
4347 [(int)_global.channel[c].voices[j].op[2].index];
4348 sampleOp[1]=ampOp[1]
4349 *waveTable[_preset[c]->oscWave[1]]
4350 [(int)_global.channel[c].voices[j].op[1].index];
4351 sampleOp[0]=ampOp[0]
4352 *waveTable[_preset[c]->oscWave[0]]
4353 [(int)_global.channel[c].voices[j].op[0].index];
4354
4355 sample[j]=
4356 (sampleOp[0]+sampleOp[1]+sampleOp[2]+sampleOp[3])
4357 /4.0;
4358
4359 _global.channel[c].voices[j].isOn =
4360 (_global.channel[c].voices[j].op[0].envState!=OFF
4361 || _global.channel[c].voices[j].op[1].envState!=OFF
4362 || _global.channel[c].voices[j].op[2].envState!=OFF
4363 || _global.channel[c].voices[j].op[3].envState!=OFF);
4364 break;
4365 default : printf("Error : No algorithm");
4366 break;
4367 }
4368
4369 _global.channel[c].voices[j].volume=
4370 ampOp[0]+ampOp[1]+ampOp[2]+ampOp[3];
4371
4372 _global.channel[c].voices[j].sampleFeedback =
4373 sampleOp[3]*_global.channel[c].feedbackAmp;
4374
4375 tempChannelOutput += sample[j];
4376 }
4377 }
4378 //printf("left out = %f, temp out = %f, left amp = %f\n",
4379 //tempLeftOutput, tempChannelOutput, _global.channel[c].ampLeft);
4380
4381 tempChannelLeftOutput = tempChannelOutput*_global.channel[c].ampLeft;
4382 tempChannelRightOutput=tempChannelOutput*_global.channel[c].ampRight;
4383
4384 if(_global.isChorusActivated) {
4385 _global.lastInputLeftChorusSample += tempChannelLeftOutput *
4386 _global.channel[c].chorusAmount;
4387 _global.lastInputRightChorusSample += tempChannelRightOutput *
4388 _global.channel[c].chorusAmount;
4389 }
4390 if(_global.isReverbActivated) {
4391 _global.lastInputLeftReverbSample += tempChannelLeftOutput *
4392 _global.channel[c].reverbAmount;
4393 _global.lastInputRightReverbSample += tempChannelRightOutput *
4394 _global.channel[c].reverbAmount;
4395 }
4396 if(_global.isDelayActivated) {
4397 _global.lastInputLeftDelaySample += tempChannelLeftOutput *
4398 _global.channel[c].delayAmount;
4399 _global.lastInputRightDelaySample += tempChannelRightOutput *
4400 _global.channel[c].delayAmount;
4401 }
4402 tempLeftOutput += tempChannelLeftOutput;
4403 tempRightOutput += tempChannelRightOutput;
4404 }
4405 }
4406 _global.lastLeftSample = tempLeftOutput * _global.masterVolume;
4407 _global.lastRightSample = tempRightOutput * _global.masterVolume;
4408 }
4409 leftOutput[i] += _global.lastLeftSample;
4410 rightOutput[i] += _global.lastRightSample;
4411
4412 if(_global.isChorusActivated) {
4413 tempInputChorus[0][i] = _global.lastInputLeftChorusSample;
4414 tempInputChorus[1][i] = _global.lastInputRightChorusSample;
4415 }
4416 if(_global.isReverbActivated) {
4417 tempInputReverb[0][i] = _global.lastInputLeftReverbSample;
4418 tempInputReverb[1][i] = _global.lastInputRightReverbSample;
4419 }
4420 if(_global.isDelayActivated) {
4421 tempInputDelay[0][i] = _global.lastInputLeftDelaySample;
4422 tempInputDelay[1][i] = _global.lastInputRightDelaySample;
4423 }
4424
4425 _global.qualityCounter++;
4426 _global.qualityCounter %= _global.qualityCounterTop;
4427 }
4428 //apply Filter
4429 if(_global.filter) _dryFilter->process(leftOutput, rightOutput, n);
4430 //Chorus
4431 if(_pluginIChorus) {
4432 if(_global.isChorusActivated)
4433 {
4434 //apply Filter
4435 if(_global.filter) _chorusFilter->process(tempOutputChorus[0],
4436 tempOutputChorus[1], n);
4437 //apply Chorus
4438 _pluginIChorus->apply(pos, n, 2, tempInputChorus, tempOutputChorus);
4439 for(int i = 0; i < n; i++) {
4440 leftOutput[i] +=
4441 tempOutputChorus[0][i] * _global.chorusReturn * _global.masterVolume;
4442 rightOutput[i] +=
4443 tempOutputChorus[1][i] * _global.chorusReturn * _global.masterVolume;
4444 }
4445 }
4446 else
4447 _pluginIChorus->apply(pos, n, 0, 0, 0); // Just process controls only, not audio (do not 'run'). Tim.
4448 }
4449 //Reverb
4450 if(_pluginIReverb) {
4451 if(_global.isReverbActivated)
4452 {
4453 //apply Filter
4454 if(_global.filter) _reverbFilter->process(tempOutputReverb[0],
4455 tempOutputReverb[1], n);
4456 //apply Reverb
4457 _pluginIReverb->apply(pos, n, 2, tempInputReverb, tempOutputReverb);
4458 for(int i = 0; i < n; i++) {
4459 leftOutput[i] +=
4460 tempOutputReverb[0][i] * _global.reverbReturn * _global.masterVolume;
4461 rightOutput[i] +=
4462 tempOutputReverb[1][i] * _global.reverbReturn * _global.masterVolume;
4463 }
4464 }
4465 else
4466 _pluginIReverb->apply(pos, n, 0, 0, 0); // Just process controls only, not audio (do not 'run'). Tim.
4467 }
4468 //Delay
4469 if(_pluginIDelay) {
4470 if(_global.isDelayActivated)
4471 {
4472 //apply Filter
4473 if(_global.filter) _delayFilter->process(tempOutputDelay[0],
4474 tempOutputDelay[1], n);
4475 //apply Delay
4476 _pluginIDelay->apply(pos, n, 2, tempInputDelay, tempOutputDelay);
4477 for(int i = 0; i < n; i++) {
4478 leftOutput[i] +=
4479 tempOutputDelay[0][i] * _global.delayReturn * _global.masterVolume;
4480 rightOutput[i] +=
4481 tempOutputDelay[1][i] * _global.delayReturn * _global.masterVolume;
4482 }
4483 }
4484 else
4485 _pluginIDelay->apply(pos, n, 0, 0, 0); // Just process controls only, not audio (do not 'run'). Tim.
4486 }
4487 }
4488
4489
4490 //---------------------------------------------------------
4491 // inst
4492 //---------------------------------------------------------
4493
4494 class QWidget;
4495
instantiate(unsigned long long,const char *,const MessConfig * config)4496 static Mess* instantiate(unsigned long long /*parentWinId*/, const char* /*name*/, const MessConfig* config)
4497 {
4498 DEI_hostConfigPath = QString(config->_configPath);
4499 DEI_hostCachePath = QString(config->_cachePath);
4500 DEI_globalLibPath = QString(config->_globalLibPath);
4501 DEI_sharePath = QString(config->_globalSharePath);
4502 DEI_segmentSize = config->_segmentSize;
4503 DEI_sampleRate = config->_sampleRate;
4504 DEI_useDenormalBias = config->_useDenormalBias;
4505 DEI_denormalBias = config->_denormalBias;
4506 DeicsOnze* deicsonze = new DeicsOnze();
4507 deicsonze->setSampleRate(config->_sampleRate);
4508 return deicsonze;
4509 }
4510
4511 extern "C" {
4512 static MESS descriptor = {
4513 "DeicsOnze",
4514 "DeicsOnze FM DX11/TX81Z emulator",
4515 "0.5.5", // version string
4516 MESS_MAJOR_VERSION, MESS_MINOR_VERSION,
4517 instantiate
4518 };
4519 // We must compile with -fvisibility=hidden to avoid namespace
4520 // conflicts with global variables.
4521 // Only visible symbol is "mess_descriptor".
4522 // (TODO: all plugins should be compiled this way)
4523
4524 __attribute__ ((visibility("default")))
mess_descriptor()4525 const MESS* mess_descriptor() { return &descriptor; }
4526 }
4527
4528