/[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 2218 by iliev, Thu Jul 28 08:05:57 2011 UTC revision 2231 by iliev, Sun Aug 7 14:27:24 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 315  namespace sfz Line 322  namespace sfz
322    
323          // amplifier          // amplifier
324          volume = 0;          volume = 0;
325            volume_oncc.clear();
326            volume_curvecc.clear();
327          pan = 0;          pan = 0;
328          width = 100;          width = 100;
329          position = 0;          position = 0;
# Line 435  namespace sfz Line 444  namespace sfz
444              eq1_gain_oncc.set(i, 0);              eq1_gain_oncc.set(i, 0);
445              eq2_gain_oncc.set(i, 0);              eq2_gain_oncc.set(i, 0);
446              eq3_gain_oncc.set(i, 0);              eq3_gain_oncc.set(i, 0);
447                
448                pitchlfo_depthcc.set(i, 0);
449          }          }
450          cutoff_cc = 0;          cutoff_cc = 0;
451    
452          eg.clear();          eg.clear();
453            lfos.clear();
454    
455          // deprecated          // deprecated
456          ampeg_delay    = 0;          ampeg_delay    = 0;
# Line 455  namespace sfz Line 467  namespace sfz
467          ampeg_vel2decay   = 0;          ampeg_vel2decay   = 0;
468          ampeg_vel2sustain = 0;          ampeg_vel2sustain = 0;
469          ampeg_vel2release = 0;          ampeg_vel2release = 0;
470            
471            ampeg_delaycc.clear();
472            ampeg_startcc.clear();
473            ampeg_attackcc.clear();
474            ampeg_holdcc.clear();
475            ampeg_decaycc.clear();
476            ampeg_sustaincc.clear();
477            ampeg_releasecc.clear();
478    
479          fileg_delay    = 0;          fileg_delay    = 0;
480          fileg_start    = 0; //in percentage          fileg_start    = 0; //in percentage
# Line 464  namespace sfz Line 484  namespace sfz
484          fileg_sustain  = 100; // in percentage          fileg_sustain  = 100; // in percentage
485          fileg_release  = 0;          fileg_release  = 0;
486    
487            fileg_vel2delay   = 0;
488            fileg_vel2attack  = 0;
489            fileg_vel2hold    = 0;
490            fileg_vel2decay   = 0;
491            fileg_vel2sustain = 0;
492            fileg_vel2release = 0;
493            fileg_depth       = 0;
494    
495          pitcheg_delay    = 0;          pitcheg_delay    = 0;
496          pitcheg_start    = 0; //in percentage          pitcheg_start    = 0; //in percentage
497          pitcheg_attack   = 0;          pitcheg_attack   = 0;
# Line 471  namespace sfz Line 499  namespace sfz
499          pitcheg_decay    = 0;          pitcheg_decay    = 0;
500          pitcheg_sustain  = 100; // in percentage          pitcheg_sustain  = 100; // in percentage
501          pitcheg_release  = 0;          pitcheg_release  = 0;
502            pitcheg_depth    = 0;
503    
504            pitcheg_vel2delay   = 0;
505            pitcheg_vel2attack  = 0;
506            pitcheg_vel2hold    = 0;
507            pitcheg_vel2decay   = 0;
508            pitcheg_vel2sustain = 0;
509            pitcheg_vel2release = 0;
510    
511          amplfo_delay     = 0;          amplfo_delay     = 0;
512          amplfo_fade      = 0;          amplfo_fade      = 0;
513          amplfo_freq      = 0;          amplfo_freq      = -1; /* -1 is used to determine whether the LFO was initialized */
514          amplfo_depth     = 0;          amplfo_depth     = 0;
515            amplfo_freqcc.clear();
516    
517          fillfo_delay     = 0;          fillfo_delay     = 0;
518          fillfo_fade      = 0;          fillfo_fade      = 0;
519          fillfo_freq      = 0;          fillfo_freq      = -1; /* -1 is used to determine whether the LFO was initialized */
520          fillfo_depth     = 0;          fillfo_depth     = 0;
521            fillfo_freqcc.clear();
522    
523          pitchlfo_delay   = 0;          pitchlfo_delay   = 0;
524          pitchlfo_fade    = 0;          pitchlfo_fade    = 0;
525          pitchlfo_freq    = 0;          pitchlfo_freq    = -1; /* -1 is used to determine whether the LFO was initialized */
526          pitchlfo_depth   = 0;          pitchlfo_depth   = 0;
527            pitchlfo_freqcc.clear();
528      }      }
529    
530      Region*      Region*
# Line 565  namespace sfz Line 604  namespace sfz
604    
605          // amplifier          // amplifier
606          region->volume = volume;          region->volume = volume;
607            region->volume_oncc = volume_oncc;
608            region->volume_curvecc = volume_curvecc;
609          region->pan = pan;          region->pan = pan;
610          region->width = width;          region->width = width;
611          region->position = position;          region->position = position;
# Line 684  namespace sfz Line 725  namespace sfz
725          region->ampeg_vel2decay   = ampeg_vel2decay;          region->ampeg_vel2decay   = ampeg_vel2decay;
726          region->ampeg_vel2sustain = ampeg_vel2sustain;          region->ampeg_vel2sustain = ampeg_vel2sustain;
727          region->ampeg_vel2release = ampeg_vel2release;          region->ampeg_vel2release = ampeg_vel2release;
728            
729            region->ampeg_delaycc   = ampeg_delaycc;
730            region->ampeg_startcc   = ampeg_startcc;
731            region->ampeg_attackcc  = ampeg_attackcc;
732            region->ampeg_holdcc    = ampeg_holdcc;
733            region->ampeg_decaycc   = ampeg_decaycc;
734            region->ampeg_sustaincc = ampeg_sustaincc;
735            region->ampeg_releasecc = ampeg_releasecc;
736    
737          region->fileg_delay    = fileg_delay;          region->fileg_delay    = fileg_delay;
738          region->fileg_start    = fileg_start;          region->fileg_start    = fileg_start;
# Line 692  namespace sfz Line 741  namespace sfz
741          region->fileg_decay    = fileg_decay;          region->fileg_decay    = fileg_decay;
742          region->fileg_sustain  = fileg_sustain;          region->fileg_sustain  = fileg_sustain;
743          region->fileg_release  = fileg_release;          region->fileg_release  = fileg_release;
744            region->fileg_depth    = fileg_depth;
745    
746            region->fileg_vel2delay   = fileg_vel2delay;
747            region->fileg_vel2attack  = fileg_vel2attack;
748            region->fileg_vel2hold    = fileg_vel2hold;
749            region->fileg_vel2decay   = fileg_vel2decay;
750            region->fileg_vel2sustain = fileg_vel2sustain;
751            region->fileg_vel2release = fileg_vel2release;
752    
753          region->pitcheg_delay    = pitcheg_delay;          region->pitcheg_delay    = pitcheg_delay;
754          region->pitcheg_start    = pitcheg_start;          region->pitcheg_start    = pitcheg_start;
# Line 700  namespace sfz Line 757  namespace sfz
757          region->pitcheg_decay    = pitcheg_decay;          region->pitcheg_decay    = pitcheg_decay;
758          region->pitcheg_sustain  = pitcheg_sustain;          region->pitcheg_sustain  = pitcheg_sustain;
759          region->pitcheg_release  = pitcheg_release;          region->pitcheg_release  = pitcheg_release;
760            region->pitcheg_depth    = pitcheg_depth;
761    
762            region->pitcheg_vel2delay   = pitcheg_vel2delay;
763            region->pitcheg_vel2attack  = pitcheg_vel2attack;
764            region->pitcheg_vel2hold    = pitcheg_vel2hold;
765            region->pitcheg_vel2decay   = pitcheg_vel2decay;
766            region->pitcheg_vel2sustain = pitcheg_vel2sustain;
767            region->pitcheg_vel2release = pitcheg_vel2release;
768    
769          region->amplfo_delay     = amplfo_delay;          region->amplfo_delay     = amplfo_delay;
770          region->amplfo_fade      = amplfo_fade;          region->amplfo_fade      = amplfo_fade;
771          region->amplfo_freq      = amplfo_freq;          region->amplfo_freq      = amplfo_freq;
772          region->amplfo_depth     = amplfo_depth;          region->amplfo_depth     = amplfo_depth;
773            
774            region->amplfo_freqcc    = amplfo_freqcc;
775    
776          region->fillfo_delay     = fillfo_delay;          region->fillfo_delay     = fillfo_delay;
777          region->fillfo_fade      = fillfo_fade;          region->fillfo_fade      = fillfo_fade;
778          region->fillfo_freq      = fillfo_freq;          region->fillfo_freq      = fillfo_freq;
779          region->fillfo_depth     = fillfo_depth;          region->fillfo_depth     = fillfo_depth;
780            
781            region->fillfo_freqcc    = fillfo_freqcc;
782    
783          region->pitchlfo_delay   = pitchlfo_delay;          region->pitchlfo_delay   = pitchlfo_delay;
784          region->pitchlfo_fade    = pitchlfo_fade;          region->pitchlfo_fade    = pitchlfo_fade;
785          region->pitchlfo_freq    = pitchlfo_freq;          region->pitchlfo_freq    = pitchlfo_freq;
786          region->pitchlfo_depth   = pitchlfo_depth;          region->pitchlfo_depth   = pitchlfo_depth;
787            
788            region->pitchlfo_depthcc = pitchlfo_depthcc;
789            region->pitchlfo_freqcc  = pitchlfo_freqcc;
790            
791            region->eg = eg;
792            region->lfos = lfos;
793    
794          return region;          return region;
795      }      }
# Line 887  namespace sfz Line 962  namespace sfz
962          for (int i = 0 ; i < 128 ; i++) {          for (int i = 0 ; i < 128 ; i++) {
963              _instrument->pLookupTableCC[i] = new LookupTable(_instrument, i);              _instrument->pLookupTableCC[i] = new LookupTable(_instrument, i);
964          }          }
965            
966            for (int k = 0; k < _instrument->regions.size(); k++) {
967                Region* r = _instrument->regions[k];
968                
969                copyCurves(r->volume_curvecc, r->volume_oncc);
970                
971                r->volume_curvecc.clear();
972            }
973      }      }
974    
975      File::~File()      File::~File()
# Line 900  namespace sfz Line 983  namespace sfz
983      {      {
984          return _instrument;          return _instrument;
985      }      }
986        
987        void File::copyCurves(LinuxSampler::ArrayList<CC>& curves, LinuxSampler::ArrayList<CC>& dest) {
988            for (int i = 0; i < curves.size(); i++) {
989                for (int j = 0; j < dest.size(); j++) {
990                    if (curves[i].Controller == dest[j].Controller) {
991                        dest[j].Curve = curves[i].Curve;
992                    }
993                }
994            }
995        }
996    
997      void      void
998      File::push_header(std::string token)      File::push_header(std::string token)
# Line 925  namespace sfz Line 1018  namespace sfz
1018              octave_offset = 0;              octave_offset = 0;
1019              note_offset = 0;              note_offset = 0;
1020          }          }
1021            else if (token == "<curve>")
1022            {
1023                _current_section = CURVE;
1024                _instrument->curves.add(Curve());
1025                _current_curve = &_instrument->curves[_instrument->curves.size() - 1];
1026            }
1027          else          else
1028          {          {
1029              _current_section = UNKNOWN;              _current_section = UNKNOWN;
# Line 941  namespace sfz Line 1040  namespace sfz
1040          std::string::size_type delimiter_index = token.find('=');          std::string::size_type delimiter_index = token.find('=');
1041          std::string key = token.substr(0, delimiter_index);          std::string key = token.substr(0, delimiter_index);
1042          std::string value = token.substr(delimiter_index + 1);          std::string value = token.substr(delimiter_index + 1);
1043          int x, y;          int x, y, z;
1044            
1045            if (_current_section == CURVE) {
1046                if (sscanf(key.c_str(), "v%d", &x)) {
1047                    if (x < 0 || x > 127) {
1048                        std::cerr << "Invalid curve index: " << x << std::endl;
1049                    }
1050                    _current_curve->v[x] = check(key, 0.0f, 1.0f, ToFloat(value));
1051                } else {
1052                    std::cerr << "The opcode '" << key << "' in section <curve> is unsupported by libsfz!" << std::endl;
1053                }
1054                
1055                return;
1056            }
1057    
1058          // sample definition          // sample definition
1059          if ("sample" == key)          if ("sample" == key)
# Line 1072  namespace sfz Line 1184  namespace sfz
1184          else if ("amp_keycenter" == key) pCurDef->amp_keycenter = parseKey(value);          else if ("amp_keycenter" == key) pCurDef->amp_keycenter = parseKey(value);
1185          else if ("amp_veltrack"  == key) pCurDef->amp_veltrack = ToFloat(value);          else if ("amp_veltrack"  == key) pCurDef->amp_veltrack = ToFloat(value);
1186          else if ("amp_random"  == key) pCurDef->amp_random = ToFloat(value);          else if ("amp_random"  == key) pCurDef->amp_random = ToFloat(value);
1187          else if ("rt_decay"    == key) pCurDef->rt_decay = ToFloat(value);          else if ("rt_decay" == key || "rtdecay" == key) pCurDef->rt_decay = ToFloat(value);
1188          else if ("xfin_lokey"  == key) pCurDef->xfin_lokey = parseKey(value);          else if ("xfin_lokey"  == key) pCurDef->xfin_lokey = parseKey(value);
1189          else if ("xfin_hikey"  == key) pCurDef->xfin_hikey = parseKey(value);          else if ("xfin_hikey"  == key) pCurDef->xfin_hikey = parseKey(value);
1190          else if ("xfout_lokey" == key) pCurDef->xfout_lokey = parseKey(value);          else if ("xfout_lokey" == key) pCurDef->xfout_lokey = parseKey(value);
# Line 1106  namespace sfz Line 1218  namespace sfz
1218          else if ("pitch_random" == key) pCurDef->pitch_random = ToInt(value);          else if ("pitch_random" == key) pCurDef->pitch_random = ToInt(value);
1219          else if ("bend_up" == key || "bendup" == key) pCurDef->bend_up = ToInt(value);          else if ("bend_up" == key || "bendup" == key) pCurDef->bend_up = ToInt(value);
1220          else if ("bend_down" == key || "benddown" == key) pCurDef->bend_down = ToInt(value);          else if ("bend_down" == key || "benddown" == key) pCurDef->bend_down = ToInt(value);
1221          else if ("bend_step" == key) pCurDef->bend_step = ToInt(value);          else if ("bend_step" == key || "bendstep" == key) pCurDef->bend_step = ToInt(value);
1222    
1223          // filter          // filter
1224          else if ("fil_type" == key || "filtype" == key)          else if ("fil_type" == key || "filtype" == key)
# Line 1180  namespace sfz Line 1292  namespace sfz
1292          else if (sscanf(key.c_str(), "amp_velcurve_%d", &x)) {          else if (sscanf(key.c_str(), "amp_velcurve_%d", &x)) {
1293              pCurDef->amp_velcurve.set(x, ToFloat(value));              pCurDef->amp_velcurve.set(x, ToFloat(value));
1294          }          }
1295            
         // 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;  
         }  
1296          // v2 envelope generators          // v2 envelope generators
1297          else if (sscanf(key.c_str(), "eg%d%n", &x, &y)) {          else if (sscanf(key.c_str(), "eg%d%n", &x, &y)) {
1298              const char* s = key.c_str() + y;              const char* s = key.c_str() + y;
1299              if (sscanf(s, "_time%d", &y)) egnode(x, y).time = ToFloat(value);              if (sscanf(s, "_time%d%n", &y, &z)) {
1300              else if (sscanf(s, "_level%d", &y)) egnode(x, y).level = ToFloat(value);                  const char* s2 = s + z;
1301                    if (strcmp(s2, "") == 0) egnode(x, y).time = check(key, 0.0f, 100.0f, ToFloat(value));
1302                    else if (sscanf(s2, "_oncc%d", &z)) egnode(x, y).time_oncc.add( CC(z, check(key, 0.0f, 100.0f, ToFloat(value))) );
1303                } else if (sscanf(s, "_level%d%n", &y, &z)) {
1304                    const char* s2 = s + z;
1305                    if (strcmp(s2, "") == 0) egnode(x, y).level = check(key, 0.0f, 1.0f, ToFloat(value));
1306                    else if (sscanf(s2, "_oncc%d", &z)) egnode(x, y).level_oncc.add( CC(z, check(key, 0.0f, 1.0f, ToFloat(value))) );
1307                }
1308              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);
1309              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);
1310              else if (strcmp(s, "_sustain") == 0) eg(x).sustain = ToInt(value);              else if (strcmp(s, "_sustain") == 0) eg(x).sustain = ToInt(value);
# Line 1278  namespace sfz Line 1336  namespace sfz
1336          else if ("fileg_decay"   == key) pCurDef->fileg_decay = ToFloat(value);          else if ("fileg_decay"   == key) pCurDef->fileg_decay = ToFloat(value);
1337          else if ("fileg_sustain"   == key) pCurDef->fileg_sustain = ToFloat(value);          else if ("fileg_sustain"   == key) pCurDef->fileg_sustain = ToFloat(value);
1338          else if ("fileg_release"   == key) pCurDef->fileg_release = ToFloat(value);          else if ("fileg_release"   == key) pCurDef->fileg_release = ToFloat(value);
1339            else if ("fileg_depth"   == key) pCurDef->fileg_depth = check(key, -12000, 12000, ToInt(value));
1340            else if ("fileg_vel2delay"   == key) pCurDef->fileg_vel2delay = check(key, -100.0f, 100.0f, ToFloat(value));
1341            else if ("fileg_vel2attack"  == key) pCurDef->fileg_vel2attack = ToFloat(value);
1342            else if ("fileg_vel2hold"    == key) pCurDef->fileg_vel2hold = ToFloat(value);
1343            else if ("fileg_vel2decay"   == key) pCurDef->fileg_vel2decay = ToFloat(value);
1344            else if ("fileg_vel2sustain" == key) pCurDef->fileg_vel2sustain = ToFloat(value);
1345            else if ("fileg_vel2release" == key) pCurDef->fileg_vel2release = ToFloat(value);
1346          else if ("pitcheg_delay"   == key) pCurDef->pitcheg_delay = ToFloat(value);          else if ("pitcheg_delay"   == key) pCurDef->pitcheg_delay = ToFloat(value);
1347          else if ("pitcheg_start"   == key) pCurDef->pitcheg_start = ToFloat(value);          else if ("pitcheg_start"   == key) pCurDef->pitcheg_start = ToFloat(value);
1348          else if ("pitcheg_attack"   == key) pCurDef->pitcheg_attack = ToFloat(value);          else if ("pitcheg_attack"  == key) pCurDef->pitcheg_attack = ToFloat(value);
1349          else if ("pitcheg_hold"   == key) pCurDef->pitcheg_hold = ToFloat(value);          else if ("pitcheg_hold"    == key) pCurDef->pitcheg_hold = ToFloat(value);
1350          else if ("pitcheg_decay"   == key) pCurDef->pitcheg_decay = ToFloat(value);          else if ("pitcheg_decay"   == key) pCurDef->pitcheg_decay = ToFloat(value);
1351          else if ("pitcheg_sustain"   == key) pCurDef->pitcheg_sustain = ToFloat(value);          else if ("pitcheg_sustain" == key) pCurDef->pitcheg_sustain = ToFloat(value);
1352          else if ("pitcheg_release"   == key) pCurDef->pitcheg_release = ToFloat(value);          else if ("pitcheg_release" == key) pCurDef->pitcheg_release = ToFloat(value);
1353            else if ("pitcheg_depth"   == key) pCurDef->pitcheg_depth = check(key, -12000, 12000, ToInt(value));
1354            else if ("pitcheg_vel2delay"   == key) pCurDef->pitcheg_vel2delay = check(key, -100.0f, 100.0f, ToFloat(value));
1355            else if ("pitcheg_vel2attack"  == key) pCurDef->pitcheg_vel2attack = ToFloat(value);
1356            else if ("pitcheg_vel2hold"    == key) pCurDef->pitcheg_vel2hold = ToFloat(value);
1357            else if ("pitcheg_vel2decay"   == key) pCurDef->pitcheg_vel2decay = ToFloat(value);
1358            else if ("pitcheg_vel2sustain" == key) pCurDef->pitcheg_vel2sustain = ToFloat(value);
1359            else if ("pitcheg_vel2release" == key) pCurDef->pitcheg_vel2release = ToFloat(value);
1360            
1361    
1362          // v1 LFO          // v1 LFO
1363          else if ("amplfo_delay" == key) pCurDef->amplfo_delay = ToFloat(value);          else if ("amplfo_delay" == key) pCurDef->amplfo_delay = ToFloat(value);
# Line 1304  namespace sfz Line 1377  namespace sfz
1377          else if (sscanf(key.c_str(), "lfo%d%n", &x, &y)) {          else if (sscanf(key.c_str(), "lfo%d%n", &x, &y)) {
1378              const char* s = key.c_str() + y;              const char* s = key.c_str() + y;
1379              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));
1380                else if (sscanf(s, "_freq_oncc%d", &y)) lfo(x).freq_oncc.add( CC(y, check(key, 0.0f, 20.0f, ToFloat(value))) );
1381              else if (strcmp(s, "_wave") == 0) lfo(x).wave = ToInt(value);              else if (strcmp(s, "_wave") == 0) lfo(x).wave = ToInt(value);
1382              else if (strcmp(s, "_delay") == 0) lfo(x).delay = check(key, 0.0f, 100.0f, ToFloat(value));              else if (strcmp(s, "_delay") == 0) lfo(x).delay = check(key, 0.0f, 100.0f, ToFloat(value));
1383                else if (strcmp(s, "_fade") == 0) lfo(x).fade = check(key, 0.0f, 100.0f, ToFloat(value));
1384                else if (sscanf(s, "_fade_oncc%d", &y)) lfo(x).fade_oncc.add( CC(y, check(key, 0.0f, 100.0f, ToFloat(value))) );
1385                else if (strcmp(s, "_phase") == 0) lfo(x).phase = check(key, 0.0f, 360.0f, ToFloat(value));
1386                else if (sscanf(s, "_phase_oncc%d", &y)) lfo(x).phase_oncc.add( CC(y, check(key, 0.0f, 360.0f, ToFloat(value))) );
1387                else if (strcmp(s, "_volume") == 0) lfo(x).volume = check(key, -144.0f, 6.0f, ToFloat(value));
1388              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));
1389                else if (sscanf(s, "_pitch_oncc%d", &y)) lfo(x).pitch_oncc.add( CC(y, check(key, -9600, 9600, ToInt(value))) );
1390              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));
1391              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));
1392              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));
1393              else std::cerr << "The opcode '" << key << "' is unsupported by libsfz!" << std::endl;              else std::cerr << "The opcode '" << key << "' is unsupported by libsfz!" << std::endl;
1394          }          }
1395            
1396            // CCs
1397            else if (key.find("cc") != std::string::npos)
1398            {
1399                std::string::size_type delimiter_index = key.find("cc");
1400                std::string key_cc = key.substr(0, delimiter_index);
1401                int num_cc = ToInt(key.substr(delimiter_index + 2));
1402    
1403                // input controls
1404                if ("lo" == key_cc) pCurDef->locc.set(num_cc, ToInt(value));
1405                else if ("hi" == key_cc) pCurDef->hicc.set(num_cc, ToInt(value));
1406                else if ("start_lo" == key_cc) pCurDef->start_locc.set(num_cc, ToInt(value));
1407                else if ("start_hi" == key_cc) pCurDef->start_hicc.set(num_cc, ToInt(value));
1408                else if ("stop_lo" == key_cc) pCurDef->stop_locc.set(num_cc, ToInt(value));
1409                else if ("stop_hi" == key_cc) pCurDef->stop_hicc.set(num_cc, ToInt(value));
1410                else if ("on_lo" == key_cc) pCurDef->on_locc.set(num_cc, ToInt(value));
1411                else if ("on_hi" == key_cc) pCurDef->on_hicc.set(num_cc, ToInt(value));
1412    
1413                // sample player
1414                else if ("delay_on" == key_cc) pCurDef->delay_oncc.set(num_cc, ToFloat(value));
1415                else if ("delay_samples_on" == key_cc) pCurDef->delay_samples_oncc.set(num_cc, ToInt(value));
1416                else if ("offset_on" == key_cc) pCurDef->offset_oncc.set(num_cc, ToInt(value));
1417    
1418                // amplifier
1419                else if ("gain_on"  == key_cc || "gain_" == key_cc) pCurDef->gain_oncc.set(num_cc, ToFloat(value));
1420                else if ("xfin_lo"  == key_cc) pCurDef->xfin_locc.set(num_cc, ToInt(value));
1421                else if ("xfin_hi"  == key_cc) pCurDef->xfin_hicc.set(num_cc, ToInt(value));
1422                else if ("xfout_lo" == key_cc) pCurDef->xfout_locc.set(num_cc, ToInt(value));
1423                else if ("xfout_hi" == key_cc) pCurDef->xfout_hicc.set(num_cc, ToInt(value));
1424    
1425                // filter
1426                else if ("cutoff_on"  == key_cc || "cutoff_" == key_cc) {
1427                    pCurDef->cutoff_oncc.set(num_cc, ToInt(value));
1428                    pCurDef->cutoff_cc = num_cc;
1429                } else if ("cutoff2_on" == key_cc) pCurDef->cutoff2_oncc.set(num_cc, ToInt(value));
1430                else if ("cutoff_smooth"  == key_cc) pCurDef->cutoff_smoothcc.set(num_cc, ToInt(value));
1431                else if ("cutoff2_smooth" == key_cc) pCurDef->cutoff2_smoothcc.set(num_cc, ToInt(value));
1432                else if ("cutoff_step"  == key_cc) pCurDef->cutoff_stepcc.set(num_cc, ToInt(value));
1433                else if ("cutoff2_step" == key_cc) pCurDef->cutoff2_stepcc.set(num_cc, ToInt(value));
1434                else if ("cutoff_curve" == key_cc) pCurDef->cutoff_curvecc.set(num_cc, ToInt(value));
1435                else if ("cutoff2_curve" == key_cc) pCurDef->cutoff2_curvecc.set(num_cc, ToInt(value));
1436                else if ("resonance_on" == key_cc) pCurDef->resonance_oncc.set(num_cc, ToInt(value));
1437                else if ("resonance2_on" == key_cc) pCurDef->resonance2_oncc.set(num_cc, ToInt(value));
1438                else if ("resonance_smooth" == key_cc) pCurDef->resonance_smoothcc.set(num_cc, ToInt(value));
1439                else if ("resonance2_smooth" == key_cc) pCurDef->resonance2_smoothcc.set(num_cc, ToInt(value));
1440                else if ("resonance_step" == key_cc) pCurDef->resonance_stepcc.set(num_cc, ToInt(value));
1441                else if ("resonance2_step" == key_cc) pCurDef->resonance2_stepcc.set(num_cc, ToInt(value));
1442                else if ("resonance_curve" == key_cc) pCurDef->resonance_curvecc.set(num_cc, ToInt(value));
1443                else if ("resonance2_curve" == key_cc) pCurDef->resonance2_curvecc.set(num_cc, ToInt(value));
1444    
1445                // per voice equalizer
1446                else if ("eq1_freq_on" == key_cc || "eq1_freq" == key_cc) pCurDef->eq1_freq_oncc.set(num_cc, ToInt(value));
1447                else if ("eq2_freq_on" == key_cc || "eq2_freq" == key_cc) pCurDef->eq2_freq_oncc.set(num_cc, ToInt(value));
1448                else if ("eq3_freq_on" == key_cc || "eq3_freq" == key_cc) pCurDef->eq3_freq_oncc.set(num_cc, ToInt(value));
1449                else if ("eq1_bw_on" == key_cc || "eq1_bw" == key_cc) pCurDef->eq1_bw_oncc.set(num_cc, ToInt(value));
1450                else if ("eq2_bw_on" == key_cc || "eq2_bw" == key_cc) pCurDef->eq2_bw_oncc.set(num_cc, ToInt(value));
1451                else if ("eq3_bw_on" == key_cc || "eq3_bw" == key_cc) pCurDef->eq3_bw_oncc.set(num_cc, ToInt(value));
1452                else if ("eq1_gain_on" == key_cc || "eq1_gain" == key_cc) pCurDef->eq1_gain_oncc.set(num_cc, ToInt(value));
1453                else if ("eq2_gain_on" == key_cc || "eq2_gain" == key_cc) pCurDef->eq2_gain_oncc.set(num_cc, ToInt(value));
1454                else if ("eq3_gain_on" == key_cc || "eq3_gain" == key_cc) pCurDef->eq3_gain_oncc.set(num_cc, ToInt(value));
1455                
1456                else if ("ampeg_delay"   == key_cc) pCurDef->ampeg_delaycc.add( CC(num_cc, check(key, -100.0f, 100.0f, ToFloat(value))) );
1457                else if ("ampeg_start"   == key_cc) pCurDef->ampeg_startcc.add( CC(num_cc, check(key, -100.0f, 100.0f, ToFloat(value))) );
1458                else if ("ampeg_attack"  == key_cc) pCurDef->ampeg_attackcc.add( CC(num_cc, check(key, -100.0f, 100.0f, ToFloat(value))) );
1459                else if ("ampeg_hold"    == key_cc) pCurDef->ampeg_holdcc.add( CC(num_cc, check(key, -100.0f, 100.0f, ToFloat(value))) );
1460                else if ("ampeg_decay"   == key_cc) pCurDef->ampeg_decaycc.add( CC(num_cc, check(key, -100.0f, 100.0f, ToFloat(value))) );
1461                else if ("ampeg_sustain" == key_cc) pCurDef->ampeg_sustaincc.add( CC(num_cc, check(key, -100.0f, 100.0f, ToFloat(value))) );
1462                else if ("ampeg_release" == key_cc) pCurDef->ampeg_releasecc.add( CC(num_cc, check(key, -100.0f, 100.0f, ToFloat(value))) );
1463                
1464                else if ("pitchlfo_depth" == key_cc) pCurDef->pitchlfo_depthcc.set(num_cc, ToInt(value));
1465                else if ("pitchlfo_freq" == key_cc) pCurDef->pitchlfo_freqcc.add( CC(num_cc, check(key, -200.0f, 200.0f, ToFloat(value))) );
1466                else if ("fillfo_freq" == key_cc) pCurDef->fillfo_freqcc.add( CC(num_cc, check(key, -200.0f, 200.0f, ToFloat(value))) );
1467                else if ("amplfo_freq" == key_cc) pCurDef->amplfo_freqcc.add( CC(num_cc, check(key, -200.0f, 200.0f, ToFloat(value))) );
1468                else if ("volume_on" == key_cc) pCurDef->volume_oncc.add( CC(num_cc, check(key, -100.0f, 100.0f, ToFloat(value))) );
1469                else if ("volume_curve" == key_cc) pCurDef->volume_curvecc.add( CC(num_cc, 0, check(key, 0, 30000, ToInt(value))) );
1470                else std::cerr << "The opcode '" << key << "' is unsupported by libsfz!" << std::endl;
1471            }
1472    
1473          else {          else {
1474              std::cerr << "The opcode '" << key << "' is unsupported by libsfz!" << std::endl;              std::cerr << "The opcode '" << key << "' is unsupported by libsfz!" << std::endl;
# Line 1356  namespace sfz Line 1513  namespace sfz
1513    
1514      EGNode::EGNode() : time(0), level(0), shape(0), curve(0) {      EGNode::EGNode() : time(0), level(0), shape(0), curve(0) {
1515      }      }
1516        
1517        void EGNode::Copy(const EGNode& egNode) {
1518            time  = egNode.time;
1519            level = egNode.level;
1520            shape = egNode.shape;
1521            curve = egNode.curve;
1522            
1523            time_oncc = egNode.time_oncc;
1524            level_oncc = egNode.level_oncc;
1525        }
1526    
1527      EG::EG() :      EG::EG() :
1528          sustain(0), loop(0), loop_count(0),          sustain(0), loop(0), loop_count(0),
1529          amplitude(0), cutoff(0) {          amplitude(0), cutoff(0) {
1530      }      }
1531        
1532        void EG::Copy(const EG& eg) {
1533            sustain    = eg.sustain;
1534            loop       = eg.loop;
1535            loop_count = eg.loop_count;
1536            amplitude  = eg.amplitude;
1537            cutoff     = eg.cutoff;
1538            node       = eg.node;
1539        }
1540        
1541        LFO::LFO(): freq (-1),/* -1 is used to determine whether the LFO was initialized */
1542                    fade(0), phase(0), wave(0), delay(0), pitch(0), cutoff(0), resonance(0), pan(0) {
1543            
1544        }
1545        
1546        void LFO::Copy(const LFO& lfo) {
1547            delay      = lfo.delay;
1548            freq       = lfo.freq;
1549            fade       = lfo.fade;
1550            phase      = lfo.phase;
1551            wave       = lfo.wave;
1552            volume     = lfo.volume;
1553            pitch      = lfo.pitch;
1554            cutoff     = lfo.cutoff;
1555            resonance  = lfo.resonance;
1556            pan        = lfo.pan;
1557            freq_oncc  = lfo.freq_oncc;
1558            fade_oncc  = lfo.fade_oncc;
1559            phase_oncc = lfo.phase_oncc;
1560            pitch_oncc = lfo.pitch_oncc;
1561        }
1562    
1563      EG& File::eg(int x) {      EG& File::eg(int x) {
1564          while (pCurDef->eg.size() <= x) {          while (pCurDef->eg.size() <= x) {
# Line 1376  namespace sfz Line 1574  namespace sfz
1574          }          }
1575          return e.node[y];          return e.node[y];
1576      }      }
       
     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) {  
           
     }  
1577    
1578      LFO& File::lfo(int x) {      LFO& File::lfo(int x) {
1579          while (pCurDef->lfos.size() <= x) {          while (pCurDef->lfos.size() <= x) {

Legend:
Removed from v.2218  
changed lines
  Added in v.2231

  ViewVC Help
Powered by ViewVC