annotate audioio/AudioTargetFactory.cpp @ 148:7dca51571320 sv-v1.4rc1

* Ensure SimpleSPARQLQuery stores an error string properly when query fails -- so (apart from anything else) RDFImporter::identifyDocumentType returns a sensible result for non-RDF
author Chris Cannam
date Mon, 08 Dec 2008 15:08:39 +0000
parents d615d0220828
children b774a451b093
rev   line source
Chris@43 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@43 2
Chris@43 3 /*
Chris@43 4 Sonic Visualiser
Chris@43 5 An audio file viewer and annotation editor.
Chris@43 6 Centre for Digital Music, Queen Mary, University of London.
Chris@43 7 This file copyright 2006 Chris Cannam.
Chris@43 8
Chris@43 9 This program is free software; you can redistribute it and/or
Chris@43 10 modify it under the terms of the GNU General Public License as
Chris@43 11 published by the Free Software Foundation; either version 2 of the
Chris@43 12 License, or (at your option) any later version. See the file
Chris@43 13 COPYING included with this distribution for more information.
Chris@43 14 */
Chris@43 15
Chris@43 16 #include "AudioTargetFactory.h"
Chris@43 17
Chris@43 18 #include "AudioJACKTarget.h"
Chris@43 19 #include "AudioCoreAudioTarget.h"
Chris@43 20 #include "AudioPortAudioTarget.h"
Chris@117 21 #include "AudioPulseAudioTarget.h"
Chris@43 22
Chris@126 23 #include <QCoreApplication>
Chris@126 24
Chris@43 25 #include <iostream>
Chris@43 26
Chris@126 27 AudioTargetFactory *
Chris@126 28 AudioTargetFactory::m_instance = 0;
Chris@126 29
Chris@126 30 AudioTargetFactory *
Chris@126 31 AudioTargetFactory::getInstance()
Chris@126 32 {
Chris@126 33 if (!m_instance) m_instance = new AudioTargetFactory();
Chris@126 34 return m_instance;
Chris@126 35 }
Chris@126 36
Chris@126 37 AudioTargetFactory::AudioTargetFactory()
Chris@126 38 {
Chris@126 39 }
Chris@126 40
Chris@126 41 std::vector<QString>
Chris@126 42 AudioTargetFactory::getCallbackTargetNames(bool includeAuto) const
Chris@126 43 {
Chris@126 44 std::vector<QString> names;
Chris@126 45 if (includeAuto) names.push_back("auto");
Chris@126 46
Chris@126 47 #ifdef HAVE_JACK
Chris@126 48 names.push_back("jack");
Chris@126 49 #endif
Chris@126 50
Chris@126 51 #ifdef HAVE_LIBPULSE
Chris@126 52 names.push_back("pulse");
Chris@126 53 #endif
Chris@126 54
Chris@126 55 #ifdef HAVE_COREAUDIO
Chris@126 56 names.push_back("core");
Chris@126 57 #endif
Chris@126 58
Chris@126 59 #ifdef HAVE_PORTAUDIO_2_0
Chris@126 60 names.push_back("port");
Chris@126 61 #endif
Chris@126 62
Chris@126 63 return names;
Chris@126 64 }
Chris@126 65
Chris@126 66 QString
Chris@126 67 AudioTargetFactory::getCallbackTargetDescription(QString name) const
Chris@126 68 {
Chris@126 69 if (name == "auto") {
Chris@126 70 return QCoreApplication::translate("AudioTargetFactory",
Chris@126 71 "(auto)");
Chris@126 72 }
Chris@126 73 if (name == "jack") {
Chris@126 74 return QCoreApplication::translate("AudioTargetFactory",
Chris@126 75 "JACK Audio Connection Kit");
Chris@126 76 }
Chris@126 77 if (name == "pulse") {
Chris@126 78 return QCoreApplication::translate("AudioTargetFactory",
Chris@126 79 "PulseAudio Server");
Chris@126 80 }
Chris@126 81 if (name == "core") {
Chris@126 82 return QCoreApplication::translate("AudioTargetFactory",
Chris@126 83 "Core Audio Device");
Chris@126 84 }
Chris@126 85 if (name == "port") {
Chris@126 86 return QCoreApplication::translate("AudioTargetFactory",
Chris@126 87 "Default Soundcard Device");
Chris@126 88 }
Chris@126 89
Chris@126 90 return "(unknown)";
Chris@126 91 }
Chris@126 92
Chris@126 93 QString
Chris@126 94 AudioTargetFactory::getDefaultCallbackTarget() const
Chris@126 95 {
Chris@126 96 if (m_default == "") return "auto";
Chris@126 97 return m_default;
Chris@126 98 }
Chris@126 99
Chris@126 100 bool
Chris@126 101 AudioTargetFactory::isAutoCallbackTarget(QString name) const
Chris@126 102 {
Chris@126 103 return (name == "auto" || name == "");
Chris@126 104 }
Chris@126 105
Chris@126 106 void
Chris@126 107 AudioTargetFactory::setDefaultCallbackTarget(QString target)
Chris@126 108 {
Chris@126 109 m_default = target;
Chris@126 110 }
Chris@126 111
Chris@43 112 AudioCallbackPlayTarget *
Chris@43 113 AudioTargetFactory::createCallbackTarget(AudioCallbackPlaySource *source)
Chris@43 114 {
Chris@43 115 AudioCallbackPlayTarget *target = 0;
Chris@43 116
Chris@126 117 if (m_default != "" && m_default != "auto") {
Chris@126 118
Chris@126 119 #ifdef HAVE_JACK
Chris@126 120 if (m_default == "jack") target = new AudioJACKTarget(source);
Chris@126 121 #endif
Chris@126 122
Chris@126 123 #ifdef HAVE_LIBPULSE
Chris@126 124 if (m_default == "pulse") target = new AudioPulseAudioTarget(source);
Chris@126 125 #endif
Chris@126 126
Chris@126 127 #ifdef HAVE_COREAUDIO
Chris@126 128 if (m_default == "core") target = new AudioCoreAudioTarget(source);
Chris@126 129 #endif
Chris@126 130
Chris@126 131 #ifdef HAVE_PORTAUDIO_2_0
Chris@126 132 if (m_default == "port") target = new AudioPortAudioTarget(source);
Chris@126 133 #endif
Chris@126 134
Chris@126 135 if (!target || !target->isOK()) {
Chris@126 136 std::cerr << "WARNING: AudioTargetFactory::createCallbackTarget: Failed to open the requested target (\"" << m_default.toStdString() << "\")" << std::endl;
Chris@126 137 delete target;
Chris@126 138 return 0;
Chris@126 139 } else {
Chris@126 140 return target;
Chris@126 141 }
Chris@126 142 }
Chris@126 143
Chris@43 144 #ifdef HAVE_JACK
Chris@43 145 target = new AudioJACKTarget(source);
Chris@43 146 if (target->isOK()) return target;
Chris@43 147 else {
Chris@43 148 std::cerr << "WARNING: AudioTargetFactory::createCallbackTarget: Failed to open JACK target" << std::endl;
Chris@43 149 delete target;
Chris@43 150 }
Chris@43 151 #endif
Chris@117 152
Chris@117 153 #ifdef HAVE_LIBPULSE
Chris@117 154 target = new AudioPulseAudioTarget(source);
Chris@117 155 if (target->isOK()) return target;
Chris@117 156 else {
Chris@117 157 std::cerr << "WARNING: AudioTargetFactory::createCallbackTarget: Failed to open PulseAudio target" << std::endl;
Chris@117 158 delete target;
Chris@117 159 }
Chris@117 160 #endif
Chris@43 161
Chris@43 162 #ifdef HAVE_COREAUDIO
Chris@43 163 target = new AudioCoreAudioTarget(source);
Chris@43 164 if (target->isOK()) return target;
Chris@43 165 else {
Chris@43 166 std::cerr << "WARNING: AudioTargetFactory::createCallbackTarget: Failed to open CoreAudio target" << std::endl;
Chris@43 167 delete target;
Chris@43 168 }
Chris@43 169 #endif
Chris@114 170
Chris@114 171 #ifdef HAVE_PORTAUDIO_2_0
Chris@43 172 target = new AudioPortAudioTarget(source);
Chris@43 173 if (target->isOK()) return target;
Chris@43 174 else {
Chris@43 175 std::cerr << "WARNING: AudioTargetFactory::createCallbackTarget: Failed to open PortAudio target" << std::endl;
Chris@43 176 delete target;
Chris@43 177 }
Chris@43 178 #endif
Chris@43 179
Chris@43 180 std::cerr << "WARNING: AudioTargetFactory::createCallbackTarget: No suitable targets available" << std::endl;
Chris@43 181 return 0;
Chris@43 182 }
Chris@43 183
Chris@43 184