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@149
|
23 #include "AudioCallbackPlayTarget.h"
|
Chris@149
|
24
|
Chris@126
|
25 #include <QCoreApplication>
|
Chris@126
|
26
|
Chris@43
|
27 #include <iostream>
|
Chris@43
|
28
|
Chris@126
|
29 AudioTargetFactory *
|
Chris@126
|
30 AudioTargetFactory::m_instance = 0;
|
Chris@126
|
31
|
Chris@126
|
32 AudioTargetFactory *
|
Chris@126
|
33 AudioTargetFactory::getInstance()
|
Chris@126
|
34 {
|
Chris@126
|
35 if (!m_instance) m_instance = new AudioTargetFactory();
|
Chris@126
|
36 return m_instance;
|
Chris@126
|
37 }
|
Chris@126
|
38
|
Chris@126
|
39 AudioTargetFactory::AudioTargetFactory()
|
Chris@126
|
40 {
|
Chris@126
|
41 }
|
Chris@126
|
42
|
Chris@126
|
43 std::vector<QString>
|
Chris@126
|
44 AudioTargetFactory::getCallbackTargetNames(bool includeAuto) const
|
Chris@126
|
45 {
|
Chris@126
|
46 std::vector<QString> names;
|
Chris@126
|
47 if (includeAuto) names.push_back("auto");
|
Chris@126
|
48
|
Chris@126
|
49 #ifdef HAVE_JACK
|
Chris@126
|
50 names.push_back("jack");
|
Chris@126
|
51 #endif
|
Chris@126
|
52
|
Chris@126
|
53 #ifdef HAVE_LIBPULSE
|
Chris@126
|
54 names.push_back("pulse");
|
Chris@126
|
55 #endif
|
Chris@126
|
56
|
Chris@126
|
57 #ifdef HAVE_COREAUDIO
|
Chris@126
|
58 names.push_back("core");
|
Chris@126
|
59 #endif
|
Chris@126
|
60
|
Chris@126
|
61 #ifdef HAVE_PORTAUDIO_2_0
|
Chris@126
|
62 names.push_back("port");
|
Chris@126
|
63 #endif
|
Chris@126
|
64
|
Chris@126
|
65 return names;
|
Chris@126
|
66 }
|
Chris@126
|
67
|
Chris@126
|
68 QString
|
Chris@126
|
69 AudioTargetFactory::getCallbackTargetDescription(QString name) const
|
Chris@126
|
70 {
|
Chris@126
|
71 if (name == "auto") {
|
Chris@126
|
72 return QCoreApplication::translate("AudioTargetFactory",
|
Chris@126
|
73 "(auto)");
|
Chris@126
|
74 }
|
Chris@126
|
75 if (name == "jack") {
|
Chris@126
|
76 return QCoreApplication::translate("AudioTargetFactory",
|
Chris@126
|
77 "JACK Audio Connection Kit");
|
Chris@126
|
78 }
|
Chris@126
|
79 if (name == "pulse") {
|
Chris@126
|
80 return QCoreApplication::translate("AudioTargetFactory",
|
Chris@126
|
81 "PulseAudio Server");
|
Chris@126
|
82 }
|
Chris@126
|
83 if (name == "core") {
|
Chris@126
|
84 return QCoreApplication::translate("AudioTargetFactory",
|
Chris@126
|
85 "Core Audio Device");
|
Chris@126
|
86 }
|
Chris@126
|
87 if (name == "port") {
|
Chris@126
|
88 return QCoreApplication::translate("AudioTargetFactory",
|
Chris@126
|
89 "Default Soundcard Device");
|
Chris@126
|
90 }
|
Chris@126
|
91
|
Chris@126
|
92 return "(unknown)";
|
Chris@126
|
93 }
|
Chris@126
|
94
|
Chris@126
|
95 QString
|
Chris@126
|
96 AudioTargetFactory::getDefaultCallbackTarget() const
|
Chris@126
|
97 {
|
Chris@126
|
98 if (m_default == "") return "auto";
|
Chris@126
|
99 return m_default;
|
Chris@126
|
100 }
|
Chris@126
|
101
|
Chris@126
|
102 bool
|
Chris@126
|
103 AudioTargetFactory::isAutoCallbackTarget(QString name) const
|
Chris@126
|
104 {
|
Chris@126
|
105 return (name == "auto" || name == "");
|
Chris@126
|
106 }
|
Chris@126
|
107
|
Chris@126
|
108 void
|
Chris@126
|
109 AudioTargetFactory::setDefaultCallbackTarget(QString target)
|
Chris@126
|
110 {
|
Chris@126
|
111 m_default = target;
|
Chris@126
|
112 }
|
Chris@126
|
113
|
Chris@43
|
114 AudioCallbackPlayTarget *
|
Chris@43
|
115 AudioTargetFactory::createCallbackTarget(AudioCallbackPlaySource *source)
|
Chris@43
|
116 {
|
Chris@43
|
117 AudioCallbackPlayTarget *target = 0;
|
Chris@43
|
118
|
Chris@126
|
119 if (m_default != "" && m_default != "auto") {
|
Chris@126
|
120
|
Chris@126
|
121 #ifdef HAVE_JACK
|
Chris@126
|
122 if (m_default == "jack") target = new AudioJACKTarget(source);
|
Chris@126
|
123 #endif
|
Chris@126
|
124
|
Chris@126
|
125 #ifdef HAVE_LIBPULSE
|
Chris@126
|
126 if (m_default == "pulse") target = new AudioPulseAudioTarget(source);
|
Chris@126
|
127 #endif
|
Chris@126
|
128
|
Chris@126
|
129 #ifdef HAVE_COREAUDIO
|
Chris@126
|
130 if (m_default == "core") target = new AudioCoreAudioTarget(source);
|
Chris@126
|
131 #endif
|
Chris@126
|
132
|
Chris@126
|
133 #ifdef HAVE_PORTAUDIO_2_0
|
Chris@126
|
134 if (m_default == "port") target = new AudioPortAudioTarget(source);
|
Chris@126
|
135 #endif
|
Chris@126
|
136
|
Chris@126
|
137 if (!target || !target->isOK()) {
|
Chris@228
|
138 std::cerr << "WARNING: AudioTargetFactory::createCallbackTarget: Failed to open the requested target (\"" << m_default << "\")" << std::endl;
|
Chris@126
|
139 delete target;
|
Chris@126
|
140 return 0;
|
Chris@126
|
141 } else {
|
Chris@126
|
142 return target;
|
Chris@126
|
143 }
|
Chris@126
|
144 }
|
Chris@126
|
145
|
Chris@43
|
146 #ifdef HAVE_JACK
|
Chris@43
|
147 target = new AudioJACKTarget(source);
|
Chris@43
|
148 if (target->isOK()) return target;
|
Chris@43
|
149 else {
|
Chris@43
|
150 std::cerr << "WARNING: AudioTargetFactory::createCallbackTarget: Failed to open JACK target" << std::endl;
|
Chris@43
|
151 delete target;
|
Chris@43
|
152 }
|
Chris@43
|
153 #endif
|
Chris@117
|
154
|
Chris@117
|
155 #ifdef HAVE_LIBPULSE
|
Chris@117
|
156 target = new AudioPulseAudioTarget(source);
|
Chris@117
|
157 if (target->isOK()) return target;
|
Chris@117
|
158 else {
|
Chris@117
|
159 std::cerr << "WARNING: AudioTargetFactory::createCallbackTarget: Failed to open PulseAudio target" << std::endl;
|
Chris@117
|
160 delete target;
|
Chris@117
|
161 }
|
Chris@117
|
162 #endif
|
Chris@43
|
163
|
Chris@43
|
164 #ifdef HAVE_COREAUDIO
|
Chris@43
|
165 target = new AudioCoreAudioTarget(source);
|
Chris@43
|
166 if (target->isOK()) return target;
|
Chris@43
|
167 else {
|
Chris@43
|
168 std::cerr << "WARNING: AudioTargetFactory::createCallbackTarget: Failed to open CoreAudio target" << std::endl;
|
Chris@43
|
169 delete target;
|
Chris@43
|
170 }
|
Chris@43
|
171 #endif
|
Chris@114
|
172
|
Chris@114
|
173 #ifdef HAVE_PORTAUDIO_2_0
|
Chris@43
|
174 target = new AudioPortAudioTarget(source);
|
Chris@43
|
175 if (target->isOK()) return target;
|
Chris@43
|
176 else {
|
Chris@43
|
177 std::cerr << "WARNING: AudioTargetFactory::createCallbackTarget: Failed to open PortAudio target" << std::endl;
|
Chris@43
|
178 delete target;
|
Chris@43
|
179 }
|
Chris@43
|
180 #endif
|
Chris@43
|
181
|
Chris@43
|
182 std::cerr << "WARNING: AudioTargetFactory::createCallbackTarget: No suitable targets available" << std::endl;
|
Chris@43
|
183 return 0;
|
Chris@43
|
184 }
|
Chris@43
|
185
|
Chris@43
|
186
|