changeset 2749:290357060cdb

More work on tuples.
author William Pitcock <nenolod@atheme.org>
date Mon, 30 Jun 2008 23:17:59 -0500
parents fe0d1cff2cd0
children 6319a15e7243
files src/psf2/plugin.c
diffstat 1 files changed, 59 insertions(+), 34 deletions(-) [+]
line wrap: on
line diff
--- a/src/psf2/plugin.c	Mon Jun 30 23:11:47 2008 -0500
+++ b/src/psf2/plugin.c	Mon Jun 30 23:17:59 2008 -0500
@@ -69,11 +69,66 @@
 	return AO_SUCCESS;
 }
 
+Tuple *psf2_tuple(gchar *filename)
+{
+	Tuple *t;
+	corlett_t *c;
+	guchar *buf;
+	gsize sz;
+
+	aud_vfs_file_get_contents(filename, (gchar **) &buf, &sz);
+
+	if (!buf)
+		return NULL;
+
+	if (corlett_decode(buf, sz, NULL, NULL, &c) != AO_SUCCESS)
+		return NULL;	
+
+	t = aud_tuple_new_from_filename(filename);
+
+	aud_tuple_associate_int(t, FIELD_LENGTH, NULL, psfTimeToMS(c->inf_length));
+	aud_tuple_associate_string(t, FIELD_ARTIST, NULL, c->inf_artist);
+	aud_tuple_associate_string(t, FIELD_ALBUM, NULL, c->inf_game);
+	aud_tuple_associate_string(t, -1, "game", c->inf_game);
+	aud_tuple_associate_string(t, FIELD_TITLE, NULL, c->inf_title);
+	aud_tuple_associate_string(t, FIELD_COPYRIGHT, NULL, c->inf_copy);
+	aud_tuple_associate_string(t, FIELD_QUALITY, NULL, "sequenced");
+	aud_tuple_associate_string(t, FIELD_CODEC, NULL, "PlayStation2 Audio");
+	aud_tuple_associate_string(t, -1, "console", "PlayStation 2");
+
+	free(c);
+	g_free(buf);
+
+	return t;
+}
+
+gchar *psf2_title(gchar *filename, gint *length)
+{
+	gchar *title = NULL;
+	Tuple *tuple = psf2_tuple(filename);
+
+	if (tuple != NULL)
+	{
+		title = aud_tuple_formatter_make_title_string(tuple, aud_get_gentitle_format());
+		*length = aud_tuple_get_int(tuple, FIELD_LENGTH, NULL);
+		aud_tuple_free(tuple);
+	}
+	else
+	{
+		title = g_path_get_basename(filename);
+		*length = -1;
+	}
+
+	return title;
+}
+
 void psf2_play(InputPlayback *data)
 {
 	guchar *buffer;
 	gsize size;
 	uint32 filesig;
+	gint length;
+	gchar *title = psf2_title(data->filename, &length);
 
 	path = g_strdup(data->filename);
 	aud_vfs_file_get_contents(data->filename, (gchar **) &buffer, &size);
@@ -110,6 +165,8 @@
 	
 	data->output->open_audio(FMT_S16_NE, 44100, 2);
 
+        data->set_params(data, title, length, 44100*2*2*8, 44100, 2);
+
 	data->playing = TRUE;
 	data->set_pb_ready(data);
 	while (data->playing)
@@ -119,6 +176,7 @@
 
 	g_free(buffer);
 	g_free(path);
+        g_free(title);
 }
 
 void psf2_update(unsigned char *buffer, long count, InputPlayback *playback)
@@ -170,7 +228,7 @@
 	playback->output->pause(p);
 }
 
-static int psf2_is_our_fd(gchar *filename, VFSFile *file)
+int psf2_is_our_fd(gchar *filename, VFSFile *file)
 {
 	gchar magic[4];
 	aud_vfs_fread(magic, 1, 4, file);
@@ -181,39 +239,6 @@
 	return 0;
 }
 
-static Tuple *psf2_tuple(gchar *filename)
-{
-	Tuple *t;
-	corlett_t *c;
-	guchar *buf;
-	gsize sz;
-
-	aud_vfs_file_get_contents(filename, (gchar **) &buf, &sz);
-
-	if (!buf)
-		return NULL;
-
-	if (corlett_decode(buf, sz, NULL, NULL, &c) != AO_SUCCESS)
-		return NULL;	
-
-	t = aud_tuple_new_from_filename(filename);
-
-	aud_tuple_associate_int(t, FIELD_LENGTH, NULL, psfTimeToMS(c->inf_length));
-	aud_tuple_associate_string(t, FIELD_ARTIST, NULL, c->inf_artist);
-	aud_tuple_associate_string(t, FIELD_ALBUM, NULL, c->inf_game);
-	aud_tuple_associate_string(t, -1, "game", c->inf_game);
-	aud_tuple_associate_string(t, FIELD_TITLE, NULL, c->inf_title);
-	aud_tuple_associate_string(t, FIELD_COPYRIGHT, NULL, c->inf_copy);
-	aud_tuple_associate_string(t, FIELD_QUALITY, NULL, "sequenced");
-	aud_tuple_associate_string(t, FIELD_CODEC, NULL, "PlayStation2 Audio");
-	aud_tuple_associate_string(t, -1, "console", "PlayStation 2");
-
-	free(c);
-	g_free(buf);
-
-	return t;
-}
-
 gchar *psf2_fmts[] = { "psf2", "minipsf2", NULL };
 
 InputPlugin psf2_ip =