comparison src/madplug/tuple.c @ 2203:13b8ab116b69

removed debugging stuff. some notes added
author Eugene Zagidullin <e.asphyx@gmail.com>
date Mon, 03 Dec 2007 02:10:29 +0300
parents f76e846d53d9
children 9a869d4bb0d3
comparison
equal deleted inserted replaced
2202:f76e846d53d9 2203:13b8ab116b69
35 #include <audacious/plugin.h> 35 #include <audacious/plugin.h>
36 #include <audacious/id3tag.h> 36 #include <audacious/id3tag.h>
37 37
38 /* yaz */ 38 /* yaz */
39 #include <langinfo.h> 39 #include <langinfo.h>
40
41 #define DEBUG
42 40
43 static void 41 static void
44 update_id3_frame(struct id3_tag *tag, const char *frame_name, const char *data, int sjis) 42 update_id3_frame(struct id3_tag *tag, const char *frame_name, const char *data, int sjis)
45 { 43 {
46 int res; 44 int res;
49 id3_ucs4_t *ucs4; 47 id3_ucs4_t *ucs4;
50 48
51 if (data == NULL) 49 if (data == NULL)
52 return; 50 return;
53 51
54 // printf ("updating id3: %s: %s\n", frame_name, data); 52 /* printf ("updating id3: %s: %s\n", frame_name, data);
55 53
56 // 54
57 // An empty string removes the frame altogether. 55 An empty string removes the frame altogether.
58 // 56 */
59 if (strlen(data) == 0) { 57 if (strlen(data) == 0) {
60 while ((frame = id3_tag_findframe(tag, frame_name, 0))) { 58 while ((frame = id3_tag_findframe(tag, frame_name, 0))) {
61 #ifdef DEBUG 59 #ifdef DEBUG
62 fprintf(stderr, "madplug: detachframe\n"); 60 fprintf(stderr, "madplug: detachframe\n");
63 #endif 61 #endif
73 #endif 71 #endif
74 frame = id3_frame_new(frame_name); 72 frame = id3_frame_new(frame_name);
75 id3_tag_attachframe(tag, frame); 73 id3_tag_attachframe(tag, frame);
76 } 74 }
77 75
78 // setup ucs4 string 76 /* setup ucs4 string */
79 if(sjis) { 77 if(sjis) {
80 ucs4 = id3_latin1_ucs4duplicate((id3_latin1_t *) data); 78 ucs4 = id3_latin1_ucs4duplicate((id3_latin1_t *) data);
81 } 79 }
82 else { 80 else {
83 ucs4 = id3_utf8_ucs4duplicate((id3_utf8_t *) data); 81 ucs4 = id3_utf8_ucs4duplicate((id3_utf8_t *) data);
84 } 82 }
85 83
86 // set encoding 84 /* set encoding */
87 field = id3_frame_field(frame, 0); 85 field = id3_frame_field(frame, 0);
88 id3_field_settextencoding(field, sjis ? ID3_FIELD_TEXTENCODING_ISO_8859_1 : 86 id3_field_settextencoding(field, sjis ? ID3_FIELD_TEXTENCODING_ISO_8859_1 :
89 ID3_FIELD_TEXTENCODING_UTF_8); 87 ID3_FIELD_TEXTENCODING_UTF_8);
90 88
91 // setup genre code 89 /* setup genre code */
92 if (!strcmp(frame_name, ID3_FRAME_GENRE)) { 90 if (!strcmp(frame_name, ID3_FRAME_GENRE)) {
93 char *tmp; 91 char *tmp;
94 int index = id3_genre_number(ucs4); 92 int index = id3_genre_number(ucs4);
95 g_free(ucs4); 93 g_free(ucs4);
96 94
97 if(index == -1) { // unknown genre. remove TCON frame. 95 if(index == -1) { /* unknown genre. remove TCON frame. */
98 #ifdef DEBUG 96 #ifdef DEBUG
99 fprintf(stderr, "madplug: remove genre frame\n"); 97 fprintf(stderr, "madplug: remove genre frame\n");
100 #endif 98 #endif
101 id3_tag_detachframe(tag, frame); 99 id3_tag_detachframe(tag, frame);
102 } 100 }
103 else { // meaningful genre 101 else { /* meaningful genre */
104 tmp = g_strdup_printf("%d", index); 102 tmp = g_strdup_printf("%d", index);
105 ucs4 = id3_latin1_ucs4duplicate((unsigned char *) tmp); 103 ucs4 = id3_latin1_ucs4duplicate((unsigned char *) tmp);
106 } 104 }
107 105
108 } 106 }
109 107
110 // write string 108 /* write string */
111 if (!strcmp(frame_name, ID3_FRAME_COMMENT)) { 109 if (!strcmp(frame_name, ID3_FRAME_COMMENT)) {
112 field = id3_frame_field(frame, 3); 110 field = id3_frame_field(frame, 3);
113 field->type = ID3_FIELD_TYPE_STRINGFULL; 111 field->type = ID3_FIELD_TYPE_STRINGFULL;
114 res = id3_field_setfullstring(field, ucs4); 112 res = id3_field_setfullstring(field, ucs4);
115 } 113 }
203 201
204 id3_file_close(id3file); 202 id3_file_close(id3file);
205 return TRUE; 203 return TRUE;
206 } 204 }
207 205
208 /*#endif // !NOGUI
209
210 void audmad_get_file_info(char *fileurl)
211 {
212 #ifndef NOGUI
213 gchar *title;
214 gchar message[128];
215 static char const *const layer_str[3] = { "I", "II", "III" };
216 static char const *const mode_str[4] = {
217 ("single channel"), ("dual channel"), "joint stereo", "stereo"
218 };
219 gchar *tmp, *utf_filename;
220 gchar *realfn = NULL;
221 #ifdef DEBUG
222 {
223 tmp = aud_str_to_utf8(fileurl);
224 g_message("f: audmad_get_file_info: %s", tmp);
225 g_free(tmp);
226 tmp = NULL;
227 }
228 #endif
229
230 if(!aud_vfs_is_remote(fileurl) && !aud_vfs_file_test(fileurl, G_FILE_TEST_EXISTS)) {
231 return;
232 }
233
234 input_init(&info, fileurl, NULL);
235
236 if(audmad_is_remote(fileurl)) {
237 info.remote = TRUE;
238 if(aud_vfs_is_streaming(info.infile))
239 return; //file info dialog for remote streaming doesn't make sense.
240 }
241
242 realfn = g_filename_from_uri(fileurl, NULL, NULL);
243 utf_filename = aud_str_to_utf8(realfn ? realfn : fileurl);
244 g_free(realfn); realfn = NULL;
245 create_window();
246
247 info.fileinfo_request = TRUE;
248 input_get_info(&info, info.remote ? TRUE : FALSE);
249
250 tmp = g_path_get_basename(utf_filename);
251 title = g_strdup_printf(_("File Info - %s"), tmp);
252 g_free(tmp); tmp = NULL;
253 gtk_window_set_title(GTK_WINDOW(window), title);
254 g_free(title);
255
256 gtk_entry_set_text(GTK_ENTRY(filename_entry), utf_filename);
257 gtk_editable_set_position(GTK_EDITABLE(filename_entry), -1);
258
259 free(utf_filename);
260
261 id3_frame_to_entry(ID3_FRAME_ARTIST, GTK_ENTRY(artist_entry));
262 id3_frame_to_entry(ID3_FRAME_TITLE, GTK_ENTRY(title_entry));
263 id3_frame_to_entry(ID3_FRAME_ALBUM, GTK_ENTRY(album_entry));
264
265 // year
266 // id3_frame_to_entry (ID3_FRAME_YEAR, GTK_ENTRY (year_entry));
267 // to set year entry, we have to do manually because TYER is still used equally to TDRC.
268 gtk_entry_set_text(GTK_ENTRY(year_entry), "");
269 if (info.tag) {
270 gchar *text = NULL;
271 text = input_id3_get_string(info.tag, "TDRC");
272 if (!text)
273 text = input_id3_get_string(info.tag, "TYER");
274 if (text) {
275 gtk_entry_set_text(GTK_ENTRY(year_entry), text);
276 g_free(text);
277 }
278 }
279
280 id3_frame_to_entry(ID3_FRAME_TRACK, GTK_ENTRY(tracknum_entry));
281 id3_frame_to_entry(ID3_FRAME_COMMENT, GTK_ENTRY(comment_entry));
282 snprintf(message, 127, _("Layer %s"), layer_str[info.mpeg_layer - 1]);
283 gtk_label_set_text(GTK_LABEL(mpeg_level), message);
284 if (info.vbr) {
285 snprintf(message, 127, _("VBR (avg. %d kbps)"), info.bitrate / 1000);
286 }
287 else {
288 snprintf(message, 127, "%d kbps", info.bitrate / 1000);
289 }
290 gtk_label_set_text(GTK_LABEL(mpeg_bitrate), message);
291 snprintf(message, 127, _("%d Hz"), info.freq);
292 gtk_label_set_text(GTK_LABEL(mpeg_samplerate), message);
293 if (info.frames != -1) {
294 snprintf(message, 127, _("%d frames"), info.frames);
295 gtk_label_set_text(GTK_LABEL(mpeg_frames), message);
296 }
297 else {
298 gtk_label_set_text(GTK_LABEL(mpeg_frames), "");
299 }
300 gtk_label_set_text(GTK_LABEL(mpeg_flags), mode_str[info.mode]);
301 {
302 guint sec = mad_timer_count(info.duration, MAD_UNITS_SECONDS);
303 snprintf(message, 127, _("%d:%02d (%d seconds)"), sec /60 ,sec % 60, sec);
304 }
305 gtk_label_set_text(GTK_LABEL(mpeg_duration), message);
306
307 if (info.replaygain_album_str != NULL) {
308 snprintf(message, 127, _("RG_album=%4s (x%4.2f)"),
309 info.replaygain_album_str, info.replaygain_album_scale);
310 gtk_label_set_text(GTK_LABEL(mpeg_replaygain), message);
311 }
312 else
313 gtk_label_set_text(GTK_LABEL(mpeg_replaygain), "");
314
315 if (info.replaygain_track_str != NULL) {
316 snprintf(message, 127, _("RG_track=%4s (x%4.2f)"),
317 info.replaygain_track_str, info.replaygain_track_scale);
318 gtk_label_set_text(GTK_LABEL(mpeg_replaygain2), message);
319 }
320 else
321 gtk_label_set_text(GTK_LABEL(mpeg_replaygain2), "");
322
323 if (info.replaygain_album_peak_str != NULL) {
324 snprintf(message, 127, _("Peak album=%4s (%+5.3fdBFS)"),
325 info.replaygain_album_peak_str,
326 20 * log10(info.replaygain_album_peak));
327 gtk_label_set_text(GTK_LABEL(mpeg_replaygain3), message);
328 }
329 else
330 gtk_label_set_text(GTK_LABEL(mpeg_replaygain3), "");
331
332 if (info.replaygain_track_peak_str != NULL) {
333 snprintf(message, 127, _("Peak track=%4s (%+5.3fdBFS)"),
334 info.replaygain_track_peak_str,
335 20 * log10(info.replaygain_track_peak));
336 gtk_label_set_text(GTK_LABEL(mpeg_replaygain4), message);
337 }
338 else
339 gtk_label_set_text(GTK_LABEL(mpeg_replaygain3), "");
340
341 if (info.mp3gain_undo_str != NULL) {
342 snprintf(message, 127, _("mp3gain undo=%4s (%+5.3fdB)"),
343 info.mp3gain_undo_str, info.mp3gain_undo);
344 gtk_label_set_text(GTK_LABEL(mp3gain1), message);
345 }
346 else
347 gtk_label_set_text(GTK_LABEL(mp3gain1), "");
348
349 if (info.mp3gain_minmax_str != NULL) {
350 snprintf(message, 127, _("mp3gain minmax=%4s (max-min=%+6.3fdB)"),
351 info.mp3gain_minmax_str, info.mp3gain_minmax);
352 gtk_label_set_text(GTK_LABEL(mp3gain2), message);
353 }
354 else
355 gtk_label_set_text(GTK_LABEL(mp3gain2), "");
356
357 gtk_label_set_text(GTK_LABEL(mpeg_fileinfo), "");
358
359
360 // work out the index of the genre in the list
361 {
362 const id3_ucs4_t *string;
363 id3_ucs4_t *genre;
364 struct id3_frame *frame;
365 union id3_field *field;
366 frame = id3_tag_findframe(info.tag, ID3_FRAME_GENRE, 0);
367 if (frame) {
368 field = id3_frame_field(frame, 1);
369 string = id3_field_getstrings(field, 0);
370 genre = mad_parse_genre(string);
371 #ifdef DEBUG
372 if (genre) {
373 gchar *utf = (gchar *)id3_ucs4_utf8duplicate(genre);
374 g_print("genre = %s\n", utf);
375 g_print("genre num = %d\n", id3_genre_number(genre));
376 g_free(utf);
377 }
378 #endif
379 if (genre) {
380 gtk_list_select_item(GTK_LIST
381 (GTK_COMBO(genre_combo)->list),
382 id3_genre_number(genre)+1); //shift one for "Unknown".
383 g_free((void *)genre);
384 }
385 }
386 }
387
388 gtk_widget_set_sensitive(id3_frame, TRUE);
389
390 #endif // !NOGUI
391 }*/
392