Mercurial > audlegacy
annotate audacious/playlist.c @ 2080:df6cf9cb531e trunk
[svn] - this commit breaks the API. I'm not done here, but hopefully the new API is
stable enough now that the other chunks of the code can be converted by
Chainsaw ;)
author | nenolod |
---|---|
date | Mon, 11 Dec 2006 03:25:21 -0800 |
parents | 25308f10b50f |
children | b98891c9e155 |
rev | line source |
---|---|
0 | 1 /* BMP (C) GPL 2003 $top_src_dir/AUTHORS |
2 * | |
3 * based on: | |
4 * | |
5 * XMMS - Cross-platform multimedia player | |
6 * Copyright (C) 1998-2003 Peter Alm, Mikael Alm, Olle Hallnas, | |
7 * Thomas Nilsson and 4Front Technologies | |
8 * Copyright (C) 1999-2003 Haavard Kvaalen | |
9 * | |
10 * | |
11 * This program is free software; you can redistribute it and/or modify | |
12 * it under the terms of the GNU General Public License as published by | |
13 * the Free Software Foundation; either version 2 of the License, or | |
14 * (at your option) any later version. | |
15 * | |
16 * This program is distributed in the hope that it will be useful, | |
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 * GNU General Public License for more details. | |
20 * | |
21 * You should have received a copy of the GNU General Public License | |
22 * along with this program; if not, write to the Free Software | |
1459 | 23 * Foundation, Inc., 59 Tmple Place - Suite 330, Boston, MA 02110-1301, USA. |
0 | 24 */ |
25 | |
26 #ifdef HAVE_CONFIG_H | |
27 # include "config.h" | |
28 #endif | |
29 | |
30 #include "playlist.h" | |
31 | |
32 #include <glib.h> | |
33 #include <glib/gprintf.h> | |
34 #include <stdlib.h> | |
35 #include <string.h> | |
36 #include <time.h> | |
37 | |
38 #include <unistd.h> | |
39 #include <sys/types.h> | |
40 #include <sys/stat.h> | |
41 #include <sys/errno.h> | |
42 | |
43 #include "input.h" | |
44 #include "main.h" | |
1653 | 45 #include "mainwin.h" |
0 | 46 #include "libaudacious/util.h" |
47 #include "libaudacious/configdb.h" | |
48 #include "libaudacious/vfs.h" | |
2073 | 49 #include "libaudacious/urldecode.h" |
1653 | 50 #include "equalizer.h" |
538
e4e897d20791
[svn] remove libaudcore, we never did anything with it
nenolod
parents:
418
diff
changeset
|
51 #include "playback.h" |
0 | 52 #include "playlist.h" |
1550 | 53 #include "playlist_container.h" |
1653 | 54 #include "ui_playlist.h" |
0 | 55 #include "util.h" |
1269 | 56 #include "ui_fileinfo.h" |
0 | 57 |
58 #include "debug.h" | |
59 | |
1251 | 60 typedef gint (*PlaylistCompareFunc) (PlaylistEntry * a, PlaylistEntry * b); |
0 | 61 typedef void (*PlaylistSaveFunc) (FILE * file); |
62 | |
63 PlaylistEntry *playlist_position; | |
2040
dbe615def81f
[svn] Playlist shuffle behaviour should now be a little more consistant.
nazca
parents:
2027
diff
changeset
|
64 /* If we manually change the song, p_p_b_j will show us where to go back to */ |
dbe615def81f
[svn] Playlist shuffle behaviour should now be a little more consistant.
nazca
parents:
2027
diff
changeset
|
65 PlaylistEntry *playlist_position_before_jump = NULL; |
2080
df6cf9cb531e
[svn] - this commit breaks the API. I'm not done here, but hopefully the new API is
nenolod
parents:
2073
diff
changeset
|
66 G_LOCK_DEFINE(playlists); |
df6cf9cb531e
[svn] - this commit breaks the API. I'm not done here, but hopefully the new API is
nenolod
parents:
2073
diff
changeset
|
67 |
df6cf9cb531e
[svn] - this commit breaks the API. I'm not done here, but hopefully the new API is
nenolod
parents:
2073
diff
changeset
|
68 static GList *playlists = NULL; |
df6cf9cb531e
[svn] - this commit breaks the API. I'm not done here, but hopefully the new API is
nenolod
parents:
2073
diff
changeset
|
69 |
df6cf9cb531e
[svn] - this commit breaks the API. I'm not done here, but hopefully the new API is
nenolod
parents:
2073
diff
changeset
|
70 static Playlist default_playlist = { |
df6cf9cb531e
[svn] - this commit breaks the API. I'm not done here, but hopefully the new API is
nenolod
parents:
2073
diff
changeset
|
71 "Default", |
df6cf9cb531e
[svn] - this commit breaks the API. I'm not done here, but hopefully the new API is
nenolod
parents:
2073
diff
changeset
|
72 #ifdef HAVE_XSPF |
df6cf9cb531e
[svn] - this commit breaks the API. I'm not done here, but hopefully the new API is
nenolod
parents:
2073
diff
changeset
|
73 "playlist.xspf", |
df6cf9cb531e
[svn] - this commit breaks the API. I'm not done here, but hopefully the new API is
nenolod
parents:
2073
diff
changeset
|
74 #else |
df6cf9cb531e
[svn] - this commit breaks the API. I'm not done here, but hopefully the new API is
nenolod
parents:
2073
diff
changeset
|
75 "playlist.m3u", |
df6cf9cb531e
[svn] - this commit breaks the API. I'm not done here, but hopefully the new API is
nenolod
parents:
2073
diff
changeset
|
76 #endif |
df6cf9cb531e
[svn] - this commit breaks the API. I'm not done here, but hopefully the new API is
nenolod
parents:
2073
diff
changeset
|
77 0, |
df6cf9cb531e
[svn] - this commit breaks the API. I'm not done here, but hopefully the new API is
nenolod
parents:
2073
diff
changeset
|
78 NULL, |
df6cf9cb531e
[svn] - this commit breaks the API. I'm not done here, but hopefully the new API is
nenolod
parents:
2073
diff
changeset
|
79 NULL, |
df6cf9cb531e
[svn] - this commit breaks the API. I'm not done here, but hopefully the new API is
nenolod
parents:
2073
diff
changeset
|
80 NULL, |
df6cf9cb531e
[svn] - this commit breaks the API. I'm not done here, but hopefully the new API is
nenolod
parents:
2073
diff
changeset
|
81 NULL |
df6cf9cb531e
[svn] - this commit breaks the API. I'm not done here, but hopefully the new API is
nenolod
parents:
2073
diff
changeset
|
82 }; |
0 | 83 |
397
4fa1244ad483
[svn] Do not generate a cache when loading a playlist.
nenolod
parents:
383
diff
changeset
|
84 /* If this is set to TRUE, we do not probe upon playlist add. |
4fa1244ad483
[svn] Do not generate a cache when loading a playlist.
nenolod
parents:
383
diff
changeset
|
85 * |
4fa1244ad483
[svn] Do not generate a cache when loading a playlist.
nenolod
parents:
383
diff
changeset
|
86 * Under Audacious 0.1.x, this was not a big deal because we used |
4fa1244ad483
[svn] Do not generate a cache when loading a playlist.
nenolod
parents:
383
diff
changeset
|
87 * file extension introspection instead of looking for file format magic |
4fa1244ad483
[svn] Do not generate a cache when loading a playlist.
nenolod
parents:
383
diff
changeset
|
88 * strings. |
4fa1244ad483
[svn] Do not generate a cache when loading a playlist.
nenolod
parents:
383
diff
changeset
|
89 * |
4fa1244ad483
[svn] Do not generate a cache when loading a playlist.
nenolod
parents:
383
diff
changeset
|
90 * Because we use file magic strings, we have to fstat a file being added |
4fa1244ad483
[svn] Do not generate a cache when loading a playlist.
nenolod
parents:
383
diff
changeset
|
91 * to a playlist up to 1 * <number of input plugins installed> times. |
4fa1244ad483
[svn] Do not generate a cache when loading a playlist.
nenolod
parents:
383
diff
changeset
|
92 * |
4fa1244ad483
[svn] Do not generate a cache when loading a playlist.
nenolod
parents:
383
diff
changeset
|
93 * This can get really slow now that we're looking for files to add to a |
4fa1244ad483
[svn] Do not generate a cache when loading a playlist.
nenolod
parents:
383
diff
changeset
|
94 * playlist. (Up to 5 minutes for 5000 songs, etcetera.) |
4fa1244ad483
[svn] Do not generate a cache when loading a playlist.
nenolod
parents:
383
diff
changeset
|
95 * |
4fa1244ad483
[svn] Do not generate a cache when loading a playlist.
nenolod
parents:
383
diff
changeset
|
96 * So, we obviously don't want to probe while opening a large playlist |
4fa1244ad483
[svn] Do not generate a cache when loading a playlist.
nenolod
parents:
383
diff
changeset
|
97 * up. Hince the boolean below. |
4fa1244ad483
[svn] Do not generate a cache when loading a playlist.
nenolod
parents:
383
diff
changeset
|
98 * |
4fa1244ad483
[svn] Do not generate a cache when loading a playlist.
nenolod
parents:
383
diff
changeset
|
99 * January 7, 2006, William Pitcock <nenolod@nenolod.net> |
4fa1244ad483
[svn] Do not generate a cache when loading a playlist.
nenolod
parents:
383
diff
changeset
|
100 */ |
4fa1244ad483
[svn] Do not generate a cache when loading a playlist.
nenolod
parents:
383
diff
changeset
|
101 static gboolean loading_playlist = FALSE; |
0 | 102 |
103 G_LOCK_DEFINE(playlist_get_info_going); | |
104 | |
105 static gchar *playlist_current_name = NULL; | |
106 | |
107 static gboolean playlist_get_info_scan_active = FALSE; | |
108 static gboolean playlist_get_info_going = FALSE; | |
109 static GThread *playlist_get_info_thread; | |
110 | |
111 static gint path_compare(const gchar * a, const gchar * b); | |
1251 | 112 static gint playlist_compare_path(PlaylistEntry * a, PlaylistEntry * b); |
113 static gint playlist_compare_filename(PlaylistEntry * a, PlaylistEntry * b); | |
114 static gint playlist_compare_title(PlaylistEntry * a, PlaylistEntry * b); | |
115 static gint playlist_compare_artist(PlaylistEntry * a, PlaylistEntry * b); | |
1588
15d92c51bde6
[svn] - modified time (mtime) has been introduced into tuple
yaz
parents:
1587
diff
changeset
|
116 static time_t playlist_get_mtime(const gchar *filename); |
1251 | 117 static gint playlist_compare_date(PlaylistEntry * a, PlaylistEntry * b); |
1415 | 118 static gint playlist_compare_track(PlaylistEntry * a, PlaylistEntry * b); |
1430
740c08db08d9
[svn] via Christian Birchinger <joker -at- netswarm.net>:
nenolod
parents:
1415
diff
changeset
|
119 static gint playlist_compare_playlist(PlaylistEntry * a, PlaylistEntry * b); |
1251 | 120 |
121 static gint playlist_dupscmp_path(PlaylistEntry * a, PlaylistEntry * b); | |
122 static gint playlist_dupscmp_filename(PlaylistEntry * a, PlaylistEntry * b); | |
123 static gint playlist_dupscmp_title(PlaylistEntry * a, PlaylistEntry * b); | |
852
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
124 |
0 | 125 static PlaylistCompareFunc playlist_compare_func_table[] = { |
126 playlist_compare_path, | |
127 playlist_compare_filename, | |
128 playlist_compare_title, | |
1251 | 129 playlist_compare_artist, |
1415 | 130 playlist_compare_date, |
1430
740c08db08d9
[svn] via Christian Birchinger <joker -at- netswarm.net>:
nenolod
parents:
1415
diff
changeset
|
131 playlist_compare_track, |
740c08db08d9
[svn] via Christian Birchinger <joker -at- netswarm.net>:
nenolod
parents:
1415
diff
changeset
|
132 playlist_compare_playlist |
0 | 133 }; |
134 | |
135 static guint playlist_load_ins(const gchar * filename, gint pos); | |
136 | |
2080
df6cf9cb531e
[svn] - this commit breaks the API. I'm not done here, but hopefully the new API is
nenolod
parents:
2073
diff
changeset
|
137 static void playlist_generate_shuffle_list(Playlist *); |
df6cf9cb531e
[svn] - this commit breaks the API. I'm not done here, but hopefully the new API is
nenolod
parents:
2073
diff
changeset
|
138 static void playlist_generate_shuffle_list_nolock(Playlist *); |
0 | 139 |
140 static void playlist_recalc_total_time_nolock(void); | |
141 static void playlist_recalc_total_time(void); | |
1825 | 142 static gboolean playlist_entry_get_info(PlaylistEntry * entry); |
0 | 143 |
144 PlaylistEntry * | |
145 playlist_entry_new(const gchar * filename, | |
146 const gchar * title, | |
355
1c701dfe5098
[svn] Cache the decoder used for each PlaylistEntry. This reduces the amount
nenolod
parents:
284
diff
changeset
|
147 const gint length, |
1c701dfe5098
[svn] Cache the decoder used for each PlaylistEntry. This reduces the amount
nenolod
parents:
284
diff
changeset
|
148 InputPlugin * dec) |
0 | 149 { |
150 PlaylistEntry *entry; | |
151 | |
152 entry = g_new0(PlaylistEntry, 1); | |
153 entry->filename = g_strdup(filename); | |
154 entry->title = str_to_utf8(title); | |
155 entry->length = length; | |
156 entry->selected = FALSE; | |
355
1c701dfe5098
[svn] Cache the decoder used for each PlaylistEntry. This reduces the amount
nenolod
parents:
284
diff
changeset
|
157 entry->decoder = dec; |
0 | 158 |
1825 | 159 /* only do this if we have a decoder, otherwise it just takes too long */ |
1824 | 160 if (entry->decoder) |
1825 | 161 playlist_entry_get_info(entry); |
1824 | 162 |
0 | 163 return entry; |
164 } | |
165 | |
166 void | |
167 playlist_entry_free(PlaylistEntry * entry) | |
168 { | |
169 if (!entry) | |
170 return; | |
171 | |
1588
15d92c51bde6
[svn] - modified time (mtime) has been introduced into tuple
yaz
parents:
1587
diff
changeset
|
172 if (entry->tuple != NULL) { |
1232 | 173 bmp_title_input_free(entry->tuple); |
1588
15d92c51bde6
[svn] - modified time (mtime) has been introduced into tuple
yaz
parents:
1587
diff
changeset
|
174 entry->tuple = NULL; |
15d92c51bde6
[svn] - modified time (mtime) has been introduced into tuple
yaz
parents:
1587
diff
changeset
|
175 } |
1232 | 176 |
177 if (entry->filename != NULL) | |
178 g_free(entry->filename); | |
179 | |
180 if (entry->title != NULL) | |
181 g_free(entry->title); | |
182 | |
0 | 183 g_free(entry); |
184 } | |
185 | |
186 static gboolean | |
187 playlist_entry_get_info(PlaylistEntry * entry) | |
188 { | |
1232 | 189 TitleInput *tuple; |
1711
c7c1e346bb55
[svn] - no more busy loop if a file in playlist disappears.
yaz
parents:
1706
diff
changeset
|
190 time_t modtime; |
0 | 191 |
192 g_return_val_if_fail(entry != NULL, FALSE); | |
193 | |
1841
7d0cd3fab6a2
[svn] - mtime=-1 has been introduced to represent "uninitialized".
yaz
parents:
1834
diff
changeset
|
194 if (entry->tuple == NULL || entry->tuple->mtime > 0 || entry->tuple->mtime == -1) |
1824 | 195 modtime = playlist_get_mtime(entry->filename); |
196 else | |
197 modtime = 0; /* URI -nenolod */ | |
1711
c7c1e346bb55
[svn] - no more busy loop if a file in playlist disappears.
yaz
parents:
1706
diff
changeset
|
198 |
1690
bb1323938306
[svn] - fix for issue that was fixed in r1946 and then appeared again later :)
giacomo
parents:
1653
diff
changeset
|
199 if (entry->decoder == NULL) |
bb1323938306
[svn] - fix for issue that was fixed in r1946 and then appeared again later :)
giacomo
parents:
1653
diff
changeset
|
200 entry->decoder = input_check_file(entry->filename, FALSE); |
bb1323938306
[svn] - fix for issue that was fixed in r1946 and then appeared again later :)
giacomo
parents:
1653
diff
changeset
|
201 |
1588
15d92c51bde6
[svn] - modified time (mtime) has been introduced into tuple
yaz
parents:
1587
diff
changeset
|
202 /* renew tuple if file mtime is newer than tuple mtime. */ |
15d92c51bde6
[svn] - modified time (mtime) has been introduced into tuple
yaz
parents:
1587
diff
changeset
|
203 if(entry->tuple){ |
15d92c51bde6
[svn] - modified time (mtime) has been introduced into tuple
yaz
parents:
1587
diff
changeset
|
204 if(entry->tuple->mtime == modtime) |
15d92c51bde6
[svn] - modified time (mtime) has been introduced into tuple
yaz
parents:
1587
diff
changeset
|
205 return TRUE; |
15d92c51bde6
[svn] - modified time (mtime) has been introduced into tuple
yaz
parents:
1587
diff
changeset
|
206 else { |
15d92c51bde6
[svn] - modified time (mtime) has been introduced into tuple
yaz
parents:
1587
diff
changeset
|
207 bmp_title_input_free(entry->tuple); |
15d92c51bde6
[svn] - modified time (mtime) has been introduced into tuple
yaz
parents:
1587
diff
changeset
|
208 entry->tuple = NULL; |
15d92c51bde6
[svn] - modified time (mtime) has been introduced into tuple
yaz
parents:
1587
diff
changeset
|
209 } |
15d92c51bde6
[svn] - modified time (mtime) has been introduced into tuple
yaz
parents:
1587
diff
changeset
|
210 } |
15d92c51bde6
[svn] - modified time (mtime) has been introduced into tuple
yaz
parents:
1587
diff
changeset
|
211 |
1232 | 212 if (entry->decoder == NULL || entry->decoder->get_song_tuple == NULL) |
213 tuple = input_get_song_tuple(entry->filename); | |
214 else | |
215 tuple = entry->decoder->get_song_tuple(entry->filename); | |
216 | |
217 if (tuple == NULL) | |
0 | 218 return FALSE; |
219 | |
1588
15d92c51bde6
[svn] - modified time (mtime) has been introduced into tuple
yaz
parents:
1587
diff
changeset
|
220 /* attach mtime */ |
15d92c51bde6
[svn] - modified time (mtime) has been introduced into tuple
yaz
parents:
1587
diff
changeset
|
221 tuple->mtime = modtime; |
15d92c51bde6
[svn] - modified time (mtime) has been introduced into tuple
yaz
parents:
1587
diff
changeset
|
222 |
0 | 223 /* entry is still around */ |
1356 | 224 entry->title = xmms_get_titlestring(tuple->formatter != NULL ? tuple->formatter : xmms_get_gentitle_format(), tuple); |
1232 | 225 entry->length = tuple->length; |
226 entry->tuple = tuple; | |
0 | 227 |
228 return TRUE; | |
229 } | |
230 | |
231 const gchar * | |
2080
df6cf9cb531e
[svn] - this commit breaks the API. I'm not done here, but hopefully the new API is
nenolod
parents:
2073
diff
changeset
|
232 playlist_get_current_name(Playlist *playlist) |
0 | 233 { |
2080
df6cf9cb531e
[svn] - this commit breaks the API. I'm not done here, but hopefully the new API is
nenolod
parents:
2073
diff
changeset
|
234 return playlist->title; |
0 | 235 } |
236 | |
237 gboolean | |
2080
df6cf9cb531e
[svn] - this commit breaks the API. I'm not done here, but hopefully the new API is
nenolod
parents:
2073
diff
changeset
|
238 playlist_set_current_name(Playlist *playlist, const gchar * filename) |
0 | 239 { |
2080
df6cf9cb531e
[svn] - this commit breaks the API. I'm not done here, but hopefully the new API is
nenolod
parents:
2073
diff
changeset
|
240 #ifdef NOTYET |
df6cf9cb531e
[svn] - this commit breaks the API. I'm not done here, but hopefully the new API is
nenolod
parents:
2073
diff
changeset
|
241 g_free(playlist->title); |
df6cf9cb531e
[svn] - this commit breaks the API. I'm not done here, but hopefully the new API is
nenolod
parents:
2073
diff
changeset
|
242 #endif |
0 | 243 |
244 if (!filename) { | |
2080
df6cf9cb531e
[svn] - this commit breaks the API. I'm not done here, but hopefully the new API is
nenolod
parents:
2073
diff
changeset
|
245 playlist->title = NULL; |
0 | 246 return FALSE; |
247 } | |
248 | |
2080
df6cf9cb531e
[svn] - this commit breaks the API. I'm not done here, but hopefully the new API is
nenolod
parents:
2073
diff
changeset
|
249 playlist->title = g_strdup(filename); |
0 | 250 return TRUE; |
251 } | |
252 | |
253 static GList * | |
2080
df6cf9cb531e
[svn] - this commit breaks the API. I'm not done here, but hopefully the new API is
nenolod
parents:
2073
diff
changeset
|
254 find_playlist_position_list(Playlist *playlist) |
0 | 255 { |
2080
df6cf9cb531e
[svn] - this commit breaks the API. I'm not done here, but hopefully the new API is
nenolod
parents:
2073
diff
changeset
|
256 REQUIRE_STATIC_LOCK(playlists); |
df6cf9cb531e
[svn] - this commit breaks the API. I'm not done here, but hopefully the new API is
nenolod
parents:
2073
diff
changeset
|
257 |
df6cf9cb531e
[svn] - this commit breaks the API. I'm not done here, but hopefully the new API is
nenolod
parents:
2073
diff
changeset
|
258 if (!playlist->position) { |
0 | 259 if (cfg.shuffle) |
2080
df6cf9cb531e
[svn] - this commit breaks the API. I'm not done here, but hopefully the new API is
nenolod
parents:
2073
diff
changeset
|
260 return playlist->shuffle; |
0 | 261 else |
2080
df6cf9cb531e
[svn] - this commit breaks the API. I'm not done here, but hopefully the new API is
nenolod
parents:
2073
diff
changeset
|
262 return playlist->entries; |
0 | 263 } |
264 | |
265 if (cfg.shuffle) | |
2080
df6cf9cb531e
[svn] - this commit breaks the API. I'm not done here, but hopefully the new API is
nenolod
parents:
2073
diff
changeset
|
266 return g_list_find(playlist->shuffle, playlist->position); |
0 | 267 else |
2080
df6cf9cb531e
[svn] - this commit breaks the API. I'm not done here, but hopefully the new API is
nenolod
parents:
2073
diff
changeset
|
268 return g_list_find(playlist->entries, playlist->position); |
0 | 269 } |
270 | |
271 static void | |
2080
df6cf9cb531e
[svn] - this commit breaks the API. I'm not done here, but hopefully the new API is
nenolod
parents:
2073
diff
changeset
|
272 play_queued(Playlist *playlist) |
0 | 273 { |
2080
df6cf9cb531e
[svn] - this commit breaks the API. I'm not done here, but hopefully the new API is
nenolod
parents:
2073
diff
changeset
|
274 GList *tmp = playlist->queue; |
df6cf9cb531e
[svn] - this commit breaks the API. I'm not done here, but hopefully the new API is
nenolod
parents:
2073
diff
changeset
|
275 |
df6cf9cb531e
[svn] - this commit breaks the API. I'm not done here, but hopefully the new API is
nenolod
parents:
2073
diff
changeset
|
276 REQUIRE_STATIC_LOCK(playlists); |
df6cf9cb531e
[svn] - this commit breaks the API. I'm not done here, but hopefully the new API is
nenolod
parents:
2073
diff
changeset
|
277 |
df6cf9cb531e
[svn] - this commit breaks the API. I'm not done here, but hopefully the new API is
nenolod
parents:
2073
diff
changeset
|
278 playlist->position = playlist->queue->data; |
df6cf9cb531e
[svn] - this commit breaks the API. I'm not done here, but hopefully the new API is
nenolod
parents:
2073
diff
changeset
|
279 playlist->queue = g_list_remove_link(playlist->queue, playlist->queue); |
0 | 280 g_list_free_1(tmp); |
281 } | |
282 | |
283 void | |
2080
df6cf9cb531e
[svn] - this commit breaks the API. I'm not done here, but hopefully the new API is
nenolod
parents:
2073
diff
changeset
|
284 playlist_clear(Playlist *playlist) |
0 | 285 { |
905 | 286 if (bmp_playback_get_playing()) { |
287 ip_data.stop = TRUE; | |
0 | 288 bmp_playback_stop(); |
905 | 289 ip_data.stop = FALSE; |
290 } | |
0 | 291 |
292 PLAYLIST_LOCK(); | |
293 | |
294 if (playlist) { | |
2080
df6cf9cb531e
[svn] - this commit breaks the API. I'm not done here, but hopefully the new API is
nenolod
parents:
2073
diff
changeset
|
295 g_list_foreach(playlist->entries, (GFunc) playlist_entry_free, NULL); |
df6cf9cb531e
[svn] - this commit breaks the API. I'm not done here, but hopefully the new API is
nenolod
parents:
2073
diff
changeset
|
296 g_list_free(playlist->entries); |
0 | 297 } |
298 | |
299 PLAYLIST_UNLOCK(); | |
300 | |
2080
df6cf9cb531e
[svn] - this commit breaks the API. I'm not done here, but hopefully the new API is
nenolod
parents:
2073
diff
changeset
|
301 playlist_generate_shuffle_list(playlist); |
0 | 302 playlistwin_update_list(); |
303 playlist_recalc_total_time(); | |
304 } | |
305 | |
2080
df6cf9cb531e
[svn] - this commit breaks the API. I'm not done here, but hopefully the new API is
nenolod
parents:
2073
diff
changeset
|
306 static void |
df6cf9cb531e
[svn] - this commit breaks the API. I'm not done here, but hopefully the new API is
nenolod
parents:
2073
diff
changeset
|
307 playlist_delete_node(Playlist * playlist, GList * node, gboolean * set_info_text, |
0 | 308 gboolean * restart_playing) |
309 { | |
310 PlaylistEntry *entry; | |
311 GList *playing_song = NULL; | |
312 | |
2080
df6cf9cb531e
[svn] - this commit breaks the API. I'm not done here, but hopefully the new API is
nenolod
parents:
2073
diff
changeset
|
313 REQUIRE_STATIC_LOCK(playlists); |
0 | 314 |
315 /* We call g_list_find manually here because we don't want an item | |
316 * in the shuffle_list */ | |
317 | |
2080
df6cf9cb531e
[svn] - this commit breaks the API. I'm not done here, but hopefully the new API is
nenolod
parents:
2073
diff
changeset
|
318 if (playlist->position) |
df6cf9cb531e
[svn] - this commit breaks the API. I'm not done here, but hopefully the new API is
nenolod
parents:
2073
diff
changeset
|
319 playing_song = g_list_find(playlist->entries, playlist->position); |
0 | 320 |
321 entry = PLAYLIST_ENTRY(node->data); | |
322 | |
323 if (playing_song == node) { | |
324 *set_info_text = TRUE; | |
325 | |
326 if (bmp_playback_get_playing()) { | |
327 PLAYLIST_UNLOCK(); | |
905 | 328 ip_data.stop = TRUE; |
0 | 329 bmp_playback_stop(); |
905 | 330 ip_data.stop = FALSE; |
0 | 331 PLAYLIST_LOCK(); |
332 *restart_playing = TRUE; | |
333 } | |
334 | |
2080
df6cf9cb531e
[svn] - this commit breaks the API. I'm not done here, but hopefully the new API is
nenolod
parents:
2073
diff
changeset
|
335 playing_song = find_playlist_position_list(playlist); |
0 | 336 |
337 if (g_list_next(playing_song)) | |
2080
df6cf9cb531e
[svn] - this commit breaks the API. I'm not done here, but hopefully the new API is
nenolod
parents:
2073
diff
changeset
|
338 playlist->position = g_list_next(playing_song)->data; |
0 | 339 else if (g_list_previous(playing_song)) |
2080
df6cf9cb531e
[svn] - this commit breaks the API. I'm not done here, but hopefully the new API is
nenolod
parents:
2073
diff
changeset
|
340 playlist->position = g_list_previous(playing_song)->data; |
0 | 341 else |
2080
df6cf9cb531e
[svn] - this commit breaks the API. I'm not done here, but hopefully the new API is
nenolod
parents:
2073
diff
changeset
|
342 playlist->position = NULL; |
0 | 343 |
344 /* Make sure the entry did not disappear under us */ | |
345 if (g_list_index(playlist_get(), entry) == -1) | |
346 return; | |
347 | |
348 } | |
2080
df6cf9cb531e
[svn] - this commit breaks the API. I'm not done here, but hopefully the new API is
nenolod
parents:
2073
diff
changeset
|
349 else if (g_list_position(playlist->entries, playing_song) > |
df6cf9cb531e
[svn] - this commit breaks the API. I'm not done here, but hopefully the new API is
nenolod
parents:
2073
diff
changeset
|
350 g_list_position(playlist->entries, node)) { |
0 | 351 *set_info_text = TRUE; |
352 } | |
353 | |
2080
df6cf9cb531e
[svn] - this commit breaks the API. I'm not done here, but hopefully the new API is
nenolod
parents:
2073
diff
changeset
|
354 playlist->shuffle = g_list_remove(playlist->shuffle, entry); |
df6cf9cb531e
[svn] - this commit breaks the API. I'm not done here, but hopefully the new API is
nenolod
parents:
2073
diff
changeset
|
355 playlist->entries = g_list_remove_link(playlist->entries, node); |
0 | 356 playlist_entry_free(entry); |
357 g_list_free_1(node); | |
358 | |
359 playlist_recalc_total_time_nolock(); | |
360 } | |
361 | |
362 void | |
2080
df6cf9cb531e
[svn] - this commit breaks the API. I'm not done here, but hopefully the new API is
nenolod
parents:
2073
diff
changeset
|
363 playlist_delete_index(Playlist *playlist, guint pos) |
0 | 364 { |
365 gboolean restart_playing = FALSE, set_info_text = FALSE; | |
366 GList *node; | |
367 | |
368 PLAYLIST_LOCK(); | |
369 | |
370 if (!playlist) { | |
371 PLAYLIST_UNLOCK(); | |
372 return; | |
373 } | |
374 | |
2080
df6cf9cb531e
[svn] - this commit breaks the API. I'm not done here, but hopefully the new API is
nenolod
parents:
2073
diff
changeset
|
375 node = g_list_nth(playlist->entries, pos); |
0 | 376 |
377 if (!node) { | |
378 PLAYLIST_UNLOCK(); | |
379 return; | |
380 } | |
381 | |
2080
df6cf9cb531e
[svn] - this commit breaks the API. I'm not done here, but hopefully the new API is
nenolod
parents:
2073
diff
changeset
|
382 playlist_delete_node(playlist, node, &set_info_text, &restart_playing); |
0 | 383 |
384 PLAYLIST_UNLOCK(); | |
385 | |
386 playlist_recalc_total_time(); | |
387 | |
388 playlistwin_update_list(); | |
389 if (restart_playing) { | |
390 if (playlist_position) { | |
391 bmp_playback_initiate(); | |
392 } | |
393 else { | |
394 mainwin_clear_song_info(); | |
395 } | |
396 } | |
397 else if (set_info_text) { | |
398 mainwin_set_info_text(); | |
399 } | |
400 } | |
401 | |
402 void | |
403 playlist_delete_filenames(GList * filenames) | |
404 { | |
405 GList *node, *fnode; | |
406 gboolean set_info_text = FALSE, restart_playing = FALSE; | |
407 | |
408 PLAYLIST_LOCK(); | |
409 | |
410 for (fnode = filenames; fnode; fnode = g_list_next(fnode)) { | |
411 node = playlist; | |
412 | |
413 while (node) { | |
414 GList *next = g_list_next(node); | |
415 PlaylistEntry *entry = node->data; | |
416 | |
417 if (!strcmp(entry->filename, fnode->data)) | |
418 playlist_delete_node(node, &set_info_text, &restart_playing); | |
419 | |
420 node = next; | |
421 } | |
422 } | |
423 | |
424 playlist_recalc_total_time(); | |
425 PLAYLIST_UNLOCK(); | |
426 | |
427 playlistwin_update_list(); | |
428 | |
429 if (restart_playing) { | |
430 if (playlist_position) { | |
431 bmp_playback_initiate(); | |
432 } | |
433 else { | |
434 mainwin_clear_song_info(); | |
435 } | |
436 } | |
437 else if (set_info_text) { | |
438 mainwin_set_info_text(); | |
439 } | |
440 | |
441 } | |
442 | |
443 void | |
444 playlist_delete(gboolean crop) | |
445 { | |
446 gboolean restart_playing = FALSE, set_info_text = FALSE; | |
447 GList *node, *next_node; | |
448 PlaylistEntry *entry; | |
449 | |
450 PLAYLIST_LOCK(); | |
451 | |
452 node = playlist; | |
453 | |
454 while (node) { | |
455 entry = PLAYLIST_ENTRY(node->data); | |
456 | |
457 next_node = g_list_next(node); | |
458 | |
459 if ((entry->selected && !crop) || (!entry->selected && crop)) { | |
460 playlist_delete_node(node, &set_info_text, &restart_playing); | |
461 } | |
462 | |
463 node = next_node; | |
464 } | |
465 | |
466 PLAYLIST_UNLOCK(); | |
467 | |
468 playlist_recalc_total_time(); | |
469 | |
470 if (set_info_text) { | |
471 mainwin_set_info_text(); | |
472 } | |
473 | |
474 if (restart_playing) { | |
475 if (playlist_position) { | |
476 bmp_playback_initiate(); | |
477 } | |
478 else { | |
479 mainwin_clear_song_info(); | |
480 } | |
481 } | |
482 | |
483 playlistwin_update_list(); | |
484 } | |
485 | |
486 static void | |
487 __playlist_ins_with_info(const gchar * filename, | |
488 gint pos, | |
489 const gchar * title, | |
355
1c701dfe5098
[svn] Cache the decoder used for each PlaylistEntry. This reduces the amount
nenolod
parents:
284
diff
changeset
|
490 gint len, |
1c701dfe5098
[svn] Cache the decoder used for each PlaylistEntry. This reduces the amount
nenolod
parents:
284
diff
changeset
|
491 InputPlugin * dec) |
0 | 492 { |
493 g_return_if_fail(filename != NULL); | |
494 | |
495 PLAYLIST_LOCK(); | |
496 playlist = g_list_insert(playlist, | |
355
1c701dfe5098
[svn] Cache the decoder used for each PlaylistEntry. This reduces the amount
nenolod
parents:
284
diff
changeset
|
497 playlist_entry_new(filename, title, len, dec), |
0 | 498 pos); |
499 PLAYLIST_UNLOCK(); | |
500 | |
2026 | 501 g_mutex_lock(mutex_scan); |
0 | 502 playlist_get_info_scan_active = TRUE; |
2026 | 503 g_mutex_unlock(mutex_scan); |
504 g_cond_signal(cond_scan); | |
0 | 505 } |
506 | |
507 static void | |
1584 | 508 __playlist_ins_with_info_tuple(const gchar * filename, |
509 gint pos, | |
510 TitleInput *tuple, | |
511 InputPlugin * dec) | |
512 { | |
513 GList *node; | |
514 PlaylistEntry *entry; | |
515 | |
516 g_return_if_fail(filename != NULL); | |
517 | |
518 PLAYLIST_LOCK(); | |
519 playlist = g_list_insert(playlist, | |
520 playlist_entry_new(filename, tuple->track_name, tuple->length, dec), | |
521 pos); | |
522 | |
523 if(pos < 0 ) { | |
524 pos = g_list_length(playlist) - 1; /* last element. */ | |
525 } | |
526 | |
527 node = g_list_nth(playlist, pos); | |
528 entry = PLAYLIST_ENTRY(node->data); | |
529 | |
1587
c073fd82ded6
[svn] - Don't explode when loading http streams from xspf files.
nhjm449
parents:
1584
diff
changeset
|
530 if (tuple != NULL) { |
c073fd82ded6
[svn] - Don't explode when loading http streams from xspf files.
nhjm449
parents:
1584
diff
changeset
|
531 entry->title = xmms_get_titlestring(tuple->formatter != NULL ? tuple->formatter : xmms_get_gentitle_format(), tuple); |
c073fd82ded6
[svn] - Don't explode when loading http streams from xspf files.
nhjm449
parents:
1584
diff
changeset
|
532 entry->length = tuple->length; |
c073fd82ded6
[svn] - Don't explode when loading http streams from xspf files.
nhjm449
parents:
1584
diff
changeset
|
533 entry->tuple = tuple; |
c073fd82ded6
[svn] - Don't explode when loading http streams from xspf files.
nhjm449
parents:
1584
diff
changeset
|
534 } |
1584 | 535 |
536 PLAYLIST_UNLOCK(); | |
537 | |
2026 | 538 g_mutex_lock(mutex_scan); |
1584 | 539 playlist_get_info_scan_active = TRUE; |
2026 | 540 g_mutex_unlock(mutex_scan); |
541 g_cond_signal(cond_scan); | |
1584 | 542 } |
543 | |
544 static void | |
355
1c701dfe5098
[svn] Cache the decoder used for each PlaylistEntry. This reduces the amount
nenolod
parents:
284
diff
changeset
|
545 __playlist_ins(const gchar * filename, gint pos, InputPlugin *dec) |
0 | 546 { |
355
1c701dfe5098
[svn] Cache the decoder used for each PlaylistEntry. This reduces the amount
nenolod
parents:
284
diff
changeset
|
547 __playlist_ins_with_info(filename, pos, NULL, -1, dec); |
0 | 548 playlist_recalc_total_time(); |
549 } | |
550 | |
551 gboolean | |
552 playlist_ins(const gchar * filename, gint pos) | |
553 { | |
554 gchar buf[64], *p; | |
555 gint r; | |
556 VFSFile *file; | |
355
1c701dfe5098
[svn] Cache the decoder used for each PlaylistEntry. This reduces the amount
nenolod
parents:
284
diff
changeset
|
557 InputPlugin *dec; |
0 | 558 |
559 if (is_playlist_name(filename)) { | |
1607
57676c0f2f33
[svn] - prevents input_check_file() working on loading playlist.
yaz
parents:
1588
diff
changeset
|
560 loading_playlist = TRUE; |
0 | 561 playlist_load_ins(filename, pos); |
1607
57676c0f2f33
[svn] - prevents input_check_file() working on loading playlist.
yaz
parents:
1588
diff
changeset
|
562 loading_playlist = FALSE; |
0 | 563 return TRUE; |
564 } | |
565 | |
1165 | 566 if (loading_playlist == TRUE || cfg.playlist_detect == TRUE) |
397
4fa1244ad483
[svn] Do not generate a cache when loading a playlist.
nenolod
parents:
383
diff
changeset
|
567 dec = NULL; |
4fa1244ad483
[svn] Do not generate a cache when loading a playlist.
nenolod
parents:
383
diff
changeset
|
568 else |
4fa1244ad483
[svn] Do not generate a cache when loading a playlist.
nenolod
parents:
383
diff
changeset
|
569 dec = input_check_file(filename, TRUE); |
4fa1244ad483
[svn] Do not generate a cache when loading a playlist.
nenolod
parents:
383
diff
changeset
|
570 |
1165 | 571 if (cfg.playlist_detect == TRUE || loading_playlist == TRUE || (loading_playlist == FALSE && dec != NULL)) |
397
4fa1244ad483
[svn] Do not generate a cache when loading a playlist.
nenolod
parents:
383
diff
changeset
|
572 { |
4fa1244ad483
[svn] Do not generate a cache when loading a playlist.
nenolod
parents:
383
diff
changeset
|
573 __playlist_ins(filename, pos, dec); |
2080
df6cf9cb531e
[svn] - this commit breaks the API. I'm not done here, but hopefully the new API is
nenolod
parents:
2073
diff
changeset
|
574 playlist_generate_shuffle_list(playlist); |
397
4fa1244ad483
[svn] Do not generate a cache when loading a playlist.
nenolod
parents:
383
diff
changeset
|
575 playlistwin_update_list(); |
0 | 576 return TRUE; |
577 } | |
578 | |
579 /* Some files (typically produced by some cgi-scripts) don't have | |
580 * the correct extension. Try to recognize these files by looking | |
581 * at their content. We only check for http entries since it does | |
582 * not make sense to have file entries in a playlist fetched from | |
583 * the net. */ | |
584 | |
585 /* Some strange people put fifo's with the .mp3 extension, so we | |
586 * need to make sure it's a real file (otherwise fread() may block | |
587 * and stall the entire program) */ | |
588 | |
589 /* FIXME: bah, FIFOs actually pass this regular file test */ | |
590 if (!vfs_file_test(filename, G_FILE_TEST_IS_REGULAR)) | |
591 return FALSE; | |
592 | |
593 if (!(file = vfs_fopen(filename, "rb"))) | |
594 return FALSE; | |
595 | |
596 r = vfs_fread(buf, 1, sizeof(buf), file); | |
597 vfs_fclose(file); | |
598 | |
599 for (p = buf; r-- > 0 && (*p == '\r' || *p == '\n'); p++); | |
600 | |
601 if (r > 5 && str_has_prefix_nocase(p, "http:")) { | |
602 playlist_load_ins(filename, pos); | |
603 return TRUE; | |
604 } | |
605 | |
606 return FALSE; | |
607 } | |
608 | |
609 /* FIXME: The next few functions are specific to Unix | |
610 * filesystems. Either abstract it away, or don't even bother checking | |
611 * at such low level */ | |
612 | |
613 typedef struct { | |
614 dev_t dev; | |
615 ino_t ino; | |
616 } DeviceInode; | |
617 | |
618 static DeviceInode * | |
619 devino_new(dev_t device, | |
620 ino_t inode) | |
621 { | |
622 DeviceInode *devino = g_new0(DeviceInode, 1); | |
623 | |
624 if (devino) | |
625 { | |
626 devino->dev = device; | |
627 devino->ino = inode; | |
628 } | |
629 | |
630 return devino; | |
631 } | |
632 | |
633 static guint | |
634 devino_hash(gconstpointer key) | |
635 { | |
636 const DeviceInode *d = key; | |
637 return d->ino; | |
638 } | |
639 | |
640 static gint | |
641 devino_compare(gconstpointer a, | |
642 gconstpointer b) | |
643 { | |
644 const DeviceInode *da = a, *db = b; | |
645 return (da->dev == db->dev && da->ino == db->ino); | |
646 } | |
647 | |
648 static gboolean | |
649 devino_destroy(gpointer key, | |
650 gpointer value, | |
651 gpointer data) | |
652 { | |
653 g_free(key); | |
654 return TRUE; | |
655 } | |
656 | |
657 static gboolean | |
658 file_is_hidden(const gchar * filename) | |
659 { | |
660 // FIXME: remove the const cast | |
661 g_return_val_if_fail(filename != NULL, FALSE); | |
662 return (g_basename((gchar *) filename)[0] == '.'); | |
663 } | |
664 | |
665 static GList * | |
666 playlist_dir_find_files(const gchar * path, | |
667 gboolean background, | |
668 GHashTable * htab) | |
669 { | |
670 GDir *dir; | |
671 GList *list = NULL, *ilist; | |
672 const gchar *dir_entry; | |
673 | |
674 struct stat statbuf; | |
675 DeviceInode *devino; | |
676 | |
677 if (!g_file_test(path, G_FILE_TEST_IS_DIR)) | |
678 return NULL; | |
679 | |
680 stat(path, &statbuf); | |
681 devino = devino_new(statbuf.st_dev, statbuf.st_ino); | |
682 | |
683 if (g_hash_table_lookup(htab, devino)) { | |
684 g_free(devino); | |
685 return NULL; | |
686 } | |
687 | |
688 g_hash_table_insert(htab, devino, GINT_TO_POINTER(1)); | |
689 | |
690 if ((ilist = input_scan_dir(path))) { | |
691 GList *node; | |
692 for (node = ilist; node; node = g_list_next(node)) { | |
693 gchar *name = g_build_filename(path, node->data, NULL); | |
694 list = g_list_prepend(list, name); | |
695 g_free(node->data); | |
696 } | |
697 g_list_free(ilist); | |
698 return list; | |
699 } | |
700 | |
701 if (!(dir = g_dir_open(path, 0, NULL))) | |
702 return NULL; | |
703 | |
704 while ((dir_entry = g_dir_read_name(dir))) { | |
705 gchar *filename; | |
706 | |
707 if (file_is_hidden(dir_entry)) | |
708 continue; | |
709 | |
710 filename = g_build_filename(path, dir_entry, NULL); | |
711 | |
712 if (g_file_test(filename, G_FILE_TEST_IS_DIR)) { | |
713 GList *sub; | |
714 sub = playlist_dir_find_files(filename, background, htab); | |
715 g_free(filename); | |
716 list = g_list_concat(list, sub); | |
717 } | |
1165 | 718 else if (cfg.playlist_detect == TRUE) |
719 list = g_list_prepend(list, filename); | |
0 | 720 else if (input_check_file(filename, TRUE)) |
721 list = g_list_prepend(list, filename); | |
722 else | |
723 g_free(filename); | |
724 | |
725 while (background && gtk_events_pending()) | |
726 gtk_main_iteration(); | |
727 } | |
728 g_dir_close(dir); | |
729 | |
730 return list; | |
731 } | |
732 | |
733 gboolean | |
734 playlist_add(const gchar * filename) | |
735 { | |
736 return playlist_ins(filename, -1); | |
737 } | |
738 | |
739 guint | |
740 playlist_add_dir(const gchar * directory) | |
741 { | |
742 return playlist_ins_dir(directory, -1, TRUE); | |
743 } | |
744 | |
745 guint | |
746 playlist_add_url(const gchar * url) | |
747 { | |
748 return playlist_ins_url(url, -1); | |
749 } | |
750 | |
751 guint | |
752 playlist_ins_dir(const gchar * path, | |
753 gint pos, | |
754 gboolean background) | |
755 { | |
756 guint entries = 0; | |
757 GList *list, *node; | |
758 GHashTable *htab; | |
759 | |
760 htab = g_hash_table_new(devino_hash, devino_compare); | |
761 | |
762 list = playlist_dir_find_files(path, background, htab); | |
763 list = g_list_sort(list, (GCompareFunc) path_compare); | |
764 | |
765 g_hash_table_foreach_remove(htab, devino_destroy, NULL); | |
766 | |
767 for (node = list; node; node = g_list_next(node)) { | |
355
1c701dfe5098
[svn] Cache the decoder used for each PlaylistEntry. This reduces the amount
nenolod
parents:
284
diff
changeset
|
768 __playlist_ins(node->data, pos, NULL); |
0 | 769 g_free(node->data); |
770 entries++; | |
771 if (pos >= 0) | |
772 pos++; | |
773 } | |
774 | |
775 g_list_free(list); | |
776 | |
777 playlist_recalc_total_time(); | |
2080
df6cf9cb531e
[svn] - this commit breaks the API. I'm not done here, but hopefully the new API is
nenolod
parents:
2073
diff
changeset
|
778 playlist_generate_shuffle_list(playlist); |
0 | 779 playlistwin_update_list(); |
780 return entries; | |
781 } | |
782 | |
783 guint | |
784 playlist_ins_url(const gchar * string, | |
785 gint pos) | |
786 { | |
787 gchar *tmp; | |
788 gint i = 1, entries = 0; | |
789 gboolean first = TRUE; | |
790 guint firstpos = 0; | |
791 gboolean success = FALSE; | |
792 gchar *decoded = NULL; | |
793 | |
794 g_return_val_if_fail(string != NULL, 0); | |
795 | |
796 playlistwin_update_list(); | |
797 | |
798 while (*string) { | |
799 GList *node; | |
800 tmp = strchr(string, '\n'); | |
801 if (tmp) { | |
802 if (*(tmp - 1) == '\r') | |
803 *(tmp - 1) = '\0'; | |
804 *tmp = '\0'; | |
805 } | |
806 | |
2010
5f19843a038b
[svn] - xmms_urldecode_path() is no longer needed due to NewVFS layer.
nenolod
parents:
1991
diff
changeset
|
807 decoded = g_strdup(string); |
0 | 808 |
809 if (g_file_test(decoded, G_FILE_TEST_IS_DIR)) { | |
810 i = playlist_ins_dir(decoded, pos, FALSE); | |
811 } | |
812 else { | |
813 if (is_playlist_name(decoded)) { | |
814 i = playlist_load_ins(decoded, pos); | |
815 } | |
816 else { | |
817 success = playlist_ins(decoded, pos); | |
818 i = 1; | |
819 } | |
820 } | |
821 | |
822 g_free(decoded); | |
823 | |
824 PLAYLIST_LOCK(); | |
825 node = g_list_nth(playlist_get(), pos); | |
826 PLAYLIST_UNLOCK(); | |
827 | |
828 entries += i; | |
829 | |
830 if (first) { | |
831 first = FALSE; | |
832 firstpos = pos; | |
833 } | |
834 | |
835 if (pos >= 0) | |
836 pos += i; | |
837 if (!tmp) | |
838 break; | |
839 | |
840 string = tmp + 1; | |
841 } | |
842 | |
843 playlist_recalc_total_time(); | |
2080
df6cf9cb531e
[svn] - this commit breaks the API. I'm not done here, but hopefully the new API is
nenolod
parents:
2073
diff
changeset
|
844 playlist_generate_shuffle_list(playlist); |
0 | 845 playlistwin_update_list(); |
846 | |
847 return entries; | |
848 } | |
849 | |
850 void | |
851 playlist_set_info(const gchar * title, gint length, gint rate, | |
852 gint freq, gint nch) | |
853 { | |
854 PLAYLIST_LOCK(); | |
855 | |
856 if (playlist_position) { | |
857 g_free(playlist_position->title); | |
858 playlist_position->title = g_strdup(title); | |
859 playlist_position->length = length; | |
860 } | |
861 | |
862 PLAYLIST_UNLOCK(); | |
863 | |
864 playlist_recalc_total_time(); | |
865 | |
1653 | 866 mainwin_set_song_info(rate, freq, nch); |
0 | 867 } |
868 | |
869 void | |
870 playlist_check_pos_current(void) | |
871 { | |
872 gint pos, row, bottom; | |
873 | |
874 PLAYLIST_LOCK(); | |
875 if (!playlist || !playlist_position || !playlistwin_list) { | |
876 PLAYLIST_UNLOCK(); | |
877 return; | |
878 } | |
879 | |
880 pos = g_list_index(playlist, playlist_position); | |
881 | |
882 if (playlistwin_item_visible(pos)) { | |
883 PLAYLIST_UNLOCK(); | |
884 return; | |
885 } | |
886 | |
887 bottom = MAX(0, playlist_get_length_nolock() - | |
888 playlistwin_list->pl_num_visible); | |
889 row = CLAMP(pos - playlistwin_list->pl_num_visible / 2, 0, bottom); | |
890 PLAYLIST_UNLOCK(); | |
891 playlistwin_set_toprow(row); | |
2026 | 892 g_cond_signal(cond_scan); |
0 | 893 } |
894 | |
895 void | |
2080
df6cf9cb531e
[svn] - this commit breaks the API. I'm not done here, but hopefully the new API is
nenolod
parents:
2073
diff
changeset
|
896 playlist_next(Playlist *playlist) |
0 | 897 { |
898 GList *plist_pos_list; | |
899 gboolean restart_playing = FALSE; | |
900 | |
901 PLAYLIST_LOCK(); | |
902 if (!playlist) { | |
903 PLAYLIST_UNLOCK(); | |
904 return; | |
905 } | |
2040
dbe615def81f
[svn] Playlist shuffle behaviour should now be a little more consistant.
nazca
parents:
2027
diff
changeset
|
906 |
dbe615def81f
[svn] Playlist shuffle behaviour should now be a little more consistant.
nazca
parents:
2027
diff
changeset
|
907 if ((playlist_position_before_jump != NULL) && !queued_list) |
dbe615def81f
[svn] Playlist shuffle behaviour should now be a little more consistant.
nazca
parents:
2027
diff
changeset
|
908 { |
2080
df6cf9cb531e
[svn] - this commit breaks the API. I'm not done here, but hopefully the new API is
nenolod
parents:
2073
diff
changeset
|
909 playlist->position = playlist_position_before_jump; |
2040
dbe615def81f
[svn] Playlist shuffle behaviour should now be a little more consistant.
nazca
parents:
2027
diff
changeset
|
910 playlist_position_before_jump = NULL; |
dbe615def81f
[svn] Playlist shuffle behaviour should now be a little more consistant.
nazca
parents:
2027
diff
changeset
|
911 } |
0 | 912 |
2080
df6cf9cb531e
[svn] - this commit breaks the API. I'm not done here, but hopefully the new API is
nenolod
parents:
2073
diff
changeset
|
913 plist_pos_list = find_playlist_position_list(playlist); |
0 | 914 |
1026 | 915 if (!cfg.repeat && !g_list_next(plist_pos_list) && !queued_list) { |
0 | 916 PLAYLIST_UNLOCK(); |
917 return; | |
918 } | |
919 | |
920 if (bmp_playback_get_playing()) { | |
921 /* We need to stop before changing playlist_position */ | |
922 PLAYLIST_UNLOCK(); | |
895
1b919783797e
[svn] - should fix the ability to change songs while paused
nhjm449
parents:
853
diff
changeset
|
923 ip_data.stop = TRUE; |
0 | 924 bmp_playback_stop(); |
895
1b919783797e
[svn] - should fix the ability to change songs while paused
nhjm449
parents:
853
diff
changeset
|
925 ip_data.stop = FALSE; |
0 | 926 PLAYLIST_LOCK(); |
927 restart_playing = TRUE; | |
928 } | |
929 | |
2080
df6cf9cb531e
[svn] - this commit breaks the API. I'm not done here, but hopefully the new API is
nenolod
parents:
2073
diff
changeset
|
930 plist_pos_list = find_playlist_position_list(playlist); |
0 | 931 if (queued_list) |
932 play_queued(); | |
933 else if (g_list_next(plist_pos_list)) | |
2080
df6cf9cb531e
[svn] - this commit breaks the API. I'm not done here, but hopefully the new API is
nenolod
parents:
2073
diff
changeset
|
934 playlist->position = g_list_next(plist_pos_list)->data; |
0 | 935 else if (cfg.repeat) { |
2080
df6cf9cb531e
[svn] - this commit breaks the API. I'm not done here, but hopefully the new API is
nenolod
parents:
2073
diff
changeset
|
936 playlist->position = NULL; |
df6cf9cb531e
[svn] - this commit breaks the API. I'm not done here, but hopefully the new API is
nenolod
parents:
2073
diff
changeset
|
937 playlist_generate_shuffle_list_nolock(playlist); |
0 | 938 if (cfg.shuffle) |
2080
df6cf9cb531e
[svn] - this commit breaks the API. I'm not done here, but hopefully the new API is
nenolod
parents:
2073
diff
changeset
|
939 playlist->position = playlist->shuffle->data; |
0 | 940 else |
2080
df6cf9cb531e
[svn] - this commit breaks the API. I'm not done here, but hopefully the new API is
nenolod
parents:
2073
diff
changeset
|
941 playlist->position = playlist->entries->data; |
0 | 942 } |
943 PLAYLIST_UNLOCK(); | |
944 playlist_check_pos_current(); | |
945 | |
946 if (restart_playing) | |
947 bmp_playback_initiate(); | |
948 else { | |
949 mainwin_set_info_text(); | |
950 playlistwin_update_list(); | |
951 } | |
952 } | |
953 | |
954 void | |
955 playlist_prev(void) | |
956 { | |
957 GList *plist_pos_list; | |
958 gboolean restart_playing = FALSE; | |
959 | |
960 PLAYLIST_LOCK(); | |
961 if (!playlist) { | |
962 PLAYLIST_UNLOCK(); | |
963 return; | |
964 } | |
2040
dbe615def81f
[svn] Playlist shuffle behaviour should now be a little more consistant.
nazca
parents:
2027
diff
changeset
|
965 |
dbe615def81f
[svn] Playlist shuffle behaviour should now be a little more consistant.
nazca
parents:
2027
diff
changeset
|
966 if ((playlist_position_before_jump != NULL) && !queued_list) |
dbe615def81f
[svn] Playlist shuffle behaviour should now be a little more consistant.
nazca
parents:
2027
diff
changeset
|
967 { |
dbe615def81f
[svn] Playlist shuffle behaviour should now be a little more consistant.
nazca
parents:
2027
diff
changeset
|
968 playlist_position = playlist_position_before_jump; |
dbe615def81f
[svn] Playlist shuffle behaviour should now be a little more consistant.
nazca
parents:
2027
diff
changeset
|
969 playlist_position_before_jump = NULL; |
dbe615def81f
[svn] Playlist shuffle behaviour should now be a little more consistant.
nazca
parents:
2027
diff
changeset
|
970 } |
0 | 971 |
972 plist_pos_list = find_playlist_position_list(); | |
973 | |
974 if (!cfg.repeat && !g_list_previous(plist_pos_list)) { | |
975 PLAYLIST_UNLOCK(); | |
976 return; | |
977 } | |
978 | |
979 if (bmp_playback_get_playing()) { | |
980 /* We need to stop before changing playlist_position */ | |
981 PLAYLIST_UNLOCK(); | |
895
1b919783797e
[svn] - should fix the ability to change songs while paused
nhjm449
parents:
853
diff
changeset
|
982 ip_data.stop = TRUE; |
0 | 983 bmp_playback_stop(); |
895
1b919783797e
[svn] - should fix the ability to change songs while paused
nhjm449
parents:
853
diff
changeset
|
984 ip_data.stop = FALSE; |
0 | 985 PLAYLIST_LOCK(); |
986 restart_playing = TRUE; | |
987 } | |
988 | |
989 plist_pos_list = find_playlist_position_list(); | |
990 if (g_list_previous(plist_pos_list)) { | |
991 playlist_position = g_list_previous(plist_pos_list)->data; | |
992 } | |
993 else if (cfg.repeat) { | |
994 GList *node; | |
995 playlist_position = NULL; | |
2080
df6cf9cb531e
[svn] - this commit breaks the API. I'm not done here, but hopefully the new API is
nenolod
parents:
2073
diff
changeset
|
996 playlist_generate_shuffle_list_nolock(playlist); |
0 | 997 if (cfg.shuffle) |
998 node = g_list_last(shuffle_list); | |
999 else | |
1000 node = g_list_last(playlist); | |
1001 if (node) | |
1002 playlist_position = node->data; | |
1003 } | |
1004 | |
1005 PLAYLIST_UNLOCK(); | |
1006 | |
1007 playlist_check_pos_current(); | |
1008 | |
1009 if (restart_playing) | |
1010 bmp_playback_initiate(); | |
1011 else { | |
1012 mainwin_set_info_text(); | |
1013 playlistwin_update_list(); | |
1014 } | |
1015 } | |
1016 | |
1017 void | |
1018 playlist_queue(void) | |
1019 { | |
1020 GList *list = playlist_get_selected(); | |
1021 GList *it = list; | |
1022 | |
1023 PLAYLIST_LOCK(); | |
2040
dbe615def81f
[svn] Playlist shuffle behaviour should now be a little more consistant.
nazca
parents:
2027
diff
changeset
|
1024 |
dbe615def81f
[svn] Playlist shuffle behaviour should now be a little more consistant.
nazca
parents:
2027
diff
changeset
|
1025 if ((cfg.shuffle) && (playlist_position_before_jump == NULL)) |
dbe615def81f
[svn] Playlist shuffle behaviour should now be a little more consistant.
nazca
parents:
2027
diff
changeset
|
1026 { |
dbe615def81f
[svn] Playlist shuffle behaviour should now be a little more consistant.
nazca
parents:
2027
diff
changeset
|
1027 /* Shuffling and this is our first manual jump. */ |
dbe615def81f
[svn] Playlist shuffle behaviour should now be a little more consistant.
nazca
parents:
2027
diff
changeset
|
1028 playlist_position_before_jump = playlist_position; |
dbe615def81f
[svn] Playlist shuffle behaviour should now be a little more consistant.
nazca
parents:
2027
diff
changeset
|
1029 } |
0 | 1030 |
1031 while (it) { | |
1032 GList *next = g_list_next(it); | |
1033 GList *tmp; | |
1034 | |
1035 it->data = g_list_nth_data(playlist, GPOINTER_TO_INT(it->data)); | |
1036 if ((tmp = g_list_find(queued_list, it->data))) { | |
1037 queued_list = g_list_remove_link(queued_list, tmp); | |
1038 g_list_free_1(tmp); | |
1039 list = g_list_remove_link(list, it); | |
1040 g_list_free_1(it); | |
1041 } | |
1042 | |
1043 it = next; | |
1044 } | |
1045 | |
1046 queued_list = g_list_concat(queued_list, list); | |
1047 | |
1048 PLAYLIST_UNLOCK(); | |
1049 | |
1050 playlist_recalc_total_time(); | |
1051 playlistwin_update_list(); | |
1052 } | |
1053 | |
1054 void | |
1055 playlist_queue_position(guint pos) | |
1056 { | |
1057 GList *tmp; | |
1058 PlaylistEntry *entry; | |
1059 | |
1060 PLAYLIST_LOCK(); | |
2040
dbe615def81f
[svn] Playlist shuffle behaviour should now be a little more consistant.
nazca
parents:
2027
diff
changeset
|
1061 |
dbe615def81f
[svn] Playlist shuffle behaviour should now be a little more consistant.
nazca
parents:
2027
diff
changeset
|
1062 if ((cfg.shuffle) && (playlist_position_before_jump == NULL)) |
dbe615def81f
[svn] Playlist shuffle behaviour should now be a little more consistant.
nazca
parents:
2027
diff
changeset
|
1063 { |
dbe615def81f
[svn] Playlist shuffle behaviour should now be a little more consistant.
nazca
parents:
2027
diff
changeset
|
1064 /* Shuffling and this is our first manual jump. */ |
dbe615def81f
[svn] Playlist shuffle behaviour should now be a little more consistant.
nazca
parents:
2027
diff
changeset
|
1065 playlist_position_before_jump = playlist_position; |
dbe615def81f
[svn] Playlist shuffle behaviour should now be a little more consistant.
nazca
parents:
2027
diff
changeset
|
1066 } |
dbe615def81f
[svn] Playlist shuffle behaviour should now be a little more consistant.
nazca
parents:
2027
diff
changeset
|
1067 |
0 | 1068 entry = g_list_nth_data(playlist, pos); |
1069 if ((tmp = g_list_find(queued_list, entry))) { | |
1070 queued_list = g_list_remove_link(queued_list, tmp); | |
1071 g_list_free_1(tmp); | |
1072 } | |
1073 else | |
1074 queued_list = g_list_append(queued_list, entry); | |
1075 PLAYLIST_UNLOCK(); | |
1076 | |
1077 playlist_recalc_total_time(); | |
1078 playlistwin_update_list(); | |
1079 } | |
1080 | |
1081 gboolean | |
1082 playlist_is_position_queued(guint pos) | |
1083 { | |
1084 PlaylistEntry *entry; | |
1085 GList *tmp; | |
1086 | |
1087 PLAYLIST_LOCK(); | |
1088 entry = g_list_nth_data(playlist, pos); | |
1089 tmp = g_list_find(queued_list, entry); | |
1090 PLAYLIST_UNLOCK(); | |
1091 | |
1092 return tmp != NULL; | |
1093 } | |
1094 | |
984 | 1095 gint |
1096 playlist_get_queue_position_number(guint pos) | |
1097 { | |
1098 PlaylistEntry *entry; | |
1099 gint tmp; | |
1100 | |
1101 PLAYLIST_LOCK(); | |
1102 entry = g_list_nth_data(playlist, pos); | |
1103 tmp = g_list_index(queued_list, entry); | |
1104 PLAYLIST_UNLOCK(); | |
1105 | |
1106 return tmp; | |
1107 } | |
1108 | |
1109 gint | |
1110 playlist_get_queue_qposition_number(guint pos) | |
1111 { | |
1112 PlaylistEntry *entry; | |
1113 gint tmp; | |
1114 | |
1115 PLAYLIST_LOCK(); | |
1116 entry = g_list_nth_data(queued_list, pos); | |
1117 tmp = g_list_index(playlist, entry); | |
1118 PLAYLIST_UNLOCK(); | |
1119 | |
1120 return tmp; | |
1121 } | |
1122 | |
0 | 1123 void |
1124 playlist_clear_queue(void) | |
1125 { | |
1126 PLAYLIST_LOCK(); | |
1127 g_list_free(queued_list); | |
1128 queued_list = NULL; | |
1129 PLAYLIST_UNLOCK(); | |
1130 | |
1131 playlist_recalc_total_time(); | |
1132 playlistwin_update_list(); | |
1133 } | |
1134 | |
1135 void | |
1136 playlist_queue_remove(guint pos) | |
1137 { | |
1138 void *entry; | |
1139 | |
1140 PLAYLIST_LOCK(); | |
1141 entry = g_list_nth_data(playlist, pos); | |
1142 queued_list = g_list_remove(queued_list, entry); | |
1143 PLAYLIST_UNLOCK(); | |
1144 | |
1145 playlistwin_update_list(); | |
1146 } | |
1147 | |
1148 gint | |
1149 playlist_get_queue_position(PlaylistEntry * entry) | |
1150 { | |
1151 return g_list_index(queued_list, entry); | |
1152 } | |
1153 | |
1154 void | |
1155 playlist_set_position(guint pos) | |
1156 { | |
1157 GList *node; | |
1158 gboolean restart_playing = FALSE; | |
1159 | |
1160 PLAYLIST_LOCK(); | |
1161 if (!playlist) { | |
1162 PLAYLIST_UNLOCK(); | |
1163 return; | |
1164 } | |
1165 | |
1166 node = g_list_nth(playlist, pos); | |
1167 if (!node) { | |
1168 PLAYLIST_UNLOCK(); | |
1169 return; | |
1170 } | |
1171 | |
1172 if (bmp_playback_get_playing()) { | |
1173 /* We need to stop before changing playlist_position */ | |
1174 PLAYLIST_UNLOCK(); | |
923 | 1175 ip_data.stop = TRUE; |
0 | 1176 bmp_playback_stop(); |
923 | 1177 ip_data.stop = FALSE; |
0 | 1178 PLAYLIST_LOCK(); |
1179 restart_playing = TRUE; | |
1180 } | |
1181 | |
2040
dbe615def81f
[svn] Playlist shuffle behaviour should now be a little more consistant.
nazca
parents:
2027
diff
changeset
|
1182 if ((cfg.shuffle) && (playlist_position_before_jump == NULL)) |
dbe615def81f
[svn] Playlist shuffle behaviour should now be a little more consistant.
nazca
parents:
2027
diff
changeset
|
1183 { |
dbe615def81f
[svn] Playlist shuffle behaviour should now be a little more consistant.
nazca
parents:
2027
diff
changeset
|
1184 /* Shuffling and this is our first manual jump. */ |
dbe615def81f
[svn] Playlist shuffle behaviour should now be a little more consistant.
nazca
parents:
2027
diff
changeset
|
1185 playlist_position_before_jump = playlist_position; |
dbe615def81f
[svn] Playlist shuffle behaviour should now be a little more consistant.
nazca
parents:
2027
diff
changeset
|
1186 } |
dbe615def81f
[svn] Playlist shuffle behaviour should now be a little more consistant.
nazca
parents:
2027
diff
changeset
|
1187 |
0 | 1188 playlist_position = node->data; |
1189 PLAYLIST_UNLOCK(); | |
1190 playlist_check_pos_current(); | |
1191 | |
1192 if (restart_playing) | |
1193 bmp_playback_initiate(); | |
1194 else { | |
1195 mainwin_set_info_text(); | |
1196 playlistwin_update_list(); | |
1197 } | |
1198 } | |
1199 | |
1200 void | |
2080
df6cf9cb531e
[svn] - this commit breaks the API. I'm not done here, but hopefully the new API is
nenolod
parents:
2073
diff
changeset
|
1201 playlist_eof_reached(Playlist *playlist) |
0 | 1202 { |
1203 GList *plist_pos_list; | |
1204 | |
904
2cb51ff37e8d
[svn] - stop the psuedo output plugin when using 'no playlist advance' or 'stop after current song'
nhjm449
parents:
898
diff
changeset
|
1205 if ((cfg.no_playlist_advance && !cfg.repeat) || cfg.stopaftersong) |
2cb51ff37e8d
[svn] - stop the psuedo output plugin when using 'no playlist advance' or 'stop after current song'
nhjm449
parents:
898
diff
changeset
|
1206 ip_data.stop = TRUE; |
0 | 1207 bmp_playback_stop(); |
904
2cb51ff37e8d
[svn] - stop the psuedo output plugin when using 'no playlist advance' or 'stop after current song'
nhjm449
parents:
898
diff
changeset
|
1208 if ((cfg.no_playlist_advance && !cfg.repeat) || cfg.stopaftersong) |
2cb51ff37e8d
[svn] - stop the psuedo output plugin when using 'no playlist advance' or 'stop after current song'
nhjm449
parents:
898
diff
changeset
|
1209 ip_data.stop = FALSE; |
0 | 1210 |
1211 PLAYLIST_LOCK(); | |
2040
dbe615def81f
[svn] Playlist shuffle behaviour should now be a little more consistant.
nazca
parents:
2027
diff
changeset
|
1212 |
dbe615def81f
[svn] Playlist shuffle behaviour should now be a little more consistant.
nazca
parents:
2027
diff
changeset
|
1213 if ((playlist_position_before_jump != NULL) && !queued_list) |
dbe615def81f
[svn] Playlist shuffle behaviour should now be a little more consistant.
nazca
parents:
2027
diff
changeset
|
1214 { |
2080
df6cf9cb531e
[svn] - this commit breaks the API. I'm not done here, but hopefully the new API is
nenolod
parents:
2073
diff
changeset
|
1215 playlist->position = playlist_position_before_jump; |
2040
dbe615def81f
[svn] Playlist shuffle behaviour should now be a little more consistant.
nazca
parents:
2027
diff
changeset
|
1216 playlist_position_before_jump = NULL; |
dbe615def81f
[svn] Playlist shuffle behaviour should now be a little more consistant.
nazca
parents:
2027
diff
changeset
|
1217 } |
dbe615def81f
[svn] Playlist shuffle behaviour should now be a little more consistant.
nazca
parents:
2027
diff
changeset
|
1218 |
0 | 1219 plist_pos_list = find_playlist_position_list(); |
1220 | |
1221 if (cfg.no_playlist_advance) { | |
1222 PLAYLIST_UNLOCK(); | |
1223 mainwin_clear_song_info(); | |
1224 if (cfg.repeat) | |
1225 bmp_playback_initiate(); | |
1226 return; | |
1227 } | |
1228 | |
898 | 1229 if (cfg.stopaftersong) { |
1230 PLAYLIST_UNLOCK(); | |
1231 mainwin_clear_song_info(); | |
1232 mainwin_set_stopaftersong(FALSE); | |
1233 return; | |
1234 } | |
1235 | |
0 | 1236 if (queued_list) { |
1237 play_queued(); | |
1238 } | |
1239 else if (!g_list_next(plist_pos_list)) { | |
1240 if (cfg.shuffle) { | |
2080
df6cf9cb531e
[svn] - this commit breaks the API. I'm not done here, but hopefully the new API is
nenolod
parents:
2073
diff
changeset
|
1241 playlist->position = NULL; |
df6cf9cb531e
[svn] - this commit breaks the API. I'm not done here, but hopefully the new API is
nenolod
parents:
2073
diff
changeset
|
1242 playlist_generate_shuffle_list_nolock(playlist); |
0 | 1243 } |
1244 else | |
2080
df6cf9cb531e
[svn] - this commit breaks the API. I'm not done here, but hopefully the new API is
nenolod
parents:
2073
diff
changeset
|
1245 playlist->position = playlist->entries->data; |
0 | 1246 |
1247 if (!cfg.repeat) { | |
1248 PLAYLIST_UNLOCK(); | |
1249 mainwin_clear_song_info(); | |
1250 mainwin_set_info_text(); | |
1251 return; | |
1252 } | |
1253 } | |
1254 else | |
2080
df6cf9cb531e
[svn] - this commit breaks the API. I'm not done here, but hopefully the new API is
nenolod
parents:
2073
diff
changeset
|
1255 playlist->position = g_list_next(plist_pos_list)->data; |
0 | 1256 |
1257 PLAYLIST_UNLOCK(); | |
1258 | |
1259 playlist_check_pos_current(); | |
1260 bmp_playback_initiate(); | |
1261 mainwin_set_info_text(); | |
1262 playlistwin_update_list(); | |
1263 } | |
1264 | |
1265 gint | |
1266 playlist_get_length(void) | |
1267 { | |
1268 gint retval; | |
1269 | |
1270 PLAYLIST_LOCK(); | |
1271 retval = playlist_get_length_nolock(); | |
1272 PLAYLIST_UNLOCK(); | |
1273 | |
1274 return retval; | |
1275 } | |
1276 | |
1277 gint | |
1278 playlist_queue_get_length(void) | |
1279 { | |
1280 gint length; | |
1281 | |
1282 PLAYLIST_LOCK(); | |
1283 length = g_list_length(queued_list); | |
1284 PLAYLIST_UNLOCK(); | |
1285 | |
1286 return length; | |
1287 } | |
1288 | |
1289 gint | |
1290 playlist_get_length_nolock(void) | |
1291 { | |
1292 return g_list_length(playlist); | |
1293 } | |
1294 | |
1295 gchar * | |
1296 playlist_get_info_text(void) | |
1297 { | |
1298 gchar *text, *title, *numbers, *length; | |
1299 | |
1300 PLAYLIST_LOCK(); | |
1301 if (!playlist_position) { | |
1302 PLAYLIST_UNLOCK(); | |
1303 return NULL; | |
1304 } | |
1305 | |
1306 /* FIXME: there should not be a need to do additional conversion, | |
1307 * if playlist is properly maintained */ | |
1308 if (playlist_position->title) { | |
1309 title = str_to_utf8(playlist_position->title); | |
1310 } | |
1311 else { | |
1312 gchar *basename = g_path_get_basename(playlist_position->filename); | |
1313 title = filename_to_utf8(basename); | |
1314 g_free(basename); | |
1315 } | |
1316 | |
1317 /* | |
1318 * If the user don't want numbers in the playlist, don't | |
1319 * display them in other parts of XMMS | |
1320 */ | |
1321 | |
1322 if (cfg.show_numbers_in_pl) | |
1323 numbers = g_strdup_printf("%d. ", playlist_get_position_nolock() + 1); | |
1324 else | |
1325 numbers = g_strdup(""); | |
1326 | |
1327 if (playlist_position->length != -1) | |
1328 length = g_strdup_printf(" (%d:%-2.2d)", | |
1329 playlist_position->length / 60000, | |
1330 (playlist_position->length / 1000) % 60); | |
1331 else | |
1332 length = g_strdup(""); | |
1333 | |
1334 PLAYLIST_UNLOCK(); | |
1335 | |
1336 text = convert_title_text(g_strconcat(numbers, title, length, NULL)); | |
1337 | |
1338 g_free(numbers); | |
1339 g_free(title); | |
1340 g_free(length); | |
1341 | |
1342 return text; | |
1343 } | |
1344 | |
1345 gint | |
1346 playlist_get_current_length(void) | |
1347 { | |
1348 gint len = 0; | |
1349 | |
1350 PLAYLIST_LOCK(); | |
1351 if (playlist && playlist_position) | |
1352 len = playlist_position->length; | |
1353 PLAYLIST_UNLOCK(); | |
1354 | |
1355 return len; | |
1356 } | |
1357 | |
1358 gboolean | |
1553 | 1359 playlist_save(const gchar * filename) |
0 | 1360 { |
1553 | 1361 PlaylistContainer *plc = NULL; |
1362 gchar *ext; | |
0 | 1363 |
1364 g_return_val_if_fail(filename != NULL, FALSE); | |
1365 | |
1553 | 1366 ext = strrchr(filename, '.') + 1; |
1367 | |
0 | 1368 playlist_set_current_name(filename); |
1369 | |
1553 | 1370 if ((plc = playlist_container_find(ext)) == NULL) |
0 | 1371 return FALSE; |
1372 | |
1555 | 1373 if (plc->plc_write == NULL) |
1374 return FALSE; | |
1375 | |
1553 | 1376 plc->plc_write(filename, 0); |
1377 | |
1378 return TRUE; | |
0 | 1379 } |
1380 | |
1381 gboolean | |
1382 playlist_load(const gchar * filename) | |
1383 { | |
397
4fa1244ad483
[svn] Do not generate a cache when loading a playlist.
nenolod
parents:
383
diff
changeset
|
1384 gboolean ret = FALSE; |
4fa1244ad483
[svn] Do not generate a cache when loading a playlist.
nenolod
parents:
383
diff
changeset
|
1385 |
4fa1244ad483
[svn] Do not generate a cache when loading a playlist.
nenolod
parents:
383
diff
changeset
|
1386 loading_playlist = TRUE; |
4fa1244ad483
[svn] Do not generate a cache when loading a playlist.
nenolod
parents:
383
diff
changeset
|
1387 ret = playlist_load_ins(filename, -1); |
4fa1244ad483
[svn] Do not generate a cache when loading a playlist.
nenolod
parents:
383
diff
changeset
|
1388 loading_playlist = FALSE; |
4fa1244ad483
[svn] Do not generate a cache when loading a playlist.
nenolod
parents:
383
diff
changeset
|
1389 |
4fa1244ad483
[svn] Do not generate a cache when loading a playlist.
nenolod
parents:
383
diff
changeset
|
1390 return ret; |
0 | 1391 } |
1392 | |
1554 | 1393 void |
0 | 1394 playlist_load_ins_file(const gchar * filename_p, |
1395 const gchar * playlist_name, gint pos, | |
1396 const gchar * title, gint len) | |
1397 { | |
1398 gchar *filename; | |
1399 gchar *tmp, *path; | |
355
1c701dfe5098
[svn] Cache the decoder used for each PlaylistEntry. This reduces the amount
nenolod
parents:
284
diff
changeset
|
1400 InputPlugin *dec; /* for decoder cache */ |
0 | 1401 |
1402 g_return_if_fail(filename_p != NULL); | |
1403 g_return_if_fail(playlist_name != NULL); | |
1404 | |
633
bf9bc9a514ba
[svn] Use g_strchug instead of g_strstrip during playlist load. Trailing whitespace can be a valid occurance. Closes bug #282.
chainsaw
parents:
538
diff
changeset
|
1405 filename = g_strchug(g_strdup(filename_p)); |
0 | 1406 |
2019
d3a62e1075e2
[svn] Allow \ to / conversion to be switched on & off, by external contributor Chris Kehler <cbkehler@sympatico.ca>.
chainsaw
parents:
2010
diff
changeset
|
1407 if(cfg.convert_slash) |
944
03d141f44b4d
[svn] Convert \ path separators to /. Support was already present, but was not enabled before. Closes bug #461.
chainsaw
parents:
923
diff
changeset
|
1408 while ((tmp = strchr(filename, '\\')) != NULL) |
03d141f44b4d
[svn] Convert \ path separators to /. Support was already present, but was not enabled before. Closes bug #461.
chainsaw
parents:
923
diff
changeset
|
1409 *tmp = '/'; |
0 | 1410 |
1411 if (filename[0] != '/' && !strstr(filename, "://")) { | |
1412 path = g_strdup(playlist_name); | |
1413 if ((tmp = strrchr(path, '/'))) | |
1414 *tmp = '\0'; | |
1415 else { | |
1163
ff71f891265b
[svn] - Allow to do format detection on demand; instead of immediately on add
nenolod
parents:
1026
diff
changeset
|
1416 if (loading_playlist != TRUE || cfg.playlist_detect == FALSE) |
397
4fa1244ad483
[svn] Do not generate a cache when loading a playlist.
nenolod
parents:
383
diff
changeset
|
1417 dec = input_check_file(filename, FALSE); |
4fa1244ad483
[svn] Do not generate a cache when loading a playlist.
nenolod
parents:
383
diff
changeset
|
1418 else |
4fa1244ad483
[svn] Do not generate a cache when loading a playlist.
nenolod
parents:
383
diff
changeset
|
1419 dec = NULL; |
4fa1244ad483
[svn] Do not generate a cache when loading a playlist.
nenolod
parents:
383
diff
changeset
|
1420 |
355
1c701dfe5098
[svn] Cache the decoder used for each PlaylistEntry. This reduces the amount
nenolod
parents:
284
diff
changeset
|
1421 __playlist_ins_with_info(filename, pos, title, len, dec); |
0 | 1422 return; |
1423 } | |
1424 tmp = g_build_filename(path, filename, NULL); | |
397
4fa1244ad483
[svn] Do not generate a cache when loading a playlist.
nenolod
parents:
383
diff
changeset
|
1425 |
1165 | 1426 if (loading_playlist != TRUE && cfg.playlist_detect != TRUE) |
397
4fa1244ad483
[svn] Do not generate a cache when loading a playlist.
nenolod
parents:
383
diff
changeset
|
1427 dec = input_check_file(tmp, FALSE); |
4fa1244ad483
[svn] Do not generate a cache when loading a playlist.
nenolod
parents:
383
diff
changeset
|
1428 else |
4fa1244ad483
[svn] Do not generate a cache when loading a playlist.
nenolod
parents:
383
diff
changeset
|
1429 dec = NULL; |
4fa1244ad483
[svn] Do not generate a cache when loading a playlist.
nenolod
parents:
383
diff
changeset
|
1430 |
355
1c701dfe5098
[svn] Cache the decoder used for each PlaylistEntry. This reduces the amount
nenolod
parents:
284
diff
changeset
|
1431 __playlist_ins_with_info(tmp, pos, title, len, dec); |
0 | 1432 g_free(tmp); |
1433 g_free(path); | |
1434 } | |
1435 else | |
355
1c701dfe5098
[svn] Cache the decoder used for each PlaylistEntry. This reduces the amount
nenolod
parents:
284
diff
changeset
|
1436 { |
1165 | 1437 if (loading_playlist != TRUE && cfg.playlist_detect != TRUE) |
397
4fa1244ad483
[svn] Do not generate a cache when loading a playlist.
nenolod
parents:
383
diff
changeset
|
1438 dec = input_check_file(filename, FALSE); |
4fa1244ad483
[svn] Do not generate a cache when loading a playlist.
nenolod
parents:
383
diff
changeset
|
1439 else |
4fa1244ad483
[svn] Do not generate a cache when loading a playlist.
nenolod
parents:
383
diff
changeset
|
1440 dec = NULL; |
4fa1244ad483
[svn] Do not generate a cache when loading a playlist.
nenolod
parents:
383
diff
changeset
|
1441 |
355
1c701dfe5098
[svn] Cache the decoder used for each PlaylistEntry. This reduces the amount
nenolod
parents:
284
diff
changeset
|
1442 __playlist_ins_with_info(filename, pos, title, len, dec); |
1c701dfe5098
[svn] Cache the decoder used for each PlaylistEntry. This reduces the amount
nenolod
parents:
284
diff
changeset
|
1443 } |
0 | 1444 |
1445 g_free(filename); | |
1446 } | |
1447 | |
1584 | 1448 void |
1449 playlist_load_ins_file_tuple(const gchar * filename_p, | |
1450 const gchar * playlist_name, | |
1451 gint pos, | |
1452 TitleInput *tuple) | |
1453 { | |
1454 gchar *filename; | |
1455 gchar *tmp, *path; | |
1456 InputPlugin *dec; /* for decoder cache */ | |
1457 | |
1458 g_return_if_fail(filename_p != NULL); | |
1459 g_return_if_fail(playlist_name != NULL); | |
1460 | |
1461 filename = g_strchug(g_strdup(filename_p)); | |
1462 | |
1463 while ((tmp = strchr(filename, '\\')) != NULL) | |
1464 *tmp = '/'; | |
1465 | |
1466 if (filename[0] != '/' && !strstr(filename, "://")) { | |
1467 path = g_strdup(playlist_name); | |
1468 if ((tmp = strrchr(path, '/'))) | |
1469 *tmp = '\0'; | |
1470 else { | |
1471 if (loading_playlist != TRUE || cfg.playlist_detect == FALSE) | |
1472 dec = input_check_file(filename, FALSE); | |
1473 else | |
1474 dec = NULL; | |
1475 | |
1476 __playlist_ins_with_info_tuple(filename, pos, tuple, dec); | |
1477 return; | |
1478 } | |
1479 tmp = g_build_filename(path, filename, NULL); | |
1480 | |
1481 if (loading_playlist != TRUE && cfg.playlist_detect != TRUE) | |
1482 dec = input_check_file(tmp, FALSE); | |
1483 else | |
1484 dec = NULL; | |
1485 | |
1486 __playlist_ins_with_info_tuple(tmp, pos, tuple, dec); | |
1487 g_free(tmp); | |
1488 g_free(path); | |
1489 } | |
1490 else | |
1491 { | |
1492 if (loading_playlist != TRUE && cfg.playlist_detect != TRUE) | |
1493 dec = input_check_file(filename, FALSE); | |
1494 else | |
1495 dec = NULL; | |
1496 | |
1497 __playlist_ins_with_info_tuple(filename, pos, tuple, dec); | |
1498 } | |
1499 | |
1500 g_free(filename); | |
1501 } | |
1502 | |
0 | 1503 static guint |
1504 playlist_load_ins(const gchar * filename, gint pos) | |
1505 { | |
1554 | 1506 PlaylistContainer *plc; |
1507 gchar *ext; | |
0 | 1508 |
1509 g_return_val_if_fail(filename != NULL, 0); | |
1510 | |
1554 | 1511 ext = strrchr(filename, '.') + 1; |
1512 plc = playlist_container_find(ext); | |
1513 | |
1514 g_return_val_if_fail(plc != NULL, 0); | |
1515 g_return_val_if_fail(plc->plc_read != NULL, 0); | |
1516 | |
1560
5840d797ea02
[svn] - hmm, calling plc->load() might be a good idea!
nenolod
parents:
1559
diff
changeset
|
1517 plc->plc_read(filename, pos); |
5840d797ea02
[svn] - hmm, calling plc->load() might be a good idea!
nenolod
parents:
1559
diff
changeset
|
1518 |
2080
df6cf9cb531e
[svn] - this commit breaks the API. I'm not done here, but hopefully the new API is
nenolod
parents:
2073
diff
changeset
|
1519 playlist_generate_shuffle_list(playlist); |
1554 | 1520 playlistwin_update_list(); |
1521 | |
1522 return 1; | |
0 | 1523 } |
1524 | |
1525 GList * | |
2080
df6cf9cb531e
[svn] - this commit breaks the API. I'm not done here, but hopefully the new API is
nenolod
parents:
2073
diff
changeset
|
1526 get_playlist_nth(Playlist *playlist, guint nth) |
0 | 1527 { |
2080
df6cf9cb531e
[svn] - this commit breaks the API. I'm not done here, but hopefully the new API is
nenolod
parents:
2073
diff
changeset
|
1528 REQUIRE_STATIC_LOCK(playlists); |
df6cf9cb531e
[svn] - this commit breaks the API. I'm not done here, but hopefully the new API is
nenolod
parents:
2073
diff
changeset
|
1529 return g_list_nth(playlist->entries, nth); |
0 | 1530 } |
1531 | |
1532 | |
1533 GList * | |
1534 playlist_get(void) | |
1535 { | |
2080
df6cf9cb531e
[svn] - this commit breaks the API. I'm not done here, but hopefully the new API is
nenolod
parents:
2073
diff
changeset
|
1536 REQUIRE_STATIC_LOCK(playlists); |
df6cf9cb531e
[svn] - this commit breaks the API. I'm not done here, but hopefully the new API is
nenolod
parents:
2073
diff
changeset
|
1537 return playlist_get_active()->entries; |
0 | 1538 } |
1539 | |
1540 gint | |
1541 playlist_get_position_nolock(void) | |
1542 { | |
1543 if (playlist && playlist_position) | |
1544 return g_list_index(playlist, playlist_position); | |
1545 return 0; | |
1546 } | |
1547 | |
1548 gint | |
1549 playlist_get_position(void) | |
1550 { | |
1551 gint pos; | |
1552 | |
1553 PLAYLIST_LOCK(); | |
1554 pos = playlist_get_position_nolock(); | |
1555 PLAYLIST_UNLOCK(); | |
1556 | |
1557 return pos; | |
1558 } | |
1559 | |
1560 gchar * | |
1561 playlist_get_filename(guint pos) | |
1562 { | |
1563 gchar *filename; | |
1564 PlaylistEntry *entry; | |
1565 GList *node; | |
1566 | |
1567 PLAYLIST_LOCK(); | |
1568 if (!playlist) { | |
1569 PLAYLIST_UNLOCK(); | |
1570 return NULL; | |
1571 } | |
1572 node = g_list_nth(playlist, pos); | |
1573 if (!node) { | |
1574 PLAYLIST_UNLOCK(); | |
1575 return NULL; | |
1576 } | |
1577 entry = node->data; | |
1578 | |
1579 filename = g_strdup(entry->filename); | |
1580 PLAYLIST_UNLOCK(); | |
1581 | |
1582 return filename; | |
1583 } | |
1584 | |
1585 gchar * | |
2080
df6cf9cb531e
[svn] - this commit breaks the API. I'm not done here, but hopefully the new API is
nenolod
parents:
2073
diff
changeset
|
1586 playlist_get_songtitle(Playlist *playlist, guint pos) |
0 | 1587 { |
1588 gchar *title = NULL; | |
1589 PlaylistEntry *entry; | |
1590 GList *node; | |
1591 | |
1592 PLAYLIST_LOCK(); | |
1593 | |
1594 if (!playlist) { | |
1595 PLAYLIST_UNLOCK(); | |
1596 return NULL; | |
1597 } | |
1598 | |
2080
df6cf9cb531e
[svn] - this commit breaks the API. I'm not done here, but hopefully the new API is
nenolod
parents:
2073
diff
changeset
|
1599 if (!(node = g_list_nth(playlist->entries, pos))) { |
0 | 1600 PLAYLIST_UNLOCK(); |
1601 return NULL; | |
1602 } | |
1603 | |
1604 entry = node->data; | |
1605 | |
1606 /* FIXME: simplify this logic */ | |
1841
7d0cd3fab6a2
[svn] - mtime=-1 has been introduced to represent "uninitialized".
yaz
parents:
1834
diff
changeset
|
1607 if ((entry->title == NULL && entry->length == -1) || |
7d0cd3fab6a2
[svn] - mtime=-1 has been introduced to represent "uninitialized".
yaz
parents:
1834
diff
changeset
|
1608 (entry->tuple && entry->tuple->mtime != 0 && (entry->tuple->mtime == -1 || entry->tuple->mtime != playlist_get_mtime(entry->filename)))) |
7d0cd3fab6a2
[svn] - mtime=-1 has been introduced to represent "uninitialized".
yaz
parents:
1834
diff
changeset
|
1609 { |
0 | 1610 if (playlist_entry_get_info(entry)) |
1611 title = entry->title; | |
1612 } | |
1613 else { | |
1614 title = entry->title; | |
1615 } | |
1616 | |
1617 PLAYLIST_UNLOCK(); | |
1618 | |
1619 if (!title) { | |
1620 title = g_path_get_basename(entry->filename); | |
1621 return str_replace(title, filename_to_utf8(title)); | |
1622 } | |
1623 | |
1624 return str_to_utf8(title); | |
1625 } | |
1626 | |
1235 | 1627 TitleInput * |
2080
df6cf9cb531e
[svn] - this commit breaks the API. I'm not done here, but hopefully the new API is
nenolod
parents:
2073
diff
changeset
|
1628 playlist_get_tuple(Playlist *playlist, guint pos) |
1235 | 1629 { |
1630 PlaylistEntry *entry; | |
1631 TitleInput *tuple = NULL; | |
1632 GList *node; | |
1633 | |
1634 PLAYLIST_LOCK(); | |
1635 | |
1636 if (!playlist) { | |
1637 PLAYLIST_UNLOCK(); | |
1638 return NULL; | |
1639 } | |
1640 | |
2080
df6cf9cb531e
[svn] - this commit breaks the API. I'm not done here, but hopefully the new API is
nenolod
parents:
2073
diff
changeset
|
1641 if (!(node = g_list_nth(playlist->entries, pos))) { |
1235 | 1642 PLAYLIST_UNLOCK(); |
1643 return NULL; | |
1644 } | |
1645 | |
1646 entry = (PlaylistEntry *) node->data; | |
1647 | |
1648 tuple = entry->tuple; | |
1649 | |
1588
15d92c51bde6
[svn] - modified time (mtime) has been introduced into tuple
yaz
parents:
1587
diff
changeset
|
1650 // if no tuple or tuple with old mtime, get new one. |
1841
7d0cd3fab6a2
[svn] - mtime=-1 has been introduced to represent "uninitialized".
yaz
parents:
1834
diff
changeset
|
1651 if (tuple == NULL || |
7d0cd3fab6a2
[svn] - mtime=-1 has been introduced to represent "uninitialized".
yaz
parents:
1834
diff
changeset
|
1652 (entry->tuple && entry->tuple->mtime != 0 && (entry->tuple->mtime == -1 || entry->tuple->mtime != playlist_get_mtime(entry->filename)))) |
7d0cd3fab6a2
[svn] - mtime=-1 has been introduced to represent "uninitialized".
yaz
parents:
1834
diff
changeset
|
1653 { |
1237
17630223d25b
[svn] - if a PlaylistEntry does not have a cached tuple, generate it on demand.
nenolod
parents:
1235
diff
changeset
|
1654 playlist_entry_get_info(entry); |
17630223d25b
[svn] - if a PlaylistEntry does not have a cached tuple, generate it on demand.
nenolod
parents:
1235
diff
changeset
|
1655 tuple = entry->tuple; |
17630223d25b
[svn] - if a PlaylistEntry does not have a cached tuple, generate it on demand.
nenolod
parents:
1235
diff
changeset
|
1656 } |
17630223d25b
[svn] - if a PlaylistEntry does not have a cached tuple, generate it on demand.
nenolod
parents:
1235
diff
changeset
|
1657 |
1235 | 1658 PLAYLIST_UNLOCK(); |
1659 | |
1660 return tuple; | |
1661 } | |
1662 | |
0 | 1663 gint |
2080
df6cf9cb531e
[svn] - this commit breaks the API. I'm not done here, but hopefully the new API is
nenolod
parents:
2073
diff
changeset
|
1664 playlist_get_songtime(Playlist *playlist, guint pos) |
0 | 1665 { |
1666 gint song_time = -1; | |
1667 PlaylistEntry *entry; | |
1668 GList *node; | |
1669 | |
1670 PLAYLIST_LOCK(); | |
1671 | |
1672 if (!playlist) { | |
1673 PLAYLIST_UNLOCK(); | |
1674 return -1; | |
1675 } | |
1676 | |
2080
df6cf9cb531e
[svn] - this commit breaks the API. I'm not done here, but hopefully the new API is
nenolod
parents:
2073
diff
changeset
|
1677 if (!(node = g_list_nth(playlist->entries, pos))) { |
0 | 1678 PLAYLIST_UNLOCK(); |
1679 return -1; | |
1680 } | |
1681 | |
1682 entry = node->data; | |
1841
7d0cd3fab6a2
[svn] - mtime=-1 has been introduced to represent "uninitialized".
yaz
parents:
1834
diff
changeset
|
1683 if (entry->tuple == NULL || |
7d0cd3fab6a2
[svn] - mtime=-1 has been introduced to represent "uninitialized".
yaz
parents:
1834
diff
changeset
|
1684 (entry->tuple->mtime != 0 && (entry->tuple->mtime == -1 || entry->tuple->mtime != playlist_get_mtime(entry->filename)))) { |
1588
15d92c51bde6
[svn] - modified time (mtime) has been introduced into tuple
yaz
parents:
1587
diff
changeset
|
1685 |
0 | 1686 if (playlist_entry_get_info(entry)) |
1687 song_time = entry->length; | |
1688 | |
1689 PLAYLIST_UNLOCK(); | |
1690 } | |
1691 else { | |
1692 song_time = entry->length; | |
1693 PLAYLIST_UNLOCK(); | |
1694 } | |
1695 | |
1696 return song_time; | |
1697 } | |
1698 | |
1699 static gint | |
1415 | 1700 playlist_compare_track(PlaylistEntry * a, |
1701 PlaylistEntry * b) | |
1702 { | |
1703 g_return_val_if_fail(a != NULL, 0); | |
1704 g_return_val_if_fail(b != NULL, 0); | |
1705 | |
1706 g_return_val_if_fail(a->tuple != NULL, 0); | |
1707 g_return_val_if_fail(b->tuple != NULL, 0); | |
1708 | |
1709 return (a->tuple->track_number - b->tuple->track_number); | |
1710 } | |
1711 | |
1712 static gint | |
1430
740c08db08d9
[svn] via Christian Birchinger <joker -at- netswarm.net>:
nenolod
parents:
1415
diff
changeset
|
1713 playlist_compare_playlist(PlaylistEntry * a, |
740c08db08d9
[svn] via Christian Birchinger <joker -at- netswarm.net>:
nenolod
parents:
1415
diff
changeset
|
1714 PlaylistEntry * b) |
740c08db08d9
[svn] via Christian Birchinger <joker -at- netswarm.net>:
nenolod
parents:
1415
diff
changeset
|
1715 { |
740c08db08d9
[svn] via Christian Birchinger <joker -at- netswarm.net>:
nenolod
parents:
1415
diff
changeset
|
1716 const gchar *a_title = NULL, *b_title = NULL; |
740c08db08d9
[svn] via Christian Birchinger <joker -at- netswarm.net>:
nenolod
parents:
1415
diff
changeset
|
1717 |
740c08db08d9
[svn] via Christian Birchinger <joker -at- netswarm.net>:
nenolod
parents:
1415
diff
changeset
|
1718 g_return_val_if_fail(a != NULL, 0); |
740c08db08d9
[svn] via Christian Birchinger <joker -at- netswarm.net>:
nenolod
parents:
1415
diff
changeset
|
1719 g_return_val_if_fail(b != NULL, 0); |
740c08db08d9
[svn] via Christian Birchinger <joker -at- netswarm.net>:
nenolod
parents:
1415
diff
changeset
|
1720 |
740c08db08d9
[svn] via Christian Birchinger <joker -at- netswarm.net>:
nenolod
parents:
1415
diff
changeset
|
1721 if (a->title != NULL) |
740c08db08d9
[svn] via Christian Birchinger <joker -at- netswarm.net>:
nenolod
parents:
1415
diff
changeset
|
1722 a_title = a->title; |
740c08db08d9
[svn] via Christian Birchinger <joker -at- netswarm.net>:
nenolod
parents:
1415
diff
changeset
|
1723 else { |
740c08db08d9
[svn] via Christian Birchinger <joker -at- netswarm.net>:
nenolod
parents:
1415
diff
changeset
|
1724 if (strrchr(a->filename, '/')) |
740c08db08d9
[svn] via Christian Birchinger <joker -at- netswarm.net>:
nenolod
parents:
1415
diff
changeset
|
1725 a_title = strrchr(a->filename, '/') + 1; |
740c08db08d9
[svn] via Christian Birchinger <joker -at- netswarm.net>:
nenolod
parents:
1415
diff
changeset
|
1726 else |
740c08db08d9
[svn] via Christian Birchinger <joker -at- netswarm.net>:
nenolod
parents:
1415
diff
changeset
|
1727 a_title = a->filename; |
740c08db08d9
[svn] via Christian Birchinger <joker -at- netswarm.net>:
nenolod
parents:
1415
diff
changeset
|
1728 } |
740c08db08d9
[svn] via Christian Birchinger <joker -at- netswarm.net>:
nenolod
parents:
1415
diff
changeset
|
1729 |
740c08db08d9
[svn] via Christian Birchinger <joker -at- netswarm.net>:
nenolod
parents:
1415
diff
changeset
|
1730 if (b->title != NULL) |
740c08db08d9
[svn] via Christian Birchinger <joker -at- netswarm.net>:
nenolod
parents:
1415
diff
changeset
|
1731 b_title = b->title; |
740c08db08d9
[svn] via Christian Birchinger <joker -at- netswarm.net>:
nenolod
parents:
1415
diff
changeset
|
1732 else { |
740c08db08d9
[svn] via Christian Birchinger <joker -at- netswarm.net>:
nenolod
parents:
1415
diff
changeset
|
1733 if (strrchr(a->filename, '/')) |
740c08db08d9
[svn] via Christian Birchinger <joker -at- netswarm.net>:
nenolod
parents:
1415
diff
changeset
|
1734 b_title = strrchr(b->filename, '/') + 1; |
740c08db08d9
[svn] via Christian Birchinger <joker -at- netswarm.net>:
nenolod
parents:
1415
diff
changeset
|
1735 else |
740c08db08d9
[svn] via Christian Birchinger <joker -at- netswarm.net>:
nenolod
parents:
1415
diff
changeset
|
1736 b_title = b->filename; |
740c08db08d9
[svn] via Christian Birchinger <joker -at- netswarm.net>:
nenolod
parents:
1415
diff
changeset
|
1737 } |
740c08db08d9
[svn] via Christian Birchinger <joker -at- netswarm.net>:
nenolod
parents:
1415
diff
changeset
|
1738 |
740c08db08d9
[svn] via Christian Birchinger <joker -at- netswarm.net>:
nenolod
parents:
1415
diff
changeset
|
1739 return strcasecmp(a_title, b_title); |
740c08db08d9
[svn] via Christian Birchinger <joker -at- netswarm.net>:
nenolod
parents:
1415
diff
changeset
|
1740 } |
740c08db08d9
[svn] via Christian Birchinger <joker -at- netswarm.net>:
nenolod
parents:
1415
diff
changeset
|
1741 |
740c08db08d9
[svn] via Christian Birchinger <joker -at- netswarm.net>:
nenolod
parents:
1415
diff
changeset
|
1742 static gint |
1251 | 1743 playlist_compare_title(PlaylistEntry * a, |
1744 PlaylistEntry * b) | |
0 | 1745 { |
1250 | 1746 const gchar *a_title = NULL, *b_title = NULL; |
0 | 1747 |
1748 g_return_val_if_fail(a != NULL, 0); | |
1749 g_return_val_if_fail(b != NULL, 0); | |
1750 | |
1250 | 1751 if (a->tuple != NULL && a->tuple->track_name != NULL) |
1752 a_title = a->tuple->track_name; | |
1753 if (b->tuple != NULL && b->tuple->track_name != NULL) | |
1754 b_title = b->tuple->track_name; | |
1755 | |
1251 | 1756 if (a_title != NULL && b_title != NULL) |
1250 | 1757 return strcasecmp(a_title, b_title); |
1758 | |
1759 if (a->title != NULL) | |
0 | 1760 a_title = a->title; |
1761 else { | |
1762 if (strrchr(a->filename, '/')) | |
1763 a_title = strrchr(a->filename, '/') + 1; | |
1764 else | |
1765 a_title = a->filename; | |
1766 } | |
1767 | |
1250 | 1768 if (b->title != NULL) |
0 | 1769 b_title = b->title; |
1770 else { | |
1771 if (strrchr(a->filename, '/')) | |
1772 b_title = strrchr(b->filename, '/') + 1; | |
1773 else | |
1774 b_title = b->filename; | |
1775 } | |
1776 | |
1777 return strcasecmp(a_title, b_title); | |
1778 } | |
1779 | |
1780 static gint | |
1251 | 1781 playlist_compare_artist(PlaylistEntry * a, |
1782 PlaylistEntry * b) | |
1783 { | |
1784 const gchar *a_artist = NULL, *b_artist = NULL; | |
1785 | |
1786 g_return_val_if_fail(a != NULL, 0); | |
1787 g_return_val_if_fail(b != NULL, 0); | |
1788 | |
1789 if (a->tuple != NULL) | |
1790 playlist_entry_get_info(a); | |
1791 | |
1792 if (b->tuple != NULL) | |
1793 playlist_entry_get_info(b); | |
1794 | |
1253
665dfbf5e9a1
[svn] - playlist_compare_artist(): more sanity checking.
nenolod
parents:
1251
diff
changeset
|
1795 if (a->tuple != NULL && a->tuple->performer != NULL) |
1251 | 1796 a_artist = a->tuple->performer; |
1253
665dfbf5e9a1
[svn] - playlist_compare_artist(): more sanity checking.
nenolod
parents:
1251
diff
changeset
|
1797 if (b->tuple != NULL && b->tuple->performer != NULL) |
1251 | 1798 b_artist = b->tuple->performer; |
1799 | |
1800 if (a_artist != NULL && b_artist != NULL) | |
1801 return strcasecmp(a_artist, b_artist); | |
1802 | |
1253
665dfbf5e9a1
[svn] - playlist_compare_artist(): more sanity checking.
nenolod
parents:
1251
diff
changeset
|
1803 return 0; |
1251 | 1804 } |
1805 | |
1806 static gint | |
1807 playlist_compare_filename(PlaylistEntry * a, | |
1808 PlaylistEntry * b) | |
0 | 1809 { |
1810 gchar *a_filename, *b_filename; | |
1811 | |
1812 g_return_val_if_fail(a != NULL, 0); | |
1813 g_return_val_if_fail(b != NULL, 0); | |
1814 | |
1815 if (strrchr(a->filename, '/')) | |
1816 a_filename = strrchr(a->filename, '/') + 1; | |
1817 else | |
1818 a_filename = a->filename; | |
1819 | |
1820 if (strrchr(b->filename, '/')) | |
1821 b_filename = strrchr(b->filename, '/') + 1; | |
1822 else | |
1823 b_filename = b->filename; | |
1824 | |
1825 | |
1826 return strcasecmp(a_filename, b_filename); | |
1827 } | |
1828 | |
1829 static gint | |
1830 path_compare(const gchar * a, const gchar * b) | |
1831 { | |
1832 gchar *posa, *posb; | |
1833 gint len, ret; | |
1834 | |
1835 posa = strrchr(a, '/'); | |
1836 posb = strrchr(b, '/'); | |
1837 | |
1838 /* | |
1839 * Sort directories before files | |
1840 */ | |
1841 if (posa && posb && (posa - a != posb - b)) { | |
1842 if (posa - a > posb - b) { | |
1843 len = posb - b; | |
1844 ret = -1; | |
1845 } | |
1846 else { | |
1847 len = posa - a; | |
1848 ret = 1; | |
1849 } | |
1850 if (!strncasecmp(a, b, len)) | |
1851 return ret; | |
1852 } | |
1853 return strcasecmp(a, b); | |
1854 } | |
1855 | |
1856 static gint | |
1251 | 1857 playlist_compare_path(PlaylistEntry * a, |
1858 PlaylistEntry * b) | |
0 | 1859 { |
1860 return path_compare(a->filename, b->filename); | |
1861 } | |
1862 | |
1588
15d92c51bde6
[svn] - modified time (mtime) has been introduced into tuple
yaz
parents:
1587
diff
changeset
|
1863 |
15d92c51bde6
[svn] - modified time (mtime) has been introduced into tuple
yaz
parents:
1587
diff
changeset
|
1864 static time_t |
15d92c51bde6
[svn] - modified time (mtime) has been introduced into tuple
yaz
parents:
1587
diff
changeset
|
1865 playlist_get_mtime(const gchar *filename) |
15d92c51bde6
[svn] - modified time (mtime) has been introduced into tuple
yaz
parents:
1587
diff
changeset
|
1866 { |
1706 | 1867 struct stat buf; |
1588
15d92c51bde6
[svn] - modified time (mtime) has been introduced into tuple
yaz
parents:
1587
diff
changeset
|
1868 gint rv; |
15d92c51bde6
[svn] - modified time (mtime) has been introduced into tuple
yaz
parents:
1587
diff
changeset
|
1869 |
15d92c51bde6
[svn] - modified time (mtime) has been introduced into tuple
yaz
parents:
1587
diff
changeset
|
1870 rv = stat(filename, &buf); |
15d92c51bde6
[svn] - modified time (mtime) has been introduced into tuple
yaz
parents:
1587
diff
changeset
|
1871 |
15d92c51bde6
[svn] - modified time (mtime) has been introduced into tuple
yaz
parents:
1587
diff
changeset
|
1872 if (rv == 0) { |
15d92c51bde6
[svn] - modified time (mtime) has been introduced into tuple
yaz
parents:
1587
diff
changeset
|
1873 return buf.st_mtime; |
15d92c51bde6
[svn] - modified time (mtime) has been introduced into tuple
yaz
parents:
1587
diff
changeset
|
1874 } else { |
15d92c51bde6
[svn] - modified time (mtime) has been introduced into tuple
yaz
parents:
1587
diff
changeset
|
1875 return 0; //error |
15d92c51bde6
[svn] - modified time (mtime) has been introduced into tuple
yaz
parents:
1587
diff
changeset
|
1876 } |
15d92c51bde6
[svn] - modified time (mtime) has been introduced into tuple
yaz
parents:
1587
diff
changeset
|
1877 } |
15d92c51bde6
[svn] - modified time (mtime) has been introduced into tuple
yaz
parents:
1587
diff
changeset
|
1878 |
15d92c51bde6
[svn] - modified time (mtime) has been introduced into tuple
yaz
parents:
1587
diff
changeset
|
1879 |
0 | 1880 static gint |
1251 | 1881 playlist_compare_date(PlaylistEntry * a, |
1882 PlaylistEntry * b) | |
0 | 1883 { |
1884 struct stat buf; | |
1885 time_t modtime; | |
1886 | |
1887 gint rv; | |
1888 | |
1889 | |
1890 rv = stat(a->filename, &buf); | |
1891 | |
1892 if (rv == 0) { | |
1893 modtime = buf.st_mtime; | |
1894 rv = stat(b->filename, &buf); | |
1895 | |
1896 if (stat(b->filename, &buf) == 0) { | |
1897 if (buf.st_mtime == modtime) | |
1898 return 0; | |
1899 else | |
1900 return (buf.st_mtime - modtime) > 0 ? -1 : 1; | |
1901 } | |
1902 else | |
1903 return -1; | |
1904 } | |
1905 else if (!lstat(b->filename, &buf)) | |
1906 return 1; | |
1907 else | |
1908 return playlist_compare_filename(a, b); | |
1909 } | |
1910 | |
1911 | |
1912 void | |
2080
df6cf9cb531e
[svn] - this commit breaks the API. I'm not done here, but hopefully the new API is
nenolod
parents:
2073
diff
changeset
|
1913 playlist_sort(Playlist *playlist, PlaylistSortType type) |
0 | 1914 { |
2080
df6cf9cb531e
[svn] - this commit breaks the API. I'm not done here, but hopefully the new API is
nenolod
parents:
2073
diff
changeset
|
1915 playlist_remove_dead_files(playlist); |
0 | 1916 PLAYLIST_LOCK(); |
2080
df6cf9cb531e
[svn] - this commit breaks the API. I'm not done here, but hopefully the new API is
nenolod
parents:
2073
diff
changeset
|
1917 playlist->entries = |
df6cf9cb531e
[svn] - this commit breaks the API. I'm not done here, but hopefully the new API is
nenolod
parents:
2073
diff
changeset
|
1918 g_list_sort(playlist->entries, |
0 | 1919 (GCompareFunc) playlist_compare_func_table[type]); |
1920 PLAYLIST_UNLOCK(); | |
1921 } | |
1922 | |
1923 static GList * | |
1924 playlist_sort_selected_generic(GList * list, GCompareFunc cmpfunc) | |
1925 { | |
1926 GList *list1, *list2; | |
1927 GList *tmp_list = NULL; | |
1928 GList *index_list = NULL; | |
1929 | |
1930 /* | |
1931 * We take all the selected entries out of the playlist, | |
1932 * sorts them, and then put them back in again. | |
1933 */ | |
1934 | |
1935 list1 = g_list_last(list); | |
1936 | |
1937 while (list1) { | |
1938 list2 = g_list_previous(list1); | |
1939 if (PLAYLIST_ENTRY(list1->data)->selected) { | |
1940 gpointer idx; | |
1941 idx = GINT_TO_POINTER(g_list_position(list, list1)); | |
1942 index_list = g_list_prepend(index_list, idx); | |
1943 list = g_list_remove_link(list, list1); | |
1944 tmp_list = g_list_concat(list1, tmp_list); | |
1945 } | |
1946 list1 = list2; | |
1947 } | |
1948 | |
1949 tmp_list = g_list_sort(tmp_list, cmpfunc); | |
1950 list1 = tmp_list; | |
1951 list2 = index_list; | |
1952 | |
1953 while (list2) { | |
1954 if (!list1) { | |
1955 g_critical(G_STRLOC ": Error during list sorting. " | |
1956 "Possibly dropped some playlist-entries."); | |
1957 break; | |
1958 } | |
1959 | |
1960 list = g_list_insert(list, list1->data, GPOINTER_TO_INT(list2->data)); | |
1961 | |
1962 list2 = g_list_next(list2); | |
1963 list1 = g_list_next(list1); | |
1964 } | |
1965 | |
1966 g_list_free(index_list); | |
1967 g_list_free(tmp_list); | |
1968 | |
1969 return list; | |
1970 } | |
1971 | |
1972 void | |
2080
df6cf9cb531e
[svn] - this commit breaks the API. I'm not done here, but hopefully the new API is
nenolod
parents:
2073
diff
changeset
|
1973 playlist_sort_selected(Playlist *playlist, PlaylistSortType type) |
0 | 1974 { |
1975 PLAYLIST_LOCK(); | |
2080
df6cf9cb531e
[svn] - this commit breaks the API. I'm not done here, but hopefully the new API is
nenolod
parents:
2073
diff
changeset
|
1976 playlist->entries = playlist_sort_selected_generic(playlist->entries, (GCompareFunc) |
df6cf9cb531e
[svn] - this commit breaks the API. I'm not done here, but hopefully the new API is
nenolod
parents:
2073
diff
changeset
|
1977 playlist_compare_func_table |
df6cf9cb531e
[svn] - this commit breaks the API. I'm not done here, but hopefully the new API is
nenolod
parents:
2073
diff
changeset
|
1978 [type]); |
0 | 1979 PLAYLIST_UNLOCK(); |
1980 } | |
1981 | |
1982 void | |
2080
df6cf9cb531e
[svn] - this commit breaks the API. I'm not done here, but hopefully the new API is
nenolod
parents:
2073
diff
changeset
|
1983 playlist_reverse(Playlist *playlist) |
0 | 1984 { |
1985 PLAYLIST_LOCK(); | |
2080
df6cf9cb531e
[svn] - this commit breaks the API. I'm not done here, but hopefully the new API is
nenolod
parents:
2073
diff
changeset
|
1986 playlist->entries = g_list_reverse(playlist->entries); |
0 | 1987 PLAYLIST_UNLOCK(); |
1988 } | |
1989 | |
1990 static GList * | |
1991 playlist_shuffle_list(GList * list) | |
1992 { | |
1993 /* | |
1994 * Note that this doesn't make a copy of the original list. | |
1995 * The pointer to the original list is not valid after this | |
1996 * fuction is run. | |
1997 */ | |
1998 gint len = g_list_length(list); | |
1999 gint i, j; | |
2000 GList *node, **ptrs; | |
2001 | |
2080
df6cf9cb531e
[svn] - this commit breaks the API. I'm not done here, but hopefully the new API is
nenolod
parents:
2073
diff
changeset
|
2002 REQUIRE_STATIC_LOCK(playlists); |
0 | 2003 |
2004 if (!len) | |
2005 return NULL; | |
2006 | |
2007 ptrs = g_new(GList *, len); | |
2008 | |
2009 for (node = list, i = 0; i < len; node = g_list_next(node), i++) | |
2010 ptrs[i] = node; | |
2011 | |
2012 j = g_random_int_range(0, len); | |
2013 list = ptrs[j]; | |
2014 ptrs[j]->next = NULL; | |
2015 ptrs[j] = ptrs[0]; | |
2016 | |
2017 for (i = 1; i < len; i++) { | |
2018 j = g_random_int_range(0, len - i); | |
2019 list->prev = ptrs[i + j]; | |
2020 ptrs[i + j]->next = list; | |
2021 list = ptrs[i + j]; | |
2022 ptrs[i + j] = ptrs[i]; | |
2023 } | |
2024 list->prev = NULL; | |
2025 | |
2026 g_free(ptrs); | |
2027 | |
2028 return list; | |
2029 } | |
2030 | |
2031 void | |
2080
df6cf9cb531e
[svn] - this commit breaks the API. I'm not done here, but hopefully the new API is
nenolod
parents:
2073
diff
changeset
|
2032 playlist_random(Playlist *playlist) |
0 | 2033 { |
2034 PLAYLIST_LOCK(); | |
2080
df6cf9cb531e
[svn] - this commit breaks the API. I'm not done here, but hopefully the new API is
nenolod
parents:
2073
diff
changeset
|
2035 playlist->entries = playlist_shuffle_list(playlist->entries); |
0 | 2036 PLAYLIST_UNLOCK(); |
2037 } | |
2038 | |
2039 GList * | |
2040 playlist_get_selected(void) | |
2041 { | |
2042 GList *node, *list = NULL; | |
2043 gint i = 0; | |
2044 | |
2045 PLAYLIST_LOCK(); | |
2046 for (node = playlist_get(); node; node = g_list_next(node), i++) { | |
2047 PlaylistEntry *entry = node->data; | |
2048 if (entry->selected) | |
2049 list = g_list_prepend(list, GINT_TO_POINTER(i)); | |
2050 } | |
2051 PLAYLIST_UNLOCK(); | |
2052 return g_list_reverse(list); | |
2053 } | |
2054 | |
2055 void | |
2056 playlist_clear_selected(void) | |
2057 { | |
2058 GList *node = NULL; | |
2059 gint i = 0; | |
2060 | |
2061 PLAYLIST_LOCK(); | |
2062 for (node = playlist_get(); node; node = g_list_next(node), i++) { | |
2063 PLAYLIST_ENTRY(node->data)->selected = FALSE; | |
2064 } | |
2065 PLAYLIST_UNLOCK(); | |
2066 playlist_recalc_total_time(); | |
2067 } | |
2068 | |
2069 gint | |
2070 playlist_get_num_selected(void) | |
2071 { | |
2072 GList *node; | |
2073 gint num = 0; | |
2074 | |
2075 PLAYLIST_LOCK(); | |
2076 for (node = playlist_get(); node; node = g_list_next(node)) { | |
2077 PlaylistEntry *entry = node->data; | |
2078 if (entry->selected) | |
2079 num++; | |
2080 } | |
2081 PLAYLIST_UNLOCK(); | |
2082 return num; | |
2083 } | |
2084 | |
2085 | |
2086 static void | |
2080
df6cf9cb531e
[svn] - this commit breaks the API. I'm not done here, but hopefully the new API is
nenolod
parents:
2073
diff
changeset
|
2087 playlist_generate_shuffle_list(Playlist *playlist) |
0 | 2088 { |
2089 PLAYLIST_LOCK(); | |
2080
df6cf9cb531e
[svn] - this commit breaks the API. I'm not done here, but hopefully the new API is
nenolod
parents:
2073
diff
changeset
|
2090 playlist_generate_shuffle_list_nolock(playlist); |
0 | 2091 PLAYLIST_UNLOCK(); |
2092 } | |
2093 | |
2094 static void | |
2080
df6cf9cb531e
[svn] - this commit breaks the API. I'm not done here, but hopefully the new API is
nenolod
parents:
2073
diff
changeset
|
2095 playlist_generate_shuffle_list_nolock(Playlist *playlist) |
0 | 2096 { |
2097 GList *node; | |
2098 gint numsongs; | |
2099 | |
2080
df6cf9cb531e
[svn] - this commit breaks the API. I'm not done here, but hopefully the new API is
nenolod
parents:
2073
diff
changeset
|
2100 REQUIRE_STATIC_LOCK(playlists); |
0 | 2101 |
2102 if (!cfg.shuffle || !playlist) | |
2103 return; | |
2104 | |
2080
df6cf9cb531e
[svn] - this commit breaks the API. I'm not done here, but hopefully the new API is
nenolod
parents:
2073
diff
changeset
|
2105 if (playlist->shuffle) { |
df6cf9cb531e
[svn] - this commit breaks the API. I'm not done here, but hopefully the new API is
nenolod
parents:
2073
diff
changeset
|
2106 g_list_free(playlist->shuffle); |
df6cf9cb531e
[svn] - this commit breaks the API. I'm not done here, but hopefully the new API is
nenolod
parents:
2073
diff
changeset
|
2107 playlist->shuffle = NULL; |
df6cf9cb531e
[svn] - this commit breaks the API. I'm not done here, but hopefully the new API is
nenolod
parents:
2073
diff
changeset
|
2108 } |
df6cf9cb531e
[svn] - this commit breaks the API. I'm not done here, but hopefully the new API is
nenolod
parents:
2073
diff
changeset
|
2109 |
df6cf9cb531e
[svn] - this commit breaks the API. I'm not done here, but hopefully the new API is
nenolod
parents:
2073
diff
changeset
|
2110 playlist->shuffle = playlist_shuffle_list(g_list_copy(playlist->entries)); |
df6cf9cb531e
[svn] - this commit breaks the API. I'm not done here, but hopefully the new API is
nenolod
parents:
2073
diff
changeset
|
2111 numsongs = g_list_length(playlist->shuffle); |
df6cf9cb531e
[svn] - this commit breaks the API. I'm not done here, but hopefully the new API is
nenolod
parents:
2073
diff
changeset
|
2112 |
df6cf9cb531e
[svn] - this commit breaks the API. I'm not done here, but hopefully the new API is
nenolod
parents:
2073
diff
changeset
|
2113 if (playlist->position) { |
df6cf9cb531e
[svn] - this commit breaks the API. I'm not done here, but hopefully the new API is
nenolod
parents:
2073
diff
changeset
|
2114 gint i = g_list_index(playlist->shuffle, playlist->position); |
df6cf9cb531e
[svn] - this commit breaks the API. I'm not done here, but hopefully the new API is
nenolod
parents:
2073
diff
changeset
|
2115 node = g_list_nth(playlist->shuffle, i); |
df6cf9cb531e
[svn] - this commit breaks the API. I'm not done here, but hopefully the new API is
nenolod
parents:
2073
diff
changeset
|
2116 playlist->shuffle = g_list_remove_link(playlist->shuffle, node); |
df6cf9cb531e
[svn] - this commit breaks the API. I'm not done here, but hopefully the new API is
nenolod
parents:
2073
diff
changeset
|
2117 playlist->shuffle = g_list_prepend(playlist->shuffle, node->data); |
0 | 2118 } |
2119 } | |
2120 | |
2121 void | |
2122 playlist_fileinfo(guint pos) | |
2123 { | |
2124 gchar *path = NULL; | |
2125 GList *node; | |
1269 | 2126 PlaylistEntry *entry = NULL; |
2127 TitleInput *tuple = NULL; | |
1818
e3e31a084b09
[svn] - try not to reject tuples that have an mtime of 0. (special tuples referring to URIs)
nenolod
parents:
1817
diff
changeset
|
2128 gint mtime; |
0 | 2129 |
2130 PLAYLIST_LOCK(); | |
1269 | 2131 |
2132 if ((node = g_list_nth(playlist_get(), pos))) | |
2133 { | |
2134 entry = node->data; | |
2135 tuple = entry->tuple; | |
1516
3483fb26b9fb
[svn] - when audacious is started and track detail on current song are requested, try to check if a decoder exists before falling back to the tuple display dialog
giacomo
parents:
1459
diff
changeset
|
2136 path = g_strdup(entry->filename); |
0 | 2137 } |
1269 | 2138 |
0 | 2139 PLAYLIST_UNLOCK(); |
1277
8c8d4841efae
[svn] - if entry->tuple == NULL, then probe the file for a decoder and build the appropriate tuple for that entry
nenolod
parents:
1270
diff
changeset
|
2140 |
8c8d4841efae
[svn] - if entry->tuple == NULL, then probe the file for a decoder and build the appropriate tuple for that entry
nenolod
parents:
1270
diff
changeset
|
2141 /* No tuple? Try to set this entry up properly. --nenolod */ |
1841
7d0cd3fab6a2
[svn] - mtime=-1 has been introduced to represent "uninitialized".
yaz
parents:
1834
diff
changeset
|
2142 if (entry->tuple == NULL || entry->tuple->mtime == -1 || |
7d0cd3fab6a2
[svn] - mtime=-1 has been introduced to represent "uninitialized".
yaz
parents:
1834
diff
changeset
|
2143 entry->tuple->mtime == 0 || entry->tuple->mtime != playlist_get_mtime(entry->filename)) |
1277
8c8d4841efae
[svn] - if entry->tuple == NULL, then probe the file for a decoder and build the appropriate tuple for that entry
nenolod
parents:
1270
diff
changeset
|
2144 { |
8c8d4841efae
[svn] - if entry->tuple == NULL, then probe the file for a decoder and build the appropriate tuple for that entry
nenolod
parents:
1270
diff
changeset
|
2145 playlist_entry_get_info(entry); |
8c8d4841efae
[svn] - if entry->tuple == NULL, then probe the file for a decoder and build the appropriate tuple for that entry
nenolod
parents:
1270
diff
changeset
|
2146 tuple = entry->tuple; |
8c8d4841efae
[svn] - if entry->tuple == NULL, then probe the file for a decoder and build the appropriate tuple for that entry
nenolod
parents:
1270
diff
changeset
|
2147 } |
8c8d4841efae
[svn] - if entry->tuple == NULL, then probe the file for a decoder and build the appropriate tuple for that entry
nenolod
parents:
1270
diff
changeset
|
2148 |
1269 | 2149 if (tuple != NULL) |
2150 { | |
2151 if (entry->decoder != NULL && entry->decoder->file_info_box == NULL) | |
2152 fileinfo_show_for_tuple(tuple); | |
1270 | 2153 else if (entry->decoder != NULL && entry->decoder->file_info_box != NULL) |
2154 entry->decoder->file_info_box(path); | |
1269 | 2155 else |
2156 fileinfo_show_for_path(path); | |
2157 g_free(path); | |
2158 } | |
2159 else if (path != NULL) | |
2160 { | |
1270 | 2161 if (entry != NULL && entry->decoder != NULL && entry->decoder->file_info_box != NULL) |
2162 entry->decoder->file_info_box(path); | |
2163 else | |
2164 fileinfo_show_for_path(path); | |
0 | 2165 g_free(path); |
2166 } | |
2167 } | |
2168 | |
2169 void | |
2170 playlist_fileinfo_current(void) | |
2171 { | |
2172 gchar *path = NULL; | |
1269 | 2173 TitleInput *tuple = NULL; |
0 | 2174 |
2175 PLAYLIST_LOCK(); | |
1269 | 2176 |
0 | 2177 if (playlist_get() && playlist_position) |
1269 | 2178 { |
0 | 2179 path = g_strdup(playlist_position->filename); |
1690
bb1323938306
[svn] - fix for issue that was fixed in r1946 and then appeared again later :)
giacomo
parents:
1653
diff
changeset
|
2180 if (( playlist_position->tuple == NULL ) || ( playlist_position->decoder == NULL )) |
1516
3483fb26b9fb
[svn] - when audacious is started and track detail on current song are requested, try to check if a decoder exists before falling back to the tuple display dialog
giacomo
parents:
1459
diff
changeset
|
2181 playlist_entry_get_info(playlist_position); |
3483fb26b9fb
[svn] - when audacious is started and track detail on current song are requested, try to check if a decoder exists before falling back to the tuple display dialog
giacomo
parents:
1459
diff
changeset
|
2182 tuple = playlist_position->tuple; |
1269 | 2183 } |
2184 | |
0 | 2185 PLAYLIST_UNLOCK(); |
2186 | |
1269 | 2187 if (tuple != NULL) |
2188 { | |
2189 if (playlist_position->decoder != NULL && playlist_position->decoder->file_info_box == NULL) | |
2190 fileinfo_show_for_tuple(tuple); | |
1270 | 2191 else if (playlist_position->decoder != NULL && playlist_position->decoder->file_info_box != NULL) |
2192 playlist_position->decoder->file_info_box(path); | |
1269 | 2193 else |
2194 fileinfo_show_for_path(path); | |
2195 g_free(path); | |
2196 } | |
2197 else if (path != NULL) | |
2198 { | |
1270 | 2199 if (playlist_position != NULL && playlist_position->decoder != NULL && playlist_position->decoder->file_info_box != NULL) |
2200 playlist_position->decoder->file_info_box(path); | |
2201 else | |
2202 fileinfo_show_for_path(path); | |
0 | 2203 g_free(path); |
2204 } | |
2205 } | |
2206 | |
2207 | |
2208 static gboolean | |
2209 playlist_get_info_is_going(void) | |
2210 { | |
2211 gboolean result; | |
2212 | |
2213 G_LOCK(playlist_get_info_going); | |
2214 result = playlist_get_info_going; | |
2215 G_UNLOCK(playlist_get_info_going); | |
2216 | |
2217 return result; | |
2218 } | |
2219 | |
2220 static gpointer | |
2221 playlist_get_info_func(gpointer arg) | |
2222 { | |
2223 GList *node; | |
2224 gboolean update_playlistwin = FALSE; | |
2225 gboolean update_mainwin = FALSE; | |
2226 | |
2227 while (playlist_get_info_is_going()) { | |
2228 PlaylistEntry *entry; | |
2229 | |
2026 | 2230 // on_load |
0 | 2231 if (cfg.use_pl_metadata && |
2232 cfg.get_info_on_load && | |
2233 playlist_get_info_scan_active) { | |
2234 | |
2235 PLAYLIST_LOCK(); | |
2236 for (node = playlist_get(); node; node = g_list_next(node)) { | |
2237 entry = node->data; | |
2238 | |
1826
d66712838e9f
[svn] - and finally special tuples are treated as they should be
nenolod
parents:
1825
diff
changeset
|
2239 if(entry->tuple && (entry->tuple->length > -1)) { |
2026 | 2240 update_playlistwin = TRUE; |
2241 continue; | |
1588
15d92c51bde6
[svn] - modified time (mtime) has been introduced into tuple
yaz
parents:
1587
diff
changeset
|
2242 } |
0 | 2243 |
2244 if (!playlist_entry_get_info(entry)) { | |
2245 if (g_list_index(playlist_get(), entry) == -1) | |
2246 /* Entry disappeared while we looked it up. | |
2247 Restart. */ | |
2248 node = playlist_get(); | |
2249 } | |
2026 | 2250 else if ((entry->tuple != NULL || entry->title != NULL) && entry->length != -1) { |
0 | 2251 update_playlistwin = TRUE; |
2252 if (entry == playlist_position) | |
2253 update_mainwin = TRUE; | |
2254 break; | |
2255 } | |
2256 } | |
2257 PLAYLIST_UNLOCK(); | |
2026 | 2258 |
2259 if (!node) { | |
2260 g_mutex_lock(mutex_scan); | |
0 | 2261 playlist_get_info_scan_active = FALSE; |
2026 | 2262 g_mutex_unlock(mutex_scan); |
2263 } | |
2264 } // on_load | |
2265 | |
2266 // on_demand | |
0 | 2267 else if (!cfg.get_info_on_load && |
2268 cfg.get_info_on_demand && | |
2269 cfg.playlist_visible && | |
2270 !cfg.playlist_shaded && | |
2271 cfg.use_pl_metadata) { | |
2272 | |
2026 | 2273 g_mutex_lock(mutex_scan); |
2274 playlist_get_info_scan_active = FALSE; | |
2275 g_mutex_unlock(mutex_scan); | |
0 | 2276 |
2277 PLAYLIST_LOCK(); | |
2278 | |
2279 if (!playlist_get()) { | |
2280 PLAYLIST_UNLOCK(); | |
2281 } | |
2026 | 2282 else { |
2283 for (node = g_list_nth(playlist_get(), playlistwin_get_toprow()); | |
2284 node && playlistwin_item_visible(g_list_position(playlist_get(), node)); | |
2285 node = g_list_next(node)) { | |
2286 | |
2287 entry = node->data; | |
2288 | |
2289 if(entry->tuple && (entry->tuple->length > -1)) { | |
2290 update_playlistwin = TRUE; | |
2291 continue; | |
2292 } | |
2293 | |
2294 if (!playlist_entry_get_info(entry)) { | |
2295 if (g_list_index(playlist_get(), entry) == -1) | |
2296 /* Entry disapeared while we | |
2297 looked it up. Restart. */ | |
2298 node = | |
2299 g_list_nth(playlist_get(), | |
2300 playlistwin_get_toprow()); | |
2301 } | |
2302 else if ((entry->tuple != NULL || entry->title != NULL) && entry->length != -1) { | |
2303 update_playlistwin = TRUE; | |
2304 if (entry == playlist_position) | |
2305 update_mainwin = TRUE; | |
2027 | 2306 // no need for break here since this iteration is very short. |
2026 | 2307 } |
1706 | 2308 } |
2026 | 2309 PLAYLIST_UNLOCK(); |
0 | 2310 } |
2026 | 2311 } // on_demand |
2063
a3ad15fb0f34
[svn] - playlist_scan_thread_is_going should not be TRUE if the playlist is
nenolod
parents:
2040
diff
changeset
|
2312 else if (cfg.get_info_on_demand && |
a3ad15fb0f34
[svn] - playlist_scan_thread_is_going should not be TRUE if the playlist is
nenolod
parents:
2040
diff
changeset
|
2313 (!cfg.playlist_visible || cfg.playlist_shaded |
a3ad15fb0f34
[svn] - playlist_scan_thread_is_going should not be TRUE if the playlist is
nenolod
parents:
2040
diff
changeset
|
2314 || !cfg.use_pl_metadata)) |
a3ad15fb0f34
[svn] - playlist_scan_thread_is_going should not be TRUE if the playlist is
nenolod
parents:
2040
diff
changeset
|
2315 { |
a3ad15fb0f34
[svn] - playlist_scan_thread_is_going should not be TRUE if the playlist is
nenolod
parents:
2040
diff
changeset
|
2316 g_mutex_lock(mutex_scan); |
a3ad15fb0f34
[svn] - playlist_scan_thread_is_going should not be TRUE if the playlist is
nenolod
parents:
2040
diff
changeset
|
2317 playlist_get_info_scan_active = FALSE; |
a3ad15fb0f34
[svn] - playlist_scan_thread_is_going should not be TRUE if the playlist is
nenolod
parents:
2040
diff
changeset
|
2318 g_mutex_unlock(mutex_scan); |
a3ad15fb0f34
[svn] - playlist_scan_thread_is_going should not be TRUE if the playlist is
nenolod
parents:
2040
diff
changeset
|
2319 } |
0 | 2320 |
2321 if (update_playlistwin) { | |
2322 playlistwin_update_list(); | |
2323 update_playlistwin = FALSE; | |
2324 } | |
2325 | |
2326 if (update_mainwin) { | |
2327 mainwin_set_info_text(); | |
2328 update_mainwin = FALSE; | |
2329 } | |
2026 | 2330 |
2331 if (playlist_get_info_scan_active) { | |
2332 continue; | |
2333 } | |
2334 | |
2335 g_mutex_lock(mutex_scan); | |
2336 g_cond_wait(cond_scan, mutex_scan); | |
2337 g_mutex_unlock(mutex_scan); | |
2338 | |
2027 | 2339 } // while |
0 | 2340 |
2341 g_thread_exit(NULL); | |
2342 return NULL; | |
2343 } | |
2344 | |
2345 void | |
2346 playlist_start_get_info_thread(void) | |
2347 { | |
2027 | 2348 G_LOCK(playlist_get_info_going); |
0 | 2349 playlist_get_info_going = TRUE; |
2027 | 2350 G_UNLOCK(playlist_get_info_going); |
2351 | |
0 | 2352 playlist_get_info_thread = g_thread_create(playlist_get_info_func, |
2353 NULL, TRUE, NULL); | |
2354 } | |
2355 | |
2356 void | |
2357 playlist_stop_get_info_thread(void) | |
2358 { | |
2359 G_LOCK(playlist_get_info_going); | |
2360 playlist_get_info_going = FALSE; | |
2361 G_UNLOCK(playlist_get_info_going); | |
2026 | 2362 |
2363 g_cond_broadcast(cond_scan); | |
0 | 2364 g_thread_join(playlist_get_info_thread); |
2365 } | |
2366 | |
2367 void | |
2368 playlist_start_get_info_scan(void) | |
2369 { | |
2026 | 2370 g_mutex_lock(mutex_scan); |
0 | 2371 playlist_get_info_scan_active = TRUE; |
2026 | 2372 g_mutex_unlock(mutex_scan); |
2373 g_cond_signal(cond_scan); | |
0 | 2374 } |
2375 | |
2376 void | |
2080
df6cf9cb531e
[svn] - this commit breaks the API. I'm not done here, but hopefully the new API is
nenolod
parents:
2073
diff
changeset
|
2377 playlist_remove_dead_files(Playlist *playlist) |
0 | 2378 { |
2379 GList *node, *next_node; | |
2380 | |
2381 PLAYLIST_LOCK(); | |
2382 | |
2080
df6cf9cb531e
[svn] - this commit breaks the API. I'm not done here, but hopefully the new API is
nenolod
parents:
2073
diff
changeset
|
2383 for (node = playlist->entries; node; node = next_node) { |
0 | 2384 PlaylistEntry *entry = PLAYLIST_ENTRY(node->data); |
2385 next_node = g_list_next(node); | |
2386 | |
2387 if (!entry || !entry->filename) { | |
2388 g_message(G_STRLOC ": Playlist entry is invalid!"); | |
2389 continue; | |
2390 } | |
2391 | |
2392 /* FIXME: What about 'file:///'? */ | |
2393 /* Don't kill URLs */ | |
2394 if (strstr(entry->filename, "://")) | |
2395 continue; | |
2396 | |
2397 /* FIXME: Should test for readability */ | |
2398 if (vfs_file_test(entry->filename, G_FILE_TEST_EXISTS)) | |
2399 continue; | |
2400 | |
2401 if (entry == playlist_position) { | |
2402 /* Don't remove the currently playing song */ | |
2403 if (bmp_playback_get_playing()) | |
2404 continue; | |
2405 | |
2406 if (next_node) | |
2080
df6cf9cb531e
[svn] - this commit breaks the API. I'm not done here, but hopefully the new API is
nenolod
parents:
2073
diff
changeset
|
2407 playlist->position = PLAYLIST_ENTRY(next_node->data); |
0 | 2408 else |
2080
df6cf9cb531e
[svn] - this commit breaks the API. I'm not done here, but hopefully the new API is
nenolod
parents:
2073
diff
changeset
|
2409 playlist->position = NULL; |
0 | 2410 } |
2411 | |
2412 playlist_entry_free(entry); | |
2080
df6cf9cb531e
[svn] - this commit breaks the API. I'm not done here, but hopefully the new API is
nenolod
parents:
2073
diff
changeset
|
2413 playlist->entries = g_list_delete_link(playlist->entries, node); |
0 | 2414 } |
2415 | |
2416 PLAYLIST_UNLOCK(); | |
2417 | |
2080
df6cf9cb531e
[svn] - this commit breaks the API. I'm not done here, but hopefully the new API is
nenolod
parents:
2073
diff
changeset
|
2418 playlist_generate_shuffle_list(playlist); |
0 | 2419 playlistwin_update_list(); |
2420 playlist_recalc_total_time(); | |
2421 } | |
2422 | |
852
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2423 |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2424 static gint |
1251 | 2425 playlist_dupscmp_title(PlaylistEntry * a, |
2426 PlaylistEntry * b) | |
852
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2427 { |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2428 const gchar *a_title, *b_title; |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2429 |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2430 g_return_val_if_fail(a != NULL, 0); |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2431 g_return_val_if_fail(b != NULL, 0); |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2432 |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2433 if (a->title) |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2434 a_title = a->title; |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2435 else { |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2436 if (strrchr(a->filename, '/')) |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2437 a_title = strrchr(a->filename, '/') + 1; |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2438 else |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2439 a_title = a->filename; |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2440 } |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2441 |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2442 if (b->title) |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2443 b_title = b->title; |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2444 else { |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2445 if (strrchr(a->filename, '/')) |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2446 b_title = strrchr(b->filename, '/') + 1; |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2447 else |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2448 b_title = b->filename; |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2449 } |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2450 |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2451 return strcmp(a_title, b_title); |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2452 } |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2453 |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2454 static gint |
1251 | 2455 playlist_dupscmp_filename(PlaylistEntry * a, |
2456 PlaylistEntry * b ) | |
852
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2457 { |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2458 gchar *a_filename, *b_filename; |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2459 |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2460 g_return_val_if_fail(a != NULL, 0); |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2461 g_return_val_if_fail(b != NULL, 0); |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2462 |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2463 if (strrchr(a->filename, '/')) |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2464 a_filename = strrchr(a->filename, '/') + 1; |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2465 else |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2466 a_filename = a->filename; |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2467 |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2468 if (strrchr(b->filename, '/')) |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2469 b_filename = strrchr(b->filename, '/') + 1; |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2470 else |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2471 b_filename = b->filename; |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2472 |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2473 return strcmp(a_filename, b_filename); |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2474 } |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2475 |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2476 static gint |
1251 | 2477 playlist_dupscmp_path(PlaylistEntry * a, |
2478 PlaylistEntry * b) | |
852
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2479 { |
853 | 2480 /* simply compare the entire filename string */ |
2481 return strcmp(a->filename, b->filename); | |
852
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2482 } |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2483 |
840
ffc5ab7b4b2c
[svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents:
633
diff
changeset
|
2484 void |
2080
df6cf9cb531e
[svn] - this commit breaks the API. I'm not done here, but hopefully the new API is
nenolod
parents:
2073
diff
changeset
|
2485 playlist_remove_duplicates(Playlist *playlist, PlaylistDupsType type) |
840
ffc5ab7b4b2c
[svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents:
633
diff
changeset
|
2486 { |
ffc5ab7b4b2c
[svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents:
633
diff
changeset
|
2487 GList *node, *next_node; |
ffc5ab7b4b2c
[svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents:
633
diff
changeset
|
2488 GList *node_cmp, *next_node_cmp; |
1251 | 2489 gint (*dups_compare_func)(PlaylistEntry * , PlaylistEntry *); |
852
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2490 |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2491 switch ( type ) |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2492 { |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2493 case PLAYLIST_DUPS_TITLE: |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2494 dups_compare_func = playlist_dupscmp_title; |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2495 break; |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2496 case PLAYLIST_DUPS_PATH: |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2497 dups_compare_func = playlist_dupscmp_path; |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2498 break; |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2499 case PLAYLIST_DUPS_FILENAME: |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2500 default: |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2501 dups_compare_func = playlist_dupscmp_filename; |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2502 break; |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2503 } |
840
ffc5ab7b4b2c
[svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents:
633
diff
changeset
|
2504 |
ffc5ab7b4b2c
[svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents:
633
diff
changeset
|
2505 PLAYLIST_LOCK(); |
ffc5ab7b4b2c
[svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents:
633
diff
changeset
|
2506 |
2080
df6cf9cb531e
[svn] - this commit breaks the API. I'm not done here, but hopefully the new API is
nenolod
parents:
2073
diff
changeset
|
2507 for (node = playlist->entries; node; node = next_node) { |
840
ffc5ab7b4b2c
[svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents:
633
diff
changeset
|
2508 PlaylistEntry *entry = PLAYLIST_ENTRY(node->data); |
ffc5ab7b4b2c
[svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents:
633
diff
changeset
|
2509 next_node = g_list_next(node); |
ffc5ab7b4b2c
[svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents:
633
diff
changeset
|
2510 |
ffc5ab7b4b2c
[svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents:
633
diff
changeset
|
2511 if (!entry || !entry->filename) { |
ffc5ab7b4b2c
[svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents:
633
diff
changeset
|
2512 g_message(G_STRLOC ": Playlist entry is invalid!"); |
ffc5ab7b4b2c
[svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents:
633
diff
changeset
|
2513 continue; |
ffc5ab7b4b2c
[svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents:
633
diff
changeset
|
2514 } |
ffc5ab7b4b2c
[svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents:
633
diff
changeset
|
2515 |
ffc5ab7b4b2c
[svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents:
633
diff
changeset
|
2516 for (node_cmp = next_node; node_cmp; node_cmp = next_node_cmp) { |
ffc5ab7b4b2c
[svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents:
633
diff
changeset
|
2517 PlaylistEntry *entry_cmp = PLAYLIST_ENTRY(node_cmp->data); |
ffc5ab7b4b2c
[svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents:
633
diff
changeset
|
2518 next_node_cmp = g_list_next(node_cmp); |
ffc5ab7b4b2c
[svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents:
633
diff
changeset
|
2519 |
ffc5ab7b4b2c
[svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents:
633
diff
changeset
|
2520 if (!entry_cmp || !entry_cmp->filename) { |
ffc5ab7b4b2c
[svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents:
633
diff
changeset
|
2521 g_message(G_STRLOC ": Playlist entry is invalid!"); |
ffc5ab7b4b2c
[svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents:
633
diff
changeset
|
2522 continue; |
ffc5ab7b4b2c
[svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents:
633
diff
changeset
|
2523 } |
ffc5ab7b4b2c
[svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents:
633
diff
changeset
|
2524 |
852
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2525 /* compare using the chosen dups_compare_func */ |
bcff46a2558d
[svn] added multiple 'remove duplicates' (by title, by filename, by path+filename)
giacomo
parents:
840
diff
changeset
|
2526 if ( !dups_compare_func( entry , entry_cmp ) ) { |
840
ffc5ab7b4b2c
[svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents:
633
diff
changeset
|
2527 |
ffc5ab7b4b2c
[svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents:
633
diff
changeset
|
2528 if (entry_cmp == playlist_position) { |
ffc5ab7b4b2c
[svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents:
633
diff
changeset
|
2529 /* Don't remove the currently playing song */ |
ffc5ab7b4b2c
[svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents:
633
diff
changeset
|
2530 if (bmp_playback_get_playing()) |
ffc5ab7b4b2c
[svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents:
633
diff
changeset
|
2531 continue; |
ffc5ab7b4b2c
[svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents:
633
diff
changeset
|
2532 |
ffc5ab7b4b2c
[svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents:
633
diff
changeset
|
2533 if (next_node_cmp) |
2080
df6cf9cb531e
[svn] - this commit breaks the API. I'm not done here, but hopefully the new API is
nenolod
parents:
2073
diff
changeset
|
2534 playlist->position = PLAYLIST_ENTRY(next_node_cmp->data); |
840
ffc5ab7b4b2c
[svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents:
633
diff
changeset
|
2535 else |
2080
df6cf9cb531e
[svn] - this commit breaks the API. I'm not done here, but hopefully the new API is
nenolod
parents:
2073
diff
changeset
|
2536 playlist->position = NULL; |
840
ffc5ab7b4b2c
[svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents:
633
diff
changeset
|
2537 } |
ffc5ab7b4b2c
[svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents:
633
diff
changeset
|
2538 |
ffc5ab7b4b2c
[svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents:
633
diff
changeset
|
2539 /* check if this was the next item of the external |
ffc5ab7b4b2c
[svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents:
633
diff
changeset
|
2540 loop; if true, replace it with the next of the next*/ |
ffc5ab7b4b2c
[svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents:
633
diff
changeset
|
2541 if ( node_cmp == next_node ) |
ffc5ab7b4b2c
[svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents:
633
diff
changeset
|
2542 next_node = g_list_next(next_node); |
ffc5ab7b4b2c
[svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents:
633
diff
changeset
|
2543 |
ffc5ab7b4b2c
[svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents:
633
diff
changeset
|
2544 playlist_entry_free(entry_cmp); |
2080
df6cf9cb531e
[svn] - this commit breaks the API. I'm not done here, but hopefully the new API is
nenolod
parents:
2073
diff
changeset
|
2545 playlist->entries = g_list_delete_link(playlist->entries, node_cmp); |
840
ffc5ab7b4b2c
[svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents:
633
diff
changeset
|
2546 } |
ffc5ab7b4b2c
[svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents:
633
diff
changeset
|
2547 } |
ffc5ab7b4b2c
[svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents:
633
diff
changeset
|
2548 } |
ffc5ab7b4b2c
[svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents:
633
diff
changeset
|
2549 |
ffc5ab7b4b2c
[svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents:
633
diff
changeset
|
2550 PLAYLIST_UNLOCK(); |
ffc5ab7b4b2c
[svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents:
633
diff
changeset
|
2551 |
ffc5ab7b4b2c
[svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents:
633
diff
changeset
|
2552 playlistwin_update_list(); |
ffc5ab7b4b2c
[svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents:
633
diff
changeset
|
2553 playlist_recalc_total_time(); |
ffc5ab7b4b2c
[svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents:
633
diff
changeset
|
2554 } |
ffc5ab7b4b2c
[svn] added a 'remove duplicates' option to the playlist removal menu
giacomo
parents:
633
diff
changeset
|
2555 |
0 | 2556 static gulong pl_total_time = 0, pl_selection_time = 0; |
2557 static gboolean pl_total_more = FALSE, pl_selection_more = FALSE; | |
2558 | |
2559 void | |
2560 playlist_get_total_time(gulong * total_time, | |
2561 gulong * selection_time, | |
2562 gboolean * total_more, | |
2563 gboolean * selection_more) | |
2564 { | |
2565 PLAYLIST_LOCK(); | |
2566 *total_time = pl_total_time; | |
2567 *selection_time = pl_selection_time; | |
2568 *total_more = pl_total_more; | |
2569 *selection_more = pl_selection_more; | |
2570 PLAYLIST_UNLOCK(); | |
2571 } | |
2572 | |
2573 | |
2574 static void | |
2575 playlist_recalc_total_time_nolock(void) | |
2576 { | |
2577 GList *list; | |
2578 PlaylistEntry *entry; | |
2579 | |
2080
df6cf9cb531e
[svn] - this commit breaks the API. I'm not done here, but hopefully the new API is
nenolod
parents:
2073
diff
changeset
|
2580 REQUIRE_STATIC_LOCK(playlists); |
0 | 2581 |
2582 pl_total_time = 0; | |
2583 pl_selection_time = 0; | |
2584 pl_total_more = FALSE; | |
2585 pl_selection_more = FALSE; | |
2586 | |
2587 for (list = playlist_get(); list; list = g_list_next(list)) { | |
2588 entry = list->data; | |
2589 | |
2590 if (entry->length != -1) | |
2591 pl_total_time += entry->length / 1000; | |
2592 else | |
2593 pl_total_more = TRUE; | |
2594 | |
2595 if (entry->selected) { | |
2596 if (entry->length != -1) | |
2597 pl_selection_time += entry->length / 1000; | |
2598 else | |
2599 pl_selection_more = TRUE; | |
2600 } | |
2601 } | |
2602 } | |
2603 | |
2604 static void | |
2605 playlist_recalc_total_time(void) | |
2606 { | |
2607 PLAYLIST_LOCK(); | |
2608 playlist_recalc_total_time_nolock(); | |
2609 PLAYLIST_UNLOCK(); | |
2610 } | |
2611 | |
2612 | |
2613 void | |
2614 playlist_select_all(gboolean set) | |
2615 { | |
2616 GList *list; | |
2617 | |
2618 PLAYLIST_LOCK(); | |
2619 | |
2620 for (list = playlist_get(); list; list = g_list_next(list)) { | |
2621 PlaylistEntry *entry = list->data; | |
2622 entry->selected = set; | |
2623 } | |
2624 | |
2625 PLAYLIST_UNLOCK(); | |
2626 playlist_recalc_total_time(); | |
2627 } | |
2628 | |
2629 void | |
2630 playlist_select_invert_all(void) | |
2631 { | |
2632 GList *list; | |
2633 | |
2634 PLAYLIST_LOCK(); | |
2635 | |
2636 for (list = playlist_get(); list; list = g_list_next(list)) { | |
2637 PlaylistEntry *entry = list->data; | |
2638 entry->selected = !entry->selected; | |
2639 } | |
2640 | |
2641 PLAYLIST_UNLOCK(); | |
2642 playlist_recalc_total_time(); | |
2643 } | |
2644 | |
2645 gboolean | |
2646 playlist_select_invert(guint pos) | |
2647 { | |
2648 GList *list; | |
2649 gboolean invert_ok = FALSE; | |
2650 | |
2651 PLAYLIST_LOCK(); | |
2652 | |
2653 if ((list = g_list_nth(playlist_get(), pos))) { | |
2654 PlaylistEntry *entry = list->data; | |
2655 entry->selected = !entry->selected; | |
2656 invert_ok = TRUE; | |
2657 } | |
2658 | |
2659 PLAYLIST_UNLOCK(); | |
2660 playlist_recalc_total_time(); | |
2661 | |
2662 return invert_ok; | |
2663 } | |
2664 | |
2665 | |
2666 void | |
2667 playlist_select_range(gint min_pos, gint max_pos, gboolean select) | |
2668 { | |
2669 GList *list; | |
2670 gint i; | |
2671 | |
2672 if (min_pos > max_pos) | |
2673 SWAP(min_pos, max_pos); | |
2674 | |
2675 PLAYLIST_LOCK(); | |
2676 | |
2677 list = g_list_nth(playlist_get(), min_pos); | |
2678 for (i = min_pos; i <= max_pos && list; i++) { | |
2679 PlaylistEntry *entry = list->data; | |
2680 entry->selected = select; | |
2681 list = g_list_next(list); | |
2682 } | |
2683 | |
2684 PLAYLIST_UNLOCK(); | |
2685 | |
2686 playlist_recalc_total_time(); | |
2687 } | |
2688 | |
2689 gboolean | |
2690 playlist_read_info_selection(void) | |
2691 { | |
2692 GList *node; | |
2693 gboolean retval = FALSE; | |
2694 | |
2695 PLAYLIST_LOCK(); | |
2696 | |
2697 for (node = playlist_get(); node; node = g_list_next(node)) { | |
2698 PlaylistEntry *entry = node->data; | |
2699 if (!entry->selected) | |
2700 continue; | |
2701 | |
2702 retval = TRUE; | |
2703 | |
2704 str_replace_in(&entry->title, NULL); | |
2705 entry->length = -1; | |
2706 | |
1588
15d92c51bde6
[svn] - modified time (mtime) has been introduced into tuple
yaz
parents:
1587
diff
changeset
|
2707 /* invalidate mtime to reread */ |
1817 | 2708 if (entry->tuple != NULL) |
1841
7d0cd3fab6a2
[svn] - mtime=-1 has been introduced to represent "uninitialized".
yaz
parents:
1834
diff
changeset
|
2709 entry->tuple->mtime = -1; /* -1 denotes "non-initialized". now 0 is for stream etc. yaz */ |
1588
15d92c51bde6
[svn] - modified time (mtime) has been introduced into tuple
yaz
parents:
1587
diff
changeset
|
2710 |
0 | 2711 if (!playlist_entry_get_info(entry)) { |
2712 if (g_list_index(playlist_get(), entry) == -1) | |
2713 /* Entry disappeared while we looked it up. Restart. */ | |
2714 node = playlist_get(); | |
2715 } | |
2716 } | |
2717 | |
2718 PLAYLIST_UNLOCK(); | |
2719 | |
2720 playlistwin_update_list(); | |
2721 playlist_recalc_total_time(); | |
2722 | |
2723 return retval; | |
2724 } | |
2725 | |
2726 void | |
2727 playlist_read_info(guint pos) | |
2728 { | |
2729 GList *node; | |
2730 | |
2731 PLAYLIST_LOCK(); | |
2732 | |
2733 if ((node = g_list_nth(playlist_get(), pos))) { | |
2734 PlaylistEntry *entry = node->data; | |
2735 str_replace_in(&entry->title, NULL); | |
2736 entry->length = -1; | |
2737 playlist_entry_get_info(entry); | |
2738 } | |
2739 | |
2740 PLAYLIST_UNLOCK(); | |
2741 | |
2742 playlistwin_update_list(); | |
2743 playlist_recalc_total_time(); | |
2744 } | |
2745 | |
2080
df6cf9cb531e
[svn] - this commit breaks the API. I'm not done here, but hopefully the new API is
nenolod
parents:
2073
diff
changeset
|
2746 Playlist * |
df6cf9cb531e
[svn] - this commit breaks the API. I'm not done here, but hopefully the new API is
nenolod
parents:
2073
diff
changeset
|
2747 playlist_get_active(void) |
df6cf9cb531e
[svn] - this commit breaks the API. I'm not done here, but hopefully the new API is
nenolod
parents:
2073
diff
changeset
|
2748 { |
df6cf9cb531e
[svn] - this commit breaks the API. I'm not done here, but hopefully the new API is
nenolod
parents:
2073
diff
changeset
|
2749 return &default_playlist; |
df6cf9cb531e
[svn] - this commit breaks the API. I'm not done here, but hopefully the new API is
nenolod
parents:
2073
diff
changeset
|
2750 }; |
df6cf9cb531e
[svn] - this commit breaks the API. I'm not done here, but hopefully the new API is
nenolod
parents:
2073
diff
changeset
|
2751 |
0 | 2752 void |
2753 playlist_set_shuffle(gboolean shuffle) | |
2754 { | |
2755 PLAYLIST_LOCK(); | |
2756 | |
2040
dbe615def81f
[svn] Playlist shuffle behaviour should now be a little more consistant.
nazca
parents:
2027
diff
changeset
|
2757 playlist_position_before_jump = NULL; |
dbe615def81f
[svn] Playlist shuffle behaviour should now be a little more consistant.
nazca
parents:
2027
diff
changeset
|
2758 |
0 | 2759 cfg.shuffle = shuffle; |
2080
df6cf9cb531e
[svn] - this commit breaks the API. I'm not done here, but hopefully the new API is
nenolod
parents:
2073
diff
changeset
|
2760 playlist_generate_shuffle_list_nolock(playlist_get_active()); |
0 | 2761 |
2762 PLAYLIST_UNLOCK(); | |
2763 } | |
2764 | |
2080
df6cf9cb531e
[svn] - this commit breaks the API. I'm not done here, but hopefully the new API is
nenolod
parents:
2073
diff
changeset
|
2765 Playlist * |
0 | 2766 playlist_new(void) |
2767 { | |
2080
df6cf9cb531e
[svn] - this commit breaks the API. I'm not done here, but hopefully the new API is
nenolod
parents:
2073
diff
changeset
|
2768 Playlist *playlist = g_new0(Playlist, 1); |
df6cf9cb531e
[svn] - this commit breaks the API. I'm not done here, but hopefully the new API is
nenolod
parents:
2073
diff
changeset
|
2769 |
df6cf9cb531e
[svn] - this commit breaks the API. I'm not done here, but hopefully the new API is
nenolod
parents:
2073
diff
changeset
|
2770 playlist_set_current_name(playlist, NULL); |
df6cf9cb531e
[svn] - this commit breaks the API. I'm not done here, but hopefully the new API is
nenolod
parents:
2073
diff
changeset
|
2771 playlist_clear(playlist); |
0 | 2772 mainwin_clear_song_info(); |
2773 mainwin_set_info_text(); | |
2080
df6cf9cb531e
[svn] - this commit breaks the API. I'm not done here, but hopefully the new API is
nenolod
parents:
2073
diff
changeset
|
2774 |
df6cf9cb531e
[svn] - this commit breaks the API. I'm not done here, but hopefully the new API is
nenolod
parents:
2073
diff
changeset
|
2775 return playlist; |
0 | 2776 } |
2777 | |
2778 | |
2779 const gchar * | |
2080
df6cf9cb531e
[svn] - this commit breaks the API. I'm not done here, but hopefully the new API is
nenolod
parents:
2073
diff
changeset
|
2780 playlist_get_filename_to_play(Playlist *playlist) |
0 | 2781 { |
2782 const gchar *filename = NULL; | |
2783 | |
2784 PLAYLIST_LOCK(); | |
2785 | |
2786 if (playlist) { | |
2080
df6cf9cb531e
[svn] - this commit breaks the API. I'm not done here, but hopefully the new API is
nenolod
parents:
2073
diff
changeset
|
2787 if (!playlist->position) { |
0 | 2788 if (cfg.shuffle) |
2080
df6cf9cb531e
[svn] - this commit breaks the API. I'm not done here, but hopefully the new API is
nenolod
parents:
2073
diff
changeset
|
2789 playlist->position = playlist->shuffle->data; |
0 | 2790 else |
2080
df6cf9cb531e
[svn] - this commit breaks the API. I'm not done here, but hopefully the new API is
nenolod
parents:
2073
diff
changeset
|
2791 playlist->position = playlist->entries->data; |
0 | 2792 } |
2793 | |
2080
df6cf9cb531e
[svn] - this commit breaks the API. I'm not done here, but hopefully the new API is
nenolod
parents:
2073
diff
changeset
|
2794 filename = playlist->position->filename; |
0 | 2795 } |
2796 | |
2797 PLAYLIST_UNLOCK(); | |
2798 | |
2799 return filename; | |
2800 } | |
356
99928e1275a1
[svn] This commit reduces the amount of times we probe a source down to ONE
nenolod
parents:
355
diff
changeset
|
2801 |
398
f908bcd87c3d
[svn] Generate cache content on demand if it was not previously there.
nenolod
parents:
397
diff
changeset
|
2802 PlaylistEntry * |
2080
df6cf9cb531e
[svn] - this commit breaks the API. I'm not done here, but hopefully the new API is
nenolod
parents:
2073
diff
changeset
|
2803 playlist_get_entry_to_play(Playlist *playlist) |
356
99928e1275a1
[svn] This commit reduces the amount of times we probe a source down to ONE
nenolod
parents:
355
diff
changeset
|
2804 { |
99928e1275a1
[svn] This commit reduces the amount of times we probe a source down to ONE
nenolod
parents:
355
diff
changeset
|
2805 PLAYLIST_LOCK(); |
99928e1275a1
[svn] This commit reduces the amount of times we probe a source down to ONE
nenolod
parents:
355
diff
changeset
|
2806 |
99928e1275a1
[svn] This commit reduces the amount of times we probe a source down to ONE
nenolod
parents:
355
diff
changeset
|
2807 if (playlist) { |
2080
df6cf9cb531e
[svn] - this commit breaks the API. I'm not done here, but hopefully the new API is
nenolod
parents:
2073
diff
changeset
|
2808 if (!playlist->position) { |
356
99928e1275a1
[svn] This commit reduces the amount of times we probe a source down to ONE
nenolod
parents:
355
diff
changeset
|
2809 if (cfg.shuffle) |
2080
df6cf9cb531e
[svn] - this commit breaks the API. I'm not done here, but hopefully the new API is
nenolod
parents:
2073
diff
changeset
|
2810 playlist->position = playlist->shuffle->data; |
356
99928e1275a1
[svn] This commit reduces the amount of times we probe a source down to ONE
nenolod
parents:
355
diff
changeset
|
2811 else |
2080
df6cf9cb531e
[svn] - this commit breaks the API. I'm not done here, but hopefully the new API is
nenolod
parents:
2073
diff
changeset
|
2812 playlist->position = playlist->entries->data; |
356
99928e1275a1
[svn] This commit reduces the amount of times we probe a source down to ONE
nenolod
parents:
355
diff
changeset
|
2813 } |
99928e1275a1
[svn] This commit reduces the amount of times we probe a source down to ONE
nenolod
parents:
355
diff
changeset
|
2814 } |
99928e1275a1
[svn] This commit reduces the amount of times we probe a source down to ONE
nenolod
parents:
355
diff
changeset
|
2815 |
99928e1275a1
[svn] This commit reduces the amount of times we probe a source down to ONE
nenolod
parents:
355
diff
changeset
|
2816 PLAYLIST_UNLOCK(); |
99928e1275a1
[svn] This commit reduces the amount of times we probe a source down to ONE
nenolod
parents:
355
diff
changeset
|
2817 |
2080
df6cf9cb531e
[svn] - this commit breaks the API. I'm not done here, but hopefully the new API is
nenolod
parents:
2073
diff
changeset
|
2818 return playlist->position; |
356
99928e1275a1
[svn] This commit reduces the amount of times we probe a source down to ONE
nenolod
parents:
355
diff
changeset
|
2819 } |