Mercurial > audlegacy
annotate src/audacious/playback.c @ 3016:e84073b61ba5 trunk
fix tinyplayer skin
| author | Tomasz Mon <desowin@gmail.com> |
|---|---|
| date | Mon, 09 Jul 2007 13:02:50 +0200 |
| parents | 6d4b7b739232 |
| children | 6a9fdd5aee3a 6065d70cb790 |
| 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 | |
| 2717 | 40 #include "configdb.h" |
| 2313 | 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" | |
| 51 #include "util.h" | |
| 52 | |
| 53 #include "playback.h" | |
| 54 | |
| 55 | |
| 56 gint | |
| 57 playback_get_time(void) | |
| 58 { | |
|
2438
8750a62abed8
[svn] Provide flags in InputPlayback for common plugin flag needs, and provide a
iabervon
parents:
2436
diff
changeset
|
59 InputPlayback *playback; |
| 2420 | 60 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
|
61 playback = get_current_input_playback(); |
|
8750a62abed8
[svn] Provide flags in InputPlayback for common plugin flag needs, and provide a
iabervon
parents:
2436
diff
changeset
|
62 g_return_val_if_fail(playback, -1); |
| 2313 | 63 |
|
2438
8750a62abed8
[svn] Provide flags in InputPlayback for common plugin flag needs, and provide a
iabervon
parents:
2436
diff
changeset
|
64 if (playback->plugin->get_time) |
|
8750a62abed8
[svn] Provide flags in InputPlayback for common plugin flag needs, and provide a
iabervon
parents:
2436
diff
changeset
|
65 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
|
66 if (playback->error) |
|
8750a62abed8
[svn] Provide flags in InputPlayback for common plugin flag needs, and provide a
iabervon
parents:
2436
diff
changeset
|
67 return -2; |
|
8750a62abed8
[svn] Provide flags in InputPlayback for common plugin flag needs, and provide a
iabervon
parents:
2436
diff
changeset
|
68 if (!playback->playing || |
|
8750a62abed8
[svn] Provide flags in InputPlayback for common plugin flag needs, and provide a
iabervon
parents:
2436
diff
changeset
|
69 (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
|
70 return -1; |
|
8750a62abed8
[svn] Provide flags in InputPlayback for common plugin flag needs, and provide a
iabervon
parents:
2436
diff
changeset
|
71 return playback->output->output_time(); |
| 2313 | 72 } |
| 73 | |
| 74 void | |
| 75 playback_initiate(void) | |
| 76 { | |
| 77 PlaylistEntry *entry = NULL; | |
| 78 Playlist *playlist = playlist_get_active(); | |
| 79 | |
| 2420 | 80 g_return_if_fail(playlist_get_length(playlist) != 0); |
| 2313 | 81 |
| 82 if (playback_get_playing()) | |
| 83 playback_stop(); | |
| 84 | |
| 85 vis_clear_data(mainwin_vis); | |
| 86 svis_clear_data(mainwin_svis); | |
| 87 mainwin_disable_seekbar(); | |
| 88 | |
| 89 entry = playlist_get_entry_to_play(playlist); | |
| 2420 | 90 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
|
91 playback_play_file(entry); |
| 2313 | 92 |
| 93 if (playback_get_time() != -1) { | |
| 94 equalizerwin_load_auto_preset(entry->filename); | |
| 95 input_set_eq(cfg.equalizer_active, cfg.equalizer_preamp, | |
| 96 cfg.equalizer_bands); | |
| 97 output_set_eq(cfg.equalizer_active, cfg.equalizer_preamp, | |
| 98 cfg.equalizer_bands); | |
| 99 } | |
| 100 | |
| 101 playlist_check_pos_current(playlist); | |
| 102 mainwin_set_info_text(); | |
|
2407
1dc1d36d0347
[svn] - add hooks: playback begin, playback end, playlist reached end
nenolod
parents:
2366
diff
changeset
|
103 |
|
3000
bbca1e0e054a
don't call gtk_widget_show/hide from func that's called every now and then
Tomasz Mon <desowin@gmail.com>
parents:
2976
diff
changeset
|
104 if (cfg.player_shaded) { |
|
bbca1e0e054a
don't call gtk_widget_show/hide from func that's called every now and then
Tomasz Mon <desowin@gmail.com>
parents:
2976
diff
changeset
|
105 gtk_widget_show(mainwin_stime_min); |
|
bbca1e0e054a
don't call gtk_widget_show/hide from func that's called every now and then
Tomasz Mon <desowin@gmail.com>
parents:
2976
diff
changeset
|
106 gtk_widget_show(mainwin_stime_sec); |
|
3001
6d4b7b739232
fully implement UiSkinnedNumber, number.c no longer needed
Tomasz Mon <desowin@gmail.com>
parents:
3000
diff
changeset
|
107 } else { |
|
6d4b7b739232
fully implement UiSkinnedNumber, number.c no longer needed
Tomasz Mon <desowin@gmail.com>
parents:
3000
diff
changeset
|
108 gtk_widget_show(mainwin_minus_num); |
|
6d4b7b739232
fully implement UiSkinnedNumber, number.c no longer needed
Tomasz Mon <desowin@gmail.com>
parents:
3000
diff
changeset
|
109 gtk_widget_show(mainwin_10min_num); |
|
6d4b7b739232
fully implement UiSkinnedNumber, number.c no longer needed
Tomasz Mon <desowin@gmail.com>
parents:
3000
diff
changeset
|
110 gtk_widget_show(mainwin_min_num); |
|
6d4b7b739232
fully implement UiSkinnedNumber, number.c no longer needed
Tomasz Mon <desowin@gmail.com>
parents:
3000
diff
changeset
|
111 gtk_widget_show(mainwin_10sec_num); |
|
6d4b7b739232
fully implement UiSkinnedNumber, number.c no longer needed
Tomasz Mon <desowin@gmail.com>
parents:
3000
diff
changeset
|
112 gtk_widget_show(mainwin_sec_num); |
|
3000
bbca1e0e054a
don't call gtk_widget_show/hide from func that's called every now and then
Tomasz Mon <desowin@gmail.com>
parents:
2976
diff
changeset
|
113 } |
|
bbca1e0e054a
don't call gtk_widget_show/hide from func that's called every now and then
Tomasz Mon <desowin@gmail.com>
parents:
2976
diff
changeset
|
114 |
|
2407
1dc1d36d0347
[svn] - add hooks: playback begin, playback end, playlist reached end
nenolod
parents:
2366
diff
changeset
|
115 hook_call("playback begin", entry); |
| 2313 | 116 } |
| 117 | |
| 118 void | |
| 119 playback_pause(void) | |
| 120 { | |
| 121 if (!playback_get_playing()) | |
| 122 return; | |
| 123 | |
|
2436
f346d30bf5ab
[svn] Change the input plugin API to use a struct for the currently-playing file.
iabervon
parents:
2420
diff
changeset
|
124 if (!get_current_input_playback()) |
| 2313 | 125 return; |
| 126 | |
| 127 ip_data.paused = !ip_data.paused; | |
| 128 | |
|
2436
f346d30bf5ab
[svn] Change the input plugin API to use a struct for the currently-playing file.
iabervon
parents:
2420
diff
changeset
|
129 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
|
130 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
|
131 ip_data.paused); |
| 2313 | 132 |
| 133 g_return_if_fail(mainwin_playstatus != NULL); | |
| 134 | |
| 135 if (ip_data.paused) | |
| 136 playstatus_set_status(mainwin_playstatus, STATUS_PAUSE); | |
| 137 else | |
| 138 playstatus_set_status(mainwin_playstatus, STATUS_PLAY); | |
| 139 } | |
| 140 | |
| 141 void | |
| 142 playback_stop(void) | |
| 143 { | |
|
2436
f346d30bf5ab
[svn] Change the input plugin API to use a struct for the currently-playing file.
iabervon
parents:
2420
diff
changeset
|
144 if (ip_data.playing && get_current_input_playback()) { |
| 2313 | 145 |
| 146 if (playback_get_paused()) { | |
| 147 output_flush(get_written_time()); /* to avoid noise */ | |
| 148 playback_pause(); | |
| 149 } | |
| 150 | |
| 151 ip_data.playing = FALSE; | |
| 152 | |
|
2436
f346d30bf5ab
[svn] Change the input plugin API to use a struct for the currently-playing file.
iabervon
parents:
2420
diff
changeset
|
153 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
|
154 get_current_input_playback()->plugin->stop(get_current_input_playback()); |
| 2313 | 155 |
| 156 free_vis_data(); | |
| 157 ip_data.paused = FALSE; | |
| 158 | |
| 159 if (input_info_text) { | |
| 160 g_free(input_info_text); | |
| 161 input_info_text = NULL; | |
| 162 mainwin_set_info_text(); | |
| 163 } | |
|
2436
f346d30bf5ab
[svn] Change the input plugin API to use a struct for the currently-playing file.
iabervon
parents:
2420
diff
changeset
|
164 |
|
2438
8750a62abed8
[svn] Provide flags in InputPlayback for common plugin flag needs, and provide a
iabervon
parents:
2436
diff
changeset
|
165 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
|
166 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
|
167 set_current_input_playback(NULL); |
| 2313 | 168 } |
| 169 | |
| 170 ip_data.buffering = FALSE; | |
| 171 ip_data.playing = FALSE; | |
| 172 | |
| 173 g_return_if_fail(mainwin_playstatus != NULL); | |
| 174 playstatus_set_status_buffering(mainwin_playstatus, FALSE); | |
| 175 } | |
| 176 | |
| 177 static void | |
| 178 run_no_output_plugin_dialog(void) | |
| 179 { | |
| 180 const gchar *markup = | |
| 181 N_("<b><big>No output plugin selected.</big></b>\n" | |
| 182 "You have not selected an output plugin."); | |
| 183 | |
| 184 GtkWidget *dialog = | |
| 185 gtk_message_dialog_new_with_markup(GTK_WINDOW(mainwin), | |
| 186 GTK_DIALOG_DESTROY_WITH_PARENT, | |
| 187 GTK_MESSAGE_ERROR, | |
| 188 GTK_BUTTONS_OK, | |
| 189 _(markup)); | |
| 190 gtk_dialog_run(GTK_DIALOG(dialog)); | |
| 191 gtk_widget_destroy(dialog); | |
| 192 } | |
| 193 | |
| 194 gboolean | |
| 195 playback_play_file(PlaylistEntry *entry) | |
| 196 { | |
|
2436
f346d30bf5ab
[svn] Change the input plugin API to use a struct for the currently-playing file.
iabervon
parents:
2420
diff
changeset
|
197 InputPlayback * playback; |
| 2313 | 198 g_return_val_if_fail(entry != NULL, FALSE); |
| 199 | |
| 200 if (!get_current_output_plugin()) { | |
| 201 run_no_output_plugin_dialog(); | |
| 202 mainwin_stop_pushed(); | |
| 203 return FALSE; | |
| 204 } | |
| 205 | |
| 206 if (cfg.random_skin_on_play) | |
|
2443
93686e8815a4
[svn] - Changed playback_set_random_skin() to skin_set_random_skin()
mf0102
parents:
2438
diff
changeset
|
207 skin_set_random_skin(); |
| 2313 | 208 |
| 209 /* | |
| 210 * This is slightly uglier than the original version, but should | |
| 211 * fix the "crash" issues as seen in 0.2 when dealing with this situation. | |
| 212 * - nenolod | |
| 213 */ | |
| 214 if (!entry->decoder && | |
| 2420 | 215 (((entry->decoder = input_check_file(entry->filename, FALSE)) == NULL) || |
| 2313 | 216 !input_is_enabled(entry->decoder->filename))) |
| 217 { | |
|
2436
f346d30bf5ab
[svn] Change the input plugin API to use a struct for the currently-playing file.
iabervon
parents:
2420
diff
changeset
|
218 set_current_input_playback(NULL); |
| 2313 | 219 mainwin_set_info_text(); |
| 220 | |
| 221 return FALSE; | |
| 222 } | |
| 223 | |
|
2436
f346d30bf5ab
[svn] Change the input plugin API to use a struct for the currently-playing file.
iabervon
parents:
2420
diff
changeset
|
224 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
|
225 |
| 2313 | 226 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
|
227 |
|
f346d30bf5ab
[svn] Change the input plugin API to use a struct for the currently-playing file.
iabervon
parents:
2420
diff
changeset
|
228 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
|
229 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
|
230 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
|
231 |
|
f346d30bf5ab
[svn] Change the input plugin API to use a struct for the currently-playing file.
iabervon
parents:
2420
diff
changeset
|
232 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
|
233 |
|
f346d30bf5ab
[svn] Change the input plugin API to use a struct for the currently-playing file.
iabervon
parents:
2420
diff
changeset
|
234 entry->decoder->play_file(playback); |
| 2313 | 235 |
| 236 ip_data.playing = TRUE; | |
| 237 | |
| 238 return TRUE; | |
| 239 } | |
| 240 | |
| 241 gboolean | |
| 242 playback_get_playing(void) | |
| 243 { | |
| 244 return ip_data.playing; | |
| 245 } | |
| 246 | |
| 247 gboolean | |
| 248 playback_get_paused(void) | |
| 249 { | |
| 250 return ip_data.paused; | |
| 251 } | |
| 252 | |
| 253 void | |
| 254 playback_seek(gint time) | |
| 255 { | |
| 256 gboolean restore_pause = FALSE; | |
| 257 gint l=0, r=0; | |
| 258 | |
| 2420 | 259 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
|
260 g_return_if_fail(get_current_input_playback()); |
| 2313 | 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 */ | |
| 2420 | 266 if (ip_data.paused) |
| 2313 | 267 { |
| 2420 | 268 restore_pause = TRUE; |
| 269 output_get_volume(&l, &r); | |
| 270 output_set_volume(0,0); | |
| 271 playback_pause(); | |
| 2313 | 272 } |
| 273 | |
| 274 free_vis_data(); | |
| 2454 | 275 get_current_input_playback()->plugin->seek(get_current_input_playback(), time); |
| 2313 | 276 |
| 2420 | 277 if (restore_pause) |
| 2313 | 278 { |
| 2420 | 279 playback_pause(); |
| 280 output_set_volume(l, r); | |
| 2313 | 281 } |
| 282 } | |
| 283 | |
| 284 void | |
| 285 playback_seek_relative(gint offset) | |
| 286 { | |
| 287 gint time = CLAMP(playback_get_time() / 1000 + offset, | |
| 288 0, playlist_get_current_length(playlist_get_active()) / 1000 - 1); | |
| 289 playback_seek(time); | |
| 290 } |
