comparison data/fileio/MP3FileReader.cpp @ 273:f1f47660483d

* Fix up and simplify the LayerTreeModel, removing a horrible memory leak * Move phase-unwrapped frequency estimation from SpectrogramLayer to FFTDataServer * Make the spectrum show peak phase-unwrapped frequencies as well (still needs work) * Start adding piano keyboard horizontal scale to spectrum * Debug output for id3 tags
author Chris Cannam
date Tue, 03 Jul 2007 12:46:18 +0000
parents 822bd7fd526c
children 20028c634494
comparison
equal deleted inserted replaced
272:8bbc9e336475 273:f1f47660483d
26 #include <iostream> 26 #include <iostream>
27 27
28 #ifdef HAVE_ID3TAG 28 #ifdef HAVE_ID3TAG
29 #include <id3tag.h> 29 #include <id3tag.h>
30 #endif 30 #endif
31 #define DEBUG_ID3TAG 1
31 32
32 #include <QApplication> 33 #include <QApplication>
33 #include <QFileInfo> 34 #include <QFileInfo>
34 #include <QProgressDialog> 35 #include <QProgressDialog>
35 36
149 150
150 id3_file *file = id3_file_open(m_path.toLocal8Bit().data(), 151 id3_file *file = id3_file_open(m_path.toLocal8Bit().data(),
151 ID3_FILE_MODE_READONLY); 152 ID3_FILE_MODE_READONLY);
152 if (!file) return; 153 if (!file) return;
153 154
155 // We can do this a lot more elegantly, but we'll leave that for
156 // when we implement support for more than just the one tag!
157
154 id3_tag *tag = id3_file_tag(file); 158 id3_tag *tag = id3_file_tag(file);
155 159 if (!tag) {
156 if (tag) { 160 #ifdef DEBUG_ID3TAG
157 id3_frame *frame = id3_tag_findframe(tag, "TIT2", 0); // work title 161 std::cerr << "MP3FileReader::loadTags: No ID3 tag found" << std::endl;
158 162 #endif
159 if (frame && frame->nfields >= 2) { 163 id3_file_close(file);
160 unsigned int nstrings = id3_field_getnstrings(&frame->fields[1]); 164 return;
161 165 }
162 if (nstrings > 0) { 166
163 id3_ucs4_t const *ustr = id3_field_getstrings(&frame->fields[1], 0); 167 id3_frame *frame = id3_tag_findframe(tag, "TIT2", 0); // work title
164 168 if (!frame) {
165 if (ustr) { 169 #ifdef DEBUG_ID3TAG
166 id3_utf8_t *u8str = id3_ucs4_utf8duplicate(ustr); 170 std::cerr << "MP3FileReader::loadTags: No work title in ID3 tag" << std::endl;
167 if (u8str) { 171 #endif
168 m_title = QString::fromUtf8((const char *)u8str); 172 id3_file_close(file);
169 free(u8str); 173 return;
170 } 174 }
171 } 175
172 } 176 if (frame->nfields < 2) {
173 } 177 std::cerr << "MP3FileReader::loadTags: WARNING: Not enough fields (" << frame->nfields << ") for work title in ID3 tag" << std::endl;
174 } 178 id3_file_close(file);
175 179 return;
180 }
181
182 unsigned int nstrings = id3_field_getnstrings(&frame->fields[1]);
183 if (nstrings == 0) {
184 #ifdef DEBUG_ID3TAG
185 std::cerr << "MP3FileReader::loadTags: No data for work title in ID3 tag" << std::endl;
186 #endif
187 id3_file_close(file);
188 return;
189 }
190
191 id3_ucs4_t const *ustr = id3_field_getstrings(&frame->fields[1], 0);
192 if (!ustr) {
193 #ifdef DEBUG_ID3TAG
194 std::cerr << "MP3FileReader::loadTags: Invalid or absent data for work title in ID3 tag" << std::endl;
195 #endif
196 id3_file_close(file);
197 return;
198 }
199
200 id3_utf8_t *u8str = id3_ucs4_utf8duplicate(ustr);
201 if (!u8str) {
202 std::cerr << "MP3FileReader::loadTags: ERROR: Internal error: Failed to convert UCS4 to UTF8 in ID3 title" << std::endl;
203 id3_file_close(file);
204 return;
205 }
206
207 m_title = QString::fromUtf8((const char *)u8str);
208 free(u8str);
176 id3_file_close(file); 209 id3_file_close(file);
177 #endif 210
211 #else
212 #ifdef DEBUG_ID3TAG
213 std::cerr << "MP3FileReader::loadTags: ID3 tag support not compiled in"
214 << std::endl;
215 #endif
216 #endif
217
178 } 218 }
179 219
180 void 220 void
181 MP3FileReader::DecodeThread::run() 221 MP3FileReader::DecodeThread::run()
182 { 222 {