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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2595 - (hide annotations) (download)
Thu Jun 5 12:14:53 2014 UTC (9 years, 10 months ago) by schoenebeck
File size: 4205 byte(s)
- Fixed compiler error with GCC 4.x (seems to be a GCC bug).

1 schoenebeck 2594 /*
2     * Copyright (c) 2014 Christian Schoenebeck
3     *
4     * http://www.linuxsampler.org
5     *
6     * This file is part of LinuxSampler and released under the same terms.
7     * See README file for details.
8     */
9    
10     #include "InstrumentScriptVM.h"
11     #include "../AbstractEngineChannel.h"
12    
13     namespace LinuxSampler {
14    
15 schoenebeck 2595 // circumvents a bug in GCC 4.x which causes a sizeof() expression applied
16     // on a class member to throw a compiler error, i.e. with GCC 4.4:
17 schoenebeck 2594 // "object missing in reference to 'LinuxSampler::AbstractEngineChannel::ControllerTable'")
18 schoenebeck 2595 // or with GCC 4.0:
19     // "invalid use of non-static data member 'LinuxSampler::AbstractEngineChannel::ControllerTable'"
20     #define _MEMBER_SIZEOF(T_Class, Member) sizeof(((T_Class*)NULL)->Member)
21 schoenebeck 2594
22     InstrumentScriptVM::InstrumentScriptVM() : m_event(NULL) {
23 schoenebeck 2595 m_CC.size = _MEMBER_SIZEOF(AbstractEngineChannel, ControllerTable);
24 schoenebeck 2594 m_CC_NUM = DECLARE_VMINT(m_cause, class Event, Param.CC.Controller);
25     m_EVENT_NOTE = DECLARE_VMINT(m_cause, class Event, Param.Note.Key);
26     m_EVENT_VELOCITY = DECLARE_VMINT(m_cause, class Event, Param.Note.Velocity);
27     }
28    
29     VMExecStatus_t InstrumentScriptVM::exec(VMParserContext* parserCtx, ScriptEvent* event) {
30     AbstractEngineChannel* pEngineChannel =
31     static_cast<AbstractEngineChannel*>(event->cause.pEngineChannel);
32    
33     // prepare built-in script variables for script execution
34     m_cause = &event->cause;
35     m_CC.data = (int8_t*) &pEngineChannel->ControllerTable[0];
36    
37     // if script is in start condition, then do mandatory MIDI event
38     // preprocessing tasks, which essentially means updating i.e. controller
39     // table with new CC value in case of a controller event, because the
40     // script might access the new CC value
41     if (!event->executionSlices) {
42     switch (m_cause->Type) {
43     case Event::type_control_change:
44     pEngineChannel->ControllerTable[m_cause->Param.CC.Controller] =
45     m_cause->Param.CC.Value;
46     break;
47     case Event::type_channel_pressure:
48     pEngineChannel->ControllerTable[CTRL_TABLE_IDX_AFTERTOUCH] =
49     m_cause->Param.ChannelPressure.Value;
50     break;
51     case Event::type_pitchbend:
52     pEngineChannel->ControllerTable[CTRL_TABLE_IDX_PITCHBEND] =
53     m_cause->Param.Pitch.Pitch;
54     break;
55     }
56     }
57    
58     // run the script handler(s)
59     VMExecStatus_t res = VM_EXEC_NOT_RUNNING;
60     while (event->handlers[event->currentHandler]) {
61     res = ScriptVM::exec(
62     parserCtx, event->execCtx, event->handlers[event->currentHandler++]
63     );
64     event->executionSlices++;
65     if (res & VM_EXEC_SUSPENDED || res & VM_EXEC_ERROR) return res;
66     }
67    
68     return res;
69     }
70    
71     std::map<String,VMIntRelPtr*> InstrumentScriptVM::builtInIntVariables() {
72     // first get buil-in integer variables of derived VM class
73     std::map<String,VMIntRelPtr*> m = ScriptVM::builtInIntVariables();
74    
75     // now add own built-in variables
76     m["$CC_NUM"] = &m_CC_NUM;
77     m["$EVENT_NOTE"] = &m_EVENT_NOTE;
78     m["$EVENT_VELOCITY"] = &m_EVENT_VELOCITY;
79     // m["$POLY_AT_NUM"] = &m_POLY_AT_NUM;
80    
81     return m;
82     }
83    
84     std::map<String,VMInt8Array*> InstrumentScriptVM::builtInIntArrayVariables() {
85     // first get buil-in integer array variables of derived VM class
86     std::map<String,VMInt8Array*> m = ScriptVM::builtInIntArrayVariables();
87    
88     // now add own built-in variables
89     m["%CC"] = &m_CC;
90     //m["%KEY_DOWN"] = &m_KEY_DOWN;
91     //m["%POLY_AT"] = &m_POLY_AT;
92    
93     return m;
94     }
95    
96     std::map<String,int> InstrumentScriptVM::builtInConstIntVariables() {
97     // first get buil-in integer variables of derived VM class
98     std::map<String,int> m = ScriptVM::builtInConstIntVariables();
99    
100     m["$VCC_MONO_AT"] = CTRL_TABLE_IDX_AFTERTOUCH;
101     m["$VCC_PITCH_BEND"] = CTRL_TABLE_IDX_PITCHBEND;
102    
103     return m;
104     }
105    
106     } // namespace LinuxSampler

  ViewVC Help
Powered by ViewVC