/[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 2232 by iliev, Mon Aug 8 13:40:04 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            volume_smoothcc.clear();
328          pan = 0;          pan = 0;
329          width = 100;          width = 100;
330          position = 0;          position = 0;
# Line 441  namespace sfz Line 451  namespace sfz
451          cutoff_cc = 0;          cutoff_cc = 0;
452    
453          eg.clear();          eg.clear();
454            lfos.clear();
455    
456          // deprecated          // deprecated
457          ampeg_delay    = 0;          ampeg_delay    = 0;
# Line 457  namespace sfz Line 468  namespace sfz
468          ampeg_vel2decay   = 0;          ampeg_vel2decay   = 0;
469          ampeg_vel2sustain = 0;          ampeg_vel2sustain = 0;
470          ampeg_vel2release = 0;          ampeg_vel2release = 0;
471            
472            ampeg_delaycc.clear();
473            ampeg_startcc.clear();
474            ampeg_attackcc.clear();
475            ampeg_holdcc.clear();
476            ampeg_decaycc.clear();
477            ampeg_sustaincc.clear();
478            ampeg_releasecc.clear();
479    
480          fileg_delay    = 0;          fileg_delay    = 0;
481          fileg_start    = 0; //in percentage          fileg_start    = 0; //in percentage
# Line 494  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_freqcc.clear();
517    
518          fillfo_delay     = 0;          fillfo_delay     = 0;
519          fillfo_fade      = 0;          fillfo_fade      = 0;
520          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 */
521          fillfo_depth     = 0;          fillfo_depth     = 0;
522            fillfo_freqcc.clear();
523    
524          pitchlfo_delay   = 0;          pitchlfo_delay   = 0;
525          pitchlfo_fade    = 0;          pitchlfo_fade    = 0;
526          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 */
527          pitchlfo_depth   = 0;          pitchlfo_depth   = 0;
528            pitchlfo_freqcc.clear();
529      }      }
530    
531      Region*      Region*
# Line 583  namespace sfz Line 605  namespace sfz
605    
606          // amplifier          // amplifier
607          region->volume = volume;          region->volume = volume;
608            region->volume_oncc = volume_oncc;
609            region->volume_curvecc = volume_curvecc;
610            region->volume_smoothcc = volume_smoothcc;
611          region->pan = pan;          region->pan = pan;
612          region->width = width;          region->width = width;
613          region->position = position;          region->position = position;
# Line 939  namespace sfz Line 964  namespace sfz
964          for (int i = 0 ; i < 128 ; i++) {          for (int i = 0 ; i < 128 ; i++) {
965              _instrument->pLookupTableCC[i] = new LookupTable(_instrument, i);              _instrument->pLookupTableCC[i] = new LookupTable(_instrument, i);
966          }          }
967            
968            for (int k = 0; k < _instrument->regions.size(); k++) {
969                Region* r = _instrument->regions[k];
970                
971                copyCurves(r->volume_curvecc, r->volume_oncc);
972                copySmoothValues(r->volume_smoothcc, r->volume_oncc);
973                
974                r->volume_curvecc.clear();
975                r->volume_smoothcc.clear();
976            }
977      }      }
978    
979      File::~File()      File::~File()
# Line 952  namespace sfz Line 987  namespace sfz
987      {      {
988          return _instrument;          return _instrument;
989      }      }
990        
991        void File::copyCurves(LinuxSampler::ArrayList<CC>& curves, LinuxSampler::ArrayList<CC>& dest) {
992            for (int i = 0; i < curves.size(); i++) {
993                for (int j = 0; j < dest.size(); j++) {
994                    if (curves[i].Controller == dest[j].Controller) {
995                        dest[j].Curve = curves[i].Curve;
996                    }
997                }
998            }
999        }
1000        
1001        void File::copySmoothValues(LinuxSampler::ArrayList<CC>& smooths, LinuxSampler::ArrayList<CC>& dest) {
1002            for (int i = 0; i < smooths.size(); i++) {
1003                for (int j = 0; j < dest.size(); j++) {
1004                    if (smooths[i].Controller == dest[j].Controller) {
1005                        dest[j].Smooth = smooths[i].Smooth;
1006                    }
1007                }
1008            }
1009        }
1010    
1011      void      void
1012      File::push_header(std::string token)      File::push_header(std::string token)
# Line 977  namespace sfz Line 1032  namespace sfz
1032              octave_offset = 0;              octave_offset = 0;
1033              note_offset = 0;              note_offset = 0;
1034          }          }
1035            else if (token == "<curve>")
1036            {
1037                _current_section = CURVE;
1038                _instrument->curves.add(Curve());
1039                _current_curve = &_instrument->curves[_instrument->curves.size() - 1];
1040            }
1041          else          else
1042          {          {
1043              _current_section = UNKNOWN;              _current_section = UNKNOWN;
# Line 994  namespace sfz Line 1055  namespace sfz
1055          std::string key = token.substr(0, delimiter_index);          std::string key = token.substr(0, delimiter_index);
1056          std::string value = token.substr(delimiter_index + 1);          std::string value = token.substr(delimiter_index + 1);
1057          int x, y, z;          int x, y, z;
1058            
1059            if (_current_section == CURVE) {
1060                if (sscanf(key.c_str(), "v%d", &x)) {
1061                    if (x < 0 || x > 127) {
1062                        std::cerr << "Invalid curve index: " << x << std::endl;
1063                    }
1064                    _current_curve->v[x] = check(key, 0.0f, 1.0f, ToFloat(value));
1065                } else {
1066                    std::cerr << "The opcode '" << key << "' in section <curve> is unsupported by libsfz!" << std::endl;
1067                }
1068                
1069                return;
1070            }
1071    
1072          // sample definition          // sample definition
1073          if ("sample" == key)          if ("sample" == key)
# Line 1332  namespace sfz Line 1406  namespace sfz
1406              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));
1407              else std::cerr << "The opcode '" << key << "' is unsupported by libsfz!" << std::endl;              else std::cerr << "The opcode '" << key << "' is unsupported by libsfz!" << std::endl;
1408          }          }
1409            
1410          // CCs          // CCs
1411          else if (key.find("cc") != std::string::npos)          else if (key.find("cc") != std::string::npos)
1412          {          {
# Line 1405  namespace sfz Line 1479  namespace sfz
1479              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))) );
1480              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))) );
1481              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))) );
1482                else if ("volume_on" == key_cc) pCurDef->volume_oncc.add( CC(num_cc, check(key, -100.0f, 100.0f, ToFloat(value))) );
1483                else if ("volume_curve" == key_cc) pCurDef->volume_curvecc.add( CC(num_cc, 0, check(key, 0, 30000, ToInt(value))) );
1484                else if ("volume_smooth" == key_cc) pCurDef->volume_smoothcc.add( CC(num_cc, 0, -1, check(key, 0.0f, 100000.0f /* max? */, ToFloat(value))) );
1485              else std::cerr << "The opcode '" << key << "' is unsupported by libsfz!" << std::endl;              else std::cerr << "The opcode '" << key << "' is unsupported by libsfz!" << std::endl;
1486          }          }
1487    
# Line 1475  namespace sfz Line 1552  namespace sfz
1552          cutoff     = eg.cutoff;          cutoff     = eg.cutoff;
1553          node       = eg.node;          node       = eg.node;
1554      }      }
   
     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];  
     }  
1555            
1556      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 */
1557                  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 1575  namespace sfz
1575          pitch_oncc = lfo.pitch_oncc;          pitch_oncc = lfo.pitch_oncc;
1576      }      }
1577    
1578        EG& File::eg(int x) {
1579            while (pCurDef->eg.size() <= x) {
1580                pCurDef->eg.add(EG());
1581            }
1582            return pCurDef->eg[x];
1583        }
1584    
1585        EGNode& File::egnode(int x, int y) {
1586            EG& e = eg(x);
1587            while (e.node.size() <= y) {
1588                e.node.add(EGNode());
1589            }
1590            return e.node[y];
1591        }
1592    
1593      LFO& File::lfo(int x) {      LFO& File::lfo(int x) {
1594          while (pCurDef->lfos.size() <= x) {          while (pCurDef->lfos.size() <= x) {
1595              pCurDef->lfos.add(LFO());              pCurDef->lfos.add(LFO());

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

  ViewVC Help
Powered by ViewVC