/[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 2559 - (show annotations) (download) (as text)
Sun May 18 17:38:25 2014 UTC (9 years, 11 months ago) by schoenebeck
File MIME type: text/x-c++hdr
File size: 16447 byte(s)
* Aftertouch: extended API to explicitly handle channel pressure and
  polyphonic key pressure events (so far polyphonic pressure was not
  supported at all, and channel pressure was rerouted as CC128 but not
  used so far).
* Gig Engine: Fixed support for 'aftertouch' attenuation controller.
* Bumped version (1.0.0.svn39).

1 /***************************************************************************
2 * *
3 * Copyright (C) 2005 - 2014 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 Sampler;
37 class SamplerChannel;
38 class AudioOutputDevice;
39 class MidiInputPort;
40 class FxSend;
41
42
43 /** @brief Channel Interface for LinuxSampler Sampler Engines
44 *
45 * Every sampler engine can be used on several sampler channels and
46 * usually the same Engine instance is used on multiple sampler
47 * channels. For this every sampler engine must also implement a class
48 * which handles all channel dependant parameters and channel
49 * dependant execution code.
50 *
51 * This abstract base interface class defines all mandatory methods
52 * which have to be implemented by all engine channel implementations.
53 */
54 class EngineChannel {
55 public:
56
57 /////////////////////////////////////////////////////////////////
58 // abstract methods
59 // (these have to be implemented by the descendant)
60
61 // general sampler part management
62 virtual void Reset() = 0;
63 virtual void SendNoteOn(uint8_t Key, uint8_t Velocity, uint8_t MidiChannel) = 0;
64 virtual void SendNoteOn(uint8_t Key, uint8_t Velocity, uint8_t MidiChannel, int32_t FragmentPos) = 0;
65 virtual void SendNoteOff(uint8_t Key, uint8_t Velocity, uint8_t MidiChannel) = 0;
66 virtual void SendNoteOff(uint8_t Key, uint8_t Velocity, uint8_t MidiChannel, int32_t FragmentPos) = 0;
67 virtual void SendPitchbend(int Pitch, uint8_t MidiChannel) = 0;
68 virtual void SendPitchbend(int Pitch, uint8_t MidiChannel, int32_t FragmentPos) = 0;
69 virtual void SendControlChange(uint8_t Controller, uint8_t Value, uint8_t MidiChannel) = 0;
70 virtual void SendControlChange(uint8_t Controller, uint8_t Value, uint8_t MidiChannel, int32_t FragmentPos) = 0;
71 virtual void SendProgramChange(uint8_t Program) = 0;
72 virtual void SendChannelPressure(uint8_t Value, uint8_t MidiChannel) = 0;
73 virtual void SendChannelPressure(uint8_t Value, uint8_t MidiChannel, int32_t FragmentPos) = 0;
74 virtual void SendPolyphonicKeyPressure(uint8_t Key, uint8_t Value, uint8_t MidiChannel) = 0;
75 virtual void SendPolyphonicKeyPressure(uint8_t Key, uint8_t Value, uint8_t MidiChannel, int32_t FragmentPos) = 0;
76 virtual bool StatusChanged(bool bNewStatus = false) = 0;
77 virtual float Volume() = 0;
78 virtual void Volume(float f) = 0;
79 virtual float Pan() = 0;
80 virtual void Pan(float f) = 0;
81 virtual uint Channels() = 0;
82
83 // audio driver management
84 virtual void Connect(AudioOutputDevice* pAudioOut) = 0;
85 virtual void DisconnectAudioOutputDevice() = 0;
86 virtual AudioOutputDevice* GetAudioOutputDevice() = 0;
87 virtual void SetOutputChannel(uint EngineAudioChannel, uint AudioDeviceChannel) = 0;
88 virtual int OutputChannel(uint EngineAudioChannel) = 0;
89
90 // MIDI driver management
91 virtual void Connect(MidiInputPort* pMidiPort) = 0;
92 virtual void Disconnect(MidiInputPort* pMidiPort) = 0;
93 virtual void DisconnectAllMidiInputPorts() = 0;
94 virtual uint GetMidiInputPortCount() = 0;
95 virtual MidiInputPort* GetMidiInputPort(uint index) = 0;
96 virtual midi_chan_t MidiChannel() = 0;
97 virtual void SetMidiChannel(midi_chan_t MidiChannel) = 0;
98 // (deprecated MIDI driver management methods)
99 virtual void Connect(MidiInputPort* pMidiPort, midi_chan_t MidiChannel) DEPRECATED_API = 0;
100 virtual void DisconnectMidiInputPort() DEPRECATED_API = 0;
101 virtual MidiInputPort* GetMidiInputPort() DEPRECATED_API = 0;
102
103 // virtual MIDI driver management (i.e. virtual on-screen MIDI keyboards)
104 virtual void Connect(VirtualMidiDevice* pDevice) = 0;
105 virtual void Disconnect(VirtualMidiDevice* pDevice) = 0;
106
107 // instrument (sound file) management
108 virtual void PrepareLoadInstrument(const char* FileName, uint Instrument) = 0;
109 virtual void LoadInstrument() = 0;
110 virtual String InstrumentFileName() = 0; ///< Returns the file name of the currently loaded instrument. Equivalent as calling InstrumentFileName(0).
111 virtual String InstrumentFileName(int index);
112 virtual String InstrumentName() = 0;
113 virtual int InstrumentIndex() = 0;
114 virtual int InstrumentStatus() = 0;
115
116 // sampler format / sampler engine implementation details
117 virtual Engine* GetEngine() = 0;
118 virtual String EngineName() = 0;
119
120 // effect routing
121 virtual FxSend* AddFxSend(uint8_t MidiCtrl, String Name = "") throw (Exception) = 0;
122 virtual FxSend* GetFxSend(uint FxSendIndex) = 0;
123 virtual uint GetFxSendCount() = 0;
124 virtual void RemoveFxSend(FxSend* pFxSend) = 0;
125
126
127 /////////////////////////////////////////////////////////////////
128 // normal methods
129 // (usually not to be overridden by descendant)
130
131 /**
132 * Sets the mute state of this channel.
133 *
134 * @param state - specifies the mute state of this sampler channel.
135 * @throws Exception - if state does not contain valid
136 * value.
137 */
138 void SetMute(int state) throw (Exception);
139
140 /**
141 * Determines whether this channel is muted.
142 *
143 * @returns 1 if the channel is muted, 0 if the channel is not muted
144 * and -1 if the channel is muted because of presence of at least
145 * one solo channel.
146 */
147 int GetMute();
148
149 /**
150 * Sets the solo state of this channel.
151 *
152 * @param solo - specifies whether this is a solo channel.
153 */
154 void SetSolo(bool solo);
155
156 /**
157 * Determines whether this is a solo channel.
158 *
159 * @returns true if this is a solo channel, false otherwise.
160 */
161 bool GetSolo();
162
163 /**
164 * Returns current MIDI program (change) number of this
165 * EngineChannel.
166 */
167 uint8_t GetMidiProgram();
168
169 /**
170 * Change EngineChannel's MIDI program.
171 */
172 void SetMidiProgram(uint8_t Program);
173
174 /**
175 * Returns current MIDI bank MSB (coarse) number of this
176 * EngineChannel.
177 */
178 uint8_t GetMidiBankMsb();
179
180 /**
181 * Change current MIDI bank MSB (coarse) number of this
182 * EngineChannel.
183 */
184 void SetMidiBankMsb(uint8_t BankMSB);
185
186 /**
187 * Returns current MIDI bank LSB (fine) number of this
188 * EngineChannel.
189 */
190 uint8_t GetMidiBankLsb();
191
192 /**
193 * Change current MIDI bank LSB (fine) number of this
194 * EngineChannel.
195 */
196 void SetMidiBankLsb(uint8_t BankLSB);
197
198 /**
199 * Returns true if this EngineChannel is using no MIDI
200 * instrument map at all, that is if it will ignore all MIDI
201 * program change messages.
202 *
203 * @see UsesDefaultMidiInstrumentMap()
204 * @see GetMidiInstrumentMap()
205 */
206 bool UsesNoMidiInstrumentMap();
207
208 /**
209 * Returns true if this EngineChannel is using the default MIDI
210 * instrument map for handling MIDI program changes.
211 *
212 * @see UsesNoMidiInstrumentMap()
213 * @see GetMidiInstrumentMap()
214 */
215 bool UsesDefaultMidiInstrumentMap();
216
217 /**
218 * Returns ID of the MIDI instrument map currently used by this
219 * EngineChannel to handle MIDI program changes. You should
220 * always call @c UsesNoMidiInstrumentMap() and
221 * @c UsesDefaultMidiInstrumentMap() before calling this method
222 * to check if this EngineChannel is probably using the default
223 * map or no map at all, because in these two particular cases
224 * this method would throw an exception!
225 *
226 * @throws Exception - if EngineChannel is set to no map at all
227 * or is set to the default map
228 * @see UsesNoMidiInstrumentMap()
229 * @see UsesDefaultMidiInstrumentMap()
230 */
231 int GetMidiInstrumentMap() throw (Exception);
232
233 /**
234 * Let this EngineChannel use no MIDI instrument map at all,
235 * that is to let it ignore all MIDI program change messages.
236 *
237 * @see SetMidiInstrumentMapToDefault()
238 * @see SetMidiInstrumentMap()
239 */
240 void SetMidiInstrumentMapToNone();
241
242 /**
243 * Let this EngineChannel use the default MIDI instrument map to
244 * handle MIDI program changes.
245 *
246 * @see SetMidiInstrumentMapToNone()
247 * @see SetMidiInstrumentMap()
248 */
249 void SetMidiInstrumentMapToDefault();
250
251 /**
252 * Set a specific MIDI instrument map this EngineChannel should
253 * use to handle MIDI program changes.
254 *
255 * @see SetMidiInstrumentMapToNone()
256 * @see SetMidiInstrumentMapToDefault()
257 *
258 * @throws Exception - in case given map does not exist
259 */
260 void SetMidiInstrumentMap(int MidiMap) throw (Exception);
261
262 /**
263 * Set MIDI Registered Parameter Number (RPN) Controller
264 * (upper 8 bits / coarse).
265 */
266 void SetMidiRpnControllerMsb(uint8_t CtrlMSB);
267
268 /**
269 * Set MIDI Registered Parameter Number (RPN) Controller
270 * (lower 8 bits / fine).
271 */
272 void SetMidiRpnControllerLsb(uint8_t CtrlLSB);
273
274 /**
275 * Reset to no RPN controller currently selected.
276 */
277 void ResetMidiRpnController();
278
279 /**
280 * Set MIDI Non-Registered Parameter Number (NRPN) Controller
281 * (upper 8 bits / coarse).
282 */
283 void SetMidiNrpnControllerMsb(uint8_t CtrlMSB);
284
285 /**
286 * Set MIDI Non-Registered Parameter Number (NRPN) Controller
287 * (lower 8 bits / fine).
288 */
289 void SetMidiNrpnControllerLsb(uint8_t CtrlLSB);
290
291 /**
292 * Reset to no NRPN controller currently selected.
293 */
294 void ResetMidiNrpnController();
295
296 /**
297 * Registers the specified listener to be notified when the number
298 * of effect sends on this channel is changed.
299 */
300 void AddFxSendCountListener(FxSendCountListener* l);
301
302 /**
303 * Removes the specified listener.
304 */
305 void RemoveFxSendCountListener(FxSendCountListener* l);
306
307 /**
308 * Removes all listeners.
309 */
310 void RemoveAllFxSendCountListeners();
311
312 /**
313 * Get currently selected MIDI Registered Parameter Number
314 * (RPN) Controller, this method will return the already merged
315 * value (MSB and LSB value).
316 *
317 * @e WARNING: you have to call @c ResetMidiRpnController()
318 * after using this value, otherwise all subsequent MIDI CC #6
319 * (Data) messages are interpreted as RPN controller value
320 * messages.
321 *
322 * @returns currently selected RPN controller number, a negative
323 * value if no RPN controller currently selected
324 */
325 int GetMidiRpnController();
326
327 /**
328 * Get currently selected MIDI Non-Registered Parameter Number
329 * (NRPN) Controller, this method will return the already merged
330 * value (MSB and LSB value).
331 *
332 * @e WARNING: you have to call @c ResetMidiNrpnController()
333 * after using this value, otherwise all subsequent MIDI CC #6
334 * (Data) messages are interpreted as NRPN controller value
335 * messages.
336 *
337 * @returns currently selected NRPN controller number, a negative
338 * value if no NRPN controller currently selected
339 */
340 int GetMidiNrpnController();
341
342 /**
343 * Gets the current number of active voices.
344 */
345 uint GetVoiceCount();
346
347 /**
348 * Sets the current number of active voices.
349 */
350 void SetVoiceCount(uint Voices);
351
352 /**
353 * Gets the current number of active disk streams.
354 */
355 uint GetDiskStreamCount();
356
357 /**
358 * Sets the current number of active disk streams.
359 */
360 void SetDiskStreamCount(uint Streams);
361
362 SamplerChannel* GetSamplerChannel();
363
364 void SetSamplerChannel(SamplerChannel* pChannel);
365
366 /** Returns the sampler to which this channel belongs */
367 Sampler* GetSampler();
368
369 /**
370 * Performs a program change on the channel.
371 *
372 * This method is not real-time safe.
373 */
374 void ExecuteProgramChange(uint32_t Program);
375
376 protected:
377 EngineChannel();
378 virtual ~EngineChannel(); // MUST only be destroyed by EngineChannelFactory
379
380 /**
381 * Notifies listeners that the number of effect sends
382 * on a this channel is changed.
383 * @param ChannelId The numerical ID of the sampler channel.
384 * @param NewCount The new number of sampler channels.
385 */
386 void fireFxSendCountChanged(int ChannelId, int NewCount);
387
388 friend class EngineChannelFactory;
389
390 private:
391 struct private_data_t;
392 private_data_t* const p;
393 };
394
395 } // namespace LinuxSampler
396
397 #endif // __LS_ENGINECHANNEL_H__

  ViewVC Help
Powered by ViewVC