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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2600 - (show annotations) (download)
Sat Jun 7 00:16:03 2014 UTC (9 years, 10 months ago) by schoenebeck
File size: 4598 byte(s)
* Implemented built-in instrument script function "set_controller()".
* Fixed built-in script functions "ignore_event()" and
  "ignore_controller()".
* Added extended instrument script VM for the Gigasampler/GigaStudio format
  sampler engine, which extends the general instrument script VM with Giga
  format specific variables and functions.
* Giga format instrument scripts: added built-in script int constant
  variables $GIG_DIM_CHANNEL, $GIG_DIM_LAYER, $GIG_DIM_VELOCITY,
  $GIG_DIM_AFTERTOUCH, $GIG_DIM_RELEASE, $GIG_DIM_KEYBOARD,
  $GIG_DIM_ROUNDROBIN, $GIG_DIM_RANDOM, $GIG_DIM_SMARTMIDI,
  $GIG_DIM_ROUNDROBINKEY, $GIG_DIM_MODWHEEL, $GIG_DIM_BREATH,
  $GIG_DIM_FOOT, $GIG_DIM_PORTAMENTOTIME, $GIG_DIM_EFFECT1,
  $GIG_DIM_EFFECT2, $GIG_DIM_GENPURPOSE1, $GIG_DIM_GENPURPOSE2,
  $GIG_DIM_GENPURPOSE3, $GIG_DIM_GENPURPOSE4, $GIG_DIM_SUSTAIN,
  $GIG_DIM_PORTAMENTO, $GIG_DIM_SOSTENUTO, $GIG_DIM_SOFT,
  $GIG_DIM_GENPURPOSE5, $GIG_DIM_GENPURPOSE6, $GIG_DIM_GENPURPOSE7,
  $GIG_DIM_GENPURPOSE8, $GIG_DIM_EFFECT1DEPTH, $GIG_DIM_EFFECT2DEPTH,
  $GIG_DIM_EFFECT3DEPTH, $GIG_DIM_EFFECT4DEPTH, $GIG_DIM_EFFECT5DEPTH.
* Giga format instrument scripts: Implemented built-in script function
  "gig_set_dim_zone(event_id, dimension, zone)", which allows to override
  dimension zone(s) for new voices.
* Bumped version (1.0.0.svn45).

1 /*
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 #include "../../common/global_private.h"
13
14 namespace LinuxSampler {
15
16 InstrumentScriptVM::InstrumentScriptVM() :
17 m_event(NULL), m_fnPlayNote(this), m_fnSetController(this),
18 m_fnIgnoreEvent(this), m_fnIgnoreController(this)
19 {
20 m_CC.size = _MEMBER_SIZEOF(AbstractEngineChannel, ControllerTable);
21 m_CC_NUM = DECLARE_VMINT(m_event, class ScriptEvent, cause.Param.CC.Controller);
22 m_EVENT_ID = DECLARE_VMINT(m_event, class ScriptEvent, id);
23 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) {
28 AbstractEngineChannel* pEngineChannel =
29 static_cast<AbstractEngineChannel*>(event->cause.pEngineChannel);
30
31 // prepare built-in script variables for script execution
32 m_event = event;
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 (event->cause.Type) {
41 case Event::type_control_change:
42 pEngineChannel->ControllerTable[event->cause.Param.CC.Controller] =
43 event->cause.Param.CC.Value;
44 break;
45 case Event::type_channel_pressure:
46 pEngineChannel->ControllerTable[CTRL_TABLE_IDX_AFTERTOUCH] =
47 event->cause.Param.ChannelPressure.Value;
48 break;
49 case Event::type_pitchbend:
50 pEngineChannel->ControllerTable[CTRL_TABLE_IDX_PITCHBEND] =
51 event->cause.Param.Pitch.Pitch;
52 break;
53 }
54 }
55
56 // run the script handler(s)
57 VMExecStatus_t res = VM_EXEC_NOT_RUNNING;
58 for ( ; event->handlers[event->currentHandler]; 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_ID"] = &m_EVENT_ID;
76 m["$EVENT_NOTE"] = &m_EVENT_NOTE;
77 m["$EVENT_VELOCITY"] = &m_EVENT_VELOCITY;
78 // m["$POLY_AT_NUM"] = &m_POLY_AT_NUM;
79
80 return m;
81 }
82
83 std::map<String,VMInt8Array*> InstrumentScriptVM::builtInIntArrayVariables() {
84 // first get buil-in integer array variables of derived VM class
85 std::map<String,VMInt8Array*> m = ScriptVM::builtInIntArrayVariables();
86
87 // now add own built-in variables
88 m["%CC"] = &m_CC;
89 //m["%KEY_DOWN"] = &m_KEY_DOWN;
90 //m["%POLY_AT"] = &m_POLY_AT;
91
92 return m;
93 }
94
95 std::map<String,int> InstrumentScriptVM::builtInConstIntVariables() {
96 // first get buil-in integer variables of derived VM class
97 std::map<String,int> m = ScriptVM::builtInConstIntVariables();
98
99 m["$VCC_MONO_AT"] = CTRL_TABLE_IDX_AFTERTOUCH;
100 m["$VCC_PITCH_BEND"] = CTRL_TABLE_IDX_PITCHBEND;
101
102 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

  ViewVC Help
Powered by ViewVC