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

Contents of /linuxsampler/trunk/src/drivers/DeviceParameter.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 123 - (show annotations) (download) (as text)
Mon Jun 14 19:33:16 2004 UTC (19 years, 9 months ago) by schoenebeck
File MIME type: text/x-c++hdr
File size: 14628 byte(s)
* src/common: added template class 'optional<>' which can be used e.g. as
  return type whenever a value might be returned, but don't has to; this
  template class pretty much acts like a pointer of the given type, but is
  much more safer than a simple pointer
* src/audiodriver: added static class AudioDeviceFactory to create audio
  devices at runtime by using a string and to obtain driver informations
  of drivers at runtime, driver classes should simply use the macro
  REGISTER_AUDIO_OUTPUT_DRIVER(DriverName,DriverClass) in their cpp file
  to register the driver to LinuxSampler (no changes needed anymore in the
  LS code to add a new audio output driver)
* src/drivers: added classes to dynamically manage driver parameters; there
  are two different kinds of parameters: parameters which are need to
  create a new device (DeviceCreationParameterX) used to e.g. create an
  audio output device or a MIDI input device and parameters which are only
  available at runtime, means when a device is already created
  (DeviceRuntimeParameterX) which will be e.g. used as audio channel
  parameters and MIDI port parameters
* src/linuxsampler.cpp: all registered audio output drivers will be shown
  on the console on startup
* src/network: implemented configuration of audio output devices via LSCP

1 /***************************************************************************
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 #ifndef __LS_DEVICE_PARAMETER_H__
24 #define __LS_DEVICE_PARAMETER_H__
25
26 #include <map>
27 #include <vector>
28 #include <sstream>
29
30 #include "../common/global.h"
31 #include "../common/optional.h"
32 #include "../common/LinuxSamplerException.h"
33
34 namespace LinuxSampler {
35
36 // TODO: All plurar parameter classes (except for String) have to be added (namely DeviceRuntimeParameterBools, DeviceRuntimeParameterInts, DeviceRuntimeParameterFloats, DeviceCreationParameterBools, DeviceCreationParameterInts, DeviceCreationParameterFloats), I ignored them for the moment, because they were not that necessary.
37
38 class DeviceRuntimeParameter {
39 public:
40 virtual String Type() = 0;
41 virtual String Description() = 0;
42 virtual bool Fix() = 0;
43 virtual bool Multiplicity() = 0;
44 virtual optional<String> RangeMin() = 0;
45 virtual optional<String> RangeMax() = 0;
46 virtual optional<String> Possibilities() = 0;
47 virtual String Value() = 0;
48 virtual void SetValue(String val) throw (LinuxSamplerException) = 0;
49 };
50
51 class DeviceRuntimeParameterBool : public DeviceRuntimeParameter {
52 public:
53 DeviceRuntimeParameterBool(bool bVal);
54 virtual String Type();
55 virtual bool Multiplicity();
56 virtual optional<String> RangeMin();
57 virtual optional<String> RangeMax();
58 virtual optional<String> Possibilities();
59 virtual String Value();
60 virtual void SetValue(String val) throw (LinuxSamplerException);
61
62 virtual bool ValueAsBool();
63 virtual void SetValue(bool b);
64
65 virtual void OnSetValue(bool b) throw (LinuxSamplerException) = 0;
66 protected:
67 bool bVal;
68 };
69
70 class DeviceRuntimeParameterInt : public DeviceRuntimeParameter {
71 public:
72 DeviceRuntimeParameterInt(int iVal);
73 virtual String Type();
74 virtual bool Multiplicity();
75 virtual optional<String> RangeMin();
76 virtual optional<String> RangeMax();
77 virtual optional<String> Possibilities();
78 virtual String Value();
79 virtual void SetValue(String val) throw (LinuxSamplerException);
80
81 virtual int ValueAsInt();
82 virtual void SetValue(int i);
83
84 virtual optional<int> RangeMinAsInt() = 0;
85 virtual optional<int> RangeMaxAsInt() = 0;
86 virtual std::vector<int> PossibilitiesAsInt() = 0;
87 virtual void OnSetValue(int i) throw (LinuxSamplerException) = 0;
88 protected:
89 int iVal;
90 };
91
92 class DeviceRuntimeParameterFloat : public DeviceRuntimeParameter {
93 public:
94 DeviceRuntimeParameterFloat(float fVal);
95 virtual String Type();
96 virtual bool Multiplicity();
97 virtual optional<String> RangeMin();
98 virtual optional<String> RangeMax();
99 virtual optional<String> Possibilities();
100 virtual String Value();
101 virtual void SetValue(String val) throw (LinuxSamplerException);
102
103 virtual float ValueAsFloat();
104 virtual void SetValue(float f);
105
106 virtual optional<float> RangeMinAsFloat() = 0;
107 virtual optional<float> RangeMaxAsFloat() = 0;
108 virtual std::vector<float> PossibilitiesAsFloat() = 0;
109 virtual void OnSetValue(float f) = 0;
110 protected:
111 float fVal;
112 };
113
114 class DeviceRuntimeParameterString : public DeviceRuntimeParameter {
115 public:
116 DeviceRuntimeParameterString(String sVal);
117 virtual String Type();
118 virtual bool Multiplicity();
119 virtual optional<String> RangeMin();
120 virtual optional<String> RangeMax();
121 virtual optional<String> Possibilities();
122 virtual String Value();
123 virtual void SetValue(String val) throw (LinuxSamplerException);
124
125 virtual std::vector<String> PossibilitiesAsString() = 0;
126 virtual void OnSetValue(String s) = 0;
127 protected:
128 String sVal;
129 };
130
131 class DeviceRuntimeParameterStrings : public DeviceRuntimeParameter {
132 public:
133 DeviceRuntimeParameterStrings(std::vector<String> vS);
134 virtual String Type();
135 virtual bool Multiplicity();
136 virtual optional<String> RangeMin();
137 virtual optional<String> RangeMax();
138 virtual optional<String> Possibilities();
139 virtual String Value();
140 virtual void SetValue(String val) throw (LinuxSamplerException);
141
142 virtual std::vector<String> ValueAsStrings();
143 virtual void SetValue(std::vector<String> vS);
144
145 virtual std::vector<String> PossibilitiesAsString() = 0;
146 virtual void OnSetValue(std::vector<String> vS) = 0;
147 protected:
148 std::vector<String> sVals;
149 };
150
151
152
153 class DeviceCreationParameter : public DeviceRuntimeParameter {
154 public:
155 virtual bool Mandatory() = 0;
156 virtual optional<String> Depends();
157 virtual std::map<String,DeviceCreationParameter*> DependsAsParameters() = 0;
158 virtual optional<String> Default();
159 virtual optional<String> Default(std::map<String,String> Parameters) = 0;
160 virtual optional<String> RangeMin();
161 virtual optional<String> RangeMin(std::map<String,String> Parameters) = 0;
162 virtual optional<String> RangeMax();
163 virtual optional<String> RangeMax(std::map<String,String> Parameters) = 0;
164 virtual optional<String> Possibilities();
165 virtual optional<String> Possibilities(std::map<String,String> Parameters) = 0;
166 };
167
168 class DeviceCreationParameterBool : public DeviceCreationParameter {
169 public:
170 DeviceCreationParameterBool();
171 DeviceCreationParameterBool(bool bVal);
172 DeviceCreationParameterBool(String val) throw (LinuxSamplerException);
173 virtual String Type();
174 virtual bool Multiplicity();
175 virtual optional<String> Default(std::map<String,String> Parameters);
176 virtual optional<String> RangeMin(std::map<String,String> Parameters);
177 virtual optional<String> RangeMax(std::map<String,String> Parameters);
178 virtual optional<String> Possibilities(std::map<String,String> Parameters);
179 virtual String Value();
180 virtual void SetValue(String val) throw (LinuxSamplerException);
181
182 virtual bool ValueAsBool();
183 virtual void SetValue(bool b);
184
185 virtual optional<bool> DefaultAsBool(std::map<String,String> Parameters) = 0;
186 virtual void OnSetValue(bool b) throw (LinuxSamplerException) = 0;
187 protected:
188 bool bVal;
189 private:
190 void InitWithDefault();
191 };
192
193 class DeviceCreationParameterInt : public DeviceCreationParameter {
194 public:
195 DeviceCreationParameterInt();
196 DeviceCreationParameterInt(int iVal);
197 DeviceCreationParameterInt(String val) throw (LinuxSamplerException);
198 virtual String Type();
199 virtual bool Multiplicity();
200 virtual optional<String> Default(std::map<String,String> Parameters);
201 virtual optional<String> RangeMin(std::map<String,String> Parameters);
202 virtual optional<String> RangeMax(std::map<String,String> Parameters);
203 virtual optional<String> Possibilities(std::map<String,String> Parameters);
204 virtual String Value();
205 virtual void SetValue(String val) throw (LinuxSamplerException);
206
207 virtual int ValueAsInt();
208 virtual void SetValue(int i);
209
210 virtual optional<int> DefaultAsInt(std::map<String,String> Parameters) = 0;
211 virtual optional<int> RangeMinAsInt(std::map<String,String> Parameters) = 0;
212 virtual optional<int> RangeMaxAsInt(std::map<String,String> Parameters) = 0;
213 virtual std::vector<int> PossibilitiesAsInt(std::map<String,String> Parameters) = 0;
214 virtual void OnSetValue(int i) throw (LinuxSamplerException) = 0;
215 protected:
216 int iVal;
217 private:
218 void InitWithDefault();
219 };
220
221 class DeviceCreationParameterFloat : public DeviceCreationParameter {
222 public:
223 DeviceCreationParameterFloat();
224 DeviceCreationParameterFloat(float fVal);
225 DeviceCreationParameterFloat(String val) throw (LinuxSamplerException);
226 virtual String Type();
227 virtual bool Multiplicity();
228 virtual optional<String> Default(std::map<String,String> Parameters);
229 virtual optional<String> RangeMin(std::map<String,String> Parameters);
230 virtual optional<String> RangeMax(std::map<String,String> Parameters);
231 virtual optional<String> Possibilities(std::map<String,String> Parameters);
232 virtual String Value();
233 virtual void SetValue(String val) throw (LinuxSamplerException);
234
235 virtual float ValueAsFloat();
236 virtual void SetValue(float f);
237
238 virtual optional<float> DefaultAsFloat(std::map<String,String> Parameters) = 0;
239 virtual optional<float> RangeMinAsFloat(std::map<String,String> Parameters) = 0;
240 virtual optional<float> RangeMaxAsFloat(std::map<String,String> Parameters) = 0;
241 virtual std::vector<float> PossibilitiesAsFloat(std::map<String,String> Parameters) = 0;
242 virtual void OnSetValue(float f) throw (LinuxSamplerException) = 0;
243 protected:
244 float fVal;
245 private:
246 void InitWithDefault();
247 };
248
249 class DeviceCreationParameterString : public DeviceCreationParameter {
250 public:
251 DeviceCreationParameterString();
252 DeviceCreationParameterString(String sVal);
253 virtual String Type();
254 virtual bool Multiplicity();
255 virtual optional<String> RangeMin(std::map<String,String> Parameters);
256 virtual optional<String> RangeMax(std::map<String,String> Parameters);
257 virtual optional<String> Possibilities(std::map<String,String> Parameters);
258 virtual String Value();
259 virtual void SetValue(String val) throw (LinuxSamplerException);
260
261 virtual std::vector<String> PossibilitiesAsString(std::map<String,String> Parameters) = 0;
262 virtual void OnSetValue(String s) throw (LinuxSamplerException) = 0;
263 protected:
264 String sVal;
265 private:
266 void InitWithDefault();
267 };
268
269 class DeviceCreationParameterStrings : public DeviceCreationParameter {
270 public:
271 DeviceCreationParameterStrings();
272 DeviceCreationParameterStrings(std::vector<String> sVals);
273 DeviceCreationParameterStrings(String val) throw (LinuxSamplerException);
274 virtual String Type();
275 virtual bool Multiplicity();
276 virtual optional<String> RangeMin(std::map<String,String> Parameters);
277 virtual optional<String> RangeMax(std::map<String,String> Parameters);
278 virtual optional<String> Possibilities(std::map<String,String> Parameters);
279 virtual String Value();
280 virtual void SetValue(String val) throw (LinuxSamplerException);
281
282 virtual std::vector<String> ValueAsStrings();
283 virtual void SetValue(std::vector<String> vS);
284
285 virtual optional<std::vector<String> > DefaultAsStrings(std::map<String,String> Parameters) = 0;
286 virtual std::vector<String> PossibilitiesAsString(std::map<String,String> Parameters) = 0;
287 virtual void OnSetValue(std::vector<String> vS) throw (LinuxSamplerException) = 0;
288 protected:
289 std::vector<String> sVals;
290 private:
291 void InitWithDefault();
292 };
293
294 template <class T>
295 inline String ToString(T o) {
296 std::stringstream ss;
297 ss << o;
298 return ss.str();
299 }
300
301 } // namespace LinuxSampler
302
303 #endif // __LS_DEVICE_PARAMETER_H__

  ViewVC Help
Powered by ViewVC