/[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 2229 by iliev, Thu Aug 4 19:02:36 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 494  namespace sfz Line 512  namespace sfz
512          amplfo_fade      = 0;          amplfo_fade      = 0;
513          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 */
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      = -1; /* -1 is used to determine whether the LFO was initialized */          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    = -1; /* -1 is used to determine whether the LFO was initialized */          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 939  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 952  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 977  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 994  namespace sfz Line 1041  namespace sfz
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, z;          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 1332  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 1405  namespace sfz Line 1465  namespace sfz
1465              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))) );
1466              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))) );
1467              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))) );
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 1475  namespace sfz Line 1537  namespace sfz
1537          cutoff     = eg.cutoff;          cutoff     = eg.cutoff;
1538          node       = eg.node;          node       = eg.node;
1539      }      }
   
     EG& File::eg(int x) {  
         while (pCurDef->eg.size() <= x) {  
             pCurDef->eg.add(EG());  
         }  
         return pCurDef->eg[x];  
     }  
   
     EGNode& File::egnode(int x, int y) {  
         EG& e = eg(x);  
         while (e.node.size() <= y) {  
             e.node.add(EGNode());  
         }  
         return e.node[y];  
     }  
1540            
1541      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 */
1542                  fade(0), phase(0), wave(0), delay(0), pitch(0), cutoff(0), resonance(0), pan(0) {                  fade(0), phase(0), wave(0), delay(0), pitch(0), cutoff(0), resonance(0), pan(0) {
# Line 1513  namespace sfz Line 1560  namespace sfz
1560          pitch_oncc = lfo.pitch_oncc;          pitch_oncc = lfo.pitch_oncc;
1561      }      }
1562    
1563        EG& File::eg(int x) {
1564            while (pCurDef->eg.size() <= x) {
1565                pCurDef->eg.add(EG());
1566            }
1567            return pCurDef->eg[x];
1568        }
1569    
1570        EGNode& File::egnode(int x, int y) {
1571            EG& e = eg(x);
1572            while (e.node.size() <= y) {
1573                e.node.add(EGNode());
1574            }
1575            return e.node[y];
1576        }
1577    
1578      LFO& File::lfo(int x) {      LFO& File::lfo(int x) {
1579          while (pCurDef->lfos.size() <= x) {          while (pCurDef->lfos.size() <= x) {
1580              pCurDef->lfos.add(LFO());              pCurDef->lfos.add(LFO());

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

  ViewVC Help
Powered by ViewVC