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