Mercurial > audlegacy-plugins
comparison src/sid/xs_title.c @ 12:3da1b8942b8b trunk
[svn] - remove src/Input src/Output src/Effect src/General src/Visualization src/Container
author | nenolod |
---|---|
date | Mon, 18 Sep 2006 03:14:20 -0700 |
parents | src/Input/sid/xs_title.c@088092a52fea |
children | 6c3c7b841382 |
comparison
equal
deleted
inserted
replaced
11:cff1d04026ae | 12:3da1b8942b8b |
---|---|
1 /* | |
2 XMMS-SID - SIDPlay input plugin for X MultiMedia System (XMMS) | |
3 | |
4 Titlestring handling | |
5 | |
6 Programmed and designed by Matti 'ccr' Hamalainen <ccr@tnsp.org> | |
7 (C) Copyright 1999-2005 Tecnic Software productions (TNSP) | |
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
22 */ | |
23 #include "xs_title.h" | |
24 #include "xs_support.h" | |
25 #include "xs_config.h" | |
26 #include "audacious/titlestring.h" | |
27 | |
28 | |
29 /* | |
30 * Create a title string based on given information and settings. | |
31 */ | |
32 #define VPUTCH(MCH) \ | |
33 if (iIndex < XS_BUF_SIZE) tmpBuf[iIndex++] = MCH; | |
34 #define VPUTSTR(MSTR) { \ | |
35 if (MSTR) { \ | |
36 if ((iIndex + strlen(MSTR) + 1) < XS_BUF_SIZE) { \ | |
37 strcpy(&tmpBuf[iIndex], MSTR); \ | |
38 iIndex += strlen(MSTR); \ | |
39 } else \ | |
40 iIndex = XS_BUF_SIZE; \ | |
41 } \ | |
42 } | |
43 | |
44 | |
45 gchar *xs_make_titlestring(gchar * pcFilename, gint iSubTune, gint nSubTunes, gint iSidModel, | |
46 const gchar * formatString, const gchar * infoString0, | |
47 const gchar * infoString1, const gchar * infoString2) | |
48 { | |
49 gchar *tmpFilename, *tmpFilePath, *tmpFileExt, *pcStr, *pcResult, tmpStr[XS_BUF_SIZE], tmpBuf[XS_BUF_SIZE]; | |
50 gint iIndex; | |
51 #ifdef HAVE_XMMSEXTRA | |
52 TitleInput *ptInput; | |
53 #endif | |
54 | |
55 /* Split the filename into path */ | |
56 tmpFilePath = g_strdup(pcFilename); | |
57 tmpFilename = xs_strrchr(tmpFilePath, '/'); | |
58 if (tmpFilename) | |
59 tmpFilename[1] = 0; | |
60 | |
61 /* Filename */ | |
62 tmpFilename = xs_strrchr(pcFilename, '/'); | |
63 if (tmpFilename) | |
64 tmpFilename = g_strdup(tmpFilename + 1); | |
65 else | |
66 tmpFilename = g_strdup(pcFilename); | |
67 | |
68 tmpFileExt = xs_strrchr(tmpFilename, '.'); | |
69 tmpFileExt[0] = 0; | |
70 | |
71 /* Extension */ | |
72 tmpFileExt = xs_strrchr(pcFilename, '.'); | |
73 | |
74 | |
75 #ifdef HAVE_XMMSEXTRA | |
76 /* Check if the titles are overridden or not */ | |
77 if (!xs_cfg.titleOverride) { | |
78 /* Use generic XMMS titles */ | |
79 /* XMMS_NEW_TITLEINPUT(ptInput); | |
80 * We duplicate and add typecast to the code here due to XMMS's braindead headers | |
81 */ | |
82 ptInput = (TitleInput *) g_malloc0(sizeof(TitleInput)); | |
83 ptInput->__size = XMMS_TITLEINPUT_SIZE; | |
84 ptInput->__version = XMMS_TITLEINPUT_VERSION; | |
85 | |
86 /* Create the input fields */ | |
87 ptInput->file_name = tmpFilename; | |
88 ptInput->file_ext = tmpFileExt; | |
89 ptInput->file_path = tmpFilePath; | |
90 | |
91 ptInput->track_name = g_strdup(infoString0); | |
92 ptInput->track_number = iSubTune; | |
93 ptInput->album_name = NULL; | |
94 ptInput->performer = g_strdup(infoString1); | |
95 ptInput->date = g_strdup((iSidModel == XS_SIDMODEL_6581) ? "SID6581" : "SID8580"); | |
96 | |
97 ptInput->year = 0; | |
98 ptInput->genre = g_strdup("SID-tune"); | |
99 ptInput->comment = g_strdup(infoString2); | |
100 | |
101 /* Create the string */ | |
102 pcResult = xmms_get_titlestring(xmms_get_gentitle_format(), ptInput); | |
103 | |
104 /* Dispose all allocated memory */ | |
105 g_free(ptInput->track_name); | |
106 g_free(ptInput->performer); | |
107 g_free(ptInput->comment); | |
108 g_free(ptInput->date); | |
109 g_free(ptInput->genre); | |
110 g_free(ptInput); | |
111 } else | |
112 #endif | |
113 { | |
114 /* Create the string */ | |
115 pcStr = xs_cfg.titleFormat; | |
116 iIndex = 0; | |
117 while (*pcStr && (iIndex < XS_BUF_SIZE)) { | |
118 if (*pcStr == '%') { | |
119 pcStr++; | |
120 switch (*pcStr) { | |
121 case '%': | |
122 VPUTCH('%'); | |
123 break; | |
124 case 'f': | |
125 VPUTSTR(tmpFilename); | |
126 break; | |
127 case 'F': | |
128 VPUTSTR(tmpFilePath); | |
129 break; | |
130 case 'e': | |
131 VPUTSTR(tmpFileExt); | |
132 break; | |
133 case 'p': | |
134 VPUTSTR(infoString1); | |
135 break; | |
136 case 't': | |
137 VPUTSTR(infoString0); | |
138 break; | |
139 case 'c': | |
140 VPUTSTR(infoString2); | |
141 break; | |
142 case 's': | |
143 VPUTSTR(formatString); | |
144 break; | |
145 case 'm': | |
146 switch (iSidModel) { | |
147 case XS_SIDMODEL_6581: | |
148 VPUTSTR("6581"); | |
149 break; | |
150 case XS_SIDMODEL_8580: | |
151 VPUTSTR("8580"); | |
152 break; | |
153 default: | |
154 VPUTSTR("Unknown"); | |
155 break; | |
156 } | |
157 break; | |
158 case 'n': | |
159 snprintf(tmpStr, XS_BUF_SIZE, "%i", iSubTune); | |
160 VPUTSTR(tmpStr); | |
161 break; | |
162 case 'N': | |
163 snprintf(tmpStr, XS_BUF_SIZE, "%i", nSubTunes); | |
164 VPUTSTR(tmpStr); | |
165 break; | |
166 } | |
167 } else { | |
168 VPUTCH(*pcStr); | |
169 } | |
170 pcStr++; | |
171 } | |
172 | |
173 tmpBuf[iIndex] = 0; | |
174 | |
175 /* Make resulting string */ | |
176 pcResult = g_strdup(tmpBuf); | |
177 } | |
178 | |
179 /* Free temporary strings */ | |
180 g_free(tmpFilename); | |
181 g_free(tmpFilePath); | |
182 | |
183 return pcResult; | |
184 } |