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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1887 - (hide annotations) (download) (as text)
Sat Apr 18 08:17:16 2009 UTC (14 years, 11 months ago) by persson
File MIME type: text/x-c++hdr
File size: 17136 byte(s)
* bugfix: pitch bend wasn't working with JackMidi, VST, LV2, Mme,
  CoreMidi or AU
* theoretical fix: made SynchronizedConfig follow C++0x memory model
  more strictly

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

  ViewVC Help
Powered by ViewVC