/[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 244 by schoenebeck, Fri Sep 17 01:01:11 2004 UTC revision 906 by schoenebeck, Sun Jul 23 16:44:08 2006 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, 2006 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
68       */       */
# Line 75  namespace LinuxSampler { Line 78  namespace LinuxSampler {
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;              } 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)  
             };  
81              union {              union {
82                  uint8_t Key;          ///< MIDI key number for note-on and note-off events.                  /// Note-on and note-off event specifics
83                  uint8_t Controller;   ///< MIDI controller number for control change events.                  struct _Note {
84              };                      uint8_t Key;         ///< MIDI key number of note-on / note-off event.
85              union {                      uint8_t Velocity;    ///< Trigger or release velocity of note-on / note-off event.
86                  uint8_t Velocity;     ///< Trigger or release velocity for note-on or note-off events.                      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).
87                  uint8_t Value;        ///< Value for control change events.                      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).
88              };                  } Note;
89              union {                  /// Control change event specifics
90                  int16_t Pitch;        ///< Pitch value for pitchbend events.                  struct _CC {
91                  uint    Size;         ///< Data length (in bytes) for MIDI system exclusive messages.                      uint8_t Controller;  ///< MIDI controller number of control change event.
92              };                      uint8_t Value;       ///< Controller Value of control change event.
93                    } CC;
94              inline uint FragmentPos() {                  /// Pitchbend event specifics
95                  if (iFragmentPos >= 0) return (uint) iFragmentPos;                  struct _Pitch {
96                  return (uint) (iFragmentPos = pEventGenerator->ToFragmentPos(TimeStamp));                      int16_t Pitch;       ///< Pitch value of pitchbend event.
97                    } Pitch;
98                    /// MIDI system exclusive event specifics
99                    struct _Sysex {
100                        uint Size;           ///< Data length (in bytes) of MIDI system exclusive message.
101                    } Sysex;
102                } Param;
103                EngineChannel* pEngineChannel; ///< Pointer to the EngineChannel where this event occured on, NULL means Engine global event (e.g. SysEx message).
104    
105                inline int32_t FragmentPos() {
106                    if (iFragmentPos >= 0) return iFragmentPos;
107                    iFragmentPos = pEventGenerator->ToFragmentPos(TimeStamp);
108                    if (iFragmentPos < 0) iFragmentPos = 0; // if event arrived shortly before the beginning of current fragment
109                    return iFragmentPos;
110                }
111                inline void ResetFragmentPos() {
112                    iFragmentPos = -1;
113              }              }
114          protected:          protected:
115              typedef EventGenerator::time_stamp_t time_stamp_t;              typedef EventGenerator::time_stamp_t time_stamp_t;
116              Event(EventGenerator* pGenerator, EventGenerator::time_stamp_t Time);              Event(EventGenerator* pGenerator, EventGenerator::time_stamp_t Time);
117                Event(EventGenerator* pGenerator, int32_t FragmentPos);
118              friend class EventGenerator;              friend class EventGenerator;
119          private:          private:
120              EventGenerator* pEventGenerator; ///< Creator of the event.              EventGenerator* pEventGenerator; ///< Creator of the event.
121              time_stamp_t    TimeStamp;       ///< Time stamp of the event's occurence.              time_stamp_t    TimeStamp;       ///< Time stamp of the event's occurence.
122              int             iFragmentPos;    ///< Position in the current fragment this event refers to.              int32_t         iFragmentPos;    ///< Position in the current fragment this event refers to.
123      };      };
124    
125  } // namespace LinuxSampler  } // namespace LinuxSampler

Legend:
Removed from v.244  
changed lines
  Added in v.906

  ViewVC Help
Powered by ViewVC