Mercurial > audlegacy
annotate src/audacious/playback.c @ 2420:b23f52fe132f trunk
[svn] Removed util.* from libaudacious
Removed my C++ comments from ui_fileopener.c
Cleanups
author | mf0102 |
---|---|
date | Sat, 27 Jan 2007 04:07:46 -0800 |
parents | 0fd7f4f969ad |
children | f346d30bf5ab |
rev | line source |
---|---|
2313 | 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/configdb.h" | |
41 | |
2420 | 42 #include "hook.h" |
2313 | 43 #include "input.h" |
44 #include "main.h" | |
45 #include "ui_equalizer.h" | |
46 #include "output.h" | |
47 #include "playlist.h" | |
2420 | 48 #include "ui_main.h" |
2313 | 49 #include "ui_playlist.h" |
50 #include "ui_skinselector.h" | |
2416
0fd7f4f969ad
[svn] integrated urldecode.* from libaudacious into audacious directory, made separate ui_fileopener.*
mf0102
parents:
2407
diff
changeset
|
51 #include "urldecode.h" |
2313 | 52 #include "util.h" |
53 | |
54 #include "playback.h" | |
55 | |
56 | |
57 /* FIXME: yuck!! this shouldn't be here... */ | |
58 void | |
59 playback_set_random_skin(void) | |
60 { | |
61 SkinNode *node; | |
62 guint32 randval; | |
63 | |
64 /* Get a random value to select the skin to use */ | |
65 randval = g_random_int_range(0, g_list_length(skinlist)); | |
66 node = g_list_nth(skinlist, randval)->data; | |
67 bmp_active_skin_load(node->path); | |
68 } | |
69 | |
70 gint | |
71 playback_get_time(void) | |
72 { | |
2420 | 73 g_return_val_if_fail(playback_get_playing(), -1); |
74 g_return_val_if_fail(get_current_input_plugin(), -1); | |
2313 | 75 |
76 return get_current_input_plugin()->get_time(); | |
77 } | |
78 | |
79 void | |
80 playback_initiate(void) | |
81 { | |
82 PlaylistEntry *entry = NULL; | |
83 Playlist *playlist = playlist_get_active(); | |
84 gint penalty = 0; | |
85 | |
2420 | 86 g_return_if_fail(playlist_get_length(playlist) != 0); |
2313 | 87 |
88 if (playback_get_playing()) | |
89 playback_stop(); | |
90 | |
91 vis_clear_data(mainwin_vis); | |
92 svis_clear_data(mainwin_svis); | |
93 mainwin_disable_seekbar(); | |
94 | |
95 entry = playlist_get_entry_to_play(playlist); | |
2420 | 96 g_return_if_fail(entry != NULL); |
2313 | 97 |
98 /* | |
99 * If the playlist entry cannot be played, try to pick another one. | |
100 * If that does not work, e.g. entry == NULL, then bail. | |
101 * | |
102 * - nenolod | |
103 */ | |
2420 | 104 for (penalty = 0; penalty <= 15 && entry != NULL && !playback_play_file(entry); penalty++) |
2313 | 105 { |
106 playlist_next(playlist); | |
107 | |
108 entry = playlist_get_entry_to_play(playlist); | |
109 | |
2420 | 110 /* XXX ew. workaround for a stupid bug where audacious will keep |
111 * trying to play a file with no valid decoder. | |
112 */ | |
113 g_return_if_fail(entry != NULL); | |
2313 | 114 |
2420 | 115 if (entry->decoder == NULL ) |
116 entry->decoder = input_check_file(entry->filename, FALSE); | |
2313 | 117 |
2420 | 118 /* if we hit 15 entries in a row with no valid decoder, just |
2313 | 119 * bail due to confusion |
2420 | 120 */ |
121 if (penalty == 15) | |
122 return; | |
2313 | 123 } |
124 | |
125 if (playback_get_time() != -1) { | |
126 equalizerwin_load_auto_preset(entry->filename); | |
127 input_set_eq(cfg.equalizer_active, cfg.equalizer_preamp, | |
128 cfg.equalizer_bands); | |
129 output_set_eq(cfg.equalizer_active, cfg.equalizer_preamp, | |
130 cfg.equalizer_bands); | |
131 } | |
132 | |
133 playlist_check_pos_current(playlist); | |
134 mainwin_set_info_text(); | |
2407
1dc1d36d0347
[svn] - add hooks: playback begin, playback end, playlist reached end
nenolod
parents:
2366
diff
changeset
|
135 |
1dc1d36d0347
[svn] - add hooks: playback begin, playback end, playlist reached end
nenolod
parents:
2366
diff
changeset
|
136 hook_call("playback begin", entry); |
2313 | 137 } |
138 | |
139 void | |
140 playback_pause(void) | |
141 { | |
142 if (!playback_get_playing()) | |
143 return; | |
144 | |
145 if (!get_current_input_plugin()) | |
146 return; | |
147 | |
148 ip_data.paused = !ip_data.paused; | |
149 | |
150 if (get_current_input_plugin()->pause) | |
151 get_current_input_plugin()->pause(ip_data.paused); | |
152 | |
153 g_return_if_fail(mainwin_playstatus != NULL); | |
154 | |
155 if (ip_data.paused) | |
156 playstatus_set_status(mainwin_playstatus, STATUS_PAUSE); | |
157 else | |
158 playstatus_set_status(mainwin_playstatus, STATUS_PLAY); | |
159 } | |
160 | |
161 void | |
162 playback_stop(void) | |
163 { | |
164 if (ip_data.playing && get_current_input_plugin()) { | |
165 | |
166 if (playback_get_paused()) { | |
167 output_flush(get_written_time()); /* to avoid noise */ | |
168 playback_pause(); | |
169 } | |
170 | |
171 ip_data.playing = FALSE; | |
172 | |
173 if (get_current_input_plugin()->stop) | |
174 get_current_input_plugin()->stop(); | |
175 | |
176 free_vis_data(); | |
177 ip_data.paused = FALSE; | |
178 | |
179 if (input_info_text) { | |
180 g_free(input_info_text); | |
181 input_info_text = NULL; | |
182 mainwin_set_info_text(); | |
183 } | |
184 } | |
185 | |
186 ip_data.buffering = FALSE; | |
187 ip_data.playing = FALSE; | |
188 | |
189 g_return_if_fail(mainwin_playstatus != NULL); | |
190 playstatus_set_status_buffering(mainwin_playstatus, FALSE); | |
191 } | |
192 | |
193 static void | |
194 run_no_output_plugin_dialog(void) | |
195 { | |
196 const gchar *markup = | |
197 N_("<b><big>No output plugin selected.</big></b>\n" | |
198 "You have not selected an output plugin."); | |
199 | |
200 GtkWidget *dialog = | |
201 gtk_message_dialog_new_with_markup(GTK_WINDOW(mainwin), | |
202 GTK_DIALOG_DESTROY_WITH_PARENT, | |
203 GTK_MESSAGE_ERROR, | |
204 GTK_BUTTONS_OK, | |
205 _(markup)); | |
206 gtk_dialog_run(GTK_DIALOG(dialog)); | |
207 gtk_widget_destroy(dialog); | |
208 } | |
209 | |
210 gboolean | |
211 playback_play_file(PlaylistEntry *entry) | |
212 { | |
213 g_return_val_if_fail(entry != NULL, FALSE); | |
214 | |
215 if (!get_current_output_plugin()) { | |
216 run_no_output_plugin_dialog(); | |
217 mainwin_stop_pushed(); | |
218 return FALSE; | |
219 } | |
220 | |
221 if (cfg.random_skin_on_play) | |
222 playback_set_random_skin(); | |
223 | |
224 /* | |
225 * This is slightly uglier than the original version, but should | |
226 * fix the "crash" issues as seen in 0.2 when dealing with this situation. | |
227 * - nenolod | |
228 */ | |
229 if (!entry->decoder && | |
2420 | 230 (((entry->decoder = input_check_file(entry->filename, FALSE)) == NULL) || |
2313 | 231 !input_is_enabled(entry->decoder->filename))) |
232 { | |
233 input_file_not_playable(entry->filename); | |
234 | |
235 set_current_input_plugin(NULL); | |
236 mainwin_set_info_text(); | |
237 | |
238 return FALSE; | |
239 } | |
240 | |
241 set_current_input_plugin(entry->decoder); | |
242 entry->decoder->output = &psuedo_output_plugin; | |
243 entry->decoder->play_file(entry->filename); | |
244 | |
245 ip_data.playing = TRUE; | |
246 | |
247 return TRUE; | |
248 } | |
249 | |
250 gboolean | |
251 playback_get_playing(void) | |
252 { | |
253 return ip_data.playing; | |
254 } | |
255 | |
256 gboolean | |
257 playback_get_paused(void) | |
258 { | |
259 return ip_data.paused; | |
260 } | |
261 | |
262 void | |
263 playback_seek(gint time) | |
264 { | |
265 gboolean restore_pause = FALSE; | |
266 gint l=0, r=0; | |
267 | |
2420 | 268 g_return_if_fail(ip_data.playing); |
269 g_return_if_fail(get_current_input_plugin()); | |
2313 | 270 |
271 /* FIXME WORKAROUND...that should work with all plugins | |
272 * mute the volume, start playback again, do the seek, then pause again | |
273 * -Patrick Sudowe | |
274 */ | |
2420 | 275 if (ip_data.paused) |
2313 | 276 { |
2420 | 277 restore_pause = TRUE; |
278 output_get_volume(&l, &r); | |
279 output_set_volume(0,0); | |
280 playback_pause(); | |
2313 | 281 } |
282 | |
283 free_vis_data(); | |
284 get_current_input_plugin()->seek(time); | |
285 | |
2420 | 286 if (restore_pause) |
2313 | 287 { |
2420 | 288 playback_pause(); |
289 output_set_volume(l, r); | |
2313 | 290 } |
291 } | |
292 | |
293 void | |
294 playback_seek_relative(gint offset) | |
295 { | |
296 gint time = CLAMP(playback_get_time() / 1000 + offset, | |
297 0, playlist_get_current_length(playlist_get_active()) / 1000 - 1); | |
298 playback_seek(time); | |
299 } |