1066 |
return type == INT_EXPR; |
return type == INT_EXPR; |
1067 |
} |
} |
1068 |
|
|
1069 |
|
// Arbitrarily chosen constant value symbolizing "no limit". |
1070 |
|
#define NO_LIMIT 1315916909 |
1071 |
|
|
1072 |
template<float NoteBase::_Override::*T_noteParam, int T_synthParam, |
template<float NoteBase::_Override::*T_noteParam, int T_synthParam, |
1073 |
bool T_isNormalizedParam, int T_maxValue, int T_minValue> |
bool T_isNormalizedParam, int T_maxValue, int T_minValue> |
1074 |
VMFnResult* VMChangeSynthParamFunction::execTemplate(VMFnArgs* args, const char* functionName) { |
VMFnResult* VMChangeSynthParamFunction::execTemplate(VMFnArgs* args, const char* functionName) { |
1075 |
int value = args->arg(1)->asInt()->evalInt(); |
int value = args->arg(1)->asInt()->evalInt(); |
1076 |
if (value > T_maxValue) { |
if (T_maxValue != NO_LIMIT && value > T_maxValue) { |
1077 |
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)); |
1078 |
value = T_maxValue; |
value = T_maxValue; |
1079 |
} else if (value < T_minValue) { |
} else if (T_minValue != NO_LIMIT && value < T_minValue) { |
1080 |
if (T_minValue == 0) |
if (T_minValue == 0) |
1081 |
wrnMsg(String(functionName) + "(): argument 2 may not be negative"); |
wrnMsg(String(functionName) + "(): argument 2 may not be negative"); |
1082 |
else |
else |
1156 |
VMFnResult* InstrumentScriptVMFunction_change_amp_lfo_depth::exec(VMFnArgs* args) { |
VMFnResult* InstrumentScriptVMFunction_change_amp_lfo_depth::exec(VMFnArgs* args) { |
1157 |
return VMChangeSynthParamFunction::execTemplate< |
return VMChangeSynthParamFunction::execTemplate< |
1158 |
&NoteBase::_Override::AmpLFODepth, |
&NoteBase::_Override::AmpLFODepth, |
1159 |
Event::synth_param_amp_lfo_depth, true>( args, "change_amp_lfo_depth" ); |
Event::synth_param_amp_lfo_depth, |
1160 |
|
true, 1000000, 0>( args, "change_amp_lfo_depth" ); |
1161 |
} |
} |
1162 |
|
|
1163 |
// change_amp_lfo_freq() function |
// change_amp_lfo_freq() function |
1165 |
VMFnResult* InstrumentScriptVMFunction_change_amp_lfo_freq::exec(VMFnArgs* args) { |
VMFnResult* InstrumentScriptVMFunction_change_amp_lfo_freq::exec(VMFnArgs* args) { |
1166 |
return VMChangeSynthParamFunction::execTemplate< |
return VMChangeSynthParamFunction::execTemplate< |
1167 |
&NoteBase::_Override::AmpLFOFreq, |
&NoteBase::_Override::AmpLFOFreq, |
1168 |
Event::synth_param_amp_lfo_freq, true>( args, "change_amp_lfo_freq" ); |
Event::synth_param_amp_lfo_freq, |
1169 |
|
true, 1000000, 0>( args, "change_amp_lfo_freq" ); |
1170 |
} |
} |
1171 |
|
|
1172 |
// change_pitch_lfo_depth() function |
// change_pitch_lfo_depth() function |
1174 |
VMFnResult* InstrumentScriptVMFunction_change_pitch_lfo_depth::exec(VMFnArgs* args) { |
VMFnResult* InstrumentScriptVMFunction_change_pitch_lfo_depth::exec(VMFnArgs* args) { |
1175 |
return VMChangeSynthParamFunction::execTemplate< |
return VMChangeSynthParamFunction::execTemplate< |
1176 |
&NoteBase::_Override::PitchLFODepth, |
&NoteBase::_Override::PitchLFODepth, |
1177 |
Event::synth_param_pitch_lfo_depth, true>( args, "change_pitch_lfo_depth" ); |
Event::synth_param_pitch_lfo_depth, |
1178 |
|
true, 1000000, 0>( args, "change_pitch_lfo_depth" ); |
1179 |
} |
} |
1180 |
|
|
1181 |
// change_pitch_lfo_freq() function |
// change_pitch_lfo_freq() function |
1183 |
VMFnResult* InstrumentScriptVMFunction_change_pitch_lfo_freq::exec(VMFnArgs* args) { |
VMFnResult* InstrumentScriptVMFunction_change_pitch_lfo_freq::exec(VMFnArgs* args) { |
1184 |
return VMChangeSynthParamFunction::execTemplate< |
return VMChangeSynthParamFunction::execTemplate< |
1185 |
&NoteBase::_Override::PitchLFOFreq, |
&NoteBase::_Override::PitchLFOFreq, |
1186 |
Event::synth_param_pitch_lfo_freq, true>( args, "change_pitch_lfo_freq" ); |
Event::synth_param_pitch_lfo_freq, |
1187 |
|
true, 1000000, 0>( args, "change_pitch_lfo_freq" ); |
1188 |
} |
} |
1189 |
|
|
1190 |
// change_vol_time() function |
// change_vol_time() function |
1192 |
VMFnResult* InstrumentScriptVMFunction_change_vol_time::exec(VMFnArgs* args) { |
VMFnResult* InstrumentScriptVMFunction_change_vol_time::exec(VMFnArgs* args) { |
1193 |
return VMChangeSynthParamFunction::execTemplate< |
return VMChangeSynthParamFunction::execTemplate< |
1194 |
&NoteBase::_Override::VolumeTime, |
&NoteBase::_Override::VolumeTime, |
1195 |
Event::synth_param_volume_time, false>( args, "change_vol_time" ); |
Event::synth_param_volume_time, |
1196 |
|
false, NO_LIMIT, 0>( args, "change_vol_time" ); |
1197 |
} |
} |
1198 |
|
|
1199 |
// change_tune_time() function |
// change_tune_time() function |
1201 |
VMFnResult* InstrumentScriptVMFunction_change_tune_time::exec(VMFnArgs* args) { |
VMFnResult* InstrumentScriptVMFunction_change_tune_time::exec(VMFnArgs* args) { |
1202 |
return VMChangeSynthParamFunction::execTemplate< |
return VMChangeSynthParamFunction::execTemplate< |
1203 |
&NoteBase::_Override::PitchTime, |
&NoteBase::_Override::PitchTime, |
1204 |
Event::synth_param_pitch_time, false>( args, "change_tune_time" ); |
Event::synth_param_pitch_time, |
1205 |
|
false, NO_LIMIT, 0>( args, "change_tune_time" ); |
1206 |
} |
} |
1207 |
|
|
1208 |
// fade_in() function |
// fade_in() function |
1467 |
return successResult(); |
return successResult(); |
1468 |
} |
} |
1469 |
|
|
1470 |
|
// get_event_par() function |
1471 |
|
|
1472 |
|
InstrumentScriptVMFunction_get_event_par::InstrumentScriptVMFunction_get_event_par(InstrumentScriptVM* parent) |
1473 |
|
: m_vm(parent) |
1474 |
|
{ |
1475 |
|
} |
1476 |
|
|
1477 |
|
VMFnResult* InstrumentScriptVMFunction_get_event_par::exec(VMFnArgs* args) { |
1478 |
|
AbstractEngineChannel* pEngineChannel = |
1479 |
|
static_cast<AbstractEngineChannel*>(m_vm->m_event->cause.pEngineChannel); |
1480 |
|
|
1481 |
|
const ScriptID id = args->arg(0)->asInt()->evalInt(); |
1482 |
|
if (!id) { |
1483 |
|
wrnMsg("get_event_par(): note ID for argument 1 may not be zero"); |
1484 |
|
return successResult(0); |
1485 |
|
} |
1486 |
|
if (!id.isNoteID()) { |
1487 |
|
wrnMsg("get_event_par(): argument 1 is not a note ID"); |
1488 |
|
return successResult(0); |
1489 |
|
} |
1490 |
|
|
1491 |
|
NoteBase* pNote = pEngineChannel->pEngine->NoteByID( id.noteID() ); |
1492 |
|
if (!pNote) { |
1493 |
|
wrnMsg("get_event_par(): no note alive with that note ID of argument 1"); |
1494 |
|
return successResult(0); |
1495 |
|
} |
1496 |
|
|
1497 |
|
const int parameter = args->arg(1)->asInt()->evalInt(); |
1498 |
|
switch (parameter) { |
1499 |
|
case EVENT_PAR_NOTE: |
1500 |
|
return successResult(pNote->cause.Param.Note.Key); |
1501 |
|
case EVENT_PAR_VELOCITY: |
1502 |
|
return successResult(pNote->cause.Param.Note.Velocity); |
1503 |
|
case EVENT_PAR_VOLUME: |
1504 |
|
return successResult( |
1505 |
|
RTMath::LinRatioToDecibel(pNote->Override.Volume) * 1000.f |
1506 |
|
); |
1507 |
|
case EVENT_PAR_TUNE: |
1508 |
|
return successResult( |
1509 |
|
RTMath::FreqRatioToCents(pNote->Override.Pitch) * 1000.f |
1510 |
|
); |
1511 |
|
case EVENT_PAR_0: |
1512 |
|
return successResult(pNote->userPar[0]); |
1513 |
|
case EVENT_PAR_1: |
1514 |
|
return successResult(pNote->userPar[1]); |
1515 |
|
case EVENT_PAR_2: |
1516 |
|
return successResult(pNote->userPar[2]); |
1517 |
|
case EVENT_PAR_3: |
1518 |
|
return successResult(pNote->userPar[3]); |
1519 |
|
} |
1520 |
|
|
1521 |
|
wrnMsg("get_event_par(): argument 2 is an invalid event parameter"); |
1522 |
|
return successResult(0); |
1523 |
|
} |
1524 |
|
|
1525 |
|
// set_event_par() function |
1526 |
|
|
1527 |
|
InstrumentScriptVMFunction_set_event_par::InstrumentScriptVMFunction_set_event_par(InstrumentScriptVM* parent) |
1528 |
|
: m_vm(parent) |
1529 |
|
{ |
1530 |
|
} |
1531 |
|
|
1532 |
|
VMFnResult* InstrumentScriptVMFunction_set_event_par::exec(VMFnArgs* args) { |
1533 |
|
AbstractEngineChannel* pEngineChannel = |
1534 |
|
static_cast<AbstractEngineChannel*>(m_vm->m_event->cause.pEngineChannel); |
1535 |
|
|
1536 |
|
const ScriptID id = args->arg(0)->asInt()->evalInt(); |
1537 |
|
if (!id) { |
1538 |
|
wrnMsg("set_event_par(): note ID for argument 1 may not be zero"); |
1539 |
|
return successResult(); |
1540 |
|
} |
1541 |
|
if (!id.isNoteID()) { |
1542 |
|
wrnMsg("set_event_par(): argument 1 is not a note ID"); |
1543 |
|
return successResult(); |
1544 |
|
} |
1545 |
|
|
1546 |
|
NoteBase* pNote = pEngineChannel->pEngine->NoteByID( id.noteID() ); |
1547 |
|
if (!pNote) return successResult(); |
1548 |
|
|
1549 |
|
const int parameter = args->arg(1)->asInt()->evalInt(); |
1550 |
|
const int value = args->arg(2)->asInt()->evalInt(); |
1551 |
|
|
1552 |
|
switch (parameter) { |
1553 |
|
case EVENT_PAR_NOTE: |
1554 |
|
if (value < 0 || value > 127) { |
1555 |
|
wrnMsg("set_event_par(): note number of argument 3 is out of range"); |
1556 |
|
return successResult(); |
1557 |
|
} |
1558 |
|
if (m_vm->m_event->cause.SchedTime() == pNote->triggerSchedTime) |
1559 |
|
pNote->cause.Param.Note.Key = value; |
1560 |
|
else |
1561 |
|
wrnMsg("set_event_par(): note number can only be changed when note is new"); |
1562 |
|
return successResult(); |
1563 |
|
case EVENT_PAR_VELOCITY: |
1564 |
|
if (value < 0 || value > 127) { |
1565 |
|
wrnMsg("set_event_par(): velocity of argument 3 is out of range"); |
1566 |
|
return successResult(); |
1567 |
|
} |
1568 |
|
if (m_vm->m_event->cause.SchedTime() == pNote->triggerSchedTime) |
1569 |
|
pNote->cause.Param.Note.Velocity = value; |
1570 |
|
else |
1571 |
|
wrnMsg("set_event_par(): velocity can only be changed when note is new"); |
1572 |
|
return successResult(); |
1573 |
|
case EVENT_PAR_VOLUME: |
1574 |
|
wrnMsg("set_event_par(): changing volume by this function is currently not supported, use change_vol() instead"); |
1575 |
|
return successResult(); |
1576 |
|
case EVENT_PAR_TUNE: |
1577 |
|
wrnMsg("set_event_par(): changing tune by this function is currently not supported, use change_tune() instead"); |
1578 |
|
return successResult(); |
1579 |
|
case EVENT_PAR_0: |
1580 |
|
pNote->userPar[0] = value; |
1581 |
|
return successResult(); |
1582 |
|
case EVENT_PAR_1: |
1583 |
|
pNote->userPar[1] = value; |
1584 |
|
return successResult(); |
1585 |
|
case EVENT_PAR_2: |
1586 |
|
pNote->userPar[2] = value; |
1587 |
|
return successResult(); |
1588 |
|
case EVENT_PAR_3: |
1589 |
|
pNote->userPar[3] = value; |
1590 |
|
return successResult(); |
1591 |
|
} |
1592 |
|
|
1593 |
|
wrnMsg("set_event_par(): argument 2 is an invalid event parameter"); |
1594 |
|
return successResult(); |
1595 |
|
} |
1596 |
|
|
1597 |
// event_status() function |
// event_status() function |
1598 |
|
|
1599 |
InstrumentScriptVMFunction_event_status::InstrumentScriptVMFunction_event_status(InstrumentScriptVM* parent) |
InstrumentScriptVMFunction_event_status::InstrumentScriptVMFunction_event_status(InstrumentScriptVM* parent) |