/[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 551 - (hide annotations) (download) (as text)
Tue May 17 18:16:54 2005 UTC (18 years, 11 months ago) by schoenebeck
File MIME type: text/x-c++hdr
File size: 10855 byte(s)
* Implemented MIDI program change as general, engine independant solution.
  The program number will determine the sampler channel to which the MIDI
  device will be connected to and the given MIDI channel defines on which
  MIDI channel that sampler channel should listen to. Also the program
  change will disconnect probably established connection from the previous
  program change event.

1 schoenebeck 221 /***************************************************************************
2     * *
3     * LinuxSampler - modular, streaming capable sampler *
4     * *
5     * Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck *
6 schoenebeck 411 * Copyright (C) 2005 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 221 #include "../../common/LinuxSamplerException.h"
30     #include "../DeviceParameter.h"
31     #include "MidiInputDevice.h"
32 schoenebeck 411 #include "../../engines/common/EngineChannel.h"
33 schoenebeck 221
34     namespace LinuxSampler {
35    
36     // just symbol prototyping
37     class MidiInputDevice;
38    
39     class MidiInputPort {
40     public:
41    
42     /////////////////////////////////////////////////////////////////
43     // type definitions
44    
45     /**
46     * MIDI channels
47     */
48     enum midi_chan_t {
49 schoenebeck 274 midi_chan_1 = 0,
50     midi_chan_2 = 1,
51     midi_chan_3 = 2,
52     midi_chan_4 = 3,
53     midi_chan_5 = 4,
54     midi_chan_6 = 5,
55     midi_chan_7 = 6,
56     midi_chan_8 = 7,
57     midi_chan_9 = 8,
58     midi_chan_10 = 9,
59     midi_chan_11 = 10,
60     midi_chan_12 = 11,
61     midi_chan_13 = 12,
62     midi_chan_14 = 13,
63     midi_chan_15 = 14,
64     midi_chan_16 = 15,
65     midi_chan_all = 16
66 schoenebeck 221 };
67    
68     /** MIDI Port Parameter 'NAME'
69     *
70     * Used to assign an arbitrary name to the MIDI port.
71     */
72     class ParameterName : public DeviceRuntimeParameterString {
73     public:
74     ParameterName(MidiInputPort* pPort);
75     ParameterName(MidiInputPort* pPort, String val);
76     virtual String Description();
77     virtual bool Fix();
78     virtual std::vector<String> PossibilitiesAsString();
79     virtual void OnSetValue(String s) throw (LinuxSamplerException);
80     protected:
81     MidiInputPort* pPort;
82     };
83    
84    
85    
86     /////////////////////////////////////////////////////////////////
87     // normal methods
88     // (usually not to be overriden by descendant)
89    
90     /**
91     * Connect given sampler engine with this MIDI input device.
92     * The engine can either be connected to one specific MIDI
93     * channel or all MIDI channels. If an engine gets connected
94     * twice to this MIDI input device, then the engine's old
95     * connection will be detached (no matter on which MIDI channel).
96     *
97     * @param pEngine - sampler engine
98     * @param MidiChannel - MIDI channel to connect to
99     * @throws MidiInputException if MidiChannel argument invalid
100     */
101 schoenebeck 411 void Connect(EngineChannel* pEngineChannel, midi_chan_t MidiChannel);
102 schoenebeck 221
103     /**
104     * Disconnect given sampler engine from this MIDI input device.
105 schoenebeck 551 * If the given engine was not connected with this device,
106     * nothing happens.
107 schoenebeck 221 *
108     * @param pEngine - sampler engine
109     */
110 schoenebeck 411 void Disconnect(EngineChannel* pEngineChannel);
111 schoenebeck 221
112     /**
113     * Return MIDI device where this MIDI port belongs to.
114     */
115     MidiInputDevice* GetDevice();
116    
117     /**
118     * Return port number with which this MIDI port is registered to
119     * the MIDI device.
120     */
121     uint GetPortNumber();
122    
123     /**
124     * Return all parameter settings of this MIDI port.
125     */
126     std::map<String,DeviceRuntimeParameter*> PortParameters();
127    
128    
129    
130    
131    
132     /////////////////////////////////////////////////////////////////
133     // dispatch methods
134     // (should be called by the MidiInputDevice descendant on events)
135    
136     /**
137     * Should be called by the implementing MIDI input device
138     * whenever a note on event arrived, this will cause the note on
139     * event to be forwarded to all connected engines on the
140     * corresponding MIDI channel.
141     *
142     * @param Key - MIDI key number of the triggered key
143     * @param Velocity - MIDI velocity of the triggered key
144     * @param MidiChannel - MIDI channel on which event occured on
145 schoenebeck 274 * (low level indexing, means 0..15)
146 schoenebeck 221 */
147     void DispatchNoteOn(uint8_t Key, uint8_t Velocity, uint MidiChannel);
148    
149     /**
150     * Should be called by the implementing MIDI input device
151     * whenever a note off event arrived, this will cause the note
152     * off event to be forwarded to all connected engines on the
153     * corresponding MIDI channel.
154     *
155     * @param Key - MIDI key number of the released key
156     * @param Velocity - MIDI velocity of the released key
157     * @param MidiChannel - MIDI channel on which event occured on
158 schoenebeck 274 * (low level indexing, means 0..15)
159 schoenebeck 221 */
160     void DispatchNoteOff(uint8_t Key, uint8_t Velocity, uint MidiChannel);
161    
162     /**
163     * Should be called by the implementing MIDI input device
164     * whenever a pitchbend event arrived, this will cause the
165     * pitchbend event to be forwarded to all connected engines.
166     *
167     * @param Pitch - MIDI pitch value
168     * @param MidiChannel - MIDI channel on which event occured on
169 schoenebeck 274 * (low level indexing, means 0..15)
170 schoenebeck 221 */
171     void DispatchPitchbend(int Pitch, uint MidiChannel);
172    
173     /**
174     * Should be called by the implementing MIDI input device
175     * whenever a control change event arrived, this will cause the
176     * control change event to be forwarded to all engines on the
177     * corresponding MIDI channel.
178     *
179     * @param Controller - MIDI controller number
180     * @param Value - MIDI control change value
181     * @param MidiChannel - MIDI channel on which event occured on
182 schoenebeck 274 * (low level indexing, means 0..15)
183 schoenebeck 221 */
184     void DispatchControlChange(uint8_t Controller, uint8_t Value, uint MidiChannel);
185    
186 schoenebeck 244 /**
187     * Should be called by the implementing MIDI input device
188 schoenebeck 551 * whenever a program change event arrived, this will cause the
189     * appropriate sampler channel to be connected with this MIDI
190     * device.
191     *
192     * For example consider a program change event on MIDI channel
193     * 3 for program number 18. This would cause this MIDI input
194     * device to be connected to sampler channel 18 and would cause
195     * sampler channel 18 to listen to MIDI channel 3.
196     *
197     * This is the current, general implementation of program
198     * change events. It might change in future, e.g to allow
199     * sampler engines to allow by themselfes how to act on a
200     * program change event.
201     *
202     * @param Program - sampler channel to connect to this MIDI
203     * input device
204     * @param MidiChannel - MIDI channel on which sampler channel
205     * \a Program should listen to
206     */
207     void DispatchProgramChange(uint8_t Program, uint MidiChannel);
208    
209     /**
210     * Should be called by the implementing MIDI input device
211 schoenebeck 244 * whenever a system exclusive message arrived, this will cause
212     * the message to be forwarded to all connected engines.
213     *
214     * @param pData - pointer to the sysex data
215     * @param Size - length of the sysex data (in bytes)
216     */
217     void DispatchSysex(void* pData, uint Size);
218    
219 schoenebeck 221 protected:
220     MidiInputDevice* pDevice;
221     int portNumber;
222     std::map<String,DeviceRuntimeParameter*> Parameters; ///< All port parameters.
223 schoenebeck 411 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.
224 schoenebeck 551 Mutex MidiChannelMapMutex; ///< Used to protect the MidiChannelMap from being used at the same time by different threads.
225 schoenebeck 221
226     /**
227     * Constructor
228     */
229     MidiInputPort(MidiInputDevice* pDevice, int portNumber);
230    
231     /**
232     * Destructor
233     */
234     virtual ~MidiInputPort();
235    
236     friend class MidiInputDevice;
237 schoenebeck 551
238     private:
239     EngineChannel* pPreviousProgramChangeEngineChannel; ///< Points to the engine channel which was connected by the previous DispatchProgramChange() call.
240 schoenebeck 221 };
241    
242     } // namsepace LinuxSampler
243    
244     #endif // __LS_MIDIINPUTPORT_H__

  ViewVC Help
Powered by ViewVC