Mercurial > audlegacy
annotate src/audacious/playback.c @ 2597:4ce36bfe9cf7 trunk
[svn] - correct a keyboard shortcut collision. closes #824.
author | nenolod |
---|---|
date | Thu, 01 Mar 2007 08:22:32 -0800 |
parents | 6f7be3702c5f |
children | 2ba01bb7e36a |
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 gint | |
58 playback_get_time(void) | |
59 { | |
2438
8750a62abed8
[svn] Provide flags in InputPlayback for common plugin flag needs, and provide a
iabervon
parents:
2436
diff
changeset
|
60 InputPlayback *playback; |
2420 | 61 g_return_val_if_fail(playback_get_playing(), -1); |
2438
8750a62abed8
[svn] Provide flags in InputPlayback for common plugin flag needs, and provide a
iabervon
parents:
2436
diff
changeset
|
62 playback = get_current_input_playback(); |
8750a62abed8
[svn] Provide flags in InputPlayback for common plugin flag needs, and provide a
iabervon
parents:
2436
diff
changeset
|
63 g_return_val_if_fail(playback, -1); |
2313 | 64 |
2438
8750a62abed8
[svn] Provide flags in InputPlayback for common plugin flag needs, and provide a
iabervon
parents:
2436
diff
changeset
|
65 if (playback->plugin->get_time) |
8750a62abed8
[svn] Provide flags in InputPlayback for common plugin flag needs, and provide a
iabervon
parents:
2436
diff
changeset
|
66 return playback->plugin->get_time(playback); |
8750a62abed8
[svn] Provide flags in InputPlayback for common plugin flag needs, and provide a
iabervon
parents:
2436
diff
changeset
|
67 if (playback->error) |
8750a62abed8
[svn] Provide flags in InputPlayback for common plugin flag needs, and provide a
iabervon
parents:
2436
diff
changeset
|
68 return -2; |
8750a62abed8
[svn] Provide flags in InputPlayback for common plugin flag needs, and provide a
iabervon
parents:
2436
diff
changeset
|
69 if (!playback->playing || |
8750a62abed8
[svn] Provide flags in InputPlayback for common plugin flag needs, and provide a
iabervon
parents:
2436
diff
changeset
|
70 (playback->eof && !playback->output->buffer_playing())) |
8750a62abed8
[svn] Provide flags in InputPlayback for common plugin flag needs, and provide a
iabervon
parents:
2436
diff
changeset
|
71 return -1; |
8750a62abed8
[svn] Provide flags in InputPlayback for common plugin flag needs, and provide a
iabervon
parents:
2436
diff
changeset
|
72 return playback->output->output_time(); |
2313 | 73 } |
74 | |
75 void | |
76 playback_initiate(void) | |
77 { | |
78 PlaylistEntry *entry = NULL; | |
79 Playlist *playlist = playlist_get_active(); | |
80 | |
2420 | 81 g_return_if_fail(playlist_get_length(playlist) != 0); |
2313 | 82 |
83 if (playback_get_playing()) | |
84 playback_stop(); | |
85 | |
86 vis_clear_data(mainwin_vis); | |
87 svis_clear_data(mainwin_svis); | |
88 mainwin_disable_seekbar(); | |
89 | |
90 entry = playlist_get_entry_to_play(playlist); | |
2420 | 91 g_return_if_fail(entry != NULL); |
2592
6f7be3702c5f
[svn] - revert the penalty-based "find something to play" logic of 1.2. it's
nenolod
parents:
2454
diff
changeset
|
92 playback_play_file(entry); |
2313 | 93 |
94 if (playback_get_time() != -1) { | |
95 equalizerwin_load_auto_preset(entry->filename); | |
96 input_set_eq(cfg.equalizer_active, cfg.equalizer_preamp, | |
97 cfg.equalizer_bands); | |
98 output_set_eq(cfg.equalizer_active, cfg.equalizer_preamp, | |
99 cfg.equalizer_bands); | |
100 } | |
101 | |
102 playlist_check_pos_current(playlist); | |
103 mainwin_set_info_text(); | |
2407
1dc1d36d0347
[svn] - add hooks: playback begin, playback end, playlist reached end
nenolod
parents:
2366
diff
changeset
|
104 |
1dc1d36d0347
[svn] - add hooks: playback begin, playback end, playlist reached end
nenolod
parents:
2366
diff
changeset
|
105 hook_call("playback begin", entry); |
2313 | 106 } |
107 | |
108 void | |
109 playback_pause(void) | |
110 { | |
111 if (!playback_get_playing()) | |
112 return; | |
113 | |
2436
f346d30bf5ab
[svn] Change the input plugin API to use a struct for the currently-playing file.
iabervon
parents:
2420
diff
changeset
|
114 if (!get_current_input_playback()) |
2313 | 115 return; |
116 | |
117 ip_data.paused = !ip_data.paused; | |
118 | |
2436
f346d30bf5ab
[svn] Change the input plugin API to use a struct for the currently-playing file.
iabervon
parents:
2420
diff
changeset
|
119 if (get_current_input_playback()->plugin->pause) |
f346d30bf5ab
[svn] Change the input plugin API to use a struct for the currently-playing file.
iabervon
parents:
2420
diff
changeset
|
120 get_current_input_playback()->plugin->pause(get_current_input_playback(), |
f346d30bf5ab
[svn] Change the input plugin API to use a struct for the currently-playing file.
iabervon
parents:
2420
diff
changeset
|
121 ip_data.paused); |
2313 | 122 |
123 g_return_if_fail(mainwin_playstatus != NULL); | |
124 | |
125 if (ip_data.paused) | |
126 playstatus_set_status(mainwin_playstatus, STATUS_PAUSE); | |
127 else | |
128 playstatus_set_status(mainwin_playstatus, STATUS_PLAY); | |
129 } | |
130 | |
131 void | |
132 playback_stop(void) | |
133 { | |
2436
f346d30bf5ab
[svn] Change the input plugin API to use a struct for the currently-playing file.
iabervon
parents:
2420
diff
changeset
|
134 if (ip_data.playing && get_current_input_playback()) { |
2313 | 135 |
136 if (playback_get_paused()) { | |
137 output_flush(get_written_time()); /* to avoid noise */ | |
138 playback_pause(); | |
139 } | |
140 | |
141 ip_data.playing = FALSE; | |
142 | |
2436
f346d30bf5ab
[svn] Change the input plugin API to use a struct for the currently-playing file.
iabervon
parents:
2420
diff
changeset
|
143 if (get_current_input_playback()->plugin->stop) |
f346d30bf5ab
[svn] Change the input plugin API to use a struct for the currently-playing file.
iabervon
parents:
2420
diff
changeset
|
144 get_current_input_playback()->plugin->stop(get_current_input_playback()); |
2313 | 145 |
146 free_vis_data(); | |
147 ip_data.paused = FALSE; | |
148 | |
149 if (input_info_text) { | |
150 g_free(input_info_text); | |
151 input_info_text = NULL; | |
152 mainwin_set_info_text(); | |
153 } | |
2436
f346d30bf5ab
[svn] Change the input plugin API to use a struct for the currently-playing file.
iabervon
parents:
2420
diff
changeset
|
154 |
2438
8750a62abed8
[svn] Provide flags in InputPlayback for common plugin flag needs, and provide a
iabervon
parents:
2436
diff
changeset
|
155 g_free(get_current_input_playback()->filename); |
2436
f346d30bf5ab
[svn] Change the input plugin API to use a struct for the currently-playing file.
iabervon
parents:
2420
diff
changeset
|
156 g_free(get_current_input_playback()); |
f346d30bf5ab
[svn] Change the input plugin API to use a struct for the currently-playing file.
iabervon
parents:
2420
diff
changeset
|
157 set_current_input_playback(NULL); |
2313 | 158 } |
159 | |
160 ip_data.buffering = FALSE; | |
161 ip_data.playing = FALSE; | |
162 | |
163 g_return_if_fail(mainwin_playstatus != NULL); | |
164 playstatus_set_status_buffering(mainwin_playstatus, FALSE); | |
165 } | |
166 | |
167 static void | |
168 run_no_output_plugin_dialog(void) | |
169 { | |
170 const gchar *markup = | |
171 N_("<b><big>No output plugin selected.</big></b>\n" | |
172 "You have not selected an output plugin."); | |
173 | |
174 GtkWidget *dialog = | |
175 gtk_message_dialog_new_with_markup(GTK_WINDOW(mainwin), | |
176 GTK_DIALOG_DESTROY_WITH_PARENT, | |
177 GTK_MESSAGE_ERROR, | |
178 GTK_BUTTONS_OK, | |
179 _(markup)); | |
180 gtk_dialog_run(GTK_DIALOG(dialog)); | |
181 gtk_widget_destroy(dialog); | |
182 } | |
183 | |
184 gboolean | |
185 playback_play_file(PlaylistEntry *entry) | |
186 { | |
2436
f346d30bf5ab
[svn] Change the input plugin API to use a struct for the currently-playing file.
iabervon
parents:
2420
diff
changeset
|
187 InputPlayback * playback; |
2313 | 188 g_return_val_if_fail(entry != NULL, FALSE); |
189 | |
190 if (!get_current_output_plugin()) { | |
191 run_no_output_plugin_dialog(); | |
192 mainwin_stop_pushed(); | |
193 return FALSE; | |
194 } | |
195 | |
196 if (cfg.random_skin_on_play) | |
2443
93686e8815a4
[svn] - Changed playback_set_random_skin() to skin_set_random_skin()
mf0102
parents:
2438
diff
changeset
|
197 skin_set_random_skin(); |
2313 | 198 |
199 /* | |
200 * This is slightly uglier than the original version, but should | |
201 * fix the "crash" issues as seen in 0.2 when dealing with this situation. | |
202 * - nenolod | |
203 */ | |
204 if (!entry->decoder && | |
2420 | 205 (((entry->decoder = input_check_file(entry->filename, FALSE)) == NULL) || |
2313 | 206 !input_is_enabled(entry->decoder->filename))) |
207 { | |
208 input_file_not_playable(entry->filename); | |
209 | |
2436
f346d30bf5ab
[svn] Change the input plugin API to use a struct for the currently-playing file.
iabervon
parents:
2420
diff
changeset
|
210 set_current_input_playback(NULL); |
2313 | 211 mainwin_set_info_text(); |
212 | |
213 return FALSE; | |
214 } | |
215 | |
2436
f346d30bf5ab
[svn] Change the input plugin API to use a struct for the currently-playing file.
iabervon
parents:
2420
diff
changeset
|
216 playback = g_new0(InputPlayback, 1); |
f346d30bf5ab
[svn] Change the input plugin API to use a struct for the currently-playing file.
iabervon
parents:
2420
diff
changeset
|
217 |
2313 | 218 entry->decoder->output = &psuedo_output_plugin; |
2436
f346d30bf5ab
[svn] Change the input plugin API to use a struct for the currently-playing file.
iabervon
parents:
2420
diff
changeset
|
219 |
f346d30bf5ab
[svn] Change the input plugin API to use a struct for the currently-playing file.
iabervon
parents:
2420
diff
changeset
|
220 playback->plugin = entry->decoder; |
f346d30bf5ab
[svn] Change the input plugin API to use a struct for the currently-playing file.
iabervon
parents:
2420
diff
changeset
|
221 playback->output = &psuedo_output_plugin; |
2438
8750a62abed8
[svn] Provide flags in InputPlayback for common plugin flag needs, and provide a
iabervon
parents:
2436
diff
changeset
|
222 playback->filename = g_strdup(entry->filename); |
2436
f346d30bf5ab
[svn] Change the input plugin API to use a struct for the currently-playing file.
iabervon
parents:
2420
diff
changeset
|
223 |
f346d30bf5ab
[svn] Change the input plugin API to use a struct for the currently-playing file.
iabervon
parents:
2420
diff
changeset
|
224 set_current_input_playback(playback); |
f346d30bf5ab
[svn] Change the input plugin API to use a struct for the currently-playing file.
iabervon
parents:
2420
diff
changeset
|
225 |
f346d30bf5ab
[svn] Change the input plugin API to use a struct for the currently-playing file.
iabervon
parents:
2420
diff
changeset
|
226 entry->decoder->play_file(playback); |
2313 | 227 |
228 ip_data.playing = TRUE; | |
229 | |
230 return TRUE; | |
231 } | |
232 | |
233 gboolean | |
234 playback_get_playing(void) | |
235 { | |
236 return ip_data.playing; | |
237 } | |
238 | |
239 gboolean | |
240 playback_get_paused(void) | |
241 { | |
242 return ip_data.paused; | |
243 } | |
244 | |
245 void | |
246 playback_seek(gint time) | |
247 { | |
248 gboolean restore_pause = FALSE; | |
249 gint l=0, r=0; | |
250 | |
2420 | 251 g_return_if_fail(ip_data.playing); |
2436
f346d30bf5ab
[svn] Change the input plugin API to use a struct for the currently-playing file.
iabervon
parents:
2420
diff
changeset
|
252 g_return_if_fail(get_current_input_playback()); |
2313 | 253 |
254 /* FIXME WORKAROUND...that should work with all plugins | |
255 * mute the volume, start playback again, do the seek, then pause again | |
256 * -Patrick Sudowe | |
257 */ | |
2420 | 258 if (ip_data.paused) |
2313 | 259 { |
2420 | 260 restore_pause = TRUE; |
261 output_get_volume(&l, &r); | |
262 output_set_volume(0,0); | |
263 playback_pause(); | |
2313 | 264 } |
265 | |
266 free_vis_data(); | |
2454 | 267 get_current_input_playback()->plugin->seek(get_current_input_playback(), time); |
2313 | 268 |
2420 | 269 if (restore_pause) |
2313 | 270 { |
2420 | 271 playback_pause(); |
272 output_set_volume(l, r); | |
2313 | 273 } |
274 } | |
275 | |
276 void | |
277 playback_seek_relative(gint offset) | |
278 { | |
279 gint time = CLAMP(playback_get_time() / 1000 + offset, | |
280 0, playlist_get_current_length(playlist_get_active()) / 1000 - 1); | |
281 playback_seek(time); | |
282 } |