Mercurial > hg > svapp
diff audioio/AudioTargetFactory.cpp @ 126:d615d0220828
* Add audio device selection to preferences
* Add (not yet functional) insert, delete, edit buttons to data edit window
* Add proper set methods for time fields in data edit window (using general
sparse model base class)
author | Chris Cannam |
---|---|
date | Fri, 13 Jun 2008 21:09:43 +0000 |
parents | 2bc8bf6d016c |
children | b774a451b093 |
line wrap: on
line diff
--- a/audioio/AudioTargetFactory.cpp Thu Jun 12 14:33:45 2008 +0000 +++ b/audioio/AudioTargetFactory.cpp Fri Jun 13 21:09:43 2008 +0000 @@ -20,13 +20,127 @@ #include "AudioPortAudioTarget.h" #include "AudioPulseAudioTarget.h" +#include <QCoreApplication> + #include <iostream> +AudioTargetFactory * +AudioTargetFactory::m_instance = 0; + +AudioTargetFactory * +AudioTargetFactory::getInstance() +{ + if (!m_instance) m_instance = new AudioTargetFactory(); + return m_instance; +} + +AudioTargetFactory::AudioTargetFactory() +{ +} + +std::vector<QString> +AudioTargetFactory::getCallbackTargetNames(bool includeAuto) const +{ + std::vector<QString> names; + if (includeAuto) names.push_back("auto"); + +#ifdef HAVE_JACK + names.push_back("jack"); +#endif + +#ifdef HAVE_LIBPULSE + names.push_back("pulse"); +#endif + +#ifdef HAVE_COREAUDIO + names.push_back("core"); +#endif + +#ifdef HAVE_PORTAUDIO_2_0 + names.push_back("port"); +#endif + + return names; +} + +QString +AudioTargetFactory::getCallbackTargetDescription(QString name) const +{ + if (name == "auto") { + return QCoreApplication::translate("AudioTargetFactory", + "(auto)"); + } + if (name == "jack") { + return QCoreApplication::translate("AudioTargetFactory", + "JACK Audio Connection Kit"); + } + if (name == "pulse") { + return QCoreApplication::translate("AudioTargetFactory", + "PulseAudio Server"); + } + if (name == "core") { + return QCoreApplication::translate("AudioTargetFactory", + "Core Audio Device"); + } + if (name == "port") { + return QCoreApplication::translate("AudioTargetFactory", + "Default Soundcard Device"); + } + + return "(unknown)"; +} + +QString +AudioTargetFactory::getDefaultCallbackTarget() const +{ + if (m_default == "") return "auto"; + return m_default; +} + +bool +AudioTargetFactory::isAutoCallbackTarget(QString name) const +{ + return (name == "auto" || name == ""); +} + +void +AudioTargetFactory::setDefaultCallbackTarget(QString target) +{ + m_default = target; +} + AudioCallbackPlayTarget * AudioTargetFactory::createCallbackTarget(AudioCallbackPlaySource *source) { AudioCallbackPlayTarget *target = 0; + if (m_default != "" && m_default != "auto") { + +#ifdef HAVE_JACK + if (m_default == "jack") target = new AudioJACKTarget(source); +#endif + +#ifdef HAVE_LIBPULSE + if (m_default == "pulse") target = new AudioPulseAudioTarget(source); +#endif + +#ifdef HAVE_COREAUDIO + if (m_default == "core") target = new AudioCoreAudioTarget(source); +#endif + +#ifdef HAVE_PORTAUDIO_2_0 + if (m_default == "port") target = new AudioPortAudioTarget(source); +#endif + + if (!target || !target->isOK()) { + std::cerr << "WARNING: AudioTargetFactory::createCallbackTarget: Failed to open the requested target (\"" << m_default.toStdString() << "\")" << std::endl; + delete target; + return 0; + } else { + return target; + } + } + #ifdef HAVE_JACK target = new AudioJACKTarget(source); if (target->isOK()) return target; @@ -53,15 +167,6 @@ delete target; } #endif - -#ifdef HAVE_DIRECTSOUND - target = new AudioDirectSoundTarget(source); - if (target->isOK()) return target; - else { - std::cerr << "WARNING: AudioTargetFactory::createCallbackTarget: Failed to open DirectSound target" << std::endl; - delete target; - } -#endif #ifdef HAVE_PORTAUDIO_2_0 target = new AudioPortAudioTarget(source);