/[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 250 - (show annotations) (download) (as text)
Mon Sep 20 00:31:13 2004 UTC (15 years, 6 months ago) by schoenebeck
File MIME type: text/x-c++hdr
File size: 6408 byte(s)
* added first two experimental voice stealing algorithms ('oldestkey' -
which just steals the oldest voice on the oldest key and 'keymask' - which
tries to pick the oldest voice on the same key where the new voice should
be spawned, if it fails it behaves like 'oldestkey'), the desired algorithm
can be selected at compile time (see Engine.h) will be configurable via
LSCP soon though

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 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).
91 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).
92 } Note;
93 /// Control change event specifics
94 struct _CC {
95 uint8_t Controller; ///< MIDI controller number of control change event.
96 uint8_t Value; ///< Controller Value of control change event.
97 } CC;
98 /// Pitchbend event specifics
99 struct _Pitch {
100 int16_t Pitch; ///< Pitch value of pitchbend event.
101 } Pitch;
102 /// MIDI system exclusive event specifics
103 struct _Sysex {
104 uint Size; ///< Data length (in bytes) of MIDI system exclusive message.
105 } Sysex;
106 } Param;
107
108 inline uint FragmentPos() {
109 if (iFragmentPos >= 0) return (uint) iFragmentPos;
110 return (uint) (iFragmentPos = pEventGenerator->ToFragmentPos(TimeStamp));
111 }
112 protected:
113 typedef EventGenerator::time_stamp_t time_stamp_t;
114 Event(EventGenerator* pGenerator, EventGenerator::time_stamp_t Time);
115 friend class EventGenerator;
116 private:
117 EventGenerator* pEventGenerator; ///< Creator of the event.
118 time_stamp_t TimeStamp; ///< Time stamp of the event's occurence.
119 int iFragmentPos; ///< Position in the current fragment this event refers to.
120 };
121
122 } // namespace LinuxSampler
123
124 #endif // __LS_EVENT_H__

  ViewVC Help
Powered by ViewVC