/[svn]/linuxsampler/trunk/src/engines/common/InstrumentScriptVM.cpp
ViewVC logotype

Diff of /linuxsampler/trunk/src/engines/common/InstrumentScriptVM.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2595 by schoenebeck, Thu Jun 5 12:14:53 2014 UTC revision 2600 by schoenebeck, Sat Jun 7 00:16:03 2014 UTC
# Line 9  Line 9 
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.x which causes a sizeof() expression applied      InstrumentScriptVM::InstrumentScriptVM() :
17      // on a class member to throw a compiler error, i.e. with GCC 4.4:          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      // or with GCC 4.0:      {
     // "invalid use of non-static data member 'LinuxSampler::AbstractEngineChannel::ControllerTable'"  
     #define _MEMBER_SIZEOF(T_Class, Member) sizeof(((T_Class*)NULL)->Member)  
   
     InstrumentScriptVM::InstrumentScriptVM() : m_event(NULL) {  
20          m_CC.size = _MEMBER_SIZEOF(AbstractEngineChannel, ControllerTable);          m_CC.size = _MEMBER_SIZEOF(AbstractEngineChannel, ControllerTable);
21          m_CC_NUM = DECLARE_VMINT(m_cause, class Event, Param.CC.Controller);          m_CC_NUM = DECLARE_VMINT(m_event, class ScriptEvent, cause.Param.CC.Controller);
22          m_EVENT_NOTE = DECLARE_VMINT(m_cause, class Event, Param.Note.Key);          m_EVENT_ID = DECLARE_VMINT(m_event, class ScriptEvent, id);
23          m_EVENT_VELOCITY = DECLARE_VMINT(m_cause, class Event, Param.Note.Velocity);          m_EVENT_NOTE = DECLARE_VMINT(m_event, class ScriptEvent, cause.Param.Note.Key);
24            m_EVENT_VELOCITY = DECLARE_VMINT(m_event, class ScriptEvent, cause.Param.Note.Velocity);
25      }      }
26    
27      VMExecStatus_t InstrumentScriptVM::exec(VMParserContext* parserCtx, ScriptEvent* event) {      VMExecStatus_t InstrumentScriptVM::exec(VMParserContext* parserCtx, ScriptEvent* event) {
# Line 31  namespace LinuxSampler { Line 29  namespace LinuxSampler {
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
# Line 39  namespace LinuxSampler { Line 37  namespace LinuxSampler {
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;
# Line 74  namespace LinuxSampler { Line 72  namespace LinuxSampler {
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;
# Line 103  namespace LinuxSampler { Line 102  namespace LinuxSampler {
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

Legend:
Removed from v.2595  
changed lines
  Added in v.2600

  ViewVC Help
Powered by ViewVC