changeset 109:578b71b62eeb

Fileinfo now basically working, STIL COMMENT-fields are not yet parsed or shown. Some bugs probably remain.
author Matti Hamalainen <ccr@tnsp.org>
date Mon, 12 Jan 2004 01:45:04 +0000
parents b02ec9a84075
children 582d32db824b
files src/xmms-sid.c src/xs_config.c src/xs_config.h src/xs_genui.c src/xs_genui.h src/xs_stil.c src/xs_stil.h src/xs_support.c src/xs_support.h
diffstat 9 files changed, 255 insertions(+), 115 deletions(-) [+]
line wrap: on
line diff
--- a/src/xmms-sid.c	Mon Jan 12 00:58:01 2004 +0000
+++ b/src/xmms-sid.c	Mon Jan 12 01:45:04 2004 +0000
@@ -106,7 +106,6 @@
 /*
  * Global variables
  */
-static GtkWidget		*xs_fileinfowin = NULL;
 static pthread_t		xs_decode_thread;
 static pthread_mutex_t		xs_mutex	= PTHREAD_MUTEX_INITIALIZER;
 struct t_xs_cfg			xs_cfg;
@@ -618,6 +617,9 @@
 /*
  * File-information window
  */
+static GtkWidget		*xs_fileinfowin = NULL;
+static t_xs_tune		*xs_fileinfotune = NULL;
+static t_xs_stil_node		*xs_fileinfostil = NULL;
 #define LUW(x...)	lookup_widget(xs_fileinfowin, ## x)
 
 
@@ -630,27 +632,32 @@
 
 void xs_fileinfo_subtune(GtkWidget *widget, void *data)
 {
-#if 0
- T_sid_stil_subtune *a_tune;
- GtkWidget *a_item;
- gint a_index;
+ t_xs_stil_subnode *tmpNode;
+ GtkWidget *tmpItem;
+ gint tmpIndex;
 
- 
+ if (!xs_fileinfostil) return;
+
  /* Get number of subtune */
- a_item  = gtk_menu_get_active(GTK_MENU(fileinfo_sub_tune_menu));
- a_index = g_list_index(GTK_MENU_SHELL(fileinfo_sub_tune_menu)->children, a_item);
-
- a_tune = &xs_stil_info.subtune[a_index];
-
+ tmpItem  = gtk_menu_get_active(GTK_MENU(data));
+ tmpIndex = g_list_index(GTK_MENU_SHELL(data)->children, tmpItem);
+ tmpNode = &xs_fileinfostil->subTune[tmpIndex];
 
  /* Get and set subtune information */
- if (a_tune->artist != NULL)
-	gtk_entry_set_text (GTK_ENTRY (fileinfo_sub_artist), a_tune->artist);
+ if (tmpNode->pArtist)
+	gtk_entry_set_text(GTK_ENTRY(LUW("fileinfo_sub_artist")), tmpNode->pArtist);
+
+ if (tmpNode->pTitle)
+	gtk_entry_set_text(GTK_ENTRY(LUW("fileinfo_sub_title")), tmpNode->pTitle);
 
- if (a_tune->title != NULL)
-	gtk_entry_set_text (GTK_ENTRY (fileinfo_sub_title), a_tune->title);
+#if 0
+XSDEBUG("%i: '%s', '%s', '%s', '%s'\n", tmpIndex,
+	tmpNode->pName,
+	tmpNode->pTitle,
+	tmpNode->pArtist,
+	tmpNode->pAuthor);
 
- if (a_tune->comment != NULL)
+ if (tmpNode->pComment)
 	{
 	/* Freeze the widget for update */
 	gtk_text_freeze(GTK_TEXT(fileinfo_sub_comment));
@@ -668,18 +675,23 @@
 	gtk_text_thaw(GTK_TEXT(fileinfo_sub_comment));
 	}
 #endif
+
+ gtk_widget_show(xs_fileinfowin);
 }
 
 
 void xs_fileinfo(gchar *pcFilename)
 {
- t_xs_tune *pInfo;
  GtkWidget *tmpMenuItem, *tmpMenu, *tmpOptionMenu;
- gchar tmpStr[32];
+ t_xs_stil_subnode *tmpNode;
+ gchar tmpStr[32], *tmpS;
  gint n;
+
+ /* Free old info, if set */
+ if (xs_fileinfotune) xs_tune_free(xs_fileinfotune);
  
- /* Get tune information */
- if ((pInfo = xs_player->plrGetSIDInfo(pcFilename)) == NULL)
+ /* Get new tune information */
+ if ((xs_fileinfotune = xs_player->plrGetSIDInfo(pcFilename)) == NULL)
  	{
  	if (xs_fileinfowin)
  		{
@@ -689,6 +701,12 @@
  	return;
  	}
 
+ if (xs_cfg.stilDBEnable)
+	xs_fileinfostil = xs_stil_get(pcFilename);
+	else
+	xs_fileinfostil = NULL;
+ 
+
  /* Check if there already is an open fileinfo window */
  if (xs_fileinfowin)
 	{
@@ -701,9 +719,9 @@
 
  /* Set the song informations */
  gtk_entry_set_text(GTK_ENTRY(LUW("fileinfo_filename")), pcFilename);
- gtk_entry_set_text(GTK_ENTRY(LUW("fileinfo_songname")), pInfo->tuneName);
- gtk_entry_set_text(GTK_ENTRY(LUW("fileinfo_composer")), pInfo->tuneComposer);
- gtk_entry_set_text(GTK_ENTRY(LUW("fileinfo_copyright")), pInfo->tuneCopyright);
+ gtk_entry_set_text(GTK_ENTRY(LUW("fileinfo_songname")), xs_fileinfotune->tuneName);
+ gtk_entry_set_text(GTK_ENTRY(LUW("fileinfo_composer")), xs_fileinfotune->tuneComposer);
+ gtk_entry_set_text(GTK_ENTRY(LUW("fileinfo_copyright")), xs_fileinfotune->tuneCopyright);
 
 
  /* Main tune - the pseudo tune */
@@ -717,11 +735,24 @@
 		GTK_SIGNAL_FUNC (xs_fileinfo_subtune), tmpMenu);
 
  /* Other menu items */
- for (n = 1; n <= pInfo->nsubTunes; n++)
+ for (n = 1; n <= xs_fileinfotune->nsubTunes; n++)
 	{
-	snprintf(tmpStr, sizeof(tmpStr), "Tune #%i", n);
+	if (xs_fileinfostil)
+		{
+		tmpNode = &xs_fileinfostil->subTune[n];
+		if (tmpNode->pName)
+			tmpS = tmpNode->pName;
+			else
+		if (tmpNode->pTitle)
+			tmpS = tmpNode->pTitle;
+			else
+			tmpS = "-";
+		
+		snprintf(tmpStr, sizeof(tmpStr), "#%i: %s", n, tmpS);
+		} else
+		snprintf(tmpStr, sizeof(tmpStr), "Tune #%i", n);
 
-	tmpMenuItem = gtk_menu_item_new_with_label (tmpStr);
+	tmpMenuItem = gtk_menu_item_new_with_label(tmpStr);
 	gtk_widget_show (tmpMenuItem);
 	gtk_menu_append (GTK_MENU(tmpMenu), tmpMenuItem);
 
--- a/src/xs_config.c	Mon Jan 12 00:58:01 2004 +0000
+++ b/src/xs_config.c	Mon Jan 12 01:45:04 2004 +0000
@@ -68,6 +68,7 @@
 
 	{CTYPE_BOOL,	&xs_cfg.stilDBEnable,		"stilDBEnable"},
 	{CTYPE_STR,	&xs_cfg.stilDBPath,		"stilDBPath"},
+	{CTYPE_STR,	&xs_cfg.hvscPath,		"hvscPath"},
 
 	{CTYPE_INT,	&xs_cfg.subsongControl,		"subsongControl"},
 	{CTYPE_BOOL,	&xs_cfg.detectMagic,		"detectMagic"},
@@ -123,6 +124,7 @@
 
 { WTYPE_BUTTON,	CTYPE_BOOL,	"cfg_stil_enable",	&xs_cfg.stilDBEnable,		0 },
 { WTYPE_TEXT,	CTYPE_STR,	"cfg_stil_dbpath",	&xs_cfg.stilDBPath,		0 },
+{ WTYPE_TEXT,	CTYPE_STR,	"cfg_hvsc_path",	&xs_cfg.hvscPath,		0 },
 
 { WTYPE_BGROUP,	CTYPE_INT,	"cfg_subsong_none",	&xs_cfg.subsongControl,		XS_SSC_NONE },
 { WTYPE_BGROUP,	CTYPE_INT,	"cfg_subsong_popup",	&xs_cfg.subsongControl,		XS_SSC_POPUP },
@@ -215,6 +217,7 @@
 
  xs_cfg.stilDBEnable		= FALSE;
  xs_strcalloc(&xs_cfg.stilDBPath, "~/C64Music/DOCUMENTS/STIL.txt");
+ xs_strcalloc(&xs_cfg.hvscPath, "~/C64Music");
 
 #ifdef HAVE_SONG_POSITION
  xs_cfg.subsongControl		= XS_SSC_PATCH;
--- a/src/xs_config.h	Mon Jan 12 00:58:01 2004 +0000
+++ b/src/xs_config.h	Mon Jan 12 01:45:04 2004 +0000
@@ -99,6 +99,7 @@
 	/* Miscellaneous settings */
 	gboolean	stilDBEnable;
 	gchar		*stilDBPath;		/* Path to STIL.txt */
+	gchar		*hvscPath;		/* Path-prefix for HVSC */
 
 	gint		subsongControl;
 	gboolean	detectMagic;
--- a/src/xs_genui.c	Mon Jan 12 00:58:01 2004 +0000
+++ b/src/xs_genui.c	Mon Jan 12 01:45:04 2004 +0000
@@ -9,3 +9,11 @@
 #include "xs_glade.h"
 
 
+
+void
+xs_cfg_hvsc_browse                     (GtkButton       *button,
+                                        gpointer         user_data)
+{
+
+}
+
--- a/src/xs_genui.h	Mon Jan 12 00:58:01 2004 +0000
+++ b/src/xs_genui.h	Mon Jan 12 01:45:04 2004 +0000
@@ -64,3 +64,7 @@
 void
 xs_cfg_stil_fs_cancel                  (GtkButton       *button,
                                         gpointer         user_data);
+
+void
+xs_cfg_hvsc_browse                     (GtkButton       *button,
+                                        gpointer         user_data);
--- a/src/xs_stil.c	Mon Jan 12 00:58:01 2004 +0000
+++ b/src/xs_stil.c	Mon Jan 12 01:45:04 2004 +0000
@@ -57,11 +57,12 @@
  
  if (pNode)
  	{
- 	for (i = 0; i < pNode->nsubTunes; i++)
+ 	for (i = 0; i < XS_STIL_MAXENTRY; i++)
  		{
  		g_free(pNode->subTune[i].pName);
  		g_free(pNode->subTune[i].pTitle);
  		g_free(pNode->subTune[i].pArtist);
+ 		g_free(pNode->subTune[i].pAuthor);
  		g_free(pNode->subTune[i].pComment);
  		}
  	
@@ -96,72 +97,6 @@
 
 
 /*
- * Get STIL information from database
- */
-t_xs_stil_node * xs_stildb_get(gchar *pcFilename)
-{
- gint iStartNode, iEndNode, iQNode, r, i;
- gboolean iFound;
- t_xs_stil_node *pResult;
-
- /* Check the database pointers */
- if (!xs_stildb || !xs_stildbi)
- 	return NULL;
- 	
- /* Look-up via index using binary search */
- pResult = NULL;
- iStartNode = 0;
- iEndNode = (xs_stildbn - 1);
- iQNode = (iEndNode / 2);
- iFound = FALSE;
-
- while ((!iFound) && ((iEndNode - iStartNode) > 128))
- 	{
- 	r = strcmp(pcFilename, xs_stildbi[iQNode]->pcFilename);
- 	if (r < 0)
- 		{
- 		/* Hash was in the <- LEFT side */
- 		iEndNode = iQNode;
- 		iQNode = iStartNode + ((iEndNode - iStartNode) / 2);
- 		} else
- 	if (r > 0)
- 		{
- 		/* Hash was in the RIGHT -> side */
- 		iStartNode = iQNode;
- 		iQNode = iStartNode + ((iEndNode - iStartNode) / 2);
- 		} else
- 		iFound = TRUE;
- 	}
-
- /* If not found already */
- if (!iFound)
- 	{
-	/* Search the are linearly */
-	iFound = FALSE;
-	i = iStartNode;
-	while ((i <= iEndNode) && (!iFound))
-		{
-		if (strcmp(pcFilename, xs_stildbi[iQNode]->pcFilename) == 0)
-			iFound = TRUE;
-			else
-			i++;
-		}
-	
-	/* Check the result */
-	if (iFound)
-		pResult = xs_stildbi[i];
-
- 	} else {
-	/* Found via binary search */
- 	pResult = xs_stildbi[iQNode];
-	}
-
-
- return pResult;
-}
-
-
-/*
  * Read database to memory
  */
 gint xs_stildb_read(gchar *dbFilename)
@@ -169,8 +104,10 @@
  FILE *inFile;
  gchar inLine[XS_BUFSIZE];
  guint lineNum, linePos;
- gboolean iOK;
  t_xs_stil_node *tmpNode;
+ t_xs_stil_subnode *qNode;
+ gboolean isError;
+ gint subEntry, i;
  
  /* Try to open the file */
  if ((inFile = fopen(dbFilename, "ra")) == NULL)
@@ -181,34 +118,117 @@
  
  /* Read and parse the data */
  lineNum = 0;
-
- while (!feof(inFile))
+ isError = FALSE;
+ tmpNode = NULL;
+  
+ while (!feof(inFile) && !isError)
  {
  fgets(inLine, sizeof(inLine), inFile);
+ linePos = 0;
+ xs_findeol(inLine, &linePos);
+ inLine[linePos] = 0;
+ linePos = 0;
  lineNum++;
 
-#if 0
  switch (inLine[0]) {
  case '/':
- 	/* A new entry */
- 	
- 	isEntry = TRUE;
+ 	/* Check if we are already parsing entry */
+ 	if (tmpNode)
+ 		{
+ 		XSERR("New entry ('%s') before end of current ('%s')! Possibly malformed STIL-file!\n",
+ 			inLine, tmpNode->pcFilename);
+
+ 		xs_stildb_node_free(tmpNode);
+ 		}
+ 
+ 	/* A new node */
+ 	tmpNode = xs_stildb_node_new();
+ 	if (tmpNode)
+ 		{
+ 		/* Initialize the node */
+ 		tmpNode->pcFilename = g_strdup(inLine);
+	 	subEntry = 0;
+	 	} else
+ 		{
+ 		/* Allocation failed */
+ 		XSERR("Could not allocate new STILdb-node for '%s'!\n", inLine);
+ 		isError = TRUE;
+ 		}
 	break;
 
  case '(':
- 	subEntry = 
+ 	/* A new sub-entry */
+ 	linePos++;
+ 	if (inLine[linePos] == '#')
+ 		{
+ 		linePos++;
+ 		if (inLine[linePos])
+ 			{
+		 	xs_findnum(inLine, &linePos);
+		 	inLine[linePos] = 0;
+	 		subEntry = atol(&inLine[2]);
+
+		 	/* Sanity check */
+		 	if ((subEntry < 1) || (subEntry >= XS_STIL_MAXENTRY))
+ 				{
+ 				XSERR("Number of subEntry (%i) for '%s' is invalid\n", subEntry, tmpNode->pcFilename);
+ 				subEntry = 0;
+ 				}
+	 		}
+	 	}
+ 	
+ 	break;
+
+ case 0:
+ case '#':
+ case '\n':
+ case '\r':
+ 	/* End of entry/field */
+ 	if (tmpNode)
+ 		{
+ 		/* Insert to database */
+ 		xs_stildb_node_insert(tmpNode);
+		tmpNode = NULL;
+		}
  	break;
  
  default:
- 	/* End of entry */
- 	isEntry = FALSE;
+ 	/* Some other type */
+ 	if (strncmp(inLine, "  TITLE:", 8) == 0)
+ 		{
+ 		g_free(tmpNode->subTune[subEntry].pTitle);
+ 		tmpNode->subTune[subEntry].pTitle = g_strdup(&inLine[9]);
+ 		} else
+ 	if (strncmp(inLine, " ARTIST:", 8) == 0)
+ 		{
+ 		g_free(tmpNode->subTune[subEntry].pArtist);
+ 		tmpNode->subTune[subEntry].pArtist = g_strdup(&inLine[9]);
+ 		} else
+ 	if (strncmp(inLine, "   NAME:", 8) == 0)
+ 		{
+ 		g_free(tmpNode->subTune[subEntry].pName);
+ 		tmpNode->subTune[subEntry].pName = g_strdup(&inLine[9]);
+ 		} else
+ 	if (strncmp(inLine, " AUTHOR:", 8) == 0)
+ 		{
+ 		g_free(tmpNode->subTune[subEntry].pAuthor);
+ 		tmpNode->subTune[subEntry].pAuthor = g_strdup(&inLine[9]);
+ 		} else
+ 	if (strncmp(inLine, "COMMENT:", 8) == 0)
+ 		{
+ 		} else
+ 	if (strncmp(inLine, "        ", 8) == 0)
+ 		{
+ 		}
  	break;
- 
  }
-#endif
  
  } /* while */
 
+ /* Check if there is one remaining node */
+ if (tmpNode)
+	xs_stildb_node_free(tmpNode);
+
  /* Close the file */  
  fclose(inFile);
  return 0;
@@ -309,11 +329,79 @@
 
 
 /*
- * Get STIL information
+ * Get STIL information from database
  */
 t_xs_stil_node * xs_stil_get(gchar *pcFilename)
 {
+ gint iStartNode, iEndNode, iQNode, r, i;
+ gchar *tmpFilename;
+ gboolean iFound;
  t_xs_stil_node *pResult;
 
+ /* Check the database pointers */
+ if (!xs_stildb || !xs_stildbi || !xs_cfg.stilDBEnable || !xs_cfg.hvscPath)
+ 	return NULL;
+ 
+ /* Remove HVSC location-prefix from filename */
+ tmpFilename = strstr(pcFilename, xs_cfg.hvscPath);
+ if (tmpFilename)
+ 	{
+	tmpFilename += strlen(xs_cfg.hvscPath);
+	} else
+	tmpFilename = pcFilename; 
+
+ XSDEBUG("'%s', '%s' -> '%s'\n", pcFilename, xs_cfg.hvscPath, tmpFilename);
+ 	
+ /* Look-up via index using binary search */
+ pResult = NULL;
+ iStartNode = 0;
+ iEndNode = (xs_stildbn - 1);
+ iQNode = (iEndNode / 2);
+ iFound = FALSE;
+
+ while ((!iFound) && ((iEndNode - iStartNode) > 128))
+ 	{
+ 	r = strcmp(tmpFilename, xs_stildbi[iQNode]->pcFilename);
+ 	if (r < 0)
+ 		{
+ 		/* Hash was in the <- LEFT side */
+ 		iEndNode = iQNode;
+ 		iQNode = iStartNode + ((iEndNode - iStartNode) / 2);
+ 		} else
+ 	if (r > 0)
+ 		{
+ 		/* Hash was in the RIGHT -> side */
+ 		iStartNode = iQNode;
+ 		iQNode = iStartNode + ((iEndNode - iStartNode) / 2);
+ 		} else
+ 		iFound = TRUE;
+ 	}
+
+ /* If not found already */
+ if (!iFound)
+ 	{
+	/* Search the are linearly */
+	iFound = FALSE;
+	i = iStartNode;
+	while ((i <= iEndNode) && (!iFound))
+		{
+		if (strcmp(tmpFilename, xs_stildbi[i]->pcFilename) == 0)
+			iFound = TRUE;
+			else
+			i++;
+		}
+	
+	/* Check the result */
+	if (iFound)
+		pResult = xs_stildbi[i];
+
+ 	} else {
+	/* Found via binary search */
+ 	pResult = xs_stildbi[iQNode];
+	}
+
+XSDEBUG("found: %p\n", pResult);
+
  return pResult;
 }
+
--- a/src/xs_stil.h	Mon Jan 12 00:58:01 2004 +0000
+++ b/src/xs_stil.h	Mon Jan 12 01:45:04 2004 +0000
@@ -14,12 +14,12 @@
 	gchar	*pName,
 		*pTitle,
 		*pArtist,
+		*pAuthor,
 		*pComment;
 } t_xs_stil_subnode;
 
 typedef struct _t_xs_stil_node {
 	gchar			*pcFilename;
-	gint			nsubTunes;
 	t_xs_stil_subnode	subTune[XS_STIL_MAXENTRY];
 	struct _t_xs_stil_node	*pPrev, *pNext;
 } t_xs_stil_node;
--- a/src/xs_support.c	Mon Jan 12 00:58:01 2004 +0000
+++ b/src/xs_support.c	Mon Jan 12 01:45:04 2004 +0000
@@ -74,17 +74,21 @@
 }
 
 
-inline void xs_findnext(gchar *pcStr, gint *piPos)
+inline void xs_findnext(gchar *pcStr, guint *piPos)
 {
- /* Terminating NULL-character is not whitespace! */
- while (isspace(pcStr[*piPos])) (*piPos)++;
+ while (pcStr[*piPos] && isspace(pcStr[*piPos])) (*piPos)++;
 }
 
 
-inline void xs_findnum(gchar *pcStr, gint *piPos)
+inline void xs_findeol(gchar *pcStr, guint *piPos)
 {
- /* Terminating NULL-character is not digit! */
- while (isdigit(pcStr[*piPos])) (*piPos)++;
+ while (pcStr[*piPos] && (pcStr[*piPos] != '\n') && (pcStr[*piPos] != '\r')) (*piPos)++;
 }
 
 
+inline void xs_findnum(gchar *pcStr, guint *piPos)
+{
+ while (pcStr[*piPos] && isdigit(pcStr[*piPos])) (*piPos)++;
+}
+
+
--- a/src/xs_support.h	Mon Jan 12 00:58:01 2004 +0000
+++ b/src/xs_support.h	Mon Jan 12 01:45:04 2004 +0000
@@ -13,8 +13,9 @@
 gint	xs_strcalloc(gchar **, const gchar *);
 gint	xs_strcat(gchar **, const gchar *);
 gchar	*xs_strrchr(gchar *, gchar);
-inline 	void xs_findnext(gchar *, gint *);
-inline	void xs_findnum(gchar *, gint *);
+inline 	void xs_findnext(gchar *, guint *);
+inline 	void xs_findeol(gchar *, guint *);
+inline	void xs_findnum(gchar *, guint *);
 
 #ifdef __cplusplus
 }