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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 486 by schoenebeck, Thu Mar 24 23:07:22 2005 UTC revision 1296 by iliev, Wed Aug 15 17:43:34 2007 UTC
# Line 3  Line 3 
3   *   LinuxSampler - modular, streaming capable sampler                     *   *   LinuxSampler - modular, streaming capable sampler                     *
4   *                                                                         *   *                                                                         *
5   *   Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck   *   *   Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck   *
6   *   Copyright (C) 2005 Christian Schoenebeck                              *   *   Copyright (C) 2005, 2006 Christian Schoenebeck                        *
7   *                                                                         *   *                                                                         *
8   *   This program is free software; you can redistribute it and/or modify  *   *   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  *   *   it under the terms of the GNU General Public License as published by  *
# Line 39  namespace LinuxSampler { Line 39  namespace LinuxSampler {
39          }          }
40      }      }
41    
42      static bool __parse_bool(String val) throw (LinuxSamplerException) {      static bool __parse_bool(String val) throw (Exception) {
43          __eliminate_quotation(val);          __eliminate_quotation(val);
44          int b;          int b;
45          if      (val == "1" || !strcasecmp(val.c_str(),"true"))  b = true;          if      (val == "1" || !strcasecmp(val.c_str(),"true"))  b = true;
46          else if (val == "0" || !strcasecmp(val.c_str(),"false")) b = false;          else if (val == "0" || !strcasecmp(val.c_str(),"false")) b = false;
47          else throw LinuxSamplerException("Invalid value for boolean Device parameter");          else throw Exception("Invalid value for boolean Device parameter");
48          return b;          return b;
49      }      }
50    
51      static int __parse_int(String val) throw (LinuxSamplerException) {      static int __parse_int(String val) throw (Exception) {
52          __eliminate_quotation(val);          __eliminate_quotation(val);
53          return atoi(val.c_str()); // TODO: format check is missing          return atoi(val.c_str()); // TODO: format check is missing
54      }      }
55    
56      static float __parse_float(String val) throw (LinuxSamplerException) {      static float __parse_float(String val) throw (Exception) {
57          __eliminate_quotation(val);          __eliminate_quotation(val);
58          return atof(val.c_str()); // TODO: format check is missing          return atof(val.c_str()); // TODO: format check is missing
59      }      }
# Line 63  namespace LinuxSampler { Line 63  namespace LinuxSampler {
63          return val;          return val;
64      }      }
65    
66      static std::vector<String> __parse_strings(String val) throw (LinuxSamplerException) {      static std::vector<String> __parse_strings(String val) throw (Exception) {
67          std::vector<String> vS;          std::vector<String> vS;
68            
69            // checking for empty list
70            if (val.length() == 0) return vS;
71    
72          // if there's only a single value, then we also allow to give it without being encapsulated into apostrophes          // if there's only a single value, then we also allow to give it without being encapsulated into apostrophes
73          if (val.find("\'") == String::npos && val.find("\"") == String::npos) {          if (val.find("\'") == String::npos && val.find("\"") == String::npos) {
# Line 75  namespace LinuxSampler { Line 78  namespace LinuxSampler {
78              char* pC     = pStart;              char* pC     = pStart;
79    
80              while (true) {              while (true) {
81                  if (*pC != '\'' && *pC != '\"') throw LinuxSamplerException("Invalid form, all individual strings should be encapsulated into apostrophes, separated by commas");                  if (*pC != '\'' && *pC != '\"') throw Exception("Invalid form, all individual strings should be encapsulated into apostrophes, separated by commas");
82    
83                  // search for token end                  // search for token end
84                  char* pTokenStart = pC + 1;                  char* pTokenStart = pC + 1;
85                  do {                  do {
86                      pC++;                      pC++;
87                      if (*pC == '\0') throw LinuxSamplerException("Invalid form, all individual strings should be encapsulated into apostrophes, separated by commas");                      if (*pC == '\0') throw Exception("Invalid form, all individual strings should be encapsulated into apostrophes, separated by commas");
88                  }                  }
89                  while (*pC != '\'' && *pC != '\"');                  while (*pC != '\'' && *pC != '\"');
90                  String token = val.substr((int)(pTokenStart - pStart), (int)(pC - pTokenStart));                  String token = val.substr((int)(pTokenStart - pStart), (int)(pC - pTokenStart));
# Line 89  namespace LinuxSampler { Line 92  namespace LinuxSampler {
92    
93                  // now there should be either a comma or the end of the total string                  // now there should be either a comma or the end of the total string
94                  if (*(++pC) == '\0') break;                  if (*(++pC) == '\0') break;
95                  if (*pC != ',') throw LinuxSamplerException("Invalid form, all individual strings should be encapsulated into apostrophes, separated by commas");                  if (*pC != ',') throw Exception("Invalid form, all individual strings should be encapsulated into apostrophes, separated by commas");
96                  pC++;                  pC++;
97              }              }
98          }          }
# Line 130  namespace LinuxSampler { Line 133  namespace LinuxSampler {
133          return (ValueAsBool()) ? "true" : "false";          return (ValueAsBool()) ? "true" : "false";
134      }      }
135    
136      void DeviceRuntimeParameterBool::SetValue(String val) throw (LinuxSamplerException) {      void DeviceRuntimeParameterBool::SetValue(String val) throw (Exception) {
137          if (Fix()) throw LinuxSamplerException("Device parameter is read only");          if (Fix()) throw Exception("Device parameter is read only");
138          int b = __parse_bool(val);          int b = __parse_bool(val);
139          SetValue(b);          SetValue(b);
140      }      }
# Line 140  namespace LinuxSampler { Line 143  namespace LinuxSampler {
143          return bVal;          return bVal;
144      }      }
145    
146      void DeviceRuntimeParameterBool::SetValue(bool b) throw (LinuxSamplerException) {      void DeviceRuntimeParameterBool::SetValue(bool b) throw (Exception) {
147          if (Fix()) throw LinuxSamplerException("Device parameter is read only");          if (Fix()) throw Exception("Device parameter is read only");
148          OnSetValue(b);          OnSetValue(b);
149          bVal = b;          bVal = b;
150      }      }
# Line 193  namespace LinuxSampler { Line 196  namespace LinuxSampler {
196          return ToString(ValueAsInt());          return ToString(ValueAsInt());
197      }      }
198    
199      void DeviceRuntimeParameterInt::SetValue(String val) throw (LinuxSamplerException) {      void DeviceRuntimeParameterInt::SetValue(String val) throw (Exception) {
200          if (Fix()) throw LinuxSamplerException("Device parameter is read only");          if (Fix()) throw Exception("Device parameter is read only");
201          int i = __parse_int(val);          int i = __parse_int(val);
202          if (RangeMinAsInt() && i < *RangeMinAsInt()) throw LinuxSamplerException("Invalid device parameter value: too small");          if (RangeMinAsInt() && i < *RangeMinAsInt()) throw Exception("Invalid device parameter value: too small");
203          if (RangeMaxAsInt() && i > *RangeMaxAsInt()) throw LinuxSamplerException("Invalid device parameter value: too big");          if (RangeMaxAsInt() && i > *RangeMaxAsInt()) throw Exception("Invalid device parameter value: too big");
204    
205          std::vector<int> possibilities = PossibilitiesAsInt();          std::vector<int> possibilities = PossibilitiesAsInt();
206          if (possibilities.size()) {          if (possibilities.size()) {
# Line 210  namespace LinuxSampler { Line 213  namespace LinuxSampler {
213                  }                  }
214                  iter++;                  iter++;
215              }              }
216              if (!valid) throw LinuxSamplerException("Invalid device parameter value: not in set of possible values");              if (!valid) throw Exception("Invalid device parameter value: not in set of possible values");
217          }          }
218          SetValue(i);          SetValue(i);
219      }      }
# Line 219  namespace LinuxSampler { Line 222  namespace LinuxSampler {
222          return iVal;          return iVal;
223      }      }
224    
225      void DeviceRuntimeParameterInt::SetValue(int i) throw (LinuxSamplerException) {      void DeviceRuntimeParameterInt::SetValue(int i) throw (Exception) {
226          if (Fix()) throw LinuxSamplerException("Device parameter is read only");          if (Fix()) throw Exception("Device parameter is read only");
227          OnSetValue(i);          OnSetValue(i);
228          iVal = i;          iVal = i;
229      }      }
# Line 272  namespace LinuxSampler { Line 275  namespace LinuxSampler {
275          return ToString(ValueAsFloat());          return ToString(ValueAsFloat());
276      }      }
277    
278      void DeviceRuntimeParameterFloat::SetValue(String val) throw (LinuxSamplerException) {      void DeviceRuntimeParameterFloat::SetValue(String val) throw (Exception) {
279          if (Fix()) throw LinuxSamplerException("Device parameter is read only");          if (Fix()) throw Exception("Device parameter is read only");
280          float f = __parse_float(val);          float f = __parse_float(val);
281          if (RangeMinAsFloat() && f < *RangeMinAsFloat()) throw LinuxSamplerException("Invalid device parameter value: too small");          if (RangeMinAsFloat() && f < *RangeMinAsFloat()) throw Exception("Invalid device parameter value: too small");
282          if (RangeMaxAsFloat() && f > *RangeMaxAsFloat()) throw LinuxSamplerException("Invalid device parameter value: too big");          if (RangeMaxAsFloat() && f > *RangeMaxAsFloat()) throw Exception("Invalid device parameter value: too big");
283    
284          std::vector<float> possibilities = PossibilitiesAsFloat();          std::vector<float> possibilities = PossibilitiesAsFloat();
285          if (possibilities.size()) {          if (possibilities.size()) {
# Line 289  namespace LinuxSampler { Line 292  namespace LinuxSampler {
292                  }                  }
293                  iter++;                  iter++;
294              }              }
295              if (!valid) throw LinuxSamplerException("Invalid device parameter value: not in set of possible values");              if (!valid) throw Exception("Invalid device parameter value: not in set of possible values");
296          }          }
297          SetValue(f);          SetValue(f);
298      }      }
# Line 298  namespace LinuxSampler { Line 301  namespace LinuxSampler {
301          return fVal;          return fVal;
302      }      }
303    
304      void DeviceRuntimeParameterFloat::SetValue(float f) throw (LinuxSamplerException) {      void DeviceRuntimeParameterFloat::SetValue(float f) throw (Exception) {
305          if (Fix()) throw LinuxSamplerException("Device parameter is read only");          if (Fix()) throw Exception("Device parameter is read only");
306          OnSetValue(f);          OnSetValue(f);
307          fVal = f;          fVal = f;
308      }      }
# Line 347  namespace LinuxSampler { Line 350  namespace LinuxSampler {
350          return "\'" + ValueAsString() + "\'";          return "\'" + ValueAsString() + "\'";
351      }      }
352    
353      void DeviceRuntimeParameterString::SetValue(String val) throw (LinuxSamplerException) {      void DeviceRuntimeParameterString::SetValue(String val) throw (Exception) {
354          if (Fix()) throw LinuxSamplerException("Device parameter is read only");          if (Fix()) throw Exception("Device parameter is read only");
355          SetValueAsString(__parse_string(val));          SetValueAsString(__parse_string(val));
356      }      }
357    
# Line 356  namespace LinuxSampler { Line 359  namespace LinuxSampler {
359          return sVal;          return sVal;
360      }      }
361    
362      void DeviceRuntimeParameterString::SetValueAsString(String val) throw (LinuxSamplerException) {      void DeviceRuntimeParameterString::SetValueAsString(String val) throw (Exception) {
363          if (Fix()) throw LinuxSamplerException("Device parameter is read only");          if (Fix()) throw Exception("Device parameter is read only");
364          if (val.find("\'") != String::npos) throw LinuxSamplerException("Character -> \' <- not allowed");          if (val.find("\'") != String::npos) throw Exception("Character -> \' <- not allowed");
365          if (val.find("\"") != String::npos) throw LinuxSamplerException("Character -> \" <- not allowed");          if (val.find("\"") != String::npos) throw Exception("Character -> \" <- not allowed");
366          OnSetValue(val);          OnSetValue(val);
367          sVal = val;          sVal = val;
368      }      }
# Line 414  namespace LinuxSampler { Line 417  namespace LinuxSampler {
417          return result;          return result;
418      }      }
419    
420      void DeviceRuntimeParameterStrings::SetValue(String val) throw (LinuxSamplerException) {      void DeviceRuntimeParameterStrings::SetValue(String val) throw (Exception) {
421          if (Fix()) throw LinuxSamplerException("Device parameter is read only");          if (Fix()) throw Exception("Device parameter is read only");
422          std::vector<String> vS = __parse_strings(val);          std::vector<String> vS = __parse_strings(val);
423          SetValue(vS);          SetValue(vS);
424      }      }
# Line 424  namespace LinuxSampler { Line 427  namespace LinuxSampler {
427          return sVals;          return sVals;
428      }      }
429    
430      void DeviceRuntimeParameterStrings::SetValue(std::vector<String> vS) throw (LinuxSamplerException) {      void DeviceRuntimeParameterStrings::SetValue(std::vector<String> vS) throw (Exception) {
431          if (Fix()) throw LinuxSamplerException("Device parameter is read only");          if (Fix()) throw Exception("Device parameter is read only");
432          OnSetValue(vS);          OnSetValue(vS);
433          sVals = vS;          sVals = vS;
434      }      }
# Line 480  namespace LinuxSampler { Line 483  namespace LinuxSampler {
483          this->bVal = bVal;          this->bVal = bVal;
484      }      }
485    
486      DeviceCreationParameterBool::DeviceCreationParameterBool(String val) throw (LinuxSamplerException) {      DeviceCreationParameterBool::DeviceCreationParameterBool(String val) throw (Exception) {
487          this->bVal = __parse_bool(val);          this->bVal = __parse_bool(val);
488      }      }
489    
# Line 520  namespace LinuxSampler { Line 523  namespace LinuxSampler {
523          return (ValueAsBool()) ? "true" : "false";          return (ValueAsBool()) ? "true" : "false";
524      }      }
525    
526      void DeviceCreationParameterBool::SetValue(String val) throw (LinuxSamplerException) {      void DeviceCreationParameterBool::SetValue(String val) throw (Exception) {
527          if (Fix()) throw LinuxSamplerException("Device parameter is read only");          if (Fix()) throw Exception("Device parameter is read only");
528          int b = __parse_bool(val);          int b = __parse_bool(val);
529          SetValue(b);          SetValue(b);
530      }      }
# Line 530  namespace LinuxSampler { Line 533  namespace LinuxSampler {
533          return bVal;          return bVal;
534      }      }
535    
536      void DeviceCreationParameterBool::SetValue(bool b) throw (LinuxSamplerException) {      void DeviceCreationParameterBool::SetValue(bool b) throw (Exception) {
537          if (Fix()) throw LinuxSamplerException("Device parameter is read only");          if (Fix()) throw Exception("Device parameter is read only");
538          OnSetValue(b);          OnSetValue(b);
539          bVal = b;          bVal = b;
540      }      }
# Line 545  namespace LinuxSampler { Line 548  namespace LinuxSampler {
548          this->iVal = iVal;          this->iVal = iVal;
549      }      }
550    
551      DeviceCreationParameterInt::DeviceCreationParameterInt(String val) throw (LinuxSamplerException) {      DeviceCreationParameterInt::DeviceCreationParameterInt(String val) throw (Exception) {
552          this->iVal = __parse_int(val);          this->iVal = __parse_int(val);
553      }      }
554    
# Line 599  namespace LinuxSampler { Line 602  namespace LinuxSampler {
602          return ToString(ValueAsInt());          return ToString(ValueAsInt());
603      }      }
604    
605      void DeviceCreationParameterInt::SetValue(String val) throw (LinuxSamplerException) {      void DeviceCreationParameterInt::SetValue(String val) throw (Exception) {
606          if (Fix()) throw LinuxSamplerException("Device parameter is read only");          if (Fix()) throw Exception("Device parameter is read only");
607          int i = __parse_int(val);          int i = __parse_int(val);
608          //if (RangeMinAsInt() && i < *RangeMinAsInt()) throw LinuxSamplerException("Invalid device parameter value: too small");          //if (RangeMinAsInt() && i < *RangeMinAsInt()) throw Exception("Invalid device parameter value: too small");
609          //if (RangeMaxAsInt() && i > *RangeMaxAsInt()) throw LinuxSamplerException("Invalid device parameter value: too big");          //if (RangeMaxAsInt() && i > *RangeMaxAsInt()) throw Exception("Invalid device parameter value: too big");
610          /*if (PossibilitiesAsInt()) {          /*if (PossibilitiesAsInt()) {
611              bool valid = false;              bool valid = false;
612              std::vector<int>* pPossibilities = PossibilitiesAsInt();              std::vector<int>* pPossibilities = PossibilitiesAsInt();
# Line 615  namespace LinuxSampler { Line 618  namespace LinuxSampler {
618                  }                  }
619                  iter++;                  iter++;
620              }              }
621              if (!valid) throw LinuxSamplerException("Invalid Device parameter value: not in set of possible values");              if (!valid) throw Exception("Invalid Device parameter value: not in set of possible values");
622          }*/          }*/
623          SetValue(i);          SetValue(i);
624      }      }
# Line 624  namespace LinuxSampler { Line 627  namespace LinuxSampler {
627          return iVal;          return iVal;
628      }      }
629    
630      void DeviceCreationParameterInt::SetValue(int i) throw (LinuxSamplerException) {      void DeviceCreationParameterInt::SetValue(int i) throw (Exception) {
631          if (Fix()) throw LinuxSamplerException("Device parameter is read only");          if (Fix()) throw Exception("Device parameter is read only");
632          OnSetValue(i);          OnSetValue(i);
633          iVal = i;          iVal = i;
634      }      }
# Line 639  namespace LinuxSampler { Line 642  namespace LinuxSampler {
642          this->fVal = fVal;          this->fVal = fVal;
643      }      }
644    
645      DeviceCreationParameterFloat::DeviceCreationParameterFloat(String val) throw (LinuxSamplerException) {      DeviceCreationParameterFloat::DeviceCreationParameterFloat(String val) throw (Exception) {
646          this->fVal = __parse_float(val);          this->fVal = __parse_float(val);
647      }      }
648    
# Line 693  namespace LinuxSampler { Line 696  namespace LinuxSampler {
696          return ToString(ValueAsFloat());          return ToString(ValueAsFloat());
697      }      }
698    
699      void DeviceCreationParameterFloat::SetValue(String val) throw (LinuxSamplerException) {      void DeviceCreationParameterFloat::SetValue(String val) throw (Exception) {
700          if (Fix()) throw LinuxSamplerException("Device parameter is read only");          if (Fix()) throw Exception("Device parameter is read only");
701          float f = __parse_float(val);          float f = __parse_float(val);
702          //if (RangeMinAsFloat() && i < *RangeMinAsFloat()) throw LinuxSamplerException("Invalid device parameter value: too small");          //if (RangeMinAsFloat() && i < *RangeMinAsFloat()) throw Exception("Invalid device parameter value: too small");
703          //if (RangeMaxAsFloat() && i > *RangeMaxAsFloat()) throw LinuxSamplerException("Invalid device parameter value: too big");          //if (RangeMaxAsFloat() && i > *RangeMaxAsFloat()) throw Exception("Invalid device parameter value: too big");
704          /*if (PossibilitiesAsFloat()) {          /*if (PossibilitiesAsFloat()) {
705              bool valid = false;              bool valid = false;
706              std::vector<float>* pPossibilities = PossibilitiesAsFloat();              std::vector<float>* pPossibilities = PossibilitiesAsFloat();
# Line 709  namespace LinuxSampler { Line 712  namespace LinuxSampler {
712                  }                  }
713                  iter++;                  iter++;
714              }              }
715              if (!valid) throw LinuxSamplerException("Invalid Device parameter value: not in set of possible values");              if (!valid) throw Exception("Invalid Device parameter value: not in set of possible values");
716          }*/          }*/
717          SetValue(f);          SetValue(f);
718      }      }
# Line 718  namespace LinuxSampler { Line 721  namespace LinuxSampler {
721          return fVal;          return fVal;
722      }      }
723    
724      void DeviceCreationParameterFloat::SetValue(float f) throw (LinuxSamplerException) {      void DeviceCreationParameterFloat::SetValue(float f) throw (Exception) {
725          if (Fix()) throw LinuxSamplerException("Device parameter is read only");          if (Fix()) throw Exception("Device parameter is read only");
726          OnSetValue(f);          OnSetValue(f);
727          fVal = f;          fVal = f;
728      }      }
# Line 780  namespace LinuxSampler { Line 783  namespace LinuxSampler {
783          return "\'" + ValueAsString() + "\'";          return "\'" + ValueAsString() + "\'";
784      }      }
785    
786      void DeviceCreationParameterString::SetValue(String val) throw (LinuxSamplerException) {      void DeviceCreationParameterString::SetValue(String val) throw (Exception) {
787          if (Fix()) throw LinuxSamplerException("Device parameter is read only");          if (Fix()) throw Exception("Device parameter is read only");
788          SetValueAsString(__parse_string(val));          SetValueAsString(__parse_string(val));
789      }      }
790    
# Line 789  namespace LinuxSampler { Line 792  namespace LinuxSampler {
792          return sVal;          return sVal;
793      }      }
794    
795      void DeviceCreationParameterString::SetValueAsString(String val) throw (LinuxSamplerException) {      void DeviceCreationParameterString::SetValueAsString(String val) throw (Exception) {
796          if (val.find("\'") != String::npos) throw LinuxSamplerException("Character -> \' <- not allowed");          if (val.find("\'") != String::npos) throw Exception("Character -> \' <- not allowed");
797          if (val.find("\"") != String::npos) throw LinuxSamplerException("Character -> \" <- not allowed");          if (val.find("\"") != String::npos) throw Exception("Character -> \" <- not allowed");
798          OnSetValue(val);          OnSetValue(val);
799          sVal = val;          sVal = val;
800      }      }
# Line 805  namespace LinuxSampler { Line 808  namespace LinuxSampler {
808          this->sVals = sVals;          this->sVals = sVals;
809      }      }
810    
811      DeviceCreationParameterStrings::DeviceCreationParameterStrings(String val) throw (LinuxSamplerException) {      DeviceCreationParameterStrings::DeviceCreationParameterStrings(String val) throw (Exception) {
812          this->sVals = __parse_strings(val);          this->sVals = __parse_strings(val);
813      }      }
814    
# Line 868  namespace LinuxSampler { Line 871  namespace LinuxSampler {
871          return result;          return result;
872      }      }
873    
874      void DeviceCreationParameterStrings::SetValue(String val) throw (LinuxSamplerException) {      void DeviceCreationParameterStrings::SetValue(String val) throw (Exception) {
875          if (Fix()) throw LinuxSamplerException("Device parameter is read only");          if (Fix()) throw Exception("Device parameter is read only");
876          std::vector<String> vS = __parse_strings(val);          std::vector<String> vS = __parse_strings(val);
877          SetValue(vS);          SetValue(vS);
878      }      }
# Line 878  namespace LinuxSampler { Line 881  namespace LinuxSampler {
881          return sVals;          return sVals;
882      }      }
883    
884      void DeviceCreationParameterStrings::SetValue(std::vector<String> vS) throw (LinuxSamplerException) {      void DeviceCreationParameterStrings::SetValue(std::vector<String> vS) throw (Exception) {
885          if (Fix()) throw LinuxSamplerException("Device parameter is read only");          if (Fix()) throw Exception("Device parameter is read only");
886          OnSetValue(vS);          OnSetValue(vS);
887          sVals = vS;          sVals = vS;
888      }      }

Legend:
Removed from v.486  
changed lines
  Added in v.1296

  ViewVC Help
Powered by ViewVC