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