/[svn]/linuxsampler/trunk/src/engines/sfz/sfz.cpp
ViewVC logotype

Annotation of /linuxsampler/trunk/src/engines/sfz/sfz.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2021 - (hide annotations) (download)
Fri Oct 30 16:36:20 2009 UTC (14 years, 5 months ago) by iliev
File size: 50900 byte(s)
* sfz engine: loop support
* sf2 engine: 24bit support
* sf2 engine: loop support
* sf2 engine: instrument unloading

1 iliev 2012 /***************************************************************************
2     * *
3     * LinuxSampler - modular, streaming capable sampler *
4     * *
5     * Copyright (C) 2008-2009 Anders Dahnielson <anders@dahnielson.com> *
6     * Copyright (C) 2009 Grigor Iliev *
7     * *
8     * This program is free software; you can redistribute it and/or modify *
9     * it under the terms of the GNU General Public License as published by *
10     * the Free Software Foundation; either version 2 of the License, or *
11     * (at your option) any later version. *
12     * *
13     * This program is distributed in the hope that it will be useful, *
14     * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16     * GNU General Public License for more details. *
17     * *
18     * You should have received a copy of the GNU General Public License *
19     * along with this program; if not, write to the Free Software *
20     * Foundation, Inc., 59 Temple Place, Suite 330, Boston, *
21     * MA 02111-1307 USA *
22     ***************************************************************************/
23    
24     #include "sfz.h"
25    
26     #include <iostream>
27     #include <sstream>
28    
29     #include "../../common/File.h"
30     #include "../../common/Path.h"
31     #include "../../common/global_private.h"
32    
33     namespace sfz
34     {
35    
36 iliev 2021 Sample* SampleManager::FindSample(std::string samplePath) {
37     std::map<Sample*, std::set<Region*> >::iterator it = sampleMap.begin();
38 iliev 2012 for (; it != sampleMap.end(); it++) {
39     if (it->first->GetFile() == samplePath) return it->first;
40     }
41    
42     return NULL;
43     }
44    
45     /////////////////////////////////////////////////////////////
46     // class optional
47    
48     const optional_base::nothing_t optional_base::nothing;
49    
50     /////////////////////////////////////////////////////////////
51     // class Articulation
52    
53     Articulation::Articulation()
54     {
55     }
56    
57     Articulation::~Articulation()
58     {
59     }
60    
61     /////////////////////////////////////////////////////////////
62     // class Definition
63    
64     Definition::Definition() :
65     locc(128), hicc(128), start_locc(128), start_hicc(128), stop_locc(128),
66     stop_hicc(128), on_locc(128), on_hicc(128), delay_oncc(128), delay_samples_oncc(128),
67     offset_oncc(128), amp_velcurve_(128), gain_oncc(128), xfin_locc(128), xfin_hicc(128),
68     xfout_locc(128), xfout_hicc(128), cutoff_oncc(128), cutoff2_oncc(128), cutoff_smoothcc(128),
69     cutoff2_smoothcc(128), cutoff_stepcc(128), cutoff2_stepcc(128), cutoff_curvecc(128),
70     cutoff2_curvecc(128), resonance_oncc(128), resonance2_oncc(128), resonance_smoothcc(128),
71     resonance2_smoothcc(128), resonance_stepcc(128), resonance2_stepcc(128),
72     resonance_curvecc(128), resonance2_curvecc(128), eq1_freq_oncc(128), eq2_freq_oncc(128),
73     eq3_freq_oncc(128), eq1_bw_oncc(128), eq2_bw_oncc(128), eq3_bw_oncc(128),
74     eq1_gain_oncc(128), eq2_gain_oncc(128), eq3_gain_oncc(128)
75    
76     {
77     }
78    
79     Definition::~Definition()
80     {
81     }
82    
83     /////////////////////////////////////////////////////////////
84     // class Region
85    
86     Region::Region()
87     {
88     pSample = NULL;
89     }
90    
91     Region::~Region()
92     {
93     DestroySampleIfNotUsed();
94     }
95    
96 iliev 2021 Sample* Region::GetSample(bool create)
97 iliev 2012 {
98     if(pSample == NULL && create) {
99 iliev 2021 Sample* sf = GetInstrument()->GetSampleManager()->FindSample(sample);
100 iliev 2012 if (sf != NULL) pSample = sf; // Reuse already created sample
101 iliev 2021 else pSample = new Sample(sample);
102 iliev 2012 GetInstrument()->GetSampleManager()->AddSampleConsumer(pSample, this);
103     }
104     return pSample;
105     }
106    
107     void Region::DestroySampleIfNotUsed() {
108     if (pSample == NULL) return;
109     GetInstrument()->GetSampleManager()->RemoveSampleConsumer(pSample, this);
110     if (!GetInstrument()->GetSampleManager()->HasSampleConsumers(pSample)) {
111     GetInstrument()->GetSampleManager()->RemoveSample(pSample);
112     delete pSample;
113     pSample = NULL;
114     }
115     }
116    
117     bool
118     Region::OnKey(uint8_t chan, uint8_t key, uint8_t vel,
119     int bend, uint8_t bpm, uint8_t chanaft, uint8_t polyaft,
120     uint8_t prog, float rand, trigger_t trig, uint8_t* cc,
121     float timer, uint8_t seq, bool* sw, uint8_t last_sw_key, uint8_t prev_sw_key)
122     {
123     // chan (MIDI channel)
124     // key (MIDI note)
125     // vel (MIDI velocity)
126    
127     // bend (MIDI pitch bend)
128     // bpm (host BPM)
129     // chanaft (MIDI channel pressure)
130     // polyaft (MIDI polyphonic aftertouch)
131     // prog (MIDI program change)
132     // rand (generated random number)
133     // trigger (how it was triggered)
134     // cc (all 128 CC values)
135    
136     // timer (time since previous region in the group was triggered)
137     // seq (the state of the region sequence counter)
138     // sw (the state of region key switches, 128 possible values)
139     // last_sw_key (the last key pressed in the key switch range)
140     // prev_sw_key (the previous note value)
141    
142     bool is_triggered (
143     chan >= lochan && chan <= hichan &&
144     key >= lokey && key <= hikey &&
145     vel >= lovel && vel <= hivel &&
146     bend >= lobend && bend <= hibend &&
147     bpm >= lobpm && bpm <= hibpm &&
148     chanaft >= lochanaft && chanaft <= hichanaft &&
149     polyaft >= lopolyaft && polyaft <= hipolyaft &&
150     prog >= loprog && prog <= hiprog &&
151     rand >= lorand && rand <= hirand &&
152     timer >= lotimer && timer <= hitimer &&
153     seq == seq_position &&
154    
155     ( (sw_lokey == -1 || sw_hikey == -1 || sw_last == -1) ||
156     ((sw_last >= sw_lokey && sw_last <= sw_hikey) ? (last_sw_key == sw_last) : true) ) &&
157    
158     ( (sw_down == -1 || sw_lokey == -1 || sw_hikey == -1) ||
159     ((sw_down >= sw_lokey && sw_down <= sw_hikey) ? (sw[sw_down]) : true) ) &&
160    
161     ( (sw_up == -1 || sw_lokey == -1 || sw_hikey == -1) ||
162     ((sw_up >= sw_lokey && sw_up <= sw_hikey) ? (!sw[sw_up]) : true) ) &&
163    
164     ((sw_previous != -1) ? (prev_sw_key == sw_previous) : true) &&
165     ((trigger && trig) != 0)
166     );
167    
168     if (!is_triggered)
169     return false;
170    
171     for (int i = 0; i < 128; ++i)
172     {
173     if (locc[i] != -1 && hicc[i] != -1 && !(cc[i] >= locc[i] && cc[i] <= hicc[i]))
174     return false;
175     }
176    
177     return true;
178     }
179    
180     bool
181     Region::OnControl(uint8_t chan, uint8_t cont, uint8_t val,
182     int bend, uint8_t bpm, uint8_t chanaft, uint8_t polyaft,
183     uint8_t prog, float rand, trigger_t trig, uint8_t* cc,
184     float timer, uint8_t seq, bool* sw, uint8_t last_sw_key, uint8_t prev_sw_key)
185     {
186     // chan (MIDI channel)
187     // cont (MIDI controller)
188     // val (MIDI controller value)
189    
190     // bend (MIDI pitch bend)
191     // bpm (host BPM)
192     // chanaft (MIDI channel pressure)
193     // polyaft (MIDI polyphonic aftertouch)
194     // prog (MIDI program change)
195     // rand (generated random number)
196     // trigger (how it was triggered)
197     // cc (all CC values)
198    
199     // timer (time since previous region in the group was triggered)
200     // seq (the state of the region sequence counter)
201     // sw (the state of region key switches, 128 possible values)
202     // last_sw_key (the last key pressed in the key switch range)
203     // prev_sw_key (the previous note value)
204    
205     bool is_triggered = (
206     chan >= lochan && chan <= hichan &&
207     ((val >= on_locc[cont] && val <= on_hicc[cont]) ||
208     (val >= start_locc[cont] && val <= start_hicc[cont])) &&
209     bend >= lobend && bend <= hibend &&
210     bpm >= lobpm && bpm <= hibpm &&
211     chanaft >= lochanaft && chanaft <= hichanaft &&
212     polyaft >= lopolyaft && polyaft <= hipolyaft &&
213     prog >= loprog && prog <= hiprog &&
214     rand >= lorand && rand <= hirand &&
215     timer >= lotimer && timer <= hitimer &&
216     seq == seq_position &&
217    
218     ( (sw_lokey == -1 || sw_hikey == -1 || sw_last == -1) ||
219     ((sw_last >= sw_lokey && sw_last <= sw_hikey) ? (last_sw_key == sw_last) : true) ) &&
220    
221     ( (sw_down == -1 || sw_lokey == -1 || sw_hikey == -1) ||
222     ((sw_down >= sw_lokey && sw_down <= sw_hikey) ? (sw[sw_down]) : true) ) &&
223    
224     ( (sw_up == -1 || sw_lokey == -1 || sw_hikey == -1) ||
225     ((sw_up >= sw_lokey && sw_up <= sw_hikey) ? (!sw[sw_up]) : true) ) &&
226    
227     ((sw_previous != -1) ? (prev_sw_key == sw_previous) : true) &&
228     ((trigger && trig) != 0)
229     );
230    
231     if (!is_triggered)
232     return false;
233    
234     for (int i = 0; i < 128; ++i)
235     {
236     if (locc[i] != -1 && hicc[i] != -1 && !(cc[i] >= locc[i] && cc[i] <= hicc[i]))
237     return false;
238     }
239    
240     return true;
241     }
242    
243     Articulation*
244     Region::GetArticulation(int bend, uint8_t bpm, uint8_t chanaft, uint8_t polyaft, uint8_t* cc)
245     {
246     return new Articulation(); //todo: implement GetArticulation()
247     }
248    
249 iliev 2021 bool Region::HasLoop() {
250     bool b = loop_mode == ::sfz::LOOP_CONTINUOUS || loop_mode == ::sfz::LOOP_SUSTAIN; // TODO: ONE_SHOT mode
251     return b && GetLoopStart() && GetLoopEnd() && GetLoopEnd() > GetLoopStart();
252     }
253    
254     uint Region::GetLoopStart() {
255     return (!loop_start) ? 0 : *loop_start; // TODO: use sample loop when loop_start not defined
256     }
257    
258     uint Region::GetLoopEnd() {
259     return (!loop_end) ? 0 : *loop_end; // TODO: use sample loop when loop_end not defined
260     }
261    
262     uint Region::GetLoopCount() {
263     return (!count) ? 0 : *count;
264     }
265    
266 iliev 2012 /////////////////////////////////////////////////////////////
267     // class Instrument
268    
269     Instrument::Instrument(std::string name, SampleManager* pSampleManager) : KeyBindings(128, false), KeySwitchBindings(128, false)
270     {
271     this->name = name;
272     this->pSampleManager = pSampleManager ? pSampleManager : this;
273     }
274    
275     Instrument::~Instrument()
276     {
277     for(int i = 0; i < regions.size(); i++) {
278     delete (regions[i]);
279     }
280     regions.clear();
281     }
282    
283     std::vector<Region*> Instrument::GetRegionsOnKey (
284     uint8_t chan, uint8_t key, uint8_t vel,
285     int bend, uint8_t bpm, uint8_t chanaft, uint8_t polyaft,
286     uint8_t prog, float rand, trigger_t trig, uint8_t* cc,
287     float timer, uint8_t seq, bool* sw, uint8_t last_sw_key, uint8_t prev_sw_key
288     ) {
289     std::vector<Region*> v;
290     for (int i = 0; i < regions.size(); i++) {
291     if (regions[i]->OnKey (
292     chan, key, vel, bend, bpm, chanaft, polyaft, prog,
293     rand, trig, cc, timer, seq, sw, last_sw_key, prev_sw_key)
294     ) { v.push_back(regions[i]); }
295     }
296    
297     return v;
298     }
299    
300     bool Instrument::DestroyRegion(Region* pRegion) {
301     for (std::vector<Region*>::iterator it = regions.begin(); it != regions.end(); it++) {
302     if(*it == pRegion) {
303     regions.erase(it);
304     delete pRegion;
305     return true;
306     }
307     }
308    
309     return false;
310     }
311    
312     bool Instrument::HasKeyBinding(uint8_t key) {
313     if (key > 127) return false;
314     return KeyBindings[key];
315     }
316    
317     bool Instrument::HasKeySwitchBinding(uint8_t key) {
318     if (key > 127) return false;
319     return KeySwitchBindings[key];
320     }
321    
322     /////////////////////////////////////////////////////////////
323     // class Group
324    
325     Group::Group() :
326     id(0)
327     {
328     Reset();
329     }
330    
331     Group::~Group()
332     {
333     }
334    
335     void
336     Group::Reset()
337     {
338     // This is where all the default values are set.
339    
340     // sample definition default
341     sample = "";
342    
343     // input control
344     lochan = 1; hichan = 16;
345     lokey = 0; hikey = 127;
346     lovel = 0; hivel = 127;
347     lobend = -8192; hibend = 8192;
348     lobpm = 0; hibpm = 500;
349     lochanaft = 0; hichanaft = 127;
350     lopolyaft = 0; hipolyaft = 127;
351     loprog = 0; hiprog = 127;
352     lorand = 0.0; hirand = 1.0;
353     lotimer = 0.0; hitimer = 0.0;
354    
355     seq_length = 1;
356     seq_position = 1;
357    
358     sw_lokey = -1; sw_hikey = -1;
359     sw_last = -1;
360     sw_down = -1;
361     sw_up = -1;
362     sw_previous = -1;
363     sw_vel = VEL_CURRENT;
364    
365     trigger = TRIGGER_ATTACK;
366    
367     group.unset();
368     off_by.unset();
369     off_mode = OFF_FAST;
370    
371     // sample player
372     count.unset();
373     delay.unset(); delay_random.unset();
374     delay_beats.unset(); stop_beats.unset();
375     delay_samples.unset();
376     end.unset();
377     loop_crossfade.unset();
378     offset.unset(); offset_random.unset();
379     loop_mode = NO_LOOP;
380     loop_start.unset(); loop_end.unset();
381     sync_beats.unset(); sync_offset.unset();
382    
383     // amplifier
384     volume = 0;
385     pan = 0;
386     width = 100;
387     position = 0;
388     amp_keytrack = 0;
389     amp_keycenter = 60;
390     amp_veltrack = 100;
391     amp_random = 0;
392     rt_decay = 0;
393     xfin_lokey = 0; xfin_hikey = 0;
394     xfout_lokey = 127; xfout_hikey = 127;
395     xf_keycurve = POWER;
396     xfin_lovel = 0; xfin_hivel = 0;
397     xfout_lovel = 127; xfout_hivel = 127;
398     xf_velcurve = POWER;
399     xf_cccurve = POWER;
400    
401     // pitch
402     transpose = 0;
403     tune = 0;
404     pitch_keycenter = 60;
405     pitch_keytrack = 100;
406     pitch_veltrack = 0;
407     pitch_random = 0;
408     bend_up = 200;
409     bend_down = -200;
410     bend_step = 1;
411    
412     // filter
413     fil_type = LPF_2P;
414     cutoff.unset();
415     cutoff_chanaft = 0;
416     cutoff_polyaft = 0;
417     resonance = 0;
418     fil_keytrack = 0;
419     fil_keycenter = 60;
420     fil_veltrack = 0;
421     fil_random = 0;
422    
423     fil2_type = LPF_2P;
424     cutoff2.unset();
425     cutoff2_chanaft = 0;
426     cutoff2_polyaft = 0;
427     resonance2 = 0;
428     fil2_keytrack = 0;
429     fil2_keycenter = 60;
430     fil2_veltrack = 0;
431     fil2_random = 0;
432    
433     // per voice equalizer
434     eq1_freq = 50;
435     eq2_freq = 500;
436     eq3_freq = 5000;
437     eq1_vel2freq = 0;
438     eq2_vel2freq = 0;
439     eq3_vel2freq = 0;
440     eq1_bw = 1;
441     eq2_bw = 1;
442     eq3_bw = 1;
443     eq1_gain = 0;
444     eq2_gain = 0;
445     eq3_gain = 0;
446     eq1_vel2gain = 0;
447     eq2_vel2gain = 0;
448     eq3_vel2gain = 0;
449    
450     // CCs
451     for (int i = 0; i < 128; ++i)
452     {
453     // input control
454     locc[i] = 0;
455     hicc[i] = 127;
456     start_locc[i] = -1;
457     start_hicc[i] = -1;
458     stop_locc[i] = -1;
459     stop_hicc[i] = -1;
460     on_locc[i] = -1;
461     on_hicc[i] = -1;
462    
463     // sample player
464     delay_oncc[i].unset();
465     delay_samples_oncc[i].unset();
466     offset_oncc[i].unset();
467    
468     // amplifier
469     amp_velcurve_[i] = 0; //fixme: 20 log (127^2 / i^2)
470     gain_oncc[i] = 0;
471     xfin_locc[i] = 0;
472     xfin_hicc[i] = 0;
473     xfout_locc[i] = 127;
474     xfout_hicc[i] = 127;
475    
476     // filter
477     cutoff_oncc[i] = 0;
478     cutoff_smoothcc[i] = 0;
479     cutoff_stepcc[i] = 0;
480     cutoff_curvecc[i] = 0;
481     resonance_oncc[i] = 0;
482     resonance_smoothcc[i] = 0;
483     resonance_stepcc[i] = 0;
484     resonance_curvecc[i] = 0;
485    
486     cutoff2_oncc[i] = 0;
487     cutoff2_smoothcc[i] = 0;
488     cutoff2_stepcc[i] = 0;
489     cutoff2_curvecc[i] = 0;
490     resonance2_oncc[i] = 0;
491     resonance2_smoothcc[i] = 0;
492     resonance2_stepcc[i] = 0;
493     resonance2_curvecc[i] = 0;
494    
495     // per voice equalizer
496     eq1_freq_oncc[i] = 0;
497     eq2_freq_oncc[i] = 0;
498     eq3_freq_oncc[i] = 0;
499     eq1_bw_oncc[i] = 0;
500     eq2_bw_oncc[i] = 0;
501     eq3_bw_oncc[i] = 0;
502     eq1_gain_oncc[i] = 0;
503     eq2_gain_oncc[i] = 0;
504     eq3_gain_oncc[i] = 0;
505     }
506 iliev 2018
507     // deprecated
508     ampeg_delay = 0;
509     ampeg_start = 0; //in percentage
510     ampeg_attack = 0;
511     ampeg_hold = 0;
512     ampeg_decay = 0;
513     ampeg_sustain = 100; // in percentage
514     ampeg_release = 0;
515    
516     fileg_delay = 0;
517     fileg_start = 0; //in percentage
518     fileg_attack = 0;
519     fileg_hold = 0;
520     fileg_decay = 0;
521     fileg_sustain = 100; // in percentage
522     fileg_release = 0;
523    
524     pitcheg_delay = 0;
525     pitcheg_start = 0; //in percentage
526     pitcheg_attack = 0;
527     pitcheg_hold = 0;
528     pitcheg_decay = 0;
529     pitcheg_sustain = 100; // in percentage
530     pitcheg_release = 0;
531 iliev 2012 }
532    
533     Region*
534     Group::RegionFactory()
535     {
536     // This is where the current group setting are copied to the new region.
537    
538     Region* region = new Region();
539    
540     region->id = id++;
541    
542     // sample definition
543     region->sample = sample;
544    
545     // input control
546     region->lochan = lochan;
547     region->hichan = hichan;
548     region->lokey = lokey;
549     region->hikey = hikey;
550     region->lovel = lovel;
551     region->hivel = hivel;
552     region->locc = locc;
553     region->hicc = hicc;
554     region->lobend = lobend;
555     region->hibend = hibend;
556     region->lobpm = lobpm;
557     region->hibpm = hibpm;
558     region->lochanaft = lochanaft;
559     region->hichanaft = hichanaft;
560     region->lopolyaft = lopolyaft;
561     region->hipolyaft = hipolyaft;
562     region->loprog = loprog;
563     region->hiprog = hiprog;
564     region->lorand = lorand;
565     region->hirand = hirand;
566     region->lotimer = lotimer;
567     region->hitimer = hitimer;
568     region->seq_length = seq_length;
569     region->seq_position = seq_position;
570     region->start_locc = start_locc;
571     region->start_hicc = start_hicc;
572     region->stop_locc = stop_locc;
573     region->stop_hicc = stop_hicc;
574     region->sw_lokey = sw_lokey;
575     region->sw_hikey = sw_hikey;
576     region->sw_last = sw_last;
577     region->sw_down = sw_down;
578     region->sw_up = sw_up;
579     region->sw_previous = sw_previous;
580     region->sw_vel = sw_vel;
581     region->trigger = trigger;
582     region->group = group;
583     region->off_by = off_by;
584     region->off_mode = off_mode;
585     region->on_locc = on_locc;
586     region->on_hicc = on_hicc;
587    
588     // sample player
589     region->count = count;
590     region->delay = delay;
591     region->delay_random = delay_random;
592     region->delay_oncc = delay_oncc;
593     region->delay_beats = delay_beats;
594     region->stop_beats = stop_beats;
595     region->delay_samples = delay_samples;
596     region->delay_samples_oncc = delay_samples_oncc;
597     region->end = end;
598     region->loop_crossfade = loop_crossfade;
599     region->offset = offset;
600     region->offset_random = offset_random;
601     region->offset_oncc = offset_oncc;
602     region->loop_mode = loop_mode;
603     region->loop_start = loop_start;
604     region->loop_end = loop_end;
605     region->sync_beats = sync_beats;
606     region->sync_offset = sync_offset;
607    
608     // amplifier
609     region->volume = volume;
610     region->pan = pan;
611     region->width = width;
612     region->position = position;
613     region->amp_keytrack = amp_keytrack;
614     region->amp_keycenter = amp_keycenter;
615     region->amp_veltrack = amp_veltrack;
616     region->amp_velcurve_ = amp_velcurve_;
617     region->amp_random = amp_random;
618     region->rt_decay = rt_decay;
619     region->gain_oncc = gain_oncc;
620     region->xfin_lokey = xfin_lokey;
621     region->xfin_hikey = xfin_hikey;
622     region->xfout_lokey = xfout_lokey;
623     region->xfout_hikey = xfout_hikey;
624     region->xf_keycurve = xf_keycurve;
625     region->xfin_lovel = xfin_lovel;
626     region->xfin_hivel = xfin_lovel;
627     region->xfout_lovel = xfout_lovel;
628     region->xfout_hivel = xfout_hivel;
629     region->xf_velcurve = xf_velcurve;
630     region->xfin_locc = xfin_locc;
631     region->xfin_hicc = xfin_hicc;
632     region->xfout_locc = xfout_locc;
633     region->xfout_hicc = xfout_hicc;
634     region->xf_cccurve = xf_cccurve;
635    
636     // pitch
637     region->transpose = transpose;
638     region->tune = tune;
639     region->pitch_keycenter = pitch_keycenter;
640     region->pitch_keytrack = pitch_keytrack;
641     region->pitch_veltrack = pitch_veltrack;
642     region->pitch_random = pitch_random;
643     region->bend_up = bend_up;
644     region->bend_down = bend_down;
645     region->bend_step = bend_step;
646    
647     // filter
648     region->fil_type = fil_type;
649     region->cutoff = cutoff;
650     region->cutoff_oncc = cutoff_oncc;
651     region->cutoff_smoothcc = cutoff_smoothcc;
652     region->cutoff_stepcc = cutoff_stepcc;
653     region->cutoff_curvecc = cutoff_curvecc;
654     region->cutoff_chanaft = cutoff_chanaft;
655     region->cutoff_polyaft = cutoff_polyaft;
656     region->resonance = resonance;
657     region->resonance_oncc = resonance_oncc;
658     region->resonance_smoothcc = resonance_smoothcc;
659     region->resonance_stepcc = resonance_stepcc;
660     region->resonance_curvecc = resonance_curvecc;
661     region->fil_keytrack = fil_keytrack;
662     region->fil_keycenter = fil_keycenter;
663     region->fil_veltrack = fil_veltrack;
664     region->fil_random = fil_random;
665    
666     region->fil2_type = fil2_type;
667     region->cutoff2 = cutoff2;
668     region->cutoff2_oncc = cutoff2_oncc;
669     region->cutoff2_smoothcc = cutoff2_smoothcc;
670     region->cutoff2_stepcc = cutoff2_stepcc;
671     region->cutoff2_curvecc = cutoff2_curvecc;
672     region->cutoff2_chanaft = cutoff2_chanaft;
673     region->cutoff2_polyaft = cutoff2_polyaft;
674     region->resonance2 = resonance2;
675     region->resonance2_oncc = resonance2_oncc;
676     region->resonance2_smoothcc = resonance2_smoothcc;
677     region->resonance2_stepcc = resonance2_stepcc;
678     region->resonance2_curvecc = resonance2_curvecc;
679     region->fil2_keytrack = fil2_keytrack;
680     region->fil2_keycenter = fil2_keycenter;
681     region->fil2_veltrack = fil2_veltrack;
682     region->fil2_random = fil2_random;
683    
684     // per voice equalizer
685     region->eq1_freq = eq1_freq;
686     region->eq2_freq = eq2_freq;
687     region->eq3_freq = eq3_freq;
688     region->eq1_freq_oncc = eq1_freq_oncc;
689     region->eq2_freq_oncc = eq2_freq_oncc;
690     region->eq3_freq_oncc = eq3_freq_oncc;
691     region->eq1_vel2freq = eq1_vel2freq;
692     region->eq2_vel2freq = eq2_vel2freq;
693     region->eq3_vel2freq = eq3_vel2freq;
694     region->eq1_bw = eq1_bw;
695     region->eq2_bw = eq2_bw;
696     region->eq3_bw = eq3_bw;
697     region->eq1_bw_oncc = eq1_bw_oncc;
698     region->eq2_bw_oncc = eq2_bw_oncc;
699     region->eq3_bw_oncc = eq3_bw_oncc;
700     region->eq1_gain = eq1_gain;
701     region->eq2_gain = eq2_gain;
702     region->eq3_gain = eq3_gain;
703     region->eq1_gain_oncc = eq1_gain_oncc;
704     region->eq2_gain_oncc = eq2_gain_oncc;
705     region->eq3_gain_oncc = eq3_gain_oncc;
706     region->eq1_vel2gain = eq1_vel2gain;
707     region->eq2_vel2gain = eq2_vel2gain;
708     region->eq3_vel2gain = eq3_vel2gain;
709    
710 iliev 2018 // deprecated
711     region->ampeg_delay = ampeg_delay;
712     region->ampeg_start = ampeg_start;
713     region->ampeg_attack = ampeg_attack;
714     region->ampeg_hold = ampeg_hold;
715     region->ampeg_decay = ampeg_decay;
716     region->ampeg_sustain = ampeg_sustain;
717     region->ampeg_release = ampeg_release;
718    
719     region->fileg_delay = fileg_delay;
720     region->fileg_start = fileg_start;
721     region->fileg_attack = fileg_attack;
722     region->fileg_hold = fileg_hold;
723     region->fileg_decay = fileg_decay;
724     region->fileg_sustain = fileg_sustain;
725     region->fileg_release = fileg_release;
726    
727     region->pitcheg_delay = pitcheg_delay;
728     region->pitcheg_start = pitcheg_start;
729     region->pitcheg_attack = pitcheg_attack;
730     region->pitcheg_hold = pitcheg_hold;
731     region->pitcheg_decay = pitcheg_decay;
732     region->pitcheg_sustain = pitcheg_sustain;
733     region->pitcheg_release = pitcheg_release;
734    
735 iliev 2012 return region;
736     }
737    
738     /////////////////////////////////////////////////////////////
739     // class File
740    
741     File::File(std::string file, SampleManager* pSampleManager) :
742     _current_section(GROUP),
743     default_path(""),
744     octave_offset(0),
745     note_offset(0)
746     {
747     _instrument = new Instrument(LinuxSampler::Path::getBaseName(file), pSampleManager);
748     _current_group = new Group();
749     pCurDef = _current_group;
750     enum token_type_t { HEADER, OPCODE };
751     token_type_t token_type;
752     std::string token_string;
753    
754     std::ifstream fs(file.c_str());
755     currentDir = LinuxSampler::Path::stripLastName(file);
756     std::string token;
757     std::string line;
758    
759     while (std::getline(fs, line))
760     {
761     // COMMENT
762     std::string::size_type slash_index = line.find("//");
763     if (slash_index != std::string::npos)
764     line.resize(slash_index);
765    
766     // DEFINITION
767     std::stringstream linestream(line);
768     while (linestream >> token)
769     {
770     if (token[0] == '<' and token[token.size()-1] == '>')
771     {
772     // HEAD
773     if (!token_string.empty())
774     {
775     switch (token_type)
776     {
777     case HEADER:
778     push_header(token_string);
779     break;
780     case OPCODE:
781     push_opcode(token_string);
782     break;
783     }
784     token_string.erase();
785     }
786     token_string.append(token);
787     token_type = HEADER;
788     }
789     else if (token.find('=') != std::string::npos)
790     {
791     // HEAD
792     if (!token_string.empty())
793     {
794     switch (token_type)
795     {
796     case HEADER:
797     push_header(token_string);
798     break;
799     case OPCODE:
800     push_opcode(token_string);
801     break;
802     }
803     token_string.erase();
804     }
805     token_string.append(token);
806     token_type = OPCODE;
807     }
808     else
809     {
810     // TAIL
811     token_string.append(" ");
812     token_string.append(token);
813     }
814     }
815    
816     // EOL
817     if (!token_string.empty())
818     {
819     switch (token_type)
820     {
821     case HEADER:
822     push_header(token_string);
823     break;
824     case OPCODE:
825     push_opcode(token_string);
826     break;
827     }
828     token_string.erase();
829     }
830     }
831    
832     for (int i = 0; i < _instrument->regions.size(); i++) {
833     ::sfz::Region* pRegion = _instrument->regions[i];
834     int low = pRegion->lokey;
835     int high = pRegion->hikey;
836     if (low < 0 || low > 127 || high < 0 || high > 127 || low > high) {
837     std::cerr << "Invalid key range: " << low << " - " << high << std::endl;
838     } else {
839     for (int j = low; j <= high; j++) _instrument->KeyBindings[j] = true;
840     }
841    
842     // get keyswitches
843     low = pRegion->sw_lokey;
844     high = pRegion->sw_hikey;
845     if(low == -1 && high == -1) {
846     // Key switches not defined, so nothing to do
847     } else if(low >= 0 && low <= 127 && high >= 0 && high <= 127 && high >= low) {
848     for (int j = low; j <= high; j++) _instrument->KeySwitchBindings[j] = true;
849     } else {
850     std::cerr << "Invalid key switch range: " << low << " - " << high << std::endl;
851     }
852     }
853     }
854    
855     File::~File()
856     {
857     delete _current_group;
858     delete _instrument;
859     }
860    
861     Instrument*
862     File::GetInstrument()
863     {
864     return _instrument;
865     }
866    
867     void
868     File::push_header(std::string token)
869     {
870     if (token == "<group>")
871     {
872     _current_section = GROUP;
873     _current_group->Reset();
874     pCurDef = _current_group;
875     }
876     else if (token == "<region>")
877     {
878     _current_section = REGION;
879     _current_region = _current_group->RegionFactory();
880     pCurDef = _current_region;
881     _instrument->regions.push_back(_current_region);
882     _current_region->SetInstrument(_instrument);
883     }
884     else if (token == "<control>")
885     {
886     _current_section = CONTROL;
887     default_path = "";
888     octave_offset = 0;
889     note_offset = 0;
890     }
891     else
892     {
893     _current_section = UNKNOWN;
894     std::cerr << "The header '" << token << "' is unsupported by libsfz!" << std::endl;
895     }
896     }
897    
898     void
899     File::push_opcode(std::string token)
900     {
901     if (_current_section == UNKNOWN)
902     return;
903    
904     std::string::size_type delimiter_index = token.find('=');
905     std::string key = token.substr(0, delimiter_index);
906     std::string value = token.substr(delimiter_index + 1);
907    
908     // sample definition
909     if ("sample" == key)
910     {
911     std::string path = default_path + value;
912     #ifndef WIN32
913     for (int i = 0; i < path.length(); i++) if( path[i] == '\\') path[i] = '/';
914     #endif
915     path = currentDir + LinuxSampler::File::DirSeparator + path; // TODO: check for absolute path
916    
917     if(pCurDef) pCurDef->sample = path;
918     return;
919     }
920    
921     // control header directives
922     else if ("default_path" == key)
923     {
924     switch (_current_section)
925     {
926     case CONTROL:
927     default_path = value;
928     }
929     return;
930     }
931     else if ("octave_offset" == key)
932     {
933     switch (_current_section)
934     {
935     case CONTROL:
936     octave_offset = ToInt(value);
937     }
938     return;
939     }
940     else if ("note_offset" == key)
941     {
942     switch (_current_section)
943     {
944     case CONTROL:
945     note_offset = ToInt(value);
946     }
947     return;
948     }
949    
950     // input controls
951     else if ("lochan" == key) pCurDef->lochan = ToInt(value);
952     else if ("hichan" == key) pCurDef->hichan = ToInt(value);
953     else if ("lokey" == key) pCurDef->lokey = ToInt(value) + note_offset + 12 * octave_offset;
954     else if ("hikey" == key) pCurDef->hikey = ToInt(value) + note_offset + 12 * octave_offset;
955     else if ("key" == key)
956     {
957     pCurDef->lokey = ToInt(value) + note_offset + 12 * octave_offset;
958     pCurDef->hikey = ToInt(value) + note_offset + 12 * octave_offset;
959     }
960     else if ("lovel" == key) pCurDef->lovel = ToInt(value);
961     else if ("hivel" == key) pCurDef->hivel = ToInt(value);
962     else if ("lobend" == key) pCurDef->lobend = ToInt(value);
963     else if ("hibend" == key) pCurDef->hibend = ToInt(value);
964     else if ("lobpm" == key) pCurDef->lobpm = ToInt(value);
965     else if ("hibpm" == key) pCurDef->hibpm = ToInt(value);
966     else if ("lochanaft" == key) pCurDef->lochanaft = ToInt(value);
967     else if ("hichanaft" == key) pCurDef->hichanaft = ToInt(value);
968     else if ("lopolyaft" == key) pCurDef->lopolyaft = ToInt(value);
969     else if ("hipolyaft" == key) pCurDef->hipolyaft = ToInt(value);
970     else if ("loprog" == key) pCurDef->loprog = ToInt(value);
971     else if ("hiprog" == key) pCurDef->hiprog = ToInt(value);
972     else if ("lorand" == key) pCurDef->lorand = ToFloat(value);
973     else if ("hirand" == key) pCurDef->hirand = ToFloat(value);
974     else if ("lotimer" == key) pCurDef->lotimer = ToFloat(value);
975     else if ("hitimer" == key) pCurDef->hitimer = ToFloat(value);
976     else if ("seq_length" == key) pCurDef->seq_length = ToInt(value);
977     else if ("seq_position" == key) pCurDef->seq_position = ToInt(value);
978     else if ("sw_lokey" == key) pCurDef->sw_lokey = ToInt(value) + note_offset + 12 * octave_offset;
979     else if ("sw_hikey" == key) pCurDef->sw_hikey = ToInt(value) + note_offset + 12 * octave_offset;
980     else if ("sw_last" == key) pCurDef->sw_last = ToInt(value) + note_offset + 12 * octave_offset;
981     else if ("sw_down" == key) pCurDef->sw_down = ToInt(value) + note_offset + 12 * octave_offset;
982     else if ("sw_up" == key) pCurDef->sw_up = ToInt(value) + note_offset + 12 * octave_offset;
983     else if ("sw_previous" == key) pCurDef->sw_previous = ToInt(value) + note_offset + 12 * octave_offset;
984     else if ("sw_vel" == key)
985     {
986     if (value == "current") pCurDef->sw_vel = VEL_CURRENT;
987     else if (value == "previous") pCurDef->sw_vel = VEL_PREVIOUS;
988     }
989     else if ("trigger" == key)
990     {
991     if (value == "attack") pCurDef->trigger = TRIGGER_ATTACK;
992     else if (value == "release") pCurDef->trigger = TRIGGER_RELEASE;
993     else if (value == "first") pCurDef->trigger = TRIGGER_FIRST;
994     else if (value == "legato") pCurDef->trigger = TRIGGER_LEGATO;
995     }
996     else if ("group" == key) pCurDef->group = ToInt(value);
997     else if ("off_by" == key) pCurDef->off_by = ToInt(value);
998     else if ("off_mode" == key)
999     {
1000     if (value == "fast") _current_group->off_mode = OFF_FAST;
1001     else if (value == "normal") _current_group->off_mode = OFF_NORMAL;
1002     }
1003    
1004     // sample player
1005 iliev 2021 else if ("count" == key) { pCurDef->count = ToInt(value); pCurDef->loop_mode = ONE_SHOT; }
1006 iliev 2012 else if ("delay" == key) pCurDef->delay = ToFloat(value);
1007     else if ("delay_random" == key) pCurDef->delay_random = ToFloat(value);
1008     else if ("delay_beats" == key) pCurDef->delay_beats = ToInt(value);
1009     else if ("stop_beats" == key) pCurDef->stop_beats = ToInt(value);
1010     else if ("delay_samples" == key) pCurDef->delay_samples = ToInt(value);
1011     else if ("end" == key) pCurDef->end = ToInt(value);
1012     else if ("loop_crossfade" == key) pCurDef->loop_crossfade = ToFloat(value);
1013     else if ("offset_random" == key) pCurDef->offset_random = ToInt(value);
1014     else if ("loop_mode" == key)
1015     {
1016     if (value == "no_loop") pCurDef->loop_mode = NO_LOOP;
1017     else if (value == "one_shot") pCurDef->loop_mode = ONE_SHOT;
1018 iliev 2021 else if (value == "loop_continuous") pCurDef->loop_mode = LOOP_CONTINUOUS;
1019 iliev 2012 else if (value == "loop_sustain") pCurDef->loop_mode = LOOP_SUSTAIN;
1020     }
1021     else if ("loop_start" == key) pCurDef->loop_start = ToInt(value);
1022 iliev 2021 else if ("loopstart" == key) pCurDef->loop_start = ToInt(value); // nonstandard
1023 iliev 2012 else if ("loop_end" == key) pCurDef->loop_end = ToInt(value);
1024 iliev 2021 else if ("loopend" == key) pCurDef->loop_end = ToInt(value); // nonstandard
1025 iliev 2012 else if ("sync_beats" == key) pCurDef->sync_beats = ToInt(value);
1026     else if ("sync_offset" == key) pCurDef->sync_offset = ToInt(value);
1027    
1028     // amplifier
1029     else if ("volume" == key) pCurDef->volume = ToFloat(value);
1030     else if ("pan" == key) pCurDef->pan = ToFloat(value);
1031     else if ("width" == key) pCurDef->width = ToFloat(value);
1032     else if ("position" == key) pCurDef->position = ToFloat(value);
1033     else if ("amp_keytrack" == key) pCurDef->amp_keytrack = ToFloat(value);
1034     else if ("amp_keycenter" == key) pCurDef->amp_keycenter = ToInt(value) + note_offset + 12 * octave_offset;
1035     else if ("amp_veltrack" == key) pCurDef->amp_veltrack = ToFloat(value);
1036     else if ("amp_random" == key) pCurDef->amp_random = ToFloat(value);
1037     else if ("rt_decay" == key) pCurDef->rt_decay = ToFloat(value);
1038     else if ("xfin_lokey" == key) pCurDef->xfin_lokey = ToInt(value) + note_offset + 12 * octave_offset;
1039     else if ("xfin_hikey" == key) pCurDef->xfin_hikey = ToInt(value) + note_offset + 12 * octave_offset;
1040     else if ("xfout_lokey" == key) pCurDef->xfout_lokey = ToInt(value) + note_offset + 12 * octave_offset;
1041     else if ("xfout_hikey" == key) pCurDef->xfout_hikey = ToInt(value) + note_offset + 12 * octave_offset;
1042     else if ("xf_keycurve" == key)
1043     {
1044     if (value == "gain") pCurDef->xf_keycurve = GAIN;
1045     else if (value == "power") pCurDef->xf_keycurve = POWER;
1046     }
1047     else if ("xfin_lovel" == key) pCurDef->xfin_lovel = ToInt(value);
1048     else if ("xfin_hivel" == key) pCurDef->xfin_hivel = ToInt(value);
1049     else if ("xfout_lovel" == key) pCurDef->xfout_lovel = ToInt(value);
1050     else if ("xfout_hivel" == key) pCurDef->xfout_hivel = ToInt(value);
1051     else if ("xf_velcurve" == key)
1052     {
1053     if (value == "gain") pCurDef->xf_velcurve = GAIN;
1054     else if (value == "power") pCurDef->xf_velcurve = POWER;
1055     }
1056     else if ("xf_cccurve" == key)
1057     {
1058     if (value == "gain") pCurDef->xf_cccurve = GAIN;
1059     else if (value == "power") pCurDef->xf_cccurve = POWER;
1060     }
1061    
1062     // pitch
1063     else if ("transpose" == key) pCurDef->transpose = ToInt(value);
1064     else if ("tune" == key) pCurDef->tune = ToInt(value);
1065     else if ("pitch_keycenter" == key) pCurDef->pitch_keycenter = ToInt(value) + note_offset + 12 * octave_offset;
1066     else if ("pitch_keytrack" == key) pCurDef->pitch_keytrack = ToInt(value);
1067     else if ("pitch_veltrack" == key) pCurDef->pitch_veltrack = ToInt(value);
1068     else if ("pitch_random" == key) pCurDef->pitch_random = ToInt(value);
1069     else if ("bend_up" == key) pCurDef->bend_up = ToInt(value);
1070     else if ("bend_down" == key) pCurDef->bend_down = ToInt(value);
1071     else if ("bend_step" == key) pCurDef->bend_step = ToInt(value);
1072    
1073     // filter
1074     else if ("fil_type" == key)
1075     {
1076     if (value == "lpf_1p") pCurDef->fil_type = LPF_1P;
1077     else if (value == "hpf_1p") pCurDef->fil_type = HPF_1P;
1078     else if (value == "bpf_1p") pCurDef->fil_type = BPF_1P;
1079     else if (value == "brf_1p") pCurDef->fil_type = BRF_1P;
1080     else if (value == "apf_1p") pCurDef->fil_type = APF_1P;
1081     else if (value == "lpf_2p") pCurDef->fil_type = LPF_2P;
1082     else if (value == "hpf_2p") pCurDef->fil_type = HPF_2P;
1083     else if (value == "bpf_2p") pCurDef->fil_type = BPF_2P;
1084     else if (value == "brf_2p") pCurDef->fil_type = BRF_2P;
1085     else if (value == "pkf_2p") pCurDef->fil_type = PKF_2P;
1086     else if (value == "lpf_4p") pCurDef->fil_type = LPF_4P;
1087     else if (value == "hpf_4p") pCurDef->fil_type = HPF_4P;
1088     else if (value == "lpf_6p") pCurDef->fil_type = LPF_6P;
1089     else if (value == "hpf_6p") pCurDef->fil_type = HPF_6P;
1090     }
1091     else if ("fil2_type" == key)
1092     {
1093     if (value == "lpf_1p") pCurDef->fil2_type = LPF_1P;
1094     else if (value == "hpf_1p") pCurDef->fil2_type = HPF_1P;
1095     else if (value == "bpf_1p") pCurDef->fil2_type = BPF_1P;
1096     else if (value == "brf_1p") pCurDef->fil2_type = BRF_1P;
1097     else if (value == "apf_1p") pCurDef->fil2_type = APF_1P;
1098     else if (value == "lpf_2p") pCurDef->fil2_type = LPF_2P;
1099     else if (value == "hpf_2p") pCurDef->fil2_type = HPF_2P;
1100     else if (value == "bpf_2p") pCurDef->fil2_type = BPF_2P;
1101     else if (value == "brf_2p") pCurDef->fil2_type = BRF_2P;
1102     else if (value == "pkf_2p") pCurDef->fil2_type = PKF_2P;
1103     else if (value == "lpf_4p") pCurDef->fil2_type = LPF_4P;
1104     else if (value == "hpf_4p") pCurDef->fil2_type = HPF_4P;
1105     else if (value == "lpf_6p") pCurDef->fil2_type = LPF_6P;
1106     else if (value == "hpf_6p") pCurDef->fil2_type = HPF_6P;
1107     }
1108     else if ("cutoff" == key) pCurDef->cutoff = ToFloat(value);
1109     else if ("cutoff2" == key) pCurDef->cutoff2 = ToFloat(value);
1110     else if ("cutoff_chanaft" == key) pCurDef->cutoff_chanaft = ToInt(value);
1111     else if ("cutoff2_chanaft" == key) pCurDef->cutoff2_chanaft = ToInt(value);
1112     else if ("cutoff_polyaft" == key) pCurDef->cutoff_polyaft = ToInt(value);
1113     else if ("cutoff2_polyaft" == key) pCurDef->cutoff2_polyaft = ToInt(value);
1114     else if ("resonance" == key) pCurDef->resonance = ToFloat(value);
1115     else if ("resonance2" == key) pCurDef->resonance2 = ToFloat(value);
1116     else if ("fil_keytrack" == key) pCurDef->fil_keytrack = ToInt(value);
1117     else if ("fil2_keytrack" == key) pCurDef->fil2_keytrack = ToInt(value);
1118     else if ("fil_keycenter" == key) pCurDef->fil_keycenter = ToInt(value) + note_offset + 12 * octave_offset;
1119     else if ("fil2_keycenter" == key) pCurDef->fil2_keycenter = ToInt(value) + note_offset + 12 * octave_offset;
1120     else if ("fil_veltrack" == key) pCurDef->fil_veltrack = ToInt(value);
1121     else if ("fil2_veltrack" == key) pCurDef->fil2_veltrack = ToInt(value);
1122     else if ("fil_random" == key) pCurDef->fil_random = ToInt(value);
1123     else if ("fil2_random" == key) pCurDef->fil2_random = ToInt(value);
1124    
1125     // per voice equalizer
1126     else if ("eq1_freq" == key) pCurDef->eq1_freq = ToFloat(value);
1127     else if ("eq2_freq" == key) pCurDef->eq2_freq = ToFloat(value);
1128     else if ("eq3_freq" == key) pCurDef->eq3_freq = ToFloat(value);
1129     else if ("eq1_vel2freq" == key) pCurDef->eq1_vel2freq = ToFloat(value);
1130     else if ("eq2_vel2freq" == key) pCurDef->eq2_vel2freq = ToFloat(value);
1131     else if ("eq3_vel2freq" == key) pCurDef->eq3_vel2freq = ToFloat(value);
1132     else if ("eq1_bw" == key) pCurDef->eq1_bw = ToFloat(value);
1133     else if ("eq2_bw" == key) pCurDef->eq2_bw = ToFloat(value);
1134     else if ("eq3_bw" == key) pCurDef->eq3_bw = ToFloat(value);
1135     else if ("eq1_gain" == key) pCurDef->eq1_gain = ToFloat(value);
1136     else if ("eq2_gain" == key) pCurDef->eq2_gain = ToFloat(value);
1137     else if ("eq3_gain" == key) pCurDef->eq3_gain = ToFloat(value);
1138     else if ("eq1_vel2gain" == key) pCurDef->eq1_vel2gain = ToFloat(value);
1139     else if ("eq2_vel2gain" == key) pCurDef->eq2_vel2gain = ToFloat(value);
1140     else if ("eq3_vel2gain" == key) pCurDef->eq3_vel2gain = ToFloat(value);
1141    
1142     //fixme: parse amp_velcurve_N
1143    
1144     // CCs
1145     else if (key.find("cc") != std::string::npos)
1146     {
1147     std::string::size_type delimiter_index = key.find("cc");
1148     std::string key_cc = key.substr(0, delimiter_index);
1149     int num_cc = ToInt(key.substr(delimiter_index + 2));
1150    
1151     // input controls
1152     if ("lo" == key_cc) pCurDef->locc[num_cc] = ToInt(value);
1153     else if ("hi" == key_cc) pCurDef->hicc[num_cc] = ToInt(value);
1154     else if ("start_lo" == key_cc) pCurDef->start_locc[num_cc] = ToInt(value);
1155     else if ("start_hi" == key_cc) pCurDef->start_hicc[num_cc] = ToInt(value);
1156     else if ("stop_lo" == key_cc) pCurDef->stop_locc[num_cc] = ToInt(value);
1157     else if ("stop_hi" == key_cc) pCurDef->stop_hicc[num_cc] = ToInt(value);
1158     else if ("on_lo" == key_cc) pCurDef->on_locc[num_cc] = ToInt(value);
1159     else if ("on_hi" == key_cc) pCurDef->on_hicc[num_cc] = ToInt(value);
1160    
1161     // sample player
1162     else if ("delay_on" == key_cc) pCurDef->delay_oncc[num_cc] = ToFloat(value);
1163     else if ("delay_samples_on" == key_cc) pCurDef->delay_samples_oncc[num_cc] = ToInt(value);
1164     else if ("offset_on" == key_cc) pCurDef->offset_oncc[num_cc] = ToInt(value);
1165    
1166     // amplifier
1167     else if ("gain_on" == key_cc) pCurDef->gain_oncc[num_cc] = ToFloat(value);
1168     else if ("xfin_lo" == key_cc) pCurDef->xfin_locc[num_cc] = ToInt(value);
1169     else if ("xfin_hi" == key_cc) pCurDef->xfin_hicc[num_cc] = ToInt(value);
1170     else if ("xfout_lo" == key_cc) pCurDef->xfout_locc[num_cc] = ToInt(value);
1171     else if ("xfout_hi" == key_cc) pCurDef->xfout_hicc[num_cc] = ToInt(value);
1172    
1173     // filter
1174     else if ("cutoff_on" == key_cc) pCurDef->cutoff_oncc[num_cc] = ToInt(value);
1175     else if ("cutoff2_on" == key_cc) pCurDef->cutoff2_oncc[num_cc] = ToInt(value);
1176     else if ("cutoff_smooth" == key_cc) pCurDef->cutoff_smoothcc[num_cc] = ToInt(value);
1177     else if ("cutoff2_smooth" == key_cc) pCurDef->cutoff2_smoothcc[num_cc] = ToInt(value);
1178     else if ("cutoff_step" == key_cc) pCurDef->cutoff_stepcc[num_cc] = ToInt(value);
1179     else if ("cutoff2_step" == key_cc) pCurDef->cutoff2_stepcc[num_cc] = ToInt(value);
1180     else if ("cutoff_curve" == key_cc) pCurDef->cutoff_curvecc[num_cc] = ToInt(value);
1181     else if ("cutoff2_curve" == key_cc) pCurDef->cutoff2_curvecc[num_cc] = ToInt(value);
1182     else if ("resonance_on" == key_cc) pCurDef->resonance_oncc[num_cc] = ToInt(value);
1183     else if ("resonance2_on" == key_cc) pCurDef->resonance2_oncc[num_cc] = ToInt(value);
1184     else if ("resonance_smooth" == key_cc) pCurDef->resonance_smoothcc[num_cc] = ToInt(value);
1185     else if ("resonance2_smooth" == key_cc) pCurDef->resonance2_smoothcc[num_cc] = ToInt(value);
1186     else if ("resonance_step" == key_cc) pCurDef->resonance_stepcc[num_cc] = ToInt(value);
1187     else if ("resonance2_step" == key_cc) pCurDef->resonance2_stepcc[num_cc] = ToInt(value);
1188     else if ("resonance_curve" == key_cc) pCurDef->resonance_curvecc[num_cc] = ToInt(value);
1189     else if ("resonance2_curve" == key_cc) pCurDef->resonance2_curvecc[num_cc] = ToInt(value);
1190    
1191     // per voice equalizer
1192     else if ("eq1_freq_on" == key_cc) pCurDef->eq1_freq_oncc[num_cc] = ToInt(value);
1193     else if ("eq2_freq_on" == key_cc) pCurDef->eq2_freq_oncc[num_cc] = ToInt(value);
1194     else if ("eq3_freq_on" == key_cc) pCurDef->eq3_freq_oncc[num_cc] = ToInt(value);
1195     else if ("eq1_bw_on" == key_cc) pCurDef->eq1_bw_oncc[num_cc] = ToInt(value);
1196     else if ("eq2_bw_on" == key_cc) pCurDef->eq2_bw_oncc[num_cc] = ToInt(value);
1197     else if ("eq3_bw_on" == key_cc) pCurDef->eq3_bw_oncc[num_cc] = ToInt(value);
1198     else if ("eq1_gain_on" == key_cc) pCurDef->eq1_gain_oncc[num_cc] = ToInt(value);
1199     else if ("eq2_gain_on" == key_cc) pCurDef->eq2_gain_oncc[num_cc] = ToInt(value);
1200     else if ("eq3_gain_on" == key_cc) pCurDef->eq3_gain_oncc[num_cc] = ToInt(value);
1201     else std::cerr << "The opcode '" << key << "' is unsupported by libsfz!" << std::endl;
1202 iliev 2018 }
1203     // Deprecated opcodes
1204     else if ("ampeg_delay" == key) pCurDef->ampeg_delay = ToFloat(value);
1205     else if ("ampeg_start" == key) pCurDef->ampeg_start = ToFloat(value);
1206     else if ("ampeg_attack" == key) pCurDef->ampeg_attack = ToFloat(value);
1207     else if ("ampeg_hold" == key) pCurDef->ampeg_hold = ToFloat(value);
1208     else if ("ampeg_decay" == key) pCurDef->ampeg_decay = ToFloat(value);
1209     else if ("ampeg_sustain" == key) pCurDef->ampeg_sustain = ToFloat(value);
1210     else if ("ampeg_release" == key) pCurDef->ampeg_release = ToFloat(value);
1211     else if ("fileg_delay" == key) pCurDef->fileg_delay = ToFloat(value);
1212     else if ("fileg_start" == key) pCurDef->fileg_start = ToFloat(value);
1213     else if ("fileg_attack" == key) pCurDef->fileg_attack = ToFloat(value);
1214     else if ("fileg_hold" == key) pCurDef->fileg_hold = ToFloat(value);
1215     else if ("fileg_decay" == key) pCurDef->fileg_decay = ToFloat(value);
1216     else if ("fileg_sustain" == key) pCurDef->fileg_sustain = ToFloat(value);
1217     else if ("fileg_release" == key) pCurDef->fileg_release = ToFloat(value);
1218     else if ("pitcheg_delay" == key) pCurDef->pitcheg_delay = ToFloat(value);
1219     else if ("pitcheg_start" == key) pCurDef->pitcheg_start = ToFloat(value);
1220     else if ("pitcheg_attack" == key) pCurDef->pitcheg_attack = ToFloat(value);
1221     else if ("pitcheg_hold" == key) pCurDef->pitcheg_hold = ToFloat(value);
1222     else if ("pitcheg_decay" == key) pCurDef->pitcheg_decay = ToFloat(value);
1223     else if ("pitcheg_sustain" == key) pCurDef->pitcheg_sustain = ToFloat(value);
1224     else if ("pitcheg_release" == key) pCurDef->pitcheg_release = ToFloat(value);
1225     else {
1226 iliev 2012 std::cerr << "The opcode '" << key << "' is unsupported by libsfz!" << std::endl;
1227     }
1228     }
1229    
1230     } // !namespace sfz

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC