21
|
1 /*
|
|
2 xmms-sid - SIDPlay input plugin for X MultiMedia System (XMMS)
|
|
3
|
|
4 Song title parsing
|
|
5
|
|
6 Written by Matti "ccr" Hamalainen <ccr@tnsp.org>
|
|
7
|
|
8 This program is free software; you can redistribute it and/or modify
|
|
9 it under the terms of the GNU General Public License as published by
|
|
10 the Free Software Foundation; either version 2 of the License, or
|
|
11 (at your option) any later version.
|
|
12
|
|
13 This program is distributed in the hope that it will be useful,
|
|
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
16 GNU General Public License for more details.
|
|
17
|
|
18 You should have received a copy of the GNU General Public License
|
|
19 along with this program; if not, write to the Free Software
|
|
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
21 */
|
|
22 #include "xmms-sid.h"
|
24
|
23 #include "xs_config.h"
|
|
24 #include "xs_support.h"
|
21
|
25 #include <stdlib.h>
|
|
26 #include <string.h>
|
|
27 #include <xmms/titlestring.h>
|
|
28
|
|
29 #include <sidplay/player.h>
|
|
30 #include <sidplay/myendian.h>
|
|
31 #include <sidplay/fformat.h>
|
|
32
|
|
33
|
|
34 /*
|
24
|
35 * Create the SID-tune description string from the tune's information
|
|
36 * formatted by the user-specified format-string.
|
21
|
37 */
|
|
38 gchar *xs_filetitle_get(gchar *pcFilename, void *pfInfo, gint iSubTune)
|
|
39 {
|
|
40 gint i, j, iLength;
|
|
41 gchar *pcResult;
|
|
42 struct sidTuneInfo *finfo = (struct sidTuneInfo *) pfInfo;
|
|
43 #ifdef HAVE_XMMSEXTRA
|
|
44 TitleInput *ptInput;
|
|
45 #endif
|
|
46
|
|
47 // FIXME FIXME: get STIL-info
|
|
48
|
|
49
|
|
50 #ifdef HAVE_XMMSEXTRA
|
|
51 /* Check if the titles are overridden or not */
|
|
52 if (!xs_cfg.titleOverride) {
|
|
53 /* Use generic XMMS titles */
|
|
54
|
|
55 // XMMS_NEW_TITLEINPUT(ptInput);
|
|
56 // we duplicate and add typecast to the code here due to XMMS's braindead headers
|
|
57
|
|
58 ptInput = (TitleInput *) g_malloc0(sizeof(TitleInput));
|
|
59 ptInput->__size = XMMS_TITLEINPUT_SIZE;
|
|
60 ptInput->__version = XMMS_TITLEINPUT_VERSION;
|
|
61
|
|
62
|
|
63 /* Create the input fields */
|
|
64 ptInput->file_name = pcFilename;
|
|
65 ptInput->file_ext = pcFilename;
|
|
66 ptInput->file_path = pcFilename;
|
|
67
|
|
68 ptInput->track_name = finfo->nameString;
|
|
69 ptInput->track_number = iSubTune;
|
|
70 ptInput->album_name = NULL;
|
|
71 ptInput->performer = finfo->authorString;
|
|
72 ptInput->date = NULL;
|
|
73 ptInput->year = 0;
|
|
74 xs_strcalloc(&ptInput->genre, "SID-tune");
|
|
75 ptInput->comment = finfo->copyrightString;
|
|
76 pcResult = xmms_get_titlestring(xmms_get_gentitle_format(), ptInput);
|
|
77
|
|
78 /* Dispose all allocated memory */
|
|
79 g_free(ptInput->genre);
|
|
80 g_free(ptInput); /* was allocated by XMMS_NEW_TITLEINPUT */
|
|
81 } else {
|
|
82 #endif
|
|
83 /* Check the info strings */
|
|
84 if (finfo->numberOfInfoStrings != 3) {
|
|
85
|
|
86 if (finfo->numberOfInfoStrings < 1)
|
|
87 return 0;
|
|
88
|
|
89 return g_strdup(finfo->infoString[0]);
|
|
90 }
|
|
91
|
|
92 /* Check the format-string for NULL */
|
|
93 if (xs_cfg.titleFormat == NULL)
|
|
94 return g_strdup_printf("%s - %s", finfo->nameString, finfo->authorString);
|
|
95
|
|
96 /* Calculate the length */
|
|
97 iLength = 2;
|
|
98
|
|
99 for (i = 0; i < strlen(xs_cfg.titleFormat); i++) {
|
|
100
|
|
101 if (xs_cfg.titleFormat[i] == '%') {
|
|
102 switch (xs_cfg.titleFormat[++i]) {
|
|
103
|
|
104 case '1': iLength += strlen(finfo->authorString); break;
|
|
105 case '2': iLength += strlen(finfo->nameString); break;
|
|
106 case '3': iLength += strlen(finfo->copyrightString); break;
|
|
107 case '4': iLength += strlen(finfo->formatString); break;
|
|
108
|
|
109 } /* case */
|
|
110
|
|
111 } else
|
|
112 iLength++;
|
|
113
|
|
114 } /* for */
|
|
115
|
|
116
|
|
117 /* Allocate the result-string */
|
|
118 pcResult = (gchar *) g_malloc(iLength);
|
|
119
|
|
120 /* Construct the final result info */
|
|
121 j = 0;
|
|
122 for (i = 0; i < strlen(xs_cfg.titleFormat); i++) {
|
|
123
|
|
124 if (xs_cfg.titleFormat[i] == '%') {
|
|
125 switch (xs_cfg.titleFormat[++i]) {
|
|
126
|
|
127 case '1':
|
|
128 xs_strcpy(&pcResult, &j, finfo->authorString);
|
|
129 break;
|
|
130
|
|
131 case '2':
|
|
132 xs_strcpy(&pcResult, &j, finfo->nameString);
|
|
133 break;
|
|
134
|
|
135 case '3':
|
|
136 xs_strcpy(&pcResult, &j, finfo->copyrightString);
|
|
137 break;
|
|
138
|
|
139 case '4':
|
|
140 xs_strcpy(&pcResult, &j, finfo->formatString);
|
|
141 break;
|
|
142
|
|
143 } /* case */
|
|
144
|
|
145 } else {
|
|
146 pcResult[j++] = xs_cfg.titleFormat[i];
|
|
147 } /* if */
|
|
148
|
|
149 } /* for */
|
|
150
|
|
151 pcResult[j] = '\0';
|
|
152 #ifdef HAVE_XMMSEXTRA
|
|
153 }
|
|
154 #endif
|
|
155
|
|
156 return pcResult;
|
|
157 }
|
|
158
|