/[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 328 - (hide annotations) (download) (as text)
Sat Dec 25 21:58:58 2004 UTC (19 years, 3 months ago) by schoenebeck
File MIME type: text/x-c++hdr
File size: 6452 byte(s)
* architecture independence fixes, should now compile again for non x86
  systems
* tiny fix of command line switch --version

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 53
29     namespace LinuxSampler {
30    
31     // just symbol prototyping
32     class Event;
33    
34     /**
35     * Generates Event objects and is responsible for resolving the position
36     * in the current audio fragment each Event actually belongs to.
37     */
38     class EventGenerator {
39     public:
40     EventGenerator(uint SampleRate);
41     void UpdateFragmentTime(uint SamplesToProcess);
42     Event CreateEvent();
43     protected:
44 schoenebeck 328 typedef RTMath::time_stamp_t time_stamp_t;
45 schoenebeck 293 inline int32_t ToFragmentPos(time_stamp_t TimeStamp) {
46     return int32_t (int32_t(TimeStamp - FragmentTime.begin) * FragmentTime.sample_ratio);
47 schoenebeck 53 }
48     friend class Event;
49     private:
50     uint uiSampleRate;
51     uint uiSamplesProcessed;
52     struct __FragmentTime__ {
53     time_stamp_t begin; ///< Real time stamp of the beginning of this audio fragment cycle.
54     time_stamp_t end; ///< Real time stamp of the end of this audio fragment cycle.
55     float sample_ratio; ///< (Samples per cycle) / (Real time duration of cycle)
56     } FragmentTime;
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 schoenebeck 244 type_sysex, ///< MIDI system exclusive message
75 schoenebeck 53 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 schoenebeck 246 /// 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 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).
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 schoenebeck 246 } 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 schoenebeck 53
108 schoenebeck 293 inline int32_t FragmentPos() {
109     if (iFragmentPos >= 0) return iFragmentPos;
110     iFragmentPos = pEventGenerator->ToFragmentPos(TimeStamp);
111     if (iFragmentPos < 0) iFragmentPos = 0; // if event arrived shortly before the beginning of current fragment
112     return iFragmentPos;
113 schoenebeck 53 }
114 schoenebeck 293 inline void ResetFragmentPos() {
115     iFragmentPos = -1;
116     }
117 schoenebeck 53 protected:
118     typedef EventGenerator::time_stamp_t time_stamp_t;
119     Event(EventGenerator* pGenerator, EventGenerator::time_stamp_t Time);
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 schoenebeck 293 int32_t iFragmentPos; ///< Position in the current fragment this event refers to.
125 schoenebeck 53 };
126    
127     } // namespace LinuxSampler
128    
129     #endif // __LS_EVENT_H__

  ViewVC Help
Powered by ViewVC