/[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 1296 - (show annotations) (download)
Wed Aug 15 17:43:34 2007 UTC (16 years, 8 months ago) by iliev
File size: 30716 byte(s)
* bugfix: The previous bindings were not been disconnected when
  altering the ALSA_SEQ_BINDINGS parameter.
* Introduced a NONE keyword for unsubscribing from all bindings
  (e.g. SET MIDI_INPUT_PORT_PARAMETER 0 0 ALSA_SEQ_BINDINGS=NONE).

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

  ViewVC Help
Powered by ViewVC