/[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 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 441  namespace sfz Line 450  namespace sfz
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 457  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 492  namespace sfz Line 510  namespace sfz
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 583  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 702  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 739  namespace sfz Line 770  namespace sfz
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;
# Line 751  namespace sfz Line 786  namespace sfz
786          region->pitchlfo_depth   = pitchlfo_depth;          region->pitchlfo_depth   = pitchlfo_depth;
787                    
788          region->pitchlfo_depthcc = pitchlfo_depthcc;          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 923  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 936  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 961  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 977  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 1108  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 1142  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 1220  namespace sfz Line 1296  namespace sfz
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 1294  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));              else if (strcmp(s, "_fade") == 0) lfo(x).fade = check(key, 0.0f, 100.0f, ToFloat(value));
# Line 1308  namespace sfz Line 1392  namespace sfz
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          // CCs
1397          else if (key.find("cc") != std::string::npos)          else if (key.find("cc") != std::string::npos)
1398          {          {
# Line 1368  namespace sfz Line 1452  namespace sfz
1452              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));
1453              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));
1454              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));
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));              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;              else std::cerr << "The opcode '" << key << "' is unsupported by libsfz!" << std::endl;
1471          }          }
1472    
# Line 1415  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 1435  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 */  
                 fade(0), phase(0), 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.2226  
changed lines
  Added in v.2231

  ViewVC Help
Powered by ViewVC