Mercurial > audlegacy
annotate audacious/playback.c @ 2226:325a97334c11 trunk
[svn] - set the translation domain for UIManager owned objects. Closes #719, #720.
author | nenolod |
---|---|
date | Sun, 31 Dec 2006 11:32:05 -0800 |
parents | fe6e7b9b4aac |
children | 894f7aa46f83 |
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 |
2105
f18a5b617c34
[svn] - move to GPLv2-only. Based on my interpretation of the license, we are
nenolod
parents:
2092
diff
changeset
|
9 * the Free Software Foundation; under version 2 of the License. |
283 | 10 * |
11 * This program is distributed in the hope that it will be useful, | |
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 * GNU General Public License for more details. | |
15 * | |
16 * You should have received a copy of the GNU General Public License | |
17 * along with this program; if not, write to the Free Software | |
1459 | 18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
283 | 19 */ |
20 | |
21 #ifdef HAVE_CONFIG_H | |
22 # include "config.h" | |
23 #endif | |
24 | |
25 #include <glib.h> | |
26 #include <glib/gi18n.h> | |
27 #include <glib/gprintf.h> | |
28 #include <stdlib.h> | |
29 #include <string.h> | |
30 #include <time.h> | |
31 | |
32 #include <unistd.h> | |
33 #include <sys/types.h> | |
34 #include <sys/stat.h> | |
35 #include <dirent.h> | |
36 | |
37 #include "libaudacious/util.h" | |
38 #include "libaudacious/configdb.h" | |
39 | |
40 #include "input.h" | |
41 #include "main.h" | |
1653 | 42 #include "mainwin.h" |
43 #include "equalizer.h" | |
283 | 44 #include "output.h" |
45 #include "playlist.h" | |
1653 | 46 #include "ui_playlist.h" |
283 | 47 #include "skinwin.h" |
2073 | 48 #include "libaudacious/urldecode.h" |
283 | 49 #include "util.h" |
50 | |
51 | |
52 #include "playback.h" | |
1653 | 53 |
54 | |
55 /* FIXME: yuck!! this shouldn't be here... */ | |
56 void | |
57 bmp_playback_set_random_skin(void) | |
58 { | |
59 SkinNode *node; | |
60 guint32 randval; | |
61 | |
62 /* Get a random value to select the skin to use */ | |
63 randval = g_random_int_range(0, g_list_length(skinlist)); | |
64 node = g_list_nth(skinlist, randval)->data; | |
65 bmp_active_skin_load(node->path); | |
66 } | |
283 | 67 |
68 gint | |
69 bmp_playback_get_time(void) | |
70 { | |
71 if (!bmp_playback_get_playing()) | |
72 return -1; | |
73 | |
74 if (!get_current_input_plugin()) | |
75 return -1; | |
76 | |
77 return get_current_input_plugin()->get_time(); | |
78 } | |
79 | |
80 void | |
81 bmp_playback_initiate(void) | |
82 { | |
1913
30d40252862d
[svn] - this should fix #592. somebody please check.
nenolod
parents:
1672
diff
changeset
|
83 PlaylistEntry *entry = NULL; |
2092 | 84 Playlist *playlist = playlist_get_active(); |
2128
a414866b32bc
[svn] - bail after 15 failures to find an acceptable playback candidate
nenolod
parents:
2105
diff
changeset
|
85 int penalty; |
283 | 86 |
2092 | 87 if (playlist_get_length(playlist) == 0) |
283 | 88 return; |
89 | |
90 if (bmp_playback_get_playing()) | |
91 bmp_playback_stop(); | |
92 | |
93 vis_clear_data(mainwin_vis); | |
94 svis_clear_data(mainwin_svis); | |
95 mainwin_disable_seekbar(); | |
96 | |
2092 | 97 entry = playlist_get_entry_to_play(playlist); |
283 | 98 |
2092 | 99 if (entry == NULL) |
283 | 100 return; |
101 | |
1913
30d40252862d
[svn] - this should fix #592. somebody please check.
nenolod
parents:
1672
diff
changeset
|
102 /* |
30d40252862d
[svn] - this should fix #592. somebody please check.
nenolod
parents:
1672
diff
changeset
|
103 * 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
|
104 * 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
|
105 * |
30d40252862d
[svn] - this should fix #592. somebody please check.
nenolod
parents:
1672
diff
changeset
|
106 * - nenolod |
30d40252862d
[svn] - this should fix #592. somebody please check.
nenolod
parents:
1672
diff
changeset
|
107 */ |
30d40252862d
[svn] - this should fix #592. somebody please check.
nenolod
parents:
1672
diff
changeset
|
108 while (entry != NULL && !bmp_playback_play_file(entry)) |
30d40252862d
[svn] - this should fix #592. somebody please check.
nenolod
parents:
1672
diff
changeset
|
109 { |
2092 | 110 playlist_next(playlist); |
1913
30d40252862d
[svn] - this should fix #592. somebody please check.
nenolod
parents:
1672
diff
changeset
|
111 |
2092 | 112 entry = playlist_get_entry_to_play(playlist); |
1913
30d40252862d
[svn] - this should fix #592. somebody please check.
nenolod
parents:
1672
diff
changeset
|
113 |
2128
a414866b32bc
[svn] - bail after 15 failures to find an acceptable playback candidate
nenolod
parents:
2105
diff
changeset
|
114 /* XXX ew. workaround for a stupid bug where audacious will keep |
a414866b32bc
[svn] - bail after 15 failures to find an acceptable playback candidate
nenolod
parents:
2105
diff
changeset
|
115 * trying to play a file with no valid decoder. |
a414866b32bc
[svn] - bail after 15 failures to find an acceptable playback candidate
nenolod
parents:
2105
diff
changeset
|
116 */ |
1913
30d40252862d
[svn] - this should fix #592. somebody please check.
nenolod
parents:
1672
diff
changeset
|
117 if (entry == NULL) |
30d40252862d
[svn] - this should fix #592. somebody please check.
nenolod
parents:
1672
diff
changeset
|
118 return; |
2128
a414866b32bc
[svn] - bail after 15 failures to find an acceptable playback candidate
nenolod
parents:
2105
diff
changeset
|
119 |
a414866b32bc
[svn] - bail after 15 failures to find an acceptable playback candidate
nenolod
parents:
2105
diff
changeset
|
120 if (entry->decoder == NULL && |
a414866b32bc
[svn] - bail after 15 failures to find an acceptable playback candidate
nenolod
parents:
2105
diff
changeset
|
121 (entry->decoder = input_check_file(entry->filename, FALSE)) == NULL) |
a414866b32bc
[svn] - bail after 15 failures to find an acceptable playback candidate
nenolod
parents:
2105
diff
changeset
|
122 penalty++; |
a414866b32bc
[svn] - bail after 15 failures to find an acceptable playback candidate
nenolod
parents:
2105
diff
changeset
|
123 |
a414866b32bc
[svn] - bail after 15 failures to find an acceptable playback candidate
nenolod
parents:
2105
diff
changeset
|
124 /* if we hit 15 entries in a row with no valid decoder, just |
a414866b32bc
[svn] - bail after 15 failures to find an acceptable playback candidate
nenolod
parents:
2105
diff
changeset
|
125 * bail due to confusion |
a414866b32bc
[svn] - bail after 15 failures to find an acceptable playback candidate
nenolod
parents:
2105
diff
changeset
|
126 */ |
a414866b32bc
[svn] - bail after 15 failures to find an acceptable playback candidate
nenolod
parents:
2105
diff
changeset
|
127 if (penalty > 15) |
a414866b32bc
[svn] - bail after 15 failures to find an acceptable playback candidate
nenolod
parents:
2105
diff
changeset
|
128 return; |
1913
30d40252862d
[svn] - this should fix #592. somebody please check.
nenolod
parents:
1672
diff
changeset
|
129 } |
283 | 130 |
131 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
|
132 equalizerwin_load_auto_preset(entry->filename); |
283 | 133 input_set_eq(cfg.equalizer_active, cfg.equalizer_preamp, |
134 cfg.equalizer_bands); | |
135 output_set_eq(cfg.equalizer_active, cfg.equalizer_preamp, | |
136 cfg.equalizer_bands); | |
137 } | |
138 | |
2092 | 139 playlist_check_pos_current(playlist); |
283 | 140 mainwin_set_info_text(); |
141 } | |
142 | |
143 void | |
144 bmp_playback_pause(void) | |
145 { | |
146 if (!bmp_playback_get_playing()) | |
147 return; | |
148 | |
149 if (!get_current_input_plugin()) | |
150 return; | |
151 | |
152 ip_data.paused = !ip_data.paused; | |
153 | |
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
|
154 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
|
155 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
|
156 |
600efc52c645
[svn] - be careful about referencing a NULL widget (e.g. headless/serveronly mode crashes on streams, bug #562)
nenolod
parents:
1653
diff
changeset
|
157 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
|
158 |
283 | 159 if (ip_data.paused) |
160 playstatus_set_status(mainwin_playstatus, STATUS_PAUSE); | |
161 else | |
162 playstatus_set_status(mainwin_playstatus, STATUS_PLAY); | |
163 } | |
164 | |
165 void | |
166 bmp_playback_stop(void) | |
167 { | |
168 if (ip_data.playing && get_current_input_plugin()) { | |
169 | |
2160
fe6e7b9b4aac
[svn] - suppress noise on transition from pause to stop.
yaz
parents:
2155
diff
changeset
|
170 if (bmp_playback_get_paused()) { |
fe6e7b9b4aac
[svn] - suppress noise on transition from pause to stop.
yaz
parents:
2155
diff
changeset
|
171 output_flush(get_written_time()); /* to avoid noise */ |
283 | 172 bmp_playback_pause(); |
2160
fe6e7b9b4aac
[svn] - suppress noise on transition from pause to stop.
yaz
parents:
2155
diff
changeset
|
173 } |
283 | 174 |
2155
840263ee3a5c
[svn] - fix the logic of bmp_playback_stop(). now JTF works well even if the playing is paused.
yaz
parents:
2128
diff
changeset
|
175 ip_data.playing = FALSE; |
840263ee3a5c
[svn] - fix the logic of bmp_playback_stop(). now JTF works well even if the playing is paused.
yaz
parents:
2128
diff
changeset
|
176 |
283 | 177 if (get_current_input_plugin()->stop) |
178 get_current_input_plugin()->stop(); | |
179 | |
180 free_vis_data(); | |
181 ip_data.paused = FALSE; | |
182 | |
183 if (input_info_text) { | |
184 g_free(input_info_text); | |
185 input_info_text = NULL; | |
186 mainwin_set_info_text(); | |
187 } | |
188 } | |
189 | |
1273
3b990c26fc46
[svn] - Support for the buffer indicator in playpaus.png that was apparently
nhjm449
parents:
890
diff
changeset
|
190 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
|
191 ip_data.playing = FALSE; |
2160
fe6e7b9b4aac
[svn] - suppress noise on transition from pause to stop.
yaz
parents:
2155
diff
changeset
|
192 |
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
|
193 g_return_if_fail(mainwin_playstatus != NULL); |
1653 | 194 playstatus_set_status_buffering(mainwin_playstatus, FALSE); |
283 | 195 } |
196 | |
197 void | |
198 bmp_playback_stop_reentrant(void) | |
199 { | |
200 if (ip_data.playing && get_current_input_plugin()) { | |
201 | |
202 if (bmp_playback_get_paused()) | |
203 bmp_playback_pause(); | |
204 | |
2160
fe6e7b9b4aac
[svn] - suppress noise on transition from pause to stop.
yaz
parents:
2155
diff
changeset
|
205 ip_data.playing = FALSE; |
fe6e7b9b4aac
[svn] - suppress noise on transition from pause to stop.
yaz
parents:
2155
diff
changeset
|
206 |
283 | 207 free_vis_data(); |
208 ip_data.paused = FALSE; | |
209 | |
210 if (input_info_text) { | |
211 g_free(input_info_text); | |
212 input_info_text = NULL; | |
213 mainwin_set_info_text(); | |
214 } | |
215 } | |
216 | |
1273
3b990c26fc46
[svn] - Support for the buffer indicator in playpaus.png that was apparently
nhjm449
parents:
890
diff
changeset
|
217 ip_data.buffering = FALSE; |
283 | 218 ip_data.playing = FALSE; |
219 } | |
220 | |
221 static void | |
222 run_no_output_plugin_dialog(void) | |
223 { | |
224 const gchar *markup = | |
225 N_("<b><big>No output plugin selected.</big></b>\n" | |
226 "You have not selected an output plugin."); | |
227 | |
228 GtkWidget *dialog = | |
1653 | 229 gtk_message_dialog_new_with_markup(GTK_WINDOW(mainwin), |
283 | 230 GTK_DIALOG_DESTROY_WITH_PARENT, |
231 GTK_MESSAGE_ERROR, | |
232 GTK_BUTTONS_OK, | |
233 _(markup)); | |
234 gtk_dialog_run(GTK_DIALOG(dialog)); | |
235 gtk_widget_destroy(dialog); | |
236 } | |
237 | |
238 gboolean | |
398
f908bcd87c3d
[svn] Generate cache content on demand if it was not previously there.
nenolod
parents:
385
diff
changeset
|
239 bmp_playback_play_file(PlaylistEntry *entry) |
283 | 240 { |
356
99928e1275a1
[svn] This commit reduces the amount of times we probe a source down to ONE
nenolod
parents:
283
diff
changeset
|
241 g_return_val_if_fail(entry != NULL, FALSE); |
283 | 242 |
243 if (!get_current_output_plugin()) { | |
244 run_no_output_plugin_dialog(); | |
245 mainwin_stop_pushed(); | |
246 return FALSE; | |
247 } | |
248 | |
249 if (cfg.random_skin_on_play) | |
250 bmp_playback_set_random_skin(); | |
251 | |
677
f52f596dc0d8
[svn] - Working exception handling at no extra charge. Closes bugs #408, #409.
nenolod
parents:
561
diff
changeset
|
252 /* |
f52f596dc0d8
[svn] - Working exception handling at no extra charge. Closes bugs #408, #409.
nenolod
parents:
561
diff
changeset
|
253 * 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
|
254 * 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
|
255 * - nenolod |
f52f596dc0d8
[svn] - Working exception handling at no extra charge. Closes bugs #408, #409.
nenolod
parents:
561
diff
changeset
|
256 */ |
f52f596dc0d8
[svn] - Working exception handling at no extra charge. Closes bugs #408, #409.
nenolod
parents:
561
diff
changeset
|
257 if (!entry->decoder && |
678 | 258 (((entry->decoder = input_check_file(entry->filename, FALSE)) == NULL) || |
259 !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
|
260 { |
99928e1275a1
[svn] This commit reduces the amount of times we probe a source down to ONE
nenolod
parents:
283
diff
changeset
|
261 input_file_not_playable(entry->filename); |
283 | 262 |
356
99928e1275a1
[svn] This commit reduces the amount of times we probe a source down to ONE
nenolod
parents:
283
diff
changeset
|
263 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
|
264 mainwin_set_info_text(); |
283 | 265 |
356
99928e1275a1
[svn] This commit reduces the amount of times we probe a source down to ONE
nenolod
parents:
283
diff
changeset
|
266 return FALSE; |
283 | 267 } |
268 | |
356
99928e1275a1
[svn] This commit reduces the amount of times we probe a source down to ONE
nenolod
parents:
283
diff
changeset
|
269 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
|
270 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
|
271 entry->decoder->play_file(entry->filename); |
283 | 272 |
356
99928e1275a1
[svn] This commit reduces the amount of times we probe a source down to ONE
nenolod
parents:
283
diff
changeset
|
273 ip_data.playing = TRUE; |
283 | 274 |
356
99928e1275a1
[svn] This commit reduces the amount of times we probe a source down to ONE
nenolod
parents:
283
diff
changeset
|
275 return TRUE; |
283 | 276 } |
277 | |
278 gboolean | |
279 bmp_playback_get_playing(void) | |
280 { | |
281 return ip_data.playing; | |
282 } | |
283 | |
284 gboolean | |
285 bmp_playback_get_paused(void) | |
286 { | |
287 return ip_data.paused; | |
288 } | |
289 | |
290 void | |
291 bmp_playback_seek(gint time) | |
292 { | |
293 gboolean restore_pause = FALSE; | |
294 gint l=0, r=0; | |
295 | |
296 if (!ip_data.playing) | |
297 return; | |
298 | |
299 if (!get_current_input_plugin()) | |
300 return; | |
301 | |
302 /* FIXME WORKAROUND...that should work with all plugins | |
303 * 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
|
304 * -Patrick Sudowe |
f52f596dc0d8
[svn] - Working exception handling at no extra charge. Closes bugs #408, #409.
nenolod
parents:
561
diff
changeset
|
305 */ |
283 | 306 if(ip_data.paused) |
307 { | |
308 restore_pause = TRUE; | |
309 output_get_volume(&l, &r); | |
310 output_set_volume(0,0); | |
311 bmp_playback_pause(); | |
312 } | |
313 | |
314 free_vis_data(); | |
315 get_current_input_plugin()->seek(time); | |
316 | |
317 if(restore_pause) | |
318 { | |
319 bmp_playback_pause(); | |
320 output_set_volume(l, r); | |
321 } | |
322 } | |
323 | |
324 void | |
325 bmp_playback_seek_relative(gint offset) | |
326 { | |
327 gint time = CLAMP(bmp_playback_get_time() / 1000 + offset, | |
2092 | 328 0, playlist_get_current_length(playlist_get_active()) / 1000 - 1); |
283 | 329 bmp_playback_seek(time); |
330 } |