Mercurial > audlegacy-plugins
annotate src/tta/aud-tta.c @ 734:ff62f5530a36 trunk
[svn] - freebsd portability fixes from "The_Paya". Closes #814.
author | nenolod |
---|---|
date | Tue, 27 Feb 2007 01:27:06 -0800 |
parents | 7b65072e2efb |
children | 712df386597e |
rev | line source |
---|---|
290 | 1 /* |
2 * aud--tta.c | |
3 * | |
4 * Description: TTA input plug-in for Audacious | |
5 * Developed by: Alexander Djourik <sasha@iszf.irk.ru> | |
6 * Pavel Zhilin <pzh@iszf.irk.ru> | |
7 * Audacious port: Yoshiki Yazawa <yaz@cc.rim.or.jp> | |
8 * | |
9 * Copyright (c) 2004 Alexander Djourik. All rights reserved. | |
10 * | |
11 */ | |
12 | |
13 /* | |
14 * This library is free software; you can redistribute it and/or | |
15 * modify it under the terms of the GNU Lesser General Public | |
16 * License as published by the Free Software Foundation; either | |
17 * version 2.1 of the License, or (at your option) any later version. | |
18 * | |
19 * This library is distributed in the hope that it will be useful, | |
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
22 * Lesser General Public License for more details. | |
23 * | |
24 * You should have received a copy of the GNU Lesser General Public | |
25 * License along with this library; if not, write to the Free Software | |
26 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
27 * | |
28 * Please see the file COPYING in this directory for full copyright | |
29 * information. | |
30 */ | |
528 | 31 |
32 #ifdef HAVE_CONFIG_H | |
33 # include "config.h" | |
34 #endif | |
35 | |
290 | 36 #include <stdio.h> |
37 #include <stdlib.h> | |
38 #include <string.h> | |
39 #include <time.h> | |
40 #include <sys/types.h> | |
41 #include <sys/stat.h> | |
42 #include <glib.h> | |
43 #include <pthread.h> | |
44 #include <string.h> | |
45 | |
46 #include <audacious/util.h> | |
47 #include <audacious/plugin.h> | |
48 #include <audacious/titlestring.h> | |
49 #include <audacious/vfs.h> | |
50 #include "aud-support.h" | |
520
8f1785471613
[svn] - add missing inclusion of audacious/strings.h where necessary
giacomo
parents:
443
diff
changeset
|
51 #include <audacious/output.h> |
8f1785471613
[svn] - add missing inclusion of audacious/strings.h where necessary
giacomo
parents:
443
diff
changeset
|
52 #include <audacious/strings.h> |
527
d124034ebea3
[svn] - glib/gi18n.h -> audacious/i18n.h for automatic dgettext support
nenolod
parents:
520
diff
changeset
|
53 #include <audacious/i18n.h> |
290 | 54 |
661 | 55 #include <audacious/id3tag.h> |
290 | 56 |
57 | |
58 | |
59 #define PLUGIN_VERSION "1.2" | |
60 #define PROJECT_URL "<http://www.true-audio.com>" | |
61 | |
62 #pragma pack (1) | |
63 #include "ttalib.h" | |
64 | |
65 #define OUTPUT_ERROR (MEMORY_ERROR+1) | |
66 #define MAX_BSIZE (MAX_BPS>>3) | |
67 | |
68 | |
69 static void init (); | |
70 static void cleanup (); | |
71 static int is_our_file (char *filename); | |
561
914c96de3244
[svn] Convert plugins to use InputPlayback.output instead of InputPlugin.output
iabervon
parents:
528
diff
changeset
|
72 static void play_file (InputPlayback *playback); |
914c96de3244
[svn] Convert plugins to use InputPlayback.output instead of InputPlugin.output
iabervon
parents:
528
diff
changeset
|
73 static void tta_pause (InputPlayback *playback, short paused); |
914c96de3244
[svn] Convert plugins to use InputPlayback.output instead of InputPlugin.output
iabervon
parents:
528
diff
changeset
|
74 static void stop (InputPlayback *playback); |
914c96de3244
[svn] Convert plugins to use InputPlayback.output instead of InputPlugin.output
iabervon
parents:
528
diff
changeset
|
75 static void seek (InputPlayback *playback, int time); |
914c96de3244
[svn] Convert plugins to use InputPlayback.output instead of InputPlugin.output
iabervon
parents:
528
diff
changeset
|
76 static int get_time (InputPlayback *playback); |
290 | 77 static void get_song_info (char *filename, char **title, int *length); |
78 static void file_info (char *filename); | |
79 static void about (); | |
80 static TitleInput *get_song_tuple(char *filename); | |
81 static gchar *extname(const char *filename); | |
82 | |
372
a157306caf03
[svn] - finalize the plugin-side of the extension-assist ABI
nenolod
parents:
368
diff
changeset
|
83 gchar *tta_fmts[] = { "tta", NULL }; |
a157306caf03
[svn] - finalize the plugin-side of the extension-assist ABI
nenolod
parents:
368
diff
changeset
|
84 |
290 | 85 InputPlugin tta_ip = |
86 { | |
87 NULL, | |
88 NULL, | |
89 NULL, | |
90 init, | |
91 about, | |
92 NULL, | |
93 is_our_file, | |
94 NULL, | |
95 play_file, | |
96 stop, | |
97 tta_pause, | |
98 seek, | |
99 NULL, | |
100 get_time, | |
101 NULL, | |
102 NULL, | |
103 cleanup, | |
104 NULL, | |
105 NULL, | |
106 NULL, | |
107 NULL, | |
108 get_song_info, | |
109 file_info, | |
110 NULL, | |
111 get_song_tuple, // get_song_tuple | |
112 NULL, // set_song_tuple | |
368
c812e846b84e
[svn] - add support for extension probing to many plugins.
nenolod
parents:
290
diff
changeset
|
113 NULL, // buffer |
372
a157306caf03
[svn] - finalize the plugin-side of the extension-assist ABI
nenolod
parents:
368
diff
changeset
|
114 NULL, // vfs |
a157306caf03
[svn] - finalize the plugin-side of the extension-assist ABI
nenolod
parents:
368
diff
changeset
|
115 tta_fmts, |
290 | 116 }; |
117 | |
118 InputPlugin * | |
119 get_iplugin_info (void) | |
120 { | |
121 tta_ip.description = g_strdup_printf ("True Audio Plugin %s", PLUGIN_VERSION); | |
122 return &tta_ip; | |
123 } | |
124 | |
125 static pthread_t decode_thread; | |
126 static char sample_buffer[PCM_BUFFER_LENGTH * MAX_BSIZE * MAX_NCH]; | |
127 static tta_info info; // currently playing file info | |
128 static long seek_position = -1; | |
129 static int playing = FALSE; | |
130 static int read_samples = -1; | |
131 | |
132 static void | |
133 tta_error (int error) | |
134 { | |
135 char *message; | |
136 static GtkWidget *errorbox; | |
137 if (errorbox != NULL) return; | |
138 | |
139 switch (error) | |
140 { | |
141 case OPEN_ERROR: | |
142 message = "Can't open file\n"; | |
143 break; | |
144 case FORMAT_ERROR: | |
145 message = "Not supported file format\n"; | |
146 break; | |
147 case FILE_ERROR: | |
148 message = "File is corrupted\n"; | |
149 break; | |
150 case READ_ERROR: | |
151 message = "Can't read from file\n"; | |
152 break; | |
153 case MEMORY_ERROR: | |
154 message = "Insufficient memory available\n"; | |
155 break; | |
156 case OUTPUT_ERROR: | |
157 message = "Output plugin error\n"; | |
158 break; | |
159 default: | |
160 message = "Unknown error\n"; | |
161 break; | |
162 } | |
163 | |
164 xmms_show_message ("TTA Decoder Error", message, | |
165 "Ok", FALSE, NULL, NULL); | |
166 | |
167 gtk_signal_connect(GTK_OBJECT(errorbox), "destroy", | |
168 G_CALLBACK(gtk_widget_destroyed), &errorbox); | |
169 } | |
170 | |
171 static gchar * | |
172 get_title (char *filename, tta_info *ttainfo) | |
173 { | |
174 char *name, *p; | |
175 | |
176 if (ttainfo->id3v2.id3has && | |
177 (*ttainfo->id3v2.artist || *ttainfo->id3v2.title)) { | |
178 if (*ttainfo->id3v2.artist && *ttainfo->id3v2.title) | |
179 return g_strdup_printf("%s - %s", ttainfo->id3v2.artist, ttainfo->id3v2.title); | |
180 else if (*ttainfo->id3v2.artist && *ttainfo->id3v2.album) | |
181 return g_strdup_printf("%s - %s", ttainfo->id3v2.artist, ttainfo->id3v2.album); | |
182 else if (*ttainfo->id3v2.artist) return g_strdup(ttainfo->id3v2.artist); | |
183 else if (*ttainfo->id3v2.title) return g_strdup(ttainfo->id3v2.title); | |
184 } else if (ttainfo->id3v1.id3has && | |
185 (*ttainfo->id3v1.artist || *ttainfo->id3v1.title)) { | |
186 if (*ttainfo->id3v1.artist && *ttainfo->id3v1.title) | |
187 return g_strdup_printf("%s - %s", ttainfo->id3v1.artist, ttainfo->id3v1.title); | |
188 else if (*ttainfo->id3v1.artist && *ttainfo->id3v1.album) | |
189 return g_strdup_printf("%s - %s", ttainfo->id3v1.artist, ttainfo->id3v1.album); | |
190 else if (*ttainfo->id3v1.artist) return g_strdup(ttainfo->id3v1.artist); | |
191 else if (*ttainfo->id3v1.title) return g_strdup(ttainfo->id3v1.title); | |
192 } | |
193 name = g_strdup (g_basename(filename)); | |
194 p = name + strlen(name); | |
195 while (*p != '.' && p >= name) p--; | |
196 if (*p == '.') *p = '\0'; | |
197 p = g_strdup (name); | |
198 g_free (name); | |
199 return p; | |
200 } | |
201 | |
202 static void * | |
203 play_loop (void *arg) | |
204 { | |
561
914c96de3244
[svn] Convert plugins to use InputPlayback.output instead of InputPlugin.output
iabervon
parents:
528
diff
changeset
|
205 InputPlayback *playback = arg; |
290 | 206 int bufsize = PCM_BUFFER_LENGTH * info.BSIZE * info.NCH; |
207 | |
208 //////////////////////////////////////// | |
209 // decode PCM_BUFFER_LENGTH samples | |
210 // into the current PCM buffer position | |
211 | |
212 while (playing) | |
213 { | |
214 while ((read_samples = get_samples (sample_buffer)) > 0) | |
215 { | |
216 | |
561
914c96de3244
[svn] Convert plugins to use InputPlayback.output instead of InputPlugin.output
iabervon
parents:
528
diff
changeset
|
217 while ((playback->output->buffer_free () < bufsize) |
290 | 218 && seek_position == -1) |
219 { | |
220 if (!playing) | |
221 goto DONE; | |
222 xmms_usleep (10000); | |
223 } | |
224 if (seek_position == -1) | |
225 { | |
561
914c96de3244
[svn] Convert plugins to use InputPlayback.output instead of InputPlugin.output
iabervon
parents:
528
diff
changeset
|
226 produce_audio(playback->output->written_time(), |
290 | 227 ((info.BPS == 8) ? FMT_U8 : FMT_S16_LE), |
228 info.NCH, | |
229 read_samples * info.NCH * info.BSIZE, | |
230 sample_buffer, | |
231 NULL); | |
232 } | |
233 else | |
234 { | |
235 set_position (seek_position); | |
561
914c96de3244
[svn] Convert plugins to use InputPlayback.output instead of InputPlugin.output
iabervon
parents:
528
diff
changeset
|
236 playback->output->flush (seek_position * SEEK_STEP); |
290 | 237 seek_position = -1; |
238 } | |
239 } | |
561
914c96de3244
[svn] Convert plugins to use InputPlayback.output instead of InputPlugin.output
iabervon
parents:
528
diff
changeset
|
240 playback->output->buffer_free (); |
914c96de3244
[svn] Convert plugins to use InputPlayback.output instead of InputPlugin.output
iabervon
parents:
528
diff
changeset
|
241 playback->output->buffer_free (); |
290 | 242 xmms_usleep(10000); |
243 } | |
244 DONE: | |
245 | |
246 //////////////////////// | |
247 // destroy memory pools | |
248 player_stop (); | |
249 | |
250 /////////////////////////////// | |
251 // close currently playing file | |
252 close_tta_file (&info); | |
253 | |
254 pthread_exit (NULL); | |
255 } | |
256 | |
257 static void | |
258 init () | |
259 { | |
260 memset (&info, 0, sizeof (tta_info)); | |
261 } | |
262 | |
263 static void | |
264 cleanup () | |
265 { | |
266 } | |
267 | |
268 static void | |
269 about () | |
270 { | |
271 static GtkWidget *aboutbox; | |
272 if (aboutbox != NULL) return; | |
273 | |
274 aboutbox = xmms_show_message( | |
275 "About True Audio Plugin", | |
276 "TTA input plugin" PLUGIN_VERSION "for BMP\n" | |
277 "Copyright (c) 2004 True Audio Software\n" | |
278 PROJECT_URL, "Ok", FALSE, NULL, NULL); | |
279 | |
280 gtk_signal_connect(GTK_OBJECT(aboutbox), "destroy", | |
281 G_CALLBACK(gtk_widget_destroyed), &aboutbox); | |
282 } | |
283 | |
284 static GtkWidget *window = NULL; | |
285 static GtkWidget *filename_entry, *title_entry, | |
286 *artist_entry, *album_entry, | |
287 *year_entry, *tracknum_entry, | |
288 *comment_entry, *genre_entry, | |
289 *info_frame; | |
290 | |
291 extern char *genre[]; | |
292 | |
293 static void | |
294 file_info (char *filename) | |
295 { | |
296 tta_info ttainfo; | |
297 char *title; | |
298 gchar *utf_filename = NULL; | |
299 | |
300 if (!window) { | |
301 GtkWidget *vbox, *hbox, *left_vbox, *table; | |
302 GtkWidget *label, *filename_hbox, *button_ok; | |
303 | |
304 window = gtk_window_new(GTK_WINDOW_TOPLEVEL); | |
305 gtk_window_set_policy(GTK_WINDOW(window), FALSE, FALSE, FALSE); | |
306 gtk_signal_connect(GTK_OBJECT(window), "destroy", | |
307 G_CALLBACK(gtk_widget_destroyed), &window); | |
308 gtk_container_set_border_width(GTK_CONTAINER(window), 10); | |
309 | |
310 vbox = gtk_vbox_new(FALSE, 10); | |
311 gtk_container_add(GTK_CONTAINER(window), vbox); | |
312 | |
313 filename_hbox = gtk_hbox_new(FALSE, 5); | |
314 gtk_box_pack_start(GTK_BOX(vbox), filename_hbox, FALSE, TRUE, 0); | |
315 label = gtk_label_new("Filename:"); | |
316 gtk_box_pack_start(GTK_BOX(filename_hbox), label, FALSE, TRUE, 0); | |
317 | |
318 filename_entry = gtk_entry_new_with_max_length(1024); | |
319 gtk_editable_set_editable(GTK_EDITABLE(filename_entry), FALSE); | |
320 gtk_box_pack_start(GTK_BOX(filename_hbox), filename_entry, TRUE, TRUE, 0); | |
321 | |
322 hbox = gtk_hbox_new(FALSE, 10); | |
323 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, TRUE, 0); | |
324 left_vbox = gtk_vbox_new(FALSE, 10); | |
325 gtk_box_pack_start(GTK_BOX(hbox), left_vbox, FALSE, FALSE, 0); | |
326 | |
327 info_frame = gtk_frame_new("ID3 Tag:"); | |
328 gtk_box_pack_start(GTK_BOX(left_vbox), info_frame, FALSE, FALSE, 0); | |
329 | |
330 table = gtk_table_new(5, 5, FALSE); | |
331 gtk_container_set_border_width(GTK_CONTAINER(table), 5); | |
332 gtk_container_add(GTK_CONTAINER(info_frame), table); | |
333 | |
334 label = gtk_label_new("Title:"); | |
335 gtk_misc_set_alignment(GTK_MISC(label), 1, 0.5); | |
336 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 0, 1, GTK_FILL, GTK_FILL, 5, 5); | |
337 | |
338 title_entry = gtk_entry_new_with_max_length(1024); | |
339 gtk_editable_set_editable(GTK_EDITABLE(title_entry), FALSE); | |
340 gtk_table_attach(GTK_TABLE(table), title_entry, 1, 4, 0, 1, | |
341 GTK_FILL | GTK_EXPAND | GTK_SHRINK, | |
342 GTK_FILL | GTK_EXPAND | GTK_SHRINK, 0, 5); | |
343 | |
344 label = gtk_label_new("Artist:"); | |
345 gtk_misc_set_alignment(GTK_MISC(label), 1, 0.5); | |
346 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 1, 2, | |
347 GTK_FILL, GTK_FILL, 5, 5); | |
348 | |
349 artist_entry = gtk_entry_new_with_max_length(1024); | |
350 gtk_editable_set_editable(GTK_EDITABLE(artist_entry), FALSE); | |
351 gtk_table_attach(GTK_TABLE(table), artist_entry, 1, 4, 1, 2, | |
352 GTK_FILL | GTK_EXPAND | GTK_SHRINK, | |
353 GTK_FILL | GTK_EXPAND | GTK_SHRINK, 0, 5); | |
354 | |
355 label = gtk_label_new("Album:"); | |
356 gtk_misc_set_alignment(GTK_MISC(label), 1, 0.5); | |
357 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 2, 3, | |
358 GTK_FILL, GTK_FILL, 5, 5); | |
359 | |
360 album_entry = gtk_entry_new_with_max_length(1024); | |
361 gtk_editable_set_editable(GTK_EDITABLE(album_entry), FALSE); | |
362 gtk_table_attach(GTK_TABLE(table), album_entry, 1, 4, 2, 3, | |
363 GTK_FILL | GTK_EXPAND | GTK_SHRINK, | |
364 GTK_FILL | GTK_EXPAND | GTK_SHRINK, 0, 5); | |
365 | |
366 label = gtk_label_new("Comment:"); | |
367 gtk_misc_set_alignment(GTK_MISC(label), 1, 0.5); | |
368 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 3, 4, | |
369 GTK_FILL, GTK_FILL, 5, 5); | |
370 | |
371 comment_entry = gtk_entry_new_with_max_length(1024); | |
372 gtk_editable_set_editable(GTK_EDITABLE(comment_entry), FALSE); | |
373 gtk_table_attach(GTK_TABLE(table), comment_entry, 1, 4, 3, 4, | |
374 GTK_FILL | GTK_EXPAND | GTK_SHRINK, | |
375 GTK_FILL | GTK_EXPAND | GTK_SHRINK, 0, 5); | |
376 | |
377 label = gtk_label_new("Year:"); | |
378 gtk_misc_set_alignment(GTK_MISC(label), 1, 0.5); | |
379 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 4, 5, | |
380 GTK_FILL, GTK_FILL, 5, 5); | |
381 | |
382 year_entry = gtk_entry_new_with_max_length(4); | |
383 gtk_editable_set_editable(GTK_EDITABLE(year_entry), FALSE); | |
384 gtk_widget_set_usize(year_entry, 40, -1); | |
385 gtk_table_attach(GTK_TABLE(table), year_entry, 1, 2, 4, 5, | |
386 GTK_FILL | GTK_EXPAND | GTK_SHRINK, | |
387 GTK_FILL | GTK_EXPAND | GTK_SHRINK, 0, 5); | |
388 | |
389 label = gtk_label_new("Track number:"); | |
390 gtk_misc_set_alignment(GTK_MISC(label), 1, 0.5); | |
391 gtk_table_attach(GTK_TABLE(table), label, 2, 3, 4, 5, | |
392 GTK_FILL, GTK_FILL, 5, 5); | |
393 | |
394 tracknum_entry = gtk_entry_new_with_max_length(3); | |
395 gtk_editable_set_editable(GTK_EDITABLE(tracknum_entry), FALSE); | |
396 gtk_widget_set_usize(tracknum_entry, 40, -1); | |
397 gtk_table_attach(GTK_TABLE(table), tracknum_entry, 3, 4, 4, 5, | |
398 GTK_FILL | GTK_EXPAND | GTK_SHRINK, | |
399 GTK_FILL | GTK_EXPAND | GTK_SHRINK, 0, 5); | |
400 | |
401 label = gtk_label_new("Genre:"); | |
402 gtk_misc_set_alignment(GTK_MISC(label), 1, 0.5); | |
403 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 5, 6, | |
404 GTK_FILL, GTK_FILL, 5, 5); | |
405 | |
406 genre_entry = gtk_entry_new_with_max_length(1024); | |
407 gtk_editable_set_editable(GTK_EDITABLE(genre_entry), FALSE); | |
408 gtk_widget_set_usize(genre_entry, 40, -1); | |
409 gtk_table_attach(GTK_TABLE(table), genre_entry, 1, 4, 5, 6, | |
410 GTK_FILL | GTK_EXPAND | GTK_SHRINK, | |
411 GTK_FILL | GTK_EXPAND | GTK_SHRINK, 0, 5); | |
412 | |
413 button_ok = gtk_button_new_with_label("Ok"); | |
414 gtk_signal_connect_object(GTK_OBJECT(button_ok), "clicked", | |
415 G_CALLBACK(gtk_widget_destroy), G_OBJECT(window)); | |
416 GTK_WIDGET_SET_FLAGS(button_ok, GTK_CAN_DEFAULT); | |
417 gtk_box_pack_start(GTK_BOX(vbox), button_ok, TRUE, TRUE, 0); | |
418 | |
419 gtk_widget_show_all (window); | |
420 } | |
421 | |
422 utf_filename = str_to_utf8(filename); | |
423 title = g_strdup_printf(_("File Info - %s"), g_basename(utf_filename)); | |
424 gtk_window_set_title(GTK_WINDOW(window), title); | |
425 g_free(title); | |
426 | |
427 gtk_entry_set_text(GTK_ENTRY(filename_entry), utf_filename); | |
428 gtk_editable_set_position(GTK_EDITABLE(filename_entry), -1); | |
429 | |
430 #if 1 | |
431 title = g_strdup(g_basename(utf_filename)); | |
432 // if ((tmp = strrchr(title, '.')) != NULL) *tmp = '\0'; | |
433 gtk_entry_set_text(GTK_ENTRY(title_entry), title); | |
434 g_free(title); | |
435 #endif | |
436 g_free(utf_filename); | |
437 | |
438 if (open_tta_file (filename, &ttainfo, 0) >= 0) | |
439 { | |
440 gtk_entry_set_text(GTK_ENTRY(title_entry), ""); | |
441 gtk_entry_set_text(GTK_ENTRY(artist_entry), ""); | |
442 gtk_entry_set_text(GTK_ENTRY(album_entry), ""); | |
443 gtk_entry_set_text(GTK_ENTRY(year_entry), ""); | |
444 gtk_entry_set_text(GTK_ENTRY(tracknum_entry), ""); | |
445 gtk_entry_set_text(GTK_ENTRY(comment_entry), ""); | |
446 gtk_entry_set_text(GTK_ENTRY(genre_entry), ""); | |
447 | |
448 if (ttainfo.id3v2.id3has) | |
449 { | |
450 gtk_entry_set_text(GTK_ENTRY(title_entry), ttainfo.id3v2.title); | |
451 gtk_entry_set_text(GTK_ENTRY(artist_entry), ttainfo.id3v2.artist); | |
452 gtk_entry_set_text(GTK_ENTRY(album_entry), ttainfo.id3v2.album); | |
453 gtk_entry_set_text(GTK_ENTRY(year_entry), ttainfo.id3v2.year); | |
454 gtk_entry_set_text(GTK_ENTRY(tracknum_entry), ttainfo.id3v2.track); | |
455 gtk_entry_set_text(GTK_ENTRY(comment_entry), ttainfo.id3v2.comment); | |
456 gtk_entry_set_text(GTK_ENTRY(genre_entry), ttainfo.id3v2.genre); | |
457 } | |
458 else if (ttainfo.id3v1.id3has) | |
459 { | |
460 gchar *track = g_strdup_printf ("%2d", ttainfo.id3v1.track); | |
461 gtk_entry_set_text(GTK_ENTRY(title_entry), ttainfo.id3v1.title); | |
462 gtk_entry_set_text(GTK_ENTRY(artist_entry), ttainfo.id3v1.artist); | |
463 gtk_entry_set_text(GTK_ENTRY(album_entry), ttainfo.id3v1.album); | |
464 gtk_entry_set_text(GTK_ENTRY(year_entry), ttainfo.id3v1.year); | |
465 gtk_entry_set_text(GTK_ENTRY(tracknum_entry), track); | |
466 gtk_entry_set_text(GTK_ENTRY(comment_entry), ttainfo.id3v1.comment); | |
467 gtk_entry_set_text(GTK_ENTRY(genre_entry), | |
468 genre[ttainfo.id3v1.genre <= GENRES ? ttainfo.id3v1.genre : 12]); | |
469 g_free (track); | |
470 } | |
471 } | |
472 close_tta_file (&ttainfo); | |
473 | |
474 gtk_widget_set_sensitive(info_frame, TRUE); | |
475 } | |
476 | |
477 static int | |
478 is_our_file (char *filename) | |
479 { | |
480 if (!strcasecmp (filename + strlen (filename) - 4, ".tta")) | |
481 { | |
482 return TRUE; | |
483 } | |
484 return FALSE; | |
485 } | |
486 | |
487 static void | |
561
914c96de3244
[svn] Convert plugins to use InputPlayback.output instead of InputPlugin.output
iabervon
parents:
528
diff
changeset
|
488 play_file (InputPlayback *playback) |
290 | 489 { |
561
914c96de3244
[svn] Convert plugins to use InputPlayback.output instead of InputPlugin.output
iabervon
parents:
528
diff
changeset
|
490 char *filename = playback->filename; |
290 | 491 char *title; |
492 long datasize, origsize, bitrate; | |
493 | |
494 playing = FALSE; | |
495 | |
496 //////////////////////////////////////// | |
497 // open TTA file | |
498 if (open_tta_file (filename, &info, 0) < 0) | |
499 { | |
500 tta_error (info.STATE); | |
501 close_tta_file (&info); | |
502 return; | |
503 } | |
504 | |
505 //////////////////////////////////////// | |
506 // initialize TTA player | |
507 if (player_init (&info) < 0) | |
508 { | |
509 tta_error (info.STATE); | |
510 close_tta_file (&info); | |
511 return; | |
512 } | |
513 | |
514 | |
561
914c96de3244
[svn] Convert plugins to use InputPlayback.output instead of InputPlugin.output
iabervon
parents:
528
diff
changeset
|
515 if (playback->output->open_audio ((info.BPS == 8) ? FMT_U8 : FMT_S16_LE, |
290 | 516 info.SAMPLERATE, info.NCH) == 0) |
517 { | |
518 tta_error (OUTPUT_ERROR); | |
519 close_tta_file (&info); | |
520 return; | |
521 } | |
522 title = get_title (filename, &info); | |
523 printf("title @1 = %s\n", title); | |
524 { | |
525 TitleInput *tuple; | |
526 | |
527 tuple = get_song_tuple(filename); | |
528 if(tuple->track_name) { | |
529 g_free(title); | |
530 title = g_strdup(tuple->track_name); | |
531 printf("title @2 = %s\n", title); | |
532 } | |
533 | |
534 bmp_title_input_free(tuple); | |
535 } | |
536 | |
537 datasize = file_size(filename) - info.DATAPOS; | |
538 origsize = info.DATALENGTH * info.BSIZE * info.NCH; | |
539 | |
540 bitrate = (long) ((float) datasize / origsize * | |
541 (info.SAMPLERATE * info.NCH * info.BPS)); | |
542 | |
543 tta_ip.set_info (title, 1000 * info.LENGTH, bitrate, info.SAMPLERATE, info.NCH); | |
544 | |
545 if (title) | |
546 g_free (title); | |
547 | |
548 playing = TRUE; | |
549 seek_position = -1; | |
550 read_samples = -1; | |
551 | |
561
914c96de3244
[svn] Convert plugins to use InputPlayback.output instead of InputPlugin.output
iabervon
parents:
528
diff
changeset
|
552 pthread_create (&decode_thread, NULL, play_loop, playback); |
290 | 553 } |
554 | |
555 static void | |
561
914c96de3244
[svn] Convert plugins to use InputPlayback.output instead of InputPlugin.output
iabervon
parents:
528
diff
changeset
|
556 tta_pause (InputPlayback *playback, short paused) |
290 | 557 { |
561
914c96de3244
[svn] Convert plugins to use InputPlayback.output instead of InputPlugin.output
iabervon
parents:
528
diff
changeset
|
558 playback->output->pause (paused); |
290 | 559 } |
560 static void | |
561
914c96de3244
[svn] Convert plugins to use InputPlayback.output instead of InputPlugin.output
iabervon
parents:
528
diff
changeset
|
561 stop (InputPlayback *playback) |
290 | 562 { |
563 if (playing) | |
564 { | |
565 playing = FALSE; | |
566 pthread_join (decode_thread, NULL); | |
561
914c96de3244
[svn] Convert plugins to use InputPlayback.output instead of InputPlugin.output
iabervon
parents:
528
diff
changeset
|
567 playback->output->close_audio (); |
290 | 568 close_tta_file (&info); |
569 read_samples = 0; | |
570 } | |
571 } | |
572 | |
573 static void | |
568 | 574 seek (InputPlayback *data, int time) |
290 | 575 { |
576 if (playing) | |
577 { | |
578 seek_position = 1000 * time / SEEK_STEP; | |
579 | |
580 while (seek_position != -1) | |
581 xmms_usleep (10000); | |
582 } | |
583 } | |
584 | |
585 static int | |
561
914c96de3244
[svn] Convert plugins to use InputPlayback.output instead of InputPlugin.output
iabervon
parents:
528
diff
changeset
|
586 get_time (InputPlayback *playback) |
290 | 587 { |
561
914c96de3244
[svn] Convert plugins to use InputPlayback.output instead of InputPlugin.output
iabervon
parents:
528
diff
changeset
|
588 if (playing && (read_samples || playback->output->buffer_playing())) |
914c96de3244
[svn] Convert plugins to use InputPlayback.output instead of InputPlugin.output
iabervon
parents:
528
diff
changeset
|
589 return playback->output->output_time(); |
290 | 590 |
591 return -1; | |
592 } | |
593 | |
594 static void | |
595 get_song_info (char *filename, char **title, int *length) | |
596 { | |
597 tta_info ttainfo; | |
598 | |
599 if (open_tta_file (filename, &ttainfo, 0) >= 0) | |
600 { | |
601 *title = get_title (filename, &ttainfo); | |
602 *length = ttainfo.LENGTH * 1000; | |
603 } | |
604 close_tta_file (&ttainfo); | |
605 } | |
606 | |
607 | |
608 | |
609 static TitleInput * | |
610 get_song_tuple(char *filename) | |
611 { | |
612 TitleInput *tuple = NULL; | |
613 tta_info *ttainfo; | |
614 VFSFile *file; | |
615 | |
616 ttainfo = g_malloc0(sizeof(tta_info)); | |
617 | |
618 if((file = vfs_fopen(filename, "rb")) != NULL) { | |
619 | |
620 #ifdef DEBUG | |
621 printf("about to open_tta_file\n"); | |
622 #endif | |
623 if(open_tta_file(filename, ttainfo, 0) >= 0) { | |
624 tuple = bmp_title_input_new(); | |
625 #ifdef DEBUG | |
626 printf("open_tta_file succeed\n"); | |
627 #endif | |
628 tuple->file_name = g_path_get_basename(filename); | |
629 tuple->file_path = g_path_get_dirname(filename); | |
630 tuple->file_ext = extname(filename); | |
631 tuple->length = ttainfo->LENGTH * 1000; | |
632 | |
633 if (ttainfo->id3v2.id3has) { | |
634 if(ttainfo->id3v2.artist) | |
635 tuple->performer = g_strdup(ttainfo->id3v2.artist); | |
636 | |
637 if(ttainfo->id3v2.album) | |
638 tuple->album_name = g_strdup(ttainfo->id3v2.album); | |
639 | |
640 if(ttainfo->id3v2.title) | |
641 tuple->track_name = g_strdup(ttainfo->id3v2.title); | |
642 | |
643 tuple->year = atoi(ttainfo->id3v2.year); | |
644 | |
645 tuple->track_number = atoi(ttainfo->id3v2.track); | |
646 | |
647 if(ttainfo->id3v2.genre){ | |
648 // printf("genre = %s\n",ttainfo->id3v2.genre); | |
649 tuple->genre = g_strdup(ttainfo->id3v2.genre); | |
650 } | |
651 if(ttainfo->id3v2.comment) | |
652 tuple->comment = g_strdup(ttainfo->id3v2.comment); | |
653 } else if (ttainfo->id3v1.id3has) { | |
654 if(ttainfo->id3v1.artist) | |
655 tuple->performer = g_strdup(ttainfo->id3v1.artist); | |
656 | |
657 if(ttainfo->id3v1.album) | |
658 tuple->album_name = g_strdup(ttainfo->id3v1.album); | |
659 | |
660 if(ttainfo->id3v1.title) | |
661 tuple->track_name = g_strdup(ttainfo->id3v1.title); | |
662 | |
663 tuple->year = atoi(ttainfo->id3v1.year); | |
664 | |
665 tuple->track_number = (int)ttainfo->id3v1.track; | |
666 | |
667 if(ttainfo->id3v1.genre) | |
668 tuple->genre = g_strdup(genre[ttainfo->id3v1.genre <= GENRES ? ttainfo->id3v1.genre : 12]); | |
669 if(ttainfo->id3v1.comment) | |
670 tuple->comment = g_strdup(ttainfo->id3v1.comment); | |
671 } | |
672 | |
673 close_tta_file (ttainfo); | |
674 } | |
675 | |
676 vfs_fclose(file); | |
677 } | |
678 return tuple; | |
679 } | |
680 | |
681 static gchar * | |
682 extname(const char *filename) | |
683 { | |
684 gchar *ext = strrchr(filename, '.'); | |
685 | |
686 if (ext != NULL) | |
687 ++ext; | |
688 | |
689 return ext; | |
690 } | |
691 | |
692 /* return length in letters */ | |
693 size_t tta_ucs4len(id3_ucs4_t *ucs) | |
694 { | |
695 id3_ucs4_t *ptr = ucs; | |
696 size_t len = 0; | |
697 | |
698 while(*ptr++ != 0) | |
699 len++; | |
700 | |
701 return len; | |
702 } | |
703 | |
704 /* duplicate id3_ucs4_t string. new string will be terminated with 0. */ | |
705 id3_ucs4_t *tta_ucs4dup(id3_ucs4_t *org) | |
706 { | |
707 id3_ucs4_t *new = NULL; | |
708 size_t len = tta_ucs4len(org); | |
709 | |
710 new = g_malloc0((len + 1) * sizeof(id3_ucs4_t)); | |
711 memcpy(new, org, len * sizeof(id3_ucs4_t)); | |
712 *(new + len) = 0; //terminate | |
713 | |
714 return new; | |
715 } | |
716 | |
717 #define BYTES(x) ((x) * sizeof(id3_ucs4_t)) | |
718 | |
719 id3_ucs4_t *tta_parse_genre(const id3_ucs4_t *string) | |
720 { | |
721 id3_ucs4_t *ret = NULL; | |
722 id3_ucs4_t *tmp = NULL; | |
723 id3_ucs4_t *genre = NULL; | |
724 id3_ucs4_t *ptr, *end, *tail, *tp; | |
725 size_t ret_len = 0; //num of ucs4 char! | |
726 size_t tmp_len = 0; | |
727 gboolean is_num = TRUE; | |
728 | |
729 tail = (id3_ucs4_t *)string + tta_ucs4len((id3_ucs4_t *)string); | |
730 | |
731 ret = g_malloc0(1024); | |
732 | |
733 for(ptr = (id3_ucs4_t *)string; *ptr != 0 && ptr <= tail; ptr++) { | |
734 if(*ptr == '(') { | |
735 if(*(++ptr) == '(') { // escaped text like: ((something) | |
736 for(end = ptr; *end != ')' && *end != 0;) { // copy "(something)" | |
737 end++; | |
738 } | |
739 end++; //include trailing ')' | |
740 memcpy(ret, ptr, BYTES(end - ptr)); | |
741 ret_len += (end - ptr); | |
742 *(ret + ret_len) = 0; //terminate | |
743 ptr = end + 1; | |
744 } | |
745 else { | |
746 // reference to an id3v1 genre code | |
747 for(end = ptr; *end != ')' && *end != 0;) { | |
748 end++; | |
749 } | |
750 | |
751 tmp = g_malloc0(BYTES(end - ptr + 1)); | |
752 memcpy(tmp, ptr, BYTES(end - ptr)); | |
753 *(tmp + (end - ptr)) = 0; //terminate | |
754 ptr += end - ptr; | |
755 | |
756 genre = (id3_ucs4_t *)id3_genre_name((const id3_ucs4_t *)tmp); | |
757 | |
758 g_free(tmp); | |
759 tmp = NULL; | |
760 | |
761 tmp_len = tta_ucs4len(genre); | |
762 | |
763 memcpy(ret + BYTES(ret_len), genre, BYTES(tmp_len)); | |
764 | |
765 ret_len += tmp_len; | |
766 *(ret + ret_len) = 0; //terminate | |
767 } | |
768 } | |
769 else { | |
770 for(end = ptr; *end != '(' && *end != 0; ) { | |
771 end++; | |
772 } | |
773 // scan string to determine whether a genre code number or not | |
774 tp = ptr; | |
775 is_num = TRUE; | |
776 while(tp < end) { | |
777 if(*tp < '0' || *tp > '9') { // anything else than number appears. | |
778 is_num = FALSE; | |
779 break; | |
780 } | |
781 tp++; | |
782 } | |
783 if(is_num) { | |
784 #ifdef DEBUG | |
785 printf("is_num!\n"); | |
786 #endif | |
787 tmp = g_malloc0(BYTES(end - ptr + 1)); | |
788 memcpy(tmp, ptr, BYTES(end - ptr)); | |
789 *(tmp + (end - ptr)) = 0; //terminate | |
790 ptr += end - ptr; | |
791 | |
792 genre = (id3_ucs4_t *)id3_genre_name((const id3_ucs4_t *)tmp); | |
793 #ifdef DEBUG | |
794 printf("genre length = %d\n", tta_ucs4len(genre)); | |
795 #endif | |
796 g_free(tmp); | |
797 tmp = NULL; | |
798 | |
799 tmp_len = tta_ucs4len(genre); | |
800 | |
801 memcpy(ret + BYTES(ret_len), genre, BYTES(tmp_len)); | |
802 | |
803 ret_len += tmp_len; | |
804 *(ret + ret_len) = 0; //terminate | |
805 } | |
806 else { // plain text | |
807 #ifdef DEBUG | |
808 printf("plain!\n"); | |
809 printf("ret_len = %d\n", ret_len); | |
810 #endif | |
811 memcpy(ret + BYTES(ret_len), ptr, BYTES(end - ptr)); | |
812 ret_len = ret_len + (end - ptr); | |
813 *(ret + ret_len) = 0; //terminate | |
814 ptr += (end - ptr); | |
815 } | |
816 } | |
817 } | |
818 return ret; | |
819 } | |
820 | |
821 gchar *tta_input_id3_get_string(struct id3_tag * tag, char *frame_name) | |
822 { | |
823 gchar *rtn; | |
824 gchar *rtn2; | |
825 const id3_ucs4_t *string_const; | |
826 id3_ucs4_t *string; | |
827 id3_ucs4_t *ucsptr; | |
828 struct id3_frame *frame; | |
829 union id3_field *field; | |
830 gboolean flagutf = FALSE; | |
831 | |
832 frame = id3_tag_findframe(tag, frame_name, 0); | |
833 if (!frame) | |
834 return NULL; | |
835 | |
836 if (frame_name == ID3_FRAME_COMMENT) | |
837 field = id3_frame_field(frame, 3); | |
838 else | |
839 field = id3_frame_field(frame, 1); | |
840 | |
841 if (!field) | |
842 return NULL; | |
843 | |
844 if (frame_name == ID3_FRAME_COMMENT) | |
845 string_const = id3_field_getfullstring(field); | |
846 else | |
847 string_const = id3_field_getstrings(field, 0); | |
848 | |
849 if (!string_const) | |
850 return NULL; | |
851 | |
852 string = tta_ucs4dup((id3_ucs4_t *)string_const); | |
853 | |
854 if (frame_name == ID3_FRAME_GENRE) { | |
855 id3_ucs4_t *string2 = NULL; | |
856 string2 = tta_parse_genre(string); | |
857 g_free((void *)string); | |
858 string = string2; | |
859 } | |
860 | |
861 ucsptr = (id3_ucs4_t *)string; | |
862 while (*ucsptr) { | |
863 if (*ucsptr > 0x000000ffL) { | |
864 flagutf = TRUE; | |
865 break; | |
866 } | |
867 ucsptr++; | |
868 } | |
869 | |
870 if (flagutf) { | |
871 #ifdef DEBUG | |
872 g_message("aud-tta: flagutf!\n"); | |
873 #endif | |
874 rtn = id3_ucs4_utf8duplicate(string); | |
875 } | |
876 else { | |
877 rtn = id3_ucs4_latin1duplicate(string); | |
878 rtn2 = str_to_utf8(rtn); | |
879 free(rtn); | |
880 rtn = rtn2; | |
881 } | |
882 g_free(string); | |
883 string = NULL; | |
884 #ifdef DEBUG | |
885 g_print("string = %s\n", rtn); | |
886 #endif | |
887 return rtn; | |
888 } | |
889 | |
890 int get_id3_tags (const char *filename, tta_info *ttainfo) { | |
891 int id3v2_size; | |
892 gchar *str = NULL; | |
893 | |
894 struct id3_file *id3file = NULL; | |
895 struct id3_tag *tag = NULL; | |
896 | |
897 ttainfo->id3v2.id3has = 0; | |
898 ttainfo->id3v1.id3has = 0; | |
899 | |
900 id3file = id3_file_open (filename, ID3_FILE_MODE_READONLY); | |
901 | |
902 if (id3file) { | |
903 tag = id3_file_tag (id3file); | |
904 | |
905 if (tag) { | |
906 str = tta_input_id3_get_string (tag, ID3_FRAME_ARTIST); | |
907 if(str) { | |
441 | 908 strncpy(ttainfo->id3v2.artist, str, MAX_LINE); |
290 | 909 strncpy(ttainfo->id3v1.artist, str, 30); |
910 } | |
911 free(str); | |
912 str = NULL; | |
913 | |
914 str = tta_input_id3_get_string (tag, ID3_FRAME_ALBUM); | |
915 if(str){ | |
442 | 916 strncpy(ttainfo->id3v2.album, str, MAX_LINE); |
290 | 917 strncpy(ttainfo->id3v1.album, str, 30); |
918 } | |
919 free(str); | |
920 str = NULL; | |
921 | |
922 str = tta_input_id3_get_string (tag, ID3_FRAME_TITLE); | |
923 if(str) { | |
442 | 924 strncpy(ttainfo->id3v2.title, str, MAX_LINE); |
290 | 925 strncpy(ttainfo->id3v1.title, str, 30); |
926 } | |
927 free(str); | |
928 str = NULL; | |
929 | |
930 // year | |
931 str = tta_input_id3_get_string (tag, ID3_FRAME_YEAR); //TDRC | |
932 if(!str) { | |
933 str = tta_input_id3_get_string (tag, "TYER"); | |
934 } | |
935 | |
936 if(str){ | |
937 strncpy(ttainfo->id3v2.year, str, 5); | |
938 strncpy(ttainfo->id3v1.year, str, 5); | |
939 } | |
940 free(str); | |
941 str = NULL; | |
942 | |
943 // track number | |
944 str = tta_input_id3_get_string (tag, ID3_FRAME_TRACK); | |
945 if(str) | |
442 | 946 strncpy(ttainfo->id3v2.track, str, MAX_TRACK); |
290 | 947 free(str); |
948 str = NULL; | |
949 | |
950 // genre | |
951 str = tta_input_id3_get_string (tag, ID3_FRAME_GENRE); | |
952 if(str) { | |
953 id3_ucs4_t *tmp = NULL; | |
442 | 954 strncpy(ttainfo->id3v2.genre, str, MAX_GENRE); |
290 | 955 tmp = id3_latin1_ucs4duplicate((id3_latin1_t *)str); |
956 ttainfo->id3v1.genre = id3_genre_number(tmp); | |
957 g_free(tmp); | |
958 } | |
959 free(str); | |
960 str = NULL; | |
961 | |
962 // comment | |
963 str = tta_input_id3_get_string (tag, ID3_FRAME_COMMENT); | |
443
9e76e87c857e
[svn] One more. Seems like one meant id3v1, not id3v2 for the 30 char limit.
js
parents:
442
diff
changeset
|
964 if(str) { |
9e76e87c857e
[svn] One more. Seems like one meant id3v1, not id3v2 for the 30 char limit.
js
parents:
442
diff
changeset
|
965 strncpy(ttainfo->id3v2.comment, str, MAX_LINE); |
9e76e87c857e
[svn] One more. Seems like one meant id3v1, not id3v2 for the 30 char limit.
js
parents:
442
diff
changeset
|
966 strncpy(ttainfo->id3v1.comment, str, 30); |
9e76e87c857e
[svn] One more. Seems like one meant id3v1, not id3v2 for the 30 char limit.
js
parents:
442
diff
changeset
|
967 } |
290 | 968 free(str); |
969 str = NULL; | |
970 | |
971 if(*(ttainfo->id3v2.title) && *(ttainfo->id3v2.artist)) { | |
972 ttainfo->id3v2.id3has = 1; | |
973 ttainfo->id3v2.id3has = 1; | |
974 } | |
975 } | |
976 id3_file_close(id3file); | |
977 } | |
978 return id3v2_size; // not used | |
979 } |