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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1723 - (hide annotations) (download) (as text)
Sun Apr 20 08:53:39 2008 UTC (16 years ago) by schoenebeck
File MIME type: text/x-c++hdr
File size: 13876 byte(s)
* allow pan control of engine channels on C++ API level
* export denormals-are-zero mode feature to C++ API

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

  ViewVC Help
Powered by ViewVC