comparison audacious/playback.c @ 0:cb178e5ad177 trunk

[svn] Import audacious source.
author nenolod
date Mon, 24 Oct 2005 03:06:47 -0700
parents
children 32c320bba8a6
comparison
equal deleted inserted replaced
-1:000000000000 0:cb178e5ad177
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
8 * it under the terms of the GNU General Public Licensse as published by
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
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
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"
47 #include "playlistwin.h"
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 {
86 const gchar *filename = NULL;
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 vis_clear_data(playlistwin_vis);
96 svis_clear_data(mainwin_svis);
97 mainwin_disable_seekbar();
98
99 filename = playlist_get_filename_to_play();
100
101 if (!filename)
102 return;
103
104 if (!bmp_playback_play_file(filename))
105 return;
106
107 if (bmp_playback_get_time() != -1) {
108 equalizerwin_load_auto_preset(filename);
109 input_set_eq(cfg.equalizer_active, cfg.equalizer_preamp,
110 cfg.equalizer_bands);
111 output_set_eq(cfg.equalizer_active, cfg.equalizer_preamp,
112 cfg.equalizer_bands);
113 }
114
115 playlist_check_pos_current();
116 mainwin_set_info_text();
117 }
118
119 void
120 bmp_playback_pause(void)
121 {
122 if (!bmp_playback_get_playing())
123 return;
124
125 if (!get_current_input_plugin())
126 return;
127
128 ip_data.paused = !ip_data.paused;
129
130 if (ip_data.paused)
131 playstatus_set_status(mainwin_playstatus, STATUS_PAUSE);
132 else
133 playstatus_set_status(mainwin_playstatus, STATUS_PLAY);
134
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
160 ip_data.playing = FALSE;
161 }
162
163
164 static void
165 run_no_output_plugin_dialog(void)
166 {
167 const gchar *markup =
168 N_("<b><big>No output plugin selected.</big></b>\n"
169 "You have not selected an output plugin.");
170
171 GtkWidget *dialog =
172 gtk_message_dialog_new_with_markup(GTK_WINDOW(mainwin),
173 GTK_DIALOG_DESTROY_WITH_PARENT,
174 GTK_MESSAGE_ERROR,
175 GTK_BUTTONS_OK,
176 _(markup));
177 gtk_dialog_run(GTK_DIALOG(dialog));
178 gtk_widget_destroy(dialog);
179 }
180
181 gboolean
182 bmp_playback_play_file(const gchar * filename)
183 {
184 GList *node;
185 InputPlugin *ip;
186 gchar *filename_proxy;
187
188 g_return_val_if_fail(filename != 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)
197 bmp_playback_set_random_skin();
198
199 filename_proxy = g_strdup(filename);
200
201 node = get_input_list();
202 node = g_list_first(node);
203
204 while (node) {
205
206 ip = node->data;
207
208 if (!ip)
209 break;
210
211 if (ip && input_is_enabled(ip->filename) &&
212 ip->is_our_file(filename_proxy)) {
213
214
215 set_current_input_plugin(ip);
216 ip->output = get_current_output_plugin();
217 ip->play_file(filename_proxy);
218
219 /* FIXME: Why the hell (yes,hell!) doesn't the input
220 plugin set this itself???? -mderezynski */
221 ip_data.playing = TRUE;
222
223 g_free(filename_proxy);
224 return TRUE;
225 }
226 node = g_list_next(node);
227 }
228
229 input_file_not_playable(filename);
230 set_current_input_plugin(NULL);
231 mainwin_set_info_text();
232
233 g_free(filename_proxy);
234
235 return FALSE;
236 }
237
238 gboolean
239 bmp_playback_get_playing(void)
240 {
241 return ip_data.playing;
242 }
243
244 gboolean
245 bmp_playback_get_paused(void)
246 {
247 return ip_data.paused;
248 }
249
250 void
251 bmp_playback_seek(gint time)
252 {
253 gboolean restore_pause = FALSE;
254 gint l=0, r=0;
255
256 if (!ip_data.playing)
257 return;
258
259 if (!get_current_input_plugin())
260 return;
261
262 /* FIXME WORKAROUND...that should work with all plugins
263 * mute the volume, start playback again, do the seek, then pause again
264 * -Patrick Sudowe */
265 if(ip_data.paused)
266 {
267 restore_pause = TRUE;
268 output_get_volume(&l, &r);
269 output_set_volume(0,0);
270 bmp_playback_pause();
271 }
272
273 free_vis_data();
274 get_current_input_plugin()->seek(time);
275
276 if(restore_pause)
277 {
278 bmp_playback_pause();
279 output_set_volume(l, r);
280 }
281 }
282
283 void
284 bmp_playback_seek_relative(gint offset)
285 {
286 gint time = CLAMP(bmp_playback_get_time() / 1000 + offset,
287 0, playlist_get_current_length() / 1000 - 1);
288 bmp_playback_seek(time);
289 }