/[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 212 - (hide annotations) (download)
Wed Jul 28 14:17:29 2004 UTC (19 years, 9 months ago) by schoenebeck
File size: 29096 byte(s)
* introduced and implemented new LSCP command "RESET" which resets the
  whole sampler instance
* src/drivers/audio/AudioOutputDeviceAlsa.cpp: parameter 'card' now
  returns all available sound cards as possibility, added dependency to
  parameter 'card' to parameters 'fragments' and 'fragmentsize'
* src/drivers/DeviceParameter.cpp: fixed return value(s) for classes
  'DeviceCreationParameterString' and 'DeviceCreationParameterStrings'
  which returned the default value(s) not encapsulated into apostrophes
* src/network/lscpserver.cpp: fixed implementation of LSCP commands
  "GET MIDI_INPUT_DRIVER_PARAMETER INFO" and
  "GET AUDIO_OUTPUT_DRIVER_PARAMETER INFO"

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

  ViewVC Help
Powered by ViewVC