/[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 64 - (show annotations) (download) (as text)
Thu May 6 20:06:20 2004 UTC (19 years, 11 months ago) by schoenebeck
File MIME type: text/x-c++hdr
File size: 9210 byte(s)
* src/Sampler.cpp: fixed 3 stupid but fatal bugs that left in the rush (in
  method SamplerChannels(), CreateAudioOutputDevice() and
  CreateMidiInputDevice())
* src/network/lscpserver.cpp: implemented LSCP command
  'SET CHANNEL MIDI_INPUT_CHANNEL'
* src/Sampler.h: moved enums 'audio_output_type_t', 'midi_input_type_t'
  and 'engine_type_t' into the respective base classes
  ('AudioOutputDevice', 'MidiInputDevice', 'Engine')

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

  ViewVC Help
Powered by ViewVC