217
|
1 /*
|
|
2 XMMS-SID - SIDPlay input plugin for X MultiMedia System (XMMS)
|
|
3
|
|
4 Titlestring handling
|
|
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 "xs_title.h"
|
|
23 #include "xs_support.h"
|
|
24 #include "xs_config.h"
|
|
25 #include <xmms/titlestring.h>
|
|
26
|
|
27
|
|
28 /*
|
|
29 * Create a title string based on given information and settings.
|
|
30 */
|
|
31 #define VBUFSIZE (1024)
|
|
32 #define VPUTCH(MCH) \
|
|
33 if (iIndex < VBUFSIZE) tmpBuf[iIndex++] = MCH;
|
|
34 #define VPUTSTR(MSTR) { \
|
|
35 if (MSTR) { \
|
|
36 if ((iIndex + strlen(MSTR) + 1) < VBUFSIZE) { \
|
|
37 strcpy(&tmpBuf[iIndex], MSTR); \
|
|
38 iIndex += strlen(MSTR); \
|
|
39 } else \
|
|
40 iIndex = VBUFSIZE; \
|
|
41 } \
|
|
42 }
|
|
43
|
|
44
|
|
45 gchar *xs_make_titlestring(gchar *pcFilename,
|
|
46 gint iSubTune,
|
|
47 gint iSidModel,
|
|
48 gchar *formatString, gchar *infoString0,
|
|
49 gchar *infoString1, gchar *infoString2)
|
|
50 {
|
|
51 gchar *tmpFilename, *tmpFilePath, *tmpFileExt, *pcStr, *pcResult,
|
|
52 tmpStr[VBUFSIZE], tmpBuf[VBUFSIZE];
|
|
53 gint iIndex;
|
|
54 #ifdef HAVE_XMMSEXTRA
|
|
55 TitleInput *ptInput;
|
|
56 #endif
|
|
57
|
|
58 /* Split the filename into path */
|
|
59 tmpFilePath = g_strdup(pcFilename);
|
|
60 tmpFilename = xs_strrchr(tmpFilePath, '/');
|
|
61 if (tmpFilename)
|
|
62 tmpFilename[1] = 0;
|
|
63
|
|
64 /* Filename */
|
|
65 tmpFilename = xs_strrchr(pcFilename, '/');
|
|
66 if (tmpFilename)
|
|
67 tmpFilename = g_strdup(tmpFilename + 1);
|
|
68 else
|
|
69 tmpFilename = g_strdup(pcFilename);
|
|
70
|
|
71 tmpFileExt = xs_strrchr(tmpFilename, '.');
|
|
72 tmpFileExt[0] = 0;
|
|
73
|
|
74 /* Extension */
|
|
75 tmpFileExt = xs_strrchr(pcFilename, '.');
|
|
76
|
|
77
|
|
78 #ifdef HAVE_XMMSEXTRA
|
|
79 /* Check if the titles are overridden or not */
|
|
80 if (!xs_cfg.titleOverride)
|
|
81 {
|
|
82 /* Use generic XMMS titles */
|
|
83 /* XMMS_NEW_TITLEINPUT(ptInput);
|
|
84 * We duplicate and add typecast to the code here due to XMMS's braindead headers
|
|
85 */
|
|
86 ptInput = (TitleInput *) g_malloc0(sizeof(TitleInput));
|
|
87 ptInput->__size = XMMS_TITLEINPUT_SIZE;
|
|
88 ptInput->__version = XMMS_TITLEINPUT_VERSION;
|
|
89
|
|
90 /* Create the input fields */
|
|
91 ptInput->file_name = tmpFilename;
|
|
92 ptInput->file_ext = tmpFileExt;
|
|
93 ptInput->file_path = tmpFilePath;
|
|
94
|
|
95 ptInput->track_name = infoString0;
|
|
96 ptInput->track_number = iSubTune;
|
|
97 ptInput->album_name = NULL;
|
|
98 ptInput->performer = infoString1;
|
|
99 ptInput->date = g_strdup((iSidModel == XS_SIDMODEL_6581) ? "SID6581" : "SID8580");
|
|
100
|
|
101 ptInput->year = 0;
|
|
102 ptInput->genre = g_strdup("SID-tune");
|
|
103 ptInput->comment = infoString2;
|
|
104
|
|
105 /* Create the string */
|
|
106 pcResult = xmms_get_titlestring(xmms_get_gentitle_format(), ptInput);
|
|
107
|
|
108 /* Dispose all allocated memory */
|
|
109 g_free(ptInput->date);
|
|
110 g_free(ptInput->genre);
|
|
111 g_free(ptInput);
|
|
112 }
|
|
113 else
|
|
114 #endif
|
|
115 {
|
|
116 /* Create the string */
|
|
117 pcStr = xs_cfg.titleFormat;
|
|
118 iIndex = 0;
|
|
119 while (*pcStr && (iIndex < VBUFSIZE))
|
|
120 {
|
|
121 if (*pcStr == '%')
|
|
122 {
|
|
123 pcStr++;
|
|
124 switch (*pcStr) {
|
|
125 case '%': VPUTCH('%'); break;
|
|
126 case 'f': VPUTSTR(tmpFilename); break;
|
|
127 case 'F': VPUTSTR(tmpFilePath); break;
|
|
128 case 'e': VPUTSTR(tmpFileExt); break;
|
|
129 case 'p': VPUTSTR(infoString1); break;
|
|
130 case 't': VPUTSTR(infoString0); break;
|
|
131 case 'c': VPUTSTR(infoString2); break;
|
|
132 case 's': VPUTSTR(formatString); break;
|
|
133 case 'm':
|
|
134 switch (iSidModel) {
|
|
135 case XS_SIDMODEL_6581: VPUTSTR("SID6581"); break;
|
|
136 case XS_SIDMODEL_8580: VPUTSTR("SID8580"); break;
|
|
137 default: VPUTSTR("Unknown SID"); break;
|
|
138 }
|
|
139 break;
|
|
140 case 'n':
|
|
141 snprintf(tmpStr, VBUFSIZE, "%i", iSubTune);
|
|
142 VPUTSTR(tmpStr);
|
|
143 break;
|
|
144 }
|
|
145 } else {
|
|
146 VPUTCH(*pcStr);
|
|
147 }
|
|
148 pcStr++;
|
|
149 }
|
|
150
|
|
151 tmpBuf[iIndex] = 0;
|
|
152
|
|
153 /* Make resulting string */
|
|
154 pcResult = g_strdup(tmpBuf);
|
|
155 }
|
|
156
|
|
157 /* Free temporary strings */
|
|
158 g_free(tmpFilename);
|
|
159 g_free(tmpFilePath);
|
|
160
|
|
161 return pcResult;
|
|
162 }
|