/[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 2231 - (hide annotations) (download)
Sun Aug 7 14:27:24 2011 UTC (12 years, 8 months ago) by iliev
File size: 66284 byte(s)
* sfz engine: some group opcodes were not reset on next group

1 iliev 2012 /***************************************************************************
2     * *
3     * LinuxSampler - modular, streaming capable sampler *
4     * *
5 persson 2055 * Copyright (C) 2008 Anders Dahnielson <anders@dahnielson.com> *
6 persson 2167 * Copyright (C) 2009 - 2011 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 2058 #include <cctype>
29 persson 2055 #include <cstdio>
30     #include <cstring>
31 iliev 2012
32     #include "../../common/File.h"
33     #include "../../common/Path.h"
34     #include "../../common/global_private.h"
35 persson 2106 #include "LookupTable.h"
36 iliev 2012
37     namespace sfz
38     {
39 iliev 2218 template <typename T> T check(std::string name, T min, T max, T val) {
40     if (val < min) {
41     std::cerr << "sfz: The value of opcode '" << name;
42     std::cerr << "' is below the minimum allowed value (min=" << min << "): " << val << std::endl;
43     val = min;
44     }
45     if (val > max) {
46     std::cerr << "sfz: The value of opcode '" << name;
47     std::cerr << "' is above the maximum allowed value (max=" << max << "): " << val << std::endl;
48     val = max;
49     }
50    
51     return val;
52     }
53 iliev 2012
54 iliev 2216 Sample* SampleManager::FindSample(std::string samplePath, int offset) {
55 iliev 2021 std::map<Sample*, std::set<Region*> >::iterator it = sampleMap.begin();
56 iliev 2012 for (; it != sampleMap.end(); it++) {
57 iliev 2216 if (it->first->GetFile() == samplePath) {
58     /* Because the start of the sample is cached in RAM we treat
59     * same sample with different offset as different samples
60     * // TODO: Ignore offset when the whole sample is cached in RAM?
61     */
62     int maxOffset = it->first->MaxOffset;
63     if(it->first->Offset == offset || (it->first->Offset < maxOffset && offset < maxOffset)) {
64     return it->first;
65     }
66     }
67 iliev 2012 }
68    
69     return NULL;
70     }
71    
72     /////////////////////////////////////////////////////////////
73     // class optional
74    
75     const optional_base::nothing_t optional_base::nothing;
76    
77     /////////////////////////////////////////////////////////////
78     // class Articulation
79    
80     Articulation::Articulation()
81     {
82     }
83    
84     Articulation::~Articulation()
85     {
86     }
87    
88     /////////////////////////////////////////////////////////////
89     // class Definition
90    
91 persson 2091 Definition::Definition()
92 iliev 2012 {
93     }
94    
95     Definition::~Definition()
96     {
97     }
98    
99     /////////////////////////////////////////////////////////////
100     // class Region
101    
102     Region::Region()
103     {
104     pSample = NULL;
105 persson 2072 seq_counter = 1;
106 iliev 2012 }
107    
108     Region::~Region()
109     {
110     DestroySampleIfNotUsed();
111     }
112    
113 iliev 2021 Sample* Region::GetSample(bool create)
114 iliev 2012 {
115     if(pSample == NULL && create) {
116 iliev 2216 int i = offset ? *offset : 0;
117     Sample* sf = GetInstrument()->GetSampleManager()->FindSample(sample, i);
118 iliev 2012 if (sf != NULL) pSample = sf; // Reuse already created sample
119 iliev 2216 else pSample = new Sample(sample, false, i);
120 iliev 2012 GetInstrument()->GetSampleManager()->AddSampleConsumer(pSample, this);
121     }
122     return pSample;
123     }
124    
125     void Region::DestroySampleIfNotUsed() {
126     if (pSample == NULL) return;
127     GetInstrument()->GetSampleManager()->RemoveSampleConsumer(pSample, this);
128     if (!GetInstrument()->GetSampleManager()->HasSampleConsumers(pSample)) {
129     GetInstrument()->GetSampleManager()->RemoveSample(pSample);
130     delete pSample;
131     pSample = NULL;
132     }
133     }
134    
135 persson 2101 bool Region::OnKey(const Query& q) {
136 persson 2106 // As the region comes from a LookupTable search on the query,
137     // the following parameters are not checked here: chan, key,
138     // vel, chanaft, polyaft, prog, sw_previous, cc. They are all
139     // handled by the lookup table.
140 persson 2101 bool is_triggered(
141     q.bend >= lobend && q.bend <= hibend &&
142     q.bpm >= lobpm && q.bpm < hibpm &&
143     q.rand >= lorand && q.rand < hirand &&
144     q.timer >= lotimer && q.timer <= hitimer &&
145 iliev 2012
146 persson 2086 ( sw_last == -1 ||
147 persson 2101 ((sw_last >= sw_lokey && sw_last <= sw_hikey) ? (q.last_sw_key == sw_last) : false) ) &&
148 iliev 2012
149 persson 2086 ( sw_down == -1 ||
150 persson 2101 ((sw_down >= sw_lokey && (sw_hikey == -1 || sw_down <= sw_hikey)) ? (q.sw[sw_down]) : false) ) &&
151 iliev 2012
152 persson 2086 ( sw_up == -1 ||
153 persson 2101 ((sw_up >= sw_lokey && (sw_hikey == -1 || sw_up <= sw_hikey)) ? (!q.sw[sw_up]) : true) ) &&
154 iliev 2012
155 persson 2101 ((trigger & q.trig) != 0)
156 iliev 2012 );
157    
158     if (!is_triggered)
159     return false;
160    
161 persson 2072 // seq_position has to be checked last, so we know that we
162     // increment the right counter
163     is_triggered = (seq_counter == seq_position);
164     seq_counter = (seq_counter % seq_length) + 1;
165    
166     return is_triggered;
167 iliev 2012 }
168    
169     Articulation*
170     Region::GetArticulation(int bend, uint8_t bpm, uint8_t chanaft, uint8_t polyaft, uint8_t* cc)
171     {
172     return new Articulation(); //todo: implement GetArticulation()
173     }
174    
175 iliev 2021 bool Region::HasLoop() {
176 persson 2167 bool b = loop_mode == ::sfz::LOOP_UNSET ? pSample->GetLoops() :
177     (loop_mode == ::sfz::LOOP_CONTINUOUS || loop_mode == ::sfz::LOOP_SUSTAIN);
178 iliev 2021 return b && GetLoopStart() && GetLoopEnd() && GetLoopEnd() > GetLoopStart();
179     }
180    
181     uint Region::GetLoopStart() {
182 persson 2167 return (!loop_start) ? pSample->GetLoopStart() : *loop_start;
183 iliev 2021 }
184    
185     uint Region::GetLoopEnd() {
186 persson 2167 return (!loop_end) ? pSample->GetLoopEnd() : *loop_end;
187 iliev 2021 }
188    
189     uint Region::GetLoopCount() {
190     return (!count) ? 0 : *count;
191     }
192    
193 iliev 2012 /////////////////////////////////////////////////////////////
194     // class Instrument
195    
196     Instrument::Instrument(std::string name, SampleManager* pSampleManager) : KeyBindings(128, false), KeySwitchBindings(128, false)
197     {
198     this->name = name;
199     this->pSampleManager = pSampleManager ? pSampleManager : this;
200 persson 2106 pLookupTable = 0;
201 iliev 2230
202     // The first 6 curves are defined internally (actually 7 with the one at index 0)
203     Curve c;
204     for (int i = 0; i < 128; i++) c.v[i] = i / 127.0f;
205     curves.add(c); curves.add(c); curves.add(c); curves.add(c);
206     curves.add(c); curves.add(c); curves.add(c);
207     ///////
208 iliev 2012 }
209    
210     Instrument::~Instrument()
211     {
212 persson 2106 for (int i = 0; i < regions.size(); i++) {
213     delete regions[i];
214 iliev 2012 }
215 persson 2106 delete pLookupTable;
216 persson 2115 for (int i = 0 ; i < 128 ; i++) {
217     delete pLookupTableCC[i];
218     }
219 iliev 2012 }
220    
221 persson 2106 void Query::search(const Instrument* pInstrument) {
222     pRegionList = &pInstrument->pLookupTable->query(*this);
223     regionIndex = 0;
224 persson 2101 }
225    
226 persson 2115 void Query::search(const Instrument* pInstrument, int triggercc) {
227     pRegionList = &pInstrument->pLookupTableCC[triggercc]->query(*this);
228     regionIndex = 0;
229     }
230    
231 persson 2101 Region* Query::next() {
232 persson 2106 for ( ; regionIndex < pRegionList->size() ; regionIndex++) {
233     if ((*pRegionList)[regionIndex]->OnKey(*this)) {
234     return (*pRegionList)[regionIndex++];
235     }
236 iliev 2012 }
237 persson 2101 return 0;
238 iliev 2012 }
239    
240     bool Instrument::DestroyRegion(Region* pRegion) {
241     for (std::vector<Region*>::iterator it = regions.begin(); it != regions.end(); it++) {
242     if(*it == pRegion) {
243     regions.erase(it);
244     delete pRegion;
245     return true;
246     }
247     }
248    
249     return false;
250     }
251    
252     bool Instrument::HasKeyBinding(uint8_t key) {
253     if (key > 127) return false;
254     return KeyBindings[key];
255     }
256    
257     bool Instrument::HasKeySwitchBinding(uint8_t key) {
258     if (key > 127) return false;
259     return KeySwitchBindings[key];
260     }
261    
262     /////////////////////////////////////////////////////////////
263     // class Group
264    
265     Group::Group() :
266     id(0)
267     {
268     Reset();
269     }
270    
271     Group::~Group()
272     {
273     }
274    
275     void
276     Group::Reset()
277     {
278     // This is where all the default values are set.
279    
280     // sample definition default
281     sample = "";
282    
283     // input control
284     lochan = 1; hichan = 16;
285     lokey = 0; hikey = 127;
286     lovel = 0; hivel = 127;
287     lobend = -8192; hibend = 8192;
288     lobpm = 0; hibpm = 500;
289     lochanaft = 0; hichanaft = 127;
290     lopolyaft = 0; hipolyaft = 127;
291     loprog = 0; hiprog = 127;
292     lorand = 0.0; hirand = 1.0;
293     lotimer = 0.0; hitimer = 0.0;
294    
295     seq_length = 1;
296     seq_position = 1;
297    
298     sw_lokey = -1; sw_hikey = -1;
299     sw_last = -1;
300     sw_down = -1;
301     sw_up = -1;
302     sw_previous = -1;
303     sw_vel = VEL_CURRENT;
304    
305     trigger = TRIGGER_ATTACK;
306    
307 iliev 2027 group = 0;
308 persson 2114 off_by = 0;
309 iliev 2012 off_mode = OFF_FAST;
310    
311     // sample player
312     count.unset();
313     delay.unset(); delay_random.unset();
314     delay_beats.unset(); stop_beats.unset();
315     delay_samples.unset();
316     end.unset();
317     loop_crossfade.unset();
318     offset.unset(); offset_random.unset();
319 persson 2167 loop_mode = LOOP_UNSET;
320 iliev 2012 loop_start.unset(); loop_end.unset();
321     sync_beats.unset(); sync_offset.unset();
322    
323     // amplifier
324     volume = 0;
325 iliev 2231 volume_oncc.clear();
326     volume_curvecc.clear();
327 iliev 2012 pan = 0;
328     width = 100;
329     position = 0;
330     amp_keytrack = 0;
331     amp_keycenter = 60;
332     amp_veltrack = 100;
333     amp_random = 0;
334     rt_decay = 0;
335     xfin_lokey = 0; xfin_hikey = 0;
336     xfout_lokey = 127; xfout_hikey = 127;
337     xf_keycurve = POWER;
338     xfin_lovel = 0; xfin_hivel = 0;
339     xfout_lovel = 127; xfout_hivel = 127;
340     xf_velcurve = POWER;
341     xf_cccurve = POWER;
342    
343     // pitch
344     transpose = 0;
345     tune = 0;
346     pitch_keycenter = 60;
347     pitch_keytrack = 100;
348     pitch_veltrack = 0;
349     pitch_random = 0;
350     bend_up = 200;
351     bend_down = -200;
352     bend_step = 1;
353    
354     // filter
355     fil_type = LPF_2P;
356     cutoff.unset();
357     cutoff_chanaft = 0;
358     cutoff_polyaft = 0;
359     resonance = 0;
360     fil_keytrack = 0;
361     fil_keycenter = 60;
362     fil_veltrack = 0;
363     fil_random = 0;
364    
365     fil2_type = LPF_2P;
366     cutoff2.unset();
367     cutoff2_chanaft = 0;
368     cutoff2_polyaft = 0;
369     resonance2 = 0;
370     fil2_keytrack = 0;
371     fil2_keycenter = 60;
372     fil2_veltrack = 0;
373     fil2_random = 0;
374    
375     // per voice equalizer
376     eq1_freq = 50;
377     eq2_freq = 500;
378     eq3_freq = 5000;
379     eq1_vel2freq = 0;
380     eq2_vel2freq = 0;
381     eq3_vel2freq = 0;
382     eq1_bw = 1;
383     eq2_bw = 1;
384     eq3_bw = 1;
385     eq1_gain = 0;
386     eq2_gain = 0;
387     eq3_gain = 0;
388     eq1_vel2gain = 0;
389     eq2_vel2gain = 0;
390     eq3_vel2gain = 0;
391    
392     // CCs
393     for (int i = 0; i < 128; ++i)
394     {
395     // input control
396 persson 2091 locc.set(i, 0);
397     hicc.set(i, 127);
398     start_locc.set(i, -1);
399     start_hicc.set(i, -1);
400     stop_locc.set(i, -1);
401     stop_hicc.set(i, -1);
402     on_locc.set(i, -1);
403     on_hicc.set(i, -1);
404 iliev 2012
405     // sample player
406 persson 2091 delay_oncc.set(i, optional<float>::nothing);
407     delay_samples_oncc.set(i, optional<int>::nothing);
408     offset_oncc.set(i, optional<int>::nothing);
409 iliev 2012
410     // amplifier
411 persson 2091 amp_velcurve.set(i, -1);
412     gain_oncc.set(i, 0);
413     xfin_locc.set(i, 0);
414     xfin_hicc.set(i, 0);
415     xfout_locc.set(i, 127);
416     xfout_hicc.set(i, 127);
417 iliev 2012
418     // filter
419 persson 2091 cutoff_oncc.set(i, 0);
420     cutoff_smoothcc.set(i, 0);
421     cutoff_stepcc.set(i, 0);
422     cutoff_curvecc.set(i, 0);
423     resonance_oncc.set(i, 0);
424     resonance_smoothcc.set(i, 0);
425     resonance_stepcc.set(i, 0);
426     resonance_curvecc.set(i, 0);
427 iliev 2012
428 persson 2091 cutoff2_oncc.set(i, 0);
429     cutoff2_smoothcc.set(i, 0);
430     cutoff2_stepcc.set(i, 0);
431     cutoff2_curvecc.set(i, 0);
432     resonance2_oncc.set(i, 0);
433     resonance2_smoothcc.set(i, 0);
434     resonance2_stepcc.set(i, 0);
435     resonance2_curvecc.set(i, 0);
436 iliev 2012
437     // per voice equalizer
438 persson 2091 eq1_freq_oncc.set(i, 0);
439     eq2_freq_oncc.set(i, 0);
440     eq3_freq_oncc.set(i, 0);
441     eq1_bw_oncc.set(i, 0);
442     eq2_bw_oncc.set(i, 0);
443     eq3_bw_oncc.set(i, 0);
444     eq1_gain_oncc.set(i, 0);
445     eq2_gain_oncc.set(i, 0);
446     eq3_gain_oncc.set(i, 0);
447 iliev 2224
448     pitchlfo_depthcc.set(i, 0);
449 iliev 2012 }
450 persson 2175 cutoff_cc = 0;
451 iliev 2018
452 persson 2055 eg.clear();
453 iliev 2231 lfos.clear();
454 persson 2055
455 iliev 2018 // deprecated
456     ampeg_delay = 0;
457     ampeg_start = 0; //in percentage
458     ampeg_attack = 0;
459     ampeg_hold = 0;
460     ampeg_decay = 0;
461 iliev 2218 ampeg_sustain = -1; // in percentage
462 iliev 2018 ampeg_release = 0;
463    
464 persson 2176 ampeg_vel2delay = 0;
465     ampeg_vel2attack = 0;
466     ampeg_vel2hold = 0;
467     ampeg_vel2decay = 0;
468     ampeg_vel2sustain = 0;
469     ampeg_vel2release = 0;
470 iliev 2231
471     ampeg_delaycc.clear();
472     ampeg_startcc.clear();
473     ampeg_attackcc.clear();
474     ampeg_holdcc.clear();
475     ampeg_decaycc.clear();
476     ampeg_sustaincc.clear();
477     ampeg_releasecc.clear();
478 persson 2176
479 iliev 2018 fileg_delay = 0;
480     fileg_start = 0; //in percentage
481     fileg_attack = 0;
482     fileg_hold = 0;
483     fileg_decay = 0;
484     fileg_sustain = 100; // in percentage
485     fileg_release = 0;
486    
487 iliev 2222 fileg_vel2delay = 0;
488     fileg_vel2attack = 0;
489     fileg_vel2hold = 0;
490     fileg_vel2decay = 0;
491     fileg_vel2sustain = 0;
492     fileg_vel2release = 0;
493     fileg_depth = 0;
494    
495 iliev 2018 pitcheg_delay = 0;
496     pitcheg_start = 0; //in percentage
497     pitcheg_attack = 0;
498     pitcheg_hold = 0;
499     pitcheg_decay = 0;
500     pitcheg_sustain = 100; // in percentage
501     pitcheg_release = 0;
502 iliev 2220 pitcheg_depth = 0;
503 persson 2072
504 iliev 2220 pitcheg_vel2delay = 0;
505     pitcheg_vel2attack = 0;
506     pitcheg_vel2hold = 0;
507     pitcheg_vel2decay = 0;
508     pitcheg_vel2sustain = 0;
509     pitcheg_vel2release = 0;
510    
511 persson 2072 amplfo_delay = 0;
512     amplfo_fade = 0;
513 iliev 2229 amplfo_freq = -1; /* -1 is used to determine whether the LFO was initialized */
514 persson 2072 amplfo_depth = 0;
515 iliev 2231 amplfo_freqcc.clear();
516 persson 2072
517     fillfo_delay = 0;
518     fillfo_fade = 0;
519 iliev 2229 fillfo_freq = -1; /* -1 is used to determine whether the LFO was initialized */
520 persson 2072 fillfo_depth = 0;
521 iliev 2231 fillfo_freqcc.clear();
522 persson 2072
523     pitchlfo_delay = 0;
524     pitchlfo_fade = 0;
525 iliev 2229 pitchlfo_freq = -1; /* -1 is used to determine whether the LFO was initialized */
526 persson 2072 pitchlfo_depth = 0;
527 iliev 2231 pitchlfo_freqcc.clear();
528 iliev 2012 }
529    
530     Region*
531     Group::RegionFactory()
532     {
533     // This is where the current group setting are copied to the new region.
534    
535     Region* region = new Region();
536    
537     region->id = id++;
538    
539     // sample definition
540     region->sample = sample;
541    
542     // input control
543     region->lochan = lochan;
544     region->hichan = hichan;
545     region->lokey = lokey;
546     region->hikey = hikey;
547     region->lovel = lovel;
548     region->hivel = hivel;
549     region->locc = locc;
550     region->hicc = hicc;
551     region->lobend = lobend;
552     region->hibend = hibend;
553     region->lobpm = lobpm;
554     region->hibpm = hibpm;
555     region->lochanaft = lochanaft;
556     region->hichanaft = hichanaft;
557     region->lopolyaft = lopolyaft;
558     region->hipolyaft = hipolyaft;
559     region->loprog = loprog;
560     region->hiprog = hiprog;
561     region->lorand = lorand;
562     region->hirand = hirand;
563     region->lotimer = lotimer;
564     region->hitimer = hitimer;
565     region->seq_length = seq_length;
566     region->seq_position = seq_position;
567     region->start_locc = start_locc;
568     region->start_hicc = start_hicc;
569     region->stop_locc = stop_locc;
570     region->stop_hicc = stop_hicc;
571     region->sw_lokey = sw_lokey;
572     region->sw_hikey = sw_hikey;
573     region->sw_last = sw_last;
574     region->sw_down = sw_down;
575     region->sw_up = sw_up;
576     region->sw_previous = sw_previous;
577     region->sw_vel = sw_vel;
578     region->trigger = trigger;
579     region->group = group;
580     region->off_by = off_by;
581     region->off_mode = off_mode;
582     region->on_locc = on_locc;
583     region->on_hicc = on_hicc;
584    
585     // sample player
586     region->count = count;
587     region->delay = delay;
588     region->delay_random = delay_random;
589     region->delay_oncc = delay_oncc;
590     region->delay_beats = delay_beats;
591     region->stop_beats = stop_beats;
592     region->delay_samples = delay_samples;
593     region->delay_samples_oncc = delay_samples_oncc;
594     region->end = end;
595     region->loop_crossfade = loop_crossfade;
596     region->offset = offset;
597     region->offset_random = offset_random;
598     region->offset_oncc = offset_oncc;
599     region->loop_mode = loop_mode;
600     region->loop_start = loop_start;
601     region->loop_end = loop_end;
602     region->sync_beats = sync_beats;
603     region->sync_offset = sync_offset;
604    
605     // amplifier
606     region->volume = volume;
607 iliev 2231 region->volume_oncc = volume_oncc;
608     region->volume_curvecc = volume_curvecc;
609 iliev 2012 region->pan = pan;
610     region->width = width;
611     region->position = position;
612     region->amp_keytrack = amp_keytrack;
613     region->amp_keycenter = amp_keycenter;
614     region->amp_veltrack = amp_veltrack;
615 persson 2082 region->amp_velcurve = amp_velcurve;
616 iliev 2012 region->amp_random = amp_random;
617     region->rt_decay = rt_decay;
618     region->gain_oncc = gain_oncc;
619     region->xfin_lokey = xfin_lokey;
620     region->xfin_hikey = xfin_hikey;
621     region->xfout_lokey = xfout_lokey;
622     region->xfout_hikey = xfout_hikey;
623     region->xf_keycurve = xf_keycurve;
624     region->xfin_lovel = xfin_lovel;
625     region->xfin_hivel = xfin_lovel;
626     region->xfout_lovel = xfout_lovel;
627     region->xfout_hivel = xfout_hivel;
628     region->xf_velcurve = xf_velcurve;
629     region->xfin_locc = xfin_locc;
630     region->xfin_hicc = xfin_hicc;
631     region->xfout_locc = xfout_locc;
632     region->xfout_hicc = xfout_hicc;
633     region->xf_cccurve = xf_cccurve;
634    
635     // pitch
636     region->transpose = transpose;
637     region->tune = tune;
638     region->pitch_keycenter = pitch_keycenter;
639     region->pitch_keytrack = pitch_keytrack;
640     region->pitch_veltrack = pitch_veltrack;
641     region->pitch_random = pitch_random;
642     region->bend_up = bend_up;
643     region->bend_down = bend_down;
644     region->bend_step = bend_step;
645    
646     // filter
647     region->fil_type = fil_type;
648     region->cutoff = cutoff;
649     region->cutoff_oncc = cutoff_oncc;
650 persson 2175 region->cutoff_cc = cutoff_cc;
651 iliev 2012 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 persson 2055 // envelope generator
711     region->eg = eg;
712    
713 iliev 2018 // deprecated
714     region->ampeg_delay = ampeg_delay;
715     region->ampeg_start = ampeg_start;
716     region->ampeg_attack = ampeg_attack;
717     region->ampeg_hold = ampeg_hold;
718     region->ampeg_decay = ampeg_decay;
719     region->ampeg_sustain = ampeg_sustain;
720     region->ampeg_release = ampeg_release;
721    
722 persson 2176 region->ampeg_vel2delay = ampeg_vel2delay;
723     region->ampeg_vel2attack = ampeg_vel2attack;
724     region->ampeg_vel2hold = ampeg_vel2hold;
725     region->ampeg_vel2decay = ampeg_vel2decay;
726     region->ampeg_vel2sustain = ampeg_vel2sustain;
727     region->ampeg_vel2release = ampeg_vel2release;
728 iliev 2229
729     region->ampeg_delaycc = ampeg_delaycc;
730     region->ampeg_startcc = ampeg_startcc;
731     region->ampeg_attackcc = ampeg_attackcc;
732     region->ampeg_holdcc = ampeg_holdcc;
733     region->ampeg_decaycc = ampeg_decaycc;
734     region->ampeg_sustaincc = ampeg_sustaincc;
735     region->ampeg_releasecc = ampeg_releasecc;
736 persson 2176
737 iliev 2018 region->fileg_delay = fileg_delay;
738     region->fileg_start = fileg_start;
739     region->fileg_attack = fileg_attack;
740     region->fileg_hold = fileg_hold;
741     region->fileg_decay = fileg_decay;
742     region->fileg_sustain = fileg_sustain;
743     region->fileg_release = fileg_release;
744 iliev 2222 region->fileg_depth = fileg_depth;
745 iliev 2018
746 iliev 2222 region->fileg_vel2delay = fileg_vel2delay;
747     region->fileg_vel2attack = fileg_vel2attack;
748     region->fileg_vel2hold = fileg_vel2hold;
749     region->fileg_vel2decay = fileg_vel2decay;
750     region->fileg_vel2sustain = fileg_vel2sustain;
751     region->fileg_vel2release = fileg_vel2release;
752    
753 iliev 2018 region->pitcheg_delay = pitcheg_delay;
754     region->pitcheg_start = pitcheg_start;
755     region->pitcheg_attack = pitcheg_attack;
756     region->pitcheg_hold = pitcheg_hold;
757     region->pitcheg_decay = pitcheg_decay;
758     region->pitcheg_sustain = pitcheg_sustain;
759     region->pitcheg_release = pitcheg_release;
760 iliev 2220 region->pitcheg_depth = pitcheg_depth;
761 iliev 2018
762 iliev 2220 region->pitcheg_vel2delay = pitcheg_vel2delay;
763     region->pitcheg_vel2attack = pitcheg_vel2attack;
764     region->pitcheg_vel2hold = pitcheg_vel2hold;
765     region->pitcheg_vel2decay = pitcheg_vel2decay;
766     region->pitcheg_vel2sustain = pitcheg_vel2sustain;
767     region->pitcheg_vel2release = pitcheg_vel2release;
768    
769 persson 2072 region->amplfo_delay = amplfo_delay;
770     region->amplfo_fade = amplfo_fade;
771     region->amplfo_freq = amplfo_freq;
772     region->amplfo_depth = amplfo_depth;
773 iliev 2227
774     region->amplfo_freqcc = amplfo_freqcc;
775 persson 2072
776     region->fillfo_delay = fillfo_delay;
777     region->fillfo_fade = fillfo_fade;
778     region->fillfo_freq = fillfo_freq;
779     region->fillfo_depth = fillfo_depth;
780 iliev 2227
781     region->fillfo_freqcc = fillfo_freqcc;
782 persson 2072
783     region->pitchlfo_delay = pitchlfo_delay;
784     region->pitchlfo_fade = pitchlfo_fade;
785     region->pitchlfo_freq = pitchlfo_freq;
786     region->pitchlfo_depth = pitchlfo_depth;
787 iliev 2224
788     region->pitchlfo_depthcc = pitchlfo_depthcc;
789 iliev 2227 region->pitchlfo_freqcc = pitchlfo_freqcc;
790 iliev 2229
791     region->eg = eg;
792     region->lfos = lfos;
793 persson 2072
794 iliev 2012 return region;
795     }
796    
797     /////////////////////////////////////////////////////////////
798     // class File
799    
800     File::File(std::string file, SampleManager* pSampleManager) :
801     _current_section(GROUP),
802     default_path(""),
803     octave_offset(0),
804     note_offset(0)
805     {
806     _instrument = new Instrument(LinuxSampler::Path::getBaseName(file), pSampleManager);
807     _current_group = new Group();
808 persson 2055 pCurDef = _current_group;
809 iliev 2012 enum token_type_t { HEADER, OPCODE };
810     token_type_t token_type;
811     std::string token_string;
812    
813     std::ifstream fs(file.c_str());
814     currentDir = LinuxSampler::Path::stripLastName(file);
815     std::string token;
816     std::string line;
817    
818     while (std::getline(fs, line))
819     {
820     // COMMENT
821     std::string::size_type slash_index = line.find("//");
822     if (slash_index != std::string::npos)
823     line.resize(slash_index);
824    
825     // DEFINITION
826     std::stringstream linestream(line);
827     while (linestream >> token)
828     {
829     if (token[0] == '<' and token[token.size()-1] == '>')
830     {
831     // HEAD
832     if (!token_string.empty())
833     {
834     switch (token_type)
835     {
836     case HEADER:
837     push_header(token_string);
838     break;
839     case OPCODE:
840     push_opcode(token_string);
841     break;
842     }
843     token_string.erase();
844     }
845     token_string.append(token);
846     token_type = HEADER;
847     }
848     else if (token.find('=') != std::string::npos)
849     {
850     // HEAD
851     if (!token_string.empty())
852     {
853     switch (token_type)
854     {
855     case HEADER:
856     push_header(token_string);
857     break;
858     case OPCODE:
859     push_opcode(token_string);
860     break;
861     }
862     token_string.erase();
863     }
864     token_string.append(token);
865     token_type = OPCODE;
866     }
867     else
868     {
869     // TAIL
870     token_string.append(" ");
871     token_string.append(token);
872     }
873     }
874    
875     // EOL
876     if (!token_string.empty())
877     {
878     switch (token_type)
879     {
880     case HEADER:
881     push_header(token_string);
882     break;
883     case OPCODE:
884     push_opcode(token_string);
885     break;
886     }
887     token_string.erase();
888     }
889     }
890    
891 persson 2091 std::set<float*> velcurves;
892 iliev 2012 for (int i = 0; i < _instrument->regions.size(); i++) {
893     ::sfz::Region* pRegion = _instrument->regions[i];
894     int low = pRegion->lokey;
895     int high = pRegion->hikey;
896 persson 2115 if (low != -1) { // lokey -1 means region doesn't play on note-on
897     // hikey -1 is the same as no limit, except that it
898     // also enables on_locc/on_hicc
899     if (high == -1) high = 127;
900     if (low < 0 || low > 127 || high < 0 || high > 127 || low > high) {
901     std::cerr << "Invalid key range: " << low << " - " << high << std::endl;
902     } else {
903     for (int j = low; j <= high; j++) _instrument->KeyBindings[j] = true;
904     }
905 iliev 2012 }
906    
907     // get keyswitches
908     low = pRegion->sw_lokey;
909 persson 2086 if (low < 0) low = 0;
910 iliev 2012 high = pRegion->sw_hikey;
911 persson 2086 if (high == -1) {
912 iliev 2012 // Key switches not defined, so nothing to do
913 persson 2086 } else if (low >= 0 && low <= 127 && high >= 0 && high <= 127 && high >= low) {
914 iliev 2012 for (int j = low; j <= high; j++) _instrument->KeySwitchBindings[j] = true;
915     } else {
916     std::cerr << "Invalid key switch range: " << low << " - " << high << std::endl;
917     }
918 persson 2082
919     // create velocity response curve
920 persson 2091
921     // don't use copy-on-write here, instead change the actual
922     // unique buffers in memory
923     float* velcurve = const_cast<float*>(&pRegion->amp_velcurve[0]);
924     if (velcurves.insert(velcurve).second) {
925     int prev = 0;
926     float prevvalue = 0;
927     for (int v = 0 ; v < 128 ; v++) {
928     if (velcurve[v] >= 0) {
929     float step = (velcurve[v] - prevvalue) / (v - prev);
930     for ( ; prev < v ; prev++) {
931     velcurve[prev] = prevvalue;
932     prevvalue += step;
933     }
934     }
935     }
936     if (prev) {
937     float step = (1 - prevvalue) / (127 - prev);
938     for ( ; prev < 128 ; prev++) {
939     velcurve[prev] = prevvalue;
940 persson 2082 prevvalue += step;
941     }
942 persson 2091 } else {
943     // default curve
944     for (int v = 0 ; v < 128 ; v++) {
945     velcurve[v] = v * v / (127.0 * 127.0);
946     }
947 persson 2082 }
948 persson 2091
949     // apply amp_veltrack
950     float offset = -pRegion->amp_veltrack;
951     if (offset <= 0) offset += 100;
952 persson 2082 for (int v = 0 ; v < 128 ; v++) {
953 persson 2091 velcurve[v] = (offset + pRegion->amp_veltrack * velcurve[v]) / 100;
954 persson 2082 }
955     }
956 iliev 2012 }
957 persson 2106
958     _instrument->pLookupTable = new LookupTable(_instrument);
959 persson 2115
960     // create separate lookup tables for controller triggered
961     // regions, one for each CC
962     for (int i = 0 ; i < 128 ; i++) {
963     _instrument->pLookupTableCC[i] = new LookupTable(_instrument, i);
964     }
965 iliev 2230
966     for (int k = 0; k < _instrument->regions.size(); k++) {
967     Region* r = _instrument->regions[k];
968    
969     copyCurves(r->volume_curvecc, r->volume_oncc);
970    
971     r->volume_curvecc.clear();
972     }
973 iliev 2012 }
974    
975     File::~File()
976     {
977     delete _current_group;
978     delete _instrument;
979     }
980    
981     Instrument*
982     File::GetInstrument()
983     {
984     return _instrument;
985     }
986 iliev 2230
987     void File::copyCurves(LinuxSampler::ArrayList<CC>& curves, LinuxSampler::ArrayList<CC>& dest) {
988     for (int i = 0; i < curves.size(); i++) {
989     for (int j = 0; j < dest.size(); j++) {
990     if (curves[i].Controller == dest[j].Controller) {
991     dest[j].Curve = curves[i].Curve;
992     }
993     }
994     }
995     }
996 iliev 2012
997     void
998     File::push_header(std::string token)
999     {
1000     if (token == "<group>")
1001     {
1002     _current_section = GROUP;
1003     _current_group->Reset();
1004 persson 2055 pCurDef = _current_group;
1005 iliev 2012 }
1006     else if (token == "<region>")
1007     {
1008     _current_section = REGION;
1009     _current_region = _current_group->RegionFactory();
1010 persson 2055 pCurDef = _current_region;
1011 iliev 2012 _instrument->regions.push_back(_current_region);
1012 persson 2055 _current_region->SetInstrument(_instrument);
1013 iliev 2012 }
1014     else if (token == "<control>")
1015     {
1016     _current_section = CONTROL;
1017     default_path = "";
1018     octave_offset = 0;
1019     note_offset = 0;
1020     }
1021 iliev 2230 else if (token == "<curve>")
1022     {
1023     _current_section = CURVE;
1024     _instrument->curves.add(Curve());
1025     _current_curve = &_instrument->curves[_instrument->curves.size() - 1];
1026     }
1027 iliev 2012 else
1028     {
1029     _current_section = UNKNOWN;
1030     std::cerr << "The header '" << token << "' is unsupported by libsfz!" << std::endl;
1031     }
1032     }
1033    
1034     void
1035     File::push_opcode(std::string token)
1036     {
1037     if (_current_section == UNKNOWN)
1038     return;
1039    
1040     std::string::size_type delimiter_index = token.find('=');
1041     std::string key = token.substr(0, delimiter_index);
1042     std::string value = token.substr(delimiter_index + 1);
1043 iliev 2229 int x, y, z;
1044 iliev 2230
1045     if (_current_section == CURVE) {
1046     if (sscanf(key.c_str(), "v%d", &x)) {
1047     if (x < 0 || x > 127) {
1048     std::cerr << "Invalid curve index: " << x << std::endl;
1049     }
1050     _current_curve->v[x] = check(key, 0.0f, 1.0f, ToFloat(value));
1051     } else {
1052     std::cerr << "The opcode '" << key << "' in section <curve> is unsupported by libsfz!" << std::endl;
1053     }
1054    
1055     return;
1056     }
1057 iliev 2012
1058     // sample definition
1059     if ("sample" == key)
1060     {
1061     std::string path = default_path + value;
1062     #ifndef WIN32
1063     for (int i = 0; i < path.length(); i++) if( path[i] == '\\') path[i] = '/';
1064     #endif
1065     path = currentDir + LinuxSampler::File::DirSeparator + path; // TODO: check for absolute path
1066    
1067     if(pCurDef) pCurDef->sample = path;
1068     return;
1069     }
1070    
1071     // control header directives
1072     else if ("default_path" == key)
1073     {
1074     switch (_current_section)
1075     {
1076     case CONTROL:
1077     default_path = value;
1078     }
1079     return;
1080     }
1081     else if ("octave_offset" == key)
1082     {
1083     switch (_current_section)
1084     {
1085     case CONTROL:
1086     octave_offset = ToInt(value);
1087     }
1088     return;
1089     }
1090     else if ("note_offset" == key)
1091     {
1092     switch (_current_section)
1093     {
1094     case CONTROL:
1095     note_offset = ToInt(value);
1096     }
1097     return;
1098     }
1099    
1100     // input controls
1101     else if ("lochan" == key) pCurDef->lochan = ToInt(value);
1102     else if ("hichan" == key) pCurDef->hichan = ToInt(value);
1103 persson 2058 else if ("lokey" == key) pCurDef->lokey = parseKey(value);
1104     else if ("hikey" == key) pCurDef->hikey = parseKey(value);
1105 iliev 2012 else if ("key" == key)
1106     {
1107 persson 2058 pCurDef->lokey = pCurDef->hikey = pCurDef->pitch_keycenter = parseKey(value);
1108 iliev 2012 }
1109     else if ("lovel" == key) pCurDef->lovel = ToInt(value);
1110     else if ("hivel" == key) pCurDef->hivel = ToInt(value);
1111     else if ("lobend" == key) pCurDef->lobend = ToInt(value);
1112     else if ("hibend" == key) pCurDef->hibend = ToInt(value);
1113 persson 2106 else if ("lobpm" == key) pCurDef->lobpm = ToFloat(value);
1114     else if ("hibpm" == key) pCurDef->hibpm = ToFloat(value);
1115 iliev 2012 else if ("lochanaft" == key) pCurDef->lochanaft = ToInt(value);
1116     else if ("hichanaft" == key) pCurDef->hichanaft = ToInt(value);
1117     else if ("lopolyaft" == key) pCurDef->lopolyaft = ToInt(value);
1118     else if ("hipolyaft" == key) pCurDef->hipolyaft = ToInt(value);
1119     else if ("loprog" == key) pCurDef->loprog = ToInt(value);
1120     else if ("hiprog" == key) pCurDef->hiprog = ToInt(value);
1121     else if ("lorand" == key) pCurDef->lorand = ToFloat(value);
1122     else if ("hirand" == key) pCurDef->hirand = ToFloat(value);
1123     else if ("lotimer" == key) pCurDef->lotimer = ToFloat(value);
1124     else if ("hitimer" == key) pCurDef->hitimer = ToFloat(value);
1125     else if ("seq_length" == key) pCurDef->seq_length = ToInt(value);
1126     else if ("seq_position" == key) pCurDef->seq_position = ToInt(value);
1127 persson 2058 else if ("sw_lokey" == key) pCurDef->sw_lokey = parseKey(value);
1128     else if ("sw_hikey" == key) pCurDef->sw_hikey = parseKey(value);
1129     else if ("sw_last" == key) pCurDef->sw_last = parseKey(value);
1130     else if ("sw_down" == key) pCurDef->sw_down = parseKey(value);
1131     else if ("sw_up" == key) pCurDef->sw_up = parseKey(value);
1132     else if ("sw_previous" == key) pCurDef->sw_previous = parseKey(value);
1133 iliev 2012 else if ("sw_vel" == key)
1134     {
1135     if (value == "current") pCurDef->sw_vel = VEL_CURRENT;
1136     else if (value == "previous") pCurDef->sw_vel = VEL_PREVIOUS;
1137     }
1138     else if ("trigger" == key)
1139     {
1140     if (value == "attack") pCurDef->trigger = TRIGGER_ATTACK;
1141     else if (value == "release") pCurDef->trigger = TRIGGER_RELEASE;
1142     else if (value == "first") pCurDef->trigger = TRIGGER_FIRST;
1143     else if (value == "legato") pCurDef->trigger = TRIGGER_LEGATO;
1144     }
1145     else if ("group" == key) pCurDef->group = ToInt(value);
1146 persson 2058 else if ("off_by" == key || "offby" == key) pCurDef->off_by = ToInt(value);
1147     else if ("off_mode" == key || "offmode" == key)
1148 iliev 2012 {
1149 persson 2114 if (value == "fast") pCurDef->off_mode = OFF_FAST;
1150     else if (value == "normal") pCurDef->off_mode = OFF_NORMAL;
1151 iliev 2012 }
1152    
1153     // sample player
1154 iliev 2021 else if ("count" == key) { pCurDef->count = ToInt(value); pCurDef->loop_mode = ONE_SHOT; }
1155 iliev 2012 else if ("delay" == key) pCurDef->delay = ToFloat(value);
1156     else if ("delay_random" == key) pCurDef->delay_random = ToFloat(value);
1157     else if ("delay_beats" == key) pCurDef->delay_beats = ToInt(value);
1158     else if ("stop_beats" == key) pCurDef->stop_beats = ToInt(value);
1159     else if ("delay_samples" == key) pCurDef->delay_samples = ToInt(value);
1160     else if ("end" == key) pCurDef->end = ToInt(value);
1161     else if ("loop_crossfade" == key) pCurDef->loop_crossfade = ToFloat(value);
1162     else if ("offset_random" == key) pCurDef->offset_random = ToInt(value);
1163 persson 2058 else if ("loop_mode" == key || "loopmode" == key)
1164 iliev 2012 {
1165     if (value == "no_loop") pCurDef->loop_mode = NO_LOOP;
1166     else if (value == "one_shot") pCurDef->loop_mode = ONE_SHOT;
1167 iliev 2021 else if (value == "loop_continuous") pCurDef->loop_mode = LOOP_CONTINUOUS;
1168 iliev 2012 else if (value == "loop_sustain") pCurDef->loop_mode = LOOP_SUSTAIN;
1169     }
1170     else if ("loop_start" == key) pCurDef->loop_start = ToInt(value);
1171 iliev 2021 else if ("loopstart" == key) pCurDef->loop_start = ToInt(value); // nonstandard
1172 iliev 2012 else if ("loop_end" == key) pCurDef->loop_end = ToInt(value);
1173 iliev 2021 else if ("loopend" == key) pCurDef->loop_end = ToInt(value); // nonstandard
1174 iliev 2216 else if ("offset" == key) pCurDef->offset = ToInt(value);
1175 iliev 2012 else if ("sync_beats" == key) pCurDef->sync_beats = ToInt(value);
1176     else if ("sync_offset" == key) pCurDef->sync_offset = ToInt(value);
1177    
1178     // amplifier
1179     else if ("volume" == key) pCurDef->volume = ToFloat(value);
1180     else if ("pan" == key) pCurDef->pan = ToFloat(value);
1181     else if ("width" == key) pCurDef->width = ToFloat(value);
1182     else if ("position" == key) pCurDef->position = ToFloat(value);
1183     else if ("amp_keytrack" == key) pCurDef->amp_keytrack = ToFloat(value);
1184 persson 2058 else if ("amp_keycenter" == key) pCurDef->amp_keycenter = parseKey(value);
1185 iliev 2012 else if ("amp_veltrack" == key) pCurDef->amp_veltrack = ToFloat(value);
1186     else if ("amp_random" == key) pCurDef->amp_random = ToFloat(value);
1187 iliev 2229 else if ("rt_decay" == key || "rtdecay" == key) pCurDef->rt_decay = ToFloat(value);
1188 persson 2058 else if ("xfin_lokey" == key) pCurDef->xfin_lokey = parseKey(value);
1189     else if ("xfin_hikey" == key) pCurDef->xfin_hikey = parseKey(value);
1190     else if ("xfout_lokey" == key) pCurDef->xfout_lokey = parseKey(value);
1191     else if ("xfout_hikey" == key) pCurDef->xfout_hikey = parseKey(value);
1192 iliev 2012 else if ("xf_keycurve" == key)
1193     {
1194     if (value == "gain") pCurDef->xf_keycurve = GAIN;
1195     else if (value == "power") pCurDef->xf_keycurve = POWER;
1196     }
1197     else if ("xfin_lovel" == key) pCurDef->xfin_lovel = ToInt(value);
1198     else if ("xfin_hivel" == key) pCurDef->xfin_hivel = ToInt(value);
1199     else if ("xfout_lovel" == key) pCurDef->xfout_lovel = ToInt(value);
1200     else if ("xfout_hivel" == key) pCurDef->xfout_hivel = ToInt(value);
1201     else if ("xf_velcurve" == key)
1202     {
1203     if (value == "gain") pCurDef->xf_velcurve = GAIN;
1204     else if (value == "power") pCurDef->xf_velcurve = POWER;
1205     }
1206     else if ("xf_cccurve" == key)
1207     {
1208     if (value == "gain") pCurDef->xf_cccurve = GAIN;
1209     else if (value == "power") pCurDef->xf_cccurve = POWER;
1210     }
1211    
1212     // pitch
1213     else if ("transpose" == key) pCurDef->transpose = ToInt(value);
1214     else if ("tune" == key) pCurDef->tune = ToInt(value);
1215 persson 2058 else if ("pitch_keycenter" == key) pCurDef->pitch_keycenter = parseKey(value);
1216 iliev 2012 else if ("pitch_keytrack" == key) pCurDef->pitch_keytrack = ToInt(value);
1217     else if ("pitch_veltrack" == key) pCurDef->pitch_veltrack = ToInt(value);
1218     else if ("pitch_random" == key) pCurDef->pitch_random = ToInt(value);
1219 persson 2058 else if ("bend_up" == key || "bendup" == key) pCurDef->bend_up = ToInt(value);
1220     else if ("bend_down" == key || "benddown" == key) pCurDef->bend_down = ToInt(value);
1221 iliev 2229 else if ("bend_step" == key || "bendstep" == key) pCurDef->bend_step = ToInt(value);
1222 iliev 2012
1223     // filter
1224 persson 2086 else if ("fil_type" == key || "filtype" == key)
1225 iliev 2012 {
1226     if (value == "lpf_1p") pCurDef->fil_type = LPF_1P;
1227     else if (value == "hpf_1p") pCurDef->fil_type = HPF_1P;
1228     else if (value == "bpf_1p") pCurDef->fil_type = BPF_1P;
1229     else if (value == "brf_1p") pCurDef->fil_type = BRF_1P;
1230     else if (value == "apf_1p") pCurDef->fil_type = APF_1P;
1231     else if (value == "lpf_2p") pCurDef->fil_type = LPF_2P;
1232     else if (value == "hpf_2p") pCurDef->fil_type = HPF_2P;
1233     else if (value == "bpf_2p") pCurDef->fil_type = BPF_2P;
1234     else if (value == "brf_2p") pCurDef->fil_type = BRF_2P;
1235     else if (value == "pkf_2p") pCurDef->fil_type = PKF_2P;
1236     else if (value == "lpf_4p") pCurDef->fil_type = LPF_4P;
1237     else if (value == "hpf_4p") pCurDef->fil_type = HPF_4P;
1238     else if (value == "lpf_6p") pCurDef->fil_type = LPF_6P;
1239     else if (value == "hpf_6p") pCurDef->fil_type = HPF_6P;
1240     }
1241     else if ("fil2_type" == key)
1242     {
1243     if (value == "lpf_1p") pCurDef->fil2_type = LPF_1P;
1244     else if (value == "hpf_1p") pCurDef->fil2_type = HPF_1P;
1245     else if (value == "bpf_1p") pCurDef->fil2_type = BPF_1P;
1246     else if (value == "brf_1p") pCurDef->fil2_type = BRF_1P;
1247     else if (value == "apf_1p") pCurDef->fil2_type = APF_1P;
1248     else if (value == "lpf_2p") pCurDef->fil2_type = LPF_2P;
1249     else if (value == "hpf_2p") pCurDef->fil2_type = HPF_2P;
1250     else if (value == "bpf_2p") pCurDef->fil2_type = BPF_2P;
1251     else if (value == "brf_2p") pCurDef->fil2_type = BRF_2P;
1252     else if (value == "pkf_2p") pCurDef->fil2_type = PKF_2P;
1253     else if (value == "lpf_4p") pCurDef->fil2_type = LPF_4P;
1254     else if (value == "hpf_4p") pCurDef->fil2_type = HPF_4P;
1255     else if (value == "lpf_6p") pCurDef->fil2_type = LPF_6P;
1256     else if (value == "hpf_6p") pCurDef->fil2_type = HPF_6P;
1257     }
1258     else if ("cutoff" == key) pCurDef->cutoff = ToFloat(value);
1259     else if ("cutoff2" == key) pCurDef->cutoff2 = ToFloat(value);
1260     else if ("cutoff_chanaft" == key) pCurDef->cutoff_chanaft = ToInt(value);
1261     else if ("cutoff2_chanaft" == key) pCurDef->cutoff2_chanaft = ToInt(value);
1262     else if ("cutoff_polyaft" == key) pCurDef->cutoff_polyaft = ToInt(value);
1263     else if ("cutoff2_polyaft" == key) pCurDef->cutoff2_polyaft = ToInt(value);
1264     else if ("resonance" == key) pCurDef->resonance = ToFloat(value);
1265     else if ("resonance2" == key) pCurDef->resonance2 = ToFloat(value);
1266     else if ("fil_keytrack" == key) pCurDef->fil_keytrack = ToInt(value);
1267     else if ("fil2_keytrack" == key) pCurDef->fil2_keytrack = ToInt(value);
1268 persson 2058 else if ("fil_keycenter" == key) pCurDef->fil_keycenter = parseKey(value);
1269     else if ("fil2_keycenter" == key) pCurDef->fil2_keycenter = parseKey(value);
1270 iliev 2012 else if ("fil_veltrack" == key) pCurDef->fil_veltrack = ToInt(value);
1271     else if ("fil2_veltrack" == key) pCurDef->fil2_veltrack = ToInt(value);
1272     else if ("fil_random" == key) pCurDef->fil_random = ToInt(value);
1273     else if ("fil2_random" == key) pCurDef->fil2_random = ToInt(value);
1274    
1275     // per voice equalizer
1276     else if ("eq1_freq" == key) pCurDef->eq1_freq = ToFloat(value);
1277     else if ("eq2_freq" == key) pCurDef->eq2_freq = ToFloat(value);
1278     else if ("eq3_freq" == key) pCurDef->eq3_freq = ToFloat(value);
1279     else if ("eq1_vel2freq" == key) pCurDef->eq1_vel2freq = ToFloat(value);
1280     else if ("eq2_vel2freq" == key) pCurDef->eq2_vel2freq = ToFloat(value);
1281     else if ("eq3_vel2freq" == key) pCurDef->eq3_vel2freq = ToFloat(value);
1282     else if ("eq1_bw" == key) pCurDef->eq1_bw = ToFloat(value);
1283     else if ("eq2_bw" == key) pCurDef->eq2_bw = ToFloat(value);
1284     else if ("eq3_bw" == key) pCurDef->eq3_bw = ToFloat(value);
1285     else if ("eq1_gain" == key) pCurDef->eq1_gain = ToFloat(value);
1286     else if ("eq2_gain" == key) pCurDef->eq2_gain = ToFloat(value);
1287     else if ("eq3_gain" == key) pCurDef->eq3_gain = ToFloat(value);
1288     else if ("eq1_vel2gain" == key) pCurDef->eq1_vel2gain = ToFloat(value);
1289     else if ("eq2_vel2gain" == key) pCurDef->eq2_vel2gain = ToFloat(value);
1290     else if ("eq3_vel2gain" == key) pCurDef->eq3_vel2gain = ToFloat(value);
1291    
1292 persson 2082 else if (sscanf(key.c_str(), "amp_velcurve_%d", &x)) {
1293 persson 2091 pCurDef->amp_velcurve.set(x, ToFloat(value));
1294 persson 2082 }
1295 iliev 2225
1296 persson 2055 // v2 envelope generators
1297     else if (sscanf(key.c_str(), "eg%d%n", &x, &y)) {
1298     const char* s = key.c_str() + y;
1299 iliev 2229 if (sscanf(s, "_time%d%n", &y, &z)) {
1300     const char* s2 = s + z;
1301     if (strcmp(s2, "") == 0) egnode(x, y).time = check(key, 0.0f, 100.0f, ToFloat(value));
1302     else if (sscanf(s2, "_oncc%d", &z)) egnode(x, y).time_oncc.add( CC(z, check(key, 0.0f, 100.0f, ToFloat(value))) );
1303     } else if (sscanf(s, "_level%d%n", &y, &z)) {
1304     const char* s2 = s + z;
1305     if (strcmp(s2, "") == 0) egnode(x, y).level = check(key, 0.0f, 1.0f, ToFloat(value));
1306     else if (sscanf(s2, "_oncc%d", &z)) egnode(x, y).level_oncc.add( CC(z, check(key, 0.0f, 1.0f, ToFloat(value))) );
1307     }
1308 persson 2055 else if (sscanf(s, "_shape%d", &y)) egnode(x, y).shape = ToFloat(value);
1309     else if (sscanf(s, "_curve%d", &y)) egnode(x, y).curve = ToFloat(value);
1310     else if (strcmp(s, "_sustain") == 0) eg(x).sustain = ToInt(value);
1311     else if (strcmp(s, "_loop") == 0) eg(x).loop = ToInt(value);
1312     else if (strcmp(s, "_loop_count") == 0) eg(x).loop_count = ToInt(value);
1313     else if (strcmp(s, "_amplitude") == 0) eg(x).amplitude = ToFloat(value);
1314     else if (strcmp(s, "_cutoff") == 0) eg(x).cutoff = ToFloat(value);
1315     else std::cerr << "The opcode '" << key << "' is unsupported by libsfz!" << std::endl;
1316     }
1317    
1318     // v1 envelope generators
1319 iliev 2018 else if ("ampeg_delay" == key) pCurDef->ampeg_delay = ToFloat(value);
1320     else if ("ampeg_start" == key) pCurDef->ampeg_start = ToFloat(value);
1321     else if ("ampeg_attack" == key) pCurDef->ampeg_attack = ToFloat(value);
1322     else if ("ampeg_hold" == key) pCurDef->ampeg_hold = ToFloat(value);
1323     else if ("ampeg_decay" == key) pCurDef->ampeg_decay = ToFloat(value);
1324     else if ("ampeg_sustain" == key) pCurDef->ampeg_sustain = ToFloat(value);
1325 persson 2176 else if ("ampeg_release" == key) pCurDef->ampeg_release = ToFloat(value);
1326     else if ("ampeg_vel2delay" == key) pCurDef->ampeg_vel2delay = ToFloat(value);
1327     else if ("ampeg_vel2attack" == key) pCurDef->ampeg_vel2attack = ToFloat(value);
1328     else if ("ampeg_vel2hold" == key) pCurDef->ampeg_vel2hold = ToFloat(value);
1329     else if ("ampeg_vel2decay" == key) pCurDef->ampeg_vel2decay = ToFloat(value);
1330     else if ("ampeg_vel2sustain" == key) pCurDef->ampeg_vel2sustain = ToFloat(value);
1331     else if ("ampeg_vel2release" == key) pCurDef->ampeg_vel2release = ToFloat(value);
1332 iliev 2018 else if ("fileg_delay" == key) pCurDef->fileg_delay = ToFloat(value);
1333     else if ("fileg_start" == key) pCurDef->fileg_start = ToFloat(value);
1334     else if ("fileg_attack" == key) pCurDef->fileg_attack = ToFloat(value);
1335     else if ("fileg_hold" == key) pCurDef->fileg_hold = ToFloat(value);
1336     else if ("fileg_decay" == key) pCurDef->fileg_decay = ToFloat(value);
1337     else if ("fileg_sustain" == key) pCurDef->fileg_sustain = ToFloat(value);
1338     else if ("fileg_release" == key) pCurDef->fileg_release = ToFloat(value);
1339 iliev 2222 else if ("fileg_depth" == key) pCurDef->fileg_depth = check(key, -12000, 12000, ToInt(value));
1340     else if ("fileg_vel2delay" == key) pCurDef->fileg_vel2delay = check(key, -100.0f, 100.0f, ToFloat(value));
1341     else if ("fileg_vel2attack" == key) pCurDef->fileg_vel2attack = ToFloat(value);
1342     else if ("fileg_vel2hold" == key) pCurDef->fileg_vel2hold = ToFloat(value);
1343     else if ("fileg_vel2decay" == key) pCurDef->fileg_vel2decay = ToFloat(value);
1344     else if ("fileg_vel2sustain" == key) pCurDef->fileg_vel2sustain = ToFloat(value);
1345     else if ("fileg_vel2release" == key) pCurDef->fileg_vel2release = ToFloat(value);
1346 iliev 2018 else if ("pitcheg_delay" == key) pCurDef->pitcheg_delay = ToFloat(value);
1347     else if ("pitcheg_start" == key) pCurDef->pitcheg_start = ToFloat(value);
1348 iliev 2220 else if ("pitcheg_attack" == key) pCurDef->pitcheg_attack = ToFloat(value);
1349     else if ("pitcheg_hold" == key) pCurDef->pitcheg_hold = ToFloat(value);
1350 iliev 2018 else if ("pitcheg_decay" == key) pCurDef->pitcheg_decay = ToFloat(value);
1351 iliev 2220 else if ("pitcheg_sustain" == key) pCurDef->pitcheg_sustain = ToFloat(value);
1352     else if ("pitcheg_release" == key) pCurDef->pitcheg_release = ToFloat(value);
1353     else if ("pitcheg_depth" == key) pCurDef->pitcheg_depth = check(key, -12000, 12000, ToInt(value));
1354     else if ("pitcheg_vel2delay" == key) pCurDef->pitcheg_vel2delay = check(key, -100.0f, 100.0f, ToFloat(value));
1355     else if ("pitcheg_vel2attack" == key) pCurDef->pitcheg_vel2attack = ToFloat(value);
1356     else if ("pitcheg_vel2hold" == key) pCurDef->pitcheg_vel2hold = ToFloat(value);
1357     else if ("pitcheg_vel2decay" == key) pCurDef->pitcheg_vel2decay = ToFloat(value);
1358     else if ("pitcheg_vel2sustain" == key) pCurDef->pitcheg_vel2sustain = ToFloat(value);
1359     else if ("pitcheg_vel2release" == key) pCurDef->pitcheg_vel2release = ToFloat(value);
1360    
1361 persson 2072
1362     // v1 LFO
1363     else if ("amplfo_delay" == key) pCurDef->amplfo_delay = ToFloat(value);
1364     else if ("amplfo_fade" == key) pCurDef->amplfo_fade = ToFloat(value);
1365     else if ("amplfo_freq" == key) pCurDef->amplfo_freq = ToFloat(value);
1366     else if ("amplfo_depth" == key) pCurDef->amplfo_depth = ToFloat(value);
1367     else if ("fillfo_delay" == key) pCurDef->fillfo_delay = ToFloat(value);
1368     else if ("fillfo_fade" == key) pCurDef->fillfo_fade = ToFloat(value);
1369     else if ("fillfo_freq" == key) pCurDef->fillfo_freq = ToFloat(value);
1370     else if ("fillfo_depth" == key) pCurDef->fillfo_depth = ToFloat(value);
1371     else if ("pitchlfo_delay" == key) pCurDef->pitchlfo_delay = ToFloat(value);
1372     else if ("pitchlfo_fade" == key) pCurDef->pitchlfo_fade = ToFloat(value);
1373     else if ("pitchlfo_freq" == key) pCurDef->pitchlfo_freq = ToFloat(value);
1374     else if ("pitchlfo_depth" == key) pCurDef->pitchlfo_depth = ToInt(value);
1375 iliev 2218
1376     // v2 LFO
1377     else if (sscanf(key.c_str(), "lfo%d%n", &x, &y)) {
1378     const char* s = key.c_str() + y;
1379     if (strcmp(s, "_freq") == 0) lfo(x).freq = check(key, 0.0f, 20.0f, ToFloat(value));
1380 iliev 2227 else if (sscanf(s, "_freq_oncc%d", &y)) lfo(x).freq_oncc.add( CC(y, check(key, 0.0f, 20.0f, ToFloat(value))) );
1381 iliev 2218 else if (strcmp(s, "_wave") == 0) lfo(x).wave = ToInt(value);
1382     else if (strcmp(s, "_delay") == 0) lfo(x).delay = check(key, 0.0f, 100.0f, ToFloat(value));
1383 iliev 2226 else if (strcmp(s, "_fade") == 0) lfo(x).fade = check(key, 0.0f, 100.0f, ToFloat(value));
1384     else if (sscanf(s, "_fade_oncc%d", &y)) lfo(x).fade_oncc.add( CC(y, check(key, 0.0f, 100.0f, ToFloat(value))) );
1385 iliev 2225 else if (strcmp(s, "_phase") == 0) lfo(x).phase = check(key, 0.0f, 360.0f, ToFloat(value));
1386     else if (sscanf(s, "_phase_oncc%d", &y)) lfo(x).phase_oncc.add( CC(y, check(key, 0.0f, 360.0f, ToFloat(value))) );
1387 iliev 2221 else if (strcmp(s, "_volume") == 0) lfo(x).volume = check(key, -144.0f, 6.0f, ToFloat(value));
1388 iliev 2218 else if (strcmp(s, "_pitch") == 0) lfo(x).pitch = check(key, -9600, 9600, ToInt(value));
1389 iliev 2225 else if (sscanf(s, "_pitch_oncc%d", &y)) lfo(x).pitch_oncc.add( CC(y, check(key, -9600, 9600, ToInt(value))) );
1390 iliev 2218 else if (strcmp(s, "_cutoff") == 0) lfo(x).cutoff = check(key, -9600, 9600, ToInt(value));
1391     else if (strcmp(s, "_resonance") == 0) lfo(x).resonance = check(key, 0.0f, 40.0f, ToFloat(value));
1392     else if (strcmp(s, "_pan") == 0) lfo(x).pan = check(key, -100.0f, 100.0f, ToFloat(value));
1393     else std::cerr << "The opcode '" << key << "' is unsupported by libsfz!" << std::endl;
1394     }
1395 iliev 2230
1396 iliev 2225 // CCs
1397     else if (key.find("cc") != std::string::npos)
1398     {
1399     std::string::size_type delimiter_index = key.find("cc");
1400     std::string key_cc = key.substr(0, delimiter_index);
1401     int num_cc = ToInt(key.substr(delimiter_index + 2));
1402    
1403     // input controls
1404     if ("lo" == key_cc) pCurDef->locc.set(num_cc, ToInt(value));
1405     else if ("hi" == key_cc) pCurDef->hicc.set(num_cc, ToInt(value));
1406     else if ("start_lo" == key_cc) pCurDef->start_locc.set(num_cc, ToInt(value));
1407     else if ("start_hi" == key_cc) pCurDef->start_hicc.set(num_cc, ToInt(value));
1408     else if ("stop_lo" == key_cc) pCurDef->stop_locc.set(num_cc, ToInt(value));
1409     else if ("stop_hi" == key_cc) pCurDef->stop_hicc.set(num_cc, ToInt(value));
1410     else if ("on_lo" == key_cc) pCurDef->on_locc.set(num_cc, ToInt(value));
1411     else if ("on_hi" == key_cc) pCurDef->on_hicc.set(num_cc, ToInt(value));
1412    
1413     // sample player
1414     else if ("delay_on" == key_cc) pCurDef->delay_oncc.set(num_cc, ToFloat(value));
1415     else if ("delay_samples_on" == key_cc) pCurDef->delay_samples_oncc.set(num_cc, ToInt(value));
1416     else if ("offset_on" == key_cc) pCurDef->offset_oncc.set(num_cc, ToInt(value));
1417    
1418     // amplifier
1419     else if ("gain_on" == key_cc || "gain_" == key_cc) pCurDef->gain_oncc.set(num_cc, ToFloat(value));
1420     else if ("xfin_lo" == key_cc) pCurDef->xfin_locc.set(num_cc, ToInt(value));
1421     else if ("xfin_hi" == key_cc) pCurDef->xfin_hicc.set(num_cc, ToInt(value));
1422     else if ("xfout_lo" == key_cc) pCurDef->xfout_locc.set(num_cc, ToInt(value));
1423     else if ("xfout_hi" == key_cc) pCurDef->xfout_hicc.set(num_cc, ToInt(value));
1424    
1425     // filter
1426     else if ("cutoff_on" == key_cc || "cutoff_" == key_cc) {
1427     pCurDef->cutoff_oncc.set(num_cc, ToInt(value));
1428     pCurDef->cutoff_cc = num_cc;
1429     } else if ("cutoff2_on" == key_cc) pCurDef->cutoff2_oncc.set(num_cc, ToInt(value));
1430     else if ("cutoff_smooth" == key_cc) pCurDef->cutoff_smoothcc.set(num_cc, ToInt(value));
1431     else if ("cutoff2_smooth" == key_cc) pCurDef->cutoff2_smoothcc.set(num_cc, ToInt(value));
1432     else if ("cutoff_step" == key_cc) pCurDef->cutoff_stepcc.set(num_cc, ToInt(value));
1433     else if ("cutoff2_step" == key_cc) pCurDef->cutoff2_stepcc.set(num_cc, ToInt(value));
1434     else if ("cutoff_curve" == key_cc) pCurDef->cutoff_curvecc.set(num_cc, ToInt(value));
1435     else if ("cutoff2_curve" == key_cc) pCurDef->cutoff2_curvecc.set(num_cc, ToInt(value));
1436     else if ("resonance_on" == key_cc) pCurDef->resonance_oncc.set(num_cc, ToInt(value));
1437     else if ("resonance2_on" == key_cc) pCurDef->resonance2_oncc.set(num_cc, ToInt(value));
1438     else if ("resonance_smooth" == key_cc) pCurDef->resonance_smoothcc.set(num_cc, ToInt(value));
1439     else if ("resonance2_smooth" == key_cc) pCurDef->resonance2_smoothcc.set(num_cc, ToInt(value));
1440     else if ("resonance_step" == key_cc) pCurDef->resonance_stepcc.set(num_cc, ToInt(value));
1441     else if ("resonance2_step" == key_cc) pCurDef->resonance2_stepcc.set(num_cc, ToInt(value));
1442     else if ("resonance_curve" == key_cc) pCurDef->resonance_curvecc.set(num_cc, ToInt(value));
1443     else if ("resonance2_curve" == key_cc) pCurDef->resonance2_curvecc.set(num_cc, ToInt(value));
1444    
1445     // per voice equalizer
1446     else if ("eq1_freq_on" == key_cc || "eq1_freq" == key_cc) pCurDef->eq1_freq_oncc.set(num_cc, ToInt(value));
1447     else if ("eq2_freq_on" == key_cc || "eq2_freq" == key_cc) pCurDef->eq2_freq_oncc.set(num_cc, ToInt(value));
1448     else if ("eq3_freq_on" == key_cc || "eq3_freq" == key_cc) pCurDef->eq3_freq_oncc.set(num_cc, ToInt(value));
1449     else if ("eq1_bw_on" == key_cc || "eq1_bw" == key_cc) pCurDef->eq1_bw_oncc.set(num_cc, ToInt(value));
1450     else if ("eq2_bw_on" == key_cc || "eq2_bw" == key_cc) pCurDef->eq2_bw_oncc.set(num_cc, ToInt(value));
1451     else if ("eq3_bw_on" == key_cc || "eq3_bw" == key_cc) pCurDef->eq3_bw_oncc.set(num_cc, ToInt(value));
1452     else if ("eq1_gain_on" == key_cc || "eq1_gain" == key_cc) pCurDef->eq1_gain_oncc.set(num_cc, ToInt(value));
1453     else if ("eq2_gain_on" == key_cc || "eq2_gain" == key_cc) pCurDef->eq2_gain_oncc.set(num_cc, ToInt(value));
1454     else if ("eq3_gain_on" == key_cc || "eq3_gain" == key_cc) pCurDef->eq3_gain_oncc.set(num_cc, ToInt(value));
1455 iliev 2229
1456     else if ("ampeg_delay" == key_cc) pCurDef->ampeg_delaycc.add( CC(num_cc, check(key, -100.0f, 100.0f, ToFloat(value))) );
1457     else if ("ampeg_start" == key_cc) pCurDef->ampeg_startcc.add( CC(num_cc, check(key, -100.0f, 100.0f, ToFloat(value))) );
1458     else if ("ampeg_attack" == key_cc) pCurDef->ampeg_attackcc.add( CC(num_cc, check(key, -100.0f, 100.0f, ToFloat(value))) );
1459     else if ("ampeg_hold" == key_cc) pCurDef->ampeg_holdcc.add( CC(num_cc, check(key, -100.0f, 100.0f, ToFloat(value))) );
1460     else if ("ampeg_decay" == key_cc) pCurDef->ampeg_decaycc.add( CC(num_cc, check(key, -100.0f, 100.0f, ToFloat(value))) );
1461     else if ("ampeg_sustain" == key_cc) pCurDef->ampeg_sustaincc.add( CC(num_cc, check(key, -100.0f, 100.0f, ToFloat(value))) );
1462     else if ("ampeg_release" == key_cc) pCurDef->ampeg_releasecc.add( CC(num_cc, check(key, -100.0f, 100.0f, ToFloat(value))) );
1463    
1464 iliev 2225 else if ("pitchlfo_depth" == key_cc) pCurDef->pitchlfo_depthcc.set(num_cc, ToInt(value));
1465 iliev 2227 else if ("pitchlfo_freq" == key_cc) pCurDef->pitchlfo_freqcc.add( CC(num_cc, check(key, -200.0f, 200.0f, ToFloat(value))) );
1466     else if ("fillfo_freq" == key_cc) pCurDef->fillfo_freqcc.add( CC(num_cc, check(key, -200.0f, 200.0f, ToFloat(value))) );
1467     else if ("amplfo_freq" == key_cc) pCurDef->amplfo_freqcc.add( CC(num_cc, check(key, -200.0f, 200.0f, ToFloat(value))) );
1468 iliev 2230 else if ("volume_on" == key_cc) pCurDef->volume_oncc.add( CC(num_cc, check(key, -100.0f, 100.0f, ToFloat(value))) );
1469     else if ("volume_curve" == key_cc) pCurDef->volume_curvecc.add( CC(num_cc, 0, check(key, 0, 30000, ToInt(value))) );
1470 iliev 2225 else std::cerr << "The opcode '" << key << "' is unsupported by libsfz!" << std::endl;
1471     }
1472    
1473 iliev 2018 else {
1474 iliev 2012 std::cerr << "The opcode '" << key << "' is unsupported by libsfz!" << std::endl;
1475     }
1476     }
1477    
1478 persson 2058 int File::parseKey(const std::string& s) {
1479     int i;
1480     std::istringstream iss(s);
1481     if (isdigit(iss.peek())) {
1482     iss >> i;
1483     } else {
1484     switch (tolower(iss.get())) {
1485     case 'c': i = 0; break;
1486     case 'd': i = 2; break;
1487     case 'e': i = 4; break;
1488     case 'f': i = 5; break;
1489     case 'g': i = 7; break;
1490     case 'a': i = 9; break;
1491     case 'b': i = 11; break;
1492 persson 2115 case '-': if (s == "-1") return -1;
1493 persson 2058 default:
1494     std::cerr << "Not a note: " << s << std::endl;
1495     return 0;
1496     }
1497     if (iss.peek() == '#') {
1498     i++;
1499     iss.get();
1500     } else if (tolower(iss.peek()) == 'b') {
1501     i--;
1502     iss.get();
1503     }
1504     int octave;
1505     if (!(iss >> octave)) {
1506     std::cerr << "Not a note: " << s << std::endl;
1507     return 0;
1508     }
1509     i += (octave + 1) * 12;
1510     }
1511     return i + note_offset + 12 * octave_offset;
1512     }
1513    
1514 persson 2055 EGNode::EGNode() : time(0), level(0), shape(0), curve(0) {
1515     }
1516 iliev 2229
1517     void EGNode::Copy(const EGNode& egNode) {
1518     time = egNode.time;
1519     level = egNode.level;
1520     shape = egNode.shape;
1521     curve = egNode.curve;
1522    
1523     time_oncc = egNode.time_oncc;
1524     level_oncc = egNode.level_oncc;
1525     }
1526 persson 2055
1527     EG::EG() :
1528     sustain(0), loop(0), loop_count(0),
1529     amplitude(0), cutoff(0) {
1530     }
1531 iliev 2229
1532     void EG::Copy(const EG& eg) {
1533     sustain = eg.sustain;
1534     loop = eg.loop;
1535     loop_count = eg.loop_count;
1536     amplitude = eg.amplitude;
1537     cutoff = eg.cutoff;
1538     node = eg.node;
1539     }
1540 iliev 2218
1541     LFO::LFO(): freq (-1),/* -1 is used to determine whether the LFO was initialized */
1542 iliev 2226 fade(0), phase(0), wave(0), delay(0), pitch(0), cutoff(0), resonance(0), pan(0) {
1543 iliev 2218
1544     }
1545 iliev 2229
1546     void LFO::Copy(const LFO& lfo) {
1547     delay = lfo.delay;
1548     freq = lfo.freq;
1549     fade = lfo.fade;
1550     phase = lfo.phase;
1551     wave = lfo.wave;
1552     volume = lfo.volume;
1553     pitch = lfo.pitch;
1554     cutoff = lfo.cutoff;
1555     resonance = lfo.resonance;
1556     pan = lfo.pan;
1557     freq_oncc = lfo.freq_oncc;
1558     fade_oncc = lfo.fade_oncc;
1559     phase_oncc = lfo.phase_oncc;
1560     pitch_oncc = lfo.pitch_oncc;
1561     }
1562 persson 2055
1563 iliev 2230 EG& File::eg(int x) {
1564     while (pCurDef->eg.size() <= x) {
1565     pCurDef->eg.add(EG());
1566     }
1567     return pCurDef->eg[x];
1568     }
1569    
1570     EGNode& File::egnode(int x, int y) {
1571     EG& e = eg(x);
1572     while (e.node.size() <= y) {
1573     e.node.add(EGNode());
1574     }
1575     return e.node[y];
1576     }
1577    
1578 iliev 2218 LFO& File::lfo(int x) {
1579     while (pCurDef->lfos.size() <= x) {
1580     pCurDef->lfos.add(LFO());
1581     }
1582     return pCurDef->lfos[x];
1583     }
1584    
1585 iliev 2012 } // !namespace sfz

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC