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 * |
44 |
return atof(val.c_str()); // TODO: format check is missing |
return atof(val.c_str()); // TODO: format check is missing |
45 |
} |
} |
46 |
|
|
47 |
|
static String __parse_string(String val) { |
48 |
|
// if string is encapsulated into apostrophes or quotation marks, then remove those apostrophes / quotation marks |
49 |
|
if (val.size()) { |
50 |
|
char cBegin = val[0]; |
51 |
|
char cEnd = val[val.size() - 1]; |
52 |
|
if ( (cBegin == '\'' && cEnd == '\'') || (cBegin == '\"' && cEnd == '\"') ) { |
53 |
|
val = val.substr(1, val.size() - 2); |
54 |
|
} |
55 |
|
} |
56 |
|
return val; |
57 |
|
} |
58 |
|
|
59 |
static std::vector<String> __parse_strings(String val) throw (LinuxSamplerException) { |
static std::vector<String> __parse_strings(String val) throw (LinuxSamplerException) { |
60 |
std::vector<String> vS; |
std::vector<String> vS; |
61 |
|
|
62 |
// 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 |
63 |
if (val.find("\'") == String::npos && val.find("\"") == String::npos) { |
if (val.find("\'") == String::npos && val.find("\"") == String::npos) { |
64 |
vS.push_back(val); |
vS.push_back(val); |
65 |
} |
} |
66 |
else { // if multiple strings or a string encapsulated into apostrophes |
else { // if multiple strings or a string encapsulated into apostrophes |
67 |
char* pStart = (char*) val.c_str(); |
char* pStart = (char*) val.c_str(); |
68 |
char* pC = pStart; |
char* pC = pStart; |
|
if (*pC != '\'' && *pC != '\"') throw LinuxSamplerException("Invalid form, all individual strings should be encapsulated into apostrophes, separated by commas"); |
|
69 |
|
|
70 |
while (true) { |
while (true) { |
71 |
|
if (*pC != '\'' && *pC != '\"') throw LinuxSamplerException("Invalid form, all individual strings should be encapsulated into apostrophes, separated by commas"); |
72 |
|
|
73 |
// search for token end |
// search for token end |
74 |
char* pTokenStart = pC + 1; |
char* pTokenStart = pC + 1; |
75 |
do { |
do { |
77 |
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"); |
78 |
} |
} |
79 |
while (*pC != '\'' && *pC != '\"'); |
while (*pC != '\'' && *pC != '\"'); |
80 |
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)); |
81 |
|
vS.push_back(token); // we found the token's end |
82 |
|
|
83 |
// 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 |
84 |
if (*(++pC) == '\0') break; |
if (*(++pC) == '\0') break; |
85 |
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"); |
86 |
|
pC++; |
87 |
} |
} |
88 |
} |
} |
89 |
|
|
120 |
} |
} |
121 |
|
|
122 |
String DeviceRuntimeParameterBool::Value() { |
String DeviceRuntimeParameterBool::Value() { |
123 |
return (ValueAsBool()) ? "TRUE" : "FALSE"; |
return (ValueAsBool()) ? "true" : "false"; |
124 |
} |
} |
125 |
|
|
126 |
void DeviceRuntimeParameterBool::SetValue(String val) throw (LinuxSamplerException) { |
void DeviceRuntimeParameterBool::SetValue(String val) throw (LinuxSamplerException) { |
127 |
if (Fix()) throw LinuxSamplerException("Device parameter is read only"); |
if (Fix()) throw LinuxSamplerException("Device parameter is read only"); |
128 |
int b = __parse_bool(val); |
int b = __parse_bool(val); |
|
OnSetValue(b); |
|
129 |
SetValue(b); |
SetValue(b); |
130 |
} |
} |
131 |
|
|
133 |
return bVal; |
return bVal; |
134 |
} |
} |
135 |
|
|
136 |
void DeviceRuntimeParameterBool::SetValue(bool b) { |
void DeviceRuntimeParameterBool::SetValue(bool b) throw (LinuxSamplerException) { |
137 |
|
if (Fix()) throw LinuxSamplerException("Device parameter is read only"); |
138 |
|
OnSetValue(b); |
139 |
bVal = b; |
bVal = b; |
140 |
} |
} |
141 |
|
|
205 |
} |
} |
206 |
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"); |
207 |
} |
} |
|
OnSetValue(i); |
|
208 |
SetValue(i); |
SetValue(i); |
209 |
} |
} |
210 |
|
|
212 |
return iVal; |
return iVal; |
213 |
} |
} |
214 |
|
|
215 |
void DeviceRuntimeParameterInt::SetValue(int i) { |
void DeviceRuntimeParameterInt::SetValue(int i) throw (LinuxSamplerException) { |
216 |
|
if (Fix()) throw LinuxSamplerException("Device parameter is read only"); |
217 |
|
OnSetValue(i); |
218 |
iVal = i; |
iVal = i; |
219 |
} |
} |
220 |
|
|
284 |
} |
} |
285 |
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"); |
286 |
} |
} |
|
OnSetValue(f); |
|
287 |
SetValue(f); |
SetValue(f); |
288 |
} |
} |
289 |
|
|
291 |
return fVal; |
return fVal; |
292 |
} |
} |
293 |
|
|
294 |
void DeviceRuntimeParameterFloat::SetValue(float f) { |
void DeviceRuntimeParameterFloat::SetValue(float f) throw (LinuxSamplerException) { |
295 |
|
if (Fix()) throw LinuxSamplerException("Device parameter is read only"); |
296 |
|
OnSetValue(f); |
297 |
fVal = f; |
fVal = f; |
298 |
} |
} |
299 |
|
|
337 |
} |
} |
338 |
|
|
339 |
String DeviceRuntimeParameterString::Value() { |
String DeviceRuntimeParameterString::Value() { |
340 |
return sVal; |
return "\'" + ValueAsString() + "\'"; |
341 |
} |
} |
342 |
|
|
343 |
void DeviceRuntimeParameterString::SetValue(String val) throw (LinuxSamplerException) { |
void DeviceRuntimeParameterString::SetValue(String val) throw (LinuxSamplerException) { |
344 |
if (Fix()) throw LinuxSamplerException("Device parameter is read only"); |
if (Fix()) throw LinuxSamplerException("Device parameter is read only"); |
345 |
|
SetValueAsString(__parse_string(val)); |
346 |
|
} |
347 |
|
|
348 |
|
String DeviceRuntimeParameterString::ValueAsString() { |
349 |
|
return sVal; |
350 |
|
} |
351 |
|
|
352 |
|
void DeviceRuntimeParameterString::SetValueAsString(String val) throw (LinuxSamplerException) { |
353 |
|
if (Fix()) throw LinuxSamplerException("Device parameter is read only"); |
354 |
if (val.find("\'") != String::npos) throw LinuxSamplerException("Character -> \' <- not allowed"); |
if (val.find("\'") != String::npos) throw LinuxSamplerException("Character -> \' <- not allowed"); |
355 |
if (val.find("\"") != String::npos) throw LinuxSamplerException("Character -> \" <- not allowed"); |
if (val.find("\"") != String::npos) throw LinuxSamplerException("Character -> \" <- not allowed"); |
356 |
OnSetValue(val); |
OnSetValue(val); |
410 |
void DeviceRuntimeParameterStrings::SetValue(String val) throw (LinuxSamplerException) { |
void DeviceRuntimeParameterStrings::SetValue(String val) throw (LinuxSamplerException) { |
411 |
if (Fix()) throw LinuxSamplerException("Device parameter is read only"); |
if (Fix()) throw LinuxSamplerException("Device parameter is read only"); |
412 |
std::vector<String> vS = __parse_strings(val); |
std::vector<String> vS = __parse_strings(val); |
|
OnSetValue(vS); |
|
413 |
SetValue(vS); |
SetValue(vS); |
414 |
} |
} |
415 |
|
|
417 |
return sVals; |
return sVals; |
418 |
} |
} |
419 |
|
|
420 |
void DeviceRuntimeParameterStrings::SetValue(std::vector<String> vS) { |
void DeviceRuntimeParameterStrings::SetValue(std::vector<String> vS) throw (LinuxSamplerException) { |
421 |
|
if (Fix()) throw LinuxSamplerException("Device parameter is read only"); |
422 |
|
OnSetValue(vS); |
423 |
sVals = vS; |
sVals = vS; |
424 |
} |
} |
425 |
|
|
469 |
// *************** DeviceCreationParameterBool *************** |
// *************** DeviceCreationParameterBool *************** |
470 |
// * |
// * |
471 |
|
|
472 |
DeviceCreationParameterBool::DeviceCreationParameterBool() { |
DeviceCreationParameterBool::DeviceCreationParameterBool(bool bVal) : DeviceCreationParameter() { |
|
} |
|
|
|
|
|
DeviceCreationParameterBool::DeviceCreationParameterBool(bool bVal) { |
|
473 |
this->bVal = bVal; |
this->bVal = bVal; |
474 |
} |
} |
475 |
|
|
494 |
optional<String> DeviceCreationParameterBool::Default(std::map<String,String> Parameters) { |
optional<String> DeviceCreationParameterBool::Default(std::map<String,String> Parameters) { |
495 |
optional<bool> defaultval = DefaultAsBool(Parameters); |
optional<bool> defaultval = DefaultAsBool(Parameters); |
496 |
if (!defaultval) return optional<String>::nothing; |
if (!defaultval) return optional<String>::nothing; |
497 |
return (*defaultval) ? "TRUE" : "FALSE"; |
return (*defaultval) ? "true" : "false"; |
498 |
} |
} |
499 |
|
|
500 |
optional<String> DeviceCreationParameterBool::RangeMin(std::map<String,String> Parameters) { |
optional<String> DeviceCreationParameterBool::RangeMin(std::map<String,String> Parameters) { |
510 |
} |
} |
511 |
|
|
512 |
String DeviceCreationParameterBool::Value() { |
String DeviceCreationParameterBool::Value() { |
513 |
return (ValueAsBool()) ? "TRUE" : "FALSE"; |
return (ValueAsBool()) ? "true" : "false"; |
514 |
} |
} |
515 |
|
|
516 |
void DeviceCreationParameterBool::SetValue(String val) throw (LinuxSamplerException) { |
void DeviceCreationParameterBool::SetValue(String val) throw (LinuxSamplerException) { |
517 |
if (Fix()) throw LinuxSamplerException("Device parameter is read only"); |
if (Fix()) throw LinuxSamplerException("Device parameter is read only"); |
518 |
int b = __parse_bool(val); |
int b = __parse_bool(val); |
|
OnSetValue(b); |
|
519 |
SetValue(b); |
SetValue(b); |
520 |
} |
} |
521 |
|
|
523 |
return bVal; |
return bVal; |
524 |
} |
} |
525 |
|
|
526 |
void DeviceCreationParameterBool::SetValue(bool b) { |
void DeviceCreationParameterBool::SetValue(bool b) throw (LinuxSamplerException) { |
527 |
|
if (Fix()) throw LinuxSamplerException("Device parameter is read only"); |
528 |
|
OnSetValue(b); |
529 |
bVal = b; |
bVal = b; |
530 |
} |
} |
531 |
|
|
534 |
// *************** DeviceCreationParameterInt *************** |
// *************** DeviceCreationParameterInt *************** |
535 |
// * |
// * |
536 |
|
|
537 |
DeviceCreationParameterInt::DeviceCreationParameterInt() { |
DeviceCreationParameterInt::DeviceCreationParameterInt(int iVal) : DeviceCreationParameter() { |
|
} |
|
|
|
|
|
DeviceCreationParameterInt::DeviceCreationParameterInt(int iVal) { |
|
538 |
this->iVal = iVal; |
this->iVal = iVal; |
539 |
} |
} |
540 |
|
|
565 |
optional<String> DeviceCreationParameterInt::RangeMin(std::map<String,String> Parameters) { |
optional<String> DeviceCreationParameterInt::RangeMin(std::map<String,String> Parameters) { |
566 |
optional<int> rangemin = RangeMinAsInt(Parameters); |
optional<int> rangemin = RangeMinAsInt(Parameters); |
567 |
if (!rangemin) return optional<String>::nothing; |
if (!rangemin) return optional<String>::nothing; |
568 |
return ToString(rangemin); |
return ToString(*rangemin); |
569 |
} |
} |
570 |
|
|
571 |
optional<String> DeviceCreationParameterInt::RangeMax(std::map<String,String> Parameters) { |
optional<String> DeviceCreationParameterInt::RangeMax(std::map<String,String> Parameters) { |
572 |
optional<int> rangemax = RangeMaxAsInt(Parameters); |
optional<int> rangemax = RangeMaxAsInt(Parameters); |
573 |
if (!rangemax) return optional<String>::nothing; |
if (!rangemax) return optional<String>::nothing; |
574 |
return ToString(rangemax); |
return ToString(*rangemax); |
575 |
} |
} |
576 |
|
|
577 |
optional<String> DeviceCreationParameterInt::Possibilities(std::map<String,String> Parameters) { |
optional<String> DeviceCreationParameterInt::Possibilities(std::map<String,String> Parameters) { |
610 |
} |
} |
611 |
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"); |
612 |
}*/ |
}*/ |
|
OnSetValue(i); |
|
613 |
SetValue(i); |
SetValue(i); |
614 |
} |
} |
615 |
|
|
617 |
return iVal; |
return iVal; |
618 |
} |
} |
619 |
|
|
620 |
void DeviceCreationParameterInt::SetValue(int i) { |
void DeviceCreationParameterInt::SetValue(int i) throw (LinuxSamplerException) { |
621 |
|
if (Fix()) throw LinuxSamplerException("Device parameter is read only"); |
622 |
|
OnSetValue(i); |
623 |
iVal = i; |
iVal = i; |
624 |
} |
} |
625 |
|
|
628 |
// *************** DeviceCreationParameterFloat *************** |
// *************** DeviceCreationParameterFloat *************** |
629 |
// * |
// * |
630 |
|
|
631 |
DeviceCreationParameterFloat::DeviceCreationParameterFloat() { |
DeviceCreationParameterFloat::DeviceCreationParameterFloat(float fVal) : DeviceCreationParameter() { |
|
} |
|
|
|
|
|
DeviceCreationParameterFloat::DeviceCreationParameterFloat(float fVal) { |
|
632 |
this->fVal = fVal; |
this->fVal = fVal; |
633 |
} |
} |
634 |
|
|
704 |
} |
} |
705 |
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"); |
706 |
}*/ |
}*/ |
|
OnSetValue(f); |
|
707 |
SetValue(f); |
SetValue(f); |
708 |
} |
} |
709 |
|
|
711 |
return fVal; |
return fVal; |
712 |
} |
} |
713 |
|
|
714 |
void DeviceCreationParameterFloat::SetValue(float f) { |
void DeviceCreationParameterFloat::SetValue(float f) throw (LinuxSamplerException) { |
715 |
|
if (Fix()) throw LinuxSamplerException("Device parameter is read only"); |
716 |
|
OnSetValue(f); |
717 |
fVal = f; |
fVal = f; |
718 |
} |
} |
719 |
|
|
722 |
// *************** DeviceCreationParameterString *************** |
// *************** DeviceCreationParameterString *************** |
723 |
// * |
// * |
724 |
|
|
725 |
DeviceCreationParameterString::DeviceCreationParameterString() { |
DeviceCreationParameterString::DeviceCreationParameterString(String sVal) : DeviceCreationParameter() { |
|
} |
|
|
|
|
|
DeviceCreationParameterString::DeviceCreationParameterString(String sVal) { |
|
726 |
this->sVal = sVal; |
this->sVal = sVal; |
727 |
} |
} |
728 |
|
|
729 |
void DeviceCreationParameterString::InitWithDefault() { |
void DeviceCreationParameterString::InitWithDefault() { |
730 |
std::map<String,String> Parameters; // empty parameters vector |
std::map<String,String> Parameters; // empty parameters vector |
731 |
optional<String> defaulval = Default(Parameters); |
optional<String> defaulval = DefaultAsString(Parameters); |
732 |
if (defaulval) this->sVal = *defaulval; |
if (defaulval) this->sVal = *defaulval; |
733 |
else this->sVal = ""; |
else this->sVal = ""; |
734 |
} |
} |
741 |
return false; |
return false; |
742 |
} |
} |
743 |
|
|
744 |
|
optional<String> DeviceCreationParameterString::Default(std::map<String,String> Parameters) { |
745 |
|
optional<String> defaultval = DefaultAsString(Parameters); |
746 |
|
if (!defaultval) return optional<String>::nothing; |
747 |
|
return "'" + *defaultval + "'"; |
748 |
|
} |
749 |
|
|
750 |
optional<String> DeviceCreationParameterString::RangeMin(std::map<String,String> Parameters) { |
optional<String> DeviceCreationParameterString::RangeMin(std::map<String,String> Parameters) { |
751 |
return optional<String>::nothing; |
return optional<String>::nothing; |
752 |
} |
} |
770 |
} |
} |
771 |
|
|
772 |
String DeviceCreationParameterString::Value() { |
String DeviceCreationParameterString::Value() { |
773 |
return sVal; |
return "\'" + ValueAsString() + "\'"; |
774 |
} |
} |
775 |
|
|
776 |
void DeviceCreationParameterString::SetValue(String val) throw (LinuxSamplerException) { |
void DeviceCreationParameterString::SetValue(String val) throw (LinuxSamplerException) { |
777 |
if (Fix()) throw LinuxSamplerException("Device parameter is read only"); |
if (Fix()) throw LinuxSamplerException("Device parameter is read only"); |
778 |
|
SetValueAsString(__parse_string(val)); |
779 |
|
} |
780 |
|
|
781 |
|
String DeviceCreationParameterString::ValueAsString() { |
782 |
|
return sVal; |
783 |
|
} |
784 |
|
|
785 |
|
void DeviceCreationParameterString::SetValueAsString(String val) throw (LinuxSamplerException) { |
786 |
if (val.find("\'") != String::npos) throw LinuxSamplerException("Character -> \' <- not allowed"); |
if (val.find("\'") != String::npos) throw LinuxSamplerException("Character -> \' <- not allowed"); |
787 |
if (val.find("\"") != String::npos) throw LinuxSamplerException("Character -> \" <- not allowed"); |
if (val.find("\"") != String::npos) throw LinuxSamplerException("Character -> \" <- not allowed"); |
788 |
OnSetValue(val); |
OnSetValue(val); |
794 |
// *************** DeviceCreationParameterStrings *************** |
// *************** DeviceCreationParameterStrings *************** |
795 |
// * |
// * |
796 |
|
|
797 |
DeviceCreationParameterStrings::DeviceCreationParameterStrings() { |
DeviceCreationParameterStrings::DeviceCreationParameterStrings(std::vector<String> sVals) : DeviceCreationParameter() { |
|
} |
|
|
|
|
|
DeviceCreationParameterStrings::DeviceCreationParameterStrings(std::vector<String> sVals) { |
|
798 |
this->sVals = sVals; |
this->sVals = sVals; |
799 |
} |
} |
800 |
|
|
816 |
return true; |
return true; |
817 |
} |
} |
818 |
|
|
819 |
|
optional<String> DeviceCreationParameterStrings::Default(std::map<String,String> Parameters) { |
820 |
|
std::vector<String> defaultval = DefaultAsStrings(Parameters); |
821 |
|
if (defaultval.empty()) return optional<String>::nothing; |
822 |
|
String result; |
823 |
|
std::vector<String>::iterator iter = defaultval.begin(); |
824 |
|
for (; iter != defaultval.end(); iter++) { |
825 |
|
if (result != "") result += ","; |
826 |
|
result += ("'" + *iter + "'"); |
827 |
|
} |
828 |
|
return result; |
829 |
|
} |
830 |
|
|
831 |
optional<String> DeviceCreationParameterStrings::RangeMin(std::map<String,String> Parameters) { |
optional<String> DeviceCreationParameterStrings::RangeMin(std::map<String,String> Parameters) { |
832 |
return optional<String>::nothing; |
return optional<String>::nothing; |
833 |
} |
} |
864 |
void DeviceCreationParameterStrings::SetValue(String val) throw (LinuxSamplerException) { |
void DeviceCreationParameterStrings::SetValue(String val) throw (LinuxSamplerException) { |
865 |
if (Fix()) throw LinuxSamplerException("Device parameter is read only"); |
if (Fix()) throw LinuxSamplerException("Device parameter is read only"); |
866 |
std::vector<String> vS = __parse_strings(val); |
std::vector<String> vS = __parse_strings(val); |
|
OnSetValue(vS); |
|
867 |
SetValue(vS); |
SetValue(vS); |
868 |
} |
} |
869 |
|
|
871 |
return sVals; |
return sVals; |
872 |
} |
} |
873 |
|
|
874 |
void DeviceCreationParameterStrings::SetValue(std::vector<String> vS) { |
void DeviceCreationParameterStrings::SetValue(std::vector<String> vS) throw (LinuxSamplerException) { |
875 |
|
if (Fix()) throw LinuxSamplerException("Device parameter is read only"); |
876 |
|
OnSetValue(vS); |
877 |
sVals = vS; |
sVals = vS; |
878 |
} |
} |
879 |
|
|