/[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 2221 by iliev, Thu Jul 28 17:17:42 2011 UTC revision 2230 by iliev, Fri Aug 5 17:59:10 2011 UTC
# Line 198  namespace sfz Line 198  namespace sfz
198          this->name = name;          this->name = name;
199          this->pSampleManager = pSampleManager ? pSampleManager : this;          this->pSampleManager = pSampleManager ? pSampleManager : this;
200          pLookupTable = 0;          pLookupTable = 0;
201            
202            // The first 6 curves are defined internally (actually 7 with the one at index 0)
203            Curve c;
204            for (int i = 0; i < 128; i++) c.v[i] = i / 127.0f;
205            curves.add(c); curves.add(c); curves.add(c); curves.add(c);
206            curves.add(c); curves.add(c); curves.add(c);
207            ///////
208      }      }
209    
210      Instrument::~Instrument()      Instrument::~Instrument()
# Line 435  namespace sfz Line 442  namespace sfz
442              eq1_gain_oncc.set(i, 0);              eq1_gain_oncc.set(i, 0);
443              eq2_gain_oncc.set(i, 0);              eq2_gain_oncc.set(i, 0);
444              eq3_gain_oncc.set(i, 0);              eq3_gain_oncc.set(i, 0);
445                
446                pitchlfo_depthcc.set(i, 0);
447          }          }
448          cutoff_cc = 0;          cutoff_cc = 0;
449    
# Line 464  namespace sfz Line 473  namespace sfz
473          fileg_sustain  = 100; // in percentage          fileg_sustain  = 100; // in percentage
474          fileg_release  = 0;          fileg_release  = 0;
475    
476            fileg_vel2delay   = 0;
477            fileg_vel2attack  = 0;
478            fileg_vel2hold    = 0;
479            fileg_vel2decay   = 0;
480            fileg_vel2sustain = 0;
481            fileg_vel2release = 0;
482            fileg_depth       = 0;
483    
484          pitcheg_delay    = 0;          pitcheg_delay    = 0;
485          pitcheg_start    = 0; //in percentage          pitcheg_start    = 0; //in percentage
486          pitcheg_attack   = 0;          pitcheg_attack   = 0;
# Line 482  namespace sfz Line 499  namespace sfz
499    
500          amplfo_delay     = 0;          amplfo_delay     = 0;
501          amplfo_fade      = 0;          amplfo_fade      = 0;
502          amplfo_freq      = 0;          amplfo_freq      = -1; /* -1 is used to determine whether the LFO was initialized */
503          amplfo_depth     = 0;          amplfo_depth     = 0;
504    
505          fillfo_delay     = 0;          fillfo_delay     = 0;
506          fillfo_fade      = 0;          fillfo_fade      = 0;
507          fillfo_freq      = 0;          fillfo_freq      = -1; /* -1 is used to determine whether the LFO was initialized */
508          fillfo_depth     = 0;          fillfo_depth     = 0;
509    
510          pitchlfo_delay   = 0;          pitchlfo_delay   = 0;
511          pitchlfo_fade    = 0;          pitchlfo_fade    = 0;
512          pitchlfo_freq    = 0;          pitchlfo_freq    = -1; /* -1 is used to determine whether the LFO was initialized */
513          pitchlfo_depth   = 0;          pitchlfo_depth   = 0;
514      }      }
515    
# Line 692  namespace sfz Line 709  namespace sfz
709          region->ampeg_vel2decay   = ampeg_vel2decay;          region->ampeg_vel2decay   = ampeg_vel2decay;
710          region->ampeg_vel2sustain = ampeg_vel2sustain;          region->ampeg_vel2sustain = ampeg_vel2sustain;
711          region->ampeg_vel2release = ampeg_vel2release;          region->ampeg_vel2release = ampeg_vel2release;
712            
713            region->ampeg_delaycc   = ampeg_delaycc;
714            region->ampeg_startcc   = ampeg_startcc;
715            region->ampeg_attackcc  = ampeg_attackcc;
716            region->ampeg_holdcc    = ampeg_holdcc;
717            region->ampeg_decaycc   = ampeg_decaycc;
718            region->ampeg_sustaincc = ampeg_sustaincc;
719            region->ampeg_releasecc = ampeg_releasecc;
720    
721          region->fileg_delay    = fileg_delay;          region->fileg_delay    = fileg_delay;
722          region->fileg_start    = fileg_start;          region->fileg_start    = fileg_start;
# Line 700  namespace sfz Line 725  namespace sfz
725          region->fileg_decay    = fileg_decay;          region->fileg_decay    = fileg_decay;
726          region->fileg_sustain  = fileg_sustain;          region->fileg_sustain  = fileg_sustain;
727          region->fileg_release  = fileg_release;          region->fileg_release  = fileg_release;
728            region->fileg_depth    = fileg_depth;
729    
730            region->fileg_vel2delay   = fileg_vel2delay;
731            region->fileg_vel2attack  = fileg_vel2attack;
732            region->fileg_vel2hold    = fileg_vel2hold;
733            region->fileg_vel2decay   = fileg_vel2decay;
734            region->fileg_vel2sustain = fileg_vel2sustain;
735            region->fileg_vel2release = fileg_vel2release;
736    
737          region->pitcheg_delay    = pitcheg_delay;          region->pitcheg_delay    = pitcheg_delay;
738          region->pitcheg_start    = pitcheg_start;          region->pitcheg_start    = pitcheg_start;
# Line 721  namespace sfz Line 754  namespace sfz
754          region->amplfo_fade      = amplfo_fade;          region->amplfo_fade      = amplfo_fade;
755          region->amplfo_freq      = amplfo_freq;          region->amplfo_freq      = amplfo_freq;
756          region->amplfo_depth     = amplfo_depth;          region->amplfo_depth     = amplfo_depth;
757            
758            region->amplfo_freqcc    = amplfo_freqcc;
759    
760          region->fillfo_delay     = fillfo_delay;          region->fillfo_delay     = fillfo_delay;
761          region->fillfo_fade      = fillfo_fade;          region->fillfo_fade      = fillfo_fade;
762          region->fillfo_freq      = fillfo_freq;          region->fillfo_freq      = fillfo_freq;
763          region->fillfo_depth     = fillfo_depth;          region->fillfo_depth     = fillfo_depth;
764            
765            region->fillfo_freqcc    = fillfo_freqcc;
766    
767          region->pitchlfo_delay   = pitchlfo_delay;          region->pitchlfo_delay   = pitchlfo_delay;
768          region->pitchlfo_fade    = pitchlfo_fade;          region->pitchlfo_fade    = pitchlfo_fade;
769          region->pitchlfo_freq    = pitchlfo_freq;          region->pitchlfo_freq    = pitchlfo_freq;
770          region->pitchlfo_depth   = pitchlfo_depth;          region->pitchlfo_depth   = pitchlfo_depth;
771            
772            region->pitchlfo_depthcc = pitchlfo_depthcc;
773            region->pitchlfo_freqcc  = pitchlfo_freqcc;
774            
775            region->eg = eg;
776            region->lfos = lfos;
777    
778          return region;          return region;
779      }      }
# Line 903  namespace sfz Line 946  namespace sfz
946          for (int i = 0 ; i < 128 ; i++) {          for (int i = 0 ; i < 128 ; i++) {
947              _instrument->pLookupTableCC[i] = new LookupTable(_instrument, i);              _instrument->pLookupTableCC[i] = new LookupTable(_instrument, i);
948          }          }
949            
950            for (int k = 0; k < _instrument->regions.size(); k++) {
951                Region* r = _instrument->regions[k];
952                
953                copyCurves(r->volume_curvecc, r->volume_oncc);
954                
955                r->volume_curvecc.clear();
956            }
957      }      }
958    
959      File::~File()      File::~File()
# Line 916  namespace sfz Line 967  namespace sfz
967      {      {
968          return _instrument;          return _instrument;
969      }      }
970        
971        void File::copyCurves(LinuxSampler::ArrayList<CC>& curves, LinuxSampler::ArrayList<CC>& dest) {
972            for (int i = 0; i < curves.size(); i++) {
973                for (int j = 0; j < dest.size(); j++) {
974                    if (curves[i].Controller == dest[j].Controller) {
975                        dest[j].Curve = curves[i].Curve;
976                    }
977                }
978            }
979        }
980    
981      void      void
982      File::push_header(std::string token)      File::push_header(std::string token)
# Line 941  namespace sfz Line 1002  namespace sfz
1002              octave_offset = 0;              octave_offset = 0;
1003              note_offset = 0;              note_offset = 0;
1004          }          }
1005            else if (token == "<curve>")
1006            {
1007                _current_section = CURVE;
1008                _instrument->curves.add(Curve());
1009                _current_curve = &_instrument->curves[_instrument->curves.size() - 1];
1010            }
1011          else          else
1012          {          {
1013              _current_section = UNKNOWN;              _current_section = UNKNOWN;
# Line 957  namespace sfz Line 1024  namespace sfz
1024          std::string::size_type delimiter_index = token.find('=');          std::string::size_type delimiter_index = token.find('=');
1025          std::string key = token.substr(0, delimiter_index);          std::string key = token.substr(0, delimiter_index);
1026          std::string value = token.substr(delimiter_index + 1);          std::string value = token.substr(delimiter_index + 1);
1027          int x, y;          int x, y, z;
1028            
1029            if (_current_section == CURVE) {
1030                if (sscanf(key.c_str(), "v%d", &x)) {
1031                    if (x < 0 || x > 127) {
1032                        std::cerr << "Invalid curve index: " << x << std::endl;
1033                    }
1034                    _current_curve->v[x] = check(key, 0.0f, 1.0f, ToFloat(value));
1035                } else {
1036                    std::cerr << "The opcode '" << key << "' in section <curve> is unsupported by libsfz!" << std::endl;
1037                }
1038                
1039                return;
1040            }
1041    
1042          // sample definition          // sample definition
1043          if ("sample" == key)          if ("sample" == key)
# Line 1088  namespace sfz Line 1168  namespace sfz
1168          else if ("amp_keycenter" == key) pCurDef->amp_keycenter = parseKey(value);          else if ("amp_keycenter" == key) pCurDef->amp_keycenter = parseKey(value);
1169          else if ("amp_veltrack"  == key) pCurDef->amp_veltrack = ToFloat(value);          else if ("amp_veltrack"  == key) pCurDef->amp_veltrack = ToFloat(value);
1170          else if ("amp_random"  == key) pCurDef->amp_random = ToFloat(value);          else if ("amp_random"  == key) pCurDef->amp_random = ToFloat(value);
1171          else if ("rt_decay"    == key) pCurDef->rt_decay = ToFloat(value);          else if ("rt_decay" == key || "rtdecay" == key) pCurDef->rt_decay = ToFloat(value);
1172          else if ("xfin_lokey"  == key) pCurDef->xfin_lokey = parseKey(value);          else if ("xfin_lokey"  == key) pCurDef->xfin_lokey = parseKey(value);
1173          else if ("xfin_hikey"  == key) pCurDef->xfin_hikey = parseKey(value);          else if ("xfin_hikey"  == key) pCurDef->xfin_hikey = parseKey(value);
1174          else if ("xfout_lokey" == key) pCurDef->xfout_lokey = parseKey(value);          else if ("xfout_lokey" == key) pCurDef->xfout_lokey = parseKey(value);
# Line 1122  namespace sfz Line 1202  namespace sfz
1202          else if ("pitch_random" == key) pCurDef->pitch_random = ToInt(value);          else if ("pitch_random" == key) pCurDef->pitch_random = ToInt(value);
1203          else if ("bend_up" == key || "bendup" == key) pCurDef->bend_up = ToInt(value);          else if ("bend_up" == key || "bendup" == key) pCurDef->bend_up = ToInt(value);
1204          else if ("bend_down" == key || "benddown" == key) pCurDef->bend_down = ToInt(value);          else if ("bend_down" == key || "benddown" == key) pCurDef->bend_down = ToInt(value);
1205          else if ("bend_step" == key) pCurDef->bend_step = ToInt(value);          else if ("bend_step" == key || "bendstep" == key) pCurDef->bend_step = ToInt(value);
1206    
1207          // filter          // filter
1208          else if ("fil_type" == key || "filtype" == key)          else if ("fil_type" == key || "filtype" == key)
# Line 1196  namespace sfz Line 1276  namespace sfz
1276          else if (sscanf(key.c_str(), "amp_velcurve_%d", &x)) {          else if (sscanf(key.c_str(), "amp_velcurve_%d", &x)) {
1277              pCurDef->amp_velcurve.set(x, ToFloat(value));              pCurDef->amp_velcurve.set(x, ToFloat(value));
1278          }          }
1279            
         // CCs  
         else if (key.find("cc") != std::string::npos)  
         {  
             std::string::size_type delimiter_index = key.find("cc");  
             std::string key_cc = key.substr(0, delimiter_index);  
             int num_cc = ToInt(key.substr(delimiter_index + 2));  
   
             // input controls  
             if ("lo" == key_cc) pCurDef->locc.set(num_cc, ToInt(value));  
             else if ("hi" == key_cc) pCurDef->hicc.set(num_cc, ToInt(value));  
             else if ("start_lo" == key_cc) pCurDef->start_locc.set(num_cc, ToInt(value));  
             else if ("start_hi" == key_cc) pCurDef->start_hicc.set(num_cc, ToInt(value));  
             else if ("stop_lo" == key_cc) pCurDef->stop_locc.set(num_cc, ToInt(value));  
             else if ("stop_hi" == key_cc) pCurDef->stop_hicc.set(num_cc, ToInt(value));  
             else if ("on_lo" == key_cc) pCurDef->on_locc.set(num_cc, ToInt(value));  
             else if ("on_hi" == key_cc) pCurDef->on_hicc.set(num_cc, ToInt(value));  
   
             // sample player  
             else if ("delay_on" == key_cc) pCurDef->delay_oncc.set(num_cc, ToFloat(value));  
             else if ("delay_samples_on" == key_cc) pCurDef->delay_samples_oncc.set(num_cc, ToInt(value));  
             else if ("offset_on" == key_cc) pCurDef->offset_oncc.set(num_cc, ToInt(value));  
   
             // amplifier  
             else if ("gain_on"  == key_cc || "gain_" == key_cc) pCurDef->gain_oncc.set(num_cc, ToFloat(value));  
             else if ("xfin_lo"  == key_cc) pCurDef->xfin_locc.set(num_cc, ToInt(value));  
             else if ("xfin_hi"  == key_cc) pCurDef->xfin_hicc.set(num_cc, ToInt(value));  
             else if ("xfout_lo" == key_cc) pCurDef->xfout_locc.set(num_cc, ToInt(value));  
             else if ("xfout_hi" == key_cc) pCurDef->xfout_hicc.set(num_cc, ToInt(value));  
   
             // filter  
             else if ("cutoff_on"  == key_cc || "cutoff_" == key_cc) {  
                 pCurDef->cutoff_oncc.set(num_cc, ToInt(value));  
                 pCurDef->cutoff_cc = num_cc;  
             } else if ("cutoff2_on" == key_cc) pCurDef->cutoff2_oncc.set(num_cc, ToInt(value));  
             else if ("cutoff_smooth"  == key_cc) pCurDef->cutoff_smoothcc.set(num_cc, ToInt(value));  
             else if ("cutoff2_smooth" == key_cc) pCurDef->cutoff2_smoothcc.set(num_cc, ToInt(value));  
             else if ("cutoff_step"  == key_cc) pCurDef->cutoff_stepcc.set(num_cc, ToInt(value));  
             else if ("cutoff2_step" == key_cc) pCurDef->cutoff2_stepcc.set(num_cc, ToInt(value));  
             else if ("cutoff_curve" == key_cc) pCurDef->cutoff_curvecc.set(num_cc, ToInt(value));  
             else if ("cutoff2_curve" == key_cc) pCurDef->cutoff2_curvecc.set(num_cc, ToInt(value));  
             else if ("resonance_on" == key_cc) pCurDef->resonance_oncc.set(num_cc, ToInt(value));  
             else if ("resonance2_on" == key_cc) pCurDef->resonance2_oncc.set(num_cc, ToInt(value));  
             else if ("resonance_smooth" == key_cc) pCurDef->resonance_smoothcc.set(num_cc, ToInt(value));  
             else if ("resonance2_smooth" == key_cc) pCurDef->resonance2_smoothcc.set(num_cc, ToInt(value));  
             else if ("resonance_step" == key_cc) pCurDef->resonance_stepcc.set(num_cc, ToInt(value));  
             else if ("resonance2_step" == key_cc) pCurDef->resonance2_stepcc.set(num_cc, ToInt(value));  
             else if ("resonance_curve" == key_cc) pCurDef->resonance_curvecc.set(num_cc, ToInt(value));  
             else if ("resonance2_curve" == key_cc) pCurDef->resonance2_curvecc.set(num_cc, ToInt(value));  
   
             // per voice equalizer  
             else if ("eq1_freq_on" == key_cc || "eq1_freq" == key_cc) pCurDef->eq1_freq_oncc.set(num_cc, ToInt(value));  
             else if ("eq2_freq_on" == key_cc || "eq2_freq" == key_cc) pCurDef->eq2_freq_oncc.set(num_cc, ToInt(value));  
             else if ("eq3_freq_on" == key_cc || "eq3_freq" == key_cc) pCurDef->eq3_freq_oncc.set(num_cc, ToInt(value));  
             else if ("eq1_bw_on" == key_cc || "eq1_bw" == key_cc) pCurDef->eq1_bw_oncc.set(num_cc, ToInt(value));  
             else if ("eq2_bw_on" == key_cc || "eq2_bw" == key_cc) pCurDef->eq2_bw_oncc.set(num_cc, ToInt(value));  
             else if ("eq3_bw_on" == key_cc || "eq3_bw" == key_cc) pCurDef->eq3_bw_oncc.set(num_cc, ToInt(value));  
             else if ("eq1_gain_on" == key_cc || "eq1_gain" == key_cc) pCurDef->eq1_gain_oncc.set(num_cc, ToInt(value));  
             else if ("eq2_gain_on" == key_cc || "eq2_gain" == key_cc) pCurDef->eq2_gain_oncc.set(num_cc, ToInt(value));  
             else if ("eq3_gain_on" == key_cc || "eq3_gain" == key_cc) pCurDef->eq3_gain_oncc.set(num_cc, ToInt(value));  
             else std::cerr << "The opcode '" << key << "' is unsupported by libsfz!" << std::endl;  
         }  
1280          // v2 envelope generators          // v2 envelope generators
1281          else if (sscanf(key.c_str(), "eg%d%n", &x, &y)) {          else if (sscanf(key.c_str(), "eg%d%n", &x, &y)) {
1282              const char* s = key.c_str() + y;              const char* s = key.c_str() + y;
1283              if (sscanf(s, "_time%d", &y)) egnode(x, y).time = ToFloat(value);              if (sscanf(s, "_time%d%n", &y, &z)) {
1284              else if (sscanf(s, "_level%d", &y)) egnode(x, y).level = ToFloat(value);                  const char* s2 = s + z;
1285                    if (strcmp(s2, "") == 0) egnode(x, y).time = check(key, 0.0f, 100.0f, ToFloat(value));
1286                    else if (sscanf(s2, "_oncc%d", &z)) egnode(x, y).time_oncc.add( CC(z, check(key, 0.0f, 100.0f, ToFloat(value))) );
1287                } else if (sscanf(s, "_level%d%n", &y, &z)) {
1288                    const char* s2 = s + z;
1289                    if (strcmp(s2, "") == 0) egnode(x, y).level = check(key, 0.0f, 1.0f, ToFloat(value));
1290                    else if (sscanf(s2, "_oncc%d", &z)) egnode(x, y).level_oncc.add( CC(z, check(key, 0.0f, 1.0f, ToFloat(value))) );
1291                }
1292              else if (sscanf(s, "_shape%d", &y)) egnode(x, y).shape = ToFloat(value);              else if (sscanf(s, "_shape%d", &y)) egnode(x, y).shape = ToFloat(value);
1293              else if (sscanf(s, "_curve%d", &y)) egnode(x, y).curve = ToFloat(value);              else if (sscanf(s, "_curve%d", &y)) egnode(x, y).curve = ToFloat(value);
1294              else if (strcmp(s, "_sustain") == 0) eg(x).sustain = ToInt(value);              else if (strcmp(s, "_sustain") == 0) eg(x).sustain = ToInt(value);
# Line 1294  namespace sfz Line 1320  namespace sfz
1320          else if ("fileg_decay"   == key) pCurDef->fileg_decay = ToFloat(value);          else if ("fileg_decay"   == key) pCurDef->fileg_decay = ToFloat(value);
1321          else if ("fileg_sustain"   == key) pCurDef->fileg_sustain = ToFloat(value);          else if ("fileg_sustain"   == key) pCurDef->fileg_sustain = ToFloat(value);
1322          else if ("fileg_release"   == key) pCurDef->fileg_release = ToFloat(value);          else if ("fileg_release"   == key) pCurDef->fileg_release = ToFloat(value);
1323            else if ("fileg_depth"   == key) pCurDef->fileg_depth = check(key, -12000, 12000, ToInt(value));
1324            else if ("fileg_vel2delay"   == key) pCurDef->fileg_vel2delay = check(key, -100.0f, 100.0f, ToFloat(value));
1325            else if ("fileg_vel2attack"  == key) pCurDef->fileg_vel2attack = ToFloat(value);
1326            else if ("fileg_vel2hold"    == key) pCurDef->fileg_vel2hold = ToFloat(value);
1327            else if ("fileg_vel2decay"   == key) pCurDef->fileg_vel2decay = ToFloat(value);
1328            else if ("fileg_vel2sustain" == key) pCurDef->fileg_vel2sustain = ToFloat(value);
1329            else if ("fileg_vel2release" == key) pCurDef->fileg_vel2release = ToFloat(value);
1330          else if ("pitcheg_delay"   == key) pCurDef->pitcheg_delay = ToFloat(value);          else if ("pitcheg_delay"   == key) pCurDef->pitcheg_delay = ToFloat(value);
1331          else if ("pitcheg_start"   == key) pCurDef->pitcheg_start = ToFloat(value);          else if ("pitcheg_start"   == key) pCurDef->pitcheg_start = ToFloat(value);
1332          else if ("pitcheg_attack"  == key) pCurDef->pitcheg_attack = ToFloat(value);          else if ("pitcheg_attack"  == key) pCurDef->pitcheg_attack = ToFloat(value);
# Line 1328  namespace sfz Line 1361  namespace sfz
1361          else if (sscanf(key.c_str(), "lfo%d%n", &x, &y)) {          else if (sscanf(key.c_str(), "lfo%d%n", &x, &y)) {
1362              const char* s = key.c_str() + y;              const char* s = key.c_str() + y;
1363              if (strcmp(s, "_freq") == 0) lfo(x).freq = check(key, 0.0f, 20.0f, ToFloat(value));              if (strcmp(s, "_freq") == 0) lfo(x).freq = check(key, 0.0f, 20.0f, ToFloat(value));
1364                else if (sscanf(s, "_freq_oncc%d", &y)) lfo(x).freq_oncc.add( CC(y, check(key, 0.0f, 20.0f, ToFloat(value))) );
1365              else if (strcmp(s, "_wave") == 0) lfo(x).wave = ToInt(value);              else if (strcmp(s, "_wave") == 0) lfo(x).wave = ToInt(value);
1366              else if (strcmp(s, "_delay") == 0) lfo(x).delay = check(key, 0.0f, 100.0f, ToFloat(value));              else if (strcmp(s, "_delay") == 0) lfo(x).delay = check(key, 0.0f, 100.0f, ToFloat(value));
1367                else if (strcmp(s, "_fade") == 0) lfo(x).fade = check(key, 0.0f, 100.0f, ToFloat(value));
1368                else if (sscanf(s, "_fade_oncc%d", &y)) lfo(x).fade_oncc.add( CC(y, check(key, 0.0f, 100.0f, ToFloat(value))) );
1369                else if (strcmp(s, "_phase") == 0) lfo(x).phase = check(key, 0.0f, 360.0f, ToFloat(value));
1370                else if (sscanf(s, "_phase_oncc%d", &y)) lfo(x).phase_oncc.add( CC(y, check(key, 0.0f, 360.0f, ToFloat(value))) );
1371              else if (strcmp(s, "_volume") == 0) lfo(x).volume = check(key, -144.0f, 6.0f, ToFloat(value));              else if (strcmp(s, "_volume") == 0) lfo(x).volume = check(key, -144.0f, 6.0f, ToFloat(value));
1372              else if (strcmp(s, "_pitch") == 0) lfo(x).pitch = check(key, -9600, 9600, ToInt(value));              else if (strcmp(s, "_pitch") == 0) lfo(x).pitch = check(key, -9600, 9600, ToInt(value));
1373                else if (sscanf(s, "_pitch_oncc%d", &y)) lfo(x).pitch_oncc.add( CC(y, check(key, -9600, 9600, ToInt(value))) );
1374              else if (strcmp(s, "_cutoff") == 0) lfo(x).cutoff = check(key, -9600, 9600, ToInt(value));              else if (strcmp(s, "_cutoff") == 0) lfo(x).cutoff = check(key, -9600, 9600, ToInt(value));
1375              else if (strcmp(s, "_resonance") == 0) lfo(x).resonance = check(key, 0.0f, 40.0f, ToFloat(value));              else if (strcmp(s, "_resonance") == 0) lfo(x).resonance = check(key, 0.0f, 40.0f, ToFloat(value));
1376              else if (strcmp(s, "_pan") == 0) lfo(x).pan = check(key, -100.0f, 100.0f, ToFloat(value));              else if (strcmp(s, "_pan") == 0) lfo(x).pan = check(key, -100.0f, 100.0f, ToFloat(value));
1377              else std::cerr << "The opcode '" << key << "' is unsupported by libsfz!" << std::endl;              else std::cerr << "The opcode '" << key << "' is unsupported by libsfz!" << std::endl;
1378          }          }
1379            
1380            // CCs
1381            else if (key.find("cc") != std::string::npos)
1382            {
1383                std::string::size_type delimiter_index = key.find("cc");
1384                std::string key_cc = key.substr(0, delimiter_index);
1385                int num_cc = ToInt(key.substr(delimiter_index + 2));
1386    
1387                // input controls
1388                if ("lo" == key_cc) pCurDef->locc.set(num_cc, ToInt(value));
1389                else if ("hi" == key_cc) pCurDef->hicc.set(num_cc, ToInt(value));
1390                else if ("start_lo" == key_cc) pCurDef->start_locc.set(num_cc, ToInt(value));
1391                else if ("start_hi" == key_cc) pCurDef->start_hicc.set(num_cc, ToInt(value));
1392                else if ("stop_lo" == key_cc) pCurDef->stop_locc.set(num_cc, ToInt(value));
1393                else if ("stop_hi" == key_cc) pCurDef->stop_hicc.set(num_cc, ToInt(value));
1394                else if ("on_lo" == key_cc) pCurDef->on_locc.set(num_cc, ToInt(value));
1395                else if ("on_hi" == key_cc) pCurDef->on_hicc.set(num_cc, ToInt(value));
1396    
1397                // sample player
1398                else if ("delay_on" == key_cc) pCurDef->delay_oncc.set(num_cc, ToFloat(value));
1399                else if ("delay_samples_on" == key_cc) pCurDef->delay_samples_oncc.set(num_cc, ToInt(value));
1400                else if ("offset_on" == key_cc) pCurDef->offset_oncc.set(num_cc, ToInt(value));
1401    
1402                // amplifier
1403                else if ("gain_on"  == key_cc || "gain_" == key_cc) pCurDef->gain_oncc.set(num_cc, ToFloat(value));
1404                else if ("xfin_lo"  == key_cc) pCurDef->xfin_locc.set(num_cc, ToInt(value));
1405                else if ("xfin_hi"  == key_cc) pCurDef->xfin_hicc.set(num_cc, ToInt(value));
1406                else if ("xfout_lo" == key_cc) pCurDef->xfout_locc.set(num_cc, ToInt(value));
1407                else if ("xfout_hi" == key_cc) pCurDef->xfout_hicc.set(num_cc, ToInt(value));
1408    
1409                // filter
1410                else if ("cutoff_on"  == key_cc || "cutoff_" == key_cc) {
1411                    pCurDef->cutoff_oncc.set(num_cc, ToInt(value));
1412                    pCurDef->cutoff_cc = num_cc;
1413                } else if ("cutoff2_on" == key_cc) pCurDef->cutoff2_oncc.set(num_cc, ToInt(value));
1414                else if ("cutoff_smooth"  == key_cc) pCurDef->cutoff_smoothcc.set(num_cc, ToInt(value));
1415                else if ("cutoff2_smooth" == key_cc) pCurDef->cutoff2_smoothcc.set(num_cc, ToInt(value));
1416                else if ("cutoff_step"  == key_cc) pCurDef->cutoff_stepcc.set(num_cc, ToInt(value));
1417                else if ("cutoff2_step" == key_cc) pCurDef->cutoff2_stepcc.set(num_cc, ToInt(value));
1418                else if ("cutoff_curve" == key_cc) pCurDef->cutoff_curvecc.set(num_cc, ToInt(value));
1419                else if ("cutoff2_curve" == key_cc) pCurDef->cutoff2_curvecc.set(num_cc, ToInt(value));
1420                else if ("resonance_on" == key_cc) pCurDef->resonance_oncc.set(num_cc, ToInt(value));
1421                else if ("resonance2_on" == key_cc) pCurDef->resonance2_oncc.set(num_cc, ToInt(value));
1422                else if ("resonance_smooth" == key_cc) pCurDef->resonance_smoothcc.set(num_cc, ToInt(value));
1423                else if ("resonance2_smooth" == key_cc) pCurDef->resonance2_smoothcc.set(num_cc, ToInt(value));
1424                else if ("resonance_step" == key_cc) pCurDef->resonance_stepcc.set(num_cc, ToInt(value));
1425                else if ("resonance2_step" == key_cc) pCurDef->resonance2_stepcc.set(num_cc, ToInt(value));
1426                else if ("resonance_curve" == key_cc) pCurDef->resonance_curvecc.set(num_cc, ToInt(value));
1427                else if ("resonance2_curve" == key_cc) pCurDef->resonance2_curvecc.set(num_cc, ToInt(value));
1428    
1429                // per voice equalizer
1430                else if ("eq1_freq_on" == key_cc || "eq1_freq" == key_cc) pCurDef->eq1_freq_oncc.set(num_cc, ToInt(value));
1431                else if ("eq2_freq_on" == key_cc || "eq2_freq" == key_cc) pCurDef->eq2_freq_oncc.set(num_cc, ToInt(value));
1432                else if ("eq3_freq_on" == key_cc || "eq3_freq" == key_cc) pCurDef->eq3_freq_oncc.set(num_cc, ToInt(value));
1433                else if ("eq1_bw_on" == key_cc || "eq1_bw" == key_cc) pCurDef->eq1_bw_oncc.set(num_cc, ToInt(value));
1434                else if ("eq2_bw_on" == key_cc || "eq2_bw" == key_cc) pCurDef->eq2_bw_oncc.set(num_cc, ToInt(value));
1435                else if ("eq3_bw_on" == key_cc || "eq3_bw" == key_cc) pCurDef->eq3_bw_oncc.set(num_cc, ToInt(value));
1436                else if ("eq1_gain_on" == key_cc || "eq1_gain" == key_cc) pCurDef->eq1_gain_oncc.set(num_cc, ToInt(value));
1437                else if ("eq2_gain_on" == key_cc || "eq2_gain" == key_cc) pCurDef->eq2_gain_oncc.set(num_cc, ToInt(value));
1438                else if ("eq3_gain_on" == key_cc || "eq3_gain" == key_cc) pCurDef->eq3_gain_oncc.set(num_cc, ToInt(value));
1439                
1440                else if ("ampeg_delay"   == key_cc) pCurDef->ampeg_delaycc.add( CC(num_cc, check(key, -100.0f, 100.0f, ToFloat(value))) );
1441                else if ("ampeg_start"   == key_cc) pCurDef->ampeg_startcc.add( CC(num_cc, check(key, -100.0f, 100.0f, ToFloat(value))) );
1442                else if ("ampeg_attack"  == key_cc) pCurDef->ampeg_attackcc.add( CC(num_cc, check(key, -100.0f, 100.0f, ToFloat(value))) );
1443                else if ("ampeg_hold"    == key_cc) pCurDef->ampeg_holdcc.add( CC(num_cc, check(key, -100.0f, 100.0f, ToFloat(value))) );
1444                else if ("ampeg_decay"   == key_cc) pCurDef->ampeg_decaycc.add( CC(num_cc, check(key, -100.0f, 100.0f, ToFloat(value))) );
1445                else if ("ampeg_sustain" == key_cc) pCurDef->ampeg_sustaincc.add( CC(num_cc, check(key, -100.0f, 100.0f, ToFloat(value))) );
1446                else if ("ampeg_release" == key_cc) pCurDef->ampeg_releasecc.add( CC(num_cc, check(key, -100.0f, 100.0f, ToFloat(value))) );
1447                
1448                else if ("pitchlfo_depth" == key_cc) pCurDef->pitchlfo_depthcc.set(num_cc, ToInt(value));
1449                else if ("pitchlfo_freq" == key_cc) pCurDef->pitchlfo_freqcc.add( CC(num_cc, check(key, -200.0f, 200.0f, ToFloat(value))) );
1450                else if ("fillfo_freq" == key_cc) pCurDef->fillfo_freqcc.add( CC(num_cc, check(key, -200.0f, 200.0f, ToFloat(value))) );
1451                else if ("amplfo_freq" == key_cc) pCurDef->amplfo_freqcc.add( CC(num_cc, check(key, -200.0f, 200.0f, ToFloat(value))) );
1452                else if ("volume_on" == key_cc) pCurDef->volume_oncc.add( CC(num_cc, check(key, -100.0f, 100.0f, ToFloat(value))) );
1453                else if ("volume_curve" == key_cc) pCurDef->volume_curvecc.add( CC(num_cc, 0, check(key, 0, 30000, ToInt(value))) );
1454                else std::cerr << "The opcode '" << key << "' is unsupported by libsfz!" << std::endl;
1455            }
1456    
1457          else {          else {
1458              std::cerr << "The opcode '" << key << "' is unsupported by libsfz!" << std::endl;              std::cerr << "The opcode '" << key << "' is unsupported by libsfz!" << std::endl;
# Line 1381  namespace sfz Line 1497  namespace sfz
1497    
1498      EGNode::EGNode() : time(0), level(0), shape(0), curve(0) {      EGNode::EGNode() : time(0), level(0), shape(0), curve(0) {
1499      }      }
1500        
1501        void EGNode::Copy(const EGNode& egNode) {
1502            time  = egNode.time;
1503            level = egNode.level;
1504            shape = egNode.shape;
1505            curve = egNode.curve;
1506            
1507            time_oncc = egNode.time_oncc;
1508            level_oncc = egNode.level_oncc;
1509        }
1510    
1511      EG::EG() :      EG::EG() :
1512          sustain(0), loop(0), loop_count(0),          sustain(0), loop(0), loop_count(0),
1513          amplitude(0), cutoff(0) {          amplitude(0), cutoff(0) {
1514      }      }
1515        
1516        void EG::Copy(const EG& eg) {
1517            sustain    = eg.sustain;
1518            loop       = eg.loop;
1519            loop_count = eg.loop_count;
1520            amplitude  = eg.amplitude;
1521            cutoff     = eg.cutoff;
1522            node       = eg.node;
1523        }
1524        
1525        LFO::LFO(): freq (-1),/* -1 is used to determine whether the LFO was initialized */
1526                    fade(0), phase(0), wave(0), delay(0), pitch(0), cutoff(0), resonance(0), pan(0) {
1527            
1528        }
1529        
1530        void LFO::Copy(const LFO& lfo) {
1531            delay      = lfo.delay;
1532            freq       = lfo.freq;
1533            fade       = lfo.fade;
1534            phase      = lfo.phase;
1535            wave       = lfo.wave;
1536            volume     = lfo.volume;
1537            pitch      = lfo.pitch;
1538            cutoff     = lfo.cutoff;
1539            resonance  = lfo.resonance;
1540            pan        = lfo.pan;
1541            freq_oncc  = lfo.freq_oncc;
1542            fade_oncc  = lfo.fade_oncc;
1543            phase_oncc = lfo.phase_oncc;
1544            pitch_oncc = lfo.pitch_oncc;
1545        }
1546    
1547      EG& File::eg(int x) {      EG& File::eg(int x) {
1548          while (pCurDef->eg.size() <= x) {          while (pCurDef->eg.size() <= x) {
# Line 1401  namespace sfz Line 1558  namespace sfz
1558          }          }
1559          return e.node[y];          return e.node[y];
1560      }      }
       
     LFO::LFO(): freq (-1),/* -1 is used to determine whether the LFO was initialized */  
                 wave(0), delay(0), pitch(0), cutoff(0), resonance(0), pan(0) {  
           
     }  
1561    
1562      LFO& File::lfo(int x) {      LFO& File::lfo(int x) {
1563          while (pCurDef->lfos.size() <= x) {          while (pCurDef->lfos.size() <= x) {

Legend:
Removed from v.2221  
changed lines
  Added in v.2230

  ViewVC Help
Powered by ViewVC