/[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 2027 by iliev, Tue Nov 3 19:27:42 2009 UTC revision 2055 by persson, Sat Jan 30 10:30:02 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 <cstdio>
29    #include <cstring>
30    
31  #include "../../common/File.h"  #include "../../common/File.h"
32  #include "../../common/Path.h"  #include "../../common/Path.h"
# Line 504  namespace sfz Line 506  namespace sfz
506              eq3_gain_oncc[i] = 0;              eq3_gain_oncc[i] = 0;
507          }          }
508    
509            eg.clear();
510    
511          // deprecated          // deprecated
512          ampeg_delay    = 0;          ampeg_delay    = 0;
513          ampeg_start    = 0; //in percentage          ampeg_start    = 0; //in percentage
# Line 707  namespace sfz Line 711  namespace sfz
711          region->eq2_vel2gain = eq2_vel2gain;          region->eq2_vel2gain = eq2_vel2gain;
712          region->eq3_vel2gain = eq3_vel2gain;          region->eq3_vel2gain = eq3_vel2gain;
713    
714            // envelope generator
715            region->eg = eg;
716    
717          // deprecated          // deprecated
718          region->ampeg_delay    = ampeg_delay;          region->ampeg_delay    = ampeg_delay;
719          region->ampeg_start    = ampeg_start;          region->ampeg_start    = ampeg_start;
# Line 746  namespace sfz Line 753  namespace sfz
753      {      {
754          _instrument = new Instrument(LinuxSampler::Path::getBaseName(file), pSampleManager);          _instrument = new Instrument(LinuxSampler::Path::getBaseName(file), pSampleManager);
755          _current_group = new Group();          _current_group = new Group();
756                  pCurDef = _current_group;          pCurDef = _current_group;
757          enum token_type_t { HEADER, OPCODE };          enum token_type_t { HEADER, OPCODE };
758          token_type_t token_type;          token_type_t token_type;
759          std::string token_string;          std::string token_string;
# Line 871  namespace sfz Line 878  namespace sfz
878          {          {
879              _current_section = GROUP;              _current_section = GROUP;
880              _current_group->Reset();              _current_group->Reset();
881                          pCurDef = _current_group;              pCurDef = _current_group;
882          }          }
883          else if (token == "<region>")          else if (token == "<region>")
884          {          {
885              _current_section = REGION;              _current_section = REGION;
886              _current_region = _current_group->RegionFactory();              _current_region = _current_group->RegionFactory();
887                          pCurDef = _current_region;              pCurDef = _current_region;
888              _instrument->regions.push_back(_current_region);              _instrument->regions.push_back(_current_region);
889                          _current_region->SetInstrument(_instrument);              _current_region->SetInstrument(_instrument);
890          }          }
891          else if (token == "<control>")          else if (token == "<control>")
892          {          {
# Line 904  namespace sfz Line 911  namespace sfz
911          std::string::size_type delimiter_index = token.find('=');          std::string::size_type delimiter_index = token.find('=');
912          std::string key = token.substr(0, delimiter_index);          std::string key = token.substr(0, delimiter_index);
913          std::string value = token.substr(delimiter_index + 1);          std::string value = token.substr(delimiter_index + 1);
914            int x, y;
915    
916          // sample definition          // sample definition
917          if ("sample" == key)          if ("sample" == key)
# Line 1200  namespace sfz Line 1208  namespace sfz
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          }          }
1211          // Deprecated opcodes          // 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);          else if ("ampeg_delay"   == key) pCurDef->ampeg_delay = ToFloat(value);
1228          else if ("ampeg_start"   == key) pCurDef->ampeg_start = ToFloat(value);          else if ("ampeg_start"   == key) pCurDef->ampeg_start = ToFloat(value);
1229          else if ("ampeg_attack"   == key) pCurDef->ampeg_attack = ToFloat(value);          else if ("ampeg_attack"   == key) pCurDef->ampeg_attack = ToFloat(value);
# Line 1227  namespace sfz Line 1250  namespace sfz
1250          }          }
1251      }      }
1252    
1253        EGNode::EGNode() : time(0), level(0), shape(0), curve(0) {
1254        }
1255    
1256        EG::EG() :
1257            sustain(0), loop(0), loop_count(0),
1258            amplitude(0), cutoff(0) {
1259        }
1260    
1261        EG& File::eg(int x) {
1262            while (pCurDef->eg.size() <= x) {
1263                pCurDef->eg.add(EG());
1264            }
1265            return pCurDef->eg[x];
1266        }
1267    
1268        EGNode& File::egnode(int x, int y) {
1269            EG& e = eg(x);
1270            while (e.node.size() <= y) {
1271                e.node.add(EGNode());
1272            }
1273            return e.node[y];
1274        }
1275    
1276  } // !namespace sfz  } // !namespace sfz

Legend:
Removed from v.2027  
changed lines
  Added in v.2055

  ViewVC Help
Powered by ViewVC