view src/xs_title.cc @ 24:271be59be975

Lots of changes
author Matti Hamalainen <ccr@tnsp.org>
date Sat, 07 Jun 2003 12:42:05 +0000
parents d5789951b7e2
children
line wrap: on
line source

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

   Song title parsing
   
   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.
*/
#include "xmms-sid.h"
#include "xs_config.h"
#include "xs_support.h"
#include <stdlib.h>
#include <string.h>
#include <xmms/titlestring.h>

#include <sidplay/player.h>
#include <sidplay/myendian.h>
#include <sidplay/fformat.h>


/*
 * Create the SID-tune description string from the tune's information
 * formatted by the user-specified format-string.
 */
gchar *xs_filetitle_get(gchar *pcFilename, void *pfInfo, gint iSubTune)
{
	gint i, j, iLength;
	gchar *pcResult;
	struct sidTuneInfo *finfo = (struct sidTuneInfo *) pfInfo;
#ifdef HAVE_XMMSEXTRA
	TitleInput *ptInput;
#endif

	// FIXME FIXME: get STIL-info
	

#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 = pcFilename;
		ptInput->file_ext = pcFilename;
		ptInput->file_path = pcFilename;

		ptInput->track_name = finfo->nameString;
		ptInput->track_number = iSubTune;
		ptInput->album_name = NULL;
		ptInput->performer = finfo->authorString;
		ptInput->date = NULL;
		ptInput->year = 0;
		xs_strcalloc(&ptInput->genre, "SID-tune");
		ptInput->comment = finfo->copyrightString;
		pcResult = xmms_get_titlestring(xmms_get_gentitle_format(), ptInput);

		/* Dispose all allocated memory */
		g_free(ptInput->genre);
		g_free(ptInput);		/* was allocated by XMMS_NEW_TITLEINPUT */
	} else {
#endif
		/* Check the info strings */
		if (finfo->numberOfInfoStrings != 3) {

			if (finfo->numberOfInfoStrings < 1)
				return 0;

			return g_strdup(finfo->infoString[0]);
			}

		/* Check the format-string for NULL */
		if (xs_cfg.titleFormat == NULL)
			return g_strdup_printf("%s - %s", finfo->nameString, finfo->authorString);

		/* Calculate the length */
		iLength = 2;

		for (i = 0; i < strlen(xs_cfg.titleFormat); i++) {

			if (xs_cfg.titleFormat[i] == '%') {
				switch (xs_cfg.titleFormat[++i]) {

				case '1': iLength += strlen(finfo->authorString); break;
				case '2': iLength += strlen(finfo->nameString); break;
				case '3': iLength += strlen(finfo->copyrightString); break;
				case '4': iLength += strlen(finfo->formatString); break;

				} /* case */

			} else
				iLength++;

		}		/* for */


		/* Allocate the result-string */
		pcResult = (gchar *) g_malloc(iLength);

		/* Construct the final result info */
		j = 0;
		for (i = 0; i < strlen(xs_cfg.titleFormat); i++) {

			if (xs_cfg.titleFormat[i] == '%') {
				switch (xs_cfg.titleFormat[++i]) {

				case '1':
					xs_strcpy(&pcResult, &j, finfo->authorString);
					break;

				case '2':
					xs_strcpy(&pcResult, &j, finfo->nameString);
					break;

				case '3':
					xs_strcpy(&pcResult, &j, finfo->copyrightString);
					break;

				case '4':
					xs_strcpy(&pcResult, &j, finfo->formatString);
					break;

				} /* case */

			} else {
				pcResult[j++] = xs_cfg.titleFormat[i];
			}	/* if */

		}		/* for */

		pcResult[j] = '\0';
#ifdef HAVE_XMMSEXTRA
	}
#endif

	return pcResult;
}