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