1 |
schoenebeck |
123 |
/*************************************************************************** |
2 |
|
|
* * |
3 |
|
|
* LinuxSampler - modular, streaming capable sampler * |
4 |
|
|
* * |
5 |
|
|
* Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck * |
6 |
schoenebeck |
880 |
* Copyright (C) 2005, 2006 Christian Schoenebeck * |
7 |
schoenebeck |
123 |
* * |
8 |
|
|
* 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 * |
10 |
|
|
* the Free Software Foundation; either version 2 of the License, or * |
11 |
|
|
* (at your option) any later version. * |
12 |
|
|
* * |
13 |
|
|
* This program is distributed in the hope that it will be useful, * |
14 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of * |
15 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
16 |
|
|
* GNU General Public License for more details. * |
17 |
|
|
* * |
18 |
|
|
* You should have received a copy of the GNU General Public License * |
19 |
|
|
* along with this program; if not, write to the Free Software * |
20 |
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, * |
21 |
|
|
* MA 02111-1307 USA * |
22 |
|
|
***************************************************************************/ |
23 |
|
|
|
24 |
|
|
#include <strings.h> |
25 |
|
|
#include <stdlib.h> |
26 |
|
|
|
27 |
|
|
#include "DeviceParameter.h" |
28 |
|
|
|
29 |
|
|
namespace LinuxSampler { |
30 |
|
|
|
31 |
schoenebeck |
486 |
// 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 |
schoenebeck |
880 |
static bool __parse_bool(String val) throw (Exception) { |
43 |
schoenebeck |
486 |
__eliminate_quotation(val); |
44 |
schoenebeck |
123 |
int b; |
45 |
|
|
if (val == "1" || !strcasecmp(val.c_str(),"true")) b = true; |
46 |
|
|
else if (val == "0" || !strcasecmp(val.c_str(),"false")) b = false; |
47 |
schoenebeck |
880 |
else throw Exception("Invalid value for boolean Device parameter"); |
48 |
schoenebeck |
123 |
return b; |
49 |
|
|
} |
50 |
|
|
|
51 |
schoenebeck |
880 |
static int __parse_int(String val) throw (Exception) { |
52 |
schoenebeck |
486 |
__eliminate_quotation(val); |
53 |
schoenebeck |
123 |
return atoi(val.c_str()); // TODO: format check is missing |
54 |
|
|
} |
55 |
|
|
|
56 |
schoenebeck |
880 |
static float __parse_float(String val) throw (Exception) { |
57 |
schoenebeck |
486 |
__eliminate_quotation(val); |
58 |
persson |
1349 |
float x; |
59 |
|
|
std::stringstream ss(val); |
60 |
|
|
ss.imbue(std::locale::classic()); |
61 |
|
|
ss >> x; // TODO: format check is missing |
62 |
|
|
return x; |
63 |
schoenebeck |
123 |
} |
64 |
|
|
|
65 |
persson |
1349 |
static String __parse_string(String val) { |
66 |
schoenebeck |
486 |
__eliminate_quotation(val); |
67 |
schoenebeck |
214 |
return val; |
68 |
|
|
} |
69 |
|
|
|
70 |
schoenebeck |
880 |
static std::vector<String> __parse_strings(String val) throw (Exception) { |
71 |
schoenebeck |
123 |
std::vector<String> vS; |
72 |
persson |
1349 |
|
73 |
iliev |
1296 |
// checking for empty list |
74 |
|
|
if (val.length() == 0) return vS; |
75 |
schoenebeck |
123 |
|
76 |
schoenebeck |
214 |
// if there's only a single value, then we also allow to give it without being encapsulated into apostrophes |
77 |
schoenebeck |
123 |
if (val.find("\'") == String::npos && val.find("\"") == String::npos) { |
78 |
|
|
vS.push_back(val); |
79 |
|
|
} |
80 |
|
|
else { // if multiple strings or a string encapsulated into apostrophes |
81 |
|
|
char* pStart = (char*) val.c_str(); |
82 |
|
|
char* pC = pStart; |
83 |
|
|
|
84 |
|
|
while (true) { |
85 |
schoenebeck |
880 |
if (*pC != '\'' && *pC != '\"') throw Exception("Invalid form, all individual strings should be encapsulated into apostrophes, separated by commas"); |
86 |
schoenebeck |
483 |
|
87 |
schoenebeck |
123 |
// search for token end |
88 |
|
|
char* pTokenStart = pC + 1; |
89 |
|
|
do { |
90 |
|
|
pC++; |
91 |
schoenebeck |
880 |
if (*pC == '\0') throw Exception("Invalid form, all individual strings should be encapsulated into apostrophes, separated by commas"); |
92 |
schoenebeck |
123 |
} |
93 |
|
|
while (*pC != '\'' && *pC != '\"'); |
94 |
schoenebeck |
483 |
String token = val.substr((int)(pTokenStart - pStart), (int)(pC - pTokenStart)); |
95 |
|
|
vS.push_back(token); // we found the token's end |
96 |
schoenebeck |
123 |
|
97 |
|
|
// now there should be either a comma or the end of the total string |
98 |
|
|
if (*(++pC) == '\0') break; |
99 |
schoenebeck |
880 |
if (*pC != ',') throw Exception("Invalid form, all individual strings should be encapsulated into apostrophes, separated by commas"); |
100 |
schoenebeck |
483 |
pC++; |
101 |
schoenebeck |
123 |
} |
102 |
|
|
} |
103 |
|
|
|
104 |
|
|
return vS; |
105 |
|
|
} |
106 |
|
|
|
107 |
|
|
|
108 |
|
|
|
109 |
|
|
// *************** DeviceRuntimeParameterBool *************** |
110 |
|
|
// * |
111 |
|
|
|
112 |
|
|
DeviceRuntimeParameterBool::DeviceRuntimeParameterBool(bool bVal) { |
113 |
|
|
this->bVal = bVal; |
114 |
|
|
} |
115 |
|
|
|
116 |
|
|
String DeviceRuntimeParameterBool::Type() { |
117 |
|
|
return "BOOL"; |
118 |
|
|
} |
119 |
|
|
|
120 |
|
|
bool DeviceRuntimeParameterBool::Multiplicity() { |
121 |
|
|
return false; |
122 |
|
|
} |
123 |
|
|
|
124 |
|
|
optional<String> DeviceRuntimeParameterBool::RangeMin() { |
125 |
|
|
return optional<String>::nothing; |
126 |
|
|
} |
127 |
|
|
|
128 |
|
|
optional<String> DeviceRuntimeParameterBool::RangeMax() { |
129 |
|
|
return optional<String>::nothing; |
130 |
|
|
} |
131 |
|
|
|
132 |
|
|
optional<String> DeviceRuntimeParameterBool::Possibilities() { |
133 |
|
|
return optional<String>::nothing; |
134 |
|
|
} |
135 |
|
|
|
136 |
|
|
String DeviceRuntimeParameterBool::Value() { |
137 |
schoenebeck |
214 |
return (ValueAsBool()) ? "true" : "false"; |
138 |
schoenebeck |
123 |
} |
139 |
|
|
|
140 |
schoenebeck |
880 |
void DeviceRuntimeParameterBool::SetValue(String val) throw (Exception) { |
141 |
|
|
if (Fix()) throw Exception("Device parameter is read only"); |
142 |
schoenebeck |
123 |
int b = __parse_bool(val); |
143 |
|
|
SetValue(b); |
144 |
|
|
} |
145 |
|
|
|
146 |
|
|
bool DeviceRuntimeParameterBool::ValueAsBool() { |
147 |
|
|
return bVal; |
148 |
|
|
} |
149 |
|
|
|
150 |
schoenebeck |
880 |
void DeviceRuntimeParameterBool::SetValue(bool b) throw (Exception) { |
151 |
|
|
if (Fix()) throw Exception("Device parameter is read only"); |
152 |
schoenebeck |
214 |
OnSetValue(b); |
153 |
schoenebeck |
123 |
bVal = b; |
154 |
|
|
} |
155 |
|
|
|
156 |
|
|
|
157 |
|
|
|
158 |
|
|
// *************** DeviceRuntimeParameterInt *************** |
159 |
|
|
// * |
160 |
|
|
|
161 |
|
|
DeviceRuntimeParameterInt::DeviceRuntimeParameterInt(int iVal) { |
162 |
|
|
this->iVal = iVal; |
163 |
|
|
} |
164 |
|
|
|
165 |
|
|
String DeviceRuntimeParameterInt::Type() { |
166 |
|
|
return "INT"; |
167 |
|
|
} |
168 |
|
|
|
169 |
|
|
bool DeviceRuntimeParameterInt::Multiplicity() { |
170 |
|
|
return false; |
171 |
|
|
} |
172 |
|
|
|
173 |
|
|
optional<String> DeviceRuntimeParameterInt::RangeMin() { |
174 |
|
|
optional<int> rangemin = RangeMinAsInt(); |
175 |
|
|
if (!rangemin) return optional<String>::nothing; |
176 |
|
|
return ToString(*rangemin); |
177 |
|
|
} |
178 |
|
|
|
179 |
|
|
optional<String> DeviceRuntimeParameterInt::RangeMax() { |
180 |
|
|
optional<int> rangemax = RangeMaxAsInt(); |
181 |
|
|
if (!rangemax) return optional<String>::nothing; |
182 |
|
|
return ToString(*rangemax); |
183 |
|
|
} |
184 |
|
|
|
185 |
|
|
optional<String> DeviceRuntimeParameterInt::Possibilities() { |
186 |
|
|
std::vector<int> possibilities = PossibilitiesAsInt(); |
187 |
|
|
if (possibilities.empty()) return optional<String>::nothing; |
188 |
|
|
|
189 |
|
|
std::stringstream ss; |
190 |
|
|
std::vector<int>::iterator iter = possibilities.begin(); |
191 |
|
|
while (iter != possibilities.end()) { |
192 |
|
|
if (ss.str() != "") ss << ","; |
193 |
|
|
ss << *iter; |
194 |
|
|
iter++; |
195 |
|
|
} |
196 |
|
|
return ss.str(); |
197 |
|
|
} |
198 |
|
|
|
199 |
|
|
String DeviceRuntimeParameterInt::Value() { |
200 |
|
|
return ToString(ValueAsInt()); |
201 |
|
|
} |
202 |
|
|
|
203 |
schoenebeck |
880 |
void DeviceRuntimeParameterInt::SetValue(String val) throw (Exception) { |
204 |
|
|
if (Fix()) throw Exception("Device parameter is read only"); |
205 |
schoenebeck |
123 |
int i = __parse_int(val); |
206 |
schoenebeck |
880 |
if (RangeMinAsInt() && i < *RangeMinAsInt()) throw Exception("Invalid device parameter value: too small"); |
207 |
|
|
if (RangeMaxAsInt() && i > *RangeMaxAsInt()) throw Exception("Invalid device parameter value: too big"); |
208 |
schoenebeck |
123 |
|
209 |
|
|
std::vector<int> possibilities = PossibilitiesAsInt(); |
210 |
|
|
if (possibilities.size()) { |
211 |
|
|
bool valid = false; |
212 |
|
|
std::vector<int>::iterator iter = possibilities.begin(); |
213 |
|
|
while (iter != possibilities.end()) { |
214 |
|
|
if (i == *iter) { |
215 |
|
|
valid = true; |
216 |
|
|
break; |
217 |
|
|
} |
218 |
|
|
iter++; |
219 |
|
|
} |
220 |
schoenebeck |
880 |
if (!valid) throw Exception("Invalid device parameter value: not in set of possible values"); |
221 |
schoenebeck |
123 |
} |
222 |
|
|
SetValue(i); |
223 |
|
|
} |
224 |
|
|
|
225 |
|
|
int DeviceRuntimeParameterInt::ValueAsInt() { |
226 |
|
|
return iVal; |
227 |
|
|
} |
228 |
|
|
|
229 |
schoenebeck |
880 |
void DeviceRuntimeParameterInt::SetValue(int i) throw (Exception) { |
230 |
|
|
if (Fix()) throw Exception("Device parameter is read only"); |
231 |
schoenebeck |
214 |
OnSetValue(i); |
232 |
schoenebeck |
123 |
iVal = i; |
233 |
|
|
} |
234 |
|
|
|
235 |
|
|
|
236 |
|
|
|
237 |
|
|
// *************** DeviceRuntimeParameterFloat *************** |
238 |
|
|
// * |
239 |
|
|
|
240 |
|
|
DeviceRuntimeParameterFloat::DeviceRuntimeParameterFloat(float fVal) { |
241 |
|
|
this->fVal = fVal; |
242 |
|
|
} |
243 |
|
|
|
244 |
|
|
String DeviceRuntimeParameterFloat::Type() { |
245 |
|
|
return "FLOAT"; |
246 |
|
|
} |
247 |
|
|
|
248 |
|
|
bool DeviceRuntimeParameterFloat::Multiplicity() { |
249 |
|
|
return false; |
250 |
|
|
} |
251 |
|
|
|
252 |
|
|
optional<String> DeviceRuntimeParameterFloat::RangeMin() { |
253 |
|
|
optional<float> rangemin = RangeMinAsFloat(); |
254 |
|
|
if (!rangemin) return optional<String>::nothing; |
255 |
|
|
return ToString(*rangemin); |
256 |
|
|
} |
257 |
|
|
|
258 |
|
|
optional<String> DeviceRuntimeParameterFloat::RangeMax() { |
259 |
|
|
optional<float> rangemax = RangeMaxAsFloat(); |
260 |
|
|
if (!rangemax) return optional<String>::nothing; |
261 |
|
|
return ToString(*rangemax); |
262 |
|
|
} |
263 |
|
|
|
264 |
|
|
optional<String> DeviceRuntimeParameterFloat::Possibilities() { |
265 |
|
|
std::vector<float> possibilities = PossibilitiesAsFloat(); |
266 |
|
|
if (possibilities.empty()) return optional<String>::nothing; |
267 |
|
|
|
268 |
|
|
std::stringstream ss; |
269 |
|
|
std::vector<float>::iterator iter = possibilities.begin(); |
270 |
|
|
while (iter != possibilities.end()) { |
271 |
|
|
if (ss.str() != "") ss << ","; |
272 |
|
|
ss << *iter; |
273 |
|
|
iter++; |
274 |
|
|
} |
275 |
|
|
return ss.str(); |
276 |
|
|
} |
277 |
|
|
|
278 |
|
|
String DeviceRuntimeParameterFloat::Value() { |
279 |
|
|
return ToString(ValueAsFloat()); |
280 |
|
|
} |
281 |
|
|
|
282 |
schoenebeck |
880 |
void DeviceRuntimeParameterFloat::SetValue(String val) throw (Exception) { |
283 |
|
|
if (Fix()) throw Exception("Device parameter is read only"); |
284 |
schoenebeck |
123 |
float f = __parse_float(val); |
285 |
schoenebeck |
880 |
if (RangeMinAsFloat() && f < *RangeMinAsFloat()) throw Exception("Invalid device parameter value: too small"); |
286 |
|
|
if (RangeMaxAsFloat() && f > *RangeMaxAsFloat()) throw Exception("Invalid device parameter value: too big"); |
287 |
schoenebeck |
123 |
|
288 |
|
|
std::vector<float> possibilities = PossibilitiesAsFloat(); |
289 |
|
|
if (possibilities.size()) { |
290 |
|
|
bool valid = false; |
291 |
|
|
std::vector<float>::iterator iter = possibilities.begin(); |
292 |
|
|
while (iter != possibilities.end()) { |
293 |
|
|
if (f == *iter) { |
294 |
|
|
valid = true; |
295 |
|
|
break; |
296 |
|
|
} |
297 |
|
|
iter++; |
298 |
|
|
} |
299 |
schoenebeck |
880 |
if (!valid) throw Exception("Invalid device parameter value: not in set of possible values"); |
300 |
schoenebeck |
123 |
} |
301 |
|
|
SetValue(f); |
302 |
|
|
} |
303 |
|
|
|
304 |
|
|
float DeviceRuntimeParameterFloat::ValueAsFloat() { |
305 |
|
|
return fVal; |
306 |
|
|
} |
307 |
|
|
|
308 |
schoenebeck |
880 |
void DeviceRuntimeParameterFloat::SetValue(float f) throw (Exception) { |
309 |
|
|
if (Fix()) throw Exception("Device parameter is read only"); |
310 |
schoenebeck |
214 |
OnSetValue(f); |
311 |
schoenebeck |
123 |
fVal = f; |
312 |
|
|
} |
313 |
|
|
|
314 |
|
|
|
315 |
|
|
|
316 |
|
|
// *************** DeviceRuntimeParameterString *************** |
317 |
|
|
// * |
318 |
|
|
|
319 |
|
|
DeviceRuntimeParameterString::DeviceRuntimeParameterString(String sVal) { |
320 |
|
|
this->sVal = sVal; |
321 |
|
|
} |
322 |
|
|
|
323 |
|
|
String DeviceRuntimeParameterString::Type() { |
324 |
|
|
return "STRING"; |
325 |
|
|
} |
326 |
|
|
|
327 |
|
|
bool DeviceRuntimeParameterString::Multiplicity() { |
328 |
|
|
return false; |
329 |
|
|
} |
330 |
|
|
|
331 |
|
|
optional<String> DeviceRuntimeParameterString::RangeMin() { |
332 |
|
|
return optional<String>::nothing; |
333 |
|
|
} |
334 |
|
|
|
335 |
|
|
optional<String> DeviceRuntimeParameterString::RangeMax() { |
336 |
|
|
return optional<String>::nothing; |
337 |
|
|
} |
338 |
|
|
|
339 |
|
|
optional<String> DeviceRuntimeParameterString::Possibilities() { |
340 |
|
|
std::vector<String> possibilities = PossibilitiesAsString(); |
341 |
|
|
if (possibilities.empty()) return optional<String>::nothing; |
342 |
|
|
|
343 |
|
|
std::stringstream ss; |
344 |
|
|
std::vector<String>::iterator iter = possibilities.begin(); |
345 |
|
|
while (iter != possibilities.end()) { |
346 |
|
|
if (ss.str() != "") ss << ","; |
347 |
|
|
ss << "'" << *iter << "'"; |
348 |
|
|
iter++; |
349 |
|
|
} |
350 |
|
|
return ss.str(); |
351 |
|
|
} |
352 |
|
|
|
353 |
|
|
String DeviceRuntimeParameterString::Value() { |
354 |
schoenebeck |
214 |
return "\'" + ValueAsString() + "\'"; |
355 |
schoenebeck |
123 |
} |
356 |
|
|
|
357 |
schoenebeck |
880 |
void DeviceRuntimeParameterString::SetValue(String val) throw (Exception) { |
358 |
|
|
if (Fix()) throw Exception("Device parameter is read only"); |
359 |
schoenebeck |
214 |
SetValueAsString(__parse_string(val)); |
360 |
|
|
} |
361 |
|
|
|
362 |
|
|
String DeviceRuntimeParameterString::ValueAsString() { |
363 |
|
|
return sVal; |
364 |
|
|
} |
365 |
|
|
|
366 |
schoenebeck |
880 |
void DeviceRuntimeParameterString::SetValueAsString(String val) throw (Exception) { |
367 |
|
|
if (Fix()) throw Exception("Device parameter is read only"); |
368 |
|
|
if (val.find("\'") != String::npos) throw Exception("Character -> \' <- not allowed"); |
369 |
|
|
if (val.find("\"") != String::npos) throw Exception("Character -> \" <- not allowed"); |
370 |
schoenebeck |
123 |
OnSetValue(val); |
371 |
|
|
sVal = val; |
372 |
|
|
} |
373 |
|
|
|
374 |
|
|
|
375 |
|
|
|
376 |
|
|
// *************** DeviceRuntimeParameterStrings *************** |
377 |
|
|
// * |
378 |
|
|
|
379 |
|
|
DeviceRuntimeParameterStrings::DeviceRuntimeParameterStrings(std::vector<String> vS) { |
380 |
|
|
this->sVals = vS; |
381 |
|
|
} |
382 |
|
|
|
383 |
|
|
String DeviceRuntimeParameterStrings::Type() { |
384 |
|
|
return "STRING"; |
385 |
|
|
} |
386 |
|
|
|
387 |
|
|
bool DeviceRuntimeParameterStrings::Multiplicity() { |
388 |
|
|
return true; |
389 |
|
|
} |
390 |
|
|
|
391 |
|
|
optional<String> DeviceRuntimeParameterStrings::RangeMin() { |
392 |
|
|
return optional<String>::nothing; |
393 |
|
|
} |
394 |
|
|
|
395 |
|
|
optional<String> DeviceRuntimeParameterStrings::RangeMax() { |
396 |
|
|
return optional<String>::nothing; |
397 |
|
|
} |
398 |
|
|
|
399 |
|
|
optional<String> DeviceRuntimeParameterStrings::Possibilities() { |
400 |
|
|
std::vector<String> possibilities = PossibilitiesAsString(); |
401 |
|
|
if (possibilities.empty()) return optional<String>::nothing; |
402 |
|
|
|
403 |
|
|
std::stringstream ss; |
404 |
|
|
std::vector<String>::iterator iter = possibilities.begin(); |
405 |
|
|
while (iter != possibilities.end()) { |
406 |
|
|
if (ss.str() != "") ss << ","; |
407 |
|
|
ss << "'" << *iter << "'"; |
408 |
|
|
iter++; |
409 |
|
|
} |
410 |
|
|
return ss.str(); |
411 |
|
|
} |
412 |
|
|
|
413 |
|
|
String DeviceRuntimeParameterStrings::Value() { |
414 |
|
|
String result; |
415 |
|
|
std::vector<String>::iterator iter = this->sVals.begin(); |
416 |
|
|
while (iter != this->sVals.end()) { |
417 |
|
|
if (result != "") result += ","; |
418 |
|
|
result += "'" + *iter + "'"; |
419 |
|
|
iter++; |
420 |
|
|
} |
421 |
|
|
return result; |
422 |
|
|
} |
423 |
|
|
|
424 |
schoenebeck |
880 |
void DeviceRuntimeParameterStrings::SetValue(String val) throw (Exception) { |
425 |
|
|
if (Fix()) throw Exception("Device parameter is read only"); |
426 |
schoenebeck |
123 |
std::vector<String> vS = __parse_strings(val); |
427 |
|
|
SetValue(vS); |
428 |
|
|
} |
429 |
|
|
|
430 |
|
|
std::vector<String> DeviceRuntimeParameterStrings::ValueAsStrings() { |
431 |
|
|
return sVals; |
432 |
|
|
} |
433 |
|
|
|
434 |
schoenebeck |
880 |
void DeviceRuntimeParameterStrings::SetValue(std::vector<String> vS) throw (Exception) { |
435 |
|
|
if (Fix()) throw Exception("Device parameter is read only"); |
436 |
schoenebeck |
214 |
OnSetValue(vS); |
437 |
schoenebeck |
123 |
sVals = vS; |
438 |
|
|
} |
439 |
|
|
|
440 |
|
|
|
441 |
|
|
|
442 |
|
|
|
443 |
|
|
|
444 |
|
|
|
445 |
|
|
// *************** DeviceCreationParameter *************** |
446 |
|
|
// * |
447 |
|
|
|
448 |
|
|
optional<String> DeviceCreationParameter::Depends() { |
449 |
|
|
std::map<String,DeviceCreationParameter*> dependencies = DependsAsParameters(); |
450 |
|
|
if (!dependencies.size()) return optional<String>::nothing; |
451 |
|
|
|
452 |
|
|
std::map<String,DeviceCreationParameter*>::iterator iter = dependencies.begin(); |
453 |
|
|
String s; |
454 |
|
|
for (; iter != dependencies.end(); iter++) { |
455 |
|
|
if (s != "") s += ","; |
456 |
|
|
s += iter->first; |
457 |
|
|
} |
458 |
|
|
return s; |
459 |
|
|
} |
460 |
|
|
|
461 |
|
|
optional<String> DeviceCreationParameter::Default() { |
462 |
|
|
std::map<String,String> Parameters; // empty parameters vector |
463 |
|
|
return Default(Parameters); |
464 |
|
|
} |
465 |
|
|
|
466 |
|
|
optional<String> DeviceCreationParameter::RangeMin() { |
467 |
|
|
std::map<String,String> Parameters; // empty parameters vector |
468 |
|
|
return RangeMin(Parameters); |
469 |
|
|
} |
470 |
|
|
|
471 |
|
|
optional<String> DeviceCreationParameter::RangeMax() { |
472 |
|
|
std::map<String,String> Parameters; // empty parameters vector |
473 |
|
|
return RangeMax(Parameters); |
474 |
|
|
} |
475 |
|
|
|
476 |
|
|
optional<String> DeviceCreationParameter::Possibilities() { |
477 |
|
|
std::map<String,String> Parameters; // empty parameters vector |
478 |
|
|
return Possibilities(Parameters); |
479 |
|
|
} |
480 |
|
|
|
481 |
|
|
|
482 |
|
|
|
483 |
|
|
// *************** DeviceCreationParameterBool *************** |
484 |
|
|
// * |
485 |
|
|
|
486 |
senkov |
174 |
DeviceCreationParameterBool::DeviceCreationParameterBool(bool bVal) : DeviceCreationParameter() { |
487 |
schoenebeck |
123 |
this->bVal = bVal; |
488 |
|
|
} |
489 |
|
|
|
490 |
schoenebeck |
880 |
DeviceCreationParameterBool::DeviceCreationParameterBool(String val) throw (Exception) { |
491 |
schoenebeck |
123 |
this->bVal = __parse_bool(val); |
492 |
|
|
} |
493 |
|
|
|
494 |
|
|
void DeviceCreationParameterBool::InitWithDefault() { |
495 |
|
|
std::map<String,String> Parameters; // empty parameters vector |
496 |
|
|
optional<bool> defaultval = DefaultAsBool(Parameters); |
497 |
|
|
this->bVal = (defaultval) ? *defaultval : false; |
498 |
|
|
} |
499 |
|
|
|
500 |
|
|
String DeviceCreationParameterBool::Type() { |
501 |
|
|
return "BOOL"; |
502 |
|
|
} |
503 |
|
|
|
504 |
|
|
bool DeviceCreationParameterBool::Multiplicity() { |
505 |
|
|
return false; |
506 |
|
|
} |
507 |
|
|
|
508 |
|
|
optional<String> DeviceCreationParameterBool::Default(std::map<String,String> Parameters) { |
509 |
|
|
optional<bool> defaultval = DefaultAsBool(Parameters); |
510 |
|
|
if (!defaultval) return optional<String>::nothing; |
511 |
schoenebeck |
214 |
return (*defaultval) ? "true" : "false"; |
512 |
schoenebeck |
123 |
} |
513 |
|
|
|
514 |
|
|
optional<String> DeviceCreationParameterBool::RangeMin(std::map<String,String> Parameters) { |
515 |
|
|
return optional<String>::nothing; |
516 |
|
|
} |
517 |
|
|
|
518 |
|
|
optional<String> DeviceCreationParameterBool::RangeMax(std::map<String,String> Parameters) { |
519 |
|
|
return optional<String>::nothing; |
520 |
|
|
} |
521 |
|
|
|
522 |
|
|
optional<String> DeviceCreationParameterBool::Possibilities(std::map<String,String> Parameters) { |
523 |
|
|
return optional<String>::nothing; |
524 |
|
|
} |
525 |
|
|
|
526 |
|
|
String DeviceCreationParameterBool::Value() { |
527 |
schoenebeck |
214 |
return (ValueAsBool()) ? "true" : "false"; |
528 |
schoenebeck |
123 |
} |
529 |
|
|
|
530 |
schoenebeck |
880 |
void DeviceCreationParameterBool::SetValue(String val) throw (Exception) { |
531 |
|
|
if (Fix()) throw Exception("Device parameter is read only"); |
532 |
schoenebeck |
123 |
int b = __parse_bool(val); |
533 |
|
|
SetValue(b); |
534 |
|
|
} |
535 |
|
|
|
536 |
|
|
bool DeviceCreationParameterBool::ValueAsBool() { |
537 |
|
|
return bVal; |
538 |
|
|
} |
539 |
|
|
|
540 |
schoenebeck |
880 |
void DeviceCreationParameterBool::SetValue(bool b) throw (Exception) { |
541 |
|
|
if (Fix()) throw Exception("Device parameter is read only"); |
542 |
schoenebeck |
214 |
OnSetValue(b); |
543 |
schoenebeck |
123 |
bVal = b; |
544 |
|
|
} |
545 |
|
|
|
546 |
|
|
|
547 |
|
|
|
548 |
|
|
// *************** DeviceCreationParameterInt *************** |
549 |
|
|
// * |
550 |
|
|
|
551 |
senkov |
174 |
DeviceCreationParameterInt::DeviceCreationParameterInt(int iVal) : DeviceCreationParameter() { |
552 |
schoenebeck |
123 |
this->iVal = iVal; |
553 |
|
|
} |
554 |
|
|
|
555 |
schoenebeck |
880 |
DeviceCreationParameterInt::DeviceCreationParameterInt(String val) throw (Exception) { |
556 |
schoenebeck |
123 |
this->iVal = __parse_int(val); |
557 |
|
|
} |
558 |
|
|
|
559 |
|
|
void DeviceCreationParameterInt::InitWithDefault() { |
560 |
|
|
std::map<String,String> Parameters; // empty parameters vector |
561 |
|
|
optional<int> i = DefaultAsInt(Parameters); |
562 |
|
|
this->iVal = (i) ? *i : 0; |
563 |
|
|
} |
564 |
|
|
|
565 |
|
|
String DeviceCreationParameterInt::Type() { |
566 |
|
|
return "INT"; |
567 |
|
|
} |
568 |
|
|
|
569 |
|
|
bool DeviceCreationParameterInt::Multiplicity() { |
570 |
|
|
return false; |
571 |
|
|
} |
572 |
|
|
|
573 |
|
|
optional<String> DeviceCreationParameterInt::Default(std::map<String,String> Parameters) { |
574 |
|
|
optional<int> defaultval = DefaultAsInt(Parameters); |
575 |
|
|
if (!defaultval) return optional<String>::nothing; |
576 |
|
|
return ToString(*defaultval); |
577 |
|
|
} |
578 |
|
|
|
579 |
|
|
optional<String> DeviceCreationParameterInt::RangeMin(std::map<String,String> Parameters) { |
580 |
|
|
optional<int> rangemin = RangeMinAsInt(Parameters); |
581 |
|
|
if (!rangemin) return optional<String>::nothing; |
582 |
schoenebeck |
226 |
return ToString(*rangemin); |
583 |
schoenebeck |
123 |
} |
584 |
|
|
|
585 |
|
|
optional<String> DeviceCreationParameterInt::RangeMax(std::map<String,String> Parameters) { |
586 |
|
|
optional<int> rangemax = RangeMaxAsInt(Parameters); |
587 |
|
|
if (!rangemax) return optional<String>::nothing; |
588 |
schoenebeck |
226 |
return ToString(*rangemax); |
589 |
schoenebeck |
123 |
} |
590 |
|
|
|
591 |
|
|
optional<String> DeviceCreationParameterInt::Possibilities(std::map<String,String> Parameters) { |
592 |
|
|
std::vector<int> possibilities = PossibilitiesAsInt(Parameters); |
593 |
|
|
if (possibilities.empty()) return optional<String>::nothing; |
594 |
|
|
|
595 |
|
|
std::vector<int>::iterator iter = possibilities.begin(); |
596 |
|
|
std::stringstream ss; |
597 |
|
|
while (iter != possibilities.end()) { |
598 |
|
|
if (ss.str() != "") ss << ","; |
599 |
|
|
ss << *iter; |
600 |
|
|
iter++; |
601 |
|
|
} |
602 |
|
|
return ss.str(); |
603 |
|
|
} |
604 |
|
|
|
605 |
|
|
String DeviceCreationParameterInt::Value() { |
606 |
|
|
return ToString(ValueAsInt()); |
607 |
|
|
} |
608 |
|
|
|
609 |
schoenebeck |
880 |
void DeviceCreationParameterInt::SetValue(String val) throw (Exception) { |
610 |
|
|
if (Fix()) throw Exception("Device parameter is read only"); |
611 |
schoenebeck |
123 |
int i = __parse_int(val); |
612 |
iliev |
1305 |
|
613 |
|
|
std::map<String,String> emptyMap; |
614 |
|
|
if (RangeMinAsInt(emptyMap) && i < *RangeMinAsInt(emptyMap)) { |
615 |
|
|
throw Exception("Invalid device parameter value: too small"); |
616 |
|
|
} |
617 |
|
|
if (RangeMaxAsInt(emptyMap) && i > *RangeMaxAsInt(emptyMap)) { |
618 |
|
|
throw Exception("Invalid device parameter value: too big"); |
619 |
|
|
} |
620 |
|
|
|
621 |
|
|
if (PossibilitiesAsInt(emptyMap).size()) { |
622 |
schoenebeck |
123 |
bool valid = false; |
623 |
iliev |
1305 |
std::vector<int> possibilities = PossibilitiesAsInt(emptyMap); |
624 |
|
|
std::vector<int>::iterator iter = possibilities.begin(); |
625 |
|
|
while (iter != possibilities.end()) { |
626 |
schoenebeck |
123 |
if (i == *iter) { |
627 |
|
|
valid = true; |
628 |
|
|
break; |
629 |
|
|
} |
630 |
|
|
iter++; |
631 |
|
|
} |
632 |
schoenebeck |
880 |
if (!valid) throw Exception("Invalid Device parameter value: not in set of possible values"); |
633 |
iliev |
1305 |
} |
634 |
schoenebeck |
123 |
SetValue(i); |
635 |
|
|
} |
636 |
|
|
|
637 |
|
|
int DeviceCreationParameterInt::ValueAsInt() { |
638 |
|
|
return iVal; |
639 |
|
|
} |
640 |
|
|
|
641 |
schoenebeck |
880 |
void DeviceCreationParameterInt::SetValue(int i) throw (Exception) { |
642 |
|
|
if (Fix()) throw Exception("Device parameter is read only"); |
643 |
schoenebeck |
214 |
OnSetValue(i); |
644 |
schoenebeck |
123 |
iVal = i; |
645 |
|
|
} |
646 |
|
|
|
647 |
|
|
|
648 |
|
|
|
649 |
|
|
// *************** DeviceCreationParameterFloat *************** |
650 |
|
|
// * |
651 |
|
|
|
652 |
senkov |
174 |
DeviceCreationParameterFloat::DeviceCreationParameterFloat(float fVal) : DeviceCreationParameter() { |
653 |
schoenebeck |
123 |
this->fVal = fVal; |
654 |
|
|
} |
655 |
|
|
|
656 |
schoenebeck |
880 |
DeviceCreationParameterFloat::DeviceCreationParameterFloat(String val) throw (Exception) { |
657 |
schoenebeck |
123 |
this->fVal = __parse_float(val); |
658 |
|
|
} |
659 |
|
|
|
660 |
|
|
void DeviceCreationParameterFloat::InitWithDefault() { |
661 |
|
|
std::map<String,String> Parameters; // empty parameters vector |
662 |
|
|
optional<float> f = DefaultAsFloat(Parameters); |
663 |
|
|
this->fVal = (f) ? *f : 0.0f; |
664 |
|
|
} |
665 |
|
|
|
666 |
|
|
String DeviceCreationParameterFloat::Type() { |
667 |
|
|
return "FLOAT"; |
668 |
|
|
} |
669 |
|
|
|
670 |
|
|
bool DeviceCreationParameterFloat::Multiplicity() { |
671 |
|
|
return false; |
672 |
|
|
} |
673 |
|
|
|
674 |
|
|
optional<String> DeviceCreationParameterFloat::Default(std::map<String,String> Parameters) { |
675 |
|
|
optional<float> defaultval = DefaultAsFloat(Parameters); |
676 |
|
|
if (!defaultval) return optional<String>::nothing; |
677 |
|
|
return ToString(*defaultval); |
678 |
|
|
} |
679 |
|
|
|
680 |
|
|
optional<String> DeviceCreationParameterFloat::RangeMin(std::map<String,String> Parameters) { |
681 |
|
|
optional<float> rangemin = RangeMinAsFloat(Parameters); |
682 |
|
|
if (!rangemin) return optional<String>::nothing; |
683 |
|
|
return ToString(*rangemin); |
684 |
|
|
} |
685 |
|
|
|
686 |
|
|
optional<String> DeviceCreationParameterFloat::RangeMax(std::map<String,String> Parameters) { |
687 |
|
|
optional<float> rangemax = RangeMaxAsFloat(Parameters); |
688 |
|
|
if (!rangemax) return optional<String>::nothing; |
689 |
|
|
return ToString(*rangemax); |
690 |
|
|
} |
691 |
|
|
|
692 |
|
|
optional<String> DeviceCreationParameterFloat::Possibilities(std::map<String,String> Parameters) { |
693 |
|
|
std::vector<float> possibilities = PossibilitiesAsFloat(Parameters); |
694 |
|
|
if (possibilities.empty()) return optional<String>::nothing; |
695 |
|
|
|
696 |
|
|
std::vector<float>::iterator iter = possibilities.begin(); |
697 |
|
|
std::stringstream ss; |
698 |
|
|
while (iter != possibilities.end()) { |
699 |
|
|
if (ss.str() != "") ss << ","; |
700 |
|
|
ss << *iter; |
701 |
|
|
iter++; |
702 |
|
|
} |
703 |
|
|
return ss.str(); |
704 |
|
|
} |
705 |
|
|
|
706 |
|
|
String DeviceCreationParameterFloat::Value() { |
707 |
|
|
return ToString(ValueAsFloat()); |
708 |
|
|
} |
709 |
|
|
|
710 |
schoenebeck |
880 |
void DeviceCreationParameterFloat::SetValue(String val) throw (Exception) { |
711 |
|
|
if (Fix()) throw Exception("Device parameter is read only"); |
712 |
schoenebeck |
123 |
float f = __parse_float(val); |
713 |
schoenebeck |
880 |
//if (RangeMinAsFloat() && i < *RangeMinAsFloat()) throw Exception("Invalid device parameter value: too small"); |
714 |
|
|
//if (RangeMaxAsFloat() && i > *RangeMaxAsFloat()) throw Exception("Invalid device parameter value: too big"); |
715 |
schoenebeck |
123 |
/*if (PossibilitiesAsFloat()) { |
716 |
|
|
bool valid = false; |
717 |
|
|
std::vector<float>* pPossibilities = PossibilitiesAsFloat(); |
718 |
|
|
std::vector<float>::iterator iter = pPossibilities->begin(); |
719 |
|
|
while (iter != pPossibilities->end()) { |
720 |
|
|
if (f == *iter) { |
721 |
|
|
valid = true; |
722 |
|
|
break; |
723 |
|
|
} |
724 |
|
|
iter++; |
725 |
|
|
} |
726 |
schoenebeck |
880 |
if (!valid) throw Exception("Invalid Device parameter value: not in set of possible values"); |
727 |
schoenebeck |
123 |
}*/ |
728 |
|
|
SetValue(f); |
729 |
|
|
} |
730 |
|
|
|
731 |
|
|
float DeviceCreationParameterFloat::ValueAsFloat() { |
732 |
|
|
return fVal; |
733 |
|
|
} |
734 |
|
|
|
735 |
schoenebeck |
880 |
void DeviceCreationParameterFloat::SetValue(float f) throw (Exception) { |
736 |
|
|
if (Fix()) throw Exception("Device parameter is read only"); |
737 |
schoenebeck |
214 |
OnSetValue(f); |
738 |
schoenebeck |
123 |
fVal = f; |
739 |
|
|
} |
740 |
|
|
|
741 |
|
|
|
742 |
|
|
|
743 |
|
|
// *************** DeviceCreationParameterString *************** |
744 |
|
|
// * |
745 |
|
|
|
746 |
senkov |
174 |
DeviceCreationParameterString::DeviceCreationParameterString(String sVal) : DeviceCreationParameter() { |
747 |
schoenebeck |
486 |
this->sVal = __parse_string(sVal); |
748 |
schoenebeck |
123 |
} |
749 |
|
|
|
750 |
|
|
void DeviceCreationParameterString::InitWithDefault() { |
751 |
|
|
std::map<String,String> Parameters; // empty parameters vector |
752 |
schoenebeck |
212 |
optional<String> defaulval = DefaultAsString(Parameters); |
753 |
schoenebeck |
123 |
if (defaulval) this->sVal = *defaulval; |
754 |
|
|
else this->sVal = ""; |
755 |
|
|
} |
756 |
|
|
|
757 |
|
|
String DeviceCreationParameterString::Type() { |
758 |
|
|
return "STRING"; |
759 |
|
|
} |
760 |
|
|
|
761 |
|
|
bool DeviceCreationParameterString::Multiplicity() { |
762 |
|
|
return false; |
763 |
|
|
} |
764 |
|
|
|
765 |
schoenebeck |
212 |
optional<String> DeviceCreationParameterString::Default(std::map<String,String> Parameters) { |
766 |
|
|
optional<String> defaultval = DefaultAsString(Parameters); |
767 |
|
|
if (!defaultval) return optional<String>::nothing; |
768 |
|
|
return "'" + *defaultval + "'"; |
769 |
|
|
} |
770 |
|
|
|
771 |
schoenebeck |
123 |
optional<String> DeviceCreationParameterString::RangeMin(std::map<String,String> Parameters) { |
772 |
|
|
return optional<String>::nothing; |
773 |
|
|
} |
774 |
|
|
|
775 |
|
|
optional<String> DeviceCreationParameterString::RangeMax(std::map<String,String> Parameters) { |
776 |
|
|
return optional<String>::nothing; |
777 |
|
|
} |
778 |
|
|
|
779 |
|
|
optional<String> DeviceCreationParameterString::Possibilities(std::map<String,String> Parameters) { |
780 |
|
|
std::vector<String> possibilities = PossibilitiesAsString(Parameters); |
781 |
|
|
if (possibilities.empty()) return optional<String>::nothing; |
782 |
|
|
|
783 |
|
|
std::stringstream ss; |
784 |
|
|
std::vector<String>::iterator iter = possibilities.begin(); |
785 |
|
|
while (iter != possibilities.end()) { |
786 |
|
|
if (ss.str() != "") ss << ","; |
787 |
|
|
ss << "'" << *iter << "'"; |
788 |
|
|
iter++; |
789 |
|
|
} |
790 |
|
|
return ss.str(); |
791 |
|
|
} |
792 |
|
|
|
793 |
|
|
String DeviceCreationParameterString::Value() { |
794 |
schoenebeck |
214 |
return "\'" + ValueAsString() + "\'"; |
795 |
schoenebeck |
123 |
} |
796 |
|
|
|
797 |
schoenebeck |
880 |
void DeviceCreationParameterString::SetValue(String val) throw (Exception) { |
798 |
|
|
if (Fix()) throw Exception("Device parameter is read only"); |
799 |
schoenebeck |
214 |
SetValueAsString(__parse_string(val)); |
800 |
|
|
} |
801 |
|
|
|
802 |
|
|
String DeviceCreationParameterString::ValueAsString() { |
803 |
|
|
return sVal; |
804 |
|
|
} |
805 |
|
|
|
806 |
schoenebeck |
880 |
void DeviceCreationParameterString::SetValueAsString(String val) throw (Exception) { |
807 |
|
|
if (val.find("\'") != String::npos) throw Exception("Character -> \' <- not allowed"); |
808 |
|
|
if (val.find("\"") != String::npos) throw Exception("Character -> \" <- not allowed"); |
809 |
schoenebeck |
123 |
OnSetValue(val); |
810 |
|
|
sVal = val; |
811 |
|
|
} |
812 |
|
|
|
813 |
|
|
|
814 |
|
|
|
815 |
|
|
// *************** DeviceCreationParameterStrings *************** |
816 |
|
|
// * |
817 |
|
|
|
818 |
senkov |
174 |
DeviceCreationParameterStrings::DeviceCreationParameterStrings(std::vector<String> sVals) : DeviceCreationParameter() { |
819 |
schoenebeck |
123 |
this->sVals = sVals; |
820 |
|
|
} |
821 |
|
|
|
822 |
schoenebeck |
880 |
DeviceCreationParameterStrings::DeviceCreationParameterStrings(String val) throw (Exception) { |
823 |
schoenebeck |
123 |
this->sVals = __parse_strings(val); |
824 |
|
|
} |
825 |
|
|
|
826 |
|
|
void DeviceCreationParameterStrings::InitWithDefault() { |
827 |
|
|
std::map<String,String> Parameters; // empty parameters vector |
828 |
|
|
optional<std::vector<String> > defaultval = DefaultAsStrings(Parameters); |
829 |
|
|
this->sVals = (defaultval) ? *defaultval : std::vector<String>(); |
830 |
|
|
} |
831 |
|
|
|
832 |
|
|
String DeviceCreationParameterStrings::Type() { |
833 |
|
|
return "STRING"; |
834 |
|
|
} |
835 |
|
|
|
836 |
|
|
bool DeviceCreationParameterStrings::Multiplicity() { |
837 |
|
|
return true; |
838 |
|
|
} |
839 |
|
|
|
840 |
schoenebeck |
212 |
optional<String> DeviceCreationParameterStrings::Default(std::map<String,String> Parameters) { |
841 |
|
|
std::vector<String> defaultval = DefaultAsStrings(Parameters); |
842 |
|
|
if (defaultval.empty()) return optional<String>::nothing; |
843 |
|
|
String result; |
844 |
|
|
std::vector<String>::iterator iter = defaultval.begin(); |
845 |
|
|
for (; iter != defaultval.end(); iter++) { |
846 |
|
|
if (result != "") result += ","; |
847 |
|
|
result += ("'" + *iter + "'"); |
848 |
|
|
} |
849 |
|
|
return result; |
850 |
|
|
} |
851 |
|
|
|
852 |
schoenebeck |
123 |
optional<String> DeviceCreationParameterStrings::RangeMin(std::map<String,String> Parameters) { |
853 |
|
|
return optional<String>::nothing; |
854 |
|
|
} |
855 |
|
|
|
856 |
|
|
optional<String> DeviceCreationParameterStrings::RangeMax(std::map<String,String> Parameters) { |
857 |
|
|
return optional<String>::nothing; |
858 |
|
|
} |
859 |
|
|
|
860 |
|
|
optional<String> DeviceCreationParameterStrings::Possibilities(std::map<String,String> Parameters) { |
861 |
|
|
std::vector<String> possibilities = PossibilitiesAsString(Parameters); |
862 |
|
|
if (possibilities.empty()) return optional<String>::nothing; |
863 |
|
|
|
864 |
|
|
std::stringstream ss; |
865 |
|
|
std::vector<String>::iterator iter = possibilities.begin(); |
866 |
|
|
while (iter != possibilities.end()) { |
867 |
|
|
if (ss.str() != "") ss << ","; |
868 |
|
|
ss << "'" << *iter << "'"; |
869 |
|
|
iter++; |
870 |
|
|
} |
871 |
|
|
return ss.str(); |
872 |
|
|
} |
873 |
|
|
|
874 |
|
|
String DeviceCreationParameterStrings::Value() { |
875 |
|
|
String result; |
876 |
|
|
std::vector<String>::iterator iter = this->sVals.begin(); |
877 |
|
|
while (iter != this->sVals.end()) { |
878 |
|
|
if (result != "") result += ","; |
879 |
|
|
result += "'" + *iter + "'"; |
880 |
|
|
iter++; |
881 |
|
|
} |
882 |
|
|
return result; |
883 |
|
|
} |
884 |
|
|
|
885 |
schoenebeck |
880 |
void DeviceCreationParameterStrings::SetValue(String val) throw (Exception) { |
886 |
|
|
if (Fix()) throw Exception("Device parameter is read only"); |
887 |
schoenebeck |
123 |
std::vector<String> vS = __parse_strings(val); |
888 |
|
|
SetValue(vS); |
889 |
|
|
} |
890 |
|
|
|
891 |
|
|
std::vector<String> DeviceCreationParameterStrings::ValueAsStrings() { |
892 |
|
|
return sVals; |
893 |
|
|
} |
894 |
|
|
|
895 |
schoenebeck |
880 |
void DeviceCreationParameterStrings::SetValue(std::vector<String> vS) throw (Exception) { |
896 |
|
|
if (Fix()) throw Exception("Device parameter is read only"); |
897 |
schoenebeck |
214 |
OnSetValue(vS); |
898 |
schoenebeck |
123 |
sVals = vS; |
899 |
|
|
} |
900 |
|
|
|
901 |
|
|
} // namespace LinuxSampler |