/[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 2317 by persson, Sun Feb 19 12:13:19 2012 UTC revision 2533 by persson, Sat Mar 8 09:04:42 2014 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 - 2012 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 322  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 638  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 872  namespace sfz Line 874  namespace sfz
874          _instrument = new Instrument(LinuxSampler::Path::getBaseName(file), pSampleManager);          _instrument = new Instrument(LinuxSampler::Path::getBaseName(file), pSampleManager);
875          _current_group = new Group();          _current_group = new Group();
876          pCurDef = _current_group;          pCurDef = _current_group;
         enum token_type_t { HEADER, OPCODE };  
         token_type_t token_type;  
         std::string token_string;  
877    
878          std::ifstream fs(file.c_str());          parseFile(file,pSampleManager);
         currentDir = LinuxSampler::Path::stripLastName(file);  
         std::string token;  
         std::string line;  
         currentLine = 0;  
   
         while (std::getline(fs, line))  
         {  
             currentLine++;  
             // COMMENT  
             std::string::size_type slash_index = line.find("//");  
             if (slash_index != std::string::npos)  
                 line.resize(slash_index);  
   
             // DEFINITION  
             std::stringstream linestream(line);  
             linestream >> std::noskipws;  
             int spaces = 0;  
             while (linestream >> token)  
             {  
                 if (token[0] == '<' && token[token.size()-1] == '>')  
                 {  
                     // HEAD  
                     if (!token_string.empty())  
                     {  
                         switch (token_type)  
                         {  
                         case HEADER:  
                             push_header(token_string);  
                             break;  
                         case OPCODE:  
                             push_opcode(token_string);  
                             break;  
                         }  
                         token_string.erase();  
                     }  
                     token_string.append(token);  
                     token_type = HEADER;  
                 }  
                 else if (token.find('=') != std::string::npos)  
                 {  
                     // HEAD  
                     if (!token_string.empty())  
                     {  
                         switch (token_type)  
                         {  
                         case HEADER:  
                             push_header(token_string);  
                             break;  
                         case OPCODE:  
                             push_opcode(token_string);  
                             break;  
                         }  
                         token_string.erase();  
                     }  
                     token_string.append(token);  
                     token_type = OPCODE;  
                 }  
                 else  
                 {  
                     // TAIL  
                     token_string.append(spaces, ' ');  
                     token_string.append(token);  
                 }  
                 spaces = 0;  
                 while (isspace(linestream.peek())) {  
                     linestream.ignore();  
                     spaces++;  
                 }  
             }  
   
             // EOL  
             if (!token_string.empty())  
             {  
                 switch (token_type)  
                 {  
                 case HEADER:  
                     push_header(token_string);  
                     break;  
                 case OPCODE:  
                     push_opcode(token_string);  
                     break;  
                 }  
                 token_string.erase();  
             }  
         }  
879    
880          std::set<float*> velcurves;          std::set<float*> velcurves;
881          for (int i = 0; i < _instrument->regions.size(); i++) {          for (int i = 0; i < _instrument->regions.size(); i++) {
# Line 1145  namespace sfz Line 1059  namespace sfz
1059          }          }
1060      }      }
1061    
1062        void File::parseFile(std::string file, SampleManager* pSampleManager){
1063            enum token_type_t { HEADER, OPCODE };
1064            token_type_t token_type;
1065            std::string token_string;
1066    
1067            std::ifstream fs(file.c_str());
1068            currentDir = LinuxSampler::Path::stripLastName(file);
1069            std::string token;
1070            std::string line;
1071            currentLine = 0;
1072    
1073            while (std::getline(fs, line))
1074            {
1075                currentLine++;
1076                // COMMENT
1077                std::string::size_type slash_index = line.find("//");
1078                if (slash_index != std::string::npos)
1079                    line.resize(slash_index);
1080    
1081                // #include
1082                if (line.find("#include ") == 0) {
1083                    size_t fname_start = line.find("\"");
1084                    if (fname_start == std::string::npos) continue;
1085    
1086                    size_t fname_end = line.find("\"", fname_start + 1);
1087                    if (fname_end == std::string::npos || fname_start == fname_end)
1088                        continue;
1089                    std::string fname = line.substr(fname_start + 1, fname_end - fname_start - 1);
1090    
1091                    if (!currentDir.empty() && !LinuxSampler::Path(fname).isAbsolute())
1092                        fname = currentDir + LinuxSampler::File::DirSeparator + fname;
1093    
1094                    std::string cd = currentDir; // backup current dir
1095                    int cl = currentLine;
1096                    parseFile(fname, pSampleManager);
1097                    currentDir = cd; // restore currentDir (since altered by parsefile())
1098                    currentLine = cl;
1099                    continue;
1100                }
1101    
1102                // DEFINITION
1103                std::stringstream linestream(line);
1104                int spaces = 0;
1105                while (linestream >> token)
1106                {
1107                    linestream >> std::noskipws;
1108                    if (token[0] == '<' && token[token.size()-1] == '>')
1109                    {
1110                        // HEAD
1111                        if (!token_string.empty())
1112                        {
1113                            switch (token_type)
1114                            {
1115                            case HEADER:
1116                                push_header(token_string);
1117                                break;
1118                            case OPCODE:
1119                                push_opcode(token_string);
1120                                break;
1121                            }
1122                            token_string.erase();
1123                        }
1124                        token_string.append(token);
1125                        token_type = HEADER;
1126                    }
1127                    else if (token.find('=') != std::string::npos)
1128                    {
1129                        // HEAD
1130                        if (!token_string.empty())
1131                        {
1132                            switch (token_type)
1133                            {
1134                            case HEADER:
1135                                push_header(token_string);
1136                                break;
1137                            case OPCODE:
1138                                push_opcode(token_string);
1139                                break;
1140                            }
1141                            token_string.erase();
1142                        }
1143                        token_string.append(token);
1144                        token_type = OPCODE;
1145                    }
1146                    else
1147                    {
1148                        // TAIL
1149                        token_string.append(spaces, ' ');
1150                        token_string.append(token);
1151                    }
1152                    spaces = 0;
1153                    while (isspace(linestream.peek())) {
1154                        linestream.ignore();
1155                        spaces++;
1156                    }
1157                }
1158    
1159                // EOL
1160                if (!token_string.empty())
1161                {
1162                    switch (token_type)
1163                    {
1164                    case HEADER:
1165                        push_header(token_string);
1166                        break;
1167                    case OPCODE:
1168                        push_opcode(token_string);
1169                        break;
1170                    }
1171                    token_string.erase();
1172                }
1173            }
1174        }
1175    
1176      File::~File()      File::~File()
1177      {      {
1178          delete _current_group;          delete _current_group;
# Line 1395  namespace sfz Line 1423  namespace sfz
1423    
1424          // amplifier          // amplifier
1425          else if ("volume"   == key) pCurDef->volume = ToFloat(value);          else if ("volume"   == key) pCurDef->volume = ToFloat(value);
1426            else if ("amplitude" == key) pCurDef->amplitude = ToFloat(value);
1427          else if ("pan"      == key) pCurDef->pan = ToFloat(value);          else if ("pan"      == key) pCurDef->pan = ToFloat(value);
1428          else if ("width"    == key) pCurDef->width = ToFloat(value);          else if ("width"    == key) pCurDef->width = ToFloat(value);
1429          else if ("position" == key) pCurDef->position = ToFloat(value);          else if ("position" == key) pCurDef->position = ToFloat(value);
# Line 1813  namespace sfz Line 1842  namespace sfz
1842              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))) );
1843              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))) );
1844              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))) );
1845              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))) );
1846              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))) );
1847              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))) );
1848              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.2317  
changed lines
  Added in v.2533

  ViewVC Help
Powered by ViewVC