1 |
/* |
/* |
2 |
* Copyright (c) 2014-2016 Christian Schoenebeck |
* Copyright (c) 2014-2019 Christian Schoenebeck |
3 |
* |
* |
4 |
* http://www.linuxsampler.org |
* http://www.linuxsampler.org |
5 |
* |
* |
42 |
class VMIntResult : public VMFnResult, public VMIntExpr { |
class VMIntResult : public VMFnResult, public VMIntExpr { |
43 |
public: |
public: |
44 |
StmtFlags_t flags; ///< general completion status (i.e. success or failure) of the function call |
StmtFlags_t flags; ///< general completion status (i.e. success or failure) of the function call |
45 |
int value; ///< result value of the function call |
vmint value; ///< result value of the function call |
46 |
|
|
47 |
VMIntResult() : flags(STMT_SUCCESS) {} |
VMIntResult() : flags(STMT_SUCCESS), value(0) {} |
48 |
int evalInt() OVERRIDE { return value; } |
vmint evalInt() OVERRIDE { return value; } |
49 |
VMExpr* resultValue() OVERRIDE { return this; } |
VMExpr* resultValue() OVERRIDE { return this; } |
50 |
StmtFlags_t resultFlags() OVERRIDE { return flags; } |
StmtFlags_t resultFlags() OVERRIDE { return flags; } |
51 |
bool isConstExpr() const OVERRIDE { return false; } |
bool isConstExpr() const OVERRIDE { return false; } |
52 |
|
MetricPrefix_t unitPrefix(vmuint i) const OVERRIDE { return VM_NO_PREFIX; } |
53 |
|
StdUnit_t unitType() const OVERRIDE { return VM_NO_UNIT; } |
54 |
|
bool isFinal() const OVERRIDE { return false; } |
55 |
}; |
}; |
56 |
|
|
57 |
/** |
/** |
80 |
ExprType_t returnType() OVERRIDE { return EMPTY_EXPR; } |
ExprType_t returnType() OVERRIDE { return EMPTY_EXPR; } |
81 |
VMFnResult* errorResult(); |
VMFnResult* errorResult(); |
82 |
VMFnResult* successResult(); |
VMFnResult* successResult(); |
83 |
bool modifiesArg(int iArg) const OVERRIDE { return false; } |
bool modifiesArg(vmint iArg) const OVERRIDE { return false; } |
84 |
protected: |
protected: |
85 |
VMEmptyResult result; |
VMEmptyResult result; |
86 |
}; |
}; |
93 |
protected: |
protected: |
94 |
virtual ~VMIntResultFunction() {} |
virtual ~VMIntResultFunction() {} |
95 |
ExprType_t returnType() OVERRIDE { return INT_EXPR; } |
ExprType_t returnType() OVERRIDE { return INT_EXPR; } |
96 |
VMFnResult* errorResult(int i = 0); |
VMFnResult* errorResult(vmint i = 0); |
97 |
VMFnResult* successResult(int i = 0); |
VMFnResult* successResult(vmint i = 0); |
98 |
bool modifiesArg(int iArg) const OVERRIDE { return false; } |
bool modifiesArg(vmint iArg) const OVERRIDE { return false; } |
99 |
protected: |
protected: |
100 |
VMIntResult result; |
VMIntResult result; |
101 |
}; |
}; |
110 |
ExprType_t returnType() OVERRIDE { return STRING_EXPR; } |
ExprType_t returnType() OVERRIDE { return STRING_EXPR; } |
111 |
VMFnResult* errorResult(const String& s = ""); |
VMFnResult* errorResult(const String& s = ""); |
112 |
VMFnResult* successResult(const String& s = ""); |
VMFnResult* successResult(const String& s = ""); |
113 |
bool modifiesArg(int iArg) const OVERRIDE { return false; } |
bool modifiesArg(vmint iArg) const OVERRIDE { return false; } |
114 |
protected: |
protected: |
115 |
VMStringResult result; |
VMStringResult result; |
116 |
}; |
}; |
124 |
*/ |
*/ |
125 |
class CoreVMFunction_message : public VMEmptyResultFunction { |
class CoreVMFunction_message : public VMEmptyResultFunction { |
126 |
public: |
public: |
127 |
int minRequiredArgs() const { return 1; } |
vmint minRequiredArgs() const OVERRIDE { return 1; } |
128 |
int maxAllowedArgs() const { return 1; } |
vmint maxAllowedArgs() const OVERRIDE { return 1; } |
129 |
bool acceptsArgType(int iArg, ExprType_t type) const; |
bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE; |
130 |
ExprType_t argType(int iArg) const { return STRING_EXPR; } |
ExprType_t argType(vmint iArg) const OVERRIDE { return STRING_EXPR; } |
131 |
VMFnResult* exec(VMFnArgs* args); |
VMFnResult* exec(VMFnArgs* args) OVERRIDE; |
132 |
}; |
}; |
133 |
|
|
134 |
/** |
/** |
136 |
*/ |
*/ |
137 |
class CoreVMFunction_exit : public VMEmptyResultFunction { |
class CoreVMFunction_exit : public VMEmptyResultFunction { |
138 |
public: |
public: |
139 |
int minRequiredArgs() const { return 0; } |
CoreVMFunction_exit(ScriptVM* vm) : vm(vm) {} |
140 |
int maxAllowedArgs() const { return 0; } |
vmint minRequiredArgs() const OVERRIDE { return 0; } |
141 |
bool acceptsArgType(int iArg, ExprType_t type) const { return false; } |
vmint maxAllowedArgs() const OVERRIDE; |
142 |
ExprType_t argType(int iArg) const { return INT_EXPR; /*whatever*/ } |
bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE; |
143 |
VMFnResult* exec(VMFnArgs* args); |
ExprType_t argType(vmint iArg) const OVERRIDE { return INT_EXPR; } |
144 |
|
VMFnResult* exec(VMFnArgs* args) OVERRIDE; |
145 |
|
protected: |
146 |
|
ScriptVM* vm; |
147 |
}; |
}; |
148 |
|
|
149 |
/** |
/** |
152 |
class CoreVMFunction_wait : public VMEmptyResultFunction { |
class CoreVMFunction_wait : public VMEmptyResultFunction { |
153 |
public: |
public: |
154 |
CoreVMFunction_wait(ScriptVM* vm) : vm(vm) {} |
CoreVMFunction_wait(ScriptVM* vm) : vm(vm) {} |
155 |
int minRequiredArgs() const { return 1; } |
vmint minRequiredArgs() const OVERRIDE { return 1; } |
156 |
int maxAllowedArgs() const { return 1; } |
vmint maxAllowedArgs() const OVERRIDE { return 1; } |
157 |
bool acceptsArgType(int iArg, ExprType_t type) const { return type == INT_EXPR; } |
bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE { return type == INT_EXPR; } |
158 |
ExprType_t argType(int iArg) const { return INT_EXPR; } |
bool acceptsArgUnitType(vmint iArg, StdUnit_t type) const OVERRIDE; |
159 |
VMFnResult* exec(VMFnArgs* args); |
bool acceptsArgUnitPrefix(vmint iArg) const OVERRIDE; |
160 |
|
ExprType_t argType(vmint iArg) const OVERRIDE { return INT_EXPR; } |
161 |
|
VMFnResult* exec(VMFnArgs* args) OVERRIDE; |
162 |
protected: |
protected: |
163 |
ScriptVM* vm; |
ScriptVM* vm; |
164 |
}; |
}; |
168 |
*/ |
*/ |
169 |
class CoreVMFunction_abs : public VMIntResultFunction { |
class CoreVMFunction_abs : public VMIntResultFunction { |
170 |
public: |
public: |
171 |
int minRequiredArgs() const { return 1; } |
vmint minRequiredArgs() const OVERRIDE { return 1; } |
172 |
int maxAllowedArgs() const { return 1; } |
vmint maxAllowedArgs() const OVERRIDE { return 1; } |
173 |
bool acceptsArgType(int iArg, ExprType_t type) const; |
bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE; |
174 |
ExprType_t argType(int iArg) const { return INT_EXPR; } |
ExprType_t argType(vmint iArg) const OVERRIDE { return INT_EXPR; } |
175 |
VMFnResult* exec(VMFnArgs* args); |
VMFnResult* exec(VMFnArgs* args) OVERRIDE; |
176 |
}; |
}; |
177 |
|
|
178 |
/** |
/** |
180 |
*/ |
*/ |
181 |
class CoreVMFunction_random : public VMIntResultFunction { |
class CoreVMFunction_random : public VMIntResultFunction { |
182 |
public: |
public: |
183 |
int minRequiredArgs() const { return 2; } |
vmint minRequiredArgs() const OVERRIDE { return 2; } |
184 |
int maxAllowedArgs() const { return 2; } |
vmint maxAllowedArgs() const OVERRIDE { return 2; } |
185 |
bool acceptsArgType(int iArg, ExprType_t type) const; |
bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE; |
186 |
ExprType_t argType(int iArg) const { return INT_EXPR; } |
ExprType_t argType(vmint iArg) const OVERRIDE { return INT_EXPR; } |
187 |
VMFnResult* exec(VMFnArgs* args); |
VMFnResult* exec(VMFnArgs* args) OVERRIDE; |
188 |
}; |
}; |
189 |
|
|
190 |
/** |
/** |
192 |
*/ |
*/ |
193 |
class CoreVMFunction_num_elements : public VMIntResultFunction { |
class CoreVMFunction_num_elements : public VMIntResultFunction { |
194 |
public: |
public: |
195 |
int minRequiredArgs() const { return 1; } |
vmint minRequiredArgs() const OVERRIDE { return 1; } |
196 |
int maxAllowedArgs() const { return 1; } |
vmint maxAllowedArgs() const OVERRIDE { return 1; } |
197 |
bool acceptsArgType(int iArg, ExprType_t type) const; |
bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE; |
198 |
ExprType_t argType(int iArg) const { return INT_ARR_EXPR; } |
ExprType_t argType(vmint iArg) const OVERRIDE { return INT_ARR_EXPR; } |
199 |
VMFnResult* exec(VMFnArgs* args); |
VMFnResult* exec(VMFnArgs* args) OVERRIDE; |
200 |
}; |
}; |
201 |
|
|
202 |
/** |
/** |
204 |
*/ |
*/ |
205 |
class CoreVMFunction_inc : public VMIntResultFunction { |
class CoreVMFunction_inc : public VMIntResultFunction { |
206 |
public: |
public: |
207 |
int minRequiredArgs() const { return 1; } |
vmint minRequiredArgs() const OVERRIDE { return 1; } |
208 |
int maxAllowedArgs() const { return 1; } |
vmint maxAllowedArgs() const OVERRIDE { return 1; } |
209 |
bool acceptsArgType(int iArg, ExprType_t type) const { return type == INT_EXPR; } |
bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE { return type == INT_EXPR; } |
210 |
ExprType_t argType(int iArg) const { return INT_EXPR; } |
ExprType_t argType(vmint iArg) const OVERRIDE { return INT_EXPR; } |
211 |
bool modifiesArg(int iArg) const { return true; } |
bool modifiesArg(vmint iArg) const OVERRIDE { return true; } |
212 |
VMFnResult* exec(VMFnArgs* args); |
VMFnResult* exec(VMFnArgs* args) OVERRIDE; |
213 |
}; |
}; |
214 |
|
|
215 |
/** |
/** |
217 |
*/ |
*/ |
218 |
class CoreVMFunction_dec : public VMIntResultFunction { |
class CoreVMFunction_dec : public VMIntResultFunction { |
219 |
public: |
public: |
220 |
int minRequiredArgs() const { return 1; } |
vmint minRequiredArgs() const OVERRIDE { return 1; } |
221 |
int maxAllowedArgs() const { return 1; } |
vmint maxAllowedArgs() const OVERRIDE { return 1; } |
222 |
bool acceptsArgType(int iArg, ExprType_t type) const { return type == INT_EXPR; } |
bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE { return type == INT_EXPR; } |
223 |
ExprType_t argType(int iArg) const { return INT_EXPR; } |
ExprType_t argType(vmint iArg) const OVERRIDE { return INT_EXPR; } |
224 |
bool modifiesArg(int iArg) const { return true; } |
bool modifiesArg(vmint iArg) const OVERRIDE { return true; } |
225 |
VMFnResult* exec(VMFnArgs* args); |
VMFnResult* exec(VMFnArgs* args) OVERRIDE; |
226 |
}; |
}; |
227 |
|
|
228 |
/** |
/** |
230 |
*/ |
*/ |
231 |
class CoreVMFunction_in_range : public VMIntResultFunction { |
class CoreVMFunction_in_range : public VMIntResultFunction { |
232 |
public: |
public: |
233 |
int minRequiredArgs() const { return 3; } |
vmint minRequiredArgs() const OVERRIDE { return 3; } |
234 |
int maxAllowedArgs() const { return 3; } |
vmint maxAllowedArgs() const OVERRIDE { return 3; } |
235 |
bool acceptsArgType(int iArg, ExprType_t type) const { return type == INT_EXPR; } |
bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE { return type == INT_EXPR; } |
236 |
ExprType_t argType(int iArg) const { return INT_EXPR; } |
ExprType_t argType(vmint iArg) const OVERRIDE { return INT_EXPR; } |
237 |
VMFnResult* exec(VMFnArgs* args); |
VMFnResult* exec(VMFnArgs* args) OVERRIDE; |
238 |
}; |
}; |
239 |
|
|
240 |
/** |
/** |
242 |
*/ |
*/ |
243 |
class CoreVMFunction_sh_left : public VMIntResultFunction { |
class CoreVMFunction_sh_left : public VMIntResultFunction { |
244 |
public: |
public: |
245 |
int minRequiredArgs() const { return 2; } |
vmint minRequiredArgs() const OVERRIDE { return 2; } |
246 |
int maxAllowedArgs() const { return 2; } |
vmint maxAllowedArgs() const OVERRIDE { return 2; } |
247 |
bool acceptsArgType(int iArg, ExprType_t type) const { return type == INT_EXPR; } |
bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE { return type == INT_EXPR; } |
248 |
ExprType_t argType(int iArg) const { return INT_EXPR; } |
ExprType_t argType(vmint iArg) const OVERRIDE { return INT_EXPR; } |
249 |
VMFnResult* exec(VMFnArgs* args); |
VMFnResult* exec(VMFnArgs* args) OVERRIDE; |
250 |
}; |
}; |
251 |
|
|
252 |
/** |
/** |
254 |
*/ |
*/ |
255 |
class CoreVMFunction_sh_right : public VMIntResultFunction { |
class CoreVMFunction_sh_right : public VMIntResultFunction { |
256 |
public: |
public: |
257 |
int minRequiredArgs() const { return 2; } |
vmint minRequiredArgs() const OVERRIDE { return 2; } |
258 |
int maxAllowedArgs() const { return 2; } |
vmint maxAllowedArgs() const OVERRIDE { return 2; } |
259 |
bool acceptsArgType(int iArg, ExprType_t type) const { return type == INT_EXPR; } |
bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE { return type == INT_EXPR; } |
260 |
ExprType_t argType(int iArg) const { return INT_EXPR; } |
ExprType_t argType(vmint iArg) const OVERRIDE { return INT_EXPR; } |
261 |
VMFnResult* exec(VMFnArgs* args); |
VMFnResult* exec(VMFnArgs* args) OVERRIDE; |
262 |
}; |
}; |
263 |
|
|
264 |
/** |
/** |
266 |
*/ |
*/ |
267 |
class CoreVMFunction_min : public VMIntResultFunction { |
class CoreVMFunction_min : public VMIntResultFunction { |
268 |
public: |
public: |
269 |
int minRequiredArgs() const { return 2; } |
vmint minRequiredArgs() const OVERRIDE { return 2; } |
270 |
int maxAllowedArgs() const { return 2; } |
vmint maxAllowedArgs() const OVERRIDE { return 2; } |
271 |
bool acceptsArgType(int iArg, ExprType_t type) const { return type == INT_EXPR; } |
bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE { return type == INT_EXPR; } |
272 |
ExprType_t argType(int iArg) const { return INT_EXPR; } |
ExprType_t argType(vmint iArg) const OVERRIDE { return INT_EXPR; } |
273 |
VMFnResult* exec(VMFnArgs* args); |
VMFnResult* exec(VMFnArgs* args) OVERRIDE; |
274 |
}; |
}; |
275 |
|
|
276 |
/** |
/** |
278 |
*/ |
*/ |
279 |
class CoreVMFunction_max : public VMIntResultFunction { |
class CoreVMFunction_max : public VMIntResultFunction { |
280 |
public: |
public: |
281 |
int minRequiredArgs() const { return 2; } |
vmint minRequiredArgs() const OVERRIDE { return 2; } |
282 |
int maxAllowedArgs() const { return 2; } |
vmint maxAllowedArgs() const OVERRIDE { return 2; } |
283 |
bool acceptsArgType(int iArg, ExprType_t type) const { return type == INT_EXPR; } |
bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE { return type == INT_EXPR; } |
284 |
ExprType_t argType(int iArg) const { return INT_EXPR; } |
ExprType_t argType(vmint iArg) const OVERRIDE { return INT_EXPR; } |
285 |
VMFnResult* exec(VMFnArgs* args); |
VMFnResult* exec(VMFnArgs* args) OVERRIDE; |
286 |
|
}; |
287 |
|
|
288 |
|
/** |
289 |
|
* Implements the built-in array_equal() script function. |
290 |
|
*/ |
291 |
|
class CoreVMFunction_array_equal : public VMIntResultFunction { |
292 |
|
public: |
293 |
|
vmint minRequiredArgs() const OVERRIDE { return 2; } |
294 |
|
vmint maxAllowedArgs() const OVERRIDE { return 2; } |
295 |
|
bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE { return type == INT_ARR_EXPR; } |
296 |
|
ExprType_t argType(vmint iArg) const OVERRIDE { return INT_ARR_EXPR; } |
297 |
|
VMFnResult* exec(VMFnArgs* args) OVERRIDE; |
298 |
|
}; |
299 |
|
|
300 |
|
/** |
301 |
|
* Implements the built-in search() script function. |
302 |
|
*/ |
303 |
|
class CoreVMFunction_search : public VMIntResultFunction { |
304 |
|
public: |
305 |
|
vmint minRequiredArgs() const OVERRIDE { return 2; } |
306 |
|
vmint maxAllowedArgs() const OVERRIDE { return 2; } |
307 |
|
bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE; |
308 |
|
ExprType_t argType(vmint iArg) const OVERRIDE; |
309 |
|
VMFnResult* exec(VMFnArgs* args) OVERRIDE; |
310 |
|
}; |
311 |
|
|
312 |
|
/** |
313 |
|
* Implements the built-in sort() script function. |
314 |
|
*/ |
315 |
|
class CoreVMFunction_sort : public VMEmptyResultFunction { |
316 |
|
public: |
317 |
|
vmint minRequiredArgs() const OVERRIDE { return 1; } |
318 |
|
vmint maxAllowedArgs() const OVERRIDE { return 2; } |
319 |
|
bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE; |
320 |
|
ExprType_t argType(vmint iArg) const OVERRIDE; |
321 |
|
bool modifiesArg(vmint iArg) const OVERRIDE { return iArg == 0; } |
322 |
|
VMFnResult* exec(VMFnArgs* args) OVERRIDE; |
323 |
}; |
}; |
324 |
|
|
325 |
} // namespace LinuxSampler |
} // namespace LinuxSampler |