--- linuxsampler/trunk/src/Sampler.h 2004/07/13 22:44:13 203 +++ linuxsampler/trunk/src/Sampler.h 2005/09/23 06:58:26 778 @@ -3,6 +3,7 @@ * LinuxSampler - modular, streaming capable sampler * * * * Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck * + * Copyright (C) 2005 Christian Schoenebeck * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * @@ -27,7 +28,7 @@ #include #include "common/global.h" #include "common/LinuxSamplerException.h" -#include "engines/common/Engine.h" +#include "engines/common/EngineChannel.h" #include "drivers/midi/MidiInputDevice.h" #include "drivers/audio/AudioOutputDevice.h" @@ -36,25 +37,23 @@ // just symbol prototyping class Sampler; - /** LinuxSampler sampler channel + /** @brief LinuxSampler sampler channel * - * Encapsulates one sampler engine, one connection to a MIDI input - * device and one connection to an audio output device. You cannot - * create an instance of this class on your own, you have to use the - * AddSamplerChannel() method of the Sampler object to create a new - * sampler channel. + * Encapsulates a channel of a specific sampler engine typ, one + * connection to a MIDI input device and one connection to an audio + * output device. You cannot create an instance of this class on your + * own, you have to use the AddSamplerChannel() method of the Sampler + * object to create a new sampler channel. */ class SamplerChannel { public: /** - * Deploy a sampler engine of the given type for this sampler - * channnel. If there was already a sampler engine deployed on - * this sampler channel, then the old engine will automatically - * be destroyed. + * Assign a sampler engine type to this sampler channel. * - * @param EngineType - type of the engine to deploy + * @param EngineType - type of the engine to use + * @throws LinuxSamplerException - if \a EngineType is invalid */ - void LoadEngine(Engine::type_t EngineType); // TODO: to be changed to 'void LoadEngine(String EngineType) throws (LinuxSamplerException);' + void SetEngineType(String EngineType) throw (LinuxSamplerException); /** * Connect this sampler channel to an audio output device, that @@ -67,43 +66,47 @@ void SetAudioOutputDevice(AudioOutputDevice* pDevice); /** - * Connect this sampler channel to and MIDI input device. + * Connect this sampler channel to a MIDI input device. * * @param pDevice - MIDI input device to connect to */ void SetMidiInputDevice(MidiInputDevice *pDevice); /** - * Connect this sampler channel to and MIDI input port. + * Connect this sampler channel to a MIDI input port. * * @param MidiPort - MIDI port to connect to */ void SetMidiInputPort(int MidiPort); /** - * Connect this sampler channel to and MIDI input channel. + * Define on which MIDI channel(s) this sampler channel should + * listen to. By default, that is after creation of a new + * sampler channel, the sampler channel will listen to all MIDI + * channels. * - * @param MidiChannel - MIDI channel to connect to + * @param MidiChannel - MIDI channel to listen */ - void SetMidiInputChannel(MidiInputDevice::MidiInputPort::midi_chan_t MidiChannel); + void SetMidiInputChannel(midi_chan_t MidiChannel); /** * Connect this sampler channel to a MIDI input triplet. * * @param pDevice - MIDI input device to connect to - * @param MidiPort - MIDI port to connect to + * @param iMidiPort - MIDI port to connect to * @param MidiChannel - optional: MIDI channel on which the * sampler channel should listen to * (default: listen on all MIDI channels) */ - void SetMidiInput(MidiInputDevice* pDevice, int MidiPort, MidiInputDevice::MidiInputPort::midi_chan_t MidiChannel = MidiInputDevice::MidiInputPort::midi_chan_all); + void SetMidiInput(MidiInputDevice* pDevice, int iMidiPort, midi_chan_t MidiChannel = midi_chan_all); /** - * Returns the engine that was deployed on this sampler channel. + * Returns the EngineChannel object that was deployed on this + * sampler channel appropriate to the given sampler engine type. * * @returns pointer to engine or NULL if no engine deployed */ - Engine* GetEngine(); + EngineChannel* GetEngineChannel(); /** * Returns the MIDI input channel to which this sampler @@ -112,7 +115,7 @@ * @returns The MIDI input channel on which the sampler * channel is listening to. */ - MidiInputDevice::MidiInputPort::midi_chan_t GetMidiInputChannel(); + midi_chan_t GetMidiInputChannel(); /** * Returns the MIDI input port number to which this sampler @@ -148,23 +151,25 @@ protected: SamplerChannel(Sampler* pS); - ~SamplerChannel(); + virtual ~SamplerChannel(); /** Getting MIDI input device port given its index number. */ - MidiInputDevice::MidiInputPort* GetMidiInputDevicePort(int MidiPort); + MidiInputPort* __GetMidiInputDevicePort(int iMidiPort); + midi_chan_t __GetMidiChannel(); Sampler* pSampler; - Engine* pEngine; + EngineChannel* pEngineChannel; AudioOutputDevice* pAudioOutputDevice; MidiInputDevice* pMidiInputDevice; - int midiPort; - MidiInputDevice::MidiInputPort::midi_chan_t midiChannel; int iIndex; friend class Sampler; + private: + int iMidiPort; ///< Don't access directly, read GetMidiInputPort() instead ! + midi_chan_t midiChannel; ///< Don't access directly, read GetMidiInputChannel() instead ! }; - /** LinuxSampler main class + /** @brief LinuxSampler main class * * This is the toplevel class for a LinuxSampler instance. * @@ -172,15 +177,16 @@ * sampler channel can individually be deployed with it's own sampler * engine, connected to an arbitrary MIDI input device and connected to * an arbitrary audio output device. Here an example setup: + * @code + * S.Channel. MIDI in S.Engine Audio out + * ------------------------------------------------------------------- + * 0 Alsa -> gig::Engine -> Jack + * 1 VSTi -> Akai::Engine -> VSTi + * 2 Jack -> DLS::Engine -> Jack + * 3 Jack -> SF::Engine -> Alsa * - * S.Channel. MIDI in S.Engine Audio out - * ------------------------------------------------------------------- - * 0 Alsa -> gig::Engine -> Jack - * 1 VSTi -> Akai::Engine -> VSTi - * 2 Jack -> DLS::Engine -> Jack - * 3 Jack -> SF::Engine -> Alsa - * - * ... (and so on) ... + * ... (and so on) ... + * @endcode * * Note that not all audio and MIDI backends and sampler engines listed * in the example above are already implemented! @@ -189,24 +195,25 @@ * several, different audio output and MIDI input systems * simultaniously at the same time. Here the example setup shown in the * ascpect of MIDI input and audio output devices / drivers: - * - * ######################### ######################### - * # AudioOutputDeviceJack # # AudioOutputDeviceVSTi # - * ######################### ######################### - * ^ ^ ^ - * /------------>|Sampler Channel 0|-----/ | | - * | /--------->|Sampler Channel 1|---------------------/ - * | | /---->|Sampler Channel 2|---------/ - * | | | /->|Sampler Channel 3|------------>######################### - * | | | | ... (and so on) ... # AudioOutputDeviceAlsa # - * | | | | ######################### - * | | | \----------------------------------------------------\ - * | | \-------------------------------------------\ | - * | \--------------------\ | | - * | | | | - * ####################### ####################### ####################### - * # MidiInputDeviceAlsa # # MidiInputDeviceVSTi # # MidiInputDeviceJack # - * ####################### ####################### ####################### + * @code + * ######################### ######################### + * # AudioOutputDeviceJack # # AudioOutputDeviceVSTi # + * ######################### ######################### + * ^ ^ ^ + * /------------>|Sampler Channel 0|-----/ | | + * | /--------->|Sampler Channel 1|---------------------/ + * | | /------>|Sampler Channel 2|---------/ + * | | | /--->|Sampler Channel 3|------------>######################### + * | | | | ... (and so on) ... # AudioOutputDeviceAlsa # + * | | | | ######################### + * | | | \-----------------------------------------------------\ + * | | \--------------------------------------------\ | + * | \--------------------\ | | + * | | | | + * ####################### ####################### ####################### + * # MidiInputDeviceAlsa # # MidiInputDeviceVSTi # # MidiInputDeviceJack # + * ####################### ####################### ####################### + * @endcode * * As you can see in this example setup, one device (that is midi input * driver / audio output driver) can be connected multiple times to @@ -222,7 +229,7 @@ /** * Destructor. */ - ~Sampler(); + virtual ~Sampler(); /** * Returns the number of sampler channels currently allocated. @@ -230,7 +237,11 @@ uint SamplerChannels(); /** - * Create and add a new sampler channel to this Sampler instance. + * Create and add a new sampler channel to this Sampler + * instance. For race condition reasons the new channel will use + * an index past the last already existing sampler channel + * index (in case the index limit was not reached yet, otherwise + * a free index starting from 0 is searched). * * @returns pointer to new sampler channel */ @@ -245,6 +256,11 @@ SamplerChannel* GetSamplerChannel(uint uiSamplerChannel); /** + * Returns all created sampler channels. + */ + std::map GetSamplerChannels(); + + /** * Destroy and remove the given sampler channel from this * Sampler instance. * @@ -261,6 +277,9 @@ */ void RemoveSamplerChannel(uint uiSamplerChannel); + /** + * Returns the names of all available audio output drivers. + */ std::vector AvailableAudioOutputDrivers(); /** @@ -285,23 +304,64 @@ */ MidiInputDevice* CreateMidiInputDevice(String MidiDriver, std::map Parameters) throw (LinuxSamplerException); + /** + * Returns the number of all created audio output devices. + */ uint AudioOutputDevices(); + + /** + * Returns the number of all created MIDI input devices. + */ uint MidiInputDevices(); + /** + * Returns all created audio output devices. + */ std::map GetAudioOutputDevices(); + /** + * Returns all created MIDI input devices. + */ std::map GetMidiInputDevices(); + /** + * Destroy the given audio output device and takes care if there + * are still sampler angines connected to this device, etc. + * + * @throws LinuxSamplerException if sampler channels are still + * connected to the device + */ void DestroyAudioOutputDevice(AudioOutputDevice* pDevice) throw (LinuxSamplerException); - void DestroyMidiInputDevice(MidiInputDevice* pDevice) throw (LinuxSamplerException); + + /** + * Destroy the given MIDI input device and takes care if there + * are still sampler angines connected to this device, etc. + * + * @throws LinuxSamplerException if sampler channels are still + * connected to the device + */ + void DestroyMidiInputDevice(MidiInputDevice* pDevice) throw (LinuxSamplerException); + + /** + * Gets the current number of all active voices. + * @returns The current number of all active voices. + */ + int GetVoiceCount(); + + /** + * Reset the whole sampler. Destroy all engines, sampler + * channels, MIDI input devices and audio output devices. + */ + void Reset(); protected: typedef std::map AudioOutputDeviceMap; typedef std::map MidiInputDeviceMap; + typedef std::map SamplerChannelMap; - std::vector vSamplerChannels; ///< contains all created sampler channels - AudioOutputDeviceMap mAudioOutputDevices; ///< contains all created audio output devices - MidiInputDeviceMap mMidiInputDevices; + SamplerChannelMap mSamplerChannels; ///< contains all created sampler channels + AudioOutputDeviceMap mAudioOutputDevices; ///< contains all created audio output devices + MidiInputDeviceMap mMidiInputDevices; ///< contains all created MIDI input devices friend class SamplerChannel; };