1 |
schoenebeck |
123 |
/*************************************************************************** |
2 |
|
|
* * |
3 |
|
|
* LinuxSampler - modular, streaming capable sampler * |
4 |
|
|
* * |
5 |
|
|
* Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck * |
6 |
schoenebeck |
880 |
* Copyright (C) 2005, 2006 Christian Schoenebeck * |
7 |
schoenebeck |
123 |
* * |
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 |
|
|
#include <strings.h> |
25 |
|
|
#include <stdlib.h> |
26 |
|
|
|
27 |
|
|
#include "DeviceParameter.h" |
28 |
|
|
|
29 |
|
|
namespace LinuxSampler { |
30 |
|
|
|
31 |
schoenebeck |
486 |
// if string is encapsulated into apostrophes or quotation marks, then remove those apostrophes / quotation marks |
32 |
|
|
static void __eliminate_quotation(String& s) { |
33 |
|
|
if (s.size()) { |
34 |
|
|
const char cBegin = s[0]; |
35 |
|
|
const char cEnd = s[s.size() - 1]; |
36 |
|
|
if ( (cBegin == '\'' && cEnd == '\'') || (cBegin == '\"' && cEnd == '\"') ) { |
37 |
|
|
s = s.substr(1, s.size() - 2); |
38 |
|
|
} |
39 |
|
|
} |
40 |
|
|
} |
41 |
|
|
|
42 |
schoenebeck |
880 |
static bool __parse_bool(String val) throw (Exception) { |
43 |
schoenebeck |
486 |
__eliminate_quotation(val); |
44 |
schoenebeck |
123 |
int b; |
45 |
|
|
if (val == "1" || !strcasecmp(val.c_str(),"true")) b = true; |
46 |
|
|
else if (val == "0" || !strcasecmp(val.c_str(),"false")) b = false; |
47 |
schoenebeck |
880 |
else throw Exception("Invalid value for boolean Device parameter"); |
48 |
schoenebeck |
123 |
return b; |
49 |
|
|
} |
50 |
|
|
|
51 |
schoenebeck |
880 |
static int __parse_int(String val) throw (Exception) { |
52 |
schoenebeck |
486 |
__eliminate_quotation(val); |
53 |
schoenebeck |
123 |
return atoi(val.c_str()); // TODO: format check is missing |
54 |
|
|
} |
55 |
|
|
|
56 |
schoenebeck |
880 |
static float __parse_float(String val) throw (Exception) { |
57 |
schoenebeck |
486 |
__eliminate_quotation(val); |
58 |
schoenebeck |
123 |
return atof(val.c_str()); // TODO: format check is missing |
59 |
|
|
} |
60 |
|
|
|
61 |
schoenebeck |
486 |
static String __parse_string(String val) { |
62 |
|
|
__eliminate_quotation(val); |
63 |
schoenebeck |
214 |
return val; |
64 |
|
|
} |
65 |
|
|
|
66 |
schoenebeck |
880 |
static std::vector<String> __parse_strings(String val) throw (Exception) { |
67 |
schoenebeck |
123 |
std::vector<String> vS; |
68 |
iliev |
1296 |
|
69 |
|
|
// checking for empty list |
70 |
|
|
if (val.length() == 0) return vS; |
71 |
schoenebeck |
123 |
|
72 |
schoenebeck |
214 |
// if there's only a single value, then we also allow to give it without being encapsulated into apostrophes |
73 |
schoenebeck |
123 |
if (val.find("\'") == String::npos && val.find("\"") == String::npos) { |
74 |
|
|
vS.push_back(val); |
75 |
|
|
} |
76 |
|
|
else { // if multiple strings or a string encapsulated into apostrophes |
77 |
|
|
char* pStart = (char*) val.c_str(); |
78 |
|
|
char* pC = pStart; |
79 |
|
|
|
80 |
|
|
while (true) { |
81 |
schoenebeck |
880 |
if (*pC != '\'' && *pC != '\"') throw Exception("Invalid form, all individual strings should be encapsulated into apostrophes, separated by commas"); |
82 |
schoenebeck |
483 |
|
83 |
schoenebeck |
123 |
// search for token end |
84 |
|
|
char* pTokenStart = pC + 1; |
85 |
|
|
do { |
86 |
|
|
pC++; |
87 |
schoenebeck |
880 |
if (*pC == '\0') throw Exception("Invalid form, all individual strings should be encapsulated into apostrophes, separated by commas"); |
88 |
schoenebeck |
123 |
} |
89 |
|
|
while (*pC != '\'' && *pC != '\"'); |
90 |
schoenebeck |
483 |
String token = val.substr((int)(pTokenStart - pStart), (int)(pC - pTokenStart)); |
91 |
|
|
vS.push_back(token); // we found the token's end |
92 |
schoenebeck |
123 |
|
93 |
|
|
// now there should be either a comma or the end of the total string |
94 |
|
|
if (*(++pC) == '\0') break; |
95 |
schoenebeck |
880 |
if (*pC != ',') throw Exception("Invalid form, all individual strings should be encapsulated into apostrophes, separated by commas"); |
96 |
schoenebeck |
483 |
pC++; |
97 |
schoenebeck |
123 |
} |
98 |
|
|
} |
99 |
|
|
|
100 |
|
|
return vS; |
101 |
|
|
} |
102 |
|
|
|
103 |
|
|
|
104 |
|
|
|
105 |
|
|
// *************** DeviceRuntimeParameterBool *************** |
106 |
|
|
// * |
107 |
|
|
|
108 |
|
|
DeviceRuntimeParameterBool::DeviceRuntimeParameterBool(bool bVal) { |
109 |
|
|
this->bVal = bVal; |
110 |
|
|
} |
111 |
|
|
|
112 |
|
|
String DeviceRuntimeParameterBool::Type() { |
113 |
|
|
return "BOOL"; |
114 |
|
|
} |
115 |
|
|
|
116 |
|
|
bool DeviceRuntimeParameterBool::Multiplicity() { |
117 |
|
|
return false; |
118 |
|
|
} |
119 |
|
|
|
120 |
|
|
optional<String> DeviceRuntimeParameterBool::RangeMin() { |
121 |
|
|
return optional<String>::nothing; |
122 |
|
|
} |
123 |
|
|
|
124 |
|
|
optional<String> DeviceRuntimeParameterBool::RangeMax() { |
125 |
|
|
return optional<String>::nothing; |
126 |
|
|
} |
127 |
|
|
|
128 |
|
|
optional<String> DeviceRuntimeParameterBool::Possibilities() { |
129 |
|
|
return optional<String>::nothing; |
130 |
|
|
} |
131 |
|
|
|
132 |
|
|
String DeviceRuntimeParameterBool::Value() { |
133 |
schoenebeck |
214 |
return (ValueAsBool()) ? "true" : "false"; |
134 |
schoenebeck |
123 |
} |
135 |
|
|
|
136 |
schoenebeck |
880 |
void DeviceRuntimeParameterBool::SetValue(String val) throw (Exception) { |
137 |
|
|
if (Fix()) throw Exception("Device parameter is read only"); |
138 |
schoenebeck |
123 |
int b = __parse_bool(val); |
139 |
|
|
SetValue(b); |
140 |
|
|
} |
141 |
|
|
|
142 |
|
|
bool DeviceRuntimeParameterBool::ValueAsBool() { |
143 |
|
|
return bVal; |
144 |
|
|
} |
145 |
|
|
|
146 |
schoenebeck |
880 |
void DeviceRuntimeParameterBool::SetValue(bool b) throw (Exception) { |
147 |
|
|
if (Fix()) throw Exception("Device parameter is read only"); |
148 |
schoenebeck |
214 |
OnSetValue(b); |
149 |
schoenebeck |
123 |
bVal = b; |
150 |
|
|
} |
151 |
|
|
|
152 |
|
|
|
153 |
|
|
|
154 |
|
|
// *************** DeviceRuntimeParameterInt *************** |
155 |
|
|
// * |
156 |
|
|
|
157 |
|
|
DeviceRuntimeParameterInt::DeviceRuntimeParameterInt(int iVal) { |
158 |
|
|
this->iVal = iVal; |
159 |
|
|
} |
160 |
|
|
|
161 |
|
|
String DeviceRuntimeParameterInt::Type() { |
162 |
|
|
return "INT"; |
163 |
|
|
} |
164 |
|
|
|
165 |
|
|
bool DeviceRuntimeParameterInt::Multiplicity() { |
166 |
|
|
return false; |
167 |
|
|
} |
168 |
|
|
|
169 |
|
|
optional<String> DeviceRuntimeParameterInt::RangeMin() { |
170 |
|
|
optional<int> rangemin = RangeMinAsInt(); |
171 |
|
|
if (!rangemin) return optional<String>::nothing; |
172 |
|
|
return ToString(*rangemin); |
173 |
|
|
} |
174 |
|
|
|
175 |
|
|
optional<String> DeviceRuntimeParameterInt::RangeMax() { |
176 |
|
|
optional<int> rangemax = RangeMaxAsInt(); |
177 |
|
|
if (!rangemax) return optional<String>::nothing; |
178 |
|
|
return ToString(*rangemax); |
179 |
|
|
} |
180 |
|
|
|
181 |
|
|
optional<String> DeviceRuntimeParameterInt::Possibilities() { |
182 |
|
|
std::vector<int> possibilities = PossibilitiesAsInt(); |
183 |
|
|
if (possibilities.empty()) return optional<String>::nothing; |
184 |
|
|
|
185 |
|
|
std::stringstream ss; |
186 |
|
|
std::vector<int>::iterator iter = possibilities.begin(); |
187 |
|
|
while (iter != possibilities.end()) { |
188 |
|
|
if (ss.str() != "") ss << ","; |
189 |
|
|
ss << *iter; |
190 |
|
|
iter++; |
191 |
|
|
} |
192 |
|
|
return ss.str(); |
193 |
|
|
} |
194 |
|
|
|
195 |
|
|
String DeviceRuntimeParameterInt::Value() { |
196 |
|
|
return ToString(ValueAsInt()); |
197 |
|
|
} |
198 |
|
|
|
199 |
schoenebeck |
880 |
void DeviceRuntimeParameterInt::SetValue(String val) throw (Exception) { |
200 |
|
|
if (Fix()) throw Exception("Device parameter is read only"); |
201 |
schoenebeck |
123 |
int i = __parse_int(val); |
202 |
schoenebeck |
880 |
if (RangeMinAsInt() && i < *RangeMinAsInt()) throw Exception("Invalid device parameter value: too small"); |
203 |
|
|
if (RangeMaxAsInt() && i > *RangeMaxAsInt()) throw Exception("Invalid device parameter value: too big"); |
204 |
schoenebeck |
123 |
|
205 |
|
|
std::vector<int> possibilities = PossibilitiesAsInt(); |
206 |
|
|
if (possibilities.size()) { |
207 |
|
|
bool valid = false; |
208 |
|
|
std::vector<int>::iterator iter = possibilities.begin(); |
209 |
|
|
while (iter != possibilities.end()) { |
210 |
|
|
if (i == *iter) { |
211 |
|
|
valid = true; |
212 |
|
|
break; |
213 |
|
|
} |
214 |
|
|
iter++; |
215 |
|
|
} |
216 |
schoenebeck |
880 |
if (!valid) throw Exception("Invalid device parameter value: not in set of possible values"); |
217 |
schoenebeck |
123 |
} |
218 |
|
|
SetValue(i); |
219 |
|
|
} |
220 |
|
|
|
221 |
|
|
int DeviceRuntimeParameterInt::ValueAsInt() { |
222 |
|
|
return iVal; |
223 |
|
|
} |
224 |
|
|
|
225 |
schoenebeck |
880 |
void DeviceRuntimeParameterInt::SetValue(int i) throw (Exception) { |
226 |
|
|
if (Fix()) throw Exception("Device parameter is read only"); |
227 |
schoenebeck |
214 |
OnSetValue(i); |
228 |
schoenebeck |
123 |
iVal = i; |
229 |
|
|
} |
230 |
|
|
|
231 |
|
|
|
232 |
|
|
|
233 |
|
|
// *************** DeviceRuntimeParameterFloat *************** |
234 |
|
|
// * |
235 |
|
|
|
236 |
|
|
DeviceRuntimeParameterFloat::DeviceRuntimeParameterFloat(float fVal) { |
237 |
|
|
this->fVal = fVal; |
238 |
|
|
} |
239 |
|
|
|
240 |
|
|
String DeviceRuntimeParameterFloat::Type() { |
241 |
|
|
return "FLOAT"; |
242 |
|
|
} |
243 |
|
|
|
244 |
|
|
bool DeviceRuntimeParameterFloat::Multiplicity() { |
245 |
|
|
return false; |
246 |
|
|
} |
247 |
|
|
|
248 |
|
|
optional<String> DeviceRuntimeParameterFloat::RangeMin() { |
249 |
|
|
optional<float> rangemin = RangeMinAsFloat(); |
250 |
|
|
if (!rangemin) return optional<String>::nothing; |
251 |
|
|
return ToString(*rangemin); |
252 |
|
|
} |
253 |
|
|
|
254 |
|
|
optional<String> DeviceRuntimeParameterFloat::RangeMax() { |
255 |
|
|
optional<float> rangemax = RangeMaxAsFloat(); |
256 |
|
|
if (!rangemax) return optional<String>::nothing; |
257 |
|
|
return ToString(*rangemax); |
258 |
|
|
} |
259 |
|
|
|
260 |
|
|
optional<String> DeviceRuntimeParameterFloat::Possibilities() { |
261 |
|
|
std::vector<float> possibilities = PossibilitiesAsFloat(); |
262 |
|
|
if (possibilities.empty()) return optional<String>::nothing; |
263 |
|
|
|
264 |
|
|
std::stringstream ss; |
265 |
|
|
std::vector<float>::iterator iter = possibilities.begin(); |
266 |
|
|
while (iter != possibilities.end()) { |
267 |
|
|
if (ss.str() != "") ss << ","; |
268 |
|
|
ss << *iter; |
269 |
|
|
iter++; |
270 |
|
|
} |
271 |
|
|
return ss.str(); |
272 |
|
|
} |
273 |
|
|
|
274 |
|
|
String DeviceRuntimeParameterFloat::Value() { |
275 |
|
|
return ToString(ValueAsFloat()); |
276 |
|
|
} |
277 |
|
|
|
278 |
schoenebeck |
880 |
void DeviceRuntimeParameterFloat::SetValue(String val) throw (Exception) { |
279 |
|
|
if (Fix()) throw Exception("Device parameter is read only"); |
280 |
schoenebeck |
123 |
float f = __parse_float(val); |
281 |
schoenebeck |
880 |
if (RangeMinAsFloat() && f < *RangeMinAsFloat()) throw Exception("Invalid device parameter value: too small"); |
282 |
|
|
if (RangeMaxAsFloat() && f > *RangeMaxAsFloat()) throw Exception("Invalid device parameter value: too big"); |
283 |
schoenebeck |
123 |
|
284 |
|
|
std::vector<float> possibilities = PossibilitiesAsFloat(); |
285 |
|
|
if (possibilities.size()) { |
286 |
|
|
bool valid = false; |
287 |
|
|
std::vector<float>::iterator iter = possibilities.begin(); |
288 |
|
|
while (iter != possibilities.end()) { |
289 |
|
|
if (f == *iter) { |
290 |
|
|
valid = true; |
291 |
|
|
break; |
292 |
|
|
} |
293 |
|
|
iter++; |
294 |
|
|
} |
295 |
schoenebeck |
880 |
if (!valid) throw Exception("Invalid device parameter value: not in set of possible values"); |
296 |
schoenebeck |
123 |
} |
297 |
|
|
SetValue(f); |
298 |
|
|
} |
299 |
|
|
|
300 |
|
|
float DeviceRuntimeParameterFloat::ValueAsFloat() { |
301 |
|
|
return fVal; |
302 |
|
|
} |
303 |
|
|
|
304 |
schoenebeck |
880 |
void DeviceRuntimeParameterFloat::SetValue(float f) throw (Exception) { |
305 |
|
|
if (Fix()) throw Exception("Device parameter is read only"); |
306 |
schoenebeck |
214 |
OnSetValue(f); |
307 |
schoenebeck |
123 |
fVal = f; |
308 |
|
|
} |
309 |
|
|
|
310 |
|
|
|
311 |
|
|
|
312 |
|
|
// *************** DeviceRuntimeParameterString *************** |
313 |
|
|
// * |
314 |
|
|
|
315 |
|
|
DeviceRuntimeParameterString::DeviceRuntimeParameterString(String sVal) { |
316 |
|
|
this->sVal = sVal; |
317 |
|
|
} |
318 |
|
|
|
319 |
|
|
String DeviceRuntimeParameterString::Type() { |
320 |
|
|
return "STRING"; |
321 |
|
|
} |
322 |
|
|
|
323 |
|
|
bool DeviceRuntimeParameterString::Multiplicity() { |
324 |
|
|
return false; |
325 |
|
|
} |
326 |
|
|
|
327 |
|
|
optional<String> DeviceRuntimeParameterString::RangeMin() { |
328 |
|
|
return optional<String>::nothing; |
329 |
|
|
} |
330 |
|
|
|
331 |
|
|
optional<String> DeviceRuntimeParameterString::RangeMax() { |
332 |
|
|
return optional<String>::nothing; |
333 |
|
|
} |
334 |
|
|
|
335 |
|
|
optional<String> DeviceRuntimeParameterString::Possibilities() { |
336 |
|
|
std::vector<String> possibilities = PossibilitiesAsString(); |
337 |
|
|
if (possibilities.empty()) return optional<String>::nothing; |
338 |
|
|
|
339 |
|
|
std::stringstream ss; |
340 |
|
|
std::vector<String>::iterator iter = possibilities.begin(); |
341 |
|
|
while (iter != possibilities.end()) { |
342 |
|
|
if (ss.str() != "") ss << ","; |
343 |
|
|
ss << "'" << *iter << "'"; |
344 |
|
|
iter++; |
345 |
|
|
} |
346 |
|
|
return ss.str(); |
347 |
|
|
} |
348 |
|
|
|
349 |
|
|
String DeviceRuntimeParameterString::Value() { |
350 |
schoenebeck |
214 |
return "\'" + ValueAsString() + "\'"; |
351 |
schoenebeck |
123 |
} |
352 |
|
|
|
353 |
schoenebeck |
880 |
void DeviceRuntimeParameterString::SetValue(String val) throw (Exception) { |
354 |
|
|
if (Fix()) throw Exception("Device parameter is read only"); |
355 |
schoenebeck |
214 |
SetValueAsString(__parse_string(val)); |
356 |
|
|
} |
357 |
|
|
|
358 |
|
|
String DeviceRuntimeParameterString::ValueAsString() { |
359 |
|
|
return sVal; |
360 |
|
|
} |
361 |
|
|
|
362 |
schoenebeck |
880 |
void DeviceRuntimeParameterString::SetValueAsString(String val) throw (Exception) { |
363 |
|
|
if (Fix()) throw Exception("Device parameter is read only"); |
364 |
|
|
if (val.find("\'") != String::npos) throw Exception("Character -> \' <- not allowed"); |
365 |
|
|
if (val.find("\"") != String::npos) throw Exception("Character -> \" <- not allowed"); |
366 |
schoenebeck |
123 |
OnSetValue(val); |
367 |
|
|
sVal = val; |
368 |
|
|
} |
369 |
|
|
|
370 |
|
|
|
371 |
|
|
|
372 |
|
|
// *************** DeviceRuntimeParameterStrings *************** |
373 |
|
|
// * |
374 |
|
|
|
375 |
|
|
DeviceRuntimeParameterStrings::DeviceRuntimeParameterStrings(std::vector<String> vS) { |
376 |
|
|
this->sVals = vS; |
377 |
|
|
} |
378 |
|
|
|
379 |
|
|
String DeviceRuntimeParameterStrings::Type() { |
380 |
|
|
return "STRING"; |
381 |
|
|
} |
382 |
|
|
|
383 |
|
|
bool DeviceRuntimeParameterStrings::Multiplicity() { |
384 |
|
|
return true; |
385 |
|
|
} |
386 |
|
|
|
387 |
|
|
optional<String> DeviceRuntimeParameterStrings::RangeMin() { |
388 |
|
|
return optional<String>::nothing; |
389 |
|
|
} |
390 |
|
|
|
391 |
|
|
optional<String> DeviceRuntimeParameterStrings::RangeMax() { |
392 |
|
|
return optional<String>::nothing; |
393 |
|
|
} |
394 |
|
|
|
395 |
|
|
optional<String> DeviceRuntimeParameterStrings::Possibilities() { |
396 |
|
|
std::vector<String> possibilities = PossibilitiesAsString(); |
397 |
|
|
if (possibilities.empty()) return optional<String>::nothing; |
398 |
|
|
|
399 |
|
|
std::stringstream ss; |
400 |
|
|
std::vector<String>::iterator iter = possibilities.begin(); |
401 |
|
|
while (iter != possibilities.end()) { |
402 |
|
|
if (ss.str() != "") ss << ","; |
403 |
|
|
ss << "'" << *iter << "'"; |
404 |
|
|
iter++; |
405 |
|
|
} |
406 |
|
|
return ss.str(); |
407 |
|
|
} |
408 |
|
|
|
409 |
|
|
String DeviceRuntimeParameterStrings::Value() { |
410 |
|
|
String result; |
411 |
|
|
std::vector<String>::iterator iter = this->sVals.begin(); |
412 |
|
|
while (iter != this->sVals.end()) { |
413 |
|
|
if (result != "") result += ","; |
414 |
|
|
result += "'" + *iter + "'"; |
415 |
|
|
iter++; |
416 |
|
|
} |
417 |
|
|
return result; |
418 |
|
|
} |
419 |
|
|
|
420 |
schoenebeck |
880 |
void DeviceRuntimeParameterStrings::SetValue(String val) throw (Exception) { |
421 |
|
|
if (Fix()) throw Exception("Device parameter is read only"); |
422 |
schoenebeck |
123 |
std::vector<String> vS = __parse_strings(val); |
423 |
|
|
SetValue(vS); |
424 |
|
|
} |
425 |
|
|
|
426 |
|
|
std::vector<String> DeviceRuntimeParameterStrings::ValueAsStrings() { |
427 |
|
|
return sVals; |
428 |
|
|
} |
429 |
|
|
|
430 |
schoenebeck |
880 |
void DeviceRuntimeParameterStrings::SetValue(std::vector<String> vS) throw (Exception) { |
431 |
|
|
if (Fix()) throw Exception("Device parameter is read only"); |
432 |
schoenebeck |
214 |
OnSetValue(vS); |
433 |
schoenebeck |
123 |
sVals = vS; |
434 |
|
|
} |
435 |
|
|
|
436 |
|
|
|
437 |
|
|
|
438 |
|
|
|
439 |
|
|
|
440 |
|
|
|
441 |
|
|
// *************** DeviceCreationParameter *************** |
442 |
|
|
// * |
443 |
|
|
|
444 |
|
|
optional<String> DeviceCreationParameter::Depends() { |
445 |
|
|
std::map<String,DeviceCreationParameter*> dependencies = DependsAsParameters(); |
446 |
|
|
if (!dependencies.size()) return optional<String>::nothing; |
447 |
|
|
|
448 |
|
|
std::map<String,DeviceCreationParameter*>::iterator iter = dependencies.begin(); |
449 |
|
|
String s; |
450 |
|
|
for (; iter != dependencies.end(); iter++) { |
451 |
|
|
if (s != "") s += ","; |
452 |
|
|
s += iter->first; |
453 |
|
|
} |
454 |
|
|
return s; |
455 |
|
|
} |
456 |
|
|
|
457 |
|
|
optional<String> DeviceCreationParameter::Default() { |
458 |
|
|
std::map<String,String> Parameters; // empty parameters vector |
459 |
|
|
return Default(Parameters); |
460 |
|
|
} |
461 |
|
|
|
462 |
|
|
optional<String> DeviceCreationParameter::RangeMin() { |
463 |
|
|
std::map<String,String> Parameters; // empty parameters vector |
464 |
|
|
return RangeMin(Parameters); |
465 |
|
|
} |
466 |
|
|
|
467 |
|
|
optional<String> DeviceCreationParameter::RangeMax() { |
468 |
|
|
std::map<String,String> Parameters; // empty parameters vector |
469 |
|
|
return RangeMax(Parameters); |
470 |
|
|
} |
471 |
|
|
|
472 |
|
|
optional<String> DeviceCreationParameter::Possibilities() { |
473 |
|
|
std::map<String,String> Parameters; // empty parameters vector |
474 |
|
|
return Possibilities(Parameters); |
475 |
|
|
} |
476 |
|
|
|
477 |
|
|
|
478 |
|
|
|
479 |
|
|
// *************** DeviceCreationParameterBool *************** |
480 |
|
|
// * |
481 |
|
|
|
482 |
senkov |
174 |
DeviceCreationParameterBool::DeviceCreationParameterBool(bool bVal) : DeviceCreationParameter() { |
483 |
schoenebeck |
123 |
this->bVal = bVal; |
484 |
|
|
} |
485 |
|
|
|
486 |
schoenebeck |
880 |
DeviceCreationParameterBool::DeviceCreationParameterBool(String val) throw (Exception) { |
487 |
schoenebeck |
123 |
this->bVal = __parse_bool(val); |
488 |
|
|
} |
489 |
|
|
|
490 |
|
|
void DeviceCreationParameterBool::InitWithDefault() { |
491 |
|
|
std::map<String,String> Parameters; // empty parameters vector |
492 |
|
|
optional<bool> defaultval = DefaultAsBool(Parameters); |
493 |
|
|
this->bVal = (defaultval) ? *defaultval : false; |
494 |
|
|
} |
495 |
|
|
|
496 |
|
|
String DeviceCreationParameterBool::Type() { |
497 |
|
|
return "BOOL"; |
498 |
|
|
} |
499 |
|
|
|
500 |
|
|
bool DeviceCreationParameterBool::Multiplicity() { |
501 |
|
|
return false; |
502 |
|
|
} |
503 |
|
|
|
504 |
|
|
optional<String> DeviceCreationParameterBool::Default(std::map<String,String> Parameters) { |
505 |
|
|
optional<bool> defaultval = DefaultAsBool(Parameters); |
506 |
|
|
if (!defaultval) return optional<String>::nothing; |
507 |
schoenebeck |
214 |
return (*defaultval) ? "true" : "false"; |
508 |
schoenebeck |
123 |
} |
509 |
|
|
|
510 |
|
|
optional<String> DeviceCreationParameterBool::RangeMin(std::map<String,String> Parameters) { |
511 |
|
|
return optional<String>::nothing; |
512 |
|
|
} |
513 |
|
|
|
514 |
|
|
optional<String> DeviceCreationParameterBool::RangeMax(std::map<String,String> Parameters) { |
515 |
|
|
return optional<String>::nothing; |
516 |
|
|
} |
517 |
|
|
|
518 |
|
|
optional<String> DeviceCreationParameterBool::Possibilities(std::map<String,String> Parameters) { |
519 |
|
|
return optional<String>::nothing; |
520 |
|
|
} |
521 |
|
|
|
522 |
|
|
String DeviceCreationParameterBool::Value() { |
523 |
schoenebeck |
214 |
return (ValueAsBool()) ? "true" : "false"; |
524 |
schoenebeck |
123 |
} |
525 |
|
|
|
526 |
schoenebeck |
880 |
void DeviceCreationParameterBool::SetValue(String val) throw (Exception) { |
527 |
|
|
if (Fix()) throw Exception("Device parameter is read only"); |
528 |
schoenebeck |
123 |
int b = __parse_bool(val); |
529 |
|
|
SetValue(b); |
530 |
|
|
} |
531 |
|
|
|
532 |
|
|
bool DeviceCreationParameterBool::ValueAsBool() { |
533 |
|
|
return bVal; |
534 |
|
|
} |
535 |
|
|
|
536 |
schoenebeck |
880 |
void DeviceCreationParameterBool::SetValue(bool b) throw (Exception) { |
537 |
|
|
if (Fix()) throw Exception("Device parameter is read only"); |
538 |
schoenebeck |
214 |
OnSetValue(b); |
539 |
schoenebeck |
123 |
bVal = b; |
540 |
|
|
} |
541 |
|
|
|
542 |
|
|
|
543 |
|
|
|
544 |
|
|
// *************** DeviceCreationParameterInt *************** |
545 |
|
|
// * |
546 |
|
|
|
547 |
senkov |
174 |
DeviceCreationParameterInt::DeviceCreationParameterInt(int iVal) : DeviceCreationParameter() { |
548 |
schoenebeck |
123 |
this->iVal = iVal; |
549 |
|
|
} |
550 |
|
|
|
551 |
schoenebeck |
880 |
DeviceCreationParameterInt::DeviceCreationParameterInt(String val) throw (Exception) { |
552 |
schoenebeck |
123 |
this->iVal = __parse_int(val); |
553 |
|
|
} |
554 |
|
|
|
555 |
|
|
void DeviceCreationParameterInt::InitWithDefault() { |
556 |
|
|
std::map<String,String> Parameters; // empty parameters vector |
557 |
|
|
optional<int> i = DefaultAsInt(Parameters); |
558 |
|
|
this->iVal = (i) ? *i : 0; |
559 |
|
|
} |
560 |
|
|
|
561 |
|
|
String DeviceCreationParameterInt::Type() { |
562 |
|
|
return "INT"; |
563 |
|
|
} |
564 |
|
|
|
565 |
|
|
bool DeviceCreationParameterInt::Multiplicity() { |
566 |
|
|
return false; |
567 |
|
|
} |
568 |
|
|
|
569 |
|
|
optional<String> DeviceCreationParameterInt::Default(std::map<String,String> Parameters) { |
570 |
|
|
optional<int> defaultval = DefaultAsInt(Parameters); |
571 |
|
|
if (!defaultval) return optional<String>::nothing; |
572 |
|
|
return ToString(*defaultval); |
573 |
|
|
} |
574 |
|
|
|
575 |
|
|
optional<String> DeviceCreationParameterInt::RangeMin(std::map<String,String> Parameters) { |
576 |
|
|
optional<int> rangemin = RangeMinAsInt(Parameters); |
577 |
|
|
if (!rangemin) return optional<String>::nothing; |
578 |
schoenebeck |
226 |
return ToString(*rangemin); |
579 |
schoenebeck |
123 |
} |
580 |
|
|
|
581 |
|
|
optional<String> DeviceCreationParameterInt::RangeMax(std::map<String,String> Parameters) { |
582 |
|
|
optional<int> rangemax = RangeMaxAsInt(Parameters); |
583 |
|
|
if (!rangemax) return optional<String>::nothing; |
584 |
schoenebeck |
226 |
return ToString(*rangemax); |
585 |
schoenebeck |
123 |
} |
586 |
|
|
|
587 |
|
|
optional<String> DeviceCreationParameterInt::Possibilities(std::map<String,String> Parameters) { |
588 |
|
|
std::vector<int> possibilities = PossibilitiesAsInt(Parameters); |
589 |
|
|
if (possibilities.empty()) return optional<String>::nothing; |
590 |
|
|
|
591 |
|
|
std::vector<int>::iterator iter = possibilities.begin(); |
592 |
|
|
std::stringstream ss; |
593 |
|
|
while (iter != possibilities.end()) { |
594 |
|
|
if (ss.str() != "") ss << ","; |
595 |
|
|
ss << *iter; |
596 |
|
|
iter++; |
597 |
|
|
} |
598 |
|
|
return ss.str(); |
599 |
|
|
} |
600 |
|
|
|
601 |
|
|
String DeviceCreationParameterInt::Value() { |
602 |
|
|
return ToString(ValueAsInt()); |
603 |
|
|
} |
604 |
|
|
|
605 |
schoenebeck |
880 |
void DeviceCreationParameterInt::SetValue(String val) throw (Exception) { |
606 |
|
|
if (Fix()) throw Exception("Device parameter is read only"); |
607 |
schoenebeck |
123 |
int i = __parse_int(val); |
608 |
schoenebeck |
880 |
//if (RangeMinAsInt() && i < *RangeMinAsInt()) throw Exception("Invalid device parameter value: too small"); |
609 |
|
|
//if (RangeMaxAsInt() && i > *RangeMaxAsInt()) throw Exception("Invalid device parameter value: too big"); |
610 |
schoenebeck |
123 |
/*if (PossibilitiesAsInt()) { |
611 |
|
|
bool valid = false; |
612 |
|
|
std::vector<int>* pPossibilities = PossibilitiesAsInt(); |
613 |
|
|
std::vector<int>::iterator iter = pPossibilities->begin(); |
614 |
|
|
while (iter != pPossibilities->end()) { |
615 |
|
|
if (i == *iter) { |
616 |
|
|
valid = true; |
617 |
|
|
break; |
618 |
|
|
} |
619 |
|
|
iter++; |
620 |
|
|
} |
621 |
schoenebeck |
880 |
if (!valid) throw Exception("Invalid Device parameter value: not in set of possible values"); |
622 |
schoenebeck |
123 |
}*/ |
623 |
|
|
SetValue(i); |
624 |
|
|
} |
625 |
|
|
|
626 |
|
|
int DeviceCreationParameterInt::ValueAsInt() { |
627 |
|
|
return iVal; |
628 |
|
|
} |
629 |
|
|
|
630 |
schoenebeck |
880 |
void DeviceCreationParameterInt::SetValue(int i) throw (Exception) { |
631 |
|
|
if (Fix()) throw Exception("Device parameter is read only"); |
632 |
schoenebeck |
214 |
OnSetValue(i); |
633 |
schoenebeck |
123 |
iVal = i; |
634 |
|
|
} |
635 |
|
|
|
636 |
|
|
|
637 |
|
|
|
638 |
|
|
// *************** DeviceCreationParameterFloat *************** |
639 |
|
|
// * |
640 |
|
|
|
641 |
senkov |
174 |
DeviceCreationParameterFloat::DeviceCreationParameterFloat(float fVal) : DeviceCreationParameter() { |
642 |
schoenebeck |
123 |
this->fVal = fVal; |
643 |
|
|
} |
644 |
|
|
|
645 |
schoenebeck |
880 |
DeviceCreationParameterFloat::DeviceCreationParameterFloat(String val) throw (Exception) { |
646 |
schoenebeck |
123 |
this->fVal = __parse_float(val); |
647 |
|
|
} |
648 |
|
|
|
649 |
|
|
void DeviceCreationParameterFloat::InitWithDefault() { |
650 |
|
|
std::map<String,String> Parameters; // empty parameters vector |
651 |
|
|
optional<float> f = DefaultAsFloat(Parameters); |
652 |
|
|
this->fVal = (f) ? *f : 0.0f; |
653 |
|
|
} |
654 |
|
|
|
655 |
|
|
String DeviceCreationParameterFloat::Type() { |
656 |
|
|
return "FLOAT"; |
657 |
|
|
} |
658 |
|
|
|
659 |
|
|
bool DeviceCreationParameterFloat::Multiplicity() { |
660 |
|
|
return false; |
661 |
|
|
} |
662 |
|
|
|
663 |
|
|
optional<String> DeviceCreationParameterFloat::Default(std::map<String,String> Parameters) { |
664 |
|
|
optional<float> defaultval = DefaultAsFloat(Parameters); |
665 |
|
|
if (!defaultval) return optional<String>::nothing; |
666 |
|
|
return ToString(*defaultval); |
667 |
|
|
} |
668 |
|
|
|
669 |
|
|
optional<String> DeviceCreationParameterFloat::RangeMin(std::map<String,String> Parameters) { |
670 |
|
|
optional<float> rangemin = RangeMinAsFloat(Parameters); |
671 |
|
|
if (!rangemin) return optional<String>::nothing; |
672 |
|
|
return ToString(*rangemin); |
673 |
|
|
} |
674 |
|
|
|
675 |
|
|
optional<String> DeviceCreationParameterFloat::RangeMax(std::map<String,String> Parameters) { |
676 |
|
|
optional<float> rangemax = RangeMaxAsFloat(Parameters); |
677 |
|
|
if (!rangemax) return optional<String>::nothing; |
678 |
|
|
return ToString(*rangemax); |
679 |
|
|
} |
680 |
|
|
|
681 |
|
|
optional<String> DeviceCreationParameterFloat::Possibilities(std::map<String,String> Parameters) { |
682 |
|
|
std::vector<float> possibilities = PossibilitiesAsFloat(Parameters); |
683 |
|
|
if (possibilities.empty()) return optional<String>::nothing; |
684 |
|
|
|
685 |
|
|
std::vector<float>::iterator iter = possibilities.begin(); |
686 |
|
|
std::stringstream ss; |
687 |
|
|
while (iter != possibilities.end()) { |
688 |
|
|
if (ss.str() != "") ss << ","; |
689 |
|
|
ss << *iter; |
690 |
|
|
iter++; |
691 |
|
|
} |
692 |
|
|
return ss.str(); |
693 |
|
|
} |
694 |
|
|
|
695 |
|
|
String DeviceCreationParameterFloat::Value() { |
696 |
|
|
return ToString(ValueAsFloat()); |
697 |
|
|
} |
698 |
|
|
|
699 |
schoenebeck |
880 |
void DeviceCreationParameterFloat::SetValue(String val) throw (Exception) { |
700 |
|
|
if (Fix()) throw Exception("Device parameter is read only"); |
701 |
schoenebeck |
123 |
float f = __parse_float(val); |
702 |
schoenebeck |
880 |
//if (RangeMinAsFloat() && i < *RangeMinAsFloat()) throw Exception("Invalid device parameter value: too small"); |
703 |
|
|
//if (RangeMaxAsFloat() && i > *RangeMaxAsFloat()) throw Exception("Invalid device parameter value: too big"); |
704 |
schoenebeck |
123 |
/*if (PossibilitiesAsFloat()) { |
705 |
|
|
bool valid = false; |
706 |
|
|
std::vector<float>* pPossibilities = PossibilitiesAsFloat(); |
707 |
|
|
std::vector<float>::iterator iter = pPossibilities->begin(); |
708 |
|
|
while (iter != pPossibilities->end()) { |
709 |
|
|
if (f == *iter) { |
710 |
|
|
valid = true; |
711 |
|
|
break; |
712 |
|
|
} |
713 |
|
|
iter++; |
714 |
|
|
} |
715 |
schoenebeck |
880 |
if (!valid) throw Exception("Invalid Device parameter value: not in set of possible values"); |
716 |
schoenebeck |
123 |
}*/ |
717 |
|
|
SetValue(f); |
718 |
|
|
} |
719 |
|
|
|
720 |
|
|
float DeviceCreationParameterFloat::ValueAsFloat() { |
721 |
|
|
return fVal; |
722 |
|
|
} |
723 |
|
|
|
724 |
schoenebeck |
880 |
void DeviceCreationParameterFloat::SetValue(float f) throw (Exception) { |
725 |
|
|
if (Fix()) throw Exception("Device parameter is read only"); |
726 |
schoenebeck |
214 |
OnSetValue(f); |
727 |
schoenebeck |
123 |
fVal = f; |
728 |
|
|
} |
729 |
|
|
|
730 |
|
|
|
731 |
|
|
|
732 |
|
|
// *************** DeviceCreationParameterString *************** |
733 |
|
|
// * |
734 |
|
|
|
735 |
senkov |
174 |
DeviceCreationParameterString::DeviceCreationParameterString(String sVal) : DeviceCreationParameter() { |
736 |
schoenebeck |
486 |
this->sVal = __parse_string(sVal); |
737 |
schoenebeck |
123 |
} |
738 |
|
|
|
739 |
|
|
void DeviceCreationParameterString::InitWithDefault() { |
740 |
|
|
std::map<String,String> Parameters; // empty parameters vector |
741 |
schoenebeck |
212 |
optional<String> defaulval = DefaultAsString(Parameters); |
742 |
schoenebeck |
123 |
if (defaulval) this->sVal = *defaulval; |
743 |
|
|
else this->sVal = ""; |
744 |
|
|
} |
745 |
|
|
|
746 |
|
|
String DeviceCreationParameterString::Type() { |
747 |
|
|
return "STRING"; |
748 |
|
|
} |
749 |
|
|
|
750 |
|
|
bool DeviceCreationParameterString::Multiplicity() { |
751 |
|
|
return false; |
752 |
|
|
} |
753 |
|
|
|
754 |
schoenebeck |
212 |
optional<String> DeviceCreationParameterString::Default(std::map<String,String> Parameters) { |
755 |
|
|
optional<String> defaultval = DefaultAsString(Parameters); |
756 |
|
|
if (!defaultval) return optional<String>::nothing; |
757 |
|
|
return "'" + *defaultval + "'"; |
758 |
|
|
} |
759 |
|
|
|
760 |
schoenebeck |
123 |
optional<String> DeviceCreationParameterString::RangeMin(std::map<String,String> Parameters) { |
761 |
|
|
return optional<String>::nothing; |
762 |
|
|
} |
763 |
|
|
|
764 |
|
|
optional<String> DeviceCreationParameterString::RangeMax(std::map<String,String> Parameters) { |
765 |
|
|
return optional<String>::nothing; |
766 |
|
|
} |
767 |
|
|
|
768 |
|
|
optional<String> DeviceCreationParameterString::Possibilities(std::map<String,String> Parameters) { |
769 |
|
|
std::vector<String> possibilities = PossibilitiesAsString(Parameters); |
770 |
|
|
if (possibilities.empty()) return optional<String>::nothing; |
771 |
|
|
|
772 |
|
|
std::stringstream ss; |
773 |
|
|
std::vector<String>::iterator iter = possibilities.begin(); |
774 |
|
|
while (iter != possibilities.end()) { |
775 |
|
|
if (ss.str() != "") ss << ","; |
776 |
|
|
ss << "'" << *iter << "'"; |
777 |
|
|
iter++; |
778 |
|
|
} |
779 |
|
|
return ss.str(); |
780 |
|
|
} |
781 |
|
|
|
782 |
|
|
String DeviceCreationParameterString::Value() { |
783 |
schoenebeck |
214 |
return "\'" + ValueAsString() + "\'"; |
784 |
schoenebeck |
123 |
} |
785 |
|
|
|
786 |
schoenebeck |
880 |
void DeviceCreationParameterString::SetValue(String val) throw (Exception) { |
787 |
|
|
if (Fix()) throw Exception("Device parameter is read only"); |
788 |
schoenebeck |
214 |
SetValueAsString(__parse_string(val)); |
789 |
|
|
} |
790 |
|
|
|
791 |
|
|
String DeviceCreationParameterString::ValueAsString() { |
792 |
|
|
return sVal; |
793 |
|
|
} |
794 |
|
|
|
795 |
schoenebeck |
880 |
void DeviceCreationParameterString::SetValueAsString(String val) throw (Exception) { |
796 |
|
|
if (val.find("\'") != String::npos) throw Exception("Character -> \' <- not allowed"); |
797 |
|
|
if (val.find("\"") != String::npos) throw Exception("Character -> \" <- not allowed"); |
798 |
schoenebeck |
123 |
OnSetValue(val); |
799 |
|
|
sVal = val; |
800 |
|
|
} |
801 |
|
|
|
802 |
|
|
|
803 |
|
|
|
804 |
|
|
// *************** DeviceCreationParameterStrings *************** |
805 |
|
|
// * |
806 |
|
|
|
807 |
senkov |
174 |
DeviceCreationParameterStrings::DeviceCreationParameterStrings(std::vector<String> sVals) : DeviceCreationParameter() { |
808 |
schoenebeck |
123 |
this->sVals = sVals; |
809 |
|
|
} |
810 |
|
|
|
811 |
schoenebeck |
880 |
DeviceCreationParameterStrings::DeviceCreationParameterStrings(String val) throw (Exception) { |
812 |
schoenebeck |
123 |
this->sVals = __parse_strings(val); |
813 |
|
|
} |
814 |
|
|
|
815 |
|
|
void DeviceCreationParameterStrings::InitWithDefault() { |
816 |
|
|
std::map<String,String> Parameters; // empty parameters vector |
817 |
|
|
optional<std::vector<String> > defaultval = DefaultAsStrings(Parameters); |
818 |
|
|
this->sVals = (defaultval) ? *defaultval : std::vector<String>(); |
819 |
|
|
} |
820 |
|
|
|
821 |
|
|
String DeviceCreationParameterStrings::Type() { |
822 |
|
|
return "STRING"; |
823 |
|
|
} |
824 |
|
|
|
825 |
|
|
bool DeviceCreationParameterStrings::Multiplicity() { |
826 |
|
|
return true; |
827 |
|
|
} |
828 |
|
|
|
829 |
schoenebeck |
212 |
optional<String> DeviceCreationParameterStrings::Default(std::map<String,String> Parameters) { |
830 |
|
|
std::vector<String> defaultval = DefaultAsStrings(Parameters); |
831 |
|
|
if (defaultval.empty()) return optional<String>::nothing; |
832 |
|
|
String result; |
833 |
|
|
std::vector<String>::iterator iter = defaultval.begin(); |
834 |
|
|
for (; iter != defaultval.end(); iter++) { |
835 |
|
|
if (result != "") result += ","; |
836 |
|
|
result += ("'" + *iter + "'"); |
837 |
|
|
} |
838 |
|
|
return result; |
839 |
|
|
} |
840 |
|
|
|
841 |
schoenebeck |
123 |
optional<String> DeviceCreationParameterStrings::RangeMin(std::map<String,String> Parameters) { |
842 |
|
|
return optional<String>::nothing; |
843 |
|
|
} |
844 |
|
|
|
845 |
|
|
optional<String> DeviceCreationParameterStrings::RangeMax(std::map<String,String> Parameters) { |
846 |
|
|
return optional<String>::nothing; |
847 |
|
|
} |
848 |
|
|
|
849 |
|
|
optional<String> DeviceCreationParameterStrings::Possibilities(std::map<String,String> Parameters) { |
850 |
|
|
std::vector<String> possibilities = PossibilitiesAsString(Parameters); |
851 |
|
|
if (possibilities.empty()) return optional<String>::nothing; |
852 |
|
|
|
853 |
|
|
std::stringstream ss; |
854 |
|
|
std::vector<String>::iterator iter = possibilities.begin(); |
855 |
|
|
while (iter != possibilities.end()) { |
856 |
|
|
if (ss.str() != "") ss << ","; |
857 |
|
|
ss << "'" << *iter << "'"; |
858 |
|
|
iter++; |
859 |
|
|
} |
860 |
|
|
return ss.str(); |
861 |
|
|
} |
862 |
|
|
|
863 |
|
|
String DeviceCreationParameterStrings::Value() { |
864 |
|
|
String result; |
865 |
|
|
std::vector<String>::iterator iter = this->sVals.begin(); |
866 |
|
|
while (iter != this->sVals.end()) { |
867 |
|
|
if (result != "") result += ","; |
868 |
|
|
result += "'" + *iter + "'"; |
869 |
|
|
iter++; |
870 |
|
|
} |
871 |
|
|
return result; |
872 |
|
|
} |
873 |
|
|
|
874 |
schoenebeck |
880 |
void DeviceCreationParameterStrings::SetValue(String val) throw (Exception) { |
875 |
|
|
if (Fix()) throw Exception("Device parameter is read only"); |
876 |
schoenebeck |
123 |
std::vector<String> vS = __parse_strings(val); |
877 |
|
|
SetValue(vS); |
878 |
|
|
} |
879 |
|
|
|
880 |
|
|
std::vector<String> DeviceCreationParameterStrings::ValueAsStrings() { |
881 |
|
|
return sVals; |
882 |
|
|
} |
883 |
|
|
|
884 |
schoenebeck |
880 |
void DeviceCreationParameterStrings::SetValue(std::vector<String> vS) throw (Exception) { |
885 |
|
|
if (Fix()) throw Exception("Device parameter is read only"); |
886 |
schoenebeck |
214 |
OnSetValue(vS); |
887 |
schoenebeck |
123 |
sVals = vS; |
888 |
|
|
} |
889 |
|
|
|
890 |
|
|
} // namespace LinuxSampler |