/[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 483 - (show annotations) (download)
Mon Mar 21 23:40:56 2005 UTC (19 years, 1 month ago) by schoenebeck
File size: 31214 byte(s)
* JACK audio driver: fixed handling of channel parameter 'JACK_BINDINGS'
* fixed parser bug of multiplicity parameters

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

  ViewVC Help
Powered by ViewVC