/[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 2630 - (show annotations) (download) (as text)
Fri Jun 13 15:01:06 2014 UTC (9 years, 9 months ago) by schoenebeck
File MIME type: text/x-c++hdr
File size: 6276 byte(s)
* Implemented built-in instrument script function "set_event_mark()".
* Implemented built-in instrument script function "delete_event_mark()".
* Implemented built-in instrument script function "by_marks()".
* Added built-in instrument script int const variables $MARK_1 to $MARK_28.
* Built-in instrument script functions "ignore_event()", "note_off()" and
  "gig_set_dim_zone()" now also accept an array of event IDs as argument
  (i.e. return value of new script function "by_marks()").
* Bumped version (1.0.0.svn53).

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 "../../common/ConstCapacityArray.h"
15 #include "../../scriptvm/ScriptVM.h"
16 #include "Event.h"
17 #include "../../common/Pool.h"
18 #include "InstrumentScriptVMFunctions.h"
19
20 #define INSTR_SCRIPT_EVENT_GROUPS 28
21
22 namespace LinuxSampler {
23
24 class AbstractEngineChannel;
25 class InstrumentScript;
26
27 /** @brief List of Event IDs.
28 *
29 * Used for built-in script functions:
30 * by_marks(), set_event_mark(), delete_event_mark()
31 */
32 class EventGroup : protected ConstCapacityArray<int> {
33 public:
34 EventGroup() : ConstCapacityArray<int>(CONFIG_MAX_EVENTS_PER_FRAGMENT), m_script(NULL) {}
35 void insert(int eventID);
36 void erase(int eventID);
37 void setScript(InstrumentScript* pScript) { m_script = pScript; }
38 inline int size() const { return ConstCapacityArray<int>::size(); }
39 inline int& operator[](uint index) { return ConstCapacityArray<int>::operator[](index); }
40 inline const int& operator[](uint index) const { return ConstCapacityArray<int>::operator[](index); }
41 protected:
42 InstrumentScript* m_script;
43 StmtFlags_t flags;
44 };
45
46 /** @brief Real-time instrument script VM representation.
47 *
48 * Holds the VM representation of all event handlers of the currently loaded
49 * script, ready to be executed by the sampler engine.
50 */
51 struct InstrumentScript {
52 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!
53 bool bHasValidScript; ///< True in case there is a valid script currently loaded, false if script processing shall be skipped.
54 VMEventHandler* handlerInit; ///< VM representation of script's initilization callback or NULL if current script did not define such an init handler.
55 VMEventHandler* handlerNote; ///< VM representation of script's MIDI note on callback or NULL if current script did not define such an event handler.
56 VMEventHandler* handlerRelease; ///< VM representation of script's MIDI note off callback or NULL if current script did not define such an event handler.
57 VMEventHandler* handlerController; ///< VM representation of script's MIDI controller callback or NULL if current script did not define such an event handler.
58 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.
59 AbstractEngineChannel* pEngineChannel;
60 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.
61 EventGroup eventGroups[INSTR_SCRIPT_EVENT_GROUPS]; ///< Used for built-in script functions: by_event_marks(), set_event_mark(), delete_event_mark().
62
63 InstrumentScript(AbstractEngineChannel* pEngineChannel);
64
65 ~InstrumentScript() {
66 resetAll();
67 }
68
69 void load(const String& text);
70 void unload();
71 void resetAll();
72 };
73
74 /** @brief Real-time instrument script virtual machine.
75 *
76 * Extends the core ScriptVM implementation with MIDI specific built-in
77 * script functions and MIDI specific built-in script variables required
78 * for MIDI processing by instrument script for all sampler engine
79 * implementations (sampler formats) of this sampler.
80 *
81 * Note that this class is currently re-entrant safe, but @b not thread
82 * safe! See also comments of base class ScriptVM regarding this issue.
83 */
84 class InstrumentScriptVM : public ScriptVM {
85 public:
86 InstrumentScriptVM();
87 VMExecStatus_t exec(VMParserContext* parserCtx, ScriptEvent* event);
88 VMFunction* functionByName(const String& name) OVERRIDE;
89 std::map<String,VMIntRelPtr*> builtInIntVariables() OVERRIDE;
90 std::map<String,VMInt8Array*> builtInIntArrayVariables() OVERRIDE;
91 std::map<String,int> builtInConstIntVariables() OVERRIDE;
92 protected:
93 ScriptEvent* m_event; ///< The event currently executed by exec().
94
95 // buil-in script variables
96 VMInt8Array m_CC;
97 VMInt8RelPtr m_CC_NUM;
98 VMIntRelPtr m_EVENT_ID;
99 VMInt8RelPtr m_EVENT_NOTE;
100 VMInt8RelPtr m_EVENT_VELOCITY;
101 VMInt8Array m_KEY_DOWN;
102 //VMIntArray m_POLY_AT; //TODO: ...
103 //int m_POLY_AT_NUM; //TODO: ...
104
105 // buil-in script functions
106 InstrumentScriptVMFunction_play_note m_fnPlayNote;
107 InstrumentScriptVMFunction_set_controller m_fnSetController;
108 InstrumentScriptVMFunction_ignore_event m_fnIgnoreEvent;
109 InstrumentScriptVMFunction_ignore_controller m_fnIgnoreController;
110 InstrumentScriptVMFunction_note_off m_fnNoteOff;
111 InstrumentScriptVMFunction_set_event_mark m_fnSetEventMark;
112 InstrumentScriptVMFunction_delete_event_mark m_fnDeleteEventMark;
113 InstrumentScriptVMFunction_by_marks m_fnByMarks;
114
115 friend class InstrumentScriptVMFunction_play_note;
116 friend class InstrumentScriptVMFunction_set_controller;
117 friend class InstrumentScriptVMFunction_ignore_event;
118 friend class InstrumentScriptVMFunction_ignore_controller;
119 friend class InstrumentScriptVMFunction_note_off;
120 friend class InstrumentScriptVMFunction_set_event_mark;
121 friend class InstrumentScriptVMFunction_delete_event_mark;
122 friend class InstrumentScriptVMFunction_by_marks;
123 };
124
125 } // namespace LinuxSampler
126
127 #endif // LS_INSTRUMENT_SCRIPT_VM_H

  ViewVC Help
Powered by ViewVC