/[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 2299 by iliev, Sun Dec 11 20:50:31 2011 UTC revision 2403 by persson, Sun Jan 20 19:01:53 2013 UTC
# Line 3  Line 3 
3   *   LinuxSampler - modular, streaming capable sampler                     *   *   LinuxSampler - modular, streaming capable sampler                     *
4   *                                                                         *   *                                                                         *
5   *   Copyright (C) 2008 Anders Dahnielson <anders@dahnielson.com>          *   *   Copyright (C) 2008 Anders Dahnielson <anders@dahnielson.com>          *
6   *   Copyright (C) 2009 - 2011 Anders Dahnielson and Grigor Iliev          *   *   Copyright (C) 2009 - 2013 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 108  namespace sfz Line 108  namespace sfz
108    
109      Sample* Region::GetSample(bool create)      Sample* Region::GetSample(bool create)
110      {      {
111          if(pSample == NULL && create) {          if (pSample == NULL && create) {
112              uint i = offset ? *offset : 0;              uint i = offset ? *offset : 0;
113              int e = end ? *end : -2;              Sample* sf = GetInstrument()->GetSampleManager()->FindSample(sample, i, end);
             Sample* sf = GetInstrument()->GetSampleManager()->FindSample(sample, i, e);  
114              if (sf != NULL) pSample = sf; // Reuse already created sample              if (sf != NULL) pSample = sf; // Reuse already created sample
115              else pSample = new Sample(sample, false, i, e);              else pSample = new Sample(sample, false, i, end);
116              GetInstrument()->GetSampleManager()->AddSampleConsumer(pSample, this);              GetInstrument()->GetSampleManager()->AddSampleConsumer(pSample, this);
117          }          }
118          return pSample;          return pSample;
# Line 170  namespace sfz Line 169  namespace sfz
169      }      }
170    
171      bool Region::HasLoop() {      bool Region::HasLoop() {
172          bool b = loop_mode == ::sfz::LOOP_UNSET ? pSample->GetLoops() :          bool b = loop_mode == LOOP_UNSET ? pSample->GetLoops() :
173              (loop_mode == ::sfz::LOOP_CONTINUOUS || loop_mode == ::sfz::LOOP_SUSTAIN);              (loop_mode == LOOP_CONTINUOUS || loop_mode == LOOP_SUSTAIN);
174          return b && GetLoopStart() && GetLoopEnd() && GetLoopEnd() > GetLoopStart();          return b && GetLoopEnd() > GetLoopStart();
175      }      }
176    
177      uint Region::GetLoopStart() {      uint Region::GetLoopStart() {
# Line 310  namespace sfz Line 309  namespace sfz
309          delay.unset(); delay_random.unset();          delay.unset(); delay_random.unset();
310          delay_beats.unset(); stop_beats.unset();          delay_beats.unset(); stop_beats.unset();
311          delay_samples.unset();          delay_samples.unset();
312          end.unset();          end = 0;
313          loop_crossfade.unset();          loop_crossfade.unset();
314          offset.unset(); offset_random.unset();          offset.unset(); offset_random.unset();
315          loop_mode = LOOP_UNSET;          loop_mode = LOOP_UNSET;
# Line 323  namespace sfz Line 322  namespace sfz
322          volume_curvecc.clear();          volume_curvecc.clear();
323          volume_smoothcc.clear();          volume_smoothcc.clear();
324          volume_stepcc.clear();          volume_stepcc.clear();
325            amplitude = 100;
326          pan = 0;          pan = 0;
327          pan_oncc.clear();          pan_oncc.clear();
328          pan_curvecc.clear();          pan_curvecc.clear();
# Line 639  namespace sfz Line 639  namespace sfz
639          region->volume_curvecc = volume_curvecc;          region->volume_curvecc = volume_curvecc;
640          region->volume_smoothcc = volume_smoothcc;          region->volume_smoothcc = volume_smoothcc;
641          region->volume_stepcc = volume_stepcc;          region->volume_stepcc = volume_stepcc;
642            region->amplitude = amplitude;
643          region->pan = pan;          region->pan = pan;
644          region->pan_oncc = pan_oncc;          region->pan_oncc = pan_oncc;
645          region->pan_curvecc = pan_curvecc;          region->pan_curvecc = pan_curvecc;
# Line 893  namespace sfz Line 894  namespace sfz
894    
895              // DEFINITION              // DEFINITION
896              std::stringstream linestream(line);              std::stringstream linestream(line);
897                int spaces = 0;
898              while (linestream >> token)              while (linestream >> token)
899              {              {
900                  if (token[0] == '<' and token[token.size()-1] == '>')                  linestream >> std::noskipws;
901                    if (token[0] == '<' && token[token.size()-1] == '>')
902                  {                  {
903                      // HEAD                      // HEAD
904                      if (!token_string.empty())                      if (!token_string.empty())
# Line 936  namespace sfz Line 939  namespace sfz
939                  else                  else
940                  {                  {
941                      // TAIL                      // TAIL
942                      token_string.append(" ");                      token_string.append(spaces, ' ');
943                      token_string.append(token);                      token_string.append(token);
944                  }                  }
945                    spaces = 0;
946                    while (isspace(linestream.peek())) {
947                        linestream.ignore();
948                        spaces++;
949                    }
950              }              }
951    
952              // EOL              // EOL
# Line 1014  namespace sfz Line 1022  namespace sfz
1022                          velcurve[v] = v * v / (127.0 * 127.0);                          velcurve[v] = v * v / (127.0 * 127.0);
1023                      }                      }
1024                  }                  }
   
                 // apply amp_veltrack  
                 float offset = -pRegion->amp_veltrack;  
                 if (offset <= 0) offset += 100;  
                 for (int v = 0 ; v < 128 ; v++) {  
                     velcurve[v] = (offset + pRegion->amp_veltrack * velcurve[v]) / 100;  
                 }  
1025              }              }
1026          }          }
1027    
# Line 1276  namespace sfz Line 1277  namespace sfz
1277          {          {
1278              std::string path = default_path + value;              std::string path = default_path + value;
1279              #ifndef WIN32              #ifndef WIN32
1280              for (int i = 0; i < path.length(); i++) if( path[i] == '\\') path[i] = '/';              for (int i = 0; i < path.length(); i++) if (path[i] == '\\') path[i] = '/';
1281                bool absolute = path[0] == '/';
1282                #else
1283                bool absolute = path[0] == '/' || path[0] == '\\' ||
1284                    (path.length() >= 2 && isalpha(path[0]) && path[1] == ':');
1285              #endif              #endif
1286              path = currentDir + LinuxSampler::File::DirSeparator + path; // TODO: check for absolute path              if (!absolute) path = currentDir + LinuxSampler::File::DirSeparator + path;
   
1287              if(pCurDef) pCurDef->sample = path;              if(pCurDef) pCurDef->sample = path;
1288              return;              return;
1289          }          }
# Line 1393  namespace sfz Line 1397  namespace sfz
1397    
1398          // amplifier          // amplifier
1399          else if ("volume"   == key) pCurDef->volume = ToFloat(value);          else if ("volume"   == key) pCurDef->volume = ToFloat(value);
1400            else if ("amplitude" == key) pCurDef->amplitude = ToFloat(value);
1401          else if ("pan"      == key) pCurDef->pan = ToFloat(value);          else if ("pan"      == key) pCurDef->pan = ToFloat(value);
1402          else if ("width"    == key) pCurDef->width = ToFloat(value);          else if ("width"    == key) pCurDef->width = ToFloat(value);
1403          else if ("position" == key) pCurDef->position = ToFloat(value);          else if ("position" == key) pCurDef->position = ToFloat(value);
# Line 1811  namespace sfz Line 1816  namespace sfz
1816              else if ("volume_curve" == key_cc) pCurDef->volume_curvecc.add( CC(num_cc, 0, check(key, 0, 30000, ToInt(value))) );              else if ("volume_curve" == key_cc) pCurDef->volume_curvecc.add( CC(num_cc, 0, check(key, 0, 30000, ToInt(value))) );
1817              else if ("volume_smooth" == key_cc) pCurDef->volume_smoothcc.add( CC(num_cc, 0, -1, check(key, 0.0f, 100000.0f /* max? */, ToFloat(value))) );              else if ("volume_smooth" == key_cc) pCurDef->volume_smoothcc.add( CC(num_cc, 0, -1, check(key, 0.0f, 100000.0f /* max? */, ToFloat(value))) );
1818              else if ("volume_step" == key_cc) pCurDef->volume_stepcc.add( CC(num_cc, 0, -1, 0, check(key, -20.0f, 20.0f, ToFloat(value))) );              else if ("volume_step" == key_cc) pCurDef->volume_stepcc.add( CC(num_cc, 0, -1, 0, check(key, -20.0f, 20.0f, ToFloat(value))) );
1819              else if ("pan" == key_cc) pCurDef->pan_oncc.add( CC(num_cc, check(key, -100.0f, 100.0f, ToFloat(value))) );              else if ("pan" == key_cc) pCurDef->pan_oncc.add( CC(num_cc, check(key, -200.0f, 200.0f, ToFloat(value))) );
1820              else if ("pan_curve" == key_cc) pCurDef->pan_curvecc.add( CC(num_cc, 0, check(key, 0, 30000, ToInt(value))) );              else if ("pan_curve" == key_cc) pCurDef->pan_curvecc.add( CC(num_cc, 0, check(key, 0, 30000, ToInt(value))) );
1821              else if ("pan_smooth" == key_cc) pCurDef->pan_smoothcc.add( CC(num_cc, 0, -1, check(key, 0.0f, 100000.0f /* max? */, ToFloat(value))) );              else if ("pan_smooth" == key_cc) pCurDef->pan_smoothcc.add( CC(num_cc, 0, -1, check(key, 0.0f, 100000.0f /* max? */, ToFloat(value))) );
1822              else if ("pan_step" == key_cc) pCurDef->pan_stepcc.add( CC(num_cc, 0, -1, 0, check(key, -100.0f, 100.0f, ToFloat(value))) );              else if ("pan_step" == key_cc) pCurDef->pan_stepcc.add( CC(num_cc, 0, -1, 0, check(key, -100.0f, 100.0f, ToFloat(value))) );

Legend:
Removed from v.2299  
changed lines
  Added in v.2403

  ViewVC Help
Powered by ViewVC