3 |
* LinuxSampler - modular, streaming capable sampler * |
* LinuxSampler - modular, streaming capable sampler * |
4 |
* * |
* * |
5 |
* Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck * |
* Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck * |
6 |
* Copyright (C) 2005 Christian Schoenebeck * |
* Copyright (C) 2005, 2006 Christian Schoenebeck * |
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 * |
39 |
} |
} |
40 |
} |
} |
41 |
|
|
42 |
static bool __parse_bool(String val) throw (LinuxSamplerException) { |
static bool __parse_bool(String val) throw (Exception) { |
43 |
__eliminate_quotation(val); |
__eliminate_quotation(val); |
44 |
int b; |
int b; |
45 |
if (val == "1" || !strcasecmp(val.c_str(),"true")) b = true; |
if (val == "1" || !strcasecmp(val.c_str(),"true")) b = true; |
46 |
else if (val == "0" || !strcasecmp(val.c_str(),"false")) b = false; |
else if (val == "0" || !strcasecmp(val.c_str(),"false")) b = false; |
47 |
else throw LinuxSamplerException("Invalid value for boolean Device parameter"); |
else throw Exception("Invalid value for boolean Device parameter"); |
48 |
return b; |
return b; |
49 |
} |
} |
50 |
|
|
51 |
static int __parse_int(String val) throw (LinuxSamplerException) { |
static int __parse_int(String val) throw (Exception) { |
52 |
__eliminate_quotation(val); |
__eliminate_quotation(val); |
53 |
return atoi(val.c_str()); // TODO: format check is missing |
return atoi(val.c_str()); // TODO: format check is missing |
54 |
} |
} |
55 |
|
|
56 |
static float __parse_float(String val) throw (LinuxSamplerException) { |
static float __parse_float(String val) throw (Exception) { |
57 |
__eliminate_quotation(val); |
__eliminate_quotation(val); |
58 |
return atof(val.c_str()); // TODO: format check is missing |
return atof(val.c_str()); // TODO: format check is missing |
59 |
} |
} |
63 |
return val; |
return val; |
64 |
} |
} |
65 |
|
|
66 |
static std::vector<String> __parse_strings(String val) throw (LinuxSamplerException) { |
static std::vector<String> __parse_strings(String val) throw (Exception) { |
67 |
std::vector<String> vS; |
std::vector<String> vS; |
68 |
|
|
69 |
// if there's only a single value, then we also allow to give it without being encapsulated into apostrophes |
// if there's only a single value, then we also allow to give it without being encapsulated into apostrophes |
75 |
char* pC = pStart; |
char* pC = pStart; |
76 |
|
|
77 |
while (true) { |
while (true) { |
78 |
if (*pC != '\'' && *pC != '\"') throw LinuxSamplerException("Invalid form, all individual strings should be encapsulated into apostrophes, separated by commas"); |
if (*pC != '\'' && *pC != '\"') throw Exception("Invalid form, all individual strings should be encapsulated into apostrophes, separated by commas"); |
79 |
|
|
80 |
// search for token end |
// search for token end |
81 |
char* pTokenStart = pC + 1; |
char* pTokenStart = pC + 1; |
82 |
do { |
do { |
83 |
pC++; |
pC++; |
84 |
if (*pC == '\0') throw LinuxSamplerException("Invalid form, all individual strings should be encapsulated into apostrophes, separated by commas"); |
if (*pC == '\0') throw Exception("Invalid form, all individual strings should be encapsulated into apostrophes, separated by commas"); |
85 |
} |
} |
86 |
while (*pC != '\'' && *pC != '\"'); |
while (*pC != '\'' && *pC != '\"'); |
87 |
String token = val.substr((int)(pTokenStart - pStart), (int)(pC - pTokenStart)); |
String token = val.substr((int)(pTokenStart - pStart), (int)(pC - pTokenStart)); |
89 |
|
|
90 |
// now there should be either a comma or the end of the total string |
// now there should be either a comma or the end of the total string |
91 |
if (*(++pC) == '\0') break; |
if (*(++pC) == '\0') break; |
92 |
if (*pC != ',') throw LinuxSamplerException("Invalid form, all individual strings should be encapsulated into apostrophes, separated by commas"); |
if (*pC != ',') throw Exception("Invalid form, all individual strings should be encapsulated into apostrophes, separated by commas"); |
93 |
pC++; |
pC++; |
94 |
} |
} |
95 |
} |
} |
130 |
return (ValueAsBool()) ? "true" : "false"; |
return (ValueAsBool()) ? "true" : "false"; |
131 |
} |
} |
132 |
|
|
133 |
void DeviceRuntimeParameterBool::SetValue(String val) throw (LinuxSamplerException) { |
void DeviceRuntimeParameterBool::SetValue(String val) throw (Exception) { |
134 |
if (Fix()) throw LinuxSamplerException("Device parameter is read only"); |
if (Fix()) throw Exception("Device parameter is read only"); |
135 |
int b = __parse_bool(val); |
int b = __parse_bool(val); |
136 |
SetValue(b); |
SetValue(b); |
137 |
} |
} |
140 |
return bVal; |
return bVal; |
141 |
} |
} |
142 |
|
|
143 |
void DeviceRuntimeParameterBool::SetValue(bool b) throw (LinuxSamplerException) { |
void DeviceRuntimeParameterBool::SetValue(bool b) throw (Exception) { |
144 |
if (Fix()) throw LinuxSamplerException("Device parameter is read only"); |
if (Fix()) throw Exception("Device parameter is read only"); |
145 |
OnSetValue(b); |
OnSetValue(b); |
146 |
bVal = b; |
bVal = b; |
147 |
} |
} |
193 |
return ToString(ValueAsInt()); |
return ToString(ValueAsInt()); |
194 |
} |
} |
195 |
|
|
196 |
void DeviceRuntimeParameterInt::SetValue(String val) throw (LinuxSamplerException) { |
void DeviceRuntimeParameterInt::SetValue(String val) throw (Exception) { |
197 |
if (Fix()) throw LinuxSamplerException("Device parameter is read only"); |
if (Fix()) throw Exception("Device parameter is read only"); |
198 |
int i = __parse_int(val); |
int i = __parse_int(val); |
199 |
if (RangeMinAsInt() && i < *RangeMinAsInt()) throw LinuxSamplerException("Invalid device parameter value: too small"); |
if (RangeMinAsInt() && i < *RangeMinAsInt()) throw Exception("Invalid device parameter value: too small"); |
200 |
if (RangeMaxAsInt() && i > *RangeMaxAsInt()) throw LinuxSamplerException("Invalid device parameter value: too big"); |
if (RangeMaxAsInt() && i > *RangeMaxAsInt()) throw Exception("Invalid device parameter value: too big"); |
201 |
|
|
202 |
std::vector<int> possibilities = PossibilitiesAsInt(); |
std::vector<int> possibilities = PossibilitiesAsInt(); |
203 |
if (possibilities.size()) { |
if (possibilities.size()) { |
210 |
} |
} |
211 |
iter++; |
iter++; |
212 |
} |
} |
213 |
if (!valid) throw LinuxSamplerException("Invalid device parameter value: not in set of possible values"); |
if (!valid) throw Exception("Invalid device parameter value: not in set of possible values"); |
214 |
} |
} |
215 |
SetValue(i); |
SetValue(i); |
216 |
} |
} |
219 |
return iVal; |
return iVal; |
220 |
} |
} |
221 |
|
|
222 |
void DeviceRuntimeParameterInt::SetValue(int i) throw (LinuxSamplerException) { |
void DeviceRuntimeParameterInt::SetValue(int i) throw (Exception) { |
223 |
if (Fix()) throw LinuxSamplerException("Device parameter is read only"); |
if (Fix()) throw Exception("Device parameter is read only"); |
224 |
OnSetValue(i); |
OnSetValue(i); |
225 |
iVal = i; |
iVal = i; |
226 |
} |
} |
272 |
return ToString(ValueAsFloat()); |
return ToString(ValueAsFloat()); |
273 |
} |
} |
274 |
|
|
275 |
void DeviceRuntimeParameterFloat::SetValue(String val) throw (LinuxSamplerException) { |
void DeviceRuntimeParameterFloat::SetValue(String val) throw (Exception) { |
276 |
if (Fix()) throw LinuxSamplerException("Device parameter is read only"); |
if (Fix()) throw Exception("Device parameter is read only"); |
277 |
float f = __parse_float(val); |
float f = __parse_float(val); |
278 |
if (RangeMinAsFloat() && f < *RangeMinAsFloat()) throw LinuxSamplerException("Invalid device parameter value: too small"); |
if (RangeMinAsFloat() && f < *RangeMinAsFloat()) throw Exception("Invalid device parameter value: too small"); |
279 |
if (RangeMaxAsFloat() && f > *RangeMaxAsFloat()) throw LinuxSamplerException("Invalid device parameter value: too big"); |
if (RangeMaxAsFloat() && f > *RangeMaxAsFloat()) throw Exception("Invalid device parameter value: too big"); |
280 |
|
|
281 |
std::vector<float> possibilities = PossibilitiesAsFloat(); |
std::vector<float> possibilities = PossibilitiesAsFloat(); |
282 |
if (possibilities.size()) { |
if (possibilities.size()) { |
289 |
} |
} |
290 |
iter++; |
iter++; |
291 |
} |
} |
292 |
if (!valid) throw LinuxSamplerException("Invalid device parameter value: not in set of possible values"); |
if (!valid) throw Exception("Invalid device parameter value: not in set of possible values"); |
293 |
} |
} |
294 |
SetValue(f); |
SetValue(f); |
295 |
} |
} |
298 |
return fVal; |
return fVal; |
299 |
} |
} |
300 |
|
|
301 |
void DeviceRuntimeParameterFloat::SetValue(float f) throw (LinuxSamplerException) { |
void DeviceRuntimeParameterFloat::SetValue(float f) throw (Exception) { |
302 |
if (Fix()) throw LinuxSamplerException("Device parameter is read only"); |
if (Fix()) throw Exception("Device parameter is read only"); |
303 |
OnSetValue(f); |
OnSetValue(f); |
304 |
fVal = f; |
fVal = f; |
305 |
} |
} |
347 |
return "\'" + ValueAsString() + "\'"; |
return "\'" + ValueAsString() + "\'"; |
348 |
} |
} |
349 |
|
|
350 |
void DeviceRuntimeParameterString::SetValue(String val) throw (LinuxSamplerException) { |
void DeviceRuntimeParameterString::SetValue(String val) throw (Exception) { |
351 |
if (Fix()) throw LinuxSamplerException("Device parameter is read only"); |
if (Fix()) throw Exception("Device parameter is read only"); |
352 |
SetValueAsString(__parse_string(val)); |
SetValueAsString(__parse_string(val)); |
353 |
} |
} |
354 |
|
|
356 |
return sVal; |
return sVal; |
357 |
} |
} |
358 |
|
|
359 |
void DeviceRuntimeParameterString::SetValueAsString(String val) throw (LinuxSamplerException) { |
void DeviceRuntimeParameterString::SetValueAsString(String val) throw (Exception) { |
360 |
if (Fix()) throw LinuxSamplerException("Device parameter is read only"); |
if (Fix()) throw Exception("Device parameter is read only"); |
361 |
if (val.find("\'") != String::npos) throw LinuxSamplerException("Character -> \' <- not allowed"); |
if (val.find("\'") != String::npos) throw Exception("Character -> \' <- not allowed"); |
362 |
if (val.find("\"") != String::npos) throw LinuxSamplerException("Character -> \" <- not allowed"); |
if (val.find("\"") != String::npos) throw Exception("Character -> \" <- not allowed"); |
363 |
OnSetValue(val); |
OnSetValue(val); |
364 |
sVal = val; |
sVal = val; |
365 |
} |
} |
414 |
return result; |
return result; |
415 |
} |
} |
416 |
|
|
417 |
void DeviceRuntimeParameterStrings::SetValue(String val) throw (LinuxSamplerException) { |
void DeviceRuntimeParameterStrings::SetValue(String val) throw (Exception) { |
418 |
if (Fix()) throw LinuxSamplerException("Device parameter is read only"); |
if (Fix()) throw Exception("Device parameter is read only"); |
419 |
std::vector<String> vS = __parse_strings(val); |
std::vector<String> vS = __parse_strings(val); |
420 |
SetValue(vS); |
SetValue(vS); |
421 |
} |
} |
424 |
return sVals; |
return sVals; |
425 |
} |
} |
426 |
|
|
427 |
void DeviceRuntimeParameterStrings::SetValue(std::vector<String> vS) throw (LinuxSamplerException) { |
void DeviceRuntimeParameterStrings::SetValue(std::vector<String> vS) throw (Exception) { |
428 |
if (Fix()) throw LinuxSamplerException("Device parameter is read only"); |
if (Fix()) throw Exception("Device parameter is read only"); |
429 |
OnSetValue(vS); |
OnSetValue(vS); |
430 |
sVals = vS; |
sVals = vS; |
431 |
} |
} |
480 |
this->bVal = bVal; |
this->bVal = bVal; |
481 |
} |
} |
482 |
|
|
483 |
DeviceCreationParameterBool::DeviceCreationParameterBool(String val) throw (LinuxSamplerException) { |
DeviceCreationParameterBool::DeviceCreationParameterBool(String val) throw (Exception) { |
484 |
this->bVal = __parse_bool(val); |
this->bVal = __parse_bool(val); |
485 |
} |
} |
486 |
|
|
520 |
return (ValueAsBool()) ? "true" : "false"; |
return (ValueAsBool()) ? "true" : "false"; |
521 |
} |
} |
522 |
|
|
523 |
void DeviceCreationParameterBool::SetValue(String val) throw (LinuxSamplerException) { |
void DeviceCreationParameterBool::SetValue(String val) throw (Exception) { |
524 |
if (Fix()) throw LinuxSamplerException("Device parameter is read only"); |
if (Fix()) throw Exception("Device parameter is read only"); |
525 |
int b = __parse_bool(val); |
int b = __parse_bool(val); |
526 |
SetValue(b); |
SetValue(b); |
527 |
} |
} |
530 |
return bVal; |
return bVal; |
531 |
} |
} |
532 |
|
|
533 |
void DeviceCreationParameterBool::SetValue(bool b) throw (LinuxSamplerException) { |
void DeviceCreationParameterBool::SetValue(bool b) throw (Exception) { |
534 |
if (Fix()) throw LinuxSamplerException("Device parameter is read only"); |
if (Fix()) throw Exception("Device parameter is read only"); |
535 |
OnSetValue(b); |
OnSetValue(b); |
536 |
bVal = b; |
bVal = b; |
537 |
} |
} |
545 |
this->iVal = iVal; |
this->iVal = iVal; |
546 |
} |
} |
547 |
|
|
548 |
DeviceCreationParameterInt::DeviceCreationParameterInt(String val) throw (LinuxSamplerException) { |
DeviceCreationParameterInt::DeviceCreationParameterInt(String val) throw (Exception) { |
549 |
this->iVal = __parse_int(val); |
this->iVal = __parse_int(val); |
550 |
} |
} |
551 |
|
|
599 |
return ToString(ValueAsInt()); |
return ToString(ValueAsInt()); |
600 |
} |
} |
601 |
|
|
602 |
void DeviceCreationParameterInt::SetValue(String val) throw (LinuxSamplerException) { |
void DeviceCreationParameterInt::SetValue(String val) throw (Exception) { |
603 |
if (Fix()) throw LinuxSamplerException("Device parameter is read only"); |
if (Fix()) throw Exception("Device parameter is read only"); |
604 |
int i = __parse_int(val); |
int i = __parse_int(val); |
605 |
//if (RangeMinAsInt() && i < *RangeMinAsInt()) throw LinuxSamplerException("Invalid device parameter value: too small"); |
//if (RangeMinAsInt() && i < *RangeMinAsInt()) throw Exception("Invalid device parameter value: too small"); |
606 |
//if (RangeMaxAsInt() && i > *RangeMaxAsInt()) throw LinuxSamplerException("Invalid device parameter value: too big"); |
//if (RangeMaxAsInt() && i > *RangeMaxAsInt()) throw Exception("Invalid device parameter value: too big"); |
607 |
/*if (PossibilitiesAsInt()) { |
/*if (PossibilitiesAsInt()) { |
608 |
bool valid = false; |
bool valid = false; |
609 |
std::vector<int>* pPossibilities = PossibilitiesAsInt(); |
std::vector<int>* pPossibilities = PossibilitiesAsInt(); |
615 |
} |
} |
616 |
iter++; |
iter++; |
617 |
} |
} |
618 |
if (!valid) throw LinuxSamplerException("Invalid Device parameter value: not in set of possible values"); |
if (!valid) throw Exception("Invalid Device parameter value: not in set of possible values"); |
619 |
}*/ |
}*/ |
620 |
SetValue(i); |
SetValue(i); |
621 |
} |
} |
624 |
return iVal; |
return iVal; |
625 |
} |
} |
626 |
|
|
627 |
void DeviceCreationParameterInt::SetValue(int i) throw (LinuxSamplerException) { |
void DeviceCreationParameterInt::SetValue(int i) throw (Exception) { |
628 |
if (Fix()) throw LinuxSamplerException("Device parameter is read only"); |
if (Fix()) throw Exception("Device parameter is read only"); |
629 |
OnSetValue(i); |
OnSetValue(i); |
630 |
iVal = i; |
iVal = i; |
631 |
} |
} |
639 |
this->fVal = fVal; |
this->fVal = fVal; |
640 |
} |
} |
641 |
|
|
642 |
DeviceCreationParameterFloat::DeviceCreationParameterFloat(String val) throw (LinuxSamplerException) { |
DeviceCreationParameterFloat::DeviceCreationParameterFloat(String val) throw (Exception) { |
643 |
this->fVal = __parse_float(val); |
this->fVal = __parse_float(val); |
644 |
} |
} |
645 |
|
|
693 |
return ToString(ValueAsFloat()); |
return ToString(ValueAsFloat()); |
694 |
} |
} |
695 |
|
|
696 |
void DeviceCreationParameterFloat::SetValue(String val) throw (LinuxSamplerException) { |
void DeviceCreationParameterFloat::SetValue(String val) throw (Exception) { |
697 |
if (Fix()) throw LinuxSamplerException("Device parameter is read only"); |
if (Fix()) throw Exception("Device parameter is read only"); |
698 |
float f = __parse_float(val); |
float f = __parse_float(val); |
699 |
//if (RangeMinAsFloat() && i < *RangeMinAsFloat()) throw LinuxSamplerException("Invalid device parameter value: too small"); |
//if (RangeMinAsFloat() && i < *RangeMinAsFloat()) throw Exception("Invalid device parameter value: too small"); |
700 |
//if (RangeMaxAsFloat() && i > *RangeMaxAsFloat()) throw LinuxSamplerException("Invalid device parameter value: too big"); |
//if (RangeMaxAsFloat() && i > *RangeMaxAsFloat()) throw Exception("Invalid device parameter value: too big"); |
701 |
/*if (PossibilitiesAsFloat()) { |
/*if (PossibilitiesAsFloat()) { |
702 |
bool valid = false; |
bool valid = false; |
703 |
std::vector<float>* pPossibilities = PossibilitiesAsFloat(); |
std::vector<float>* pPossibilities = PossibilitiesAsFloat(); |
709 |
} |
} |
710 |
iter++; |
iter++; |
711 |
} |
} |
712 |
if (!valid) throw LinuxSamplerException("Invalid Device parameter value: not in set of possible values"); |
if (!valid) throw Exception("Invalid Device parameter value: not in set of possible values"); |
713 |
}*/ |
}*/ |
714 |
SetValue(f); |
SetValue(f); |
715 |
} |
} |
718 |
return fVal; |
return fVal; |
719 |
} |
} |
720 |
|
|
721 |
void DeviceCreationParameterFloat::SetValue(float f) throw (LinuxSamplerException) { |
void DeviceCreationParameterFloat::SetValue(float f) throw (Exception) { |
722 |
if (Fix()) throw LinuxSamplerException("Device parameter is read only"); |
if (Fix()) throw Exception("Device parameter is read only"); |
723 |
OnSetValue(f); |
OnSetValue(f); |
724 |
fVal = f; |
fVal = f; |
725 |
} |
} |
780 |
return "\'" + ValueAsString() + "\'"; |
return "\'" + ValueAsString() + "\'"; |
781 |
} |
} |
782 |
|
|
783 |
void DeviceCreationParameterString::SetValue(String val) throw (LinuxSamplerException) { |
void DeviceCreationParameterString::SetValue(String val) throw (Exception) { |
784 |
if (Fix()) throw LinuxSamplerException("Device parameter is read only"); |
if (Fix()) throw Exception("Device parameter is read only"); |
785 |
SetValueAsString(__parse_string(val)); |
SetValueAsString(__parse_string(val)); |
786 |
} |
} |
787 |
|
|
789 |
return sVal; |
return sVal; |
790 |
} |
} |
791 |
|
|
792 |
void DeviceCreationParameterString::SetValueAsString(String val) throw (LinuxSamplerException) { |
void DeviceCreationParameterString::SetValueAsString(String val) throw (Exception) { |
793 |
if (val.find("\'") != String::npos) throw LinuxSamplerException("Character -> \' <- not allowed"); |
if (val.find("\'") != String::npos) throw Exception("Character -> \' <- not allowed"); |
794 |
if (val.find("\"") != String::npos) throw LinuxSamplerException("Character -> \" <- not allowed"); |
if (val.find("\"") != String::npos) throw Exception("Character -> \" <- not allowed"); |
795 |
OnSetValue(val); |
OnSetValue(val); |
796 |
sVal = val; |
sVal = val; |
797 |
} |
} |
805 |
this->sVals = sVals; |
this->sVals = sVals; |
806 |
} |
} |
807 |
|
|
808 |
DeviceCreationParameterStrings::DeviceCreationParameterStrings(String val) throw (LinuxSamplerException) { |
DeviceCreationParameterStrings::DeviceCreationParameterStrings(String val) throw (Exception) { |
809 |
this->sVals = __parse_strings(val); |
this->sVals = __parse_strings(val); |
810 |
} |
} |
811 |
|
|
868 |
return result; |
return result; |
869 |
} |
} |
870 |
|
|
871 |
void DeviceCreationParameterStrings::SetValue(String val) throw (LinuxSamplerException) { |
void DeviceCreationParameterStrings::SetValue(String val) throw (Exception) { |
872 |
if (Fix()) throw LinuxSamplerException("Device parameter is read only"); |
if (Fix()) throw Exception("Device parameter is read only"); |
873 |
std::vector<String> vS = __parse_strings(val); |
std::vector<String> vS = __parse_strings(val); |
874 |
SetValue(vS); |
SetValue(vS); |
875 |
} |
} |
878 |
return sVals; |
return sVals; |
879 |
} |
} |
880 |
|
|
881 |
void DeviceCreationParameterStrings::SetValue(std::vector<String> vS) throw (LinuxSamplerException) { |
void DeviceCreationParameterStrings::SetValue(std::vector<String> vS) throw (Exception) { |
882 |
if (Fix()) throw LinuxSamplerException("Device parameter is read only"); |
if (Fix()) throw Exception("Device parameter is read only"); |
883 |
OnSetValue(vS); |
OnSetValue(vS); |
884 |
sVals = vS; |
sVals = vS; |
885 |
} |
} |