/[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 890 - (hide annotations) (download) (as text)
Sat Jul 1 13:43:04 2006 UTC (17 years, 9 months ago) by schoenebeck
File MIME type: text/x-c++hdr
File size: 6316 byte(s)
just some refactoring work, moved the following files:

- src/engines/common/Engine.h -> src/engines/Engine.h,

- src/engines/common/EngineChannel.h ->
  src/engines/EngineChannel.h,

- src/engines/common/EngineChannel.cpp ->
  src/engines/EngineChannel.cpp

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 890 * Copyright (C) 2005, 2006 Christian Schoenebeck *
7 schoenebeck 53 * *
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 schoenebeck 328 #include "../../common/RTMath.h"
29 schoenebeck 890 #include "../EngineChannel.h"
30 schoenebeck 53
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     protected:
46 schoenebeck 328 typedef RTMath::time_stamp_t time_stamp_t;
47 schoenebeck 293 inline int32_t ToFragmentPos(time_stamp_t TimeStamp) {
48     return int32_t (int32_t(TimeStamp - FragmentTime.begin) * FragmentTime.sample_ratio);
49 schoenebeck 53 }
50     friend class Event;
51     private:
52     uint uiSampleRate;
53     uint uiSamplesProcessed;
54     struct __FragmentTime__ {
55     time_stamp_t begin; ///< Real time stamp of the beginning of this audio fragment cycle.
56     time_stamp_t end; ///< Real time stamp of the end of this audio fragment cycle.
57     float sample_ratio; ///< (Samples per cycle) / (Real time duration of cycle)
58     } FragmentTime;
59     };
60    
61     /**
62     * Events are usually caused by a MIDI source or an internal modulation
63     * controller like LFO or EG. An event can only be created by an
64     * EventGenerator.
65     *
66     * @see EventGenerator
67     */
68     class Event {
69     public:
70     Event(){}
71     enum type_t {
72     type_note_on,
73     type_note_off,
74     type_pitchbend,
75     type_control_change,
76 schoenebeck 244 type_sysex, ///< MIDI system exclusive message
77 schoenebeck 53 type_cancel_release, ///< transformed either from a note-on or sustain-pedal-down event
78     type_release ///< transformed either from a note-off or sustain-pedal-up event
79     } Type;
80     union {
81 schoenebeck 246 /// Note-on and note-off event specifics
82     struct _Note {
83     uint8_t Key; ///< MIDI key number of note-on / note-off event.
84     uint8_t Velocity; ///< Trigger or release velocity of note-on / note-off event.
85 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).
86     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).
87 schoenebeck 246 } Note;
88     /// Control change event specifics
89     struct _CC {
90     uint8_t Controller; ///< MIDI controller number of control change event.
91     uint8_t Value; ///< Controller Value of control change event.
92     } CC;
93     /// Pitchbend event specifics
94     struct _Pitch {
95     int16_t Pitch; ///< Pitch value of pitchbend event.
96     } Pitch;
97     /// MIDI system exclusive event specifics
98     struct _Sysex {
99     uint Size; ///< Data length (in bytes) of MIDI system exclusive message.
100     } Sysex;
101     } Param;
102 schoenebeck 412 EngineChannel* pEngineChannel; ///< Pointer to the EngineChannel where this event occured on, NULL means Engine global event (e.g. SysEx message).
103 schoenebeck 53
104 schoenebeck 293 inline int32_t FragmentPos() {
105     if (iFragmentPos >= 0) return iFragmentPos;
106     iFragmentPos = pEventGenerator->ToFragmentPos(TimeStamp);
107     if (iFragmentPos < 0) iFragmentPos = 0; // if event arrived shortly before the beginning of current fragment
108     return iFragmentPos;
109 schoenebeck 53 }
110 schoenebeck 293 inline void ResetFragmentPos() {
111     iFragmentPos = -1;
112     }
113 schoenebeck 53 protected:
114     typedef EventGenerator::time_stamp_t time_stamp_t;
115     Event(EventGenerator* pGenerator, EventGenerator::time_stamp_t Time);
116     friend class EventGenerator;
117     private:
118     EventGenerator* pEventGenerator; ///< Creator of the event.
119     time_stamp_t TimeStamp; ///< Time stamp of the event's occurence.
120 schoenebeck 293 int32_t iFragmentPos; ///< Position in the current fragment this event refers to.
121 schoenebeck 53 };
122    
123     } // namespace LinuxSampler
124    
125     #endif // __LS_EVENT_H__

  ViewVC Help
Powered by ViewVC