comparison data/fileio/AudioFileReaderFactory.cpp @ 285:20028c634494

* change some QStrings to std::strings etc
author Chris Cannam
date Thu, 09 Aug 2007 16:29:29 +0000
parents 9c447d664275
children 92e8dbde73cd
comparison
equal deleted inserted replaced
284:41d64b873d87 285:20028c634494
22 22
23 #include <QString> 23 #include <QString>
24 #include <QFileInfo> 24 #include <QFileInfo>
25 #include <iostream> 25 #include <iostream>
26 26
27 QString 27 std::string
28 AudioFileReaderFactory::getKnownExtensions() 28 AudioFileReaderFactory::getKnownExtensions()
29 { 29 {
30 std::set<QString> extensions; 30 std::set<std::string> 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 QString rv; 45 std::string rv;
46 for (std::set<QString>::const_iterator i = extensions.begin(); 46 for (std::set<std::string>::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(QString path) 56 AudioFileReaderFactory::createReader(std::string path)
57 { 57 {
58 QString err; 58 std::string 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 QString ext = QFileInfo(path).suffix().toLower(); 66 std::string ext;
67 std::set<QString> extensions; 67 std::string::size_type idx = path.rfind('.');
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;
68 76
69 WavFileReader::getSupportedExtensions(extensions); 77 WavFileReader::getSupportedExtensions(extensions);
70 if (extensions.find(ext) != extensions.end()) { 78 if (extensions.find(ext) != extensions.end()) {
71 reader = new WavFileReader(path); 79 reader = new WavFileReader(path);
72 } 80 }
114 122
115 if (reader) { 123 if (reader) {
116 if (reader->isOK()) return reader; 124 if (reader->isOK()) return reader;
117 if (reader->getError() != "") { 125 if (reader->getError() != "") {
118 std::cerr << "AudioFileReaderFactory: Preferred reader for " 126 std::cerr << "AudioFileReaderFactory: Preferred reader for "
119 << "extension \"" << ext.toStdString() << "\" failed: \"" 127 << "extension \"" << ext << "\" failed: \""
120 << reader->getError().toStdString() << "\"" << std::endl; 128 << reader->getError() << "\"" << std::endl;
121 } else { 129 } else {
122 std::cerr << "AudioFileReaderFactory: Preferred reader for " 130 std::cerr << "AudioFileReaderFactory: Preferred reader for "
123 << "extension \"" << ext.toStdString() << "\" failed" 131 << "extension \"" << ext << "\" failed"
124 << std::endl; 132 << std::endl;
125 } 133 }
126 delete reader; 134 delete reader;
127 reader = 0; 135 reader = 0;
128 } 136 }
129 137
130 reader = new WavFileReader(path); 138 reader = new WavFileReader(path);
131 if (reader->isOK()) return reader; 139 if (reader->isOK()) return reader;
132 if (reader->getError() != "") { 140 if (reader->getError() != "") {
133 std::cerr << "AudioFileReaderFactory: WAV file reader error: \"" 141 std::cerr << "AudioFileReaderFactory: WAV file reader error: \""
134 << reader->getError().toStdString() << "\"" << std::endl; 142 << reader->getError() << "\"" << std::endl;
135 } else { 143 } else {
136 std::cerr << "AudioFileReaderFactory: WAV file reader failed" 144 std::cerr << "AudioFileReaderFactory: WAV file reader failed"
137 << std::endl; 145 << std::endl;
138 } 146 }
139 delete reader; 147 delete reader;
145 OggVorbisFileReader::DecodeThreaded, 153 OggVorbisFileReader::DecodeThreaded,
146 OggVorbisFileReader::CacheInTemporaryFile); 154 OggVorbisFileReader::CacheInTemporaryFile);
147 if (reader->isOK()) return reader; 155 if (reader->isOK()) return reader;
148 if (reader->getError() != "") { 156 if (reader->getError() != "") {
149 std::cerr << "AudioFileReaderFactory: Ogg file reader error: \"" 157 std::cerr << "AudioFileReaderFactory: Ogg file reader error: \""
150 << reader->getError().toStdString() << "\"" << std::endl; 158 << reader->getError() << "\"" << std::endl;
151 } else { 159 } else {
152 std::cerr << "AudioFileReaderFactory: Ogg file reader failed" 160 std::cerr << "AudioFileReaderFactory: Ogg file reader failed"
153 << std::endl; 161 << std::endl;
154 } 162 }
155 delete reader; 163 delete reader;
162 MP3FileReader::DecodeThreaded, 170 MP3FileReader::DecodeThreaded,
163 MP3FileReader::CacheInTemporaryFile); 171 MP3FileReader::CacheInTemporaryFile);
164 if (reader->isOK()) return reader; 172 if (reader->isOK()) return reader;
165 if (reader->getError() != "") { 173 if (reader->getError() != "") {
166 std::cerr << "AudioFileReaderFactory: MP3 file reader error: \"" 174 std::cerr << "AudioFileReaderFactory: MP3 file reader error: \""
167 << reader->getError().toStdString() << "\"" << std::endl; 175 << reader->getError() << "\"" << std::endl;
168 } else { 176 } else {
169 std::cerr << "AudioFileReaderFactory: MP3 file reader failed" 177 std::cerr << "AudioFileReaderFactory: MP3 file reader failed"
170 << std::endl; 178 << std::endl;
171 } 179 }
172 delete reader; 180 delete reader;
178 QuickTimeFileReader::DecodeThreaded, 186 QuickTimeFileReader::DecodeThreaded,
179 QuickTimeFileReader::CacheInTemporaryFile); 187 QuickTimeFileReader::CacheInTemporaryFile);
180 if (reader->isOK()) return reader; 188 if (reader->isOK()) return reader;
181 if (reader->getError() != "") { 189 if (reader->getError() != "") {
182 std::cerr << "AudioFileReaderFactory: QuickTime file reader error: \"" 190 std::cerr << "AudioFileReaderFactory: QuickTime file reader error: \""
183 << reader->getError().toStdString() << "\"" << std::endl; 191 << reader->getError() << "\"" << std::endl;
184 } else { 192 } else {
185 std::cerr << "AudioFileReaderFactory: QuickTime file reader failed" 193 std::cerr << "AudioFileReaderFactory: QuickTime file reader failed"
186 << std::endl; 194 << std::endl;
187 } 195 }
188 delete reader; 196 delete reader;