876 |
pCurDef = _current_group; |
pCurDef = _current_group; |
877 |
|
|
878 |
parseFile(file,pSampleManager); |
parseFile(file,pSampleManager); |
|
} |
|
|
|
|
|
void File::parseFile(std::string file, SampleManager* pSampleManager){ |
|
|
enum token_type_t { HEADER, OPCODE }; |
|
|
token_type_t token_type; |
|
|
std::string token_string; |
|
|
|
|
|
std::ifstream fs(file.c_str()); |
|
|
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); |
|
|
|
|
|
// #include |
|
|
if (line.find("#include ") == 0) { |
|
|
size_t fname_start = line.find("\""); |
|
|
if (fname_start == std::string::npos) continue; |
|
|
|
|
|
size_t fname_end = line.find("\"", fname_start + 1); |
|
|
if (fname_end == std::string::npos || fname_start == fname_end) |
|
|
continue; |
|
|
std::string fname = line.substr(fname_start + 1, fname_end - fname_start - 1); |
|
|
|
|
|
if (!currentDir.empty() && !LinuxSampler::Path(fname).isAbsolute()) |
|
|
fname = currentDir + LinuxSampler::File::DirSeparator + fname; |
|
|
|
|
|
std::string cd = currentDir; // backup current dir |
|
|
parseFile(fname, pSampleManager); |
|
|
currentDir = cd; // restore currentDir (since altered by parsefile()) |
|
|
continue; |
|
|
} |
|
|
|
|
|
// DEFINITION |
|
|
std::stringstream linestream(line); |
|
|
int spaces = 0; |
|
|
while (linestream >> token) |
|
|
{ |
|
|
linestream >> std::noskipws; |
|
|
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++) { |
1058 |
} |
} |
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 |
{ |
{ |