/[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 246 - (show annotations) (download) (as text)
Sun Sep 19 14:12:55 2004 UTC (19 years, 6 months ago) by schoenebeck
File MIME type: text/x-c++hdr
File size: 6031 byte(s)
just tidied up event type specific parameters (that is note-on specific
parameters, controle change specific parameters, etc.) in Event class

1 /***************************************************************************
2 * *
3 * LinuxSampler - modular, streaming capable sampler *
4 * *
5 * Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck *
6 * *
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
28 namespace LinuxSampler {
29
30 // just symbol prototyping
31 class Event;
32
33 /**
34 * Generates Event objects and is responsible for resolving the position
35 * in the current audio fragment each Event actually belongs to.
36 */
37 class EventGenerator {
38 public:
39 EventGenerator(uint SampleRate);
40 void UpdateFragmentTime(uint SamplesToProcess);
41 Event CreateEvent();
42 protected:
43 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.
44 inline uint ToFragmentPos(time_stamp_t TimeStamp) {
45 return uint ((TimeStamp - FragmentTime.begin) * FragmentTime.sample_ratio);
46 }
47 friend class Event;
48 private:
49 uint uiSampleRate;
50 uint uiSamplesProcessed;
51 struct __FragmentTime__ {
52 time_stamp_t begin; ///< Real time stamp of the beginning of this audio fragment cycle.
53 time_stamp_t end; ///< Real time stamp of the end of this audio fragment cycle.
54 float sample_ratio; ///< (Samples per cycle) / (Real time duration of cycle)
55 } FragmentTime;
56 time_stamp_t CreateTimeStamp();
57 };
58
59 /**
60 * Events are usually caused by a MIDI source or an internal modulation
61 * controller like LFO or EG. An event can only be created by an
62 * EventGenerator.
63 *
64 * @see EventGenerator
65 */
66 class Event {
67 public:
68 Event(){}
69 enum type_t {
70 type_note_on,
71 type_note_off,
72 type_pitchbend,
73 type_control_change,
74 type_sysex, ///< MIDI system exclusive message
75 type_cancel_release, ///< transformed either from a note-on or sustain-pedal-down event
76 type_release ///< transformed either from a note-off or sustain-pedal-up event
77 } Type;
78 enum destination_t {
79 destination_vca, ///< Volume level
80 destination_vco, ///< Pitch depth
81 destination_vcfc, ///< Filter curoff frequency
82 destination_vcfr, ///< Filter resonance
83 destination_count ///< Total number of modulation destinations (this has to stay the last element in the enum)
84 };
85 union {
86 /// Note-on and note-off event specifics
87 struct _Note {
88 uint8_t Key; ///< MIDI key number of note-on / note-off event.
89 uint8_t Velocity; ///< Trigger or release velocity of note-on / note-off event.
90 } Note;
91 /// Control change event specifics
92 struct _CC {
93 uint8_t Controller; ///< MIDI controller number of control change event.
94 uint8_t Value; ///< Controller Value of control change event.
95 } CC;
96 /// Pitchbend event specifics
97 struct _Pitch {
98 int16_t Pitch; ///< Pitch value of pitchbend event.
99 } Pitch;
100 /// MIDI system exclusive event specifics
101 struct _Sysex {
102 uint Size; ///< Data length (in bytes) of MIDI system exclusive message.
103 } Sysex;
104 } Param;
105
106 inline uint FragmentPos() {
107 if (iFragmentPos >= 0) return (uint) iFragmentPos;
108 return (uint) (iFragmentPos = pEventGenerator->ToFragmentPos(TimeStamp));
109 }
110 protected:
111 typedef EventGenerator::time_stamp_t time_stamp_t;
112 Event(EventGenerator* pGenerator, EventGenerator::time_stamp_t Time);
113 friend class EventGenerator;
114 private:
115 EventGenerator* pEventGenerator; ///< Creator of the event.
116 time_stamp_t TimeStamp; ///< Time stamp of the event's occurence.
117 int iFragmentPos; ///< Position in the current fragment this event refers to.
118 };
119
120 } // namespace LinuxSampler
121
122 #endif // __LS_EVENT_H__

  ViewVC Help
Powered by ViewVC