/[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 486 - (hide annotations) (download)
Thu Mar 24 23:07:22 2005 UTC (19 years, 1 month ago) by schoenebeck
File size: 31434 byte(s)
* remove quotation marks from driver parameters

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

  ViewVC Help
Powered by ViewVC