/[svn]/linuxsampler/trunk/src/drivers/midi/MidiInputPort.h
ViewVC logotype

Contents of /linuxsampler/trunk/src/drivers/midi/MidiInputPort.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1424 - (show annotations) (download) (as text)
Sun Oct 14 22:00:17 2007 UTC (16 years, 6 months ago) by schoenebeck
File MIME type: text/x-c++hdr
File size: 15745 byte(s)
* code cleanup:
- global.h now only covers global definitions that are needed for the C++
  API header files, all implementation internal global definitions are now
  in global_private.h
- atomic.h is not exposed to the C++ API anymore (replaced the references
  in SynchronizedConfig.h for this with local definitions)
- no need to include config.h anymore for using LS's API header files
- DB instruments classes are not exposed to the C++ API
- POSIX callback functions of Thread.h are hidden
- the (optional) gig Engine benchmark compiles again
- updated Doxyfile.in
- fixed warnings in API doc generation
* preparations for release 0.5.0

1 /***************************************************************************
2 * *
3 * LinuxSampler - modular, streaming capable sampler *
4 * *
5 * Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck *
6 * Copyright (C) 2005 - 2007 Christian Schoenebeck *
7 * *
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_MIDIINPUTPORT_H__
25 #define __LS_MIDIINPUTPORT_H__
26
27 #include "../../common/global.h"
28 #include "../../common/Mutex.h"
29 #include "../../common/Exception.h"
30 #include "../DeviceParameter.h"
31 #include "midi.h"
32 #include "MidiInputDevice.h"
33 #include "../../engines/EngineChannel.h"
34 #include "../../common/SynchronizedConfig.h"
35
36 namespace LinuxSampler {
37
38 // just symbol prototyping
39 class MidiInputDevice;
40 class EngineChannel;
41
42 class MidiInputPort {
43 public:
44
45 /////////////////////////////////////////////////////////////////
46 // type definitions
47
48 /** MIDI Port Parameter 'NAME'
49 *
50 * Used to assign an arbitrary name to the MIDI port.
51 */
52 class ParameterName : public DeviceRuntimeParameterString {
53 public:
54 ParameterName(MidiInputPort* pPort);
55 ParameterName(MidiInputPort* pPort, String val);
56 virtual String Description();
57 virtual bool Fix();
58 virtual std::vector<String> PossibilitiesAsString();
59 virtual void OnSetValue(String s) throw (Exception);
60 protected:
61 MidiInputPort* pPort;
62 };
63
64
65
66 /////////////////////////////////////////////////////////////////
67 // normal methods
68 // (usually not to be overriden by descendant)
69
70 /**
71 * Connect given sampler engine channel with this MIDI input
72 * device. The engine channel can either be connected to one
73 * specific MIDI channel or all MIDI channels. If an engine
74 * channel gets connected twice to this MIDI input device, then
75 * the engine's old connection will be detached (no matter on
76 * which MIDI channel).
77 *
78 * @param pEngineChannel - sampler engine
79 * @param MidiChannel - MIDI channel to connect to
80 * @throws MidiInputException if MidiChannel argument invalid
81 */
82 void Connect(EngineChannel* pEngineChannel, midi_chan_t MidiChannel);
83
84 /**
85 * Disconnect given sampler engine channel from this MIDI input
86 * device. If the given engine channel was not connected with
87 * this device, nothing happens.
88 *
89 * @param pEngineChannel - sampler engine
90 */
91 void Disconnect(EngineChannel* pEngineChannel);
92
93 /**
94 * Return MIDI device where this MIDI port belongs to.
95 */
96 MidiInputDevice* GetDevice();
97
98 /**
99 * Return port number with which this MIDI port is registered to
100 * the MIDI device.
101 */
102 uint GetPortNumber();
103
104 /**
105 * Return all parameter settings of this MIDI port.
106 */
107 std::map<String,DeviceRuntimeParameter*> PortParameters();
108
109 /**
110 * Registers that an engine wants to have sysex messages.
111 */
112 static void AddSysexListener(Engine* engine);
113
114 /**
115 * Removes engine from list of engines getting sysex
116 * messages.
117 *
118 * @returns true if engine was removed, false if it wasn't
119 * present in the list.
120 */
121 static bool RemoveSysexListener(Engine* engine);
122
123
124 /////////////////////////////////////////////////////////////////
125 // dispatch methods
126 // (should be called by the MidiInputDevice descendant on events)
127
128 /**
129 * Should be called by the implementing MIDI input device
130 * whenever a note on event arrived, this will cause the note on
131 * event to be forwarded to all connected engines on the
132 * corresponding MIDI channel.
133 *
134 * This method is meant for realtime rendering, this way an event
135 * is immediately created with the current system time as time
136 * stamp.
137 *
138 * @param Key - MIDI key number of the triggered key
139 * @param Velocity - MIDI velocity of the triggered key
140 * @param MidiChannel - MIDI channel on which event occured on
141 * (low level indexing, means 0..15)
142 */
143 void DispatchNoteOn(uint8_t Key, uint8_t Velocity, uint MidiChannel);
144
145 /**
146 * Should be called by the implementing MIDI input device
147 * whenever a note on event arrived, this will cause the note on
148 * event to be forwarded to all connected engines on the
149 * corresponding MIDI channel.
150 *
151 * This method is meant for offline rendering and / or in case the
152 * exact fragment position of the event is already known.
153 *
154 * @param Key - MIDI key number of the triggered key
155 * @param Velocity - MIDI velocity of the triggered key
156 * @param MidiChannel - MIDI channel on which event occured on
157 * (low level indexing, means 0..15)
158 * @param FragmentPos - event's sample point position in the
159 * current audio fragment
160 */
161 void DispatchNoteOn(uint8_t Key, uint8_t Velocity, uint MidiChannel, int32_t FragmentPos);
162
163 /**
164 * Should be called by the implementing MIDI input device
165 * whenever a note off event arrived, this will cause the note
166 * off event to be forwarded to all connected engines on the
167 * corresponding MIDI channel.
168 *
169 * This method is meant for realtime rendering, this way an event
170 * is immediately created with the current system time as time
171 * stamp.
172 *
173 * @param Key - MIDI key number of the released key
174 * @param Velocity - MIDI velocity of the released key
175 * @param MidiChannel - MIDI channel on which event occured on
176 * (low level indexing, means 0..15)
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 note off event arrived, this will cause the note
183 * off event to be forwarded to all connected engines on the
184 * corresponding MIDI channel.
185 *
186 * This method is meant for offline rendering and / or in case the
187 * exact fragment position of the event is already known.
188 *
189 * @param Key - MIDI key number of the released key
190 * @param Velocity - MIDI velocity of the released key
191 * @param MidiChannel - MIDI channel on which event occured on
192 * (low level indexing, means 0..15)
193 * @param FragmentPos - event's sample point position in the
194 * current audio fragment
195 */
196 void DispatchNoteOff(uint8_t Key, uint8_t Velocity, uint MidiChannel, int32_t FragmentPos);
197
198 /**
199 * Should be called by the implementing MIDI input device
200 * whenever a pitchbend event arrived, this will cause the
201 * pitchbend event to be forwarded to all connected engines.
202 *
203 * This method is meant for realtime rendering, this way an event
204 * is immediately created with the current system time as time
205 * stamp.
206 *
207 * @param Pitch - MIDI pitch value
208 * @param MidiChannel - MIDI channel on which event occured on
209 * (low level indexing, means 0..15)
210 */
211 void DispatchPitchbend(int Pitch, uint MidiChannel);
212
213 /**
214 * Should be called by the implementing MIDI input device
215 * whenever a pitchbend event arrived, this will cause the
216 * pitchbend event to be forwarded to all connected engines.
217 *
218 * This method is meant for offline rendering and / or in case the
219 * exact fragment position of the event is already known.
220 *
221 * @param Pitch - MIDI pitch value
222 * @param MidiChannel - MIDI channel on which event occured on
223 * (low level indexing, means 0..15)
224 * @param FragmentPos - event's sample point position in the
225 * current audio fragment
226 */
227 void DispatchPitchbend(int Pitch, uint MidiChannel, int32_t FragmentPos);
228
229 /**
230 * Should be called by the implementing MIDI input device
231 * whenever a control change event arrived, this will cause the
232 * control change event to be forwarded to all engines on the
233 * corresponding MIDI channel.
234 *
235 * This method is meant for realtime rendering, this way an event
236 * is immediately created with the current system time as time
237 * stamp.
238 *
239 * @param Controller - MIDI controller number
240 * @param Value - MIDI control change value
241 * @param MidiChannel - MIDI channel on which event occured on
242 * (low level indexing, means 0..15)
243 */
244 void DispatchControlChange(uint8_t Controller, uint8_t Value, uint MidiChannel);
245
246 /**
247 * Should be called by the implementing MIDI input device
248 * whenever a control change event arrived, this will cause the
249 * control change event to be forwarded to all engines on the
250 * corresponding MIDI channel.
251 *
252 * This method is meant for offline rendering and / or in case the
253 * exact fragment position of the event is already known.
254 *
255 * @param Controller - MIDI controller number
256 * @param Value - MIDI control change value
257 * @param MidiChannel - MIDI channel on which event occured on
258 * (low level indexing, means 0..15)
259 * @param FragmentPos - event's sample point position in the
260 * current audio fragment
261 */
262 void DispatchControlChange(uint8_t Controller, uint8_t Value, uint MidiChannel, int32_t FragmentPos);
263
264 /**
265 * Should be called by the implementing MIDI input device
266 * whenever a program change event arrived, this will cause the
267 * appropriate sampler channel to be connected with this MIDI
268 * device.
269 *
270 * For example consider a program change event on MIDI channel
271 * 3 for program number 18. This would cause this MIDI input
272 * device to be connected to sampler channel 18 and would cause
273 * sampler channel 18 to listen to MIDI channel 3.
274 *
275 * This is the current, general implementation of program
276 * change events. It might change in future, e.g to allow
277 * sampler engines to allow by themselfes how to act on a
278 * program change event.
279 *
280 * @param Program - sampler channel to connect to this MIDI
281 * input device
282 * @param MidiChannel - MIDI channel on which sampler channel
283 * \a Program should listen to
284 */
285 void DispatchProgramChange(uint8_t Program, uint MidiChannel);
286
287 void DispatchBankSelectMsb(uint8_t BankMsb, uint MidiChannel);
288
289 void DispatchBankSelectLsb(uint8_t BankLsb, uint MidiChannel);
290
291 /**
292 * Should be called by the implementing MIDI input device
293 * whenever a system exclusive message arrived, this will cause
294 * the message to be forwarded to all connected engines.
295 *
296 * @param pData - pointer to the sysex data
297 * @param Size - length of the sysex data (in bytes)
298 */
299 void DispatchSysex(void* pData, uint Size);
300
301 protected:
302 MidiInputDevice* pDevice;
303 int portNumber;
304 std::map<String,DeviceRuntimeParameter*> Parameters; ///< All port parameters.
305 typedef std::set<EngineChannel*> MidiChannelMap_t[17];
306 SynchronizedConfig<MidiChannelMap_t> MidiChannelMap; ///< 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.
307 SynchronizedConfig<MidiChannelMap_t>::Reader MidiChannelMapReader; ///< MIDI thread access to MidiChannelMap
308 Mutex MidiChannelMapMutex; ///< Used to protect the MidiChannelMap from being used at the same time by different threads.
309 SynchronizedConfig<std::set<Engine*> >::Reader SysexListenersReader; ///< MIDI thread access to SysexListeners
310
311 /**
312 * Constructor
313 */
314 MidiInputPort(MidiInputDevice* pDevice, int portNumber);
315
316 /**
317 * Destructor
318 */
319 virtual ~MidiInputPort();
320
321 friend class MidiInputDevice;
322
323 private:
324 static SynchronizedConfig<std::set<Engine*> > SysexListeners; ///< All engines that are listening to sysex messages.
325 };
326
327 } // namsepace LinuxSampler
328
329 #endif // __LS_MIDIINPUTPORT_H__

  ViewVC Help
Powered by ViewVC