--- linuxsampler/trunk/src/Sampler.h 2004/05/03 19:29:44 61 +++ linuxsampler/trunk/src/Sampler.h 2004/07/18 00:29:39 209 @@ -28,33 +28,11 @@ #include "common/global.h" #include "common/LinuxSamplerException.h" #include "engines/common/Engine.h" -#include "mididriver/MidiInputDevice.h" -#include "audiodriver/AudioOutputDevice.h" +#include "drivers/midi/MidiInputDevice.h" +#include "drivers/audio/AudioOutputDevice.h" namespace LinuxSampler { - /** - * Which sampler engine to be used. - */ - enum engine_type_t { - engine_type_gig - }; - - /** - * Which audio output system to be used. - */ - enum audio_output_type_t { - audio_output_type_alsa, - audio_output_type_jack - }; - - /** - * Which MIDI input system to be used. - */ - enum midi_input_type_t { - midi_input_type_alsa - }; - // just symbol prototyping class Sampler; @@ -62,7 +40,7 @@ * * 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 you own, you have to use the + * 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. */ @@ -76,36 +54,49 @@ * * @param EngineType - type of the engine to deploy */ - void LoadEngine(engine_type_t EngineType); + void LoadEngine(Engine::type_t EngineType); // TODO: to be changed to 'void LoadEngine(String EngineType) throws (LinuxSamplerException);' + + /** + * Connect this sampler channel to an audio output device, that + * is an instance of an audio output driver. If this sampler + * channel was already connected to an audio output device, then + * the old connection will automatically be removed before. + * + * @param pDevice - audio output device to connect to + */ + void SetAudioOutputDevice(AudioOutputDevice* pDevice); /** - * Connect this sampler channel to an audio output device (that - * is audio output driver) of the given type. If the audio - * output for the desired audio output system is not yet - * created, then it will be created automatically, but with - * default settings though. If this sampler channel was already - * connected to an audio output device, then the old connection - * will automatically be removed before. + * Connect this sampler channel to and MIDI input device. * - * @param AudioType - audio output system to connect to + * @param pDevice - MIDI input device to connect to */ - void SetAudioOutputDevice(audio_output_type_t AudioType); + void SetMidiInputDevice(MidiInputDevice *pDevice); /** - * Connect this sampler channel to and MIDI input device (that - * is MIDI input driver) of the given type. If the MIDI input - * driver for the desired MIDI input system is not yet created, - * then it will be created automatically, but with default - * settings though. If this sampler channel was already - * connected to a MIDI input device, then the old connection - * will automatically be removed before. + * Connect this sampler channel to and MIDI input port. * - * @param MidiType - MIDI input system to connect to + * @param MidiPort - MIDI port to connect to + */ + void SetMidiInputPort(int MidiPort); + + /** + * Connect this sampler channel to and MIDI input channel. + * + * @param MidiChannel - MIDI channel to connect to + */ + void SetMidiInputChannel(MidiInputDevice::MidiInputPort::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 MidiChannel - optional: MIDI channel on which the * sampler channel should listen to * (default: listen on all MIDI channels) */ - void SetMidiInputDevice(midi_input_type_t MidiType, MidiInputDevice::midi_chan_t MidiChannel = MidiInputDevice::midi_chan_all); + void SetMidiInput(MidiInputDevice* pDevice, int MidiPort, MidiInputDevice::MidiInputPort::midi_chan_t MidiChannel = MidiInputDevice::MidiInputPort::midi_chan_all); /** * Returns the engine that was deployed on this sampler channel. @@ -115,13 +106,21 @@ Engine* GetEngine(); /** - * Returns the MIDI input device to which this sampler channel - * is currently connected to. + * Returns the MIDI input channel to which this sampler + * channel is currently connected to. * - * @returns pointer to MIDI input device or NULL if not - * connected + * @returns The MIDI input channel on which the sampler + * channel is listening to. */ - MidiInputDevice* GetMidiInputDevice(); + MidiInputDevice::MidiInputPort::midi_chan_t GetMidiInputChannel(); + + /** + * Returns the MIDI input port number to which this sampler + * channel is currently connected to. + * + * @returns MIDI input port number or -1 if not connected + */ + int GetMidiInputPort(); /** * Returns the audio output device to which this sampler channel @@ -133,6 +132,15 @@ AudioOutputDevice* GetAudioOutputDevice(); /** + * Returns the MIDI input device to which this sampler channel + * is currently connected to. + * + * @returns pointer to MIDI input device or NULL if not + * connected + */ + MidiInputDevice* GetMidiInputDevice(); + + /** * Returns the index number of this sampler channel within the * Sampler instance. */ @@ -142,10 +150,15 @@ SamplerChannel(Sampler* pS); ~SamplerChannel(); + /** Getting MIDI input device port given its index number. */ + MidiInputDevice::MidiInputPort* GetMidiInputDevicePort(int MidiPort); + Sampler* pSampler; Engine* pEngine; - MidiInputDevice* pMidiInputDevice; AudioOutputDevice* pAudioOutputDevice; + MidiInputDevice* pMidiInputDevice; + int midiPort; + MidiInputDevice::MidiInputPort::midi_chan_t midiChannel; int iIndex; friend class Sampler; @@ -217,7 +230,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 */ @@ -232,6 +249,11 @@ SamplerChannel* GetSamplerChannel(uint uiSamplerChannel); /** + * Returns all created sampler channels. + */ + std::map GetSamplerChannels(); + + /** * Destroy and remove the given sampler channel from this * Sampler instance. * @@ -249,46 +271,78 @@ void RemoveSamplerChannel(uint uiSamplerChannel); /** - * Create an audio output device of the given type. + * Returns the names of all available audio output drivers. + */ + std::vector AvailableAudioOutputDrivers(); + + /** + * Create an audio output device. * - * @param AudioType - desired audio output system to use + * @param AudioDriver - name of the audio driver + * @param Parameters - eventually needed driver parameters to + * create the device * @returns pointer to created audio output device + * @throws LinuxSamplerException if device could not be created */ - AudioOutputDevice* CreateAudioOutputDevice(audio_output_type_t AudioType); + AudioOutputDevice* CreateAudioOutputDevice(String AudioDriver, std::map Parameters) throw (LinuxSamplerException); /** - * Returns the audio output device of the given type. + * Create a midi input device. * - * @param AudioType - desired audio output system to use - * @returns pointer to audio output device or NULL if device of - * desired type is not yet created + * @param MidiDriver - name of the midi driver + * @param Parameters - eventually needed driver parameters to + * create the device + * @returns pointer to created midi input device + * @throws LinuxSamplerException if device could not be created + */ + 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. */ - AudioOutputDevice* GetAudioOutputDevice(audio_output_type_t AudioType); + uint MidiInputDevices(); /** - * Create a MIDI input device of the given type. + * 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. * - * @param MidiType - desired MIDI input system to use - * @returns pointer to created MIDI input device + * @throws LinuxSamplerException if sampler channels are still + * connected to the device */ - MidiInputDevice* CreateMidiInputDevice(midi_input_type_t MidiType); + void DestroyAudioOutputDevice(AudioOutputDevice* pDevice) throw (LinuxSamplerException); /** - * Returns the MIDI input device of the given type. + * Destroy the given MIDI input device and takes care if there + * are still sampler angines connected to this device, etc. * - * @param MidiType - desired MIDI input system to use - * @returns pointer to MIDI input device or NULL if device of - * desired type is not yet created + * @throws LinuxSamplerException if sampler channels are still + * connected to the device */ - MidiInputDevice* GetMidiInputDevice(midi_input_type_t MidiType); + void DestroyMidiInputDevice(MidiInputDevice* pDevice) throw (LinuxSamplerException); protected: - typedef std::map AudioOutputDeviceMap; - typedef std::map MidiInputDeviceMap; - - std::vector vSamplerChannels; ///< contains all created sampler channels - AudioOutputDeviceMap AudioOutputDevices; ///< contains all created audio output devices - MidiInputDeviceMap MidiInputDevices; + typedef std::map AudioOutputDeviceMap; + typedef std::map MidiInputDeviceMap; + typedef std::map SamplerChannelMap; + + 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; };