Mercurial > hg > xmms-sid
annotate src/xs_title.c @ 324:dd201740a720
Changed copyright text.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Tue, 11 Jan 2005 04:11:02 +0000 |
parents | 9b5704548219 |
children | b1a858b8cb1a |
rev | line source |
---|---|
217 | 1 /* |
2 XMMS-SID - SIDPlay input plugin for X MultiMedia System (XMMS) | |
3 | |
4 Titlestring handling | |
5 | |
324 | 6 Programmed and designed by Matti 'ccr' Hamalainen <ccr@tnsp.org> |
7 (C) Copyright 1999-2005 Tecnic Software productions (TNSP) | |
217 | 8 |
9 This program is free software; you can redistribute it and/or modify | |
10 it under the terms of the GNU General Public License as published by | |
11 the Free Software Foundation; either version 2 of the License, or | |
12 (at your option) any later version. | |
13 | |
14 This program is distributed in the hope that it will be useful, | |
15 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 GNU General Public License for more details. | |
18 | |
19 You should have received a copy of the GNU General Public License | |
20 along with this program; if not, write to the Free Software | |
21 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | |
22 */ | |
23 #include "xs_title.h" | |
24 #include "xs_support.h" | |
25 #include "xs_config.h" | |
26 #include <xmms/titlestring.h> | |
27 | |
28 | |
29 /* | |
30 * Create a title string based on given information and settings. | |
31 */ | |
32 #define VBUFSIZE (1024) | |
33 #define VPUTCH(MCH) \ | |
34 if (iIndex < VBUFSIZE) tmpBuf[iIndex++] = MCH; | |
35 #define VPUTSTR(MSTR) { \ | |
36 if (MSTR) { \ | |
37 if ((iIndex + strlen(MSTR) + 1) < VBUFSIZE) { \ | |
38 strcpy(&tmpBuf[iIndex], MSTR); \ | |
39 iIndex += strlen(MSTR); \ | |
40 } else \ | |
41 iIndex = VBUFSIZE; \ | |
42 } \ | |
43 } | |
44 | |
45 | |
46 gchar *xs_make_titlestring(gchar *pcFilename, | |
47 gint iSubTune, | |
48 gint iSidModel, | |
230 | 49 const gchar *formatString, const gchar *infoString0, |
50 const gchar *infoString1, const gchar *infoString2) | |
217 | 51 { |
52 gchar *tmpFilename, *tmpFilePath, *tmpFileExt, *pcStr, *pcResult, | |
53 tmpStr[VBUFSIZE], tmpBuf[VBUFSIZE]; | |
54 gint iIndex; | |
55 #ifdef HAVE_XMMSEXTRA | |
56 TitleInput *ptInput; | |
57 #endif | |
58 | |
59 /* Split the filename into path */ | |
60 tmpFilePath = g_strdup(pcFilename); | |
61 tmpFilename = xs_strrchr(tmpFilePath, '/'); | |
62 if (tmpFilename) | |
63 tmpFilename[1] = 0; | |
64 | |
65 /* Filename */ | |
66 tmpFilename = xs_strrchr(pcFilename, '/'); | |
67 if (tmpFilename) | |
68 tmpFilename = g_strdup(tmpFilename + 1); | |
69 else | |
70 tmpFilename = g_strdup(pcFilename); | |
71 | |
72 tmpFileExt = xs_strrchr(tmpFilename, '.'); | |
73 tmpFileExt[0] = 0; | |
74 | |
75 /* Extension */ | |
76 tmpFileExt = xs_strrchr(pcFilename, '.'); | |
77 | |
78 | |
79 #ifdef HAVE_XMMSEXTRA | |
80 /* Check if the titles are overridden or not */ | |
81 if (!xs_cfg.titleOverride) | |
82 { | |
83 /* Use generic XMMS titles */ | |
84 /* XMMS_NEW_TITLEINPUT(ptInput); | |
85 * We duplicate and add typecast to the code here due to XMMS's braindead headers | |
86 */ | |
87 ptInput = (TitleInput *) g_malloc0(sizeof(TitleInput)); | |
88 ptInput->__size = XMMS_TITLEINPUT_SIZE; | |
89 ptInput->__version = XMMS_TITLEINPUT_VERSION; | |
90 | |
91 /* Create the input fields */ | |
92 ptInput->file_name = tmpFilename; | |
93 ptInput->file_ext = tmpFileExt; | |
94 ptInput->file_path = tmpFilePath; | |
95 | |
233
9b5704548219
Compiler complains about discarding the const qualifier, so let's be dumb
Matti Hamalainen <ccr@tnsp.org>
parents:
230
diff
changeset
|
96 ptInput->track_name = g_strdup(infoString0); |
217 | 97 ptInput->track_number = iSubTune; |
98 ptInput->album_name = NULL; | |
233
9b5704548219
Compiler complains about discarding the const qualifier, so let's be dumb
Matti Hamalainen <ccr@tnsp.org>
parents:
230
diff
changeset
|
99 ptInput->performer = g_strdup(infoString1); |
217 | 100 ptInput->date = g_strdup((iSidModel == XS_SIDMODEL_6581) ? "SID6581" : "SID8580"); |
101 | |
102 ptInput->year = 0; | |
103 ptInput->genre = g_strdup("SID-tune"); | |
233
9b5704548219
Compiler complains about discarding the const qualifier, so let's be dumb
Matti Hamalainen <ccr@tnsp.org>
parents:
230
diff
changeset
|
104 ptInput->comment = g_strdup(infoString2); |
217 | 105 |
106 /* Create the string */ | |
107 pcResult = xmms_get_titlestring(xmms_get_gentitle_format(), ptInput); | |
108 | |
109 /* Dispose all allocated memory */ | |
233
9b5704548219
Compiler complains about discarding the const qualifier, so let's be dumb
Matti Hamalainen <ccr@tnsp.org>
parents:
230
diff
changeset
|
110 g_free(ptInput->track_name); |
9b5704548219
Compiler complains about discarding the const qualifier, so let's be dumb
Matti Hamalainen <ccr@tnsp.org>
parents:
230
diff
changeset
|
111 g_free(ptInput->performer); |
9b5704548219
Compiler complains about discarding the const qualifier, so let's be dumb
Matti Hamalainen <ccr@tnsp.org>
parents:
230
diff
changeset
|
112 g_free(ptInput->comment); |
217 | 113 g_free(ptInput->date); |
114 g_free(ptInput->genre); | |
115 g_free(ptInput); | |
116 } | |
117 else | |
118 #endif | |
119 { | |
120 /* Create the string */ | |
121 pcStr = xs_cfg.titleFormat; | |
122 iIndex = 0; | |
123 while (*pcStr && (iIndex < VBUFSIZE)) | |
124 { | |
125 if (*pcStr == '%') | |
126 { | |
127 pcStr++; | |
128 switch (*pcStr) { | |
129 case '%': VPUTCH('%'); break; | |
130 case 'f': VPUTSTR(tmpFilename); break; | |
131 case 'F': VPUTSTR(tmpFilePath); break; | |
132 case 'e': VPUTSTR(tmpFileExt); break; | |
133 case 'p': VPUTSTR(infoString1); break; | |
134 case 't': VPUTSTR(infoString0); break; | |
135 case 'c': VPUTSTR(infoString2); break; | |
136 case 's': VPUTSTR(formatString); break; | |
137 case 'm': | |
138 switch (iSidModel) { | |
139 case XS_SIDMODEL_6581: VPUTSTR("SID6581"); break; | |
140 case XS_SIDMODEL_8580: VPUTSTR("SID8580"); break; | |
141 default: VPUTSTR("Unknown SID"); break; | |
142 } | |
143 break; | |
144 case 'n': | |
145 snprintf(tmpStr, VBUFSIZE, "%i", iSubTune); | |
146 VPUTSTR(tmpStr); | |
147 break; | |
148 } | |
149 } else { | |
150 VPUTCH(*pcStr); | |
151 } | |
152 pcStr++; | |
153 } | |
154 | |
155 tmpBuf[iIndex] = 0; | |
156 | |
157 /* Make resulting string */ | |
158 pcResult = g_strdup(tmpBuf); | |
159 } | |
160 | |
161 /* Free temporary strings */ | |
162 g_free(tmpFilename); | |
163 g_free(tmpFilePath); | |
164 | |
165 return pcResult; | |
166 } |