Mercurial > audlegacy
annotate audacious/playback.c @ 1621:fae6e0cfcc77 trunk
[svn] - Reapply r2161
author | nhjm449 |
---|---|
date | Tue, 05 Sep 2006 19:57:18 -0700 |
parents | 06329cbf186a |
children | f3934d790a2e |
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" | |
43 #include "mainwin.h" | |
44 #include "equalizer.h" | |
45 #include "output.h" | |
46 #include "playlist.h" | |
385 | 47 #include "ui_playlist.h" |
283 | 48 #include "skinwin.h" |
49 #include "urldecode.h" | |
50 #include "util.h" | |
51 | |
52 | |
53 #include "playback.h" | |
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 } | |
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 { | |
398
f908bcd87c3d
[svn] Generate cache content on demand if it was not previously there.
nenolod
parents:
385
diff
changeset
|
84 PlaylistEntry *entry; |
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 | |
356
99928e1275a1
[svn] This commit reduces the amount of times we probe a source down to ONE
nenolod
parents:
283
diff
changeset
|
101 if (!bmp_playback_play_file(entry)) |
283 | 102 return; |
103 | |
104 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
|
105 equalizerwin_load_auto_preset(entry->filename); |
283 | 106 input_set_eq(cfg.equalizer_active, cfg.equalizer_preamp, |
107 cfg.equalizer_bands); | |
108 output_set_eq(cfg.equalizer_active, cfg.equalizer_preamp, | |
109 cfg.equalizer_bands); | |
110 } | |
111 | |
112 playlist_check_pos_current(); | |
113 mainwin_set_info_text(); | |
114 } | |
115 | |
116 void | |
117 bmp_playback_pause(void) | |
118 { | |
119 if (!bmp_playback_get_playing()) | |
120 return; | |
121 | |
122 if (!get_current_input_plugin()) | |
123 return; | |
124 | |
125 ip_data.paused = !ip_data.paused; | |
126 | |
127 if (ip_data.paused) | |
128 playstatus_set_status(mainwin_playstatus, STATUS_PAUSE); | |
129 else | |
130 playstatus_set_status(mainwin_playstatus, STATUS_PLAY); | |
131 | |
132 if (get_current_input_plugin()->pause) | |
133 get_current_input_plugin()->pause(ip_data.paused); | |
134 } | |
135 | |
136 void | |
137 bmp_playback_stop(void) | |
138 { | |
139 if (ip_data.playing && get_current_input_plugin()) { | |
140 ip_data.playing = FALSE; | |
141 | |
142 if (bmp_playback_get_paused()) | |
143 bmp_playback_pause(); | |
144 | |
145 if (get_current_input_plugin()->stop) | |
146 get_current_input_plugin()->stop(); | |
147 | |
148 free_vis_data(); | |
149 ip_data.paused = FALSE; | |
150 | |
151 if (input_info_text) { | |
152 g_free(input_info_text); | |
153 input_info_text = NULL; | |
154 mainwin_set_info_text(); | |
155 } | |
156 } | |
157 | |
1273
3b990c26fc46
[svn] - Support for the buffer indicator in playpaus.png that was apparently
nhjm449
parents:
890
diff
changeset
|
158 ip_data.buffering = FALSE; |
3b990c26fc46
[svn] - Support for the buffer indicator in playpaus.png that was apparently
nhjm449
parents:
890
diff
changeset
|
159 playstatus_set_status_buffering(mainwin_playstatus, FALSE); |
283 | 160 ip_data.playing = FALSE; |
161 } | |
162 | |
163 void | |
164 bmp_playback_stop_reentrant(void) | |
165 { | |
166 if (ip_data.playing && get_current_input_plugin()) { | |
167 ip_data.playing = FALSE; | |
168 | |
169 if (bmp_playback_get_paused()) | |
170 bmp_playback_pause(); | |
171 | |
172 free_vis_data(); | |
173 ip_data.paused = FALSE; | |
174 | |
175 if (input_info_text) { | |
176 g_free(input_info_text); | |
177 input_info_text = NULL; | |
178 mainwin_set_info_text(); | |
179 } | |
180 } | |
181 | |
1273
3b990c26fc46
[svn] - Support for the buffer indicator in playpaus.png that was apparently
nhjm449
parents:
890
diff
changeset
|
182 ip_data.buffering = FALSE; |
283 | 183 ip_data.playing = FALSE; |
184 } | |
185 | |
186 static void | |
187 run_no_output_plugin_dialog(void) | |
188 { | |
189 const gchar *markup = | |
190 N_("<b><big>No output plugin selected.</big></b>\n" | |
191 "You have not selected an output plugin."); | |
192 | |
193 GtkWidget *dialog = | |
194 gtk_message_dialog_new_with_markup(GTK_WINDOW(mainwin), | |
195 GTK_DIALOG_DESTROY_WITH_PARENT, | |
196 GTK_MESSAGE_ERROR, | |
197 GTK_BUTTONS_OK, | |
198 _(markup)); | |
199 gtk_dialog_run(GTK_DIALOG(dialog)); | |
200 gtk_widget_destroy(dialog); | |
201 } | |
202 | |
203 gboolean | |
398
f908bcd87c3d
[svn] Generate cache content on demand if it was not previously there.
nenolod
parents:
385
diff
changeset
|
204 bmp_playback_play_file(PlaylistEntry *entry) |
283 | 205 { |
356
99928e1275a1
[svn] This commit reduces the amount of times we probe a source down to ONE
nenolod
parents:
283
diff
changeset
|
206 g_return_val_if_fail(entry != NULL, FALSE); |
283 | 207 |
208 if (!get_current_output_plugin()) { | |
209 run_no_output_plugin_dialog(); | |
210 mainwin_stop_pushed(); | |
211 return FALSE; | |
212 } | |
213 | |
214 if (cfg.random_skin_on_play) | |
215 bmp_playback_set_random_skin(); | |
216 | |
677
f52f596dc0d8
[svn] - Working exception handling at no extra charge. Closes bugs #408, #409.
nenolod
parents:
561
diff
changeset
|
217 /* |
f52f596dc0d8
[svn] - Working exception handling at no extra charge. Closes bugs #408, #409.
nenolod
parents:
561
diff
changeset
|
218 * 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
|
219 * 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
|
220 * - nenolod |
f52f596dc0d8
[svn] - Working exception handling at no extra charge. Closes bugs #408, #409.
nenolod
parents:
561
diff
changeset
|
221 */ |
f52f596dc0d8
[svn] - Working exception handling at no extra charge. Closes bugs #408, #409.
nenolod
parents:
561
diff
changeset
|
222 if (!entry->decoder && |
678 | 223 (((entry->decoder = input_check_file(entry->filename, FALSE)) == NULL) || |
224 !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
|
225 { |
99928e1275a1
[svn] This commit reduces the amount of times we probe a source down to ONE
nenolod
parents:
283
diff
changeset
|
226 input_file_not_playable(entry->filename); |
283 | 227 |
356
99928e1275a1
[svn] This commit reduces the amount of times we probe a source down to ONE
nenolod
parents:
283
diff
changeset
|
228 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
|
229 mainwin_set_info_text(); |
283 | 230 |
356
99928e1275a1
[svn] This commit reduces the amount of times we probe a source down to ONE
nenolod
parents:
283
diff
changeset
|
231 return FALSE; |
283 | 232 } |
233 | |
356
99928e1275a1
[svn] This commit reduces the amount of times we probe a source down to ONE
nenolod
parents:
283
diff
changeset
|
234 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
|
235 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
|
236 entry->decoder->play_file(entry->filename); |
283 | 237 |
356
99928e1275a1
[svn] This commit reduces the amount of times we probe a source down to ONE
nenolod
parents:
283
diff
changeset
|
238 ip_data.playing = TRUE; |
283 | 239 |
356
99928e1275a1
[svn] This commit reduces the amount of times we probe a source down to ONE
nenolod
parents:
283
diff
changeset
|
240 return TRUE; |
283 | 241 } |
242 | |
243 gboolean | |
244 bmp_playback_get_playing(void) | |
245 { | |
246 return ip_data.playing; | |
247 } | |
248 | |
249 gboolean | |
250 bmp_playback_get_paused(void) | |
251 { | |
252 return ip_data.paused; | |
253 } | |
254 | |
255 void | |
256 bmp_playback_seek(gint time) | |
257 { | |
258 gboolean restore_pause = FALSE; | |
259 gint l=0, r=0; | |
260 | |
261 if (!ip_data.playing) | |
262 return; | |
263 | |
264 if (!get_current_input_plugin()) | |
265 return; | |
266 | |
267 /* FIXME WORKAROUND...that should work with all plugins | |
268 * 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
|
269 * -Patrick Sudowe |
f52f596dc0d8
[svn] - Working exception handling at no extra charge. Closes bugs #408, #409.
nenolod
parents:
561
diff
changeset
|
270 */ |
283 | 271 if(ip_data.paused) |
272 { | |
273 restore_pause = TRUE; | |
274 output_get_volume(&l, &r); | |
275 output_set_volume(0,0); | |
276 bmp_playback_pause(); | |
277 } | |
278 | |
279 free_vis_data(); | |
280 get_current_input_plugin()->seek(time); | |
281 | |
282 if(restore_pause) | |
283 { | |
284 bmp_playback_pause(); | |
285 output_set_volume(l, r); | |
286 } | |
287 } | |
288 | |
289 void | |
290 bmp_playback_seek_relative(gint offset) | |
291 { | |
292 gint time = CLAMP(bmp_playback_get_time() / 1000 + offset, | |
293 0, playlist_get_current_length() / 1000 - 1); | |
294 bmp_playback_seek(time); | |
295 } |