Mercurial > audlegacy
comparison src/audacious/playback.c @ 2313:3149d4b1a9a9 trunk
[svn] - objective-make autodepend fixes
- move all sourcecode into src/ and adjust Makefiles accordingly
author | nenolod |
---|---|
date | Fri, 12 Jan 2007 11:43:40 -0800 |
parents | |
children | 0358eb5783e6 |
comparison
equal
deleted
inserted
replaced
2312:e1a5a66fb9cc | 2313:3149d4b1a9a9 |
---|---|
1 /* Audacious - Cross-platform multimedia player | |
2 * Copyright (C) 2005-2007 Audacious development team | |
3 * | |
4 * Based on BMP: | |
5 * Copyright (C) 2003-2004 BMP development team. | |
6 * | |
7 * Based on XMMS: | |
8 * Copyright (C) 1998-2003 XMMS development team. | |
9 * | |
10 * This program is free software; you can redistribute it and/or modify | |
11 * it under the terms of the GNU General Public License as published by | |
12 * the Free Software Foundation; under version 2 of the License. | |
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 | |
24 #ifdef HAVE_CONFIG_H | |
25 # include "config.h" | |
26 #endif | |
27 | |
28 #include <glib.h> | |
29 #include <glib/gi18n.h> | |
30 #include <glib/gprintf.h> | |
31 #include <stdlib.h> | |
32 #include <string.h> | |
33 #include <time.h> | |
34 | |
35 #include <unistd.h> | |
36 #include <sys/types.h> | |
37 #include <sys/stat.h> | |
38 #include <dirent.h> | |
39 | |
40 #include "libaudacious/util.h" | |
41 #include "libaudacious/configdb.h" | |
42 | |
43 #include "input.h" | |
44 #include "main.h" | |
45 #include "ui_main.h" | |
46 #include "ui_equalizer.h" | |
47 #include "output.h" | |
48 #include "playlist.h" | |
49 #include "ui_playlist.h" | |
50 #include "ui_skinselector.h" | |
51 #include "libaudacious/urldecode.h" | |
52 #include "util.h" | |
53 | |
54 | |
55 #include "playback.h" | |
56 | |
57 | |
58 /* FIXME: yuck!! this shouldn't be here... */ | |
59 void | |
60 playback_set_random_skin(void) | |
61 { | |
62 SkinNode *node; | |
63 guint32 randval; | |
64 | |
65 /* Get a random value to select the skin to use */ | |
66 randval = g_random_int_range(0, g_list_length(skinlist)); | |
67 node = g_list_nth(skinlist, randval)->data; | |
68 bmp_active_skin_load(node->path); | |
69 } | |
70 | |
71 gint | |
72 playback_get_time(void) | |
73 { | |
74 if (!playback_get_playing()) | |
75 return -1; | |
76 | |
77 if (!get_current_input_plugin()) | |
78 return -1; | |
79 | |
80 return get_current_input_plugin()->get_time(); | |
81 } | |
82 | |
83 void | |
84 playback_initiate(void) | |
85 { | |
86 PlaylistEntry *entry = NULL; | |
87 Playlist *playlist = playlist_get_active(); | |
88 gint penalty = 0; | |
89 | |
90 if (playlist_get_length(playlist) == 0) | |
91 return; | |
92 | |
93 if (playback_get_playing()) | |
94 playback_stop(); | |
95 | |
96 vis_clear_data(mainwin_vis); | |
97 svis_clear_data(mainwin_svis); | |
98 mainwin_disable_seekbar(); | |
99 | |
100 entry = playlist_get_entry_to_play(playlist); | |
101 | |
102 if (entry == NULL) | |
103 return; | |
104 | |
105 /* | |
106 * If the playlist entry cannot be played, try to pick another one. | |
107 * If that does not work, e.g. entry == NULL, then bail. | |
108 * | |
109 * - nenolod | |
110 */ | |
111 for ( penalty=0 ; penalty <= 15 && entry != NULL && !playback_play_file(entry) ; penalty++ ) | |
112 { | |
113 playlist_next(playlist); | |
114 | |
115 entry = playlist_get_entry_to_play(playlist); | |
116 | |
117 /* XXX ew. workaround for a stupid bug where audacious will keep | |
118 * trying to play a file with no valid decoder. | |
119 */ | |
120 if (entry == NULL) | |
121 return; | |
122 | |
123 if (entry->decoder == NULL ) | |
124 entry->decoder = input_check_file(entry->filename, FALSE); | |
125 | |
126 /* if we hit 15 entries in a row with no valid decoder, just | |
127 * bail due to confusion | |
128 */ | |
129 if (penalty == 15) | |
130 return; | |
131 } | |
132 | |
133 if (playback_get_time() != -1) { | |
134 equalizerwin_load_auto_preset(entry->filename); | |
135 input_set_eq(cfg.equalizer_active, cfg.equalizer_preamp, | |
136 cfg.equalizer_bands); | |
137 output_set_eq(cfg.equalizer_active, cfg.equalizer_preamp, | |
138 cfg.equalizer_bands); | |
139 } | |
140 | |
141 playlist_check_pos_current(playlist); | |
142 mainwin_set_info_text(); | |
143 } | |
144 | |
145 void | |
146 playback_pause(void) | |
147 { | |
148 if (!playback_get_playing()) | |
149 return; | |
150 | |
151 if (!get_current_input_plugin()) | |
152 return; | |
153 | |
154 ip_data.paused = !ip_data.paused; | |
155 | |
156 if (get_current_input_plugin()->pause) | |
157 get_current_input_plugin()->pause(ip_data.paused); | |
158 | |
159 g_return_if_fail(mainwin_playstatus != NULL); | |
160 | |
161 if (ip_data.paused) | |
162 playstatus_set_status(mainwin_playstatus, STATUS_PAUSE); | |
163 else | |
164 playstatus_set_status(mainwin_playstatus, STATUS_PLAY); | |
165 } | |
166 | |
167 void | |
168 playback_stop(void) | |
169 { | |
170 if (ip_data.playing && get_current_input_plugin()) { | |
171 | |
172 if (playback_get_paused()) { | |
173 output_flush(get_written_time()); /* to avoid noise */ | |
174 playback_pause(); | |
175 } | |
176 | |
177 ip_data.playing = FALSE; | |
178 | |
179 if (get_current_input_plugin()->stop) | |
180 get_current_input_plugin()->stop(); | |
181 | |
182 free_vis_data(); | |
183 ip_data.paused = FALSE; | |
184 | |
185 if (input_info_text) { | |
186 g_free(input_info_text); | |
187 input_info_text = NULL; | |
188 mainwin_set_info_text(); | |
189 } | |
190 } | |
191 | |
192 ip_data.buffering = FALSE; | |
193 ip_data.playing = FALSE; | |
194 | |
195 g_return_if_fail(mainwin_playstatus != NULL); | |
196 playstatus_set_status_buffering(mainwin_playstatus, FALSE); | |
197 } | |
198 | |
199 void | |
200 playback_stop_reentrant(void) | |
201 { | |
202 if (ip_data.playing && get_current_input_plugin()) { | |
203 | |
204 if (playback_get_paused()) | |
205 playback_pause(); | |
206 | |
207 ip_data.playing = FALSE; | |
208 | |
209 free_vis_data(); | |
210 ip_data.paused = FALSE; | |
211 | |
212 if (input_info_text) { | |
213 g_free(input_info_text); | |
214 input_info_text = NULL; | |
215 mainwin_set_info_text(); | |
216 } | |
217 } | |
218 | |
219 ip_data.buffering = FALSE; | |
220 ip_data.playing = FALSE; | |
221 } | |
222 | |
223 static void | |
224 run_no_output_plugin_dialog(void) | |
225 { | |
226 const gchar *markup = | |
227 N_("<b><big>No output plugin selected.</big></b>\n" | |
228 "You have not selected an output plugin."); | |
229 | |
230 GtkWidget *dialog = | |
231 gtk_message_dialog_new_with_markup(GTK_WINDOW(mainwin), | |
232 GTK_DIALOG_DESTROY_WITH_PARENT, | |
233 GTK_MESSAGE_ERROR, | |
234 GTK_BUTTONS_OK, | |
235 _(markup)); | |
236 gtk_dialog_run(GTK_DIALOG(dialog)); | |
237 gtk_widget_destroy(dialog); | |
238 } | |
239 | |
240 gboolean | |
241 playback_play_file(PlaylistEntry *entry) | |
242 { | |
243 g_return_val_if_fail(entry != NULL, FALSE); | |
244 | |
245 if (!get_current_output_plugin()) { | |
246 run_no_output_plugin_dialog(); | |
247 mainwin_stop_pushed(); | |
248 return FALSE; | |
249 } | |
250 | |
251 if (cfg.random_skin_on_play) | |
252 playback_set_random_skin(); | |
253 | |
254 /* | |
255 * This is slightly uglier than the original version, but should | |
256 * fix the "crash" issues as seen in 0.2 when dealing with this situation. | |
257 * - nenolod | |
258 */ | |
259 if (!entry->decoder && | |
260 (((entry->decoder = input_check_file(entry->filename, FALSE)) == NULL) || | |
261 !input_is_enabled(entry->decoder->filename))) | |
262 { | |
263 input_file_not_playable(entry->filename); | |
264 | |
265 set_current_input_plugin(NULL); | |
266 mainwin_set_info_text(); | |
267 | |
268 return FALSE; | |
269 } | |
270 | |
271 set_current_input_plugin(entry->decoder); | |
272 entry->decoder->output = &psuedo_output_plugin; | |
273 entry->decoder->play_file(entry->filename); | |
274 | |
275 ip_data.playing = TRUE; | |
276 | |
277 return TRUE; | |
278 } | |
279 | |
280 gboolean | |
281 playback_get_playing(void) | |
282 { | |
283 return ip_data.playing; | |
284 } | |
285 | |
286 gboolean | |
287 playback_get_paused(void) | |
288 { | |
289 return ip_data.paused; | |
290 } | |
291 | |
292 void | |
293 playback_seek(gint time) | |
294 { | |
295 gboolean restore_pause = FALSE; | |
296 gint l=0, r=0; | |
297 | |
298 if (!ip_data.playing) | |
299 return; | |
300 | |
301 if (!get_current_input_plugin()) | |
302 return; | |
303 | |
304 /* FIXME WORKAROUND...that should work with all plugins | |
305 * mute the volume, start playback again, do the seek, then pause again | |
306 * -Patrick Sudowe | |
307 */ | |
308 if(ip_data.paused) | |
309 { | |
310 restore_pause = TRUE; | |
311 output_get_volume(&l, &r); | |
312 output_set_volume(0,0); | |
313 playback_pause(); | |
314 } | |
315 | |
316 free_vis_data(); | |
317 get_current_input_plugin()->seek(time); | |
318 | |
319 if(restore_pause) | |
320 { | |
321 playback_pause(); | |
322 output_set_volume(l, r); | |
323 } | |
324 } | |
325 | |
326 void | |
327 playback_seek_relative(gint offset) | |
328 { | |
329 gint time = CLAMP(playback_get_time() / 1000 + offset, | |
330 0, playlist_get_current_length(playlist_get_active()) / 1000 - 1); | |
331 playback_seek(time); | |
332 } |