--- linuxsampler/trunk/src/drivers/audio/AudioOutputDevice.cpp 2004/07/13 22:04:16 200 +++ linuxsampler/trunk/src/drivers/audio/AudioOutputDevice.cpp 2004/08/25 22:00:33 226 @@ -25,16 +25,178 @@ namespace LinuxSampler { +// *************** ParameterActive *************** +// * + + AudioOutputDevice::ParameterActive::ParameterActive() : DeviceCreationParameterBool() { + InitWithDefault(); + } + + AudioOutputDevice::ParameterActive::ParameterActive(String s) : DeviceCreationParameterBool(s) { + } + + String AudioOutputDevice::ParameterActive::Description() { + return "Enable / disable device"; + } + + bool AudioOutputDevice::ParameterActive::Fix() { + return false; + } + + bool AudioOutputDevice::ParameterActive::Mandatory() { + return false; + } + + std::map AudioOutputDevice::ParameterActive::DependsAsParameters() { + return std::map(); + } + + optional AudioOutputDevice::ParameterActive::DefaultAsBool(std::map Parameters) { + return true; + } + + void AudioOutputDevice::ParameterActive::OnSetValue(bool b) throw (LinuxSamplerException) { + if (b) ((AudioOutputDevice*)pDevice)->Play(); + else ((AudioOutputDevice*)pDevice)->Stop(); + } + + String AudioOutputDevice::ParameterActive::Name() { + return "ACTIVE"; + } + + + +// *************** ParameterSampleRate *************** +// * + + AudioOutputDevice::ParameterSampleRate::ParameterSampleRate() : DeviceCreationParameterInt() { + InitWithDefault(); + } + + AudioOutputDevice::ParameterSampleRate::ParameterSampleRate(String s) : DeviceCreationParameterInt(s) { + } + + String AudioOutputDevice::ParameterSampleRate::Description() { + return "Output sample rate"; + } + + bool AudioOutputDevice::ParameterSampleRate::Fix() { + return true; + } + + bool AudioOutputDevice::ParameterSampleRate::Mandatory() { + return false; + } + + std::map AudioOutputDevice::ParameterSampleRate::DependsAsParameters() { + return std::map(); + } + + optional AudioOutputDevice::ParameterSampleRate::DefaultAsInt(std::map Parameters) { + return 44100; + } + + optional AudioOutputDevice::ParameterSampleRate::RangeMinAsInt(std::map Parameters) { + return optional::nothing; + } + + optional AudioOutputDevice::ParameterSampleRate::RangeMaxAsInt(std::map Parameters) { + return optional::nothing; + } + + std::vector AudioOutputDevice::ParameterSampleRate::PossibilitiesAsInt(std::map Parameters) { + return std::vector(); + } + + void AudioOutputDevice::ParameterSampleRate::OnSetValue(int i) throw (LinuxSamplerException) { + /* cannot happen, as parameter is fix */ + } + + String AudioOutputDevice::ParameterSampleRate::Name() { + return "SAMPLERATE"; + } + + + +// *************** ParameterChannels *************** +// * + + AudioOutputDevice::ParameterChannels::ParameterChannels() : DeviceCreationParameterInt() { + InitWithDefault(); + } + + AudioOutputDevice::ParameterChannels::ParameterChannels(String s) : DeviceCreationParameterInt(s) { + } + + String AudioOutputDevice::ParameterChannels::Description() { + return "Number of output channels"; + } + + bool AudioOutputDevice::ParameterChannels::Fix() { + return false; + } + + bool AudioOutputDevice::ParameterChannels::Mandatory() { + return false; + } + + std::map AudioOutputDevice::ParameterChannels::DependsAsParameters() { + return std::map(); + } + + optional AudioOutputDevice::ParameterChannels::DefaultAsInt(std::map Parameters) { + return 2; + } + + optional AudioOutputDevice::ParameterChannels::RangeMinAsInt(std::map Parameters) { + return optional::nothing; + } + + optional AudioOutputDevice::ParameterChannels::RangeMaxAsInt(std::map Parameters) { + return optional::nothing; + } + + std::vector AudioOutputDevice::ParameterChannels::PossibilitiesAsInt(std::map Parameters) { + return std::vector(); + } + + void AudioOutputDevice::ParameterChannels::OnSetValue(int i) throw (LinuxSamplerException) { + ((AudioOutputDevice*)pDevice)->AcquireChannels(i); + } + + String AudioOutputDevice::ParameterChannels::Name() { + return "CHANNELS"; + } + + + +// *************** AudioOutputDevice *************** +// * + AudioOutputDevice::AudioOutputDevice(std::map DriverParameters) { this->Parameters = DriverParameters; } AudioOutputDevice::~AudioOutputDevice() { - std::map::iterator iter = Parameters.begin(); - while (iter != Parameters.end()) { - Parameters.erase(iter); - delete iter->second; - iter++; + // delete all audio channels + { + std::vector::iterator iter = Channels.begin(); + while (iter != Channels.end()) { + Channels.erase(iter); + delete *iter; + iter++; + } + + } + + // delete all device parameters + { + std::map::iterator iter = Parameters.begin(); + while (iter != Parameters.end()) { + Parameters.erase(iter); + delete iter->second; + iter++; + } } } @@ -56,6 +218,14 @@ return (ChannelIndex < Channels.size()) ? Channels[ChannelIndex] : NULL; } + void AudioOutputDevice::AcquireChannels(uint Channels) { + if (Channels > this->Channels.size()) { + for (int c = this->Channels.size(); c < Channels; c++) { + this->Channels.push_back(CreateChannel(c)); + } + } + } + std::map AudioOutputDevice::DeviceParameters() { return Parameters; }