/[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 246 by schoenebeck, Sun Sep 19 14:12:55 2004 UTC revision 2600 by schoenebeck, Sat Jun 7 00:16:03 2014 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 - 2014 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 24  Line 25 
25  #define __LS_EVENT_H__  #define __LS_EVENT_H__
26    
27  #include "../../common/global.h"  #include "../../common/global.h"
28    #include "../../common/RTMath.h"
29    #include "../EngineChannel.h"
30    
31  namespace LinuxSampler {  namespace LinuxSampler {
32    
# Line 39  namespace LinuxSampler { Line 42  namespace LinuxSampler {
42              EventGenerator(uint SampleRate);              EventGenerator(uint SampleRate);
43              void UpdateFragmentTime(uint SamplesToProcess);              void UpdateFragmentTime(uint SamplesToProcess);
44              Event CreateEvent();              Event CreateEvent();
45                Event CreateEvent(int32_t FragmentPos);
46          protected:          protected:
47              typedef uint32_t time_stamp_t; ///< We read the processor's cycle count register as a reference for the real time. These are of course only abstract values with arbitrary time entity, but that's not a problem as we calculate relatively.              typedef RTMath::time_stamp_t time_stamp_t;
48              inline uint ToFragmentPos(time_stamp_t TimeStamp) {              inline int32_t ToFragmentPos(time_stamp_t TimeStamp) {
49                  return uint ((TimeStamp - FragmentTime.begin) * FragmentTime.sample_ratio);                  return int32_t (int32_t(TimeStamp - FragmentTime.begin) * FragmentTime.sample_ratio);
50              }              }
51              friend class Event;              friend class Event;
52          private:          private:
# Line 53  namespace LinuxSampler { Line 57  namespace LinuxSampler {
57                  time_stamp_t end;          ///< Real time stamp of the end of this audio fragment cycle.                  time_stamp_t end;          ///< Real time stamp of the end of this audio fragment cycle.
58                  float        sample_ratio; ///< (Samples per cycle) / (Real time duration of cycle)                  float        sample_ratio; ///< (Samples per cycle) / (Real time duration of cycle)
59              } FragmentTime;              } FragmentTime;
             time_stamp_t CreateTimeStamp();  
60      };      };
61    
62      /**      /**
63       * Events are usually caused by a MIDI source or an internal modulation       * Events are usually caused by a MIDI source or an internal modulation
64       * controller like LFO or EG. An event can only be created by an       * controller like LFO or EG. An event should only be created by an
65       * EventGenerator.       * EventGenerator!
66       *       *
67       * @see EventGenerator       * @see EventGenerator, ScriptEvent
68       */       */
69      class Event {      class Event {
70          public:          public:
# Line 73  namespace LinuxSampler { Line 76  namespace LinuxSampler {
76                  type_control_change,                  type_control_change,
77                  type_sysex,           ///< MIDI system exclusive message                  type_sysex,           ///< MIDI system exclusive message
78                  type_cancel_release,  ///< transformed either from a note-on or sustain-pedal-down event                  type_cancel_release,  ///< transformed either from a note-on or sustain-pedal-down event
79                  type_release          ///< transformed either from a note-off or sustain-pedal-up event                  type_release,         ///< transformed either from a note-off or sustain-pedal-up event
80                    type_channel_pressure, ///< a.k.a. aftertouch
81                    type_note_pressure, ///< polyphonic key pressure (aftertouch)
82              } Type;              } Type;
             enum destination_t {  
                 destination_vca,   ///< Volume level  
                 destination_vco,   ///< Pitch depth  
                 destination_vcfc,  ///< Filter curoff frequency  
                 destination_vcfr,  ///< Filter resonance  
                 destination_count  ///< Total number of modulation destinations (this has to stay the last element in the enum)  
             };  
83              union {              union {
84                  /// Note-on and note-off event specifics                  /// Note-on and note-off event specifics
85                  struct _Note {                  struct _Note {
86                        uint8_t Channel;     ///< MIDI channel (0..15)
87                      uint8_t Key;         ///< MIDI key number of note-on / note-off event.                      uint8_t Key;         ///< MIDI key number of note-on / note-off event.
88                      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.
89                        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).
90                        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).
91                        void*   pRegion;     ///< Engine specific pointer to instrument region
92                  } Note;                  } Note;
93                  /// Control change event specifics                  /// Control change event specifics
94                  struct _CC {                  struct _CC {
95                        uint8_t Channel;     ///< MIDI channel (0..15)
96                      uint8_t Controller;  ///< MIDI controller number of control change event.                      uint8_t Controller;  ///< MIDI controller number of control change event.
97                      uint8_t Value;       ///< Controller Value of control change event.                      uint8_t Value;       ///< Controller Value of control change event.
98                  } CC;                  } CC;
99                  /// Pitchbend event specifics                  /// Pitchbend event specifics
100                  struct _Pitch {                  struct _Pitch {
101                        uint8_t Channel;     ///< MIDI channel (0..15)
102                      int16_t Pitch;       ///< Pitch value of pitchbend event.                      int16_t Pitch;       ///< Pitch value of pitchbend event.
103                  } Pitch;                  } Pitch;
104                  /// MIDI system exclusive event specifics                  /// MIDI system exclusive event specifics
105                  struct _Sysex {                  struct _Sysex {
106                      uint Size;           ///< Data length (in bytes) of MIDI system exclusive message.                      uint Size;           ///< Data length (in bytes) of MIDI system exclusive message.
107                  } Sysex;                  } Sysex;
108                    /// Channel Pressure (aftertouch) event specifics
109                    struct _ChannelPressure {
110                        uint8_t Channel; ///< MIDI channel (0..15)
111                        uint8_t Value;   ///< New aftertouch / pressure value for keys on that channel.
112                    } ChannelPressure;
113                    /// Polyphonic Note Pressure (aftertouch) event specifics
114                    struct _NotePressure {
115                        uint8_t Channel; ///< MIDI channel (0..15)
116                        uint8_t Key;     ///< MIDI note number where key pressure (polyphonic aftertouch) changed.
117                        uint8_t Value;   ///< New pressure value for note.
118                    } NotePressure;
119              } Param;              } Param;
120                /// Sampler format specific informations and variables.
121              inline uint FragmentPos() {              union {
122                  if (iFragmentPos >= 0) return (uint) iFragmentPos;                  /// Gigasampler/GigaStudio format specifics.
123                  return (uint) (iFragmentPos = pEventGenerator->ToFragmentPos(TimeStamp));                  struct _Gig {
124                        uint8_t DimMask; ///< May be used to override the Dimension zone to be selected for a new voice: each 1 bit means that respective bit shall be overridden by taking the respective bit from DimBits instead.
125                        uint8_t DimBits; ///< Used only in conjunction with DimMask: Dimension bits that shall be selected.
126                    } Gig;
127                } Format;
128                EngineChannel* pEngineChannel; ///< Pointer to the EngineChannel where this event occured on, NULL means Engine global event (e.g. SysEx message).
129                MidiInputPort* pMidiInputPort; ///< Pointer to the MIDI input port on which this event occured (NOTE: currently only for global events, that is SysEx messages)
130    
131                inline int32_t FragmentPos() {
132                    if (iFragmentPos >= 0) return iFragmentPos;
133                    iFragmentPos = pEventGenerator->ToFragmentPos(TimeStamp);
134                    if (iFragmentPos < 0) iFragmentPos = 0; // if event arrived shortly before the beginning of current fragment
135                    return iFragmentPos;
136                }
137                inline void ResetFragmentPos() {
138                    iFragmentPos = -1;
139              }              }
140          protected:          protected:
141              typedef EventGenerator::time_stamp_t time_stamp_t;              typedef EventGenerator::time_stamp_t time_stamp_t;
142              Event(EventGenerator* pGenerator, EventGenerator::time_stamp_t Time);              Event(EventGenerator* pGenerator, EventGenerator::time_stamp_t Time);
143                Event(EventGenerator* pGenerator, int32_t FragmentPos);
144              friend class EventGenerator;              friend class EventGenerator;
145          private:          private:
146              EventGenerator* pEventGenerator; ///< Creator of the event.              EventGenerator* pEventGenerator; ///< Creator of the event.
147              time_stamp_t    TimeStamp;       ///< Time stamp of the event's occurence.              time_stamp_t    TimeStamp;       ///< Time stamp of the event's occurence.
148              int             iFragmentPos;    ///< Position in the current fragment this event refers to.              int32_t         iFragmentPos;    ///< Position in the current fragment this event refers to.
149        };
150    
151        class VMEventHandler;
152        class VMExecContext;
153    
154        /** @brief Real-time instrument script event.
155         *
156         * Encapsulates one execution instance of a real-time instrument script for
157         * exactly one script event handler (script event callback).
158         */
159        class ScriptEvent {
160        public:
161            Event cause; ///< Original external event that triggered this script event (i.e. MIDI note on event, MIDI CC event, etc.).
162            int id; ///< Unique ID of the external event that triggered this cript event.
163            VMEventHandler** handlers; ///< The script's event handlers (callbacks) to be processed (NULL terminated list).
164            VMExecContext* execCtx; ///< Script's current execution state (polyphonic variables and execution stack).
165            int currentHandler; ///< Current index in 'handlers' list above.
166            int executionSlices; ///< Amount of times this script event has been executed by the ScriptVM runner class.
167      };      };
168    
169  } // namespace LinuxSampler  } // namespace LinuxSampler

Legend:
Removed from v.246  
changed lines
  Added in v.2600

  ViewVC Help
Powered by ViewVC