diff src/xmms-sid.c @ 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
line wrap: on
line diff
--- 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();
 }
 
-