/[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 2055 - (hide annotations) (download)
Sat Jan 30 10:30:02 2010 UTC (14 years, 2 months ago) by persson
File size: 52468 byte(s)
* sfz engine: added support for v2 multiple stage envelope generators
* sfz engine: added a fine-tuned v1 envelope generator instead of
  using the one from the gig engine

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

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC