/[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 214 - (show annotations) (download)
Sat Aug 14 23:00:44 2004 UTC (19 years, 8 months ago) by schoenebeck
File size: 31070 byte(s)
* src/drivers/DeviceParameter.cpp: fixed return values for
classes 'DeviceRuntimeParameterString' and 'DeviceCreationParameterString'
which returned their values without being encapsulated into apostrophes,
fixed return values for 'DeviceRuntimeParameterBool' and
'DeviceCreationParameterBool' to be returned in lower case (as defined in
the LSCP documentation)
* src/network/lscp.y: key value pairs now also allow strings (without
spaces) to be not encapsulated into apostrophes (e.g. foo=bar instead of
foo='bar')
* src/linuxsampler.cpp: show on the console which TCP port the LSCP server
is using

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

  ViewVC Help
Powered by ViewVC