Mercurial > audlegacy-plugins
annotate src/sexypsf/xmms.c @ 1201:2ae8155baef1
First cleanups
author | michi@tux.homenetwork |
---|---|
date | Mon, 02 Jul 2007 15:53:49 +0200 |
parents | 3bcb772fa1b5 |
children | 82ef51e8934a |
rev | line source |
---|---|
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
1 /* sexyPSF - PSF1 player |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
2 * Copyright (C) 2002-2004 xodnizel |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
3 * |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
4 * This library is free software; you can redistribute it and/or |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
5 * modify it under the terms of the GNU Lesser General Public |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
6 * License as published by the Free Software Foundation; either |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
7 * version 2.1 of the License, or (at your option) any later version. |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
8 * |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
9 * This library is distributed in the hope that it will be useful, |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
12 * Lesser General Public License for more details. |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
13 * |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
14 * You should have received a copy of the GNU Lesser General Public |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
15 * License along with this library; if not, write to the Free Software |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
1201 | 17 */ |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
18 |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
19 #include "audacious/output.h" |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
20 #include "audacious/plugin.h" |
3
088092a52fea
[svn] - move from (internal) libaudacious/ include path to audacious/ include path
nenolod
parents:
0
diff
changeset
|
21 #include "audacious/titlestring.h" |
088092a52fea
[svn] - move from (internal) libaudacious/ include path to audacious/ include path
nenolod
parents:
0
diff
changeset
|
22 #include "audacious/util.h" |
088092a52fea
[svn] - move from (internal) libaudacious/ include path to audacious/ include path
nenolod
parents:
0
diff
changeset
|
23 #include "audacious/vfs.h" |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
24 #include <stdio.h> |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
25 #include <stdlib.h> |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
26 #include <string.h> |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
27 #include <unistd.h> |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
28 #include "driver.h" |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
29 |
1201 | 30 #define CMD_SEEK 0x80000000 |
31 #define CMD_STOP 0x40000000 | |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
32 |
1201 | 33 static volatile int seek_time = 0; |
34 static volatile int stop = 0; | |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
35 static volatile int playing=0; |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
36 static volatile int nextsong=0; |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
37 |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
38 extern InputPlugin sexypsf_ip; |
1201 | 39 static char *fnsave = NULL; |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
40 |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
41 static gchar *get_title_psf(gchar *fn); |
1201 | 42 static short paused; |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
43 static GThread *dethread; |
1201 | 44 static PSFINFO *PSFInfo = NULL; |
561
914c96de3244
[svn] Convert plugins to use InputPlayback.output instead of InputPlugin.output
iabervon
parents:
559
diff
changeset
|
45 static InputPlayback *playback; |
914c96de3244
[svn] Convert plugins to use InputPlayback.output instead of InputPlugin.output
iabervon
parents:
559
diff
changeset
|
46 |
1201 | 47 static int is_our_fd(gchar *filename, VFSFile *file) { |
48 gchar magic[4]; | |
49 vfs_fread(magic, 1, 4, file); | |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
50 |
1201 | 51 // only allow PSF1 for now |
52 if (!memcmp(magic, "PSF\x01", 4)) | |
53 return 1; | |
54 return 0; | |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
55 } |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
56 |
1201 | 57 |
58 void sexypsf_update(unsigned char *buffer, long count) | |
59 { | |
60 const int mask = ~((((16 / 8) * 2)) - 1); | |
61 | |
62 while (count > 0) | |
63 { | |
64 int t = playback->output->buffer_free() & mask; | |
65 if (t > count) | |
66 produce_audio(playback->output->written_time(), FMT_S16_NE, 2, count, buffer, NULL); | |
67 else | |
68 { | |
69 if (t) | |
70 produce_audio(playback->output->written_time(), FMT_S16_NE, 2, t, buffer, NULL); | |
71 g_usleep((count-t)*1000*5/441/2); | |
72 } | |
73 count -= t; | |
74 buffer += t; | |
75 } | |
76 if (seek_time) | |
77 { | |
78 if(sexypsf_seek(seek_time)) | |
79 playback->output->flush(seek_time); | |
80 // negative time - must make a C time machine | |
81 else | |
82 { | |
83 sexypsf_stop(); | |
84 return; | |
85 } | |
86 seek_time = 0; | |
87 } | |
88 if (stop) | |
89 sexypsf_stop(); | |
90 } | |
91 | |
92 static gpointer sexypsf_playloop(gpointer arg) | |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
93 { |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
94 dofunky: |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
95 |
1201 | 96 sexypsf_execute(); |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
97 |
1201 | 98 /* we have reached the end of the song */ |
99 | |
100 playback->output->buffer_free(); | |
101 playback->output->buffer_free(); | |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
102 |
1201 | 103 while (!(stop)) |
104 { | |
105 if (seek_time) | |
106 { | |
107 playback->output->flush(seek_time); | |
108 if(!(PSFInfo=sexypsf_load(fnsave))) | |
109 break; | |
110 sexypsf_seek(seek_time); | |
111 seek_time = 0; | |
112 goto dofunky; | |
113 } | |
114 if (!playback->output->buffer_playing()) break; | |
115 usleep(2000); | |
116 } | |
117 playback->output->close_audio(); | |
118 if(!(stop)) nextsong=1; | |
119 g_thread_exit(NULL); | |
120 return NULL; | |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
121 } |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
122 |
559 | 123 static void sexypsf_xmms_play(InputPlayback *data) |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
124 { |
1201 | 125 char *fn = data->filename; |
126 if(playing) | |
127 return; | |
128 playback = data; | |
129 nextsong=0; | |
130 paused = 0; | |
131 if(!playback->output->open_audio(FMT_S16_NE, 44100, 2)) | |
132 { | |
133 puts("Error opening audio."); | |
134 return; | |
135 } | |
136 fnsave=malloc(strlen(fn)+1); | |
137 strcpy(fnsave,fn); | |
138 if(!(PSFInfo=sexypsf_load(fn))) | |
139 { | |
140 playback->output->close_audio(); | |
141 nextsong=1; | |
142 } | |
143 else | |
144 { | |
145 stop = seek_time = 0; | |
146 | |
147 gchar *name = get_title_psf(fn); | |
148 sexypsf_ip.set_info(name,PSFInfo->length,44100*2*2*8,44100,2); | |
149 g_free(name); | |
150 | |
151 playing=1; | |
152 dethread = g_thread_create((GThreadFunc)sexypsf_playloop,NULL,TRUE,NULL); | |
153 } | |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
154 } |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
155 |
561
914c96de3244
[svn] Convert plugins to use InputPlayback.output instead of InputPlugin.output
iabervon
parents:
559
diff
changeset
|
156 static void sexypsf_xmms_stop(InputPlayback * playback) |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
157 { |
1201 | 158 if(!playing) return; |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
159 |
1201 | 160 if(paused) |
161 playback->output->pause(0); | |
162 paused = 0; | |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
163 |
1201 | 164 stop = TRUE; |
165 g_thread_join(dethread); | |
166 playing = 0; | |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
167 |
1201 | 168 if(fnsave) |
169 { | |
170 free(fnsave); | |
171 fnsave=NULL; | |
172 } | |
173 sexypsf_freepsfinfo(PSFInfo); | |
174 PSFInfo=NULL; | |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
175 } |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
176 |
561
914c96de3244
[svn] Convert plugins to use InputPlayback.output instead of InputPlugin.output
iabervon
parents:
559
diff
changeset
|
177 static void sexypsf_xmms_pause(InputPlayback * playback, short p) |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
178 { |
1201 | 179 if(!playing) return; |
180 playback->output->pause(p); | |
181 paused = p; | |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
182 } |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
183 |
559 | 184 static void sexypsf_xmms_seek(InputPlayback * data, int time) |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
185 { |
1201 | 186 if(!playing) return; |
187 seek_time = time * 1000; | |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
188 } |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
189 |
561
914c96de3244
[svn] Convert plugins to use InputPlayback.output instead of InputPlugin.output
iabervon
parents:
559
diff
changeset
|
190 static int sexypsf_xmms_gettime(InputPlayback *playback) |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
191 { |
1201 | 192 if(nextsong) |
193 return(-1); | |
194 if(!playing) return(0); | |
195 return playback->output->output_time(); | |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
196 } |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
197 |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
198 static void sexypsf_xmms_getsonginfo(char *fn, char **title, int *length) |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
199 { |
1201 | 200 PSFINFO *tmp; |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
201 |
1201 | 202 if((tmp=sexypsf_getpsfinfo(fn))) { |
203 *length = tmp->length; | |
204 *title = get_title_psf(fn); | |
205 sexypsf_freepsfinfo(tmp); | |
206 } | |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
207 } |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
208 |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
209 static TitleInput *get_tuple_psf(gchar *fn) { |
1201 | 210 TitleInput *tuple = NULL; |
211 PSFINFO *tmp = sexypsf_getpsfinfo(fn); | |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
212 |
1201 | 213 if (tmp->length) { |
214 tuple = bmp_title_input_new(); | |
215 tuple->length = tmp->length; | |
216 tuple->performer = g_strdup(tmp->artist); | |
217 tuple->album_name = g_strdup(tmp->game); | |
218 tuple->track_name = g_strdup(tmp->title); | |
219 tuple->file_name = g_path_get_basename(fn); | |
220 tuple->file_path = g_path_get_dirname(fn); | |
221 sexypsf_freepsfinfo(tmp); | |
222 } | |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
223 |
1201 | 224 return tuple; |
225 } | |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
226 |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
227 static gchar *get_title_psf(gchar *fn) { |
1201 | 228 gchar *title; |
229 TitleInput *tinput = get_tuple_psf(fn); | |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
230 |
1201 | 231 if (tinput != NULL) { |
232 title = xmms_get_titlestring(xmms_get_gentitle_format(), | |
233 tinput); | |
234 bmp_title_input_free(tinput); | |
235 } | |
236 else | |
237 title = g_path_get_basename(fn); | |
238 | |
239 return title; | |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
240 } |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
241 |
372
a157306caf03
[svn] - finalize the plugin-side of the extension-assist ABI
nenolod
parents:
368
diff
changeset
|
242 gchar *sexypsf_fmts[] = { "psf", "minipsf", NULL }; |
a157306caf03
[svn] - finalize the plugin-side of the extension-assist ABI
nenolod
parents:
368
diff
changeset
|
243 |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
244 InputPlugin sexypsf_ip = |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
245 { |
1201 | 246 NULL, |
247 NULL, | |
248 "PSF Audio Plugin", | |
249 NULL, | |
250 NULL, | |
251 NULL, | |
252 NULL, | |
253 NULL, | |
254 sexypsf_xmms_play, | |
255 sexypsf_xmms_stop, | |
256 sexypsf_xmms_pause, | |
257 sexypsf_xmms_seek, | |
258 NULL, | |
259 sexypsf_xmms_gettime, | |
260 NULL, | |
261 NULL, | |
262 NULL, | |
263 NULL, | |
264 NULL, | |
265 NULL, | |
266 NULL, | |
267 sexypsf_xmms_getsonginfo, | |
268 NULL, | |
269 NULL, | |
270 get_tuple_psf, | |
271 NULL, | |
272 NULL, | |
273 is_our_fd, | |
274 sexypsf_fmts, | |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
275 }; |
1090 | 276 |
277 InputPlugin *sexypsf_iplist[] = { &sexypsf_ip, NULL }; | |
278 | |
279 DECLARE_PLUGIN(sexypsf, NULL, NULL, sexypsf_iplist, NULL, NULL, NULL, NULL); |