diff src/xmms-sid.c @ 73:2bc607888f53

Added libsidplay2 module, lots of reworking of internals, sidplay1 support now works with the new framework! Getting libsidplay2 support working shouldn't be too far now...
author Matti Hamalainen <ccr@tnsp.org>
date Sun, 14 Sep 2003 03:14:01 +0000
parents e3b205a6bc7e
children 8cb66a3f75f7
line wrap: on
line diff
--- a/src/xmms-sid.c	Fri Sep 12 03:26:04 2003 +0000
+++ b/src/xmms-sid.c	Sun Sep 14 03:14:01 2003 +0000
@@ -48,25 +48,44 @@
 
 typedef struct {
 	gint		plrIdent;
+	gboolean	(*plrIsOurFile)(gchar *);
 	gboolean	(*plrInit)(t_xs_status *);
 	void		(*plrClose)(t_xs_status *);
 	gboolean	(*plrInitSong)(t_xs_status *);
-	void		(*plrFillBuffer)(t_xs_status *, gchar *, gint);
+	gboolean	(*plrFillBuffer)(t_xs_status *, gchar *, gint);
 	gboolean	(*plrLoadSID)(t_xs_status *, gchar *);
+	gint		(*plrGetTuneSpeed)(t_xs_status *);
+	void		(*plrDeleteSID)(t_xs_status *);
+	void		(*plrGetSIDInfo)(gchar *, gchar **, gint *);
 } t_xs_player;
 
 
 t_xs_player xs_playerlist[] = {
 #ifdef HAVE_SIDPLAY1
-	{ XS_ENG_SIDPLAY1, xs_sidplay1_init, xs_sidplay1_close,
+	{ XS_ENG_SIDPLAY1,
+		xs_sidplay1_isourfile,
+		xs_sidplay1_init, xs_sidplay1_close,
 		xs_sidplay1_initsong, xs_sidplay1_fillbuffer,
-		xs_sidplay1_loadsid
+		xs_sidplay1_loadsid, xs_sidplay1_gettunespeed,
+		xs_sidplay1_deletesid, xs_sidplay1_getsidinfo
 	},
 #endif
 #ifdef HAVE_SIDPLAY2
-	{ XS_ENG_SIDPLAY2, xs_sidplay2_init, xs_sidplay2_close,
+	{ XS_ENG_SIDPLAY2,
+		xs_sidplay2_isourfile,
+		xs_sidplay2_init, xs_sidplay2_close,
 		xs_sidplay2_initsong, xs_sidplay2_fillbuffer,
-		xs_sidplay2_loadsid
+		xs_sidplay2_loadsid, xs_sidplay2_gettunespeed,
+		xs_sidplay2_deletesid, xs_sidplay2_getsidinfo
+	},
+#endif
+#ifdef HAVE_NANOSID
+	{ XS_ENG_NANOSID,
+		xs_nanosid_isourfile,
+		xs_nanosid_init, xs_nanosid_close,
+		xs_nanosid_initsong, xs_nanosid_fillbuffer,
+		xs_nanosid_loadsid, xs_nanosid_gettunespeed,
+		xs_nanosid_deletesid, xs_nanosid_getsidinfo
 	},
 #endif
 };
@@ -117,10 +136,12 @@
  memset(&xs_cfg, 0, sizeof(xs_cfg));
  xs_read_configuration();
 
+
  /* Initialize status */
  memset(&xs_status, 0, sizeof(xs_status));
  xs_status.allowNext = TRUE;
 
+
  /* Try to initialize emulator engine */
  XSDEBUG("initializing emulator engine...\n");
 
@@ -135,8 +156,8 @@
  			isInitialized = TRUE;
  			xs_player = (t_xs_player *) &xs_playerlist[iPlayer];
  			}
- 		} else
- 		iPlayer++;
+ 		}
+ 	iPlayer++;
  	}
 
 
@@ -147,8 +168,8 @@
 		{
 		isInitialized = TRUE;
 		xs_player = (t_xs_player *) &xs_playerlist[iPlayer];
- 		} else
- 		iPlayer++;
+ 		}
+	iPlayer++;
  	}
  
 
@@ -178,6 +199,7 @@
  /* Stop playing */
  xs_stop();
 
+ xs_player->plrDeleteSID(&xs_status);
  xs_player->plrClose(&xs_status);
 
  /* Close sub-song control window */
@@ -191,6 +213,37 @@
 
 
 /*
+ * Check whether the given file is handled by this plugin
+ */
+gint xs_is_our_file(gchar *pcFileName)
+{
+ char *pcExt;
+
+ /* Check the filename */
+ if (pcFileName == NULL)
+	return FALSE;
+
+ /* Try to detect via detection routine, if required */
+ if (xs_cfg.detectMagic && xs_player->plrIsOurFile(pcFileName))
+ 	return TRUE;
+
+ /* Detect just by checking filename extension */
+ pcExt = strrchr(pcFileName, '.');
+ if (pcExt)
+	{
+	pcExt++;
+	if (!strcasecmp(pcExt, "psid")) return TRUE;
+	if (!strcasecmp(pcExt, "sid"))	return TRUE;
+	if (!strcasecmp(pcExt, "dat"))	return TRUE;
+	if (!strcasecmp(pcExt, "inf"))	return TRUE;
+	if (!strcasecmp(pcExt, "info"))	return TRUE;
+	}
+
+ return FALSE;
+}
+
+
+/*
  * Main playing thread loop
  */
 void *xs_play_loop(void *argPointer)
@@ -199,7 +252,6 @@
  gboolean audioOpen;
  gint audioFreq, audioChannels, songLength, audioFmt;
  gchar audioBuffer[XS_BUFSIZE];
- gchar *tmpStr;
 
 
  pthread_mutex_lock(&xs_mutex);
@@ -244,11 +296,8 @@
  XSDEBUG("subtune #%i selected, initializing...\n", myStatus.currSong);
 
 
- /* Get song length for current subtune */
- songLength = xs_songlen_get(myStatus.currFileName, myStatus.currSong);
-
  /* Initialize song */
- if ((myStatus.currTune == NULL) || !xs_player->plrInitSong(&myStatus))
+ if (!xs_player->plrInitSong(&myStatus))
 	{
 	XSERR("Couldn't initialize SID-tune '%s' (sub-tune #%i)!\n",
 		myStatus.currFileName, myStatus.currSong);
@@ -256,16 +305,17 @@
 	}
 
 
- /* Set information for current sub-tune */
- xs_player->plrGetTuneInfo(&myStatus, &myTuneInfo);
+ /* Get song information for current subtune */
+ songLength = xs_songlen_get(myStatus.currFileName, myStatus.currSong);
 
+/*
  xs_plugin_ip.set_info(
- 	myTuneInfo->titleStr,
+ 	myTuneInfo.titleStr,
  	(songLength > 0) ? (songLength * 1000) : -1,
- 	1000 * myTuneInfo->songSpeed,
+ 	1000 * myTuneInfo.songSpeed,
 	audioFreq,
 	audioChannels);
-
+*/
 
  /* Open the audio output */
  if (!xs_plugin_ip.output->open_audio(audioFmt, audioFreq, audioChannels))
@@ -349,11 +399,7 @@
 	xs_plugin_ip.output->close_audio();
 	}
 
- if (myStatus.currTune != NULL)
-	{
-	myStatus.currPlayer->plrDeleteTune(&myStatus);
-	myStatus.currTune = NULL;
-	}
+ xs_player->plrDeleteSID(&myStatus);
 
  g_free(myStatus.currFileName);
 
@@ -376,7 +422,18 @@
  */
 void xs_play_file(gchar *pcFileName)
 {
+ /* Initialize the tune */
+ if (!xs_player->plrLoadSID(&xs_status, pcFileName))
+ 	return;
 
+ /* 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));
+	xs_player->plrDeleteSID(&xs_status);
+	}
+
+ XSDEBUG("systems should be up?\n");
 }
 
 
@@ -449,3 +506,11 @@
  return xs_plugin_ip.output->output_time();
 }
 
+
+/*
+ * Return song information
+ */
+void xs_get_song_info(gchar *songFileName, gchar **songTitle, gint *songLength)
+{
+ xs_player->plrGetSIDInfo(songFileName, songTitle, songLength);
+}