/[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 2235 by iliev, Wed Aug 10 19:40:39 2011 UTC revision 2248 by iliev, Fri Aug 19 15:51:18 2011 UTC
# Line 31  Line 31 
31    
32  #include "../../common/File.h"  #include "../../common/File.h"
33  #include "../../common/Path.h"  #include "../../common/Path.h"
 #include "../../common/global_private.h"  
34  #include "LookupTable.h"  #include "LookupTable.h"
35    
36  namespace sfz  namespace sfz
# Line 324  namespace sfz Line 323  namespace sfz
323          volume_curvecc.clear();          volume_curvecc.clear();
324          volume_smoothcc.clear();          volume_smoothcc.clear();
325          pan = 0;          pan = 0;
326            pan_oncc.clear();
327            pan_curvecc.clear();
328            pan_smoothcc.clear();
329          width = 100;          width = 100;
330          position = 0;          position = 0;
331          amp_keytrack = 0;          amp_keytrack = 0;
# Line 411  namespace sfz Line 413  namespace sfz
413              gain_oncc.set(i, 0);              gain_oncc.set(i, 0);
414              xfin_locc.set(i, 0);              xfin_locc.set(i, 0);
415              xfin_hicc.set(i, 0);              xfin_hicc.set(i, 0);
416              xfout_locc.set(i, 127);              xfout_locc.set(i, 0);
417              xfout_hicc.set(i, 127);              xfout_hicc.set(i, 0);
418    
419              // filter              // filter
420              cutoff_oncc.set(i, 0);              cutoff_oncc.set(i, 0);
# Line 511  namespace sfz Line 513  namespace sfz
513          amplfo_fade      = 0;          amplfo_fade      = 0;
514          amplfo_freq      = -1; /* -1 is used to determine whether the LFO was initialized */          amplfo_freq      = -1; /* -1 is used to determine whether the LFO was initialized */
515          amplfo_depth     = 0;          amplfo_depth     = 0;
516            amplfo_delay_oncc.clear();
517            amplfo_fade_oncc.clear();
518          amplfo_depthcc.clear();          amplfo_depthcc.clear();
519          amplfo_freqcc.clear();          amplfo_freqcc.clear();
520    
# Line 518  namespace sfz Line 522  namespace sfz
522          fillfo_fade      = 0;          fillfo_fade      = 0;
523          fillfo_freq      = -1; /* -1 is used to determine whether the LFO was initialized */          fillfo_freq      = -1; /* -1 is used to determine whether the LFO was initialized */
524          fillfo_depth     = 0;          fillfo_depth     = 0;
525            fillfo_delay_oncc.clear();
526            fillfo_fade_oncc.clear();
527          fillfo_depthcc.clear();          fillfo_depthcc.clear();
528          fillfo_freqcc.clear();          fillfo_freqcc.clear();
529    
# Line 525  namespace sfz Line 531  namespace sfz
531          pitchlfo_fade    = 0;          pitchlfo_fade    = 0;
532          pitchlfo_freq    = -1; /* -1 is used to determine whether the LFO was initialized */          pitchlfo_freq    = -1; /* -1 is used to determine whether the LFO was initialized */
533          pitchlfo_depth   = 0;          pitchlfo_depth   = 0;
534            pitchlfo_delay_oncc.clear();
535            pitchlfo_fade_oncc.clear();
536          pitchlfo_freqcc.clear();          pitchlfo_freqcc.clear();
537      }      }
538    
# Line 609  namespace sfz Line 617  namespace sfz
617          region->volume_curvecc = volume_curvecc;          region->volume_curvecc = volume_curvecc;
618          region->volume_smoothcc = volume_smoothcc;          region->volume_smoothcc = volume_smoothcc;
619          region->pan = pan;          region->pan = pan;
620            region->pan_oncc = pan_oncc;
621            region->pan_curvecc = pan_curvecc;
622            region->pan_smoothcc = pan_smoothcc;
623          region->width = width;          region->width = width;
624          region->position = position;          region->position = position;
625          region->amp_keytrack = amp_keytrack;          region->amp_keytrack = amp_keytrack;
# Line 773  namespace sfz Line 784  namespace sfz
784          region->amplfo_freq      = amplfo_freq;          region->amplfo_freq      = amplfo_freq;
785          region->amplfo_depth     = amplfo_depth;          region->amplfo_depth     = amplfo_depth;
786                    
787            region->amplfo_delay_oncc = amplfo_delay_oncc;
788            region->amplfo_fade_oncc  = amplfo_fade_oncc;
789          region->amplfo_depthcc   = amplfo_depthcc;          region->amplfo_depthcc   = amplfo_depthcc;
790          region->amplfo_freqcc    = amplfo_freqcc;          region->amplfo_freqcc    = amplfo_freqcc;
791    
# Line 781  namespace sfz Line 794  namespace sfz
794          region->fillfo_freq      = fillfo_freq;          region->fillfo_freq      = fillfo_freq;
795          region->fillfo_depth     = fillfo_depth;          region->fillfo_depth     = fillfo_depth;
796                    
797            region->fillfo_delay_oncc = fillfo_delay_oncc;
798            region->fillfo_fade_oncc  = fillfo_fade_oncc;
799          region->fillfo_depthcc   = fillfo_depthcc;          region->fillfo_depthcc   = fillfo_depthcc;
800          region->fillfo_freqcc    = fillfo_freqcc;          region->fillfo_freqcc    = fillfo_freqcc;
801    
# Line 789  namespace sfz Line 804  namespace sfz
804          region->pitchlfo_freq    = pitchlfo_freq;          region->pitchlfo_freq    = pitchlfo_freq;
805          region->pitchlfo_depth   = pitchlfo_depth;          region->pitchlfo_depth   = pitchlfo_depth;
806                    
807            region->pitchlfo_delay_oncc = pitchlfo_delay_oncc;
808            region->pitchlfo_fade_oncc  = pitchlfo_fade_oncc;
809          region->pitchlfo_depthcc = pitchlfo_depthcc;          region->pitchlfo_depthcc = pitchlfo_depthcc;
810          region->pitchlfo_freqcc  = pitchlfo_freqcc;          region->pitchlfo_freqcc  = pitchlfo_freqcc;
811                    
# Line 818  namespace sfz Line 835  namespace sfz
835          currentDir = LinuxSampler::Path::stripLastName(file);          currentDir = LinuxSampler::Path::stripLastName(file);
836          std::string token;          std::string token;
837          std::string line;          std::string line;
838            currentLine = 0;
839    
840          while (std::getline(fs, line))          while (std::getline(fs, line))
841          {          {
842                currentLine++;
843              // COMMENT              // COMMENT
844              std::string::size_type slash_index = line.find("//");              std::string::size_type slash_index = line.find("//");
845              if (slash_index != std::string::npos)              if (slash_index != std::string::npos)
# Line 976  namespace sfz Line 995  namespace sfz
995              copySmoothValues(r->volume_smoothcc, r->volume_oncc);              copySmoothValues(r->volume_smoothcc, r->volume_oncc);
996              r->volume_smoothcc.clear();              r->volume_smoothcc.clear();
997                            
998                copyCurves(r->pan_curvecc, r->pan_oncc);
999                r->pan_curvecc.clear();
1000                
1001                copySmoothValues(r->pan_smoothcc, r->pan_oncc);
1002                r->pan_smoothcc.clear();
1003                
1004                for (int j = 0; j < r->eg.size(); j++) {
1005                    copyCurves(r->eg[j].pan_curvecc, r->eg[j].pan_oncc);
1006                    r->eg[j].pan_curvecc.clear();
1007                }
1008                
1009              for (int j = 0; j < r->lfos.size(); j++) {              for (int j = 0; j < r->lfos.size(); j++) {
1010                  copySmoothValues(r->lfos[j].volume_smoothcc, r->lfos[j].volume_oncc);                  copySmoothValues(r->lfos[j].volume_smoothcc, r->lfos[j].volume_oncc);
1011                  r->lfos[j].volume_smoothcc.clear();                  r->lfos[j].volume_smoothcc.clear();
# Line 1029  namespace sfz Line 1059  namespace sfz
1059              }              }
1060          }          }
1061      }      }
1062        
1063        int File::ToInt(const std::string& s) throw(LinuxSampler::Exception) {
1064            int i;
1065            std::istringstream iss(s);
1066            if(!(iss >> i)) {
1067                std::ostringstream oss;
1068                oss << "Line " << currentLine << ": Expected an integer";
1069                throw LinuxSampler::Exception(oss.str());
1070            }
1071            return i;
1072        }
1073    
1074        float File::ToFloat(const std::string& s) throw(LinuxSampler::Exception) {
1075            float i;
1076            std::istringstream iss(s);
1077            if(!(iss >> i)) {
1078                std::ostringstream oss;
1079                oss << "Line " << currentLine << ": Expected a floating-point number";
1080                throw LinuxSampler::Exception(oss.str());
1081            }
1082            return i;
1083        }
1084    
1085      void      void
1086      File::push_header(std::string token)      File::push_header(std::string token)
# Line 1356  namespace sfz Line 1408  namespace sfz
1408              else if (sscanf(s, "_pitch_oncc%d", &y)) eg(x).pitch_oncc.add( CC(y, check(key, -9600, 9600, ToInt(value))) );              else if (sscanf(s, "_pitch_oncc%d", &y)) eg(x).pitch_oncc.add( CC(y, check(key, -9600, 9600, ToInt(value))) );
1409              else if (strcmp(s, "_resonance") == 0) eg(x).resonance = check(key, 0.0f, 40.0f, ToFloat(value));              else if (strcmp(s, "_resonance") == 0) eg(x).resonance = check(key, 0.0f, 40.0f, ToFloat(value));
1410              else if (sscanf(s, "_resonance_oncc%d", &y)) eg(x).resonance_oncc.add( CC(y, check(key, 0.0f, 40.0f, ToFloat(value))) );              else if (sscanf(s, "_resonance_oncc%d", &y)) eg(x).resonance_oncc.add( CC(y, check(key, 0.0f, 40.0f, ToFloat(value))) );
1411                else if (strcmp(s, "_pan") == 0) eg(x).pan = check(key, -100.0f, 100.0f, ToFloat(value));
1412                else if (strcmp(s, "_pan_curve") == 0) eg(x).pan_curve = check(key, 0, 30000, ToInt(value));
1413                else if (sscanf(s, "_pan_oncc%d", &y)) eg(x).pan_oncc.add( CC(y, check(key, -100.0f, 100.0f, ToFloat(value))) );
1414                else if (sscanf(s, "_pan_curvecc%d", &y)) eg(x).pan_curvecc.add( CC(y, 0.0f, check(key, 0, 30000, ToInt(value))) );
1415              else std::cerr << "The opcode '" << key << "' is unsupported by libsfz!" << std::endl;              else std::cerr << "The opcode '" << key << "' is unsupported by libsfz!" << std::endl;
1416          }          }
1417    
# Line 1516  namespace sfz Line 1572  namespace sfz
1572              else if ("ampeg_sustain" == key_cc) pCurDef->ampeg_sustaincc.add( CC(num_cc, check(key, -100.0f, 100.0f, ToFloat(value))) );              else if ("ampeg_sustain" == key_cc) pCurDef->ampeg_sustaincc.add( CC(num_cc, check(key, -100.0f, 100.0f, ToFloat(value))) );
1573              else if ("ampeg_release" == key_cc) pCurDef->ampeg_releasecc.add( CC(num_cc, check(key, -100.0f, 100.0f, ToFloat(value))) );              else if ("ampeg_release" == key_cc) pCurDef->ampeg_releasecc.add( CC(num_cc, check(key, -100.0f, 100.0f, ToFloat(value))) );
1574                            
1575                else if ("pitchlfo_delay_on" == key_cc) pCurDef->pitchlfo_delay_oncc.add( CC(num_cc, check(key, 0.0f, 100.0f, ToFloat(value))) );
1576                else if ("pitchlfo_fade_on" == key_cc) pCurDef->pitchlfo_fade_oncc.add( CC(num_cc, check(key, 0.0f, 100.0f, ToFloat(value))) );
1577              else if ("pitchlfo_depth" == key_cc) pCurDef->pitchlfo_depthcc.set(num_cc, ToInt(value));              else if ("pitchlfo_depth" == key_cc) pCurDef->pitchlfo_depthcc.set(num_cc, ToInt(value));
1578              else if ("pitchlfo_freq" == key_cc) pCurDef->pitchlfo_freqcc.add( CC(num_cc, check(key, -200.0f, 200.0f, ToFloat(value))) );              else if ("pitchlfo_freq" == key_cc) pCurDef->pitchlfo_freqcc.add( CC(num_cc, check(key, -200.0f, 200.0f, ToFloat(value))) );
1579                else if ("fillfo_delay_on" == key_cc) pCurDef->fillfo_delay_oncc.add( CC(num_cc, check(key, 0.0f, 100.0f, ToFloat(value))) );
1580                else if ("fillfo_fade_on" == key_cc) pCurDef->fillfo_fade_oncc.add( CC(num_cc, check(key, 0.0f, 100.0f, ToFloat(value))) );
1581              else if ("fillfo_depth" == key_cc) pCurDef->fillfo_depthcc.add( CC(num_cc, check(key, -1200, 1200, ToInt(value))) );              else if ("fillfo_depth" == key_cc) pCurDef->fillfo_depthcc.add( CC(num_cc, check(key, -1200, 1200, ToInt(value))) );
1582              else if ("fillfo_freq" == key_cc) pCurDef->fillfo_freqcc.add( CC(num_cc, check(key, -200.0f, 200.0f, ToFloat(value))) );              else if ("fillfo_freq" == key_cc) pCurDef->fillfo_freqcc.add( CC(num_cc, check(key, -200.0f, 200.0f, ToFloat(value))) );
1583                else if ("amplfo_delay_on" == key_cc) pCurDef->amplfo_delay_oncc.add( CC(num_cc, check(key, 0.0f, 100.0f, ToFloat(value))) );
1584                else if ("amplfo_fade_on" == key_cc) pCurDef->amplfo_fade_oncc.add( CC(num_cc, check(key, 0.0f, 100.0f, ToFloat(value))) );
1585              else if ("amplfo_depth" == key_cc) pCurDef->amplfo_depthcc.add( CC(num_cc, check(key, -10.0f, 10.0f, ToFloat(value))) );              else if ("amplfo_depth" == key_cc) pCurDef->amplfo_depthcc.add( CC(num_cc, check(key, -10.0f, 10.0f, ToFloat(value))) );
1586              else if ("amplfo_freq" == key_cc) pCurDef->amplfo_freqcc.add( CC(num_cc, check(key, -200.0f, 200.0f, ToFloat(value))) );              else if ("amplfo_freq" == key_cc) pCurDef->amplfo_freqcc.add( CC(num_cc, check(key, -200.0f, 200.0f, ToFloat(value))) );
1587              else if ("volume_on" == key_cc) pCurDef->volume_oncc.add( CC(num_cc, check(key, -100.0f, 100.0f, ToFloat(value))) );              else if ("volume_on" == key_cc) pCurDef->volume_oncc.add( CC(num_cc, check(key, -144.0f, 100.0f, ToFloat(value))) );
1588              else if ("volume_curve" == key_cc) pCurDef->volume_curvecc.add( CC(num_cc, 0, check(key, 0, 30000, ToInt(value))) );              else if ("volume_curve" == key_cc) pCurDef->volume_curvecc.add( CC(num_cc, 0, check(key, 0, 30000, ToInt(value))) );
1589              else if ("volume_smooth" == key_cc) pCurDef->volume_smoothcc.add( CC(num_cc, 0, -1, check(key, 0.0f, 100000.0f /* max? */, ToFloat(value))) );              else if ("volume_smooth" == key_cc) pCurDef->volume_smoothcc.add( CC(num_cc, 0, -1, check(key, 0.0f, 100000.0f /* max? */, ToFloat(value))) );
1590                else if ("pan_on" == key_cc) pCurDef->pan_oncc.add( CC(num_cc, check(key, -100.0f, 100.0f, ToFloat(value))) );
1591                else if ("pan_curve" == key_cc) pCurDef->pan_curvecc.add( CC(num_cc, 0, check(key, 0, 30000, ToInt(value))) );
1592                else if ("pan_smooth" == key_cc) pCurDef->pan_smoothcc.add( CC(num_cc, 0, -1, check(key, 0.0f, 100000.0f /* max? */, ToFloat(value))) );
1593              else std::cerr << "The opcode '" << key << "' is unsupported by libsfz!" << std::endl;              else std::cerr << "The opcode '" << key << "' is unsupported by libsfz!" << std::endl;
1594          }          }
1595    
# Line 1583  namespace sfz Line 1648  namespace sfz
1648      }      }
1649    
1650      EG::EG() :      EG::EG() :
1651          sustain(0), loop(0), loop_count(0), amplitude(0),          sustain(0), loop(0), loop_count(0), amplitude(0), pan(0), pan_curve(-1),
1652          cutoff(0), pitch(0), resonance(0), volume(-200) /* less than -144 dB is considered unset */          cutoff(0), pitch(0), resonance(0), volume(-200) /* less than -144 dB is considered unset */
1653      { }      { }
1654            
# Line 1596  namespace sfz Line 1661  namespace sfz
1661          cutoff     = eg.cutoff;          cutoff     = eg.cutoff;
1662          pitch      = eg.pitch;          pitch      = eg.pitch;
1663          resonance  = eg.resonance;          resonance  = eg.resonance;
1664            pan        = eg.pan;
1665            pan_curve  = eg.pan_curve;
1666          node       = eg.node;          node       = eg.node;
1667                    
1668          amplitude_oncc = eg.amplitude_oncc;          amplitude_oncc = eg.amplitude_oncc;
# Line 1603  namespace sfz Line 1670  namespace sfz
1670          cutoff_oncc    = eg.cutoff_oncc;          cutoff_oncc    = eg.cutoff_oncc;
1671          pitch_oncc     = eg.pitch_oncc;          pitch_oncc     = eg.pitch_oncc;
1672          resonance_oncc = eg.resonance_oncc;          resonance_oncc = eg.resonance_oncc;
1673            pan_oncc       = eg.pan_oncc;
1674            pan_curvecc    = eg.pan_curvecc;
1675      }      }
1676            
1677      LFO::LFO(): freq (-1),/* -1 is used to determine whether the LFO was initialized */      LFO::LFO(): freq (-1),/* -1 is used to determine whether the LFO was initialized */

Legend:
Removed from v.2235  
changed lines
  Added in v.2248

  ViewVC Help
Powered by ViewVC