changeset 281:d913f0f69487

Automatic sub-tune changing.
author Matti Hamalainen <ccr@tnsp.org>
date Sat, 25 Dec 2004 10:57:03 +0000
parents b7e2938f2837
children 0d2d379a83c0
files src/xmms-sid.c
diffstat 1 files changed, 56 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/src/xmms-sid.c	Sat Dec 25 08:53:05 2004 +0000
+++ b/src/xmms-sid.c	Sat Dec 25 10:57:03 2004 +0000
@@ -271,8 +271,9 @@
 {
  t_xs_status myStatus;
  t_xs_tuneinfo *myTune;
- gboolean audioOpen = FALSE, doPlay = FALSE;
- gint audioGot, songLength;
+ gboolean audioOpen = FALSE, doPlay = FALSE, isFound = FALSE;
+ gboolean playedTune[XS_STIL_MAXENTRY];
+ gint audioGot, songLength, i;
 #ifdef XS_BUF_DYNAMIC
  gchar *audioBuffer = NULL, *oversampleBuffer = NULL;
 #else
@@ -286,6 +287,7 @@
  myTune = xs_status.tuneInfo;
  XS_MUTEX_UNLOCK(xs_status);
 
+ xs_memset(&playedTune, 0, sizeof(playedTune));
  audioBuffer = oversampleBuffer = NULL;
 
  /* Allocate audio buffer */
@@ -316,8 +318,57 @@
  while (xs_status.isPlaying && doPlay)
  {
  XS_MUTEX_LOCK(xs_status);
+ assert(xs_status.currSong >= 1);
+ assert(xs_status.currSong <= XS_STIL_MAXENTRY);
+ myStatus.isPlaying = TRUE;
+ XS_MUTEX_UNLOCK(xs_status);
+
+ /* Automatic sub-tune change logic */
+ if (xs_cfg.subAutoEnable && (myStatus.currSong == xs_status.currSong))
+ 	{
+ 	/* Check if currently selected sub-tune has been played already */
+ 	if (playedTune[myStatus.currSong - 1])
+ 		{
+ 		/* Find a tune that has not been played */
+ 		XSDEBUG("tune #%i already played, finding next match ...\n", myStatus.currSong);
+ 		isFound = FALSE;
+ 		i = 0;
+ 		while (!isFound && (i < myTune->nsubTunes))
+ 			{
+ 			if (xs_cfg.subAutoMinOnly)
+ 				{
+ 				/* A tune with minimum length must be found */
+ 				if (!playedTune[i] && myTune->subTunes[i].tuneLength >= xs_cfg.subAutoMinTime)
+ 					isFound = TRUE;
+ 				} else {
+ 				/* Any unplayed tune is okay */
+ 				if (!playedTune[i])
+ 					isFound = TRUE;
+ 				}
+
+			i++;
+ 			}
+
+		if (isFound)
+			{
+			/* Set the new sub-tune */
+			XSDEBUG("found #%i\n", i);
+			XS_MUTEX_LOCK(xs_status);
+			xs_status.currSong = i;
+			XS_MUTEX_UNLOCK(xs_status);
+			} else
+			/* This is the end */
+			doPlay = FALSE;
+
+		continue; /* This is ugly, but ... */
+ 		}
+ 	}
+
+ /* Tell that we are initializing, update sub-tune controls */ 
+ XS_MUTEX_LOCK(xs_status);
  myStatus.currSong = xs_status.currSong;
  XS_MUTEX_UNLOCK(xs_status);
+ playedTune[myStatus.currSong - 1] = TRUE;
 
  XSDEBUG("subtune #%i selected, initializing...\n", myStatus.currSong);
 
@@ -325,9 +376,8 @@
  xs_subctrl_update();
  GDK_THREADS_LEAVE();
 
+ /* Check minimum playtime */
  songLength = myTune->subTunes[myStatus.currSong - 1].tuneLength;
- 
- /* Check minimum playtime */
  if (xs_cfg.playMinTimeEnable)
  	{
 	if (xs_cfg.playMinTimeUnknown)
@@ -450,11 +500,8 @@
 	}
 
  /* Now determine if we continue by selecting other subtune or something */
- if (!myStatus.isPlaying)
- 	{
- 	/* FIXME FIX ME! !! subtunet joo ja tuota eli */
+ if (!myStatus.isPlaying && !xs_cfg.subAutoEnable)
  	doPlay = FALSE;
- 	}
  }
 
 xs_err_exit:
@@ -582,7 +629,7 @@
 void xs_pause(short pauseState)
 {
  XS_MUTEX_LOCK(xs_status);
- /* pause... */
+ /* FIXME FIX ME todo: pause should disable sub-tune controls */
  XS_MUTEX_UNLOCK(xs_status);
 
  xs_subctrl_close();