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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2101 - (show annotations) (download) (as text)
Sun May 30 11:40:31 2010 UTC (13 years, 10 months ago) by persson
File MIME type: text/x-c++hdr
File size: 6702 byte(s)
* sfz/sf2 engines: RT-safeness: avoid malloc in audio thread
* sfz/sf2 engines: fixed a bug that could cause voice stealing to fail

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

  ViewVC Help
Powered by ViewVC