/[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 2594 - (hide annotations) (download)
Thu Jun 5 00:16:25 2014 UTC (9 years, 10 months ago) by schoenebeck
File size: 4117 byte(s)
* ScriptVM (WIP): started to integrate real-time instrument script
  support into the sampler engine implementations. The code is
  shared among all sampler engines, however currently only the gig
  file format supports storing instrument scripts (as LinuxSampler
  extension to the original GigaStudio 4 file format).
* gig engine: Added support for loading instrument scripts from .gig
  files.
* ScriptVM (WIP): Implemented built-in script variables %CC, $CC_NUM,
  $EVENT_NOTE, $EVENT_VELOCITY, $VCC_MONO_AT, $VCC_PITCH_BEND.
* ScriptVM (WIP): Implemented execution of script event handler "init".
* ScriptVM (WIP): Implemented execution of script event handler
  "controller".
* Bumped version (1.0.0.svn42).

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

  ViewVC Help
Powered by ViewVC