/[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 2012 by iliev, Fri Oct 23 17:53:17 2009 UTC revision 2058 by persson, Sun Feb 14 11:40:49 2010 UTC
# Line 2  Line 2 
2   *                                                                         *   *                                                                         *
3   *   LinuxSampler - modular, streaming capable sampler                     *   *   LinuxSampler - modular, streaming capable sampler                     *
4   *                                                                         *   *                                                                         *
5   *   Copyright (C) 2008-2009 Anders Dahnielson <anders@dahnielson.com>     *   *   Copyright (C) 2008 Anders Dahnielson <anders@dahnielson.com>          *
6   *   Copyright (C) 2009 Grigor Iliev                                       *   *   Copyright (C) 2009 - 2010 Anders Dahnielson and Grigor Iliev          *
7   *                                                                         *   *                                                                         *
8   *   This program is free software; you can redistribute it and/or modify  *   *   This program is free software; you can redistribute it and/or modify  *
9   *   it under the terms of the GNU General Public License as published by  *   *   it under the terms of the GNU General Public License as published by  *
# Line 25  Line 25 
25    
26  #include <iostream>  #include <iostream>
27  #include <sstream>  #include <sstream>
28    #include <cctype>
29    #include <cstdio>
30    #include <cstring>
31    
32  #include "../../common/File.h"  #include "../../common/File.h"
33  #include "../../common/Path.h"  #include "../../common/Path.h"
# Line 33  Line 36 
36  namespace sfz  namespace sfz
37  {  {
38    
39      LinuxSampler::SampleFile* SampleManager::FindSample(std::string samplePath) {      Sample* SampleManager::FindSample(std::string samplePath) {
40          std::map<LinuxSampler::SampleFile*, std::set<Region*> >::iterator it = sampleMap.begin();          std::map<Sample*, std::set<Region*> >::iterator it = sampleMap.begin();
41          for (; it != sampleMap.end(); it++) {          for (; it != sampleMap.end(); it++) {
42              if (it->first->GetFile() == samplePath) return it->first;              if (it->first->GetFile() == samplePath) return it->first;
43          }          }
# Line 93  namespace sfz Line 96  namespace sfz
96          DestroySampleIfNotUsed();          DestroySampleIfNotUsed();
97      }      }
98    
99      LinuxSampler::SampleFile* Region::GetSample(bool create)      Sample* Region::GetSample(bool create)
100      {      {
101          if(pSample == NULL && create) {          if(pSample == NULL && create) {
102              LinuxSampler::SampleFile* sf = GetInstrument()->GetSampleManager()->FindSample(sample);              Sample* sf = GetInstrument()->GetSampleManager()->FindSample(sample);
103              if (sf != NULL) pSample = sf; // Reuse already created sample              if (sf != NULL) pSample = sf; // Reuse already created sample
104              else pSample = new LinuxSampler::SampleFile(sample);              else pSample = new Sample(sample);
105              GetInstrument()->GetSampleManager()->AddSampleConsumer(pSample, this);              GetInstrument()->GetSampleManager()->AddSampleConsumer(pSample, this);
106          }          }
107          return pSample;          return pSample;
# Line 162  namespace sfz Line 165  namespace sfz
165                ((sw_up   >= sw_lokey && sw_up   <= sw_hikey) ? (!sw[sw_up])  : true) )  &&                ((sw_up   >= sw_lokey && sw_up   <= sw_hikey) ? (!sw[sw_up])  : true) )  &&
166    
167              ((sw_previous != -1) ? (prev_sw_key == sw_previous) : true)  &&              ((sw_previous != -1) ? (prev_sw_key == sw_previous) : true)  &&
168               ((trigger && trig) != 0)               ((trigger & trig) != 0)
169          );          );
170    
171          if (!is_triggered)          if (!is_triggered)
# Line 225  namespace sfz Line 228  namespace sfz
228                ((sw_up   >= sw_lokey && sw_up   <= sw_hikey) ? (!sw[sw_up])  : true) )  &&                ((sw_up   >= sw_lokey && sw_up   <= sw_hikey) ? (!sw[sw_up])  : true) )  &&
229    
230              ((sw_previous != -1) ? (prev_sw_key == sw_previous) : true)  &&              ((sw_previous != -1) ? (prev_sw_key == sw_previous) : true)  &&
231               ((trigger && trig) != 0)               ((trigger & trig) != 0)
232          );          );
233    
234          if (!is_triggered)          if (!is_triggered)
# Line 246  namespace sfz Line 249  namespace sfz
249          return new Articulation(); //todo: implement GetArticulation()          return new Articulation(); //todo: implement GetArticulation()
250      }      }
251    
252        bool Region::HasLoop() {
253            bool b = loop_mode == ::sfz::LOOP_CONTINUOUS || loop_mode == ::sfz::LOOP_SUSTAIN; // TODO: ONE_SHOT mode
254            return b && GetLoopStart() && GetLoopEnd() && GetLoopEnd() > GetLoopStart();
255        }
256    
257        uint Region::GetLoopStart() {
258            return (!loop_start) ? 0 : *loop_start; // TODO: use sample loop when loop_start not defined
259        }
260    
261        uint Region::GetLoopEnd() {
262            return (!loop_end) ? 0 : *loop_end; // TODO: use sample loop when loop_end not defined
263        }
264    
265        uint Region::GetLoopCount() {
266            return (!count) ? 0 : *count;
267        }
268    
269      /////////////////////////////////////////////////////////////      /////////////////////////////////////////////////////////////
270      // class Instrument      // class Instrument
271    
# Line 347  namespace sfz Line 367  namespace sfz
367    
368          trigger = TRIGGER_ATTACK;          trigger = TRIGGER_ATTACK;
369    
370          group.unset();          group = 0;
371          off_by.unset();          off_by.unset();
372          off_mode = OFF_FAST;          off_mode = OFF_FAST;
373    
# Line 486  namespace sfz Line 506  namespace sfz
506              eq2_gain_oncc[i] = 0;              eq2_gain_oncc[i] = 0;
507              eq3_gain_oncc[i] = 0;              eq3_gain_oncc[i] = 0;
508          }          }
509    
510            eg.clear();
511    
512            // deprecated
513            ampeg_delay    = 0;
514            ampeg_start    = 0; //in percentage
515            ampeg_attack   = 0;
516            ampeg_hold     = 0;
517            ampeg_decay    = 0;
518            ampeg_sustain  = 100; // in percentage
519            ampeg_release  = 0;
520    
521            fileg_delay    = 0;
522            fileg_start    = 0; //in percentage
523            fileg_attack   = 0;
524            fileg_hold     = 0;
525            fileg_decay    = 0;
526            fileg_sustain  = 100; // in percentage
527            fileg_release  = 0;
528    
529            pitcheg_delay    = 0;
530            pitcheg_start    = 0; //in percentage
531            pitcheg_attack   = 0;
532            pitcheg_hold     = 0;
533            pitcheg_decay    = 0;
534            pitcheg_sustain  = 100; // in percentage
535            pitcheg_release  = 0;
536      }      }
537    
538      Region*      Region*
# Line 665  namespace sfz Line 712  namespace sfz
712          region->eq2_vel2gain = eq2_vel2gain;          region->eq2_vel2gain = eq2_vel2gain;
713          region->eq3_vel2gain = eq3_vel2gain;          region->eq3_vel2gain = eq3_vel2gain;
714    
715            // envelope generator
716            region->eg = eg;
717    
718            // deprecated
719            region->ampeg_delay    = ampeg_delay;
720            region->ampeg_start    = ampeg_start;
721            region->ampeg_attack   = ampeg_attack;
722            region->ampeg_hold     = ampeg_hold;
723            region->ampeg_decay    = ampeg_decay;
724            region->ampeg_sustain  = ampeg_sustain;
725            region->ampeg_release  = ampeg_release;
726    
727            region->fileg_delay    = fileg_delay;
728            region->fileg_start    = fileg_start;
729            region->fileg_attack   = fileg_attack;
730            region->fileg_hold     = fileg_hold;
731            region->fileg_decay    = fileg_decay;
732            region->fileg_sustain  = fileg_sustain;
733            region->fileg_release  = fileg_release;
734    
735            region->pitcheg_delay    = pitcheg_delay;
736            region->pitcheg_start    = pitcheg_start;
737            region->pitcheg_attack   = pitcheg_attack;
738            region->pitcheg_hold     = pitcheg_hold;
739            region->pitcheg_decay    = pitcheg_decay;
740            region->pitcheg_sustain  = pitcheg_sustain;
741            region->pitcheg_release  = pitcheg_release;
742    
743          return region;          return region;
744      }      }
745    
# Line 679  namespace sfz Line 754  namespace sfz
754      {      {
755          _instrument = new Instrument(LinuxSampler::Path::getBaseName(file), pSampleManager);          _instrument = new Instrument(LinuxSampler::Path::getBaseName(file), pSampleManager);
756          _current_group = new Group();          _current_group = new Group();
757                  pCurDef = _current_group;          pCurDef = _current_group;
758          enum token_type_t { HEADER, OPCODE };          enum token_type_t { HEADER, OPCODE };
759          token_type_t token_type;          token_type_t token_type;
760          std::string token_string;          std::string token_string;
# Line 804  namespace sfz Line 879  namespace sfz
879          {          {
880              _current_section = GROUP;              _current_section = GROUP;
881              _current_group->Reset();              _current_group->Reset();
882                          pCurDef = _current_group;              pCurDef = _current_group;
883          }          }
884          else if (token == "<region>")          else if (token == "<region>")
885          {          {
886              _current_section = REGION;              _current_section = REGION;
887              _current_region = _current_group->RegionFactory();              _current_region = _current_group->RegionFactory();
888                          pCurDef = _current_region;              pCurDef = _current_region;
889              _instrument->regions.push_back(_current_region);              _instrument->regions.push_back(_current_region);
890                          _current_region->SetInstrument(_instrument);              _current_region->SetInstrument(_instrument);
891          }          }
892          else if (token == "<control>")          else if (token == "<control>")
893          {          {
# Line 837  namespace sfz Line 912  namespace sfz
912          std::string::size_type delimiter_index = token.find('=');          std::string::size_type delimiter_index = token.find('=');
913          std::string key = token.substr(0, delimiter_index);          std::string key = token.substr(0, delimiter_index);
914          std::string value = token.substr(delimiter_index + 1);          std::string value = token.substr(delimiter_index + 1);
915            int x, y;
916    
917          // sample definition          // sample definition
918          if ("sample" == key)          if ("sample" == key)
# Line 883  namespace sfz Line 959  namespace sfz
959          // input controls          // input controls
960          else if ("lochan" == key) pCurDef->lochan = ToInt(value);          else if ("lochan" == key) pCurDef->lochan = ToInt(value);
961          else if ("hichan" == key) pCurDef->hichan = ToInt(value);          else if ("hichan" == key) pCurDef->hichan = ToInt(value);
962          else if ("lokey"  == key) pCurDef->lokey  = ToInt(value) + note_offset + 12 * octave_offset;          else if ("lokey"  == key) pCurDef->lokey  = parseKey(value);
963          else if ("hikey"  == key) pCurDef->hikey  = ToInt(value) + note_offset + 12 * octave_offset;          else if ("hikey"  == key) pCurDef->hikey  = parseKey(value);
964          else if ("key" == key)          else if ("key" == key)
965          {          {
966              pCurDef->lokey = ToInt(value) + note_offset + 12 * octave_offset;              pCurDef->lokey = pCurDef->hikey = pCurDef->pitch_keycenter = parseKey(value);
             pCurDef->hikey = ToInt(value) + note_offset + 12 * octave_offset;  
967          }          }
968          else if ("lovel"  == key) pCurDef->lovel = ToInt(value);          else if ("lovel"  == key) pCurDef->lovel = ToInt(value);
969          else if ("hivel"  == key) pCurDef->hivel = ToInt(value);          else if ("hivel"  == key) pCurDef->hivel = ToInt(value);
# Line 908  namespace sfz Line 983  namespace sfz
983          else if ("hitimer" == key) pCurDef->hitimer = ToFloat(value);          else if ("hitimer" == key) pCurDef->hitimer = ToFloat(value);
984          else if ("seq_length"   == key) pCurDef->seq_length = ToInt(value);          else if ("seq_length"   == key) pCurDef->seq_length = ToInt(value);
985          else if ("seq_position" == key) pCurDef->seq_position = ToInt(value);          else if ("seq_position" == key) pCurDef->seq_position = ToInt(value);
986          else if ("sw_lokey" == key) pCurDef->sw_lokey = ToInt(value) + note_offset + 12 * octave_offset;          else if ("sw_lokey" == key) pCurDef->sw_lokey = parseKey(value);
987          else if ("sw_hikey" == key) pCurDef->sw_hikey = ToInt(value) + note_offset + 12 * octave_offset;          else if ("sw_hikey" == key) pCurDef->sw_hikey = parseKey(value);
988          else if ("sw_last"  == key) pCurDef->sw_last = ToInt(value) + note_offset + 12 * octave_offset;          else if ("sw_last"  == key) pCurDef->sw_last = parseKey(value);
989          else if ("sw_down"  == key) pCurDef->sw_down = ToInt(value) + note_offset + 12 * octave_offset;          else if ("sw_down"  == key) pCurDef->sw_down = parseKey(value);
990          else if ("sw_up"    == key) pCurDef->sw_up = ToInt(value) + note_offset + 12 * octave_offset;          else if ("sw_up"    == key) pCurDef->sw_up = parseKey(value);
991          else if ("sw_previous" == key) pCurDef->sw_previous = ToInt(value) + note_offset + 12 * octave_offset;          else if ("sw_previous" == key) pCurDef->sw_previous = parseKey(value);
992          else if ("sw_vel" == key)          else if ("sw_vel" == key)
993          {          {
994              if (value == "current") pCurDef->sw_vel = VEL_CURRENT;              if (value == "current") pCurDef->sw_vel = VEL_CURRENT;
# Line 927  namespace sfz Line 1002  namespace sfz
1002              else if (value == "legato")  pCurDef->trigger = TRIGGER_LEGATO;              else if (value == "legato")  pCurDef->trigger = TRIGGER_LEGATO;
1003          }          }
1004          else if ("group"  == key) pCurDef->group = ToInt(value);          else if ("group"  == key) pCurDef->group = ToInt(value);
1005          else if ("off_by" == key) pCurDef->off_by = ToInt(value);          else if ("off_by" == key || "offby" == key) pCurDef->off_by = ToInt(value);
1006          else if ("off_mode" == key)          else if ("off_mode" == key || "offmode" == key)
1007          {          {
1008              if (value == "fast")  _current_group->off_mode = OFF_FAST;              if (value == "fast")  _current_group->off_mode = OFF_FAST;
1009              else if (value == "normal") _current_group->off_mode = OFF_NORMAL;              else if (value == "normal") _current_group->off_mode = OFF_NORMAL;
1010          }          }
1011    
1012          // sample player          // sample player
1013          else if ("count" == key) pCurDef->count = ToInt(value);          else if ("count" == key) { pCurDef->count = ToInt(value); pCurDef->loop_mode = ONE_SHOT; }
1014          else if ("delay" == key) pCurDef->delay = ToFloat(value);          else if ("delay" == key) pCurDef->delay = ToFloat(value);
1015          else if ("delay_random"   == key) pCurDef->delay_random = ToFloat(value);          else if ("delay_random"   == key) pCurDef->delay_random = ToFloat(value);
1016          else if ("delay_beats"    == key) pCurDef->delay_beats = ToInt(value);          else if ("delay_beats"    == key) pCurDef->delay_beats = ToInt(value);
# Line 944  namespace sfz Line 1019  namespace sfz
1019          else if ("end"            == key) pCurDef->end = ToInt(value);          else if ("end"            == key) pCurDef->end = ToInt(value);
1020          else if ("loop_crossfade" == key) pCurDef->loop_crossfade = ToFloat(value);          else if ("loop_crossfade" == key) pCurDef->loop_crossfade = ToFloat(value);
1021          else if ("offset_random"  == key) pCurDef->offset_random = ToInt(value);          else if ("offset_random"  == key) pCurDef->offset_random = ToInt(value);
1022          else if ("loop_mode" == key)          else if ("loop_mode" == key || "loopmode" == key)
1023          {          {
1024              if (value == "no_loop") pCurDef->loop_mode = NO_LOOP;              if (value == "no_loop") pCurDef->loop_mode = NO_LOOP;
1025              else if (value == "one_shot") pCurDef->loop_mode = ONE_SHOT;              else if (value == "one_shot") pCurDef->loop_mode = ONE_SHOT;
1026              else if (value == "loop_continous") pCurDef->loop_mode = LOOP_CONTINOUS;              else if (value == "loop_continuous") pCurDef->loop_mode = LOOP_CONTINUOUS;
1027              else if (value == "loop_sustain") pCurDef->loop_mode = LOOP_SUSTAIN;              else if (value == "loop_sustain") pCurDef->loop_mode = LOOP_SUSTAIN;
1028          }          }
1029          else if ("loop_start" == key) pCurDef->loop_start = ToInt(value);          else if ("loop_start" == key) pCurDef->loop_start = ToInt(value);
1030            else if ("loopstart" == key) pCurDef->loop_start = ToInt(value); // nonstandard
1031          else if ("loop_end" == key) pCurDef->loop_end = ToInt(value);          else if ("loop_end" == key) pCurDef->loop_end = ToInt(value);
1032            else if ("loopend" == key) pCurDef->loop_end = ToInt(value); // nonstandard
1033          else if ("sync_beats" == key) pCurDef->sync_beats = ToInt(value);          else if ("sync_beats" == key) pCurDef->sync_beats = ToInt(value);
1034          else if ("sync_offset" == key) pCurDef->sync_offset = ToInt(value);          else if ("sync_offset" == key) pCurDef->sync_offset = ToInt(value);
1035    
# Line 962  namespace sfz Line 1039  namespace sfz
1039          else if ("width"    == key) pCurDef->width = ToFloat(value);          else if ("width"    == key) pCurDef->width = ToFloat(value);
1040          else if ("position" == key) pCurDef->position = ToFloat(value);          else if ("position" == key) pCurDef->position = ToFloat(value);
1041          else if ("amp_keytrack"  == key) pCurDef->amp_keytrack = ToFloat(value);          else if ("amp_keytrack"  == key) pCurDef->amp_keytrack = ToFloat(value);
1042          else if ("amp_keycenter" == key) pCurDef->amp_keycenter = ToInt(value) + note_offset + 12 * octave_offset;          else if ("amp_keycenter" == key) pCurDef->amp_keycenter = parseKey(value);
1043          else if ("amp_veltrack"  == key) pCurDef->amp_veltrack = ToFloat(value);          else if ("amp_veltrack"  == key) pCurDef->amp_veltrack = ToFloat(value);
1044          else if ("amp_random"  == key) pCurDef->amp_random = ToFloat(value);          else if ("amp_random"  == key) pCurDef->amp_random = ToFloat(value);
1045          else if ("rt_decay"    == key) pCurDef->rt_decay = ToFloat(value);          else if ("rt_decay"    == key) pCurDef->rt_decay = ToFloat(value);
1046          else if ("xfin_lokey"  == key) pCurDef->xfin_lokey = ToInt(value) + note_offset + 12 * octave_offset;          else if ("xfin_lokey"  == key) pCurDef->xfin_lokey = parseKey(value);
1047          else if ("xfin_hikey"  == key) pCurDef->xfin_hikey = ToInt(value) + note_offset + 12 * octave_offset;          else if ("xfin_hikey"  == key) pCurDef->xfin_hikey = parseKey(value);
1048          else if ("xfout_lokey" == key) pCurDef->xfout_lokey = ToInt(value) + note_offset + 12 * octave_offset;          else if ("xfout_lokey" == key) pCurDef->xfout_lokey = parseKey(value);
1049          else if ("xfout_hikey" == key) pCurDef->xfout_hikey = ToInt(value) + note_offset + 12 * octave_offset;          else if ("xfout_hikey" == key) pCurDef->xfout_hikey = parseKey(value);
1050          else if ("xf_keycurve" == key)          else if ("xf_keycurve" == key)
1051          {          {
1052              if (value == "gain") pCurDef->xf_keycurve = GAIN;              if (value == "gain") pCurDef->xf_keycurve = GAIN;
# Line 993  namespace sfz Line 1070  namespace sfz
1070          // pitch          // pitch
1071          else if ("transpose" == key) pCurDef->transpose = ToInt(value);          else if ("transpose" == key) pCurDef->transpose = ToInt(value);
1072          else if ("tune" == key) pCurDef->tune = ToInt(value);          else if ("tune" == key) pCurDef->tune = ToInt(value);
1073          else if ("pitch_keycenter" == key) pCurDef->pitch_keycenter = ToInt(value) + note_offset + 12 * octave_offset;          else if ("pitch_keycenter" == key) pCurDef->pitch_keycenter = parseKey(value);
1074          else if ("pitch_keytrack" == key) pCurDef->pitch_keytrack = ToInt(value);          else if ("pitch_keytrack" == key) pCurDef->pitch_keytrack = ToInt(value);
1075          else if ("pitch_veltrack" == key) pCurDef->pitch_veltrack = ToInt(value);          else if ("pitch_veltrack" == key) pCurDef->pitch_veltrack = ToInt(value);
1076          else if ("pitch_random" == key) pCurDef->pitch_random = ToInt(value);          else if ("pitch_random" == key) pCurDef->pitch_random = ToInt(value);
1077          else if ("bend_up" == key) pCurDef->bend_up = ToInt(value);          else if ("bend_up" == key || "bendup" == key) pCurDef->bend_up = ToInt(value);
1078          else if ("bend_down" == key) pCurDef->bend_down = ToInt(value);          else if ("bend_down" == key || "benddown" == key) pCurDef->bend_down = ToInt(value);
1079          else if ("bend_step" == key) pCurDef->bend_step = ToInt(value);          else if ("bend_step" == key) pCurDef->bend_step = ToInt(value);
1080    
1081          // filter          // filter
# Line 1046  namespace sfz Line 1123  namespace sfz
1123          else if ("resonance2" == key) pCurDef->resonance2 = ToFloat(value);          else if ("resonance2" == key) pCurDef->resonance2 = ToFloat(value);
1124          else if ("fil_keytrack"   == key) pCurDef->fil_keytrack = ToInt(value);          else if ("fil_keytrack"   == key) pCurDef->fil_keytrack = ToInt(value);
1125          else if ("fil2_keytrack"  == key) pCurDef->fil2_keytrack = ToInt(value);          else if ("fil2_keytrack"  == key) pCurDef->fil2_keytrack = ToInt(value);
1126          else if ("fil_keycenter"  == key) pCurDef->fil_keycenter = ToInt(value) + note_offset + 12 * octave_offset;          else if ("fil_keycenter"  == key) pCurDef->fil_keycenter = parseKey(value);
1127          else if ("fil2_keycenter" == key) pCurDef->fil2_keycenter = ToInt(value) + note_offset + 12 * octave_offset;          else if ("fil2_keycenter" == key) pCurDef->fil2_keycenter = parseKey(value);
1128          else if ("fil_veltrack"   == key) pCurDef->fil_veltrack = ToInt(value);          else if ("fil_veltrack"   == key) pCurDef->fil_veltrack = ToInt(value);
1129          else if ("fil2_veltrack"  == key) pCurDef->fil2_veltrack = ToInt(value);          else if ("fil2_veltrack"  == key) pCurDef->fil2_veltrack = ToInt(value);
1130          else if ("fil_random"     == key) pCurDef->fil_random = ToInt(value);          else if ("fil_random"     == key) pCurDef->fil_random = ToInt(value);
# Line 1130  namespace sfz Line 1207  namespace sfz
1207              else if ("eq2_gain_on" == key_cc) pCurDef->eq2_gain_oncc[num_cc] = ToInt(value);              else if ("eq2_gain_on" == key_cc) pCurDef->eq2_gain_oncc[num_cc] = ToInt(value);
1208              else if ("eq3_gain_on" == key_cc) pCurDef->eq3_gain_oncc[num_cc] = ToInt(value);              else if ("eq3_gain_on" == key_cc) pCurDef->eq3_gain_oncc[num_cc] = ToInt(value);
1209              else std::cerr << "The opcode '" << key << "' is unsupported by libsfz!" << std::endl;              else std::cerr << "The opcode '" << key << "' is unsupported by libsfz!" << std::endl;
1210          } else {          }
1211            // v2 envelope generators
1212            else if (sscanf(key.c_str(), "eg%d%n", &x, &y)) {
1213                const char* s = key.c_str() + y;
1214                if (sscanf(s, "_time%d", &y)) egnode(x, y).time = ToFloat(value);
1215                else if (sscanf(s, "_level%d", &y)) egnode(x, y).level = ToFloat(value);
1216                else if (sscanf(s, "_shape%d", &y)) egnode(x, y).shape = ToFloat(value);
1217                else if (sscanf(s, "_curve%d", &y)) egnode(x, y).curve = ToFloat(value);
1218                else if (strcmp(s, "_sustain") == 0) eg(x).sustain = ToInt(value);
1219                else if (strcmp(s, "_loop") == 0) eg(x).loop = ToInt(value);
1220                else if (strcmp(s, "_loop_count") == 0) eg(x).loop_count = ToInt(value);
1221                else if (strcmp(s, "_amplitude") == 0) eg(x).amplitude = ToFloat(value);
1222                else if (strcmp(s, "_cutoff") == 0) eg(x).cutoff = ToFloat(value);
1223                else std::cerr << "The opcode '" << key << "' is unsupported by libsfz!" << std::endl;
1224            }
1225    
1226            // v1 envelope generators
1227            else if ("ampeg_delay"   == key) pCurDef->ampeg_delay = ToFloat(value);
1228            else if ("ampeg_start"   == key) pCurDef->ampeg_start = ToFloat(value);
1229            else if ("ampeg_attack"   == key) pCurDef->ampeg_attack = ToFloat(value);
1230            else if ("ampeg_hold"   == key) pCurDef->ampeg_hold = ToFloat(value);
1231            else if ("ampeg_decay"   == key) pCurDef->ampeg_decay = ToFloat(value);
1232            else if ("ampeg_sustain"   == key) pCurDef->ampeg_sustain = ToFloat(value);
1233            else if ("ampeg_release"   == key) pCurDef->ampeg_release = ToFloat(value);
1234            else if ("fileg_delay"   == key) pCurDef->fileg_delay = ToFloat(value);
1235            else if ("fileg_start"   == key) pCurDef->fileg_start = ToFloat(value);
1236            else if ("fileg_attack"   == key) pCurDef->fileg_attack = ToFloat(value);
1237            else if ("fileg_hold"   == key) pCurDef->fileg_hold = ToFloat(value);
1238            else if ("fileg_decay"   == key) pCurDef->fileg_decay = ToFloat(value);
1239            else if ("fileg_sustain"   == key) pCurDef->fileg_sustain = ToFloat(value);
1240            else if ("fileg_release"   == key) pCurDef->fileg_release = ToFloat(value);
1241            else if ("pitcheg_delay"   == key) pCurDef->pitcheg_delay = ToFloat(value);
1242            else if ("pitcheg_start"   == key) pCurDef->pitcheg_start = ToFloat(value);
1243            else if ("pitcheg_attack"   == key) pCurDef->pitcheg_attack = ToFloat(value);
1244            else if ("pitcheg_hold"   == key) pCurDef->pitcheg_hold = ToFloat(value);
1245            else if ("pitcheg_decay"   == key) pCurDef->pitcheg_decay = ToFloat(value);
1246            else if ("pitcheg_sustain"   == key) pCurDef->pitcheg_sustain = ToFloat(value);
1247            else if ("pitcheg_release"   == key) pCurDef->pitcheg_release = ToFloat(value);
1248            else {
1249              std::cerr << "The opcode '" << key << "' is unsupported by libsfz!" << std::endl;              std::cerr << "The opcode '" << key << "' is unsupported by libsfz!" << std::endl;
1250          }          }
1251      }      }
1252    
1253        int File::parseKey(const std::string& s) {
1254            int i;
1255            std::istringstream iss(s);
1256            if (isdigit(iss.peek())) {
1257                iss >> i;
1258            } else {
1259                switch (tolower(iss.get())) {
1260                case 'c': i = 0; break;
1261                case 'd': i = 2; break;
1262                case 'e': i = 4; break;
1263                case 'f': i = 5; break;
1264                case 'g': i = 7; break;
1265                case 'a': i = 9; break;
1266                case 'b': i = 11; break;
1267                default:
1268                    std::cerr << "Not a note: " << s << std::endl;
1269                    return 0;
1270                }
1271                if (iss.peek() == '#') {
1272                    i++;
1273                    iss.get();
1274                } else if (tolower(iss.peek()) == 'b') {
1275                    i--;
1276                    iss.get();
1277                }
1278                int octave;
1279                if (!(iss >> octave)) {
1280                    std::cerr << "Not a note: " << s << std::endl;
1281                    return 0;
1282                }
1283                i += (octave + 1) * 12;
1284            }
1285            return i + note_offset + 12 * octave_offset;
1286        }
1287    
1288        EGNode::EGNode() : time(0), level(0), shape(0), curve(0) {
1289        }
1290    
1291        EG::EG() :
1292            sustain(0), loop(0), loop_count(0),
1293            amplitude(0), cutoff(0) {
1294        }
1295    
1296        EG& File::eg(int x) {
1297            while (pCurDef->eg.size() <= x) {
1298                pCurDef->eg.add(EG());
1299            }
1300            return pCurDef->eg[x];
1301        }
1302    
1303        EGNode& File::egnode(int x, int y) {
1304            EG& e = eg(x);
1305            while (e.node.size() <= y) {
1306                e.node.add(EGNode());
1307            }
1308            return e.node[y];
1309        }
1310    
1311  } // !namespace sfz  } // !namespace sfz

Legend:
Removed from v.2012  
changed lines
  Added in v.2058

  ViewVC Help
Powered by ViewVC