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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2629 - (show annotations) (download) (as text)
Thu Jun 12 18:25:11 2014 UTC (9 years, 9 months ago) by schoenebeck
File MIME type: text/x-c++hdr
File size: 5074 byte(s)
* Implemented built-in instrument script function "note_off()".
* Bumped version (1.0.0.svn52).

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 #ifndef LS_INSTRUMENT_SCRIPT_VM_H
11 #define LS_INSTRUMENT_SCRIPT_VM_H
12
13 #include "../../common/global.h"
14 #include "../../scriptvm/ScriptVM.h"
15 #include "Event.h"
16 #include "../../common/Pool.h"
17 #include "InstrumentScriptVMFunctions.h"
18
19 namespace LinuxSampler {
20
21 class AbstractEngineChannel;
22
23 /** @brief Real-time instrument script VM representation.
24 *
25 * Holds the VM representation of all event handlers of the currently loaded
26 * script, ready to be executed by the sampler engine.
27 */
28 struct InstrumentScript {
29 VMParserContext* parserContext; ///< VM represenation of the currently loaded script or NULL if not script was loaded. Note that it is also not NULL if parser errors occurred!
30 bool bHasValidScript; ///< True in case there is a valid script currently loaded, false if script processing shall be skipped.
31 VMEventHandler* handlerInit; ///< VM representation of script's initilization callback or NULL if current script did not define such an init handler.
32 VMEventHandler* handlerNote; ///< VM representation of script's MIDI note on callback or NULL if current script did not define such an event handler.
33 VMEventHandler* handlerRelease; ///< VM representation of script's MIDI note off callback or NULL if current script did not define such an event handler.
34 VMEventHandler* handlerController; ///< VM representation of script's MIDI controller callback or NULL if current script did not define such an event handler.
35 Pool<ScriptEvent>* pEvents; ///< Pool of all available script execution instances. ScriptEvents available to be allocated from the Pool are currently unused / not executiong, whereas the ScriptEvents allocated on the list are currently suspended / have not finished execution yet.
36 AbstractEngineChannel* pEngineChannel;
37 String code; ///< Source code of the instrument script. Used in case the sampler engine is changed, in that case a new ScriptVM object is created for the engine and VMParserContext object for this script needs to be recreated as well. Thus the script is then parsed again by passing the source code to recreate the parser context.
38
39 InstrumentScript(AbstractEngineChannel* pEngineChannel) {
40 parserContext = NULL;
41 bHasValidScript = false;
42 handlerInit = NULL;
43 handlerNote = NULL;
44 handlerRelease = NULL;
45 handlerController = NULL;
46 pEvents = NULL;
47 this->pEngineChannel = pEngineChannel;
48 }
49
50 ~InstrumentScript() {
51 resetAll();
52 }
53
54 void load(const String& text);
55 void unload();
56 void resetAll();
57 };
58
59 /** @brief Real-time instrument script virtual machine.
60 *
61 * Extends the core ScriptVM implementation with MIDI specific built-in
62 * script functions and MIDI specific built-in script variables required
63 * for MIDI processing by instrument script for all sampler engine
64 * implementations (sampler formats) of this sampler.
65 *
66 * Note that this class is currently re-entrant safe, but @b not thread
67 * safe! See also comments of base class ScriptVM regarding this issue.
68 */
69 class InstrumentScriptVM : public ScriptVM {
70 public:
71 InstrumentScriptVM();
72 VMExecStatus_t exec(VMParserContext* parserCtx, ScriptEvent* event);
73 VMFunction* functionByName(const String& name) OVERRIDE;
74 std::map<String,VMIntRelPtr*> builtInIntVariables() OVERRIDE;
75 std::map<String,VMInt8Array*> builtInIntArrayVariables() OVERRIDE;
76 std::map<String,int> builtInConstIntVariables() OVERRIDE;
77 protected:
78 ScriptEvent* m_event; ///< The event currently executed by exec().
79
80 // buil-in script variables
81 VMInt8Array m_CC;
82 VMInt8RelPtr m_CC_NUM;
83 VMIntRelPtr m_EVENT_ID;
84 VMInt8RelPtr m_EVENT_NOTE;
85 VMInt8RelPtr m_EVENT_VELOCITY;
86 VMInt8Array m_KEY_DOWN;
87 //VMIntArray m_POLY_AT; //TODO: ...
88 //int m_POLY_AT_NUM; //TODO: ...
89
90 // buil-in script functions
91 InstrumentScriptVMFunction_play_note m_fnPlayNote;
92 InstrumentScriptVMFunction_set_controller m_fnSetController;
93 InstrumentScriptVMFunction_ignore_event m_fnIgnoreEvent;
94 InstrumentScriptVMFunction_ignore_controller m_fnIgnoreController;
95 InstrumentScriptVMFunction_note_off m_fnNoteOff;
96
97 friend class InstrumentScriptVMFunction_play_note;
98 friend class InstrumentScriptVMFunction_set_controller;
99 friend class InstrumentScriptVMFunction_ignore_event;
100 friend class InstrumentScriptVMFunction_ignore_controller;
101 friend class InstrumentScriptVMFunction_note_off;
102 };
103
104 } // namespace LinuxSampler
105
106 #endif // LS_INSTRUMENT_SCRIPT_VM_H

  ViewVC Help
Powered by ViewVC