/[svn]/linuxsampler/trunk/src/Sampler.h
ViewVC logotype

Annotation of /linuxsampler/trunk/src/Sampler.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, 3 months ago) by schoenebeck
File MIME type: text/x-c++hdr
File size: 38388 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 53 /***************************************************************************
2     * *
3     * LinuxSampler - modular, streaming capable sampler *
4     * *
5 schoenebeck 61 * Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck *
6 schoenebeck 2500 * Copyright (C) 2005 - 2014 Christian Schoenebeck *
7 schoenebeck 53 * *
8     * This program is free software; you can redistribute it and/or modify *
9     * it under the terms of the GNU General Public License as published by *
10     * the Free Software Foundation; either version 2 of the License, or *
11     * (at your option) any later version. *
12     * *
13     * This program is distributed in the hope that it will be useful, *
14     * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16     * GNU General Public License for more details. *
17     * *
18     * You should have received a copy of the GNU General Public License *
19     * along with this program; if not, write to the Free Software *
20     * Foundation, Inc., 59 Temple Place, Suite 330, Boston, *
21     * MA 02111-1307 USA *
22     ***************************************************************************/
23    
24     #ifndef __LS_SAMPLER_H__
25     #define __LS_SAMPLER_H__
26    
27     #include <vector>
28     #include <map>
29 iliev 1130 #include "EventListeners.h"
30 schoenebeck 53 #include "common/global.h"
31 schoenebeck 880 #include "common/Exception.h"
32 schoenebeck 890 #include "engines/EngineChannel.h"
33 schoenebeck 203 #include "drivers/midi/MidiInputDevice.h"
34     #include "drivers/audio/AudioOutputDevice.h"
35 schoenebeck 53
36     namespace LinuxSampler {
37    
38     // just symbol prototyping
39     class Sampler;
40    
41 schoenebeck 2500 /** @brief LinuxSampler sampler channel (a.k.a. "sampler part")
42 schoenebeck 57 *
43 persson 840 * Encapsulates a channel of a specific sampler engine type, one
44 schoenebeck 411 * connection to a MIDI input device and one connection to an audio
45     * output device. You cannot create an instance of this class on your
46     * own, you have to use the AddSamplerChannel() method of the Sampler
47     * object to create a new sampler channel.
48 schoenebeck 57 */
49 schoenebeck 53 class SamplerChannel {
50     public:
51 schoenebeck 57 /**
52 schoenebeck 411 * Assign a sampler engine type to this sampler channel.
53 schoenebeck 57 *
54 schoenebeck 411 * @param EngineType - type of the engine to use
55 schoenebeck 880 * @throws Exception - if \a EngineType is invalid
56 schoenebeck 900 * @see Sampler::AvailableEngineTypes()
57 schoenebeck 57 */
58 schoenebeck 880 void SetEngineType(String EngineType) throw (Exception);
59 schoenebeck 57
60     /**
61 schoenebeck 123 * Connect this sampler channel to an audio output device, that
62     * is an instance of an audio output driver. If this sampler
63     * channel was already connected to an audio output device, then
64     * the old connection will automatically be removed before.
65 schoenebeck 57 *
66 schoenebeck 123 * @param pDevice - audio output device to connect to
67 schoenebeck 1937 * @throws Exception in case the audio device is tried to be
68     * changed while the sampler channel is used by a
69     * host plugin (e.g. VST, AU, DSSI, LV2) which
70     * don't allow to change the audio output device
71 schoenebeck 57 */
72 schoenebeck 1937 void SetAudioOutputDevice(AudioOutputDevice* pDevice) throw (Exception);
73 schoenebeck 57
74     /**
75 schoenebeck 2500 * Connect the given MIDIInputPort to this SamplerChannel. The
76     * connection is added to the sampler channel. So other MIDI input
77     * connections remain unaffected by this call. If the given port is
78     * already connected to this sampler channel, then this call is
79     * ignored.
80     *
81     * @param pPort - MIDI input port to connect to
82     * @throws Exception in case the MIDI device is tried to be changed
83     * while the sampler channel is being used by a
84     * host plugin (e.g. VST, AU, DSSI, LV2) which
85     * don't allow to change the MIDI port or even
86     * device
87     */
88     void Connect(MidiInputPort* pPort) throw (Exception);
89    
90     /**
91     * Disconnects the given MidiInputPort from this SamplerChannel.
92     * All other MIDI input ports connected to this sampler channel
93     * remain unaffected. If the given port is not currently connected
94     * to this sampler channel, then this call is ignored.
95     *
96     * @param pPort - MIDI input port to disconnect
97     * @throws Exception in case the MIDI device is tried to be changed
98     * while the sampler channel is being used by a
99     * host plugin (e.g. VST, AU, DSSI, LV2) which
100     * don't allow to change the MIDI port or even
101     * device
102     */
103     void Disconnect(MidiInputPort* pPort) throw (Exception);
104    
105     /**
106     * Disconnects all MIDI input ports currently connected with this
107     * SamplerChannel.
108     *
109     * @throws Exception in case the MIDI device is tried to be changed
110     * while the sampler channel is being used by a
111     * host plugin (e.g. VST, AU, DSSI, LV2) which
112     * don't allow to change the MIDI port or even
113     * device
114     */
115     void DisconnectAllMidiInputPorts() throw (Exception);
116    
117     /**
118     * Returns all MIDI input ports currently connected to this sampler
119     * channel.
120     */
121     std::vector<MidiInputPort*> GetMidiInputPorts();
122    
123     /**
124 schoenebeck 411 * Connect this sampler channel to a MIDI input device.
125 schoenebeck 57 *
126 schoenebeck 2500 * This call will also disconnect <b>all</b> existing MIDI input
127     * connections from this sampler channel before establishing the
128     * new connection! Disconnection of all previous connections is
129     * done to preserve full behavior backward compatibility to times
130     * when this API only allowed one MIDI input port per sampler
131     * channel.
132     *
133 capela 159 * @param pDevice - MIDI input device to connect to
134 schoenebeck 1937 * @throws Exception in case the MIDI device is tried to be changed
135     * while the sampler channel is being used by a
136     * host plugin (e.g. VST, AU, DSSI, LV2) which
137     * don't allow to change the MIDI port or even
138     * device
139 schoenebeck 2500 * @deprecated This method is only provided for backward
140     * compatibility. It is a relict from days where there
141     * was only 1 MIDI input allowed per SamplerChannel.
142 capela 159 */
143 schoenebeck 2500 void SetMidiInputDevice(MidiInputDevice *pDevice) throw (Exception) DEPRECATED_API;
144 capela 159
145     /**
146 schoenebeck 2500 * Change the MIDI input port connected to this sampler channel.
147 capela 159 *
148 schoenebeck 2500 * Calling this method will switch the connection of the first
149     * (and only the first) MIDIInputPort currently being connected to
150     * this sampler channel, to another port of the same
151     * MidiInputDevice. Or in other words: the first MIDIInputPort
152     * currently connected to this sampler channel will be disconnected,
153     * and the requested other port of its MIDIInputDevice will be
154     * connected to this sampler channel instead.
155     *
156     * This behavior is implemented to preserve full behavior backward
157     * compatibility to times when this API only allowed one MIDI input
158     * port per SamplerChannel.
159     *
160 capela 159 * @param MidiPort - MIDI port to connect to
161 schoenebeck 1937 * @throws Exception in case the MIDI port is tried to be changed
162     * while the sampler channel is being used by a
163     * host plugin (e.g. VST, AU, DSSI, LV2) which
164     * don't allow to change the MIDI port
165 schoenebeck 2500 * @deprecated This method is only provided for backward
166     * compatibility. It is a relict from days where there
167     * was only 1 MIDI input allowed per SamplerChannel.
168 capela 159 */
169 schoenebeck 2500 void SetMidiInputPort(int MidiPort) throw (Exception) DEPRECATED_API;
170 capela 159
171     /**
172 schoenebeck 411 * Define on which MIDI channel(s) this sampler channel should
173 schoenebeck 2500 * listen to (on all MIDI ports and all virtual MIDI devices
174     * connected to this sampler channel). By default, that is after
175     * creation of a new sampler channel, the sampler channel will
176     * listen to all MIDI channels (a.k.a. "MIDI Omni mode").
177 capela 159 *
178 schoenebeck 411 * @param MidiChannel - MIDI channel to listen
179 schoenebeck 2500 * @throws Exception if provided MidiChannel is not a valid constant
180     * as defined by midi_chan_t
181 capela 159 */
182 schoenebeck 675 void SetMidiInputChannel(midi_chan_t MidiChannel);
183 capela 159
184     /**
185     * Connect this sampler channel to a MIDI input triplet.
186     *
187 schoenebeck 2500 * This call will also disconnect <b>all</b> existing MIDI input
188     * connections from this sampler channel before establishing the
189     * new connection! Disconnection of all previous connections is
190     * done to preserve full behavior backward compatibility to times
191     * when this API only allowed one MIDI input port per sampler
192     * channel.
193     *
194 capela 159 * @param pDevice - MIDI input device to connect to
195 schoenebeck 221 * @param iMidiPort - MIDI port to connect to
196 schoenebeck 57 * @param MidiChannel - optional: MIDI channel on which the
197     * sampler channel should listen to
198     * (default: listen on all MIDI channels)
199 schoenebeck 1937 * @throws Exception in case the MIDI port is tried to be changed
200     * while the sampler channel is being used by a
201     * host plugin (e.g. VST, AU, DSSI, LV2) which
202     * don't allow to change the MIDI port
203 schoenebeck 2500 * @deprecated This method is only provided for backward
204     * compatibility. It is a relict from days where there
205     * was only 1 MIDI input allowed per sampler channel.
206 schoenebeck 57 */
207 schoenebeck 2500 void SetMidiInput(MidiInputDevice* pDevice, int iMidiPort, midi_chan_t MidiChannel = midi_chan_all) throw (Exception) DEPRECATED_API;
208 schoenebeck 57
209     /**
210 schoenebeck 411 * Returns the EngineChannel object that was deployed on this
211     * sampler channel appropriate to the given sampler engine type.
212 schoenebeck 57 *
213     * @returns pointer to engine or NULL if no engine deployed
214     */
215 schoenebeck 411 EngineChannel* GetEngineChannel();
216 schoenebeck 57
217     /**
218 capela 159 * Returns the MIDI input channel to which this sampler
219     * channel is currently connected to.
220 schoenebeck 57 *
221 capela 159 * @returns The MIDI input channel on which the sampler
222     * channel is listening to.
223 schoenebeck 57 */
224 schoenebeck 675 midi_chan_t GetMidiInputChannel();
225 schoenebeck 57
226     /**
227 capela 159 * Returns the MIDI input port number to which this sampler
228     * channel is currently connected to.
229     *
230 schoenebeck 2500 * This method should not be used in new applications anymore!
231     *
232 capela 159 * @returns MIDI input port number or -1 if not connected
233 schoenebeck 2500 * @deprecated This method is only provided for backward
234     * compatibility. It is a relict from days where there
235     * was only 1 MIDI input allowed per sampler channel.
236 capela 159 */
237 schoenebeck 2500 int GetMidiInputPort() DEPRECATED_API;
238 capela 159
239     /**
240 schoenebeck 57 * Returns the audio output device to which this sampler channel
241     * is currently connected to.
242     *
243     * @returns pointer to audio output device or NULL if not
244     * connected
245     */
246     AudioOutputDevice* GetAudioOutputDevice();
247    
248     /**
249 capela 159 * Returns the MIDI input device to which this sampler channel
250 senkov 155 * is currently connected to.
251     *
252 capela 159 * @returns pointer to MIDI input device or NULL if not
253 senkov 155 * connected
254 schoenebeck 2500 * @deprecated This method is only provided for backward
255     * compatibility. It is a relict from days where there
256     * was only 1 MIDI input allowed per sampler channel.
257 senkov 155 */
258 schoenebeck 2500 MidiInputDevice* GetMidiInputDevice() DEPRECATED_API;
259 senkov 155
260     /**
261 schoenebeck 57 * Returns the index number of this sampler channel within the
262     * Sampler instance.
263     */
264     uint Index();
265 iliev 1761
266     /** Returns the sampler to which this channel belongs */
267     Sampler* GetSampler();
268 schoenebeck 1934
269     ///////////////////////////////////////////////////////////////
270     // Event Listener methods
271    
272 iliev 1130 /**
273     * Registers the specified listener to be notified
274     * when the engine type of this sampler channel is changed.
275     */
276     void AddEngineChangeListener(EngineChangeListener* l);
277 schoenebeck 57
278 iliev 1130 /**
279     * Removes the specified listener.
280     */
281     void RemoveEngineChangeListener(EngineChangeListener* l);
282    
283     /**
284     * Removes the specified listener.
285     */
286     void RemoveAllEngineChangeListeners();
287    
288     /**
289 schoenebeck 1686 * Notifies listeners that the engine type of this sampler
290     * channel is going to be changed soon.
291     */
292     void fireEngineToBeChanged();
293    
294     /**
295 iliev 1130 * Notifies listeners that the engine
296     * type of this sampler channel is changed.
297     */
298     void fireEngineChanged();
299    
300    
301 schoenebeck 57 protected:
302 schoenebeck 53 SamplerChannel(Sampler* pS);
303 letz 502 virtual ~SamplerChannel();
304 schoenebeck 57
305 schoenebeck 53 Sampler* pSampler;
306 schoenebeck 411 EngineChannel* pEngineChannel;
307 schoenebeck 2500 AudioOutputDevice* pAudioOutputDevice; //FIXME: should be stored as numeric device ID instead of raw pointer to avoid pointer invalidation problems
308 schoenebeck 53 int iIndex;
309 schoenebeck 57
310     friend class Sampler;
311 schoenebeck 2500
312 schoenebeck 675 private:
313 schoenebeck 2500 struct midi_conn_t {
314     uint deviceID;
315     uint portNr;
316    
317     bool operator== (const midi_conn_t& other) const {
318     return other.deviceID == this->deviceID &&
319     other.portNr == this->portNr;
320     }
321    
322     bool operator< (const midi_conn_t& other) const {
323     return memcmp(this, &other, sizeof(midi_conn_t)) < 0;
324     }
325     };
326    
327     int iMidiPort; ///< Don't access directly, read GetMidiInputPort() instead ! @deprecated This variable is just for backward compatibility from days when there was only one MIDI connection per SamplerChannel.
328 schoenebeck 675 midi_chan_t midiChannel; ///< Don't access directly, read GetMidiInputChannel() instead !
329 schoenebeck 2500 std::vector<midi_conn_t> vMidiInputs; ///< MIDI input ports connected to this sampler channel. Only used as "cache" (device id, port nr pair) in initial situation where no engine type is selected yet, and accordingly no EngineChannel instance exists which actually manages the device connections. This way users can "connect" MIDI input ports to this SamplerChannel before an engine type is chosen.
330 iliev 1130 ListenerList<EngineChangeListener*> llEngineChangeListeners;
331 schoenebeck 2500
332     static MidiInputPort* _getPortForID(const midi_conn_t& c);
333 schoenebeck 53 };
334    
335 schoenebeck 411 /** @brief LinuxSampler main class
336 schoenebeck 57 *
337     * This is the toplevel class for a LinuxSampler instance.
338     *
339     * LinuxSampler can have arbitrary numbers of sampler channels. Each
340 schoenebeck 2500 * sampler channel (a.k.a. "sampler part") can individually be deployed
341     * with it's own sampler engine, connected to an arbitrary MIDI input
342     * device and connected to an arbitrary audio output device. Here an
343     * example setup:
344 schoenebeck 675 * @code
345 schoenebeck 898 * S.Channel MIDI in S.Engine Audio out
346 schoenebeck 675 * -------------------------------------------------------------------
347 schoenebeck 898 * 0 Alsa -> gig::Engine -> Jack
348 schoenebeck 2500 * 1 VSTi -> gig::Engine -> VSTi
349     * 2 Jack -> sfz::Engine -> Jack
350     * 3 Jack -> SF2::Engine -> Alsa
351     * 4 LV2 -> sfz::Engine -> LV2
352 schoenebeck 57 *
353 schoenebeck 675 * ... (and so on) ...
354     * @endcode
355 schoenebeck 57 *
356     * As you can see in the example setup, LinuxSampler is capable to use
357     * several, different audio output and MIDI input systems
358     * simultaniously at the same time. Here the example setup shown in the
359 schoenebeck 898 * aspect of MIDI input and audio output devices / drivers:
360 schoenebeck 675 * @code
361 schoenebeck 898 * ######################### #########################
362     * # AudioOutputDeviceJack # # AudioOutputDeviceVSTi #
363     * ######################### #########################
364     * ^ ^ ^
365     * /------------>|Sampler Channel 0|-----/ | |
366     * | /--------->|Sampler Channel 1|---------------------/
367     * | | /------>|Sampler Channel 2|---------/
368     * | | | /--->|Sampler Channel 3|------------>#########################
369     * | | | | ... (and so on) ... # AudioOutputDeviceAlsa #
370     * | | | | #########################
371     * | | | \-----------------------------------------------------\
372     * | | \--------------------------------------------\ |
373     * | \--------------------\ | |
374     * | | | |
375 schoenebeck 675 * ####################### ####################### #######################
376     * # MidiInputDeviceAlsa # # MidiInputDeviceVSTi # # MidiInputDeviceJack #
377     * ####################### ####################### #######################
378     * @endcode
379 schoenebeck 57 *
380     * As you can see in this example setup, one device (that is midi input
381     * driver / audio output driver) can be connected multiple times to
382     * different sampler channels.
383 schoenebeck 898 *
384     * It's even possible to create multiple instances of the same driver, for
385     * example multiple instances of the Alsa output driver to use multiple
386     * sound cards at the same time, or multiple instances of the JACK audio
387     * output driver to leverage SMP systems or boxes with several hard discs.
388 schoenebeck 57 */
389 schoenebeck 53 class Sampler {
390     public:
391 schoenebeck 57 /**
392     * Constructor. Create a LinuxSampler instance.
393     */
394 schoenebeck 53 Sampler();
395 schoenebeck 57
396     /**
397     * Destructor.
398     */
399 letz 502 virtual ~Sampler();
400 schoenebeck 57
401     /**
402     * Returns the number of sampler channels currently allocated.
403     */
404     uint SamplerChannels();
405    
406     /**
407 schoenebeck 209 * Create and add a new sampler channel to this Sampler
408     * instance. For race condition reasons the new channel will use
409     * an index past the last already existing sampler channel
410     * index (in case the index limit was not reached yet, otherwise
411     * a free index starting from 0 is searched).
412 schoenebeck 57 *
413     * @returns pointer to new sampler channel
414     */
415     SamplerChannel* AddSamplerChannel();
416    
417     /**
418     * Returns the sampler channel of the given sampler channel
419     * index.
420     *
421     * @returns pointer to sought sampler channel
422     */
423     SamplerChannel* GetSamplerChannel(uint uiSamplerChannel);
424    
425     /**
426 schoenebeck 209 * Returns all created sampler channels.
427     */
428     std::map<uint, SamplerChannel*> GetSamplerChannels();
429    
430     /**
431 schoenebeck 57 * Destroy and remove the given sampler channel from this
432     * Sampler instance.
433     *
434     * @param pSamplerChannel - pointer to sampler channel to remove
435     */
436     void RemoveSamplerChannel(SamplerChannel* pSamplerChannel);
437    
438     /**
439     * Destroy and remove the given sampler channel from this
440     * Sampler instance.
441     *
442     * @param uiSamplerChannel - index of the sampler channel to
443     * remove
444     */
445     void RemoveSamplerChannel(uint uiSamplerChannel);
446    
447 schoenebeck 209 /**
448 iliev 1835 * Destroy and remove all sampler channels from this
449     * Sampler instance.
450     */
451     void RemoveAllSamplerChannels();
452    
453     /**
454 schoenebeck 1934 * Returns the names of all available audio output drivers.
455     */
456     std::vector<String> AvailableAudioOutputDrivers();
457    
458     /**
459     * Returns the names of all available MIDI input drivers.
460     */
461     std::vector<String> AvailableMidiInputDrivers();
462    
463     /**
464     * Returns the names of all available sampler engine types.
465     * @see SamplerChannel::SetEngineType()
466     */
467     std::vector<String> AvailableEngineTypes();
468    
469     /**
470     * Create an audio output device.
471     *
472     * @param AudioDriver - name of the audio driver
473     * @param Parameters - eventually needed driver parameters to
474     * create the device
475     * @returns pointer to created audio output device
476     * @throws Exception if device could not be created
477     */
478     AudioOutputDevice* CreateAudioOutputDevice(String AudioDriver, std::map<String,String> Parameters) throw (Exception);
479    
480     /**
481     * Create a midi input device.
482     *
483     * @param MidiDriver - name of the midi driver
484     * @param Parameters - eventually needed driver parameters to
485     * create the device
486     * @returns pointer to created midi input device
487     * @throws Exception if device could not be created
488     */
489     MidiInputDevice* CreateMidiInputDevice(String MidiDriver, std::map<String,String> Parameters) throw (Exception);
490    
491     /**
492     * Returns the number of all created audio output devices.
493     */
494     uint AudioOutputDevices();
495    
496     /**
497     * Returns the number of all created MIDI input devices.
498     */
499     uint MidiInputDevices();
500    
501     /**
502     * Returns all created audio output devices.
503     */
504     std::map<uint, AudioOutputDevice*> GetAudioOutputDevices();
505    
506     /**
507     * Returns all created MIDI input devices.
508     */
509     std::map<uint, MidiInputDevice*> GetMidiInputDevices();
510    
511     /**
512     * Destroy the given audio output device and takes care if there
513     * are still sampler engines connected to this device, etc.
514     *
515     * @throws Exception if sampler channels are still
516     * connected to the device
517     */
518     void DestroyAudioOutputDevice(AudioOutputDevice* pDevice) throw (Exception);
519    
520     /**
521     * Destroy all audio output devices and takes care if there
522     * are still sampler engines connected to devices, etc.
523     *
524     * Note: non-autonomous devices, that is devices associated with
525     * host plugin instances like VST, AU, DSSI, LV2 are not
526     * destroyed by this method.
527     *
528     * @throws Exception if sampler channels are still
529     * connected to device
530     */
531     void DestroyAllAudioOutputDevices() throw (Exception);
532    
533     /**
534     * Destroy the given MIDI input device and takes care if there
535     * are still sampler engines connected to this device, etc.
536     *
537     * @throws Exception if sampler channels are still
538     * connected to the device
539     */
540     void DestroyMidiInputDevice(MidiInputDevice* pDevice) throw (Exception);
541    
542     /**
543     * Destroy all MIDI input devices and take care if there
544     * are still sampler engines connected to device, etc.
545     *
546     * Note: non-autonomous devices, that is devices associated with
547     * host plugin instances like VST, AU, DSSI, LV2 are not
548     * destroyed by this method.
549     *
550     * @throws Exception if sampler channels are still
551     * connected to device
552     */
553     void DestroyAllMidiInputDevices() throw (Exception);
554    
555     /**
556     * Gets the current number of all active streams.
557     * @returns The current number of all active streams.
558     */
559     int GetDiskStreamCount();
560    
561     /**
562     * Gets the current number of all active voices.
563     * @returns The current number of all active voices.
564     */
565     int GetVoiceCount();
566    
567     /**
568 schoenebeck 2375 * @see SetGlobalMaxVoices()
569     */
570     int GetGlobalMaxVoices();
571    
572     /**
573     * @see SetGlobalMaxStreams()
574     */
575     int GetGlobalMaxStreams();
576    
577     /**
578     * Sets the global maximum amount limit of voices.
579     *
580     * Note that this voice limit can also be altered for
581     * each sampler engine instance individually instead.
582     *
583     * @throws Exception if \a n is invalid
584     */
585     void SetGlobalMaxVoices(int n) throw (Exception);
586    
587     /**
588     * Sets the global maximum amount limit of disk streams.
589     *
590     * Note that this stream limit can also be altered for
591     * each sampler engine instance individually instead.
592     *
593     * @throws Exception if \a n is invalid
594     */
595     void SetGlobalMaxStreams(int n) throw (Exception);
596    
597     /**
598 schoenebeck 1934 * Reset the whole sampler. Destroy all engines, sampler
599     * channels, MIDI input devices and audio output devices.
600     */
601     void Reset();
602    
603     ///////////////////////////////////////////////////////////////
604     // Event Listener methods
605    
606     /**
607 iliev 1130 * Registers the specified listener to be notified
608     * when the number of sampler chanels is changed.
609     */
610     void AddChannelCountListener(ChannelCountListener* l);
611    
612     /**
613     * Removes the specified listener.
614     */
615     void RemoveChannelCountListener(ChannelCountListener* l);
616    
617     /**
618     * Registers the specified listener to be notified
619     * when the number of audio output devices is changed.
620     */
621     void AddAudioDeviceCountListener(AudioDeviceCountListener* l);
622    
623     /**
624     * Removes the specified listener.
625     */
626     void RemoveAudioDeviceCountListener(AudioDeviceCountListener* l);
627    
628     /**
629     * Registers the specified listener to be notified
630     * when the number of MIDI input devices is changed.
631     */
632     void AddMidiDeviceCountListener(MidiDeviceCountListener* l);
633    
634     /**
635     * Removes the specified listener.
636     */
637     void RemoveMidiDeviceCountListener(MidiDeviceCountListener* l);
638    
639     /**
640     * Registers the specified listener to be notified when the number
641     * of active voices in a particular sampler channel is changed.
642     */
643     void AddVoiceCountListener(VoiceCountListener* l);
644    
645     /**
646     * Removes the specified listener.
647     */
648     void RemoveVoiceCountListener(VoiceCountListener* l);
649    
650     /**
651     * Notifies listeners that the number of active voices
652     * on the specified sampler channel is changed.
653     * @param ChannelId The numerical ID of the sampler channel.
654     * @param NewCount The new number of active voices.
655     */
656     void fireVoiceCountChanged(int ChannelId, int NewCount);
657    
658     /**
659     * Registers the specified listener to be notified when the number
660     * of active disk streams in a particular sampler channel is changed.
661     */
662     void AddStreamCountListener(StreamCountListener* l);
663    
664     /**
665     * Removes the specified listener.
666     */
667     void RemoveStreamCountListener(StreamCountListener* l);
668    
669     /**
670     * Notifies listeners that the number of active disk streams
671     * on the specified sampler channel is changed.
672     * @param ChannelId The numerical ID of the sampler channel.
673     * @param NewCount The new number of active disk streams.
674     */
675     void fireStreamCountChanged(int ChannelId, int NewCount);
676    
677     /**
678     * Registers the specified listener to be
679     * notified when the fill state of the disk stream
680     * buffers on a specific sampler channel is changed.
681     */
682     void AddBufferFillListener(BufferFillListener* l);
683    
684     /**
685     * Removes the specified listener.
686     */
687     void RemoveBufferFillListener(BufferFillListener* l);
688    
689     /**
690     * Notifies listeners that the fill state of the disk stream
691     * buffers on the specified sampler channel is changed.
692     * @param ChannelId The numerical ID of the sampler channel.
693     * @param FillData The buffer fill data for the specified sampler channel.
694     */
695     void fireBufferFillChanged(int ChannelId, String FillData);
696    
697     /**
698     * Registers the specified listener to be notified
699     * when total number of active voices is changed.
700     */
701     void AddTotalVoiceCountListener(TotalVoiceCountListener* l);
702    
703     /**
704     * Removes the specified listener.
705     */
706     void RemoveTotalVoiceCountListener(TotalVoiceCountListener* l);
707    
708     /**
709     * Notifies listeners that the total number of active voices is changed.
710     * @param NewCount The new number of active voices.
711     */
712     void fireTotalVoiceCountChanged(int NewCount);
713    
714     /**
715     * Registers the specified listener to be notified when the number
716 schoenebeck 1934 * of total streams is changed.
717 iliev 1130 */
718 schoenebeck 1934 void AddTotalStreamCountListener(TotalStreamCountListener* l);
719 iliev 1130
720     /**
721     * Removes the specified listener.
722     */
723 schoenebeck 1934 void RemoveTotalStreamCountListener(TotalStreamCountListener* l);
724 iliev 1130
725     /**
726 schoenebeck 1934 * Notifies listeners that the total number of total streams changed.
727     * @param NewCount The new number of total streams.
728 schoenebeck 209 */
729 schoenebeck 1934 void fireTotalStreamCountChanged(int NewCount);
730 schoenebeck 123
731 schoenebeck 57 /**
732 schoenebeck 1934 * Registers the specified listener to be notified when the number
733     * of effect sends on a particular sampler channel is changed.
734 schoenebeck 900 */
735 schoenebeck 1934 void AddFxSendCountListener(FxSendCountListener* l);
736 schoenebeck 900
737     /**
738 schoenebeck 1934 * Removes the specified listener.
739 schoenebeck 900 */
740 schoenebeck 1934 void RemoveFxSendCountListener(FxSendCountListener* l);
741 schoenebeck 900
742     /**
743 schoenebeck 1934 * Notifies listeners about the current number of voices,
744     * streams and total voices, and the current fill state of
745     * the disk stream buffers.
746 schoenebeck 57 */
747 schoenebeck 1934 void fireStatistics();
748 schoenebeck 57
749 schoenebeck 1934 ///////////////////////////////////////////////////////////////
750     // system specific methods
751 senkov 155
752 schoenebeck 209 /**
753 schoenebeck 1723 * Advise the FPU to treat denormal floating point numbers as
754     * zero, to avoid severe performance penalty when dealing with
755     * such extreme floating point values.
756     *
757     * @returns @c true if FPU supports it, @c false otherwise
758     */
759     static bool EnableDenormalsAreZeroMode();
760    
761 persson 1897 #if defined(WIN32)
762     /**
763 schoenebeck 1934 * Gets the directory where the liblinuxsampler dll is located.
764     * Note: this method is currently only available for Windows.
765 persson 1897 * @returns installation directory
766     */
767     static String GetInstallDir();
768     #endif
769 schoenebeck 53 protected:
770 iliev 1130 /**
771     * Notifies listeners that the number of sampler channels has been changed.
772     * @param NewCount The new number of sampler channels.
773     */
774     void fireChannelCountChanged(int NewCount);
775    
776     /**
777 schoenebeck 1686 * Notifies listeners that the specified sampler channel has just
778     * been added.
779     * @param pChannel The new sampler channel.
780     */
781     void fireChannelAdded(SamplerChannel* pChannel);
782    
783     /**
784     * Notifies listeners that the specified sampler channel is
785     * going to be removed soon.
786     * @param pChannel sampler channel to be removed.
787     */
788     void fireChannelToBeRemoved(SamplerChannel* pChannel);
789    
790     /**
791 iliev 1130 * Notifies listeners that the number of audio output devices has been changed.
792     * @param NewCount The new number of audio output devices.
793     */
794     void fireAudioDeviceCountChanged(int NewCount);
795    
796     /**
797     * Notifies listeners that the number of MIDI input devices has been changed.
798     * @param NewCount The new number of MIDI input devices.
799     */
800     void fireMidiDeviceCountChanged(int NewCount);
801    
802     /**
803 schoenebeck 1695 * Notifies listeners that the supplied MIDI input device is
804     * going to be destroyed soon.
805     * @param pDevice MIDI input device to be destroyed
806     */
807     void fireMidiDeviceToBeDestroyed(MidiInputDevice* pDevice);
808    
809     /**
810     * Notifies listeners that the supplied MIDI input device was
811     * just created.
812     * @param pDevice new MIDI input device
813     */
814     void fireMidiDeviceCreated(MidiInputDevice* pDevice);
815    
816     /**
817 iliev 1130 * Notifies listeners that the number of effect sends
818     * on a particular sampler channel is changed.
819     * @param ChannelId The numerical ID of the sampler channel.
820     * @param NewCount The new number of sampler channels.
821     */
822     void fireFxSendCountChanged(int ChannelId, int NewCount);
823    
824 schoenebeck 209 typedef std::map<uint, SamplerChannel*> SamplerChannelMap;
825 schoenebeck 53
826 schoenebeck 1934 SamplerChannelMap mSamplerChannels; ///< contains all created sampler channels
827 schoenebeck 53
828 iliev 1789 // statistics cache
829     uint uiOldTotalVoiceCount;
830     uint uiOldTotalStreamCount;
831     std::map<uint, uint> mOldVoiceCounts;
832     std::map<uint, uint> mOldStreamCounts;
833    
834 schoenebeck 53 friend class SamplerChannel;
835 iliev 1130
836     private:
837     ListenerList<ChannelCountListener*> llChannelCountListeners;
838     ListenerList<AudioDeviceCountListener*> llAudioDeviceCountListeners;
839     ListenerList<MidiDeviceCountListener*> llMidiDeviceCountListeners;
840     ListenerList<VoiceCountListener*> llVoiceCountListeners;
841     ListenerList<StreamCountListener*> llStreamCountListeners;
842     ListenerList<BufferFillListener*> llBufferFillListeners;
843 iliev 1541 ListenerList<TotalStreamCountListener*> llTotalStreamCountListeners;
844 iliev 1130 ListenerList<TotalVoiceCountListener*> llTotalVoiceCountListeners;
845     ListenerList<FxSendCountListener*> llFxSendCountListeners;
846    
847     class EventHandler : public EngineChangeListener, public FxSendCountListener {
848     public:
849     void SetSampler(Sampler* pSampler) { this->pSampler = pSampler; }
850    
851     /**
852 schoenebeck 1686 * Invoked when the engine type of the specified sampler
853     * channel is going to be changed soon.
854     * @param ChannelId The numerical ID of the sampler channel
855     */
856     virtual void EngineToBeChanged(int ChannelId);
857    
858     /**
859 iliev 1130 * Invoked when the engine type of the
860     * specified sampler channel is changed.
861     * @param ChannelId The numerical ID of the sampler
862     * channel, which engine type has been changed.
863     */
864     virtual void EngineChanged(int ChannelId);
865    
866     /**
867     * Invoked when the number of effect sends
868     * on the specified sampler channel has changed.
869     * @param ChannelId The numerical ID of the sampler channel.
870     * @param NewCount The new number of effect sends.
871     */
872     virtual void FxSendCountChanged(int ChannelId, int NewCount);
873    
874     private:
875     Sampler* pSampler;
876     } eventHandler;
877 schoenebeck 53 };
878     }
879    
880     #endif // __LS_SAMPLER_H__

  ViewVC Help
Powered by ViewVC