/[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 675 - (show annotations) (download) (as text)
Wed Jun 22 22:09:28 2005 UTC (18 years, 10 months ago) by schoenebeck
File MIME type: text/x-c++hdr
File size: 10177 byte(s)
* update MIDI channel info on program change

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

  ViewVC Help
Powered by ViewVC