--- linuxsampler/trunk/src/drivers/audio/AudioOutputDeviceAlsa.cpp 2004/07/25 23:27:41 211 +++ linuxsampler/trunk/src/drivers/audio/AudioOutputDeviceAlsa.cpp 2004/07/28 14:17:29 212 @@ -37,6 +37,192 @@ REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceAlsa, ParameterFragments); REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceAlsa, ParameterFragmentSize); + + +// *************** ParameterCard *************** +// * + + AudioOutputDeviceAlsa::ParameterCard::ParameterCard() : DeviceCreationParameterString() { + InitWithDefault(); // use default card + } + + AudioOutputDeviceAlsa::ParameterCard::ParameterCard(String s) throw (LinuxSamplerException) : DeviceCreationParameterString(s) { + SetValue(s); // try to use given card + } + + String AudioOutputDeviceAlsa::ParameterCard::Description() { + return "Sound card to be used"; + } + + bool AudioOutputDeviceAlsa::ParameterCard::Fix() { + return true; + } + + bool AudioOutputDeviceAlsa::ParameterCard::Mandatory() { + return false; + } + + std::map AudioOutputDeviceAlsa::ParameterCard::DependsAsParameters() { + return std::map(); // no dependencies + } + + optional AudioOutputDeviceAlsa::ParameterCard::DefaultAsString(std::map Parameters) { + std::vector cards = PossibilitiesAsString(Parameters); + if (cards.empty()) throw LinuxSamplerException("AudioOutputDeviceAlsa: Can't find any card"); + return cards[0]; // first card by default + } + + std::vector AudioOutputDeviceAlsa::ParameterCard::PossibilitiesAsString(std::map Parameters) { + int err; + std::vector CardNames; + + // iterate through all cards + int card_index = -1; + while (snd_card_next(&card_index) >= 0 && card_index >= 0) { + String hw_name = "hw:" + ToString(card_index); + snd_ctl_t* hCardCtrl; + if ((err = snd_ctl_open(&hCardCtrl, hw_name.c_str(), 0)) < 0) { + std::cerr << "AudioOutputDeviceAlsa: Cannot open sound control for card " << card_index << " - " << snd_strerror(err) << std::endl; + continue; + } + + // iterate through all devices of that card + int device_index = -1; + while (!snd_ctl_pcm_next_device(hCardCtrl, &device_index) && device_index >= 0) { + String name = ToString(card_index) + "," + ToString(device_index); + //dmsg(1,("[possibility:%s]", name.c_str())); + CardNames.push_back(name); + } + + snd_ctl_close(hCardCtrl); + } + + return CardNames; + } + + void AudioOutputDeviceAlsa::ParameterCard::OnSetValue(String s) throw (LinuxSamplerException) { + // not posssible, as parameter is fix + } + + String AudioOutputDeviceAlsa::ParameterCard::Name() { + return "card"; + } + + + +// *************** ParameterFragments *************** +// * + + AudioOutputDeviceAlsa::ParameterFragments::ParameterFragments() : DeviceCreationParameterInt() { + InitWithDefault(); + } + + AudioOutputDeviceAlsa::ParameterFragments::ParameterFragments(String s) throw (LinuxSamplerException) : DeviceCreationParameterInt(s) { + } + + String AudioOutputDeviceAlsa::ParameterFragments::Description() { + return "Number of buffer fragments"; + } + + bool AudioOutputDeviceAlsa::ParameterFragments::Fix() { + return true; + } + + bool AudioOutputDeviceAlsa::ParameterFragments::Mandatory() { + return false; + } + + std::map AudioOutputDeviceAlsa::ParameterFragments::DependsAsParameters() { + static ParameterCard card; + std::map dependencies; + dependencies[card.Name()] = &card; + return dependencies; + } + + optional AudioOutputDeviceAlsa::ParameterFragments::DefaultAsInt(std::map Parameters) { + return 2; // until done + } + + optional AudioOutputDeviceAlsa::ParameterFragments::RangeMinAsInt(std::map Parameters) { + return optional::nothing; + } + + optional AudioOutputDeviceAlsa::ParameterFragments::RangeMaxAsInt(std::map Parameters) { + return optional::nothing; + } + + std::vector AudioOutputDeviceAlsa::ParameterFragments::PossibilitiesAsInt(std::map Parameters) { + return std::vector(); + } + + void AudioOutputDeviceAlsa::ParameterFragments::OnSetValue(int i) throw (LinuxSamplerException) { + // not posssible, as parameter is fix + } + + String AudioOutputDeviceAlsa::ParameterFragments::Name() { + return "fragments"; + } + + + +// *************** ParameterFragmentSize *************** +// * + + AudioOutputDeviceAlsa::ParameterFragmentSize::ParameterFragmentSize() : DeviceCreationParameterInt() { + InitWithDefault(); + } + + AudioOutputDeviceAlsa::ParameterFragmentSize::ParameterFragmentSize(String s) throw (LinuxSamplerException) : DeviceCreationParameterInt(s) { + } + + String AudioOutputDeviceAlsa::ParameterFragmentSize::Description() { + return "Size of each buffer fragment"; + } + + bool AudioOutputDeviceAlsa::ParameterFragmentSize::Fix() { + return true; + } + + bool AudioOutputDeviceAlsa::ParameterFragmentSize::Mandatory() { + return false; + } + + std::map AudioOutputDeviceAlsa::ParameterFragmentSize::DependsAsParameters() { + static ParameterCard card; + std::map dependencies; + dependencies[card.Name()] = &card; + return dependencies; + } + + optional AudioOutputDeviceAlsa::ParameterFragmentSize::DefaultAsInt(std::map Parameters) { + return 128; // until done + } + + optional AudioOutputDeviceAlsa::ParameterFragmentSize::RangeMinAsInt(std::map Parameters) { + return optional::nothing; + } + + optional AudioOutputDeviceAlsa::ParameterFragmentSize::RangeMaxAsInt(std::map Parameters) { + return optional::nothing; + } + + std::vector AudioOutputDeviceAlsa::ParameterFragmentSize::PossibilitiesAsInt(std::map Parameters) { + return std::vector(); + } + + void AudioOutputDeviceAlsa::ParameterFragmentSize::OnSetValue(int i) throw (LinuxSamplerException) { + // not posssible, as parameter is fix + } + + String AudioOutputDeviceAlsa::ParameterFragmentSize::Name() { + return "fragmentsize"; + } + + + +// *************** AudioOutputDeviceAlsa *************** +// * + /** * Create and initialize Alsa audio output device with given parameters. * @@ -273,7 +459,7 @@ } String AudioOutputDeviceAlsa::Version() { - String s = "$Revision: 1.10 $"; + String s = "$Revision: 1.11 $"; return s.substr(11, s.size() - 13); // cut dollar signs, spaces and CVS macro keyword }