/[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 2500 - (hide annotations) (download) (as text)
Fri Jan 10 12:20:05 2014 UTC (10 years, 4 months ago) by schoenebeck
File MIME type: text/x-c++hdr
File size: 16011 byte(s)
* Added support for multiple MIDI input ports per sampler channel (added
  various new C++ API methods for this new feature/design, old C++ API
  methods are now marked as deprecated but should still provide full
  behavior backward compatibility).
* LSCP Network interface: Added the following new LSCP commands for the new
  feature mentioned above: "ADD CHANNEL MIDI_INPUT",
  "REMOVE CHANNEL MIDI_INPUT" and "LIST CHANNEL MIDI_INPUTS". As with the
  C++ API changes, the old LSCP commands for MIDI input management are now
  marked as deprecated, but are still there and should provide full behavior
  backward compatibility.
* New LSCP specification document (LSCP v1.6).
* AbstractEngine::GSCheckSum(): don't allocate memory on the stack (was
  unsafe and caused compilation error with old clang 2.x).
* Bumped version (1.0.0.svn25).

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

  ViewVC Help
Powered by ViewVC