12 |
|
|
13 |
namespace LinuxSampler { |
namespace LinuxSampler { |
14 |
|
|
15 |
// circumvents a bug in GCC 4.4 which prevents the sizeof() expr to be used |
// circumvents a bug in GCC 4.x which causes a sizeof() expression applied |
16 |
// directly within the scrope of a class (would throw a compiler error with: |
// on a class member to throw a compiler error, i.e. with GCC 4.4: |
17 |
// "object missing in reference to 'LinuxSampler::AbstractEngineChannel::ControllerTable'") |
// "object missing in reference to 'LinuxSampler::AbstractEngineChannel::ControllerTable'") |
18 |
static const int _AbstractEngineChannel_ControllerTable_size = sizeof(AbstractEngineChannel::ControllerTable); |
// or with GCC 4.0: |
19 |
|
// "invalid use of non-static data member 'LinuxSampler::AbstractEngineChannel::ControllerTable'" |
20 |
InstrumentScriptVM::InstrumentScriptVM() : m_event(NULL) { |
#define _MEMBER_SIZEOF(T_Class, Member) sizeof(((T_Class*)NULL)->Member) |
21 |
m_CC.size = _AbstractEngineChannel_ControllerTable_size; |
|
22 |
m_CC_NUM = DECLARE_VMINT(m_cause, class Event, Param.CC.Controller); |
InstrumentScriptVM::InstrumentScriptVM() : |
23 |
m_EVENT_NOTE = DECLARE_VMINT(m_cause, class Event, Param.Note.Key); |
m_event(NULL), m_fnPlayNote(this), m_fnIgnoreEvent(this), |
24 |
m_EVENT_VELOCITY = DECLARE_VMINT(m_cause, class Event, Param.Note.Velocity); |
m_fnIgnoreController(this) |
25 |
|
{ |
26 |
|
m_CC.size = _MEMBER_SIZEOF(AbstractEngineChannel, ControllerTable); |
27 |
|
m_CC_NUM = DECLARE_VMINT(m_event, class ScriptEvent, cause.Param.CC.Controller); |
28 |
|
m_EVENT_ID = DECLARE_VMINT(m_event, class ScriptEvent, id); |
29 |
|
m_EVENT_NOTE = DECLARE_VMINT(m_event, class ScriptEvent, cause.Param.Note.Key); |
30 |
|
m_EVENT_VELOCITY = DECLARE_VMINT(m_event, class ScriptEvent, cause.Param.Note.Velocity); |
31 |
} |
} |
32 |
|
|
33 |
VMExecStatus_t InstrumentScriptVM::exec(VMParserContext* parserCtx, ScriptEvent* event) { |
VMExecStatus_t InstrumentScriptVM::exec(VMParserContext* parserCtx, ScriptEvent* event) { |
35 |
static_cast<AbstractEngineChannel*>(event->cause.pEngineChannel); |
static_cast<AbstractEngineChannel*>(event->cause.pEngineChannel); |
36 |
|
|
37 |
// prepare built-in script variables for script execution |
// prepare built-in script variables for script execution |
38 |
m_cause = &event->cause; |
m_event = event; |
39 |
m_CC.data = (int8_t*) &pEngineChannel->ControllerTable[0]; |
m_CC.data = (int8_t*) &pEngineChannel->ControllerTable[0]; |
40 |
|
|
41 |
// if script is in start condition, then do mandatory MIDI event |
// if script is in start condition, then do mandatory MIDI event |
43 |
// 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 |
44 |
// script might access the new CC value |
// script might access the new CC value |
45 |
if (!event->executionSlices) { |
if (!event->executionSlices) { |
46 |
switch (m_cause->Type) { |
switch (event->cause.Type) { |
47 |
case Event::type_control_change: |
case Event::type_control_change: |
48 |
pEngineChannel->ControllerTable[m_cause->Param.CC.Controller] = |
pEngineChannel->ControllerTable[event->cause.Param.CC.Controller] = |
49 |
m_cause->Param.CC.Value; |
event->cause.Param.CC.Value; |
50 |
break; |
break; |
51 |
case Event::type_channel_pressure: |
case Event::type_channel_pressure: |
52 |
pEngineChannel->ControllerTable[CTRL_TABLE_IDX_AFTERTOUCH] = |
pEngineChannel->ControllerTable[CTRL_TABLE_IDX_AFTERTOUCH] = |
53 |
m_cause->Param.ChannelPressure.Value; |
event->cause.Param.ChannelPressure.Value; |
54 |
break; |
break; |
55 |
case Event::type_pitchbend: |
case Event::type_pitchbend: |
56 |
pEngineChannel->ControllerTable[CTRL_TABLE_IDX_PITCHBEND] = |
pEngineChannel->ControllerTable[CTRL_TABLE_IDX_PITCHBEND] = |
57 |
m_cause->Param.Pitch.Pitch; |
event->cause.Param.Pitch.Pitch; |
58 |
break; |
break; |
59 |
} |
} |
60 |
} |
} |
61 |
|
|
62 |
// run the script handler(s) |
// run the script handler(s) |
63 |
VMExecStatus_t res = VM_EXEC_NOT_RUNNING; |
VMExecStatus_t res = VM_EXEC_NOT_RUNNING; |
64 |
while (event->handlers[event->currentHandler]) { |
for ( ; event->handlers[event->currentHandler]; event->currentHandler++) { |
65 |
res = ScriptVM::exec( |
res = ScriptVM::exec( |
66 |
parserCtx, event->execCtx, event->handlers[event->currentHandler++] |
parserCtx, event->execCtx, event->handlers[event->currentHandler] |
67 |
); |
); |
68 |
event->executionSlices++; |
event->executionSlices++; |
69 |
if (res & VM_EXEC_SUSPENDED || res & VM_EXEC_ERROR) return res; |
if (res & VM_EXEC_SUSPENDED || res & VM_EXEC_ERROR) return res; |
78 |
|
|
79 |
// now add own built-in variables |
// now add own built-in variables |
80 |
m["$CC_NUM"] = &m_CC_NUM; |
m["$CC_NUM"] = &m_CC_NUM; |
81 |
|
m["$EVENT_ID"] = &m_EVENT_ID; |
82 |
m["$EVENT_NOTE"] = &m_EVENT_NOTE; |
m["$EVENT_NOTE"] = &m_EVENT_NOTE; |
83 |
m["$EVENT_VELOCITY"] = &m_EVENT_VELOCITY; |
m["$EVENT_VELOCITY"] = &m_EVENT_VELOCITY; |
84 |
// m["$POLY_AT_NUM"] = &m_POLY_AT_NUM; |
// m["$POLY_AT_NUM"] = &m_POLY_AT_NUM; |
108 |
return m; |
return m; |
109 |
} |
} |
110 |
|
|
111 |
|
VMFunction* InstrumentScriptVM::functionByName(const String& name) { |
112 |
|
// built-in script functions of this class |
113 |
|
if (name == "play_note") return &m_fnPlayNote; |
114 |
|
else if (name == "ignore_event") return &m_fnIgnoreEvent; |
115 |
|
else if (name == "ignore_controller") return &m_fnIgnoreController; |
116 |
|
|
117 |
|
// built-in script functions of derived VM class |
118 |
|
return ScriptVM::functionByName(name); |
119 |
|
} |
120 |
|
|
121 |
} // namespace LinuxSampler |
} // namespace LinuxSampler |