/[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 2226 by iliev, Wed Aug 3 09:12:09 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 492  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 702  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 739  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;
# Line 751  namespace sfz Line 770  namespace sfz
770          region->pitchlfo_depth   = pitchlfo_depth;          region->pitchlfo_depth   = pitchlfo_depth;
771                    
772          region->pitchlfo_depthcc = pitchlfo_depthcc;          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 923  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 936  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 961  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 977  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 1108  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 1142  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 1220  namespace sfz Line 1280  namespace sfz
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 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));              else if (strcmp(s, "_fade") == 0) lfo(x).fade = check(key, 0.0f, 100.0f, ToFloat(value));
# Line 1308  namespace sfz Line 1376  namespace sfz
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          // CCs
1381          else if (key.find("cc") != std::string::npos)          else if (key.find("cc") != std::string::npos)
1382          {          {
# Line 1368  namespace sfz Line 1436  namespace sfz
1436              else if ("eq1_gain_on" == key_cc || "eq1_gain" == key_cc) pCurDef->eq1_gain_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));
1437              else if ("eq2_gain_on" == key_cc || "eq2_gain" == key_cc) pCurDef->eq2_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));
1438              else if ("eq3_gain_on" == key_cc || "eq3_gain" == key_cc) pCurDef->eq3_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));
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));              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;              else std::cerr << "The opcode '" << key << "' is unsupported by libsfz!" << std::endl;
1455          }          }
1456    
# Line 1415  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 1435  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 */  
                 fade(0), phase(0), 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.2226  
changed lines
  Added in v.2230

  ViewVC Help
Powered by ViewVC