/[svn]/linuxsampler/trunk/src/scriptvm/CoreVMFunctions.h
ViewVC logotype

Contents of /linuxsampler/trunk/src/scriptvm/CoreVMFunctions.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3590 - (show annotations) (download) (as text)
Mon Sep 2 09:03:31 2019 UTC (4 years, 7 months ago) by schoenebeck
File MIME type: text/x-c++hdr
File size: 32929 byte(s)
NKSP: Implemented common real number math functions.

* Added built-in real number functions "round()", "ceil()", "floor()",
  "sqrt()", "log()", "log2()", "log10()", "exp()", "pow()", "sin()",
  "cos()", "tan()", "asin()", "acos()", "atan()".

* Added built-in script real number constant "~NI_MATH_PI".

* Added built-in script real number constant "~NI_MATH_E".

* Added NKSP test cases for built-in functions "round()", "ceil()",
  "floor()", "sqrt()", "log()", "log2()", "log10()", "exp()", "pow()",
  "sin()", "cos()", "tan()", "asin()", "acos()", "atan()".

* Bumped version (2.1.1.svn14).

1 /*
2 * Copyright (c) 2014-2019 Christian Schoenebeck
3 *
4 * http://www.linuxsampler.org
5 *
6 * This file is part of LinuxSampler and released under the same terms.
7 * See README file for details.
8 */
9
10 #ifndef LS_COREVMFUNCTIONS_H
11 #define LS_COREVMFUNCTIONS_H
12
13 #include "../common/global.h"
14 #include "common.h"
15
16 namespace LinuxSampler {
17
18 class ScriptVM;
19
20 ///////////////////////////////////////////////////////////////////////////
21 // convenience base classes for built-in script functions ...
22
23 /**
24 * An instance of this class is returned by built-in function implementations
25 * which do not return a function return value.
26 */
27 class VMEmptyResult FINAL : public VMFnResult, public VMExpr {
28 public:
29 StmtFlags_t flags; ///< general completion status (i.e. success or failure) of the function call
30
31 VMEmptyResult() : flags(STMT_SUCCESS) {}
32 ExprType_t exprType() const OVERRIDE { return EMPTY_EXPR; }
33 VMExpr* resultValue() OVERRIDE { return this; }
34 StmtFlags_t resultFlags() OVERRIDE { return flags; }
35 bool isConstExpr() const OVERRIDE { return false; }
36 };
37
38 /**
39 * An instance of this class is returned by built-in function implementations
40 * which return an integer value as function return value.
41 */
42 class VMIntResult FINAL : public VMFnResult, public VMIntExpr {
43 public:
44 StmtFlags_t flags; ///< general completion status (i.e. success or failure) of the function call
45 vmint value; ///< result value of the function call
46 vmfloat unitPrefixFactor; ///< unit factor of result value of the function call
47
48 VMIntResult() : flags(STMT_SUCCESS), value(0), unitPrefixFactor(VM_NO_FACTOR) {}
49 vmint evalInt() OVERRIDE { return value; }
50 VMExpr* resultValue() OVERRIDE { return this; }
51 StmtFlags_t resultFlags() OVERRIDE { return flags; }
52 bool isConstExpr() const OVERRIDE { return false; }
53 vmfloat unitFactor() const OVERRIDE { return unitPrefixFactor; }
54 StdUnit_t unitType() const OVERRIDE { return VM_NO_UNIT; } // actually never called, VMFunction::returnUnitType() is always used instead
55 bool isFinal() const OVERRIDE { return false; } // actually never called, VMFunction::returnsFinal() is always used instead
56 };
57
58 /**
59 * An instance of this class is returned by built-in function implementations
60 * which return a real number (floating point) value as function return value.
61 */
62 class VMRealResult FINAL : public VMFnResult, public VMRealExpr {
63 public:
64 StmtFlags_t flags; ///< general completion status (i.e. success or failure) of the function call
65 vmfloat value; ///< result value of the function call
66 vmfloat unitPrefixFactor; ///< unit factor of result value of the function call
67
68 VMRealResult() : flags(STMT_SUCCESS), value(0), unitPrefixFactor(VM_NO_FACTOR) {}
69 vmfloat evalReal() OVERRIDE { return value; }
70 VMExpr* resultValue() OVERRIDE { return this; }
71 StmtFlags_t resultFlags() OVERRIDE { return flags; }
72 bool isConstExpr() const OVERRIDE { return false; }
73 vmfloat unitFactor() const OVERRIDE { return unitPrefixFactor; }
74 StdUnit_t unitType() const OVERRIDE { return VM_NO_UNIT; } // actually never called, VMFunction::returnUnitType() is always used instead
75 bool isFinal() const OVERRIDE { return false; } // actually never called, VMFunction::returnsFinal() is always used instead
76 };
77
78 /**
79 * An instance of this class is returned by built-in function implementations
80 * which return a string value as function return value.
81 */
82 class VMStringResult FINAL : public VMFnResult, public VMStringExpr {
83 public:
84 StmtFlags_t flags; ///< general completion status (i.e. success or failure) of the function call
85 String value; ///< result value of the function call
86
87 VMStringResult() : flags(STMT_SUCCESS) {}
88 String evalStr() OVERRIDE { return value; }
89 VMExpr* resultValue() OVERRIDE { return this; }
90 StmtFlags_t resultFlags() OVERRIDE { return flags; }
91 bool isConstExpr() const OVERRIDE { return false; }
92 };
93
94 /**
95 * Abstract base class for built-in script functions which do not return any
96 * function return value (void).
97 */
98 class VMEmptyResultFunction : public VMFunction {
99 protected:
100 virtual ~VMEmptyResultFunction() {}
101 ExprType_t returnType(VMFnArgs* args) OVERRIDE { return EMPTY_EXPR; }
102 StdUnit_t returnUnitType(VMFnArgs* args) OVERRIDE { return VM_NO_UNIT; }
103 bool returnsFinal(VMFnArgs* args) OVERRIDE { return false; }
104 VMFnResult* errorResult();
105 VMFnResult* successResult();
106 bool modifiesArg(vmint iArg) const OVERRIDE { return false; }
107 protected:
108 VMEmptyResult result;
109 };
110
111 struct VMIntFnResDef {
112 vmint value = 0; //NOTE: sequence matters! Since this is usually initialized with VMIntExpr::evalInt() it should be before member unitFactor, since the latter is usually initialized with VMIntExpr::unitFactor() which does not evaluate the expression.
113 vmfloat unitFactor = VM_NO_FACTOR;
114 };
115
116 struct VMRealFnResDef {
117 vmfloat value = vmfloat(0); //NOTE: sequence matters! Since this is usually initialized with VMRealExpr::evalReal() it should be before member unitFactor, since the latter is usually initialized with VMRealExpr::unitFactor() which does not evaluate the expression.
118 vmfloat unitFactor = VM_NO_FACTOR;
119 };
120
121 /**
122 * Abstract base class for built-in script functions which return an integer
123 * (scalar) as their function return value.
124 */
125 class VMIntResultFunction : public VMFunction {
126 protected:
127 virtual ~VMIntResultFunction() {}
128 ExprType_t returnType(VMFnArgs* args) OVERRIDE { return INT_EXPR; }
129 VMFnResult* errorResult(vmint i = 0);
130 VMFnResult* errorResult(VMIntFnResDef res);
131 VMFnResult* successResult(vmint i = 0);
132 VMFnResult* successResult(VMIntFnResDef res);
133 bool modifiesArg(vmint iArg) const OVERRIDE { return false; }
134 protected:
135 VMIntResult result;
136 };
137
138 /**
139 * Abstract base class for built-in script functions which return a real number
140 * (floating point scalar) as their function return value.
141 */
142 class VMRealResultFunction : public VMFunction {
143 protected:
144 virtual ~VMRealResultFunction() {}
145 ExprType_t returnType(VMFnArgs* args) OVERRIDE { return REAL_EXPR; }
146 VMFnResult* errorResult(vmfloat f = 0);
147 VMFnResult* errorResult(VMRealFnResDef res);
148 VMFnResult* successResult(vmfloat f = 0);
149 VMFnResult* successResult(VMRealFnResDef res);
150 bool modifiesArg(vmint iArg) const OVERRIDE { return false; }
151 protected:
152 VMRealResult result;
153 };
154
155 /**
156 * Abstract base class for built-in script functions which return a string as
157 * their function return value.
158 */
159 class VMStringResultFunction : public VMFunction {
160 protected:
161 virtual ~VMStringResultFunction() {}
162 ExprType_t returnType(VMFnArgs* args) OVERRIDE { return STRING_EXPR; }
163 VMFnResult* errorResult(const String& s = "");
164 VMFnResult* successResult(const String& s = "");
165 bool modifiesArg(vmint iArg) const OVERRIDE { return false; }
166 protected:
167 VMStringResult result;
168 };
169
170 /**
171 * Abstract base class for built-in script functions which either return an
172 * integer or a real number (floating point scalar) as their function return
173 * value. The actual return type is determined at parse time once after
174 * potential arguments were associated with the respective function call.
175 */
176 class VMNumberResultFunction : public VMFunction {
177 protected:
178 virtual ~VMNumberResultFunction() {}
179 VMFnResult* errorResult(vmint i);
180 VMFnResult* errorResult(vmfloat f);
181 VMFnResult* successResult(vmint i);
182 VMFnResult* successResult(vmfloat f);
183 VMFnResult* errorIntResult(VMIntFnResDef res);
184 VMFnResult* errorRealResult(VMRealFnResDef res);
185 VMFnResult* successIntResult(VMIntFnResDef res);
186 VMFnResult* successRealResult(VMRealFnResDef res);
187 bool modifiesArg(vmint iArg) const OVERRIDE { return false; }
188 protected:
189 VMIntResult intResult;
190 VMRealResult realResult;
191 };
192
193
194 ///////////////////////////////////////////////////////////////////////////
195 // implementations of core built-in script functions ...
196
197 /**
198 * Implements the built-in message() script function.
199 */
200 class CoreVMFunction_message FINAL : public VMEmptyResultFunction {
201 public:
202 vmint minRequiredArgs() const OVERRIDE { return 1; }
203 vmint maxAllowedArgs() const OVERRIDE { return 1; }
204 bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE;
205 VMFnResult* exec(VMFnArgs* args) OVERRIDE;
206 };
207
208 /**
209 * Implements the built-in exit() script function.
210 */
211 class CoreVMFunction_exit FINAL : public VMEmptyResultFunction {
212 public:
213 CoreVMFunction_exit(ScriptVM* vm) : vm(vm) {}
214 vmint minRequiredArgs() const OVERRIDE { return 0; }
215 vmint maxAllowedArgs() const OVERRIDE;
216 bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE;
217 bool acceptsArgUnitType(vmint iArg, StdUnit_t type) const OVERRIDE;
218 bool acceptsArgUnitPrefix(vmint iArg, StdUnit_t type) const OVERRIDE;
219 bool acceptsArgFinal(vmint iArg) const OVERRIDE;
220 VMFnResult* exec(VMFnArgs* args) OVERRIDE;
221 protected:
222 ScriptVM* vm;
223 };
224
225 /**
226 * Implements the built-in wait() script function.
227 */
228 class CoreVMFunction_wait : public VMEmptyResultFunction {
229 public:
230 CoreVMFunction_wait(ScriptVM* vm) : vm(vm) {}
231 vmint minRequiredArgs() const OVERRIDE { return 1; }
232 vmint maxAllowedArgs() const OVERRIDE { return 1; }
233 bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE;
234 bool acceptsArgUnitType(vmint iArg, StdUnit_t type) const OVERRIDE;
235 bool acceptsArgUnitPrefix(vmint iArg, StdUnit_t type) const OVERRIDE;
236 VMFnResult* exec(VMFnArgs* args) OVERRIDE;
237 protected:
238 ScriptVM* vm;
239 };
240
241 /**
242 * Implements the built-in abs() script function.
243 */
244 class CoreVMFunction_abs FINAL : public VMNumberResultFunction {
245 public:
246 ExprType_t returnType(VMFnArgs* args) OVERRIDE;
247 StdUnit_t returnUnitType(VMFnArgs* args) OVERRIDE;
248 bool returnsFinal(VMFnArgs* args) OVERRIDE;
249 vmint minRequiredArgs() const OVERRIDE { return 1; }
250 vmint maxAllowedArgs() const OVERRIDE { return 1; }
251 bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE;
252 bool acceptsArgUnitType(vmint iArg, StdUnit_t type) const OVERRIDE { return true; }
253 bool acceptsArgUnitPrefix(vmint iArg, StdUnit_t type) const OVERRIDE { return true; }
254 bool acceptsArgFinal(vmint iArg) const OVERRIDE { return true; }
255 VMFnResult* exec(VMFnArgs* args) OVERRIDE;
256 };
257
258 /**
259 * Implements the built-in random() script function.
260 */
261 class CoreVMFunction_random FINAL : public VMNumberResultFunction {
262 using Super = VMNumberResultFunction; // just an alias for the super class
263 public:
264 ExprType_t returnType(VMFnArgs* args) OVERRIDE;
265 StdUnit_t returnUnitType(VMFnArgs* args) OVERRIDE;
266 bool returnsFinal(VMFnArgs* args) OVERRIDE;
267 vmint minRequiredArgs() const OVERRIDE { return 2; }
268 vmint maxAllowedArgs() const OVERRIDE { return 2; }
269 bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE;
270 bool acceptsArgUnitType(vmint iArg, StdUnit_t type) const OVERRIDE { return true; }
271 bool acceptsArgUnitPrefix(vmint iArg, StdUnit_t type) const OVERRIDE { return true; }
272 bool acceptsArgFinal(vmint iArg) const OVERRIDE { return true; }
273 void checkArgs(VMFnArgs* args, std::function<void(String)> err,
274 std::function<void(String)> wrn) OVERRIDE;
275 VMFnResult* exec(VMFnArgs* args) OVERRIDE;
276 };
277
278 /**
279 * Implements the built-in num_elements() script function.
280 */
281 class CoreVMFunction_num_elements FINAL : public VMIntResultFunction {
282 public:
283 StdUnit_t returnUnitType(VMFnArgs* args) OVERRIDE { return VM_NO_UNIT; }
284 bool returnsFinal(VMFnArgs* args) OVERRIDE { return false; }
285 vmint minRequiredArgs() const OVERRIDE { return 1; }
286 vmint maxAllowedArgs() const OVERRIDE { return 1; }
287 bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE;
288 VMFnResult* exec(VMFnArgs* args) OVERRIDE;
289 };
290
291 /**
292 * Implements the built-in inc() script function.
293 */
294 class CoreVMFunction_inc FINAL : public VMIntResultFunction {
295 using Super = VMIntResultFunction; // just an alias for the super class
296 public:
297 StdUnit_t returnUnitType(VMFnArgs* args) OVERRIDE;
298 bool returnsFinal(VMFnArgs* args) OVERRIDE;
299 vmint minRequiredArgs() const OVERRIDE { return 1; }
300 vmint maxAllowedArgs() const OVERRIDE { return 1; }
301 bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE { return type == INT_EXPR; }
302 bool acceptsArgUnitType(vmint iArg, StdUnit_t type) const OVERRIDE { return true; }
303 bool acceptsArgUnitPrefix(vmint iArg, StdUnit_t type) const OVERRIDE { return true; }
304 bool acceptsArgFinal(vmint iArg) const OVERRIDE { return true; }
305 bool modifiesArg(vmint iArg) const OVERRIDE { return true; }
306 void checkArgs(VMFnArgs* args, std::function<void(String)> err,
307 std::function<void(String)> wrn) OVERRIDE;
308 VMFnResult* exec(VMFnArgs* args) OVERRIDE;
309 };
310
311 /**
312 * Implements the built-in dec() script function.
313 */
314 class CoreVMFunction_dec FINAL : public VMIntResultFunction {
315 using Super = VMIntResultFunction; // just an alias for the super class
316 public:
317 StdUnit_t returnUnitType(VMFnArgs* args) OVERRIDE;
318 bool returnsFinal(VMFnArgs* args) OVERRIDE;
319 vmint minRequiredArgs() const OVERRIDE { return 1; }
320 vmint maxAllowedArgs() const OVERRIDE { return 1; }
321 bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE { return type == INT_EXPR; }
322 bool acceptsArgUnitType(vmint iArg, StdUnit_t type) const OVERRIDE { return true; }
323 bool acceptsArgUnitPrefix(vmint iArg, StdUnit_t type) const OVERRIDE { return true; }
324 bool acceptsArgFinal(vmint iArg) const OVERRIDE { return true; }
325 bool modifiesArg(vmint iArg) const OVERRIDE { return true; }
326 void checkArgs(VMFnArgs* args, std::function<void(String)> err,
327 std::function<void(String)> wrn) OVERRIDE;
328 VMFnResult* exec(VMFnArgs* args) OVERRIDE;
329 };
330
331 /**
332 * Implements the built-in in_range() script function.
333 */
334 class CoreVMFunction_in_range FINAL : public VMIntResultFunction {
335 using Super = VMIntResultFunction; // just an alias for the super class
336 public:
337 StdUnit_t returnUnitType(VMFnArgs* args) OVERRIDE { return VM_NO_UNIT; }
338 bool returnsFinal(VMFnArgs* args) OVERRIDE { return false; }
339 vmint minRequiredArgs() const OVERRIDE { return 3; }
340 vmint maxAllowedArgs() const OVERRIDE { return 3; }
341 bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE;
342 bool acceptsArgUnitType(vmint iArg, StdUnit_t type) const OVERRIDE { return true; }
343 bool acceptsArgUnitPrefix(vmint iArg, StdUnit_t type) const OVERRIDE { return true; }
344 bool acceptsArgFinal(vmint iArg) const OVERRIDE { return true; }
345 void checkArgs(VMFnArgs* args, std::function<void(String)> err,
346 std::function<void(String)> wrn) OVERRIDE;
347 VMFnResult* exec(VMFnArgs* args) OVERRIDE;
348 };
349
350 /**
351 * Implements the built-in sh_left() script function.
352 */
353 class CoreVMFunction_sh_left FINAL : public VMIntResultFunction {
354 public:
355 StdUnit_t returnUnitType(VMFnArgs* args) OVERRIDE { return VM_NO_UNIT; }
356 bool returnsFinal(VMFnArgs* args) OVERRIDE;
357 vmint minRequiredArgs() const OVERRIDE { return 2; }
358 vmint maxAllowedArgs() const OVERRIDE { return 2; }
359 bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE { return type == INT_EXPR; }
360 bool acceptsArgFinal(vmint iArg) const OVERRIDE { return true; }
361 VMFnResult* exec(VMFnArgs* args) OVERRIDE;
362 };
363
364 /**
365 * Implements the built-in sh_right() script function.
366 */
367 class CoreVMFunction_sh_right FINAL : public VMIntResultFunction {
368 public:
369 StdUnit_t returnUnitType(VMFnArgs* args) OVERRIDE { return VM_NO_UNIT; }
370 bool returnsFinal(VMFnArgs* args) OVERRIDE;
371 vmint minRequiredArgs() const OVERRIDE { return 2; }
372 vmint maxAllowedArgs() const OVERRIDE { return 2; }
373 bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE { return type == INT_EXPR; }
374 bool acceptsArgFinal(vmint iArg) const OVERRIDE { return true; }
375 VMFnResult* exec(VMFnArgs* args) OVERRIDE;
376 };
377
378 /**
379 * Implements the built-in min() script function.
380 */
381 class CoreVMFunction_min FINAL : public VMNumberResultFunction {
382 using Super = VMNumberResultFunction; // just an alias for the super class
383 public:
384 ExprType_t returnType(VMFnArgs* args) OVERRIDE;
385 StdUnit_t returnUnitType(VMFnArgs* args) OVERRIDE;
386 bool returnsFinal(VMFnArgs* args) OVERRIDE;
387 vmint minRequiredArgs() const OVERRIDE { return 2; }
388 vmint maxAllowedArgs() const OVERRIDE { return 2; }
389 bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE;
390 bool acceptsArgUnitType(vmint iArg, StdUnit_t type) const OVERRIDE { return true; }
391 bool acceptsArgUnitPrefix(vmint iArg, StdUnit_t type) const OVERRIDE { return true; }
392 bool acceptsArgFinal(vmint iArg) const OVERRIDE { return true; }
393 void checkArgs(VMFnArgs* args, std::function<void(String)> err,
394 std::function<void(String)> wrn) OVERRIDE;
395 VMFnResult* exec(VMFnArgs* args) OVERRIDE;
396 };
397
398 /**
399 * Implements the built-in max() script function.
400 */
401 class CoreVMFunction_max FINAL : public VMNumberResultFunction {
402 using Super = VMNumberResultFunction; // just an alias for the super class
403 public:
404 ExprType_t returnType(VMFnArgs* args) OVERRIDE;
405 StdUnit_t returnUnitType(VMFnArgs* args) OVERRIDE;
406 bool returnsFinal(VMFnArgs* args) OVERRIDE;
407 vmint minRequiredArgs() const OVERRIDE { return 2; }
408 vmint maxAllowedArgs() const OVERRIDE { return 2; }
409 bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE;
410 bool acceptsArgUnitType(vmint iArg, StdUnit_t type) const OVERRIDE { return true; }
411 bool acceptsArgUnitPrefix(vmint iArg, StdUnit_t type) const OVERRIDE { return true; }
412 bool acceptsArgFinal(vmint iArg) const OVERRIDE { return true; }
413 void checkArgs(VMFnArgs* args, std::function<void(String)> err,
414 std::function<void(String)> wrn) OVERRIDE;
415 VMFnResult* exec(VMFnArgs* args) OVERRIDE;
416 };
417
418 /**
419 * Implements the built-in array_equal() script function.
420 */
421 class CoreVMFunction_array_equal FINAL : public VMIntResultFunction {
422 using Super = VMIntResultFunction; // just an alias for the super class
423 public:
424 StdUnit_t returnUnitType(VMFnArgs* args) OVERRIDE { return VM_NO_UNIT; }
425 bool returnsFinal(VMFnArgs* args) OVERRIDE { return false; }
426 vmint minRequiredArgs() const OVERRIDE { return 2; }
427 vmint maxAllowedArgs() const OVERRIDE { return 2; }
428 bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE;
429 void checkArgs(VMFnArgs* args, std::function<void(String)> err,
430 std::function<void(String)> wrn) OVERRIDE;
431 VMFnResult* exec(VMFnArgs* args) OVERRIDE;
432 };
433
434 /**
435 * Implements the built-in search() script function.
436 */
437 class CoreVMFunction_search FINAL : public VMIntResultFunction {
438 using Super = VMIntResultFunction; // just an alias for the super class
439 public:
440 StdUnit_t returnUnitType(VMFnArgs* args) OVERRIDE { return VM_NO_UNIT; }
441 bool returnsFinal(VMFnArgs* args) OVERRIDE { return false; }
442 vmint minRequiredArgs() const OVERRIDE { return 2; }
443 vmint maxAllowedArgs() const OVERRIDE { return 2; }
444 bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE;
445 void checkArgs(VMFnArgs* args, std::function<void(String)> err,
446 std::function<void(String)> wrn) OVERRIDE;
447 VMFnResult* exec(VMFnArgs* args) OVERRIDE;
448 };
449
450 /**
451 * Implements the built-in sort() script function.
452 */
453 class CoreVMFunction_sort FINAL : public VMEmptyResultFunction {
454 public:
455 vmint minRequiredArgs() const OVERRIDE { return 1; }
456 vmint maxAllowedArgs() const OVERRIDE { return 2; }
457 bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE;
458 bool modifiesArg(vmint iArg) const OVERRIDE { return iArg == 0; }
459 VMFnResult* exec(VMFnArgs* args) OVERRIDE;
460 };
461
462 /**
463 * Implements the built-in real_to_int() script function and its short hand
464 * variant int(). The behaviour of the two built-in script functions are
465 * identical ATM.
466 */
467 class CoreVMFunction_real_to_int FINAL : public VMIntResultFunction {
468 public:
469 StdUnit_t returnUnitType(VMFnArgs* args) OVERRIDE;
470 bool returnsFinal(VMFnArgs* args) OVERRIDE;
471 vmint minRequiredArgs() const OVERRIDE { return 1; }
472 vmint maxAllowedArgs() const OVERRIDE { return 1; }
473 bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE { return type == REAL_EXPR; }
474 bool acceptsArgUnitType(vmint iArg, StdUnit_t type) const OVERRIDE { return true; }
475 bool acceptsArgUnitPrefix(vmint iArg, StdUnit_t type) const OVERRIDE { return true; }
476 bool acceptsArgFinal(vmint iArg) const OVERRIDE { return true; }
477 VMFnResult* exec(VMFnArgs* args) OVERRIDE;
478 };
479
480 /**
481 * Implements the built-in int_to_real() script function and its short hand
482 * variant real(). The behaviour of the two built-in script functions are
483 * identical ATM.
484 */
485 class CoreVMFunction_int_to_real FINAL : public VMRealResultFunction {
486 public:
487 StdUnit_t returnUnitType(VMFnArgs* args) OVERRIDE;
488 bool returnsFinal(VMFnArgs* args) OVERRIDE;
489 vmint minRequiredArgs() const OVERRIDE { return 1; }
490 vmint maxAllowedArgs() const OVERRIDE { return 1; }
491 bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE { return type == INT_EXPR; }
492 bool acceptsArgUnitType(vmint iArg, StdUnit_t type) const OVERRIDE { return true; }
493 bool acceptsArgUnitPrefix(vmint iArg, StdUnit_t type) const OVERRIDE { return true; }
494 bool acceptsArgFinal(vmint iArg) const OVERRIDE { return true; }
495 VMFnResult* exec(VMFnArgs* args) OVERRIDE;
496 };
497
498 /**
499 * Implements the built-in round() script function.
500 */
501 class CoreVMFunction_round FINAL : public VMRealResultFunction {
502 public:
503 StdUnit_t returnUnitType(VMFnArgs* args) OVERRIDE;
504 bool returnsFinal(VMFnArgs* args) OVERRIDE;
505 vmint minRequiredArgs() const OVERRIDE { return 1; }
506 vmint maxAllowedArgs() const OVERRIDE { return 1; }
507 bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE { return type == REAL_EXPR; }
508 bool acceptsArgUnitType(vmint iArg, StdUnit_t type) const OVERRIDE { return true; }
509 bool acceptsArgUnitPrefix(vmint iArg, StdUnit_t type) const OVERRIDE { return true; }
510 bool acceptsArgFinal(vmint iArg) const OVERRIDE { return true; }
511 VMFnResult* exec(VMFnArgs* args) OVERRIDE;
512 };
513
514 /**
515 * Implements the built-in ceil() script function.
516 */
517 class CoreVMFunction_ceil FINAL : public VMRealResultFunction {
518 public:
519 StdUnit_t returnUnitType(VMFnArgs* args) OVERRIDE;
520 bool returnsFinal(VMFnArgs* args) OVERRIDE;
521 vmint minRequiredArgs() const OVERRIDE { return 1; }
522 vmint maxAllowedArgs() const OVERRIDE { return 1; }
523 bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE { return type == REAL_EXPR; }
524 bool acceptsArgUnitType(vmint iArg, StdUnit_t type) const OVERRIDE { return true; }
525 bool acceptsArgUnitPrefix(vmint iArg, StdUnit_t type) const OVERRIDE { return true; }
526 bool acceptsArgFinal(vmint iArg) const OVERRIDE { return true; }
527 VMFnResult* exec(VMFnArgs* args) OVERRIDE;
528 };
529
530 /**
531 * Implements the built-in floor() script function.
532 */
533 class CoreVMFunction_floor FINAL : public VMRealResultFunction {
534 public:
535 StdUnit_t returnUnitType(VMFnArgs* args) OVERRIDE;
536 bool returnsFinal(VMFnArgs* args) OVERRIDE;
537 vmint minRequiredArgs() const OVERRIDE { return 1; }
538 vmint maxAllowedArgs() const OVERRIDE { return 1; }
539 bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE { return type == REAL_EXPR; }
540 bool acceptsArgUnitType(vmint iArg, StdUnit_t type) const OVERRIDE { return true; }
541 bool acceptsArgUnitPrefix(vmint iArg, StdUnit_t type) const OVERRIDE { return true; }
542 bool acceptsArgFinal(vmint iArg) const OVERRIDE { return true; }
543 VMFnResult* exec(VMFnArgs* args) OVERRIDE;
544 };
545
546 /**
547 * Implements the built-in sqrt() script function.
548 */
549 class CoreVMFunction_sqrt FINAL : public VMRealResultFunction {
550 public:
551 StdUnit_t returnUnitType(VMFnArgs* args) OVERRIDE;
552 bool returnsFinal(VMFnArgs* args) OVERRIDE;
553 vmint minRequiredArgs() const OVERRIDE { return 1; }
554 vmint maxAllowedArgs() const OVERRIDE { return 1; }
555 bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE { return type == REAL_EXPR; }
556 bool acceptsArgUnitType(vmint iArg, StdUnit_t type) const OVERRIDE { return true; }
557 bool acceptsArgUnitPrefix(vmint iArg, StdUnit_t type) const OVERRIDE { return true; }
558 bool acceptsArgFinal(vmint iArg) const OVERRIDE { return true; }
559 VMFnResult* exec(VMFnArgs* args) OVERRIDE;
560 };
561
562 /**
563 * Implements the built-in log() script function.
564 */
565 class CoreVMFunction_log FINAL : public VMRealResultFunction {
566 public:
567 StdUnit_t returnUnitType(VMFnArgs* args) OVERRIDE;
568 bool returnsFinal(VMFnArgs* args) OVERRIDE;
569 vmint minRequiredArgs() const OVERRIDE { return 1; }
570 vmint maxAllowedArgs() const OVERRIDE { return 1; }
571 bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE { return type == REAL_EXPR; }
572 bool acceptsArgUnitType(vmint iArg, StdUnit_t type) const OVERRIDE { return true; }
573 bool acceptsArgUnitPrefix(vmint iArg, StdUnit_t type) const OVERRIDE { return true; }
574 bool acceptsArgFinal(vmint iArg) const OVERRIDE { return true; }
575 VMFnResult* exec(VMFnArgs* args) OVERRIDE;
576 };
577
578 /**
579 * Implements the built-in log2() script function.
580 */
581 class CoreVMFunction_log2 FINAL : public VMRealResultFunction {
582 public:
583 StdUnit_t returnUnitType(VMFnArgs* args) OVERRIDE;
584 bool returnsFinal(VMFnArgs* args) OVERRIDE;
585 vmint minRequiredArgs() const OVERRIDE { return 1; }
586 vmint maxAllowedArgs() const OVERRIDE { return 1; }
587 bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE { return type == REAL_EXPR; }
588 bool acceptsArgUnitType(vmint iArg, StdUnit_t type) const OVERRIDE { return true; }
589 bool acceptsArgUnitPrefix(vmint iArg, StdUnit_t type) const OVERRIDE { return true; }
590 bool acceptsArgFinal(vmint iArg) const OVERRIDE { return true; }
591 VMFnResult* exec(VMFnArgs* args) OVERRIDE;
592 };
593
594 /**
595 * Implements the built-in log10() script function.
596 */
597 class CoreVMFunction_log10 FINAL : public VMRealResultFunction {
598 public:
599 StdUnit_t returnUnitType(VMFnArgs* args) OVERRIDE;
600 bool returnsFinal(VMFnArgs* args) OVERRIDE;
601 vmint minRequiredArgs() const OVERRIDE { return 1; }
602 vmint maxAllowedArgs() const OVERRIDE { return 1; }
603 bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE { return type == REAL_EXPR; }
604 bool acceptsArgUnitType(vmint iArg, StdUnit_t type) const OVERRIDE { return true; }
605 bool acceptsArgUnitPrefix(vmint iArg, StdUnit_t type) const OVERRIDE { return true; }
606 bool acceptsArgFinal(vmint iArg) const OVERRIDE { return true; }
607 VMFnResult* exec(VMFnArgs* args) OVERRIDE;
608 };
609
610 /**
611 * Implements the built-in exp() script function.
612 */
613 class CoreVMFunction_exp FINAL : public VMRealResultFunction {
614 public:
615 StdUnit_t returnUnitType(VMFnArgs* args) OVERRIDE;
616 bool returnsFinal(VMFnArgs* args) OVERRIDE;
617 vmint minRequiredArgs() const OVERRIDE { return 1; }
618 vmint maxAllowedArgs() const OVERRIDE { return 1; }
619 bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE { return type == REAL_EXPR; }
620 bool acceptsArgUnitType(vmint iArg, StdUnit_t type) const OVERRIDE { return true; }
621 bool acceptsArgUnitPrefix(vmint iArg, StdUnit_t type) const OVERRIDE { return true; }
622 bool acceptsArgFinal(vmint iArg) const OVERRIDE { return true; }
623 VMFnResult* exec(VMFnArgs* args) OVERRIDE;
624 };
625
626 /**
627 * Implements the built-in pow() script function.
628 */
629 class CoreVMFunction_pow FINAL : public VMRealResultFunction {
630 using Super = VMRealResultFunction; // just an alias for the super class
631 public:
632 StdUnit_t returnUnitType(VMFnArgs* args) OVERRIDE;
633 bool returnsFinal(VMFnArgs* args) OVERRIDE;
634 vmint minRequiredArgs() const OVERRIDE { return 2; }
635 vmint maxAllowedArgs() const OVERRIDE { return 2; }
636 bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE { return type == REAL_EXPR; }
637 bool acceptsArgUnitType(vmint iArg, StdUnit_t type) const OVERRIDE;
638 bool acceptsArgUnitPrefix(vmint iArg, StdUnit_t type) const OVERRIDE;
639 bool acceptsArgFinal(vmint iArg) const OVERRIDE { return iArg == 0; }
640 VMFnResult* exec(VMFnArgs* args) OVERRIDE;
641 };
642
643 /**
644 * Implements the built-in sin() script function.
645 */
646 class CoreVMFunction_sin FINAL : public VMRealResultFunction {
647 public:
648 StdUnit_t returnUnitType(VMFnArgs* args) OVERRIDE;
649 bool returnsFinal(VMFnArgs* args) OVERRIDE;
650 vmint minRequiredArgs() const OVERRIDE { return 1; }
651 vmint maxAllowedArgs() const OVERRIDE { return 1; }
652 bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE { return type == REAL_EXPR; }
653 bool acceptsArgUnitType(vmint iArg, StdUnit_t type) const OVERRIDE { return true; }
654 bool acceptsArgUnitPrefix(vmint iArg, StdUnit_t type) const OVERRIDE { return true; }
655 bool acceptsArgFinal(vmint iArg) const OVERRIDE { return true; }
656 VMFnResult* exec(VMFnArgs* args) OVERRIDE;
657 };
658
659 /**
660 * Implements the built-in cos() script function.
661 */
662 class CoreVMFunction_cos FINAL : public VMRealResultFunction {
663 public:
664 StdUnit_t returnUnitType(VMFnArgs* args) OVERRIDE;
665 bool returnsFinal(VMFnArgs* args) OVERRIDE;
666 vmint minRequiredArgs() const OVERRIDE { return 1; }
667 vmint maxAllowedArgs() const OVERRIDE { return 1; }
668 bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE { return type == REAL_EXPR; }
669 bool acceptsArgUnitType(vmint iArg, StdUnit_t type) const OVERRIDE { return true; }
670 bool acceptsArgUnitPrefix(vmint iArg, StdUnit_t type) const OVERRIDE { return true; }
671 bool acceptsArgFinal(vmint iArg) const OVERRIDE { return true; }
672 VMFnResult* exec(VMFnArgs* args) OVERRIDE;
673 };
674
675 /**
676 * Implements the built-in tan() script function.
677 */
678 class CoreVMFunction_tan FINAL : public VMRealResultFunction {
679 public:
680 StdUnit_t returnUnitType(VMFnArgs* args) OVERRIDE;
681 bool returnsFinal(VMFnArgs* args) OVERRIDE;
682 vmint minRequiredArgs() const OVERRIDE { return 1; }
683 vmint maxAllowedArgs() const OVERRIDE { return 1; }
684 bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE { return type == REAL_EXPR; }
685 bool acceptsArgUnitType(vmint iArg, StdUnit_t type) const OVERRIDE { return true; }
686 bool acceptsArgUnitPrefix(vmint iArg, StdUnit_t type) const OVERRIDE { return true; }
687 bool acceptsArgFinal(vmint iArg) const OVERRIDE { return true; }
688 VMFnResult* exec(VMFnArgs* args) OVERRIDE;
689 };
690
691 /**
692 * Implements the built-in asin() script function.
693 */
694 class CoreVMFunction_asin FINAL : public VMRealResultFunction {
695 public:
696 StdUnit_t returnUnitType(VMFnArgs* args) OVERRIDE;
697 bool returnsFinal(VMFnArgs* args) OVERRIDE;
698 vmint minRequiredArgs() const OVERRIDE { return 1; }
699 vmint maxAllowedArgs() const OVERRIDE { return 1; }
700 bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE { return type == REAL_EXPR; }
701 bool acceptsArgUnitType(vmint iArg, StdUnit_t type) const OVERRIDE { return true; }
702 bool acceptsArgUnitPrefix(vmint iArg, StdUnit_t type) const OVERRIDE { return true; }
703 bool acceptsArgFinal(vmint iArg) const OVERRIDE { return true; }
704 VMFnResult* exec(VMFnArgs* args) OVERRIDE;
705 };
706
707 /**
708 * Implements the built-in acos() script function.
709 */
710 class CoreVMFunction_acos FINAL : public VMRealResultFunction {
711 public:
712 StdUnit_t returnUnitType(VMFnArgs* args) OVERRIDE;
713 bool returnsFinal(VMFnArgs* args) OVERRIDE;
714 vmint minRequiredArgs() const OVERRIDE { return 1; }
715 vmint maxAllowedArgs() const OVERRIDE { return 1; }
716 bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE { return type == REAL_EXPR; }
717 bool acceptsArgUnitType(vmint iArg, StdUnit_t type) const OVERRIDE { return true; }
718 bool acceptsArgUnitPrefix(vmint iArg, StdUnit_t type) const OVERRIDE { return true; }
719 bool acceptsArgFinal(vmint iArg) const OVERRIDE { return true; }
720 VMFnResult* exec(VMFnArgs* args) OVERRIDE;
721 };
722
723 /**
724 * Implements the built-in atan() script function.
725 */
726 class CoreVMFunction_atan FINAL : public VMRealResultFunction {
727 public:
728 StdUnit_t returnUnitType(VMFnArgs* args) OVERRIDE;
729 bool returnsFinal(VMFnArgs* args) OVERRIDE;
730 vmint minRequiredArgs() const OVERRIDE { return 1; }
731 vmint maxAllowedArgs() const OVERRIDE { return 1; }
732 bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE { return type == REAL_EXPR; }
733 bool acceptsArgUnitType(vmint iArg, StdUnit_t type) const OVERRIDE { return true; }
734 bool acceptsArgUnitPrefix(vmint iArg, StdUnit_t type) const OVERRIDE { return true; }
735 bool acceptsArgFinal(vmint iArg) const OVERRIDE { return true; }
736 VMFnResult* exec(VMFnArgs* args) OVERRIDE;
737 };
738
739 } // namespace LinuxSampler
740
741 #endif // LS_COREVMFUNCTIONS_H

  ViewVC Help
Powered by ViewVC