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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 551 by schoenebeck, Tue May 17 18:16:54 2005 UTC revision 1765 by persson, Sat Sep 6 16:44:42 2008 UTC
# Line 3  Line 3 
3   *   LinuxSampler - modular, streaming capable sampler                     *   *   LinuxSampler - modular, streaming capable sampler                     *
4   *                                                                         *   *                                                                         *
5   *   Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck   *   *   Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck   *
6   *   Copyright (C) 2005 Christian Schoenebeck                              *   *   Copyright (C) 2005 - 2008 Christian Schoenebeck                       *
7   *                                                                         *   *                                                                         *
8   *   This program is free software; you can redistribute it and/or modify  *   *   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  *   *   it under the terms of the GNU General Public License as published by  *
# Line 26  Line 26 
26    
27  #include "../../common/global.h"  #include "../../common/global.h"
28  #include "../../common/Mutex.h"  #include "../../common/Mutex.h"
29  #include "../../common/LinuxSamplerException.h"  #include "../../common/Exception.h"
30  #include "../DeviceParameter.h"  #include "../DeviceParameter.h"
31    #include "midi.h"
32  #include "MidiInputDevice.h"  #include "MidiInputDevice.h"
33  #include "../../engines/common/EngineChannel.h"  #include "../../engines/EngineChannel.h"
34    #include "../../common/SynchronizedConfig.h"
35    
36  namespace LinuxSampler {  namespace LinuxSampler {
37    
38      // just symbol prototyping      // just symbol prototyping
39      class MidiInputDevice;      class MidiInputDevice;
40        class EngineChannel;
41        class VirtualMidiDevice;
42    
43      class MidiInputPort {      class MidiInputPort {
44          public:          public:
# Line 42  namespace LinuxSampler { Line 46  namespace LinuxSampler {
46              /////////////////////////////////////////////////////////////////              /////////////////////////////////////////////////////////////////
47              // type definitions              // type definitions
48    
             /**  
              * MIDI channels  
              */  
             enum midi_chan_t {  
                 midi_chan_1   = 0,  
                 midi_chan_2   = 1,  
                 midi_chan_3   = 2,  
                 midi_chan_4   = 3,  
                 midi_chan_5   = 4,  
                 midi_chan_6   = 5,  
                 midi_chan_7   = 6,  
                 midi_chan_8   = 7,  
                 midi_chan_9   = 8,  
                 midi_chan_10  = 9,  
                 midi_chan_11  = 10,  
                 midi_chan_12  = 11,  
                 midi_chan_13  = 12,  
                 midi_chan_14  = 13,  
                 midi_chan_15  = 14,  
                 midi_chan_16  = 15,  
                 midi_chan_all = 16  
             };  
   
49              /** MIDI Port Parameter 'NAME'              /** MIDI Port Parameter 'NAME'
50               *               *
51               * Used to assign an arbitrary name to the MIDI port.               * Used to assign an arbitrary name to the MIDI port.
# Line 76  namespace LinuxSampler { Line 57  namespace LinuxSampler {
57                      virtual String Description();                      virtual String Description();
58                      virtual bool   Fix();                      virtual bool   Fix();
59                      virtual std::vector<String> PossibilitiesAsString();                      virtual std::vector<String> PossibilitiesAsString();
60                      virtual void OnSetValue(String s) throw (LinuxSamplerException);                      virtual void OnSetValue(String s) throw (Exception);
61                  protected:                  protected:
62                      MidiInputPort* pPort;                      MidiInputPort* pPort;
63              };              };
# Line 88  namespace LinuxSampler { Line 69  namespace LinuxSampler {
69              //     (usually not to be overriden by descendant)              //     (usually not to be overriden by descendant)
70    
71              /**              /**
72               * Connect given sampler engine with this MIDI input device.               * Connect given sampler engine channel with this MIDI input
73               * The engine can either be connected to one specific MIDI               * device. The engine channel can either be connected to one
74               * channel or all MIDI channels. If an engine gets connected               * specific MIDI channel or all MIDI channels. If an engine
75               * twice to this MIDI input device, then the engine's old               * channel gets connected twice to this MIDI input device, then
76               * connection will be detached (no matter on which MIDI channel).               * the engine's old connection will be detached (no matter on
77                 * which MIDI channel).
78               *               *
79               * @param pEngine     - sampler engine               * @param pEngineChannel - sampler engine
80               * @param MidiChannel - MIDI channel to connect to               * @param MidiChannel - MIDI channel to connect to
81               * @throws MidiInputException  if MidiChannel argument invalid               * @throws MidiInputException  if MidiChannel argument invalid
82               */               */
83              void Connect(EngineChannel* pEngineChannel, midi_chan_t MidiChannel);              void Connect(EngineChannel* pEngineChannel, midi_chan_t MidiChannel);
84    
85              /**              /**
86               * Disconnect given sampler engine from this MIDI input device.               * Disconnect given sampler engine channel from this MIDI input
87               * If the given engine was not connected with this device,               * device. If the given engine channel was not connected with
88               * nothing happens.               * this device, nothing happens.
89               *               *
90               * @param pEngine - sampler engine               * @param pEngineChannel - sampler engine
91               */               */
92              void Disconnect(EngineChannel* pEngineChannel);              void Disconnect(EngineChannel* pEngineChannel);
93    
# Line 125  namespace LinuxSampler { Line 107  namespace LinuxSampler {
107               */               */
108              std::map<String,DeviceRuntimeParameter*> PortParameters();              std::map<String,DeviceRuntimeParameter*> PortParameters();
109    
110                /**
111                 * Registers that an engine wants to have sysex messages.
112                 */
113                static void AddSysexListener(Engine* engine);
114    
115                /**
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    
124                /**
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    
132                /**
133                 * Disconnect the previously connected virtual MIDI device.
134                 */
135                void Disconnect(VirtualMidiDevice* pDevice);
136    
137    
138              /////////////////////////////////////////////////////////////////              /////////////////////////////////////////////////////////////////
# Line 139  namespace LinuxSampler { Line 145  namespace LinuxSampler {
145               * event to be forwarded to all connected engines on the               * event to be forwarded to all connected engines on the
146               * corresponding MIDI channel.               * corresponding MIDI channel.
147               *               *
148                 * 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               * @param Key         - MIDI key number of the triggered key               * @param Key         - MIDI key number of the triggered key
153               * @param Velocity    - MIDI velocity of the triggered key               * @param Velocity    - MIDI velocity of the triggered key
154               * @param MidiChannel - MIDI channel on which event occured on               * @param MidiChannel - MIDI channel on which event occured on
# Line 148  namespace LinuxSampler { Line 158  namespace LinuxSampler {
158    
159              /**              /**
160               * Should be called by the implementing MIDI input device               * Should be called by the implementing MIDI input device
161                 * 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               * whenever a note off event arrived, this will cause the note               * whenever a note off event arrived, this will cause the note
180               * off event to be forwarded to all connected engines on the               * off event to be forwarded to all connected engines on the
181               * corresponding MIDI channel.               * corresponding MIDI channel.
182               *               *
183                 * 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               * @param Key         - MIDI key number of the released key               * @param Key         - MIDI key number of the released key
188               * @param Velocity    - MIDI velocity of the released key               * @param Velocity    - MIDI velocity of the released key
189               * @param MidiChannel - MIDI channel on which event occured on               * @param MidiChannel - MIDI channel on which event occured on
# Line 161  namespace LinuxSampler { Line 193  namespace LinuxSampler {
193    
194              /**              /**
195               * Should be called by the implementing MIDI input device               * Should be called by the implementing MIDI input device
196                 * 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               * whenever a pitchbend event arrived, this will cause the               * whenever a pitchbend event arrived, this will cause the
215               * pitchbend event to be forwarded to all connected engines.               * pitchbend event to be forwarded to all connected engines.
216               *               *
217                 * 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               * @param Pitch       - MIDI pitch value               * @param Pitch       - MIDI pitch value
222               * @param MidiChannel - MIDI channel on which event occured on               * @param MidiChannel - MIDI channel on which event occured on
223               *                      (low level indexing, means 0..15)               *                      (low level indexing, means 0..15)
# Line 172  namespace LinuxSampler { Line 226  namespace LinuxSampler {
226    
227              /**              /**
228               * Should be called by the implementing MIDI input device               * Should be called by the implementing MIDI input device
229                 * 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               * whenever a control change event arrived, this will cause the               * whenever a control change event arrived, this will cause the
246               * control change event to be forwarded to all engines on the               * control change event to be forwarded to all engines on the
247               * corresponding MIDI channel.               * corresponding MIDI channel.
248               *               *
249                 * 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               * @param Controller  - MIDI controller number               * @param Controller  - MIDI controller number
254               * @param Value       - MIDI control change value               * @param Value       - MIDI control change value
255               * @param MidiChannel - MIDI channel on which event occured on               * @param MidiChannel - MIDI channel on which event occured on
# Line 185  namespace LinuxSampler { Line 259  namespace LinuxSampler {
259    
260              /**              /**
261               * Should be called by the implementing MIDI input device               * Should be called by the implementing MIDI input device
262               * whenever a program change event arrived, this will cause the               * whenever a control change event arrived, this will cause the
263               * appropriate sampler channel to be connected with this MIDI               * control change event to be forwarded to all engines on the
264               * device.               * corresponding MIDI channel.
265               *               *
266               * For example consider a program change event on MIDI channel               * This method is meant for offline rendering and / or in case the
267               * 3 for program number 18. This would cause this MIDI input               * exact fragment position of the event is already known.
268               * device to be connected to sampler channel 18 and would cause               *
269               * sampler channel 18 to listen to MIDI channel 3.               * @param Controller  - MIDI controller number
270               *               * @param Value       - MIDI control change value
271               * This is the current, general implementation of program               * @param MidiChannel - MIDI channel on which event occured on
272               * change events. It might change in future, e.g to allow               *                      (low level indexing, means 0..15)
273               * sampler engines to allow by themselfes how to act on a               * @param FragmentPos - event's sample point position in the
274               * program change event.               *                      current audio fragment
275               *               */
276               * @param Program     - sampler channel to connect to this MIDI              void DispatchControlChange(uint8_t Controller, uint8_t Value, uint MidiChannel, int32_t FragmentPos);
277               *                      input device  
278               * @param MidiChannel - MIDI channel on which sampler channel              /**
279               *                      \a Program should listen to               * Should be called by the implementing MIDI input device
280                 * 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                 *
287                 * @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                 *
293                 * @param Program     - MIDI program change number
294                 * @param MidiChannel - MIDI channel on which this program
295                 *                      change occured
296                 * @see MidiInstrumentMapper
297               */               */
298              void DispatchProgramChange(uint8_t Program, uint MidiChannel);              void DispatchProgramChange(uint8_t Program, uint MidiChannel);
299    
300                void DispatchBankSelectMsb(uint8_t BankMsb, uint MidiChannel);
301    
302                void DispatchBankSelectLsb(uint8_t BankLsb, uint MidiChannel);
303    
304              /**              /**
305               * Should be called by the implementing MIDI input device               * Should be called by the implementing MIDI input device
306               * whenever a system exclusive message arrived, this will cause               * whenever a system exclusive message arrived, this will cause
# Line 216  namespace LinuxSampler { Line 311  namespace LinuxSampler {
311               */               */
312              void DispatchSysex(void* pData, uint Size);              void DispatchSysex(void* pData, uint Size);
313    
314                /**
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                 * @param FragmentPos - event's sample point position in the
320                 *                      current audio fragment
321                 */
322                void DispatchRaw(uint8_t* pData, int32_t FragmentPos);
323    
324          protected:          protected:
325              MidiInputDevice* pDevice;              MidiInputDevice* pDevice;
326              int portNumber;              int portNumber;
327              std::map<String,DeviceRuntimeParameter*> Parameters;  ///< All port parameters.              std::map<String,DeviceRuntimeParameter*> Parameters;  ///< All port parameters.
328              std::set<EngineChannel*> 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.              typedef std::set<EngineChannel*> MidiChannelMap_t[17];
329                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.
330                SynchronizedConfig<MidiChannelMap_t>::Reader MidiChannelMapReader; ///< MIDI thread access to MidiChannelMap
331              Mutex MidiChannelMapMutex; ///< Used to protect the MidiChannelMap from being used at the same time by different threads.              Mutex MidiChannelMapMutex; ///< Used to protect the MidiChannelMap from being used at the same time by different threads.
332                SynchronizedConfig<std::set<Engine*> >::Reader SysexListenersReader; ///< MIDI thread access to SysexListeners
333                SynchronizedConfig<std::vector<VirtualMidiDevice*> > virtualMidiDevices;
334                SynchronizedConfig<std::vector<VirtualMidiDevice*> >::Reader virtualMidiDevicesReader;
335                Mutex virtualMidiDevicesMutex;
336    
337              /**              /**
338               * Constructor               * Constructor
# Line 234  namespace LinuxSampler { Line 345  namespace LinuxSampler {
345              virtual ~MidiInputPort();              virtual ~MidiInputPort();
346    
347              friend class MidiInputDevice;              friend class MidiInputDevice;
348                
349          private:          private:
350              EngineChannel* pPreviousProgramChangeEngineChannel; ///< Points to the engine channel which was connected by the previous DispatchProgramChange() call.              static SynchronizedConfig<std::set<Engine*> > SysexListeners; ///< All engines that are listening to sysex messages.
351      };      };
352    
353  } // namsepace LinuxSampler  } // namsepace LinuxSampler

Legend:
Removed from v.551  
changed lines
  Added in v.1765

  ViewVC Help
Powered by ViewVC