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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3561 - (hide annotations) (download) (as text)
Fri Aug 23 11:44:00 2019 UTC (4 years, 8 months ago) by schoenebeck
File MIME type: text/x-c++hdr
File size: 11771 byte(s)
NKSP: Added standard units support for numbers and final "!" operator:

* NKSP strictness: Variable names, function names and preprocessor condition
  names must start with a regular character (a-z or A-Z); starting them with
  a digit or underscore is no longer allowed.

* NKSP parser fix: equal comparison operator "=" and not equal comparison
  operator "#" must only accept integer operands.

* NKSP language: Implemented support for standard units like Hertz, seconds,
  Bel including support for metric unit prefixes; so one can now e.g.
  conveniently use numbers in scripts like "5us" meaning "5 microseconds",
  or e.g. "12kHz" meaning "12 kilo Hertz", or e.g. "-14mdB" meaning
  "minus 14 Millidecibel", or e.g. "28c" meaning "28 cents" (for tuning).

* NKSP language: Introduced "final" operator "!" which is specifically
  intended for synthesis parameter values to denote that the synthesis
  parameter value is intended to be the "final" value for that synthesis
  parameter that should explicitly be used by the engine and thus causing
  the sampler engine to ignore all other modulation sources for the same
  synthesis parameter (like e.g. LFO, EG); by simply prefixing a value,
  variable or formula with this new "!" operator the expression is marked as
  being "final".

* Bumped version (2.1.1.svn4).

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 2581 class VMEmptyResult : public VMFnResult, public VMExpr {
28     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 2598 class VMIntResult : public VMFnResult, public VMIntExpr {
43     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 2598
47 schoenebeck 3561 VMIntResult() : flags(STMT_SUCCESS), value(0) {}
48 schoenebeck 3557 vmint evalInt() OVERRIDE { return value; }
49 schoenebeck 3054 VMExpr* resultValue() OVERRIDE { return this; }
50     StmtFlags_t resultFlags() OVERRIDE { return flags; }
51 schoenebeck 2945 bool isConstExpr() const OVERRIDE { return false; }
52 schoenebeck 3561 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 schoenebeck 2598 };
56    
57 schoenebeck 2727 /**
58     * An instance of this class is returned by built-in function implementations
59     * which return a string value as function return value.
60     */
61 schoenebeck 2581 class VMStringResult : public VMFnResult, public VMStringExpr {
62     public:
63 schoenebeck 2727 StmtFlags_t flags; ///< general completion status (i.e. success or failure) of the function call
64     String value; ///< result value of the function call
65 schoenebeck 2581
66     VMStringResult() : flags(STMT_SUCCESS) {}
67 schoenebeck 3054 String evalStr() OVERRIDE { return value; }
68     VMExpr* resultValue() OVERRIDE { return this; }
69     StmtFlags_t resultFlags() OVERRIDE { return flags; }
70 schoenebeck 2945 bool isConstExpr() const OVERRIDE { return false; }
71 schoenebeck 2581 };
72    
73 schoenebeck 2727 /**
74     * Abstract base class for built-in script functions which do not return any
75     * function return value (void).
76     */
77 schoenebeck 2581 class VMEmptyResultFunction : public VMFunction {
78     protected:
79 schoenebeck 3034 virtual ~VMEmptyResultFunction() {}
80 schoenebeck 3054 ExprType_t returnType() OVERRIDE { return EMPTY_EXPR; }
81 schoenebeck 2581 VMFnResult* errorResult();
82     VMFnResult* successResult();
83 schoenebeck 3557 bool modifiesArg(vmint iArg) const OVERRIDE { return false; }
84 schoenebeck 2581 protected:
85     VMEmptyResult result;
86     };
87    
88 schoenebeck 2727 /**
89     * Abstract base class for built-in script functions which return an integer
90     * (scalar) as their function return value.
91     */
92 schoenebeck 2598 class VMIntResultFunction : public VMFunction {
93     protected:
94 schoenebeck 3034 virtual ~VMIntResultFunction() {}
95 schoenebeck 3054 ExprType_t returnType() OVERRIDE { return INT_EXPR; }
96 schoenebeck 3557 VMFnResult* errorResult(vmint i = 0);
97     VMFnResult* successResult(vmint i = 0);
98     bool modifiesArg(vmint iArg) const OVERRIDE { return false; }
99 schoenebeck 2598 protected:
100     VMIntResult result;
101     };
102    
103 schoenebeck 2727 /**
104     * Abstract base class for built-in script functions which return a string as
105     * their function return value.
106     */
107 schoenebeck 2581 class VMStringResultFunction : public VMFunction {
108     protected:
109 schoenebeck 3034 virtual ~VMStringResultFunction() {}
110 schoenebeck 3054 ExprType_t returnType() OVERRIDE { return STRING_EXPR; }
111 schoenebeck 2581 VMFnResult* errorResult(const String& s = "");
112     VMFnResult* successResult(const String& s = "");
113 schoenebeck 3557 bool modifiesArg(vmint iArg) const OVERRIDE { return false; }
114 schoenebeck 2581 protected:
115     VMStringResult result;
116     };
117    
118 schoenebeck 2727
119     ///////////////////////////////////////////////////////////////////////////
120     // implementations of core built-in script functions ...
121    
122     /**
123     * Implements the built-in message() script function.
124     */
125 schoenebeck 2581 class CoreVMFunction_message : public VMEmptyResultFunction {
126     public:
127 schoenebeck 3557 vmint minRequiredArgs() const OVERRIDE { return 1; }
128     vmint maxAllowedArgs() const OVERRIDE { return 1; }
129     bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE;
130     ExprType_t argType(vmint iArg) const OVERRIDE { return STRING_EXPR; }
131     VMFnResult* exec(VMFnArgs* args) OVERRIDE;
132 schoenebeck 2581 };
133    
134 schoenebeck 2727 /**
135     * Implements the built-in exit() script function.
136     */
137 schoenebeck 2581 class CoreVMFunction_exit : public VMEmptyResultFunction {
138     public:
139 schoenebeck 3551 CoreVMFunction_exit(ScriptVM* vm) : vm(vm) {}
140 schoenebeck 3557 vmint minRequiredArgs() const OVERRIDE { return 0; }
141     vmint maxAllowedArgs() const OVERRIDE;
142     bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE;
143     ExprType_t argType(vmint iArg) const OVERRIDE { return INT_EXPR; }
144     VMFnResult* exec(VMFnArgs* args) OVERRIDE;
145 schoenebeck 3551 protected:
146     ScriptVM* vm;
147 schoenebeck 2581 };
148    
149 schoenebeck 2727 /**
150     * Implements the built-in wait() script function.
151     */
152 schoenebeck 2581 class CoreVMFunction_wait : public VMEmptyResultFunction {
153     public:
154     CoreVMFunction_wait(ScriptVM* vm) : vm(vm) {}
155 schoenebeck 3557 vmint minRequiredArgs() const OVERRIDE { return 1; }
156     vmint maxAllowedArgs() const OVERRIDE { return 1; }
157     bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE { return type == INT_EXPR; }
158 schoenebeck 3561 bool acceptsArgUnitType(vmint iArg, StdUnit_t type) const OVERRIDE;
159     bool acceptsArgUnitPrefix(vmint iArg) const OVERRIDE;
160 schoenebeck 3557 ExprType_t argType(vmint iArg) const OVERRIDE { return INT_EXPR; }
161     VMFnResult* exec(VMFnArgs* args) OVERRIDE;
162 schoenebeck 2581 protected:
163     ScriptVM* vm;
164     };
165    
166 schoenebeck 2727 /**
167     * Implements the built-in abs() script function.
168     */
169 schoenebeck 2619 class CoreVMFunction_abs : public VMIntResultFunction {
170     public:
171 schoenebeck 3557 vmint minRequiredArgs() const OVERRIDE { return 1; }
172     vmint maxAllowedArgs() const OVERRIDE { return 1; }
173     bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE;
174     ExprType_t argType(vmint iArg) const OVERRIDE { return INT_EXPR; }
175     VMFnResult* exec(VMFnArgs* args) OVERRIDE;
176 schoenebeck 2619 };
177    
178 schoenebeck 2727 /**
179     * Implements the built-in random() script function.
180     */
181 schoenebeck 2619 class CoreVMFunction_random : public VMIntResultFunction {
182     public:
183 schoenebeck 3557 vmint minRequiredArgs() const OVERRIDE { return 2; }
184     vmint maxAllowedArgs() const OVERRIDE { return 2; }
185     bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE;
186     ExprType_t argType(vmint iArg) const OVERRIDE { return INT_EXPR; }
187     VMFnResult* exec(VMFnArgs* args) OVERRIDE;
188 schoenebeck 2619 };
189    
190 schoenebeck 2727 /**
191     * Implements the built-in num_elements() script function.
192     */
193 schoenebeck 2619 class CoreVMFunction_num_elements : public VMIntResultFunction {
194     public:
195 schoenebeck 3557 vmint minRequiredArgs() const OVERRIDE { return 1; }
196     vmint maxAllowedArgs() const OVERRIDE { return 1; }
197     bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE;
198     ExprType_t argType(vmint iArg) const OVERRIDE { return INT_ARR_EXPR; }
199     VMFnResult* exec(VMFnArgs* args) OVERRIDE;
200 schoenebeck 2619 };
201    
202 schoenebeck 2945 /**
203     * Implements the built-in inc() script function.
204     */
205     class CoreVMFunction_inc : public VMIntResultFunction {
206     public:
207 schoenebeck 3557 vmint minRequiredArgs() const OVERRIDE { return 1; }
208     vmint maxAllowedArgs() const OVERRIDE { return 1; }
209     bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE { return type == INT_EXPR; }
210     ExprType_t argType(vmint iArg) const OVERRIDE { return INT_EXPR; }
211     bool modifiesArg(vmint iArg) const OVERRIDE { return true; }
212     VMFnResult* exec(VMFnArgs* args) OVERRIDE;
213 schoenebeck 2945 };
214    
215     /**
216     * Implements the built-in dec() script function.
217     */
218     class CoreVMFunction_dec : public VMIntResultFunction {
219     public:
220 schoenebeck 3557 vmint minRequiredArgs() const OVERRIDE { return 1; }
221     vmint maxAllowedArgs() const OVERRIDE { return 1; }
222     bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE { return type == INT_EXPR; }
223     ExprType_t argType(vmint iArg) const OVERRIDE { return INT_EXPR; }
224     bool modifiesArg(vmint iArg) const OVERRIDE { return true; }
225     VMFnResult* exec(VMFnArgs* args) OVERRIDE;
226 schoenebeck 2945 };
227    
228 schoenebeck 2965 /**
229 schoenebeck 3076 * Implements the built-in in_range() script function.
230     */
231     class CoreVMFunction_in_range : public VMIntResultFunction {
232     public:
233 schoenebeck 3557 vmint minRequiredArgs() const OVERRIDE { return 3; }
234     vmint maxAllowedArgs() const OVERRIDE { return 3; }
235     bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE { return type == INT_EXPR; }
236     ExprType_t argType(vmint iArg) const OVERRIDE { return INT_EXPR; }
237     VMFnResult* exec(VMFnArgs* args) OVERRIDE;
238 schoenebeck 3076 };
239    
240     /**
241 schoenebeck 2965 * Implements the built-in sh_left() script function.
242     */
243     class CoreVMFunction_sh_left : public VMIntResultFunction {
244     public:
245 schoenebeck 3557 vmint minRequiredArgs() const OVERRIDE { return 2; }
246     vmint maxAllowedArgs() const OVERRIDE { return 2; }
247     bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE { return type == INT_EXPR; }
248     ExprType_t argType(vmint iArg) const OVERRIDE { return INT_EXPR; }
249     VMFnResult* exec(VMFnArgs* args) OVERRIDE;
250 schoenebeck 2965 };
251    
252     /**
253     * Implements the built-in sh_right() script function.
254     */
255     class CoreVMFunction_sh_right : public VMIntResultFunction {
256     public:
257 schoenebeck 3557 vmint minRequiredArgs() const OVERRIDE { return 2; }
258     vmint maxAllowedArgs() const OVERRIDE { return 2; }
259     bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE { return type == INT_EXPR; }
260     ExprType_t argType(vmint iArg) const OVERRIDE { return INT_EXPR; }
261     VMFnResult* exec(VMFnArgs* args) OVERRIDE;
262 schoenebeck 2965 };
263    
264 schoenebeck 2970 /**
265     * Implements the built-in min() script function.
266     */
267     class CoreVMFunction_min : public VMIntResultFunction {
268     public:
269 schoenebeck 3557 vmint minRequiredArgs() const OVERRIDE { return 2; }
270     vmint maxAllowedArgs() const OVERRIDE { return 2; }
271     bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE { return type == INT_EXPR; }
272     ExprType_t argType(vmint iArg) const OVERRIDE { return INT_EXPR; }
273     VMFnResult* exec(VMFnArgs* args) OVERRIDE;
274 schoenebeck 2970 };
275    
276     /**
277     * Implements the built-in max() script function.
278     */
279     class CoreVMFunction_max : public VMIntResultFunction {
280     public:
281 schoenebeck 3557 vmint minRequiredArgs() const OVERRIDE { return 2; }
282     vmint maxAllowedArgs() const OVERRIDE { return 2; }
283     bool acceptsArgType(vmint iArg, ExprType_t type) const OVERRIDE { return type == INT_EXPR; }
284     ExprType_t argType(vmint iArg) const OVERRIDE { return INT_EXPR; }
285     VMFnResult* exec(VMFnArgs* args) OVERRIDE;
286 schoenebeck 2970 };
287    
288 schoenebeck 3221 /**
289     * Implements the built-in array_equal() script function.
290     */
291     class CoreVMFunction_array_equal : public VMIntResultFunction {
292     public:
293 schoenebeck 3557 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 schoenebeck 3221 };
299    
300     /**
301     * Implements the built-in search() script function.
302     */
303     class CoreVMFunction_search : public VMIntResultFunction {
304     public:
305 schoenebeck 3557 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 schoenebeck 3221 };
311    
312     /**
313     * Implements the built-in sort() script function.
314     */
315     class CoreVMFunction_sort : public VMEmptyResultFunction {
316     public:
317 schoenebeck 3557 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 schoenebeck 3221 };
324    
325 schoenebeck 2581 } // namespace LinuxSampler
326    
327     #endif // LS_COREVMFUNCTIONS_H

  ViewVC Help
Powered by ViewVC