Mercurial > audlegacy
annotate audacious/playback.c @ 2073:25308f10b50f trunk
[svn] - fix urldecode dependencies
author | nenolod |
---|---|
date | Sat, 09 Dec 2006 01:55:27 -0800 |
parents | 30d40252862d |
children | 79b077f6234b |
rev | line source |
---|---|
283 | 1 /* BMP - Cross-platform multimedia player |
2 * Copyright (C) 2003-2004 BMP development team. | |
3 * | |
4 * Based on XMMS: | |
5 * Copyright (C) 1998-2003 XMMS development team. | |
6 * | |
7 * This program is free software; you can redistribute it and/or modify | |
1460 | 8 * it under the terms of the GNU General Public License as published by |
283 | 9 * the Free Software Foundation; either version 2 of the License, or |
10 * (at your option) any later version. | |
11 * | |
12 * This program is distributed in the hope that it will be useful, | |
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 * GNU General Public License for more details. | |
16 * | |
17 * You should have received a copy of the GNU General Public License | |
18 * along with this program; if not, write to the Free Software | |
1459 | 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
283 | 20 */ |
21 | |
22 #ifdef HAVE_CONFIG_H | |
23 # include "config.h" | |
24 #endif | |
25 | |
26 #include <glib.h> | |
27 #include <glib/gi18n.h> | |
28 #include <glib/gprintf.h> | |
29 #include <stdlib.h> | |
30 #include <string.h> | |
31 #include <time.h> | |
32 | |
33 #include <unistd.h> | |
34 #include <sys/types.h> | |
35 #include <sys/stat.h> | |
36 #include <dirent.h> | |
37 | |
38 #include "libaudacious/util.h" | |
39 #include "libaudacious/configdb.h" | |
40 | |
41 #include "input.h" | |
42 #include "main.h" | |
1653 | 43 #include "mainwin.h" |
44 #include "equalizer.h" | |
283 | 45 #include "output.h" |
46 #include "playlist.h" | |
1653 | 47 #include "ui_playlist.h" |
283 | 48 #include "skinwin.h" |
2073 | 49 #include "libaudacious/urldecode.h" |
283 | 50 #include "util.h" |
51 | |
52 | |
53 #include "playback.h" | |
1653 | 54 |
55 | |
56 /* FIXME: yuck!! this shouldn't be here... */ | |
57 void | |
58 bmp_playback_set_random_skin(void) | |
59 { | |
60 SkinNode *node; | |
61 guint32 randval; | |
62 | |
63 /* Get a random value to select the skin to use */ | |
64 randval = g_random_int_range(0, g_list_length(skinlist)); | |
65 node = g_list_nth(skinlist, randval)->data; | |
66 bmp_active_skin_load(node->path); | |
67 } | |
283 | 68 |
69 gint | |
70 bmp_playback_get_time(void) | |
71 { | |
72 if (!bmp_playback_get_playing()) | |
73 return -1; | |
74 | |
75 if (!get_current_input_plugin()) | |
76 return -1; | |
77 | |
78 return get_current_input_plugin()->get_time(); | |
79 } | |
80 | |
81 void | |
82 bmp_playback_initiate(void) | |
83 { | |
1913
30d40252862d
[svn] - this should fix #592. somebody please check.
nenolod
parents:
1672
diff
changeset
|
84 PlaylistEntry *entry = NULL; |
283 | 85 |
86 if (playlist_get_length() == 0) | |
87 return; | |
88 | |
89 if (bmp_playback_get_playing()) | |
90 bmp_playback_stop(); | |
91 | |
92 vis_clear_data(mainwin_vis); | |
93 svis_clear_data(mainwin_svis); | |
94 mainwin_disable_seekbar(); | |
95 | |
356
99928e1275a1
[svn] This commit reduces the amount of times we probe a source down to ONE
nenolod
parents:
283
diff
changeset
|
96 entry = playlist_get_entry_to_play(); |
283 | 97 |
356
99928e1275a1
[svn] This commit reduces the amount of times we probe a source down to ONE
nenolod
parents:
283
diff
changeset
|
98 if (!entry) |
283 | 99 return; |
100 | |
1913
30d40252862d
[svn] - this should fix #592. somebody please check.
nenolod
parents:
1672
diff
changeset
|
101 /* |
30d40252862d
[svn] - this should fix #592. somebody please check.
nenolod
parents:
1672
diff
changeset
|
102 * If the playlist entry cannot be played, try to pick another one. |
30d40252862d
[svn] - this should fix #592. somebody please check.
nenolod
parents:
1672
diff
changeset
|
103 * If that does not work, e.g. entry == NULL, then bail. |
30d40252862d
[svn] - this should fix #592. somebody please check.
nenolod
parents:
1672
diff
changeset
|
104 * |
30d40252862d
[svn] - this should fix #592. somebody please check.
nenolod
parents:
1672
diff
changeset
|
105 * - nenolod |
30d40252862d
[svn] - this should fix #592. somebody please check.
nenolod
parents:
1672
diff
changeset
|
106 */ |
30d40252862d
[svn] - this should fix #592. somebody please check.
nenolod
parents:
1672
diff
changeset
|
107 while (entry != NULL && !bmp_playback_play_file(entry)) |
30d40252862d
[svn] - this should fix #592. somebody please check.
nenolod
parents:
1672
diff
changeset
|
108 { |
30d40252862d
[svn] - this should fix #592. somebody please check.
nenolod
parents:
1672
diff
changeset
|
109 playlist_next(); |
30d40252862d
[svn] - this should fix #592. somebody please check.
nenolod
parents:
1672
diff
changeset
|
110 |
30d40252862d
[svn] - this should fix #592. somebody please check.
nenolod
parents:
1672
diff
changeset
|
111 entry = playlist_get_entry_to_play(); |
30d40252862d
[svn] - this should fix #592. somebody please check.
nenolod
parents:
1672
diff
changeset
|
112 |
30d40252862d
[svn] - this should fix #592. somebody please check.
nenolod
parents:
1672
diff
changeset
|
113 if (entry == NULL) |
30d40252862d
[svn] - this should fix #592. somebody please check.
nenolod
parents:
1672
diff
changeset
|
114 return; |
30d40252862d
[svn] - this should fix #592. somebody please check.
nenolod
parents:
1672
diff
changeset
|
115 } |
283 | 116 |
117 if (bmp_playback_get_time() != -1) { | |
356
99928e1275a1
[svn] This commit reduces the amount of times we probe a source down to ONE
nenolod
parents:
283
diff
changeset
|
118 equalizerwin_load_auto_preset(entry->filename); |
283 | 119 input_set_eq(cfg.equalizer_active, cfg.equalizer_preamp, |
120 cfg.equalizer_bands); | |
121 output_set_eq(cfg.equalizer_active, cfg.equalizer_preamp, | |
122 cfg.equalizer_bands); | |
123 } | |
124 | |
125 playlist_check_pos_current(); | |
126 mainwin_set_info_text(); | |
127 } | |
128 | |
129 void | |
130 bmp_playback_pause(void) | |
131 { | |
132 if (!bmp_playback_get_playing()) | |
133 return; | |
134 | |
135 if (!get_current_input_plugin()) | |
136 return; | |
137 | |
138 ip_data.paused = !ip_data.paused; | |
139 | |
1672
600efc52c645
[svn] - be careful about referencing a NULL widget (e.g. headless/serveronly mode crashes on streams, bug #562)
nenolod
parents:
1653
diff
changeset
|
140 if (get_current_input_plugin()->pause) |
600efc52c645
[svn] - be careful about referencing a NULL widget (e.g. headless/serveronly mode crashes on streams, bug #562)
nenolod
parents:
1653
diff
changeset
|
141 get_current_input_plugin()->pause(ip_data.paused); |
600efc52c645
[svn] - be careful about referencing a NULL widget (e.g. headless/serveronly mode crashes on streams, bug #562)
nenolod
parents:
1653
diff
changeset
|
142 |
600efc52c645
[svn] - be careful about referencing a NULL widget (e.g. headless/serveronly mode crashes on streams, bug #562)
nenolod
parents:
1653
diff
changeset
|
143 g_return_if_fail(mainwin_playstatus != NULL); |
600efc52c645
[svn] - be careful about referencing a NULL widget (e.g. headless/serveronly mode crashes on streams, bug #562)
nenolod
parents:
1653
diff
changeset
|
144 |
283 | 145 if (ip_data.paused) |
146 playstatus_set_status(mainwin_playstatus, STATUS_PAUSE); | |
147 else | |
148 playstatus_set_status(mainwin_playstatus, STATUS_PLAY); | |
149 } | |
150 | |
151 void | |
152 bmp_playback_stop(void) | |
153 { | |
154 if (ip_data.playing && get_current_input_plugin()) { | |
155 ip_data.playing = FALSE; | |
156 | |
157 if (bmp_playback_get_paused()) | |
158 bmp_playback_pause(); | |
159 | |
160 if (get_current_input_plugin()->stop) | |
161 get_current_input_plugin()->stop(); | |
162 | |
163 free_vis_data(); | |
164 ip_data.paused = FALSE; | |
165 | |
166 if (input_info_text) { | |
167 g_free(input_info_text); | |
168 input_info_text = NULL; | |
169 mainwin_set_info_text(); | |
170 } | |
171 } | |
172 | |
1273
3b990c26fc46
[svn] - Support for the buffer indicator in playpaus.png that was apparently
nhjm449
parents:
890
diff
changeset
|
173 ip_data.buffering = FALSE; |
1672
600efc52c645
[svn] - be careful about referencing a NULL widget (e.g. headless/serveronly mode crashes on streams, bug #562)
nenolod
parents:
1653
diff
changeset
|
174 ip_data.playing = FALSE; |
600efc52c645
[svn] - be careful about referencing a NULL widget (e.g. headless/serveronly mode crashes on streams, bug #562)
nenolod
parents:
1653
diff
changeset
|
175 |
600efc52c645
[svn] - be careful about referencing a NULL widget (e.g. headless/serveronly mode crashes on streams, bug #562)
nenolod
parents:
1653
diff
changeset
|
176 g_return_if_fail(mainwin_playstatus != NULL); |
600efc52c645
[svn] - be careful about referencing a NULL widget (e.g. headless/serveronly mode crashes on streams, bug #562)
nenolod
parents:
1653
diff
changeset
|
177 |
1653 | 178 playstatus_set_status_buffering(mainwin_playstatus, FALSE); |
283 | 179 } |
180 | |
181 void | |
182 bmp_playback_stop_reentrant(void) | |
183 { | |
184 if (ip_data.playing && get_current_input_plugin()) { | |
185 ip_data.playing = FALSE; | |
186 | |
187 if (bmp_playback_get_paused()) | |
188 bmp_playback_pause(); | |
189 | |
190 free_vis_data(); | |
191 ip_data.paused = FALSE; | |
192 | |
193 if (input_info_text) { | |
194 g_free(input_info_text); | |
195 input_info_text = NULL; | |
196 mainwin_set_info_text(); | |
197 } | |
198 } | |
199 | |
1273
3b990c26fc46
[svn] - Support for the buffer indicator in playpaus.png that was apparently
nhjm449
parents:
890
diff
changeset
|
200 ip_data.buffering = FALSE; |
283 | 201 ip_data.playing = FALSE; |
202 } | |
203 | |
204 static void | |
205 run_no_output_plugin_dialog(void) | |
206 { | |
207 const gchar *markup = | |
208 N_("<b><big>No output plugin selected.</big></b>\n" | |
209 "You have not selected an output plugin."); | |
210 | |
211 GtkWidget *dialog = | |
1653 | 212 gtk_message_dialog_new_with_markup(GTK_WINDOW(mainwin), |
283 | 213 GTK_DIALOG_DESTROY_WITH_PARENT, |
214 GTK_MESSAGE_ERROR, | |
215 GTK_BUTTONS_OK, | |
216 _(markup)); | |
217 gtk_dialog_run(GTK_DIALOG(dialog)); | |
218 gtk_widget_destroy(dialog); | |
219 } | |
220 | |
221 gboolean | |
398
f908bcd87c3d
[svn] Generate cache content on demand if it was not previously there.
nenolod
parents:
385
diff
changeset
|
222 bmp_playback_play_file(PlaylistEntry *entry) |
283 | 223 { |
356
99928e1275a1
[svn] This commit reduces the amount of times we probe a source down to ONE
nenolod
parents:
283
diff
changeset
|
224 g_return_val_if_fail(entry != NULL, FALSE); |
283 | 225 |
226 if (!get_current_output_plugin()) { | |
227 run_no_output_plugin_dialog(); | |
228 mainwin_stop_pushed(); | |
229 return FALSE; | |
230 } | |
231 | |
232 if (cfg.random_skin_on_play) | |
233 bmp_playback_set_random_skin(); | |
234 | |
677
f52f596dc0d8
[svn] - Working exception handling at no extra charge. Closes bugs #408, #409.
nenolod
parents:
561
diff
changeset
|
235 /* |
f52f596dc0d8
[svn] - Working exception handling at no extra charge. Closes bugs #408, #409.
nenolod
parents:
561
diff
changeset
|
236 * This is slightly uglier than the original version, but should |
f52f596dc0d8
[svn] - Working exception handling at no extra charge. Closes bugs #408, #409.
nenolod
parents:
561
diff
changeset
|
237 * fix the "crash" issues as seen in 0.2 when dealing with this situation. |
f52f596dc0d8
[svn] - Working exception handling at no extra charge. Closes bugs #408, #409.
nenolod
parents:
561
diff
changeset
|
238 * - nenolod |
f52f596dc0d8
[svn] - Working exception handling at no extra charge. Closes bugs #408, #409.
nenolod
parents:
561
diff
changeset
|
239 */ |
f52f596dc0d8
[svn] - Working exception handling at no extra charge. Closes bugs #408, #409.
nenolod
parents:
561
diff
changeset
|
240 if (!entry->decoder && |
678 | 241 (((entry->decoder = input_check_file(entry->filename, FALSE)) == NULL) || |
242 !input_is_enabled(entry->decoder->filename))) | |
356
99928e1275a1
[svn] This commit reduces the amount of times we probe a source down to ONE
nenolod
parents:
283
diff
changeset
|
243 { |
99928e1275a1
[svn] This commit reduces the amount of times we probe a source down to ONE
nenolod
parents:
283
diff
changeset
|
244 input_file_not_playable(entry->filename); |
283 | 245 |
356
99928e1275a1
[svn] This commit reduces the amount of times we probe a source down to ONE
nenolod
parents:
283
diff
changeset
|
246 set_current_input_plugin(NULL); |
99928e1275a1
[svn] This commit reduces the amount of times we probe a source down to ONE
nenolod
parents:
283
diff
changeset
|
247 mainwin_set_info_text(); |
283 | 248 |
356
99928e1275a1
[svn] This commit reduces the amount of times we probe a source down to ONE
nenolod
parents:
283
diff
changeset
|
249 return FALSE; |
283 | 250 } |
251 | |
356
99928e1275a1
[svn] This commit reduces the amount of times we probe a source down to ONE
nenolod
parents:
283
diff
changeset
|
252 set_current_input_plugin(entry->decoder); |
890
ed26947bbf57
[svn] Gapless support. This comes with a few caveats, that I will mention here:
nenolod
parents:
678
diff
changeset
|
253 entry->decoder->output = &psuedo_output_plugin; |
356
99928e1275a1
[svn] This commit reduces the amount of times we probe a source down to ONE
nenolod
parents:
283
diff
changeset
|
254 entry->decoder->play_file(entry->filename); |
283 | 255 |
356
99928e1275a1
[svn] This commit reduces the amount of times we probe a source down to ONE
nenolod
parents:
283
diff
changeset
|
256 ip_data.playing = TRUE; |
283 | 257 |
356
99928e1275a1
[svn] This commit reduces the amount of times we probe a source down to ONE
nenolod
parents:
283
diff
changeset
|
258 return TRUE; |
283 | 259 } |
260 | |
261 gboolean | |
262 bmp_playback_get_playing(void) | |
263 { | |
264 return ip_data.playing; | |
265 } | |
266 | |
267 gboolean | |
268 bmp_playback_get_paused(void) | |
269 { | |
270 return ip_data.paused; | |
271 } | |
272 | |
273 void | |
274 bmp_playback_seek(gint time) | |
275 { | |
276 gboolean restore_pause = FALSE; | |
277 gint l=0, r=0; | |
278 | |
279 if (!ip_data.playing) | |
280 return; | |
281 | |
282 if (!get_current_input_plugin()) | |
283 return; | |
284 | |
285 /* FIXME WORKAROUND...that should work with all plugins | |
286 * mute the volume, start playback again, do the seek, then pause again | |
677
f52f596dc0d8
[svn] - Working exception handling at no extra charge. Closes bugs #408, #409.
nenolod
parents:
561
diff
changeset
|
287 * -Patrick Sudowe |
f52f596dc0d8
[svn] - Working exception handling at no extra charge. Closes bugs #408, #409.
nenolod
parents:
561
diff
changeset
|
288 */ |
283 | 289 if(ip_data.paused) |
290 { | |
291 restore_pause = TRUE; | |
292 output_get_volume(&l, &r); | |
293 output_set_volume(0,0); | |
294 bmp_playback_pause(); | |
295 } | |
296 | |
297 free_vis_data(); | |
298 get_current_input_plugin()->seek(time); | |
299 | |
300 if(restore_pause) | |
301 { | |
302 bmp_playback_pause(); | |
303 output_set_volume(l, r); | |
304 } | |
305 } | |
306 | |
307 void | |
308 bmp_playback_seek_relative(gint offset) | |
309 { | |
310 gint time = CLAMP(bmp_playback_get_time() / 1000 + offset, | |
311 0, playlist_get_current_length() / 1000 - 1); | |
312 bmp_playback_seek(time); | |
313 } |