9 |
|
|
10 |
#include "InstrumentScriptVM.h" |
#include "InstrumentScriptVM.h" |
11 |
#include "../AbstractEngineChannel.h" |
#include "../AbstractEngineChannel.h" |
12 |
|
#include "../../common/global_private.h" |
13 |
|
|
14 |
namespace LinuxSampler { |
namespace LinuxSampler { |
15 |
|
|
16 |
// circumvents a bug in GCC 4.4 which prevents the sizeof() expr to be used |
InstrumentScriptVM::InstrumentScriptVM() : |
17 |
// directly within the scrope of a class (would throw a compiler error with: |
m_event(NULL), m_fnPlayNote(this), m_fnSetController(this), |
18 |
// "object missing in reference to 'LinuxSampler::AbstractEngineChannel::ControllerTable'") |
m_fnIgnoreEvent(this), m_fnIgnoreController(this) |
19 |
static const int _AbstractEngineChannel_ControllerTable_size = sizeof(AbstractEngineChannel::ControllerTable); |
{ |
20 |
|
m_CC.size = _MEMBER_SIZEOF(AbstractEngineChannel, ControllerTable); |
21 |
InstrumentScriptVM::InstrumentScriptVM() : m_event(NULL) { |
m_CC_NUM = DECLARE_VMINT(m_event, class ScriptEvent, cause.Param.CC.Controller); |
22 |
m_CC.size = _AbstractEngineChannel_ControllerTable_size; |
m_EVENT_ID = DECLARE_VMINT(m_event, class ScriptEvent, id); |
23 |
m_CC_NUM = DECLARE_VMINT(m_cause, class Event, Param.CC.Controller); |
m_EVENT_NOTE = DECLARE_VMINT(m_event, class ScriptEvent, cause.Param.Note.Key); |
24 |
m_EVENT_NOTE = DECLARE_VMINT(m_cause, class Event, Param.Note.Key); |
m_EVENT_VELOCITY = DECLARE_VMINT(m_event, class ScriptEvent, cause.Param.Note.Velocity); |
|
m_EVENT_VELOCITY = DECLARE_VMINT(m_cause, class Event, Param.Note.Velocity); |
|
25 |
} |
} |
26 |
|
|
27 |
VMExecStatus_t InstrumentScriptVM::exec(VMParserContext* parserCtx, ScriptEvent* event) { |
VMExecStatus_t InstrumentScriptVM::exec(VMParserContext* parserCtx, ScriptEvent* event) { |
29 |
static_cast<AbstractEngineChannel*>(event->cause.pEngineChannel); |
static_cast<AbstractEngineChannel*>(event->cause.pEngineChannel); |
30 |
|
|
31 |
// prepare built-in script variables for script execution |
// prepare built-in script variables for script execution |
32 |
m_cause = &event->cause; |
m_event = event; |
33 |
m_CC.data = (int8_t*) &pEngineChannel->ControllerTable[0]; |
m_CC.data = (int8_t*) &pEngineChannel->ControllerTable[0]; |
34 |
|
|
35 |
// if script is in start condition, then do mandatory MIDI event |
// if script is in start condition, then do mandatory MIDI event |
37 |
// table with new CC value in case of a controller event, because the |
// table with new CC value in case of a controller event, because the |
38 |
// script might access the new CC value |
// script might access the new CC value |
39 |
if (!event->executionSlices) { |
if (!event->executionSlices) { |
40 |
switch (m_cause->Type) { |
switch (event->cause.Type) { |
41 |
case Event::type_control_change: |
case Event::type_control_change: |
42 |
pEngineChannel->ControllerTable[m_cause->Param.CC.Controller] = |
pEngineChannel->ControllerTable[event->cause.Param.CC.Controller] = |
43 |
m_cause->Param.CC.Value; |
event->cause.Param.CC.Value; |
44 |
break; |
break; |
45 |
case Event::type_channel_pressure: |
case Event::type_channel_pressure: |
46 |
pEngineChannel->ControllerTable[CTRL_TABLE_IDX_AFTERTOUCH] = |
pEngineChannel->ControllerTable[CTRL_TABLE_IDX_AFTERTOUCH] = |
47 |
m_cause->Param.ChannelPressure.Value; |
event->cause.Param.ChannelPressure.Value; |
48 |
break; |
break; |
49 |
case Event::type_pitchbend: |
case Event::type_pitchbend: |
50 |
pEngineChannel->ControllerTable[CTRL_TABLE_IDX_PITCHBEND] = |
pEngineChannel->ControllerTable[CTRL_TABLE_IDX_PITCHBEND] = |
51 |
m_cause->Param.Pitch.Pitch; |
event->cause.Param.Pitch.Pitch; |
52 |
break; |
break; |
53 |
} |
} |
54 |
} |
} |
55 |
|
|
56 |
// run the script handler(s) |
// run the script handler(s) |
57 |
VMExecStatus_t res = VM_EXEC_NOT_RUNNING; |
VMExecStatus_t res = VM_EXEC_NOT_RUNNING; |
58 |
while (event->handlers[event->currentHandler]) { |
for ( ; event->handlers[event->currentHandler]; event->currentHandler++) { |
59 |
res = ScriptVM::exec( |
res = ScriptVM::exec( |
60 |
parserCtx, event->execCtx, event->handlers[event->currentHandler++] |
parserCtx, event->execCtx, event->handlers[event->currentHandler] |
61 |
); |
); |
62 |
event->executionSlices++; |
event->executionSlices++; |
63 |
if (res & VM_EXEC_SUSPENDED || res & VM_EXEC_ERROR) return res; |
if (res & VM_EXEC_SUSPENDED || res & VM_EXEC_ERROR) return res; |
72 |
|
|
73 |
// now add own built-in variables |
// now add own built-in variables |
74 |
m["$CC_NUM"] = &m_CC_NUM; |
m["$CC_NUM"] = &m_CC_NUM; |
75 |
|
m["$EVENT_ID"] = &m_EVENT_ID; |
76 |
m["$EVENT_NOTE"] = &m_EVENT_NOTE; |
m["$EVENT_NOTE"] = &m_EVENT_NOTE; |
77 |
m["$EVENT_VELOCITY"] = &m_EVENT_VELOCITY; |
m["$EVENT_VELOCITY"] = &m_EVENT_VELOCITY; |
78 |
// m["$POLY_AT_NUM"] = &m_POLY_AT_NUM; |
// m["$POLY_AT_NUM"] = &m_POLY_AT_NUM; |
102 |
return m; |
return m; |
103 |
} |
} |
104 |
|
|
105 |
|
VMFunction* InstrumentScriptVM::functionByName(const String& name) { |
106 |
|
// built-in script functions of this class |
107 |
|
if (name == "play_note") return &m_fnPlayNote; |
108 |
|
else if (name == "set_controller") return &m_fnSetController; |
109 |
|
else if (name == "ignore_event") return &m_fnIgnoreEvent; |
110 |
|
else if (name == "ignore_controller") return &m_fnIgnoreController; |
111 |
|
|
112 |
|
// built-in script functions of derived VM class |
113 |
|
return ScriptVM::functionByName(name); |
114 |
|
} |
115 |
|
|
116 |
} // namespace LinuxSampler |
} // namespace LinuxSampler |