/[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 87 - (show annotations) (download) (as text)
Mon May 24 12:48:57 2004 UTC (19 years, 11 months ago) by letz
File MIME type: text/x-c++hdr
File size: 9306 byte(s)
* New type_core_midi and type_midishare types

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 /**
54 * List of all currently implemented MIDI input drivers.
55 */
56 enum type_t {
57 type_alsa,
58 type_core_midi,
59 type_midishare
60 };
61
62 /**
63 * MIDI channels
64 */
65 enum midi_chan_t {
66 midi_chan_all = 0,
67 midi_chan_1 = 1,
68 midi_chan_2 = 2,
69 midi_chan_3 = 3,
70 midi_chan_4 = 4,
71 midi_chan_5 = 5,
72 midi_chan_6 = 6,
73 midi_chan_7 = 7,
74 midi_chan_8 = 8,
75 midi_chan_9 = 9,
76 midi_chan_10 = 10,
77 midi_chan_11 = 11,
78 midi_chan_12 = 12,
79 midi_chan_13 = 13,
80 midi_chan_14 = 14,
81 midi_chan_15 = 15,
82 midi_chan_16 = 16
83 };
84
85
86
87 /////////////////////////////////////////////////////////////////
88 // abstract methods
89 // (these have to be implemented by the descendant)
90
91 /**
92 * Start listen to MIDI input events on the MIDI input device.
93 * The MIDIInputDevice descendant should forward all MIDI input
94 * events by calling the appropriate (protected) Dispatch*
95 * method of class MidiInputDevice.
96 */
97 virtual void Listen() = 0;
98
99 /**
100 * Stop to listen to MIDI input events on the MIDI input device.
101 * After this method was called, the MidiInputDevice descendant
102 * should ignore all MIDI input events.
103 */
104 virtual void StopListen() = 0;
105
106 virtual void SetInputPort(const char *) = 0;
107
108 /////////////////////////////////////////////////////////////////
109 // normal methods
110 // (usually not to be overriden by descendant)
111
112 /**
113 * Connect given sampler engine with this MIDI input device.
114 * The engine can either be connected to one specific MIDI
115 * channel or all MIDI channels. If an engine gets connected
116 * twice to this MIDI input device, then the engine's old
117 * connection will be detached (no matter on which MIDI channel).
118 *
119 * @param pEngine - sampler engine
120 * @param MidiChannel - MIDI channel to connect to
121 * @throws MidiInputException if MidiChannel argument invalid
122 */
123 void Connect(Engine* pEngine, midi_chan_t MidiChannel);
124
125 /**
126 * Disconnect given sampler engine from this MIDI input device.
127 *
128 * @param pEngine - sampler engine
129 */
130 void Disconnect(Engine* pEngine);
131
132 /**
133 * Returns the ID that identifies the implementing MIDI input
134 * driver.
135 */
136 type_t Type();
137
138 protected:
139 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.
140 type_t MidiInputType;
141
142
143 /**
144 * Constructor. Has to be called by the implementing MIDI
145 * input driver to define the ID of the driver. When a new MIDI
146 * input driver is implemented, the
147 * MidiInputDevice::midi_input_type_t enumeration has to be
148 * extended with a new ID for the new MIDI input driver.
149 */
150 MidiInputDevice(type_t Type);
151
152
153
154 /////////////////////////////////////////////////////////////////
155 // dispatch methods
156 // (should be called by the MidiInputDevice descendant on events)
157
158 /**
159 * Should be called by the implementing MIDI input device
160 * whenever a note on event arrived, this will cause the note on
161 * event to be forwarded to all connected engines on the
162 * corresponding MIDI channel.
163 *
164 * @param Key - MIDI key number of the triggered key
165 * @param Velocity - MIDI velocity of the triggered key
166 * @param MidiChannel - MIDI channel on which event occured on
167 */
168 void DispatchNoteOn(uint8_t Key, uint8_t Velocity, uint MidiChannel);
169
170 /**
171 * Should be called by the implementing MIDI input device
172 * whenever a note off event arrived, this will cause the note
173 * off event to be forwarded to all connected engines on the
174 * corresponding MIDI channel.
175 *
176 * @param Key - MIDI key number of the released key
177 * @param Velocity - MIDI velocity of the released key
178 * @param MidiChannel - MIDI channel on which event occured on
179 */
180 void DispatchNoteOff(uint8_t Key, uint8_t Velocity, uint MidiChannel);
181
182 /**
183 * Should be called by the implementing MIDI input device
184 * whenever a pitchbend event arrived, this will cause the
185 * pitchbend event to be forwarded to all connected engines.
186 *
187 * @param Pitch - MIDI pitch value
188 * @param MidiChannel - MIDI channel on which event occured on
189 */
190 void DispatchPitchbend(int Pitch, uint MidiChannel);
191
192 /**
193 * Should be called by the implementing MIDI input device
194 * whenever a control change event arrived, this will cause the
195 * control change event to be forwarded to all engines on the
196 * corresponding MIDI channel.
197 *
198 * @param Controller - MIDI controller number
199 * @param Value - MIDI control change value
200 * @param MidiChannel - MIDI channel on which event occured on
201 */
202 void DispatchControlChange(uint8_t Controller, uint8_t Value, uint MidiChannel);
203 };
204
205 /**
206 * Midi input exception that should be thrown by the MidiInputDevice
207 * descendants in case initialization of the MIDI input system failed
208 * (which should be done in the constructor of the MidiInputDevice
209 * descendant).
210 */
211 class MidiInputException : public LinuxSamplerException {
212 public:
213 MidiInputException(const std::string& msg) : LinuxSamplerException(msg) {}
214 };
215 }
216
217 #endif // __LS_MIDIINPUTDEVICE_H__

  ViewVC Help
Powered by ViewVC