1 |
/*************************************************************************** |
2 |
* * |
3 |
* LinuxSampler - modular, streaming capable sampler * |
4 |
* * |
5 |
* Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck * |
6 |
* Copyright (C) 2005 - 2013 Christian Schoenebeck * |
7 |
* * |
8 |
* 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 * |
10 |
* the Free Software Foundation; either version 2 of the License, or * |
11 |
* (at your option) any later version. * |
12 |
* * |
13 |
* This program is distributed in the hope that it will be useful, * |
14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of * |
15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
16 |
* GNU General Public License for more details. * |
17 |
* * |
18 |
* You should have received a copy of the GNU General Public License * |
19 |
* along with this program; if not, write to the Free Software * |
20 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, * |
21 |
* MA 02111-1307 USA * |
22 |
***************************************************************************/ |
23 |
|
24 |
#ifndef __LS_DEVICE_PARAMETER_H__ |
25 |
#define __LS_DEVICE_PARAMETER_H__ |
26 |
|
27 |
#include <map> |
28 |
#include <vector> |
29 |
|
30 |
#include "../common/global.h" |
31 |
#include "../common/optional.h" |
32 |
#include "../common/Exception.h" |
33 |
#include "Device.h" |
34 |
|
35 |
namespace LinuxSampler { |
36 |
|
37 |
///////////////////////////////////////////////////////////////// |
38 |
// "Runtime" parameters |
39 |
|
40 |
// 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. |
41 |
|
42 |
/** @brief Abstracet base class for all driver parameters of the sampler. |
43 |
* |
44 |
* All audio / MIDI drivers for the sampler are using dynamic driver |
45 |
* parameters based on this base class. The main purpose behind this |
46 |
* concept is to be able to write GUI frontends for the sampler, which |
47 |
* don't need to know about specific drivers the sampler provides, nor the |
48 |
* exact list of parameters those drivers offer. Instead a frontend can |
49 |
* use this API to retrieve what kind of parameters the respective |
50 |
* available drivers offer at runtime. This way new drivers can be added |
51 |
* or existing ones being changed arbitrarily to the sampler at any time, |
52 |
* without a GUI frontend to be changed or recompiled. |
53 |
* |
54 |
* There are various parameter classes deriving from this base class, which |
55 |
* implement convenient handling for the various common value types like |
56 |
* bool, int, float, String. A driver would rather use one of those |
57 |
* type specialized classes, instead of this abstract base class. Because |
58 |
* the methods of this very base parameter class here are generalized being |
59 |
* encoded in String type for all parameter types. |
60 |
* |
61 |
* Besides that, there are 2 distinct sets of parameter types: |
62 |
* - "Runtime" parameters which can be set and changed by the user (i.e. |
63 |
* with a GUI frontend) at any time. |
64 |
* - "Creation" parameters which can only be set by the user before a |
65 |
* driver is instantiated (a driver instance is called a "device" in |
66 |
* the sampler's terms). After the driver is instantiated, "creation" |
67 |
* parameters are read only for the life time of a driver (device) |
68 |
* instance. Typical example for a "creation" parameter would be an |
69 |
* audio driver that allows to select a specific sound card. |
70 |
* |
71 |
* @see DeviceCreationParameter |
72 |
*/ |
73 |
class DeviceRuntimeParameter { |
74 |
public: |
75 |
/** |
76 |
* Some name reflecting the parameter's value type, like "BOOL, |
77 |
* "INT", "FLOAT", "STRING", "STRINGS". Upon the value returned |
78 |
* here, the object can be casted to the respective implementing |
79 |
* parameter class. |
80 |
*/ |
81 |
virtual String Type() = 0; |
82 |
|
83 |
/** |
84 |
* A human readable description, explaining the exact purpose of |
85 |
* the driver parameter. The text returned here can be used to |
86 |
* display the user in a GUI frontend some helping text, that |
87 |
* explains what the parameter actually does. |
88 |
*/ |
89 |
virtual String Description() = 0; |
90 |
|
91 |
/** |
92 |
* Whether the parameter is read only. Not to be confused with |
93 |
* "creation" parameters! A driver parameter which returns true |
94 |
* here can never be set or altered at any time. Not even at |
95 |
* instanciation time of the driver! A typical example would be |
96 |
* a parameter "SAMPLERATE" for a specific sound card, where the |
97 |
* specific sound card does not allow to switch the sound card's |
98 |
* sample rate in any way. Yet the value returned by the parameter |
99 |
* (read only) might be different, depending on the actual sound |
100 |
* card the user selected with the audio driver. |
101 |
*/ |
102 |
virtual bool Fix() = 0; |
103 |
|
104 |
/** |
105 |
* Whether the parameter only allows to set one scalar value, or |
106 |
* if @c true is returned here, the parameter allows to manage a |
107 |
* list of values instead. A typical example of multiplicity |
108 |
* parameter is i.e. a "ROUTING" parameter, that would allow a |
109 |
* user to interconnect the sampler with other apps and devices |
110 |
* with drivers that support such concepts (like JACK and ALSA MIDI |
111 |
* do). |
112 |
*/ |
113 |
virtual bool Multiplicity() = 0; |
114 |
|
115 |
/** |
116 |
* The driver parameter might (optionally) return a minimum value |
117 |
* for the parameter. If some actual value is returned here, the |
118 |
* sampler automatically performs bounds checking of parameter |
119 |
* values to be set for such a parameter and a GUI frontend might |
120 |
* display a spin box in such a case to the user, honoring the |
121 |
* returned minimum value. |
122 |
* |
123 |
* You probably don't want to call this method directly, but instead |
124 |
* cast this object to the respective deriving parameter class like |
125 |
* DeviceRuntimeParameterInt, and use its RangeMinAsInt() method |
126 |
* instead, which conveniently returns a value in its value type. |
127 |
* So you don't need to parse this return value here. |
128 |
*/ |
129 |
virtual optional<String> RangeMin() = 0; |
130 |
|
131 |
/** |
132 |
* The driver parameter might (optionally) return a maximum value |
133 |
* for the parameter. If some actual value is returned here, the |
134 |
* sampler automatically performs bounds checking of parameter |
135 |
* values to be set for such a parameter and a GUI frontend might |
136 |
* display a spin box in such a case to the user, honoring the |
137 |
* returned maximum value. |
138 |
* |
139 |
* You probably don't want to call this method directly, but instead |
140 |
* cast this object to the respective deriving parameter class like |
141 |
* DeviceRuntimeParameterInt, and use its RangeMaxAsInt() method |
142 |
* instead, which conveniently returns a value in its value type. |
143 |
* So you don't need to parse this return value here. |
144 |
*/ |
145 |
virtual optional<String> RangeMax() = 0; |
146 |
|
147 |
/** |
148 |
* The driver parameter might (optionally) return a list of |
149 |
* possible values for this parameter, encoded as comma separated |
150 |
* list. For example an audio driver might return "44100,96000" for |
151 |
* a "SAMPLERATE" parameter for a specific sound card. |
152 |
* |
153 |
* You probably don't want to call this method directly, but instead |
154 |
* cast this object to the respective deriving parameter class like |
155 |
* DeviceRuntimeParameterInt, and use its PossibilitiesAsInt() method |
156 |
* instead, which conveniently returns a vector in its value type. |
157 |
* So you don't need to parse this return value here. |
158 |
*/ |
159 |
virtual optional<String> Possibilities() = 0; |
160 |
|
161 |
/** |
162 |
* The current value of this parameter (encoded as String). |
163 |
* You might want to cast to the respective deriving parameter |
164 |
* class like DeviceRuntimeParameterInt and use its method |
165 |
* ValueAsInt() for not being forced to parse the String here. |
166 |
*/ |
167 |
virtual String Value() = 0; |
168 |
|
169 |
/** |
170 |
* Alter the parameter with the value given by @a val. The |
171 |
* respective deriving parameter class automatically parses the |
172 |
* String value supplied here, and converts it into its native |
173 |
* value type like int, float or String vector ("Strings"). |
174 |
* |
175 |
* @param - new parameter value encoded as string |
176 |
* @throws Exception - if @a val is out of bounds, not encoded |
177 |
* correctly in its string representation or |
178 |
* any other reason the driver might not want |
179 |
* to accept the given value. |
180 |
*/ |
181 |
virtual void SetValue(String val) throw (Exception) = 0; |
182 |
|
183 |
/** @brief Destructor. |
184 |
* |
185 |
* Virtual base destructor which enforces that all destructors of |
186 |
* all deriving classes are called automatically upon object |
187 |
* destruction. |
188 |
*/ |
189 |
virtual ~DeviceRuntimeParameter(){}; |
190 |
}; |
191 |
|
192 |
/** @brief Abstract base class for driver parameters of type @c bool. |
193 |
* |
194 |
* Implements a "runtime" driver parameter for value type @c bool. |
195 |
* A driver offering a parameter of type @c bool would derive its |
196 |
* parameter class from this class and implement the abstract method |
197 |
* OnSetValue() to react on a parameter value being set. |
198 |
* |
199 |
* See DeviceCreationParameter and DeviceRuntimeParameter for a discussion |
200 |
* about "runtime" parameters vs. "creation" parameters. |
201 |
* |
202 |
* @see DeviceCreationParameterBool |
203 |
*/ |
204 |
class DeviceRuntimeParameterBool : public DeviceRuntimeParameter { |
205 |
public: |
206 |
/** @brief Constructor for value type @c bool. |
207 |
* |
208 |
* Sets an initial value for the parameter. |
209 |
* |
210 |
* @param bVal - initial boolean value |
211 |
*/ |
212 |
DeviceRuntimeParameterBool(bool bVal); |
213 |
|
214 |
///////////////////////////////////////////////////////////////// |
215 |
// derived methods, implementing type "BOOL" |
216 |
// (usually not to be overriden by descendant) |
217 |
|
218 |
virtual String Type() OVERRIDE; |
219 |
virtual bool Multiplicity() OVERRIDE; |
220 |
virtual optional<String> RangeMin() OVERRIDE; |
221 |
virtual optional<String> RangeMax() OVERRIDE; |
222 |
virtual optional<String> Possibilities() OVERRIDE; |
223 |
virtual String Value() OVERRIDE; |
224 |
virtual void SetValue(String val) throw (Exception) OVERRIDE; |
225 |
|
226 |
///////////////////////////////////////////////////////////////// |
227 |
// convenience methods for type "BOOL" |
228 |
// (usually not to be overriden by descendant) |
229 |
|
230 |
virtual bool ValueAsBool(); |
231 |
virtual void SetValue(bool b) throw (Exception); |
232 |
|
233 |
///////////////////////////////////////////////////////////////// |
234 |
// abstract methods |
235 |
// (these have to be implemented by the descendant) |
236 |
|
237 |
/** |
238 |
* Must be implemented be a driver's parameter class to react on |
239 |
* the parameter value being set / altered. |
240 |
* |
241 |
* @param b - new parameter value set by the user |
242 |
* @throws Exception - might be thrown by the driver in case it |
243 |
* cannot handle the supplied parameter value |
244 |
* for whatever reason |
245 |
*/ |
246 |
virtual void OnSetValue(bool b) throw (Exception) = 0; |
247 |
protected: |
248 |
bool bVal; |
249 |
}; |
250 |
|
251 |
/** @brief Abstract base class for driver parameters of type @c int. |
252 |
* |
253 |
* Implements a "runtime" driver parameter for value type @c int. |
254 |
* A driver offering a parameter of type @c int would derive its |
255 |
* parameter class from this class and implement the abstract methods |
256 |
* OnSetValue(), RangeMinAsInt(), RangeMaxAsInt(), PossibilitiesAsInt(). |
257 |
* |
258 |
* See DeviceCreationParameter and DeviceRuntimeParameter for a discussion |
259 |
* about "runtime" parameters vs. "creation" parameters. |
260 |
* |
261 |
* @see DeviceCreationParameterInt |
262 |
*/ |
263 |
class DeviceRuntimeParameterInt : public DeviceRuntimeParameter { |
264 |
public: |
265 |
/** @brief Constructor for value type @c int. |
266 |
* |
267 |
* Sets an initial value for the parameter. |
268 |
* |
269 |
* @param iVal - initial integer value |
270 |
*/ |
271 |
DeviceRuntimeParameterInt(int iVal); |
272 |
|
273 |
///////////////////////////////////////////////////////////////// |
274 |
// derived methods, implementing type "INT" |
275 |
// (usually not to be overriden by descendant) |
276 |
|
277 |
virtual String Type() OVERRIDE; |
278 |
virtual bool Multiplicity() OVERRIDE; |
279 |
virtual optional<String> RangeMin() OVERRIDE; |
280 |
virtual optional<String> RangeMax() OVERRIDE; |
281 |
virtual optional<String> Possibilities() OVERRIDE; |
282 |
virtual String Value() OVERRIDE; |
283 |
virtual void SetValue(String val) throw (Exception) OVERRIDE; |
284 |
|
285 |
///////////////////////////////////////////////////////////////// |
286 |
// convenience methods for type "INT" |
287 |
// (usually not to be overriden by descendant) |
288 |
|
289 |
virtual int ValueAsInt(); |
290 |
virtual void SetValue(int i) throw (Exception); |
291 |
|
292 |
///////////////////////////////////////////////////////////////// |
293 |
// abstract methods |
294 |
// (these have to be implemented by the descendant) |
295 |
|
296 |
/** |
297 |
* Must be implemented by descendant, returning a minimum int value |
298 |
* for the parameter. If a minimum value does not make sense for |
299 |
* the specific driver parameter, then the implementation should |
300 |
* return @c optional<int>::nothing. |
301 |
*/ |
302 |
virtual optional<int> RangeMinAsInt() = 0; |
303 |
|
304 |
/** |
305 |
* Must be implemented by descendant, returning a maximum int value |
306 |
* for the parameter. If a maximum value does not make sense for |
307 |
* the specific driver parameter, then the implementation should |
308 |
* return @c optional<int>::nothing. |
309 |
*/ |
310 |
virtual optional<int> RangeMaxAsInt() = 0; |
311 |
|
312 |
/** |
313 |
* Must be implemented by descendant, returning a list of possible |
314 |
* int values for the parameter. If a list of possible values does |
315 |
* not make sense, the implementation should return an empty |
316 |
* vector. |
317 |
*/ |
318 |
virtual std::vector<int> PossibilitiesAsInt() = 0; |
319 |
|
320 |
/** |
321 |
* Must be implemented be a driver's parameter class to react on |
322 |
* the parameter value being set / altered. |
323 |
* |
324 |
* @param i - new parameter value set by the user |
325 |
* @throws Exception - might be thrown by the driver in case it |
326 |
* cannot handle the supplied parameter value |
327 |
* for whatever reason |
328 |
*/ |
329 |
virtual void OnSetValue(int i) throw (Exception) = 0; |
330 |
protected: |
331 |
int iVal; |
332 |
}; |
333 |
|
334 |
/** @brief Abstract base class for driver parameters of type @c float. |
335 |
* |
336 |
* Implements a "runtime" driver parameter for value type @c float. |
337 |
* A driver offering a parameter of type @c float would derive its |
338 |
* parameter class from this class and implement the abstract methods |
339 |
* OnSetValue(), RangeMinAsFloat(), RangeMaxAsFloat() and |
340 |
* PossibilitiesAsFloat(). |
341 |
* |
342 |
* See DeviceCreationParameter and DeviceRuntimeParameter for a discussion |
343 |
* about "runtime" parameters vs. "creation" parameters. |
344 |
* |
345 |
* @see DeviceCreationParameterFloat |
346 |
*/ |
347 |
class DeviceRuntimeParameterFloat : public DeviceRuntimeParameter { |
348 |
public: |
349 |
/** @brief Constructor for value type @c float. |
350 |
* |
351 |
* Sets an initial value for the parameter. |
352 |
* |
353 |
* @param fVal - initial float value |
354 |
*/ |
355 |
DeviceRuntimeParameterFloat(float fVal); |
356 |
|
357 |
///////////////////////////////////////////////////////////////// |
358 |
// derived methods, implementing type "FLOAT" |
359 |
// (usually not to be overriden by descendant) |
360 |
|
361 |
virtual String Type() OVERRIDE; |
362 |
virtual bool Multiplicity() OVERRIDE; |
363 |
virtual optional<String> RangeMin() OVERRIDE; |
364 |
virtual optional<String> RangeMax() OVERRIDE; |
365 |
virtual optional<String> Possibilities() OVERRIDE; |
366 |
virtual String Value() OVERRIDE; |
367 |
virtual void SetValue(String val) throw (Exception) OVERRIDE; |
368 |
|
369 |
///////////////////////////////////////////////////////////////// |
370 |
// convenience methods for type "FLOAT" |
371 |
// (usually not to be overriden by descendant) |
372 |
|
373 |
virtual float ValueAsFloat(); |
374 |
virtual void SetValue(float f) throw (Exception); |
375 |
|
376 |
///////////////////////////////////////////////////////////////// |
377 |
// abstract methods |
378 |
// (these have to be implemented by the descendant) |
379 |
|
380 |
/** |
381 |
* Must be implemented by descendant, returning a minimum float |
382 |
* value for the parameter. If a minimum value does not make sense |
383 |
* for the specific driver parameter, then the implementation |
384 |
* should return @c optional<float>::nothing. |
385 |
*/ |
386 |
virtual optional<float> RangeMinAsFloat() = 0; |
387 |
|
388 |
/** |
389 |
* Must be implemented by descendant, returning a maximum float |
390 |
* value for the parameter. If a maximum value does not make sense |
391 |
* for the specific driver parameter, then the implementation |
392 |
* should return @c optional<float>::nothing. |
393 |
*/ |
394 |
virtual optional<float> RangeMaxAsFloat() = 0; |
395 |
|
396 |
/** |
397 |
* Must be implemented by descendant, returning a list of possible |
398 |
* float values for the parameter. If a list of possible values |
399 |
* does not make sense, the implementation should return an empty |
400 |
* vector. |
401 |
*/ |
402 |
virtual std::vector<float> PossibilitiesAsFloat() = 0; |
403 |
|
404 |
/** |
405 |
* Must be implemented be a driver's parameter class to react on |
406 |
* the parameter value being set / altered. |
407 |
* |
408 |
* @param f - new parameter value set by the user |
409 |
* @throws Exception - might be thrown by the driver in case it |
410 |
* cannot handle the supplied parameter value |
411 |
* for whatever reason |
412 |
*/ |
413 |
virtual void OnSetValue(float f) = 0; |
414 |
protected: |
415 |
float fVal; |
416 |
}; |
417 |
|
418 |
/** @brief Abstract base class for driver parameters of type @c String. |
419 |
* |
420 |
* Implements a "runtime" driver parameter for value type @c String. |
421 |
* A driver offering a parameter of type @c String would derive its |
422 |
* parameter class from this class and implement the abstract methods |
423 |
* OnSetValue() and PossibilitiesAsString(). |
424 |
* |
425 |
* See DeviceCreationParameter and DeviceRuntimeParameter for a discussion |
426 |
* about "runtime" parameters vs. "creation" parameters. |
427 |
* |
428 |
* @see DeviceCreationParameterString |
429 |
*/ |
430 |
class DeviceRuntimeParameterString : public DeviceRuntimeParameter { |
431 |
public: |
432 |
/** @brief Constructor for value type @c String. |
433 |
* |
434 |
* Sets an initial value for the parameter. |
435 |
* |
436 |
* @param sVal - initial String value |
437 |
*/ |
438 |
DeviceRuntimeParameterString(String sVal); |
439 |
|
440 |
/// @brief Destructor. |
441 |
virtual ~DeviceRuntimeParameterString(){} |
442 |
|
443 |
///////////////////////////////////////////////////////////////// |
444 |
// derived methods, implementing type "STRING" |
445 |
// (usually not to be overriden by descendant) |
446 |
|
447 |
virtual String Type() OVERRIDE; |
448 |
virtual bool Multiplicity() OVERRIDE; |
449 |
virtual optional<String> RangeMin() OVERRIDE; |
450 |
virtual optional<String> RangeMax() OVERRIDE; |
451 |
virtual optional<String> Possibilities() OVERRIDE; |
452 |
virtual String Value() OVERRIDE; |
453 |
virtual void SetValue(String val) throw (Exception) OVERRIDE; |
454 |
|
455 |
///////////////////////////////////////////////////////////////// |
456 |
// convenience methods for type "STRING" |
457 |
// (usually not to be overriden by descendant) |
458 |
|
459 |
virtual String ValueAsString(); |
460 |
virtual void SetValueAsString(String s) throw (Exception); |
461 |
|
462 |
///////////////////////////////////////////////////////////////// |
463 |
// abstract methods |
464 |
// (these have to be implemented by the descendant) |
465 |
|
466 |
/** |
467 |
* Must be implemented by descendant, returning a list of possible |
468 |
* String values for the parameter. If a list of possible values |
469 |
* does not make sense, the implementation should return an empty |
470 |
* vector. |
471 |
*/ |
472 |
virtual std::vector<String> PossibilitiesAsString() = 0; |
473 |
|
474 |
/** |
475 |
* Must be implemented be a driver's parameter class to react on |
476 |
* the parameter value being set / altered. |
477 |
* |
478 |
* @param s - new parameter value set by the user |
479 |
* @throws Exception - might be thrown by the driver in case it |
480 |
* cannot handle the supplied parameter value |
481 |
* for whatever reason |
482 |
*/ |
483 |
virtual void OnSetValue(String s) = 0; |
484 |
protected: |
485 |
String sVal; |
486 |
}; |
487 |
|
488 |
/** @brief Abstract base class for driver parameters of a @c String list type. |
489 |
* |
490 |
* Implements a "runtime" driver parameter for multiple values of type |
491 |
* @c String. A driver offering a parameter of a @c String list type would |
492 |
* derive its parameter class from this class and implement the abstract |
493 |
* methods OnSetValue() and PossibilitiesAsString(). |
494 |
* |
495 |
* See DeviceCreationParameter and DeviceRuntimeParameter for a discussion |
496 |
* about "runtime" parameters vs. "creation" parameters. |
497 |
* |
498 |
* @see DeviceCreationParameterStrings |
499 |
*/ |
500 |
class DeviceRuntimeParameterStrings : public DeviceRuntimeParameter { |
501 |
public: |
502 |
/** @brief Constructor for value type @c String. |
503 |
* |
504 |
* Sets an initial list of values for the parameter. |
505 |
* |
506 |
* @param sVal - initial String value |
507 |
*/ |
508 |
DeviceRuntimeParameterStrings(std::vector<String> vS); |
509 |
|
510 |
/// @brief Destructor. |
511 |
virtual ~DeviceRuntimeParameterStrings(){} |
512 |
|
513 |
///////////////////////////////////////////////////////////////// |
514 |
// derived methods, implementing type "STRINGS" |
515 |
// (usually not to be overriden by descendant) |
516 |
|
517 |
virtual String Type() OVERRIDE; |
518 |
virtual bool Multiplicity() OVERRIDE; |
519 |
virtual optional<String> RangeMin() OVERRIDE; |
520 |
virtual optional<String> RangeMax() OVERRIDE; |
521 |
virtual optional<String> Possibilities() OVERRIDE; |
522 |
virtual String Value() OVERRIDE; |
523 |
virtual void SetValue(String val) throw (Exception) OVERRIDE; |
524 |
|
525 |
///////////////////////////////////////////////////////////////// |
526 |
// convenience methods for type "STRINGS" |
527 |
// (usually not to be overriden by descendant) |
528 |
|
529 |
virtual std::vector<String> ValueAsStrings(); |
530 |
virtual void SetValue(std::vector<String> vS) throw (Exception); |
531 |
|
532 |
///////////////////////////////////////////////////////////////// |
533 |
// abstract methods |
534 |
// (these have to be implemented by the descendant) |
535 |
|
536 |
/** |
537 |
* Must be implemented by descendant, returning a list of possible |
538 |
* String values for the parameter. If a list of possible values |
539 |
* does not make sense, the implementation should return an empty |
540 |
* vector. |
541 |
*/ |
542 |
virtual std::vector<String> PossibilitiesAsString() = 0; |
543 |
|
544 |
/** |
545 |
* Must be implemented be a driver's parameter class to react on |
546 |
* the parameter value being set / altered. |
547 |
* |
548 |
* @param vS - new parameter values set by the user |
549 |
* @throws Exception - might be thrown by the driver in case it |
550 |
* cannot handle the supplied parameter values |
551 |
* for whatever reason |
552 |
*/ |
553 |
virtual void OnSetValue(std::vector<String> vS) = 0; |
554 |
protected: |
555 |
std::vector<String> sVals; |
556 |
}; |
557 |
|
558 |
|
559 |
///////////////////////////////////////////////////////////////// |
560 |
// "Creation" parameters |
561 |
|
562 |
/** @brief Abstract base class for parameters at driver instanciation time. |
563 |
* |
564 |
* Device "creation" parameters are special parameters, that are meant to be only |
565 |
* set when a device (driver instance) is created. After device creation those |
566 |
* parameters act as read only parameters. See DeviceRuntimeParameter for a |
567 |
* discussion about this topic. |
568 |
* |
569 |
* In addition to "runtime" parameters, "creation" parameters also handle |
570 |
* additional meta informations required in the specific situations of |
571 |
* creating a device (driver instance). For example "creation" parameters |
572 |
* might indicate whether they MUST be provided explicitly |
573 |
* ( @c Mandatory() ) by the user (i.e. a parameter "CARD" selecting a |
574 |
* specific sound card) for being able to create an instance of the driver. |
575 |
* And "creation" parameters might indicate being dependent to other |
576 |
* parameters, i.e. a parameter "SAMPLERATE" might depend on a parameter |
577 |
* "CARD", to be able to actually provide a list of meaningful |
578 |
* possibilities for sample rates the respective sound card supports. |
579 |
*/ |
580 |
class DeviceCreationParameter : public DeviceRuntimeParameter { |
581 |
public: |
582 |
/// @brief Constructor. |
583 |
DeviceCreationParameter ( void ) { pDevice = NULL; } |
584 |
|
585 |
/** |
586 |
* Whether the parameter must be supplied by the user at device |
587 |
* creation time. If this method return @c false, then the |
588 |
* parameter is optional |
589 |
*/ |
590 |
virtual bool Mandatory() = 0; |
591 |
|
592 |
/** |
593 |
* Might return a comma separated list of parameter names this |
594 |
* parameter depends on. See this class's introduction about a |
595 |
* discussion of parameters with dependencies. If this method |
596 |
* returns @c optional<String>::nothing, then it does not have any |
597 |
* dependencies to other parameters. |
598 |
* |
599 |
* This method already provides an implementation, which usually is |
600 |
* not overridden by descendants. A descendant would rather |
601 |
* implement DependsAsParameters() instead. |
602 |
* |
603 |
* @see DependsAsParameters() |
604 |
*/ |
605 |
virtual optional<String> Depends(); |
606 |
|
607 |
/** |
608 |
* Might return a unique key-value pair list (map) reflecting the |
609 |
* dependencies of this parameter to other parameters. Each entry |
610 |
* in the map consists of a key-value pair, the key being the |
611 |
* parameter name of the respective dependent parameter, and the |
612 |
* value being an instance of the dependency parameter of that name. |
613 |
* |
614 |
* A descendant MUST implement this method, informing about its |
615 |
* dependencies. If the parameter does not have any dependencies it |
616 |
* should return an empty map. |
617 |
* |
618 |
* See this class's introduction about a discussion of parameters |
619 |
* with dependencies. |
620 |
*/ |
621 |
virtual std::map<String,DeviceCreationParameter*> DependsAsParameters() = 0; |
622 |
|
623 |
/** |
624 |
* Might return a default value for this parameter. The default |
625 |
* value will be used if the user does not provide a specific value |
626 |
* for this parameter at device creation time. If the parameter |
627 |
* does not have a reasonable default value, it will return |
628 |
* @c optional<String>::nothing. |
629 |
* |
630 |
* This method already provides an implementation, which usually is |
631 |
* not overridden by descendants. A descendant would rather |
632 |
* implement the other Default() method taking arguments. |
633 |
*/ |
634 |
virtual optional<String> Default(); |
635 |
|
636 |
/** |
637 |
* Might return a default value for this parameter. The default |
638 |
* value will be used if the user does not provide a specific value |
639 |
* for this parameter at device creation time. |
640 |
* |
641 |
* This method must be implemented by descendants. If the parameter |
642 |
* does not have a reasonable default value, it should return |
643 |
* @c optional<String>::nothing. |
644 |
* |
645 |
* As arguments, the parameters are passed to this method |
646 |
* automatically, which the user already provided. For example a |
647 |
* parameter "CARD" the user already did set for selecting a |
648 |
* specific sound card. So such arguments resolve dependencies |
649 |
* of this parameter. |
650 |
* |
651 |
* @param Parameters - other parameters which the user already |
652 |
* supplied |
653 |
*/ |
654 |
virtual optional<String> Default(std::map<String,String> Parameters) = 0; |
655 |
|
656 |
/** |
657 |
* Might return a minimum value for this parameter. If the |
658 |
* parameter does not have a reasonable minimum value, it will |
659 |
* return @c optional<String>::nothing. |
660 |
* |
661 |
* This method already provides an implementation, which usually is |
662 |
* not overridden by descendants. A descendant would rather |
663 |
* implement the other RangeMin() method taking arguments. |
664 |
*/ |
665 |
virtual optional<String> RangeMin(); |
666 |
|
667 |
/** |
668 |
* Might return a minimum value for this parameter. |
669 |
* |
670 |
* This method must be implemented by descendants. If the parameter |
671 |
* does not have a reasonable minimum value, it should return |
672 |
* @c optional<String>::nothing. |
673 |
* |
674 |
* As arguments, the parameters are passed to this method |
675 |
* automatically, which the user already provided. For example a |
676 |
* parameter "CARD" the user already did set for selecting a |
677 |
* specific sound card. So such arguments resolve dependencies |
678 |
* of this parameter. |
679 |
* |
680 |
* @param Parameters - other parameters which the user already |
681 |
* supplied |
682 |
*/ |
683 |
virtual optional<String> RangeMin(std::map<String,String> Parameters) = 0; |
684 |
|
685 |
/** |
686 |
* Might return a maximum value for this parameter. If the |
687 |
* parameter does not have a reasonable maximum value, it will |
688 |
* return @c optional<String>::nothing. |
689 |
* |
690 |
* This method already provides an implementation, which usually is |
691 |
* not overridden by descendants. A descendant would rather |
692 |
* implement the other RangeMax() method taking arguments. |
693 |
*/ |
694 |
virtual optional<String> RangeMax(); |
695 |
|
696 |
/** |
697 |
* Might return a maximum value for this parameter. |
698 |
* |
699 |
* This method must be implemented by descendants. If the parameter |
700 |
* does not have a reasonable maximum value, it should return |
701 |
* @c optional<String>::nothing. |
702 |
* |
703 |
* As arguments, the parameters are passed to this method |
704 |
* automatically, which the user already provided. For example a |
705 |
* parameter "CARD" the user already did set for selecting a |
706 |
* specific sound card. So such arguments resolve dependencies |
707 |
* of this parameter. |
708 |
* |
709 |
* @param Parameters - other parameters which the user already |
710 |
* supplied |
711 |
*/ |
712 |
virtual optional<String> RangeMax(std::map<String,String> Parameters) = 0; |
713 |
|
714 |
/** |
715 |
* Might return a comma separated list as String with possible |
716 |
* values for this parameter. If the parameter does not have |
717 |
* reasonable, specific possible values, it will return |
718 |
* @c optional<String>::nothing. |
719 |
* |
720 |
* This method already provides an implementation, which usually is |
721 |
* not overridden by descendants. A descendant would rather |
722 |
* implement the other Possibilities() method taking arguments. |
723 |
*/ |
724 |
virtual optional<String> Possibilities(); |
725 |
|
726 |
/** |
727 |
* Might return a comma separated list as String with possible |
728 |
* values for this parameter. |
729 |
* |
730 |
* This method must be implemented by descendants. If the parameter |
731 |
* does not have reasonable, specific possible values, it should |
732 |
* return @c optional<String>::nothing. |
733 |
* |
734 |
* As arguments, the parameters are passed to this method |
735 |
* automatically, which the user already provided. For example a |
736 |
* parameter "CARD" the user already did set for selecting a |
737 |
* specific sound card. So such arguments resolve dependencies |
738 |
* of this parameter. |
739 |
* |
740 |
* @param Parameters - other parameters which the user already |
741 |
* supplied |
742 |
*/ |
743 |
virtual optional<String> Possibilities(std::map<String,String> Parameters) = 0; |
744 |
|
745 |
/** |
746 |
* Sets the internal device pointer to a specific device (driver |
747 |
* instance) for this parameter object. Descendants usually use |
748 |
* that internal pointer to interact with their specific driver |
749 |
* implementation class. |
750 |
*/ |
751 |
void Attach(Device* pDevice) { this->pDevice = pDevice; } |
752 |
protected: |
753 |
Device* pDevice; |
754 |
}; |
755 |
|
756 |
/** @brief Abstract base class for driver parameters of type @c Bool. |
757 |
* |
758 |
* Implements a "creation" driver parameter for value type @c bool. |
759 |
* A driver offering a parameter of type @c bool would derive its |
760 |
* parameter class from this class and implement the abstract methods |
761 |
* OnSetValue() and DefaultAsBool(). |
762 |
* |
763 |
* See DeviceCreationParameter and DeviceRuntimeParameter for a discussion |
764 |
* about "runtime" parameters vs. "creation" parameters. |
765 |
* |
766 |
* @see DeviceRuntimeParameterBool |
767 |
*/ |
768 |
class DeviceCreationParameterBool : public DeviceCreationParameter { |
769 |
public: |
770 |
DeviceCreationParameterBool(bool bVal = false); |
771 |
DeviceCreationParameterBool(String val) throw (Exception); |
772 |
virtual String Type() OVERRIDE; |
773 |
virtual bool Multiplicity() OVERRIDE; |
774 |
virtual optional<String> Default(std::map<String,String> Parameters) OVERRIDE; |
775 |
virtual optional<String> RangeMin(std::map<String,String> Parameters) OVERRIDE; |
776 |
virtual optional<String> RangeMax(std::map<String,String> Parameters) OVERRIDE; |
777 |
virtual optional<String> Possibilities(std::map<String,String> Parameters) OVERRIDE; |
778 |
virtual String Value() OVERRIDE; |
779 |
virtual void SetValue(String val) throw (Exception) OVERRIDE; |
780 |
|
781 |
virtual bool ValueAsBool(); |
782 |
virtual void SetValue(bool b) throw (Exception); |
783 |
|
784 |
virtual optional<bool> DefaultAsBool(std::map<String,String> Parameters) = 0; |
785 |
virtual void OnSetValue(bool b) throw (Exception) = 0; |
786 |
protected: |
787 |
bool bVal; |
788 |
void InitWithDefault(); |
789 |
private: |
790 |
}; |
791 |
|
792 |
/** @brief Abstract base class for driver parameters of type @c int. |
793 |
* |
794 |
* Implements a "creation" driver parameter for value type @c int. |
795 |
* A driver offering a parameter of type @c int would derive its |
796 |
* parameter class from this class and implement the abstract methods |
797 |
* OnSetValue(), PossibilitiesAsInt(), RangeMinAsInt(), RangeMaxAsInt() |
798 |
* and DefaultAsInt(). |
799 |
* |
800 |
* See DeviceCreationParameter and DeviceRuntimeParameter for a discussion |
801 |
* about "runtime" parameters vs. "creation" parameters. |
802 |
* |
803 |
* @see DeviceRuntimeParameterInt |
804 |
*/ |
805 |
class DeviceCreationParameterInt : public DeviceCreationParameter { |
806 |
public: |
807 |
DeviceCreationParameterInt(int iVal = 0); |
808 |
DeviceCreationParameterInt(String val) throw (Exception); |
809 |
virtual String Type() OVERRIDE; |
810 |
virtual bool Multiplicity() OVERRIDE; |
811 |
virtual optional<String> Default(std::map<String,String> Parameters) OVERRIDE; |
812 |
virtual optional<String> RangeMin(std::map<String,String> Parameters) OVERRIDE; |
813 |
virtual optional<String> RangeMax(std::map<String,String> Parameters) OVERRIDE; |
814 |
virtual optional<String> Possibilities(std::map<String,String> Parameters) OVERRIDE; |
815 |
virtual String Value() OVERRIDE; |
816 |
virtual void SetValue(String val) throw (Exception) OVERRIDE; |
817 |
|
818 |
virtual int ValueAsInt(); |
819 |
virtual void SetValue(int i) throw (Exception); |
820 |
|
821 |
virtual optional<int> DefaultAsInt(std::map<String,String> Parameters) = 0; |
822 |
virtual optional<int> RangeMinAsInt(std::map<String,String> Parameters) = 0; |
823 |
virtual optional<int> RangeMaxAsInt(std::map<String,String> Parameters) = 0; |
824 |
virtual std::vector<int> PossibilitiesAsInt(std::map<String,String> Parameters) = 0; |
825 |
virtual void OnSetValue(int i) throw (Exception) = 0; |
826 |
protected: |
827 |
int iVal; |
828 |
void InitWithDefault(); |
829 |
private: |
830 |
}; |
831 |
|
832 |
/** @brief Abstract base class for driver parameters of type @c float. |
833 |
* |
834 |
* Implements a "creation" driver parameter for value type @c float. |
835 |
* A driver offering a parameter of type @c float would derive its |
836 |
* parameter class from this class and implement the abstract methods |
837 |
* OnSetValue(), PossibilitiesAsFloat(), RangeMinAsFloat(), |
838 |
* RangeMaxAsFloat() and DefaultAsFloat(). |
839 |
* |
840 |
* See DeviceCreationParameter and DeviceRuntimeParameter for a discussion |
841 |
* about "runtime" parameters vs. "creation" parameters. |
842 |
* |
843 |
* @see DeviceRuntimeParameterFloat |
844 |
*/ |
845 |
class DeviceCreationParameterFloat : public DeviceCreationParameter { |
846 |
public: |
847 |
DeviceCreationParameterFloat(float fVal = 0.0); |
848 |
DeviceCreationParameterFloat(String val) throw (Exception); |
849 |
virtual String Type() OVERRIDE; |
850 |
virtual bool Multiplicity() OVERRIDE; |
851 |
virtual optional<String> Default(std::map<String,String> Parameters) OVERRIDE; |
852 |
virtual optional<String> RangeMin(std::map<String,String> Parameters) OVERRIDE; |
853 |
virtual optional<String> RangeMax(std::map<String,String> Parameters) OVERRIDE; |
854 |
virtual optional<String> Possibilities(std::map<String,String> Parameters) OVERRIDE; |
855 |
virtual String Value() OVERRIDE; |
856 |
virtual void SetValue(String val) throw (Exception) OVERRIDE; |
857 |
|
858 |
virtual float ValueAsFloat(); |
859 |
virtual void SetValue(float f) throw (Exception); |
860 |
|
861 |
virtual optional<float> DefaultAsFloat(std::map<String,String> Parameters) = 0; |
862 |
virtual optional<float> RangeMinAsFloat(std::map<String,String> Parameters) = 0; |
863 |
virtual optional<float> RangeMaxAsFloat(std::map<String,String> Parameters) = 0; |
864 |
virtual std::vector<float> PossibilitiesAsFloat(std::map<String,String> Parameters) = 0; |
865 |
virtual void OnSetValue(float f) throw (Exception) = 0; |
866 |
protected: |
867 |
float fVal; |
868 |
void InitWithDefault(); |
869 |
private: |
870 |
}; |
871 |
|
872 |
/** @brief Abstract base class for driver parameters of type @c String. |
873 |
* |
874 |
* Implements a "creation" driver parameter for value type @c String. |
875 |
* A driver offering a parameter of type @c String would derive its |
876 |
* parameter class from this class and implement the abstract methods |
877 |
* OnSetValue(), PossibilitiesAsString() and DefaultAsString(). |
878 |
* |
879 |
* See DeviceCreationParameter and DeviceRuntimeParameter for a discussion |
880 |
* about "runtime" parameters vs. "creation" parameters. |
881 |
* |
882 |
* @see DeviceRuntimeParameterString |
883 |
*/ |
884 |
class DeviceCreationParameterString : public DeviceCreationParameter { |
885 |
public: |
886 |
DeviceCreationParameterString(String sVal = String()); |
887 |
virtual ~DeviceCreationParameterString(){} |
888 |
virtual String Type() OVERRIDE; |
889 |
virtual bool Multiplicity() OVERRIDE; |
890 |
virtual optional<String> Default(std::map<String,String> Parameters) OVERRIDE; |
891 |
virtual optional<String> RangeMin(std::map<String,String> Parameters) OVERRIDE; |
892 |
virtual optional<String> RangeMax(std::map<String,String> Parameters) OVERRIDE; |
893 |
virtual optional<String> Possibilities(std::map<String,String> Parameters) OVERRIDE; |
894 |
virtual String Value() OVERRIDE; |
895 |
virtual void SetValue(String val) throw (Exception) OVERRIDE; |
896 |
|
897 |
virtual String ValueAsString(); |
898 |
virtual void SetValueAsString(String s) throw (Exception); |
899 |
|
900 |
virtual optional<String> DefaultAsString(std::map<String,String> Parameters) = 0; |
901 |
virtual std::vector<String> PossibilitiesAsString(std::map<String,String> Parameters) = 0; |
902 |
virtual void OnSetValue(String s) throw (Exception) = 0; |
903 |
protected: |
904 |
String sVal; |
905 |
void InitWithDefault(); |
906 |
private: |
907 |
}; |
908 |
|
909 |
/** @brief Abstract base class for driver parameters of a @c String list type. |
910 |
* |
911 |
* Implements a "creation" driver parameter for @c String value types. |
912 |
* A driver offering a parameter allowing to set multiple values of type |
913 |
* @c String would derive its parameter class from this class and implement |
914 |
* the abstract methods OnSetValue(), PossibilitiesAsString() and |
915 |
* DefaultAsStrings(). |
916 |
* |
917 |
* See DeviceCreationParameter and DeviceRuntimeParameter for a discussion |
918 |
* about "runtime" parameters vs. "creation" parameters. |
919 |
* |
920 |
* @see DeviceRuntimeParameterStrings |
921 |
*/ |
922 |
class DeviceCreationParameterStrings : public DeviceCreationParameter { |
923 |
public: |
924 |
DeviceCreationParameterStrings(); |
925 |
DeviceCreationParameterStrings(std::vector<String> sVals); |
926 |
DeviceCreationParameterStrings(String val) throw (Exception); |
927 |
virtual ~DeviceCreationParameterStrings(){} |
928 |
virtual String Type() OVERRIDE; |
929 |
virtual bool Multiplicity() OVERRIDE; |
930 |
virtual optional<String> Default(std::map<String,String> Parameters) OVERRIDE; |
931 |
virtual optional<String> RangeMin(std::map<String,String> Parameters) OVERRIDE; |
932 |
virtual optional<String> RangeMax(std::map<String,String> Parameters) OVERRIDE; |
933 |
virtual optional<String> Possibilities(std::map<String,String> Parameters) OVERRIDE; |
934 |
virtual String Value() OVERRIDE; |
935 |
virtual void SetValue(String val) throw (Exception) OVERRIDE; |
936 |
|
937 |
virtual std::vector<String> ValueAsStrings(); |
938 |
virtual void SetValue(std::vector<String> vS) throw (Exception); |
939 |
|
940 |
virtual std::vector<String> DefaultAsStrings(std::map<String,String> Parameters) = 0; |
941 |
virtual std::vector<String> PossibilitiesAsString(std::map<String,String> Parameters) = 0; |
942 |
virtual void OnSetValue(std::vector<String> vS) throw (Exception) = 0; |
943 |
protected: |
944 |
std::vector<String> sVals; |
945 |
void InitWithDefault(); |
946 |
private: |
947 |
}; |
948 |
|
949 |
} // namespace LinuxSampler |
950 |
|
951 |
#endif // __LS_DEVICE_PARAMETER_H__ |