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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2018 by iliev, Tue Oct 27 19:04:57 2009 UTC revision 3095 by schoenebeck, Wed Jan 18 14:52:31 2017 UTC
# Line 2  Line 2 
2   *                                                                         *   *                                                                         *
3   *   LinuxSampler - modular, streaming capable sampler                     *   *   LinuxSampler - modular, streaming capable sampler                     *
4   *                                                                         *   *                                                                         *
5   *   Copyright (C) 2008-2009 Anders Dahnielson <anders@dahnielson.com>     *   *   Copyright (C) 2008 Anders Dahnielson <anders@dahnielson.com>          *
6   *   Copyright (C) 2009 Grigor Iliev                                       *   *   Copyright (C) 2009 - 2016 Anders Dahnielson and Grigor Iliev          *
7   *                                                                         *   *                                                                         *
8   *   This program is free software; you can redistribute it and/or modify  *   *   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  *   *   it under the terms of the GNU General Public License as published by  *
# Line 25  Line 25 
25    
26  #include <iostream>  #include <iostream>
27  #include <sstream>  #include <sstream>
28    #include <cctype>
29    #include <cstdio>
30    #include <cstring>
31    
32  #include "../../common/File.h"  #include "../../common/File.h"
33  #include "../../common/Path.h"  #include "../../common/Path.h"
34    #include "LookupTable.h"
35  #include "../../common/global_private.h"  #include "../../common/global_private.h"
36    
37  namespace sfz  namespace sfz
38  {  {
39        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    
54      LinuxSampler::SampleFile* SampleManager::FindSample(std::string samplePath) {      Sample* SampleManager::FindSample(std::string samplePath, uint offset, int end) {
55          std::map<LinuxSampler::SampleFile*, std::set<Region*> >::iterator it = sampleMap.begin();          std::map<Sample*, std::set<Region*> >::iterator it = sampleMap.begin();
56          for (; it != sampleMap.end(); it++) {          for (; it != sampleMap.end(); it++) {
57              if (it->first->GetFile() == samplePath) return it->first;              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                    if (it->first->Offset == offset && it->first->End == end) return it->first;
63                }
64          }          }
65    
66          return NULL;          return NULL;
67      }      }
68    
69      /////////////////////////////////////////////////////////////      /////////////////////////////////////////////////////////////
70      // class optional      // class Script
71    
72        Script::Script(LinuxSampler::Path path) : m_path(path) {
73        }
74    
75        Script::Script(String path) : m_path(LinuxSampler::Path::fromUnknownFS(path)) {
76        }
77    
78      const optional_base::nothing_t optional_base::nothing;      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      /////////////////////////////////////////////////////////////      /////////////////////////////////////////////////////////////
103      // class Articulation      // class Articulation
# Line 61  namespace sfz Line 113  namespace sfz
113      /////////////////////////////////////////////////////////////      /////////////////////////////////////////////////////////////
114      // class Definition      // class Definition
115    
116      Definition::Definition() :      Definition::Definition()
         locc(128), hicc(128), start_locc(128), start_hicc(128), stop_locc(128),  
         stop_hicc(128), on_locc(128), on_hicc(128), delay_oncc(128), delay_samples_oncc(128),  
         offset_oncc(128), amp_velcurve_(128), gain_oncc(128), xfin_locc(128), xfin_hicc(128),  
         xfout_locc(128), xfout_hicc(128), cutoff_oncc(128), cutoff2_oncc(128), cutoff_smoothcc(128),  
         cutoff2_smoothcc(128), cutoff_stepcc(128), cutoff2_stepcc(128), cutoff_curvecc(128),  
         cutoff2_curvecc(128), resonance_oncc(128), resonance2_oncc(128), resonance_smoothcc(128),  
         resonance2_smoothcc(128), resonance_stepcc(128), resonance2_stepcc(128),  
         resonance_curvecc(128), resonance2_curvecc(128), eq1_freq_oncc(128), eq2_freq_oncc(128),  
         eq3_freq_oncc(128), eq1_bw_oncc(128), eq2_bw_oncc(128), eq3_bw_oncc(128),  
         eq1_gain_oncc(128), eq2_gain_oncc(128), eq3_gain_oncc(128)  
   
117      {      {
118      }      }
119    
# Line 86  namespace sfz Line 127  namespace sfz
127      Region::Region()      Region::Region()
128      {      {
129          pSample = NULL;          pSample = NULL;
130            seq_counter = 1;
131      }      }
132    
133      Region::~Region()      Region::~Region()
# Line 93  namespace sfz Line 135  namespace sfz
135          DestroySampleIfNotUsed();          DestroySampleIfNotUsed();
136      }      }
137    
138      LinuxSampler::SampleFile* Region::GetSample(bool create)      Sample* Region::GetSample(bool create)
139      {      {
140          if(pSample == NULL && create) {          if (pSample == NULL && create) {
141              LinuxSampler::SampleFile* sf = GetInstrument()->GetSampleManager()->FindSample(sample);              uint i = offset ? *offset : 0;
142                Sample* sf = GetInstrument()->GetSampleManager()->FindSample(sample, i, end);
143              if (sf != NULL) pSample = sf; // Reuse already created sample              if (sf != NULL) pSample = sf; // Reuse already created sample
144              else pSample = new LinuxSampler::SampleFile(sample);              else pSample = new Sample(sample, false, i, end);
145              GetInstrument()->GetSampleManager()->AddSampleConsumer(pSample, this);              GetInstrument()->GetSampleManager()->AddSampleConsumer(pSample, this);
146          }          }
147          return pSample;          return pSample;
# Line 114  namespace sfz Line 157  namespace sfz
157          }          }
158      }      }
159    
160      bool      bool Region::OnKey(const Query& q) {
161      Region::OnKey(uint8_t chan, uint8_t key, uint8_t vel,          // As the region comes from a LookupTable search on the query,
162                int bend, uint8_t bpm, uint8_t chanaft, uint8_t polyaft,          // the following parameters are not checked here: chan, key,
163                uint8_t prog, float rand, trigger_t trig, uint8_t* cc,          // vel, chanaft, polyaft, prog, sw_previous, cc. They are all
164                float timer, uint8_t seq, bool* sw, uint8_t last_sw_key, uint8_t prev_sw_key)          // handled by the lookup table.
165      {          bool is_triggered(
166          // chan        (MIDI channel)              q.bend    >= lobend     &&  q.bend    <= hibend     &&
167          // key         (MIDI note)              q.bpm     >= lobpm      &&  q.bpm     <  hibpm      &&
168          // vel         (MIDI velocity)              q.rand    >= lorand     &&  q.rand    <  hirand     &&
169                q.timer   >= lotimer    &&  q.timer   <= hitimer    &&
170          // bend        (MIDI pitch bend)  
171          // bpm         (host BPM)              ( sw_last == -1 ||
172          // chanaft     (MIDI channel pressure)                ((sw_last >= sw_lokey && sw_last <= sw_hikey) ? (q.last_sw_key == sw_last) : false) ) &&
         // polyaft     (MIDI polyphonic aftertouch)  
         // prog        (MIDI program change)  
         // rand        (generated random number)  
         // trigger     (how it was triggered)  
         // cc          (all 128 CC values)  
   
         // timer       (time since previous region in the group was triggered)  
         // seq         (the state of the region sequence counter)  
         // sw          (the state of region key switches, 128 possible values)  
         // last_sw_key (the last key pressed in the key switch range)  
         // prev_sw_key (the previous note value)  
   
         bool is_triggered (  
             chan    >= lochan     &&  chan    <= hichan     &&  
             key     >= lokey      &&  key     <= hikey      &&  
             vel     >= lovel      &&  vel     <= hivel      &&  
             bend    >= lobend     &&  bend    <= hibend     &&  
             bpm     >= lobpm      &&  bpm     <= hibpm      &&  
             chanaft >= lochanaft  &&  chanaft <= hichanaft  &&  
             polyaft >= lopolyaft  &&  polyaft <= hipolyaft  &&  
             prog    >= loprog     &&  prog    <= hiprog     &&  
             rand    >= lorand     &&  rand    <= hirand     &&  
             timer   >= lotimer    &&  timer   <= hitimer    &&  
             seq == seq_position   &&  
   
             ( (sw_lokey == -1 || sw_hikey == -1 || sw_last  == -1) ||  
               ((sw_last >= sw_lokey && sw_last <= sw_hikey) ? (last_sw_key == sw_last) : true) ) &&  
173    
174              ( (sw_down  == -1 || sw_lokey == -1 || sw_hikey == -1) ||              ( sw_down == -1 ||
175                ((sw_down >= sw_lokey && sw_down <= sw_hikey) ? (sw[sw_down]) : true) )  &&                ((sw_down >= sw_lokey && (sw_hikey == -1 || sw_down <= sw_hikey)) ? (q.sw[sw_down]) : false) )  &&
176    
177              ( (sw_up    == -1 || sw_lokey == -1 || sw_hikey == -1) ||              ( sw_up   == -1 ||
178                ((sw_up   >= sw_lokey && sw_up   <= sw_hikey) ? (!sw[sw_up])  : true) )  &&                ((sw_up   >= sw_lokey && (sw_hikey == -1 || sw_up   <= sw_hikey)) ? (!q.sw[sw_up]) : true) )  &&
179    
180              ((sw_previous != -1) ? (prev_sw_key == sw_previous) : true)  &&              ((trigger & q.trig) != 0)
              ((trigger && trig) != 0)  
181          );          );
182    
183          if (!is_triggered)          if (!is_triggered)
184              return false;              return false;
185    
186          for (int i = 0; i < 128; ++i)          // seq_position has to be checked last, so we know that we
187          {          // increment the right counter
188              if (locc[i] != -1 && hicc[i] != -1 && !(cc[i] >= locc[i] && cc[i] <= hicc[i]))          is_triggered = (seq_counter == seq_position);
189                  return false;          seq_counter = (seq_counter % seq_length) + 1;
         }  
190    
191          return true;          return is_triggered;
192      }      }
193    
194      bool      Articulation*
195      Region::OnControl(uint8_t chan, uint8_t cont, uint8_t val,      Region::GetArticulation(int bend, uint8_t bpm, uint8_t chanaft, uint8_t polyaft, uint8_t* cc)
         int bend, uint8_t bpm, uint8_t chanaft, uint8_t polyaft,  
         uint8_t prog, float rand, trigger_t trig, uint8_t* cc,  
         float timer, uint8_t seq, bool* sw, uint8_t last_sw_key, uint8_t prev_sw_key)  
196      {      {
197          // chan      (MIDI channel)          return new Articulation(); //todo: implement GetArticulation()
198          // cont      (MIDI controller)      }
         // val       (MIDI controller value)  
   
         // bend      (MIDI pitch bend)  
         // bpm       (host BPM)  
         // chanaft   (MIDI channel pressure)  
         // polyaft   (MIDI polyphonic aftertouch)  
         // prog      (MIDI program change)  
         // rand      (generated random number)  
         // trigger   (how it was triggered)  
         // cc        (all CC values)  
   
         // timer       (time since previous region in the group was triggered)  
         // seq         (the state of the region sequence counter)  
         // sw          (the state of region key switches, 128 possible values)  
         // last_sw_key (the last key pressed in the key switch range)  
         // prev_sw_key (the previous note value)  
   
         bool is_triggered = (  
             chan    >= lochan           &&  chan    <= hichan             &&  
             ((val   >= on_locc[cont]    &&  val     <= on_hicc[cont])     ||  
              (val   >= start_locc[cont] &&  val     <= start_hicc[cont])) &&  
             bend    >= lobend           &&  bend    <= hibend             &&  
             bpm     >= lobpm            &&  bpm     <= hibpm              &&  
             chanaft >= lochanaft        &&  chanaft <= hichanaft          &&  
             polyaft >= lopolyaft        &&  polyaft <= hipolyaft          &&  
             prog    >= loprog           &&  prog    <= hiprog             &&  
             rand    >= lorand           &&  rand    <= hirand             &&  
             timer   >= lotimer          &&  timer   <= hitimer            &&  
             seq == seq_position   &&  
   
             ( (sw_lokey == -1 || sw_hikey == -1 || sw_last  == -1) ||  
               ((sw_last >= sw_lokey && sw_last <= sw_hikey) ? (last_sw_key == sw_last) : true) ) &&  
   
             ( (sw_down  == -1 || sw_lokey == -1 || sw_hikey == -1) ||  
               ((sw_down >= sw_lokey && sw_down <= sw_hikey) ? (sw[sw_down]) : true) )  &&  
   
             ( (sw_up    == -1 || sw_lokey == -1 || sw_hikey == -1) ||  
               ((sw_up   >= sw_lokey && sw_up   <= sw_hikey) ? (!sw[sw_up])  : true) )  &&  
   
             ((sw_previous != -1) ? (prev_sw_key == sw_previous) : true)  &&  
              ((trigger && trig) != 0)  
         );  
199    
200          if (!is_triggered)      bool Region::HasLoop() {
201              return false;          bool b = loop_mode == LOOP_UNSET ? pSample->GetLoops() :
202                (loop_mode == LOOP_CONTINUOUS || loop_mode == LOOP_SUSTAIN);
203            return b && GetLoopEnd() > GetLoopStart();
204        }
205    
206          for (int i = 0; i < 128; ++i)      uint Region::GetLoopStart() {
207          {          return (!loop_start) ? pSample->GetLoopStart() : *loop_start;
208              if (locc[i] != -1 && hicc[i] != -1 && !(cc[i] >= locc[i] && cc[i] <= hicc[i]))      }
                 return false;  
         }  
209    
210          return true;      uint Region::GetLoopEnd() {
211            return (!loop_end) ? pSample->GetLoopEnd() : *loop_end;
212      }      }
213    
214      Articulation*      uint Region::GetLoopCount() {
215      Region::GetArticulation(int bend, uint8_t bpm, uint8_t chanaft, uint8_t polyaft, uint8_t* cc)          return (!count) ? 0 : *count;
     {  
         return new Articulation(); //todo: implement GetArticulation()  
216      }      }
217    
218      /////////////////////////////////////////////////////////////      /////////////////////////////////////////////////////////////
# Line 253  namespace sfz Line 222  namespace sfz
222      {      {
223          this->name = name;          this->name = name;
224          this->pSampleManager = pSampleManager ? pSampleManager : this;          this->pSampleManager = pSampleManager ? pSampleManager : this;
225            pLookupTable = 0;
226            
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      }      }
234    
235      Instrument::~Instrument()      Instrument::~Instrument()
236      {      {
237          for(int i = 0; i < regions.size(); i++) {          for (int i = 0; i < regions.size(); i++) {
238              delete (regions[i]);              delete regions[i];
239            }
240            delete pLookupTable;
241            for (int i = 0 ; i < 128 ; i++) {
242                delete pLookupTableCC[i];
243          }          }
         regions.clear();  
244      }      }
245    
246      std::vector<Region*> Instrument::GetRegionsOnKey (      void Query::search(const Instrument* pInstrument) {
247          uint8_t chan, uint8_t key, uint8_t vel,          pRegionList = &pInstrument->pLookupTable->query(*this);
248          int bend, uint8_t bpm, uint8_t chanaft, uint8_t polyaft,          regionIndex = 0;
249          uint8_t prog, float rand, trigger_t trig, uint8_t* cc,      }
         float timer, uint8_t seq, bool* sw, uint8_t last_sw_key, uint8_t prev_sw_key  
     ) {  
         std::vector<Region*> v;  
         for (int i = 0; i < regions.size(); i++) {  
             if (regions[i]->OnKey (  
                 chan, key, vel, bend, bpm, chanaft, polyaft, prog,  
                 rand, trig, cc, timer, seq, sw, last_sw_key, prev_sw_key)  
                     ) { v.push_back(regions[i]); }  
         }  
250    
251          return v;      void Query::search(const Instrument* pInstrument, int triggercc) {
252            pRegionList = &pInstrument->pLookupTableCC[triggercc]->query(*this);
253            regionIndex = 0;
254        }
255    
256        Region* Query::next() {
257            for ( ; regionIndex < pRegionList->size() ; regionIndex++) {
258                if ((*pRegionList)[regionIndex]->OnKey(*this)) {
259                    return (*pRegionList)[regionIndex++];
260                }
261            }
262            return 0;
263      }      }
264    
265      bool Instrument::DestroyRegion(Region* pRegion) {      bool Instrument::DestroyRegion(Region* pRegion) {
# Line 303  namespace sfz Line 285  namespace sfz
285      }      }
286    
287      /////////////////////////////////////////////////////////////      /////////////////////////////////////////////////////////////
288      // class Group      // class ContainerDefinition
289    
290      Group::Group() :      ContainerDefinition::ContainerDefinition(section_type type)
         id(0)  
291      {      {
292          Reset();          Reset();
293            level = type;
294      }      }
295    
296      Group::~Group()      ContainerDefinition::~ContainerDefinition()
297      {      {
298      }      }
299    
300      void      void
301      Group::Reset()      ContainerDefinition::Reset()
302      {      {
303          // This is where all the default values are set.          // This is where all the default values are set.
304    
# Line 347  namespace sfz Line 329  namespace sfz
329    
330          trigger = TRIGGER_ATTACK;          trigger = TRIGGER_ATTACK;
331    
332          group.unset();          group = 0;
333          off_by.unset();          off_by = 0;
334          off_mode = OFF_FAST;          off_mode = OFF_FAST;
335    
336          // sample player          // sample player
337          count.unset();          count = optional<int>::nothing;
338          delay.unset(); delay_random.unset();          delay = optional<float>::nothing;
339          delay_beats.unset(); stop_beats.unset();          delay_random = optional<float>::nothing;
340          delay_samples.unset();          delay_beats = optional<int>::nothing;
341          end.unset();          stop_beats = optional<int>::nothing;
342          loop_crossfade.unset();          delay_samples = optional<int>::nothing;
343          offset.unset(); offset_random.unset();          end = 0;
344          loop_mode = NO_LOOP;          loop_crossfade = optional<float>::nothing;
345          loop_start.unset(); loop_end.unset();          offset = optional<uint>::nothing;
346          sync_beats.unset(); sync_offset.unset();          offset_random = optional<int>::nothing;
347            loop_mode = LOOP_UNSET;
348            loop_start = optional<int>::nothing;
349            loop_end = optional<int>::nothing;
350            sync_beats = optional<int>::nothing;
351            sync_offset = optional<int>::nothing;
352    
353          // amplifier          // amplifier
354          volume = 0;          volume = 0;
355            volume_oncc.clear();
356            volume_curvecc.clear();
357            volume_smoothcc.clear();
358            volume_stepcc.clear();
359            amplitude = 100;
360          pan = 0;          pan = 0;
361            pan_oncc.clear();
362            pan_curvecc.clear();
363            pan_smoothcc.clear();
364            pan_stepcc.clear();
365          width = 100;          width = 100;
366          position = 0;          position = 0;
367          amp_keytrack = 0;          amp_keytrack = 0;
# Line 391  namespace sfz Line 387  namespace sfz
387          bend_up = 200;          bend_up = 200;
388          bend_down = -200;          bend_down = -200;
389          bend_step = 1;          bend_step = 1;
390            
391            pitch_oncc.clear();
392            pitch_smoothcc.clear();
393            pitch_curvecc.clear();
394            pitch_stepcc.clear();
395    
396          // filter          // filter
397          fil_type = LPF_2P;          fil_type = LPF_2P;
398          cutoff.unset();          cutoff = optional<float>::nothing;
399          cutoff_chanaft = 0;          cutoff_chanaft = 0;
400          cutoff_polyaft = 0;          cutoff_polyaft = 0;
401          resonance = 0;          resonance = 0;
# Line 404  namespace sfz Line 405  namespace sfz
405          fil_random = 0;          fil_random = 0;
406    
407          fil2_type = LPF_2P;          fil2_type = LPF_2P;
408          cutoff2.unset();          cutoff2 = optional<float>::nothing;
409          cutoff2_chanaft = 0;          cutoff2_chanaft = 0;
410          cutoff2_polyaft = 0;          cutoff2_polyaft = 0;
411          resonance2 = 0;          resonance2 = 0;
# Line 412  namespace sfz Line 413  namespace sfz
413          fil2_keycenter = 60;          fil2_keycenter = 60;
414          fil2_veltrack = 0;          fil2_veltrack = 0;
415          fil2_random = 0;          fil2_random = 0;
416            
417            cutoff_oncc.clear();
418            cutoff_smoothcc.clear();
419            cutoff_curvecc.clear();
420            cutoff_stepcc.clear();
421            cutoff2_oncc.clear();
422            cutoff2_smoothcc.clear();
423            cutoff2_curvecc.clear();
424            cutoff2_stepcc.clear();
425            
426            resonance_oncc.clear();
427            resonance_smoothcc.clear();
428            resonance_curvecc.clear();
429            resonance_stepcc.clear();
430            resonance2_oncc.clear();
431            resonance2_smoothcc.clear();
432            resonance2_curvecc.clear();
433            resonance2_stepcc.clear();
434    
435          // per voice equalizer          // per voice equalizer
436          eq1_freq = 50;          eq1_freq = 50;
# Line 434  namespace sfz Line 453  namespace sfz
453          for (int i = 0; i < 128; ++i)          for (int i = 0; i < 128; ++i)
454          {          {
455              // input control              // input control
456              locc[i] = 0;              locc.set(i, 0);
457              hicc[i] = 127;              hicc.set(i, 127);
458              start_locc[i] = -1;              start_locc.set(i, -1);
459              start_hicc[i] = -1;              start_hicc.set(i, -1);
460              stop_locc[i] = -1;              stop_locc.set(i, -1);
461              stop_hicc[i] = -1;              stop_hicc.set(i, -1);
462              on_locc[i] = -1;              on_locc.set(i, -1);
463              on_hicc[i] = -1;              on_hicc.set(i, -1);
464    
465              // sample player              // sample player
466              delay_oncc[i].unset();              delay_oncc.set(i, optional<float>::nothing);
467              delay_samples_oncc[i].unset();              delay_samples_oncc.set(i, optional<int>::nothing);
468              offset_oncc[i].unset();              offset_oncc.set(i, optional<int>::nothing);
469    
470              // amplifier              // amplifier
471              amp_velcurve_[i] = 0; //fixme: 20 log (127^2 / i^2)              amp_velcurve.set(i, -1);
472              gain_oncc[i] = 0;              gain_oncc.set(i, 0);
473              xfin_locc[i] = 0;              xfin_locc.set(i, 0);
474              xfin_hicc[i] = 0;              xfin_hicc.set(i, 0);
475              xfout_locc[i] = 127;              xfout_locc.set(i, 0);
476              xfout_hicc[i] = 127;              xfout_hicc.set(i, 0);
   
             // filter  
             cutoff_oncc[i] = 0;  
             cutoff_smoothcc[i] = 0;  
             cutoff_stepcc[i] = 0;  
             cutoff_curvecc[i] = 0;  
             resonance_oncc[i] = 0;  
             resonance_smoothcc[i] = 0;  
             resonance_stepcc[i] = 0;  
             resonance_curvecc[i] = 0;  
   
             cutoff2_oncc[i] = 0;  
             cutoff2_smoothcc[i] = 0;  
             cutoff2_stepcc[i] = 0;  
             cutoff2_curvecc[i] = 0;  
             resonance2_oncc[i] = 0;  
             resonance2_smoothcc[i] = 0;  
             resonance2_stepcc[i] = 0;  
             resonance2_curvecc[i] = 0;  
477    
478              // per voice equalizer              // per voice equalizer
479              eq1_freq_oncc[i] = 0;              eq1_freq_oncc.set(i, 0);
480              eq2_freq_oncc[i] = 0;              eq2_freq_oncc.set(i, 0);
481              eq3_freq_oncc[i] = 0;              eq3_freq_oncc.set(i, 0);
482              eq1_bw_oncc[i] = 0;              eq1_bw_oncc.set(i, 0);
483              eq2_bw_oncc[i] = 0;              eq2_bw_oncc.set(i, 0);
484              eq3_bw_oncc[i] = 0;              eq3_bw_oncc.set(i, 0);
485              eq1_gain_oncc[i] = 0;              eq1_gain_oncc.set(i, 0);
486              eq2_gain_oncc[i] = 0;              eq2_gain_oncc.set(i, 0);
487              eq3_gain_oncc[i] = 0;              eq3_gain_oncc.set(i, 0);
488          }          }
489    
490            eg.clear();
491            lfos.clear();
492    
493          // deprecated          // deprecated
494          ampeg_delay    = 0;          ampeg_delay    = 0;
495          ampeg_start    = 0; //in percentage          ampeg_start    = 0; //in percentage
496          ampeg_attack   = 0;          ampeg_attack   = 0;
497          ampeg_hold     = 0;          ampeg_hold     = 0;
498          ampeg_decay    = 0;          ampeg_decay    = 0;
499          ampeg_sustain  = 100; // in percentage          ampeg_sustain  = -1; // in percentage
500          ampeg_release  = 0;          ampeg_release  = 0;
501    
502            ampeg_vel2delay   = 0;
503            ampeg_vel2attack  = 0;
504            ampeg_vel2hold    = 0;
505            ampeg_vel2decay   = 0;
506            ampeg_vel2sustain = 0;
507            ampeg_vel2release = 0;
508            
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    
517          fileg_delay    = 0;          fileg_delay    = 0;
518          fileg_start    = 0; //in percentage          fileg_start    = 0; //in percentage
519          fileg_attack   = 0;          fileg_attack   = 0;
# Line 504  namespace sfz Line 522  namespace sfz
522          fileg_sustain  = 100; // in percentage          fileg_sustain  = 100; // in percentage
523          fileg_release  = 0;          fileg_release  = 0;
524    
525            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            
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    
542          pitcheg_delay    = 0;          pitcheg_delay    = 0;
543          pitcheg_start    = 0; //in percentage          pitcheg_start    = 0; //in percentage
544          pitcheg_attack   = 0;          pitcheg_attack   = 0;
# Line 511  namespace sfz Line 546  namespace sfz
546          pitcheg_decay    = 0;          pitcheg_decay    = 0;
547          pitcheg_sustain  = 100; // in percentage          pitcheg_sustain  = 100; // in percentage
548          pitcheg_release  = 0;          pitcheg_release  = 0;
549            pitcheg_depth    = 0;
550    
551            pitcheg_vel2delay   = 0;
552            pitcheg_vel2attack  = 0;
553            pitcheg_vel2hold    = 0;
554            pitcheg_vel2decay   = 0;
555            pitcheg_vel2sustain = 0;
556            pitcheg_vel2release = 0;
557            
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    
567            amplfo_delay     = 0;
568            amplfo_fade      = 0;
569            amplfo_freq      = -1; /* -1 is used to determine whether the LFO was initialized */
570            amplfo_depth     = 0;
571            amplfo_delay_oncc.clear();
572            amplfo_fade_oncc.clear();
573            amplfo_depthcc.clear();
574            amplfo_freqcc.clear();
575    
576            fillfo_delay     = 0;
577            fillfo_fade      = 0;
578            fillfo_freq      = -1; /* -1 is used to determine whether the LFO was initialized */
579            fillfo_depth     = 0;
580            fillfo_delay_oncc.clear();
581            fillfo_fade_oncc.clear();
582            fillfo_depthcc.clear();
583            fillfo_freqcc.clear();
584    
585            pitchlfo_delay   = 0;
586            pitchlfo_fade    = 0;
587            pitchlfo_freq    = -1; /* -1 is used to determine whether the LFO was initialized */
588            pitchlfo_depth   = 0;
589            pitchlfo_delay_oncc.clear();
590            pitchlfo_fade_oncc.clear();
591            pitchlfo_depthcc.clear();
592            pitchlfo_freqcc.clear();
593      }      }
594    
595      Region*      void ContainerDefinition::CopyValuesToDefinition(Definition* definition)
     Group::RegionFactory()  
596      {      {
597          // This is where the current group setting are copied to the new region.          // This is where the current settings are copied to the new definition.
   
         Region* region = new Region();  
   
         region->id = id++;  
598    
599          // sample definition          // sample definition
600          region->sample = sample;          definition->sample = sample;
601    
602          // input control          // input control
603          region->lochan = lochan;          definition->lochan = lochan;
604          region->hichan = hichan;          definition->hichan = hichan;
605          region->lokey = lokey;          definition->lokey = lokey;
606          region->hikey = hikey;          definition->hikey = hikey;
607          region->lovel = lovel;          definition->lovel = lovel;
608          region->hivel = hivel;          definition->hivel = hivel;
609          region->locc = locc;          definition->locc = locc;
610          region->hicc = hicc;          definition->hicc = hicc;
611          region->lobend = lobend;          definition->lobend = lobend;
612          region->hibend = hibend;          definition->hibend = hibend;
613          region->lobpm = lobpm;          definition->lobpm = lobpm;
614          region->hibpm = hibpm;          definition->hibpm = hibpm;
615          region->lochanaft = lochanaft;          definition->lochanaft = lochanaft;
616          region->hichanaft = hichanaft;          definition->hichanaft = hichanaft;
617          region->lopolyaft = lopolyaft;          definition->lopolyaft = lopolyaft;
618          region->hipolyaft = hipolyaft;          definition->hipolyaft = hipolyaft;
619          region->loprog = loprog;          definition->loprog = loprog;
620          region->hiprog = hiprog;          definition->hiprog = hiprog;
621          region->lorand = lorand;          definition->lorand = lorand;
622          region->hirand = hirand;          definition->hirand = hirand;
623          region->lotimer = lotimer;          definition->lotimer = lotimer;
624          region->hitimer = hitimer;          definition->hitimer = hitimer;
625          region->seq_length = seq_length;          definition->seq_length = seq_length;
626          region->seq_position = seq_position;          definition->seq_position = seq_position;
627          region->start_locc = start_locc;          definition->start_locc = start_locc;
628          region->start_hicc = start_hicc;          definition->start_hicc = start_hicc;
629          region->stop_locc = stop_locc;          definition->stop_locc = stop_locc;
630          region->stop_hicc = stop_hicc;          definition->stop_hicc = stop_hicc;
631          region->sw_lokey = sw_lokey;          definition->sw_lokey = sw_lokey;
632          region->sw_hikey = sw_hikey;          definition->sw_hikey = sw_hikey;
633          region->sw_last = sw_last;          definition->sw_last = sw_last;
634          region->sw_down = sw_down;          definition->sw_down = sw_down;
635          region->sw_up = sw_up;          definition->sw_up = sw_up;
636          region->sw_previous = sw_previous;          definition->sw_previous = sw_previous;
637          region->sw_vel = sw_vel;          definition->sw_vel = sw_vel;
638          region->trigger = trigger;          definition->trigger = trigger;
639          region->group = group;          definition->group = group;
640          region->off_by = off_by;          definition->off_by = off_by;
641          region->off_mode = off_mode;          definition->off_mode = off_mode;
642          region->on_locc = on_locc;          definition->on_locc = on_locc;
643          region->on_hicc = on_hicc;          definition->on_hicc = on_hicc;
644    
645          // sample player          // sample player
646          region->count = count;          definition->count = count;
647          region->delay = delay;          definition->delay = delay;
648          region->delay_random = delay_random;          definition->delay_random = delay_random;
649          region->delay_oncc = delay_oncc;          definition->delay_oncc = delay_oncc;
650          region->delay_beats = delay_beats;          definition->delay_beats = delay_beats;
651          region->stop_beats = stop_beats;          definition->stop_beats = stop_beats;
652          region->delay_samples = delay_samples;          definition->delay_samples = delay_samples;
653          region->delay_samples_oncc = delay_samples_oncc;          definition->delay_samples_oncc = delay_samples_oncc;
654          region->end = end;          definition->end = end;
655          region->loop_crossfade = loop_crossfade;          definition->loop_crossfade = loop_crossfade;
656          region->offset = offset;          definition->offset = offset;
657          region->offset_random = offset_random;          definition->offset_random = offset_random;
658          region->offset_oncc = offset_oncc;          definition->offset_oncc = offset_oncc;
659          region->loop_mode = loop_mode;          definition->loop_mode = loop_mode;
660          region->loop_start = loop_start;          definition->loop_start = loop_start;
661          region->loop_end = loop_end;          definition->loop_end = loop_end;
662          region->sync_beats = sync_beats;          definition->sync_beats = sync_beats;
663          region->sync_offset = sync_offset;          definition->sync_offset = sync_offset;
664    
665          // amplifier          // amplifier
666          region->volume = volume;          definition->volume = volume;
667          region->pan = pan;          definition->volume_oncc = volume_oncc;
668          region->width = width;          definition->volume_curvecc = volume_curvecc;
669          region->position = position;          definition->volume_smoothcc = volume_smoothcc;
670          region->amp_keytrack = amp_keytrack;          definition->volume_stepcc = volume_stepcc;
671          region->amp_keycenter = amp_keycenter;          definition->amplitude = amplitude;
672          region->amp_veltrack = amp_veltrack;          definition->pan = pan;
673          region->amp_velcurve_ = amp_velcurve_;          definition->pan_oncc = pan_oncc;
674          region->amp_random = amp_random;          definition->pan_curvecc = pan_curvecc;
675          region->rt_decay = rt_decay;          definition->pan_smoothcc = pan_smoothcc;
676          region->gain_oncc = gain_oncc;          definition->pan_stepcc = pan_stepcc;
677          region->xfin_lokey = xfin_lokey;          definition->width = width;
678          region->xfin_hikey = xfin_hikey;          definition->position = position;
679          region->xfout_lokey = xfout_lokey;          definition->amp_keytrack = amp_keytrack;
680          region->xfout_hikey = xfout_hikey;          definition->amp_keycenter = amp_keycenter;
681          region->xf_keycurve = xf_keycurve;          definition->amp_veltrack = amp_veltrack;
682          region->xfin_lovel = xfin_lovel;          definition->amp_velcurve = amp_velcurve;
683          region->xfin_hivel = xfin_lovel;          definition->amp_random = amp_random;
684          region->xfout_lovel = xfout_lovel;          definition->rt_decay = rt_decay;
685          region->xfout_hivel = xfout_hivel;          definition->gain_oncc = gain_oncc;
686          region->xf_velcurve = xf_velcurve;          definition->xfin_lokey = xfin_lokey;
687          region->xfin_locc = xfin_locc;          definition->xfin_hikey = xfin_hikey;
688          region->xfin_hicc = xfin_hicc;          definition->xfout_lokey = xfout_lokey;
689          region->xfout_locc = xfout_locc;          definition->xfout_hikey = xfout_hikey;
690          region->xfout_hicc = xfout_hicc;          definition->xf_keycurve = xf_keycurve;
691          region->xf_cccurve = xf_cccurve;          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    
702          // pitch          // pitch
703          region->transpose = transpose;          definition->transpose = transpose;
704          region->tune = tune;          definition->tune = tune;
705          region->pitch_keycenter = pitch_keycenter;          definition->pitch_keycenter = pitch_keycenter;
706          region->pitch_keytrack = pitch_keytrack;          definition->pitch_keytrack = pitch_keytrack;
707          region->pitch_veltrack = pitch_veltrack;          definition->pitch_veltrack = pitch_veltrack;
708          region->pitch_random = pitch_random;          definition->pitch_random = pitch_random;
709          region->bend_up = bend_up;          definition->bend_up = bend_up;
710          region->bend_down = bend_down;          definition->bend_down = bend_down;
711          region->bend_step = bend_step;          definition->bend_step = bend_step;
712            
713            definition->pitch_oncc     = pitch_oncc;
714            definition->pitch_smoothcc = pitch_smoothcc;
715            definition->pitch_curvecc  = pitch_curvecc;
716            definition->pitch_stepcc   = pitch_stepcc;
717    
718          // filter          // filter
719          region->fil_type = fil_type;          definition->fil_type = fil_type;
720          region->cutoff = cutoff;          definition->cutoff = cutoff;
721          region->cutoff_oncc = cutoff_oncc;          definition->cutoff_oncc = cutoff_oncc;
722          region->cutoff_smoothcc = cutoff_smoothcc;          definition->cutoff_smoothcc = cutoff_smoothcc;
723          region->cutoff_stepcc = cutoff_stepcc;          definition->cutoff_stepcc = cutoff_stepcc;
724          region->cutoff_curvecc = cutoff_curvecc;          definition->cutoff_curvecc = cutoff_curvecc;
725          region->cutoff_chanaft = cutoff_chanaft;          definition->cutoff_chanaft = cutoff_chanaft;
726          region->cutoff_polyaft = cutoff_polyaft;          definition->cutoff_polyaft = cutoff_polyaft;
727          region->resonance = resonance;          definition->resonance = resonance;
728          region->resonance_oncc = resonance_oncc;          definition->resonance_oncc = resonance_oncc;
729          region->resonance_smoothcc = resonance_smoothcc;          definition->resonance_smoothcc = resonance_smoothcc;
730          region->resonance_stepcc = resonance_stepcc;          definition->resonance_stepcc = resonance_stepcc;
731          region->resonance_curvecc = resonance_curvecc;          definition->resonance_curvecc = resonance_curvecc;
732          region->fil_keytrack = fil_keytrack;          definition->fil_keytrack = fil_keytrack;
733          region->fil_keycenter = fil_keycenter;          definition->fil_keycenter = fil_keycenter;
734          region->fil_veltrack = fil_veltrack;          definition->fil_veltrack = fil_veltrack;
735          region->fil_random = fil_random;          definition->fil_random = fil_random;
736    
737          region->fil2_type = fil2_type;          definition->fil2_type = fil2_type;
738          region->cutoff2 = cutoff2;          definition->cutoff2 = cutoff2;
739          region->cutoff2_oncc = cutoff2_oncc;          definition->cutoff2_oncc = cutoff2_oncc;
740          region->cutoff2_smoothcc = cutoff2_smoothcc;          definition->cutoff2_smoothcc = cutoff2_smoothcc;
741          region->cutoff2_stepcc = cutoff2_stepcc;          definition->cutoff2_stepcc = cutoff2_stepcc;
742          region->cutoff2_curvecc = cutoff2_curvecc;          definition->cutoff2_curvecc = cutoff2_curvecc;
743          region->cutoff2_chanaft = cutoff2_chanaft;          definition->cutoff2_chanaft = cutoff2_chanaft;
744          region->cutoff2_polyaft = cutoff2_polyaft;          definition->cutoff2_polyaft = cutoff2_polyaft;
745          region->resonance2 = resonance2;          definition->resonance2 = resonance2;
746          region->resonance2_oncc = resonance2_oncc;          definition->resonance2_oncc = resonance2_oncc;
747          region->resonance2_smoothcc = resonance2_smoothcc;          definition->resonance2_smoothcc = resonance2_smoothcc;
748          region->resonance2_stepcc = resonance2_stepcc;          definition->resonance2_stepcc = resonance2_stepcc;
749          region->resonance2_curvecc = resonance2_curvecc;          definition->resonance2_curvecc = resonance2_curvecc;
750          region->fil2_keytrack = fil2_keytrack;          definition->fil2_keytrack = fil2_keytrack;
751          region->fil2_keycenter = fil2_keycenter;          definition->fil2_keycenter = fil2_keycenter;
752          region->fil2_veltrack = fil2_veltrack;          definition->fil2_veltrack = fil2_veltrack;
753          region->fil2_random = fil2_random;          definition->fil2_random = fil2_random;
754    
755          // per voice equalizer          // per voice equalizer
756          region->eq1_freq = eq1_freq;          definition->eq1_freq = eq1_freq;
757          region->eq2_freq = eq2_freq;          definition->eq2_freq = eq2_freq;
758          region->eq3_freq = eq3_freq;          definition->eq3_freq = eq3_freq;
759          region->eq1_freq_oncc = eq1_freq_oncc;          definition->eq1_freq_oncc = eq1_freq_oncc;
760          region->eq2_freq_oncc = eq2_freq_oncc;          definition->eq2_freq_oncc = eq2_freq_oncc;
761          region->eq3_freq_oncc = eq3_freq_oncc;          definition->eq3_freq_oncc = eq3_freq_oncc;
762          region->eq1_vel2freq = eq1_vel2freq;          definition->eq1_vel2freq = eq1_vel2freq;
763          region->eq2_vel2freq = eq2_vel2freq;          definition->eq2_vel2freq = eq2_vel2freq;
764          region->eq3_vel2freq = eq3_vel2freq;          definition->eq3_vel2freq = eq3_vel2freq;
765          region->eq1_bw = eq1_bw;          definition->eq1_bw = eq1_bw;
766          region->eq2_bw = eq2_bw;          definition->eq2_bw = eq2_bw;
767          region->eq3_bw = eq3_bw;          definition->eq3_bw = eq3_bw;
768          region->eq1_bw_oncc = eq1_bw_oncc;          definition->eq1_bw_oncc = eq1_bw_oncc;
769          region->eq2_bw_oncc = eq2_bw_oncc;          definition->eq2_bw_oncc = eq2_bw_oncc;
770          region->eq3_bw_oncc = eq3_bw_oncc;          definition->eq3_bw_oncc = eq3_bw_oncc;
771          region->eq1_gain = eq1_gain;          definition->eq1_gain = eq1_gain;
772          region->eq2_gain = eq2_gain;          definition->eq2_gain = eq2_gain;
773          region->eq3_gain = eq3_gain;          definition->eq3_gain = eq3_gain;
774          region->eq1_gain_oncc = eq1_gain_oncc;          definition->eq1_gain_oncc = eq1_gain_oncc;
775          region->eq2_gain_oncc = eq2_gain_oncc;          definition->eq2_gain_oncc = eq2_gain_oncc;
776          region->eq3_gain_oncc = eq3_gain_oncc;          definition->eq3_gain_oncc = eq3_gain_oncc;
777          region->eq1_vel2gain = eq1_vel2gain;          definition->eq1_vel2gain = eq1_vel2gain;
778          region->eq2_vel2gain = eq2_vel2gain;          definition->eq2_vel2gain = eq2_vel2gain;
779          region->eq3_vel2gain = eq3_vel2gain;          definition->eq3_vel2gain = eq3_vel2gain;
780    
781          // deprecated          // envelope generator
782          region->ampeg_delay    = ampeg_delay;          definition->eg = eg;
         region->ampeg_start    = ampeg_start;  
         region->ampeg_attack   = ampeg_attack;  
         region->ampeg_hold     = ampeg_hold;  
         region->ampeg_decay    = ampeg_decay;  
         region->ampeg_sustain  = ampeg_sustain;  
         region->ampeg_release  = ampeg_release;  
   
         region->fileg_delay    = fileg_delay;  
         region->fileg_start    = fileg_start;  
         region->fileg_attack   = fileg_attack;  
         region->fileg_hold     = fileg_hold;  
         region->fileg_decay    = fileg_decay;  
         region->fileg_sustain  = fileg_sustain;  
         region->fileg_release  = fileg_release;  
   
         region->pitcheg_delay    = pitcheg_delay;  
         region->pitcheg_start    = pitcheg_start;  
         region->pitcheg_attack   = pitcheg_attack;  
         region->pitcheg_hold     = pitcheg_hold;  
         region->pitcheg_decay    = pitcheg_decay;  
         region->pitcheg_sustain  = pitcheg_sustain;  
         region->pitcheg_release  = pitcheg_release;  
783    
784          return region;          // deprecated
785            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    
793            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            
800            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    
808            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    
817            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            
824            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    
833            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    
842            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            
849            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    
858            definition->amplfo_delay     = amplfo_delay;
859            definition->amplfo_fade      = amplfo_fade;
860            definition->amplfo_freq      = amplfo_freq;
861            definition->amplfo_depth     = amplfo_depth;
862            
863            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    
868            definition->fillfo_delay     = fillfo_delay;
869            definition->fillfo_fade      = fillfo_fade;
870            definition->fillfo_freq      = fillfo_freq;
871            definition->fillfo_depth     = fillfo_depth;
872            
873            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    
878            definition->pitchlfo_delay   = pitchlfo_delay;
879            definition->pitchlfo_fade    = pitchlfo_fade;
880            definition->pitchlfo_freq    = pitchlfo_freq;
881            definition->pitchlfo_depth   = pitchlfo_depth;
882            
883            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            
888            definition->eg = eg;
889            definition->lfos = lfos;
890      }      }
891    
892      /////////////////////////////////////////////////////////////      /////////////////////////////////////////////////////////////
893      // class File      // class File
894    
895        const std::string File::MACRO_NAME_CHARS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_";
896        const std::string File::MACRO_VALUE_CHARS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_. /\\";
897    
898      File::File(std::string file, SampleManager* pSampleManager) :      File::File(std::string file, SampleManager* pSampleManager) :
899          _current_section(GROUP),          _current_section(GLOBAL),
900            id(0),
901          default_path(""),          default_path(""),
902          octave_offset(0),          octave_offset(0),
903          note_offset(0)          note_offset(0)
904      {      {
905          _instrument = new Instrument(LinuxSampler::Path::getBaseName(file), pSampleManager);          _instrument = new Instrument(LinuxSampler::Path::getBaseName(file), pSampleManager);
906          _current_group = new Group();          ContainerDefinition* defaultGlobalContainer = new ContainerDefinition(ContainerDefinition::GLOBAL);
907                  pCurDef = _current_group;          _current_containers.push(defaultGlobalContainer);
908            pCurDef = defaultGlobalContainer;
909    
910            parseFile(file,pSampleManager);
911    
912            std::set<float*> velcurves;
913            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                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                }
927    
928                // get keyswitches
929                low = pRegion->sw_lokey;
930                if (low < 0) low = 0;
931                high = pRegion->sw_hikey;
932                if (high == -1) {
933                    // Key switches not defined, so nothing to do
934                } else if (low >= 0 && low <= 127 && high >= 0 && high <= 127 && high >= low) {
935                    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    
940                // create velocity response curve
941    
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                            prevvalue += step;
962                        }
963                    } else {
964                        // default curve
965                        for (int v = 0 ; v < 128 ; v++) {
966                            velcurve[v] = v * v / (127.0 * 127.0);
967                        }
968                    }
969                }
970            }
971    
972            _instrument->pLookupTable = new LookupTable(_instrument);
973    
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            
980            for (int i = 0; i < _instrument->regions.size(); i++) {
981                Region* r = _instrument->regions[i];
982                
983                copyCurves(r->volume_curvecc, r->volume_oncc);
984                r->volume_curvecc.clear();
985                
986                copySmoothValues(r->volume_smoothcc, r->volume_oncc);
987                r->volume_smoothcc.clear();
988                
989                copyStepValues(r->volume_stepcc, r->volume_oncc);
990                r->volume_stepcc.clear();
991                
992                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                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                copyStepValues(r->pan_stepcc, r->pan_oncc);
1008                r->pan_stepcc.clear();
1009                
1010                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                copyStepValues(r->cutoff_stepcc, r->cutoff_oncc);
1017                r->cutoff_stepcc.clear();
1018                
1019                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                copyStepValues(r->cutoff2_stepcc, r->cutoff2_oncc);
1026                r->cutoff2_stepcc.clear();
1027                
1028                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                copyStepValues(r->resonance_stepcc, r->resonance_oncc);
1035                r->resonance_stepcc.clear();
1036                
1037                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                copyStepValues(r->resonance2_stepcc, r->resonance2_oncc);
1044                r->resonance2_stepcc.clear();
1045                
1046                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                for (int j = 0; j < r->lfos.size(); j++) {
1052                    r->lfos[j].copySmoothValues();
1053                    r->lfos[j].copyStepValues();
1054                    
1055                    copySmoothValues(r->lfos[j].volume_smoothcc, r->lfos[j].volume_oncc);
1056                    r->lfos[j].volume_smoothcc.clear();
1057                    
1058                    copyStepValues(r->lfos[j].volume_stepcc, r->lfos[j].volume_oncc);
1059                    r->lfos[j].volume_stepcc.clear();
1060                    
1061                    copySmoothValues(r->lfos[j].freq_smoothcc, r->lfos[j].freq_oncc);
1062                    r->lfos[j].freq_smoothcc.clear();
1063                    
1064                    copyStepValues(r->lfos[j].freq_stepcc, r->lfos[j].freq_oncc);
1065                    r->lfos[j].freq_stepcc.clear();
1066                    
1067                    copySmoothValues(r->lfos[j].pitch_smoothcc, r->lfos[j].pitch_oncc);
1068                    r->lfos[j].pitch_smoothcc.clear();
1069                    
1070                    copyStepValues(r->lfos[j].pitch_stepcc, r->lfos[j].pitch_oncc);
1071                    r->lfos[j].pitch_stepcc.clear();
1072                    
1073                    copySmoothValues(r->lfos[j].pan_smoothcc, r->lfos[j].pan_oncc);
1074                    r->lfos[j].pan_smoothcc.clear();
1075                    
1076                    copyStepValues(r->lfos[j].pan_stepcc, r->lfos[j].pan_oncc);
1077                    r->lfos[j].pan_stepcc.clear();
1078                    
1079                    copySmoothValues(r->lfos[j].cutoff_smoothcc, r->lfos[j].cutoff_oncc);
1080                    r->lfos[j].cutoff_smoothcc.clear();
1081                    
1082                    copyStepValues(r->lfos[j].cutoff_stepcc, r->lfos[j].cutoff_oncc);
1083                    r->lfos[j].cutoff_stepcc.clear();
1084                    
1085                    copySmoothValues(r->lfos[j].resonance_smoothcc, r->lfos[j].resonance_oncc);
1086                    r->lfos[j].resonance_smoothcc.clear();
1087                    
1088                    copyStepValues(r->lfos[j].resonance_stepcc, r->lfos[j].resonance_oncc);
1089                    r->lfos[j].resonance_stepcc.clear();
1090                }
1091            }
1092        }
1093    
1094        void File::parseFile(std::string file, SampleManager* pSampleManager){
1095          enum token_type_t { HEADER, OPCODE };          enum token_type_t { HEADER, OPCODE };
1096          token_type_t token_type;          token_type_t token_type = (token_type_t) -1;
1097          std::string token_string;          std::string token_string;
1098    
1099          std::ifstream fs(file.c_str());          std::ifstream fs(file.c_str());
1100          currentDir = LinuxSampler::Path::stripLastName(file);          currentDir = LinuxSampler::Path::stripLastName(file);
1101          std::string token;          std::string token;
1102          std::string line;          std::string line;
1103            currentLine = 0;
1104    
1105          while (std::getline(fs, line))          while (std::getline(fs, line))
1106          {          {
1107                currentLine++;
1108              // COMMENT              // COMMENT
1109              std::string::size_type slash_index = line.find("//");              std::string::size_type slash_index = line.find("//");
1110              if (slash_index != std::string::npos)              if (slash_index != std::string::npos)
1111                  line.resize(slash_index);                  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                // #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                // 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    
1210                    continue;
1211                }
1212    
1213              // DEFINITION              // DEFINITION
1214              std::stringstream linestream(line);              std::stringstream linestream(line);
1215                int spaces = 0;
1216              while (linestream >> token)              while (linestream >> token)
1217              {              {
1218                  if (token[0] == '<' and token[token.size()-1] == '>')                  linestream >> std::noskipws;
1219                    if (token[0] == '<' && token[token.size()-1] == '>')
1220                  {                  {
1221                      // HEAD                      // HEAD
1222                      if (!token_string.empty())                      if (!token_string.empty())
# Line 791  namespace sfz Line 1257  namespace sfz
1257                  else                  else
1258                  {                  {
1259                      // TAIL                      // TAIL
1260                      token_string.append(" ");                      token_string.append(spaces, ' ');
1261                      token_string.append(token);                      token_string.append(token);
1262                  }                  }
1263                    spaces = 0;
1264                    while (isspace(linestream.peek())) {
1265                        linestream.ignore();
1266                        spaces++;
1267                    }
1268              }              }
1269    
1270              // EOL              // EOL
# Line 811  namespace sfz Line 1282  namespace sfz
1282                  token_string.erase();                  token_string.erase();
1283              }              }
1284          }          }
   
         for (int i = 0; i < _instrument->regions.size(); i++) {  
             ::sfz::Region* pRegion = _instrument->regions[i];  
             int low = pRegion->lokey;  
             int high = pRegion->hikey;  
             if (low < 0 || low > 127 || high < 0 || high > 127 || low > high) {  
                 std::cerr << "Invalid key range: " << low << " - " << high << std::endl;  
             } else {  
                 for (int j = low; j <= high; j++) _instrument->KeyBindings[j] = true;  
             }  
   
             // get keyswitches  
             low = pRegion->sw_lokey;  
             high = pRegion->sw_hikey;  
             if(low == -1 && high == -1) {  
                 // Key switches not defined, so nothing to do  
             } else if(low >= 0 && low <= 127 && high >= 0 && high <= 127 && high >= low) {  
                 for (int j = low; j <= high; j++) _instrument->KeySwitchBindings[j] = true;  
             } else {  
                 std::cerr << "Invalid key switch range: " << low << " - " << high << std::endl;  
             }  
         }  
1285      }      }
1286    
1287      File::~File()      File::~File()
1288      {      {
1289          delete _current_group;          for (int i = 0; i < _current_containers.size(); i++)
1290            {
1291                delete _current_containers.top();
1292                _current_containers.pop();
1293            }
1294          delete _instrument;          delete _instrument;
1295      }      }
1296    
# Line 846  namespace sfz Line 1299  namespace sfz
1299      {      {
1300          return _instrument;          return _instrument;
1301      }      }
1302        
1303        void File::copyCurves(LinuxSampler::ArrayList<CC>& curves, LinuxSampler::ArrayList<CC>& dest) {
1304            for (int i = 0; i < curves.size(); i++) {
1305                for (int j = 0; j < dest.size(); j++) {
1306                    if (curves[i].Controller == dest[j].Controller) {
1307                        dest[j].Curve = curves[i].Curve;
1308                    }
1309                }
1310            }
1311        }
1312        
1313        void File::copySmoothValues(LinuxSampler::ArrayList<CC>& smooths, LinuxSampler::ArrayList<CC>& dest) {
1314            for (int i = 0; i < smooths.size(); i++) {
1315                for (int j = 0; j < dest.size(); j++) {
1316                    if (smooths[i].Controller == dest[j].Controller) {
1317                        dest[j].Smooth = smooths[i].Smooth;
1318                    }
1319                }
1320            }
1321        }
1322        
1323        void File::copyStepValues(LinuxSampler::ArrayList<CC>& steps, LinuxSampler::ArrayList<CC>& dest) {
1324            for (int i = 0; i < steps.size(); i++) {
1325                for (int j = 0; j < dest.size(); j++) {
1326                    if (steps[i].Controller == dest[j].Controller) {
1327                        dest[j].Step = steps[i].Step;
1328                    }
1329                }
1330            }
1331        }
1332        
1333        int File::ToInt(const std::string& s) throw(LinuxSampler::Exception) {
1334            int i;
1335            std::istringstream iss(s);
1336            if(!(iss >> i)) {
1337                std::ostringstream oss;
1338                oss << "Line " << currentLine << ": Expected an integer";
1339                throw LinuxSampler::Exception(oss.str());
1340            }
1341            return i;
1342        }
1343    
1344        float File::ToFloat(const std::string& s) throw(LinuxSampler::Exception) {
1345            float i;
1346            std::istringstream iss(s);
1347            if(!(iss >> i)) {
1348                std::ostringstream oss;
1349                oss << "Line " << currentLine << ": Expected a floating-point number";
1350                throw LinuxSampler::Exception(oss.str());
1351            }
1352            return i;
1353        }
1354    
1355      void      void
1356      File::push_header(std::string token)      File::push_header(std::string token)
1357      {      {
1358          if (token == "<group>")          if (token == "<global>" ||
1359                token == "<master>" ||
1360                token == "<group>")
1361          {          {
1362              _current_section = GROUP;              ContainerDefinition::section_type level = ContainerDefinition::GLOBAL; // initialized only to avoid an irrelevant compiler warning
1363              _current_group->Reset();  
1364                          pCurDef = _current_group;              if (token == "<global>")
1365                {
1366                    _current_section = GLOBAL;
1367                    level = ContainerDefinition::GLOBAL;
1368                }
1369                else if (token == "<master>")
1370                {
1371                    _current_section = MASTER;
1372                    level = ContainerDefinition::MASTER;
1373                }
1374                else if (token == "<group>")
1375                {
1376                    _current_section = GROUP;
1377                    level = ContainerDefinition::GROUP;
1378                }
1379    
1380                ContainerDefinition* newContainer = new ContainerDefinition(level);
1381                
1382                while (_current_containers.size() > 0 && _current_containers.top()->level <= level)
1383                {
1384                    delete _current_containers.top();
1385                    _current_containers.pop();
1386                }
1387                
1388                //If the new header is a <global>, there won't be anything left in _current_containers
1389                //to copy from.
1390                if (_current_containers.size() > 0)
1391                {
1392                    _current_containers.top()->CopyValuesToDefinition(newContainer);
1393                }
1394                _current_containers.push(newContainer);
1395                pCurDef = newContainer;
1396          }          }
1397          else if (token == "<region>")          else if (token == "<region>")
1398          {          {
1399              _current_section = REGION;              _current_section = REGION;
1400              _current_region = _current_group->RegionFactory();              _current_region = new Region();
1401                          pCurDef = _current_region;              _current_region->id = id++;
1402                _current_containers.top()->CopyValuesToDefinition(_current_region);
1403                pCurDef = _current_region;
1404              _instrument->regions.push_back(_current_region);              _instrument->regions.push_back(_current_region);
1405                          _current_region->SetInstrument(_instrument);              _current_region->SetInstrument(_instrument);
1406          }          }
1407          else if (token == "<control>")          else if (token == "<control>")
1408          {          {
# Line 871  namespace sfz Line 1411  namespace sfz
1411              octave_offset = 0;              octave_offset = 0;
1412              note_offset = 0;              note_offset = 0;
1413          }          }
1414            else if (token == "<curve>")
1415            {
1416                _current_section = CURVE;
1417                _instrument->curves.add(Curve());
1418                _current_curve = &_instrument->curves[_instrument->curves.size() - 1];
1419            }
1420          else          else
1421          {          {
1422              _current_section = UNKNOWN;              _current_section = UNKNOWN;
# Line 887  namespace sfz Line 1433  namespace sfz
1433          std::string::size_type delimiter_index = token.find('=');          std::string::size_type delimiter_index = token.find('=');
1434          std::string key = token.substr(0, delimiter_index);          std::string key = token.substr(0, delimiter_index);
1435          std::string value = token.substr(delimiter_index + 1);          std::string value = token.substr(delimiter_index + 1);
1436            int x, y, z;
1437            
1438            // Apply macros
1439            size_t macro_start = 0;
1440            size_t macro_end = 0;
1441            std::string macro_value;
1442            while ((macro_start = value.find("$", macro_start + macro_value.size())) != std::string::npos)
1443            {
1444                macro_end = value.find_first_not_of(MACRO_NAME_CHARS, macro_start + 1);
1445                size_t macro_len = macro_end - macro_start;
1446                std::string macro_name = value.substr(macro_start, macro_len);
1447                if (_defined_macros.count(macro_name) != 0)
1448                {
1449                    macro_value = _defined_macros[macro_name];
1450                    value.replace(macro_start, macro_len, macro_value);
1451                }
1452                else
1453                {
1454                    std::cerr << "Macro '" << macro_name << "' referenced on line ";
1455                    std::cerr << currentLine << " is undefined." << std::endl;
1456                    return;
1457                }
1458            }
1459            
1460            if (_current_section == CURVE) {
1461                if (sscanf(key.c_str(), "v%d", &x)) {
1462                    if (x < 0 || x > 127) {
1463                        std::cerr << "Invalid curve index: " << x << std::endl;
1464                    }
1465                    _current_curve->v[x] = check(key, 0.0f, 1.0f, ToFloat(value));
1466                } else {
1467                    std::cerr << "The opcode '" << key << "' in section <curve> is unsupported by libsfz!" << std::endl;
1468                }
1469                
1470                return;
1471            }
1472    
1473          // sample definition          // sample definition
1474          if ("sample" == key)          if ("sample" == key)
1475          {          {
1476              std::string path = default_path + value;              std::string path = default_path + value;
1477              #ifndef WIN32              #ifndef WIN32
1478              for (int i = 0; i < path.length(); i++) if( path[i] == '\\') path[i] = '/';              for (int i = 0; i < path.length(); i++) if (path[i] == '\\') path[i] = '/';
1479                bool absolute = path[0] == '/';
1480                #else
1481                bool absolute = path[0] == '/' || path[0] == '\\' ||
1482                    (path.length() >= 2 && isalpha(path[0]) && path[1] == ':');
1483              #endif              #endif
1484              path = currentDir + LinuxSampler::File::DirSeparator + path; // TODO: check for absolute path              if (!absolute) path = currentDir + LinuxSampler::File::DirSeparator + path;
   
1485              if(pCurDef) pCurDef->sample = path;              if(pCurDef) pCurDef->sample = path;
1486              return;              return;
1487          }          }
# Line 908  namespace sfz Line 1493  namespace sfz
1493              {              {
1494              case CONTROL:              case CONTROL:
1495                  default_path = value;                  default_path = value;
1496                    break;
1497                default:
1498                    ; // noop
1499              }              }
1500              return;              return;
1501          }          }
# Line 917  namespace sfz Line 1505  namespace sfz
1505              {              {
1506              case CONTROL:              case CONTROL:
1507                  octave_offset = ToInt(value);                  octave_offset = ToInt(value);
1508                    break;
1509                default:
1510                    ; // noop
1511              }              }
1512              return;              return;
1513          }          }
# Line 926  namespace sfz Line 1517  namespace sfz
1517              {              {
1518              case CONTROL:              case CONTROL:
1519                  note_offset = ToInt(value);                  note_offset = ToInt(value);
1520                    break;
1521                default:
1522                    ; // noop
1523              }              }
1524              return;              return;
1525          }          }
# Line 933  namespace sfz Line 1527  namespace sfz
1527          // input controls          // input controls
1528          else if ("lochan" == key) pCurDef->lochan = ToInt(value);          else if ("lochan" == key) pCurDef->lochan = ToInt(value);
1529          else if ("hichan" == key) pCurDef->hichan = ToInt(value);          else if ("hichan" == key) pCurDef->hichan = ToInt(value);
1530          else if ("lokey"  == key) pCurDef->lokey  = ToInt(value) + note_offset + 12 * octave_offset;          else if ("lokey"  == key) pCurDef->lokey  = parseKey(value);
1531          else if ("hikey"  == key) pCurDef->hikey  = ToInt(value) + note_offset + 12 * octave_offset;          else if ("hikey"  == key) pCurDef->hikey  = parseKey(value);
1532          else if ("key" == key)          else if ("key" == key)
1533          {          {
1534              pCurDef->lokey = ToInt(value) + note_offset + 12 * octave_offset;              pCurDef->lokey = pCurDef->hikey = pCurDef->pitch_keycenter = parseKey(value);
             pCurDef->hikey = ToInt(value) + note_offset + 12 * octave_offset;  
1535          }          }
1536          else if ("lovel"  == key) pCurDef->lovel = ToInt(value);          else if ("lovel"  == key) pCurDef->lovel = ToInt(value);
1537          else if ("hivel"  == key) pCurDef->hivel = ToInt(value);          else if ("hivel"  == key) pCurDef->hivel = ToInt(value);
1538          else if ("lobend" == key) pCurDef->lobend = ToInt(value);          else if ("lobend" == key) pCurDef->lobend = ToInt(value);
1539          else if ("hibend" == key) pCurDef->hibend = ToInt(value);          else if ("hibend" == key) pCurDef->hibend = ToInt(value);
1540          else if ("lobpm"  == key) pCurDef->lobpm = ToInt(value);          else if ("lobpm"  == key) pCurDef->lobpm = ToFloat(value);
1541          else if ("hibpm"  == key) pCurDef->hibpm = ToInt(value);          else if ("hibpm"  == key) pCurDef->hibpm = ToFloat(value);
1542          else if ("lochanaft" == key) pCurDef->lochanaft = ToInt(value);          else if ("lochanaft" == key) pCurDef->lochanaft = ToInt(value);
1543          else if ("hichanaft" == key) pCurDef->hichanaft = ToInt(value);          else if ("hichanaft" == key) pCurDef->hichanaft = ToInt(value);
1544          else if ("lopolyaft" == key) pCurDef->lopolyaft = ToInt(value);          else if ("lopolyaft" == key) pCurDef->lopolyaft = ToInt(value);
# Line 958  namespace sfz Line 1551  namespace sfz
1551          else if ("hitimer" == key) pCurDef->hitimer = ToFloat(value);          else if ("hitimer" == key) pCurDef->hitimer = ToFloat(value);
1552          else if ("seq_length"   == key) pCurDef->seq_length = ToInt(value);          else if ("seq_length"   == key) pCurDef->seq_length = ToInt(value);
1553          else if ("seq_position" == key) pCurDef->seq_position = ToInt(value);          else if ("seq_position" == key) pCurDef->seq_position = ToInt(value);
1554          else if ("sw_lokey" == key) pCurDef->sw_lokey = ToInt(value) + note_offset + 12 * octave_offset;          else if ("sw_lokey" == key) pCurDef->sw_lokey = parseKey(value);
1555          else if ("sw_hikey" == key) pCurDef->sw_hikey = ToInt(value) + note_offset + 12 * octave_offset;          else if ("sw_hikey" == key) pCurDef->sw_hikey = parseKey(value);
1556          else if ("sw_last"  == key) pCurDef->sw_last = ToInt(value) + note_offset + 12 * octave_offset;          else if ("sw_last"  == key) pCurDef->sw_last = parseKey(value);
1557          else if ("sw_down"  == key) pCurDef->sw_down = ToInt(value) + note_offset + 12 * octave_offset;          else if ("sw_down"  == key) pCurDef->sw_down = parseKey(value);
1558          else if ("sw_up"    == key) pCurDef->sw_up = ToInt(value) + note_offset + 12 * octave_offset;          else if ("sw_up"    == key) pCurDef->sw_up = parseKey(value);
1559          else if ("sw_previous" == key) pCurDef->sw_previous = ToInt(value) + note_offset + 12 * octave_offset;          else if ("sw_previous" == key) pCurDef->sw_previous = parseKey(value);
1560          else if ("sw_vel" == key)          else if ("sw_vel" == key)
1561          {          {
1562              if (value == "current") pCurDef->sw_vel = VEL_CURRENT;              if (value == "current") pCurDef->sw_vel = VEL_CURRENT;
# Line 977  namespace sfz Line 1570  namespace sfz
1570              else if (value == "legato")  pCurDef->trigger = TRIGGER_LEGATO;              else if (value == "legato")  pCurDef->trigger = TRIGGER_LEGATO;
1571          }          }
1572          else if ("group"  == key) pCurDef->group = ToInt(value);          else if ("group"  == key) pCurDef->group = ToInt(value);
1573          else if ("off_by" == key) pCurDef->off_by = ToInt(value);          else if ("off_by" == key || "offby" == key) pCurDef->off_by = ToInt(value);
1574          else if ("off_mode" == key)          else if ("off_mode" == key || "offmode" == key)
1575          {          {
1576              if (value == "fast")  _current_group->off_mode = OFF_FAST;              if (value == "fast")  pCurDef->off_mode = OFF_FAST;
1577              else if (value == "normal") _current_group->off_mode = OFF_NORMAL;              else if (value == "normal") pCurDef->off_mode = OFF_NORMAL;
1578          }          }
1579    
1580          // sample player          // sample player
1581          else if ("count" == key) pCurDef->count = ToInt(value);          else if ("count" == key) { pCurDef->count = ToInt(value); pCurDef->loop_mode = ONE_SHOT; }
1582          else if ("delay" == key) pCurDef->delay = ToFloat(value);          else if ("delay" == key) pCurDef->delay = ToFloat(value);
1583          else if ("delay_random"   == key) pCurDef->delay_random = ToFloat(value);          else if ("delay_random"   == key) pCurDef->delay_random = ToFloat(value);
1584          else if ("delay_beats"    == key) pCurDef->delay_beats = ToInt(value);          else if ("delay_beats"    == key) pCurDef->delay_beats = ToInt(value);
# Line 994  namespace sfz Line 1587  namespace sfz
1587          else if ("end"            == key) pCurDef->end = ToInt(value);          else if ("end"            == key) pCurDef->end = ToInt(value);
1588          else if ("loop_crossfade" == key) pCurDef->loop_crossfade = ToFloat(value);          else if ("loop_crossfade" == key) pCurDef->loop_crossfade = ToFloat(value);
1589          else if ("offset_random"  == key) pCurDef->offset_random = ToInt(value);          else if ("offset_random"  == key) pCurDef->offset_random = ToInt(value);
1590          else if ("loop_mode" == key)          else if ("loop_mode" == key || "loopmode" == key)
1591          {          {
1592              if (value == "no_loop") pCurDef->loop_mode = NO_LOOP;              if (value == "no_loop") pCurDef->loop_mode = NO_LOOP;
1593              else if (value == "one_shot") pCurDef->loop_mode = ONE_SHOT;              else if (value == "one_shot") pCurDef->loop_mode = ONE_SHOT;
1594              else if (value == "loop_continous") pCurDef->loop_mode = LOOP_CONTINOUS;              else if (value == "loop_continuous") pCurDef->loop_mode = LOOP_CONTINUOUS;
1595              else if (value == "loop_sustain") pCurDef->loop_mode = LOOP_SUSTAIN;              else if (value == "loop_sustain") pCurDef->loop_mode = LOOP_SUSTAIN;
1596          }          }
1597          else if ("loop_start" == key) pCurDef->loop_start = ToInt(value);          else if ("loop_start" == key) pCurDef->loop_start = ToInt(value);
1598            else if ("loopstart" == key) pCurDef->loop_start = ToInt(value); // nonstandard
1599          else if ("loop_end" == key) pCurDef->loop_end = ToInt(value);          else if ("loop_end" == key) pCurDef->loop_end = ToInt(value);
1600            else if ("loopend" == key) pCurDef->loop_end = ToInt(value); // nonstandard
1601            else if ("offset" == key) pCurDef->offset = ToInt(value);
1602          else if ("sync_beats" == key) pCurDef->sync_beats = ToInt(value);          else if ("sync_beats" == key) pCurDef->sync_beats = ToInt(value);
1603          else if ("sync_offset" == key) pCurDef->sync_offset = ToInt(value);          else if ("sync_offset" == key) pCurDef->sync_offset = ToInt(value);
1604    
1605          // amplifier          // amplifier
1606          else if ("volume"   == key) pCurDef->volume = ToFloat(value);          else if ("volume"   == key) pCurDef->volume = ToFloat(value);
1607            else if ("amplitude" == key) pCurDef->amplitude = ToFloat(value);
1608          else if ("pan"      == key) pCurDef->pan = ToFloat(value);          else if ("pan"      == key) pCurDef->pan = ToFloat(value);
1609          else if ("width"    == key) pCurDef->width = ToFloat(value);          else if ("width"    == key) pCurDef->width = ToFloat(value);
1610          else if ("position" == key) pCurDef->position = ToFloat(value);          else if ("position" == key) pCurDef->position = ToFloat(value);
1611          else if ("amp_keytrack"  == key) pCurDef->amp_keytrack = ToFloat(value);          else if ("amp_keytrack"  == key) pCurDef->amp_keytrack = ToFloat(value);
1612          else if ("amp_keycenter" == key) pCurDef->amp_keycenter = ToInt(value) + note_offset + 12 * octave_offset;          else if ("amp_keycenter" == key) pCurDef->amp_keycenter = parseKey(value);
1613          else if ("amp_veltrack"  == key) pCurDef->amp_veltrack = ToFloat(value);          else if ("amp_veltrack"  == key) pCurDef->amp_veltrack = ToFloat(value);
1614          else if ("amp_random"  == key) pCurDef->amp_random = ToFloat(value);          else if ("amp_random"  == key) pCurDef->amp_random = ToFloat(value);
1615          else if ("rt_decay"    == key) pCurDef->rt_decay = ToFloat(value);          else if ("rt_decay" == key || "rtdecay" == key) pCurDef->rt_decay = ToFloat(value);
1616          else if ("xfin_lokey"  == key) pCurDef->xfin_lokey = ToInt(value) + note_offset + 12 * octave_offset;          else if ("xfin_lokey"  == key) pCurDef->xfin_lokey = parseKey(value);
1617          else if ("xfin_hikey"  == key) pCurDef->xfin_hikey = ToInt(value) + note_offset + 12 * octave_offset;          else if ("xfin_hikey"  == key) pCurDef->xfin_hikey = parseKey(value);
1618          else if ("xfout_lokey" == key) pCurDef->xfout_lokey = ToInt(value) + note_offset + 12 * octave_offset;          else if ("xfout_lokey" == key) pCurDef->xfout_lokey = parseKey(value);
1619          else if ("xfout_hikey" == key) pCurDef->xfout_hikey = ToInt(value) + note_offset + 12 * octave_offset;          else if ("xfout_hikey" == key) pCurDef->xfout_hikey = parseKey(value);
1620          else if ("xf_keycurve" == key)          else if ("xf_keycurve" == key)
1621          {          {
1622              if (value == "gain") pCurDef->xf_keycurve = GAIN;              if (value == "gain") pCurDef->xf_keycurve = GAIN;
# Line 1043  namespace sfz Line 1640  namespace sfz
1640          // pitch          // pitch
1641          else if ("transpose" == key) pCurDef->transpose = ToInt(value);          else if ("transpose" == key) pCurDef->transpose = ToInt(value);
1642          else if ("tune" == key) pCurDef->tune = ToInt(value);          else if ("tune" == key) pCurDef->tune = ToInt(value);
1643          else if ("pitch_keycenter" == key) pCurDef->pitch_keycenter = ToInt(value) + note_offset + 12 * octave_offset;          else if ("pitch_keycenter" == key) pCurDef->pitch_keycenter = parseKey(value);
1644          else if ("pitch_keytrack" == key) pCurDef->pitch_keytrack = ToInt(value);          else if ("pitch_keytrack" == key) pCurDef->pitch_keytrack = ToInt(value);
1645          else if ("pitch_veltrack" == key) pCurDef->pitch_veltrack = ToInt(value);          else if ("pitch_veltrack" == key) pCurDef->pitch_veltrack = ToInt(value);
1646          else if ("pitch_random" == key) pCurDef->pitch_random = ToInt(value);          else if ("pitch_random" == key) pCurDef->pitch_random = ToInt(value);
1647          else if ("bend_up" == key) pCurDef->bend_up = ToInt(value);          else if ("bend_up" == key || "bendup" == key) pCurDef->bend_up = ToInt(value);
1648          else if ("bend_down" == key) pCurDef->bend_down = ToInt(value);          else if ("bend_down" == key || "benddown" == key) pCurDef->bend_down = ToInt(value);
1649          else if ("bend_step" == key) pCurDef->bend_step = ToInt(value);          else if ("bend_step" == key || "bendstep" == key) pCurDef->bend_step = ToInt(value);
1650    
1651          // filter          // filter
1652          else if ("fil_type" == key)          else if ("fil_type" == key || "filtype" == key)
1653          {          {
1654              if (value == "lpf_1p") pCurDef->fil_type = LPF_1P;              if (value == "lpf_1p") pCurDef->fil_type = LPF_1P;
1655              else if (value == "hpf_1p") pCurDef->fil_type = HPF_1P;              else if (value == "hpf_1p") pCurDef->fil_type = HPF_1P;
# Line 1088  namespace sfz Line 1685  namespace sfz
1685          }          }
1686          else if ("cutoff"  == key) pCurDef->cutoff = ToFloat(value);          else if ("cutoff"  == key) pCurDef->cutoff = ToFloat(value);
1687          else if ("cutoff2" == key) pCurDef->cutoff2 = ToFloat(value);          else if ("cutoff2" == key) pCurDef->cutoff2 = ToFloat(value);
1688          else if ("cutoff_chanaft"  == key) pCurDef->cutoff_chanaft = ToInt(value);          else if ("cutoff_chanaft"  == key) {
1689          else if ("cutoff2_chanaft" == key) pCurDef->cutoff2_chanaft = ToInt(value);              pCurDef->cutoff_chanaft = check(key, -9600, 9600, ToInt(value));
1690                pCurDef->cutoff_oncc.add( CC(128, check(key, -9600, 9600, ToInt(value))) );
1691            } else if ("cutoff2_chanaft" == key) pCurDef->cutoff2_chanaft = ToInt(value);
1692          else if ("cutoff_polyaft"  == key) pCurDef->cutoff_polyaft = ToInt(value);          else if ("cutoff_polyaft"  == key) pCurDef->cutoff_polyaft = ToInt(value);
1693          else if ("cutoff2_polyaft" == key) pCurDef->cutoff2_polyaft = ToInt(value);          else if ("cutoff2_polyaft" == key) pCurDef->cutoff2_polyaft = ToInt(value);
1694          else if ("resonance"  == key) pCurDef->resonance = ToFloat(value);          else if ("resonance"  == key) pCurDef->resonance = ToFloat(value);
1695          else if ("resonance2" == key) pCurDef->resonance2 = ToFloat(value);          else if ("resonance2" == key) pCurDef->resonance2 = ToFloat(value);
1696          else if ("fil_keytrack"   == key) pCurDef->fil_keytrack = ToInt(value);          else if ("fil_keytrack"   == key) pCurDef->fil_keytrack = ToInt(value);
1697          else if ("fil2_keytrack"  == key) pCurDef->fil2_keytrack = ToInt(value);          else if ("fil2_keytrack"  == key) pCurDef->fil2_keytrack = ToInt(value);
1698          else if ("fil_keycenter"  == key) pCurDef->fil_keycenter = ToInt(value) + note_offset + 12 * octave_offset;          else if ("fil_keycenter"  == key) pCurDef->fil_keycenter = parseKey(value);
1699          else if ("fil2_keycenter" == key) pCurDef->fil2_keycenter = ToInt(value) + note_offset + 12 * octave_offset;          else if ("fil2_keycenter" == key) pCurDef->fil2_keycenter = parseKey(value);
1700          else if ("fil_veltrack"   == key) pCurDef->fil_veltrack = ToInt(value);          else if ("fil_veltrack"   == key) pCurDef->fil_veltrack = ToInt(value);
1701          else if ("fil2_veltrack"  == key) pCurDef->fil2_veltrack = ToInt(value);          else if ("fil2_veltrack"  == key) pCurDef->fil2_veltrack = ToInt(value);
1702          else if ("fil_random"     == key) pCurDef->fil_random = ToInt(value);          else if ("fil_random"     == key) pCurDef->fil_random = ToInt(value);
# Line 1120  namespace sfz Line 1719  namespace sfz
1719          else if ("eq2_vel2gain" == key) pCurDef->eq2_vel2gain = ToFloat(value);          else if ("eq2_vel2gain" == key) pCurDef->eq2_vel2gain = ToFloat(value);
1720          else if ("eq3_vel2gain" == key) pCurDef->eq3_vel2gain = ToFloat(value);          else if ("eq3_vel2gain" == key) pCurDef->eq3_vel2gain = ToFloat(value);
1721    
1722          //fixme: parse amp_velcurve_N          else if (sscanf(key.c_str(), "amp_velcurve_%d", &x)) {
1723                pCurDef->amp_velcurve.set(x, ToFloat(value));
1724          // CCs          }
1725          else if (key.find("cc") != std::string::npos)          
1726          {          // v2 envelope generators
1727              std::string::size_type delimiter_index = key.find("cc");          else if (sscanf(key.c_str(), "eg%d%n", &x, &y)) {
1728              std::string key_cc = key.substr(0, delimiter_index);              const char* s = key.c_str() + y;
1729              int num_cc = ToInt(key.substr(delimiter_index + 2));              if (sscanf(s, "_time%d%n", &y, &z)) {
1730                    const char* s2 = s + z;
1731              // input controls                  if (strcmp(s2, "") == 0) egnode(x, y).time = check(key, 0.0f, 100.0f, ToFloat(value));
1732              if ("lo" == key_cc) pCurDef->locc[num_cc] = ToInt(value);                  else if (sscanf(s2, "_oncc%d", &z)) egnode(x, y).time_oncc.add( CC(z, check(key, 0.0f, 100.0f, ToFloat(value))) );
1733              else if ("hi" == key_cc) pCurDef->hicc[num_cc] = ToInt(value);              } else if (sscanf(s, "_level%d%n", &y, &z)) {
1734              else if ("start_lo" == key_cc) pCurDef->start_locc[num_cc] = ToInt(value);                  const char* s2 = s + z;
1735              else if ("start_hi" == key_cc) pCurDef->start_hicc[num_cc] = ToInt(value);                  if (strcmp(s2, "") == 0) egnode(x, y).level = check(key, 0.0f, 1.0f, ToFloat(value));
1736              else if ("stop_lo" == key_cc) pCurDef->stop_locc[num_cc] = ToInt(value);                  else if (sscanf(s2, "_oncc%d", &z)) egnode(x, y).level_oncc.add( CC(z, check(key, 0.0f, 1.0f, ToFloat(value))) );
1737              else if ("stop_hi" == key_cc) pCurDef->stop_hicc[num_cc] = ToInt(value);              }
1738              else if ("on_lo" == key_cc) pCurDef->on_locc[num_cc] = ToInt(value);              else if (sscanf(s, "_shape%d", &y)) egnode(x, y).shape = ToFloat(value);
1739              else if ("on_hi" == key_cc) pCurDef->on_hicc[num_cc] = ToInt(value);              else if (sscanf(s, "_curve%d", &y)) egnode(x, y).curve = ToFloat(value);
1740                else if (strcmp(s, "_sustain") == 0) eg(x).sustain = ToInt(value);
1741              // sample player              else if (strcmp(s, "_loop") == 0) eg(x).loop = ToInt(value);
1742              else if ("delay_on" == key_cc) pCurDef->delay_oncc[num_cc] = ToFloat(value);              else if (strcmp(s, "_loop_count") == 0) eg(x).loop_count = ToInt(value);
1743              else if ("delay_samples_on" == key_cc) pCurDef->delay_samples_oncc[num_cc] = ToInt(value);              else if (strcmp(s, "_amplitude") == 0) eg(x).amplitude = ToFloat(value);
1744              else if ("offset_on" == key_cc) pCurDef->offset_oncc[num_cc] = ToInt(value);              else if (sscanf(s, "_amplitude_oncc%d", &y)) eg(x).amplitude_oncc.add( CC(y, check(key, 0.0f, 100.0f, ToFloat(value))) );
1745                else if (strcmp(s, "_volume") == 0) eg(x).volume = check(key, -144.0f, 6.0f, ToFloat(value));
1746              // amplifier              else if (sscanf(s, "_volume_oncc%d", &y)) eg(x).volume_oncc.add( CC(y, check(key, -144.0f, 6.0f, ToFloat(value))) );
1747              else if ("gain_on"  == key_cc) pCurDef->gain_oncc[num_cc]  = ToFloat(value);              else if (strcmp(s, "_cutoff") == 0) eg(x).cutoff = ToFloat(value);
1748              else if ("xfin_lo"  == key_cc) pCurDef->xfin_locc[num_cc]  = ToInt(value);              else if (sscanf(s, "_cutoff_oncc%d", &y)) eg(x).cutoff_oncc.add( CC(y, check(key, -9600, 9600, ToInt(value))) );
1749              else if ("xfin_hi"  == key_cc) pCurDef->xfin_hicc[num_cc]  = ToInt(value);              else if (strcmp(s, "_pitch") == 0) eg(x).pitch = check(key, -9600, 9600, ToInt(value));
1750              else if ("xfout_lo" == key_cc) pCurDef->xfout_locc[num_cc] = ToInt(value);              else if (sscanf(s, "_pitch_oncc%d", &y)) eg(x).pitch_oncc.add( CC(y, check(key, -9600, 9600, ToInt(value))) );
1751              else if ("xfout_hi" == key_cc) pCurDef->xfout_hicc[num_cc] = ToInt(value);              else if (strcmp(s, "_resonance") == 0) eg(x).resonance = check(key, 0.0f, 40.0f, ToFloat(value));
1752                else if (sscanf(s, "_resonance_oncc%d", &y)) eg(x).resonance_oncc.add( CC(y, check(key, 0.0f, 40.0f, ToFloat(value))) );
1753              // filter              else if (strcmp(s, "_pan") == 0) eg(x).pan = check(key, -100.0f, 100.0f, ToFloat(value));
1754              else if ("cutoff_on"  == key_cc) pCurDef->cutoff_oncc[num_cc]  = ToInt(value);              else if (strcmp(s, "_pan_curve") == 0) eg(x).pan_curve = check(key, 0, 30000, ToInt(value));
1755              else if ("cutoff2_on" == key_cc) pCurDef->cutoff2_oncc[num_cc] = ToInt(value);              else if (sscanf(s, "_pan_oncc%d", &y)) eg(x).pan_oncc.add( CC(y, check(key, -100.0f, 100.0f, ToFloat(value))) );
1756              else if ("cutoff_smooth"  == key_cc) pCurDef->cutoff_smoothcc[num_cc]  = ToInt(value);              else if (sscanf(s, "_pan_curvecc%d", &y)) eg(x).pan_curvecc.add( CC(y, 0.0f, check(key, 0, 30000, ToInt(value))) );
1757              else if ("cutoff2_smooth" == key_cc) pCurDef->cutoff2_smoothcc[num_cc] = ToInt(value);              else if (strcmp(s, "_eq1freq") == 0) eg(x).eq1freq = check(key, 0.0f, 30000.0f, ToFloat(value));
1758              else if ("cutoff_step"  == key_cc) pCurDef->cutoff_stepcc[num_cc]  = ToInt(value);              else if (strcmp(s, "_eq2freq") == 0) eg(x).eq2freq = check(key, 0.0f, 30000.0f, ToFloat(value));
1759              else if ("cutoff2_step" == key_cc) pCurDef->cutoff2_stepcc[num_cc] = ToInt(value);              else if (strcmp(s, "_eq3freq") == 0) eg(x).eq3freq = check(key, 0.0f, 30000.0f, ToFloat(value));
1760              else if ("cutoff_curve" == key_cc) pCurDef->cutoff_curvecc[num_cc] = ToInt(value);              else if (strcmp(s, "_eq1bw") == 0) eg(x).eq1bw = check(key, 0.001f, 4.0f, ToFloat(value));
1761              else if ("cutoff2_curve" == key_cc) pCurDef->cutoff2_curvecc[num_cc] = ToInt(value);              else if (strcmp(s, "_eq2bw") == 0) eg(x).eq2bw = check(key, 0.001f, 4.0f, ToFloat(value));
1762              else if ("resonance_on" == key_cc) pCurDef->resonance_oncc[num_cc] = ToInt(value);              else if (strcmp(s, "_eq3bw") == 0) eg(x).eq3bw = check(key, 0.001f, 4.0f, ToFloat(value));
1763              else if ("resonance2_on" == key_cc) pCurDef->resonance2_oncc[num_cc] = ToInt(value);              else if (strcmp(s, "_eq1gain") == 0) eg(x).eq1gain = check(key, -96.0f, 24.0f, ToFloat(value));
1764              else if ("resonance_smooth" == key_cc) pCurDef->resonance_smoothcc[num_cc] = ToInt(value);              else if (strcmp(s, "_eq2gain") == 0) eg(x).eq2gain = check(key, -96.0f, 24.0f, ToFloat(value));
1765              else if ("resonance2_smooth" == key_cc) pCurDef->resonance2_smoothcc[num_cc] = ToInt(value);              else if (strcmp(s, "_eq3gain") == 0) eg(x).eq3gain = check(key, -96.0f, 24.0f, ToFloat(value));
1766              else if ("resonance_step" == key_cc) pCurDef->resonance_stepcc[num_cc] = ToInt(value);              else if (sscanf(s, "_eq1freq_oncc%d", &y)) eg(x).eq1freq_oncc.add( CC(y, check(key, 0.0f, 30000.0f, ToFloat(value))) );
1767              else if ("resonance2_step" == key_cc) pCurDef->resonance2_stepcc[num_cc] = ToInt(value);              else if (sscanf(s, "_eq2freq_oncc%d", &y)) eg(x).eq2freq_oncc.add( CC(y, check(key, 0.0f, 30000.0f, ToFloat(value))) );
1768              else if ("resonance_curve" == key_cc) pCurDef->resonance_curvecc[num_cc] = ToInt(value);              else if (sscanf(s, "_eq3freq_oncc%d", &y)) eg(x).eq3freq_oncc.add( CC(y, check(key, 0.0f, 30000.0f, ToFloat(value))) );
1769              else if ("resonance2_curve" == key_cc) pCurDef->resonance2_curvecc[num_cc] = ToInt(value);              else if (sscanf(s, "_eq1bw_oncc%d", &y)) eg(x).eq1bw_oncc.add( CC(y, check(key, 0.001f, 4.0f, ToFloat(value))) );
1770                else if (sscanf(s, "_eq2bw_oncc%d", &y)) eg(x).eq2bw_oncc.add( CC(y, check(key, 0.001f, 4.0f, ToFloat(value))) );
1771              // per voice equalizer              else if (sscanf(s, "_eq3bw_oncc%d", &y)) eg(x).eq3bw_oncc.add( CC(y, check(key, 0.001f, 4.0f, ToFloat(value))) );
1772              else if ("eq1_freq_on" == key_cc) pCurDef->eq1_freq_oncc[num_cc] = ToInt(value);              else if (sscanf(s, "_eq1gain_oncc%d", &y)) eg(x).eq1gain_oncc.add( CC(y, check(key, -96.0f, 24.0f, ToFloat(value))) );
1773              else if ("eq2_freq_on" == key_cc) pCurDef->eq2_freq_oncc[num_cc] = ToInt(value);              else if (sscanf(s, "_eq2gain_oncc%d", &y)) eg(x).eq2gain_oncc.add( CC(y, check(key, -96.0f, 24.0f, ToFloat(value))) );
1774              else if ("eq3_freq_on" == key_cc) pCurDef->eq3_freq_oncc[num_cc] = ToInt(value);              else if (sscanf(s, "_eq3gain_oncc%d", &y)) eg(x).eq3gain_oncc.add( CC(y, check(key, -96.0f, 24.0f, ToFloat(value))) );
             else if ("eq1_bw_on" == key_cc) pCurDef->eq1_bw_oncc[num_cc] = ToInt(value);  
             else if ("eq2_bw_on" == key_cc) pCurDef->eq2_bw_oncc[num_cc] = ToInt(value);  
             else if ("eq3_bw_on" == key_cc) pCurDef->eq3_bw_oncc[num_cc] = ToInt(value);  
             else if ("eq1_gain_on" == key_cc) pCurDef->eq1_gain_oncc[num_cc] = ToInt(value);  
             else if ("eq2_gain_on" == key_cc) pCurDef->eq2_gain_oncc[num_cc] = ToInt(value);  
             else if ("eq3_gain_on" == key_cc) pCurDef->eq3_gain_oncc[num_cc] = ToInt(value);  
1775              else std::cerr << "The opcode '" << key << "' is unsupported by libsfz!" << std::endl;              else std::cerr << "The opcode '" << key << "' is unsupported by libsfz!" << std::endl;
1776          }          }
1777          // Deprecated opcodes  
1778            // v1 envelope generators
1779          else if ("ampeg_delay"   == key) pCurDef->ampeg_delay = ToFloat(value);          else if ("ampeg_delay"   == key) pCurDef->ampeg_delay = ToFloat(value);
1780          else if ("ampeg_start"   == key) pCurDef->ampeg_start = ToFloat(value);          else if ("ampeg_start"   == key) pCurDef->ampeg_start = ToFloat(value);
1781          else if ("ampeg_attack"   == key) pCurDef->ampeg_attack = ToFloat(value);          else if ("ampeg_attack"   == key) pCurDef->ampeg_attack = ToFloat(value);
1782          else if ("ampeg_hold"   == key) pCurDef->ampeg_hold = ToFloat(value);          else if ("ampeg_hold"   == key) pCurDef->ampeg_hold = ToFloat(value);
1783          else if ("ampeg_decay"   == key) pCurDef->ampeg_decay = ToFloat(value);          else if ("ampeg_decay"   == key) pCurDef->ampeg_decay = ToFloat(value);
1784          else if ("ampeg_sustain"   == key) pCurDef->ampeg_sustain = ToFloat(value);          else if ("ampeg_sustain"   == key) pCurDef->ampeg_sustain = ToFloat(value);
1785          else if ("ampeg_release"   == key) pCurDef->ampeg_release = ToFloat(value);          else if ("ampeg_release" == key) pCurDef->ampeg_release = ToFloat(value);
1786            else if ("ampeg_vel2delay" == key) pCurDef->ampeg_vel2delay = ToFloat(value);
1787            else if ("ampeg_vel2attack" == key) pCurDef->ampeg_vel2attack = ToFloat(value);
1788            else if ("ampeg_vel2hold" == key) pCurDef->ampeg_vel2hold = ToFloat(value);
1789            else if ("ampeg_vel2decay" == key) pCurDef->ampeg_vel2decay = ToFloat(value);
1790            else if ("ampeg_vel2sustain" == key) pCurDef->ampeg_vel2sustain = ToFloat(value);
1791            else if ("ampeg_vel2release" == key) pCurDef->ampeg_vel2release = ToFloat(value);
1792          else if ("fileg_delay"   == key) pCurDef->fileg_delay = ToFloat(value);          else if ("fileg_delay"   == key) pCurDef->fileg_delay = ToFloat(value);
1793          else if ("fileg_start"   == key) pCurDef->fileg_start = ToFloat(value);          else if ("fileg_start"   == key) pCurDef->fileg_start = ToFloat(value);
1794          else if ("fileg_attack"   == key) pCurDef->fileg_attack = ToFloat(value);          else if ("fileg_attack"   == key) pCurDef->fileg_attack = ToFloat(value);
# Line 1196  namespace sfz Line 1796  namespace sfz
1796          else if ("fileg_decay"   == key) pCurDef->fileg_decay = ToFloat(value);          else if ("fileg_decay"   == key) pCurDef->fileg_decay = ToFloat(value);
1797          else if ("fileg_sustain"   == key) pCurDef->fileg_sustain = ToFloat(value);          else if ("fileg_sustain"   == key) pCurDef->fileg_sustain = ToFloat(value);
1798          else if ("fileg_release"   == key) pCurDef->fileg_release = ToFloat(value);          else if ("fileg_release"   == key) pCurDef->fileg_release = ToFloat(value);
1799            else if ("fileg_depth"   == key) pCurDef->fileg_depth = check(key, -12000, 12000, ToInt(value));
1800            else if ("fileg_vel2delay"   == key) pCurDef->fileg_vel2delay = check(key, -100.0f, 100.0f, ToFloat(value));
1801            else if ("fileg_vel2attack"  == key) pCurDef->fileg_vel2attack = ToFloat(value);
1802            else if ("fileg_vel2hold"    == key) pCurDef->fileg_vel2hold = ToFloat(value);
1803            else if ("fileg_vel2decay"   == key) pCurDef->fileg_vel2decay = ToFloat(value);
1804            else if ("fileg_vel2sustain" == key) pCurDef->fileg_vel2sustain = ToFloat(value);
1805            else if ("fileg_vel2release" == key) pCurDef->fileg_vel2release = ToFloat(value);
1806          else if ("pitcheg_delay"   == key) pCurDef->pitcheg_delay = ToFloat(value);          else if ("pitcheg_delay"   == key) pCurDef->pitcheg_delay = ToFloat(value);
1807          else if ("pitcheg_start"   == key) pCurDef->pitcheg_start = ToFloat(value);          else if ("pitcheg_start"   == key) pCurDef->pitcheg_start = ToFloat(value);
1808          else if ("pitcheg_attack"   == key) pCurDef->pitcheg_attack = ToFloat(value);          else if ("pitcheg_attack"  == key) pCurDef->pitcheg_attack = ToFloat(value);
1809          else if ("pitcheg_hold"   == key) pCurDef->pitcheg_hold = ToFloat(value);          else if ("pitcheg_hold"    == key) pCurDef->pitcheg_hold = ToFloat(value);
1810          else if ("pitcheg_decay"   == key) pCurDef->pitcheg_decay = ToFloat(value);          else if ("pitcheg_decay"   == key) pCurDef->pitcheg_decay = ToFloat(value);
1811          else if ("pitcheg_sustain"   == key) pCurDef->pitcheg_sustain = ToFloat(value);          else if ("pitcheg_sustain" == key) pCurDef->pitcheg_sustain = ToFloat(value);
1812          else if ("pitcheg_release"   == key) pCurDef->pitcheg_release = ToFloat(value);          else if ("pitcheg_release" == key) pCurDef->pitcheg_release = ToFloat(value);
1813            else if ("pitcheg_depth"   == key) pCurDef->pitcheg_depth = check(key, -12000, 12000, ToInt(value));
1814            else if ("pitcheg_vel2delay"   == key) pCurDef->pitcheg_vel2delay = check(key, -100.0f, 100.0f, ToFloat(value));
1815            else if ("pitcheg_vel2attack"  == key) pCurDef->pitcheg_vel2attack = ToFloat(value);
1816            else if ("pitcheg_vel2hold"    == key) pCurDef->pitcheg_vel2hold = ToFloat(value);
1817            else if ("pitcheg_vel2decay"   == key) pCurDef->pitcheg_vel2decay = ToFloat(value);
1818            else if ("pitcheg_vel2sustain" == key) pCurDef->pitcheg_vel2sustain = ToFloat(value);
1819            else if ("pitcheg_vel2release" == key) pCurDef->pitcheg_vel2release = ToFloat(value);
1820            
1821    
1822            // v1 LFO
1823            else if ("amplfo_delay" == key) pCurDef->amplfo_delay = ToFloat(value);
1824            else if ("amplfo_fade" == key) pCurDef->amplfo_fade = ToFloat(value);
1825            else if ("amplfo_freq" == key) pCurDef->amplfo_freq = ToFloat(value);
1826            else if ("amplfo_freqchanaft" == key) pCurDef->amplfo_freqcc.add( CC(128, check(key, -200.0f, 200.0f, ToFloat(value))) );
1827            else if ("amplfo_depth" == key) pCurDef->amplfo_depth = ToFloat(value);
1828            else if ("amplfo_depthchanaft" == key) pCurDef->amplfo_depthcc.add( CC(128, check(key, -10.0f, 10.0f, ToFloat(value))) );
1829            else if ("fillfo_delay" == key) pCurDef->fillfo_delay = ToFloat(value);
1830            else if ("fillfo_fade" == key) pCurDef->fillfo_fade = ToFloat(value);
1831            else if ("fillfo_freq" == key) pCurDef->fillfo_freq = ToFloat(value);
1832            else if ("fillfo_freqchanaft" == key) pCurDef->fillfo_freqcc.add( CC(128, check(key, -200.0f, 200.0f, ToFloat(value))) );
1833            else if ("fillfo_depth" == key) pCurDef->fillfo_depth = ToFloat(value);
1834            else if ("fillfo_depthchanaft" == key) pCurDef->fillfo_depthcc.add( CC(128, check(key, -1200, 1200, ToInt(value))) );
1835            else if ("pitchlfo_delay" == key) pCurDef->pitchlfo_delay = ToFloat(value);
1836            else if ("pitchlfo_fade" == key) pCurDef->pitchlfo_fade = ToFloat(value);
1837            else if ("pitchlfo_freq" == key) pCurDef->pitchlfo_freq = ToFloat(value);
1838            else if ("pitchlfo_freqchanaft" == key) pCurDef->pitchlfo_freqcc.add( CC(128, check(key, -200.0f, 200.0f, ToFloat(value))) );
1839            else if ("pitchlfo_depth" == key) pCurDef->pitchlfo_depth = ToInt(value);
1840            else if ("pitchlfo_depthchanaft" == key) pCurDef->pitchlfo_depthcc.add( CC(128, check(key, -1200, 1200, ToInt(value))) );
1841            
1842            
1843            // v2 LFO
1844            else if (sscanf(key.c_str(), "lfo%d%n", &x, &y)) {
1845                const char* s = key.c_str() + y;
1846                if (strcmp(s, "_freq") == 0) lfo(x).freq = check(key, 0.0f, 20.0f, ToFloat(value));
1847                else if (sscanf(s, "_freq_oncc%d", &y)) lfo(x).freq_oncc.add( CC(y, check(key, 0.0f, 20.0f, ToFloat(value))) );
1848                else if (sscanf(s, "_freq_smoothcc%d", &y)) lfo(x).freq_smoothcc.add( CC(y, 0, -1, check(key, 0, 100000 /* max? */, ToInt(value))) );
1849                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))) );
1850                else if (strcmp(s, "_wave") == 0) lfo(x).wave = ToInt(value);
1851                else if (strcmp(s, "_delay") == 0) lfo(x).delay = check(key, 0.0f, 100.0f, ToFloat(value));
1852                else if (sscanf(s, "_delay_oncc%d", &y)) lfo(x).delay_oncc.add( CC(y, check(key, 0.0f, 100.0f, ToFloat(value))) );
1853                else if (strcmp(s, "_fade") == 0) lfo(x).fade = check(key, 0.0f, 100.0f, ToFloat(value));
1854                else if (sscanf(s, "_fade_oncc%d", &y)) lfo(x).fade_oncc.add( CC(y, check(key, 0.0f, 100.0f, ToFloat(value))) );
1855                else if (strcmp(s, "_phase") == 0) lfo(x).phase = check(key, 0.0f, 360.0f, ToFloat(value));
1856                else if (sscanf(s, "_phase_oncc%d", &y)) lfo(x).phase_oncc.add( CC(y, check(key, 0.0f, 360.0f, ToFloat(value))) );
1857                else if (strcmp(s, "_volume") == 0) lfo(x).volume = check(key, -144.0f, 6.0f, ToFloat(value));
1858                else if (sscanf(s, "_volume_oncc%d", &y)) lfo(x).volume_oncc.add( CC(y, check(key, -144.0f, 6.0f, ToFloat(value))) );
1859                else if (sscanf(s, "_volume_smoothcc%d", &y)) lfo(x).volume_smoothcc.add( CC(y, 0, -1, check(key, 0, 100000 /* max? */, ToInt(value))) );
1860                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))) );
1861                else if (strcmp(s, "_pitch") == 0) lfo(x).pitch = check(key, -9600, 9600, ToInt(value));
1862                else if (sscanf(s, "_pitch_oncc%d", &y)) lfo(x).pitch_oncc.add( CC(y, check(key, -9600, 9600, ToInt(value))) );
1863                else if (sscanf(s, "_pitch_smoothcc%d", &y)) lfo(x).pitch_smoothcc.add( CC(y, 0, -1, check(key, 0, 100000 /* max? */, ToInt(value))) );
1864                else if (sscanf(s, "_pitch_stepcc%d", &y)) lfo(x).pitch_stepcc.add( CC(y, 0, -1, 0, check(key, -9600, 9600, ToInt(value))) );
1865                else if (strcmp(s, "_cutoff") == 0) lfo(x).cutoff = check(key, -9600, 9600, ToInt(value));
1866                else if (sscanf(s, "_cutoff_oncc%d", &y)) lfo(x).cutoff_oncc.add( CC(y, check(key, -9600, 9600, ToInt(value))) );
1867                else if (sscanf(s, "_cutoff_smoothcc%d", &y)) lfo(x).cutoff_smoothcc.add( CC(y, 0, -1, check(key, 0, 100000 /* max? */, ToInt(value))) );
1868                else if (sscanf(s, "_cutoff_stepcc%d", &y)) lfo(x).cutoff_stepcc.add( CC(y, 0, -1, 0, check(key, -9600, 9600, ToInt(value))) );
1869                else if (strcmp(s, "_resonance") == 0) lfo(x).resonance = check(key, 0.0f, 40.0f, ToFloat(value));
1870                else if (sscanf(s, "_resonance_oncc%d", &y)) lfo(x).resonance_oncc.add( CC(y, check(key, 0.0f, 40.0f, ToFloat(value))) );
1871                else if (sscanf(s, "_resonance_smoothcc%d", &y)) lfo(x).resonance_smoothcc.add( CC(y, 0, -1, check(key, 0, 100000 /* max? */, ToInt(value))) );
1872                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))) );
1873                else if (strcmp(s, "_pan") == 0) lfo(x).pan = check(key, -100.0f, 100.0f, ToFloat(value));
1874                else if (sscanf(s, "_pan_oncc%d", &y)) lfo(x).pan_oncc.add( CC(y, check(key, -100.0f, 100.0f, ToFloat(value))) );
1875                else if (sscanf(s, "_pan_smoothcc%d", &y)) lfo(x).pan_smoothcc.add( CC(y, 0, -1, check(key, 0, 100000 /* max? */, ToInt(value))) );
1876                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))) );
1877                else if (strcmp(s, "_eq1freq") == 0) lfo(x).eq1freq = check(key, 0.0f, 30000.0f, ToFloat(value));
1878                else if (strcmp(s, "_eq2freq") == 0) lfo(x).eq2freq = check(key, 0.0f, 30000.0f, ToFloat(value));
1879                else if (strcmp(s, "_eq3freq") == 0) lfo(x).eq3freq = check(key, 0.0f, 30000.0f, ToFloat(value));
1880                else if (strcmp(s, "_eq1bw") == 0) lfo(x).eq1bw = check(key, 0.001f, 4.0f, ToFloat(value));
1881                else if (strcmp(s, "_eq2bw") == 0) lfo(x).eq2bw = check(key, 0.001f, 4.0f, ToFloat(value));
1882                else if (strcmp(s, "_eq3bw") == 0) lfo(x).eq3bw = check(key, 0.001f, 4.0f, ToFloat(value));
1883                else if (strcmp(s, "_eq1gain") == 0) lfo(x).eq1gain = check(key, -96.0f, 24.0f, ToFloat(value));
1884                else if (strcmp(s, "_eq2gain") == 0) lfo(x).eq2gain = check(key, -96.0f, 24.0f, ToFloat(value));
1885                else if (strcmp(s, "_eq3gain") == 0) lfo(x).eq3gain = check(key, -96.0f, 24.0f, ToFloat(value));
1886                else if (sscanf(s, "_eq1freq_oncc%d", &y)) lfo(x).eq1freq_oncc.add( CC(y, check(key, 0.0f, 30000.0f, ToFloat(value))) );
1887                else if (sscanf(s, "_eq1freq_smoothcc%d", &y)) lfo(x).eq1freq_smoothcc.add( CC(y, 0, -1, check(key, 0, 100000 /* max? */, ToInt(value))) );
1888                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))) );
1889                else if (sscanf(s, "_eq2freq_oncc%d", &y)) lfo(x).eq2freq_oncc.add( CC(y, check(key, 0.0f, 30000.0f, ToFloat(value))) );
1890                else if (sscanf(s, "_eq2freq_smoothcc%d", &y)) lfo(x).eq2freq_smoothcc.add( CC(y, 0, -1, check(key, 0, 100000 /* max? */, ToInt(value))) );
1891                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))) );
1892                else if (sscanf(s, "_eq3freq_oncc%d", &y)) lfo(x).eq3freq_oncc.add( CC(y, check(key, 0.0f, 30000.0f, ToFloat(value))) );
1893                else if (sscanf(s, "_eq3freq_smoothcc%d", &y)) lfo(x).eq3freq_smoothcc.add( CC(y, 0, -1, check(key, 0, 100000 /* max? */, ToInt(value))) );
1894                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))) );
1895                else if (sscanf(s, "_eq1bw_oncc%d", &y)) lfo(x).eq1bw_oncc.add( CC(y, check(key, 0.001f, 4.0f, ToFloat(value))) );
1896                else if (sscanf(s, "_eq1bw_smoothcc%d", &y)) lfo(x).eq1bw_smoothcc.add( CC(y, 0, -1, check(key, 0, 100000 /* max? */, ToInt(value))) );
1897                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))) );
1898                else if (sscanf(s, "_eq2bw_oncc%d", &y)) lfo(x).eq2bw_oncc.add( CC(y, check(key, 0.001f, 4.0f, ToFloat(value))) );
1899                else if (sscanf(s, "_eq2bw_smoothcc%d", &y)) lfo(x).eq2bw_smoothcc.add( CC(y, 0, -1, check(key, 0, 100000 /* max? */, ToInt(value))) );
1900                else if (sscanf(s, "_eq2bw_stepcc%d", &y)) lfo(x).eq2bw_stepcc.add( CC(y, 0, -1, 0, check(key, 0.0f, 4294967296.0f, ToFloat(value))) );
1901                else if (sscanf(s, "_eq3bw_oncc%d", &y)) lfo(x).eq3bw_oncc.add( CC(y, check(key, 0.001f, 4.0f, ToFloat(value))) );
1902                else if (sscanf(s, "_eq3bw_smoothcc%d", &y)) lfo(x).eq3bw_smoothcc.add( CC(y, 0, -1, check(key, 0, 100000 /* max? */, ToInt(value))) );
1903                else if (sscanf(s, "_eq3bw_stepcc%d", &y)) lfo(x).eq3bw_stepcc.add( CC(y, 0, -1, 0, check(key, 0.0f, 4294967296.0f, ToFloat(value))) );
1904                else if (sscanf(s, "_eq1gain_oncc%d", &y)) lfo(x).eq1gain_oncc.add( CC(y, check(key, -96.0f, 24.0f, ToFloat(value))) );
1905                else if (sscanf(s, "_eq1gain_smoothcc%d", &y)) lfo(x).eq1gain_smoothcc.add( CC(y, 0, -1, check(key, 0, 100000 /* max? */, ToInt(value))) );
1906                else if (sscanf(s, "_eq1gain_stepcc%d", &y)) lfo(x).eq1gain_stepcc.add( CC(y, 0, -1, 0, check(key, 0.0f, 4294967296.0f, ToFloat(value))) );
1907                else if (sscanf(s, "_eq2gain_oncc%d", &y)) lfo(x).eq2gain_oncc.add( CC(y, check(key, -96.0f, 24.0f, ToFloat(value))) );
1908                else if (sscanf(s, "_eq2gain_smoothcc%d", &y)) lfo(x).eq2gain_smoothcc.add( CC(y, 0, -1, check(key, 0, 100000 /* max? */, ToInt(value))) );
1909                else if (sscanf(s, "_eq2gain_stepcc%d", &y)) lfo(x).eq2gain_stepcc.add( CC(y, 0, -1, 0, check(key, 0.0f, 4294967296.0f, ToFloat(value))) );
1910                else if (sscanf(s, "_eq3gain_oncc%d", &y)) lfo(x).eq3gain_oncc.add( CC(y, check(key, -96.0f, 24.0f, ToFloat(value))) );
1911                else if (sscanf(s, "_eq3gain_smoothcc%d", &y)) lfo(x).eq3gain_smoothcc.add( CC(y, 0, -1, check(key, 0, 100000 /* max? */, ToInt(value))) );
1912                else if (sscanf(s, "_eq3gain_stepcc%d", &y)) lfo(x).eq3gain_stepcc.add( CC(y, 0, -1, 0, check(key, 0.0f, 4294967296.0f, ToFloat(value))) );
1913                else std::cerr << "The opcode '" << key << "' is unsupported by libsfz!" << std::endl;
1914            }
1915            
1916            // CCs
1917            else if (key.find("cc") != std::string::npos)
1918            {
1919                std::string::size_type delimiter_index = key.find("cc");
1920                std::string key_cc = key.substr(0, delimiter_index);
1921                if (key_cc.size() > 3 && !strcmp(key_cc.c_str() + (key_cc.size() - 3), "_on")) {
1922                    key_cc = key_cc.substr(0, key_cc.size() - 3);
1923                }
1924                
1925                // Apply macros
1926                std::string num_cc_str = key.substr(delimiter_index + 2);
1927                
1928                if (num_cc_str[0] == '$')
1929                {
1930                    if (_defined_macros.count(num_cc_str) == 0)
1931                    {
1932                        std::cerr << "Macro '" << value << "' referenced on line ";
1933                        std::cerr << currentLine << " is undefined." << std::endl;
1934                        return;
1935                    }
1936                    
1937                    num_cc_str = _defined_macros[num_cc_str];
1938                }
1939    
1940                int num_cc = ToInt(num_cc_str);
1941                if (num_cc < 0 || num_cc > 127) {
1942                    std::cerr << "sfz: WARNING: CC " << num_cc << " of opcode '" << key;
1943                    std::cerr << "' is an invalid MIDI controller number." << std::endl;
1944                }
1945    
1946                // input controls
1947                if ("lo" == key_cc) pCurDef->locc.set(num_cc, ToInt(value));
1948                else if ("hi" == key_cc) pCurDef->hicc.set(num_cc, ToInt(value));
1949                else if ("start_lo" == key_cc) pCurDef->start_locc.set(num_cc, ToInt(value));
1950                else if ("start_hi" == key_cc) pCurDef->start_hicc.set(num_cc, ToInt(value));
1951                else if ("stop_lo" == key_cc) pCurDef->stop_locc.set(num_cc, ToInt(value));
1952                else if ("stop_hi" == key_cc) pCurDef->stop_hicc.set(num_cc, ToInt(value));
1953                else if ("on_lo" == key_cc) pCurDef->on_locc.set(num_cc, ToInt(value));
1954                else if ("on_hi" == key_cc) pCurDef->on_hicc.set(num_cc, ToInt(value));
1955    
1956                // sample player
1957                else if ("delay" == key_cc) pCurDef->delay_oncc.set(num_cc, ToFloat(value));
1958                else if ("delay_samples" == key_cc) pCurDef->delay_samples_oncc.set(num_cc, ToInt(value));
1959                else if ("offset" == key_cc) pCurDef->offset_oncc.set(num_cc, ToInt(value));
1960    
1961                // amplifier
1962                else if ("gain"  == key_cc || "gain_" == key_cc) pCurDef->gain_oncc.set(num_cc, ToFloat(value));
1963                else if ("xfin_lo"  == key_cc) pCurDef->xfin_locc.set(num_cc, ToInt(value));
1964                else if ("xfin_hi"  == key_cc) pCurDef->xfin_hicc.set(num_cc, ToInt(value));
1965                else if ("xfout_lo" == key_cc) pCurDef->xfout_locc.set(num_cc, ToInt(value));
1966                else if ("xfout_hi" == key_cc) pCurDef->xfout_hicc.set(num_cc, ToInt(value));
1967                
1968                // pitch
1969                else if ("pitch" == key_cc) pCurDef->pitch_oncc.add( CC(num_cc, check(key, -9600, 9600, ToInt(value))) );
1970                else if ("pitch_smooth" == key_cc) pCurDef->pitch_smoothcc.add( CC(num_cc, 0, -1, check(key, 0.0f, 100000.0f /* max? */, ToFloat(value))) );
1971                else if ("pitch_curve" == key_cc) pCurDef->pitch_curvecc.add( CC(num_cc, 0, check(key, 0, 30000, ToInt(value))) );
1972                else if ("pitch_step" == key_cc) pCurDef->pitch_stepcc.add( CC(num_cc, 0, -1, 0, check(key, 0, 1200, ToInt(value))) );
1973    
1974                // filter
1975                else if ("cutoff"  == key_cc || "cutoff_" == key_cc) {
1976                    pCurDef->cutoff_oncc.add( CC(num_cc, check(key, -9600, 9600, ToInt(value))) );
1977                } else if ("cutoff2" == key_cc) pCurDef->cutoff2_oncc.add( CC(num_cc, check(key, -9600, 9600, ToInt(value))) );
1978                else if ("cutoff_smooth"  == key_cc) pCurDef->cutoff_smoothcc.add( CC(num_cc, 0, -1, check(key, 0.0f, 100000.0f /* max? */, ToFloat(value))) );
1979                else if ("cutoff2_smooth" == key_cc) pCurDef->cutoff2_smoothcc.add( CC(num_cc, 0, -1, check(key, 0.0f, 100000.0f /* max? */, ToFloat(value))) );
1980                else if ("cutoff_step"  == key_cc) pCurDef->cutoff_stepcc.add( CC(num_cc, 0, -1, 0, check(key, -1200, 1200, ToInt(value))) );
1981                else if ("cutoff2_step" == key_cc) pCurDef->cutoff2_stepcc.add( CC(num_cc, 0, -1, 0, check(key, -1200, 1200, ToInt(value))) );
1982                else if ("cutoff_curve" == key_cc) pCurDef->cutoff_curvecc.add( CC(num_cc, 0, check(key, 0, 30000, ToInt(value))) );
1983                else if ("cutoff2_curve" == key_cc) pCurDef->cutoff2_curvecc.add( CC(num_cc, 0, check(key, 0, 30000, ToInt(value))) );
1984                else if ("resonance" == key_cc) pCurDef->resonance_oncc.add( CC(num_cc, check(key, 0.0f, 40.0f, ToFloat(value))) );
1985                else if ("resonance2" == key_cc) pCurDef->resonance2_oncc.add( CC(num_cc, check(key, 0.0f, 40.0f, ToFloat(value))) );
1986                else if ("resonance_smooth" == key_cc) pCurDef->resonance_smoothcc.add( CC(num_cc, 0, -1, check(key, 0, 100000 /* max? */, ToInt(value))) );
1987                else if ("resonance2_smooth" == key_cc) pCurDef->resonance2_smoothcc.add( CC(num_cc, 0, -1, check(key, 0, 100000 /* max? */, ToInt(value))) );
1988                else if ("resonance_step" == key_cc) pCurDef->resonance_stepcc.add( CC(num_cc, 0, -1, 0, check(key, 0.0f, 40.0f, ToFloat(value))) );
1989                else if ("resonance2_step" == key_cc) pCurDef->resonance2_stepcc.add( CC(num_cc, 0, -1, 0, check(key, 0.0f, 40.0f, ToFloat(value))) );
1990                else if ("resonance_curve" == key_cc) pCurDef->resonance_curvecc.add( CC(num_cc, 0.0f, check(key, 0, 30000, ToInt(value))) );
1991                else if ("resonance2_curve" == key_cc) pCurDef->resonance2_curvecc.add( CC(num_cc, 0.0f, check(key, 0, 30000, ToInt(value))) );
1992    
1993                // per voice equalizer
1994                else if ("eq1_freq" == key_cc) pCurDef->eq1_freq_oncc.set(num_cc, ToInt(value));
1995                else if ("eq2_freq" == key_cc) pCurDef->eq2_freq_oncc.set(num_cc, ToInt(value));
1996                else if ("eq3_freq" == key_cc) pCurDef->eq3_freq_oncc.set(num_cc, ToInt(value));
1997                else if ("eq1_bw" == key_cc) pCurDef->eq1_bw_oncc.set(num_cc, ToInt(value));
1998                else if ("eq2_bw" == key_cc) pCurDef->eq2_bw_oncc.set(num_cc, ToInt(value));
1999                else if ("eq3_bw" == key_cc) pCurDef->eq3_bw_oncc.set(num_cc, ToInt(value));
2000                else if ("eq1_gain" == key_cc) pCurDef->eq1_gain_oncc.set(num_cc, ToInt(value));
2001                else if ("eq2_gain" == key_cc) pCurDef->eq2_gain_oncc.set(num_cc, ToInt(value));
2002                else if ("eq3_gain" == key_cc) pCurDef->eq3_gain_oncc.set(num_cc, ToInt(value));
2003                
2004                else if ("ampeg_delay"   == key_cc) pCurDef->ampeg_delaycc.add( CC(num_cc, check(key, -100.0f, 100.0f, ToFloat(value))) );
2005                else if ("ampeg_start"   == key_cc) pCurDef->ampeg_startcc.add( CC(num_cc, check(key, -100.0f, 100.0f, ToFloat(value))) );
2006                else if ("ampeg_attack"  == key_cc) pCurDef->ampeg_attackcc.add( CC(num_cc, check(key, -100.0f, 100.0f, ToFloat(value))) );
2007                else if ("ampeg_hold"    == key_cc) pCurDef->ampeg_holdcc.add( CC(num_cc, check(key, -100.0f, 100.0f, ToFloat(value))) );
2008                else if ("ampeg_decay"   == key_cc) pCurDef->ampeg_decaycc.add( CC(num_cc, check(key, -100.0f, 100.0f, ToFloat(value))) );
2009                else if ("ampeg_sustain" == key_cc) pCurDef->ampeg_sustaincc.add( CC(num_cc, check(key, -100.0f, 100.0f, ToFloat(value))) );
2010                else if ("ampeg_release" == key_cc) pCurDef->ampeg_releasecc.add( CC(num_cc, check(key, -100.0f, 100.0f, ToFloat(value))) );
2011                
2012                else if ("fileg_delay"   == key_cc) pCurDef->fileg_delay_oncc.add( CC(num_cc, check(key, -100.0f, 100.0f, ToFloat(value))) );
2013                else if ("fileg_start"   == key_cc) pCurDef->fileg_start_oncc.add( CC(num_cc, check(key, -100.0f, 100.0f, ToFloat(value))) );
2014                else if ("fileg_attack"  == key_cc) pCurDef->fileg_attack_oncc.add( CC(num_cc, check(key, -100.0f, 100.0f, ToFloat(value))) );
2015                else if ("fileg_hold"    == key_cc) pCurDef->fileg_hold_oncc.add( CC(num_cc, check(key, -100.0f, 100.0f, ToFloat(value))) );
2016                else if ("fileg_decay"   == key_cc) pCurDef->fileg_decay_oncc.add( CC(num_cc, check(key, -100.0f, 100.0f, ToFloat(value))) );
2017                else if ("fileg_sustain" == key_cc) pCurDef->fileg_sustain_oncc.add( CC(num_cc, check(key, -100.0f, 100.0f, ToFloat(value))) );
2018                else if ("fileg_release" == key_cc) pCurDef->fileg_release_oncc.add( CC(num_cc, check(key, -100.0f, 100.0f, ToFloat(value))) );
2019                else if ("fileg_depth"   == key_cc) pCurDef->fileg_depth_oncc.add( CC(num_cc, check(key, -12000, 12000, ToInt(value))) );
2020                
2021                else if ("pitcheg_delay"   == key_cc) pCurDef->pitcheg_delay_oncc.add( CC(num_cc, check(key, -100.0f, 100.0f, ToFloat(value))) );
2022                else if ("pitcheg_start"   == key_cc) pCurDef->pitcheg_start_oncc.add( CC(num_cc, check(key, -100.0f, 100.0f, ToFloat(value))) );
2023                else if ("pitcheg_attack"  == key_cc) pCurDef->pitcheg_attack_oncc.add( CC(num_cc, check(key, -100.0f, 100.0f, ToFloat(value))) );
2024                else if ("pitcheg_hold"    == key_cc) pCurDef->pitcheg_hold_oncc.add( CC(num_cc, check(key, -100.0f, 100.0f, ToFloat(value))) );
2025                else if ("pitcheg_decay"   == key_cc) pCurDef->pitcheg_decay_oncc.add( CC(num_cc, check(key, -100.0f, 100.0f, ToFloat(value))) );
2026                else if ("pitcheg_sustain" == key_cc) pCurDef->pitcheg_sustain_oncc.add( CC(num_cc, check(key, -100.0f, 100.0f, ToFloat(value))) );
2027                else if ("pitcheg_release" == key_cc) pCurDef->pitcheg_release_oncc.add( CC(num_cc, check(key, -100.0f, 100.0f, ToFloat(value))) );
2028                else if ("pitcheg_depth"   == key_cc) pCurDef->pitcheg_depth_oncc.add( CC(num_cc, check(key, -12000, 12000, ToInt(value))) );
2029                
2030                else if ("pitchlfo_delay" == key_cc) pCurDef->pitchlfo_delay_oncc.add( CC(num_cc, check(key, 0.0f, 100.0f, ToFloat(value))) );
2031                else if ("pitchlfo_fade" == key_cc) pCurDef->pitchlfo_fade_oncc.add( CC(num_cc, check(key, 0.0f, 100.0f, ToFloat(value))) );
2032                else if ("pitchlfo_depth" == key_cc) pCurDef->pitchlfo_depthcc.add( CC(num_cc, check(key, -1200, 1200, ToInt(value))) );
2033                else if ("pitchlfo_freq" == key_cc) pCurDef->pitchlfo_freqcc.add( CC(num_cc, check(key, -200.0f, 200.0f, ToFloat(value))) );
2034                else if ("fillfo_delay" == key_cc) pCurDef->fillfo_delay_oncc.add( CC(num_cc, check(key, 0.0f, 100.0f, ToFloat(value))) );
2035                else if ("fillfo_fade" == key_cc) pCurDef->fillfo_fade_oncc.add( CC(num_cc, check(key, 0.0f, 100.0f, ToFloat(value))) );
2036                else if ("fillfo_depth" == key_cc) pCurDef->fillfo_depthcc.add( CC(num_cc, check(key, -1200, 1200, ToInt(value))) );
2037                else if ("fillfo_freq" == key_cc) pCurDef->fillfo_freqcc.add( CC(num_cc, check(key, -200.0f, 200.0f, ToFloat(value))) );
2038                else if ("amplfo_delay" == key_cc) pCurDef->amplfo_delay_oncc.add( CC(num_cc, check(key, 0.0f, 100.0f, ToFloat(value))) );
2039                else if ("amplfo_fade" == key_cc) pCurDef->amplfo_fade_oncc.add( CC(num_cc, check(key, 0.0f, 100.0f, ToFloat(value))) );
2040                else if ("amplfo_depth" == key_cc) pCurDef->amplfo_depthcc.add( CC(num_cc, check(key, -10.0f, 10.0f, ToFloat(value))) );
2041                else if ("amplfo_freq" == key_cc) pCurDef->amplfo_freqcc.add( CC(num_cc, check(key, -200.0f, 200.0f, ToFloat(value))) );
2042                else if ("volume" == key_cc) pCurDef->volume_oncc.add( CC(num_cc, check(key, -144.0f, 100.0f, ToFloat(value))) );
2043                else if ("volume_curve" == key_cc) pCurDef->volume_curvecc.add( CC(num_cc, 0, check(key, 0, 30000, ToInt(value))) );
2044                else if ("volume_smooth" == key_cc) pCurDef->volume_smoothcc.add( CC(num_cc, 0, -1, check(key, 0.0f, 100000.0f /* max? */, ToFloat(value))) );
2045                else if ("volume_step" == key_cc) pCurDef->volume_stepcc.add( CC(num_cc, 0, -1, 0, check(key, -20.0f, 20.0f, ToFloat(value))) );
2046                else if ("pan" == key_cc) pCurDef->pan_oncc.add( CC(num_cc, check(key, -200.0f, 200.0f, ToFloat(value))) );
2047                else if ("pan_curve" == key_cc) pCurDef->pan_curvecc.add( CC(num_cc, 0, check(key, 0, 30000, ToInt(value))) );
2048                else if ("pan_smooth" == key_cc) pCurDef->pan_smoothcc.add( CC(num_cc, 0, -1, check(key, 0.0f, 100000.0f /* max? */, ToFloat(value))) );
2049                else if ("pan_step" == key_cc) pCurDef->pan_stepcc.add( CC(num_cc, 0, -1, 0, check(key, -100.0f, 100.0f, ToFloat(value))) );
2050                else if ("set_" == key_cc) _instrument->initialCCValues[num_cc] = (num_cc < 128) ? check(key, 0, 127, ToInt(value)) : ToInt(value);
2051                else std::cerr << "The opcode '" << key << "' is unsupported by libsfz!" << std::endl;
2052            }
2053    
2054          else {          else {
2055              std::cerr << "The opcode '" << key << "' is unsupported by libsfz!" << std::endl;              std::cerr << "The opcode '" << key << "' is unsupported by libsfz!" << std::endl;
2056          }          }
2057      }      }
2058    
2059        int File::parseKey(const std::string& s) {
2060            int i;
2061            std::istringstream iss(s);
2062            if (isdigit(iss.peek())) {
2063                iss >> i;
2064            } else {
2065                switch (tolower(iss.get())) {
2066                case 'c': i = 0; break;
2067                case 'd': i = 2; break;
2068                case 'e': i = 4; break;
2069                case 'f': i = 5; break;
2070                case 'g': i = 7; break;
2071                case 'a': i = 9; break;
2072                case 'b': i = 11; break;
2073                case '-': if (s == "-1") return -1;
2074                default:
2075                    std::cerr << "Not a note: " << s << std::endl;
2076                    return 0;
2077                }
2078                if (iss.peek() == '#') {
2079                    i++;
2080                    iss.get();
2081                } else if (tolower(iss.peek()) == 'b') {
2082                    i--;
2083                    iss.get();
2084                }
2085                int octave;
2086                if (!(iss >> octave)) {
2087                    std::cerr << "Not a note: " << s << std::endl;
2088                    return 0;
2089                }
2090                i += (octave + 1) * 12;
2091            }
2092            return i + note_offset + 12 * octave_offset;
2093        }
2094    
2095        EGNode::EGNode() : time(0), level(0), shape(0), curve(0) {
2096        }
2097        
2098        void EGNode::Copy(const EGNode& egNode) {
2099            time  = egNode.time;
2100            level = egNode.level;
2101            shape = egNode.shape;
2102            curve = egNode.curve;
2103            
2104            time_oncc = egNode.time_oncc;
2105            level_oncc = egNode.level_oncc;
2106        }
2107    
2108        EG::EG() :
2109            sustain(0), loop(0), loop_count(0), amplitude(0), volume(-200), /* less than -144 dB is considered unset */
2110            cutoff(0), pitch(0), resonance(0), pan(0), pan_curve(-1)
2111        { }
2112        
2113        void EG::Copy(const EG& eg) {
2114            EqImpl::Copy(static_cast<const EqImpl>(eg));
2115            
2116            sustain    = eg.sustain;
2117            loop       = eg.loop;
2118            loop_count = eg.loop_count;
2119            amplitude  = eg.amplitude;
2120            volume     = eg.volume;
2121            cutoff     = eg.cutoff;
2122            pitch      = eg.pitch;
2123            resonance  = eg.resonance;
2124            pan        = eg.pan;
2125            pan_curve  = eg.pan_curve;
2126            node       = eg.node;
2127            
2128            amplitude_oncc = eg.amplitude_oncc;
2129            volume_oncc    = eg.volume_oncc;
2130            cutoff_oncc    = eg.cutoff_oncc;
2131            pitch_oncc     = eg.pitch_oncc;
2132            resonance_oncc = eg.resonance_oncc;
2133            pan_oncc       = eg.pan_oncc;
2134            pan_curvecc    = eg.pan_curvecc;
2135        }
2136        
2137        LFO::LFO():
2138            delay(0),
2139            freq(-1), /* -1 is used to determine whether the LFO was initialized */
2140            fade(0), phase(0), wave(0), volume(0), pitch(0), cutoff(0), resonance(0), pan(0)
2141        {
2142        }
2143    
2144        void LFO::Copy(const LFO& lfo) {
2145            EqSmoothStepImpl::Copy(static_cast<const EqSmoothStepImpl>(lfo));
2146            
2147            delay      = lfo.delay;
2148            freq       = lfo.freq;
2149            fade       = lfo.fade;
2150            phase      = lfo.phase;
2151            wave       = lfo.wave;
2152            volume     = lfo.volume;
2153            pitch      = lfo.pitch;
2154            cutoff     = lfo.cutoff;
2155            resonance  = lfo.resonance;
2156            pan        = lfo.pan;
2157            
2158            delay_oncc      = lfo.delay_oncc;
2159            freq_oncc       = lfo.freq_oncc;
2160            freq_smoothcc   = lfo.freq_smoothcc;
2161            freq_stepcc     = lfo.freq_stepcc;
2162            fade_oncc       = lfo.fade_oncc;
2163            phase_oncc      = lfo.phase_oncc;
2164            pitch_oncc      = lfo.pitch_oncc;
2165            pitch_smoothcc  = lfo.pitch_smoothcc;
2166            pitch_stepcc    = lfo.pitch_stepcc;
2167            volume_oncc     = lfo.volume_oncc;
2168            volume_smoothcc = lfo.volume_smoothcc;
2169            volume_stepcc   = lfo.volume_stepcc;
2170            pan_oncc        = lfo.pan_oncc;
2171            pan_smoothcc    = lfo.pan_smoothcc;
2172            pan_stepcc      = lfo.pan_stepcc;
2173            cutoff_oncc     = lfo.cutoff_oncc;
2174            cutoff_smoothcc = lfo.cutoff_smoothcc;
2175            cutoff_stepcc   = lfo.cutoff_stepcc;
2176            resonance_oncc     = lfo.resonance_oncc;
2177            resonance_smoothcc = lfo.resonance_smoothcc;
2178            resonance_stepcc   = lfo.resonance_stepcc;
2179        }
2180        
2181        EqImpl::EqImpl() {
2182            eq1freq = eq2freq = eq3freq = 0;
2183            eq1bw = eq2bw = eq3bw = 0;
2184            eq1gain = eq2gain = eq3gain = 0;
2185        }
2186        
2187        void EqImpl::Copy(const EqImpl& eq) {
2188            eq1freq = eq.eq1freq;
2189            eq2freq = eq.eq2freq;
2190            eq3freq = eq.eq3freq;
2191            eq1bw   = eq.eq1bw;
2192            eq2bw   = eq.eq2bw;
2193            eq3bw   = eq.eq3bw;
2194            eq1gain = eq.eq1gain;
2195            eq2gain = eq.eq2gain;
2196            eq3gain = eq.eq3gain;
2197            
2198            eq1freq_oncc = eq.eq1freq_oncc;
2199            eq2freq_oncc = eq.eq2freq_oncc;
2200            eq3freq_oncc = eq.eq3freq_oncc;
2201            eq1bw_oncc   = eq.eq1bw_oncc;
2202            eq2bw_oncc   = eq.eq2bw_oncc;
2203            eq3bw_oncc   = eq.eq3bw_oncc;
2204            eq1gain_oncc = eq.eq1gain_oncc;
2205            eq2gain_oncc = eq.eq2gain_oncc;
2206            eq3gain_oncc = eq.eq3gain_oncc;
2207        }
2208        
2209        bool EqImpl::HasEq() {
2210            return eq1freq || eq2freq || eq3freq || eq1bw || eq2bw || eq3bw ||
2211                   eq1gain || eq2gain || eq3gain || !eq1gain_oncc.empty() ||
2212                   !eq2gain_oncc.empty() || !eq3gain_oncc.empty() ||
2213                   !eq1freq_oncc.empty() || !eq2freq_oncc.empty() || !eq3freq_oncc.empty() ||
2214                   !eq1bw_oncc.empty() || !eq2bw_oncc.empty() || !eq3bw_oncc.empty();
2215        }
2216        
2217        void EqSmoothStepImpl::Copy(const EqSmoothStepImpl& eq) {
2218            EqImpl::Copy(eq);
2219            
2220            eq1freq_smoothcc = eq.eq1freq_smoothcc;
2221            eq2freq_smoothcc = eq.eq2freq_smoothcc;
2222            eq3freq_smoothcc = eq.eq3freq_smoothcc;
2223            eq1bw_smoothcc   = eq.eq1bw_smoothcc;
2224            eq2bw_smoothcc   = eq.eq2bw_smoothcc;
2225            eq3bw_smoothcc   = eq.eq3bw_smoothcc;
2226            eq1gain_smoothcc = eq.eq1gain_smoothcc;
2227            eq2gain_smoothcc = eq.eq2gain_smoothcc;
2228            eq3gain_smoothcc = eq.eq3gain_smoothcc;
2229            
2230            eq1freq_stepcc = eq.eq1freq_stepcc;
2231            eq2freq_stepcc = eq.eq2freq_stepcc;
2232            eq3freq_stepcc = eq.eq3freq_stepcc;
2233            eq1bw_stepcc   = eq.eq1bw_stepcc;
2234            eq2bw_stepcc   = eq.eq2bw_stepcc;
2235            eq3bw_stepcc   = eq.eq3bw_stepcc;
2236            eq1gain_stepcc = eq.eq1gain_stepcc;
2237            eq2gain_stepcc = eq.eq2gain_stepcc;
2238            eq3gain_stepcc = eq.eq3gain_stepcc;
2239        }
2240        
2241        void EqSmoothStepImpl::copySmoothValues() {
2242            File::copySmoothValues(eq1freq_smoothcc, eq1freq_oncc);
2243            eq1freq_smoothcc.clear();
2244            
2245            File::copySmoothValues(eq2freq_smoothcc, eq2freq_oncc);
2246            eq2freq_smoothcc.clear();
2247            
2248            File::copySmoothValues(eq3freq_smoothcc, eq3freq_oncc);
2249            eq3freq_smoothcc.clear();
2250            
2251            File::copySmoothValues(eq1bw_smoothcc, eq1bw_oncc);
2252            eq1bw_smoothcc.clear();
2253            
2254            File::copySmoothValues(eq2bw_smoothcc, eq2bw_oncc);
2255            eq2bw_smoothcc.clear();
2256            
2257            File::copySmoothValues(eq3bw_smoothcc, eq3bw_oncc);
2258            eq3bw_smoothcc.clear();
2259            
2260            File::copySmoothValues(eq1gain_smoothcc, eq1gain_oncc);
2261            eq1gain_smoothcc.clear();
2262            
2263            File::copySmoothValues(eq2gain_smoothcc, eq2gain_oncc);
2264            eq2gain_smoothcc.clear();
2265            
2266            File::copySmoothValues(eq3gain_smoothcc, eq3gain_oncc);
2267            eq3gain_smoothcc.clear();
2268        }
2269        
2270        void EqSmoothStepImpl::copyStepValues() {
2271            File::copyStepValues(eq1freq_stepcc, eq1freq_oncc);
2272            eq1freq_stepcc.clear();
2273            
2274            File::copyStepValues(eq2freq_stepcc, eq2freq_oncc);
2275            eq2freq_stepcc.clear();
2276            
2277            File::copyStepValues(eq3freq_stepcc, eq3freq_oncc);
2278            eq3freq_stepcc.clear();
2279            
2280            File::copyStepValues(eq1bw_stepcc, eq1bw_oncc);
2281            eq1bw_stepcc.clear();
2282            
2283            File::copyStepValues(eq2bw_stepcc, eq2bw_oncc);
2284            eq2bw_stepcc.clear();
2285            
2286            File::copyStepValues(eq3bw_stepcc, eq3bw_oncc);
2287            eq3bw_stepcc.clear();
2288            
2289            File::copyStepValues(eq1gain_stepcc, eq1gain_oncc);
2290            eq1gain_stepcc.clear();
2291            
2292            File::copyStepValues(eq2gain_stepcc, eq2gain_oncc);
2293            eq2gain_stepcc.clear();
2294            
2295            File::copyStepValues(eq3gain_stepcc, eq3gain_oncc);
2296            eq3gain_stepcc.clear();
2297        }
2298    
2299        EG& File::eg(int x) {
2300            while (pCurDef->eg.size() <= x) {
2301                pCurDef->eg.add(EG());
2302            }
2303            return pCurDef->eg[x];
2304        }
2305    
2306        EGNode& File::egnode(int x, int y) {
2307            EG& e = eg(x);
2308            while (e.node.size() <= y) {
2309                e.node.add(EGNode());
2310            }
2311            return e.node[y];
2312        }
2313    
2314        LFO& File::lfo(int x) {
2315            while (pCurDef->lfos.size() <= x) {
2316                pCurDef->lfos.add(LFO());
2317            }
2318            return pCurDef->lfos[x];
2319        }
2320    
2321  } // !namespace sfz  } // !namespace sfz

Legend:
Removed from v.2018  
changed lines
  Added in v.3095

  ViewVC Help
Powered by ViewVC