comparison data/fileio/AudioFileReaderFactory.cpp @ 290:92e8dbde73cd

* Revert revision 713. We do like QStrings after all.
author Chris Cannam
date Fri, 24 Aug 2007 11:41:48 +0000
parents 20028c634494
children c022976d18e8
comparison
equal deleted inserted replaced
289:3020904de772 290:92e8dbde73cd
22 22
23 #include <QString> 23 #include <QString>
24 #include <QFileInfo> 24 #include <QFileInfo>
25 #include <iostream> 25 #include <iostream>
26 26
27 std::string 27 QString
28 AudioFileReaderFactory::getKnownExtensions() 28 AudioFileReaderFactory::getKnownExtensions()
29 { 29 {
30 std::set<std::string> extensions; 30 std::set<QString> extensions;
31 31
32 WavFileReader::getSupportedExtensions(extensions); 32 WavFileReader::getSupportedExtensions(extensions);
33 #ifdef HAVE_MAD 33 #ifdef HAVE_MAD
34 MP3FileReader::getSupportedExtensions(extensions); 34 MP3FileReader::getSupportedExtensions(extensions);
35 #endif 35 #endif
40 #endif 40 #endif
41 #ifdef HAVE_QUICKTIME 41 #ifdef HAVE_QUICKTIME
42 QuickTimeFileReader::getSupportedExtensions(extensions); 42 QuickTimeFileReader::getSupportedExtensions(extensions);
43 #endif 43 #endif
44 44
45 std::string rv; 45 QString rv;
46 for (std::set<std::string>::const_iterator i = extensions.begin(); 46 for (std::set<QString>::const_iterator i = extensions.begin();
47 i != extensions.end(); ++i) { 47 i != extensions.end(); ++i) {
48 if (i != extensions.begin()) rv += " "; 48 if (i != extensions.begin()) rv += " ";
49 rv += "*." + *i; 49 rv += "*." + *i;
50 } 50 }
51 51
52 return rv; 52 return rv;
53 } 53 }
54 54
55 AudioFileReader * 55 AudioFileReader *
56 AudioFileReaderFactory::createReader(std::string path) 56 AudioFileReaderFactory::createReader(QString path)
57 { 57 {
58 std::string err; 58 QString err;
59 59
60 AudioFileReader *reader = 0; 60 AudioFileReader *reader = 0;
61 61
62 // First try to construct a preferred reader based on the 62 // First try to construct a preferred reader based on the
63 // extension. If we can't identify one or it fails to load the 63 // extension. If we can't identify one or it fails to load the
64 // file, fall back to trying all readers in no particular order. 64 // file, fall back to trying all readers in no particular order.
65 65
66 std::string ext; 66 QString ext = QFileInfo(path).suffix().toLower();
67 std::string::size_type idx = path.rfind('.'); 67 std::set<QString> extensions;
68 if (idx != std::string::npos) {
69 ext = path.substr(idx + 1);
70 for (size_t i = 0; i < ext.length(); ++i) {
71 ext[i] = std::tolower(ext[i]);
72 }
73 }
74
75 std::set<std::string> extensions;
76 68
77 WavFileReader::getSupportedExtensions(extensions); 69 WavFileReader::getSupportedExtensions(extensions);
78 if (extensions.find(ext) != extensions.end()) { 70 if (extensions.find(ext) != extensions.end()) {
79 reader = new WavFileReader(path); 71 reader = new WavFileReader(path);
80 } 72 }
122 114
123 if (reader) { 115 if (reader) {
124 if (reader->isOK()) return reader; 116 if (reader->isOK()) return reader;
125 if (reader->getError() != "") { 117 if (reader->getError() != "") {
126 std::cerr << "AudioFileReaderFactory: Preferred reader for " 118 std::cerr << "AudioFileReaderFactory: Preferred reader for "
127 << "extension \"" << ext << "\" failed: \"" 119 << "extension \"" << ext.toStdString() << "\" failed: \""
128 << reader->getError() << "\"" << std::endl; 120 << reader->getError().toStdString() << "\"" << std::endl;
129 } else { 121 } else {
130 std::cerr << "AudioFileReaderFactory: Preferred reader for " 122 std::cerr << "AudioFileReaderFactory: Preferred reader for "
131 << "extension \"" << ext << "\" failed" 123 << "extension \"" << ext.toStdString() << "\" failed"
132 << std::endl; 124 << std::endl;
133 } 125 }
134 delete reader; 126 delete reader;
135 reader = 0; 127 reader = 0;
136 } 128 }
137 129
138 reader = new WavFileReader(path); 130 reader = new WavFileReader(path);
139 if (reader->isOK()) return reader; 131 if (reader->isOK()) return reader;
140 if (reader->getError() != "") { 132 if (reader->getError() != "") {
141 std::cerr << "AudioFileReaderFactory: WAV file reader error: \"" 133 std::cerr << "AudioFileReaderFactory: WAV file reader error: \""
142 << reader->getError() << "\"" << std::endl; 134 << reader->getError().toStdString() << "\"" << std::endl;
143 } else { 135 } else {
144 std::cerr << "AudioFileReaderFactory: WAV file reader failed" 136 std::cerr << "AudioFileReaderFactory: WAV file reader failed"
145 << std::endl; 137 << std::endl;
146 } 138 }
147 delete reader; 139 delete reader;
153 OggVorbisFileReader::DecodeThreaded, 145 OggVorbisFileReader::DecodeThreaded,
154 OggVorbisFileReader::CacheInTemporaryFile); 146 OggVorbisFileReader::CacheInTemporaryFile);
155 if (reader->isOK()) return reader; 147 if (reader->isOK()) return reader;
156 if (reader->getError() != "") { 148 if (reader->getError() != "") {
157 std::cerr << "AudioFileReaderFactory: Ogg file reader error: \"" 149 std::cerr << "AudioFileReaderFactory: Ogg file reader error: \""
158 << reader->getError() << "\"" << std::endl; 150 << reader->getError().toStdString() << "\"" << std::endl;
159 } else { 151 } else {
160 std::cerr << "AudioFileReaderFactory: Ogg file reader failed" 152 std::cerr << "AudioFileReaderFactory: Ogg file reader failed"
161 << std::endl; 153 << std::endl;
162 } 154 }
163 delete reader; 155 delete reader;
170 MP3FileReader::DecodeThreaded, 162 MP3FileReader::DecodeThreaded,
171 MP3FileReader::CacheInTemporaryFile); 163 MP3FileReader::CacheInTemporaryFile);
172 if (reader->isOK()) return reader; 164 if (reader->isOK()) return reader;
173 if (reader->getError() != "") { 165 if (reader->getError() != "") {
174 std::cerr << "AudioFileReaderFactory: MP3 file reader error: \"" 166 std::cerr << "AudioFileReaderFactory: MP3 file reader error: \""
175 << reader->getError() << "\"" << std::endl; 167 << reader->getError().toStdString() << "\"" << std::endl;
176 } else { 168 } else {
177 std::cerr << "AudioFileReaderFactory: MP3 file reader failed" 169 std::cerr << "AudioFileReaderFactory: MP3 file reader failed"
178 << std::endl; 170 << std::endl;
179 } 171 }
180 delete reader; 172 delete reader;
186 QuickTimeFileReader::DecodeThreaded, 178 QuickTimeFileReader::DecodeThreaded,
187 QuickTimeFileReader::CacheInTemporaryFile); 179 QuickTimeFileReader::CacheInTemporaryFile);
188 if (reader->isOK()) return reader; 180 if (reader->isOK()) return reader;
189 if (reader->getError() != "") { 181 if (reader->getError() != "") {
190 std::cerr << "AudioFileReaderFactory: QuickTime file reader error: \"" 182 std::cerr << "AudioFileReaderFactory: QuickTime file reader error: \""
191 << reader->getError() << "\"" << std::endl; 183 << reader->getError().toStdString() << "\"" << std::endl;
192 } else { 184 } else {
193 std::cerr << "AudioFileReaderFactory: QuickTime file reader failed" 185 std::cerr << "AudioFileReaderFactory: QuickTime file reader failed"
194 << std::endl; 186 << std::endl;
195 } 187 }
196 delete reader; 188 delete reader;