/[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 128 by senkov, Tue Jun 15 03:19:30 2004 UTC revision 483 by schoenebeck, Mon Mar 21 23:40:56 2005 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                              *
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 43  namespace LinuxSampler { Line 44  namespace LinuxSampler {
44          return atof(val.c_str()); // TODO: format check is missing          return atof(val.c_str()); // TODO: format check is missing
45      }      }
46    
47        static String __parse_string(String val) {
48            // if string is encapsulated into apostrophes or quotation marks, then remove those apostrophes / quotation marks
49            if (val.size()) {
50                char cBegin = val[0];
51                char cEnd   = val[val.size() - 1];
52                if ( (cBegin == '\'' && cEnd == '\'') || (cBegin == '\"' && cEnd == '\"') ) {
53                    val = val.substr(1, val.size() - 2);
54                }
55            }
56            return val;
57        }
58    
59      static std::vector<String> __parse_strings(String val) throw (LinuxSamplerException) {      static std::vector<String> __parse_strings(String val) throw (LinuxSamplerException) {
60          std::vector<String> vS;          std::vector<String> vS;
61    
62          // if there's only a single value, then we also allow to give it without being encapsulted into apostrophes          // if there's only a single value, then we also allow to give it without being encapsulated into apostrophes
63          if (val.find("\'") == String::npos && val.find("\"") == String::npos) {          if (val.find("\'") == String::npos && val.find("\"") == String::npos) {
64              vS.push_back(val);              vS.push_back(val);
65          }          }
66          else { // if multiple strings or a string encapsulated into apostrophes          else { // if multiple strings or a string encapsulated into apostrophes
67              char* pStart = (char*) val.c_str();              char* pStart = (char*) val.c_str();
68              char* pC     = pStart;              char* pC     = pStart;
             if (*pC != '\'' && *pC != '\"') throw LinuxSamplerException("Invalid form, all individual strings should be encapsulated into apostrophes, separated by commas");  
69    
70              while (true) {              while (true) {
71                    if (*pC != '\'' && *pC != '\"') throw LinuxSamplerException("Invalid form, all individual strings should be encapsulated into apostrophes, separated by commas");
72    
73                  // search for token end                  // search for token end
74                  char* pTokenStart = pC + 1;                  char* pTokenStart = pC + 1;
75                  do {                  do {
# Line 63  namespace LinuxSampler { Line 77  namespace LinuxSampler {
77                      if (*pC == '\0') throw LinuxSamplerException("Invalid form, all individual strings should be encapsulated into apostrophes, separated by commas");                      if (*pC == '\0') throw LinuxSamplerException("Invalid form, all individual strings should be encapsulated into apostrophes, separated by commas");
78                  }                  }
79                  while (*pC != '\'' && *pC != '\"');                  while (*pC != '\'' && *pC != '\"');
80                  vS.push_back(val.substr((int)(pTokenStart - pStart), (int)(pC - pTokenStart))); // we found the token's end                  String token = val.substr((int)(pTokenStart - pStart), (int)(pC - pTokenStart));
81                    vS.push_back(token); // we found the token's end
82    
83                  // 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
84                  if (*(++pC) == '\0') break;                  if (*(++pC) == '\0') break;
85                  if (*pC != ',') throw LinuxSamplerException("Invalid form, all individual strings should be encapsulated into apostrophes, separated by commas");                  if (*pC != ',') throw LinuxSamplerException("Invalid form, all individual strings should be encapsulated into apostrophes, separated by commas");
86                    pC++;
87              }              }
88          }          }
89    
# Line 104  namespace LinuxSampler { Line 120  namespace LinuxSampler {
120      }      }
121    
122      String DeviceRuntimeParameterBool::Value() {      String DeviceRuntimeParameterBool::Value() {
123          return (ValueAsBool()) ? "TRUE" : "FALSE";          return (ValueAsBool()) ? "true" : "false";
124      }      }
125    
126      void DeviceRuntimeParameterBool::SetValue(String val) throw (LinuxSamplerException) {      void DeviceRuntimeParameterBool::SetValue(String val) throw (LinuxSamplerException) {
127          if (Fix()) throw LinuxSamplerException("Device parameter is read only");          if (Fix()) throw LinuxSamplerException("Device parameter is read only");
128          int b = __parse_bool(val);          int b = __parse_bool(val);
         OnSetValue(b);  
129          SetValue(b);          SetValue(b);
130      }      }
131    
# Line 118  namespace LinuxSampler { Line 133  namespace LinuxSampler {
133          return bVal;          return bVal;
134      }      }
135    
136      void DeviceRuntimeParameterBool::SetValue(bool b) {      void DeviceRuntimeParameterBool::SetValue(bool b) throw (LinuxSamplerException) {
137            if (Fix()) throw LinuxSamplerException("Device parameter is read only");
138            OnSetValue(b);
139          bVal = b;          bVal = b;
140      }      }
141    
# Line 188  namespace LinuxSampler { Line 205  namespace LinuxSampler {
205              }              }
206              if (!valid) throw LinuxSamplerException("Invalid device parameter value: not in set of possible values");              if (!valid) throw LinuxSamplerException("Invalid device parameter value: not in set of possible values");
207          }          }
         OnSetValue(i);  
208          SetValue(i);          SetValue(i);
209      }      }
210    
# Line 196  namespace LinuxSampler { Line 212  namespace LinuxSampler {
212          return iVal;          return iVal;
213      }      }
214    
215      void DeviceRuntimeParameterInt::SetValue(int i) {      void DeviceRuntimeParameterInt::SetValue(int i) throw (LinuxSamplerException) {
216            if (Fix()) throw LinuxSamplerException("Device parameter is read only");
217            OnSetValue(i);
218          iVal = i;          iVal = i;
219      }      }
220    
# Line 266  namespace LinuxSampler { Line 284  namespace LinuxSampler {
284              }              }
285              if (!valid) throw LinuxSamplerException("Invalid device parameter value: not in set of possible values");              if (!valid) throw LinuxSamplerException("Invalid device parameter value: not in set of possible values");
286          }          }
         OnSetValue(f);  
287          SetValue(f);          SetValue(f);
288      }      }
289    
# Line 274  namespace LinuxSampler { Line 291  namespace LinuxSampler {
291          return fVal;          return fVal;
292      }      }
293    
294      void DeviceRuntimeParameterFloat::SetValue(float f) {      void DeviceRuntimeParameterFloat::SetValue(float f) throw (LinuxSamplerException) {
295            if (Fix()) throw LinuxSamplerException("Device parameter is read only");
296            OnSetValue(f);
297          fVal = f;          fVal = f;
298      }      }
299    
# Line 318  namespace LinuxSampler { Line 337  namespace LinuxSampler {
337      }      }
338    
339      String DeviceRuntimeParameterString::Value() {      String DeviceRuntimeParameterString::Value() {
340          return sVal;          return "\'" + ValueAsString() + "\'";
341      }      }
342    
343      void DeviceRuntimeParameterString::SetValue(String val) throw (LinuxSamplerException) {      void DeviceRuntimeParameterString::SetValue(String val) throw (LinuxSamplerException) {
344          if (Fix()) throw LinuxSamplerException("Device parameter is read only");          if (Fix()) throw LinuxSamplerException("Device parameter is read only");
345            SetValueAsString(__parse_string(val));
346        }
347    
348        String DeviceRuntimeParameterString::ValueAsString() {
349            return sVal;
350        }
351    
352        void DeviceRuntimeParameterString::SetValueAsString(String val) throw (LinuxSamplerException) {
353            if (Fix()) throw LinuxSamplerException("Device parameter is read only");
354          if (val.find("\'") != String::npos) throw LinuxSamplerException("Character -> \' <- not allowed");          if (val.find("\'") != String::npos) throw LinuxSamplerException("Character -> \' <- not allowed");
355          if (val.find("\"") != String::npos) throw LinuxSamplerException("Character -> \" <- not allowed");          if (val.find("\"") != String::npos) throw LinuxSamplerException("Character -> \" <- not allowed");
356          OnSetValue(val);          OnSetValue(val);
# Line 382  namespace LinuxSampler { Line 410  namespace LinuxSampler {
410      void DeviceRuntimeParameterStrings::SetValue(String val) throw (LinuxSamplerException) {      void DeviceRuntimeParameterStrings::SetValue(String val) throw (LinuxSamplerException) {
411          if (Fix()) throw LinuxSamplerException("Device parameter is read only");          if (Fix()) throw LinuxSamplerException("Device parameter is read only");
412          std::vector<String> vS = __parse_strings(val);          std::vector<String> vS = __parse_strings(val);
         OnSetValue(vS);  
413          SetValue(vS);          SetValue(vS);
414      }      }
415    
# Line 390  namespace LinuxSampler { Line 417  namespace LinuxSampler {
417          return sVals;          return sVals;
418      }      }
419    
420      void DeviceRuntimeParameterStrings::SetValue(std::vector<String> vS) {      void DeviceRuntimeParameterStrings::SetValue(std::vector<String> vS) throw (LinuxSamplerException) {
421            if (Fix()) throw LinuxSamplerException("Device parameter is read only");
422            OnSetValue(vS);
423          sVals = vS;          sVals = vS;
424      }      }
425    
# Line 440  namespace LinuxSampler { Line 469  namespace LinuxSampler {
469  // *************** DeviceCreationParameterBool ***************  // *************** DeviceCreationParameterBool ***************
470  // *  // *
471    
472      DeviceCreationParameterBool::DeviceCreationParameterBool() {      DeviceCreationParameterBool::DeviceCreationParameterBool(bool bVal) : DeviceCreationParameter() {
     }  
   
     DeviceCreationParameterBool::DeviceCreationParameterBool(bool bVal) {  
473          this->bVal = bVal;          this->bVal = bVal;
474      }      }
475    
# Line 468  namespace LinuxSampler { Line 494  namespace LinuxSampler {
494      optional<String> DeviceCreationParameterBool::Default(std::map<String,String> Parameters) {      optional<String> DeviceCreationParameterBool::Default(std::map<String,String> Parameters) {
495          optional<bool> defaultval = DefaultAsBool(Parameters);          optional<bool> defaultval = DefaultAsBool(Parameters);
496          if (!defaultval) return optional<String>::nothing;          if (!defaultval) return optional<String>::nothing;
497          return (*defaultval) ? "TRUE" : "FALSE";          return (*defaultval) ? "true" : "false";
498      }      }
499    
500      optional<String> DeviceCreationParameterBool::RangeMin(std::map<String,String> Parameters) {      optional<String> DeviceCreationParameterBool::RangeMin(std::map<String,String> Parameters) {
# Line 484  namespace LinuxSampler { Line 510  namespace LinuxSampler {
510      }      }
511    
512      String DeviceCreationParameterBool::Value() {      String DeviceCreationParameterBool::Value() {
513          return (ValueAsBool()) ? "TRUE" : "FALSE";          return (ValueAsBool()) ? "true" : "false";
514      }      }
515    
516      void DeviceCreationParameterBool::SetValue(String val) throw (LinuxSamplerException) {      void DeviceCreationParameterBool::SetValue(String val) throw (LinuxSamplerException) {
517          if (Fix()) throw LinuxSamplerException("Device parameter is read only");          if (Fix()) throw LinuxSamplerException("Device parameter is read only");
518          int b = __parse_bool(val);          int b = __parse_bool(val);
         OnSetValue(b);  
519          SetValue(b);          SetValue(b);
520      }      }
521    
# Line 498  namespace LinuxSampler { Line 523  namespace LinuxSampler {
523          return bVal;          return bVal;
524      }      }
525    
526      void DeviceCreationParameterBool::SetValue(bool b) {      void DeviceCreationParameterBool::SetValue(bool b) throw (LinuxSamplerException) {
527            if (Fix()) throw LinuxSamplerException("Device parameter is read only");
528            OnSetValue(b);
529          bVal = b;          bVal = b;
530      }      }
531    
# Line 507  namespace LinuxSampler { Line 534  namespace LinuxSampler {
534  // *************** DeviceCreationParameterInt ***************  // *************** DeviceCreationParameterInt ***************
535  // *  // *
536    
537      DeviceCreationParameterInt::DeviceCreationParameterInt() {      DeviceCreationParameterInt::DeviceCreationParameterInt(int iVal) : DeviceCreationParameter() {
     }  
   
     DeviceCreationParameterInt::DeviceCreationParameterInt(int iVal) {  
538          this->iVal = iVal;          this->iVal = iVal;
539      }      }
540    
# Line 541  namespace LinuxSampler { Line 565  namespace LinuxSampler {
565      optional<String> DeviceCreationParameterInt::RangeMin(std::map<String,String> Parameters) {      optional<String> DeviceCreationParameterInt::RangeMin(std::map<String,String> Parameters) {
566          optional<int> rangemin = RangeMinAsInt(Parameters);          optional<int> rangemin = RangeMinAsInt(Parameters);
567          if (!rangemin) return optional<String>::nothing;          if (!rangemin) return optional<String>::nothing;
568          return ToString(rangemin);          return ToString(*rangemin);
569      }      }
570    
571      optional<String> DeviceCreationParameterInt::RangeMax(std::map<String,String> Parameters) {      optional<String> DeviceCreationParameterInt::RangeMax(std::map<String,String> Parameters) {
572          optional<int> rangemax = RangeMaxAsInt(Parameters);          optional<int> rangemax = RangeMaxAsInt(Parameters);
573          if (!rangemax) return optional<String>::nothing;          if (!rangemax) return optional<String>::nothing;
574          return ToString(rangemax);          return ToString(*rangemax);
575      }      }
576    
577      optional<String> DeviceCreationParameterInt::Possibilities(std::map<String,String> Parameters) {      optional<String> DeviceCreationParameterInt::Possibilities(std::map<String,String> Parameters) {
# Line 586  namespace LinuxSampler { Line 610  namespace LinuxSampler {
610              }              }
611              if (!valid) throw LinuxSamplerException("Invalid Device parameter value: not in set of possible values");              if (!valid) throw LinuxSamplerException("Invalid Device parameter value: not in set of possible values");
612          }*/          }*/
         OnSetValue(i);  
613          SetValue(i);          SetValue(i);
614      }      }
615    
# Line 594  namespace LinuxSampler { Line 617  namespace LinuxSampler {
617          return iVal;          return iVal;
618      }      }
619    
620      void DeviceCreationParameterInt::SetValue(int i) {      void DeviceCreationParameterInt::SetValue(int i) throw (LinuxSamplerException) {
621            if (Fix()) throw LinuxSamplerException("Device parameter is read only");
622            OnSetValue(i);
623          iVal = i;          iVal = i;
624      }      }
625    
# Line 603  namespace LinuxSampler { Line 628  namespace LinuxSampler {
628  // *************** DeviceCreationParameterFloat ***************  // *************** DeviceCreationParameterFloat ***************
629  // *  // *
630    
631      DeviceCreationParameterFloat::DeviceCreationParameterFloat() {      DeviceCreationParameterFloat::DeviceCreationParameterFloat(float fVal) : DeviceCreationParameter() {
     }  
   
     DeviceCreationParameterFloat::DeviceCreationParameterFloat(float fVal) {  
632          this->fVal = fVal;          this->fVal = fVal;
633      }      }
634    
# Line 682  namespace LinuxSampler { Line 704  namespace LinuxSampler {
704              }              }
705              if (!valid) throw LinuxSamplerException("Invalid Device parameter value: not in set of possible values");              if (!valid) throw LinuxSamplerException("Invalid Device parameter value: not in set of possible values");
706          }*/          }*/
         OnSetValue(f);  
707          SetValue(f);          SetValue(f);
708      }      }
709    
# Line 690  namespace LinuxSampler { Line 711  namespace LinuxSampler {
711          return fVal;          return fVal;
712      }      }
713    
714      void DeviceCreationParameterFloat::SetValue(float f) {      void DeviceCreationParameterFloat::SetValue(float f) throw (LinuxSamplerException) {
715            if (Fix()) throw LinuxSamplerException("Device parameter is read only");
716            OnSetValue(f);
717          fVal = f;          fVal = f;
718      }      }
719    
# Line 699  namespace LinuxSampler { Line 722  namespace LinuxSampler {
722  // *************** DeviceCreationParameterString ***************  // *************** DeviceCreationParameterString ***************
723  // *  // *
724    
725      DeviceCreationParameterString::DeviceCreationParameterString() {      DeviceCreationParameterString::DeviceCreationParameterString(String sVal) : DeviceCreationParameter() {
     }  
   
     DeviceCreationParameterString::DeviceCreationParameterString(String sVal) {  
726          this->sVal = sVal;          this->sVal = sVal;
727      }      }
728    
729      void DeviceCreationParameterString::InitWithDefault() {      void DeviceCreationParameterString::InitWithDefault() {
730          std::map<String,String> Parameters; // empty parameters vector          std::map<String,String> Parameters; // empty parameters vector
731          optional<String> defaulval = Default(Parameters);          optional<String> defaulval = DefaultAsString(Parameters);
732          if (defaulval) this->sVal = *defaulval;          if (defaulval) this->sVal = *defaulval;
733          else           this->sVal = "";          else           this->sVal = "";
734      }      }
# Line 721  namespace LinuxSampler { Line 741  namespace LinuxSampler {
741          return false;          return false;
742      }      }
743    
744        optional<String> DeviceCreationParameterString::Default(std::map<String,String> Parameters) {
745            optional<String> defaultval = DefaultAsString(Parameters);
746            if (!defaultval) return optional<String>::nothing;
747            return "'" + *defaultval + "'";
748        }
749    
750      optional<String> DeviceCreationParameterString::RangeMin(std::map<String,String> Parameters) {      optional<String> DeviceCreationParameterString::RangeMin(std::map<String,String> Parameters) {
751          return optional<String>::nothing;          return optional<String>::nothing;
752      }      }
# Line 744  namespace LinuxSampler { Line 770  namespace LinuxSampler {
770      }      }
771    
772      String DeviceCreationParameterString::Value() {      String DeviceCreationParameterString::Value() {
773          return sVal;          return "\'" + ValueAsString() + "\'";
774      }      }
775    
776      void DeviceCreationParameterString::SetValue(String val) throw (LinuxSamplerException) {      void DeviceCreationParameterString::SetValue(String val) throw (LinuxSamplerException) {
777          if (Fix()) throw LinuxSamplerException("Device parameter is read only");          if (Fix()) throw LinuxSamplerException("Device parameter is read only");
778            SetValueAsString(__parse_string(val));
779        }
780    
781        String DeviceCreationParameterString::ValueAsString() {
782            return sVal;
783        }
784    
785        void DeviceCreationParameterString::SetValueAsString(String val) throw (LinuxSamplerException) {
786          if (val.find("\'") != String::npos) throw LinuxSamplerException("Character -> \' <- not allowed");          if (val.find("\'") != String::npos) throw LinuxSamplerException("Character -> \' <- not allowed");
787          if (val.find("\"") != String::npos) throw LinuxSamplerException("Character -> \" <- not allowed");          if (val.find("\"") != String::npos) throw LinuxSamplerException("Character -> \" <- not allowed");
788          OnSetValue(val);          OnSetValue(val);
# Line 760  namespace LinuxSampler { Line 794  namespace LinuxSampler {
794  // *************** DeviceCreationParameterStrings ***************  // *************** DeviceCreationParameterStrings ***************
795  // *  // *
796    
797      DeviceCreationParameterStrings::DeviceCreationParameterStrings() {      DeviceCreationParameterStrings::DeviceCreationParameterStrings(std::vector<String> sVals) : DeviceCreationParameter() {
     }  
   
     DeviceCreationParameterStrings::DeviceCreationParameterStrings(std::vector<String> sVals) {  
798          this->sVals = sVals;          this->sVals = sVals;
799      }      }
800    
# Line 785  namespace LinuxSampler { Line 816  namespace LinuxSampler {
816          return true;          return true;
817      }      }
818    
819        optional<String> DeviceCreationParameterStrings::Default(std::map<String,String> Parameters) {
820            std::vector<String> defaultval = DefaultAsStrings(Parameters);
821            if (defaultval.empty()) return optional<String>::nothing;
822            String result;
823            std::vector<String>::iterator iter = defaultval.begin();
824            for (; iter != defaultval.end(); iter++) {
825                if (result != "") result += ",";
826                result += ("'" + *iter + "'");
827            }
828            return result;
829        }
830    
831      optional<String> DeviceCreationParameterStrings::RangeMin(std::map<String,String> Parameters) {      optional<String> DeviceCreationParameterStrings::RangeMin(std::map<String,String> Parameters) {
832          return optional<String>::nothing;          return optional<String>::nothing;
833      }      }
# Line 821  namespace LinuxSampler { Line 864  namespace LinuxSampler {
864      void DeviceCreationParameterStrings::SetValue(String val) throw (LinuxSamplerException) {      void DeviceCreationParameterStrings::SetValue(String val) throw (LinuxSamplerException) {
865          if (Fix()) throw LinuxSamplerException("Device parameter is read only");          if (Fix()) throw LinuxSamplerException("Device parameter is read only");
866          std::vector<String> vS = __parse_strings(val);          std::vector<String> vS = __parse_strings(val);
         OnSetValue(vS);  
867          SetValue(vS);          SetValue(vS);
868      }      }
869    
# Line 829  namespace LinuxSampler { Line 871  namespace LinuxSampler {
871          return sVals;          return sVals;
872      }      }
873    
874      void DeviceCreationParameterStrings::SetValue(std::vector<String> vS) {      void DeviceCreationParameterStrings::SetValue(std::vector<String> vS) throw (LinuxSamplerException) {
875            if (Fix()) throw LinuxSamplerException("Device parameter is read only");
876            OnSetValue(vS);
877          sVals = vS;          sVals = vS;
878      }      }
879    

Legend:
Removed from v.128  
changed lines
  Added in v.483

  ViewVC Help
Powered by ViewVC