/[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 221 by schoenebeck, Fri Aug 20 17:25:19 2004 UTC revision 890 by schoenebeck, Sat Jul 1 13:43:04 2006 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, 2006 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 24  Line 25 
25  #define __LS_MIDIINPUTPORT_H__  #define __LS_MIDIINPUTPORT_H__
26    
27  #include "../../common/global.h"  #include "../../common/global.h"
28  #include "../../common/LinuxSamplerException.h"  #include "../../common/Mutex.h"
29    #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/Engine.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    
42      class MidiInputPort {      class MidiInputPort {
43          public:          public:
# Line 40  namespace LinuxSampler { Line 45  namespace LinuxSampler {
45              /////////////////////////////////////////////////////////////////              /////////////////////////////////////////////////////////////////
46              // type definitions              // type definitions
47    
             /**  
              * MIDI channels  
              */  
             enum midi_chan_t {  
                 midi_chan_all = 0,  
                 midi_chan_1   = 1,  
                 midi_chan_2   = 2,  
                 midi_chan_3   = 3,  
                 midi_chan_4   = 4,  
                 midi_chan_5   = 5,  
                 midi_chan_6   = 6,  
                 midi_chan_7   = 7,  
                 midi_chan_8   = 8,  
                 midi_chan_9   = 9,  
                 midi_chan_10  = 10,  
                 midi_chan_11  = 11,  
                 midi_chan_12  = 12,  
                 midi_chan_13  = 13,  
                 midi_chan_14  = 14,  
                 midi_chan_15  = 15,  
                 midi_chan_16  = 16  
             };  
   
48              /** MIDI Port Parameter 'NAME'              /** MIDI Port Parameter 'NAME'
49               *               *
50               * Used to assign an arbitrary name to the MIDI port.               * Used to assign an arbitrary name to the MIDI port.
# Line 74  namespace LinuxSampler { Line 56  namespace LinuxSampler {
56                      virtual String Description();                      virtual String Description();
57                      virtual bool   Fix();                      virtual bool   Fix();
58                      virtual std::vector<String> PossibilitiesAsString();                      virtual std::vector<String> PossibilitiesAsString();
59                      virtual void OnSetValue(String s) throw (LinuxSamplerException);                      virtual void OnSetValue(String s) throw (Exception);
60                  protected:                  protected:
61                      MidiInputPort* pPort;                      MidiInputPort* pPort;
62              };              };
# Line 96  namespace LinuxSampler { Line 78  namespace LinuxSampler {
78               * @param MidiChannel - MIDI channel to connect to               * @param MidiChannel - MIDI channel to connect to
79               * @throws MidiInputException  if MidiChannel argument invalid               * @throws MidiInputException  if MidiChannel argument invalid
80               */               */
81              void Connect(Engine* pEngine, midi_chan_t MidiChannel);              void Connect(EngineChannel* pEngineChannel, midi_chan_t MidiChannel);
82    
83              /**              /**
84               * Disconnect given sampler engine from this MIDI input device.               * Disconnect given sampler engine from this MIDI input device.
85                 * If the given engine was not connected with this device,
86                 * nothing happens.
87               *               *
88               * @param pEngine - sampler engine               * @param pEngine - sampler engine
89               */               */
90              void Disconnect(Engine* pEngine);              void Disconnect(EngineChannel* pEngineChannel);
91    
92              /**              /**
93               * Return MIDI device where this MIDI port belongs to.               * Return MIDI device where this MIDI port belongs to.
# Line 121  namespace LinuxSampler { Line 105  namespace LinuxSampler {
105               */               */
106              std::map<String,DeviceRuntimeParameter*> PortParameters();              std::map<String,DeviceRuntimeParameter*> PortParameters();
107    
108                /**
109                 * Registers that an engine wants to have sysex messages.
110                 */
111                static void AddSysexListener(Engine* engine);
112    
113                /**
114                 * Removes engine from list of engines getting sysex
115                 * messages.
116                 *
117                 * @returns true if engine was removed, false if it wasn't
118                 *          present in the list.
119                 */
120                static bool RemoveSysexListener(Engine* engine);
121    
122    
123              /////////////////////////////////////////////////////////////////              /////////////////////////////////////////////////////////////////
# Line 138  namespace LinuxSampler { Line 133  namespace LinuxSampler {
133               * @param Key         - MIDI key number of the triggered key               * @param Key         - MIDI key number of the triggered key
134               * @param Velocity    - MIDI velocity of the triggered key               * @param Velocity    - MIDI velocity of the triggered key
135               * @param MidiChannel - MIDI channel on which event occured on               * @param MidiChannel - MIDI channel on which event occured on
136                 *                      (low level indexing, means 0..15)
137               */               */
138              void DispatchNoteOn(uint8_t Key, uint8_t Velocity, uint MidiChannel);              void DispatchNoteOn(uint8_t Key, uint8_t Velocity, uint MidiChannel);
139    
# Line 150  namespace LinuxSampler { Line 146  namespace LinuxSampler {
146               * @param Key         - MIDI key number of the released key               * @param Key         - MIDI key number of the released key
147               * @param Velocity    - MIDI velocity of the released key               * @param Velocity    - MIDI velocity of the released key
148               * @param MidiChannel - MIDI channel on which event occured on               * @param MidiChannel - MIDI channel on which event occured on
149                 *                      (low level indexing, means 0..15)
150               */               */
151              void DispatchNoteOff(uint8_t Key, uint8_t Velocity, uint MidiChannel);              void DispatchNoteOff(uint8_t Key, uint8_t Velocity, uint MidiChannel);
152    
# Line 160  namespace LinuxSampler { Line 157  namespace LinuxSampler {
157               *               *
158               * @param Pitch       - MIDI pitch value               * @param Pitch       - MIDI pitch value
159               * @param MidiChannel - MIDI channel on which event occured on               * @param MidiChannel - MIDI channel on which event occured on
160                 *                      (low level indexing, means 0..15)
161               */               */
162              void DispatchPitchbend(int Pitch, uint MidiChannel);              void DispatchPitchbend(int Pitch, uint MidiChannel);
163    
# Line 172  namespace LinuxSampler { Line 170  namespace LinuxSampler {
170               * @param Controller  - MIDI controller number               * @param Controller  - MIDI controller number
171               * @param Value       - MIDI control change value               * @param Value       - MIDI control change value
172               * @param MidiChannel - MIDI channel on which event occured on               * @param MidiChannel - MIDI channel on which event occured on
173                 *                      (low level indexing, means 0..15)
174               */               */
175              void DispatchControlChange(uint8_t Controller, uint8_t Value, uint MidiChannel);              void DispatchControlChange(uint8_t Controller, uint8_t Value, uint MidiChannel);
176    
177                /**
178                 * Should be called by the implementing MIDI input device
179                 * whenever a program change event arrived, this will cause the
180                 * appropriate sampler channel to be connected with this MIDI
181                 * device.
182                 *
183                 * For example consider a program change event on MIDI channel
184                 * 3 for program number 18. This would cause this MIDI input
185                 * device to be connected to sampler channel 18 and would cause
186                 * sampler channel 18 to listen to MIDI channel 3.
187                 *
188                 * This is the current, general implementation of program
189                 * change events. It might change in future, e.g to allow
190                 * sampler engines to allow by themselfes how to act on a
191                 * program change event.
192                 *
193                 * @param Program     - sampler channel to connect to this MIDI
194                 *                      input device
195                 * @param MidiChannel - MIDI channel on which sampler channel
196                 *                      \a Program should listen to
197                 */
198                void DispatchProgramChange(uint8_t Program, uint MidiChannel);
199    
200                /**
201                 * Should be called by the implementing MIDI input device
202                 * whenever a system exclusive message arrived, this will cause
203                 * the message to be forwarded to all connected engines.
204                 *
205                 * @param pData - pointer to the sysex data
206                 * @param Size  - length of the sysex data (in bytes)
207                 */
208                void DispatchSysex(void* pData, uint Size);
209    
210          protected:          protected:
211              MidiInputDevice* pDevice;              MidiInputDevice* pDevice;
212              int portNumber;              int portNumber;
213              std::map<String,DeviceRuntimeParameter*> Parameters;  ///< All port parameters.              std::map<String,DeviceRuntimeParameter*> Parameters;  ///< All port parameters.
214              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.              typedef std::set<EngineChannel*> MidiChannelMap_t[17];
215                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.
216                SynchronizedConfig<MidiChannelMap_t>::Reader MidiChannelMapReader; ///< MIDI thread access to MidiChannelMap
217                Mutex MidiChannelMapMutex; ///< Used to protect the MidiChannelMap from being used at the same time by different threads.
218                SynchronizedConfig<std::set<Engine*> >::Reader SysexListenersReader; ///< MIDI thread access to SysexListeners
219    
220              /**              /**
221               * Constructor               * Constructor
# Line 192  namespace LinuxSampler { Line 228  namespace LinuxSampler {
228              virtual ~MidiInputPort();              virtual ~MidiInputPort();
229    
230              friend class MidiInputDevice;              friend class MidiInputDevice;
231    
232            private:
233                EngineChannel* pPreviousProgramChangeEngineChannel; ///< Points to the engine channel which was connected by the previous DispatchProgramChange() call.
234                static SynchronizedConfig<std::set<Engine*> > SysexListeners; ///< All engines that are listening to sysex messages.
235      };      };
236    
237  } // namsepace LinuxSampler  } // namsepace LinuxSampler

Legend:
Removed from v.221  
changed lines
  Added in v.890

  ViewVC Help
Powered by ViewVC