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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1424 - (hide annotations) (download)
Sun Oct 14 22:00:17 2007 UTC (16 years, 6 months ago) by schoenebeck
File size: 30967 byte(s)
* code cleanup:
- global.h now only covers global definitions that are needed for the C++
  API header files, all implementation internal global definitions are now
  in global_private.h
- atomic.h is not exposed to the C++ API anymore (replaced the references
  in SynchronizedConfig.h for this with local definitions)
- no need to include config.h anymore for using LS's API header files
- DB instruments classes are not exposed to the C++ API
- POSIX callback functions of Thread.h are hidden
- the (optional) gig Engine benchmark compiles again
- updated Doxyfile.in
- fixed warnings in API doc generation
* preparations for release 0.5.0

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

  ViewVC Help
Powered by ViewVC