/[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 244 - (show annotations) (download) (as text)
Fri Sep 17 01:01:11 2004 UTC (19 years, 6 months ago) by schoenebeck
File MIME type: text/x-c++hdr
File size: 5649 byte(s)
* added support for scale tuning via MIDI GS system exclusive message

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 uint8_t Key; ///< MIDI key number for note-on and note-off events.
87 uint8_t Controller; ///< MIDI controller number for control change events.
88 };
89 union {
90 uint8_t Velocity; ///< Trigger or release velocity for note-on or note-off events.
91 uint8_t Value; ///< Value for control change events.
92 };
93 union {
94 int16_t Pitch; ///< Pitch value for pitchbend events.
95 uint Size; ///< Data length (in bytes) for MIDI system exclusive messages.
96 };
97
98 inline uint FragmentPos() {
99 if (iFragmentPos >= 0) return (uint) iFragmentPos;
100 return (uint) (iFragmentPos = pEventGenerator->ToFragmentPos(TimeStamp));
101 }
102 protected:
103 typedef EventGenerator::time_stamp_t time_stamp_t;
104 Event(EventGenerator* pGenerator, EventGenerator::time_stamp_t Time);
105 friend class EventGenerator;
106 private:
107 EventGenerator* pEventGenerator; ///< Creator of the event.
108 time_stamp_t TimeStamp; ///< Time stamp of the event's occurence.
109 int iFragmentPos; ///< Position in the current fragment this event refers to.
110 };
111
112 } // namespace LinuxSampler
113
114 #endif // __LS_EVENT_H__

  ViewVC Help
Powered by ViewVC