/[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 128 - (show annotations) (download)
Tue Jun 15 03:19:30 2004 UTC (13 years, 5 months ago) by senkov
File size: 28544 byte(s)
* Remove calls to pure virtual from constructor of base class
 to avoid runtime failure. InitWithDefault() will have to be called
 from the constructor of the class where virtuals are implemented.

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 }
445
446 DeviceCreationParameterBool::DeviceCreationParameterBool(bool bVal) {
447 this->bVal = bVal;
448 }
449
450 DeviceCreationParameterBool::DeviceCreationParameterBool(String val) throw (LinuxSamplerException) {
451 this->bVal = __parse_bool(val);
452 }
453
454 void DeviceCreationParameterBool::InitWithDefault() {
455 std::map<String,String> Parameters; // empty parameters vector
456 optional<bool> defaultval = DefaultAsBool(Parameters);
457 this->bVal = (defaultval) ? *defaultval : false;
458 }
459
460 String DeviceCreationParameterBool::Type() {
461 return "BOOL";
462 }
463
464 bool DeviceCreationParameterBool::Multiplicity() {
465 return false;
466 }
467
468 optional<String> DeviceCreationParameterBool::Default(std::map<String,String> Parameters) {
469 optional<bool> defaultval = DefaultAsBool(Parameters);
470 if (!defaultval) return optional<String>::nothing;
471 return (*defaultval) ? "TRUE" : "FALSE";
472 }
473
474 optional<String> DeviceCreationParameterBool::RangeMin(std::map<String,String> Parameters) {
475 return optional<String>::nothing;
476 }
477
478 optional<String> DeviceCreationParameterBool::RangeMax(std::map<String,String> Parameters) {
479 return optional<String>::nothing;
480 }
481
482 optional<String> DeviceCreationParameterBool::Possibilities(std::map<String,String> Parameters) {
483 return optional<String>::nothing;
484 }
485
486 String DeviceCreationParameterBool::Value() {
487 return (ValueAsBool()) ? "TRUE" : "FALSE";
488 }
489
490 void DeviceCreationParameterBool::SetValue(String val) throw (LinuxSamplerException) {
491 if (Fix()) throw LinuxSamplerException("Device parameter is read only");
492 int b = __parse_bool(val);
493 OnSetValue(b);
494 SetValue(b);
495 }
496
497 bool DeviceCreationParameterBool::ValueAsBool() {
498 return bVal;
499 }
500
501 void DeviceCreationParameterBool::SetValue(bool b) {
502 bVal = b;
503 }
504
505
506
507 // *************** DeviceCreationParameterInt ***************
508 // *
509
510 DeviceCreationParameterInt::DeviceCreationParameterInt() {
511 }
512
513 DeviceCreationParameterInt::DeviceCreationParameterInt(int iVal) {
514 this->iVal = iVal;
515 }
516
517 DeviceCreationParameterInt::DeviceCreationParameterInt(String val) throw (LinuxSamplerException) {
518 this->iVal = __parse_int(val);
519 }
520
521 void DeviceCreationParameterInt::InitWithDefault() {
522 std::map<String,String> Parameters; // empty parameters vector
523 optional<int> i = DefaultAsInt(Parameters);
524 this->iVal = (i) ? *i : 0;
525 }
526
527 String DeviceCreationParameterInt::Type() {
528 return "INT";
529 }
530
531 bool DeviceCreationParameterInt::Multiplicity() {
532 return false;
533 }
534
535 optional<String> DeviceCreationParameterInt::Default(std::map<String,String> Parameters) {
536 optional<int> defaultval = DefaultAsInt(Parameters);
537 if (!defaultval) return optional<String>::nothing;
538 return ToString(*defaultval);
539 }
540
541 optional<String> DeviceCreationParameterInt::RangeMin(std::map<String,String> Parameters) {
542 optional<int> rangemin = RangeMinAsInt(Parameters);
543 if (!rangemin) return optional<String>::nothing;
544 return ToString(rangemin);
545 }
546
547 optional<String> DeviceCreationParameterInt::RangeMax(std::map<String,String> Parameters) {
548 optional<int> rangemax = RangeMaxAsInt(Parameters);
549 if (!rangemax) return optional<String>::nothing;
550 return ToString(rangemax);
551 }
552
553 optional<String> DeviceCreationParameterInt::Possibilities(std::map<String,String> Parameters) {
554 std::vector<int> possibilities = PossibilitiesAsInt(Parameters);
555 if (possibilities.empty()) return optional<String>::nothing;
556
557 std::vector<int>::iterator iter = possibilities.begin();
558 std::stringstream ss;
559 while (iter != possibilities.end()) {
560 if (ss.str() != "") ss << ",";
561 ss << *iter;
562 iter++;
563 }
564 return ss.str();
565 }
566
567 String DeviceCreationParameterInt::Value() {
568 return ToString(ValueAsInt());
569 }
570
571 void DeviceCreationParameterInt::SetValue(String val) throw (LinuxSamplerException) {
572 if (Fix()) throw LinuxSamplerException("Device parameter is read only");
573 int i = __parse_int(val);
574 //if (RangeMinAsInt() && i < *RangeMinAsInt()) throw LinuxSamplerException("Invalid device parameter value: too small");
575 //if (RangeMaxAsInt() && i > *RangeMaxAsInt()) throw LinuxSamplerException("Invalid device parameter value: too big");
576 /*if (PossibilitiesAsInt()) {
577 bool valid = false;
578 std::vector<int>* pPossibilities = PossibilitiesAsInt();
579 std::vector<int>::iterator iter = pPossibilities->begin();
580 while (iter != pPossibilities->end()) {
581 if (i == *iter) {
582 valid = true;
583 break;
584 }
585 iter++;
586 }
587 if (!valid) throw LinuxSamplerException("Invalid Device parameter value: not in set of possible values");
588 }*/
589 OnSetValue(i);
590 SetValue(i);
591 }
592
593 int DeviceCreationParameterInt::ValueAsInt() {
594 return iVal;
595 }
596
597 void DeviceCreationParameterInt::SetValue(int i) {
598 iVal = i;
599 }
600
601
602
603 // *************** DeviceCreationParameterFloat ***************
604 // *
605
606 DeviceCreationParameterFloat::DeviceCreationParameterFloat() {
607 }
608
609 DeviceCreationParameterFloat::DeviceCreationParameterFloat(float fVal) {
610 this->fVal = fVal;
611 }
612
613 DeviceCreationParameterFloat::DeviceCreationParameterFloat(String val) throw (LinuxSamplerException) {
614 this->fVal = __parse_float(val);
615 }
616
617 void DeviceCreationParameterFloat::InitWithDefault() {
618 std::map<String,String> Parameters; // empty parameters vector
619 optional<float> f = DefaultAsFloat(Parameters);
620 this->fVal = (f) ? *f : 0.0f;
621 }
622
623 String DeviceCreationParameterFloat::Type() {
624 return "FLOAT";
625 }
626
627 bool DeviceCreationParameterFloat::Multiplicity() {
628 return false;
629 }
630
631 optional<String> DeviceCreationParameterFloat::Default(std::map<String,String> Parameters) {
632 optional<float> defaultval = DefaultAsFloat(Parameters);
633 if (!defaultval) return optional<String>::nothing;
634 return ToString(*defaultval);
635 }
636
637 optional<String> DeviceCreationParameterFloat::RangeMin(std::map<String,String> Parameters) {
638 optional<float> rangemin = RangeMinAsFloat(Parameters);
639 if (!rangemin) return optional<String>::nothing;
640 return ToString(*rangemin);
641 }
642
643 optional<String> DeviceCreationParameterFloat::RangeMax(std::map<String,String> Parameters) {
644 optional<float> rangemax = RangeMaxAsFloat(Parameters);
645 if (!rangemax) return optional<String>::nothing;
646 return ToString(*rangemax);
647 }
648
649 optional<String> DeviceCreationParameterFloat::Possibilities(std::map<String,String> Parameters) {
650 std::vector<float> possibilities = PossibilitiesAsFloat(Parameters);
651 if (possibilities.empty()) return optional<String>::nothing;
652
653 std::vector<float>::iterator iter = possibilities.begin();
654 std::stringstream ss;
655 while (iter != possibilities.end()) {
656 if (ss.str() != "") ss << ",";
657 ss << *iter;
658 iter++;
659 }
660 return ss.str();
661 }
662
663 String DeviceCreationParameterFloat::Value() {
664 return ToString(ValueAsFloat());
665 }
666
667 void DeviceCreationParameterFloat::SetValue(String val) throw (LinuxSamplerException) {
668 if (Fix()) throw LinuxSamplerException("Device parameter is read only");
669 float f = __parse_float(val);
670 //if (RangeMinAsFloat() && i < *RangeMinAsFloat()) throw LinuxSamplerException("Invalid device parameter value: too small");
671 //if (RangeMaxAsFloat() && i > *RangeMaxAsFloat()) throw LinuxSamplerException("Invalid device parameter value: too big");
672 /*if (PossibilitiesAsFloat()) {
673 bool valid = false;
674 std::vector<float>* pPossibilities = PossibilitiesAsFloat();
675 std::vector<float>::iterator iter = pPossibilities->begin();
676 while (iter != pPossibilities->end()) {
677 if (f == *iter) {
678 valid = true;
679 break;
680 }
681 iter++;
682 }
683 if (!valid) throw LinuxSamplerException("Invalid Device parameter value: not in set of possible values");
684 }*/
685 OnSetValue(f);
686 SetValue(f);
687 }
688
689 float DeviceCreationParameterFloat::ValueAsFloat() {
690 return fVal;
691 }
692
693 void DeviceCreationParameterFloat::SetValue(float f) {
694 fVal = f;
695 }
696
697
698
699 // *************** DeviceCreationParameterString ***************
700 // *
701
702 DeviceCreationParameterString::DeviceCreationParameterString() {
703 }
704
705 DeviceCreationParameterString::DeviceCreationParameterString(String sVal) {
706 this->sVal = sVal;
707 }
708
709 void DeviceCreationParameterString::InitWithDefault() {
710 std::map<String,String> Parameters; // empty parameters vector
711 optional<String> defaulval = Default(Parameters);
712 if (defaulval) this->sVal = *defaulval;
713 else this->sVal = "";
714 }
715
716 String DeviceCreationParameterString::Type() {
717 return "STRING";
718 }
719
720 bool DeviceCreationParameterString::Multiplicity() {
721 return false;
722 }
723
724 optional<String> DeviceCreationParameterString::RangeMin(std::map<String,String> Parameters) {
725 return optional<String>::nothing;
726 }
727
728 optional<String> DeviceCreationParameterString::RangeMax(std::map<String,String> Parameters) {
729 return optional<String>::nothing;
730 }
731
732 optional<String> DeviceCreationParameterString::Possibilities(std::map<String,String> Parameters) {
733 std::vector<String> possibilities = PossibilitiesAsString(Parameters);
734 if (possibilities.empty()) return optional<String>::nothing;
735
736 std::stringstream ss;
737 std::vector<String>::iterator iter = possibilities.begin();
738 while (iter != possibilities.end()) {
739 if (ss.str() != "") ss << ",";
740 ss << "'" << *iter << "'";
741 iter++;
742 }
743 return ss.str();
744 }
745
746 String DeviceCreationParameterString::Value() {
747 return sVal;
748 }
749
750 void DeviceCreationParameterString::SetValue(String val) throw (LinuxSamplerException) {
751 if (Fix()) throw LinuxSamplerException("Device parameter is read only");
752 if (val.find("\'") != String::npos) throw LinuxSamplerException("Character -> \' <- not allowed");
753 if (val.find("\"") != String::npos) throw LinuxSamplerException("Character -> \" <- not allowed");
754 OnSetValue(val);
755 sVal = val;
756 }
757
758
759
760 // *************** DeviceCreationParameterStrings ***************
761 // *
762
763 DeviceCreationParameterStrings::DeviceCreationParameterStrings() {
764 }
765
766 DeviceCreationParameterStrings::DeviceCreationParameterStrings(std::vector<String> sVals) {
767 this->sVals = sVals;
768 }
769
770 DeviceCreationParameterStrings::DeviceCreationParameterStrings(String val) throw (LinuxSamplerException) {
771 this->sVals = __parse_strings(val);
772 }
773
774 void DeviceCreationParameterStrings::InitWithDefault() {
775 std::map<String,String> Parameters; // empty parameters vector
776 optional<std::vector<String> > defaultval = DefaultAsStrings(Parameters);
777 this->sVals = (defaultval) ? *defaultval : std::vector<String>();
778 }
779
780 String DeviceCreationParameterStrings::Type() {
781 return "STRING";
782 }
783
784 bool DeviceCreationParameterStrings::Multiplicity() {
785 return true;
786 }
787
788 optional<String> DeviceCreationParameterStrings::RangeMin(std::map<String,String> Parameters) {
789 return optional<String>::nothing;
790 }
791
792 optional<String> DeviceCreationParameterStrings::RangeMax(std::map<String,String> Parameters) {
793 return optional<String>::nothing;
794 }
795
796 optional<String> DeviceCreationParameterStrings::Possibilities(std::map<String,String> Parameters) {
797 std::vector<String> possibilities = PossibilitiesAsString(Parameters);
798 if (possibilities.empty()) return optional<String>::nothing;
799
800 std::stringstream ss;
801 std::vector<String>::iterator iter = possibilities.begin();
802 while (iter != possibilities.end()) {
803 if (ss.str() != "") ss << ",";
804 ss << "'" << *iter << "'";
805 iter++;
806 }
807 return ss.str();
808 }
809
810 String DeviceCreationParameterStrings::Value() {
811 String result;
812 std::vector<String>::iterator iter = this->sVals.begin();
813 while (iter != this->sVals.end()) {
814 if (result != "") result += ",";
815 result += "'" + *iter + "'";
816 iter++;
817 }
818 return result;
819 }
820
821 void DeviceCreationParameterStrings::SetValue(String val) throw (LinuxSamplerException) {
822 if (Fix()) throw LinuxSamplerException("Device parameter is read only");
823 std::vector<String> vS = __parse_strings(val);
824 OnSetValue(vS);
825 SetValue(vS);
826 }
827
828 std::vector<String> DeviceCreationParameterStrings::ValueAsStrings() {
829 return sVals;
830 }
831
832 void DeviceCreationParameterStrings::SetValue(std::vector<String> vS) {
833 sVals = vS;
834 }
835
836 } // namespace LinuxSampler

  ViewVC Help
Powered by ViewVC