changeset 72:e3b205a6bc7e

Lots re-arranging and new code for upcoming modularization.
author Matti Hamalainen <ccr@tnsp.org>
date Fri, 12 Sep 2003 03:26:04 +0000
parents 2b32c75729ce
children 2bc607888f53
files src/Makefile.am src/xmms-sid.c src/xmms-sid.h src/xs_config.c src/xs_config.h src/xs_sidplay1.cc src/xs_sidplay1.h
diffstat 7 files changed, 215 insertions(+), 108 deletions(-) [+]
line wrap: on
line diff
--- a/src/Makefile.am	Wed Sep 10 06:21:04 2003 +0000
+++ b/src/Makefile.am	Fri Sep 12 03:26:04 2003 +0000
@@ -10,8 +10,6 @@
 
 # Plugin sources
 libxmmssid_la_SOURCES =	\
-	xmms-sid.c	xmms-sid.h	\
-	xs_sidplay1.cc	xs_sidplay1.h	\
 	xs_init.c	\
 	xs_about.c	\
 	xs_support.c	xs_support.h	\
@@ -20,6 +18,8 @@
 	xs_length.c	xs_length.h	\
 	xs_genui.c	xs_genui.h	\
 	xs_glade.c	xs_glade.h	\
-	xs_interface.c	xs_interface.h
+	xs_interface.c	xs_interface.h	\
+	xs_sidplay1.cc	xs_sidplay1.h	\
+	xmms-sid.c	xmms-sid.h
 
 EXTRA_DIST = xmms-sid-logo.xpm
--- a/src/xmms-sid.c	Wed Sep 10 06:21:04 2003 +0000
+++ b/src/xmms-sid.c	Fri Sep 12 03:26:04 2003 +0000
@@ -26,6 +26,7 @@
 #include <errno.h>
 
 #include <xmms/plugin.h>
+#include <xmms/util.h>
 
 #include "xmms-sid.h"
 #include "xs_support.h"
@@ -37,8 +38,40 @@
 /*
  * Include player engines
  */
+#ifdef HAVE_SIDPLAY1
 #include "xs_sidplay1.h"
+#endif
+#ifdef HAVE_SIDPLAY2
 #include "xs_sidplay2.h"
+#endif
+
+
+typedef struct {
+	gint		plrIdent;
+	gboolean	(*plrInit)(t_xs_status *);
+	void		(*plrClose)(t_xs_status *);
+	gboolean	(*plrInitSong)(t_xs_status *);
+	void		(*plrFillBuffer)(t_xs_status *, gchar *, gint);
+	gboolean	(*plrLoadSID)(t_xs_status *, gchar *);
+} t_xs_player;
+
+
+t_xs_player xs_playerlist[] = {
+#ifdef HAVE_SIDPLAY1
+	{ XS_ENG_SIDPLAY1, xs_sidplay1_init, xs_sidplay1_close,
+		xs_sidplay1_initsong, xs_sidplay1_fillbuffer,
+		xs_sidplay1_loadsid
+	},
+#endif
+#ifdef HAVE_SIDPLAY2
+	{ XS_ENG_SIDPLAY2, xs_sidplay2_init, xs_sidplay2_close,
+		xs_sidplay2_initsong, xs_sidplay2_fillbuffer,
+		xs_sidplay2_loadsid
+	},
+#endif
+};
+
+const gint xs_nplayerlist = (sizeof(xs_playerlist) / sizeof(t_xs_player));
 
 
 /*
@@ -48,6 +81,8 @@
 static pthread_t		xs_decode_thread;
 static pthread_mutex_t		xs_mutex = PTHREAD_MUTEX_INITIALIZER;
 struct t_xs_cfg			xs_cfg;
+t_xs_status			xs_status;
+t_xs_player			*xs_player;
 
 
 /*
@@ -73,22 +108,49 @@
  */
 void xs_init(void)
 {
+ gint iPlayer;
+ gboolean isInitialized;
+ 
  XSDEBUG("xs_init()\n");
 
  /* Initialize and get configuration */
  memset(&xs_cfg, 0, sizeof(xs_cfg));
-
  xs_read_configuration();
 
  /* Initialize status */
  memset(&xs_status, 0, sizeof(xs_status));
- xs_status.allowNext = TRUE;	// Initialize to TRUE to allow first song
+ xs_status.allowNext = TRUE;
+
+ /* Try to initialize emulator engine */
+ XSDEBUG("initializing emulator engine...\n");
 
- /* Try to initialize emulator engine(s) */
- XSDEBUG("initializing emulator engine(s)...\n");
+ iPlayer = 0;
+ isInitialized = FALSE;
+ while ((iPlayer < xs_nplayerlist) && !isInitialized)
+ 	{
+ 	if (xs_playerlist[iPlayer].plrIdent == xs_cfg.playerEngine)
+ 		{
+ 		if (xs_playerlist[iPlayer].plrInit(&xs_status))
+ 			{
+ 			isInitialized = TRUE;
+ 			xs_player = (t_xs_player *) &xs_playerlist[iPlayer];
+ 			}
+ 		} else
+ 		iPlayer++;
+ 	}
 
 
-
+ iPlayer = 0;
+ while ((iPlayer < xs_nplayerlist) && !isInitialized)
+ 	{
+	if (xs_playerlist[iPlayer].plrInit(&xs_status))
+		{
+		isInitialized = TRUE;
+		xs_player = (t_xs_player *) &xs_playerlist[iPlayer];
+ 		} else
+ 		iPlayer++;
+ 	}
+ 
 
  /* Read song-length database */
  if (xs_cfg.songlenDBEnable && (xs_songlen_init() < 0))
@@ -116,12 +178,7 @@
  /* Stop playing */
  xs_stop();
 
- /* Shutdown libSIDPlay(s) */
-
-
-
-
-
+ xs_player->plrClose(&xs_status);
 
  /* Close sub-song control window */
 
@@ -139,10 +196,8 @@
 void *xs_play_loop(void *argPointer)
 {
  t_xs_status myStatus;
- t_xs_tuneinfo tuneInfo;
  gboolean audioOpen;
- gint audioFreq, audioChannels, songLength;
- enum AFormat audioFmt;
+ gint audioFreq, audioChannels, songLength, audioFmt;
  gchar audioBuffer[XS_BUFSIZE];
  gchar *tmpStr;
 
@@ -193,29 +248,24 @@
  songLength = xs_songlen_get(myStatus.currFileName, myStatus.currSong);
 
  /* Initialize song */
-#ifdef HAVE_SIDPLAY1
- if ((myStatus.currTune == NULL) || !myStatus.currTune->getStatus() ||
-	!sidEmuInitializeSong(xs_emuEngine, *myStatus.currTune, myStatus.currSong))
-#endif
-#ifdef HAVE_SIDPLAY2
- if ()
-#endif
+ if ((myStatus.currTune == NULL) || !xs_player->plrInitSong(&myStatus))
 	{
 	XSERR("Couldn't initialize SID-tune '%s' (sub-tune #%i)!\n",
 		myStatus.currFileName, myStatus.currSong);
 	goto err_exit;
 	}
 
- myStatus.currTune->getInfo(tuneInfo);
-
 
  /* Set information for current sub-tune */
- tmpStr = xs_filetitle_get(myStatus.currFileName, &tuneInfo, myStatus.currSong);
+ xs_player->plrGetTuneInfo(&myStatus, &myTuneInfo);
 
- xs_plugin_ip.set_info(tmpStr, (songLength > 0) ? songLength * 1000 : -1,
- 1000 * (tuneInfo.songSpeed ? tuneInfo.songSpeed : (tuneInfo.clockSpeed == SIDTUNE_CLOCK_NTSC) ? 60 : 50),
- audioFreq, audioChannels);
- g_free(tmpStr);
+ xs_plugin_ip.set_info(
+ 	myTuneInfo->titleStr,
+ 	(songLength > 0) ? (songLength * 1000) : -1,
+ 	1000 * myTuneInfo->songSpeed,
+	audioFreq,
+	audioChannels);
+
 
  /* Open the audio output */
  if (!xs_plugin_ip.output->open_audio(audioFmt, audioFreq, audioChannels))
@@ -235,11 +285,7 @@
  while (xs_status.isPlaying && myStatus.isPlaying && (xs_status.currSong == myStatus.currSong))
 	{
 	/* Render audio data */
-#ifdef HAVE_SIDPLAY1
-	sidEmuFillBuffer(xs_emuEngine, *myStatus.currTune, audioBuffer, XS_BUFSIZE);
-#endif
-#ifdef HAVE_SIDPLAY2
-#endif
+	xs_player->plrFillBuffer(&myStatus, audioBuffer, XS_BUFSIZE);
 
 	/* I <3 visualice/haujobb */
 	xs_plugin_ip.add_vis_pcm(
@@ -305,7 +351,7 @@
 
  if (myStatus.currTune != NULL)
 	{
-	delete myStatus.currTune;
+	myStatus.currPlayer->plrDeleteTune(&myStatus);
 	myStatus.currTune = NULL;
 	}
 
@@ -328,8 +374,9 @@
 /*
  * Start playing the given file
  */
-void xs_play_file(char *pcFileName)
+void xs_play_file(gchar *pcFileName)
 {
+
 }
 
 
@@ -402,4 +449,3 @@
  return xs_plugin_ip.output->output_time();
 }
 
-
--- a/src/xmms-sid.h	Wed Sep 10 06:21:04 2003 +0000
+++ b/src/xmms-sid.h	Fri Sep 12 03:26:04 2003 +0000
@@ -34,6 +34,7 @@
 #include <xmms/plugin.h>
 #include <assert.h>
 
+
 /*
  * Generals
  */
@@ -47,8 +48,20 @@
 #define XS_MIN_OVERSAMPLE	(2)		/* Minimum oversampling factor */
 #define XS_MAX_OVERSAMPLE	(8)		/* Maximum oversampling factor */
 
+extern InputPlugin xs_plugin_ip;		/* XMMS-SID plugin structure */
 
-extern InputPlugin xs_plugin_ip;		/* XMMS-SID plugin structure */
+
+
+typedef struct {
+	void			*currConf;
+	void			*currEng;
+	gboolean		isError, isPlaying, allowNext;
+	gint			currSong, nSongs;
+	void			*currTune;
+	gchar			*currFileName;
+} t_xs_status;
+
+extern t_xs_status xs_status;
 
 
 /*
--- a/src/xs_config.c	Wed Sep 10 06:21:04 2003 +0000
+++ b/src/xs_config.c	Fri Sep 12 03:26:04 2003 +0000
@@ -70,7 +70,9 @@
 	{CTYPE_BOOL,	&xs_cfg.alwaysRaise,		"alwaysRaise"},
 
 	{CTYPE_BOOL,	&xs_cfg.titleOverride,		"titleOverride"},
-	{CTYPE_STR,	&xs_cfg.titleFormat,		"titleFormat"}
+	{CTYPE_STR,	&xs_cfg.titleFormat,		"titleFormat"},
+
+	{CTYPE_INT,	&xs_cfg.playerEngine,		"playerEngine"},
 };
 
 const gint xs_cfgtable_max = (sizeof(xs_cfgtable) / sizeof(t_xs_cfg_item));
@@ -120,7 +122,11 @@
 { WTYPE_BUTTON,	CTYPE_BOOL,	"cfg_alwaysraise",	&xs_cfg.alwaysRaise,		0 },
 
 { WTYPE_BUTTON,	CTYPE_BOOL,	"cfg_ftitle_override",	&xs_cfg.titleOverride,		0 },
-{ WTYPE_TEXT,	CTYPE_STR,	"cfg_ftitle_format",	&xs_cfg.titleFormat,		0 }
+{ WTYPE_TEXT,	CTYPE_STR,	"cfg_ftitle_format",	&xs_cfg.titleFormat,		0 },
+
+{ WTYPE_BGROUP,	CTYPE_INT,	"cfg_emu_sidplay1",	&xs_cfg.playerEngine,	XS_ENG_SIDPLAY1 },
+{ WTYPE_BGROUP,	CTYPE_INT,	"cfg_emu_sidplay2",	&xs_cfg.playerEngine,	XS_ENG_SIDPLAY2 },
+
 };
 
 const gint xs_widtable_max = (sizeof(xs_widtable) / sizeof(t_xs_wid_item));
--- a/src/xs_config.h	Wed Sep 10 06:21:04 2003 +0000
+++ b/src/xs_config.h	Fri Sep 12 03:26:04 2003 +0000
@@ -10,6 +10,13 @@
 /*
  * Configuration structure
  */
+enum XS_ENG {
+	XS_ENG_SIDPLAY1,
+	XS_ENG_SIDPLAY2,
+	XS_ENG_TINYSID	
+};
+
+
 enum XS_RES {
 	XS_RES_8BIT = 8,
 	XS_RES_16BIT = 16,
@@ -82,6 +89,8 @@
 
 	gboolean	titleOverride;		/* TRUE if XMMS titles are overriden */
 	gchar		*titleFormat;
+
+	gint		playerEngine;
 } xs_cfg;
 
 
--- a/src/xs_sidplay1.cc	Wed Sep 10 06:21:04 2003 +0000
+++ b/src/xs_sidplay1.cc	Fri Sep 12 03:26:04 2003 +0000
@@ -20,7 +20,7 @@
    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */
 #ifdef HAVE_SIDPLAY1
-#include "xmms-sid.h"
+#include "xs_sidplay1.h"
 
 extern "C" {
 #include <xmms/title.h>
@@ -31,64 +31,96 @@
 #include <sidplay/fformat.h>
 
 
-struct xs_sidplay1 {
-	struct emuConfig	emuConf;
-	emuEngine		emuEngine;
-	gboolean	isError, isPlaying, allowNext;
-	gint		currSong, nSongs;
-	sidTune		*currTune;
-	gchar		*currFileName;
-};
+void xs_sidplay1_close(t_xs_status *myStatus)
+{
+ if (!myStatus) return;
 
-
+ if (!myStatus->currEng)
+	delete (emuEngine *) myStatus->currEng;
 
-gboolean xs_sidplay1_initsong(struct xs_sidplay1 *myStatus)
-{
- return sidEmuInitializeSong(myStatus->emuEngine, myStatus->currTune, myStatus->currSong);
+ if (!myStatus->currConf)
+	free(myStatus->currConf);
+
+ free(myStatus);
 }
 
 
-void xs_sidplay1_fillbuffer(struct xs_sidplay1 *myStatus, gchar *audioBuffer, gint audioBufSize)
+gboolean xs_sidplay1_init(t_xs_status *myStatus)
 {
- sidEmuFillBuffer(myStatus->emuEngine, myStatus->currTune, audioBuffer, audioBufSize);
+ if (!myStatus) return FALSE;
+
+ myStatus->currEng = (void *) new emuEngine;
+ if (!myStatus->currEng)
+	{
+	xs_sidplay1_close(myStatus);
+	return FALSE;
+	}
+
+ myStatus->currConf = calloc(1, sizeof(struct emuConfig));
+ if (!myStatus->currConf)
+	{
+	xs_sidplay1_close(myStatus);
+	return FALSE;
+	}
+
+ return TRUE;
 }
 
 
-gint xs_sidplay1_inittune(gchar *pcFileName)
+gboolean xs_sidplay1_initsong(t_xs_status *myStatus)
+{
+ if ((!myStatus->currTune) || (!((sidTune *)myStatus->currTune)->getStatus())) return FALSE;
+
+ return sidEmuInitializeSong(
+	(emuEngine *) myStatus->currEngine,
+	(sidTune *) myStatus->currTune,
+	myStatus->currSong);
+}
+
+
+void xs_sidplay1_fillbuffer(t_xs_status *myStatus, gchar *audioBuffer, gint audioBufSize)
+{
+ sidEmuFillBuffer(
+	(emuEngine *) myStatus->currEngine,
+	(sidTune *) myStatus->currTune,
+	audioBuffer,
+	audioBufSize);
+}
+
+
+gboolean xs_sidplay1_loadsid(t_xs_status *myStatus, gchar *pcFileName)
 {
  sidTune *newTune;
  sidTuneInfo tuneInfo;
 
- /* Can we set the next tune? */ 
- XSDEBUG("request to play '%s'\n", pcFileName);
-
  /* Try to get the tune */
+ if (!pcFileName) return FALSE;
  newTune = new sidTune(pcFileName);
- if (newTune == NULL) return;
+ if (newTune == NULL) return FALSE;
 
  /* Get current configuration */
- xs_emuEngine.getConfig(xs_emuConf);
+ myStatus->currEngine.getConfig(myStatus->currConf);
 
  /* Configure channels and stuff */
  switch (xs_cfg.fmtChannels) {
 
 	case XS_CHN_AUTOPAN:
-		xs_emuConf.channels = SIDEMU_STEREO;
-		xs_emuConf.autoPanning = SIDEMU_CENTEREDAUTOPANNING;
-		xs_emuConf.volumeControl = SIDEMU_FULLPANNING;
+		myStatus->currConf.channels = SIDEMU_STEREO;
+		myStatus->currConf.autoPanning = SIDEMU_CENTEREDAUTOPANNING;
+		myStatus->currConf.volumeControl = SIDEMU_FULLPANNING;
 		break;
 
 	case XS_CHN_STEREO:
-		xs_emuConf.channels = SIDEMU_STEREO;
-		xs_emuConf.autoPanning = SIDEMU_NONE;
-		xs_emuConf.volumeControl = SIDEMU_NONE;
+		myStatus->currConf.channels = SIDEMU_STEREO;
+		myStatus->currConf.autoPanning = SIDEMU_NONE;
+		myStatus->currConf.volumeControl = SIDEMU_NONE;
 		break;
 
 	case XS_CHN_MONO:
 	default:
-		xs_emuConf.channels = SIDEMU_MONO;
-		xs_emuConf.autoPanning = SIDEMU_NONE;
-		xs_emuConf.volumeControl = SIDEMU_NONE;
+		myStatus->currConf.channels = SIDEMU_MONO;
+		myStatus->currConf.autoPanning = SIDEMU_NONE;
+		myStatus->currConf.volumeControl = SIDEMU_NONE;
 		break;
  }
 
@@ -96,19 +128,19 @@
  /* Memory mode settings */
  switch (xs_cfg.memoryMode) {
 	case XS_MPU_BANK_SWITCHING:
-		xs_emuConf.memoryMode = MPU_BANK_SWITCHING;
+		myStatus->currConf.memoryMode = MPU_BANK_SWITCHING;
 		break;
 
 	case XS_MPU_TRANSPARENT_ROM:
-		xs_emuConf.memoryMode = MPU_TRANSPARENT_ROM;
+		myStatus->currConf.memoryMode = MPU_TRANSPARENT_ROM;
 		break;
 
 	case XS_MPU_PLAYSID_ENVIRONMENT:
-		xs_emuConf.memoryMode = MPU_PLAYSID_ENVIRONMENT;
+		myStatus->currConf.memoryMode = MPU_PLAYSID_ENVIRONMENT;
 		break;
 
 	default:
-		xs_emuConf.memoryMode = MPU_BANK_SWITCHING;
+		myStatus->currConf.memoryMode = MPU_BANK_SWITCHING;
 		break;
  }
 
@@ -116,58 +148,46 @@
  /* Clockspeed settings */
  switch (xs_cfg.clockSpeed) {
 	case XS_CLOCK_NTSC:
-		xs_emuConf.clockSpeed = SIDTUNE_CLOCK_NTSC;
+		myStatus->currConf.clockSpeed = SIDTUNE_CLOCK_NTSC;
 		break;
 
 	case XS_CLOCK_PAL:
 	default:
-		xs_emuConf.clockSpeed = SIDTUNE_CLOCK_PAL;
+		myStatus->currConf.clockSpeed = SIDTUNE_CLOCK_PAL;
 		break;
  }
 
 
  /* Configure rest of the emulation */
- xs_emuConf.bitsPerSample	= xs_cfg.fmtBitsPerSample;
- xs_emuConf.frequency		= xs_cfg.fmtFrequency;
+ myStatus->currConf.bitsPerSample	= xs_cfg.fmtBitsPerSample;
+ myStatus->currConf.frequency		= xs_cfg.fmtFrequency;
 #ifdef HAVE_UNSIGNEDPCM
- xs_emuConf.sampleFormat	= SIDEMU_UNSIGNED_PCM;
+ myStatus->currConf.sampleFormat	= SIDEMU_UNSIGNED_PCM;
 #else
- xs_emuConf.sampleFormat	= SIDEMU_SIGNED_PCM;
+ myStatus->currConf.sampleFormat	= SIDEMU_SIGNED_PCM;
 #endif
- xs_emuConf.mos8580		= xs_cfg.mos8580;
- xs_emuConf.emulateFilter	= xs_cfg.emulateFilters;
- xs_emuConf.filterFs		= xs_cfg.filterFs;
- xs_emuConf.filterFm		= xs_cfg.filterFm;
- xs_emuConf.filterFt		= xs_cfg.filterFt;
+ myStatus->currConf.mos8580		= xs_cfg.mos8580;
+ myStatus->currConf.emulateFilter	= xs_cfg.emulateFilters;
+ myStatus->currConf.filterFs		= xs_cfg.filterFs;
+ myStatus->currConf.filterFm		= xs_cfg.filterFm;
+ myStatus->currConf.filterFt		= xs_cfg.filterFt;
 
  /* Now set the emulator configuration */
- xs_emuEngine.setConfig(xs_emuConf);
-
+ myStatus->currEngine.setConfig(myStatus->currConf);
 
  /* Initialize status information */
- XSDEBUG("starting playing thread!\n");
-
  newTune->getInfo(tuneInfo);
-
- xs_status->isPlaying	= TRUE;
- xs_status->isError	= FALSE;
- xs_status->currSong	= tuneInfo.startSong;
- xs_status->nSongs	= tuneInfo.songs;
- xs_status->currTune	= newTune;
- xs_status->currFileName = g_strdup(pcFileName);
+ if (!newTune) return FALSE;
 
- /* Start the playing thread! */
- if (pthread_create(&xs_decode_thread, NULL, xs_play_loop, NULL) < 0)
-	{
-	XSERR("Couldn't start playing thread! Possible reason reported by system: %s\n", strerror(errno));
-	delete newTune;
-	}
+ myStatus->isPlaying	= TRUE;
+ myStatus->isError	= FALSE;
+ myStatus->currSong	= tuneInfo.startSong;
+ myStatus->nSongs	= tuneInfo.songs;
+ myStatus->currTune	= newTune;
+ myStatus->currFileName = g_strdup(pcFileName);
 
- XSDEBUG("systems should be up?\n");
-
- /* Exit */
+ return TRUE;
 }
 
 
 #endif	/* HAVE_SIDPLAY1 */
-
--- a/src/xs_sidplay1.h	Wed Sep 10 06:21:04 2003 +0000
+++ b/src/xs_sidplay1.h	Fri Sep 12 03:26:04 2003 +0000
@@ -0,0 +1,13 @@
+#ifndef _XS_SIDPLAY1_H
+#define _XS_SIDPLAY1_H
+
+#include "xmms-sid.h"
+
+void		xs_sidplay1_close(t_xs_status *myStatus);
+gboolean	xs_sidplay1_init(t_xs_status *myStatus);
+gboolean	xs_sidplay1_initsong(t_xs_status *myStatus);
+void		xs_sidplay1_fillbuffer(t_xs_status *myStatus, gchar *audioBuffer, gint audioBufSize);
+gboolean	xs_sidplay1_loadsid(t_xs_status *myStatus, gchar *pcFileName);
+void		xs_sidplay1_deletesid(t_xs_status *myStatus);
+
+#endif /* _XS_SIDPLAY1_H */