Mercurial > hg > xmms-sid
annotate src/xs_sidplay.h @ 87:94497283affa
Various fixes and improvements
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Sun, 05 Oct 2003 10:38:03 +0000 |
parents | 741291e14080 |
children | 2607683bc9eb |
rev | line source |
---|---|
76 | 1 /* |
87
94497283affa
Various fixes and improvements
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
2 * Here comes the really ugly code... |
94497283affa
Various fixes and improvements
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
3 * |
76 | 4 * Create the SID-tune description string from the tune's information |
5 * formatted by the user-specified format-string. | |
6 */ | |
87
94497283affa
Various fixes and improvements
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
7 #define VBUFSIZE (1024) |
94497283affa
Various fixes and improvements
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
8 #define VPUTCH(MCH) if (iIndex < VBUFSIZE) tmpBuf[iIndex++] = MCH; |
94497283affa
Various fixes and improvements
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
9 #define VPUTSTR(MSTR) {if (MSTR) {if ((iIndex + strlen(MSTR) + 1) < VBUFSIZE){strcpy(&tmpBuf[iIndex], MSTR);iIndex += strlen(MSTR); } else iIndex = VBUFSIZE;}} |
94497283affa
Various fixes and improvements
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
10 |
94497283affa
Various fixes and improvements
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
11 gchar * TFUNCTION1(gchar *pcFilename, TTUNEINFO *pfInfo, gint iSubTune) |
76 | 12 { |
87
94497283affa
Various fixes and improvements
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
13 gchar *pcStr, *pcResult, tmpStr[VBUFSIZE], tmpBuf[VBUFSIZE]; |
94497283affa
Various fixes and improvements
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
14 gint iIndex; |
76 | 15 #ifdef HAVE_XMMSEXTRA |
16 TitleInput *ptInput; | |
17 #endif | |
18 | |
19 /* FIXME FIXME: get STIL-information */ | |
87
94497283affa
Various fixes and improvements
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
20 |
76 | 21 /* Check the info strings */ |
22 if (pfInfo->numberOfInfoStrings < 3) | |
23 { | |
24 if (pfInfo->numberOfInfoStrings < 1) | |
25 return 0; | |
26 | |
27 return g_strdup(pfInfo->infoString[0]); | |
28 } | |
29 | |
30 #ifdef HAVE_XMMSEXTRA | |
31 /* Check if the titles are overridden or not */ | |
32 if (!xs_cfg.titleOverride) | |
33 { | |
34 /* Use generic XMMS titles */ | |
35 /* XMMS_NEW_TITLEINPUT(ptInput); | |
36 * We duplicate and add typecast to the code here due to XMMS's braindead headers | |
37 */ | |
38 ptInput = (TitleInput *) g_malloc0(sizeof(TitleInput)); | |
39 ptInput->__size = XMMS_TITLEINPUT_SIZE; | |
40 ptInput->__version = XMMS_TITLEINPUT_VERSION; | |
41 | |
42 /* Create the input fields */ | |
43 ptInput->file_name = pfInfo->dataFileName; | |
44 ptInput->file_ext = g_strdup("sid"); | |
45 ptInput->file_path = pfInfo->path; | |
46 | |
47 ptInput->track_name = pfInfo->infoString[0]; | |
48 ptInput->track_number = iSubTune; | |
49 ptInput->album_name = NULL; | |
50 ptInput->performer = pfInfo->infoString[1]; | |
51 ptInput->date = g_strdup((pfInfo->sidModel == SIDTUNE_SIDMODEL_6581) ? "6581" : "8580"); | |
52 | |
53 ptInput->year = 0; | |
54 ptInput->genre = g_strdup("SID-tune"); | |
55 ptInput->comment = pfInfo->infoString[2]; | |
56 | |
57 /* Create the string */ | |
58 pcResult = xmms_get_titlestring(xmms_get_gentitle_format(), ptInput); | |
59 | |
60 /* Dispose all allocated memory */ | |
61 g_free(ptInput->file_ext); | |
62 g_free(ptInput->date); | |
63 g_free(ptInput->genre); | |
64 g_free(ptInput); | |
65 } | |
66 else | |
67 #endif | |
68 { | |
87
94497283affa
Various fixes and improvements
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
69 /* Create the string */ |
76 | 70 pcStr = xs_cfg.titleFormat; |
87
94497283affa
Various fixes and improvements
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
71 iIndex = 0; |
94497283affa
Various fixes and improvements
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
72 while (*pcStr && (iIndex < VBUFSIZE)) |
76 | 73 { |
74 if (*pcStr == '%') | |
75 { | |
87
94497283affa
Various fixes and improvements
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
76 pcStr++; |
94497283affa
Various fixes and improvements
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
77 switch (*pcStr) { |
94497283affa
Various fixes and improvements
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
78 case '%': VPUTCH('%'); break; |
94497283affa
Various fixes and improvements
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
79 case '1': VPUTSTR(pfInfo->infoString[1]); break; |
94497283affa
Various fixes and improvements
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
80 case '2': VPUTSTR(pfInfo->infoString[0]); break; |
94497283affa
Various fixes and improvements
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
81 case '3': VPUTSTR(pfInfo->infoString[2]); break; |
94497283affa
Various fixes and improvements
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
82 case '4': VPUTSTR(pfInfo->formatString); break; |
94497283affa
Various fixes and improvements
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
83 case '5': |
94497283affa
Various fixes and improvements
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
84 snprintf(tmpStr, VBUFSIZE, "%i", iSubTune); |
94497283affa
Various fixes and improvements
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
85 VPUTSTR(tmpStr); |
94497283affa
Various fixes and improvements
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
86 break; |
76 | 87 } |
87
94497283affa
Various fixes and improvements
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
88 } else { |
94497283affa
Various fixes and improvements
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
89 VPUTCH(*pcStr); |
94497283affa
Various fixes and improvements
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
90 } |
76 | 91 pcStr++; |
92 } | |
87
94497283affa
Various fixes and improvements
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
93 tmpBuf[iIndex] = 0; |
94497283affa
Various fixes and improvements
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
94 pcResult = g_strdup(tmpBuf); |
76 | 95 } |
96 | |
97 return pcResult; | |
98 } | |
99 | |
87
94497283affa
Various fixes and improvements
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
100 |
94497283affa
Various fixes and improvements
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
101 /* |
94497283affa
Various fixes and improvements
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
102 * Get all SID-tune information (for all sub-tunes) including name, length, etc. |
94497283affa
Various fixes and improvements
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
103 */ |
94497283affa
Various fixes and improvements
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
104 t_xs_tune * TFUNCTION2(gchar *pcFilename) |
94497283affa
Various fixes and improvements
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
105 { |
94497283affa
Various fixes and improvements
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
106 t_xs_sldb_node *tuneLen = NULL; |
94497283affa
Various fixes and improvements
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
107 t_xs_tune *pResult; |
94497283affa
Various fixes and improvements
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
108 TTUNEINFO tuneInfo; |
94497283affa
Various fixes and improvements
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
109 TTUNE *testTune; |
94497283affa
Various fixes and improvements
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
110 gint i; |
94497283affa
Various fixes and improvements
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
111 |
94497283affa
Various fixes and improvements
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
112 /* Check if the tune exists and is readable */ |
94497283affa
Various fixes and improvements
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
113 if ((testTune = new TTUNE(pcFilename)) == NULL) |
94497283affa
Various fixes and improvements
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
114 return NULL; |
94497283affa
Various fixes and improvements
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
115 |
94497283affa
Various fixes and improvements
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
116 if (!testTune->getStatus()) |
94497283affa
Various fixes and improvements
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
117 { |
94497283affa
Various fixes and improvements
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
118 delete testTune; |
94497283affa
Various fixes and improvements
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
119 return NULL; |
94497283affa
Various fixes and improvements
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
120 } |
94497283affa
Various fixes and improvements
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
121 |
94497283affa
Various fixes and improvements
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
122 /* Get general tune information */ |
94497283affa
Various fixes and improvements
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
123 testTune->getInfo(tuneInfo); |
94497283affa
Various fixes and improvements
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
124 |
94497283affa
Various fixes and improvements
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
125 /* Get length information (NOTE: Do not free this!) */ |
94497283affa
Various fixes and improvements
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
126 tuneLen = xs_songlen_get(pcFilename); |
94497283affa
Various fixes and improvements
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
127 |
94497283affa
Various fixes and improvements
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
128 /* Allocate tuneinfo structure */ |
94497283affa
Various fixes and improvements
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
129 if ((pResult = xs_tune_new(pcFilename, tuneInfo.songs, tuneInfo.startSong)) == NULL) |
94497283affa
Various fixes and improvements
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
130 { |
94497283affa
Various fixes and improvements
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
131 delete testTune; |
94497283affa
Various fixes and improvements
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
132 return NULL; |
94497283affa
Various fixes and improvements
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
133 } |
94497283affa
Various fixes and improvements
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
134 |
94497283affa
Various fixes and improvements
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
135 /* Get information for subtunes */ |
94497283affa
Various fixes and improvements
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
136 for (i = 0; i < pResult->nsubTunes; i++) |
94497283affa
Various fixes and improvements
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
137 { |
94497283affa
Various fixes and improvements
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
138 /* Make the title */ |
94497283affa
Various fixes and improvements
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
139 pResult->subTunes[i].tuneTitle = TFUNCTION1(pcFilename, &tuneInfo, i+1); |
94497283affa
Various fixes and improvements
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
140 |
94497283affa
Various fixes and improvements
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
141 /* Get song length */ |
94497283affa
Various fixes and improvements
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
142 if (tuneLen && (i < tuneLen->nLengths)) |
94497283affa
Various fixes and improvements
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
143 pResult->subTunes[i].tuneLength = tuneLen->sLengths[i]; |
94497283affa
Various fixes and improvements
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
144 else |
94497283affa
Various fixes and improvements
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
145 pResult->subTunes[i].tuneLength = -1; |
94497283affa
Various fixes and improvements
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
146 } |
94497283affa
Various fixes and improvements
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
147 |
94497283affa
Various fixes and improvements
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
148 delete testTune; |
94497283affa
Various fixes and improvements
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
149 |
94497283affa
Various fixes and improvements
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
150 return pResult; |
94497283affa
Various fixes and improvements
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
151 } |
94497283affa
Various fixes and improvements
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
152 |
94497283affa
Various fixes and improvements
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
153 |