Mercurial > hg > svcore
comparison data/fileio/MP3FileReader.cpp @ 333:1afaf98dbf11
* Factor out uses of "Sonic Visualiser" in "common" code to applicationName()
* Add ability to show work title + artist in top-left of pane (thinking of Vect
but may be useful in SV in future)
* A few other generalisations useful for Vect
author | Chris Cannam |
---|---|
date | Fri, 09 Nov 2007 17:46:58 +0000 |
parents | 1d656dcda8ef |
children | aa8dbac62024 |
comparison
equal
deleted
inserted
replaced
332:13e5870040e6 | 333:1afaf98dbf11 |
---|---|
166 #endif | 166 #endif |
167 id3_file_close(file); | 167 id3_file_close(file); |
168 return; | 168 return; |
169 } | 169 } |
170 | 170 |
171 id3_frame *frame = id3_tag_findframe(tag, "TIT2", 0); // work title | 171 m_title = loadTag(tag, "TIT2"); // work title |
172 if (m_title == "") m_title = loadTag(tag, "TIT1"); | |
173 | |
174 m_maker = loadTag(tag, "TPE1"); // "lead artist" | |
175 if (m_maker == "") m_maker = loadTag(tag, "TPE2"); | |
176 | |
177 id3_file_close(file); | |
178 | |
179 #else | |
180 #ifdef DEBUG_ID3TAG | |
181 std::cerr << "MP3FileReader::loadTags: ID3 tag support not compiled in" | |
182 << std::endl; | |
183 #endif | |
184 #endif | |
185 } | |
186 | |
187 QString | |
188 MP3FileReader::loadTag(void *vtag, const char *name) | |
189 { | |
190 #ifdef HAVE_ID3TAG | |
191 id3_tag *tag = (id3_tag *)vtag; | |
192 | |
193 id3_frame *frame = id3_tag_findframe(tag, name, 0); | |
172 if (!frame) { | 194 if (!frame) { |
173 #ifdef DEBUG_ID3TAG | 195 #ifdef DEBUG_ID3TAG |
174 std::cerr << "MP3FileReader::loadTags: No work title in ID3 tag" << std::endl; | 196 std::cerr << "MP3FileReader::loadTags: No \"" << name << "\" in ID3 tag" << std::endl; |
175 #endif | 197 #endif |
176 id3_file_close(file); | 198 return ""; |
177 return; | |
178 } | 199 } |
179 | 200 |
180 if (frame->nfields < 2) { | 201 if (frame->nfields < 2) { |
181 std::cerr << "MP3FileReader::loadTags: WARNING: Not enough fields (" << frame->nfields << ") for work title in ID3 tag" << std::endl; | 202 std::cerr << "MP3FileReader::loadTags: WARNING: Not enough fields (" << frame->nfields << ") for \"" << name << "\" in ID3 tag" << std::endl; |
182 id3_file_close(file); | 203 return ""; |
183 return; | |
184 } | 204 } |
185 | 205 |
186 unsigned int nstrings = id3_field_getnstrings(&frame->fields[1]); | 206 unsigned int nstrings = id3_field_getnstrings(&frame->fields[1]); |
187 if (nstrings == 0) { | 207 if (nstrings == 0) { |
188 #ifdef DEBUG_ID3TAG | 208 #ifdef DEBUG_ID3TAG |
189 std::cerr << "MP3FileReader::loadTags: No data for work title in ID3 tag" << std::endl; | 209 std::cerr << "MP3FileReader::loadTags: No data for \"" << name << "\" in ID3 tag" << std::endl; |
190 #endif | 210 #endif |
191 id3_file_close(file); | 211 return ""; |
192 return; | |
193 } | 212 } |
194 | 213 |
195 id3_ucs4_t const *ustr = id3_field_getstrings(&frame->fields[1], 0); | 214 id3_ucs4_t const *ustr = id3_field_getstrings(&frame->fields[1], 0); |
196 if (!ustr) { | 215 if (!ustr) { |
197 #ifdef DEBUG_ID3TAG | 216 #ifdef DEBUG_ID3TAG |
198 std::cerr << "MP3FileReader::loadTags: Invalid or absent data for work title in ID3 tag" << std::endl; | 217 std::cerr << "MP3FileReader::loadTags: Invalid or absent data for \"" << name << "\" in ID3 tag" << std::endl; |
199 #endif | 218 #endif |
200 id3_file_close(file); | 219 return ""; |
201 return; | |
202 } | 220 } |
203 | 221 |
204 id3_utf8_t *u8str = id3_ucs4_utf8duplicate(ustr); | 222 id3_utf8_t *u8str = id3_ucs4_utf8duplicate(ustr); |
205 if (!u8str) { | 223 if (!u8str) { |
206 std::cerr << "MP3FileReader::loadTags: ERROR: Internal error: Failed to convert UCS4 to UTF8 in ID3 title" << std::endl; | 224 std::cerr << "MP3FileReader::loadTags: ERROR: Internal error: Failed to convert UCS4 to UTF8 in ID3 title" << std::endl; |
207 id3_file_close(file); | 225 return ""; |
208 return; | |
209 } | 226 } |
210 | 227 |
211 m_title = QString::fromUtf8((const char *)u8str); | 228 QString rv = QString::fromUtf8((const char *)u8str); |
212 free(u8str); | 229 free(u8str); |
213 id3_file_close(file); | 230 return rv; |
214 | 231 |
215 #else | 232 #else |
216 #ifdef DEBUG_ID3TAG | 233 return ""; |
217 std::cerr << "MP3FileReader::loadTags: ID3 tag support not compiled in" | 234 #endif |
218 << std::endl; | |
219 #endif | |
220 #endif | |
221 | |
222 } | 235 } |
223 | 236 |
224 void | 237 void |
225 MP3FileReader::DecodeThread::run() | 238 MP3FileReader::DecodeThread::run() |
226 { | 239 { |