Chris@43: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ Chris@43: Chris@43: /* Chris@43: Sonic Visualiser Chris@43: An audio file viewer and annotation editor. Chris@43: Centre for Digital Music, Queen Mary, University of London. Chris@43: This file copyright 2006 Chris Cannam. Chris@43: Chris@43: This program is free software; you can redistribute it and/or Chris@43: modify it under the terms of the GNU General Public License as Chris@43: published by the Free Software Foundation; either version 2 of the Chris@43: License, or (at your option) any later version. See the file Chris@43: COPYING included with this distribution for more information. Chris@43: */ Chris@43: Chris@43: #include "AudioTargetFactory.h" Chris@43: Chris@43: #include "AudioJACKTarget.h" Chris@43: #include "AudioPortAudioTarget.h" Chris@117: #include "AudioPulseAudioTarget.h" Chris@43: Chris@149: #include "AudioCallbackPlayTarget.h" Chris@149: Chris@126: #include Chris@126: Chris@43: #include Chris@43: Chris@126: AudioTargetFactory * Chris@126: AudioTargetFactory::m_instance = 0; Chris@126: Chris@126: AudioTargetFactory * Chris@126: AudioTargetFactory::getInstance() Chris@126: { Chris@126: if (!m_instance) m_instance = new AudioTargetFactory(); Chris@126: return m_instance; Chris@126: } Chris@126: Chris@126: AudioTargetFactory::AudioTargetFactory() Chris@126: { Chris@126: } Chris@126: Chris@126: std::vector Chris@126: AudioTargetFactory::getCallbackTargetNames(bool includeAuto) const Chris@126: { Chris@126: std::vector names; Chris@126: if (includeAuto) names.push_back("auto"); Chris@126: Chris@126: #ifdef HAVE_JACK Chris@126: names.push_back("jack"); Chris@126: #endif Chris@126: Chris@126: #ifdef HAVE_LIBPULSE Chris@126: names.push_back("pulse"); Chris@126: #endif Chris@126: Chris@126: #ifdef HAVE_PORTAUDIO_2_0 Chris@126: names.push_back("port"); Chris@126: #endif Chris@126: Chris@126: return names; Chris@126: } Chris@126: Chris@126: QString Chris@126: AudioTargetFactory::getCallbackTargetDescription(QString name) const Chris@126: { Chris@126: if (name == "auto") { Chris@126: return QCoreApplication::translate("AudioTargetFactory", Chris@126: "(auto)"); Chris@126: } Chris@126: if (name == "jack") { Chris@126: return QCoreApplication::translate("AudioTargetFactory", Chris@126: "JACK Audio Connection Kit"); Chris@126: } Chris@126: if (name == "pulse") { Chris@126: return QCoreApplication::translate("AudioTargetFactory", Chris@126: "PulseAudio Server"); Chris@126: } Chris@126: if (name == "port") { Chris@126: return QCoreApplication::translate("AudioTargetFactory", Chris@126: "Default Soundcard Device"); Chris@126: } Chris@126: Chris@126: return "(unknown)"; Chris@126: } Chris@126: Chris@126: QString Chris@126: AudioTargetFactory::getDefaultCallbackTarget() const Chris@126: { Chris@126: if (m_default == "") return "auto"; Chris@126: return m_default; Chris@126: } Chris@126: Chris@126: bool Chris@126: AudioTargetFactory::isAutoCallbackTarget(QString name) const Chris@126: { Chris@126: return (name == "auto" || name == ""); Chris@126: } Chris@126: Chris@126: void Chris@126: AudioTargetFactory::setDefaultCallbackTarget(QString target) Chris@126: { Chris@126: m_default = target; Chris@126: } Chris@126: Chris@43: AudioCallbackPlayTarget * Chris@43: AudioTargetFactory::createCallbackTarget(AudioCallbackPlaySource *source) Chris@43: { Chris@43: AudioCallbackPlayTarget *target = 0; Chris@43: Chris@126: if (m_default != "" && m_default != "auto") { Chris@126: Chris@126: #ifdef HAVE_JACK Chris@126: if (m_default == "jack") target = new AudioJACKTarget(source); Chris@126: #endif Chris@126: Chris@126: #ifdef HAVE_LIBPULSE Chris@126: if (m_default == "pulse") target = new AudioPulseAudioTarget(source); Chris@126: #endif Chris@126: Chris@126: #ifdef HAVE_PORTAUDIO_2_0 Chris@126: if (m_default == "port") target = new AudioPortAudioTarget(source); Chris@126: #endif Chris@126: Chris@126: if (!target || !target->isOK()) { Chris@293: cerr << "WARNING: AudioTargetFactory::createCallbackTarget: Failed to open the requested target (\"" << m_default << "\")" << endl; Chris@126: delete target; Chris@126: return 0; Chris@126: } else { Chris@126: return target; Chris@126: } Chris@126: } Chris@126: Chris@43: #ifdef HAVE_JACK Chris@43: target = new AudioJACKTarget(source); Chris@43: if (target->isOK()) return target; Chris@43: else { Chris@293: cerr << "WARNING: AudioTargetFactory::createCallbackTarget: Failed to open JACK target" << endl; Chris@43: delete target; Chris@43: } Chris@43: #endif Chris@117: Chris@117: #ifdef HAVE_LIBPULSE Chris@117: target = new AudioPulseAudioTarget(source); Chris@117: if (target->isOK()) return target; Chris@117: else { Chris@293: cerr << "WARNING: AudioTargetFactory::createCallbackTarget: Failed to open PulseAudio target" << endl; Chris@117: delete target; Chris@117: } Chris@117: #endif Chris@114: Chris@114: #ifdef HAVE_PORTAUDIO_2_0 Chris@43: target = new AudioPortAudioTarget(source); Chris@43: if (target->isOK()) return target; Chris@43: else { Chris@293: cerr << "WARNING: AudioTargetFactory::createCallbackTarget: Failed to open PortAudio target" << endl; Chris@43: delete target; Chris@43: } Chris@43: #endif Chris@43: Chris@293: cerr << "WARNING: AudioTargetFactory::createCallbackTarget: No suitable targets available" << endl; Chris@43: return 0; Chris@43: } Chris@43: Chris@43: