1 |
schoenebeck |
2581 |
/* |
2 |
schoenebeck |
3551 |
* Copyright (c) 2014-2019 Christian Schoenebeck |
3 |
schoenebeck |
2581 |
* |
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 |
schoenebeck |
2727 |
|
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 |
schoenebeck |
3581 |
class VMEmptyResult FINAL : public VMFnResult, public VMExpr { |
28 |
schoenebeck |
2581 |
public: |
29 |
schoenebeck |
2727 |
StmtFlags_t flags; ///< general completion status (i.e. success or failure) of the function call |
30 |
schoenebeck |
2581 |
|
31 |
|
|
VMEmptyResult() : flags(STMT_SUCCESS) {} |
32 |
schoenebeck |
3054 |
ExprType_t exprType() const OVERRIDE { return EMPTY_EXPR; } |
33 |
|
|
VMExpr* resultValue() OVERRIDE { return this; } |
34 |
|
|
StmtFlags_t resultFlags() OVERRIDE { return flags; } |
35 |
schoenebeck |
2945 |
bool isConstExpr() const OVERRIDE { return false; } |
36 |
schoenebeck |
2581 |
}; |
37 |
|
|
|
38 |
schoenebeck |
2727 |
/** |
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 |
schoenebeck |
3581 |
class VMIntResult FINAL : public VMFnResult, public VMIntExpr { |
43 |
schoenebeck |
2598 |
public: |
44 |
schoenebeck |
2727 |
StmtFlags_t flags; ///< general completion status (i.e. success or failure) of the function call |
45 |
schoenebeck |
3557 |
vmint value; ///< result value of the function call |
46 |
schoenebeck |
3581 |
vmfloat unitPrefixFactor; ///< unit factor of result value of the function call |
47 |
schoenebeck |
2598 |
|
48 |
schoenebeck |
3581 |
VMIntResult() : flags(STMT_SUCCESS), value(0), unitPrefixFactor(VM_NO_FACTOR) {} |
49 |
schoenebeck |
3557 |
vmint evalInt() OVERRIDE { return value; } |
50 |
schoenebeck |
3054 |
VMExpr* resultValue() OVERRIDE { return this; } |
51 |
|
|
StmtFlags_t resultFlags() OVERRIDE { return flags; } |
52 |
schoenebeck |
2945 |
bool isConstExpr() const OVERRIDE { return false; } |
53 |
schoenebeck |
3581 |
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 |
schoenebeck |
2598 |
}; |
57 |
|
|
|
58 |
schoenebeck |
2727 |
/** |
59 |
|
|
* An instance of this class is returned by built-in function implementations |
60 |
schoenebeck |
3573 |
* which return a real number (floating point) value as function return value. |
61 |
|
|
*/ |
62 |
schoenebeck |
3581 |
class VMRealResult FINAL : public VMFnResult, public VMRealExpr { |
63 |
schoenebeck |
3573 |
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 |
schoenebeck |
3581 |
vmfloat unitPrefixFactor; ///< unit factor of result value of the function call |
67 |
schoenebeck |
3573 |
|
68 |
schoenebeck |
3581 |
VMRealResult() : flags(STMT_SUCCESS), value(0), unitPrefixFactor(VM_NO_FACTOR) {} |
69 |
schoenebeck |
3573 |
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 |
schoenebeck |
3581 |
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 |
schoenebeck |
3573 |
}; |
77 |
|
|
|
78 |
|
|
/** |
79 |
|
|
* An instance of this class is returned by built-in function implementations |
80 |
schoenebeck |
2727 |
* which return a string value as function return value. |
81 |
|
|
*/ |
82 |
schoenebeck |
3581 |
class VMStringResult FINAL : public VMFnResult, public VMStringExpr { |
83 |
schoenebeck |
2581 |
public: |
84 |
schoenebeck |
2727 |
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 |
schoenebeck |
2581 |
|
87 |
|
|
VMStringResult() : flags(STMT_SUCCESS) {} |
88 |
schoenebeck |
3054 |
String evalStr() OVERRIDE { return value; } |
89 |
|
|
VMExpr* resultValue() OVERRIDE { return this; } |
90 |
|
|
StmtFlags_t resultFlags() OVERRIDE { return flags; } |
91 |
schoenebeck |
2945 |
bool isConstExpr() const OVERRIDE { return false; } |
92 |
schoenebeck |
2581 |
}; |
93 |
|
|
|
94 |
schoenebeck |
2727 |
/** |
95 |
|
|
* Abstract base class for built-in script functions which do not return any |
96 |
|
|
* function return value (void). |
97 |
|
|
*/ |
98 |
schoenebeck |
2581 |
class VMEmptyResultFunction : public VMFunction { |
99 |
|
|
protected: |
100 |
schoenebeck |
3034 |
virtual ~VMEmptyResultFunction() {} |
101 |
schoenebeck |
3577 |
ExprType_t returnType(VMFnArgs* args) OVERRIDE { return EMPTY_EXPR; } |
102 |
schoenebeck |
3581 |
StdUnit_t returnUnitType(VMFnArgs* args) OVERRIDE { return VM_NO_UNIT; } |
103 |
|
|
bool returnsFinal(VMFnArgs* args) OVERRIDE { return false; } |
104 |
schoenebeck |
2581 |
VMFnResult* errorResult(); |
105 |
|
|
VMFnResult* successResult(); |
106 |
schoenebeck |
3557 |
bool modifiesArg(vmint iArg) const OVERRIDE { return false; } |
107 |
schoenebeck |
2581 |
protected: |
108 |
|
|
VMEmptyResult result; |
109 |
|
|
}; |
110 |
|
|
|
111 |
schoenebeck |
3581 |
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 |
schoenebeck |
2727 |
/** |
122 |
|
|
* Abstract base class for built-in script functions which return an integer |
123 |
|
|
* (scalar) as their function return value. |
124 |
|
|
*/ |
125 |
schoenebeck |
2598 |
class VMIntResultFunction : public VMFunction { |
126 |
|
|
protected: |
127 |
schoenebeck |
3034 |
virtual ~VMIntResultFunction() {} |
128 |
schoenebeck |
3577 |
ExprType_t returnType(VMFnArgs* args) OVERRIDE { return INT_EXPR; } |
129 |
schoenebeck |
3557 |
VMFnResult* errorResult(vmint i = 0); |
130 |
schoenebeck |
3581 |
VMFnResult* errorResult(VMIntFnResDef res); |
131 |
schoenebeck |
3557 |
VMFnResult* successResult(vmint i = 0); |
132 |
schoenebeck |
3581 |
VMFnResult* successResult(VMIntFnResDef res); |
133 |
schoenebeck |
3557 |
bool modifiesArg(vmint iArg) const OVERRIDE { return false; } |
134 |
schoenebeck |
2598 |
protected: |
135 |
|
|
VMIntResult result; |
136 |
|
|
}; |
137 |
|
|
|
138 |
schoenebeck |
2727 |
/** |
139 |
schoenebeck |
3573 |
* 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 |
schoenebeck |
3577 |
ExprType_t returnType(VMFnArgs* args) OVERRIDE { return REAL_EXPR; } |
146 |
schoenebeck |
3573 |
VMFnResult* errorResult(vmfloat f = 0); |
147 |
schoenebeck |
3581 |
VMFnResult* errorResult(VMRealFnResDef res); |
148 |
schoenebeck |
3573 |
VMFnResult* successResult(vmfloat f = 0); |
149 |
schoenebeck |
3581 |
VMFnResult* successResult(VMRealFnResDef res); |
150 |
schoenebeck |
3573 |
bool modifiesArg(vmint iArg) const OVERRIDE { return false; } |
151 |
|
|
protected: |
152 |
|
|
VMRealResult result; |
153 |
|
|
}; |
154 |
|
|
|
155 |
|
|
/** |
156 |
schoenebeck |
2727 |
* Abstract base class for built-in script functions which return a string as |
157 |
|
|
* their function return value. |
158 |
|
|
*/ |
159 |
schoenebeck |
2581 |
class VMStringResultFunction : public VMFunction { |
160 |
|
|
protected: |
161 |
schoenebeck |
3034 |
virtual ~VMStringResultFunction() {} |
162 |
schoenebeck |
3577 |
ExprType_t returnType(VMFnArgs* args) OVERRIDE { return STRING_EXPR; } |
163 |
schoenebeck |
2581 |
VMFnResult* errorResult(const String& s = ""); |
164 |
|
|
VMFnResult* successResult(const String& s = ""); |
165 |
schoenebeck |
3557 |
bool modifiesArg(vmint iArg) const OVERRIDE { return false; } |
166 |
schoenebeck |
2581 |
protected: |
167 |
|
|
VMStringResult result; |
168 |
|
|
}; |
169 |
|
|
|
170 |
schoenebeck |
3577 |
/** |
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 |
schoenebeck |
3582 |
class VMNumberResultFunction : public VMFunction { |
177 |
schoenebeck |
3577 |
protected: |
178 |
schoenebeck |
3582 |
virtual ~VMNumberResultFunction() {} |
179 |
schoenebeck |
3577 |
VMFnResult* errorResult(vmint i); |
180 |
|
|
VMFnResult* errorResult(vmfloat f); |
181 |
|
|
VMFnResult* successResult(vmint i); |
182 |
|
|
VMFnResult* successResult(vmfloat f); |
183 |
schoenebeck |
3581 |
VMFnResult* errorIntResult(VMIntFnResDef res); |
184 |
|
|
VMFnResult* errorRealResult(VMRealFnResDef res); |
185 |
|
|
VMFnResult* successIntResult(VMIntFnResDef res); |
186 |
|
|
VMFnResult* successRealResult(VMRealFnResDef res); |
187 |
schoenebeck |
3577 |
bool modifiesArg(vmint iArg) const OVERRIDE { return false; } |
188 |
|
|
protected: |
189 |
|
|
VMIntResult intResult; |
190 |
|
|
VMRealResult realResult; |
191 |
|
|
}; |
192 |
schoenebeck |
2727 |
|
193 |
schoenebeck |
3577 |
|
194 |
schoenebeck |
2727 |
/////////////////////////////////////////////////////////////////////////// |
195 |
|
|
// implementations of core built-in script functions ... |
196 |
|
|
|
197 |
|
|
/** |
198 |
|
|
* Implements the built-in message() script function. |
199 |
|
|
*/ |
200 |
schoenebeck |
3581 |
class CoreVMFunction_message FINAL : public VMEmptyResultFunction { |
201 |
schoenebeck |
2581 |
public: |
202 |
schoenebeck |
3557 |
vmint minRequiredArgs() const OVERRIDE { return 1; } |
203 |
|
|
vmint maxAllowedArgs() const OVERRIDE { return 1; } |
204 |
|
|
bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE; |
205 |
|
|
ExprType_t argType(vmint iArg) const OVERRIDE { return STRING_EXPR; } |
206 |
|
|
VMFnResult* exec(VMFnArgs* args) OVERRIDE; |
207 |
schoenebeck |
2581 |
}; |
208 |
|
|
|
209 |
schoenebeck |
2727 |
/** |
210 |
|
|
* Implements the built-in exit() script function. |
211 |
|
|
*/ |
212 |
schoenebeck |
3581 |
class CoreVMFunction_exit FINAL : public VMEmptyResultFunction { |
213 |
schoenebeck |
2581 |
public: |
214 |
schoenebeck |
3551 |
CoreVMFunction_exit(ScriptVM* vm) : vm(vm) {} |
215 |
schoenebeck |
3557 |
vmint minRequiredArgs() const OVERRIDE { return 0; } |
216 |
|
|
vmint maxAllowedArgs() const OVERRIDE; |
217 |
|
|
bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE; |
218 |
|
|
ExprType_t argType(vmint iArg) const OVERRIDE { return INT_EXPR; } |
219 |
schoenebeck |
3581 |
bool acceptsArgUnitType(vmint iArg, StdUnit_t type) const OVERRIDE; |
220 |
|
|
bool acceptsArgUnitPrefix(vmint iArg, StdUnit_t type) const OVERRIDE; |
221 |
|
|
bool acceptsArgFinal(vmint iArg) const OVERRIDE; |
222 |
schoenebeck |
3557 |
VMFnResult* exec(VMFnArgs* args) OVERRIDE; |
223 |
schoenebeck |
3551 |
protected: |
224 |
|
|
ScriptVM* vm; |
225 |
schoenebeck |
2581 |
}; |
226 |
|
|
|
227 |
schoenebeck |
2727 |
/** |
228 |
|
|
* Implements the built-in wait() script function. |
229 |
|
|
*/ |
230 |
schoenebeck |
2581 |
class CoreVMFunction_wait : public VMEmptyResultFunction { |
231 |
|
|
public: |
232 |
|
|
CoreVMFunction_wait(ScriptVM* vm) : vm(vm) {} |
233 |
schoenebeck |
3557 |
vmint minRequiredArgs() const OVERRIDE { return 1; } |
234 |
|
|
vmint maxAllowedArgs() const OVERRIDE { return 1; } |
235 |
|
|
bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE { return type == INT_EXPR; } |
236 |
schoenebeck |
3561 |
bool acceptsArgUnitType(vmint iArg, StdUnit_t type) const OVERRIDE; |
237 |
schoenebeck |
3564 |
bool acceptsArgUnitPrefix(vmint iArg, StdUnit_t type) const OVERRIDE; |
238 |
schoenebeck |
3557 |
ExprType_t argType(vmint iArg) const OVERRIDE { return INT_EXPR; } |
239 |
|
|
VMFnResult* exec(VMFnArgs* args) OVERRIDE; |
240 |
schoenebeck |
2581 |
protected: |
241 |
|
|
ScriptVM* vm; |
242 |
|
|
}; |
243 |
|
|
|
244 |
schoenebeck |
2727 |
/** |
245 |
|
|
* Implements the built-in abs() script function. |
246 |
|
|
*/ |
247 |
schoenebeck |
3582 |
class CoreVMFunction_abs FINAL : public VMNumberResultFunction { |
248 |
schoenebeck |
2619 |
public: |
249 |
schoenebeck |
3577 |
ExprType_t returnType(VMFnArgs* args) OVERRIDE; |
250 |
schoenebeck |
3581 |
StdUnit_t returnUnitType(VMFnArgs* args) OVERRIDE; |
251 |
|
|
bool returnsFinal(VMFnArgs* args) OVERRIDE; |
252 |
schoenebeck |
3557 |
vmint minRequiredArgs() const OVERRIDE { return 1; } |
253 |
|
|
vmint maxAllowedArgs() const OVERRIDE { return 1; } |
254 |
|
|
bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE; |
255 |
schoenebeck |
3581 |
bool acceptsArgUnitType(vmint iArg, StdUnit_t type) const OVERRIDE { return true; } |
256 |
|
|
bool acceptsArgUnitPrefix(vmint iArg, StdUnit_t type) const OVERRIDE { return true; } |
257 |
|
|
bool acceptsArgFinal(vmint iArg) const OVERRIDE { return true; } |
258 |
schoenebeck |
3557 |
ExprType_t argType(vmint iArg) const OVERRIDE { return INT_EXPR; } |
259 |
|
|
VMFnResult* exec(VMFnArgs* args) OVERRIDE; |
260 |
schoenebeck |
2619 |
}; |
261 |
|
|
|
262 |
schoenebeck |
2727 |
/** |
263 |
|
|
* Implements the built-in random() script function. |
264 |
|
|
*/ |
265 |
schoenebeck |
3582 |
class CoreVMFunction_random FINAL : public VMNumberResultFunction { |
266 |
|
|
using Super = VMNumberResultFunction; // just an alias for the super class |
267 |
schoenebeck |
2619 |
public: |
268 |
schoenebeck |
3581 |
ExprType_t returnType(VMFnArgs* args) OVERRIDE; |
269 |
|
|
StdUnit_t returnUnitType(VMFnArgs* args) OVERRIDE; |
270 |
|
|
bool returnsFinal(VMFnArgs* args) OVERRIDE; |
271 |
schoenebeck |
3557 |
vmint minRequiredArgs() const OVERRIDE { return 2; } |
272 |
|
|
vmint maxAllowedArgs() const OVERRIDE { return 2; } |
273 |
|
|
bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE; |
274 |
schoenebeck |
3581 |
bool acceptsArgUnitType(vmint iArg, StdUnit_t type) const OVERRIDE { return true; } |
275 |
|
|
bool acceptsArgUnitPrefix(vmint iArg, StdUnit_t type) const OVERRIDE { return true; } |
276 |
|
|
bool acceptsArgFinal(vmint iArg) const OVERRIDE { return true; } |
277 |
schoenebeck |
3557 |
ExprType_t argType(vmint iArg) const OVERRIDE { return INT_EXPR; } |
278 |
schoenebeck |
3581 |
void checkArgs(VMFnArgs* args, std::function<void(String)> err, |
279 |
|
|
std::function<void(String)> wrn) OVERRIDE; |
280 |
schoenebeck |
3557 |
VMFnResult* exec(VMFnArgs* args) OVERRIDE; |
281 |
schoenebeck |
2619 |
}; |
282 |
|
|
|
283 |
schoenebeck |
2727 |
/** |
284 |
|
|
* Implements the built-in num_elements() script function. |
285 |
|
|
*/ |
286 |
schoenebeck |
3581 |
class CoreVMFunction_num_elements FINAL : public VMIntResultFunction { |
287 |
schoenebeck |
2619 |
public: |
288 |
schoenebeck |
3581 |
StdUnit_t returnUnitType(VMFnArgs* args) OVERRIDE { return VM_NO_UNIT; } |
289 |
|
|
bool returnsFinal(VMFnArgs* args) OVERRIDE { return false; } |
290 |
schoenebeck |
3557 |
vmint minRequiredArgs() const OVERRIDE { return 1; } |
291 |
|
|
vmint maxAllowedArgs() const OVERRIDE { return 1; } |
292 |
|
|
bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE; |
293 |
|
|
ExprType_t argType(vmint iArg) const OVERRIDE { return INT_ARR_EXPR; } |
294 |
|
|
VMFnResult* exec(VMFnArgs* args) OVERRIDE; |
295 |
schoenebeck |
2619 |
}; |
296 |
|
|
|
297 |
schoenebeck |
2945 |
/** |
298 |
|
|
* Implements the built-in inc() script function. |
299 |
|
|
*/ |
300 |
schoenebeck |
3581 |
class CoreVMFunction_inc FINAL : public VMIntResultFunction { |
301 |
|
|
using Super = VMIntResultFunction; // just an alias for the super class |
302 |
schoenebeck |
2945 |
public: |
303 |
schoenebeck |
3581 |
StdUnit_t returnUnitType(VMFnArgs* args) OVERRIDE; |
304 |
|
|
bool returnsFinal(VMFnArgs* args) OVERRIDE; |
305 |
schoenebeck |
3557 |
vmint minRequiredArgs() const OVERRIDE { return 1; } |
306 |
|
|
vmint maxAllowedArgs() const OVERRIDE { return 1; } |
307 |
|
|
bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE { return type == INT_EXPR; } |
308 |
schoenebeck |
3581 |
bool acceptsArgUnitType(vmint iArg, StdUnit_t type) const OVERRIDE { return true; } |
309 |
|
|
bool acceptsArgUnitPrefix(vmint iArg, StdUnit_t type) const OVERRIDE { return true; } |
310 |
|
|
bool acceptsArgFinal(vmint iArg) const OVERRIDE { return true; } |
311 |
schoenebeck |
3557 |
ExprType_t argType(vmint iArg) const OVERRIDE { return INT_EXPR; } |
312 |
|
|
bool modifiesArg(vmint iArg) const OVERRIDE { return true; } |
313 |
schoenebeck |
3581 |
void checkArgs(VMFnArgs* args, std::function<void(String)> err, |
314 |
|
|
std::function<void(String)> wrn) OVERRIDE; |
315 |
schoenebeck |
3557 |
VMFnResult* exec(VMFnArgs* args) OVERRIDE; |
316 |
schoenebeck |
2945 |
}; |
317 |
|
|
|
318 |
|
|
/** |
319 |
|
|
* Implements the built-in dec() script function. |
320 |
|
|
*/ |
321 |
schoenebeck |
3581 |
class CoreVMFunction_dec FINAL : public VMIntResultFunction { |
322 |
|
|
using Super = VMIntResultFunction; // just an alias for the super class |
323 |
schoenebeck |
2945 |
public: |
324 |
schoenebeck |
3581 |
StdUnit_t returnUnitType(VMFnArgs* args) OVERRIDE; |
325 |
|
|
bool returnsFinal(VMFnArgs* args) OVERRIDE; |
326 |
schoenebeck |
3557 |
vmint minRequiredArgs() const OVERRIDE { return 1; } |
327 |
|
|
vmint maxAllowedArgs() const OVERRIDE { return 1; } |
328 |
|
|
bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE { return type == INT_EXPR; } |
329 |
schoenebeck |
3581 |
bool acceptsArgUnitType(vmint iArg, StdUnit_t type) const OVERRIDE { return true; } |
330 |
|
|
bool acceptsArgUnitPrefix(vmint iArg, StdUnit_t type) const OVERRIDE { return true; } |
331 |
|
|
bool acceptsArgFinal(vmint iArg) const OVERRIDE { return true; } |
332 |
schoenebeck |
3557 |
ExprType_t argType(vmint iArg) const OVERRIDE { return INT_EXPR; } |
333 |
|
|
bool modifiesArg(vmint iArg) const OVERRIDE { return true; } |
334 |
schoenebeck |
3581 |
void checkArgs(VMFnArgs* args, std::function<void(String)> err, |
335 |
|
|
std::function<void(String)> wrn) OVERRIDE; |
336 |
schoenebeck |
3557 |
VMFnResult* exec(VMFnArgs* args) OVERRIDE; |
337 |
schoenebeck |
2945 |
}; |
338 |
|
|
|
339 |
schoenebeck |
2965 |
/** |
340 |
schoenebeck |
3076 |
* Implements the built-in in_range() script function. |
341 |
|
|
*/ |
342 |
schoenebeck |
3581 |
class CoreVMFunction_in_range FINAL : public VMIntResultFunction { |
343 |
|
|
using Super = VMIntResultFunction; // just an alias for the super class |
344 |
schoenebeck |
3076 |
public: |
345 |
schoenebeck |
3581 |
StdUnit_t returnUnitType(VMFnArgs* args) OVERRIDE { return VM_NO_UNIT; } |
346 |
|
|
bool returnsFinal(VMFnArgs* args) OVERRIDE { return false; } |
347 |
schoenebeck |
3557 |
vmint minRequiredArgs() const OVERRIDE { return 3; } |
348 |
|
|
vmint maxAllowedArgs() const OVERRIDE { return 3; } |
349 |
schoenebeck |
3581 |
bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE; |
350 |
schoenebeck |
3557 |
ExprType_t argType(vmint iArg) const OVERRIDE { return INT_EXPR; } |
351 |
schoenebeck |
3581 |
bool acceptsArgUnitType(vmint iArg, StdUnit_t type) const OVERRIDE { return true; } |
352 |
|
|
bool acceptsArgUnitPrefix(vmint iArg, StdUnit_t type) const OVERRIDE { return true; } |
353 |
|
|
bool acceptsArgFinal(vmint iArg) const OVERRIDE { return true; } |
354 |
|
|
void checkArgs(VMFnArgs* args, std::function<void(String)> err, |
355 |
|
|
std::function<void(String)> wrn) OVERRIDE; |
356 |
schoenebeck |
3557 |
VMFnResult* exec(VMFnArgs* args) OVERRIDE; |
357 |
schoenebeck |
3076 |
}; |
358 |
|
|
|
359 |
|
|
/** |
360 |
schoenebeck |
2965 |
* Implements the built-in sh_left() script function. |
361 |
|
|
*/ |
362 |
schoenebeck |
3581 |
class CoreVMFunction_sh_left FINAL : public VMIntResultFunction { |
363 |
schoenebeck |
2965 |
public: |
364 |
schoenebeck |
3581 |
StdUnit_t returnUnitType(VMFnArgs* args) OVERRIDE { return VM_NO_UNIT; } |
365 |
|
|
bool returnsFinal(VMFnArgs* args) OVERRIDE; |
366 |
schoenebeck |
3557 |
vmint minRequiredArgs() const OVERRIDE { return 2; } |
367 |
|
|
vmint maxAllowedArgs() const OVERRIDE { return 2; } |
368 |
|
|
bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE { return type == INT_EXPR; } |
369 |
|
|
ExprType_t argType(vmint iArg) const OVERRIDE { return INT_EXPR; } |
370 |
schoenebeck |
3581 |
bool acceptsArgFinal(vmint iArg) const OVERRIDE { return true; } |
371 |
schoenebeck |
3557 |
VMFnResult* exec(VMFnArgs* args) OVERRIDE; |
372 |
schoenebeck |
2965 |
}; |
373 |
|
|
|
374 |
|
|
/** |
375 |
|
|
* Implements the built-in sh_right() script function. |
376 |
|
|
*/ |
377 |
schoenebeck |
3581 |
class CoreVMFunction_sh_right FINAL : public VMIntResultFunction { |
378 |
schoenebeck |
2965 |
public: |
379 |
schoenebeck |
3581 |
StdUnit_t returnUnitType(VMFnArgs* args) OVERRIDE { return VM_NO_UNIT; } |
380 |
|
|
bool returnsFinal(VMFnArgs* args) OVERRIDE; |
381 |
schoenebeck |
3557 |
vmint minRequiredArgs() const OVERRIDE { return 2; } |
382 |
|
|
vmint maxAllowedArgs() const OVERRIDE { return 2; } |
383 |
|
|
bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE { return type == INT_EXPR; } |
384 |
|
|
ExprType_t argType(vmint iArg) const OVERRIDE { return INT_EXPR; } |
385 |
schoenebeck |
3581 |
bool acceptsArgFinal(vmint iArg) const OVERRIDE { return true; } |
386 |
schoenebeck |
3557 |
VMFnResult* exec(VMFnArgs* args) OVERRIDE; |
387 |
schoenebeck |
2965 |
}; |
388 |
|
|
|
389 |
schoenebeck |
2970 |
/** |
390 |
|
|
* Implements the built-in min() script function. |
391 |
|
|
*/ |
392 |
schoenebeck |
3582 |
class CoreVMFunction_min FINAL : public VMNumberResultFunction { |
393 |
|
|
using Super = VMNumberResultFunction; // just an alias for the super class |
394 |
schoenebeck |
2970 |
public: |
395 |
schoenebeck |
3577 |
ExprType_t returnType(VMFnArgs* args) OVERRIDE; |
396 |
schoenebeck |
3581 |
StdUnit_t returnUnitType(VMFnArgs* args) OVERRIDE; |
397 |
|
|
bool returnsFinal(VMFnArgs* args) OVERRIDE; |
398 |
schoenebeck |
3557 |
vmint minRequiredArgs() const OVERRIDE { return 2; } |
399 |
|
|
vmint maxAllowedArgs() const OVERRIDE { return 2; } |
400 |
schoenebeck |
3577 |
bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE; |
401 |
schoenebeck |
3557 |
ExprType_t argType(vmint iArg) const OVERRIDE { return INT_EXPR; } |
402 |
schoenebeck |
3581 |
bool acceptsArgUnitType(vmint iArg, StdUnit_t type) const OVERRIDE { return true; } |
403 |
|
|
bool acceptsArgUnitPrefix(vmint iArg, StdUnit_t type) const OVERRIDE { return true; } |
404 |
|
|
bool acceptsArgFinal(vmint iArg) const OVERRIDE { return true; } |
405 |
|
|
void checkArgs(VMFnArgs* args, std::function<void(String)> err, |
406 |
|
|
std::function<void(String)> wrn) OVERRIDE; |
407 |
schoenebeck |
3557 |
VMFnResult* exec(VMFnArgs* args) OVERRIDE; |
408 |
schoenebeck |
2970 |
}; |
409 |
|
|
|
410 |
|
|
/** |
411 |
|
|
* Implements the built-in max() script function. |
412 |
|
|
*/ |
413 |
schoenebeck |
3582 |
class CoreVMFunction_max FINAL : public VMNumberResultFunction { |
414 |
|
|
using Super = VMNumberResultFunction; // just an alias for the super class |
415 |
schoenebeck |
2970 |
public: |
416 |
schoenebeck |
3577 |
ExprType_t returnType(VMFnArgs* args) OVERRIDE; |
417 |
schoenebeck |
3581 |
StdUnit_t returnUnitType(VMFnArgs* args) OVERRIDE; |
418 |
|
|
bool returnsFinal(VMFnArgs* args) OVERRIDE; |
419 |
schoenebeck |
3557 |
vmint minRequiredArgs() const OVERRIDE { return 2; } |
420 |
|
|
vmint maxAllowedArgs() const OVERRIDE { return 2; } |
421 |
schoenebeck |
3577 |
bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE; |
422 |
schoenebeck |
3557 |
ExprType_t argType(vmint iArg) const OVERRIDE { return INT_EXPR; } |
423 |
schoenebeck |
3581 |
bool acceptsArgUnitType(vmint iArg, StdUnit_t type) const OVERRIDE { return true; } |
424 |
|
|
bool acceptsArgUnitPrefix(vmint iArg, StdUnit_t type) const OVERRIDE { return true; } |
425 |
|
|
bool acceptsArgFinal(vmint iArg) const OVERRIDE { return true; } |
426 |
|
|
void checkArgs(VMFnArgs* args, std::function<void(String)> err, |
427 |
|
|
std::function<void(String)> wrn) OVERRIDE; |
428 |
schoenebeck |
3557 |
VMFnResult* exec(VMFnArgs* args) OVERRIDE; |
429 |
schoenebeck |
2970 |
}; |
430 |
|
|
|
431 |
schoenebeck |
3221 |
/** |
432 |
|
|
* Implements the built-in array_equal() script function. |
433 |
|
|
*/ |
434 |
schoenebeck |
3581 |
class CoreVMFunction_array_equal FINAL : public VMIntResultFunction { |
435 |
|
|
using Super = VMIntResultFunction; // just an alias for the super class |
436 |
schoenebeck |
3221 |
public: |
437 |
schoenebeck |
3581 |
StdUnit_t returnUnitType(VMFnArgs* args) OVERRIDE { return VM_NO_UNIT; } |
438 |
|
|
bool returnsFinal(VMFnArgs* args) OVERRIDE { return false; } |
439 |
schoenebeck |
3557 |
vmint minRequiredArgs() const OVERRIDE { return 2; } |
440 |
|
|
vmint maxAllowedArgs() const OVERRIDE { return 2; } |
441 |
schoenebeck |
3581 |
bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE; |
442 |
schoenebeck |
3557 |
ExprType_t argType(vmint iArg) const OVERRIDE { return INT_ARR_EXPR; } |
443 |
schoenebeck |
3581 |
void checkArgs(VMFnArgs* args, std::function<void(String)> err, |
444 |
|
|
std::function<void(String)> wrn) OVERRIDE; |
445 |
schoenebeck |
3557 |
VMFnResult* exec(VMFnArgs* args) OVERRIDE; |
446 |
schoenebeck |
3221 |
}; |
447 |
|
|
|
448 |
|
|
/** |
449 |
|
|
* Implements the built-in search() script function. |
450 |
|
|
*/ |
451 |
schoenebeck |
3581 |
class CoreVMFunction_search FINAL : public VMIntResultFunction { |
452 |
|
|
using Super = VMIntResultFunction; // just an alias for the super class |
453 |
schoenebeck |
3221 |
public: |
454 |
schoenebeck |
3581 |
StdUnit_t returnUnitType(VMFnArgs* args) OVERRIDE { return VM_NO_UNIT; } |
455 |
|
|
bool returnsFinal(VMFnArgs* args) OVERRIDE { return false; } |
456 |
schoenebeck |
3557 |
vmint minRequiredArgs() const OVERRIDE { return 2; } |
457 |
|
|
vmint maxAllowedArgs() const OVERRIDE { return 2; } |
458 |
|
|
bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE; |
459 |
|
|
ExprType_t argType(vmint iArg) const OVERRIDE; |
460 |
schoenebeck |
3581 |
void checkArgs(VMFnArgs* args, std::function<void(String)> err, |
461 |
|
|
std::function<void(String)> wrn) OVERRIDE; |
462 |
schoenebeck |
3557 |
VMFnResult* exec(VMFnArgs* args) OVERRIDE; |
463 |
schoenebeck |
3221 |
}; |
464 |
|
|
|
465 |
|
|
/** |
466 |
|
|
* Implements the built-in sort() script function. |
467 |
|
|
*/ |
468 |
schoenebeck |
3581 |
class CoreVMFunction_sort FINAL : public VMEmptyResultFunction { |
469 |
schoenebeck |
3221 |
public: |
470 |
schoenebeck |
3557 |
vmint minRequiredArgs() const OVERRIDE { return 1; } |
471 |
|
|
vmint maxAllowedArgs() const OVERRIDE { return 2; } |
472 |
|
|
bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE; |
473 |
|
|
ExprType_t argType(vmint iArg) const OVERRIDE; |
474 |
|
|
bool modifiesArg(vmint iArg) const OVERRIDE { return iArg == 0; } |
475 |
|
|
VMFnResult* exec(VMFnArgs* args) OVERRIDE; |
476 |
schoenebeck |
3221 |
}; |
477 |
|
|
|
478 |
schoenebeck |
3573 |
/** |
479 |
|
|
* Implements the built-in real_to_int() script function and its short hand |
480 |
|
|
* variant int(). The behaviour of the two built-in script functions are |
481 |
|
|
* identical ATM. |
482 |
|
|
*/ |
483 |
schoenebeck |
3581 |
class CoreVMFunction_real_to_int FINAL : public VMIntResultFunction { |
484 |
schoenebeck |
3573 |
public: |
485 |
schoenebeck |
3581 |
StdUnit_t returnUnitType(VMFnArgs* args) OVERRIDE; |
486 |
|
|
bool returnsFinal(VMFnArgs* args) OVERRIDE; |
487 |
schoenebeck |
3573 |
vmint minRequiredArgs() const OVERRIDE { return 1; } |
488 |
|
|
vmint maxAllowedArgs() const OVERRIDE { return 1; } |
489 |
|
|
bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE { return type == REAL_EXPR; } |
490 |
|
|
ExprType_t argType(vmint iArg) const OVERRIDE { return REAL_EXPR; } |
491 |
schoenebeck |
3581 |
bool acceptsArgUnitType(vmint iArg, StdUnit_t type) const OVERRIDE { return true; } |
492 |
|
|
bool acceptsArgUnitPrefix(vmint iArg, StdUnit_t type) const OVERRIDE { return true; } |
493 |
|
|
bool acceptsArgFinal(vmint iArg) const OVERRIDE { return true; } |
494 |
schoenebeck |
3573 |
VMFnResult* exec(VMFnArgs* args) OVERRIDE; |
495 |
|
|
}; |
496 |
|
|
|
497 |
|
|
/** |
498 |
|
|
* Implements the built-in int_to_real() script function and its short hand |
499 |
|
|
* variant real(). The behaviour of the two built-in script functions are |
500 |
|
|
* identical ATM. |
501 |
|
|
*/ |
502 |
schoenebeck |
3581 |
class CoreVMFunction_int_to_real FINAL : public VMRealResultFunction { |
503 |
schoenebeck |
3573 |
public: |
504 |
schoenebeck |
3581 |
StdUnit_t returnUnitType(VMFnArgs* args) OVERRIDE; |
505 |
|
|
bool returnsFinal(VMFnArgs* args) OVERRIDE; |
506 |
schoenebeck |
3573 |
vmint minRequiredArgs() const OVERRIDE { return 1; } |
507 |
|
|
vmint maxAllowedArgs() const OVERRIDE { return 1; } |
508 |
|
|
bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE { return type == INT_EXPR; } |
509 |
|
|
ExprType_t argType(vmint iArg) const OVERRIDE { return INT_EXPR; } |
510 |
schoenebeck |
3581 |
bool acceptsArgUnitType(vmint iArg, StdUnit_t type) const OVERRIDE { return true; } |
511 |
|
|
bool acceptsArgUnitPrefix(vmint iArg, StdUnit_t type) const OVERRIDE { return true; } |
512 |
|
|
bool acceptsArgFinal(vmint iArg) const OVERRIDE { return true; } |
513 |
schoenebeck |
3573 |
VMFnResult* exec(VMFnArgs* args) OVERRIDE; |
514 |
|
|
}; |
515 |
|
|
|
516 |
schoenebeck |
2581 |
} // namespace LinuxSampler |
517 |
|
|
|
518 |
|
|
#endif // LS_COREVMFUNCTIONS_H |