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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2948 by schoenebeck, Fri Jul 15 15:29:04 2016 UTC revision 3690 by schoenebeck, Fri Jan 3 10:18:21 2020 UTC
# Line 1  Line 1 
1  /*  /*
2   * Copyright (c) 2014-2016 Christian Schoenebeck   * Copyright (c) 2014-2020 Christian Schoenebeck
3   *   *
4   * http://www.linuxsampler.org   * http://www.linuxsampler.org
5   *   *
# Line 51  enum InstrScriptIDType_T { Line 51  enum InstrScriptIDType_T {
51      /**      /**
52       * Used to mark IDs (in script scope) to actually be a MIDI event ID.       * Used to mark IDs (in script scope) to actually be a MIDI event ID.
53       */       */
54      INSTR_SCRIPT_EVENT_ID_FLAG = INSTR_SCRIPT_ID_TYPE_FLAG(0),      INSTR_SCRIPT_EVENT_ID_FLAG = INSTR_SCRIPT_ID_TYPE_FLAG(0LL),
55    
56      /**      /**
57       * Used to mark IDs (in script scope) to actually be a note ID.       * Used to mark IDs (in script scope) to actually be a note ID.
58       */       */
59      INSTR_SCRIPT_NOTE_ID_FLAG = INSTR_SCRIPT_ID_TYPE_FLAG(1),      INSTR_SCRIPT_NOTE_ID_FLAG = INSTR_SCRIPT_ID_TYPE_FLAG(1LL),
60  };  };
61    
62  #define INSTR_SCRIPT_EVENT_GROUPS 28  #define INSTR_SCRIPT_EVENT_GROUPS 28
# Line 64  enum InstrScriptIDType_T { Line 64  enum InstrScriptIDType_T {
64  #define EVENT_STATUS_INACTIVE 0  #define EVENT_STATUS_INACTIVE 0
65  #define EVENT_STATUS_NOTE_QUEUE 1  #define EVENT_STATUS_NOTE_QUEUE 1
66    
67    enum {
68        EVENT_PAR_NOTE = 1,
69        EVENT_PAR_VELOCITY,
70        EVENT_PAR_VOLUME,
71        EVENT_PAR_TUNE,
72        EVENT_PAR_0 = 1024,
73        EVENT_PAR_1,
74        EVENT_PAR_2,
75        EVENT_PAR_3,
76    };
77    
78    enum {
79        CALLBACK_STATUS_TERMINATED = 0,
80        CALLBACK_STATUS_QUEUE = 1,
81        CALLBACK_STATUS_RUNNING = (1 << 1)
82    };
83    
84  namespace LinuxSampler {  namespace LinuxSampler {
85    
86      class AbstractEngineChannel;      class AbstractEngineChannel;
87      class InstrumentScript;      struct InstrumentScript;
88    
89      /** @brief Convert IDs between script scope and engine internal scope.      /** @brief Convert IDs between script scope and engine internal scope.
90       *       *
# Line 101  namespace LinuxSampler { Line 118  namespace LinuxSampler {
118          /**          /**
119           * Construct a ScriptID object with an ID from script scope.           * Construct a ScriptID object with an ID from script scope.
120           */           */
121          ScriptID(uint id) : m_id(id) {}          ScriptID(vmint id) : m_id(id) {}
122    
123          /**          /**
124           * Returns a ScriptID object constructed with an event ID from engine           * Returns a ScriptID object constructed with an event ID from engine
# Line 163  namespace LinuxSampler { Line 180  namespace LinuxSampler {
180           * Integer cast operator, which returns an ID number of this ScripID           * Integer cast operator, which returns an ID number of this ScripID
181           * object intended for script scope.           * object intended for script scope.
182           */           */
183          inline operator uint() const {          inline operator vmint() const {
184              return m_id;              return m_id;
185          }          }
186    
187      private:      private:
188          uint m_id;          vmint m_id;
189      };      };
190    
191      /** @brief List of Event IDs.      /** @brief List of Event IDs.
# Line 176  namespace LinuxSampler { Line 193  namespace LinuxSampler {
193       * Used for built-in script functions:       * Used for built-in script functions:
194       *     by_marks(), set_event_mark(), delete_event_mark()       *     by_marks(), set_event_mark(), delete_event_mark()
195       */       */
196      class EventGroup : protected ConstCapacityArray<int> {      class EventGroup : protected ConstCapacityArray<vmint> {
197      public:      public:
198          EventGroup() : ConstCapacityArray<int>(CONFIG_MAX_EVENTS_PER_FRAGMENT), m_script(NULL) {}          EventGroup() : ConstCapacityArray<vmint>(CONFIG_MAX_EVENTS_PER_FRAGMENT), m_script(NULL) {}
199          void insert(int eventID);          void insert(vmint eventID);
200          void erase(int eventID);          void erase(vmint eventID);
201          void setScript(InstrumentScript* pScript) { m_script = pScript; }          void setScript(InstrumentScript* pScript) { m_script = pScript; }
202          inline int size() const { return ConstCapacityArray<int>::size(); }          inline size_t size() const { return ConstCapacityArray<vmint>::size(); }
203          inline void clear() { ConstCapacityArray<int>::clear(); }          inline void clear() { ConstCapacityArray<vmint>::clear(); }
204          inline int& operator[](uint index) { return ConstCapacityArray<int>::operator[](index); }          inline vmint& operator[](ssize_t index) { return ConstCapacityArray<vmint>::operator[](index); }
205          inline const int& operator[](uint index) const { return ConstCapacityArray<int>::operator[](index); }          inline const vmint& operator[](ssize_t index) const { return ConstCapacityArray<vmint>::operator[](index); }
206      protected:      protected:
207          InstrumentScript* m_script;          InstrumentScript* m_script;
208      };      };
# Line 209  namespace LinuxSampler { Line 226  namespace LinuxSampler {
226          VMEventHandler*       handlerNote; ///< VM representation of script's MIDI note on callback or NULL if current script did not define such an event handler.          VMEventHandler*       handlerNote; ///< VM representation of script's MIDI note on callback or NULL if current script did not define such an event handler.
227          VMEventHandler*       handlerRelease; ///< VM representation of script's MIDI note off callback or NULL if current script did not define such an event handler.          VMEventHandler*       handlerRelease; ///< VM representation of script's MIDI note off callback or NULL if current script did not define such an event handler.
228          VMEventHandler*       handlerController; ///< VM representation of script's MIDI controller callback or NULL if current script did not define such an event handler.          VMEventHandler*       handlerController; ///< VM representation of script's MIDI controller callback or NULL if current script did not define such an event handler.
229            VMEventHandler*       handlerRpn; ///< VM representation of script's MIDI RPN event callback or NULL if current script did not define such an event handler.
230            VMEventHandler*       handlerNrpn; ///< VM representation of script's MIDI NRPN event callback or NULL if current script did not define such an event handler.
231          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 (@see pKeyEvents).          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 (@see pKeyEvents).
232          RTList<ScriptEvent>*  pKeyEvents[128]; ///< Stores previously finished executed "note on" script events for the respective active note/key as long as the key/note is active. This is however only done if there is a "note" script event handler and a "release" script event handler defined in the script and both handlers use (reference) polyphonic variables. If that is not the case, then this list is not used at all. So the purpose of pKeyEvents is only to implement preserving/passing polyphonic variable data from "on note .. end on" script block to the respective "on release .. end on" script block.          RTList<ScriptEvent>*  pKeyEvents[128]; ///< Stores previously finished executed "note on" script events for the respective active note/key as long as the key/note is active. This is however only done if there is a "note" script event handler and a "release" script event handler defined in the script and both handlers use (reference) polyphonic variables. If that is not the case, then this list is not used at all. So the purpose of pKeyEvents is only to implement preserving/passing polyphonic variable data from "on note .. end on" script block to the respective "on release .. end on" script block.
233          RTAVLTree<ScriptEvent> suspendedEvents; ///< Contains pointers to all suspended events, sorted by time when those script events are to be resumed next.          RTAVLTree<ScriptEvent> suspendedEvents; ///< Contains pointers to all suspended events, sorted by time when those script events are to be resumed next.
# Line 240  namespace LinuxSampler { Line 259  namespace LinuxSampler {
259          InstrumentScriptVM();          InstrumentScriptVM();
260          VMExecStatus_t exec(VMParserContext* parserCtx, ScriptEvent* event);          VMExecStatus_t exec(VMParserContext* parserCtx, ScriptEvent* event);
261          VMFunction* functionByName(const String& name) OVERRIDE;          VMFunction* functionByName(const String& name) OVERRIDE;
262          std::map<String,VMIntRelPtr*> builtInIntVariables() OVERRIDE;          std::map<String,VMIntPtr*> builtInIntVariables() OVERRIDE;
263          std::map<String,VMInt8Array*> builtInIntArrayVariables() OVERRIDE;          std::map<String,VMInt8Array*> builtInIntArrayVariables() OVERRIDE;
264          std::map<String,int> builtInConstIntVariables() OVERRIDE;          std::map<String,vmint> builtInConstIntVariables() OVERRIDE;
265          std::map<String,VMDynVar*> builtInDynamicVariables() OVERRIDE;          std::map<String,VMDynVar*> builtInDynamicVariables() OVERRIDE;
266      protected:      protected:
267          ScriptEvent* m_event; ///< The event currently executed by exec().          ScriptEvent* m_event; ///< The event currently executed by exec().
268    
269          // buil-in script variables          // built-in script variables
270          VMInt8Array m_CC;          VMInt8Array m_CC;
271          VMInt8RelPtr m_CC_NUM;          VMInt8RelPtr m_CC_NUM;
272          VMIntRelPtr  m_EVENT_ID;          VMIntRelPtr  m_EVENT_ID;
273          VMInt8RelPtr m_EVENT_NOTE;          VMInt8RelPtr m_EVENT_NOTE;
274          VMInt8RelPtr m_EVENT_VELOCITY;          VMInt8RelPtr m_EVENT_VELOCITY;
275          VMInt8Array  m_KEY_DOWN;          VMInt8Array  m_KEY_DOWN;
276            VMInt16RelPtr m_RPN_ADDRESS; // used for both RPN and NRPN events
277            VMInt16RelPtr m_RPN_VALUE;   // used for both RPN and NRPN events
278          //VMIntArray m_POLY_AT; //TODO: ...          //VMIntArray m_POLY_AT; //TODO: ...
279          //int m_POLY_AT_NUM; //TODO: ...          //int m_POLY_AT_NUM; //TODO: ...
280          VMIntRelPtr  m_NI_CALLBACK_TYPE;          VMInt32RelPtr m_NI_CALLBACK_TYPE;
281          VMIntRelPtr  m_NKSP_IGNORE_WAIT;          VMInt8RelPtr m_NKSP_IGNORE_WAIT;
282            VMIntRelPtr  m_NKSP_CALLBACK_PARENT_ID;
283    
284          // buil-in script functions          // built-in script functions
285          InstrumentScriptVMFunction_play_note m_fnPlayNote;          InstrumentScriptVMFunction_play_note m_fnPlayNote;
286          InstrumentScriptVMFunction_set_controller m_fnSetController;          InstrumentScriptVMFunction_set_controller m_fnSetController;
287          InstrumentScriptVMFunction_ignore_event m_fnIgnoreEvent;          InstrumentScriptVMFunction_ignore_event m_fnIgnoreEvent;
# Line 269  namespace LinuxSampler { Line 291  namespace LinuxSampler {
291          InstrumentScriptVMFunction_delete_event_mark m_fnDeleteEventMark;          InstrumentScriptVMFunction_delete_event_mark m_fnDeleteEventMark;
292          InstrumentScriptVMFunction_by_marks m_fnByMarks;          InstrumentScriptVMFunction_by_marks m_fnByMarks;
293          InstrumentScriptVMFunction_change_vol m_fnChangeVol;          InstrumentScriptVMFunction_change_vol m_fnChangeVol;
294            InstrumentScriptVMFunction_change_vol_time m_fnChangeVolTime;
295          InstrumentScriptVMFunction_change_tune m_fnChangeTune;          InstrumentScriptVMFunction_change_tune m_fnChangeTune;
296            InstrumentScriptVMFunction_change_tune_time m_fnChangeTuneTime;
297          InstrumentScriptVMFunction_change_pan m_fnChangePan;          InstrumentScriptVMFunction_change_pan m_fnChangePan;
298            InstrumentScriptVMFunction_change_pan_time m_fnChangePanTime;
299            InstrumentScriptVMFunction_change_pan_curve m_fnChangePanCurve;
300          InstrumentScriptVMFunction_change_cutoff m_fnChangeCutoff;          InstrumentScriptVMFunction_change_cutoff m_fnChangeCutoff;
301          InstrumentScriptVMFunction_change_reso m_fnChangeReso;          InstrumentScriptVMFunction_change_reso m_fnChangeReso;
302            InstrumentScriptVMFunction_change_attack m_fnChangeAttack;
303            InstrumentScriptVMFunction_change_decay m_fnChangeDecay;
304            InstrumentScriptVMFunction_change_sustain m_fnChangeSustain;
305            InstrumentScriptVMFunction_change_release m_fnChangeRelease;
306            InstrumentScriptVMFunction_change_cutoff_attack m_fnChangeCutoffAttack;
307            InstrumentScriptVMFunction_change_cutoff_decay m_fnChangeCutoffDecay;
308            InstrumentScriptVMFunction_change_cutoff_sustain m_fnChangeCutoffSustain;
309            InstrumentScriptVMFunction_change_cutoff_release m_fnChangeCutoffRelease;
310            InstrumentScriptVMFunction_change_amp_lfo_depth m_fnChangeAmpLFODepth;
311            InstrumentScriptVMFunction_change_amp_lfo_freq m_fnChangeAmpLFOFreq;
312            InstrumentScriptVMFunction_change_cutoff_lfo_depth m_fnChangeCutoffLFODepth;
313            InstrumentScriptVMFunction_change_cutoff_lfo_freq m_fnChangeCutoffLFOFreq;
314            InstrumentScriptVMFunction_change_pitch_lfo_depth m_fnChangePitchLFODepth;
315            InstrumentScriptVMFunction_change_pitch_lfo_freq m_fnChangePitchLFOFreq;
316            InstrumentScriptVMFunction_change_note m_fnChangeNote;
317            InstrumentScriptVMFunction_change_velo m_fnChangeVelo;
318            InstrumentScriptVMFunction_fork m_fnFork;
319          InstrumentScriptVMFunction_event_status m_fnEventStatus;          InstrumentScriptVMFunction_event_status m_fnEventStatus;
320          InstrumentScriptVMFunction_wait m_fnWait2;          InstrumentScriptVMFunction_wait m_fnWait2;
321          InstrumentScriptVMFunction_stop_wait m_fnStopWait;          InstrumentScriptVMFunction_stop_wait m_fnStopWait;
322            InstrumentScriptVMFunction_abort m_fnAbort;
323            InstrumentScriptVMFunction_fade_in m_fnFadeIn;
324            InstrumentScriptVMFunction_fade_out m_fnFadeOut;
325            InstrumentScriptVMFunction_change_vol_curve m_fnChangeVolCurve;
326            InstrumentScriptVMFunction_change_tune_curve m_fnChangeTuneCurve;
327            InstrumentScriptVMFunction_get_event_par m_fnGetEventPar;
328            InstrumentScriptVMFunction_set_event_par m_fnSetEventPar;
329            InstrumentScriptVMFunction_change_play_pos m_fnChangePlayPos;
330            InstrumentScriptVMFunction_callback_status m_fnCallbackStatus;
331          InstrumentScriptVMDynVar_ENGINE_UPTIME m_varEngineUptime;          InstrumentScriptVMDynVar_ENGINE_UPTIME m_varEngineUptime;
332          InstrumentScriptVMDynVar_NI_CALLBACK_ID m_varCallbackID;          InstrumentScriptVMDynVar_NI_CALLBACK_ID m_varCallbackID;
333            InstrumentScriptVMDynVar_ALL_EVENTS m_varAllEvents;
334            InstrumentScriptVMDynVar_NKSP_CALLBACK_CHILD_ID m_varCallbackChildID;
335    
336          friend class InstrumentScriptVMFunction_play_note;          friend class InstrumentScriptVMFunction_play_note;
337          friend class InstrumentScriptVMFunction_set_controller;          friend class InstrumentScriptVMFunction_set_controller;
# Line 288  namespace LinuxSampler { Line 342  namespace LinuxSampler {
342          friend class InstrumentScriptVMFunction_delete_event_mark;          friend class InstrumentScriptVMFunction_delete_event_mark;
343          friend class InstrumentScriptVMFunction_by_marks;          friend class InstrumentScriptVMFunction_by_marks;
344          friend class InstrumentScriptVMFunction_change_vol;          friend class InstrumentScriptVMFunction_change_vol;
345            friend class InstrumentScriptVMFunction_change_vol_time;
346          friend class InstrumentScriptVMFunction_change_tune;          friend class InstrumentScriptVMFunction_change_tune;
347            friend class InstrumentScriptVMFunction_change_tune_time;
348          friend class InstrumentScriptVMFunction_change_pan;          friend class InstrumentScriptVMFunction_change_pan;
349            friend class InstrumentScriptVMFunction_change_pan_time;
350            friend class InstrumentScriptVMFunction_change_pan_curve;
351          friend class InstrumentScriptVMFunction_change_cutoff;          friend class InstrumentScriptVMFunction_change_cutoff;
352          friend class InstrumentScriptVMFunction_change_reso;          friend class InstrumentScriptVMFunction_change_reso;
353            friend class InstrumentScriptVMFunction_change_attack;
354            friend class InstrumentScriptVMFunction_change_decay;
355            friend class InstrumentScriptVMFunction_change_release;
356            friend class InstrumentScriptVMFunction_change_sustain;
357            friend class InstrumentScriptVMFunction_change_cutoff_attack;
358            friend class InstrumentScriptVMFunction_change_cutoff_decay;
359            friend class InstrumentScriptVMFunction_change_cutoff_release;
360            friend class InstrumentScriptVMFunction_change_cutoff_sustain;
361            friend class VMChangeSynthParamFunction;
362            friend class InstrumentScriptVMFunction_change_amp_lfo_depth;
363            friend class InstrumentScriptVMFunction_change_amp_lfo_freq;
364            friend class InstrumentScriptVMFunction_change_cutoff_lfo_depth;
365            friend class InstrumentScriptVMFunction_change_cutoff_lfo_freq;
366            friend class InstrumentScriptVMFunction_change_pitch_lfo_depth;
367            friend class InstrumentScriptVMFunction_change_pitch_lfo_freq;
368            friend class VMChangeFadeCurveFunction;
369            friend class InstrumentScriptVMFunction_fade_in;
370            friend class InstrumentScriptVMFunction_fade_out;
371            friend class InstrumentScriptVMFunction_get_event_par;
372            friend class InstrumentScriptVMFunction_set_event_par;
373            friend class InstrumentScriptVMFunction_change_note;
374            friend class InstrumentScriptVMFunction_change_velo;
375            friend class InstrumentScriptVMFunction_change_play_pos;
376          friend class InstrumentScriptVMFunction_event_status;          friend class InstrumentScriptVMFunction_event_status;
377          friend class InstrumentScriptVMFunction_wait;          friend class InstrumentScriptVMFunction_wait;
378          friend class InstrumentScriptVMFunction_stop_wait;          friend class InstrumentScriptVMFunction_stop_wait;
379            friend class InstrumentScriptVMFunction_abort;
380            friend class InstrumentScriptVMFunction_fork;
381            friend class InstrumentScriptVMFunction_callback_status;
382          friend class InstrumentScriptVMDynVar_ENGINE_UPTIME;          friend class InstrumentScriptVMDynVar_ENGINE_UPTIME;
383          friend class InstrumentScriptVMDynVar_NI_CALLBACK_ID;          friend class InstrumentScriptVMDynVar_NI_CALLBACK_ID;
384            friend class InstrumentScriptVMDynVar_ALL_EVENTS;
385            friend class InstrumentScriptVMDynVar_NKSP_CALLBACK_CHILD_ID;
386      };      };
387    
388  } // namespace LinuxSampler  } // namespace LinuxSampler

Legend:
Removed from v.2948  
changed lines
  Added in v.3690

  ViewVC Help
Powered by ViewVC