/[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 3497 - (hide annotations) (download)
Sun Mar 10 13:34:33 2019 UTC (18 months, 2 weeks ago) by schoenebeck
File size: 109269 byte(s)
* sfz opcode 'sample': Added support for built-in sample '*silence'
  (fixes bug #310, patch by Jacek Roszkowski).
* sfz opcode 'sample': Show warning message for unknown or unsupported
  built-in sample types.
* Bumped version (2.1.0.svn7).

1 iliev 2012 /***************************************************************************
2     * *
3     * LinuxSampler - modular, streaming capable sampler *
4     * *
5 persson 2055 * Copyright (C) 2008 Anders Dahnielson <anders@dahnielson.com> *
6 persson 2856 * Copyright (C) 2009 - 2016 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 persson 2106 #include "LookupTable.h"
35 schoenebeck 3082 #include "../../common/global_private.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 2234 Sample* SampleManager::FindSample(std::string samplePath, uint offset, int end) {
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 iliev 2234 if (it->first->Offset == offset && it->first->End == end) return it->first;
63 iliev 2216 }
64 iliev 2012 }
65    
66     return NULL;
67     }
68    
69     /////////////////////////////////////////////////////////////
70 schoenebeck 3082 // class Script
71 iliev 2012
72 schoenebeck 3082 Script::Script(LinuxSampler::Path path) : m_path(path) {
73     }
74 iliev 2012
75 schoenebeck 3082 Script::Script(String path) : m_path(LinuxSampler::Path::fromUnknownFS(path)) {
76     }
77    
78     Script::~Script() {
79     }
80    
81     String Script::Name() const {
82     return m_path.getName();
83     }
84    
85     Script::Language_t Script::Language() {
86     return LANGUAGE_NKSP;
87     }
88    
89     String Script::GetSourceCode() {
90     std::ifstream f(m_path.toNativeFSPath().c_str());
91     std::string s;
92     // reserve required space on string object
93     f.seekg(0, std::ios::end);
94     s.reserve(f.tellg());
95     f.seekg(0, std::ios::beg);
96     // read entire content from file and assign it to string object
97     s.assign((std::istreambuf_iterator<char>(f)),
98     std::istreambuf_iterator<char>());
99     return s;
100     }
101    
102 iliev 2012 /////////////////////////////////////////////////////////////
103     // class Articulation
104    
105     Articulation::Articulation()
106     {
107     }
108    
109     Articulation::~Articulation()
110     {
111     }
112    
113     /////////////////////////////////////////////////////////////
114     // class Definition
115    
116 persson 2091 Definition::Definition()
117 iliev 2012 {
118     }
119    
120     Definition::~Definition()
121     {
122     }
123    
124     /////////////////////////////////////////////////////////////
125     // class Region
126    
127     Region::Region()
128     {
129     pSample = NULL;
130 persson 2072 seq_counter = 1;
131 iliev 2012 }
132    
133     Region::~Region()
134     {
135     DestroySampleIfNotUsed();
136     }
137    
138 iliev 2021 Sample* Region::GetSample(bool create)
139 iliev 2012 {
140 schoenebeck 3497 if (pSample == NULL && create && sample != "*silence") {
141 iliev 2234 uint i = offset ? *offset : 0;
142 persson 2317 Sample* sf = GetInstrument()->GetSampleManager()->FindSample(sample, i, end);
143 iliev 2012 if (sf != NULL) pSample = sf; // Reuse already created sample
144 persson 2317 else pSample = new Sample(sample, false, i, end);
145 iliev 2012 GetInstrument()->GetSampleManager()->AddSampleConsumer(pSample, this);
146     }
147     return pSample;
148     }
149    
150     void Region::DestroySampleIfNotUsed() {
151     if (pSample == NULL) return;
152     GetInstrument()->GetSampleManager()->RemoveSampleConsumer(pSample, this);
153     if (!GetInstrument()->GetSampleManager()->HasSampleConsumers(pSample)) {
154     GetInstrument()->GetSampleManager()->RemoveSample(pSample);
155     delete pSample;
156     pSample = NULL;
157     }
158     }
159    
160 persson 2101 bool Region::OnKey(const Query& q) {
161 persson 2106 // As the region comes from a LookupTable search on the query,
162     // the following parameters are not checked here: chan, key,
163     // vel, chanaft, polyaft, prog, sw_previous, cc. They are all
164     // handled by the lookup table.
165 persson 2101 bool is_triggered(
166     q.bend >= lobend && q.bend <= hibend &&
167     q.bpm >= lobpm && q.bpm < hibpm &&
168     q.rand >= lorand && q.rand < hirand &&
169     q.timer >= lotimer && q.timer <= hitimer &&
170 iliev 2012
171 persson 2086 ( sw_last == -1 ||
172 persson 2101 ((sw_last >= sw_lokey && sw_last <= sw_hikey) ? (q.last_sw_key == sw_last) : false) ) &&
173 iliev 2012
174 persson 2086 ( sw_down == -1 ||
175 persson 2101 ((sw_down >= sw_lokey && (sw_hikey == -1 || sw_down <= sw_hikey)) ? (q.sw[sw_down]) : false) ) &&
176 iliev 2012
177 persson 2086 ( sw_up == -1 ||
178 persson 2101 ((sw_up >= sw_lokey && (sw_hikey == -1 || sw_up <= sw_hikey)) ? (!q.sw[sw_up]) : true) ) &&
179 iliev 2012
180 persson 2101 ((trigger & q.trig) != 0)
181 iliev 2012 );
182    
183     if (!is_triggered)
184     return false;
185    
186 persson 2072 // seq_position has to be checked last, so we know that we
187     // increment the right counter
188     is_triggered = (seq_counter == seq_position);
189     seq_counter = (seq_counter % seq_length) + 1;
190    
191     return is_triggered;
192 iliev 2012 }
193    
194     Articulation*
195     Region::GetArticulation(int bend, uint8_t bpm, uint8_t chanaft, uint8_t polyaft, uint8_t* cc)
196     {
197     return new Articulation(); //todo: implement GetArticulation()
198     }
199    
200 iliev 2021 bool Region::HasLoop() {
201 persson 2317 bool b = loop_mode == LOOP_UNSET ? pSample->GetLoops() :
202     (loop_mode == LOOP_CONTINUOUS || loop_mode == LOOP_SUSTAIN);
203     return b && GetLoopEnd() > GetLoopStart();
204 iliev 2021 }
205    
206     uint Region::GetLoopStart() {
207 persson 2167 return (!loop_start) ? pSample->GetLoopStart() : *loop_start;
208 iliev 2021 }
209    
210     uint Region::GetLoopEnd() {
211 persson 2167 return (!loop_end) ? pSample->GetLoopEnd() : *loop_end;
212 iliev 2021 }
213    
214     uint Region::GetLoopCount() {
215     return (!count) ? 0 : *count;
216     }
217    
218 iliev 2012 /////////////////////////////////////////////////////////////
219     // class Instrument
220    
221     Instrument::Instrument(std::string name, SampleManager* pSampleManager) : KeyBindings(128, false), KeySwitchBindings(128, false)
222     {
223     this->name = name;
224     this->pSampleManager = pSampleManager ? pSampleManager : this;
225 persson 2106 pLookupTable = 0;
226 iliev 2230
227     // The first 6 curves are defined internally (actually 7 with the one at index 0)
228     Curve c;
229     for (int i = 0; i < 128; i++) c.v[i] = i / 127.0f;
230     curves.add(c); curves.add(c); curves.add(c); curves.add(c);
231     curves.add(c); curves.add(c); curves.add(c);
232     ///////
233 iliev 2012 }
234    
235     Instrument::~Instrument()
236     {
237 persson 2106 for (int i = 0; i < regions.size(); i++) {
238     delete regions[i];
239 iliev 2012 }
240 persson 2106 delete pLookupTable;
241 persson 2115 for (int i = 0 ; i < 128 ; i++) {
242     delete pLookupTableCC[i];
243     }
244 iliev 2012 }
245    
246 persson 2106 void Query::search(const Instrument* pInstrument) {
247     pRegionList = &pInstrument->pLookupTable->query(*this);
248     regionIndex = 0;
249 persson 2101 }
250    
251 persson 2115 void Query::search(const Instrument* pInstrument, int triggercc) {
252     pRegionList = &pInstrument->pLookupTableCC[triggercc]->query(*this);
253     regionIndex = 0;
254     }
255    
256 persson 2101 Region* Query::next() {
257 persson 2106 for ( ; regionIndex < pRegionList->size() ; regionIndex++) {
258     if ((*pRegionList)[regionIndex]->OnKey(*this)) {
259     return (*pRegionList)[regionIndex++];
260     }
261 iliev 2012 }
262 persson 2101 return 0;
263 iliev 2012 }
264    
265     bool Instrument::DestroyRegion(Region* pRegion) {
266     for (std::vector<Region*>::iterator it = regions.begin(); it != regions.end(); it++) {
267     if(*it == pRegion) {
268     regions.erase(it);
269     delete pRegion;
270     return true;
271     }
272     }
273    
274     return false;
275     }
276    
277     bool Instrument::HasKeyBinding(uint8_t key) {
278     if (key > 127) return false;
279     return KeyBindings[key];
280     }
281    
282     bool Instrument::HasKeySwitchBinding(uint8_t key) {
283     if (key > 127) return false;
284     return KeySwitchBindings[key];
285     }
286    
287     /////////////////////////////////////////////////////////////
288 persson 2856 // class ContainerDefinition
289 iliev 2012
290 persson 2856 ContainerDefinition::ContainerDefinition(section_type type)
291 iliev 2012 {
292     Reset();
293 persson 2856 level = type;
294 iliev 2012 }
295    
296 persson 2856 ContainerDefinition::~ContainerDefinition()
297 iliev 2012 {
298     }
299    
300     void
301 persson 2856 ContainerDefinition::Reset()
302 iliev 2012 {
303     // This is where all the default values are set.
304    
305     // sample definition default
306     sample = "";
307    
308     // input control
309     lochan = 1; hichan = 16;
310     lokey = 0; hikey = 127;
311     lovel = 0; hivel = 127;
312     lobend = -8192; hibend = 8192;
313     lobpm = 0; hibpm = 500;
314     lochanaft = 0; hichanaft = 127;
315     lopolyaft = 0; hipolyaft = 127;
316     loprog = 0; hiprog = 127;
317     lorand = 0.0; hirand = 1.0;
318     lotimer = 0.0; hitimer = 0.0;
319    
320     seq_length = 1;
321     seq_position = 1;
322    
323     sw_lokey = -1; sw_hikey = -1;
324     sw_last = -1;
325     sw_down = -1;
326     sw_up = -1;
327     sw_previous = -1;
328     sw_vel = VEL_CURRENT;
329    
330     trigger = TRIGGER_ATTACK;
331    
332 iliev 2027 group = 0;
333 persson 2114 off_by = 0;
334 iliev 2012 off_mode = OFF_FAST;
335    
336     // sample player
337 schoenebeck 3082 count = optional<int>::nothing;
338     delay = optional<float>::nothing;
339     delay_random = optional<float>::nothing;
340     delay_beats = optional<int>::nothing;
341     stop_beats = optional<int>::nothing;
342     delay_samples = optional<int>::nothing;
343 persson 2317 end = 0;
344 schoenebeck 3082 loop_crossfade = optional<float>::nothing;
345     offset = optional<uint>::nothing;
346     offset_random = optional<int>::nothing;
347 persson 2167 loop_mode = LOOP_UNSET;
348 schoenebeck 3082 loop_start = optional<int>::nothing;
349     loop_end = optional<int>::nothing;
350     sync_beats = optional<int>::nothing;
351     sync_offset = optional<int>::nothing;
352 iliev 2012
353     // amplifier
354     volume = 0;
355 iliev 2231 volume_oncc.clear();
356     volume_curvecc.clear();
357 iliev 2232 volume_smoothcc.clear();
358 iliev 2265 volume_stepcc.clear();
359 persson 2403 amplitude = 100;
360 iliev 2012 pan = 0;
361 iliev 2237 pan_oncc.clear();
362     pan_curvecc.clear();
363     pan_smoothcc.clear();
364 iliev 2265 pan_stepcc.clear();
365 iliev 2012 width = 100;
366     position = 0;
367     amp_keytrack = 0;
368     amp_keycenter = 60;
369     amp_veltrack = 100;
370     amp_random = 0;
371     rt_decay = 0;
372     xfin_lokey = 0; xfin_hikey = 0;
373     xfout_lokey = 127; xfout_hikey = 127;
374     xf_keycurve = POWER;
375     xfin_lovel = 0; xfin_hivel = 0;
376     xfout_lovel = 127; xfout_hivel = 127;
377     xf_velcurve = POWER;
378     xf_cccurve = POWER;
379    
380     // pitch
381     transpose = 0;
382     tune = 0;
383     pitch_keycenter = 60;
384     pitch_keytrack = 100;
385     pitch_veltrack = 0;
386     pitch_random = 0;
387     bend_up = 200;
388     bend_down = -200;
389     bend_step = 1;
390 iliev 2264
391     pitch_oncc.clear();
392     pitch_smoothcc.clear();
393     pitch_curvecc.clear();
394     pitch_stepcc.clear();
395 iliev 2012
396     // filter
397     fil_type = LPF_2P;
398 schoenebeck 3082 cutoff = optional<float>::nothing;
399 iliev 2012 cutoff_chanaft = 0;
400     cutoff_polyaft = 0;
401     resonance = 0;
402     fil_keytrack = 0;
403     fil_keycenter = 60;
404     fil_veltrack = 0;
405     fil_random = 0;
406    
407     fil2_type = LPF_2P;
408 schoenebeck 3082 cutoff2 = optional<float>::nothing;
409 iliev 2012 cutoff2_chanaft = 0;
410     cutoff2_polyaft = 0;
411     resonance2 = 0;
412     fil2_keytrack = 0;
413     fil2_keycenter = 60;
414     fil2_veltrack = 0;
415     fil2_random = 0;
416 iliev 2252
417     cutoff_oncc.clear();
418     cutoff_smoothcc.clear();
419     cutoff_curvecc.clear();
420 iliev 2265 cutoff_stepcc.clear();
421 iliev 2252 cutoff2_oncc.clear();
422     cutoff2_smoothcc.clear();
423     cutoff2_curvecc.clear();
424 iliev 2265 cutoff2_stepcc.clear();
425 iliev 2252
426     resonance_oncc.clear();
427     resonance_smoothcc.clear();
428     resonance_curvecc.clear();
429 iliev 2265 resonance_stepcc.clear();
430 iliev 2252 resonance2_oncc.clear();
431     resonance2_smoothcc.clear();
432     resonance2_curvecc.clear();
433 iliev 2265 resonance2_stepcc.clear();
434 iliev 2012
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 persson 2091 locc.set(i, 0);
457     hicc.set(i, 127);
458     start_locc.set(i, -1);
459     start_hicc.set(i, -1);
460     stop_locc.set(i, -1);
461     stop_hicc.set(i, -1);
462     on_locc.set(i, -1);
463     on_hicc.set(i, -1);
464 iliev 2012
465     // sample player
466 persson 2091 delay_oncc.set(i, optional<float>::nothing);
467     delay_samples_oncc.set(i, optional<int>::nothing);
468     offset_oncc.set(i, optional<int>::nothing);
469 iliev 2012
470     // amplifier
471 persson 2091 amp_velcurve.set(i, -1);
472     gain_oncc.set(i, 0);
473     xfin_locc.set(i, 0);
474     xfin_hicc.set(i, 0);
475 iliev 2236 xfout_locc.set(i, 0);
476     xfout_hicc.set(i, 0);
477 iliev 2012
478     // per voice equalizer
479 persson 2091 eq1_freq_oncc.set(i, 0);
480     eq2_freq_oncc.set(i, 0);
481     eq3_freq_oncc.set(i, 0);
482     eq1_bw_oncc.set(i, 0);
483     eq2_bw_oncc.set(i, 0);
484     eq3_bw_oncc.set(i, 0);
485     eq1_gain_oncc.set(i, 0);
486     eq2_gain_oncc.set(i, 0);
487     eq3_gain_oncc.set(i, 0);
488 iliev 2012 }
489 iliev 2018
490 persson 2055 eg.clear();
491 iliev 2231 lfos.clear();
492 persson 2055
493 iliev 2018 // deprecated
494     ampeg_delay = 0;
495     ampeg_start = 0; //in percentage
496     ampeg_attack = 0;
497     ampeg_hold = 0;
498     ampeg_decay = 0;
499 iliev 2218 ampeg_sustain = -1; // in percentage
500 iliev 2018 ampeg_release = 0;
501    
502 persson 2176 ampeg_vel2delay = 0;
503     ampeg_vel2attack = 0;
504     ampeg_vel2hold = 0;
505     ampeg_vel2decay = 0;
506     ampeg_vel2sustain = 0;
507     ampeg_vel2release = 0;
508 iliev 2231
509     ampeg_delaycc.clear();
510     ampeg_startcc.clear();
511     ampeg_attackcc.clear();
512     ampeg_holdcc.clear();
513     ampeg_decaycc.clear();
514     ampeg_sustaincc.clear();
515     ampeg_releasecc.clear();
516 persson 2176
517 iliev 2018 fileg_delay = 0;
518     fileg_start = 0; //in percentage
519     fileg_attack = 0;
520     fileg_hold = 0;
521     fileg_decay = 0;
522     fileg_sustain = 100; // in percentage
523     fileg_release = 0;
524    
525 iliev 2222 fileg_vel2delay = 0;
526     fileg_vel2attack = 0;
527     fileg_vel2hold = 0;
528     fileg_vel2decay = 0;
529     fileg_vel2sustain = 0;
530     fileg_vel2release = 0;
531     fileg_depth = 0;
532 iliev 2249
533     fileg_delay_oncc.clear();
534     fileg_start_oncc.clear();
535     fileg_attack_oncc.clear();
536     fileg_hold_oncc.clear();
537     fileg_decay_oncc.clear();
538     fileg_sustain_oncc.clear();
539     fileg_release_oncc.clear();
540     fileg_depth_oncc.clear();
541 iliev 2222
542 iliev 2018 pitcheg_delay = 0;
543     pitcheg_start = 0; //in percentage
544     pitcheg_attack = 0;
545     pitcheg_hold = 0;
546     pitcheg_decay = 0;
547     pitcheg_sustain = 100; // in percentage
548     pitcheg_release = 0;
549 iliev 2220 pitcheg_depth = 0;
550 persson 2072
551 iliev 2220 pitcheg_vel2delay = 0;
552     pitcheg_vel2attack = 0;
553     pitcheg_vel2hold = 0;
554     pitcheg_vel2decay = 0;
555     pitcheg_vel2sustain = 0;
556     pitcheg_vel2release = 0;
557 iliev 2249
558     pitcheg_delay_oncc.clear();
559     pitcheg_start_oncc.clear();
560     pitcheg_attack_oncc.clear();
561     pitcheg_hold_oncc.clear();
562     pitcheg_decay_oncc.clear();
563     pitcheg_sustain_oncc.clear();
564     pitcheg_release_oncc.clear();
565     pitcheg_depth_oncc.clear();
566 iliev 2220
567 persson 2072 amplfo_delay = 0;
568     amplfo_fade = 0;
569 iliev 2229 amplfo_freq = -1; /* -1 is used to determine whether the LFO was initialized */
570 persson 2072 amplfo_depth = 0;
571 iliev 2248 amplfo_delay_oncc.clear();
572     amplfo_fade_oncc.clear();
573 iliev 2233 amplfo_depthcc.clear();
574 iliev 2231 amplfo_freqcc.clear();
575 persson 2072
576     fillfo_delay = 0;
577     fillfo_fade = 0;
578 iliev 2229 fillfo_freq = -1; /* -1 is used to determine whether the LFO was initialized */
579 persson 2072 fillfo_depth = 0;
580 iliev 2248 fillfo_delay_oncc.clear();
581     fillfo_fade_oncc.clear();
582 iliev 2233 fillfo_depthcc.clear();
583 iliev 2231 fillfo_freqcc.clear();
584 persson 2072
585     pitchlfo_delay = 0;
586     pitchlfo_fade = 0;
587 iliev 2229 pitchlfo_freq = -1; /* -1 is used to determine whether the LFO was initialized */
588 persson 2072 pitchlfo_depth = 0;
589 iliev 2248 pitchlfo_delay_oncc.clear();
590     pitchlfo_fade_oncc.clear();
591 iliev 2253 pitchlfo_depthcc.clear();
592 iliev 2231 pitchlfo_freqcc.clear();
593 iliev 2012 }
594    
595 persson 2856 void ContainerDefinition::CopyValuesToDefinition(Definition* definition)
596 iliev 2012 {
597 persson 2856 // This is where the current settings are copied to the new definition.
598 iliev 2012
599     // sample definition
600 persson 2856 definition->sample = sample;
601 iliev 2012
602     // input control
603 persson 2856 definition->lochan = lochan;
604     definition->hichan = hichan;
605     definition->lokey = lokey;
606     definition->hikey = hikey;
607     definition->lovel = lovel;
608     definition->hivel = hivel;
609     definition->locc = locc;
610     definition->hicc = hicc;
611     definition->lobend = lobend;
612     definition->hibend = hibend;
613     definition->lobpm = lobpm;
614     definition->hibpm = hibpm;
615     definition->lochanaft = lochanaft;
616     definition->hichanaft = hichanaft;
617     definition->lopolyaft = lopolyaft;
618     definition->hipolyaft = hipolyaft;
619     definition->loprog = loprog;
620     definition->hiprog = hiprog;
621     definition->lorand = lorand;
622     definition->hirand = hirand;
623     definition->lotimer = lotimer;
624     definition->hitimer = hitimer;
625     definition->seq_length = seq_length;
626     definition->seq_position = seq_position;
627     definition->start_locc = start_locc;
628     definition->start_hicc = start_hicc;
629     definition->stop_locc = stop_locc;
630     definition->stop_hicc = stop_hicc;
631     definition->sw_lokey = sw_lokey;
632     definition->sw_hikey = sw_hikey;
633     definition->sw_last = sw_last;
634     definition->sw_down = sw_down;
635     definition->sw_up = sw_up;
636     definition->sw_previous = sw_previous;
637     definition->sw_vel = sw_vel;
638     definition->trigger = trigger;
639     definition->group = group;
640     definition->off_by = off_by;
641     definition->off_mode = off_mode;
642     definition->on_locc = on_locc;
643     definition->on_hicc = on_hicc;
644 iliev 2012
645     // sample player
646 persson 2856 definition->count = count;
647     definition->delay = delay;
648     definition->delay_random = delay_random;
649     definition->delay_oncc = delay_oncc;
650     definition->delay_beats = delay_beats;
651     definition->stop_beats = stop_beats;
652     definition->delay_samples = delay_samples;
653     definition->delay_samples_oncc = delay_samples_oncc;
654     definition->end = end;
655     definition->loop_crossfade = loop_crossfade;
656     definition->offset = offset;
657     definition->offset_random = offset_random;
658     definition->offset_oncc = offset_oncc;
659     definition->loop_mode = loop_mode;
660     definition->loop_start = loop_start;
661     definition->loop_end = loop_end;
662     definition->sync_beats = sync_beats;
663     definition->sync_offset = sync_offset;
664 iliev 2012
665     // amplifier
666 persson 2856 definition->volume = volume;
667     definition->volume_oncc = volume_oncc;
668     definition->volume_curvecc = volume_curvecc;
669     definition->volume_smoothcc = volume_smoothcc;
670     definition->volume_stepcc = volume_stepcc;
671     definition->amplitude = amplitude;
672     definition->pan = pan;
673     definition->pan_oncc = pan_oncc;
674     definition->pan_curvecc = pan_curvecc;
675     definition->pan_smoothcc = pan_smoothcc;
676     definition->pan_stepcc = pan_stepcc;
677     definition->width = width;
678     definition->position = position;
679     definition->amp_keytrack = amp_keytrack;
680     definition->amp_keycenter = amp_keycenter;
681     definition->amp_veltrack = amp_veltrack;
682     definition->amp_velcurve = amp_velcurve;
683     definition->amp_random = amp_random;
684     definition->rt_decay = rt_decay;
685     definition->gain_oncc = gain_oncc;
686     definition->xfin_lokey = xfin_lokey;
687     definition->xfin_hikey = xfin_hikey;
688     definition->xfout_lokey = xfout_lokey;
689     definition->xfout_hikey = xfout_hikey;
690     definition->xf_keycurve = xf_keycurve;
691     definition->xfin_lovel = xfin_lovel;
692     definition->xfin_hivel = xfin_lovel;
693     definition->xfout_lovel = xfout_lovel;
694     definition->xfout_hivel = xfout_hivel;
695     definition->xf_velcurve = xf_velcurve;
696     definition->xfin_locc = xfin_locc;
697     definition->xfin_hicc = xfin_hicc;
698     definition->xfout_locc = xfout_locc;
699     definition->xfout_hicc = xfout_hicc;
700     definition->xf_cccurve = xf_cccurve;
701 iliev 2012
702     // pitch
703 persson 2856 definition->transpose = transpose;
704     definition->tune = tune;
705     definition->pitch_keycenter = pitch_keycenter;
706     definition->pitch_keytrack = pitch_keytrack;
707     definition->pitch_veltrack = pitch_veltrack;
708     definition->pitch_random = pitch_random;
709     definition->bend_up = bend_up;
710     definition->bend_down = bend_down;
711     definition->bend_step = bend_step;
712 iliev 2264
713 persson 2856 definition->pitch_oncc = pitch_oncc;
714     definition->pitch_smoothcc = pitch_smoothcc;
715     definition->pitch_curvecc = pitch_curvecc;
716     definition->pitch_stepcc = pitch_stepcc;
717 iliev 2012
718     // filter
719 persson 2856 definition->fil_type = fil_type;
720     definition->cutoff = cutoff;
721     definition->cutoff_oncc = cutoff_oncc;
722     definition->cutoff_smoothcc = cutoff_smoothcc;
723     definition->cutoff_stepcc = cutoff_stepcc;
724     definition->cutoff_curvecc = cutoff_curvecc;
725     definition->cutoff_chanaft = cutoff_chanaft;
726     definition->cutoff_polyaft = cutoff_polyaft;
727     definition->resonance = resonance;
728     definition->resonance_oncc = resonance_oncc;
729     definition->resonance_smoothcc = resonance_smoothcc;
730     definition->resonance_stepcc = resonance_stepcc;
731     definition->resonance_curvecc = resonance_curvecc;
732     definition->fil_keytrack = fil_keytrack;
733     definition->fil_keycenter = fil_keycenter;
734     definition->fil_veltrack = fil_veltrack;
735     definition->fil_random = fil_random;
736 iliev 2012
737 persson 2856 definition->fil2_type = fil2_type;
738     definition->cutoff2 = cutoff2;
739     definition->cutoff2_oncc = cutoff2_oncc;
740     definition->cutoff2_smoothcc = cutoff2_smoothcc;
741     definition->cutoff2_stepcc = cutoff2_stepcc;
742     definition->cutoff2_curvecc = cutoff2_curvecc;
743     definition->cutoff2_chanaft = cutoff2_chanaft;
744     definition->cutoff2_polyaft = cutoff2_polyaft;
745     definition->resonance2 = resonance2;
746     definition->resonance2_oncc = resonance2_oncc;
747     definition->resonance2_smoothcc = resonance2_smoothcc;
748     definition->resonance2_stepcc = resonance2_stepcc;
749     definition->resonance2_curvecc = resonance2_curvecc;
750     definition->fil2_keytrack = fil2_keytrack;
751     definition->fil2_keycenter = fil2_keycenter;
752     definition->fil2_veltrack = fil2_veltrack;
753     definition->fil2_random = fil2_random;
754 iliev 2012
755     // per voice equalizer
756 persson 2856 definition->eq1_freq = eq1_freq;
757     definition->eq2_freq = eq2_freq;
758     definition->eq3_freq = eq3_freq;
759     definition->eq1_freq_oncc = eq1_freq_oncc;
760     definition->eq2_freq_oncc = eq2_freq_oncc;
761     definition->eq3_freq_oncc = eq3_freq_oncc;
762     definition->eq1_vel2freq = eq1_vel2freq;
763     definition->eq2_vel2freq = eq2_vel2freq;
764     definition->eq3_vel2freq = eq3_vel2freq;
765     definition->eq1_bw = eq1_bw;
766     definition->eq2_bw = eq2_bw;
767     definition->eq3_bw = eq3_bw;
768     definition->eq1_bw_oncc = eq1_bw_oncc;
769     definition->eq2_bw_oncc = eq2_bw_oncc;
770     definition->eq3_bw_oncc = eq3_bw_oncc;
771     definition->eq1_gain = eq1_gain;
772     definition->eq2_gain = eq2_gain;
773     definition->eq3_gain = eq3_gain;
774     definition->eq1_gain_oncc = eq1_gain_oncc;
775     definition->eq2_gain_oncc = eq2_gain_oncc;
776     definition->eq3_gain_oncc = eq3_gain_oncc;
777     definition->eq1_vel2gain = eq1_vel2gain;
778     definition->eq2_vel2gain = eq2_vel2gain;
779     definition->eq3_vel2gain = eq3_vel2gain;
780 iliev 2012
781 persson 2055 // envelope generator
782 persson 2856 definition->eg = eg;
783 persson 2055
784 iliev 2018 // deprecated
785 persson 2856 definition->ampeg_delay = ampeg_delay;
786     definition->ampeg_start = ampeg_start;
787     definition->ampeg_attack = ampeg_attack;
788     definition->ampeg_hold = ampeg_hold;
789     definition->ampeg_decay = ampeg_decay;
790     definition->ampeg_sustain = ampeg_sustain;
791     definition->ampeg_release = ampeg_release;
792 iliev 2018
793 persson 2856 definition->ampeg_vel2delay = ampeg_vel2delay;
794     definition->ampeg_vel2attack = ampeg_vel2attack;
795     definition->ampeg_vel2hold = ampeg_vel2hold;
796     definition->ampeg_vel2decay = ampeg_vel2decay;
797     definition->ampeg_vel2sustain = ampeg_vel2sustain;
798     definition->ampeg_vel2release = ampeg_vel2release;
799 iliev 2229
800 persson 2856 definition->ampeg_delaycc = ampeg_delaycc;
801     definition->ampeg_startcc = ampeg_startcc;
802     definition->ampeg_attackcc = ampeg_attackcc;
803     definition->ampeg_holdcc = ampeg_holdcc;
804     definition->ampeg_decaycc = ampeg_decaycc;
805     definition->ampeg_sustaincc = ampeg_sustaincc;
806     definition->ampeg_releasecc = ampeg_releasecc;
807 persson 2176
808 persson 2856 definition->fileg_delay = fileg_delay;
809     definition->fileg_start = fileg_start;
810     definition->fileg_attack = fileg_attack;
811     definition->fileg_hold = fileg_hold;
812     definition->fileg_decay = fileg_decay;
813     definition->fileg_sustain = fileg_sustain;
814     definition->fileg_release = fileg_release;
815     definition->fileg_depth = fileg_depth;
816 iliev 2018
817 persson 2856 definition->fileg_vel2delay = fileg_vel2delay;
818     definition->fileg_vel2attack = fileg_vel2attack;
819     definition->fileg_vel2hold = fileg_vel2hold;
820     definition->fileg_vel2decay = fileg_vel2decay;
821     definition->fileg_vel2sustain = fileg_vel2sustain;
822     definition->fileg_vel2release = fileg_vel2release;
823 iliev 2249
824 persson 2856 definition->fileg_delay_oncc = fileg_delay_oncc;
825     definition->fileg_start_oncc = fileg_start_oncc;
826     definition->fileg_attack_oncc = fileg_attack_oncc;
827     definition->fileg_hold_oncc = fileg_hold_oncc;
828     definition->fileg_decay_oncc = fileg_decay_oncc;
829     definition->fileg_sustain_oncc = fileg_sustain_oncc;
830     definition->fileg_release_oncc = fileg_release_oncc;
831     definition->fileg_depth_oncc = fileg_depth_oncc;
832 iliev 2222
833 persson 2856 definition->pitcheg_delay = pitcheg_delay;
834     definition->pitcheg_start = pitcheg_start;
835     definition->pitcheg_attack = pitcheg_attack;
836     definition->pitcheg_hold = pitcheg_hold;
837     definition->pitcheg_decay = pitcheg_decay;
838     definition->pitcheg_sustain = pitcheg_sustain;
839     definition->pitcheg_release = pitcheg_release;
840     definition->pitcheg_depth = pitcheg_depth;
841 iliev 2018
842 persson 2856 definition->pitcheg_vel2delay = pitcheg_vel2delay;
843     definition->pitcheg_vel2attack = pitcheg_vel2attack;
844     definition->pitcheg_vel2hold = pitcheg_vel2hold;
845     definition->pitcheg_vel2decay = pitcheg_vel2decay;
846     definition->pitcheg_vel2sustain = pitcheg_vel2sustain;
847     definition->pitcheg_vel2release = pitcheg_vel2release;
848 iliev 2249
849 persson 2856 definition->pitcheg_delay_oncc = pitcheg_delay_oncc;
850     definition->pitcheg_start_oncc = pitcheg_start_oncc;
851     definition->pitcheg_attack_oncc = pitcheg_attack_oncc;
852     definition->pitcheg_hold_oncc = pitcheg_hold_oncc;
853     definition->pitcheg_decay_oncc = pitcheg_decay_oncc;
854     definition->pitcheg_sustain_oncc = pitcheg_sustain_oncc;
855     definition->pitcheg_release_oncc = pitcheg_release_oncc;
856     definition->pitcheg_depth_oncc = pitcheg_depth_oncc;
857 iliev 2220
858 persson 2856 definition->amplfo_delay = amplfo_delay;
859     definition->amplfo_fade = amplfo_fade;
860     definition->amplfo_freq = amplfo_freq;
861     definition->amplfo_depth = amplfo_depth;
862 iliev 2227
863 persson 2856 definition->amplfo_delay_oncc = amplfo_delay_oncc;
864     definition->amplfo_fade_oncc = amplfo_fade_oncc;
865     definition->amplfo_depthcc = amplfo_depthcc;
866     definition->amplfo_freqcc = amplfo_freqcc;
867 persson 2072
868 persson 2856 definition->fillfo_delay = fillfo_delay;
869     definition->fillfo_fade = fillfo_fade;
870     definition->fillfo_freq = fillfo_freq;
871     definition->fillfo_depth = fillfo_depth;
872 iliev 2227
873 persson 2856 definition->fillfo_delay_oncc = fillfo_delay_oncc;
874     definition->fillfo_fade_oncc = fillfo_fade_oncc;
875     definition->fillfo_depthcc = fillfo_depthcc;
876     definition->fillfo_freqcc = fillfo_freqcc;
877 persson 2072
878 persson 2856 definition->pitchlfo_delay = pitchlfo_delay;
879     definition->pitchlfo_fade = pitchlfo_fade;
880     definition->pitchlfo_freq = pitchlfo_freq;
881     definition->pitchlfo_depth = pitchlfo_depth;
882 iliev 2224
883 persson 2856 definition->pitchlfo_delay_oncc = pitchlfo_delay_oncc;
884     definition->pitchlfo_fade_oncc = pitchlfo_fade_oncc;
885     definition->pitchlfo_depthcc = pitchlfo_depthcc;
886     definition->pitchlfo_freqcc = pitchlfo_freqcc;
887 iliev 2229
888 persson 2856 definition->eg = eg;
889     definition->lfos = lfos;
890 iliev 2012 }
891    
892     /////////////////////////////////////////////////////////////
893     // class File
894    
895 persson 2856 const std::string File::MACRO_NAME_CHARS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_";
896     const std::string File::MACRO_VALUE_CHARS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_. /\\";
897    
898 iliev 2012 File::File(std::string file, SampleManager* pSampleManager) :
899 persson 2856 _current_section(GLOBAL),
900 schoenebeck 3034 id(0),
901 iliev 2012 default_path(""),
902     octave_offset(0),
903 schoenebeck 3034 note_offset(0)
904 iliev 2012 {
905     _instrument = new Instrument(LinuxSampler::Path::getBaseName(file), pSampleManager);
906 persson 2856 ContainerDefinition* defaultGlobalContainer = new ContainerDefinition(ContainerDefinition::GLOBAL);
907     _current_containers.push(defaultGlobalContainer);
908     pCurDef = defaultGlobalContainer;
909 schoenebeck 2529
910     parseFile(file,pSampleManager);
911    
912 persson 2091 std::set<float*> velcurves;
913 iliev 2012 for (int i = 0; i < _instrument->regions.size(); i++) {
914     ::sfz::Region* pRegion = _instrument->regions[i];
915     int low = pRegion->lokey;
916     int high = pRegion->hikey;
917 persson 2115 if (low != -1) { // lokey -1 means region doesn't play on note-on
918     // hikey -1 is the same as no limit, except that it
919     // also enables on_locc/on_hicc
920     if (high == -1) high = 127;
921     if (low < 0 || low > 127 || high < 0 || high > 127 || low > high) {
922     std::cerr << "Invalid key range: " << low << " - " << high << std::endl;
923     } else {
924     for (int j = low; j <= high; j++) _instrument->KeyBindings[j] = true;
925     }
926 iliev 2012 }
927    
928     // get keyswitches
929     low = pRegion->sw_lokey;
930 persson 2086 if (low < 0) low = 0;
931 iliev 2012 high = pRegion->sw_hikey;
932 persson 2086 if (high == -1) {
933 iliev 2012 // Key switches not defined, so nothing to do
934 persson 2086 } else if (low >= 0 && low <= 127 && high >= 0 && high <= 127 && high >= low) {
935 iliev 2012 for (int j = low; j <= high; j++) _instrument->KeySwitchBindings[j] = true;
936     } else {
937     std::cerr << "Invalid key switch range: " << low << " - " << high << std::endl;
938     }
939 persson 2082
940     // create velocity response curve
941 persson 2091
942     // don't use copy-on-write here, instead change the actual
943     // unique buffers in memory
944     float* velcurve = const_cast<float*>(&pRegion->amp_velcurve[0]);
945     if (velcurves.insert(velcurve).second) {
946     int prev = 0;
947     float prevvalue = 0;
948     for (int v = 0 ; v < 128 ; v++) {
949     if (velcurve[v] >= 0) {
950     float step = (velcurve[v] - prevvalue) / (v - prev);
951     for ( ; prev < v ; prev++) {
952     velcurve[prev] = prevvalue;
953     prevvalue += step;
954     }
955     }
956     }
957     if (prev) {
958     float step = (1 - prevvalue) / (127 - prev);
959     for ( ; prev < 128 ; prev++) {
960     velcurve[prev] = prevvalue;
961 persson 2082 prevvalue += step;
962     }
963 persson 2091 } else {
964     // default curve
965     for (int v = 0 ; v < 128 ; v++) {
966     velcurve[v] = v * v / (127.0 * 127.0);
967     }
968 persson 2082 }
969     }
970 iliev 2012 }
971 persson 2106
972     _instrument->pLookupTable = new LookupTable(_instrument);
973 persson 2115
974     // create separate lookup tables for controller triggered
975     // regions, one for each CC
976     for (int i = 0 ; i < 128 ; i++) {
977     _instrument->pLookupTableCC[i] = new LookupTable(_instrument, i);
978     }
979 iliev 2230
980 iliev 2233 for (int i = 0; i < _instrument->regions.size(); i++) {
981     Region* r = _instrument->regions[i];
982 iliev 2230
983     copyCurves(r->volume_curvecc, r->volume_oncc);
984 iliev 2233 r->volume_curvecc.clear();
985    
986 iliev 2232 copySmoothValues(r->volume_smoothcc, r->volume_oncc);
987 iliev 2233 r->volume_smoothcc.clear();
988 iliev 2230
989 iliev 2265 copyStepValues(r->volume_stepcc, r->volume_oncc);
990     r->volume_stepcc.clear();
991    
992 iliev 2264 copyCurves(r->pitch_curvecc, r->pitch_oncc);
993     r->pitch_curvecc.clear();
994    
995     copySmoothValues(r->pitch_smoothcc, r->pitch_oncc);
996     r->pitch_smoothcc.clear();
997    
998     copyStepValues(r->pitch_stepcc, r->pitch_oncc);
999     r->pitch_stepcc.clear();
1000    
1001 iliev 2237 copyCurves(r->pan_curvecc, r->pan_oncc);
1002     r->pan_curvecc.clear();
1003    
1004     copySmoothValues(r->pan_smoothcc, r->pan_oncc);
1005     r->pan_smoothcc.clear();
1006    
1007 iliev 2265 copyStepValues(r->pan_stepcc, r->pan_oncc);
1008     r->pan_stepcc.clear();
1009    
1010 iliev 2252 copyCurves(r->cutoff_curvecc, r->cutoff_oncc);
1011     r->cutoff_curvecc.clear();
1012    
1013     copySmoothValues(r->cutoff_smoothcc, r->cutoff_oncc);
1014     r->cutoff_smoothcc.clear();
1015    
1016 iliev 2265 copyStepValues(r->cutoff_stepcc, r->cutoff_oncc);
1017     r->cutoff_stepcc.clear();
1018    
1019 iliev 2252 copyCurves(r->cutoff2_curvecc, r->cutoff2_oncc);
1020     r->cutoff2_curvecc.clear();
1021    
1022     copySmoothValues(r->cutoff2_smoothcc, r->cutoff2_oncc);
1023     r->cutoff2_smoothcc.clear();
1024    
1025 iliev 2265 copyStepValues(r->cutoff2_stepcc, r->cutoff2_oncc);
1026     r->cutoff2_stepcc.clear();
1027    
1028 iliev 2252 copyCurves(r->resonance_curvecc, r->resonance_oncc);
1029     r->resonance_curvecc.clear();
1030    
1031     copySmoothValues(r->resonance_smoothcc, r->resonance_oncc);
1032     r->resonance_smoothcc.clear();
1033    
1034 iliev 2265 copyStepValues(r->resonance_stepcc, r->resonance_oncc);
1035     r->resonance_stepcc.clear();
1036    
1037 iliev 2252 copyCurves(r->resonance2_curvecc, r->resonance2_oncc);
1038     r->resonance2_curvecc.clear();
1039    
1040     copySmoothValues(r->resonance2_smoothcc, r->resonance2_oncc);
1041     r->resonance2_smoothcc.clear();
1042    
1043 iliev 2265 copyStepValues(r->resonance2_stepcc, r->resonance2_oncc);
1044     r->resonance2_stepcc.clear();
1045    
1046 iliev 2237 for (int j = 0; j < r->eg.size(); j++) {
1047     copyCurves(r->eg[j].pan_curvecc, r->eg[j].pan_oncc);
1048     r->eg[j].pan_curvecc.clear();
1049     }
1050    
1051 iliev 2233 for (int j = 0; j < r->lfos.size(); j++) {
1052 iliev 2299 r->lfos[j].copySmoothValues();
1053     r->lfos[j].copyStepValues();
1054    
1055 iliev 2233 copySmoothValues(r->lfos[j].volume_smoothcc, r->lfos[j].volume_oncc);
1056     r->lfos[j].volume_smoothcc.clear();
1057    
1058 iliev 2265 copyStepValues(r->lfos[j].volume_stepcc, r->lfos[j].volume_oncc);
1059     r->lfos[j].volume_stepcc.clear();
1060    
1061 iliev 2233 copySmoothValues(r->lfos[j].freq_smoothcc, r->lfos[j].freq_oncc);
1062     r->lfos[j].freq_smoothcc.clear();
1063    
1064 iliev 2265 copyStepValues(r->lfos[j].freq_stepcc, r->lfos[j].freq_oncc);
1065     r->lfos[j].freq_stepcc.clear();
1066    
1067 iliev 2233 copySmoothValues(r->lfos[j].pitch_smoothcc, r->lfos[j].pitch_oncc);
1068     r->lfos[j].pitch_smoothcc.clear();
1069    
1070 iliev 2265 copyStepValues(r->lfos[j].pitch_stepcc, r->lfos[j].pitch_oncc);
1071     r->lfos[j].pitch_stepcc.clear();
1072    
1073 iliev 2233 copySmoothValues(r->lfos[j].pan_smoothcc, r->lfos[j].pan_oncc);
1074     r->lfos[j].pan_smoothcc.clear();
1075    
1076 iliev 2265 copyStepValues(r->lfos[j].pan_stepcc, r->lfos[j].pan_oncc);
1077     r->lfos[j].pan_stepcc.clear();
1078    
1079 iliev 2233 copySmoothValues(r->lfos[j].cutoff_smoothcc, r->lfos[j].cutoff_oncc);
1080     r->lfos[j].cutoff_smoothcc.clear();
1081    
1082 iliev 2265 copyStepValues(r->lfos[j].cutoff_stepcc, r->lfos[j].cutoff_oncc);
1083     r->lfos[j].cutoff_stepcc.clear();
1084    
1085 iliev 2233 copySmoothValues(r->lfos[j].resonance_smoothcc, r->lfos[j].resonance_oncc);
1086     r->lfos[j].resonance_smoothcc.clear();
1087 iliev 2265
1088     copyStepValues(r->lfos[j].resonance_stepcc, r->lfos[j].resonance_oncc);
1089     r->lfos[j].resonance_stepcc.clear();
1090 iliev 2233 }
1091 iliev 2230 }
1092 iliev 2012 }
1093    
1094 persson 2533 void File::parseFile(std::string file, SampleManager* pSampleManager){
1095     enum token_type_t { HEADER, OPCODE };
1096 schoenebeck 3054 token_type_t token_type = (token_type_t) -1;
1097 persson 2533 std::string token_string;
1098    
1099     std::ifstream fs(file.c_str());
1100     currentDir = LinuxSampler::Path::stripLastName(file);
1101     std::string token;
1102     std::string line;
1103     currentLine = 0;
1104    
1105     while (std::getline(fs, line))
1106     {
1107     currentLine++;
1108     // COMMENT
1109     std::string::size_type slash_index = line.find("//");
1110     if (slash_index != std::string::npos)
1111     line.resize(slash_index);
1112    
1113     // #include
1114     if (line.find("#include ") == 0) {
1115     size_t fname_start = line.find("\"");
1116     if (fname_start == std::string::npos) continue;
1117    
1118     size_t fname_end = line.find("\"", fname_start + 1);
1119     if (fname_end == std::string::npos || fname_start == fname_end)
1120     continue;
1121     std::string fname = line.substr(fname_start + 1, fname_end - fname_start - 1);
1122    
1123     if (!currentDir.empty() && !LinuxSampler::Path(fname).isAbsolute())
1124     fname = currentDir + LinuxSampler::File::DirSeparator + fname;
1125    
1126     std::string cd = currentDir; // backup current dir
1127     int cl = currentLine;
1128     parseFile(fname, pSampleManager);
1129     currentDir = cd; // restore currentDir (since altered by parsefile())
1130     currentLine = cl;
1131     continue;
1132     }
1133 persson 2856 // #define
1134     else if (line.find("#define") == 0)
1135     {
1136    
1137     size_t varname_start = line.find_first_not_of("\t ", std::strlen("#define"));
1138     size_t varname_end = line.find_first_of("\t ", varname_start + 1);
1139     size_t value_start = line.find_first_not_of("\t ", varname_end + 1);
1140    
1141     std::string varname = line.substr(varname_start, varname_end - varname_start);
1142     std::string value = line.substr(value_start, std::string::npos);
1143    
1144     if (varname.size() == 0 || value.size() == 0)
1145     {
1146     std::cerr << "sfz error: Malformed #define statement on line " << currentLine << std::endl;
1147     continue;
1148     }
1149    
1150     // Deal with DOS EOLs
1151     if (value[value.size() - 1] == '\r')
1152     {
1153     value.erase(value.size() - 1);
1154     }
1155    
1156     // Check varname
1157     if (varname[0] != '$')
1158     {
1159     std::cerr << "sfz error: Macro name '" << varname;
1160     std::cerr << "' doesn't start with '$'." << std::endl;
1161     continue;
1162     }
1163     // Invalid chars
1164     if (varname.find_first_not_of(MACRO_NAME_CHARS, 1) != std::string::npos)
1165     {
1166     std::cerr << "sfz error: Macro name '" << varname;
1167     std::cerr << "' contains invalid characters." << std::endl;
1168     }
1169    
1170     // Check value
1171     // Match alphanumeric, underscore, and decimal point.
1172     if (value.find_first_not_of(MACRO_VALUE_CHARS) != std::string::npos)
1173     {
1174     std::cerr << "sfz error: Macro value '" << value;
1175     std::cerr << "' contains invalid characters." << std::endl;
1176     continue;
1177     }
1178    
1179     _defined_macros[varname] = value;
1180    
1181     continue;
1182     }
1183 schoenebeck 3082 // script=path/to/scriptfile
1184     else if (line.find("script") == 0) {
1185     size_t eq = line.find_first_of("=");
1186     if (eq == std::string::npos) {
1187     std::cerr << "sfz error: opcode 'script' misses '=' character\n";
1188     continue;
1189     }
1190     std::string value = trim( line.substr(eq+1, std::string::npos) );
1191     if (value.empty()) {
1192     std::cerr << "sfz error: empty path assigned to opcode 'script'\n";
1193     continue;
1194     }
1195     LinuxSampler::Path path = LinuxSampler::Path::fromUnknownFS(value);
1196     if (!currentDir.empty() && !path.isAbsolute())
1197     path = LinuxSampler::Path::fromUnknownFS(currentDir) + path;
1198     LinuxSampler::File file(path);
1199     if (!file.Exist()) {
1200     std::cerr << "sfz error: script file '" << value << "' does not exist\n";
1201     continue;
1202     }
1203     if (!file.IsFile()) {
1204     std::cerr << "sfz error: script '" << value << "' is not a file\n";
1205     continue;
1206     }
1207     Script script(path);
1208     _instrument->scripts.push_back(script);
1209 schoenebeck 3084
1210     continue;
1211 schoenebeck 3082 }
1212 persson 2533
1213     // DEFINITION
1214     std::stringstream linestream(line);
1215     int spaces = 0;
1216     while (linestream >> token)
1217     {
1218     linestream >> std::noskipws;
1219 persson 3291 if (token[0] == '<') {
1220     std::string::size_type p = token.find('>', 1);
1221     if (p != std::string::npos && p < (token.size() - 1)) {
1222     linestream.seekg(p + 1 - token.size(), std::stringstream::cur);
1223     token.erase(p + 1);
1224     }
1225     }
1226 persson 2533 if (token[0] == '<' && token[token.size()-1] == '>')
1227     {
1228     // HEAD
1229     if (!token_string.empty())
1230     {
1231     switch (token_type)
1232     {
1233     case HEADER:
1234     push_header(token_string);
1235     break;
1236     case OPCODE:
1237     push_opcode(token_string);
1238     break;
1239     }
1240     token_string.erase();
1241     }
1242     token_string.append(token);
1243     token_type = HEADER;
1244     }
1245     else if (token.find('=') != std::string::npos)
1246     {
1247     // HEAD
1248     if (!token_string.empty())
1249     {
1250     switch (token_type)
1251     {
1252     case HEADER:
1253     push_header(token_string);
1254     break;
1255     case OPCODE:
1256     push_opcode(token_string);
1257     break;
1258     }
1259     token_string.erase();
1260     }
1261     token_string.append(token);
1262     token_type = OPCODE;
1263     }
1264     else
1265     {
1266     // TAIL
1267     token_string.append(spaces, ' ');
1268     token_string.append(token);
1269     }
1270     spaces = 0;
1271     while (isspace(linestream.peek())) {
1272     linestream.ignore();
1273     spaces++;
1274     }
1275     }
1276    
1277     // EOL
1278     if (!token_string.empty())
1279     {
1280     switch (token_type)
1281     {
1282     case HEADER:
1283     push_header(token_string);
1284     break;
1285     case OPCODE:
1286     push_opcode(token_string);
1287     break;
1288     }
1289     token_string.erase();
1290     }
1291     }
1292     }
1293    
1294 iliev 2012 File::~File()
1295     {
1296 persson 2856 for (int i = 0; i < _current_containers.size(); i++)
1297     {
1298     delete _current_containers.top();
1299     _current_containers.pop();
1300     }
1301 iliev 2012 delete _instrument;
1302     }
1303    
1304     Instrument*
1305     File::GetInstrument()
1306     {
1307     return _instrument;
1308     }
1309 iliev 2230
1310     void File::copyCurves(LinuxSampler::ArrayList<CC>& curves, LinuxSampler::ArrayList<CC>& dest) {
1311     for (int i = 0; i < curves.size(); i++) {
1312     for (int j = 0; j < dest.size(); j++) {
1313     if (curves[i].Controller == dest[j].Controller) {
1314     dest[j].Curve = curves[i].Curve;
1315     }
1316     }
1317     }
1318     }
1319 iliev 2232
1320     void File::copySmoothValues(LinuxSampler::ArrayList<CC>& smooths, LinuxSampler::ArrayList<CC>& dest) {
1321     for (int i = 0; i < smooths.size(); i++) {
1322     for (int j = 0; j < dest.size(); j++) {
1323     if (smooths[i].Controller == dest[j].Controller) {
1324     dest[j].Smooth = smooths[i].Smooth;
1325     }
1326     }
1327     }
1328     }
1329 iliev 2237
1330 iliev 2264 void File::copyStepValues(LinuxSampler::ArrayList<CC>& steps, LinuxSampler::ArrayList<CC>& dest) {
1331     for (int i = 0; i < steps.size(); i++) {
1332     for (int j = 0; j < dest.size(); j++) {
1333     if (steps[i].Controller == dest[j].Controller) {
1334     dest[j].Step = steps[i].Step;
1335     }
1336     }
1337     }
1338     }
1339    
1340 iliev 2237 int File::ToInt(const std::string& s) throw(LinuxSampler::Exception) {
1341     int i;
1342     std::istringstream iss(s);
1343     if(!(iss >> i)) {
1344     std::ostringstream oss;
1345     oss << "Line " << currentLine << ": Expected an integer";
1346     throw LinuxSampler::Exception(oss.str());
1347     }
1348     return i;
1349     }
1350 iliev 2012
1351 iliev 2237 float File::ToFloat(const std::string& s) throw(LinuxSampler::Exception) {
1352     float i;
1353     std::istringstream iss(s);
1354     if(!(iss >> i)) {
1355     std::ostringstream oss;
1356     oss << "Line " << currentLine << ": Expected a floating-point number";
1357     throw LinuxSampler::Exception(oss.str());
1358     }
1359     return i;
1360     }
1361    
1362 iliev 2012 void
1363     File::push_header(std::string token)
1364     {
1365 persson 2856 if (token == "<global>" ||
1366     token == "<master>" ||
1367     token == "<group>")
1368 iliev 2012 {
1369 schoenebeck 3034 ContainerDefinition::section_type level = ContainerDefinition::GLOBAL; // initialized only to avoid an irrelevant compiler warning
1370    
1371 persson 2856 if (token == "<global>")
1372     {
1373     _current_section = GLOBAL;
1374     level = ContainerDefinition::GLOBAL;
1375     }
1376     else if (token == "<master>")
1377     {
1378     _current_section = MASTER;
1379     level = ContainerDefinition::MASTER;
1380     }
1381     else if (token == "<group>")
1382     {
1383     _current_section = GROUP;
1384     level = ContainerDefinition::GROUP;
1385     }
1386 schoenebeck 3034
1387 persson 2856 ContainerDefinition* newContainer = new ContainerDefinition(level);
1388    
1389     while (_current_containers.size() > 0 && _current_containers.top()->level <= level)
1390     {
1391     delete _current_containers.top();
1392     _current_containers.pop();
1393     }
1394    
1395     //If the new header is a <global>, there won't be anything left in _current_containers
1396     //to copy from.
1397     if (_current_containers.size() > 0)
1398     {
1399     _current_containers.top()->CopyValuesToDefinition(newContainer);
1400     }
1401     _current_containers.push(newContainer);
1402     pCurDef = newContainer;
1403 iliev 2012 }
1404     else if (token == "<region>")
1405     {
1406     _current_section = REGION;
1407 persson 2856 _current_region = new Region();
1408     _current_region->id = id++;
1409     _current_containers.top()->CopyValuesToDefinition(_current_region);
1410 persson 2055 pCurDef = _current_region;
1411 iliev 2012 _instrument->regions.push_back(_current_region);
1412 persson 2055 _current_region->SetInstrument(_instrument);
1413 iliev 2012 }
1414     else if (token == "<control>")
1415     {
1416     _current_section = CONTROL;
1417     default_path = "";
1418     octave_offset = 0;
1419     note_offset = 0;
1420     }
1421 iliev 2230 else if (token == "<curve>")
1422     {
1423     _current_section = CURVE;
1424     _instrument->curves.add(Curve());
1425     _current_curve = &_instrument->curves[_instrument->curves.size() - 1];
1426     }
1427 iliev 2012 else
1428     {
1429     _current_section = UNKNOWN;
1430     std::cerr << "The header '" << token << "' is unsupported by libsfz!" << std::endl;
1431     }
1432     }
1433    
1434     void
1435     File::push_opcode(std::string token)
1436     {
1437     if (_current_section == UNKNOWN)
1438     return;
1439    
1440     std::string::size_type delimiter_index = token.find('=');
1441     std::string key = token.substr(0, delimiter_index);
1442     std::string value = token.substr(delimiter_index + 1);
1443 iliev 2229 int x, y, z;
1444 iliev 2230
1445 persson 2856 // Apply macros
1446     size_t macro_start = 0;
1447     size_t macro_end = 0;
1448     std::string macro_value;
1449     while ((macro_start = value.find("$", macro_start + macro_value.size())) != std::string::npos)
1450     {
1451     macro_end = value.find_first_not_of(MACRO_NAME_CHARS, macro_start + 1);
1452     size_t macro_len = macro_end - macro_start;
1453     std::string macro_name = value.substr(macro_start, macro_len);
1454     if (_defined_macros.count(macro_name) != 0)
1455     {
1456     macro_value = _defined_macros[macro_name];
1457     value.replace(macro_start, macro_len, macro_value);
1458     }
1459     else
1460     {
1461     std::cerr << "Macro '" << macro_name << "' referenced on line ";
1462     std::cerr << currentLine << " is undefined." << std::endl;
1463     return;
1464     }
1465     }
1466    
1467 iliev 2230 if (_current_section == CURVE) {
1468     if (sscanf(key.c_str(), "v%d", &x)) {
1469     if (x < 0 || x > 127) {
1470     std::cerr << "Invalid curve index: " << x << std::endl;
1471     }
1472     _current_curve->v[x] = check(key, 0.0f, 1.0f, ToFloat(value));
1473     } else {
1474     std::cerr << "The opcode '" << key << "' in section <curve> is unsupported by libsfz!" << std::endl;
1475     }
1476    
1477     return;
1478     }
1479 iliev 2012
1480     // sample definition
1481     if ("sample" == key)
1482     {
1483 schoenebeck 3497 // handle built-in sample types ...
1484     if (value == "*silence") {
1485     pCurDef->sample = value;
1486     return;
1487     } else if (value.length() >= 1 && value[0] == '*') {
1488     std::cerr << "Unknown or unsupported built-in sample type '" << value << "'!" << std::endl;
1489     return;
1490     }
1491    
1492     // handle external samples ...
1493 iliev 2012 std::string path = default_path + value;
1494     #ifndef WIN32
1495 persson 2311 for (int i = 0; i < path.length(); i++) if (path[i] == '\\') path[i] = '/';
1496     bool absolute = path[0] == '/';
1497     #else
1498     bool absolute = path[0] == '/' || path[0] == '\\' ||
1499     (path.length() >= 2 && isalpha(path[0]) && path[1] == ':');
1500 iliev 2012 #endif
1501 persson 2311 if (!absolute) path = currentDir + LinuxSampler::File::DirSeparator + path;
1502 iliev 2012 if(pCurDef) pCurDef->sample = path;
1503     return;
1504     }
1505    
1506     // control header directives
1507     else if ("default_path" == key)
1508     {
1509     switch (_current_section)
1510     {
1511     case CONTROL:
1512     default_path = value;
1513 schoenebeck 3054 break;
1514     default:
1515     ; // noop
1516 iliev 2012 }
1517     return;
1518     }
1519     else if ("octave_offset" == key)
1520     {
1521     switch (_current_section)
1522     {
1523     case CONTROL:
1524     octave_offset = ToInt(value);
1525 schoenebeck 3054 break;
1526     default:
1527     ; // noop
1528 iliev 2012 }
1529     return;
1530     }
1531     else if ("note_offset" == key)
1532     {
1533     switch (_current_section)
1534     {
1535     case CONTROL:
1536     note_offset = ToInt(value);
1537 schoenebeck 3054 break;
1538     default:
1539     ; // noop
1540 iliev 2012 }
1541     return;
1542     }
1543    
1544     // input controls
1545     else if ("lochan" == key) pCurDef->lochan = ToInt(value);
1546     else if ("hichan" == key) pCurDef->hichan = ToInt(value);
1547 persson 2058 else if ("lokey" == key) pCurDef->lokey = parseKey(value);
1548     else if ("hikey" == key) pCurDef->hikey = parseKey(value);
1549 iliev 2012 else if ("key" == key)
1550     {
1551 persson 2058 pCurDef->lokey = pCurDef->hikey = pCurDef->pitch_keycenter = parseKey(value);
1552 iliev 2012 }
1553     else if ("lovel" == key) pCurDef->lovel = ToInt(value);
1554     else if ("hivel" == key) pCurDef->hivel = ToInt(value);
1555     else if ("lobend" == key) pCurDef->lobend = ToInt(value);
1556     else if ("hibend" == key) pCurDef->hibend = ToInt(value);
1557 persson 2106 else if ("lobpm" == key) pCurDef->lobpm = ToFloat(value);
1558     else if ("hibpm" == key) pCurDef->hibpm = ToFloat(value);
1559 iliev 2012 else if ("lochanaft" == key) pCurDef->lochanaft = ToInt(value);
1560     else if ("hichanaft" == key) pCurDef->hichanaft = ToInt(value);
1561     else if ("lopolyaft" == key) pCurDef->lopolyaft = ToInt(value);
1562     else if ("hipolyaft" == key) pCurDef->hipolyaft = ToInt(value);
1563     else if ("loprog" == key) pCurDef->loprog = ToInt(value);
1564     else if ("hiprog" == key) pCurDef->hiprog = ToInt(value);
1565     else if ("lorand" == key) pCurDef->lorand = ToFloat(value);
1566     else if ("hirand" == key) pCurDef->hirand = ToFloat(value);
1567     else if ("lotimer" == key) pCurDef->lotimer = ToFloat(value);
1568     else if ("hitimer" == key) pCurDef->hitimer = ToFloat(value);
1569     else if ("seq_length" == key) pCurDef->seq_length = ToInt(value);
1570     else if ("seq_position" == key) pCurDef->seq_position = ToInt(value);
1571 persson 2058 else if ("sw_lokey" == key) pCurDef->sw_lokey = parseKey(value);
1572     else if ("sw_hikey" == key) pCurDef->sw_hikey = parseKey(value);
1573     else if ("sw_last" == key) pCurDef->sw_last = parseKey(value);
1574     else if ("sw_down" == key) pCurDef->sw_down = parseKey(value);
1575     else if ("sw_up" == key) pCurDef->sw_up = parseKey(value);
1576     else if ("sw_previous" == key) pCurDef->sw_previous = parseKey(value);
1577 iliev 2012 else if ("sw_vel" == key)
1578     {
1579     if (value == "current") pCurDef->sw_vel = VEL_CURRENT;
1580     else if (value == "previous") pCurDef->sw_vel = VEL_PREVIOUS;
1581     }
1582     else if ("trigger" == key)
1583     {
1584     if (value == "attack") pCurDef->trigger = TRIGGER_ATTACK;
1585     else if (value == "release") pCurDef->trigger = TRIGGER_RELEASE;
1586     else if (value == "first") pCurDef->trigger = TRIGGER_FIRST;
1587     else if (value == "legato") pCurDef->trigger = TRIGGER_LEGATO;
1588     }
1589     else if ("group" == key) pCurDef->group = ToInt(value);
1590 persson 2058 else if ("off_by" == key || "offby" == key) pCurDef->off_by = ToInt(value);
1591     else if ("off_mode" == key || "offmode" == key)
1592 iliev 2012 {
1593 persson 2114 if (value == "fast") pCurDef->off_mode = OFF_FAST;
1594     else if (value == "normal") pCurDef->off_mode = OFF_NORMAL;
1595 iliev 2012 }
1596    
1597     // sample player
1598 iliev 2021 else if ("count" == key) { pCurDef->count = ToInt(value); pCurDef->loop_mode = ONE_SHOT; }
1599 iliev 2012 else if ("delay" == key) pCurDef->delay = ToFloat(value);
1600     else if ("delay_random" == key) pCurDef->delay_random = ToFloat(value);
1601     else if ("delay_beats" == key) pCurDef->delay_beats = ToInt(value);
1602     else if ("stop_beats" == key) pCurDef->stop_beats = ToInt(value);
1603     else if ("delay_samples" == key) pCurDef->delay_samples = ToInt(value);
1604     else if ("end" == key) pCurDef->end = ToInt(value);
1605     else if ("loop_crossfade" == key) pCurDef->loop_crossfade = ToFloat(value);
1606     else if ("offset_random" == key) pCurDef->offset_random = ToInt(value);
1607 persson 2058 else if ("loop_mode" == key || "loopmode" == key)
1608 iliev 2012 {
1609     if (value == "no_loop") pCurDef->loop_mode = NO_LOOP;
1610     else if (value == "one_shot") pCurDef->loop_mode = ONE_SHOT;
1611 iliev 2021 else if (value == "loop_continuous") pCurDef->loop_mode = LOOP_CONTINUOUS;
1612 iliev 2012 else if (value == "loop_sustain") pCurDef->loop_mode = LOOP_SUSTAIN;
1613     }
1614     else if ("loop_start" == key) pCurDef->loop_start = ToInt(value);
1615 iliev 2021 else if ("loopstart" == key) pCurDef->loop_start = ToInt(value); // nonstandard
1616 iliev 2012 else if ("loop_end" == key) pCurDef->loop_end = ToInt(value);
1617 iliev 2021 else if ("loopend" == key) pCurDef->loop_end = ToInt(value); // nonstandard
1618 iliev 2216 else if ("offset" == key) pCurDef->offset = ToInt(value);
1619 iliev 2012 else if ("sync_beats" == key) pCurDef->sync_beats = ToInt(value);
1620     else if ("sync_offset" == key) pCurDef->sync_offset = ToInt(value);
1621    
1622     // amplifier
1623     else if ("volume" == key) pCurDef->volume = ToFloat(value);
1624 persson 2403 else if ("amplitude" == key) pCurDef->amplitude = ToFloat(value);
1625 iliev 2012 else if ("pan" == key) pCurDef->pan = ToFloat(value);
1626     else if ("width" == key) pCurDef->width = ToFloat(value);
1627     else if ("position" == key) pCurDef->position = ToFloat(value);
1628     else if ("amp_keytrack" == key) pCurDef->amp_keytrack = ToFloat(value);
1629 persson 2058 else if ("amp_keycenter" == key) pCurDef->amp_keycenter = parseKey(value);
1630 iliev 2012 else if ("amp_veltrack" == key) pCurDef->amp_veltrack = ToFloat(value);
1631     else if ("amp_random" == key) pCurDef->amp_random = ToFloat(value);
1632 iliev 2229 else if ("rt_decay" == key || "rtdecay" == key) pCurDef->rt_decay = ToFloat(value);
1633 persson 2058 else if ("xfin_lokey" == key) pCurDef->xfin_lokey = parseKey(value);
1634     else if ("xfin_hikey" == key) pCurDef->xfin_hikey = parseKey(value);
1635     else if ("xfout_lokey" == key) pCurDef->xfout_lokey = parseKey(value);
1636     else if ("xfout_hikey" == key) pCurDef->xfout_hikey = parseKey(value);
1637 iliev 2012 else if ("xf_keycurve" == key)
1638     {
1639     if (value == "gain") pCurDef->xf_keycurve = GAIN;
1640     else if (value == "power") pCurDef->xf_keycurve = POWER;
1641     }
1642     else if ("xfin_lovel" == key) pCurDef->xfin_lovel = ToInt(value);
1643     else if ("xfin_hivel" == key) pCurDef->xfin_hivel = ToInt(value);
1644     else if ("xfout_lovel" == key) pCurDef->xfout_lovel = ToInt(value);
1645     else if ("xfout_hivel" == key) pCurDef->xfout_hivel = ToInt(value);
1646     else if ("xf_velcurve" == key)
1647     {
1648     if (value == "gain") pCurDef->xf_velcurve = GAIN;
1649     else if (value == "power") pCurDef->xf_velcurve = POWER;
1650     }
1651     else if ("xf_cccurve" == key)
1652     {
1653     if (value == "gain") pCurDef->xf_cccurve = GAIN;
1654     else if (value == "power") pCurDef->xf_cccurve = POWER;
1655     }
1656    
1657     // pitch
1658     else if ("transpose" == key) pCurDef->transpose = ToInt(value);
1659     else if ("tune" == key) pCurDef->tune = ToInt(value);
1660 persson 2058 else if ("pitch_keycenter" == key) pCurDef->pitch_keycenter = parseKey(value);
1661 iliev 2012 else if ("pitch_keytrack" == key) pCurDef->pitch_keytrack = ToInt(value);
1662     else if ("pitch_veltrack" == key) pCurDef->pitch_veltrack = ToInt(value);
1663     else if ("pitch_random" == key) pCurDef->pitch_random = ToInt(value);
1664 persson 2058 else if ("bend_up" == key || "bendup" == key) pCurDef->bend_up = ToInt(value);
1665     else if ("bend_down" == key || "benddown" == key) pCurDef->bend_down = ToInt(value);
1666 iliev 2229 else if ("bend_step" == key || "bendstep" == key) pCurDef->bend_step = ToInt(value);
1667 iliev 2012
1668     // filter
1669 persson 2086 else if ("fil_type" == key || "filtype" == key)
1670 iliev 2012 {
1671     if (value == "lpf_1p") pCurDef->fil_type = LPF_1P;
1672     else if (value == "hpf_1p") pCurDef->fil_type = HPF_1P;
1673     else if (value == "bpf_1p") pCurDef->fil_type = BPF_1P;
1674     else if (value == "brf_1p") pCurDef->fil_type = BRF_1P;
1675     else if (value == "apf_1p") pCurDef->fil_type = APF_1P;
1676     else if (value == "lpf_2p") pCurDef->fil_type = LPF_2P;
1677     else if (value == "hpf_2p") pCurDef->fil_type = HPF_2P;
1678     else if (value == "bpf_2p") pCurDef->fil_type = BPF_2P;
1679     else if (value == "brf_2p") pCurDef->fil_type = BRF_2P;
1680     else if (value == "pkf_2p") pCurDef->fil_type = PKF_2P;
1681     else if (value == "lpf_4p") pCurDef->fil_type = LPF_4P;
1682     else if (value == "hpf_4p") pCurDef->fil_type = HPF_4P;
1683     else if (value == "lpf_6p") pCurDef->fil_type = LPF_6P;
1684     else if (value == "hpf_6p") pCurDef->fil_type = HPF_6P;
1685     }
1686     else if ("fil2_type" == key)
1687     {
1688     if (value == "lpf_1p") pCurDef->fil2_type = LPF_1P;
1689     else if (value == "hpf_1p") pCurDef->fil2_type = HPF_1P;
1690     else if (value == "bpf_1p") pCurDef->fil2_type = BPF_1P;
1691     else if (value == "brf_1p") pCurDef->fil2_type = BRF_1P;
1692     else if (value == "apf_1p") pCurDef->fil2_type = APF_1P;
1693     else if (value == "lpf_2p") pCurDef->fil2_type = LPF_2P;
1694     else if (value == "hpf_2p") pCurDef->fil2_type = HPF_2P;
1695     else if (value == "bpf_2p") pCurDef->fil2_type = BPF_2P;
1696     else if (value == "brf_2p") pCurDef->fil2_type = BRF_2P;
1697     else if (value == "pkf_2p") pCurDef->fil2_type = PKF_2P;
1698     else if (value == "lpf_4p") pCurDef->fil2_type = LPF_4P;
1699     else if (value == "hpf_4p") pCurDef->fil2_type = HPF_4P;
1700     else if (value == "lpf_6p") pCurDef->fil2_type = LPF_6P;
1701     else if (value == "hpf_6p") pCurDef->fil2_type = HPF_6P;
1702     }
1703     else if ("cutoff" == key) pCurDef->cutoff = ToFloat(value);
1704     else if ("cutoff2" == key) pCurDef->cutoff2 = ToFloat(value);
1705 iliev 2252 else if ("cutoff_chanaft" == key) {
1706     pCurDef->cutoff_chanaft = check(key, -9600, 9600, ToInt(value));
1707     pCurDef->cutoff_oncc.add( CC(128, check(key, -9600, 9600, ToInt(value))) );
1708     } else if ("cutoff2_chanaft" == key) pCurDef->cutoff2_chanaft = ToInt(value);
1709 iliev 2012 else if ("cutoff_polyaft" == key) pCurDef->cutoff_polyaft = ToInt(value);
1710     else if ("cutoff2_polyaft" == key) pCurDef->cutoff2_polyaft = ToInt(value);
1711     else if ("resonance" == key) pCurDef->resonance = ToFloat(value);
1712     else if ("resonance2" == key) pCurDef->resonance2 = ToFloat(value);
1713     else if ("fil_keytrack" == key) pCurDef->fil_keytrack = ToInt(value);
1714     else if ("fil2_keytrack" == key) pCurDef->fil2_keytrack = ToInt(value);
1715 persson 2058 else if ("fil_keycenter" == key) pCurDef->fil_keycenter = parseKey(value);
1716     else if ("fil2_keycenter" == key) pCurDef->fil2_keycenter = parseKey(value);
1717 iliev 2012 else if ("fil_veltrack" == key) pCurDef->fil_veltrack = ToInt(value);
1718     else if ("fil2_veltrack" == key) pCurDef->fil2_veltrack = ToInt(value);
1719     else if ("fil_random" == key) pCurDef->fil_random = ToInt(value);
1720     else if ("fil2_random" == key) pCurDef->fil2_random = ToInt(value);
1721    
1722     // per voice equalizer
1723     else if ("eq1_freq" == key) pCurDef->eq1_freq = ToFloat(value);
1724     else if ("eq2_freq" == key) pCurDef->eq2_freq = ToFloat(value);
1725     else if ("eq3_freq" == key) pCurDef->eq3_freq = ToFloat(value);
1726     else if ("eq1_vel2freq" == key) pCurDef->eq1_vel2freq = ToFloat(value);
1727     else if ("eq2_vel2freq" == key) pCurDef->eq2_vel2freq = ToFloat(value);
1728     else if ("eq3_vel2freq" == key) pCurDef->eq3_vel2freq = ToFloat(value);
1729     else if ("eq1_bw" == key) pCurDef->eq1_bw = ToFloat(value);
1730     else if ("eq2_bw" == key) pCurDef->eq2_bw = ToFloat(value);
1731     else if ("eq3_bw" == key) pCurDef->eq3_bw = ToFloat(value);
1732     else if ("eq1_gain" == key) pCurDef->eq1_gain = ToFloat(value);
1733     else if ("eq2_gain" == key) pCurDef->eq2_gain = ToFloat(value);
1734     else if ("eq3_gain" == key) pCurDef->eq3_gain = ToFloat(value);
1735     else if ("eq1_vel2gain" == key) pCurDef->eq1_vel2gain = ToFloat(value);
1736     else if ("eq2_vel2gain" == key) pCurDef->eq2_vel2gain = ToFloat(value);
1737     else if ("eq3_vel2gain" == key) pCurDef->eq3_vel2gain = ToFloat(value);
1738    
1739 persson 2082 else if (sscanf(key.c_str(), "amp_velcurve_%d", &x)) {
1740 persson 2091 pCurDef->amp_velcurve.set(x, ToFloat(value));
1741 persson 2082 }
1742 iliev 2225
1743 persson 2055 // v2 envelope generators
1744     else if (sscanf(key.c_str(), "eg%d%n", &x, &y)) {
1745     const char* s = key.c_str() + y;
1746 iliev 2229 if (sscanf(s, "_time%d%n", &y, &z)) {
1747     const char* s2 = s + z;
1748     if (strcmp(s2, "") == 0) egnode(x, y).time = check(key, 0.0f, 100.0f, ToFloat(value));
1749     else if (sscanf(s2, "_oncc%d", &z)) egnode(x, y).time_oncc.add( CC(z, check(key, 0.0f, 100.0f, ToFloat(value))) );
1750     } else if (sscanf(s, "_level%d%n", &y, &z)) {
1751     const char* s2 = s + z;
1752     if (strcmp(s2, "") == 0) egnode(x, y).level = check(key, 0.0f, 1.0f, ToFloat(value));
1753     else if (sscanf(s2, "_oncc%d", &z)) egnode(x, y).level_oncc.add( CC(z, check(key, 0.0f, 1.0f, ToFloat(value))) );
1754     }
1755 persson 2055 else if (sscanf(s, "_shape%d", &y)) egnode(x, y).shape = ToFloat(value);
1756     else if (sscanf(s, "_curve%d", &y)) egnode(x, y).curve = ToFloat(value);
1757     else if (strcmp(s, "_sustain") == 0) eg(x).sustain = ToInt(value);
1758     else if (strcmp(s, "_loop") == 0) eg(x).loop = ToInt(value);
1759     else if (strcmp(s, "_loop_count") == 0) eg(x).loop_count = ToInt(value);
1760     else if (strcmp(s, "_amplitude") == 0) eg(x).amplitude = ToFloat(value);
1761 iliev 2235 else if (sscanf(s, "_amplitude_oncc%d", &y)) eg(x).amplitude_oncc.add( CC(y, check(key, 0.0f, 100.0f, ToFloat(value))) );
1762     else if (strcmp(s, "_volume") == 0) eg(x).volume = check(key, -144.0f, 6.0f, ToFloat(value));
1763     else if (sscanf(s, "_volume_oncc%d", &y)) eg(x).volume_oncc.add( CC(y, check(key, -144.0f, 6.0f, ToFloat(value))) );
1764 persson 2055 else if (strcmp(s, "_cutoff") == 0) eg(x).cutoff = ToFloat(value);
1765 iliev 2235 else if (sscanf(s, "_cutoff_oncc%d", &y)) eg(x).cutoff_oncc.add( CC(y, check(key, -9600, 9600, ToInt(value))) );
1766     else if (strcmp(s, "_pitch") == 0) eg(x).pitch = check(key, -9600, 9600, ToInt(value));
1767     else if (sscanf(s, "_pitch_oncc%d", &y)) eg(x).pitch_oncc.add( CC(y, check(key, -9600, 9600, ToInt(value))) );
1768     else if (strcmp(s, "_resonance") == 0) eg(x).resonance = check(key, 0.0f, 40.0f, ToFloat(value));
1769     else if (sscanf(s, "_resonance_oncc%d", &y)) eg(x).resonance_oncc.add( CC(y, check(key, 0.0f, 40.0f, ToFloat(value))) );
1770 iliev 2237 else if (strcmp(s, "_pan") == 0) eg(x).pan = check(key, -100.0f, 100.0f, ToFloat(value));
1771     else if (strcmp(s, "_pan_curve") == 0) eg(x).pan_curve = check(key, 0, 30000, ToInt(value));
1772     else if (sscanf(s, "_pan_oncc%d", &y)) eg(x).pan_oncc.add( CC(y, check(key, -100.0f, 100.0f, ToFloat(value))) );
1773     else if (sscanf(s, "_pan_curvecc%d", &y)) eg(x).pan_curvecc.add( CC(y, 0.0f, check(key, 0, 30000, ToInt(value))) );
1774 iliev 2299 else if (strcmp(s, "_eq1freq") == 0) eg(x).eq1freq = check(key, 0.0f, 30000.0f, ToFloat(value));
1775     else if (strcmp(s, "_eq2freq") == 0) eg(x).eq2freq = check(key, 0.0f, 30000.0f, ToFloat(value));
1776     else if (strcmp(s, "_eq3freq") == 0) eg(x).eq3freq = check(key, 0.0f, 30000.0f, ToFloat(value));
1777     else if (strcmp(s, "_eq1bw") == 0) eg(x).eq1bw = check(key, 0.001f, 4.0f, ToFloat(value));
1778     else if (strcmp(s, "_eq2bw") == 0) eg(x).eq2bw = check(key, 0.001f, 4.0f, ToFloat(value));
1779     else if (strcmp(s, "_eq3bw") == 0) eg(x).eq3bw = check(key, 0.001f, 4.0f, ToFloat(value));
1780     else if (strcmp(s, "_eq1gain") == 0) eg(x).eq1gain = check(key, -96.0f, 24.0f, ToFloat(value));
1781     else if (strcmp(s, "_eq2gain") == 0) eg(x).eq2gain = check(key, -96.0f, 24.0f, ToFloat(value));
1782     else if (strcmp(s, "_eq3gain") == 0) eg(x).eq3gain = check(key, -96.0f, 24.0f, ToFloat(value));
1783     else if (sscanf(s, "_eq1freq_oncc%d", &y)) eg(x).eq1freq_oncc.add( CC(y, check(key, 0.0f, 30000.0f, ToFloat(value))) );
1784     else if (sscanf(s, "_eq2freq_oncc%d", &y)) eg(x).eq2freq_oncc.add( CC(y, check(key, 0.0f, 30000.0f, ToFloat(value))) );
1785     else if (sscanf(s, "_eq3freq_oncc%d", &y)) eg(x).eq3freq_oncc.add( CC(y, check(key, 0.0f, 30000.0f, ToFloat(value))) );
1786     else if (sscanf(s, "_eq1bw_oncc%d", &y)) eg(x).eq1bw_oncc.add( CC(y, check(key, 0.001f, 4.0f, ToFloat(value))) );
1787     else if (sscanf(s, "_eq2bw_oncc%d", &y)) eg(x).eq2bw_oncc.add( CC(y, check(key, 0.001f, 4.0f, ToFloat(value))) );
1788     else if (sscanf(s, "_eq3bw_oncc%d", &y)) eg(x).eq3bw_oncc.add( CC(y, check(key, 0.001f, 4.0f, ToFloat(value))) );
1789     else if (sscanf(s, "_eq1gain_oncc%d", &y)) eg(x).eq1gain_oncc.add( CC(y, check(key, -96.0f, 24.0f, ToFloat(value))) );
1790     else if (sscanf(s, "_eq2gain_oncc%d", &y)) eg(x).eq2gain_oncc.add( CC(y, check(key, -96.0f, 24.0f, ToFloat(value))) );
1791     else if (sscanf(s, "_eq3gain_oncc%d", &y)) eg(x).eq3gain_oncc.add( CC(y, check(key, -96.0f, 24.0f, ToFloat(value))) );
1792 persson 2055 else std::cerr << "The opcode '" << key << "' is unsupported by libsfz!" << std::endl;
1793     }
1794    
1795     // v1 envelope generators
1796 iliev 2018 else if ("ampeg_delay" == key) pCurDef->ampeg_delay = ToFloat(value);
1797     else if ("ampeg_start" == key) pCurDef->ampeg_start = ToFloat(value);
1798     else if ("ampeg_attack" == key) pCurDef->ampeg_attack = ToFloat(value);
1799     else if ("ampeg_hold" == key) pCurDef->ampeg_hold = ToFloat(value);
1800     else if ("ampeg_decay" == key) pCurDef->ampeg_decay = ToFloat(value);
1801     else if ("ampeg_sustain" == key) pCurDef->ampeg_sustain = ToFloat(value);
1802 persson 2176 else if ("ampeg_release" == key) pCurDef->ampeg_release = ToFloat(value);
1803     else if ("ampeg_vel2delay" == key) pCurDef->ampeg_vel2delay = ToFloat(value);
1804     else if ("ampeg_vel2attack" == key) pCurDef->ampeg_vel2attack = ToFloat(value);
1805     else if ("ampeg_vel2hold" == key) pCurDef->ampeg_vel2hold = ToFloat(value);
1806     else if ("ampeg_vel2decay" == key) pCurDef->ampeg_vel2decay = ToFloat(value);
1807     else if ("ampeg_vel2sustain" == key) pCurDef->ampeg_vel2sustain = ToFloat(value);
1808     else if ("ampeg_vel2release" == key) pCurDef->ampeg_vel2release = ToFloat(value);
1809 iliev 2018 else if ("fileg_delay" == key) pCurDef->fileg_delay = ToFloat(value);
1810     else if ("fileg_start" == key) pCurDef->fileg_start = ToFloat(value);
1811     else if ("fileg_attack" == key) pCurDef->fileg_attack = ToFloat(value);
1812     else if ("fileg_hold" == key) pCurDef->fileg_hold = ToFloat(value);
1813     else if ("fileg_decay" == key) pCurDef->fileg_decay = ToFloat(value);
1814     else if ("fileg_sustain" == key) pCurDef->fileg_sustain = ToFloat(value);
1815     else if ("fileg_release" == key) pCurDef->fileg_release = ToFloat(value);
1816 iliev 2222 else if ("fileg_depth" == key) pCurDef->fileg_depth = check(key, -12000, 12000, ToInt(value));
1817     else if ("fileg_vel2delay" == key) pCurDef->fileg_vel2delay = check(key, -100.0f, 100.0f, ToFloat(value));
1818     else if ("fileg_vel2attack" == key) pCurDef->fileg_vel2attack = ToFloat(value);
1819     else if ("fileg_vel2hold" == key) pCurDef->fileg_vel2hold = ToFloat(value);
1820     else if ("fileg_vel2decay" == key) pCurDef->fileg_vel2decay = ToFloat(value);
1821     else if ("fileg_vel2sustain" == key) pCurDef->fileg_vel2sustain = ToFloat(value);
1822     else if ("fileg_vel2release" == key) pCurDef->fileg_vel2release = ToFloat(value);
1823 iliev 2018 else if ("pitcheg_delay" == key) pCurDef->pitcheg_delay = ToFloat(value);
1824     else if ("pitcheg_start" == key) pCurDef->pitcheg_start = ToFloat(value);
1825 iliev 2220 else if ("pitcheg_attack" == key) pCurDef->pitcheg_attack = ToFloat(value);
1826     else if ("pitcheg_hold" == key) pCurDef->pitcheg_hold = ToFloat(value);
1827 iliev 2018 else if ("pitcheg_decay" == key) pCurDef->pitcheg_decay = ToFloat(value);
1828 iliev 2220 else if ("pitcheg_sustain" == key) pCurDef->pitcheg_sustain = ToFloat(value);
1829     else if ("pitcheg_release" == key) pCurDef->pitcheg_release = ToFloat(value);
1830     else if ("pitcheg_depth" == key) pCurDef->pitcheg_depth = check(key, -12000, 12000, ToInt(value));
1831     else if ("pitcheg_vel2delay" == key) pCurDef->pitcheg_vel2delay = check(key, -100.0f, 100.0f, ToFloat(value));
1832     else if ("pitcheg_vel2attack" == key) pCurDef->pitcheg_vel2attack = ToFloat(value);
1833     else if ("pitcheg_vel2hold" == key) pCurDef->pitcheg_vel2hold = ToFloat(value);
1834     else if ("pitcheg_vel2decay" == key) pCurDef->pitcheg_vel2decay = ToFloat(value);
1835     else if ("pitcheg_vel2sustain" == key) pCurDef->pitcheg_vel2sustain = ToFloat(value);
1836     else if ("pitcheg_vel2release" == key) pCurDef->pitcheg_vel2release = ToFloat(value);
1837    
1838 persson 2072
1839     // v1 LFO
1840     else if ("amplfo_delay" == key) pCurDef->amplfo_delay = ToFloat(value);
1841     else if ("amplfo_fade" == key) pCurDef->amplfo_fade = ToFloat(value);
1842     else if ("amplfo_freq" == key) pCurDef->amplfo_freq = ToFloat(value);
1843 iliev 2253 else if ("amplfo_freqchanaft" == key) pCurDef->amplfo_freqcc.add( CC(128, check(key, -200.0f, 200.0f, ToFloat(value))) );
1844 persson 2072 else if ("amplfo_depth" == key) pCurDef->amplfo_depth = ToFloat(value);
1845 iliev 2253 else if ("amplfo_depthchanaft" == key) pCurDef->amplfo_depthcc.add( CC(128, check(key, -10.0f, 10.0f, ToFloat(value))) );
1846 persson 2072 else if ("fillfo_delay" == key) pCurDef->fillfo_delay = ToFloat(value);
1847     else if ("fillfo_fade" == key) pCurDef->fillfo_fade = ToFloat(value);
1848     else if ("fillfo_freq" == key) pCurDef->fillfo_freq = ToFloat(value);
1849 iliev 2253 else if ("fillfo_freqchanaft" == key) pCurDef->fillfo_freqcc.add( CC(128, check(key, -200.0f, 200.0f, ToFloat(value))) );
1850 persson 2072 else if ("fillfo_depth" == key) pCurDef->fillfo_depth = ToFloat(value);
1851 iliev 2253 else if ("fillfo_depthchanaft" == key) pCurDef->fillfo_depthcc.add( CC(128, check(key, -1200, 1200, ToInt(value))) );
1852 persson 2072 else if ("pitchlfo_delay" == key) pCurDef->pitchlfo_delay = ToFloat(value);
1853     else if ("pitchlfo_fade" == key) pCurDef->pitchlfo_fade = ToFloat(value);
1854     else if ("pitchlfo_freq" == key) pCurDef->pitchlfo_freq = ToFloat(value);
1855 iliev 2253 else if ("pitchlfo_freqchanaft" == key) pCurDef->pitchlfo_freqcc.add( CC(128, check(key, -200.0f, 200.0f, ToFloat(value))) );
1856 persson 2072 else if ("pitchlfo_depth" == key) pCurDef->pitchlfo_depth = ToInt(value);
1857 iliev 2253 else if ("pitchlfo_depthchanaft" == key) pCurDef->pitchlfo_depthcc.add( CC(128, check(key, -1200, 1200, ToInt(value))) );
1858 iliev 2218
1859 iliev 2253
1860 iliev 2218 // v2 LFO
1861     else if (sscanf(key.c_str(), "lfo%d%n", &x, &y)) {
1862     const char* s = key.c_str() + y;
1863     if (strcmp(s, "_freq") == 0) lfo(x).freq = check(key, 0.0f, 20.0f, ToFloat(value));
1864 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))) );
1865 iliev 2233 else if (sscanf(s, "_freq_smoothcc%d", &y)) lfo(x).freq_smoothcc.add( CC(y, 0, -1, check(key, 0, 100000 /* max? */, ToInt(value))) );
1866 iliev 2265 else if (sscanf(s, "_freq_stepcc%d", &y)) lfo(x).freq_stepcc.add( CC(y, 0, -1, 0, check(key, 0.0f, 20.0f, ToFloat(value))) );
1867 iliev 2218 else if (strcmp(s, "_wave") == 0) lfo(x).wave = ToInt(value);
1868     else if (strcmp(s, "_delay") == 0) lfo(x).delay = check(key, 0.0f, 100.0f, ToFloat(value));
1869 iliev 2233 else if (sscanf(s, "_delay_oncc%d", &y)) lfo(x).delay_oncc.add( CC(y, check(key, 0.0f, 100.0f, ToFloat(value))) );
1870 iliev 2226 else if (strcmp(s, "_fade") == 0) lfo(x).fade = check(key, 0.0f, 100.0f, ToFloat(value));
1871     else if (sscanf(s, "_fade_oncc%d", &y)) lfo(x).fade_oncc.add( CC(y, check(key, 0.0f, 100.0f, ToFloat(value))) );
1872 iliev 2225 else if (strcmp(s, "_phase") == 0) lfo(x).phase = check(key, 0.0f, 360.0f, ToFloat(value));
1873     else if (sscanf(s, "_phase_oncc%d", &y)) lfo(x).phase_oncc.add( CC(y, check(key, 0.0f, 360.0f, ToFloat(value))) );
1874 iliev 2221 else if (strcmp(s, "_volume") == 0) lfo(x).volume = check(key, -144.0f, 6.0f, ToFloat(value));
1875 iliev 2233 else if (sscanf(s, "_volume_oncc%d", &y)) lfo(x).volume_oncc.add( CC(y, check(key, -144.0f, 6.0f, ToFloat(value))) );
1876     else if (sscanf(s, "_volume_smoothcc%d", &y)) lfo(x).volume_smoothcc.add( CC(y, 0, -1, check(key, 0, 100000 /* max? */, ToInt(value))) );
1877 iliev 2265 else if (sscanf(s, "_volume_stepcc%d", &y)) lfo(x).volume_stepcc.add( CC(y, 0, -1, 0, check(key, -20.0f, 20.0f, ToFloat(value))) );
1878 iliev 2218 else if (strcmp(s, "_pitch") == 0) lfo(x).pitch = check(key, -9600, 9600, ToInt(value));
1879 iliev 2225 else if (sscanf(s, "_pitch_oncc%d", &y)) lfo(x).pitch_oncc.add( CC(y, check(key, -9600, 9600, ToInt(value))) );
1880 iliev 2233 else if (sscanf(s, "_pitch_smoothcc%d", &y)) lfo(x).pitch_smoothcc.add( CC(y, 0, -1, check(key, 0, 100000 /* max? */, ToInt(value))) );
1881 iliev 2265 else if (sscanf(s, "_pitch_stepcc%d", &y)) lfo(x).pitch_stepcc.add( CC(y, 0, -1, 0, check(key, -9600, 9600, ToInt(value))) );
1882 iliev 2218 else if (strcmp(s, "_cutoff") == 0) lfo(x).cutoff = check(key, -9600, 9600, ToInt(value));
1883 iliev 2233 else if (sscanf(s, "_cutoff_oncc%d", &y)) lfo(x).cutoff_oncc.add( CC(y, check(key, -9600, 9600, ToInt(value))) );
1884     else if (sscanf(s, "_cutoff_smoothcc%d", &y)) lfo(x).cutoff_smoothcc.add( CC(y, 0, -1, check(key, 0, 100000 /* max? */, ToInt(value))) );
1885 iliev 2265 else if (sscanf(s, "_cutoff_stepcc%d", &y)) lfo(x).cutoff_stepcc.add( CC(y, 0, -1, 0, check(key, -9600, 9600, ToInt(value))) );
1886 iliev 2218 else if (strcmp(s, "_resonance") == 0) lfo(x).resonance = check(key, 0.0f, 40.0f, ToFloat(value));
1887 iliev 2233 else if (sscanf(s, "_resonance_oncc%d", &y)) lfo(x).resonance_oncc.add( CC(y, check(key, 0.0f, 40.0f, ToFloat(value))) );
1888     else if (sscanf(s, "_resonance_smoothcc%d", &y)) lfo(x).resonance_smoothcc.add( CC(y, 0, -1, check(key, 0, 100000 /* max? */, ToInt(value))) );
1889 iliev 2265 else if (sscanf(s, "_resonance_stepcc%d", &y)) lfo(x).resonance_stepcc.add( CC(y, 0, -1, 0, check(key, 0.0f, 40.0f, ToFloat(value))) );
1890 iliev 2218 else if (strcmp(s, "_pan") == 0) lfo(x).pan = check(key, -100.0f, 100.0f, ToFloat(value));
1891 iliev 2233 else if (sscanf(s, "_pan_oncc%d", &y)) lfo(x).pan_oncc.add( CC(y, check(key, -100.0f, 100.0f, ToFloat(value))) );
1892     else if (sscanf(s, "_pan_smoothcc%d", &y)) lfo(x).pan_smoothcc.add( CC(y, 0, -1, check(key, 0, 100000 /* max? */, ToInt(value))) );
1893 iliev 2265 else if (sscanf(s, "_pan_stepcc%d", &y)) lfo(x).pan_stepcc.add( CC(y, 0, -1, 0, check(key, -100.0f, 100.0f, ToFloat(value))) );
1894 iliev 2299 else if (strcmp(s, "_eq1freq") == 0) lfo(x).eq1freq = check(key, 0.0f, 30000.0f, ToFloat(value));
1895     else if (strcmp(s, "_eq2freq") == 0) lfo(x).eq2freq = check(key, 0.0f, 30000.0f, ToFloat(value));
1896     else if (strcmp(s, "_eq3freq") == 0) lfo(x).eq3freq = check(key, 0.0f, 30000.0f, ToFloat(value));
1897     else if (strcmp(s, "_eq1bw") == 0) lfo(x).eq1bw = check(key, 0.001f, 4.0f, ToFloat(value));
1898     else if (strcmp(s, "_eq2bw") == 0) lfo(x).eq2bw = check(key, 0.001f, 4.0f, ToFloat(value));
1899     else if (strcmp(s, "_eq3bw") == 0) lfo(x).eq3bw = check(key, 0.001f, 4.0f, ToFloat(value));
1900     else if (strcmp(s, "_eq1gain") == 0) lfo(x).eq1gain = check(key, -96.0f, 24.0f, ToFloat(value));
1901     else if (strcmp(s, "_eq2gain") == 0) lfo(x).eq2gain = check(key, -96.0f, 24.0f, ToFloat(value));
1902     else if (strcmp(s, "_eq3gain") == 0) lfo(x).eq3gain = check(key, -96.0f, 24.0f, ToFloat(value));
1903     else if (sscanf(s, "_eq1freq_oncc%d", &y)) lfo(x).eq1freq_oncc.add( CC(y, check(key, 0.0f, 30000.0f, ToFloat(value))) );
1904     else if (sscanf(s, "_eq1freq_smoothcc%d", &y)) lfo(x).eq1freq_smoothcc.add( CC(y, 0, -1, check(key, 0, 100000 /* max? */, ToInt(value))) );
1905     else if (sscanf(s, "_eq1freq_stepcc%d", &y)) lfo(x).eq1freq_stepcc.add( CC(y, 0, -1, 0, check(key, 0.0f, 4294967296.0f, ToFloat(value))) );
1906     else if (sscanf(s, "_eq2freq_oncc%d", &y)) lfo(x).eq2freq_oncc.add( CC(y, check(key, 0.0f, 30000.0f, ToFloat(value))) );
1907     else if (sscanf(s, "_eq2freq_smoothcc%d", &y)) lfo(x).eq2freq_smoothcc.add( CC(y, 0, -1, check(key, 0, 100000 /* max? */, ToInt(value))) );
1908     else if (sscanf(s, "_eq2freq_stepcc%d", &y)) lfo(x).eq2freq_stepcc.add( CC(y, 0, -1, 0, check(key, 0.0f, 4294967296.0f, ToFloat(value))) );
1909     else if (sscanf(s, "_eq3freq_oncc%d", &y)) lfo(x).eq3freq_oncc.add( CC(y, check(key, 0.0f, 30000.0f, ToFloat(value))) );
1910     else if (sscanf(s, "_eq3freq_smoothcc%d", &y)) lfo(x).eq3freq_smoothcc.add( CC(y, 0, -1, check(key, 0, 100000 /* max? */, ToInt(value))) );
1911     else if (sscanf(s, "_eq3freq_stepcc%d", &y)) lfo(x).eq3freq_stepcc.add( CC(y, 0, -1, 0, check(key, 0.0f, 4294967296.0f, ToFloat(value))) );
1912     else if (sscanf(s, "_eq1bw_oncc%d", &y)) lfo(x).eq1bw_oncc.add( CC(y, check(key, 0.001f, 4.0f, ToFloat(value))) );
1913     else if (sscanf(s, "_eq1bw_smoothcc%d", &y)) lfo(x).eq1bw_smoothcc.add( CC(y, 0, -1, check(key, 0, 100000 /* max? */, ToInt(value))) );
1914     else if (sscanf(s, "_eq1bw_stepcc%d", &y)) lfo(x).eq1bw_stepcc.add( CC(y, 0, -1, 0, check(key, 0.0f, 4294967296.0f, ToFloat(value))) );
1915     else if (sscanf(s, "_eq2bw_oncc%d", &y)) lfo(x).eq2bw_oncc.add( CC(y, check(key, 0.001f, 4.0f, ToFloat(value))) );
1916     else if (sscanf(s, "_eq2bw_smoothcc%d", &y)) lfo(x).eq2bw_smoothcc.add( CC(y