linuxsampler 2.3.1
Sampler.h
Go to the documentation of this file.
1/***************************************************************************
2 * *
3 * LinuxSampler - modular, streaming capable sampler *
4 * *
5 * Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck *
6 * Copyright (C) 2005 - 2014 Christian Schoenebeck *
7 * *
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#include "EventListeners.h"
30#include "common/global.h"
31#include "common/Exception.h"
35
36namespace LinuxSampler {
37
38 // just symbol prototyping
39 class Sampler;
40
50 public:
59
73
88 void Connect(MidiInputPort* pPort) throw (Exception);
89
103 void Disconnect(MidiInputPort* pPort) throw (Exception);
104
116
122
144
170
183
208
216
225
238
247
259
265
268
270 // Event Listener methods
271
277
282
287
293
299
300
301 protected:
304
307 AudioOutputDevice* pAudioOutputDevice; //FIXME: should be stored as numeric device ID instead of raw pointer to avoid pointer invalidation problems
309
311
312 private:
313 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;
328 midi_chan_t midiChannel;
329 std::vector<midi_conn_t> vMidiInputs;
330 ListenerList<EngineChangeListener*> llEngineChangeListeners;
331
332 static MidiInputPort* _getPortForID(const midi_conn_t& c);
333 };
334
389 class Sampler {
390 public:
395
399 virtual ~Sampler();
400
405
416
424
428 std::map<uint, SamplerChannel*> GetSamplerChannels();
429
437
446
452
456 std::vector<String> AvailableAudioOutputDrivers();
457
461 std::vector<String> AvailableMidiInputDrivers();
462
467 std::vector<String> AvailableEngineTypes();
468
478 AudioOutputDevice* CreateAudioOutputDevice(String AudioDriver, std::map<String,String> Parameters) throw (Exception);
479
489 MidiInputDevice* CreateMidiInputDevice(String MidiDriver, std::map<String,String> Parameters) throw (Exception);
490
495
500
504 std::map<uint, AudioOutputDevice*> GetAudioOutputDevices();
505
509 std::map<uint, MidiInputDevice*> GetMidiInputDevices();
510
519
532
541
554
560
566
571
576
586
596
601 void Reset();
602
604 // Event Listener methods
605
611
616
622
627
633
638
644
649
657
663
668
676
683
688
696
702
707
713
719
724
730
736
741
748
750 // system specific methods
751
760
761#if defined(WIN32)
767 static String GetInstallDir();
768#endif
769 protected:
775
782
789
795
801
808
815
823
824 typedef std::map<uint, SamplerChannel*> SamplerChannelMap;
825
827
828 // statistics cache
831 std::map<uint, uint> mOldVoiceCounts;
832 std::map<uint, uint> mOldStreamCounts;
833
834 friend class SamplerChannel;
835
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 ListenerList<TotalStreamCountListener*> llTotalStreamCountListeners;
844 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
856 virtual void EngineToBeChanged(int ChannelId);
857
864 virtual void EngineChanged(int ChannelId);
865
872 virtual void FxSendCountChanged(int ChannelId, int NewCount);
873
874 private:
875 Sampler* pSampler;
876 } eventHandler;
877 };
878}
879
880#endif // __LS_SAMPLER_H__
This class is used as a listener, which is notified when the number of audio output devices is change...
Abstract base class for audio output drivers in LinuxSampler.
This class is used as a listener, which is notified when the fill state of the disk stream buffers on...
This class is used as a listener, which is notified when the number of sampler channels is changed.
This class is used as a listener, which is notified when the engine type of a particular sampler chan...
Channel Interface for LinuxSampler Sampler Engines.
Exception that will be thrown in NON REAL TIME PARTS of the LinuxSampler application.
Definition Exception.h:37
This class is used as a listener, which is notified when the number of effect sends on a particular s...
This class is used as a listener, which is notified when the number of MIDI input devices is changed.
Abstract base class for MIDI input drivers in LinuxSampler.
LinuxSampler sampler channel (a.k.a.
Definition Sampler.h:49
void RemoveEngineChangeListener(EngineChangeListener *l)
Removes the specified listener.
void SetMidiInputDevice(MidiInputDevice *pDevice) DEPRECATED_API
Connect this sampler channel to a MIDI input device.
void fireEngineToBeChanged()
Notifies listeners that the engine type of this sampler channel is going to be changed soon.
EngineChannel * pEngineChannel
Definition Sampler.h:306
void RemoveAllEngineChangeListeners()
Removes the specified listener.
uint Index()
Returns the index number of this sampler channel within the Sampler instance.
EngineChannel * GetEngineChannel()
Returns the EngineChannel object that was deployed on this sampler channel appropriate to the given s...
void AddEngineChangeListener(EngineChangeListener *l)
Registers the specified listener to be notified when the engine type of this sampler channel is chang...
void fireEngineChanged()
Notifies listeners that the engine type of this sampler channel is changed.
MidiInputDevice * GetMidiInputDevice() DEPRECATED_API
Returns the MIDI input device to which this sampler channel is currently connected to.
void SetMidiInputPort(int MidiPort) DEPRECATED_API
Change the MIDI input port connected to this sampler channel.
void Disconnect(MidiInputPort *pPort)
Disconnects the given MidiInputPort from this SamplerChannel.
void SetAudioOutputDevice(AudioOutputDevice *pDevice)
Connect this sampler channel to an audio output device, that is an instance of an audio output driver...
std::vector< MidiInputPort * > GetMidiInputPorts()
Returns all MIDI input ports currently connected to this sampler channel.
midi_chan_t GetMidiInputChannel()
Returns the MIDI input channel to which this sampler channel is currently connected to.
AudioOutputDevice * pAudioOutputDevice
Definition Sampler.h:307
AudioOutputDevice * GetAudioOutputDevice()
Returns the audio output device to which this sampler channel is currently connected to.
void SetMidiInput(MidiInputDevice *pDevice, int iMidiPort, midi_chan_t MidiChannel=midi_chan_all) DEPRECATED_API
Connect this sampler channel to a MIDI input triplet.
Sampler * GetSampler()
Returns the sampler to which this channel belongs.
void DisconnectAllMidiInputPorts()
Disconnects all MIDI input ports currently connected with this SamplerChannel.
int GetMidiInputPort() DEPRECATED_API
Returns the MIDI input port number to which this sampler channel is currently connected to.
void SetMidiInputChannel(midi_chan_t MidiChannel)
Define on which MIDI channel(s) this sampler channel should listen to (on all MIDI ports and all virt...
void SetEngineType(String EngineType)
Assign a sampler engine type to this sampler channel.
void Connect(MidiInputPort *pPort)
Connect the given MIDIInputPort to this SamplerChannel.
LinuxSampler main class.
Definition Sampler.h:389
void RemoveMidiDeviceCountListener(MidiDeviceCountListener *l)
Removes the specified listener.
void AddChannelCountListener(ChannelCountListener *l)
Registers the specified listener to be notified when the number of sampler chanels is changed.
std::vector< String > AvailableAudioOutputDrivers()
Returns the names of all available audio output drivers.
void fireMidiDeviceCreated(MidiInputDevice *pDevice)
Notifies listeners that the supplied MIDI input device was just created.
void AddAudioDeviceCountListener(AudioDeviceCountListener *l)
Registers the specified listener to be notified when the number of audio output devices is changed.
MidiInputDevice * CreateMidiInputDevice(String MidiDriver, std::map< String, String > Parameters)
Create a midi input device.
void fireStatistics()
Notifies listeners about the current number of voices, streams and total voices, and the current fill...
int GetVoiceCount()
Gets the current number of all active voices.
void DestroyMidiInputDevice(MidiInputDevice *pDevice)
Destroy the given MIDI input device and takes care if there are still sampler engines connected to th...
void RemoveFxSendCountListener(FxSendCountListener *l)
Removes the specified listener.
Sampler()
Constructor.
std::map< uint, SamplerChannel * > GetSamplerChannels()
Returns all created sampler channels.
void AddTotalVoiceCountListener(TotalVoiceCountListener *l)
Registers the specified listener to be notified when total number of active voices is changed.
void RemoveStreamCountListener(StreamCountListener *l)
Removes the specified listener.
int GetDiskStreamCount()
Gets the current number of all active streams.
void AddFxSendCountListener(FxSendCountListener *l)
Registers the specified listener to be notified when the number of effect sends on a particular sampl...
void fireChannelAdded(SamplerChannel *pChannel)
Notifies listeners that the specified sampler channel has just been added.
void AddTotalStreamCountListener(TotalStreamCountListener *l)
Registers the specified listener to be notified when the number of total streams is changed.
uint MidiInputDevices()
Returns the number of all created MIDI input devices.
void AddStreamCountListener(StreamCountListener *l)
Registers the specified listener to be notified when the number of active disk streams in a particula...
void fireBufferFillChanged(int ChannelId, String FillData)
Notifies listeners that the fill state of the disk stream buffers on the specified sampler channel is...
void fireStreamCountChanged(int ChannelId, int NewCount)
Notifies listeners that the number of active disk streams on the specified sampler channel is changed...
void RemoveTotalVoiceCountListener(TotalVoiceCountListener *l)
Removes the specified listener.
std::map< uint, AudioOutputDevice * > GetAudioOutputDevices()
Returns all created audio output devices.
void RemoveAudioDeviceCountListener(AudioDeviceCountListener *l)
Removes the specified listener.
void RemoveVoiceCountListener(VoiceCountListener *l)
Removes the specified listener.
void fireTotalStreamCountChanged(int NewCount)
Notifies listeners that the total number of total streams changed.
std::vector< String > AvailableEngineTypes()
Returns the names of all available sampler engine types.
AudioOutputDevice * CreateAudioOutputDevice(String AudioDriver, std::map< String, String > Parameters)
Create an audio output device.
uint AudioOutputDevices()
Returns the number of all created audio output devices.
void fireAudioDeviceCountChanged(int NewCount)
Notifies listeners that the number of audio output devices has been changed.
SamplerChannel * AddSamplerChannel()
Create and add a new sampler channel to this Sampler instance.
void fireTotalVoiceCountChanged(int NewCount)
Notifies listeners that the total number of active voices is changed.
void RemoveAllSamplerChannels()
Destroy and remove all sampler channels from this Sampler instance.
void RemoveTotalStreamCountListener(TotalStreamCountListener *l)
Removes the specified listener.
void fireChannelCountChanged(int NewCount)
Notifies listeners that the number of sampler channels has been changed.
void DestroyAllMidiInputDevices()
Destroy all MIDI input devices and take care if there are still sampler engines connected to device,...
void AddVoiceCountListener(VoiceCountListener *l)
Registers the specified listener to be notified when the number of active voices in a particular samp...
SamplerChannel * GetSamplerChannel(uint uiSamplerChannel)
Returns the sampler channel of the given sampler channel index.
static bool EnableDenormalsAreZeroMode()
Advise the FPU to treat denormal floating point numbers as zero, to avoid severe performance penalty ...
std::vector< String > AvailableMidiInputDrivers()
Returns the names of all available MIDI input drivers.
void AddBufferFillListener(BufferFillListener *l)
Registers the specified listener to be notified when the fill state of the disk stream buffers on a s...
void SetGlobalMaxVoices(int n)
Sets the global maximum amount limit of voices.
std::map< uint, MidiInputDevice * > GetMidiInputDevices()
Returns all created MIDI input devices.
std::map< uint, uint > mOldVoiceCounts
Definition Sampler.h:831
void Reset()
Reset the whole sampler.
void fireFxSendCountChanged(int ChannelId, int NewCount)
Notifies listeners that the number of effect sends on a particular sampler channel is changed.
void RemoveBufferFillListener(BufferFillListener *l)
Removes the specified listener.
virtual ~Sampler()
Destructor.
uint SamplerChannels()
Returns the number of sampler channels currently allocated.
void fireVoiceCountChanged(int ChannelId, int NewCount)
Notifies listeners that the number of active voices on the specified sampler channel is changed.
void fireChannelToBeRemoved(SamplerChannel *pChannel)
Notifies listeners that the specified sampler channel is going to be removed soon.
void RemoveSamplerChannel(uint uiSamplerChannel)
Destroy and remove the given sampler channel from this Sampler instance.
std::map< uint, uint > mOldStreamCounts
Definition Sampler.h:832
void DestroyAllAudioOutputDevices()
Destroy all audio output devices and takes care if there are still sampler engines connected to devic...
void fireMidiDeviceToBeDestroyed(MidiInputDevice *pDevice)
Notifies listeners that the supplied MIDI input device is going to be destroyed soon.
SamplerChannelMap mSamplerChannels
contains all created sampler channels
Definition Sampler.h:826
void SetGlobalMaxStreams(int n)
Sets the global maximum amount limit of disk streams.
void RemoveChannelCountListener(ChannelCountListener *l)
Removes the specified listener.
std::map< uint, SamplerChannel * > SamplerChannelMap
Definition Sampler.h:824
void AddMidiDeviceCountListener(MidiDeviceCountListener *l)
Registers the specified listener to be notified when the number of MIDI input devices is changed.
void RemoveSamplerChannel(SamplerChannel *pSamplerChannel)
Destroy and remove the given sampler channel from this Sampler instance.
void DestroyAudioOutputDevice(AudioOutputDevice *pDevice)
Destroy the given audio output device and takes care if there are still sampler engines connected to ...
void fireMidiDeviceCountChanged(int NewCount)
Notifies listeners that the number of MIDI input devices has been changed.
This class is used as a listener, which is notified when the number of active disk streams in a parti...
Wraps as a kind of pointer class some data object shared with other threads, to protect / synchronize...
This class is used as a listener, which is notified when the total number of active streams is change...
This class is used as a listener, which is notified when the total number of active voices is changed...
This class is used as a listener, which is notified when the number of active voices in a particular ...
#define DEPRECATED_API
Definition global.h:71
std::string String
Definition global.h:44
midi_chan_t
MIDI channels.
Definition midi.h:34
@ midi_chan_all
Definition midi.h:51