view src/xmms-sid.h @ 230:608f31f6c095

Raw cleanup.
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 21 Dec 2004 09:25:03 +0000
parents d18bf68d7bd9
children d04191d1ea64
line wrap: on
line source

/*  
   XMMS-SID - SIDPlay input plugin for X MultiMedia System (XMMS)

   Main header file

   Written by Matti "ccr" Hamalainen <ccr@tnsp.org>

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef _XMMS_SID_H
#define _XMMS_SID_H

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#ifdef HAVE_ASSERT_H
#include <assert.h>
#else
#define assert(x) /* stub */
#endif

#include <glib.h>
#include <pthread.h>
#include <xmms/plugin.h>

#ifdef __cplusplus
extern "C" {
#endif

/* Some defines
 */
#define DEBUG

#undef HAVE_HARDSID_BUILDER	/* HardSID-support is not working and is untested */

#define XS_BUFSIZE		(4096)		/* Size for some buffers */

#define XS_SIDBUF_SIZE		(80*1024)	/* Size of data buffer used for SID-tune
						MD5 hash calculation. If this is too small,
						the computed hash will be incorrect.
						Largest SID files I've seen are ~70kB.
						*/

#define XS_SIDBUF_DYNAMIC			/* If not defined, static buffer is used.
						Probably faster than allocating/deallocating
						from heap, but fails on systems with limited
						stack space.
						*/

#define XS_STIL_MAXENTRY	(128)		/* Max number of sub-songs in STIL/SLDB node */


#define XS_CONFIG_IDENT		"XMMS-SID"	/* Configuration file identifier */
#define XS_CONFIG_FILE		"/.xmms/xmms-sid"	/* Use this configfile if autocyrpe fails */

#define XS_MIN_OVERSAMPLE	(2)		/* Minimum oversampling factor */
#define XS_MAX_OVERSAMPLE	(8)		/* Maximum oversampling factor */


/* Macros for mutexes and threads. These exist to be able to
 * easily change from pthreads to glib threads, etc, if necessary.
 */
#define XS_MPP(M)	M ## _mutex
#ifdef DEBUG
#define XS_MUTEX(M)	pthread_mutex_t	XS_MPP(M) = PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP; int M ## _qq;
#else
#define XS_MUTEX(M)	pthread_mutex_t	XS_MPP(M) = PTHREAD_MUTEX_INITIALIZER
#endif
#define XS_MUTEX_H(M)	extern pthread_mutex_t XS_MPP(M); extern int M ## _qq;
#define XS_MUTEX_LOCK(M)	{ M ## _qq = pthread_mutex_lock(&XS_MPP(M)); if (M ## _qq) XSDEBUG("XS_MUTEX_LOCK(" #M ") == %i\n", M ## _qq); }
#define XS_MUTEX_UNLOCK(M)	{ M ## _qq = pthread_mutex_unlock(&XS_MPP(M)); if (M ## _qq) XSDEBUG("XS_MUTEX_UNLOCK(" #M ") == %i\n", M ## _qq); }

/* Shorthands for linked lists
 */
#define LPREV	(pNode->pPrev)
#define LTHIS	(pNode)
#define LNEXT	(pNode->pNext)


/* Plugin-wide typedefs
 */
typedef struct {
	gint		tuneSpeed;
	gint		tuneLength;
	gchar		*tuneTitle;
} t_xs_subtuneinfo;


typedef struct {
	gchar		*sidFilename,
			*sidName,
			*sidComposer,
			*sidCopyright;
	gint		loadAddr,
			initAddr,
			playAddr,
			dataFileLen;
	gint		nsubTunes, startTune;
	t_xs_subtuneinfo	subTunes[XS_STIL_MAXENTRY];
} t_xs_tuneinfo;


struct t_xs_status;

typedef struct {
	gint		plrIdent;
	gboolean	(*plrIsOurFile)(gchar *);
	gboolean	(*plrInit)(struct t_xs_status *);
	void		(*plrClose)(struct t_xs_status *);
	gboolean	(*plrInitSong)(struct t_xs_status *);
	guint		(*plrFillBuffer)(struct t_xs_status *, gchar *, guint);
	gboolean	(*plrLoadSID)(struct t_xs_status *, gchar *);
	void		(*plrDeleteSID)(struct t_xs_status *);
	t_xs_tuneinfo*	(*plrGetSIDInfo)(gchar *);
} t_xs_player;


typedef struct t_xs_status {
	gint		audioFrequency,		/* Audio settings */
			audioFormat,
			audioChannels,
			audioBitsPerSample;
	void		*sidEngine;		/* SID-emulation internal engine data */
	t_xs_player	*sidPlayer;		/* Selected player engine */
	gboolean	isError, isPlaying;
	gint		currSong,		/* Current sub-tune */
			lastTime;
	t_xs_tuneinfo	*tuneInfo;
} t_xs_status;


/* Global variables
 */
extern InputPlugin	xs_plugin_ip;

extern t_xs_status	xs_status;
XS_MUTEX_H(xs_status);



/* Plugin function prototypes
 */
void	xs_init(void);
void	xs_reinit(void);
void	xs_close(void);
gint	xs_is_our_file(gchar *);
void	xs_play_file(gchar *);
void	xs_stop(void);
void	xs_pause(short);
void	xs_seek(gint);
gint	xs_get_time(void);
void	xs_get_song_info(gchar *, gchar **, gint *);
void	xs_fileinfo(gchar *);
void	xs_about(void);
void	xs_set_subtune(gint);

t_xs_tuneinfo *xs_tuneinfo_new(gchar *, gint, gint, gchar *, gchar *, gchar *, gint, gint, gint, gint);
void	xs_tuneinfo_free(t_xs_tuneinfo *);


/* Debugging and error handling macros
 */
#ifdef DEBUG
#define XSDEBUG(x...) { fprintf(stderr, "XS[%s:%s:%d]: ", __FILE__, __FUNCTION__, (int) __LINE__); fprintf(stderr, ## x); }
#else
#define XSDEBUG(x...) /* foo */
#endif

#define XSERR(x...) { fprintf(stderr, PACKAGE_NAME ": "); fprintf(stderr, ## x); }


#ifdef __cplusplus
}
#endif
#endif /* _XMMS_SID_H */