23 |
VMFnResult* InstrumentScriptVMFunction_play_note::exec(VMFnArgs* args) { |
VMFnResult* InstrumentScriptVMFunction_play_note::exec(VMFnArgs* args) { |
24 |
int note = args->arg(0)->asInt()->evalInt(); |
int note = args->arg(0)->asInt()->evalInt(); |
25 |
int velocity = (args->argsCount() >= 2) ? args->arg(1)->asInt()->evalInt() : 127; |
int velocity = (args->argsCount() >= 2) ? args->arg(1)->asInt()->evalInt() : 127; |
|
int sampleoffset = (args->argsCount() >= 3) ? args->arg(2)->asInt()->evalInt() : 0; |
|
26 |
int duration = (args->argsCount() >= 4) ? args->arg(3)->asInt()->evalInt() : 0; //TODO: -1 might be a better default value instead of 0 |
int 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) { |
35 |
return errorResult(0); |
return errorResult(0); |
36 |
} |
} |
37 |
|
|
38 |
if (sampleoffset < 0) { |
if (duration < -2) { |
39 |
errMsg("play_note(): argument 3 may not be a negative sample offset"); |
errMsg("play_note(): argument 4 must be a duration value of at least -2 or higher"); |
|
return errorResult(0); |
|
|
} else if (sampleoffset != 0) { |
|
|
wrnMsg("play_note(): argument 3 does not support a sample offset other than 0 yet"); |
|
|
} |
|
|
|
|
|
if (duration < -1) { |
|
|
errMsg("play_note(): argument 4 must be a duration value of at least -1 or higher"); |
|
40 |
return errorResult(0); |
return errorResult(0); |
41 |
} |
} |
42 |
|
|
55 |
return errorResult(0); |
return errorResult(0); |
56 |
} |
} |
57 |
e.Param.Note.ParentNoteID = m_vm->m_event->cause.Param.Note.ID; |
e.Param.Note.ParentNoteID = m_vm->m_event->cause.Param.Note.ID; |
58 |
|
// check if that requested parent note is actually still alive |
59 |
|
NoteBase* pParentNote = |
60 |
|
pEngineChannel->pEngine->NoteByID( e.Param.Note.ParentNoteID ); |
61 |
|
// if parent note is already gone then this new note is not required anymore |
62 |
|
if (!pParentNote) |
63 |
|
return successResult(0); |
64 |
} |
} |
65 |
|
|
66 |
const note_id_t id = pEngineChannel->ScheduleNoteMicroSec(&e, 0); |
const note_id_t id = pEngineChannel->ScheduleNoteMicroSec(&e, 0); |
67 |
|
|
68 |
|
// if a sample offset is supplied, assign the offset as override |
69 |
|
// to the previously created Note object |
70 |
|
if (args->argsCount() >= 3) { |
71 |
|
int sampleoffset = args->arg(2)->asInt()->evalInt(); |
72 |
|
if (sampleoffset >= 0) { |
73 |
|
NoteBase* pNote = pEngineChannel->pEngine->NoteByID(id); |
74 |
|
if (pNote) { |
75 |
|
pNote->Override.SampleOffset = sampleoffset; |
76 |
|
} |
77 |
|
} else if (sampleoffset < -1) { |
78 |
|
errMsg("play_note(): sample offset of argument 3 may not be less than -1"); |
79 |
|
} |
80 |
|
} |
81 |
|
|
82 |
// if a duration is supplied (and play-note event was scheduled |
// if a duration is supplied (and play-note event was scheduled |
83 |
// successfully above), then schedule a subsequent stop-note event |
// successfully above), then schedule a subsequent stop-note event |
84 |
if (id && duration > 0) { |
if (id && duration > 0) { |
1805 |
return successResult(); |
return successResult(); |
1806 |
} |
} |
1807 |
|
|
1808 |
|
// change_play_pos() function |
1809 |
|
|
1810 |
|
InstrumentScriptVMFunction_change_play_pos::InstrumentScriptVMFunction_change_play_pos(InstrumentScriptVM* parent) |
1811 |
|
: m_vm(parent) |
1812 |
|
{ |
1813 |
|
} |
1814 |
|
|
1815 |
|
VMFnResult* InstrumentScriptVMFunction_change_play_pos::exec(VMFnArgs* args) { |
1816 |
|
const ScriptID id = args->arg(0)->asInt()->evalInt(); |
1817 |
|
if (!id) { |
1818 |
|
wrnMsg("change_play_pos(): note ID for argument 1 may not be zero"); |
1819 |
|
return successResult(); |
1820 |
|
} |
1821 |
|
if (!id.isNoteID()) { |
1822 |
|
wrnMsg("change_play_pos(): argument 1 is not a note ID"); |
1823 |
|
return successResult(); |
1824 |
|
} |
1825 |
|
|
1826 |
|
const int pos = args->arg(1)->asInt()->evalInt(); |
1827 |
|
if (pos < 0) { |
1828 |
|
wrnMsg("change_play_pos(): playback position of argument 2 may not be negative"); |
1829 |
|
return successResult(); |
1830 |
|
} |
1831 |
|
|
1832 |
|
AbstractEngineChannel* pEngineChannel = |
1833 |
|
static_cast<AbstractEngineChannel*>(m_vm->m_event->cause.pEngineChannel); |
1834 |
|
|
1835 |
|
NoteBase* pNote = pEngineChannel->pEngine->NoteByID( id.noteID() ); |
1836 |
|
if (!pNote) return successResult(); |
1837 |
|
|
1838 |
|
pNote->Override.SampleOffset = pos; |
1839 |
|
|
1840 |
|
return successResult(); |
1841 |
|
} |
1842 |
|
|
1843 |
// event_status() function |
// event_status() function |
1844 |
|
|
1845 |
InstrumentScriptVMFunction_event_status::InstrumentScriptVMFunction_event_status(InstrumentScriptVM* parent) |
InstrumentScriptVMFunction_event_status::InstrumentScriptVMFunction_event_status(InstrumentScriptVM* parent) |
1910 |
|
|
1911 |
return successResult(); |
return successResult(); |
1912 |
} |
} |
1913 |
|
|
1914 |
|
// abort() function |
1915 |
|
|
1916 |
|
InstrumentScriptVMFunction_abort::InstrumentScriptVMFunction_abort(InstrumentScriptVM* parent) |
1917 |
|
: m_vm(parent) |
1918 |
|
{ |
1919 |
|
} |
1920 |
|
|
1921 |
|
VMFnResult* InstrumentScriptVMFunction_abort::exec(VMFnArgs* args) { |
1922 |
|
const script_callback_id_t id = args->arg(0)->asInt()->evalInt(); |
1923 |
|
if (!id) { |
1924 |
|
wrnMsg("abort(): callback ID for argument 1 may not be zero"); |
1925 |
|
return successResult(); |
1926 |
|
} |
1927 |
|
|
1928 |
|
AbstractEngineChannel* pEngineChannel = |
1929 |
|
static_cast<AbstractEngineChannel*>(m_vm->m_event->cause.pEngineChannel); |
1930 |
|
|
1931 |
|
RTList<ScriptEvent>::Iterator itCallback = pEngineChannel->ScriptCallbackByID(id); |
1932 |
|
if (!itCallback) return successResult(); // ignore if callback is i.e. not alive anymore |
1933 |
|
|
1934 |
|
itCallback->execCtx->signalAbort(); |
1935 |
|
|
1936 |
|
return successResult(); |
1937 |
|
} |
1938 |
|
|
1939 |
} // namespace LinuxSampler |
} // namespace LinuxSampler |