diff src/xs_sidplay.h @ 202:fe684a2ccdc7

Reworking code.
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 16 Nov 2004 06:56:02 +0000
parents 84bff1a4bb1c
children 608f31f6c095
line wrap: on
line diff
--- a/src/xs_sidplay.h	Tue Nov 16 06:55:04 2004 +0000
+++ b/src/xs_sidplay.h	Tue Nov 16 06:56:02 2004 +0000
@@ -1,137 +1,11 @@
 /*
  * Here comes the really ugly code...
- *
- * Create the SID-tune description string from the tune's information
- * formatted by the user-specified format-string.
+ * Get all SID-tune information (for all sub-tunes)
+ * including name, length, etc.
  */
-#define VBUFSIZE	(1024)
-#define VPUTCH(MCH)	if (iIndex < VBUFSIZE) tmpBuf[iIndex++] = MCH;
-#define VPUTSTR(MSTR)	{if (MSTR) {if ((iIndex + strlen(MSTR) + 1) < VBUFSIZE){strcpy(&tmpBuf[iIndex], MSTR);iIndex += strlen(MSTR); } else iIndex = VBUFSIZE;}}
-
-gchar * TFUNCTION1(gchar *pcFilename, TTUNEINFO *pfInfo, gint iSubTune)
+t_xs_tune * TFUNCTION(gchar *pcFilename)
 {
- gchar *sFileName, *sFilePath, *sFileExt, *pcStr, *pcResult,
- 	tmpStr[VBUFSIZE], tmpBuf[VBUFSIZE];
- gint iIndex;
-#ifdef HAVE_XMMSEXTRA
- TitleInput *ptInput;
-#endif
-
- /* Check the info strings */
- if (pfInfo->numberOfInfoStrings < 3)
-	{
-	if (pfInfo->numberOfInfoStrings < 1)
-		return 0;
-
-	return g_strdup(pfInfo->infoString[0]);
-	}
-
- /* Split the filename into path */
- sFilePath = g_strdup(pcFilename);
- sFileName = strrchr(sFilePath, '/');
- if (sFileName)
-	sFileName[1] = 0;
-		
- /* Filename */
- sFileName = strrchr(pcFilename, '/');
- if (sFileName)
-	sFileName = g_strdup(sFileName + 1);
-	else
-	sFileName = g_strdup(pcFilename);
-
- sFileExt = strrchr(sFileName, '.');
- sFileExt[0] = 0;
-
- /* Extension */
- sFileExt = strrchr(pcFilename, '.');
-
-
-#ifdef HAVE_XMMSEXTRA
- /* Check if the titles are overridden or not */
- if (!xs_cfg.titleOverride)
-	{
-	/* Use generic XMMS titles */
-	/* XMMS_NEW_TITLEINPUT(ptInput);
-	 * We duplicate and add typecast to the code here due to XMMS's braindead headers
-	 */
-	ptInput = (TitleInput *) g_malloc0(sizeof(TitleInput));
-	ptInput->__size = XMMS_TITLEINPUT_SIZE;
-	ptInput->__version = XMMS_TITLEINPUT_VERSION;
-
-	/* Create the input fields */
-	ptInput->file_name	= sFileName;
-	ptInput->file_ext	= sFileExt;
-	ptInput->file_path	= sFilePath;
-
-	ptInput->track_name	= pfInfo->infoString[0];
-	ptInput->track_number	= iSubTune;
-	ptInput->album_name	= NULL;
-	ptInput->performer	= pfInfo->infoString[1];
-	ptInput->date		= g_strdup((pfInfo->sidModel == SIDTUNE_SIDMODEL_6581) ? "SID6581" : "SID8580");
-
-	ptInput->year		= 0;
-	ptInput->genre		= g_strdup("SID-tune");
-	ptInput->comment	= pfInfo->infoString[2];
-
-	/* Create the string */
-	pcResult = xmms_get_titlestring(xmms_get_gentitle_format(), ptInput);
-
-	/* Dispose all allocated memory */
-	g_free(ptInput->date);
-	g_free(ptInput->genre);
-	g_free(ptInput);
-	}
-	else
-#endif
-	{
-	/* Create the string */
-	pcStr = xs_cfg.titleFormat;
-	iIndex = 0;
-	while (*pcStr && (iIndex < VBUFSIZE))
-	{
-	if (*pcStr == '%')
-		{
-		pcStr++;
-		switch (*pcStr) {
-		case '%': VPUTCH('%'); break;
-		case 'f': VPUTSTR(sFileName); break;
-		case 'F': VPUTSTR(sFilePath); break;
-		case 'e': VPUTSTR(sFileExt); break;
-		case 'p': VPUTSTR(pfInfo->infoString[1]); break;
-		case 't': VPUTSTR(pfInfo->infoString[0]); break;
-		case 'c': VPUTSTR(pfInfo->infoString[2]); break;
-		case 's': VPUTSTR(pfInfo->formatString); break;
-		case 'n':
-			snprintf(tmpStr, VBUFSIZE, "%i", iSubTune);
-			VPUTSTR(tmpStr);
-			break;
-		}
-		} else {
-		VPUTCH(*pcStr);
-		}
-	pcStr++;
-	}
-
-	tmpBuf[iIndex] = 0;
-
-	/* Make resulting string */
-	pcResult = g_strdup(tmpBuf);
-	}
-
- /* Free temporary strings */
- g_free(sFileName);
- g_free(sFilePath);
-	
- return pcResult;
-}
-
-
-/*
- * Get all SID-tune information (for all sub-tunes) including name, length, etc.
- */
-t_xs_tune * TFUNCTION2(gchar *pcFilename)
-{
- t_xs_sldb_node *tuneLen = NULL;
+ t_xs_sldb_node *tuneLength = NULL;
  t_xs_tune *pResult;
  TTUNEINFO tuneInfo;
  TTUNE *testTune;
@@ -158,11 +32,14 @@
 #endif
 
  /* Get length information (NOTE: Do not free this!) */
- tuneLen = xs_songlen_get(pcFilename);
+ tuneLength = xs_songlen_get(pcFilename);
 
  /* Allocate tuneinfo structure */
- pResult = xs_tune_new(pcFilename, tuneInfo.songs, tuneInfo.startSong,
- 	tuneInfo.infoString[0], tuneInfo.infoString[1], tuneInfo.infoString[2]);
+ pResult = xs_tune_new(pcFilename,
+ 	tuneInfo.songs, tuneInfo.startSong,
+ 	tuneInfo.infoString[0], tuneInfo.infoString[1], tuneInfo.infoString[2],
+ 	tuneInfo.loadAddr, tuneInfo.initAddr, tuneInfo.playAddr,
+ 	tuneInfo.dataFileLen);
 
  if (!pResult)
  	{
@@ -175,14 +52,17 @@
 	{
 	/* Make the title */
 	if (haveInfo)
-		pResult->subTunes[i].tuneTitle = TFUNCTION1(pcFilename, &tuneInfo, i+1);
-		else
+		{
+		pResult->subTunes[i].tuneTitle =
+		xs_make_titlestring(pcFilename, i+1, tuneInfo.sidModel,
+		tuneInfo.formatString, tuneInfo.infoString[0],
+		tuneInfo.infoString[1], tuneInfo.infoString[2]);
+		} else
 		pResult->subTunes[i].tuneTitle = g_strdup(pcFilename);
-	
 
 	/* Get song length */
-	if (tuneLen && (i < tuneLen->nLengths))
-		pResult->subTunes[i].tuneLength = tuneLen->sLengths[i];
+	if (tuneLength && (i < tuneLength->nLengths))
+		pResult->subTunes[i].tuneLength = tuneLength->sLengths[i];
 		else
 		pResult->subTunes[i].tuneLength = -1;
 	}
@@ -193,7 +73,6 @@
 }
 
 /* Undefine these */
-#undef TFUNCTION1
-#undef TFUNCTION2
+#undef TFUNCTION
 #undef TTUNEINFO
 #undef TTUNE