/[svn]/linuxsampler/trunk/src/drivers/DeviceParameter.cpp
ViewVC logotype

Contents of /linuxsampler/trunk/src/drivers/DeviceParameter.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1349 - (show annotations) (download)
Sat Sep 15 11:05:38 2007 UTC (12 years, 6 months ago) by persson
File size: 30928 byte(s)
* made sure that LSCP syntax is not affected by gigedit locale
  settings

1 /***************************************************************************
2 * *
3 * LinuxSampler - modular, streaming capable sampler *
4 * *
5 * Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck *
6 * Copyright (C) 2005, 2006 Christian Schoenebeck *
7 * *
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 // 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 (Exception) {
43 __eliminate_quotation(val);
44 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 else throw Exception("Invalid value for boolean Device parameter");
48 return b;
49 }
50
51 static int __parse_int(String val) throw (Exception) {
52 __eliminate_quotation(val);
53 return atoi(val.c_str()); // TODO: format check is missing
54 }
55
56 static float __parse_float(String val) throw (Exception) {
57 __eliminate_quotation(val);
58 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 }
64
65 static String __parse_string(String val) {
66 __eliminate_quotation(val);
67 return val;
68 }
69
70 static std::vector<String> __parse_strings(String val) throw (Exception) {
71 std::vector<String> vS;
72
73 // checking for empty list
74 if (val.length() == 0) return vS;
75
76 // if there's only a single value, then we also allow to give it without being encapsulated into apostrophes
77 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 if (*pC != '\'' && *pC != '\"') throw Exception("Invalid form, all individual strings should be encapsulated into apostrophes, separated by commas");
86
87 // search for token end
88 char* pTokenStart = pC + 1;
89 do {
90 pC++;
91 if (*pC == '\0') throw Exception("Invalid form, all individual strings should be encapsulated into apostrophes, separated by commas");
92 }
93 while (*pC != '\'' && *pC != '\"');
94 String token = val.substr((int)(pTokenStart - pStart), (int)(pC - pTokenStart));
95 vS.push_back(token); // we found the token's end
96
97 // now there should be either a comma or the end of the total string
98 if (*(++pC) == '\0') break;
99 if (*pC != ',') throw Exception("Invalid form, all individual strings should be encapsulated into apostrophes, separated by commas");
100 pC++;
101 }
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 return (ValueAsBool()) ? "true" : "false";
138 }
139
140 void DeviceRuntimeParameterBool::SetValue(String val) throw (Exception) {
141 if (Fix()) throw Exception("Device parameter is read only");
142 int b = __parse_bool(val);
143 SetValue(b);
144 }
145
146 bool DeviceRuntimeParameterBool::ValueAsBool() {
147 return bVal;
148 }
149
150 void DeviceRuntimeParameterBool::SetValue(bool b) throw (Exception) {
151 if (Fix()) throw Exception("Device parameter is read only");
152 OnSetValue(b);
153 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 void DeviceRuntimeParameterInt::SetValue(String val) throw (Exception) {
204 if (Fix()) throw Exception("Device parameter is read only");
205 int i = __parse_int(val);
206 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
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 if (!valid) throw Exception("Invalid device parameter value: not in set of possible values");
221 }
222 SetValue(i);
223 }
224
225 int DeviceRuntimeParameterInt::ValueAsInt() {
226 return iVal;
227 }
228
229 void DeviceRuntimeParameterInt::SetValue(int i) throw (Exception) {
230 if (Fix()) throw Exception("Device parameter is read only");
231 OnSetValue(i);
232 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 void DeviceRuntimeParameterFloat::SetValue(String val) throw (Exception) {
283 if (Fix()) throw Exception("Device parameter is read only");
284 float f = __parse_float(val);
285 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
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 if (!valid) throw Exception("Invalid device parameter value: not in set of possible values");
300 }
301 SetValue(f);
302 }
303
304 float DeviceRuntimeParameterFloat::ValueAsFloat() {
305 return fVal;
306 }
307
308 void DeviceRuntimeParameterFloat::SetValue(float f) throw (Exception) {
309 if (Fix()) throw Exception("Device parameter is read only");
310 OnSetValue(f);
311 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 return "\'" + ValueAsString() + "\'";
355 }
356
357 void DeviceRuntimeParameterString::SetValue(String val) throw (Exception) {
358 if (Fix()) throw Exception("Device parameter is read only");
359 SetValueAsString(__parse_string(val));
360 }
361
362 String DeviceRuntimeParameterString::ValueAsString() {
363 return sVal;
364 }
365
366 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 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 void DeviceRuntimeParameterStrings::SetValue(String val) throw (Exception) {
425 if (Fix()) throw Exception("Device parameter is read only");
426 std::vector<String> vS = __parse_strings(val);
427 SetValue(vS);
428 }
429
430 std::vector<String> DeviceRuntimeParameterStrings::ValueAsStrings() {
431 return sVals;
432 }
433
434 void DeviceRuntimeParameterStrings::SetValue(std::vector<String> vS) throw (Exception) {
435 if (Fix()) throw Exception("Device parameter is read only");
436 OnSetValue(vS);
437 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 DeviceCreationParameterBool::DeviceCreationParameterBool(bool bVal) : DeviceCreationParameter() {
487 this->bVal = bVal;
488 }
489
490 DeviceCreationParameterBool::DeviceCreationParameterBool(String val) throw (Exception) {
491 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 return (*defaultval) ? "true" : "false";
512 }
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 return (ValueAsBool()) ? "true" : "false";
528 }
529
530 void DeviceCreationParameterBool::SetValue(String val) throw (Exception) {
531 if (Fix()) throw Exception("Device parameter is read only");
532 int b = __parse_bool(val);
533 SetValue(b);
534 }
535
536 bool DeviceCreationParameterBool::ValueAsBool() {
537 return bVal;
538 }
539
540 void DeviceCreationParameterBool::SetValue(bool b) throw (Exception) {
541 if (Fix()) throw Exception("Device parameter is read only");
542 OnSetValue(b);
543 bVal = b;
544 }
545
546
547
548 // *************** DeviceCreationParameterInt ***************
549 // *
550
551 DeviceCreationParameterInt::DeviceCreationParameterInt(int iVal) : DeviceCreationParameter() {
552 this->iVal = iVal;
553 }
554
555 DeviceCreationParameterInt::DeviceCreationParameterInt(String val) throw (Exception) {
556 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 return ToString(*rangemin);
583 }
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 return ToString(*rangemax);
589 }
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 void DeviceCreationParameterInt::SetValue(String val) throw (Exception) {
610 if (Fix()) throw Exception("Device parameter is read only");
611 int i = __parse_int(val);
612
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 bool valid = false;
623 std::vector<int> possibilities = PossibilitiesAsInt(emptyMap);
624 std::vector<int>::iterator iter = possibilities.begin();
625 while (iter != possibilities.end()) {
626 if (i == *iter) {
627 valid = true;
628 break;
629 }
630 iter++;
631 }
632 if (!valid) throw Exception("Invalid Device parameter value: not in set of possible values");
633 }
634 SetValue(i);
635 }
636
637 int DeviceCreationParameterInt::ValueAsInt() {
638 return iVal;
639 }
640
641 void DeviceCreationParameterInt::SetValue(int i) throw (Exception) {
642 if (Fix()) throw Exception("Device parameter is read only");
643 OnSetValue(i);
644 iVal = i;
645 }
646
647
648
649 // *************** DeviceCreationParameterFloat ***************
650 // *
651
652 DeviceCreationParameterFloat::DeviceCreationParameterFloat(float fVal) : DeviceCreationParameter() {
653 this->fVal = fVal;
654 }
655
656 DeviceCreationParameterFloat::DeviceCreationParameterFloat(String val) throw (Exception) {
657 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 void DeviceCreationParameterFloat::SetValue(String val) throw (Exception) {
711 if (Fix()) throw Exception("Device parameter is read only");
712 float f = __parse_float(val);
713 //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 /*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 if (!valid) throw Exception("Invalid Device parameter value: not in set of possible values");
727 }*/
728 SetValue(f);
729 }
730
731 float DeviceCreationParameterFloat::ValueAsFloat() {
732 return fVal;
733 }
734
735 void DeviceCreationParameterFloat::SetValue(float f) throw (Exception) {
736 if (Fix()) throw Exception("Device parameter is read only");
737 OnSetValue(f);
738 fVal = f;
739 }
740
741
742
743 // *************** DeviceCreationParameterString ***************
744 // *
745
746 DeviceCreationParameterString::DeviceCreationParameterString(String sVal) : DeviceCreationParameter() {
747 this->sVal = __parse_string(sVal);
748 }
749
750 void DeviceCreationParameterString::InitWithDefault() {
751 std::map<String,String> Parameters; // empty parameters vector
752 optional<String> defaulval = DefaultAsString(Parameters);
753 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 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 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 return "\'" + ValueAsString() + "\'";
795 }
796
797 void DeviceCreationParameterString::SetValue(String val) throw (Exception) {
798 if (Fix()) throw Exception("Device parameter is read only");
799 SetValueAsString(__parse_string(val));
800 }
801
802 String DeviceCreationParameterString::ValueAsString() {
803 return sVal;
804 }
805
806 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 OnSetValue(val);
810 sVal = val;
811 }
812
813
814
815 // *************** DeviceCreationParameterStrings ***************
816 // *
817
818 DeviceCreationParameterStrings::DeviceCreationParameterStrings(std::vector<String> sVals) : DeviceCreationParameter() {
819 this->sVals = sVals;
820 }
821
822 DeviceCreationParameterStrings::DeviceCreationParameterStrings(String val) throw (Exception) {
823 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 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 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 void DeviceCreationParameterStrings::SetValue(String val) throw (Exception) {
886 if (Fix()) throw Exception("Device parameter is read only");
887 std::vector<String> vS = __parse_strings(val);
888 SetValue(vS);
889 }
890
891 std::vector<String> DeviceCreationParameterStrings::ValueAsStrings() {
892 return sVals;
893 }
894
895 void DeviceCreationParameterStrings::SetValue(std::vector<String> vS) throw (Exception) {
896 if (Fix()) throw Exception("Device parameter is read only");
897 OnSetValue(vS);
898 sVals = vS;
899 }
900
901 } // namespace LinuxSampler

  ViewVC Help
Powered by ViewVC