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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 412 - (hide annotations) (download) (as text)
Sat Feb 26 22:44:51 2005 UTC (19 years, 1 month ago) by schoenebeck
File MIME type: text/x-c++hdr
File size: 6638 byte(s)
* gig::Engine: fixed silence (engine channels' events were not imported
  into the engine, fixed undesired creation of new gig::Engine instances
  (and disk threads)
* AudioOutputDevice: reverted behavior to render per Engine instance (and
  not per EngineChannel instance)

1 schoenebeck 53 /***************************************************************************
2     * *
3     * LinuxSampler - modular, streaming capable sampler *
4     * *
5 schoenebeck 56 * Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck *
6 schoenebeck 53 * *
7     * This program is free software; you can redistribute it and/or modify *
8     * it under the terms of the GNU General Public License as published by *
9     * the Free Software Foundation; either version 2 of the License, or *
10     * (at your option) any later version. *
11     * *
12     * This program is distributed in the hope that it will be useful, *
13     * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15     * GNU General Public License for more details. *
16     * *
17     * You should have received a copy of the GNU General Public License *
18     * along with this program; if not, write to the Free Software *
19     * Foundation, Inc., 59 Temple Place, Suite 330, Boston, *
20     * MA 02111-1307 USA *
21     ***************************************************************************/
22    
23     #ifndef __LS_EVENT_H__
24     #define __LS_EVENT_H__
25    
26     #include "../../common/global.h"
27 schoenebeck 328 #include "../../common/RTMath.h"
28 schoenebeck 412 #include "EngineChannel.h"
29 schoenebeck 53
30     namespace LinuxSampler {
31    
32     // just symbol prototyping
33     class Event;
34    
35     /**
36     * Generates Event objects and is responsible for resolving the position
37     * in the current audio fragment each Event actually belongs to.
38     */
39     class EventGenerator {
40     public:
41     EventGenerator(uint SampleRate);
42     void UpdateFragmentTime(uint SamplesToProcess);
43     Event CreateEvent();
44     protected:
45 schoenebeck 328 typedef RTMath::time_stamp_t time_stamp_t;
46 schoenebeck 293 inline int32_t ToFragmentPos(time_stamp_t TimeStamp) {
47     return int32_t (int32_t(TimeStamp - FragmentTime.begin) * FragmentTime.sample_ratio);
48 schoenebeck 53 }
49     friend class Event;
50     private:
51     uint uiSampleRate;
52     uint uiSamplesProcessed;
53     struct __FragmentTime__ {
54     time_stamp_t begin; ///< Real time stamp of the beginning of this audio fragment cycle.
55     time_stamp_t end; ///< Real time stamp of the end of this audio fragment cycle.
56     float sample_ratio; ///< (Samples per cycle) / (Real time duration of cycle)
57     } FragmentTime;
58     };
59    
60     /**
61     * Events are usually caused by a MIDI source or an internal modulation
62     * controller like LFO or EG. An event can only be created by an
63     * EventGenerator.
64     *
65     * @see EventGenerator
66     */
67     class Event {
68     public:
69     Event(){}
70     enum type_t {
71     type_note_on,
72     type_note_off,
73     type_pitchbend,
74     type_control_change,
75 schoenebeck 244 type_sysex, ///< MIDI system exclusive message
76 schoenebeck 53 type_cancel_release, ///< transformed either from a note-on or sustain-pedal-down event
77     type_release ///< transformed either from a note-off or sustain-pedal-up event
78     } Type;
79     enum destination_t {
80     destination_vca, ///< Volume level
81     destination_vco, ///< Pitch depth
82     destination_vcfc, ///< Filter curoff frequency
83     destination_vcfr, ///< Filter resonance
84     destination_count ///< Total number of modulation destinations (this has to stay the last element in the enum)
85     };
86     union {
87 schoenebeck 246 /// Note-on and note-off event specifics
88     struct _Note {
89     uint8_t Key; ///< MIDI key number of note-on / note-off event.
90     uint8_t Velocity; ///< Trigger or release velocity of note-on / note-off event.
91 schoenebeck 250 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).
92     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).
93 schoenebeck 246 } Note;
94     /// Control change event specifics
95     struct _CC {
96     uint8_t Controller; ///< MIDI controller number of control change event.
97     uint8_t Value; ///< Controller Value of control change event.
98     } CC;
99     /// Pitchbend event specifics
100     struct _Pitch {
101     int16_t Pitch; ///< Pitch value of pitchbend event.
102     } Pitch;
103     /// MIDI system exclusive event specifics
104     struct _Sysex {
105     uint Size; ///< Data length (in bytes) of MIDI system exclusive message.
106     } Sysex;
107     } Param;
108 schoenebeck 412 EngineChannel* pEngineChannel; ///< Pointer to the EngineChannel where this event occured on, NULL means Engine global event (e.g. SysEx message).
109 schoenebeck 53
110 schoenebeck 293 inline int32_t FragmentPos() {
111     if (iFragmentPos >= 0) return iFragmentPos;
112     iFragmentPos = pEventGenerator->ToFragmentPos(TimeStamp);
113     if (iFragmentPos < 0) iFragmentPos = 0; // if event arrived shortly before the beginning of current fragment
114     return iFragmentPos;
115 schoenebeck 53 }
116 schoenebeck 293 inline void ResetFragmentPos() {
117     iFragmentPos = -1;
118     }
119 schoenebeck 53 protected:
120     typedef EventGenerator::time_stamp_t time_stamp_t;
121     Event(EventGenerator* pGenerator, EventGenerator::time_stamp_t Time);
122     friend class EventGenerator;
123     private:
124     EventGenerator* pEventGenerator; ///< Creator of the event.
125     time_stamp_t TimeStamp; ///< Time stamp of the event's occurence.
126 schoenebeck 293 int32_t iFragmentPos; ///< Position in the current fragment this event refers to.
127 schoenebeck 53 };
128    
129     } // namespace LinuxSampler
130    
131     #endif // __LS_EVENT_H__

  ViewVC Help
Powered by ViewVC