/[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 2596 - (hide annotations) (download)
Thu Jun 5 19:39:12 2014 UTC (9 years, 9 months ago) by schoenebeck
File size: 4552 byte(s)
* ScriptVM (WIP): Implemented execution of script event
  handlers "note" and "release".
* ScriptVM (WIP): Implemented built-in script function
  "play_note()" (only two of the max. four function
  arguments are currently implemented yet though).
* ScriptVM (WIP): Fixed incorrect handling of
  suspended scripts.
* Bumped version (1.0.0.svn43).

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 schoenebeck 2596 InstrumentScriptVM::InstrumentScriptVM() :
23     m_event(NULL), m_fnPlayNote(this)
24     {
25 schoenebeck 2595 m_CC.size = _MEMBER_SIZEOF(AbstractEngineChannel, ControllerTable);
26 schoenebeck 2594 m_CC_NUM = DECLARE_VMINT(m_cause, class Event, Param.CC.Controller);
27     m_EVENT_NOTE = DECLARE_VMINT(m_cause, class Event, Param.Note.Key);
28     m_EVENT_VELOCITY = DECLARE_VMINT(m_cause, class Event, Param.Note.Velocity);
29     }
30    
31     VMExecStatus_t InstrumentScriptVM::exec(VMParserContext* parserCtx, ScriptEvent* event) {
32     AbstractEngineChannel* pEngineChannel =
33     static_cast<AbstractEngineChannel*>(event->cause.pEngineChannel);
34    
35     // prepare built-in script variables for script execution
36     m_cause = &event->cause;
37     m_CC.data = (int8_t*) &pEngineChannel->ControllerTable[0];
38    
39     // if script is in start condition, then do mandatory MIDI event
40     // preprocessing tasks, which essentially means updating i.e. controller
41     // table with new CC value in case of a controller event, because the
42     // script might access the new CC value
43     if (!event->executionSlices) {
44     switch (m_cause->Type) {
45     case Event::type_control_change:
46     pEngineChannel->ControllerTable[m_cause->Param.CC.Controller] =
47     m_cause->Param.CC.Value;
48     break;
49     case Event::type_channel_pressure:
50     pEngineChannel->ControllerTable[CTRL_TABLE_IDX_AFTERTOUCH] =
51     m_cause->Param.ChannelPressure.Value;
52     break;
53     case Event::type_pitchbend:
54     pEngineChannel->ControllerTable[CTRL_TABLE_IDX_PITCHBEND] =
55     m_cause->Param.Pitch.Pitch;
56     break;
57     }
58     }
59    
60     // run the script handler(s)
61     VMExecStatus_t res = VM_EXEC_NOT_RUNNING;
62 schoenebeck 2596 for ( ; event->handlers[event->currentHandler]; event->currentHandler++) {
63 schoenebeck 2594 res = ScriptVM::exec(
64 schoenebeck 2596 parserCtx, event->execCtx, event->handlers[event->currentHandler]
65 schoenebeck 2594 );
66     event->executionSlices++;
67     if (res & VM_EXEC_SUSPENDED || res & VM_EXEC_ERROR) return res;
68     }
69    
70     return res;
71     }
72    
73     std::map<String,VMIntRelPtr*> InstrumentScriptVM::builtInIntVariables() {
74     // first get buil-in integer variables of derived VM class
75     std::map<String,VMIntRelPtr*> m = ScriptVM::builtInIntVariables();
76    
77     // now add own built-in variables
78     m["$CC_NUM"] = &m_CC_NUM;
79     m["$EVENT_NOTE"] = &m_EVENT_NOTE;
80     m["$EVENT_VELOCITY"] = &m_EVENT_VELOCITY;
81     // m["$POLY_AT_NUM"] = &m_POLY_AT_NUM;
82    
83     return m;
84     }
85    
86     std::map<String,VMInt8Array*> InstrumentScriptVM::builtInIntArrayVariables() {
87     // first get buil-in integer array variables of derived VM class
88     std::map<String,VMInt8Array*> m = ScriptVM::builtInIntArrayVariables();
89    
90     // now add own built-in variables
91     m["%CC"] = &m_CC;
92     //m["%KEY_DOWN"] = &m_KEY_DOWN;
93     //m["%POLY_AT"] = &m_POLY_AT;
94    
95     return m;
96     }
97    
98     std::map<String,int> InstrumentScriptVM::builtInConstIntVariables() {
99     // first get buil-in integer variables of derived VM class
100     std::map<String,int> m = ScriptVM::builtInConstIntVariables();
101    
102     m["$VCC_MONO_AT"] = CTRL_TABLE_IDX_AFTERTOUCH;
103     m["$VCC_PITCH_BEND"] = CTRL_TABLE_IDX_PITCHBEND;
104    
105     return m;
106     }
107    
108 schoenebeck 2596 VMFunction* InstrumentScriptVM::functionByName(const String& name) {
109     // built-in script functions of this class
110     if (name == "play_note") return &m_fnPlayNote;
111    
112     // built-in script functions of derived VM class
113     return ScriptVM::functionByName(name);
114     }
115    
116 schoenebeck 2594 } // namespace LinuxSampler

  ViewVC Help
Powered by ViewVC