/[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 879 by schoenebeck, Thu Mar 24 23:07:22 2005 UTC revision 880 by schoenebeck, Tue Jun 27 22:57:37 2006 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          // 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
# Line 75  namespace LinuxSampler { Line 75  namespace LinuxSampler {
75              char* pC     = pStart;              char* pC     = pStart;
76    
77              while (true) {              while (true) {
78                  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");
79    
80                  // search for token end                  // search for token end
81                  char* pTokenStart = pC + 1;                  char* pTokenStart = pC + 1;
82                  do {                  do {
83                      pC++;                      pC++;
84                      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");
85                  }                  }
86                  while (*pC != '\'' && *pC != '\"');                  while (*pC != '\'' && *pC != '\"');
87                  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 89  namespace LinuxSampler {
89    
90                  // 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
91                  if (*(++pC) == '\0') break;                  if (*(++pC) == '\0') break;
92                  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");
93                  pC++;                  pC++;
94              }              }
95          }          }
# Line 130  namespace LinuxSampler { Line 130  namespace LinuxSampler {
130          return (ValueAsBool()) ? "true" : "false";          return (ValueAsBool()) ? "true" : "false";
131      }      }
132    
133      void DeviceRuntimeParameterBool::SetValue(String val) throw (LinuxSamplerException) {      void DeviceRuntimeParameterBool::SetValue(String val) throw (Exception) {
134          if (Fix()) throw LinuxSamplerException("Device parameter is read only");          if (Fix()) throw Exception("Device parameter is read only");
135          int b = __parse_bool(val);          int b = __parse_bool(val);
136          SetValue(b);          SetValue(b);
137      }      }
# Line 140  namespace LinuxSampler { Line 140  namespace LinuxSampler {
140          return bVal;          return bVal;
141      }      }
142    
143      void DeviceRuntimeParameterBool::SetValue(bool b) throw (LinuxSamplerException) {      void DeviceRuntimeParameterBool::SetValue(bool b) throw (Exception) {
144          if (Fix()) throw LinuxSamplerException("Device parameter is read only");          if (Fix()) throw Exception("Device parameter is read only");
145          OnSetValue(b);          OnSetValue(b);
146          bVal = b;          bVal = b;
147      }      }
# Line 193  namespace LinuxSampler { Line 193  namespace LinuxSampler {
193          return ToString(ValueAsInt());          return ToString(ValueAsInt());
194      }      }
195    
196      void DeviceRuntimeParameterInt::SetValue(String val) throw (LinuxSamplerException) {      void DeviceRuntimeParameterInt::SetValue(String val) throw (Exception) {
197          if (Fix()) throw LinuxSamplerException("Device parameter is read only");          if (Fix()) throw Exception("Device parameter is read only");
198          int i = __parse_int(val);          int i = __parse_int(val);
199          if (RangeMinAsInt() && i < *RangeMinAsInt()) throw LinuxSamplerException("Invalid device parameter value: too small");          if (RangeMinAsInt() && i < *RangeMinAsInt()) throw Exception("Invalid device parameter value: too small");
200          if (RangeMaxAsInt() && i > *RangeMaxAsInt()) throw LinuxSamplerException("Invalid device parameter value: too big");          if (RangeMaxAsInt() && i > *RangeMaxAsInt()) throw Exception("Invalid device parameter value: too big");
201    
202          std::vector<int> possibilities = PossibilitiesAsInt();          std::vector<int> possibilities = PossibilitiesAsInt();
203          if (possibilities.size()) {          if (possibilities.size()) {
# Line 210  namespace LinuxSampler { Line 210  namespace LinuxSampler {
210                  }                  }
211                  iter++;                  iter++;
212              }              }
213              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");
214          }          }
215          SetValue(i);          SetValue(i);
216      }      }
# Line 219  namespace LinuxSampler { Line 219  namespace LinuxSampler {
219          return iVal;          return iVal;
220      }      }
221    
222      void DeviceRuntimeParameterInt::SetValue(int i) throw (LinuxSamplerException) {      void DeviceRuntimeParameterInt::SetValue(int i) throw (Exception) {
223          if (Fix()) throw LinuxSamplerException("Device parameter is read only");          if (Fix()) throw Exception("Device parameter is read only");
224          OnSetValue(i);          OnSetValue(i);
225          iVal = i;          iVal = i;
226      }      }
# Line 272  namespace LinuxSampler { Line 272  namespace LinuxSampler {
272          return ToString(ValueAsFloat());          return ToString(ValueAsFloat());
273      }      }
274    
275      void DeviceRuntimeParameterFloat::SetValue(String val) throw (LinuxSamplerException) {      void DeviceRuntimeParameterFloat::SetValue(String val) throw (Exception) {
276          if (Fix()) throw LinuxSamplerException("Device parameter is read only");          if (Fix()) throw Exception("Device parameter is read only");
277          float f = __parse_float(val);          float f = __parse_float(val);
278          if (RangeMinAsFloat() && f < *RangeMinAsFloat()) throw LinuxSamplerException("Invalid device parameter value: too small");          if (RangeMinAsFloat() && f < *RangeMinAsFloat()) throw Exception("Invalid device parameter value: too small");
279          if (RangeMaxAsFloat() && f > *RangeMaxAsFloat()) throw LinuxSamplerException("Invalid device parameter value: too big");          if (RangeMaxAsFloat() && f > *RangeMaxAsFloat()) throw Exception("Invalid device parameter value: too big");
280    
281          std::vector<float> possibilities = PossibilitiesAsFloat();          std::vector<float> possibilities = PossibilitiesAsFloat();
282          if (possibilities.size()) {          if (possibilities.size()) {
# Line 289  namespace LinuxSampler { Line 289  namespace LinuxSampler {
289                  }                  }
290                  iter++;                  iter++;
291              }              }
292              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");
293          }          }
294          SetValue(f);          SetValue(f);
295      }      }
# Line 298  namespace LinuxSampler { Line 298  namespace LinuxSampler {
298          return fVal;          return fVal;
299      }      }
300    
301      void DeviceRuntimeParameterFloat::SetValue(float f) throw (LinuxSamplerException) {      void DeviceRuntimeParameterFloat::SetValue(float f) throw (Exception) {
302          if (Fix()) throw LinuxSamplerException("Device parameter is read only");          if (Fix()) throw Exception("Device parameter is read only");
303          OnSetValue(f);          OnSetValue(f);
304          fVal = f;          fVal = f;
305      }      }
# Line 347  namespace LinuxSampler { Line 347  namespace LinuxSampler {
347          return "\'" + ValueAsString() + "\'";          return "\'" + ValueAsString() + "\'";
348      }      }
349    
350      void DeviceRuntimeParameterString::SetValue(String val) throw (LinuxSamplerException) {      void DeviceRuntimeParameterString::SetValue(String val) throw (Exception) {
351          if (Fix()) throw LinuxSamplerException("Device parameter is read only");          if (Fix()) throw Exception("Device parameter is read only");
352          SetValueAsString(__parse_string(val));          SetValueAsString(__parse_string(val));
353      }      }
354    
# Line 356  namespace LinuxSampler { Line 356  namespace LinuxSampler {
356          return sVal;          return sVal;
357      }      }
358    
359      void DeviceRuntimeParameterString::SetValueAsString(String val) throw (LinuxSamplerException) {      void DeviceRuntimeParameterString::SetValueAsString(String val) throw (Exception) {
360          if (Fix()) throw LinuxSamplerException("Device parameter is read only");          if (Fix()) throw Exception("Device parameter is read only");
361          if (val.find("\'") != String::npos) throw LinuxSamplerException("Character -> \' <- not allowed");          if (val.find("\'") != String::npos) throw Exception("Character -> \' <- not allowed");
362          if (val.find("\"") != String::npos) throw LinuxSamplerException("Character -> \" <- not allowed");          if (val.find("\"") != String::npos) throw Exception("Character -> \" <- not allowed");
363          OnSetValue(val);          OnSetValue(val);
364          sVal = val;          sVal = val;
365      }      }
# Line 414  namespace LinuxSampler { Line 414  namespace LinuxSampler {
414          return result;          return result;
415      }      }
416    
417      void DeviceRuntimeParameterStrings::SetValue(String val) throw (LinuxSamplerException) {      void DeviceRuntimeParameterStrings::SetValue(String val) throw (Exception) {
418          if (Fix()) throw LinuxSamplerException("Device parameter is read only");          if (Fix()) throw Exception("Device parameter is read only");
419          std::vector<String> vS = __parse_strings(val);          std::vector<String> vS = __parse_strings(val);
420          SetValue(vS);          SetValue(vS);
421      }      }
# Line 424  namespace LinuxSampler { Line 424  namespace LinuxSampler {
424          return sVals;          return sVals;
425      }      }
426    
427      void DeviceRuntimeParameterStrings::SetValue(std::vector<String> vS) throw (LinuxSamplerException) {      void DeviceRuntimeParameterStrings::SetValue(std::vector<String> vS) throw (Exception) {
428          if (Fix()) throw LinuxSamplerException("Device parameter is read only");          if (Fix()) throw Exception("Device parameter is read only");
429          OnSetValue(vS);          OnSetValue(vS);
430          sVals = vS;          sVals = vS;
431      }      }
# Line 480  namespace LinuxSampler { Line 480  namespace LinuxSampler {
480          this->bVal = bVal;          this->bVal = bVal;
481      }      }
482    
483      DeviceCreationParameterBool::DeviceCreationParameterBool(String val) throw (LinuxSamplerException) {      DeviceCreationParameterBool::DeviceCreationParameterBool(String val) throw (Exception) {
484          this->bVal = __parse_bool(val);          this->bVal = __parse_bool(val);
485      }      }
486    
# Line 520  namespace LinuxSampler { Line 520  namespace LinuxSampler {
520          return (ValueAsBool()) ? "true" : "false";          return (ValueAsBool()) ? "true" : "false";
521      }      }
522    
523      void DeviceCreationParameterBool::SetValue(String val) throw (LinuxSamplerException) {      void DeviceCreationParameterBool::SetValue(String val) throw (Exception) {
524          if (Fix()) throw LinuxSamplerException("Device parameter is read only");          if (Fix()) throw Exception("Device parameter is read only");
525          int b = __parse_bool(val);          int b = __parse_bool(val);
526          SetValue(b);          SetValue(b);
527      }      }
# Line 530  namespace LinuxSampler { Line 530  namespace LinuxSampler {
530          return bVal;          return bVal;
531      }      }
532    
533      void DeviceCreationParameterBool::SetValue(bool b) throw (LinuxSamplerException) {      void DeviceCreationParameterBool::SetValue(bool b) throw (Exception) {
534          if (Fix()) throw LinuxSamplerException("Device parameter is read only");          if (Fix()) throw Exception("Device parameter is read only");
535          OnSetValue(b);          OnSetValue(b);
536          bVal = b;          bVal = b;
537      }      }
# Line 545  namespace LinuxSampler { Line 545  namespace LinuxSampler {
545          this->iVal = iVal;          this->iVal = iVal;
546      }      }
547    
548      DeviceCreationParameterInt::DeviceCreationParameterInt(String val) throw (LinuxSamplerException) {      DeviceCreationParameterInt::DeviceCreationParameterInt(String val) throw (Exception) {
549          this->iVal = __parse_int(val);          this->iVal = __parse_int(val);
550      }      }
551    
# Line 599  namespace LinuxSampler { Line 599  namespace LinuxSampler {
599          return ToString(ValueAsInt());          return ToString(ValueAsInt());
600      }      }
601    
602      void DeviceCreationParameterInt::SetValue(String val) throw (LinuxSamplerException) {      void DeviceCreationParameterInt::SetValue(String val) throw (Exception) {
603          if (Fix()) throw LinuxSamplerException("Device parameter is read only");          if (Fix()) throw Exception("Device parameter is read only");
604          int i = __parse_int(val);          int i = __parse_int(val);
605          //if (RangeMinAsInt() && i < *RangeMinAsInt()) throw LinuxSamplerException("Invalid device parameter value: too small");          //if (RangeMinAsInt() && i < *RangeMinAsInt()) throw Exception("Invalid device parameter value: too small");
606          //if (RangeMaxAsInt() && i > *RangeMaxAsInt()) throw LinuxSamplerException("Invalid device parameter value: too big");          //if (RangeMaxAsInt() && i > *RangeMaxAsInt()) throw Exception("Invalid device parameter value: too big");
607          /*if (PossibilitiesAsInt()) {          /*if (PossibilitiesAsInt()) {
608              bool valid = false;              bool valid = false;
609              std::vector<int>* pPossibilities = PossibilitiesAsInt();              std::vector<int>* pPossibilities = PossibilitiesAsInt();
# Line 615  namespace LinuxSampler { Line 615  namespace LinuxSampler {
615                  }                  }
616                  iter++;                  iter++;
617              }              }
618              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");
619          }*/          }*/
620          SetValue(i);          SetValue(i);
621      }      }
# Line 624  namespace LinuxSampler { Line 624  namespace LinuxSampler {
624          return iVal;          return iVal;
625      }      }
626    
627      void DeviceCreationParameterInt::SetValue(int i) throw (LinuxSamplerException) {      void DeviceCreationParameterInt::SetValue(int i) throw (Exception) {
628          if (Fix()) throw LinuxSamplerException("Device parameter is read only");          if (Fix()) throw Exception("Device parameter is read only");
629          OnSetValue(i);          OnSetValue(i);
630          iVal = i;          iVal = i;
631      }      }
# Line 639  namespace LinuxSampler { Line 639  namespace LinuxSampler {
639          this->fVal = fVal;          this->fVal = fVal;
640      }      }
641    
642      DeviceCreationParameterFloat::DeviceCreationParameterFloat(String val) throw (LinuxSamplerException) {      DeviceCreationParameterFloat::DeviceCreationParameterFloat(String val) throw (Exception) {
643          this->fVal = __parse_float(val);          this->fVal = __parse_float(val);
644      }      }
645    
# Line 693  namespace LinuxSampler { Line 693  namespace LinuxSampler {
693          return ToString(ValueAsFloat());          return ToString(ValueAsFloat());
694      }      }
695    
696      void DeviceCreationParameterFloat::SetValue(String val) throw (LinuxSamplerException) {      void DeviceCreationParameterFloat::SetValue(String val) throw (Exception) {
697          if (Fix()) throw LinuxSamplerException("Device parameter is read only");          if (Fix()) throw Exception("Device parameter is read only");
698          float f = __parse_float(val);          float f = __parse_float(val);
699          //if (RangeMinAsFloat() && i < *RangeMinAsFloat()) throw LinuxSamplerException("Invalid device parameter value: too small");          //if (RangeMinAsFloat() && i < *RangeMinAsFloat()) throw Exception("Invalid device parameter value: too small");
700          //if (RangeMaxAsFloat() && i > *RangeMaxAsFloat()) throw LinuxSamplerException("Invalid device parameter value: too big");          //if (RangeMaxAsFloat() && i > *RangeMaxAsFloat()) throw Exception("Invalid device parameter value: too big");
701          /*if (PossibilitiesAsFloat()) {          /*if (PossibilitiesAsFloat()) {
702              bool valid = false;              bool valid = false;
703              std::vector<float>* pPossibilities = PossibilitiesAsFloat();              std::vector<float>* pPossibilities = PossibilitiesAsFloat();
# Line 709  namespace LinuxSampler { Line 709  namespace LinuxSampler {
709                  }                  }
710                  iter++;                  iter++;
711              }              }
712              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");
713          }*/          }*/
714          SetValue(f);          SetValue(f);
715      }      }
# Line 718  namespace LinuxSampler { Line 718  namespace LinuxSampler {
718          return fVal;          return fVal;
719      }      }
720    
721      void DeviceCreationParameterFloat::SetValue(float f) throw (LinuxSamplerException) {      void DeviceCreationParameterFloat::SetValue(float f) throw (Exception) {
722          if (Fix()) throw LinuxSamplerException("Device parameter is read only");          if (Fix()) throw Exception("Device parameter is read only");
723          OnSetValue(f);          OnSetValue(f);
724          fVal = f;          fVal = f;
725      }      }
# Line 780  namespace LinuxSampler { Line 780  namespace LinuxSampler {
780          return "\'" + ValueAsString() + "\'";          return "\'" + ValueAsString() + "\'";
781      }      }
782    
783      void DeviceCreationParameterString::SetValue(String val) throw (LinuxSamplerException) {      void DeviceCreationParameterString::SetValue(String val) throw (Exception) {
784          if (Fix()) throw LinuxSamplerException("Device parameter is read only");          if (Fix()) throw Exception("Device parameter is read only");
785          SetValueAsString(__parse_string(val));          SetValueAsString(__parse_string(val));
786      }      }
787    
# Line 789  namespace LinuxSampler { Line 789  namespace LinuxSampler {
789          return sVal;          return sVal;
790      }      }
791    
792      void DeviceCreationParameterString::SetValueAsString(String val) throw (LinuxSamplerException) {      void DeviceCreationParameterString::SetValueAsString(String val) throw (Exception) {
793          if (val.find("\'") != String::npos) throw LinuxSamplerException("Character -> \' <- not allowed");          if (val.find("\'") != String::npos) throw Exception("Character -> \' <- not allowed");
794          if (val.find("\"") != String::npos) throw LinuxSamplerException("Character -> \" <- not allowed");          if (val.find("\"") != String::npos) throw Exception("Character -> \" <- not allowed");
795          OnSetValue(val);          OnSetValue(val);
796          sVal = val;          sVal = val;
797      }      }
# Line 805  namespace LinuxSampler { Line 805  namespace LinuxSampler {
805          this->sVals = sVals;          this->sVals = sVals;
806      }      }
807    
808      DeviceCreationParameterStrings::DeviceCreationParameterStrings(String val) throw (LinuxSamplerException) {      DeviceCreationParameterStrings::DeviceCreationParameterStrings(String val) throw (Exception) {
809          this->sVals = __parse_strings(val);          this->sVals = __parse_strings(val);
810      }      }
811    
# Line 868  namespace LinuxSampler { Line 868  namespace LinuxSampler {
868          return result;          return result;
869      }      }
870    
871      void DeviceCreationParameterStrings::SetValue(String val) throw (LinuxSamplerException) {      void DeviceCreationParameterStrings::SetValue(String val) throw (Exception) {
872          if (Fix()) throw LinuxSamplerException("Device parameter is read only");          if (Fix()) throw Exception("Device parameter is read only");
873          std::vector<String> vS = __parse_strings(val);          std::vector<String> vS = __parse_strings(val);
874          SetValue(vS);          SetValue(vS);
875      }      }
# Line 878  namespace LinuxSampler { Line 878  namespace LinuxSampler {
878          return sVals;          return sVals;
879      }      }
880    
881      void DeviceCreationParameterStrings::SetValue(std::vector<String> vS) throw (LinuxSamplerException) {      void DeviceCreationParameterStrings::SetValue(std::vector<String> vS) throw (Exception) {
882          if (Fix()) throw LinuxSamplerException("Device parameter is read only");          if (Fix()) throw Exception("Device parameter is read only");
883          OnSetValue(vS);          OnSetValue(vS);
884          sVals = vS;          sVals = vS;
885      }      }

Legend:
Removed from v.879  
changed lines
  Added in v.880

  ViewVC Help
Powered by ViewVC