changeset 202:fe684a2ccdc7

Reworking code.
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 16 Nov 2004 06:56:02 +0000
parents 6a82506329ae
children 4306881d0244
files src/xmms-sid.c src/xs_config.c src/xs_config.h src/xs_genui.c src/xs_genui.h src/xs_sidplay.h src/xs_sidplay1.cc src/xs_support.c
diffstat 8 files changed, 75 insertions(+), 149 deletions(-) [+]
line wrap: on
line diff
--- a/src/xmms-sid.c	Tue Nov 16 06:55:04 2004 +0000
+++ b/src/xmms-sid.c	Tue Nov 16 06:56:02 2004 +0000
@@ -411,6 +411,9 @@
 
 /*
  * Start playing the given file
+ * Here we load the tune and initialize the playing thread.
+ * Usually you would also initialize the output-plugin, but
+ * this is XMMS-SID and we do it on the player thread instead.
  */
 void xs_play_file(gchar *pcFilename)
 {
@@ -450,6 +453,12 @@
 
 /*
  * Stop playing
+ * Here we set the playing status to stop and wait for playing
+ * thread to shut down. In any "correctly" done plugin, this is
+ * also the function where you close the output-plugin, but since
+ * XMMS-SID's special behaviour, we don't do that here.
+ *
+ * Finally tune and other memory allocations are free'd.
  */
 void xs_stop(void)
 {
@@ -668,7 +677,12 @@
 
 /*
  * Set the time-seek position
- * (the playing thread will do the "seeking" aka song-change)
+ * The playing thread will do the "seeking", which means sub-tune
+ * changing in XMMS-SID's case. iTime argument is time in seconds,
+ * in contrast to milliseconds used in other occasions.
+ *
+ * This function is called whenever position slider is clicked or
+ * other method of seeking is used (keyboard, etc.)
  */
 void xs_seek(gint iTime)
 {
@@ -709,6 +723,10 @@
 
 /*
  * Return the playing "position/time"
+ * Determine current position/time in song. Used by XMMS to update
+ * the song clock and position slider and MOST importantly to determine
+ * END OF SONG! Return value of -2 means error, XMMS opens an audio
+ * error dialog. -1 means end of song (if one was playing currently).
  */
 gint xs_get_time(void)
 {
@@ -746,6 +764,9 @@
 
 /*
  * Return song information
+ * This function is called by XMMS when initially loading the playlist.
+ * Subsequent changes to information are made by the player thread,
+ * which uses xs_plugin_ip.set_info();
  */
 void xs_get_song_info(gchar *songFilename, gchar **songTitle, gint *songLength)
 {
--- a/src/xs_config.c	Tue Nov 16 06:55:04 2004 +0000
+++ b/src/xs_config.c	Tue Nov 16 06:56:02 2004 +0000
@@ -439,7 +439,6 @@
  gtk_widget_destroy(xs_configwin);
  xs_configwin = NULL;
 
-
  /* Write settings */
  xs_write_configuration();
 
--- a/src/xs_config.h	Tue Nov 16 06:55:04 2004 +0000
+++ b/src/xs_config.h	Tue Nov 16 06:56:02 2004 +0000
@@ -55,6 +55,13 @@
 };
 
 
+enum XS_SIDMODEL {
+	XS_SIDMODEL_UNKNOWN = 0,
+	XS_SIDMODEL_6581,
+	XS_SIDMODEL_8580
+};
+
+
 extern struct t_xs_cfg {
 	/* General audio settings */
 	gint		audioBitsPerSample;
--- a/src/xs_genui.c	Tue Nov 16 06:55:04 2004 +0000
+++ b/src/xs_genui.c	Tue Nov 16 06:56:02 2004 +0000
@@ -8,3 +8,19 @@
 #include "xs_interface.h"
 #include "xs_glade.h"
 
+
+void
+xs_cfg_subauto_enable_toggled          (GtkToggleButton *togglebutton,
+                                        gpointer         user_data)
+{
+
+}
+
+
+void
+xs_cfg_subauto_min_enable_toggled      (GtkToggleButton *togglebutton,
+                                        gpointer         user_data)
+{
+
+}
+
--- a/src/xs_genui.h	Tue Nov 16 06:55:04 2004 +0000
+++ b/src/xs_genui.h	Tue Nov 16 06:56:02 2004 +0000
@@ -112,3 +112,11 @@
 void
 xs_cfg_stil_enable_toggled             (GtkToggleButton *togglebutton,
                                         gpointer         user_data);
+
+void
+xs_cfg_subauto_enable_toggled          (GtkToggleButton *togglebutton,
+                                        gpointer         user_data);
+
+void
+xs_cfg_subauto_min_enable_toggled      (GtkToggleButton *togglebutton,
+                                        gpointer         user_data);
--- 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
--- a/src/xs_sidplay1.cc	Tue Nov 16 06:55:04 2004 +0000
+++ b/src/xs_sidplay1.cc	Tue Nov 16 06:56:02 2004 +0000
@@ -26,10 +26,9 @@
 extern "C" {
 #include "xs_sidplay1.h"
 #include <stdio.h>
-#include <xmms/titlestring.h>
 #include "xs_config.h"
-#include "xs_support.h"
 #include "xs_length.h"
+#include "xs_title.h"
 }
 
 #include <sidplay/player.h>
@@ -318,8 +317,7 @@
 /*
  * Return song information
  */
-#define TFUNCTION1	xs_sidplay1_filetitle
-#define TFUNCTION2	xs_sidplay1_getsidinfo
+#define TFUNCTION	xs_sidplay1_getsidinfo
 #define TTUNEINFO	sidTuneInfo
 #define TTUNE		sidTune
 #include "xs_sidplay.h"
--- a/src/xs_support.c	Tue Nov 16 06:55:04 2004 +0000
+++ b/src/xs_support.c	Tue Nov 16 06:56:02 2004 +0000
@@ -21,10 +21,10 @@
 */
 
 #include "xs_support.h"
-#include <stdlib.h>
 #include <string.h>
 #include <ctype.h>
 
+
 /*
  * Utility routines
  */
@@ -90,5 +90,3 @@
 {
  while (pcStr[*piPos] && isdigit(pcStr[*piPos])) (*piPos)++;
 }
-
-