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

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

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

revision 2879 by schoenebeck, Tue Apr 19 14:07:53 2016 UTC revision 3283 by schoenebeck, Wed Jun 21 20:59:06 2017 UTC
# Line 3  Line 3 
3   *   LinuxSampler - modular, streaming capable sampler                     *   *   LinuxSampler - modular, streaming capable sampler                     *
4   *                                                                         *   *                                                                         *
5   *   Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck   *   *   Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck   *
6   *   Copyright (C) 2005 - 2016 Christian Schoenebeck                       *   *   Copyright (C) 2005 - 2017 Christian Schoenebeck                       *
7   *                                                                         *   *                                                                         *
8   *   This program is free software; you can redistribute it and/or modify  *   *   This program is free software; you can redistribute it and/or modify  *
9   *   it under the terms of the GNU General Public License as published by  *   *   it under the terms of the GNU General Public License as published by  *
# Line 29  Line 29 
29  #include "../../common/RTAVLTree.h"  #include "../../common/RTAVLTree.h"
30  #include "../../common/Pool.h"  #include "../../common/Pool.h"
31  #include "../EngineChannel.h"  #include "../EngineChannel.h"
32    #include "../../scriptvm/common.h"
33    
34  namespace LinuxSampler {  namespace LinuxSampler {
35    
# Line 57  namespace LinuxSampler { Line 58  namespace LinuxSampler {
58          public:          public:
59              EventGenerator(uint SampleRate);              EventGenerator(uint SampleRate);
60              void UpdateFragmentTime(uint SamplesToProcess);              void UpdateFragmentTime(uint SamplesToProcess);
61                void SetSampleRate(uint SampleRate);
62              Event CreateEvent();              Event CreateEvent();
63              Event CreateEvent(int32_t FragmentPos);              Event CreateEvent(int32_t FragmentPos);
64    
# Line 67  namespace LinuxSampler { Line 69  namespace LinuxSampler {
69              RTList<ScriptEvent>::Iterator popNextScheduledScriptEvent(RTAVLTree<ScriptEvent>& queue, Pool<ScriptEvent>& pool, sched_time_t end);              RTList<ScriptEvent>::Iterator popNextScheduledScriptEvent(RTAVLTree<ScriptEvent>& queue, Pool<ScriptEvent>& pool, sched_time_t end);
70    
71              /**              /**
72                 * Returns the scheduler time for the first sample point of the
73                 * current audio fragment cycle.
74                 */
75                sched_time_t schedTimeAtCurrentFragmentStart() const {
76                    return uiTotalSamplesProcessed;
77                }
78    
79                /**
80               * Returns the scheduler time for the first sample point of the next               * Returns the scheduler time for the first sample point of the next
81               * audio fragment cycle.               * audio fragment cycle.
82               */               */
# Line 124  namespace LinuxSampler { Line 134  namespace LinuxSampler {
134      typedef pool_element_id_t note_id_t;      typedef pool_element_id_t note_id_t;
135    
136      /**      /**
137         * Unique numeric ID of a script callback ID instance which can be used to
138         * retrieve access to the actual @c ScriptEvent object. Once the script
139         * callback instance associated with a certain ID stopped its execution
140         * (that is completely stopped, not just suspended) then this numeric ID
141         * becomes invalid and Pool< ScriptEvent >::fromID() will detect this
142         * circumstance and will return an invalid Iterator, and thus will prevent
143         * you from misusing a script callback instance which no longer "exists".
144         */
145        typedef pool_element_id_t script_callback_id_t;
146    
147        /**
148       * Events are usually caused by a MIDI source or an internal modulation       * Events are usually caused by a MIDI source or an internal modulation
149       * controller like LFO or EG. An event should only be created by an       * controller like LFO or EG. An event should only be created by an
150       * EventGenerator!       * EventGenerator!
# Line 134  namespace LinuxSampler { Line 155  namespace LinuxSampler {
155          public:          public:
156              Event(){}              Event(){}
157              enum type_t {              enum type_t {
158                  type_note_on,                  type_note_on, ///< (real) MIDI note-on event
159                  type_note_off,                  type_note_off, ///< (real) MIDI note-off event
160                  type_pitchbend,                  type_pitchbend, ///< MIDI pitch bend wheel change event
161                  type_control_change,                  type_control_change, ///< MIDI CC event
162                  type_sysex,           ///< MIDI system exclusive message                  type_sysex,           ///< MIDI system exclusive message
163                  type_cancel_release,  ///< transformed either from a note-on or sustain-pedal-down event                  type_cancel_release_key, ///< transformed either from a (real) MIDI note-on or sustain-pedal-down event
164                  type_release,         ///< transformed either from a note-off or sustain-pedal-up event                  type_release_key,     ///< transformed either from a (real) MIDI note-off or sustain-pedal-up event
165                    type_release_note,    ///< transformed from a type_stop_note event
166                  type_channel_pressure, ///< a.k.a. aftertouch                  type_channel_pressure, ///< a.k.a. aftertouch
167                  type_note_pressure, ///< polyphonic key pressure (aftertouch)                  type_note_pressure, ///< polyphonic key pressure (aftertouch)
168                    type_play_note, ///< caused by a call to built-in instrument script function play_note()
169                    type_stop_note, ///< caused by a call to built-in instrument script function note_off()
170                    type_kill_note, ///< caused by a call to built-in instrument script function fade_out()
171                    type_note_synth_param, ///< change a note's synthesis parameters (upon real-time instrument script function calls, i.e. change_vol(), change_tune(), change_pan(), etc.)
172              } Type;              } Type;
173                enum synth_param_t {
174                    synth_param_volume,
175                    synth_param_volume_time,
176                    synth_param_volume_curve,
177                    synth_param_pitch,
178                    synth_param_pitch_time,
179                    synth_param_pitch_curve,
180                    synth_param_pan,
181                    synth_param_cutoff,
182                    synth_param_resonance,
183                    synth_param_attack,
184                    synth_param_decay,
185                    synth_param_release,
186                    synth_param_amp_lfo_depth,
187                    synth_param_amp_lfo_freq,
188                    synth_param_pitch_lfo_depth,
189                    synth_param_pitch_lfo_freq,
190                };
191              union {              union {
192                  /// Note-on and note-off event specifics                  /// Note-on and note-off event specifics
193                  struct _Note {                  struct _Note {
# Line 152  namespace LinuxSampler { Line 196  namespace LinuxSampler {
196                      uint8_t Velocity;    ///< Trigger or release velocity of note-on / note-off event.                      uint8_t Velocity;    ///< Trigger or release velocity of note-on / note-off event.
197                      int8_t  Layer;       ///< Layer index (usually only used if a note-on event has to be postponed, e.g. due to shortage of free voices).                      int8_t  Layer;       ///< Layer index (usually only used if a note-on event has to be postponed, e.g. due to shortage of free voices).
198                      int8_t  ReleaseTrigger; ///< If new voice should be a release triggered voice (actually boolean field and usually only used if a note-on event has to be postponed, e.g. due to shortage of free voices).                      int8_t  ReleaseTrigger; ///< If new voice should be a release triggered voice (actually boolean field and usually only used if a note-on event has to be postponed, e.g. due to shortage of free voices).
199                      note_id_t ID;        ///< Unique numeric ID of the @c Note object associated with this note (on) event.                      note_id_t ID;        ///< Unique numeric ID of the @c Note object associated with this note event.
200                      note_id_t ParentNoteID; ///< If not zero: Unique numeric ID of the parent @c Note object that shall become parent of resulting new Note object of this Event. So this is used to associate a new note with a previous note, i.e. to release the new note once the parent note was released.                      note_id_t ParentNoteID; ///< If not zero: Unique numeric ID of the parent @c Note object that shall become parent of resulting new Note object of this Event. So this is used to associate a new note with a previous note, i.e. to release the new note once the parent note was released.
201                      void*   pRegion;     ///< Engine specific pointer to instrument region                      void*   pRegion;     ///< Engine specific pointer to instrument region
202                  } Note;                  } Note;
# Line 183  namespace LinuxSampler { Line 227  namespace LinuxSampler {
227                      uint8_t Key;     ///< MIDI note number where key pressure (polyphonic aftertouch) changed.                      uint8_t Key;     ///< MIDI note number where key pressure (polyphonic aftertouch) changed.
228                      uint8_t Value;   ///< New pressure value for note.                      uint8_t Value;   ///< New pressure value for note.
229                  } NotePressure;                  } NotePressure;
230                    ///< Note synthesis parameter change event's specifics (used for real-time instrument script built-in functions which may alter synthesis parameters on note level).
231                    struct _NoteSynthParam {
232                        note_id_t     NoteID;   ///< ID of Note whose voices shall be modified.
233                        synth_param_t Type;     ///< Synthesis parameter which is to be changed.
234                        float         Delta;    ///< The value change that should be applied against the note's current synthesis parameter value.
235                        bool          Relative; ///< Whether @c Delta should be applied relatively against the note's current synthesis parameter value (false means the paramter's current value is simply replaced by Delta).
236                        float         AbsValue; ///< New current absolute value of synthesis parameter (that is after @c Delta being applied).
237                    } NoteSynthParam;
238              } Param;              } Param;
239              EngineChannel* pEngineChannel; ///< Pointer to the EngineChannel where this event occured on, NULL means Engine global event (e.g. SysEx message).              EngineChannel* pEngineChannel; ///< Pointer to the EngineChannel where this event occured on, NULL means Engine global event (e.g. SysEx message).
240              MidiInputPort* pMidiInputPort; ///< Pointer to the MIDI input port on which this event occured (NOTE: currently only for global events, that is SysEx messages)              MidiInputPort* pMidiInputPort; ///< Pointer to the MIDI input port on which this event occured (NOTE: currently only for global events, that is SysEx messages)
# Line 190  namespace LinuxSampler { Line 242  namespace LinuxSampler {
242              inline void Init() {              inline void Init() {
243                  Param.Note.ID = 0;                  Param.Note.ID = 0;
244                  Param.Note.ParentNoteID = 0;                  Param.Note.ParentNoteID = 0;
245                    Param.NoteSynthParam.NoteID = 0;
246              }              }
247              inline int32_t FragmentPos() {              inline int32_t FragmentPos() {
248                  if (iFragmentPos >= 0) return iFragmentPos;                  if (iFragmentPos >= 0) return iFragmentPos;
# Line 204  namespace LinuxSampler { Line 257  namespace LinuxSampler {
257                  TimeStamp = other.TimeStamp;                  TimeStamp = other.TimeStamp;
258                  iFragmentPos = other.iFragmentPos;                  iFragmentPos = other.iFragmentPos;
259              }              }
260                inline sched_time_t SchedTime() {
261                    return pEventGenerator->schedTimeAtCurrentFragmentStart() + FragmentPos();
262                }
263          protected:          protected:
264              typedef EventGenerator::time_stamp_t time_stamp_t;              typedef EventGenerator::time_stamp_t time_stamp_t;
265              Event(EventGenerator* pGenerator, EventGenerator::time_stamp_t Time);              Event(EventGenerator* pGenerator, EventGenerator::time_stamp_t Time);
# Line 222  namespace LinuxSampler { Line 278  namespace LinuxSampler {
278       */       */
279      class SchedulerNode : public RTAVLNode {      class SchedulerNode : public RTAVLNode {
280      public:      public:
281            using RTAVLNode::reset; // make reset() method public
282    
283          sched_time_t scheduleTime; ///< Time ahead in future (in sample points) when this object shall be processed. This value is compared with EventGenerator's uiTotalSamplesProcessed member variable.          sched_time_t scheduleTime; ///< Time ahead in future (in sample points) when this object shall be processed. This value is compared with EventGenerator's uiTotalSamplesProcessed member variable.
284    
285          /// Required operator implementation for RTAVLTree class.          /// Required operator implementation for RTAVLTree class.
# Line 233  namespace LinuxSampler { Line 291  namespace LinuxSampler {
291          inline bool operator<(const SchedulerNode& other) const {          inline bool operator<(const SchedulerNode& other) const {
292              return this->scheduleTime < other.scheduleTime;              return this->scheduleTime < other.scheduleTime;
293          }          }
294    
295            /// This is actually just for code readability.
296            inline RTAVLTreeBase* currentSchedulerQueue() const { return rtavlTree(); }
297      };      };
298    
299      /**      /**
# Line 269  namespace LinuxSampler { Line 330  namespace LinuxSampler {
330          VMExecContext* execCtx; ///< Script's current execution state (polyphonic variables and execution stack).          VMExecContext* execCtx; ///< Script's current execution state (polyphonic variables and execution stack).
331          int currentHandler; ///< Current index in 'handlers' list above.          int currentHandler; ///< Current index in 'handlers' list above.
332          int executionSlices; ///< Amount of times this script event has been executed by the ScriptVM runner class.          int executionSlices; ///< Amount of times this script event has been executed by the ScriptVM runner class.
333            bool ignoreAllWaitCalls; ///< If true: calling any built-in wait*() script function should be ignored (this variable may be set with the 2nd argument of built-in script function stop_wait()).
334            VMEventHandlerType_t handlerType; ///< Native representation of built-in script variable $NI_CALLBACK_TYPE, reflecting the script event type of this script event.
335      };      };
336    
337      /**      /**
# Line 290  namespace LinuxSampler { Line 353  namespace LinuxSampler {
353       */       */
354      template<typename T>      template<typename T>
355      void EventGenerator::scheduleAheadMicroSec(RTAVLTree<T>& queue, T& node, int32_t fragmentPosBase, uint64_t microseconds) {      void EventGenerator::scheduleAheadMicroSec(RTAVLTree<T>& queue, T& node, int32_t fragmentPosBase, uint64_t microseconds) {
356          node.scheduleTime = uiTotalSamplesProcessed + fragmentPosBase + float(uiSampleRate) * (float(microseconds) / 1000000.f);          // round up (+1) if microseconds is not zero (i.e. because 44.1 kHz and
357            // 1 us would yield in < 1 and thus would be offset == 0)
358            const sched_time_t offset =
359                (microseconds != 0LL) ?
360                    1.f + (float(uiSampleRate) * (float(microseconds) / 1000000.f))
361                    : 0.f;
362            node.scheduleTime = uiTotalSamplesProcessed + fragmentPosBase + offset;
363          queue.insert(node);          queue.insert(node);
364      }      }
365    

Legend:
Removed from v.2879  
changed lines
  Added in v.3283

  ViewVC Help
Powered by ViewVC