1 |
/* |
/* |
2 |
* Copyright (c) 2014 Christian Schoenebeck |
* Copyright (c) 2014 - 2017 Christian Schoenebeck |
3 |
* |
* |
4 |
* http://www.linuxsampler.org |
* http://www.linuxsampler.org |
5 |
* |
* |
12 |
|
|
13 |
#include "../../common/global.h" |
#include "../../common/global.h" |
14 |
#include "../../scriptvm/CoreVMFunctions.h" |
#include "../../scriptvm/CoreVMFunctions.h" |
15 |
|
#include "Note.h" |
16 |
|
|
17 |
namespace LinuxSampler { |
namespace LinuxSampler { |
18 |
|
|
19 |
|
class EventGroup; |
20 |
class InstrumentScriptVM; |
class InstrumentScriptVM; |
21 |
|
|
22 |
class InstrumentScriptVMFunction_play_note : public VMIntResultFunction { |
class InstrumentScriptVMFunction_play_note : public VMIntResultFunction { |
46 |
class InstrumentScriptVMFunction_ignore_event : public VMEmptyResultFunction { |
class InstrumentScriptVMFunction_ignore_event : public VMEmptyResultFunction { |
47 |
public: |
public: |
48 |
InstrumentScriptVMFunction_ignore_event(InstrumentScriptVM* parent); |
InstrumentScriptVMFunction_ignore_event(InstrumentScriptVM* parent); |
49 |
int minRequiredArgs() const { return 1; } |
int minRequiredArgs() const { return 0; } |
50 |
int maxAllowedArgs() const { return 1; } |
int maxAllowedArgs() const { return 1; } |
51 |
bool acceptsArgType(int iArg, ExprType_t type) const { return type == INT_EXPR;} |
bool acceptsArgType(int iArg, ExprType_t type) const; |
52 |
ExprType_t argType(int iArg) const { return INT_EXPR; } |
ExprType_t argType(int iArg) const { return INT_EXPR; } |
53 |
VMFnResult* exec(VMFnArgs* args); |
VMFnResult* exec(VMFnArgs* args); |
54 |
protected: |
protected: |
72 |
InstrumentScriptVMFunction_note_off(InstrumentScriptVM* parent); |
InstrumentScriptVMFunction_note_off(InstrumentScriptVM* parent); |
73 |
int minRequiredArgs() const { return 1; } |
int minRequiredArgs() const { return 1; } |
74 |
int maxAllowedArgs() const { return 2; } |
int maxAllowedArgs() const { return 2; } |
75 |
|
bool acceptsArgType(int iArg, ExprType_t type) const; |
76 |
|
ExprType_t argType(int iArg) const { return INT_EXPR; } |
77 |
|
VMFnResult* exec(VMFnArgs* args); |
78 |
|
protected: |
79 |
|
InstrumentScriptVM* m_vm; |
80 |
|
}; |
81 |
|
|
82 |
|
class InstrumentScriptVMFunction_set_event_mark : public VMEmptyResultFunction { |
83 |
|
public: |
84 |
|
InstrumentScriptVMFunction_set_event_mark(InstrumentScriptVM* parent); |
85 |
|
int minRequiredArgs() const { return 2; } |
86 |
|
int maxAllowedArgs() const { return 2; } |
87 |
|
bool acceptsArgType(int iArg, ExprType_t type) const { return type == INT_EXPR;} |
88 |
|
ExprType_t argType(int iArg) const { return INT_EXPR; } |
89 |
|
VMFnResult* exec(VMFnArgs* args); |
90 |
|
protected: |
91 |
|
InstrumentScriptVM* m_vm; |
92 |
|
}; |
93 |
|
|
94 |
|
class InstrumentScriptVMFunction_delete_event_mark : public VMEmptyResultFunction { |
95 |
|
public: |
96 |
|
InstrumentScriptVMFunction_delete_event_mark(InstrumentScriptVM* parent); |
97 |
|
int minRequiredArgs() const { return 2; } |
98 |
|
int maxAllowedArgs() const { return 2; } |
99 |
|
bool acceptsArgType(int iArg, ExprType_t type) const { return type == INT_EXPR;} |
100 |
|
ExprType_t argType(int iArg) const { return INT_EXPR; } |
101 |
|
VMFnResult* exec(VMFnArgs* args); |
102 |
|
protected: |
103 |
|
InstrumentScriptVM* m_vm; |
104 |
|
}; |
105 |
|
|
106 |
|
class InstrumentScriptVMFunction_by_marks : public VMFunction { |
107 |
|
public: |
108 |
|
InstrumentScriptVMFunction_by_marks(InstrumentScriptVM* parent); |
109 |
|
int minRequiredArgs() const OVERRIDE { return 1; } |
110 |
|
int maxAllowedArgs() const OVERRIDE { return 1; } |
111 |
|
bool acceptsArgType(int iArg, ExprType_t type) const OVERRIDE { return type == INT_EXPR;} |
112 |
|
bool modifiesArg(int iArg) const OVERRIDE { return false; } |
113 |
|
ExprType_t argType(int iArg) const OVERRIDE { return INT_EXPR; } |
114 |
|
ExprType_t returnType() OVERRIDE { return INT_ARR_EXPR; } |
115 |
|
VMFnResult* exec(VMFnArgs* args) OVERRIDE; |
116 |
|
protected: |
117 |
|
InstrumentScriptVM* m_vm; |
118 |
|
class Result : public VMFnResult, public VMIntArrayExpr { |
119 |
|
public: |
120 |
|
StmtFlags_t flags; |
121 |
|
EventGroup* eventGroup; |
122 |
|
|
123 |
|
int arraySize() const OVERRIDE; |
124 |
|
int evalIntElement(uint i) OVERRIDE; |
125 |
|
void assignIntElement(uint i, int value) OVERRIDE {} // ignore assignment |
126 |
|
VMExpr* resultValue() OVERRIDE { return this; } |
127 |
|
StmtFlags_t resultFlags() OVERRIDE { return flags; } |
128 |
|
bool isConstExpr() const OVERRIDE { return false; } |
129 |
|
} m_result; |
130 |
|
|
131 |
|
VMFnResult* errorResult(); |
132 |
|
VMFnResult* successResult(EventGroup* eventGroup); |
133 |
|
}; |
134 |
|
|
135 |
|
class InstrumentScriptVMFunction_change_vol : public VMEmptyResultFunction { |
136 |
|
public: |
137 |
|
InstrumentScriptVMFunction_change_vol(InstrumentScriptVM* parent); |
138 |
|
int minRequiredArgs() const { return 2; } |
139 |
|
int maxAllowedArgs() const { return 3; } |
140 |
|
bool acceptsArgType(int iArg, ExprType_t type) const; |
141 |
|
ExprType_t argType(int iArg) const { return INT_EXPR; } |
142 |
|
VMFnResult* exec(VMFnArgs* args); |
143 |
|
protected: |
144 |
|
InstrumentScriptVM* m_vm; |
145 |
|
}; |
146 |
|
|
147 |
|
class InstrumentScriptVMFunction_change_tune : public VMEmptyResultFunction { |
148 |
|
public: |
149 |
|
InstrumentScriptVMFunction_change_tune(InstrumentScriptVM* parent); |
150 |
|
int minRequiredArgs() const { return 2; } |
151 |
|
int maxAllowedArgs() const { return 3; } |
152 |
|
bool acceptsArgType(int iArg, ExprType_t type) const; |
153 |
|
ExprType_t argType(int iArg) const { return INT_EXPR; } |
154 |
|
VMFnResult* exec(VMFnArgs* args); |
155 |
|
protected: |
156 |
|
InstrumentScriptVM* m_vm; |
157 |
|
}; |
158 |
|
|
159 |
|
class InstrumentScriptVMFunction_change_pan : public VMEmptyResultFunction { |
160 |
|
public: |
161 |
|
InstrumentScriptVMFunction_change_pan(InstrumentScriptVM* parent); |
162 |
|
int minRequiredArgs() const { return 2; } |
163 |
|
int maxAllowedArgs() const { return 3; } |
164 |
|
bool acceptsArgType(int iArg, ExprType_t type) const; |
165 |
|
ExprType_t argType(int iArg) const { return INT_EXPR; } |
166 |
|
VMFnResult* exec(VMFnArgs* args); |
167 |
|
protected: |
168 |
|
InstrumentScriptVM* m_vm; |
169 |
|
}; |
170 |
|
|
171 |
|
class InstrumentScriptVMFunction_change_cutoff : public VMEmptyResultFunction { |
172 |
|
public: |
173 |
|
InstrumentScriptVMFunction_change_cutoff(InstrumentScriptVM* parent); |
174 |
|
int minRequiredArgs() const { return 2; } |
175 |
|
int maxAllowedArgs() const { return 2; } |
176 |
|
bool acceptsArgType(int iArg, ExprType_t type) const; |
177 |
|
ExprType_t argType(int iArg) const { return INT_EXPR; } |
178 |
|
VMFnResult* exec(VMFnArgs* args); |
179 |
|
protected: |
180 |
|
InstrumentScriptVM* m_vm; |
181 |
|
}; |
182 |
|
|
183 |
|
class InstrumentScriptVMFunction_change_reso : public VMEmptyResultFunction { |
184 |
|
public: |
185 |
|
InstrumentScriptVMFunction_change_reso(InstrumentScriptVM* parent); |
186 |
|
int minRequiredArgs() const { return 2; } |
187 |
|
int maxAllowedArgs() const { return 2; } |
188 |
|
bool acceptsArgType(int iArg, ExprType_t type) const; |
189 |
|
ExprType_t argType(int iArg) const { return INT_EXPR; } |
190 |
|
VMFnResult* exec(VMFnArgs* args); |
191 |
|
protected: |
192 |
|
InstrumentScriptVM* m_vm; |
193 |
|
}; |
194 |
|
|
195 |
|
class InstrumentScriptVMFunction_change_attack : public VMEmptyResultFunction { |
196 |
|
public: |
197 |
|
InstrumentScriptVMFunction_change_attack(InstrumentScriptVM* parent); |
198 |
|
int minRequiredArgs() const { return 2; } |
199 |
|
int maxAllowedArgs() const { return 2; } |
200 |
|
bool acceptsArgType(int iArg, ExprType_t type) const; |
201 |
|
ExprType_t argType(int iArg) const { return INT_EXPR; } |
202 |
|
VMFnResult* exec(VMFnArgs* args); |
203 |
|
protected: |
204 |
|
InstrumentScriptVM* m_vm; |
205 |
|
}; |
206 |
|
|
207 |
|
class InstrumentScriptVMFunction_change_decay : public VMEmptyResultFunction { |
208 |
|
public: |
209 |
|
InstrumentScriptVMFunction_change_decay(InstrumentScriptVM* parent); |
210 |
|
int minRequiredArgs() const { return 2; } |
211 |
|
int maxAllowedArgs() const { return 2; } |
212 |
|
bool acceptsArgType(int iArg, ExprType_t type) const; |
213 |
|
ExprType_t argType(int iArg) const { return INT_EXPR; } |
214 |
|
VMFnResult* exec(VMFnArgs* args); |
215 |
|
protected: |
216 |
|
InstrumentScriptVM* m_vm; |
217 |
|
}; |
218 |
|
|
219 |
|
class InstrumentScriptVMFunction_change_release : public VMEmptyResultFunction { |
220 |
|
public: |
221 |
|
InstrumentScriptVMFunction_change_release(InstrumentScriptVM* parent); |
222 |
|
int minRequiredArgs() const { return 2; } |
223 |
|
int maxAllowedArgs() const { return 2; } |
224 |
|
bool acceptsArgType(int iArg, ExprType_t type) const; |
225 |
|
ExprType_t argType(int iArg) const { return INT_EXPR; } |
226 |
|
VMFnResult* exec(VMFnArgs* args); |
227 |
|
protected: |
228 |
|
InstrumentScriptVM* m_vm; |
229 |
|
}; |
230 |
|
|
231 |
|
class VMChangeSynthParamFunction : public VMEmptyResultFunction { |
232 |
|
public: |
233 |
|
VMChangeSynthParamFunction(InstrumentScriptVM* parent) : m_vm(parent) {} |
234 |
|
int minRequiredArgs() const { return 2; } |
235 |
|
int maxAllowedArgs() const { return 2; } |
236 |
|
bool acceptsArgType(int iArg, ExprType_t type) const; |
237 |
|
ExprType_t argType(int iArg) const { return INT_EXPR; } |
238 |
|
|
239 |
|
template<float NoteBase::_Override::*T_noteParam, int T_synthParam, |
240 |
|
bool T_isNormalizedParam, int T_maxValue, int T_minValue> |
241 |
|
VMFnResult* execTemplate(VMFnArgs* args, const char* functionName); |
242 |
|
protected: |
243 |
|
InstrumentScriptVM* m_vm; |
244 |
|
}; |
245 |
|
|
246 |
|
class InstrumentScriptVMFunction_change_amp_lfo_depth : public VMChangeSynthParamFunction { |
247 |
|
public: |
248 |
|
InstrumentScriptVMFunction_change_amp_lfo_depth(InstrumentScriptVM* parent) : VMChangeSynthParamFunction(parent) {} |
249 |
|
VMFnResult* exec(VMFnArgs* args); |
250 |
|
}; |
251 |
|
|
252 |
|
class InstrumentScriptVMFunction_change_amp_lfo_freq : public VMChangeSynthParamFunction { |
253 |
|
public: |
254 |
|
InstrumentScriptVMFunction_change_amp_lfo_freq(InstrumentScriptVM* parent) : VMChangeSynthParamFunction(parent) {} |
255 |
|
VMFnResult* exec(VMFnArgs* args); |
256 |
|
}; |
257 |
|
|
258 |
|
class InstrumentScriptVMFunction_change_pitch_lfo_depth : public VMChangeSynthParamFunction { |
259 |
|
public: |
260 |
|
InstrumentScriptVMFunction_change_pitch_lfo_depth(InstrumentScriptVM* parent) : VMChangeSynthParamFunction(parent) {} |
261 |
|
VMFnResult* exec(VMFnArgs* args); |
262 |
|
}; |
263 |
|
|
264 |
|
class InstrumentScriptVMFunction_change_pitch_lfo_freq : public VMChangeSynthParamFunction { |
265 |
|
public: |
266 |
|
InstrumentScriptVMFunction_change_pitch_lfo_freq(InstrumentScriptVM* parent) : VMChangeSynthParamFunction(parent) {} |
267 |
|
VMFnResult* exec(VMFnArgs* args); |
268 |
|
}; |
269 |
|
|
270 |
|
class InstrumentScriptVMFunction_change_vol_time : public VMChangeSynthParamFunction { |
271 |
|
public: |
272 |
|
InstrumentScriptVMFunction_change_vol_time(InstrumentScriptVM* parent) : VMChangeSynthParamFunction(parent) {} |
273 |
|
VMFnResult* exec(VMFnArgs* args); |
274 |
|
}; |
275 |
|
|
276 |
|
class InstrumentScriptVMFunction_change_tune_time : public VMChangeSynthParamFunction { |
277 |
|
public: |
278 |
|
InstrumentScriptVMFunction_change_tune_time(InstrumentScriptVM* parent) : VMChangeSynthParamFunction(parent) {} |
279 |
|
VMFnResult* exec(VMFnArgs* args); |
280 |
|
}; |
281 |
|
|
282 |
|
class VMChangeFadeCurveFunction : public VMEmptyResultFunction { |
283 |
|
public: |
284 |
|
VMChangeFadeCurveFunction(InstrumentScriptVM* parent) : m_vm(parent) {} |
285 |
|
int minRequiredArgs() const { return 2; } |
286 |
|
int maxAllowedArgs() const { return 2; } |
287 |
|
bool acceptsArgType(int iArg, ExprType_t type) const; |
288 |
|
ExprType_t argType(int iArg) const { return INT_EXPR; } |
289 |
|
|
290 |
|
template<fade_curve_t NoteBase::_Override::*T_noteParam, int T_synthParam> |
291 |
|
VMFnResult* execTemplate(VMFnArgs* args, const char* functionName); |
292 |
|
protected: |
293 |
|
InstrumentScriptVM* m_vm; |
294 |
|
}; |
295 |
|
|
296 |
|
class InstrumentScriptVMFunction_change_vol_curve : public VMChangeFadeCurveFunction { |
297 |
|
public: |
298 |
|
InstrumentScriptVMFunction_change_vol_curve(InstrumentScriptVM* parent) : VMChangeFadeCurveFunction(parent) {} |
299 |
|
VMFnResult* exec(VMFnArgs* args); |
300 |
|
}; |
301 |
|
|
302 |
|
class InstrumentScriptVMFunction_change_tune_curve : public VMChangeFadeCurveFunction { |
303 |
|
public: |
304 |
|
InstrumentScriptVMFunction_change_tune_curve(InstrumentScriptVM* parent) : VMChangeFadeCurveFunction(parent) {} |
305 |
|
VMFnResult* exec(VMFnArgs* args); |
306 |
|
}; |
307 |
|
|
308 |
|
class InstrumentScriptVMFunction_fade_in : public VMEmptyResultFunction { |
309 |
|
public: |
310 |
|
InstrumentScriptVMFunction_fade_in(InstrumentScriptVM* parent); |
311 |
|
int minRequiredArgs() const { return 2; } |
312 |
|
int maxAllowedArgs() const { return 2; } |
313 |
|
bool acceptsArgType(int iArg, ExprType_t type) const; |
314 |
|
ExprType_t argType(int iArg) const { return INT_EXPR; } |
315 |
|
VMFnResult* exec(VMFnArgs* args); |
316 |
|
protected: |
317 |
|
InstrumentScriptVM* m_vm; |
318 |
|
}; |
319 |
|
|
320 |
|
class InstrumentScriptVMFunction_fade_out : public VMEmptyResultFunction { |
321 |
|
public: |
322 |
|
InstrumentScriptVMFunction_fade_out(InstrumentScriptVM* parent); |
323 |
|
int minRequiredArgs() const { return 2; } |
324 |
|
int maxAllowedArgs() const { return 3; } |
325 |
|
bool acceptsArgType(int iArg, ExprType_t type) const; |
326 |
|
ExprType_t argType(int iArg) const { return INT_EXPR; } |
327 |
|
VMFnResult* exec(VMFnArgs* args); |
328 |
|
protected: |
329 |
|
InstrumentScriptVM* m_vm; |
330 |
|
}; |
331 |
|
|
332 |
|
class InstrumentScriptVMFunction_get_event_par : public VMIntResultFunction { |
333 |
|
public: |
334 |
|
InstrumentScriptVMFunction_get_event_par(InstrumentScriptVM* parent); |
335 |
|
int minRequiredArgs() const { return 2; } |
336 |
|
int maxAllowedArgs() const { return 2; } |
337 |
|
bool acceptsArgType(int iArg, ExprType_t type) const { return type == INT_EXPR;} |
338 |
|
ExprType_t argType(int iArg) const { return INT_EXPR; } |
339 |
|
VMFnResult* exec(VMFnArgs* args); |
340 |
|
protected: |
341 |
|
InstrumentScriptVM* m_vm; |
342 |
|
}; |
343 |
|
|
344 |
|
class InstrumentScriptVMFunction_set_event_par : public VMEmptyResultFunction { |
345 |
|
public: |
346 |
|
InstrumentScriptVMFunction_set_event_par(InstrumentScriptVM* parent); |
347 |
|
int minRequiredArgs() const { return 3; } |
348 |
|
int maxAllowedArgs() const { return 3; } |
349 |
|
bool acceptsArgType(int iArg, ExprType_t type) const { return type == INT_EXPR;} |
350 |
|
ExprType_t argType(int iArg) const { return INT_EXPR; } |
351 |
|
VMFnResult* exec(VMFnArgs* args); |
352 |
|
protected: |
353 |
|
InstrumentScriptVM* m_vm; |
354 |
|
}; |
355 |
|
|
356 |
|
class InstrumentScriptVMFunction_change_note : public VMEmptyResultFunction { |
357 |
|
public: |
358 |
|
InstrumentScriptVMFunction_change_note(InstrumentScriptVM* parent); |
359 |
|
int minRequiredArgs() const { return 2; } |
360 |
|
int maxAllowedArgs() const { return 2; } |
361 |
|
bool acceptsArgType(int iArg, ExprType_t type) const { return type == INT_EXPR;} |
362 |
|
ExprType_t argType(int iArg) const { return INT_EXPR; } |
363 |
|
VMFnResult* exec(VMFnArgs* args); |
364 |
|
protected: |
365 |
|
InstrumentScriptVM* m_vm; |
366 |
|
}; |
367 |
|
|
368 |
|
class InstrumentScriptVMFunction_change_velo : public VMEmptyResultFunction { |
369 |
|
public: |
370 |
|
InstrumentScriptVMFunction_change_velo(InstrumentScriptVM* parent); |
371 |
|
int minRequiredArgs() const { return 2; } |
372 |
|
int maxAllowedArgs() const { return 2; } |
373 |
|
bool acceptsArgType(int iArg, ExprType_t type) const { return type == INT_EXPR;} |
374 |
|
ExprType_t argType(int iArg) const { return INT_EXPR; } |
375 |
|
VMFnResult* exec(VMFnArgs* args); |
376 |
|
protected: |
377 |
|
InstrumentScriptVM* m_vm; |
378 |
|
}; |
379 |
|
|
380 |
|
class InstrumentScriptVMFunction_change_play_pos : public VMEmptyResultFunction { |
381 |
|
public: |
382 |
|
InstrumentScriptVMFunction_change_play_pos(InstrumentScriptVM* parent); |
383 |
|
int minRequiredArgs() const { return 2; } |
384 |
|
int maxAllowedArgs() const { return 2; } |
385 |
|
bool acceptsArgType(int iArg, ExprType_t type) const { return type == INT_EXPR; } |
386 |
|
ExprType_t argType(int iArg) const { return INT_EXPR; } |
387 |
|
VMFnResult* exec(VMFnArgs* args); |
388 |
|
protected: |
389 |
|
InstrumentScriptVM* m_vm; |
390 |
|
}; |
391 |
|
|
392 |
|
class InstrumentScriptVMFunction_event_status : public VMIntResultFunction { |
393 |
|
public: |
394 |
|
InstrumentScriptVMFunction_event_status(InstrumentScriptVM* parent); |
395 |
|
int minRequiredArgs() const { return 1; } |
396 |
|
int maxAllowedArgs() const { return 1; } |
397 |
|
bool acceptsArgType(int iArg, ExprType_t type) const { return type == INT_EXPR;} |
398 |
|
ExprType_t argType(int iArg) const { return INT_EXPR; } |
399 |
|
VMFnResult* exec(VMFnArgs* args); |
400 |
|
protected: |
401 |
|
InstrumentScriptVM* m_vm; |
402 |
|
}; |
403 |
|
|
404 |
|
// overrides core wait() implementation |
405 |
|
class InstrumentScriptVMFunction_wait : public CoreVMFunction_wait { |
406 |
|
public: |
407 |
|
InstrumentScriptVMFunction_wait(InstrumentScriptVM* parent); |
408 |
|
VMFnResult* exec(VMFnArgs* args); |
409 |
|
}; |
410 |
|
|
411 |
|
class InstrumentScriptVMFunction_stop_wait : public VMEmptyResultFunction { |
412 |
|
public: |
413 |
|
InstrumentScriptVMFunction_stop_wait(InstrumentScriptVM* parent); |
414 |
|
int minRequiredArgs() const { return 1; } |
415 |
|
int maxAllowedArgs() const { return 2; } |
416 |
bool acceptsArgType(int iArg, ExprType_t type) const { return type == INT_EXPR;} |
bool acceptsArgType(int iArg, ExprType_t type) const { return type == INT_EXPR;} |
417 |
ExprType_t argType(int iArg) const { return INT_EXPR; } |
ExprType_t argType(int iArg) const { return INT_EXPR; } |
418 |
VMFnResult* exec(VMFnArgs* args); |
VMFnResult* exec(VMFnArgs* args); |