/[svn]/linuxsampler/trunk/src/engines/EngineChannel.h
ViewVC logotype

Contents of /linuxsampler/trunk/src/engines/EngineChannel.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1686 - (show annotations) (download) (as text)
Thu Feb 14 14:58:50 2008 UTC (12 years, 5 months ago) by schoenebeck
File MIME type: text/x-c++hdr
File size: 13791 byte(s)
* added new LSCP event "CHANNEL_MIDI" which can be used by frontends to
  react on MIDI data arriving on certain sampler channels (so far only
  Note-On and Note-Off events are sent via this LSCP event)
* bumped LSCP compliance version to 1.4
* bumped LS version to 0.5.1.3cvs

1 /***************************************************************************
2 * *
3 * Copyright (C) 2005 - 2008 Christian Schoenebeck *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the Free Software *
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, *
18 * MA 02111-1307 USA *
19 ***************************************************************************/
20
21 #ifndef __LS_ENGINECHANNEL_H__
22 #define __LS_ENGINECHANNEL_H__
23
24 #include "../EventListeners.h"
25 #include "../drivers/audio/AudioOutputDevice.h"
26 #include "../drivers/midi/midi.h"
27 #include "../drivers/midi/MidiInputDevice.h"
28 #include "../drivers/midi/MidiInputPort.h"
29 #include "../drivers/midi/VirtualMidiDevice.h"
30 #include "Engine.h"
31 #include "FxSend.h"
32
33 namespace LinuxSampler {
34
35 // just symbol prototyping
36 class AudioOutputDevice;
37 class MidiInputPort;
38 class FxSend;
39
40
41 /** @brief Channel Interface for LinuxSampler Sampler Engines
42 *
43 * Every sampler engine can be used on several sampler channels and
44 * usually the same Engine instance is used on multiple sampler
45 * channels. For this every sampler engine must also implement a class
46 * which handles all channel dependant parameters and channel
47 * dependant execution code.
48 *
49 * This abstract base interface class defines all mandatory methods
50 * which have to be implemented by all engine channel implementations.
51 */
52 class EngineChannel {
53 public:
54
55 /////////////////////////////////////////////////////////////////
56 // abstract methods
57 // (these have to be implemented by the descendant)
58
59 virtual void PrepareLoadInstrument(const char* FileName, uint Instrument) = 0;
60 virtual void LoadInstrument() = 0;
61 virtual void Reset() = 0;
62 virtual void SendNoteOn(uint8_t Key, uint8_t Velocity) = 0;
63 virtual void SendNoteOn(uint8_t Key, uint8_t Velocity, int32_t FragmentPos) = 0;
64 virtual void SendNoteOff(uint8_t Key, uint8_t Velocity) = 0;
65 virtual void SendNoteOff(uint8_t Key, uint8_t Velocity, int32_t FragmentPos) = 0;
66 virtual void SendPitchbend(int Pitch) = 0;
67 virtual void SendPitchbend(int Pitch, int32_t FragmentPos) = 0;
68 virtual void SendControlChange(uint8_t Controller, uint8_t Value) = 0;
69 virtual void SendControlChange(uint8_t Controller, uint8_t Value, int32_t FragmentPos) = 0;
70 virtual bool StatusChanged(bool bNewStatus = false) = 0;
71 virtual float Volume() = 0;
72 virtual void Volume(float f) = 0;
73 virtual uint Channels() = 0;
74 virtual void Connect(AudioOutputDevice* pAudioOut) = 0;
75 virtual void DisconnectAudioOutputDevice() = 0;
76 virtual AudioOutputDevice* GetAudioOutputDevice() = 0;
77 virtual void SetOutputChannel(uint EngineAudioChannel, uint AudioDeviceChannel) = 0;
78 virtual int OutputChannel(uint EngineAudioChannel) = 0;
79 virtual void Connect(MidiInputPort* pMidiPort, midi_chan_t MidiChannel) = 0;
80 virtual void DisconnectMidiInputPort() = 0;
81 virtual MidiInputPort* GetMidiInputPort() = 0;
82 virtual midi_chan_t MidiChannel() = 0;
83 virtual String InstrumentFileName() = 0;
84 virtual String InstrumentName() = 0;
85 virtual int InstrumentIndex() = 0;
86 virtual int InstrumentStatus() = 0;
87 virtual Engine* GetEngine() = 0;
88 virtual String EngineName() = 0;
89 virtual FxSend* AddFxSend(uint8_t MidiCtrl, String Name = "") throw (Exception) = 0;
90 virtual FxSend* GetFxSend(uint FxSendIndex) = 0;
91 virtual uint GetFxSendCount() = 0;
92 virtual void RemoveFxSend(FxSend* pFxSend) = 0;
93 virtual void Connect(VirtualMidiDevice* pDevice) = 0;
94 virtual void Disconnect(VirtualMidiDevice* pDevice) = 0;
95
96
97 /////////////////////////////////////////////////////////////////
98 // normal methods
99 // (usually not to be overridden by descendant)
100
101 /**
102 * Sets the mute state of this channel.
103 *
104 * @param state - specifies the mute state of this sampler channel.
105 * @throws Exception - if state does not contain valid
106 * value.
107 */
108 void SetMute(int state) throw (Exception);
109
110 /**
111 * Determines whether this channel is muted.
112 *
113 * @returns 1 if the channel is muted, 0 if the channel is not muted
114 * and -1 if the channel is muted because of presence of at least
115 * one solo channel.
116 */
117 int GetMute();
118
119 /**
120 * Sets the solo state of this channel.
121 *
122 * @param solo - specifies whether this is a solo channel.
123 */
124 void SetSolo(bool solo);
125
126 /**
127 * Determines whether this is a solo channel.
128 *
129 * @returns true if this is a solo channel, false otherwise.
130 */
131 bool GetSolo();
132
133 /**
134 * Returns current MIDI program (change) number of this
135 * EngineChannel.
136 */
137 uint8_t GetMidiProgram();
138
139 /**
140 * Change EngineChannel's MIDI program.
141 */
142 void SetMidiProgram(uint8_t Program);
143
144 /**
145 * Returns current MIDI bank MSB (coarse) number of this
146 * EngineChannel.
147 */
148 uint8_t GetMidiBankMsb();
149
150 /**
151 * Change current MIDI bank MSB (coarse) number of this
152 * EngineChannel.
153 */
154 void SetMidiBankMsb(uint8_t BankMSB);
155
156 /**
157 * Returns current MIDI bank LSB (fine) number of this
158 * EngineChannel.
159 */
160 uint8_t GetMidiBankLsb();
161
162 /**
163 * Change current MIDI bank LSB (fine) number of this
164 * EngineChannel.
165 */
166 void SetMidiBankLsb(uint8_t BankLSB);
167
168 /**
169 * Returns true if this EngineChannel is using no MIDI
170 * instrument map at all, that is if it will ignore all MIDI
171 * program change messages.
172 *
173 * @see UsesDefaultMidiInstrumentMap()
174 * @see GetMidiInstrumentMap()
175 */
176 bool UsesNoMidiInstrumentMap();
177
178 /**
179 * Returns true if this EngineChannel is using the default MIDI
180 * instrument map for handling MIDI program changes.
181 *
182 * @see UsesNoMidiInstrumentMap()
183 * @see GetMidiInstrumentMap()
184 */
185 bool UsesDefaultMidiInstrumentMap();
186
187 /**
188 * Returns ID of the MIDI instrument map currently used by this
189 * EngineChannel to handle MIDI program changes. You should
190 * always call @c UsesNoMidiInstrumentMap() and
191 * @c UsesDefaultMidiInstrumentMap() before calling this method
192 * to check if this EngineChannel is probably using the default
193 * map or no map at all, because in these two particular cases
194 * this method would throw an exception!
195 *
196 * @throws Exception - if EngineChannel is set to no map at all
197 * or is set to the default map
198 * @see UsesNoMidiInstrumentMap()
199 * @see UsesDefaultMidiInstrumentMap()
200 */
201 int GetMidiInstrumentMap() throw (Exception);
202
203 /**
204 * Let this EngineChannel use no MIDI instrument map at all,
205 * that is to let it ignore all MIDI program change messages.
206 *
207 * @see SetMidiInstrumentMapToDefault()
208 * @see SetMidiInstrumentMap()
209 */
210 void SetMidiInstrumentMapToNone();
211
212 /**
213 * Let this EngineChannel use the default MIDI instrument map to
214 * handle MIDI program changes.
215 *
216 * @see SetMidiInstrumentMapToNone()
217 * @see SetMidiInstrumentMap()
218 */
219 void SetMidiInstrumentMapToDefault();
220
221 /**
222 * Set a specific MIDI instrument map this EngineChannel should
223 * use to handle MIDI program changes.
224 *
225 * @see SetMidiInstrumentMapToNone()
226 * @see SetMidiInstrumentMapToDefault()
227 *
228 * @throws Exception - in case given map does not exist
229 */
230 void SetMidiInstrumentMap(int MidiMap) throw (Exception);
231
232 /**
233 * Set MIDI Registered Parameter Number (RPN) Controller
234 * (upper 8 bits / coarse).
235 */
236 void SetMidiRpnControllerMsb(uint8_t CtrlMSB);
237
238 /**
239 * Set MIDI Registered Parameter Number (RPN) Controller
240 * (lower 8 bits / fine).
241 */
242 void SetMidiRpnControllerLsb(uint8_t CtrlLSB);
243
244 /**
245 * Reset to no RPN controller currently selected.
246 */
247 void ResetMidiRpnController();
248
249 /**
250 * Registers the specified listener to be notified when the number
251 * of effect sends on this channel is changed.
252 */
253 void AddFxSendCountListener(FxSendCountListener* l);
254
255 /**
256 * Removes the specified listener.
257 */
258 void RemoveFxSendCountListener(FxSendCountListener* l);
259
260 /**
261 * Removes all listeners.
262 */
263 void RemoveAllFxSendCountListeners();
264
265 /**
266 * Get currently selected MIDI Registered Parameter Number
267 * (RPN) Controller, this method will return the already merged
268 * value (MSB and LSB value).
269 *
270 * @e WARNING: you have to call @c ResetMidiRpnController()
271 * after using this value, otherwise all subsequent MIDI CC #6
272 * (Data) messages are interpreted as RPN controller value
273 * messages.
274 *
275 * @returns currently selected RPN controller number, a negative
276 * value if no RPN controller currently selected
277 */
278 int GetMidiRpnController();
279
280 /**
281 * Gets the current number of active voices.
282 */
283 uint GetVoiceCount();
284
285 /**
286 * Sets the current number of active voices.
287 */
288 void SetVoiceCount(uint Voices);
289
290 /**
291 * Gets the current number of active disk streams.
292 */
293 uint GetDiskStreamCount();
294
295 /**
296 * Sets the current number of active disk streams.
297 */
298 void SetDiskStreamCount(uint Streams);
299
300 int iSamplerChannelIndex; ///< FIXME: nasty hack, might be removed (should be 'virtual EngineChannel* EngineChannel() = 0;', but due to cyclic dependencies only a void* solution would be possible ATM)
301
302 protected:
303 EngineChannel();
304 virtual ~EngineChannel() {}; // MUST only be destroyed by EngineChannelFactory
305
306 /**
307 * Notifies listeners that the number of effect sends
308 * on a this channel is changed.
309 * @param ChannelId The numerical ID of the sampler channel.
310 * @param NewCount The new number of sampler channels.
311 */
312 void fireFxSendCountChanged(int ChannelId, int NewCount);
313
314 friend class EngineChannelFactory;
315
316 private:
317 int iMute;
318 bool bSolo;
319 uint8_t uiMidiProgram;
320 uint8_t uiMidiBankMsb;
321 uint8_t uiMidiBankLsb;
322 uint8_t uiMidiRpnMsb; ///< MIDI Registered Parameter Number (upper 8 bits / coarse)
323 uint8_t uiMidiRpnLsb; ///< MIDI Registered Parameter Number (lower 8 bits / fine)
324 bool bMidiBankMsbReceived;
325 bool bMidiBankLsbReceived;
326 bool bProgramChangeReceived;
327 bool bMidiRpnReceived;
328 int iMidiInstrumentMap;
329 uint uiVoiceCount;
330 uint uiDiskStreamCount;
331 ListenerList<FxSendCountListener*> llFxSendCountListeners;
332 };
333
334 } // namespace LinuxSampler
335
336 #endif // __LS_ENGINECHANNEL_H__

  ViewVC Help
Powered by ViewVC