diff src/xmms-sid.c @ 103:fe83646e6baa

Changed plrFillBuffer()-functions to return actual number of samples computed. Rudimentary changes for return of fileinfo window. Minor tweaks for STILdb.
author Matti Hamalainen <ccr@tnsp.org>
date Sun, 11 Jan 2004 17:42:00 +0000
parents 2bc56809ec0b
children 98a72c44f56b
line wrap: on
line diff
--- a/src/xmms-sid.c	Sun Jan 11 16:48:05 2004 +0000
+++ b/src/xmms-sid.c	Sun Jan 11 17:42:00 2004 +0000
@@ -32,9 +32,11 @@
 #include "xs_support.h"
 #include "xs_config.h"
 #include "xs_length.h"
+#include "xs_stil.h"
 #include "xs_interface.h"
 #include "xs_glade.h"
 
+
 /*
  * Include player engines
  */
@@ -58,7 +60,7 @@
 	gboolean	(*plrInit)(t_xs_status *);
 	void		(*plrClose)(t_xs_status *);
 	gboolean	(*plrInitSong)(t_xs_status *);
-	gboolean	(*plrFillBuffer)(t_xs_status *, gchar *, gint);
+	guint		(*plrFillBuffer)(t_xs_status *, gchar *, guint);
 	gboolean	(*plrLoadSID)(t_xs_status *, gchar *);
 	void		(*plrDeleteSID)(t_xs_status *);
 	t_xs_tune*	(*plrGetSIDInfo)(gchar *);
@@ -104,7 +106,7 @@
 /*
  * Global variables
  */
-static GtkWidget		*xs_ctrlwin	= NULL;
+static GtkWidget		*xs_fileinfowin = NULL;
 static pthread_t		xs_decode_thread;
 static pthread_mutex_t		xs_mutex	= PTHREAD_MUTEX_INITIALIZER;
 struct t_xs_cfg			xs_cfg;
@@ -194,7 +196,6 @@
  xs_player->plrDeleteSID(&xs_status);
  xs_player->plrClose(&xs_status);
 
- /* Free allocated memory */
  xs_songlen_close();
  xs_stil_close();
 
@@ -251,6 +252,7 @@
  t_xs_status myStatus;
  t_xs_tune *myTune;
  gboolean audioOpen, doPlay;
+ guint audioGot;
  gint audioFreq, audioChannels, songLength, audioFmt;
  gchar audioBuffer[XS_BUFSIZE];
 
@@ -279,11 +281,11 @@
  {
  pthread_mutex_lock(&xs_mutex);
  myStatus.currSong = xs_status.currSong;
- songLength = myTune->subTunes[myStatus.currSong - 1].tuneLength;
  pthread_mutex_unlock(&xs_mutex);
 
  XSDEBUG("subtune #%i selected, initializing...\n", myStatus.currSong);
 
+ songLength = myTune->subTunes[myStatus.currSong - 1].tuneLength;
 
  /* Initialize song */
  if (!xs_player->plrInitSong(&myStatus))
@@ -321,22 +323,22 @@
  while (xs_status.isPlaying && myStatus.isPlaying && (xs_status.currSong == myStatus.currSong))
 	{
 	/* Render audio data */
-	xs_player->plrFillBuffer(&myStatus, audioBuffer, XS_BUFSIZE);
+	audioGot = xs_player->plrFillBuffer(&myStatus, audioBuffer, XS_BUFSIZE);
 
 	/* I <3 visualice/haujobb */
 	xs_plugin_ip.add_vis_pcm(
 		xs_plugin_ip.output->written_time(),
-		audioFmt, audioChannels, XS_BUFSIZE, audioBuffer);
+		audioFmt, audioChannels, audioGot, audioBuffer);
 
 	/* Wait a little */
 	while (xs_status.isPlaying &&
 		(xs_status.currSong == myStatus.currSong) &&
-		(xs_plugin_ip.output->buffer_free() < XS_BUFSIZE))
+		(xs_plugin_ip.output->buffer_free() < audioGot))
 		xmms_usleep(10000);
 
 	/* Output audio */
 	if (xs_status.isPlaying && (xs_status.currSong == myStatus.currSong))
-		xs_plugin_ip.output->write_audio(audioBuffer, XS_BUFSIZE);
+		xs_plugin_ip.output->write_audio(audioBuffer, audioGot);
 
 	/* Check if we have played enough */
 	if (xs_cfg.playMaxTimeEnable)
@@ -470,25 +472,37 @@
  */
 void xs_seek(gint iTime)
 {
- if (!xs_status.pTune) return;
-
- if (xs_cfg.subsongControl == XS_SSC_POPUP)
-	{
-	/* User wants to use the pop-up */
-	}
+ gint n;
+ if (!xs_status.pTune || !xs_status.isPlaying) return;
+ 
+ switch (xs_cfg.subsongControl) {
+ case XS_SSC_POPUP:
+	pthread_mutex_lock(&xs_mutex);
+	
+	n = xs_status.pTune->subTunes[xs_status.currSong].tuneLength;
+	if ((iTime > 0) && (iTime <= n))
+		{
+		xs_status.currSong = 1 + ((iTime * xs_status.pTune->nsubTunes) / n);
+		}
+	
+	pthread_mutex_unlock(&xs_mutex);
+	break;
 
  /* If we have song-position patch, check settings */
 #ifdef HAVE_SONG_POSITION
- if (xs_cfg.subsongControl == XS_SSC_PATCH)
- 	{
+ case XS_SSC_PATCH:
 	pthread_mutex_lock(&xs_mutex);
 
-	if ((iTime > 0) && (iTime <= xs_status.pTune->nsubTunes) && xs_status.isPlaying)
+	if ((iTime > 0) && (iTime <= xs_status.pTune->nsubTunes))
 		xs_status.currSong = iTime;
 	
 	pthread_mutex_unlock(&xs_mutex);
-	}
+	break;
 #endif
+
+ default:
+ 	break;
+ }
 }
 
 
@@ -601,3 +615,114 @@
 }
 
 
+/*
+ * File-information window
+ */
+#define LUW(x...)	lookup_widget(xs_fileinfowin, ## x)
+
+
+void xs_fileinfo_ok(void)
+{
+ gtk_widget_destroy(xs_fileinfowin);
+ xs_fileinfowin = NULL;
+}
+
+
+void xs_fileinfo_subtune(GtkWidget *widget, void *data)
+{
+#if 0
+ T_sid_stil_subtune *a_tune;
+ GtkWidget *a_item;
+ gint a_index;
+
+ 
+ /* Get number of subtune */
+ a_item  = gtk_menu_get_active(GTK_MENU(fileinfo_sub_tune_menu));
+ a_index = g_list_index(GTK_MENU_SHELL(fileinfo_sub_tune_menu)->children, a_item);
+
+ a_tune = &xs_stil_info.subtune[a_index];
+
+
+ /* Get and set subtune information */
+ if (a_tune->artist != NULL)
+	gtk_entry_set_text (GTK_ENTRY (fileinfo_sub_artist), a_tune->artist);
+
+ if (a_tune->title != NULL)
+	gtk_entry_set_text (GTK_ENTRY (fileinfo_sub_title), a_tune->title);
+
+ if (a_tune->comment != NULL)
+	{
+	/* Freeze the widget for update */
+	gtk_text_freeze(GTK_TEXT(fileinfo_sub_comment));
+
+	/* Delete the old comment */
+	gtk_text_set_point(GTK_TEXT(fileinfo_sub_comment), 0);
+	gtk_text_forward_delete(GTK_TEXT(fileinfo_sub_comment),
+	gtk_text_get_length(GTK_TEXT(fileinfo_sub_comment)));
+
+	/* Put in the new comment */	
+	gtk_text_insert (GTK_TEXT (fileinfo_sub_comment), NULL, NULL, NULL,
+	a_tune->comment, strlen(a_tune->comment));
+
+	/* Un-freeze the widget */
+	gtk_text_thaw(GTK_TEXT(fileinfo_sub_comment));
+	}
+#endif
+}
+
+
+void xs_fileinfo(gchar *pcFilename)
+{
+ /* Check if there already is an open fileinfo window */
+ if (xs_fileinfowin)
+	{
+	gdk_window_raise(xs_fileinfowin->window);
+	return;
+	}
+
+ /* If not, create a new one */
+ xs_fileinfowin = create_xs_fileinfowin();
+
+
+ /* Set the song informations */
+ gtk_entry_set_text(GTK_ENTRY (LUW("fileinfo_filename")), pcFilename);
+
+#if 0
+ gtk_entry_set_text(GTK_ENTRY (LUW("fileinfo_songname")), sidInf.infoString[0]);
+ gtk_entry_set_text(GTK_ENTRY (LUW("fileinfo_composer")), sidInf.infoString[1]);
+ gtk_entry_set_text(GTK_ENTRY (LUW("fileinfo_copyright")), sidInf.infoString[2]);
+
+
+  /* "main tune" - the pseudo tune */
+  tmpMenuItem = gtk_menu_item_new_with_label ("General info");
+  gtk_widget_show (tmpMenuItem);
+  gtk_menu_append (GTK_MENU (fileinfo_sub_tune_menu), tmpMenuItem);
+  gtk_signal_connect (GTK_OBJECT (tmpMenuItem), "activate",
+			GTK_SIGNAL_FUNC (xs_fileinfo_sub_tune), fileinfo_sub_tune_menu);
+
+  /* Other menu items */
+  for (n = 1; n <= sidInf.songs; n++)
+	{
+	snprintf(tmpStr, sizeof(tmpStr), "Tune #%i", n);
+
+	tmpMenuItem = gtk_menu_item_new_with_label (tmpStr);
+	gtk_widget_show (tmpMenuItem);
+	gtk_menu_append (GTK_MENU (fileinfo_sub_tune_menu), tmpMenuItem);
+
+	gtk_signal_connect (GTK_OBJECT (tmpMenuItem), "activate",
+			GTK_SIGNAL_FUNC (xs_fileinfo_sub_tune), fileinfo_sub_tune_menu);
+	}
+
+  gtk_option_menu_set_menu (GTK_OPTION_MENU (fileinfo_sub_tune), fileinfo_sub_tune_menu);
+
+  /* Check if user wants STIL info */
+  if (xs_cfg.usestil)
+	xs_stil_get(filename);
+
+  /* Set the sub-tune information */
+  xs_fileinfo_subtune(NULL, fileinfo_sub_tune_menu);
+#endif
+
+  /* Show the window */
+  gtk_widget_show(xs_fileinfowin);
+}