changeset 333:15c5b231efc9

- subTune -> subTunes - adjust to struct size + 1 (XS_STIL_MAXENTRY change) - misc cleanups
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 22 Sep 2005 01:55:01 +0000
parents 961212302eb9
children 19c89f9ca2cc
files src/xmms-sid.c
diffstat 1 files changed, 38 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/src/xmms-sid.c	Thu Sep 22 01:54:01 2005 +0000
+++ b/src/xmms-sid.c	Thu Sep 22 01:55:01 2005 +0000
@@ -303,7 +303,7 @@
  t_xs_status myStatus;
  t_xs_tuneinfo *myTune;
  gboolean audioOpen = FALSE, doPlay = FALSE, isFound = FALSE;
- gboolean playedTune[XS_STIL_MAXENTRY];
+ gboolean playedTune[XS_STIL_MAXENTRY + 1];
  gint audioGot, songLength, i;
 #ifdef XS_BUF_DYNAMIC
  gchar *audioBuffer = NULL, *oversampleBuffer = NULL;
@@ -358,13 +358,13 @@
  if (xs_cfg.subAutoEnable && (myStatus.currSong == xs_status.currSong))
  	{
  	/* Check if currently selected sub-tune has been played already */
- 	if (playedTune[myStatus.currSong - 1])
+ 	if (playedTune[myStatus.currSong])
  		{
  		/* 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))
+ 		while (!isFound && (i <= myTune->nsubTunes))
  			{
  			if (xs_cfg.subAutoMinOnly)
  				{
@@ -398,7 +398,7 @@
 
  /* Tell that we are initializing, update sub-tune controls */ 
  myStatus.currSong = xs_status.currSong;
- playedTune[myStatus.currSong - 1] = TRUE;
+ playedTune[myStatus.currSong] = TRUE;
  XS_MUTEX_UNLOCK(xs_status);
  XS_MUTEX_UNLOCK(xs_cfg);
 
@@ -891,7 +891,7 @@
  /* If we have song-position patch, check settings */
 #ifdef HAVE_SONG_POSITION
  case XS_SSC_PATCH:
-	if ((iTime >= 1) && (iTime <= xs_status.tuneInfo->nsubTunes))
+	if ((iTime > 0) && (iTime <= xs_status.tuneInfo->nsubTunes))
 		xs_status.currSong = iTime;
 	break;
 #endif
@@ -966,9 +966,9 @@
  /* Get tune information from emulation engine */
  pInfo = xs_status.sidPlayer->plrGetSIDInfo(songFilename);
  if (!pInfo) return;
-
+ 
  /* Get sub-tune information, if available */
- if ((pInfo->startTune >= 0) && (pInfo->startTune <= pInfo->nsubTunes))
+ if ((pInfo->startTune > 0) && (pInfo->startTune <= pInfo->nsubTunes))
  	{
 	(*songTitle) = g_strdup(pInfo->subTunes[pInfo->startTune - 1].tuneTitle);
 
@@ -992,19 +992,42 @@
 {
  t_xs_tuneinfo *pResult;
  
+ /* Allocate structure */
  pResult = (t_xs_tuneinfo *) g_malloc0(sizeof(t_xs_tuneinfo));
- if (!pResult) return NULL;
+ if (!pResult)
+ 	{
+ 	XSERR("Could not allocate memory for t_xs_tuneinfo ('%s')\n", pcFilename);
+ 	return NULL;
+ 	}
  
  pResult->sidFilename = g_strdup(pcFilename);
  if (!pResult->sidFilename)
  	{
+ 	XSERR("Could not allocate sidFilename ('%s')\n", pcFilename);
  	g_free(pResult);
  	return NULL;
  	}
+
+ /* Allocate space for subtune information */
+ if (nsubTunes > 0)
+ 	{
+ 	pResult->subTunes = g_malloc0(sizeof(t_xs_subtuneinfo) * nsubTunes);
+ 	if (!pResult->subTunes)
+ 		{
+ 		XSERR("Could not allocate memory for t_xs_subtuneinfo ('%s', %i)\n",
+ 		pcFilename, nsubTunes);
+
+	 	g_free(pResult->sidFilename);
+ 		g_free(pResult);
+ 		return NULL;
+ 		}
+	}
  
+ /* The following allocations don't matter if they fail */
  pResult->sidName	= g_strdup(sidName);
  pResult->sidComposer	= g_strdup(sidComposer);
  pResult->sidCopyright	= g_strdup(sidCopyright);
+
  pResult->nsubTunes	= nsubTunes;
  pResult->startTune	= startTune;
 
@@ -1024,20 +1047,17 @@
  gint i;
  if (!pTune) return;
 
+ for (i = 0; i < pTune->nsubTunes; i++)
+ 	{
+	g_free(pTune->subTunes[i].tuneTitle);
+	pTune->subTunes[i].tuneTitle = NULL;
+ 	}
+ 
+ pTune->nsubTunes = 0;
  g_free(pTune->sidFilename);	pTune->sidFilename = NULL;
  g_free(pTune->sidName);	pTune->sidName = NULL;
  g_free(pTune->sidComposer);	pTune->sidComposer = NULL;
  g_free(pTune->sidCopyright);	pTune->sidCopyright = NULL;
- 
- for (i = 0; i < pTune->nsubTunes; i++)
- 	{
- 	if (pTune->subTunes[i].tuneTitle)
- 		{
- 		g_free(pTune->subTunes[i].tuneTitle);
- 		pTune->subTunes[i].tuneTitle = NULL;
- 		}
- 	}
- 
  g_free(pTune);
 }