Mercurial > audlegacy
comparison audacious/playlist.c @ 2120:1d67cf383e32 trunk
[svn] - dynamically allocate the playlist at startup and fix some lingering improper uses of playlist_get()
author | nenolod |
---|---|
date | Fri, 15 Dec 2006 07:20:41 -0800 |
parents | f18a5b617c34 |
children | 185db04b815f |
comparison
equal
deleted
inserted
replaced
2119:6d7381072a45 | 2120:1d67cf383e32 |
---|---|
62 /* If we manually change the song, p_p_b_j will show us where to go back to */ | 62 /* If we manually change the song, p_p_b_j will show us where to go back to */ |
63 PlaylistEntry *playlist_position_before_jump = NULL; | 63 PlaylistEntry *playlist_position_before_jump = NULL; |
64 G_LOCK_DEFINE(playlists); | 64 G_LOCK_DEFINE(playlists); |
65 | 65 |
66 static GList *playlists = NULL; | 66 static GList *playlists = NULL; |
67 static GList *playlists_iter; | |
67 | 68 |
68 static Playlist default_playlist = { | 69 static Playlist default_playlist = { |
69 "Default", | 70 "Default", |
70 #ifdef HAVE_XSPF | 71 #ifdef HAVE_XSPF |
71 "playlist.xspf", | 72 "playlist.xspf", |
141 | 142 |
142 static void playlist_recalc_total_time_nolock(Playlist *); | 143 static void playlist_recalc_total_time_nolock(Playlist *); |
143 static void playlist_recalc_total_time(Playlist *); | 144 static void playlist_recalc_total_time(Playlist *); |
144 static gboolean playlist_entry_get_info(PlaylistEntry * entry); | 145 static gboolean playlist_entry_get_info(PlaylistEntry * entry); |
145 | 146 |
147 /* *********************** playlist entry code ********************** */ | |
148 | |
146 PlaylistEntry * | 149 PlaylistEntry * |
147 playlist_entry_new(const gchar * filename, | 150 playlist_entry_new(const gchar * filename, |
148 const gchar * title, | 151 const gchar * title, |
149 const gint length, | 152 const gint length, |
150 InputPlugin * dec) | 153 InputPlugin * dec) |
228 entry->tuple = tuple; | 231 entry->tuple = tuple; |
229 | 232 |
230 return TRUE; | 233 return TRUE; |
231 } | 234 } |
232 | 235 |
236 /* *********************** playlist selector code ************************* */ | |
237 | |
238 void | |
239 playlist_init(void) | |
240 { | |
241 Playlist *initial_pl; | |
242 | |
243 REQUIRE_STATIC_LOCK(playlists); | |
244 | |
245 initial_pl = playlist_new(); | |
246 | |
247 playlist_add_playlist(initial_pl); | |
248 } | |
249 | |
250 void | |
251 playlist_add_playlist(Playlist *playlist) | |
252 { | |
253 playlists = g_list_append(playlists, playlist); | |
254 | |
255 if (playlists_iter == NULL) | |
256 playlists_iter = playlists; | |
257 } | |
258 | |
259 void | |
260 playlist_remove_playlist(Playlist *playlist) | |
261 { | |
262 playlists = g_list_remove(playlists, playlist); | |
263 | |
264 if (playlists_iter == NULL) | |
265 playlists_iter = playlists; | |
266 } | |
267 | |
268 /* *********************** playlist code ********************** */ | |
269 | |
233 const gchar * | 270 const gchar * |
234 playlist_get_current_name(Playlist *playlist) | 271 playlist_get_current_name(Playlist *playlist) |
235 { | 272 { |
236 return playlist->title; | 273 return playlist->title; |
237 } | 274 } |
238 | 275 |
239 gboolean | 276 gboolean |
240 playlist_set_current_name(Playlist *playlist, const gchar * filename) | 277 playlist_set_current_name(Playlist *playlist, const gchar * filename) |
241 { | 278 { |
242 #ifdef NOTYET | 279 if (playlist->title) |
243 g_free(playlist->title); | 280 g_free(playlist->title); |
244 #endif | |
245 | 281 |
246 if (!filename) { | 282 if (!filename) { |
247 playlist->title = NULL; | 283 playlist->title = NULL; |
248 return FALSE; | 284 return FALSE; |
249 } | 285 } |
2625 playlist->pl_total_time = 0; | 2661 playlist->pl_total_time = 0; |
2626 playlist->pl_selection_time = 0; | 2662 playlist->pl_selection_time = 0; |
2627 playlist->pl_total_more = FALSE; | 2663 playlist->pl_total_more = FALSE; |
2628 playlist->pl_selection_more = FALSE; | 2664 playlist->pl_selection_more = FALSE; |
2629 | 2665 |
2630 for (list = playlist_get(); list; list = g_list_next(list)) { | 2666 for (list = playlist->entries; list; list = g_list_next(list)) { |
2631 entry = list->data; | 2667 entry = list->data; |
2632 | 2668 |
2633 if (entry->length != -1) | 2669 if (entry->length != -1) |
2634 playlist->pl_total_time += entry->length / 1000; | 2670 playlist->pl_total_time += entry->length / 1000; |
2635 else | 2671 else |
2787 } | 2823 } |
2788 | 2824 |
2789 Playlist * | 2825 Playlist * |
2790 playlist_get_active(void) | 2826 playlist_get_active(void) |
2791 { | 2827 { |
2792 return &default_playlist; | 2828 if (playlists_iter != NULL) |
2793 }; | 2829 return (Playlist *) playlists_iter->data; |
2830 | |
2831 return (Playlist *) playlists->data; | |
2832 } | |
2794 | 2833 |
2795 void | 2834 void |
2796 playlist_set_shuffle(gboolean shuffle) | 2835 playlist_set_shuffle(gboolean shuffle) |
2797 { | 2836 { |
2798 PLAYLIST_LOCK(); | 2837 PLAYLIST_LOCK(); |
2810 { | 2849 { |
2811 Playlist *playlist = g_new0(Playlist, 1); | 2850 Playlist *playlist = g_new0(Playlist, 1); |
2812 | 2851 |
2813 playlist_set_current_name(playlist, NULL); | 2852 playlist_set_current_name(playlist, NULL); |
2814 playlist_clear(playlist); | 2853 playlist_clear(playlist); |
2815 mainwin_clear_song_info(); | |
2816 mainwin_set_info_text(); | |
2817 | 2854 |
2818 return playlist; | 2855 return playlist; |
2819 } | 2856 } |
2820 | 2857 |
2821 | 2858 |