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