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 |
|
// checking for empty list |
70 |
|
if (val.length() == 0) return vS; |
71 |
|
|
72 |
// 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 |
73 |
if (val.find("\'") == String::npos && val.find("\"") == String::npos) { |
if (val.find("\'") == String::npos && val.find("\"") == String::npos) { |
78 |
char* pC = pStart; |
char* pC = pStart; |
79 |
|
|
80 |
while (true) { |
while (true) { |
81 |
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"); |
82 |
|
|
83 |
// search for token end |
// search for token end |
84 |
char* pTokenStart = pC + 1; |
char* pTokenStart = pC + 1; |
85 |
do { |
do { |
86 |
pC++; |
pC++; |
87 |
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"); |
88 |
} |
} |
89 |
while (*pC != '\'' && *pC != '\"'); |
while (*pC != '\'' && *pC != '\"'); |
90 |
String token = val.substr((int)(pTokenStart - pStart), (int)(pC - pTokenStart)); |
String token = val.substr((int)(pTokenStart - pStart), (int)(pC - pTokenStart)); |
92 |
|
|
93 |
// 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 |
94 |
if (*(++pC) == '\0') break; |
if (*(++pC) == '\0') break; |
95 |
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"); |
96 |
pC++; |
pC++; |
97 |
} |
} |
98 |
} |
} |
133 |
return (ValueAsBool()) ? "true" : "false"; |
return (ValueAsBool()) ? "true" : "false"; |
134 |
} |
} |
135 |
|
|
136 |
void DeviceRuntimeParameterBool::SetValue(String val) throw (LinuxSamplerException) { |
void DeviceRuntimeParameterBool::SetValue(String val) throw (Exception) { |
137 |
if (Fix()) throw LinuxSamplerException("Device parameter is read only"); |
if (Fix()) throw Exception("Device parameter is read only"); |
138 |
int b = __parse_bool(val); |
int b = __parse_bool(val); |
139 |
SetValue(b); |
SetValue(b); |
140 |
} |
} |
143 |
return bVal; |
return bVal; |
144 |
} |
} |
145 |
|
|
146 |
void DeviceRuntimeParameterBool::SetValue(bool b) throw (LinuxSamplerException) { |
void DeviceRuntimeParameterBool::SetValue(bool b) throw (Exception) { |
147 |
if (Fix()) throw LinuxSamplerException("Device parameter is read only"); |
if (Fix()) throw Exception("Device parameter is read only"); |
148 |
OnSetValue(b); |
OnSetValue(b); |
149 |
bVal = b; |
bVal = b; |
150 |
} |
} |
196 |
return ToString(ValueAsInt()); |
return ToString(ValueAsInt()); |
197 |
} |
} |
198 |
|
|
199 |
void DeviceRuntimeParameterInt::SetValue(String val) throw (LinuxSamplerException) { |
void DeviceRuntimeParameterInt::SetValue(String val) throw (Exception) { |
200 |
if (Fix()) throw LinuxSamplerException("Device parameter is read only"); |
if (Fix()) throw Exception("Device parameter is read only"); |
201 |
int i = __parse_int(val); |
int i = __parse_int(val); |
202 |
if (RangeMinAsInt() && i < *RangeMinAsInt()) throw LinuxSamplerException("Invalid device parameter value: too small"); |
if (RangeMinAsInt() && i < *RangeMinAsInt()) throw Exception("Invalid device parameter value: too small"); |
203 |
if (RangeMaxAsInt() && i > *RangeMaxAsInt()) throw LinuxSamplerException("Invalid device parameter value: too big"); |
if (RangeMaxAsInt() && i > *RangeMaxAsInt()) throw Exception("Invalid device parameter value: too big"); |
204 |
|
|
205 |
std::vector<int> possibilities = PossibilitiesAsInt(); |
std::vector<int> possibilities = PossibilitiesAsInt(); |
206 |
if (possibilities.size()) { |
if (possibilities.size()) { |
213 |
} |
} |
214 |
iter++; |
iter++; |
215 |
} |
} |
216 |
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"); |
217 |
} |
} |
218 |
SetValue(i); |
SetValue(i); |
219 |
} |
} |
222 |
return iVal; |
return iVal; |
223 |
} |
} |
224 |
|
|
225 |
void DeviceRuntimeParameterInt::SetValue(int i) throw (LinuxSamplerException) { |
void DeviceRuntimeParameterInt::SetValue(int i) throw (Exception) { |
226 |
if (Fix()) throw LinuxSamplerException("Device parameter is read only"); |
if (Fix()) throw Exception("Device parameter is read only"); |
227 |
OnSetValue(i); |
OnSetValue(i); |
228 |
iVal = i; |
iVal = i; |
229 |
} |
} |
275 |
return ToString(ValueAsFloat()); |
return ToString(ValueAsFloat()); |
276 |
} |
} |
277 |
|
|
278 |
void DeviceRuntimeParameterFloat::SetValue(String val) throw (LinuxSamplerException) { |
void DeviceRuntimeParameterFloat::SetValue(String val) throw (Exception) { |
279 |
if (Fix()) throw LinuxSamplerException("Device parameter is read only"); |
if (Fix()) throw Exception("Device parameter is read only"); |
280 |
float f = __parse_float(val); |
float f = __parse_float(val); |
281 |
if (RangeMinAsFloat() && f < *RangeMinAsFloat()) throw LinuxSamplerException("Invalid device parameter value: too small"); |
if (RangeMinAsFloat() && f < *RangeMinAsFloat()) throw Exception("Invalid device parameter value: too small"); |
282 |
if (RangeMaxAsFloat() && f > *RangeMaxAsFloat()) throw LinuxSamplerException("Invalid device parameter value: too big"); |
if (RangeMaxAsFloat() && f > *RangeMaxAsFloat()) throw Exception("Invalid device parameter value: too big"); |
283 |
|
|
284 |
std::vector<float> possibilities = PossibilitiesAsFloat(); |
std::vector<float> possibilities = PossibilitiesAsFloat(); |
285 |
if (possibilities.size()) { |
if (possibilities.size()) { |
292 |
} |
} |
293 |
iter++; |
iter++; |
294 |
} |
} |
295 |
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"); |
296 |
} |
} |
297 |
SetValue(f); |
SetValue(f); |
298 |
} |
} |
301 |
return fVal; |
return fVal; |
302 |
} |
} |
303 |
|
|
304 |
void DeviceRuntimeParameterFloat::SetValue(float f) throw (LinuxSamplerException) { |
void DeviceRuntimeParameterFloat::SetValue(float f) throw (Exception) { |
305 |
if (Fix()) throw LinuxSamplerException("Device parameter is read only"); |
if (Fix()) throw Exception("Device parameter is read only"); |
306 |
OnSetValue(f); |
OnSetValue(f); |
307 |
fVal = f; |
fVal = f; |
308 |
} |
} |
350 |
return "\'" + ValueAsString() + "\'"; |
return "\'" + ValueAsString() + "\'"; |
351 |
} |
} |
352 |
|
|
353 |
void DeviceRuntimeParameterString::SetValue(String val) throw (LinuxSamplerException) { |
void DeviceRuntimeParameterString::SetValue(String val) throw (Exception) { |
354 |
if (Fix()) throw LinuxSamplerException("Device parameter is read only"); |
if (Fix()) throw Exception("Device parameter is read only"); |
355 |
SetValueAsString(__parse_string(val)); |
SetValueAsString(__parse_string(val)); |
356 |
} |
} |
357 |
|
|
359 |
return sVal; |
return sVal; |
360 |
} |
} |
361 |
|
|
362 |
void DeviceRuntimeParameterString::SetValueAsString(String val) throw (LinuxSamplerException) { |
void DeviceRuntimeParameterString::SetValueAsString(String val) throw (Exception) { |
363 |
if (Fix()) throw LinuxSamplerException("Device parameter is read only"); |
if (Fix()) throw Exception("Device parameter is read only"); |
364 |
if (val.find("\'") != String::npos) throw LinuxSamplerException("Character -> \' <- not allowed"); |
if (val.find("\'") != String::npos) throw Exception("Character -> \' <- not allowed"); |
365 |
if (val.find("\"") != String::npos) throw LinuxSamplerException("Character -> \" <- not allowed"); |
if (val.find("\"") != String::npos) throw Exception("Character -> \" <- not allowed"); |
366 |
OnSetValue(val); |
OnSetValue(val); |
367 |
sVal = val; |
sVal = val; |
368 |
} |
} |
417 |
return result; |
return result; |
418 |
} |
} |
419 |
|
|
420 |
void DeviceRuntimeParameterStrings::SetValue(String val) throw (LinuxSamplerException) { |
void DeviceRuntimeParameterStrings::SetValue(String val) throw (Exception) { |
421 |
if (Fix()) throw LinuxSamplerException("Device parameter is read only"); |
if (Fix()) throw Exception("Device parameter is read only"); |
422 |
std::vector<String> vS = __parse_strings(val); |
std::vector<String> vS = __parse_strings(val); |
423 |
SetValue(vS); |
SetValue(vS); |
424 |
} |
} |
427 |
return sVals; |
return sVals; |
428 |
} |
} |
429 |
|
|
430 |
void DeviceRuntimeParameterStrings::SetValue(std::vector<String> vS) throw (LinuxSamplerException) { |
void DeviceRuntimeParameterStrings::SetValue(std::vector<String> vS) throw (Exception) { |
431 |
if (Fix()) throw LinuxSamplerException("Device parameter is read only"); |
if (Fix()) throw Exception("Device parameter is read only"); |
432 |
OnSetValue(vS); |
OnSetValue(vS); |
433 |
sVals = vS; |
sVals = vS; |
434 |
} |
} |
483 |
this->bVal = bVal; |
this->bVal = bVal; |
484 |
} |
} |
485 |
|
|
486 |
DeviceCreationParameterBool::DeviceCreationParameterBool(String val) throw (LinuxSamplerException) { |
DeviceCreationParameterBool::DeviceCreationParameterBool(String val) throw (Exception) { |
487 |
this->bVal = __parse_bool(val); |
this->bVal = __parse_bool(val); |
488 |
} |
} |
489 |
|
|
523 |
return (ValueAsBool()) ? "true" : "false"; |
return (ValueAsBool()) ? "true" : "false"; |
524 |
} |
} |
525 |
|
|
526 |
void DeviceCreationParameterBool::SetValue(String val) throw (LinuxSamplerException) { |
void DeviceCreationParameterBool::SetValue(String val) throw (Exception) { |
527 |
if (Fix()) throw LinuxSamplerException("Device parameter is read only"); |
if (Fix()) throw Exception("Device parameter is read only"); |
528 |
int b = __parse_bool(val); |
int b = __parse_bool(val); |
529 |
SetValue(b); |
SetValue(b); |
530 |
} |
} |
533 |
return bVal; |
return bVal; |
534 |
} |
} |
535 |
|
|
536 |
void DeviceCreationParameterBool::SetValue(bool b) throw (LinuxSamplerException) { |
void DeviceCreationParameterBool::SetValue(bool b) throw (Exception) { |
537 |
if (Fix()) throw LinuxSamplerException("Device parameter is read only"); |
if (Fix()) throw Exception("Device parameter is read only"); |
538 |
OnSetValue(b); |
OnSetValue(b); |
539 |
bVal = b; |
bVal = b; |
540 |
} |
} |
548 |
this->iVal = iVal; |
this->iVal = iVal; |
549 |
} |
} |
550 |
|
|
551 |
DeviceCreationParameterInt::DeviceCreationParameterInt(String val) throw (LinuxSamplerException) { |
DeviceCreationParameterInt::DeviceCreationParameterInt(String val) throw (Exception) { |
552 |
this->iVal = __parse_int(val); |
this->iVal = __parse_int(val); |
553 |
} |
} |
554 |
|
|
602 |
return ToString(ValueAsInt()); |
return ToString(ValueAsInt()); |
603 |
} |
} |
604 |
|
|
605 |
void DeviceCreationParameterInt::SetValue(String val) throw (LinuxSamplerException) { |
void DeviceCreationParameterInt::SetValue(String val) throw (Exception) { |
606 |
if (Fix()) throw LinuxSamplerException("Device parameter is read only"); |
if (Fix()) throw Exception("Device parameter is read only"); |
607 |
int i = __parse_int(val); |
int i = __parse_int(val); |
608 |
//if (RangeMinAsInt() && i < *RangeMinAsInt()) throw LinuxSamplerException("Invalid device parameter value: too small"); |
//if (RangeMinAsInt() && i < *RangeMinAsInt()) throw Exception("Invalid device parameter value: too small"); |
609 |
//if (RangeMaxAsInt() && i > *RangeMaxAsInt()) throw LinuxSamplerException("Invalid device parameter value: too big"); |
//if (RangeMaxAsInt() && i > *RangeMaxAsInt()) throw Exception("Invalid device parameter value: too big"); |
610 |
/*if (PossibilitiesAsInt()) { |
/*if (PossibilitiesAsInt()) { |
611 |
bool valid = false; |
bool valid = false; |
612 |
std::vector<int>* pPossibilities = PossibilitiesAsInt(); |
std::vector<int>* pPossibilities = PossibilitiesAsInt(); |
618 |
} |
} |
619 |
iter++; |
iter++; |
620 |
} |
} |
621 |
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"); |
622 |
}*/ |
}*/ |
623 |
SetValue(i); |
SetValue(i); |
624 |
} |
} |
627 |
return iVal; |
return iVal; |
628 |
} |
} |
629 |
|
|
630 |
void DeviceCreationParameterInt::SetValue(int i) throw (LinuxSamplerException) { |
void DeviceCreationParameterInt::SetValue(int i) throw (Exception) { |
631 |
if (Fix()) throw LinuxSamplerException("Device parameter is read only"); |
if (Fix()) throw Exception("Device parameter is read only"); |
632 |
OnSetValue(i); |
OnSetValue(i); |
633 |
iVal = i; |
iVal = i; |
634 |
} |
} |
642 |
this->fVal = fVal; |
this->fVal = fVal; |
643 |
} |
} |
644 |
|
|
645 |
DeviceCreationParameterFloat::DeviceCreationParameterFloat(String val) throw (LinuxSamplerException) { |
DeviceCreationParameterFloat::DeviceCreationParameterFloat(String val) throw (Exception) { |
646 |
this->fVal = __parse_float(val); |
this->fVal = __parse_float(val); |
647 |
} |
} |
648 |
|
|
696 |
return ToString(ValueAsFloat()); |
return ToString(ValueAsFloat()); |
697 |
} |
} |
698 |
|
|
699 |
void DeviceCreationParameterFloat::SetValue(String val) throw (LinuxSamplerException) { |
void DeviceCreationParameterFloat::SetValue(String val) throw (Exception) { |
700 |
if (Fix()) throw LinuxSamplerException("Device parameter is read only"); |
if (Fix()) throw Exception("Device parameter is read only"); |
701 |
float f = __parse_float(val); |
float f = __parse_float(val); |
702 |
//if (RangeMinAsFloat() && i < *RangeMinAsFloat()) throw LinuxSamplerException("Invalid device parameter value: too small"); |
//if (RangeMinAsFloat() && i < *RangeMinAsFloat()) throw Exception("Invalid device parameter value: too small"); |
703 |
//if (RangeMaxAsFloat() && i > *RangeMaxAsFloat()) throw LinuxSamplerException("Invalid device parameter value: too big"); |
//if (RangeMaxAsFloat() && i > *RangeMaxAsFloat()) throw Exception("Invalid device parameter value: too big"); |
704 |
/*if (PossibilitiesAsFloat()) { |
/*if (PossibilitiesAsFloat()) { |
705 |
bool valid = false; |
bool valid = false; |
706 |
std::vector<float>* pPossibilities = PossibilitiesAsFloat(); |
std::vector<float>* pPossibilities = PossibilitiesAsFloat(); |
712 |
} |
} |
713 |
iter++; |
iter++; |
714 |
} |
} |
715 |
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"); |
716 |
}*/ |
}*/ |
717 |
SetValue(f); |
SetValue(f); |
718 |
} |
} |
721 |
return fVal; |
return fVal; |
722 |
} |
} |
723 |
|
|
724 |
void DeviceCreationParameterFloat::SetValue(float f) throw (LinuxSamplerException) { |
void DeviceCreationParameterFloat::SetValue(float f) throw (Exception) { |
725 |
if (Fix()) throw LinuxSamplerException("Device parameter is read only"); |
if (Fix()) throw Exception("Device parameter is read only"); |
726 |
OnSetValue(f); |
OnSetValue(f); |
727 |
fVal = f; |
fVal = f; |
728 |
} |
} |
783 |
return "\'" + ValueAsString() + "\'"; |
return "\'" + ValueAsString() + "\'"; |
784 |
} |
} |
785 |
|
|
786 |
void DeviceCreationParameterString::SetValue(String val) throw (LinuxSamplerException) { |
void DeviceCreationParameterString::SetValue(String val) throw (Exception) { |
787 |
if (Fix()) throw LinuxSamplerException("Device parameter is read only"); |
if (Fix()) throw Exception("Device parameter is read only"); |
788 |
SetValueAsString(__parse_string(val)); |
SetValueAsString(__parse_string(val)); |
789 |
} |
} |
790 |
|
|
792 |
return sVal; |
return sVal; |
793 |
} |
} |
794 |
|
|
795 |
void DeviceCreationParameterString::SetValueAsString(String val) throw (LinuxSamplerException) { |
void DeviceCreationParameterString::SetValueAsString(String val) throw (Exception) { |
796 |
if (val.find("\'") != String::npos) throw LinuxSamplerException("Character -> \' <- not allowed"); |
if (val.find("\'") != String::npos) throw Exception("Character -> \' <- not allowed"); |
797 |
if (val.find("\"") != String::npos) throw LinuxSamplerException("Character -> \" <- not allowed"); |
if (val.find("\"") != String::npos) throw Exception("Character -> \" <- not allowed"); |
798 |
OnSetValue(val); |
OnSetValue(val); |
799 |
sVal = val; |
sVal = val; |
800 |
} |
} |
808 |
this->sVals = sVals; |
this->sVals = sVals; |
809 |
} |
} |
810 |
|
|
811 |
DeviceCreationParameterStrings::DeviceCreationParameterStrings(String val) throw (LinuxSamplerException) { |
DeviceCreationParameterStrings::DeviceCreationParameterStrings(String val) throw (Exception) { |
812 |
this->sVals = __parse_strings(val); |
this->sVals = __parse_strings(val); |
813 |
} |
} |
814 |
|
|
871 |
return result; |
return result; |
872 |
} |
} |
873 |
|
|
874 |
void DeviceCreationParameterStrings::SetValue(String val) throw (LinuxSamplerException) { |
void DeviceCreationParameterStrings::SetValue(String val) throw (Exception) { |
875 |
if (Fix()) throw LinuxSamplerException("Device parameter is read only"); |
if (Fix()) throw Exception("Device parameter is read only"); |
876 |
std::vector<String> vS = __parse_strings(val); |
std::vector<String> vS = __parse_strings(val); |
877 |
SetValue(vS); |
SetValue(vS); |
878 |
} |
} |
881 |
return sVals; |
return sVals; |
882 |
} |
} |
883 |
|
|
884 |
void DeviceCreationParameterStrings::SetValue(std::vector<String> vS) throw (LinuxSamplerException) { |
void DeviceCreationParameterStrings::SetValue(std::vector<String> vS) throw (Exception) { |
885 |
if (Fix()) throw LinuxSamplerException("Device parameter is read only"); |
if (Fix()) throw Exception("Device parameter is read only"); |
886 |
OnSetValue(vS); |
OnSetValue(vS); |
887 |
sVals = vS; |
sVals = vS; |
888 |
} |
} |