/[svn]/linuxsampler/trunk/src/mididriver/MidiInputDevice.h
ViewVC logotype

Contents of /linuxsampler/trunk/src/mididriver/MidiInputDevice.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 56 - (show annotations) (download) (as text)
Tue Apr 27 09:21:58 2004 UTC (19 years, 11 months ago) by schoenebeck
File MIME type: text/x-c++hdr
File size: 8402 byte(s)
updated copyright header for 2004

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_MIDIINPUTDEVICE_H__
24 #define __LS_MIDIINPUTDEVICE_H__
25
26 #include <stdexcept>
27 #include <set>
28
29 #include "../common/global.h"
30 #include "../common/LinuxSamplerException.h"
31 #include "../engines/common/Engine.h"
32
33 namespace LinuxSampler {
34
35 // just symbol prototyping
36 class Engine;
37
38 /** Abstract base class for MIDI input drivers in LinuxSampler
39 *
40 * This class will be derived by specialized classes which implement the
41 * connection to a specific MIDI input system (e.g. Alsa Sequencer,
42 * CoreMIDI). The MidiInputDevice desendant should just call the
43 * appropriate (protected) Dispatch* method here when an MIDI event
44 * occured. The dispatch* methods here will automatically forward the
45 * MIDI event to the appropriate, connected sampler engines.
46 */
47 class MidiInputDevice {
48 public:
49
50 /////////////////////////////////////////////////////////////////
51 // type definitions
52
53 enum midi_chan_t {
54 midi_chan_all = 0,
55 midi_chan_1 = 1,
56 midi_chan_2 = 2,
57 midi_chan_3 = 3,
58 midi_chan_4 = 4,
59 midi_chan_5 = 5,
60 midi_chan_6 = 6,
61 midi_chan_7 = 7,
62 midi_chan_8 = 8,
63 midi_chan_9 = 9,
64 midi_chan_10 = 10,
65 midi_chan_11 = 11,
66 midi_chan_12 = 12,
67 midi_chan_13 = 13,
68 midi_chan_14 = 14,
69 midi_chan_15 = 15,
70 midi_chan_16 = 16,
71 midi_chan_17 = 17
72 };
73
74
75
76 /////////////////////////////////////////////////////////////////
77 // abstract methods
78 // (these have to be implemented by the descendant)
79
80 /**
81 * Start listen to MIDI input events on the MIDI input device.
82 * The MIDIInputDevice descendant should forward all MIDI input
83 * events by calling the appropriate (protected) Dispatch*
84 * method of class MidiInputDevice.
85 */
86 virtual void Listen() = 0;
87
88 /**
89 * Stop to listen to MIDI input events on the MIDI input device.
90 * After this method was called, the MidiInputDevice descendant
91 * should ignore all MIDI input events.
92 */
93 virtual void StopListen() = 0;
94
95
96
97 /////////////////////////////////////////////////////////////////
98 // normal methods
99 // (usually not to be overriden by descendant)
100
101 /**
102 * Connect given sampler engine with this MIDI input device.
103 * The engine can either be connected to one specific MIDI
104 * channel or all MIDI channels. If an engine gets connected
105 * twice to this MIDI input device, then the engine's old
106 * connection will be detached (no matter on which MIDI channel).
107 *
108 * @param pEngine - sampler engine
109 * @param MidiChannel - MIDI channel to connect to
110 * @throws MidiInputException if MidiChannel argument invalid
111 */
112 void Connect(Engine* pEngine, midi_chan_t MidiChannel);
113
114 /**
115 * Disconnect given sampler engine from this MIDI input device.
116 *
117 * @param pEngine - sampler engine
118 */
119 void Disconnect(Engine* pEngine);
120
121 protected:
122 std::set<Engine*> MidiChannelMap[17]; ///< Contains the list of connected engines for each MIDI channel, where index 0 points to the list of engines which are connected to all MIDI channels. Usually it's not necessary for the descendant to use this map, instead it should just use the Dispatch* methods.
123
124
125 /////////////////////////////////////////////////////////////////
126 // dispatch methods
127 // (should be called by the MidiInputDevice descendant on events)
128
129 /**
130 * Should be called by the implementing MIDI input device
131 * whenever a note on event arrived, this will cause the note on
132 * event to be forwarded to all connected engines on the
133 * corresponding MIDI channel.
134 *
135 * @param Key - MIDI key number of the triggered key
136 * @param Velocity - MIDI velocity of the triggered key
137 * @param MidiChannel - MIDI channel on which event occured on
138 */
139 void DispatchNoteOn(uint8_t Key, uint8_t Velocity, uint MidiChannel);
140
141 /**
142 * Should be called by the implementing MIDI input device
143 * whenever a note off event arrived, this will cause the note
144 * off event to be forwarded to all connected engines on the
145 * corresponding MIDI channel.
146 *
147 * @param Key - MIDI key number of the released key
148 * @param Velocity - MIDI velocity of the released key
149 * @param MidiChannel - MIDI channel on which event occured on
150 */
151 void DispatchNoteOff(uint8_t Key, uint8_t Velocity, uint MidiChannel);
152
153 /**
154 * Should be called by the implementing MIDI input device
155 * whenever a pitchbend event arrived, this will cause the
156 * pitchbend event to be forwarded to all connected engines.
157 *
158 * @param Pitch - MIDI pitch value
159 * @param MidiChannel - MIDI channel on which event occured on
160 */
161 void DispatchPitchbend(int Pitch, uint MidiChannel);
162
163 /**
164 * Should be called by the implementing MIDI input device
165 * whenever a control change event arrived, this will cause the
166 * control change event to be forwarded to all engines on the
167 * corresponding MIDI channel.
168 *
169 * @param Controller - MIDI controller number
170 * @param Value - MIDI control change value
171 * @param MidiChannel - MIDI channel on which event occured on
172 */
173 void DispatchControlChange(uint8_t Controller, uint8_t Value, uint MidiChannel);
174 };
175
176 /**
177 * Midi input exception that should be thrown by the MidiInputDevice
178 * descendants in case initialization of the MIDI input system failed
179 * (which should be done in the constructor of the MidiInputDevice
180 * descendant).
181 */
182 class MidiInputException : public LinuxSamplerException {
183 public:
184 MidiInputException(const std::string& msg) : LinuxSamplerException(msg) {}
185 };
186 }
187
188 #endif // __LS_MIDIINPUTDEVICE_H__

  ViewVC Help
Powered by ViewVC