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 * |
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 * |
28 |
|
|
29 |
namespace LinuxSampler { |
namespace LinuxSampler { |
30 |
|
|
31 |
|
// if string is encapsulated into apostrophes or quotation marks, then remove those apostrophes / quotation marks |
32 |
|
static void __eliminate_quotation(String& s) { |
33 |
|
if (s.size()) { |
34 |
|
const char cBegin = s[0]; |
35 |
|
const char cEnd = s[s.size() - 1]; |
36 |
|
if ( (cBegin == '\'' && cEnd == '\'') || (cBegin == '\"' && cEnd == '\"') ) { |
37 |
|
s = s.substr(1, s.size() - 2); |
38 |
|
} |
39 |
|
} |
40 |
|
} |
41 |
|
|
42 |
static bool __parse_bool(String val) throw (LinuxSamplerException) { |
static bool __parse_bool(String val) throw (LinuxSamplerException) { |
43 |
|
__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; |
49 |
} |
} |
50 |
|
|
51 |
static int __parse_int(String val) throw (LinuxSamplerException) { |
static int __parse_int(String val) throw (LinuxSamplerException) { |
52 |
|
__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 (LinuxSamplerException) { |
57 |
|
__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 |
} |
} |
60 |
|
|
61 |
|
static String __parse_string(String val) { |
62 |
|
__eliminate_quotation(val); |
63 |
|
return val; |
64 |
|
} |
65 |
|
|
66 |
static std::vector<String> __parse_strings(String val) throw (LinuxSamplerException) { |
static std::vector<String> __parse_strings(String val) throw (LinuxSamplerException) { |
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 encapsulted into apostrophes |
// if there's only a single value, then we also allow to give it without being encapsulated into apostrophes |
70 |
if (val.find("\'") == String::npos && val.find("\"") == String::npos) { |
if (val.find("\'") == String::npos && val.find("\"") == String::npos) { |
71 |
vS.push_back(val); |
vS.push_back(val); |
72 |
} |
} |
73 |
else { // if multiple strings or a string encapsulated into apostrophes |
else { // if multiple strings or a string encapsulated into apostrophes |
74 |
char* pStart = (char*) val.c_str(); |
char* pStart = (char*) val.c_str(); |
75 |
char* pC = pStart; |
char* pC = pStart; |
|
if (*pC != '\'' && *pC != '\"') throw LinuxSamplerException("Invalid form, all individual strings should be encapsulated into apostrophes, separated by commas"); |
|
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"); |
79 |
|
|
80 |
// search for token end |
// search for token end |
81 |
char* pTokenStart = pC + 1; |
char* pTokenStart = pC + 1; |
82 |
do { |
do { |
84 |
if (*pC == '\0') throw LinuxSamplerException("Invalid form, all individual strings should be encapsulated into apostrophes, separated by commas"); |
if (*pC == '\0') throw LinuxSamplerException("Invalid form, all individual strings should be encapsulated into apostrophes, separated by commas"); |
85 |
} |
} |
86 |
while (*pC != '\'' && *pC != '\"'); |
while (*pC != '\'' && *pC != '\"'); |
87 |
vS.push_back(val.substr((int)(pTokenStart - pStart), (int)(pC - pTokenStart))); // we found the token's end |
String token = val.substr((int)(pTokenStart - pStart), (int)(pC - pTokenStart)); |
88 |
|
vS.push_back(token); // we found the token's end |
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 LinuxSamplerException("Invalid form, all individual strings should be encapsulated into apostrophes, separated by commas"); |
93 |
|
pC++; |
94 |
} |
} |
95 |
} |
} |
96 |
|
|
127 |
} |
} |
128 |
|
|
129 |
String DeviceRuntimeParameterBool::Value() { |
String DeviceRuntimeParameterBool::Value() { |
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 (LinuxSamplerException) { |
134 |
if (Fix()) throw LinuxSamplerException("Device parameter is read only"); |
if (Fix()) throw LinuxSamplerException("Device parameter is read only"); |
135 |
int b = __parse_bool(val); |
int b = __parse_bool(val); |
|
OnSetValue(b); |
|
136 |
SetValue(b); |
SetValue(b); |
137 |
} |
} |
138 |
|
|
140 |
return bVal; |
return bVal; |
141 |
} |
} |
142 |
|
|
143 |
void DeviceRuntimeParameterBool::SetValue(bool b) { |
void DeviceRuntimeParameterBool::SetValue(bool b) throw (LinuxSamplerException) { |
144 |
|
if (Fix()) throw LinuxSamplerException("Device parameter is read only"); |
145 |
|
OnSetValue(b); |
146 |
bVal = b; |
bVal = b; |
147 |
} |
} |
148 |
|
|
212 |
} |
} |
213 |
if (!valid) throw LinuxSamplerException("Invalid device parameter value: not in set of possible values"); |
if (!valid) throw LinuxSamplerException("Invalid device parameter value: not in set of possible values"); |
214 |
} |
} |
|
OnSetValue(i); |
|
215 |
SetValue(i); |
SetValue(i); |
216 |
} |
} |
217 |
|
|
219 |
return iVal; |
return iVal; |
220 |
} |
} |
221 |
|
|
222 |
void DeviceRuntimeParameterInt::SetValue(int i) { |
void DeviceRuntimeParameterInt::SetValue(int i) throw (LinuxSamplerException) { |
223 |
|
if (Fix()) throw LinuxSamplerException("Device parameter is read only"); |
224 |
|
OnSetValue(i); |
225 |
iVal = i; |
iVal = i; |
226 |
} |
} |
227 |
|
|
291 |
} |
} |
292 |
if (!valid) throw LinuxSamplerException("Invalid device parameter value: not in set of possible values"); |
if (!valid) throw LinuxSamplerException("Invalid device parameter value: not in set of possible values"); |
293 |
} |
} |
|
OnSetValue(f); |
|
294 |
SetValue(f); |
SetValue(f); |
295 |
} |
} |
296 |
|
|
298 |
return fVal; |
return fVal; |
299 |
} |
} |
300 |
|
|
301 |
void DeviceRuntimeParameterFloat::SetValue(float f) { |
void DeviceRuntimeParameterFloat::SetValue(float f) throw (LinuxSamplerException) { |
302 |
|
if (Fix()) throw LinuxSamplerException("Device parameter is read only"); |
303 |
|
OnSetValue(f); |
304 |
fVal = f; |
fVal = f; |
305 |
} |
} |
306 |
|
|
344 |
} |
} |
345 |
|
|
346 |
String DeviceRuntimeParameterString::Value() { |
String DeviceRuntimeParameterString::Value() { |
347 |
return sVal; |
return "\'" + ValueAsString() + "\'"; |
348 |
} |
} |
349 |
|
|
350 |
void DeviceRuntimeParameterString::SetValue(String val) throw (LinuxSamplerException) { |
void DeviceRuntimeParameterString::SetValue(String val) throw (LinuxSamplerException) { |
351 |
if (Fix()) throw LinuxSamplerException("Device parameter is read only"); |
if (Fix()) throw LinuxSamplerException("Device parameter is read only"); |
352 |
|
SetValueAsString(__parse_string(val)); |
353 |
|
} |
354 |
|
|
355 |
|
String DeviceRuntimeParameterString::ValueAsString() { |
356 |
|
return sVal; |
357 |
|
} |
358 |
|
|
359 |
|
void DeviceRuntimeParameterString::SetValueAsString(String val) throw (LinuxSamplerException) { |
360 |
|
if (Fix()) throw LinuxSamplerException("Device parameter is read only"); |
361 |
if (val.find("\'") != String::npos) throw LinuxSamplerException("Character -> \' <- not allowed"); |
if (val.find("\'") != String::npos) throw LinuxSamplerException("Character -> \' <- not allowed"); |
362 |
if (val.find("\"") != String::npos) throw LinuxSamplerException("Character -> \" <- not allowed"); |
if (val.find("\"") != String::npos) throw LinuxSamplerException("Character -> \" <- not allowed"); |
363 |
OnSetValue(val); |
OnSetValue(val); |
417 |
void DeviceRuntimeParameterStrings::SetValue(String val) throw (LinuxSamplerException) { |
void DeviceRuntimeParameterStrings::SetValue(String val) throw (LinuxSamplerException) { |
418 |
if (Fix()) throw LinuxSamplerException("Device parameter is read only"); |
if (Fix()) throw LinuxSamplerException("Device parameter is read only"); |
419 |
std::vector<String> vS = __parse_strings(val); |
std::vector<String> vS = __parse_strings(val); |
|
OnSetValue(vS); |
|
420 |
SetValue(vS); |
SetValue(vS); |
421 |
} |
} |
422 |
|
|
424 |
return sVals; |
return sVals; |
425 |
} |
} |
426 |
|
|
427 |
void DeviceRuntimeParameterStrings::SetValue(std::vector<String> vS) { |
void DeviceRuntimeParameterStrings::SetValue(std::vector<String> vS) throw (LinuxSamplerException) { |
428 |
|
if (Fix()) throw LinuxSamplerException("Device parameter is read only"); |
429 |
|
OnSetValue(vS); |
430 |
sVals = vS; |
sVals = vS; |
431 |
} |
} |
432 |
|
|
501 |
optional<String> DeviceCreationParameterBool::Default(std::map<String,String> Parameters) { |
optional<String> DeviceCreationParameterBool::Default(std::map<String,String> Parameters) { |
502 |
optional<bool> defaultval = DefaultAsBool(Parameters); |
optional<bool> defaultval = DefaultAsBool(Parameters); |
503 |
if (!defaultval) return optional<String>::nothing; |
if (!defaultval) return optional<String>::nothing; |
504 |
return (*defaultval) ? "TRUE" : "FALSE"; |
return (*defaultval) ? "true" : "false"; |
505 |
} |
} |
506 |
|
|
507 |
optional<String> DeviceCreationParameterBool::RangeMin(std::map<String,String> Parameters) { |
optional<String> DeviceCreationParameterBool::RangeMin(std::map<String,String> Parameters) { |
517 |
} |
} |
518 |
|
|
519 |
String DeviceCreationParameterBool::Value() { |
String DeviceCreationParameterBool::Value() { |
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 (LinuxSamplerException) { |
524 |
if (Fix()) throw LinuxSamplerException("Device parameter is read only"); |
if (Fix()) throw LinuxSamplerException("Device parameter is read only"); |
525 |
int b = __parse_bool(val); |
int b = __parse_bool(val); |
|
OnSetValue(b); |
|
526 |
SetValue(b); |
SetValue(b); |
527 |
} |
} |
528 |
|
|
530 |
return bVal; |
return bVal; |
531 |
} |
} |
532 |
|
|
533 |
void DeviceCreationParameterBool::SetValue(bool b) { |
void DeviceCreationParameterBool::SetValue(bool b) throw (LinuxSamplerException) { |
534 |
|
if (Fix()) throw LinuxSamplerException("Device parameter is read only"); |
535 |
|
OnSetValue(b); |
536 |
bVal = b; |
bVal = b; |
537 |
} |
} |
538 |
|
|
572 |
optional<String> DeviceCreationParameterInt::RangeMin(std::map<String,String> Parameters) { |
optional<String> DeviceCreationParameterInt::RangeMin(std::map<String,String> Parameters) { |
573 |
optional<int> rangemin = RangeMinAsInt(Parameters); |
optional<int> rangemin = RangeMinAsInt(Parameters); |
574 |
if (!rangemin) return optional<String>::nothing; |
if (!rangemin) return optional<String>::nothing; |
575 |
return ToString(rangemin); |
return ToString(*rangemin); |
576 |
} |
} |
577 |
|
|
578 |
optional<String> DeviceCreationParameterInt::RangeMax(std::map<String,String> Parameters) { |
optional<String> DeviceCreationParameterInt::RangeMax(std::map<String,String> Parameters) { |
579 |
optional<int> rangemax = RangeMaxAsInt(Parameters); |
optional<int> rangemax = RangeMaxAsInt(Parameters); |
580 |
if (!rangemax) return optional<String>::nothing; |
if (!rangemax) return optional<String>::nothing; |
581 |
return ToString(rangemax); |
return ToString(*rangemax); |
582 |
} |
} |
583 |
|
|
584 |
optional<String> DeviceCreationParameterInt::Possibilities(std::map<String,String> Parameters) { |
optional<String> DeviceCreationParameterInt::Possibilities(std::map<String,String> Parameters) { |
617 |
} |
} |
618 |
if (!valid) throw LinuxSamplerException("Invalid Device parameter value: not in set of possible values"); |
if (!valid) throw LinuxSamplerException("Invalid Device parameter value: not in set of possible values"); |
619 |
}*/ |
}*/ |
|
OnSetValue(i); |
|
620 |
SetValue(i); |
SetValue(i); |
621 |
} |
} |
622 |
|
|
624 |
return iVal; |
return iVal; |
625 |
} |
} |
626 |
|
|
627 |
void DeviceCreationParameterInt::SetValue(int i) { |
void DeviceCreationParameterInt::SetValue(int i) throw (LinuxSamplerException) { |
628 |
|
if (Fix()) throw LinuxSamplerException("Device parameter is read only"); |
629 |
|
OnSetValue(i); |
630 |
iVal = i; |
iVal = i; |
631 |
} |
} |
632 |
|
|
711 |
} |
} |
712 |
if (!valid) throw LinuxSamplerException("Invalid Device parameter value: not in set of possible values"); |
if (!valid) throw LinuxSamplerException("Invalid Device parameter value: not in set of possible values"); |
713 |
}*/ |
}*/ |
|
OnSetValue(f); |
|
714 |
SetValue(f); |
SetValue(f); |
715 |
} |
} |
716 |
|
|
718 |
return fVal; |
return fVal; |
719 |
} |
} |
720 |
|
|
721 |
void DeviceCreationParameterFloat::SetValue(float f) { |
void DeviceCreationParameterFloat::SetValue(float f) throw (LinuxSamplerException) { |
722 |
|
if (Fix()) throw LinuxSamplerException("Device parameter is read only"); |
723 |
|
OnSetValue(f); |
724 |
fVal = f; |
fVal = f; |
725 |
} |
} |
726 |
|
|
730 |
// * |
// * |
731 |
|
|
732 |
DeviceCreationParameterString::DeviceCreationParameterString(String sVal) : DeviceCreationParameter() { |
DeviceCreationParameterString::DeviceCreationParameterString(String sVal) : DeviceCreationParameter() { |
733 |
this->sVal = sVal; |
this->sVal = __parse_string(sVal); |
734 |
} |
} |
735 |
|
|
736 |
void DeviceCreationParameterString::InitWithDefault() { |
void DeviceCreationParameterString::InitWithDefault() { |
737 |
std::map<String,String> Parameters; // empty parameters vector |
std::map<String,String> Parameters; // empty parameters vector |
738 |
optional<String> defaulval = Default(Parameters); |
optional<String> defaulval = DefaultAsString(Parameters); |
739 |
if (defaulval) this->sVal = *defaulval; |
if (defaulval) this->sVal = *defaulval; |
740 |
else this->sVal = ""; |
else this->sVal = ""; |
741 |
} |
} |
748 |
return false; |
return false; |
749 |
} |
} |
750 |
|
|
751 |
|
optional<String> DeviceCreationParameterString::Default(std::map<String,String> Parameters) { |
752 |
|
optional<String> defaultval = DefaultAsString(Parameters); |
753 |
|
if (!defaultval) return optional<String>::nothing; |
754 |
|
return "'" + *defaultval + "'"; |
755 |
|
} |
756 |
|
|
757 |
optional<String> DeviceCreationParameterString::RangeMin(std::map<String,String> Parameters) { |
optional<String> DeviceCreationParameterString::RangeMin(std::map<String,String> Parameters) { |
758 |
return optional<String>::nothing; |
return optional<String>::nothing; |
759 |
} |
} |
777 |
} |
} |
778 |
|
|
779 |
String DeviceCreationParameterString::Value() { |
String DeviceCreationParameterString::Value() { |
780 |
return sVal; |
return "\'" + ValueAsString() + "\'"; |
781 |
} |
} |
782 |
|
|
783 |
void DeviceCreationParameterString::SetValue(String val) throw (LinuxSamplerException) { |
void DeviceCreationParameterString::SetValue(String val) throw (LinuxSamplerException) { |
784 |
if (Fix()) throw LinuxSamplerException("Device parameter is read only"); |
if (Fix()) throw LinuxSamplerException("Device parameter is read only"); |
785 |
|
SetValueAsString(__parse_string(val)); |
786 |
|
} |
787 |
|
|
788 |
|
String DeviceCreationParameterString::ValueAsString() { |
789 |
|
return sVal; |
790 |
|
} |
791 |
|
|
792 |
|
void DeviceCreationParameterString::SetValueAsString(String val) throw (LinuxSamplerException) { |
793 |
if (val.find("\'") != String::npos) throw LinuxSamplerException("Character -> \' <- not allowed"); |
if (val.find("\'") != String::npos) throw LinuxSamplerException("Character -> \' <- not allowed"); |
794 |
if (val.find("\"") != String::npos) throw LinuxSamplerException("Character -> \" <- not allowed"); |
if (val.find("\"") != String::npos) throw LinuxSamplerException("Character -> \" <- not allowed"); |
795 |
OnSetValue(val); |
OnSetValue(val); |
823 |
return true; |
return true; |
824 |
} |
} |
825 |
|
|
826 |
|
optional<String> DeviceCreationParameterStrings::Default(std::map<String,String> Parameters) { |
827 |
|
std::vector<String> defaultval = DefaultAsStrings(Parameters); |
828 |
|
if (defaultval.empty()) return optional<String>::nothing; |
829 |
|
String result; |
830 |
|
std::vector<String>::iterator iter = defaultval.begin(); |
831 |
|
for (; iter != defaultval.end(); iter++) { |
832 |
|
if (result != "") result += ","; |
833 |
|
result += ("'" + *iter + "'"); |
834 |
|
} |
835 |
|
return result; |
836 |
|
} |
837 |
|
|
838 |
optional<String> DeviceCreationParameterStrings::RangeMin(std::map<String,String> Parameters) { |
optional<String> DeviceCreationParameterStrings::RangeMin(std::map<String,String> Parameters) { |
839 |
return optional<String>::nothing; |
return optional<String>::nothing; |
840 |
} |
} |
871 |
void DeviceCreationParameterStrings::SetValue(String val) throw (LinuxSamplerException) { |
void DeviceCreationParameterStrings::SetValue(String val) throw (LinuxSamplerException) { |
872 |
if (Fix()) throw LinuxSamplerException("Device parameter is read only"); |
if (Fix()) throw LinuxSamplerException("Device parameter is read only"); |
873 |
std::vector<String> vS = __parse_strings(val); |
std::vector<String> vS = __parse_strings(val); |
|
OnSetValue(vS); |
|
874 |
SetValue(vS); |
SetValue(vS); |
875 |
} |
} |
876 |
|
|
878 |
return sVals; |
return sVals; |
879 |
} |
} |
880 |
|
|
881 |
void DeviceCreationParameterStrings::SetValue(std::vector<String> vS) { |
void DeviceCreationParameterStrings::SetValue(std::vector<String> vS) throw (LinuxSamplerException) { |
882 |
|
if (Fix()) throw LinuxSamplerException("Device parameter is read only"); |
883 |
|
OnSetValue(vS); |
884 |
sVals = vS; |
sVals = vS; |
885 |
} |
} |
886 |
|
|