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