Mercurial > audlegacy
annotate libaudcore/playback.c @ 474:f3b46533da81 trunk
[svn] Experimental about box stuff... doesnt work right yet. Work in progress!
author | nenolod |
---|---|
date | Wed, 18 Jan 2006 21:21:50 -0800 |
parents | f908bcd87c3d |
children |
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 | |
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" | |
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 vis_clear_data(playlistwin_vis); | |
96 svis_clear_data(mainwin_svis); | |
97 mainwin_disable_seekbar(); | |
98 | |
356
99928e1275a1
[svn] This commit reduces the amount of times we probe a source down to ONE
nenolod
parents:
283
diff
changeset
|
99 entry = playlist_get_entry_to_play(); |
283 | 100 |
356
99928e1275a1
[svn] This commit reduces the amount of times we probe a source down to ONE
nenolod
parents:
283
diff
changeset
|
101 if (!entry) |
283 | 102 return; |
103 | |
356
99928e1275a1
[svn] This commit reduces the amount of times we probe a source down to ONE
nenolod
parents:
283
diff
changeset
|
104 if (!bmp_playback_play_file(entry)) |
283 | 105 return; |
106 | |
107 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
|
108 equalizerwin_load_auto_preset(entry->filename); |
283 | 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 if (get_current_input_plugin()->pause) | |
136 get_current_input_plugin()->pause(ip_data.paused); | |
137 } | |
138 | |
139 void | |
140 bmp_playback_stop(void) | |
141 { | |
142 if (ip_data.playing && get_current_input_plugin()) { | |
143 ip_data.playing = FALSE; | |
144 | |
145 if (bmp_playback_get_paused()) | |
146 bmp_playback_pause(); | |
147 | |
148 if (get_current_input_plugin()->stop) | |
149 get_current_input_plugin()->stop(); | |
150 | |
151 free_vis_data(); | |
152 ip_data.paused = FALSE; | |
153 | |
154 if (input_info_text) { | |
155 g_free(input_info_text); | |
156 input_info_text = NULL; | |
157 mainwin_set_info_text(); | |
158 } | |
159 } | |
160 | |
161 ip_data.playing = FALSE; | |
162 } | |
163 | |
164 void | |
165 bmp_playback_stop_reentrant(void) | |
166 { | |
167 if (ip_data.playing && get_current_input_plugin()) { | |
168 ip_data.playing = FALSE; | |
169 | |
170 if (bmp_playback_get_paused()) | |
171 bmp_playback_pause(); | |
172 | |
173 free_vis_data(); | |
174 ip_data.paused = FALSE; | |
175 | |
176 if (input_info_text) { | |
177 g_free(input_info_text); | |
178 input_info_text = NULL; | |
179 mainwin_set_info_text(); | |
180 } | |
181 } | |
182 | |
183 ip_data.playing = FALSE; | |
184 } | |
185 | |
186 static void | |
187 run_no_output_plugin_dialog(void) | |
188 { | |
189 const gchar *markup = | |
190 N_("<b><big>No output plugin selected.</big></b>\n" | |
191 "You have not selected an output plugin."); | |
192 | |
193 GtkWidget *dialog = | |
194 gtk_message_dialog_new_with_markup(GTK_WINDOW(mainwin), | |
195 GTK_DIALOG_DESTROY_WITH_PARENT, | |
196 GTK_MESSAGE_ERROR, | |
197 GTK_BUTTONS_OK, | |
198 _(markup)); | |
199 gtk_dialog_run(GTK_DIALOG(dialog)); | |
200 gtk_widget_destroy(dialog); | |
201 } | |
202 | |
203 gboolean | |
398
f908bcd87c3d
[svn] Generate cache content on demand if it was not previously there.
nenolod
parents:
385
diff
changeset
|
204 bmp_playback_play_file(PlaylistEntry *entry) |
283 | 205 { |
356
99928e1275a1
[svn] This commit reduces the amount of times we probe a source down to ONE
nenolod
parents:
283
diff
changeset
|
206 g_return_val_if_fail(entry != NULL, FALSE); |
283 | 207 |
208 if (!get_current_output_plugin()) { | |
209 run_no_output_plugin_dialog(); | |
210 mainwin_stop_pushed(); | |
211 return FALSE; | |
212 } | |
213 | |
214 if (cfg.random_skin_on_play) | |
215 bmp_playback_set_random_skin(); | |
216 | |
398
f908bcd87c3d
[svn] Generate cache content on demand if it was not previously there.
nenolod
parents:
385
diff
changeset
|
217 if (!entry->decoder) |
f908bcd87c3d
[svn] Generate cache content on demand if it was not previously there.
nenolod
parents:
385
diff
changeset
|
218 entry->decoder = input_check_file(entry->filename, FALSE); |
f908bcd87c3d
[svn] Generate cache content on demand if it was not previously there.
nenolod
parents:
385
diff
changeset
|
219 |
356
99928e1275a1
[svn] This commit reduces the amount of times we probe a source down to ONE
nenolod
parents:
283
diff
changeset
|
220 if (!entry->decoder || !input_is_enabled(entry->decoder->filename)) |
99928e1275a1
[svn] This commit reduces the amount of times we probe a source down to ONE
nenolod
parents:
283
diff
changeset
|
221 { |
99928e1275a1
[svn] This commit reduces the amount of times we probe a source down to ONE
nenolod
parents:
283
diff
changeset
|
222 input_file_not_playable(entry->filename); |
283 | 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(NULL); |
99928e1275a1
[svn] This commit reduces the amount of times we probe a source down to ONE
nenolod
parents:
283
diff
changeset
|
225 mainwin_set_info_text(); |
283 | 226 |
356
99928e1275a1
[svn] This commit reduces the amount of times we probe a source down to ONE
nenolod
parents:
283
diff
changeset
|
227 return FALSE; |
283 | 228 } |
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(entry->decoder); |
99928e1275a1
[svn] This commit reduces the amount of times we probe a source down to ONE
nenolod
parents:
283
diff
changeset
|
231 entry->decoder->output = get_current_output_plugin(); |
99928e1275a1
[svn] This commit reduces the amount of times we probe a source down to ONE
nenolod
parents:
283
diff
changeset
|
232 entry->decoder->play_file(entry->filename); |
283 | 233 |
356
99928e1275a1
[svn] This commit reduces the amount of times we probe a source down to ONE
nenolod
parents:
283
diff
changeset
|
234 ip_data.playing = TRUE; |
283 | 235 |
356
99928e1275a1
[svn] This commit reduces the amount of times we probe a source down to ONE
nenolod
parents:
283
diff
changeset
|
236 return TRUE; |
283 | 237 } |
238 | |
239 gboolean | |
240 bmp_playback_get_playing(void) | |
241 { | |
242 return ip_data.playing; | |
243 } | |
244 | |
245 gboolean | |
246 bmp_playback_get_paused(void) | |
247 { | |
248 return ip_data.paused; | |
249 } | |
250 | |
251 void | |
252 bmp_playback_seek(gint time) | |
253 { | |
254 gboolean restore_pause = FALSE; | |
255 gint l=0, r=0; | |
256 | |
257 if (!ip_data.playing) | |
258 return; | |
259 | |
260 if (!get_current_input_plugin()) | |
261 return; | |
262 | |
263 /* FIXME WORKAROUND...that should work with all plugins | |
264 * mute the volume, start playback again, do the seek, then pause again | |
265 * -Patrick Sudowe */ | |
266 if(ip_data.paused) | |
267 { | |
268 restore_pause = TRUE; | |
269 output_get_volume(&l, &r); | |
270 output_set_volume(0,0); | |
271 bmp_playback_pause(); | |
272 } | |
273 | |
274 free_vis_data(); | |
275 get_current_input_plugin()->seek(time); | |
276 | |
277 if(restore_pause) | |
278 { | |
279 bmp_playback_pause(); | |
280 output_set_volume(l, r); | |
281 } | |
282 } | |
283 | |
284 void | |
285 bmp_playback_seek_relative(gint offset) | |
286 { | |
287 gint time = CLAMP(bmp_playback_get_time() / 1000 + offset, | |
288 0, playlist_get_current_length() / 1000 - 1); | |
289 bmp_playback_seek(time); | |
290 } |