1 |
/* |
/* |
2 |
* Copyright (c) 2014-2017 Christian Schoenebeck |
* Copyright (c) 2014-2019 Christian Schoenebeck |
3 |
* |
* |
4 |
* http://www.linuxsampler.org |
* http://www.linuxsampler.org |
5 |
* |
* |
21 |
} |
} |
22 |
|
|
23 |
VMFnResult* InstrumentScriptVMFunction_play_note::exec(VMFnArgs* args) { |
VMFnResult* InstrumentScriptVMFunction_play_note::exec(VMFnArgs* args) { |
24 |
int note = args->arg(0)->asInt()->evalInt(); |
vmint note = args->arg(0)->asInt()->evalInt(); |
25 |
int velocity = (args->argsCount() >= 2) ? args->arg(1)->asInt()->evalInt() : 127; |
vmint velocity = (args->argsCount() >= 2) ? args->arg(1)->asInt()->evalInt() : 127; |
26 |
int duration = (args->argsCount() >= 4) ? args->arg(3)->asInt()->evalInt() : 0; //TODO: -1 might be a better default value instead of 0 |
vmint duration = (args->argsCount() >= 4) ? args->arg(3)->asInt()->evalInt() : 0; //TODO: -1 might be a better default value instead of 0 |
27 |
|
|
28 |
if (note < 0 || note > 127) { |
if (note < 0 || note > 127) { |
29 |
errMsg("play_note(): argument 1 is an invalid note number"); |
errMsg("play_note(): argument 1 is an invalid note number"); |
68 |
// if a sample offset is supplied, assign the offset as override |
// if a sample offset is supplied, assign the offset as override |
69 |
// to the previously created Note object |
// to the previously created Note object |
70 |
if (args->argsCount() >= 3) { |
if (args->argsCount() >= 3) { |
71 |
int sampleoffset = args->arg(2)->asInt()->evalInt(); |
vmint sampleoffset = args->arg(2)->asInt()->evalInt(); |
72 |
if (sampleoffset >= 0) { |
if (sampleoffset >= 0) { |
73 |
NoteBase* pNote = pEngineChannel->pEngine->NoteByID(id); |
NoteBase* pNote = pEngineChannel->pEngine->NoteByID(id); |
74 |
if (pNote) { |
if (pNote) { |
75 |
pNote->Override.SampleOffset = sampleoffset; |
pNote->Override.SampleOffset = |
76 |
|
(decltype(pNote->Override.SampleOffset)) sampleoffset; |
77 |
} |
} |
78 |
} else if (sampleoffset < -1) { |
} else if (sampleoffset < -1) { |
79 |
errMsg("play_note(): sample offset of argument 3 may not be less than -1"); |
errMsg("play_note(): sample offset of argument 3 may not be less than -1"); |
103 |
} |
} |
104 |
|
|
105 |
VMFnResult* InstrumentScriptVMFunction_set_controller::exec(VMFnArgs* args) { |
VMFnResult* InstrumentScriptVMFunction_set_controller::exec(VMFnArgs* args) { |
106 |
int controller = args->arg(0)->asInt()->evalInt(); |
vmint controller = args->arg(0)->asInt()->evalInt(); |
107 |
int value = args->arg(1)->asInt()->evalInt(); |
vmint value = args->arg(1)->asInt()->evalInt(); |
108 |
|
|
109 |
AbstractEngineChannel* pEngineChannel = |
AbstractEngineChannel* pEngineChannel = |
110 |
static_cast<AbstractEngineChannel*>(m_vm->m_event->cause.pEngineChannel); |
static_cast<AbstractEngineChannel*>(m_vm->m_event->cause.pEngineChannel); |
141 |
{ |
{ |
142 |
} |
} |
143 |
|
|
144 |
bool InstrumentScriptVMFunction_ignore_event::acceptsArgType(int iArg, ExprType_t type) const { |
bool InstrumentScriptVMFunction_ignore_event::acceptsArgType(vmint iArg, ExprType_t type) const { |
145 |
return type == INT_EXPR || type == INT_ARR_EXPR; |
return type == INT_EXPR || type == INT_ARR_EXPR; |
146 |
} |
} |
147 |
|
|
197 |
{ |
{ |
198 |
} |
} |
199 |
|
|
200 |
bool InstrumentScriptVMFunction_note_off::acceptsArgType(int iArg, ExprType_t type) const { |
bool InstrumentScriptVMFunction_note_off::acceptsArgType(vmint iArg, ExprType_t type) const { |
201 |
return type == INT_EXPR || type == INT_ARR_EXPR; |
return type == INT_EXPR || type == INT_ARR_EXPR; |
202 |
} |
} |
203 |
|
|
205 |
AbstractEngineChannel* pEngineChannel = |
AbstractEngineChannel* pEngineChannel = |
206 |
static_cast<AbstractEngineChannel*>(m_vm->m_event->cause.pEngineChannel); |
static_cast<AbstractEngineChannel*>(m_vm->m_event->cause.pEngineChannel); |
207 |
|
|
208 |
int velocity = (args->argsCount() >= 2) ? args->arg(1)->asInt()->evalInt() : 127; |
vmint velocity = (args->argsCount() >= 2) ? args->arg(1)->asInt()->evalInt() : 127; |
209 |
if (velocity < 0 || velocity > 127) { |
if (velocity < 0 || velocity > 127) { |
210 |
errMsg("note_off(): argument 2 is an invalid velocity value"); |
errMsg("note_off(): argument 2 is an invalid velocity value"); |
211 |
return errorResult(); |
return errorResult(); |
236 |
pEngineChannel->ScheduleEventMicroSec(&e, 0); |
pEngineChannel->ScheduleEventMicroSec(&e, 0); |
237 |
} else if (args->arg(0)->exprType() == INT_ARR_EXPR) { |
} else if (args->arg(0)->exprType() == INT_ARR_EXPR) { |
238 |
VMIntArrayExpr* ids = args->arg(0)->asIntArray(); |
VMIntArrayExpr* ids = args->arg(0)->asIntArray(); |
239 |
for (int i = 0; i < ids->arraySize(); ++i) { |
for (vmint i = 0; i < ids->arraySize(); ++i) { |
240 |
const ScriptID id = ids->evalIntElement(i); |
const ScriptID id = ids->evalIntElement(i); |
241 |
if (!id || !id.isNoteID()) continue; |
if (!id || !id.isNoteID()) continue; |
242 |
|
|
267 |
|
|
268 |
VMFnResult* InstrumentScriptVMFunction_set_event_mark::exec(VMFnArgs* args) { |
VMFnResult* InstrumentScriptVMFunction_set_event_mark::exec(VMFnArgs* args) { |
269 |
const ScriptID id = args->arg(0)->asInt()->evalInt(); |
const ScriptID id = args->arg(0)->asInt()->evalInt(); |
270 |
const int groupID = args->arg(1)->asInt()->evalInt(); |
const vmint groupID = args->arg(1)->asInt()->evalInt(); |
271 |
|
|
272 |
if (groupID < 0 || groupID >= INSTR_SCRIPT_EVENT_GROUPS) { |
if (groupID < 0 || groupID >= INSTR_SCRIPT_EVENT_GROUPS) { |
273 |
errMsg("set_event_mark(): argument 2 is an invalid group id"); |
errMsg("set_event_mark(): argument 2 is an invalid group id"); |
305 |
|
|
306 |
VMFnResult* InstrumentScriptVMFunction_delete_event_mark::exec(VMFnArgs* args) { |
VMFnResult* InstrumentScriptVMFunction_delete_event_mark::exec(VMFnArgs* args) { |
307 |
const ScriptID id = args->arg(0)->asInt()->evalInt(); |
const ScriptID id = args->arg(0)->asInt()->evalInt(); |
308 |
const int groupID = args->arg(1)->asInt()->evalInt(); |
const vmint groupID = args->arg(1)->asInt()->evalInt(); |
309 |
|
|
310 |
if (groupID < 0 || groupID >= INSTR_SCRIPT_EVENT_GROUPS) { |
if (groupID < 0 || groupID >= INSTR_SCRIPT_EVENT_GROUPS) { |
311 |
errMsg("delete_event_mark(): argument 2 is an invalid group id"); |
errMsg("delete_event_mark(): argument 2 is an invalid group id"); |
327 |
{ |
{ |
328 |
} |
} |
329 |
|
|
330 |
int InstrumentScriptVMFunction_by_marks::Result::arraySize() const { |
vmint InstrumentScriptVMFunction_by_marks::Result::arraySize() const { |
331 |
return eventGroup->size(); |
return eventGroup->size(); |
332 |
} |
} |
333 |
|
|
334 |
int InstrumentScriptVMFunction_by_marks::Result::evalIntElement(uint i) { |
vmint InstrumentScriptVMFunction_by_marks::Result::evalIntElement(vmuint i) { |
335 |
return (*eventGroup)[i]; |
return (*eventGroup)[i]; |
336 |
} |
} |
337 |
|
|
348 |
} |
} |
349 |
|
|
350 |
VMFnResult* InstrumentScriptVMFunction_by_marks::exec(VMFnArgs* args) { |
VMFnResult* InstrumentScriptVMFunction_by_marks::exec(VMFnArgs* args) { |
351 |
int groupID = args->arg(0)->asInt()->evalInt(); |
vmint groupID = args->arg(0)->asInt()->evalInt(); |
352 |
|
|
353 |
if (groupID < 0 || groupID >= INSTR_SCRIPT_EVENT_GROUPS) { |
if (groupID < 0 || groupID >= INSTR_SCRIPT_EVENT_GROUPS) { |
354 |
errMsg("by_marks(): argument is an invalid group id"); |
errMsg("by_marks(): argument is an invalid group id"); |
368 |
{ |
{ |
369 |
} |
} |
370 |
|
|
371 |
bool InstrumentScriptVMFunction_change_vol::acceptsArgType(int iArg, ExprType_t type) const { |
bool InstrumentScriptVMFunction_change_vol::acceptsArgType(vmint iArg, ExprType_t type) const { |
372 |
if (iArg == 0) |
if (iArg == 0) |
373 |
return type == INT_EXPR || type == INT_ARR_EXPR; |
return type == INT_EXPR || type == INT_ARR_EXPR; |
374 |
else |
else |
376 |
} |
} |
377 |
|
|
378 |
VMFnResult* InstrumentScriptVMFunction_change_vol::exec(VMFnArgs* args) { |
VMFnResult* InstrumentScriptVMFunction_change_vol::exec(VMFnArgs* args) { |
379 |
int volume = args->arg(1)->asInt()->evalInt(); // volume change in milli dB |
vmint volume = args->arg(1)->asInt()->evalInt(); // volume change in milli dB |
380 |
bool relative = (args->argsCount() >= 3) ? (args->arg(2)->asInt()->evalInt() & 1) : false; |
bool relative = (args->argsCount() >= 3) ? (args->arg(2)->asInt()->evalInt() & 1) : false; |
381 |
const float fVolumeLin = RTMath::DecibelToLinRatio(float(volume) / 1000.f); |
const float fVolumeLin = RTMath::DecibelToLinRatio(float(volume) / 1000.f); |
382 |
|
|
420 |
} |
} |
421 |
} else if (args->arg(0)->exprType() == INT_ARR_EXPR) { |
} else if (args->arg(0)->exprType() == INT_ARR_EXPR) { |
422 |
VMIntArrayExpr* ids = args->arg(0)->asIntArray(); |
VMIntArrayExpr* ids = args->arg(0)->asIntArray(); |
423 |
for (int i = 0; i < ids->arraySize(); ++i) { |
for (vmint i = 0; i < ids->arraySize(); ++i) { |
424 |
const ScriptID id = ids->evalIntElement(i); |
const ScriptID id = ids->evalIntElement(i); |
425 |
if (!id || !id.isNoteID()) continue; |
if (!id || !id.isNoteID()) continue; |
426 |
|
|
461 |
{ |
{ |
462 |
} |
} |
463 |
|
|
464 |
bool InstrumentScriptVMFunction_change_tune::acceptsArgType(int iArg, ExprType_t type) const { |
bool InstrumentScriptVMFunction_change_tune::acceptsArgType(vmint iArg, ExprType_t type) const { |
465 |
if (iArg == 0) |
if (iArg == 0) |
466 |
return type == INT_EXPR || type == INT_ARR_EXPR; |
return type == INT_EXPR || type == INT_ARR_EXPR; |
467 |
else |
else |
469 |
} |
} |
470 |
|
|
471 |
VMFnResult* InstrumentScriptVMFunction_change_tune::exec(VMFnArgs* args) { |
VMFnResult* InstrumentScriptVMFunction_change_tune::exec(VMFnArgs* args) { |
472 |
int tune = args->arg(1)->asInt()->evalInt(); // tuning change in milli cents |
vmint tune = args->arg(1)->asInt()->evalInt(); // tuning change in milli cents |
473 |
bool relative = (args->argsCount() >= 3) ? (args->arg(2)->asInt()->evalInt() & 1) : false; |
bool relative = (args->argsCount() >= 3) ? (args->arg(2)->asInt()->evalInt() & 1) : false; |
474 |
const float fFreqRatio = RTMath::CentsToFreqRatioUnlimited(float(tune) / 1000.f); |
const float fFreqRatio = RTMath::CentsToFreqRatioUnlimited(float(tune) / 1000.f); |
475 |
|
|
513 |
} |
} |
514 |
} else if (args->arg(0)->exprType() == INT_ARR_EXPR) { |
} else if (args->arg(0)->exprType() == INT_ARR_EXPR) { |
515 |
VMIntArrayExpr* ids = args->arg(0)->asIntArray(); |
VMIntArrayExpr* ids = args->arg(0)->asIntArray(); |
516 |
for (int i = 0; i < ids->arraySize(); ++i) { |
for (vmint i = 0; i < ids->arraySize(); ++i) { |
517 |
const ScriptID id = ids->evalIntElement(i); |
const ScriptID id = ids->evalIntElement(i); |
518 |
if (!id || !id.isNoteID()) continue; |
if (!id || !id.isNoteID()) continue; |
519 |
|
|
554 |
{ |
{ |
555 |
} |
} |
556 |
|
|
557 |
bool InstrumentScriptVMFunction_change_pan::acceptsArgType(int iArg, ExprType_t type) const { |
bool InstrumentScriptVMFunction_change_pan::acceptsArgType(vmint iArg, ExprType_t type) const { |
558 |
if (iArg == 0) |
if (iArg == 0) |
559 |
return type == INT_EXPR || type == INT_ARR_EXPR; |
return type == INT_EXPR || type == INT_ARR_EXPR; |
560 |
else |
else |
562 |
} |
} |
563 |
|
|
564 |
VMFnResult* InstrumentScriptVMFunction_change_pan::exec(VMFnArgs* args) { |
VMFnResult* InstrumentScriptVMFunction_change_pan::exec(VMFnArgs* args) { |
565 |
int pan = args->arg(1)->asInt()->evalInt(); |
vmint pan = args->arg(1)->asInt()->evalInt(); |
566 |
bool relative = (args->argsCount() >= 3) ? (args->arg(2)->asInt()->evalInt() & 1) : false; |
bool relative = (args->argsCount() >= 3) ? (args->arg(2)->asInt()->evalInt() & 1) : false; |
567 |
|
|
568 |
if (pan > 1000) { |
if (pan > 1000) { |
613 |
} |
} |
614 |
} else if (args->arg(0)->exprType() == INT_ARR_EXPR) { |
} else if (args->arg(0)->exprType() == INT_ARR_EXPR) { |
615 |
VMIntArrayExpr* ids = args->arg(0)->asIntArray(); |
VMIntArrayExpr* ids = args->arg(0)->asIntArray(); |
616 |
for (int i = 0; i < ids->arraySize(); ++i) { |
for (vmint i = 0; i < ids->arraySize(); ++i) { |
617 |
const ScriptID id = ids->evalIntElement(i); |
const ScriptID id = ids->evalIntElement(i); |
618 |
if (!id || !id.isNoteID()) continue; |
if (!id || !id.isNoteID()) continue; |
619 |
|
|
656 |
{ |
{ |
657 |
} |
} |
658 |
|
|
659 |
bool InstrumentScriptVMFunction_change_cutoff::acceptsArgType(int iArg, ExprType_t type) const { |
bool InstrumentScriptVMFunction_change_cutoff::acceptsArgType(vmint iArg, ExprType_t type) const { |
660 |
if (iArg == 0) |
if (iArg == 0) |
661 |
return type == INT_EXPR || type == INT_ARR_EXPR; |
return type == INT_EXPR || type == INT_ARR_EXPR; |
662 |
else |
else |
664 |
} |
} |
665 |
|
|
666 |
VMFnResult* InstrumentScriptVMFunction_change_cutoff::exec(VMFnArgs* args) { |
VMFnResult* InstrumentScriptVMFunction_change_cutoff::exec(VMFnArgs* args) { |
667 |
int cutoff = args->arg(1)->asInt()->evalInt(); |
vmint cutoff = args->arg(1)->asInt()->evalInt(); |
668 |
if (cutoff > VM_FILTER_PAR_MAX_VALUE) { |
if (cutoff > VM_FILTER_PAR_MAX_VALUE) { |
669 |
wrnMsg("change_cutoff(): argument 2 may not be larger than 1000000"); |
wrnMsg("change_cutoff(): argument 2 may not be larger than 1000000"); |
670 |
cutoff = VM_FILTER_PAR_MAX_VALUE; |
cutoff = VM_FILTER_PAR_MAX_VALUE; |
708 |
} |
} |
709 |
} else if (args->arg(0)->exprType() == INT_ARR_EXPR) { |
} else if (args->arg(0)->exprType() == INT_ARR_EXPR) { |
710 |
VMIntArrayExpr* ids = args->arg(0)->asIntArray(); |
VMIntArrayExpr* ids = args->arg(0)->asIntArray(); |
711 |
for (int i = 0; i < ids->arraySize(); ++i) { |
for (vmint i = 0; i < ids->arraySize(); ++i) { |
712 |
const ScriptID id = ids->evalIntElement(i); |
const ScriptID id = ids->evalIntElement(i); |
713 |
if (!id || !id.isNoteID()) continue; |
if (!id || !id.isNoteID()) continue; |
714 |
|
|
743 |
{ |
{ |
744 |
} |
} |
745 |
|
|
746 |
bool InstrumentScriptVMFunction_change_reso::acceptsArgType(int iArg, ExprType_t type) const { |
bool InstrumentScriptVMFunction_change_reso::acceptsArgType(vmint iArg, ExprType_t type) const { |
747 |
if (iArg == 0) |
if (iArg == 0) |
748 |
return type == INT_EXPR || type == INT_ARR_EXPR; |
return type == INT_EXPR || type == INT_ARR_EXPR; |
749 |
else |
else |
751 |
} |
} |
752 |
|
|
753 |
VMFnResult* InstrumentScriptVMFunction_change_reso::exec(VMFnArgs* args) { |
VMFnResult* InstrumentScriptVMFunction_change_reso::exec(VMFnArgs* args) { |
754 |
int resonance = args->arg(1)->asInt()->evalInt(); |
vmint resonance = args->arg(1)->asInt()->evalInt(); |
755 |
if (resonance > VM_FILTER_PAR_MAX_VALUE) { |
if (resonance > VM_FILTER_PAR_MAX_VALUE) { |
756 |
wrnMsg("change_reso(): argument 2 may not be larger than 1000000"); |
wrnMsg("change_reso(): argument 2 may not be larger than 1000000"); |
757 |
resonance = VM_FILTER_PAR_MAX_VALUE; |
resonance = VM_FILTER_PAR_MAX_VALUE; |
795 |
} |
} |
796 |
} else if (args->arg(0)->exprType() == INT_ARR_EXPR) { |
} else if (args->arg(0)->exprType() == INT_ARR_EXPR) { |
797 |
VMIntArrayExpr* ids = args->arg(0)->asIntArray(); |
VMIntArrayExpr* ids = args->arg(0)->asIntArray(); |
798 |
for (int i = 0; i < ids->arraySize(); ++i) { |
for (vmint i = 0; i < ids->arraySize(); ++i) { |
799 |
const ScriptID id = ids->evalIntElement(i); |
const ScriptID id = ids->evalIntElement(i); |
800 |
if (!id || !id.isNoteID()) continue; |
if (!id || !id.isNoteID()) continue; |
801 |
|
|
830 |
{ |
{ |
831 |
} |
} |
832 |
|
|
833 |
bool InstrumentScriptVMFunction_change_attack::acceptsArgType(int iArg, ExprType_t type) const { |
bool InstrumentScriptVMFunction_change_attack::acceptsArgType(vmint iArg, ExprType_t type) const { |
834 |
if (iArg == 0) |
if (iArg == 0) |
835 |
return type == INT_EXPR || type == INT_ARR_EXPR; |
return type == INT_EXPR || type == INT_ARR_EXPR; |
836 |
else |
else |
838 |
} |
} |
839 |
|
|
840 |
VMFnResult* InstrumentScriptVMFunction_change_attack::exec(VMFnArgs* args) { |
VMFnResult* InstrumentScriptVMFunction_change_attack::exec(VMFnArgs* args) { |
841 |
int attack = args->arg(1)->asInt()->evalInt(); |
vmint attack = args->arg(1)->asInt()->evalInt(); |
842 |
if (attack > VM_EG_PAR_MAX_VALUE) { |
// note: intentionally not checking against a max. value here! |
843 |
wrnMsg("change_attack(): argument 2 may not be larger than 1000000"); |
// (to allow i.e. passing 2000000 for doubling the attack time) |
844 |
attack = VM_EG_PAR_MAX_VALUE; |
if (attack < 0) { |
|
} else if (attack < 0) { |
|
845 |
wrnMsg("change_attack(): argument 2 may not be negative"); |
wrnMsg("change_attack(): argument 2 may not be negative"); |
846 |
attack = 0; |
attack = 0; |
847 |
} |
} |
881 |
} |
} |
882 |
} else if (args->arg(0)->exprType() == INT_ARR_EXPR) { |
} else if (args->arg(0)->exprType() == INT_ARR_EXPR) { |
883 |
VMIntArrayExpr* ids = args->arg(0)->asIntArray(); |
VMIntArrayExpr* ids = args->arg(0)->asIntArray(); |
884 |
for (int i = 0; i < ids->arraySize(); ++i) { |
for (vmint i = 0; i < ids->arraySize(); ++i) { |
885 |
const ScriptID id = ids->evalIntElement(i); |
const ScriptID id = ids->evalIntElement(i); |
886 |
if (!id || !id.isNoteID()) continue; |
if (!id || !id.isNoteID()) continue; |
887 |
|
|
916 |
{ |
{ |
917 |
} |
} |
918 |
|
|
919 |
bool InstrumentScriptVMFunction_change_decay::acceptsArgType(int iArg, ExprType_t type) const { |
bool InstrumentScriptVMFunction_change_decay::acceptsArgType(vmint iArg, ExprType_t type) const { |
920 |
if (iArg == 0) |
if (iArg == 0) |
921 |
return type == INT_EXPR || type == INT_ARR_EXPR; |
return type == INT_EXPR || type == INT_ARR_EXPR; |
922 |
else |
else |
924 |
} |
} |
925 |
|
|
926 |
VMFnResult* InstrumentScriptVMFunction_change_decay::exec(VMFnArgs* args) { |
VMFnResult* InstrumentScriptVMFunction_change_decay::exec(VMFnArgs* args) { |
927 |
int decay = args->arg(1)->asInt()->evalInt(); |
vmint decay = args->arg(1)->asInt()->evalInt(); |
928 |
if (decay > VM_EG_PAR_MAX_VALUE) { |
// note: intentionally not checking against a max. value here! |
929 |
wrnMsg("change_decay(): argument 2 may not be larger than 1000000"); |
// (to allow i.e. passing 2000000 for doubling the decay time) |
930 |
decay = VM_EG_PAR_MAX_VALUE; |
if (decay < 0) { |
|
} else if (decay < 0) { |
|
931 |
wrnMsg("change_decay(): argument 2 may not be negative"); |
wrnMsg("change_decay(): argument 2 may not be negative"); |
932 |
decay = 0; |
decay = 0; |
933 |
} |
} |
967 |
} |
} |
968 |
} else if (args->arg(0)->exprType() == INT_ARR_EXPR) { |
} else if (args->arg(0)->exprType() == INT_ARR_EXPR) { |
969 |
VMIntArrayExpr* ids = args->arg(0)->asIntArray(); |
VMIntArrayExpr* ids = args->arg(0)->asIntArray(); |
970 |
for (int i = 0; i < ids->arraySize(); ++i) { |
for (vmint i = 0; i < ids->arraySize(); ++i) { |
971 |
const ScriptID id = ids->evalIntElement(i); |
const ScriptID id = ids->evalIntElement(i); |
972 |
if (!id || !id.isNoteID()) continue; |
if (!id || !id.isNoteID()) continue; |
973 |
|
|
1002 |
{ |
{ |
1003 |
} |
} |
1004 |
|
|
1005 |
bool InstrumentScriptVMFunction_change_release::acceptsArgType(int iArg, ExprType_t type) const { |
bool InstrumentScriptVMFunction_change_release::acceptsArgType(vmint iArg, ExprType_t type) const { |
1006 |
if (iArg == 0) |
if (iArg == 0) |
1007 |
return type == INT_EXPR || type == INT_ARR_EXPR; |
return type == INT_EXPR || type == INT_ARR_EXPR; |
1008 |
else |
else |
1010 |
} |
} |
1011 |
|
|
1012 |
VMFnResult* InstrumentScriptVMFunction_change_release::exec(VMFnArgs* args) { |
VMFnResult* InstrumentScriptVMFunction_change_release::exec(VMFnArgs* args) { |
1013 |
int release = args->arg(1)->asInt()->evalInt(); |
vmint release = args->arg(1)->asInt()->evalInt(); |
1014 |
if (release > VM_EG_PAR_MAX_VALUE) { |
// note: intentionally not checking against a max. value here! |
1015 |
wrnMsg("change_release(): argument 2 may not be larger than 1000000"); |
// (to allow i.e. passing 2000000 for doubling the release time) |
1016 |
release = VM_EG_PAR_MAX_VALUE; |
if (release < 0) { |
|
} else if (release < 0) { |
|
1017 |
wrnMsg("change_release(): argument 2 may not be negative"); |
wrnMsg("change_release(): argument 2 may not be negative"); |
1018 |
release = 0; |
release = 0; |
1019 |
} |
} |
1053 |
} |
} |
1054 |
} else if (args->arg(0)->exprType() == INT_ARR_EXPR) { |
} else if (args->arg(0)->exprType() == INT_ARR_EXPR) { |
1055 |
VMIntArrayExpr* ids = args->arg(0)->asIntArray(); |
VMIntArrayExpr* ids = args->arg(0)->asIntArray(); |
1056 |
for (int i = 0; i < ids->arraySize(); ++i) { |
for (vmint i = 0; i < ids->arraySize(); ++i) { |
1057 |
const ScriptID id = ids->evalIntElement(i); |
const ScriptID id = ids->evalIntElement(i); |
1058 |
if (!id || !id.isNoteID()) continue; |
if (!id || !id.isNoteID()) continue; |
1059 |
|
|
1083 |
|
|
1084 |
// template for change_*() functions |
// template for change_*() functions |
1085 |
|
|
1086 |
bool VMChangeSynthParamFunction::acceptsArgType(int iArg, ExprType_t type) const { |
bool VMChangeSynthParamFunction::acceptsArgType(vmint iArg, ExprType_t type) const { |
1087 |
if (iArg == 0) |
if (iArg == 0) |
1088 |
return type == INT_EXPR || type == INT_ARR_EXPR; |
return type == INT_EXPR || type == INT_ARR_EXPR; |
1089 |
else |
else |
1093 |
// Arbitrarily chosen constant value symbolizing "no limit". |
// Arbitrarily chosen constant value symbolizing "no limit". |
1094 |
#define NO_LIMIT 1315916909 |
#define NO_LIMIT 1315916909 |
1095 |
|
|
1096 |
template<float NoteBase::_Override::*T_noteParam, int T_synthParam, |
template<float NoteBase::_Override::*T_noteParam, vmint T_synthParam, |
1097 |
bool T_isNormalizedParam, int T_maxValue, int T_minValue> |
bool T_isNormalizedParam, vmint T_maxValue, vmint T_minValue> |
1098 |
VMFnResult* VMChangeSynthParamFunction::execTemplate(VMFnArgs* args, const char* functionName) { |
VMFnResult* VMChangeSynthParamFunction::execTemplate(VMFnArgs* args, const char* functionName) { |
1099 |
int value = args->arg(1)->asInt()->evalInt(); |
vmint value = args->arg(1)->asInt()->evalInt(); |
1100 |
if (T_maxValue != NO_LIMIT && value > T_maxValue) { |
if (T_maxValue != NO_LIMIT && value > T_maxValue) { |
1101 |
wrnMsg(String(functionName) + "(): argument 2 may not be larger than " + ToString(T_maxValue)); |
wrnMsg(String(functionName) + "(): argument 2 may not be larger than " + ToString(T_maxValue)); |
1102 |
value = T_maxValue; |
value = T_maxValue; |
1146 |
} |
} |
1147 |
} else if (args->arg(0)->exprType() == INT_ARR_EXPR) { |
} else if (args->arg(0)->exprType() == INT_ARR_EXPR) { |
1148 |
VMIntArrayExpr* ids = args->arg(0)->asIntArray(); |
VMIntArrayExpr* ids = args->arg(0)->asIntArray(); |
1149 |
for (int i = 0; i < ids->arraySize(); ++i) { |
for (vmint i = 0; i < ids->arraySize(); ++i) { |
1150 |
const ScriptID id = ids->evalIntElement(i); |
const ScriptID id = ids->evalIntElement(i); |
1151 |
if (!id || !id.isNoteID()) continue; |
if (!id || !id.isNoteID()) continue; |
1152 |
|
|
1175 |
return successResult(); |
return successResult(); |
1176 |
} |
} |
1177 |
|
|
1178 |
|
// change_sustain() function |
1179 |
|
|
1180 |
|
VMFnResult* InstrumentScriptVMFunction_change_sustain::exec(VMFnArgs* args) { |
1181 |
|
return VMChangeSynthParamFunction::execTemplate< |
1182 |
|
&NoteBase::_Override::Sustain, |
1183 |
|
Event::synth_param_sustain, |
1184 |
|
false, NO_LIMIT, 0>( args, "change_sustain" ); |
1185 |
|
} |
1186 |
|
|
1187 |
|
// change_cutoff_attack() function |
1188 |
|
|
1189 |
|
VMFnResult* InstrumentScriptVMFunction_change_cutoff_attack::exec(VMFnArgs* args) { |
1190 |
|
return VMChangeSynthParamFunction::execTemplate< |
1191 |
|
&NoteBase::_Override::CutoffAttack, |
1192 |
|
Event::synth_param_cutoff_attack, |
1193 |
|
false, NO_LIMIT, 0>( args, "change_cutoff_attack" ); |
1194 |
|
} |
1195 |
|
|
1196 |
|
// change_cutoff_decay() function |
1197 |
|
|
1198 |
|
VMFnResult* InstrumentScriptVMFunction_change_cutoff_decay::exec(VMFnArgs* args) { |
1199 |
|
return VMChangeSynthParamFunction::execTemplate< |
1200 |
|
&NoteBase::_Override::CutoffDecay, |
1201 |
|
Event::synth_param_cutoff_decay, |
1202 |
|
false, NO_LIMIT, 0>( args, "change_cutoff_decay" ); |
1203 |
|
} |
1204 |
|
|
1205 |
|
// change_cutoff_sustain() function |
1206 |
|
|
1207 |
|
VMFnResult* InstrumentScriptVMFunction_change_cutoff_sustain::exec(VMFnArgs* args) { |
1208 |
|
return VMChangeSynthParamFunction::execTemplate< |
1209 |
|
&NoteBase::_Override::CutoffSustain, |
1210 |
|
Event::synth_param_cutoff_sustain, |
1211 |
|
false, NO_LIMIT, 0>( args, "change_cutoff_sustain" ); |
1212 |
|
} |
1213 |
|
|
1214 |
|
// change_cutoff_release() function |
1215 |
|
|
1216 |
|
VMFnResult* InstrumentScriptVMFunction_change_cutoff_release::exec(VMFnArgs* args) { |
1217 |
|
return VMChangeSynthParamFunction::execTemplate< |
1218 |
|
&NoteBase::_Override::CutoffRelease, |
1219 |
|
Event::synth_param_cutoff_release, |
1220 |
|
false, NO_LIMIT, 0>( args, "change_cutoff_release" ); |
1221 |
|
} |
1222 |
|
|
1223 |
// change_amp_lfo_depth() function |
// change_amp_lfo_depth() function |
1224 |
|
|
1225 |
VMFnResult* InstrumentScriptVMFunction_change_amp_lfo_depth::exec(VMFnArgs* args) { |
VMFnResult* InstrumentScriptVMFunction_change_amp_lfo_depth::exec(VMFnArgs* args) { |
1238 |
true, 1000000, 0>( args, "change_amp_lfo_freq" ); |
true, 1000000, 0>( args, "change_amp_lfo_freq" ); |
1239 |
} |
} |
1240 |
|
|
1241 |
|
// change_cutoff_lfo_depth() function |
1242 |
|
|
1243 |
|
VMFnResult* InstrumentScriptVMFunction_change_cutoff_lfo_depth::exec(VMFnArgs* args) { |
1244 |
|
return VMChangeSynthParamFunction::execTemplate< |
1245 |
|
&NoteBase::_Override::CutoffLFODepth, |
1246 |
|
Event::synth_param_cutoff_lfo_depth, |
1247 |
|
true, 1000000, 0>( args, "change_cutoff_lfo_depth" ); |
1248 |
|
} |
1249 |
|
|
1250 |
|
// change_cutoff_lfo_freq() function |
1251 |
|
|
1252 |
|
VMFnResult* InstrumentScriptVMFunction_change_cutoff_lfo_freq::exec(VMFnArgs* args) { |
1253 |
|
return VMChangeSynthParamFunction::execTemplate< |
1254 |
|
&NoteBase::_Override::CutoffLFOFreq, |
1255 |
|
Event::synth_param_cutoff_lfo_freq, |
1256 |
|
true, 1000000, 0>( args, "change_cutoff_lfo_freq" ); |
1257 |
|
} |
1258 |
|
|
1259 |
// change_pitch_lfo_depth() function |
// change_pitch_lfo_depth() function |
1260 |
|
|
1261 |
VMFnResult* InstrumentScriptVMFunction_change_pitch_lfo_depth::exec(VMFnArgs* args) { |
VMFnResult* InstrumentScriptVMFunction_change_pitch_lfo_depth::exec(VMFnArgs* args) { |
1292 |
false, NO_LIMIT, 0>( args, "change_tune_time" ); |
false, NO_LIMIT, 0>( args, "change_tune_time" ); |
1293 |
} |
} |
1294 |
|
|
1295 |
|
// change_pan_time() function |
1296 |
|
|
1297 |
|
VMFnResult* InstrumentScriptVMFunction_change_pan_time::exec(VMFnArgs* args) { |
1298 |
|
return VMChangeSynthParamFunction::execTemplate< |
1299 |
|
&NoteBase::_Override::PanTime, |
1300 |
|
Event::synth_param_pan_time, |
1301 |
|
false, NO_LIMIT, 0>( args, "change_pan_time" ); |
1302 |
|
} |
1303 |
|
|
1304 |
// template for change_*_curve() functions |
// template for change_*_curve() functions |
1305 |
|
|
1306 |
bool VMChangeFadeCurveFunction::acceptsArgType(int iArg, ExprType_t type) const { |
bool VMChangeFadeCurveFunction::acceptsArgType(vmint iArg, ExprType_t type) const { |
1307 |
if (iArg == 0) |
if (iArg == 0) |
1308 |
return type == INT_EXPR || type == INT_ARR_EXPR; |
return type == INT_EXPR || type == INT_ARR_EXPR; |
1309 |
else |
else |
1310 |
return type == INT_EXPR; |
return type == INT_EXPR; |
1311 |
} |
} |
1312 |
|
|
1313 |
template<fade_curve_t NoteBase::_Override::*T_noteParam, int T_synthParam> |
template<fade_curve_t NoteBase::_Override::*T_noteParam, vmint T_synthParam> |
1314 |
VMFnResult* VMChangeFadeCurveFunction::execTemplate(VMFnArgs* args, const char* functionName) { |
VMFnResult* VMChangeFadeCurveFunction::execTemplate(VMFnArgs* args, const char* functionName) { |
1315 |
int value = args->arg(1)->asInt()->evalInt(); |
vmint value = args->arg(1)->asInt()->evalInt(); |
1316 |
switch (value) { |
switch (value) { |
1317 |
case FADE_CURVE_LINEAR: |
case FADE_CURVE_LINEAR: |
1318 |
case FADE_CURVE_EASE_IN_EASE_OUT: |
case FADE_CURVE_EASE_IN_EASE_OUT: |
1357 |
} |
} |
1358 |
} else if (args->arg(0)->exprType() == INT_ARR_EXPR) { |
} else if (args->arg(0)->exprType() == INT_ARR_EXPR) { |
1359 |
VMIntArrayExpr* ids = args->arg(0)->asIntArray(); |
VMIntArrayExpr* ids = args->arg(0)->asIntArray(); |
1360 |
for (int i = 0; i < ids->arraySize(); ++i) { |
for (vmint i = 0; i < ids->arraySize(); ++i) { |
1361 |
const ScriptID id = ids->evalIntElement(i); |
const ScriptID id = ids->evalIntElement(i); |
1362 |
if (!id || !id.isNoteID()) continue; |
if (!id || !id.isNoteID()) continue; |
1363 |
|
|
1402 |
Event::synth_param_pitch_curve>( args, "change_tune_curve" ); |
Event::synth_param_pitch_curve>( args, "change_tune_curve" ); |
1403 |
} |
} |
1404 |
|
|
1405 |
|
// change_pan_curve() function |
1406 |
|
|
1407 |
|
VMFnResult* InstrumentScriptVMFunction_change_pan_curve::exec(VMFnArgs* args) { |
1408 |
|
return VMChangeFadeCurveFunction::execTemplate< |
1409 |
|
&NoteBase::_Override::PanCurve, |
1410 |
|
Event::synth_param_pan_curve>( args, "change_pan_curve" ); |
1411 |
|
} |
1412 |
|
|
1413 |
// fade_in() function |
// fade_in() function |
1414 |
|
|
1415 |
InstrumentScriptVMFunction_fade_in::InstrumentScriptVMFunction_fade_in(InstrumentScriptVM* parent) |
InstrumentScriptVMFunction_fade_in::InstrumentScriptVMFunction_fade_in(InstrumentScriptVM* parent) |
1417 |
{ |
{ |
1418 |
} |
} |
1419 |
|
|
1420 |
bool InstrumentScriptVMFunction_fade_in::acceptsArgType(int iArg, ExprType_t type) const { |
bool InstrumentScriptVMFunction_fade_in::acceptsArgType(vmint iArg, ExprType_t type) const { |
1421 |
if (iArg == 0) |
if (iArg == 0) |
1422 |
return type == INT_EXPR || type == INT_ARR_EXPR; |
return type == INT_EXPR || type == INT_ARR_EXPR; |
1423 |
else |
else |
1425 |
} |
} |
1426 |
|
|
1427 |
VMFnResult* InstrumentScriptVMFunction_fade_in::exec(VMFnArgs* args) { |
VMFnResult* InstrumentScriptVMFunction_fade_in::exec(VMFnArgs* args) { |
1428 |
int duration = args->arg(1)->asInt()->evalInt(); |
vmint duration = args->arg(1)->asInt()->evalInt(); |
1429 |
if (duration < 0) { |
if (duration < 0) { |
1430 |
wrnMsg("fade_in(): argument 2 may not be negative"); |
wrnMsg("fade_in(): argument 2 may not be negative"); |
1431 |
duration = 0; |
duration = 0; |
1484 |
} |
} |
1485 |
} else if (args->arg(0)->exprType() == INT_ARR_EXPR) { |
} else if (args->arg(0)->exprType() == INT_ARR_EXPR) { |
1486 |
VMIntArrayExpr* ids = args->arg(0)->asIntArray(); |
VMIntArrayExpr* ids = args->arg(0)->asIntArray(); |
1487 |
for (int i = 0; i < ids->arraySize(); ++i) { |
for (vmint i = 0; i < ids->arraySize(); ++i) { |
1488 |
const ScriptID id = ids->evalIntElement(i); |
const ScriptID id = ids->evalIntElement(i); |
1489 |
if (!id || !id.isNoteID()) continue; |
if (!id || !id.isNoteID()) continue; |
1490 |
|
|
1537 |
{ |
{ |
1538 |
} |
} |
1539 |
|
|
1540 |
bool InstrumentScriptVMFunction_fade_out::acceptsArgType(int iArg, ExprType_t type) const { |
bool InstrumentScriptVMFunction_fade_out::acceptsArgType(vmint iArg, ExprType_t type) const { |
1541 |
if (iArg == 0) |
if (iArg == 0) |
1542 |
return type == INT_EXPR || type == INT_ARR_EXPR; |
return type == INT_EXPR || type == INT_ARR_EXPR; |
1543 |
else |
else |
1545 |
} |
} |
1546 |
|
|
1547 |
VMFnResult* InstrumentScriptVMFunction_fade_out::exec(VMFnArgs* args) { |
VMFnResult* InstrumentScriptVMFunction_fade_out::exec(VMFnArgs* args) { |
1548 |
int duration = args->arg(1)->asInt()->evalInt(); |
vmint duration = args->arg(1)->asInt()->evalInt(); |
1549 |
if (duration < 0) { |
if (duration < 0) { |
1550 |
wrnMsg("fade_out(): argument 2 may not be negative"); |
wrnMsg("fade_out(): argument 2 may not be negative"); |
1551 |
duration = 0; |
duration = 0; |
1616 |
} |
} |
1617 |
} else if (args->arg(0)->exprType() == INT_ARR_EXPR) { |
} else if (args->arg(0)->exprType() == INT_ARR_EXPR) { |
1618 |
VMIntArrayExpr* ids = args->arg(0)->asIntArray(); |
VMIntArrayExpr* ids = args->arg(0)->asIntArray(); |
1619 |
for (int i = 0; i < ids->arraySize(); ++i) { |
for (vmint i = 0; i < ids->arraySize(); ++i) { |
1620 |
const ScriptID id = ids->evalIntElement(i); |
const ScriptID id = ids->evalIntElement(i); |
1621 |
if (!id || !id.isNoteID()) continue; |
if (!id || !id.isNoteID()) continue; |
1622 |
|
|
1699 |
return successResult(0); |
return successResult(0); |
1700 |
} |
} |
1701 |
|
|
1702 |
const int parameter = args->arg(1)->asInt()->evalInt(); |
const vmint parameter = args->arg(1)->asInt()->evalInt(); |
1703 |
switch (parameter) { |
switch (parameter) { |
1704 |
case EVENT_PAR_NOTE: |
case EVENT_PAR_NOTE: |
1705 |
return successResult(pNote->cause.Param.Note.Key); |
return successResult(pNote->cause.Param.Note.Key); |
1751 |
NoteBase* pNote = pEngineChannel->pEngine->NoteByID( id.noteID() ); |
NoteBase* pNote = pEngineChannel->pEngine->NoteByID( id.noteID() ); |
1752 |
if (!pNote) return successResult(); |
if (!pNote) return successResult(); |
1753 |
|
|
1754 |
const int parameter = args->arg(1)->asInt()->evalInt(); |
const vmint parameter = args->arg(1)->asInt()->evalInt(); |
1755 |
const int value = args->arg(2)->asInt()->evalInt(); |
const vmint value = args->arg(2)->asInt()->evalInt(); |
1756 |
|
|
1757 |
switch (parameter) { |
switch (parameter) { |
1758 |
case EVENT_PAR_NOTE: |
case EVENT_PAR_NOTE: |
1827 |
NoteBase* pNote = pEngineChannel->pEngine->NoteByID( id.noteID() ); |
NoteBase* pNote = pEngineChannel->pEngine->NoteByID( id.noteID() ); |
1828 |
if (!pNote) return successResult(); |
if (!pNote) return successResult(); |
1829 |
|
|
1830 |
const int value = args->arg(1)->asInt()->evalInt(); |
const vmint value = args->arg(1)->asInt()->evalInt(); |
1831 |
if (value < 0 || value > 127) { |
if (value < 0 || value > 127) { |
1832 |
wrnMsg("change_note(): note number of argument 2 is out of range"); |
wrnMsg("change_note(): note number of argument 2 is out of range"); |
1833 |
return successResult(); |
return successResult(); |
1867 |
NoteBase* pNote = pEngineChannel->pEngine->NoteByID( id.noteID() ); |
NoteBase* pNote = pEngineChannel->pEngine->NoteByID( id.noteID() ); |
1868 |
if (!pNote) return successResult(); |
if (!pNote) return successResult(); |
1869 |
|
|
1870 |
const int value = args->arg(1)->asInt()->evalInt(); |
const vmint value = args->arg(1)->asInt()->evalInt(); |
1871 |
if (value < 0 || value > 127) { |
if (value < 0 || value > 127) { |
1872 |
wrnMsg("change_velo(): velocity of argument 2 is out of range"); |
wrnMsg("change_velo(): velocity of argument 2 is out of range"); |
1873 |
return successResult(); |
return successResult(); |
1901 |
return successResult(); |
return successResult(); |
1902 |
} |
} |
1903 |
|
|
1904 |
const int pos = args->arg(1)->asInt()->evalInt(); |
const vmint pos = args->arg(1)->asInt()->evalInt(); |
1905 |
if (pos < 0) { |
if (pos < 0) { |
1906 |
wrnMsg("change_play_pos(): playback position of argument 2 may not be negative"); |
wrnMsg("change_play_pos(): playback position of argument 2 may not be negative"); |
1907 |
return successResult(); |
return successResult(); |
1913 |
NoteBase* pNote = pEngineChannel->pEngine->NoteByID( id.noteID() ); |
NoteBase* pNote = pEngineChannel->pEngine->NoteByID( id.noteID() ); |
1914 |
if (!pNote) return successResult(); |
if (!pNote) return successResult(); |
1915 |
|
|
1916 |
pNote->Override.SampleOffset = pos; |
pNote->Override.SampleOffset = |
1917 |
|
(decltype(pNote->Override.SampleOffset)) pos; |
1918 |
|
|
1919 |
return successResult(); |
return successResult(); |
1920 |
} |
} |
2061 |
|
|
2062 |
// if we are here, then this is the parent, so we must fork this parent |
// if we are here, then this is the parent, so we must fork this parent |
2063 |
|
|
2064 |
const int n = |
const vmint n = |
2065 |
(args->argsCount() >= 1) ? args->arg(0)->asInt()->evalInt() : 1; |
(args->argsCount() >= 1) ? args->arg(0)->asInt()->evalInt() : 1; |
2066 |
const bool bAutoAbort = |
const bool bAutoAbort = |
2067 |
(args->argsCount() >= 2) ? args->arg(1)->asInt()->evalInt() : true; |
(args->argsCount() >= 2) ? args->arg(1)->asInt()->evalInt() : true; |
2087 |
return errorResult(-1); // terminate script |
return errorResult(-1); // terminate script |
2088 |
} |
} |
2089 |
// since both parent, as well all child script execution instances |
// since both parent, as well all child script execution instances |
2090 |
// all land in this exect() method, the following is (more or less) |
// all land in this exec() method, the following is (more or less) |
2091 |
// the only feature that lets us distinguish the parent and |
// the only feature that lets us distinguish the parent and |
2092 |
// respective children from each other in this exect() method |
// respective children from each other in this exec() method |
2093 |
itChild->forkIndex = iChild + 1; |
itChild->forkIndex = iChild + 1; |
2094 |
} |
} |
2095 |
|
|