Mercurial > audlegacy
annotate src/audacious/playlist.c @ 3959:a575c29cee05
- revive on-demand metadata retrieving. in the combination with "Detect file formats on demand", now audacious can load large directory in a few seconds.
- revise ext_hash to have lists of input plugins which associated with each extension.
- now input_check_file() makes use of ext_hash for file format probing to avoid full scan in the input list.
- make "detect file formats on demand" default.
- change tooltip text for on demand {detect|metadata}.
- move update request for playlist from idle function to event queue.
author | Yoshiki Yazawa <yaz@cc.rim.or.jp> |
---|---|
date | Sat, 17 Nov 2007 17:07:46 +0900 |
parents | eb20411bb9e1 |
children | efd7ec36483e |
rev | line source |
---|---|
2313 | 1 /* Audacious |
2 * Copyright (C) 2005-2007 Audacious team. | |
3 * | |
4 * BMP (C) GPL 2003 $top_src_dir/AUTHORS | |
5 * | |
6 * based on: | |
7 * | |
8 * XMMS - Cross-platform multimedia player | |
9 * Copyright (C) 1998-2003 Peter Alm, Mikael Alm, Olle Hallnas, | |
10 * Thomas Nilsson and 4Front Technologies | |
11 * Copyright (C) 1999-2003 Haavard Kvaalen | |
12 * | |
13 * This program is free software; you can redistribute it and/or modify | |
14 * it under the terms of the GNU General Public License as published by | |
3121
3b6d316f8b09
GPL3 relicensing.
William Pitcock <nenolod@atheme-project.org>
parents:
3097
diff
changeset
|
15 * the Free Software Foundation; under version 3 of the License. |
2313 | 16 * |
17 * This program is distributed in the hope that it will be useful, | |
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
20 * GNU General Public License for more details. | |
21 * | |
22 * You should have received a copy of the GNU General Public License | |
3121
3b6d316f8b09
GPL3 relicensing.
William Pitcock <nenolod@atheme-project.org>
parents:
3097
diff
changeset
|
23 * along with this program. If not, see <http://www.gnu.org/licenses>. |
3123
f1c756f39e6c
Invoke "Plugins are not derived work" clause provided by GPL3.
William Pitcock <nenolod@atheme-project.org>
parents:
3121
diff
changeset
|
24 * |
f1c756f39e6c
Invoke "Plugins are not derived work" clause provided by GPL3.
William Pitcock <nenolod@atheme-project.org>
parents:
3121
diff
changeset
|
25 * The Audacious team does not consider modular code linking to |
f1c756f39e6c
Invoke "Plugins are not derived work" clause provided by GPL3.
William Pitcock <nenolod@atheme-project.org>
parents:
3121
diff
changeset
|
26 * Audacious or using our public API to be a derived work. |
2313 | 27 */ |
28 | |
29 #ifdef HAVE_CONFIG_H | |
30 # include "config.h" | |
31 #endif | |
32 | |
33 #include "playlist.h" | |
34 | |
2633
c079e507869a
[svn] - use a managed heap for playlist entry node allocation.
nenolod
parents:
2614
diff
changeset
|
35 #include <mowgli.h> |
2313 | 36 #include <glib.h> |
37 #include <glib/gprintf.h> | |
38 #include <stdlib.h> | |
39 #include <string.h> | |
40 #include <time.h> | |
41 | |
42 #include <unistd.h> | |
43 #include <sys/types.h> | |
44 #include <sys/stat.h> | |
45 #include <sys/errno.h> | |
46 | |
47 #if defined(USE_REGEX_ONIGURUMA) | |
3460
0fcff78c0c2c
Make the shutdown procedure more sane and improve playlist clearing
Matti Hamalainen <ccr@tnsp.org>
parents:
3401
diff
changeset
|
48 # include <onigposix.h> |
2313 | 49 #elif defined(USE_REGEX_PCRE) |
3460
0fcff78c0c2c
Make the shutdown procedure more sane and improve playlist clearing
Matti Hamalainen <ccr@tnsp.org>
parents:
3401
diff
changeset
|
50 # include <pcreposix.h> |
2313 | 51 #else |
3460
0fcff78c0c2c
Make the shutdown procedure more sane and improve playlist clearing
Matti Hamalainen <ccr@tnsp.org>
parents:
3401
diff
changeset
|
52 # include <regex.h> |
2313 | 53 #endif |
54 | |
55 #include "input.h" | |
56 #include "main.h" | |
57 #include "ui_main.h" | |
2416
0fd7f4f969ad
[svn] integrated urldecode.* from libaudacious into audacious directory, made separate ui_fileopener.*
mf0102
parents:
2408
diff
changeset
|
58 #include "util.h" |
2717 | 59 #include "configdb.h" |
2313 | 60 #include "vfs.h" |
61 #include "ui_equalizer.h" | |
62 #include "playback.h" | |
63 #include "playlist.h" | |
64 #include "playlist_container.h" | |
2499
15a1f5ee4d1c
[svn] - playlist_manager -> ui_playlist_manager, since it's a UI component.
nenolod
parents:
2493
diff
changeset
|
65 #include "ui_playlist_manager.h" |
2313 | 66 #include "ui_playlist.h" |
2373
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
67 #include "strings.h" |
2313 | 68 #include "ui_fileinfo.h" |
69 | |
70 #include "debug.h" | |
71 | |
2407
1dc1d36d0347
[svn] - add hooks: playback begin, playback end, playlist reached end
nenolod
parents:
2380
diff
changeset
|
72 #include "hook.h" |
1dc1d36d0347
[svn] - add hooks: playback begin, playback end, playlist reached end
nenolod
parents:
2380
diff
changeset
|
73 |
3159
a2d552ea48f0
Use message passing to make sure the UI is updated in the main thread.
William Pitcock <nenolod@atheme-project.org>
parents:
3132
diff
changeset
|
74 #include "playlist_evmessages.h" |
a2d552ea48f0
Use message passing to make sure the UI is updated in the main thread.
William Pitcock <nenolod@atheme-project.org>
parents:
3132
diff
changeset
|
75 #include "playlist_evlisteners.h" |
3217 | 76 #include "ui_skinned_playlist.h" |
3159
a2d552ea48f0
Use message passing to make sure the UI is updated in the main thread.
William Pitcock <nenolod@atheme-project.org>
parents:
3132
diff
changeset
|
77 |
2313 | 78 typedef gint (*PlaylistCompareFunc) (PlaylistEntry * a, PlaylistEntry * b); |
79 typedef void (*PlaylistSaveFunc) (FILE * file); | |
80 | |
81 /* If we manually change the song, p_p_b_j will show us where to go back to */ | |
82 PlaylistEntry *playlist_position_before_jump = NULL; | |
83 | |
84 static GList *playlists = NULL; | |
85 static GList *playlists_iter; | |
86 | |
87 /* If this is set to TRUE, we do not probe upon playlist add. | |
88 * | |
89 * Under Audacious 0.1.x, this was not a big deal because we used | |
90 * file extension introspection instead of looking for file format magic | |
91 * strings. | |
92 * | |
93 * Because we use file magic strings, we have to fstat a file being added | |
94 * to a playlist up to 1 * <number of input plugins installed> times. | |
95 * | |
96 * This can get really slow now that we're looking for files to add to a | |
97 * playlist. (Up to 5 minutes for 5000 songs, etcetera.) | |
98 * | |
99 * So, we obviously don't want to probe while opening a large playlist | |
100 * up. Hince the boolean below. | |
101 * | |
102 * January 7, 2006, William Pitcock <nenolod@nenolod.net> | |
103 */ | |
104 | |
105 | |
2328 | 106 //static gchar *playlist_current_name = NULL; |
2313 | 107 |
108 static gboolean playlist_get_info_scan_active = FALSE; | |
3460
0fcff78c0c2c
Make the shutdown procedure more sane and improve playlist clearing
Matti Hamalainen <ccr@tnsp.org>
parents:
3401
diff
changeset
|
109 GStaticRWLock playlist_get_info_rwlock = G_STATIC_RW_LOCK_INIT; |
2313 | 110 static gboolean playlist_get_info_going = FALSE; |
111 static GThread *playlist_get_info_thread; | |
112 | |
3934
e924c9ee3958
when "Detect file formats on demand" is specified, filter unplayable files on loading by the hash table of all available extensions.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3923
diff
changeset
|
113 extern GHashTable *ext_hash; |
e924c9ee3958
when "Detect file formats on demand" is specified, filter unplayable files on loading by the hash table of all available extensions.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3923
diff
changeset
|
114 |
2313 | 115 static gint path_compare(const gchar * a, const gchar * b); |
116 static gint playlist_compare_path(PlaylistEntry * a, PlaylistEntry * b); | |
117 static gint playlist_compare_filename(PlaylistEntry * a, PlaylistEntry * b); | |
118 static gint playlist_compare_title(PlaylistEntry * a, PlaylistEntry * b); | |
119 static gint playlist_compare_artist(PlaylistEntry * a, PlaylistEntry * b); | |
120 static time_t playlist_get_mtime(const gchar *filename); | |
121 static gint playlist_compare_date(PlaylistEntry * a, PlaylistEntry * b); | |
122 static gint playlist_compare_track(PlaylistEntry * a, PlaylistEntry * b); | |
123 static gint playlist_compare_playlist(PlaylistEntry * a, PlaylistEntry * b); | |
124 | |
125 static gint playlist_dupscmp_path(PlaylistEntry * a, PlaylistEntry * b); | |
126 static gint playlist_dupscmp_filename(PlaylistEntry * a, PlaylistEntry * b); | |
127 static gint playlist_dupscmp_title(PlaylistEntry * a, PlaylistEntry * b); | |
128 | |
129 static PlaylistCompareFunc playlist_compare_func_table[] = { | |
130 playlist_compare_path, | |
131 playlist_compare_filename, | |
132 playlist_compare_title, | |
133 playlist_compare_artist, | |
134 playlist_compare_date, | |
135 playlist_compare_track, | |
136 playlist_compare_playlist | |
137 }; | |
138 | |
139 static guint playlist_load_ins(Playlist * playlist, const gchar * filename, gint pos); | |
140 | |
141 static void playlist_generate_shuffle_list(Playlist *); | |
142 static void playlist_generate_shuffle_list_nolock(Playlist *); | |
143 | |
144 static void playlist_recalc_total_time_nolock(Playlist *); | |
145 static void playlist_recalc_total_time(Playlist *); | |
146 static gboolean playlist_entry_get_info(PlaylistEntry * entry); | |
147 | |
3934
e924c9ee3958
when "Detect file formats on demand" is specified, filter unplayable files on loading by the hash table of all available extensions.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3923
diff
changeset
|
148 static gboolean filter_by_extension(const gchar *filename); |
e924c9ee3958
when "Detect file formats on demand" is specified, filter unplayable files on loading by the hash table of all available extensions.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3923
diff
changeset
|
149 |
2633
c079e507869a
[svn] - use a managed heap for playlist entry node allocation.
nenolod
parents:
2614
diff
changeset
|
150 static mowgli_heap_t *playlist_entry_heap = NULL; |
c079e507869a
[svn] - use a managed heap for playlist entry node allocation.
nenolod
parents:
2614
diff
changeset
|
151 |
2313 | 152 /* *********************** playlist entry code ********************** */ |
153 | |
154 PlaylistEntry * | |
155 playlist_entry_new(const gchar * filename, | |
156 const gchar * title, | |
157 const gint length, | |
158 InputPlugin * dec) | |
159 { | |
160 PlaylistEntry *entry; | |
161 | |
2633
c079e507869a
[svn] - use a managed heap for playlist entry node allocation.
nenolod
parents:
2614
diff
changeset
|
162 entry = mowgli_heap_alloc(playlist_entry_heap); |
2313 | 163 entry->filename = g_strdup(filename); |
164 entry->title = str_to_utf8(title); | |
165 entry->length = length; | |
166 entry->selected = FALSE; | |
167 entry->decoder = dec; | |
168 | |
169 /* only do this if we have a decoder, otherwise it just takes too long */ | |
170 if (entry->decoder) | |
171 playlist_entry_get_info(entry); | |
172 | |
173 return entry; | |
174 } | |
175 | |
176 void | |
177 playlist_entry_free(PlaylistEntry * entry) | |
178 { | |
179 if (!entry) | |
180 return; | |
181 | |
182 if (entry->tuple != NULL) { | |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
183 mowgli_object_unref(entry->tuple); |
2313 | 184 entry->tuple = NULL; |
185 } | |
186 | |
3510
b2a82a73a788
Few bits of pre-integration shit.
Matti Hamalainen <ccr@tnsp.org>
parents:
3507
diff
changeset
|
187 g_free(entry->filename); |
b2a82a73a788
Few bits of pre-integration shit.
Matti Hamalainen <ccr@tnsp.org>
parents:
3507
diff
changeset
|
188 g_free(entry->title); |
2633
c079e507869a
[svn] - use a managed heap for playlist entry node allocation.
nenolod
parents:
2614
diff
changeset
|
189 mowgli_heap_free(playlist_entry_heap, entry); |
2313 | 190 } |
191 | |
192 static gboolean | |
193 playlist_entry_get_info(PlaylistEntry * entry) | |
194 { | |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
195 Tuple *tuple = NULL; |
3127
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
196 ProbeResult *pr = NULL; |
2313 | 197 time_t modtime; |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
198 const gchar *formatter; |
2313 | 199 |
200 g_return_val_if_fail(entry != NULL, FALSE); | |
201 | |
3490
602ec8c40d0d
Fixed to comply with the Tuple API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
3401
diff
changeset
|
202 if (entry->tuple == NULL || tuple_get_int(entry->tuple, FIELD_MTIME, NULL) > 0 || |
602ec8c40d0d
Fixed to comply with the Tuple API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
3401
diff
changeset
|
203 tuple_get_int(entry->tuple, FIELD_MTIME, NULL) == -1) |
2636 | 204 modtime = playlist_get_mtime(entry->filename); |
2313 | 205 else |
2636 | 206 modtime = 0; /* URI -nenolod */ |
2313 | 207 |
2668
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
208 if (str_has_prefix_nocase(entry->filename, "http:") && |
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
209 g_thread_self() != playlist_get_info_thread) |
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
210 return FALSE; |
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
211 |
3635 | 212 if (entry->decoder == NULL) { |
3127
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
213 pr = input_check_file(entry->filename, FALSE); |
3128
343504d43afc
Fix warnings.
William Pitcock <nenolod@atheme-project.org>
parents:
3127
diff
changeset
|
214 if (pr) |
3635 | 215 entry->decoder = pr->ip; |
3127
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
216 } |
2313 | 217 |
218 /* renew tuple if file mtime is newer than tuple mtime. */ | |
3635 | 219 if (entry->tuple){ |
220 if (tuple_get_int(entry->tuple, FIELD_MTIME, NULL) == modtime) | |
2313 | 221 return TRUE; |
222 else { | |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
223 mowgli_object_unref(entry->tuple); |
2313 | 224 entry->tuple = NULL; |
225 } | |
226 } | |
227 | |
3127
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
228 if (pr != NULL && pr->tuple != NULL) |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
229 tuple = pr->tuple; |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
230 else if (entry->decoder != NULL && entry->decoder->get_song_tuple != NULL) |
2313 | 231 tuple = entry->decoder->get_song_tuple(entry->filename); |
232 | |
233 if (tuple == NULL) | |
234 return FALSE; | |
235 | |
236 /* attach mtime */ | |
3490
602ec8c40d0d
Fixed to comply with the Tuple API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
3401
diff
changeset
|
237 tuple_associate_int(tuple, FIELD_MTIME, NULL, modtime); |
2313 | 238 |
239 /* entry is still around */ | |
3490
602ec8c40d0d
Fixed to comply with the Tuple API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
3401
diff
changeset
|
240 formatter = tuple_get_string(tuple, FIELD_FORMATTER, NULL); |
3349
01a241d35146
add tuple_formatter_make_title_string(). it is a wrapper function to tuple_formatter_process_construct() to make title string. it falls back to the file name if the formatted string is blank or unavailable.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3348
diff
changeset
|
241 entry->title = tuple_formatter_make_title_string(tuple, formatter ? |
3334
ea806daf3ef0
rename xmms_get_gentitle_format() to get_gentitle_format().
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3327
diff
changeset
|
242 formatter : get_gentitle_format()); |
3490
602ec8c40d0d
Fixed to comply with the Tuple API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
3401
diff
changeset
|
243 entry->length = tuple_get_int(tuple, FIELD_LENGTH, NULL); |
2313 | 244 entry->tuple = tuple; |
245 | |
3127
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
246 g_free(pr); |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
247 |
2313 | 248 return TRUE; |
249 } | |
250 | |
251 /* *********************** playlist selector code ************************* */ | |
252 | |
253 void | |
254 playlist_init(void) | |
255 { | |
256 Playlist *initial_pl; | |
257 | |
2633
c079e507869a
[svn] - use a managed heap for playlist entry node allocation.
nenolod
parents:
2614
diff
changeset
|
258 /* create a heap with 1024 playlist entry nodes preallocated. --nenolod */ |
c079e507869a
[svn] - use a managed heap for playlist entry node allocation.
nenolod
parents:
2614
diff
changeset
|
259 playlist_entry_heap = mowgli_heap_create(sizeof(PlaylistEntry), 1024, |
c079e507869a
[svn] - use a managed heap for playlist entry node allocation.
nenolod
parents:
2614
diff
changeset
|
260 BH_NOW); |
c079e507869a
[svn] - use a managed heap for playlist entry node allocation.
nenolod
parents:
2614
diff
changeset
|
261 |
2313 | 262 /* FIXME: is this really necessary? REQUIRE_STATIC_LOCK(playlists); */ |
263 | |
264 initial_pl = playlist_new(); | |
265 | |
266 playlist_add_playlist(initial_pl); | |
3159
a2d552ea48f0
Use message passing to make sure the UI is updated in the main thread.
William Pitcock <nenolod@atheme-project.org>
parents:
3132
diff
changeset
|
267 |
a2d552ea48f0
Use message passing to make sure the UI is updated in the main thread.
William Pitcock <nenolod@atheme-project.org>
parents:
3132
diff
changeset
|
268 playlist_evlistener_init(); |
2313 | 269 } |
270 | |
271 void | |
272 playlist_add_playlist(Playlist *playlist) | |
273 { | |
274 playlists = g_list_append(playlists, playlist); | |
275 | |
276 if (playlists_iter == NULL) | |
277 playlists_iter = playlists; | |
278 | |
279 playlist_manager_update(); | |
280 } | |
281 | |
282 void | |
283 playlist_remove_playlist(Playlist *playlist) | |
284 { | |
3473
3b26640f9fd6
Don't stop playback when deleting a non-active playlist
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3401
diff
changeset
|
285 gboolean active; |
3b26640f9fd6
Don't stop playback when deleting a non-active playlist
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3401
diff
changeset
|
286 active = (playlist && playlist == playlist_get_active()); |
2820 | 287 /* users suppose playback will be stopped on removing playlist */ |
3473
3b26640f9fd6
Don't stop playback when deleting a non-active playlist
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3401
diff
changeset
|
288 if (active && playback_get_playing()) { |
2820 | 289 ip_data.stop = TRUE; |
290 playback_stop(); | |
291 ip_data.stop = FALSE; | |
292 mainwin_clear_song_info(); | |
293 } | |
294 | |
2313 | 295 /* trying to free the last playlist simply clears and resets it */ |
296 if (g_list_length(playlists) < 2) { | |
297 playlist_clear(playlist); | |
298 playlist_set_current_name(playlist, NULL); | |
3477
57f4971b7086
New functions for associating a filename with a playlist. Made title/filename setting more consistent.
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3476
diff
changeset
|
299 playlist_filename_set(playlist, NULL); |
2313 | 300 return; |
301 } | |
302 | |
3473
3b26640f9fd6
Don't stop playback when deleting a non-active playlist
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3401
diff
changeset
|
303 if (active) playlist_select_next(); |
2313 | 304 |
305 /* upon removal, a playlist should be cleared and freed */ | |
306 playlists = g_list_remove(playlists, playlist); | |
307 playlist_clear(playlist); | |
308 playlist_free(playlist); | |
309 | |
310 if (playlists_iter == NULL) | |
311 playlists_iter = playlists; | |
312 | |
313 playlist_manager_update(); | |
314 } | |
315 | |
316 GList * | |
317 playlist_get_playlists(void) | |
318 { | |
319 return playlists; | |
320 } | |
321 | |
322 void | |
323 playlist_select_next(void) | |
324 { | |
325 if (playlists_iter == NULL) | |
326 playlists_iter = playlists; | |
327 | |
328 playlists_iter = g_list_next(playlists_iter); | |
329 | |
330 if (playlists_iter == NULL) | |
331 playlists_iter = playlists; | |
332 | |
333 playlistwin_update_list(playlist_get_active()); | |
3621
2d6106656276
Notify playlist manager of more changes
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3583
diff
changeset
|
334 playlist_manager_update(); |
2313 | 335 } |
336 | |
337 void | |
338 playlist_select_prev(void) | |
339 { | |
340 if (playlists_iter == NULL) | |
341 playlists_iter = playlists; | |
342 | |
343 playlists_iter = g_list_previous(playlists_iter); | |
344 | |
345 if (playlists_iter == NULL) | |
346 playlists_iter = playlists; | |
347 | |
348 playlistwin_update_list(playlist_get_active()); | |
3621
2d6106656276
Notify playlist manager of more changes
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3583
diff
changeset
|
349 playlist_manager_update(); |
2313 | 350 } |
351 | |
352 void | |
353 playlist_select_playlist(Playlist *playlist) | |
354 { | |
355 playlists_iter = g_list_find(playlists, playlist); | |
356 | |
357 if (playlists_iter == NULL) | |
358 playlists_iter = playlists; | |
359 | |
360 playlistwin_update_list(playlist); | |
3621
2d6106656276
Notify playlist manager of more changes
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3583
diff
changeset
|
361 playlist_manager_update(); |
2313 | 362 } |
363 | |
364 /* *********************** playlist code ********************** */ | |
365 | |
366 const gchar * | |
367 playlist_get_current_name(Playlist *playlist) | |
368 { | |
369 return playlist->title; | |
370 } | |
371 | |
3477
57f4971b7086
New functions for associating a filename with a playlist. Made title/filename setting more consistent.
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3476
diff
changeset
|
372 /* This function now sets the playlist title, not the playlist filename. |
57f4971b7086
New functions for associating a filename with a playlist. Made title/filename setting more consistent.
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3476
diff
changeset
|
373 * See playlist_filename_set */ |
2313 | 374 gboolean |
3477
57f4971b7086
New functions for associating a filename with a playlist. Made title/filename setting more consistent.
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3476
diff
changeset
|
375 playlist_set_current_name(Playlist *playlist, const gchar * title) |
2313 | 376 { |
3635 | 377 gchar *oldtitle = playlist->title; |
3477
57f4971b7086
New functions for associating a filename with a playlist. Made title/filename setting more consistent.
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3476
diff
changeset
|
378 |
57f4971b7086
New functions for associating a filename with a playlist. Made title/filename setting more consistent.
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3476
diff
changeset
|
379 if (!title) { |
2313 | 380 playlist->title = NULL; |
3635 | 381 g_free(oldtitle); |
3621
2d6106656276
Notify playlist manager of more changes
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3583
diff
changeset
|
382 playlist_manager_update(); |
2313 | 383 return FALSE; |
384 } | |
385 | |
3477
57f4971b7086
New functions for associating a filename with a playlist. Made title/filename setting more consistent.
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3476
diff
changeset
|
386 playlist->title = str_to_utf8(title); |
3635 | 387 g_free(oldtitle); |
3621
2d6106656276
Notify playlist manager of more changes
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3583
diff
changeset
|
388 playlist_manager_update(); |
2313 | 389 return TRUE; |
390 } | |
391 | |
3477
57f4971b7086
New functions for associating a filename with a playlist. Made title/filename setting more consistent.
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3476
diff
changeset
|
392 /* Setting the filename allows the original playlist to be modified later */ |
57f4971b7086
New functions for associating a filename with a playlist. Made title/filename setting more consistent.
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3476
diff
changeset
|
393 gboolean |
57f4971b7086
New functions for associating a filename with a playlist. Made title/filename setting more consistent.
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3476
diff
changeset
|
394 playlist_filename_set(Playlist *playlist, const gchar * filename) |
57f4971b7086
New functions for associating a filename with a playlist. Made title/filename setting more consistent.
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3476
diff
changeset
|
395 { |
57f4971b7086
New functions for associating a filename with a playlist. Made title/filename setting more consistent.
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3476
diff
changeset
|
396 gchar *old; |
57f4971b7086
New functions for associating a filename with a playlist. Made title/filename setting more consistent.
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3476
diff
changeset
|
397 old = playlist->filename; |
57f4971b7086
New functions for associating a filename with a playlist. Made title/filename setting more consistent.
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3476
diff
changeset
|
398 |
3635 | 399 if (!filename) { |
3477
57f4971b7086
New functions for associating a filename with a playlist. Made title/filename setting more consistent.
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3476
diff
changeset
|
400 playlist->filename = NULL; |
3635 | 401 g_free(old); |
3477
57f4971b7086
New functions for associating a filename with a playlist. Made title/filename setting more consistent.
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3476
diff
changeset
|
402 return FALSE; |
57f4971b7086
New functions for associating a filename with a playlist. Made title/filename setting more consistent.
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3476
diff
changeset
|
403 } |
57f4971b7086
New functions for associating a filename with a playlist. Made title/filename setting more consistent.
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3476
diff
changeset
|
404 |
57f4971b7086
New functions for associating a filename with a playlist. Made title/filename setting more consistent.
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3476
diff
changeset
|
405 playlist->filename = filename_to_utf8(filename); |
3635 | 406 g_free(old); |
3477
57f4971b7086
New functions for associating a filename with a playlist. Made title/filename setting more consistent.
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3476
diff
changeset
|
407 return TRUE; |
57f4971b7086
New functions for associating a filename with a playlist. Made title/filename setting more consistent.
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3476
diff
changeset
|
408 } |
57f4971b7086
New functions for associating a filename with a playlist. Made title/filename setting more consistent.
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3476
diff
changeset
|
409 |
57f4971b7086
New functions for associating a filename with a playlist. Made title/filename setting more consistent.
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3476
diff
changeset
|
410 gchar * |
57f4971b7086
New functions for associating a filename with a playlist. Made title/filename setting more consistent.
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3476
diff
changeset
|
411 playlist_filename_get(Playlist *playlist) |
57f4971b7086
New functions for associating a filename with a playlist. Made title/filename setting more consistent.
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3476
diff
changeset
|
412 { |
3635 | 413 if (!playlist->filename) return NULL; |
3477
57f4971b7086
New functions for associating a filename with a playlist. Made title/filename setting more consistent.
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3476
diff
changeset
|
414 return g_filename_from_utf8(playlist->filename, -1, NULL, NULL, NULL); |
57f4971b7086
New functions for associating a filename with a playlist. Made title/filename setting more consistent.
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3476
diff
changeset
|
415 } |
57f4971b7086
New functions for associating a filename with a playlist. Made title/filename setting more consistent.
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3476
diff
changeset
|
416 |
2313 | 417 static GList * |
418 find_playlist_position_list(Playlist *playlist) | |
419 { | |
420 REQUIRE_LOCK(playlist->mutex); | |
421 | |
422 if (!playlist->position) { | |
423 if (cfg.shuffle) | |
424 return playlist->shuffle; | |
425 else | |
426 return playlist->entries; | |
427 } | |
428 | |
429 if (cfg.shuffle) | |
430 return g_list_find(playlist->shuffle, playlist->position); | |
431 else | |
432 return g_list_find(playlist->entries, playlist->position); | |
433 } | |
434 | |
435 static void | |
436 play_queued(Playlist *playlist) | |
437 { | |
438 GList *tmp = playlist->queue; | |
439 | |
3635 | 440 REQUIRE_LOCK(playlist->mutex); |
2313 | 441 |
442 playlist->position = playlist->queue->data; | |
443 playlist->queue = g_list_remove_link(playlist->queue, playlist->queue); | |
444 g_list_free_1(tmp); | |
445 } | |
446 | |
447 void | |
3460
0fcff78c0c2c
Make the shutdown procedure more sane and improve playlist clearing
Matti Hamalainen <ccr@tnsp.org>
parents:
3401
diff
changeset
|
448 playlist_clear_only(Playlist *playlist) |
2313 | 449 { |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
450 PLAYLIST_LOCK(playlist); |
2313 | 451 |
452 g_list_foreach(playlist->entries, (GFunc) playlist_entry_free, NULL); | |
453 g_list_free(playlist->entries); | |
454 playlist->position = NULL; | |
455 playlist->entries = NULL; | |
2549
ef59b072a5d2
[svn] - update playlist->tail when an entry has been removed.
yaz
parents:
2548
diff
changeset
|
456 playlist->tail = NULL; |
2637
420ce282920d
[svn] - clear playlist attribute when playlist_clear() is called.
yaz
parents:
2636
diff
changeset
|
457 playlist->attribute = PLAYLIST_PLAIN; |
3920
c2b2828186ba
- serial number has been added to playlist structure so that changes of the current playlist can be notified.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3867
diff
changeset
|
458 playlist->serial = 0; |
2313 | 459 |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
460 PLAYLIST_UNLOCK(playlist); |
3460
0fcff78c0c2c
Make the shutdown procedure more sane and improve playlist clearing
Matti Hamalainen <ccr@tnsp.org>
parents:
3401
diff
changeset
|
461 } |
0fcff78c0c2c
Make the shutdown procedure more sane and improve playlist clearing
Matti Hamalainen <ccr@tnsp.org>
parents:
3401
diff
changeset
|
462 |
0fcff78c0c2c
Make the shutdown procedure more sane and improve playlist clearing
Matti Hamalainen <ccr@tnsp.org>
parents:
3401
diff
changeset
|
463 void |
0fcff78c0c2c
Make the shutdown procedure more sane and improve playlist clearing
Matti Hamalainen <ccr@tnsp.org>
parents:
3401
diff
changeset
|
464 playlist_clear(Playlist *playlist) |
0fcff78c0c2c
Make the shutdown procedure more sane and improve playlist clearing
Matti Hamalainen <ccr@tnsp.org>
parents:
3401
diff
changeset
|
465 { |
0fcff78c0c2c
Make the shutdown procedure more sane and improve playlist clearing
Matti Hamalainen <ccr@tnsp.org>
parents:
3401
diff
changeset
|
466 if (!playlist) |
0fcff78c0c2c
Make the shutdown procedure more sane and improve playlist clearing
Matti Hamalainen <ccr@tnsp.org>
parents:
3401
diff
changeset
|
467 return; |
0fcff78c0c2c
Make the shutdown procedure more sane and improve playlist clearing
Matti Hamalainen <ccr@tnsp.org>
parents:
3401
diff
changeset
|
468 |
0fcff78c0c2c
Make the shutdown procedure more sane and improve playlist clearing
Matti Hamalainen <ccr@tnsp.org>
parents:
3401
diff
changeset
|
469 playlist_clear_only(playlist); |
2313 | 470 playlist_generate_shuffle_list(playlist); |
471 playlistwin_update_list(playlist); | |
472 playlist_recalc_total_time(playlist); | |
3923
e9fd46b0893b
- redefine playlist_incr_serial as a macro.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3922
diff
changeset
|
473 PLAYLIST_INCR_SERIAL(playlist); |
2313 | 474 playlist_manager_update(); |
475 } | |
476 | |
477 static void | |
478 playlist_delete_node(Playlist * playlist, GList * node, gboolean * set_info_text, | |
479 gboolean * restart_playing) | |
480 { | |
481 PlaylistEntry *entry; | |
482 GList *playing_song = NULL; | |
483 | |
484 REQUIRE_LOCK(playlist->mutex); | |
485 | |
486 /* We call g_list_find manually here because we don't want an item | |
487 * in the shuffle_list */ | |
488 | |
489 if (playlist->position) | |
490 playing_song = g_list_find(playlist->entries, playlist->position); | |
491 | |
492 entry = PLAYLIST_ENTRY(node->data); | |
493 | |
494 if (playing_song == node) { | |
495 *set_info_text = TRUE; | |
496 | |
497 if (playback_get_playing()) { | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
498 PLAYLIST_UNLOCK(playlist); |
2313 | 499 ip_data.stop = TRUE; |
500 playback_stop(); | |
501 ip_data.stop = FALSE; | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
502 PLAYLIST_LOCK(playlist); |
2313 | 503 *restart_playing = TRUE; |
504 } | |
505 | |
506 playing_song = find_playlist_position_list(playlist); | |
507 | |
508 if (g_list_next(playing_song)) | |
509 playlist->position = g_list_next(playing_song)->data; | |
510 else if (g_list_previous(playing_song)) | |
511 playlist->position = g_list_previous(playing_song)->data; | |
512 else | |
513 playlist->position = NULL; | |
514 | |
515 /* Make sure the entry did not disappear under us */ | |
516 if (g_list_index(playlist->entries, entry) == -1) | |
517 return; | |
518 | |
519 } | |
520 else if (g_list_position(playlist->entries, playing_song) > | |
521 g_list_position(playlist->entries, node)) { | |
522 *set_info_text = TRUE; | |
523 } | |
524 | |
525 playlist->shuffle = g_list_remove(playlist->shuffle, entry); | |
526 playlist->queue = g_list_remove(playlist->queue, entry); | |
527 playlist->entries = g_list_remove_link(playlist->entries, node); | |
2549
ef59b072a5d2
[svn] - update playlist->tail when an entry has been removed.
yaz
parents:
2548
diff
changeset
|
528 playlist->tail = g_list_last(playlist->entries); |
2313 | 529 playlist_entry_free(entry); |
530 g_list_free_1(node); | |
531 | |
532 playlist_recalc_total_time_nolock(playlist); | |
3923
e9fd46b0893b
- redefine playlist_incr_serial as a macro.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3922
diff
changeset
|
533 PLAYLIST_INCR_SERIAL(playlist); |
2313 | 534 } |
535 | |
536 void | |
537 playlist_delete_index(Playlist *playlist, guint pos) | |
538 { | |
539 gboolean restart_playing = FALSE, set_info_text = FALSE; | |
540 GList *node; | |
541 | |
542 if (!playlist) | |
543 return; | |
544 | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
545 PLAYLIST_LOCK(playlist); |
2313 | 546 |
547 node = g_list_nth(playlist->entries, pos); | |
548 | |
549 if (!node) { | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
550 PLAYLIST_UNLOCK(playlist); |
2313 | 551 return; |
552 } | |
553 | |
554 playlist_delete_node(playlist, node, &set_info_text, &restart_playing); | |
555 | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
556 PLAYLIST_UNLOCK(playlist); |
2313 | 557 |
558 playlist_recalc_total_time(playlist); | |
3923
e9fd46b0893b
- redefine playlist_incr_serial as a macro.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3922
diff
changeset
|
559 PLAYLIST_INCR_SERIAL(playlist); |
2313 | 560 |
561 playlistwin_update_list(playlist); | |
562 if (restart_playing) { | |
3348
2a081105513c
-Set the track "title" in metadata instead of "name"
Ben Tucker <ben.tucker@gmail.com>
parents:
3346
diff
changeset
|
563 if (playlist->position) |
2313 | 564 playback_initiate(); |
3635 | 565 else |
2313 | 566 mainwin_clear_song_info(); |
567 } | |
568 | |
569 playlist_manager_update(); | |
570 } | |
571 | |
572 void | |
573 playlist_delete_filenames(Playlist * playlist, GList * filenames) | |
574 { | |
575 GList *node, *fnode; | |
576 gboolean set_info_text = FALSE, restart_playing = FALSE; | |
577 | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
578 PLAYLIST_LOCK(playlist); |
2313 | 579 |
580 for (fnode = filenames; fnode; fnode = g_list_next(fnode)) { | |
581 node = playlist->entries; | |
582 | |
583 while (node) { | |
584 GList *next = g_list_next(node); | |
585 PlaylistEntry *entry = node->data; | |
586 | |
587 if (!strcmp(entry->filename, fnode->data)) | |
588 playlist_delete_node(playlist, node, &set_info_text, &restart_playing); | |
589 | |
590 node = next; | |
591 } | |
592 } | |
593 | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
594 PLAYLIST_UNLOCK(playlist); |
2792
790bb0954b93
[svn] - move playlist_recalc_total_time() out of the giant playlist lock in playlist_delete_filenames(). reported by dotzen, closes #908.
nenolod
parents:
2776
diff
changeset
|
595 |
2313 | 596 playlist_recalc_total_time(playlist); |
3923
e9fd46b0893b
- redefine playlist_incr_serial as a macro.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3922
diff
changeset
|
597 PLAYLIST_INCR_SERIAL(playlist); |
2313 | 598 playlistwin_update_list(playlist); |
599 | |
600 if (restart_playing) { | |
3348
2a081105513c
-Set the track "title" in metadata instead of "name"
Ben Tucker <ben.tucker@gmail.com>
parents:
3346
diff
changeset
|
601 if (playlist->position) |
2313 | 602 playback_initiate(); |
3635 | 603 else |
2313 | 604 mainwin_clear_song_info(); |
605 } | |
606 | |
607 playlist_manager_update(); | |
608 } | |
609 | |
610 void | |
611 playlist_delete(Playlist * playlist, gboolean crop) | |
612 { | |
613 gboolean restart_playing = FALSE, set_info_text = FALSE; | |
614 GList *node, *next_node; | |
615 PlaylistEntry *entry; | |
616 | |
617 g_return_if_fail(playlist != NULL); | |
618 | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
619 PLAYLIST_LOCK(playlist); |
2313 | 620 |
621 node = playlist->entries; | |
622 | |
623 while (node) { | |
624 entry = PLAYLIST_ENTRY(node->data); | |
625 | |
626 next_node = g_list_next(node); | |
627 | |
628 if ((entry->selected && !crop) || (!entry->selected && crop)) { | |
629 playlist_delete_node(playlist, node, &set_info_text, &restart_playing); | |
630 } | |
631 | |
632 node = next_node; | |
633 } | |
634 | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
635 PLAYLIST_UNLOCK(playlist); |
2313 | 636 |
637 playlist_recalc_total_time(playlist); | |
3923
e9fd46b0893b
- redefine playlist_incr_serial as a macro.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3922
diff
changeset
|
638 PLAYLIST_INCR_SERIAL(playlist); |
2313 | 639 |
640 if (restart_playing) { | |
3348
2a081105513c
-Set the track "title" in metadata instead of "name"
Ben Tucker <ben.tucker@gmail.com>
parents:
3346
diff
changeset
|
641 if (playlist->position) |
2313 | 642 playback_initiate(); |
3635 | 643 else |
2313 | 644 mainwin_clear_song_info(); |
645 } | |
646 | |
647 playlistwin_update_list(playlist); | |
648 playlist_manager_update(); | |
649 } | |
650 | |
651 static void | |
652 __playlist_ins_with_info(Playlist * playlist, | |
2545
610d85b8a22b
[svn] - on loading a playlist with tuple, invoke the scanner thread only if mtime is -1.
yaz
parents:
2504
diff
changeset
|
653 const gchar * filename, |
2313 | 654 gint pos, |
655 const gchar * title, | |
656 gint len, | |
2545
610d85b8a22b
[svn] - on loading a playlist with tuple, invoke the scanner thread only if mtime is -1.
yaz
parents:
2504
diff
changeset
|
657 InputPlugin * dec) |
2313 | 658 { |
659 g_return_if_fail(filename != NULL); | |
660 | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
661 PLAYLIST_LOCK(playlist); |
2313 | 662 playlist->entries = g_list_insert(playlist->entries, |
663 playlist_entry_new(filename, title, len, dec), | |
664 pos); | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
665 PLAYLIST_UNLOCK(playlist); |
2313 | 666 |
667 g_mutex_lock(mutex_scan); | |
668 playlist_get_info_scan_active = TRUE; | |
669 g_mutex_unlock(mutex_scan); | |
670 g_cond_signal(cond_scan); | |
3923
e9fd46b0893b
- redefine playlist_incr_serial as a macro.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3922
diff
changeset
|
671 PLAYLIST_INCR_SERIAL(playlist); |
2313 | 672 } |
673 | |
674 static void | |
675 __playlist_ins_with_info_tuple(Playlist * playlist, | |
676 const gchar * filename, | |
677 gint pos, | |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
678 Tuple *tuple, |
2313 | 679 InputPlugin * dec) |
680 { | |
681 PlaylistEntry *entry; | |
3778
b4fe7d2a0d0d
Use a more describing variable name.
Matti Hamalainen <ccr@tnsp.org>
parents:
3733
diff
changeset
|
682 Tuple *parent_tuple = NULL; |
3784 | 683 gint nsubtunes = 0, subtune = 0; |
3636
65b750891387
Possibly fix a lockup problem.
Matti Hamalainen <ccr@tnsp.org>
parents:
3635
diff
changeset
|
684 gboolean add_flag = TRUE; |
2313 | 685 |
686 g_return_if_fail(playlist != NULL); | |
687 g_return_if_fail(filename != NULL); | |
688 | |
3635 | 689 if (tuple != NULL) { |
690 nsubtunes = tuple->nsubtunes; | |
3784 | 691 if (nsubtunes > 0) { |
3778
b4fe7d2a0d0d
Use a more describing variable name.
Matti Hamalainen <ccr@tnsp.org>
parents:
3733
diff
changeset
|
692 parent_tuple = tuple; |
3784 | 693 subtune = 1; |
694 } | |
3782
a3fc112b10f1
Fix insertion into playlist for plugins that _don't_ have subtunes. Sorry
Matti Hamalainen <ccr@tnsp.org>
parents:
3780
diff
changeset
|
695 } |
a3fc112b10f1
Fix insertion into playlist for plugins that _don't_ have subtunes. Sorry
Matti Hamalainen <ccr@tnsp.org>
parents:
3780
diff
changeset
|
696 |
a3fc112b10f1
Fix insertion into playlist for plugins that _don't_ have subtunes. Sorry
Matti Hamalainen <ccr@tnsp.org>
parents:
3780
diff
changeset
|
697 for (; add_flag && subtune <= nsubtunes; subtune++) { |
3550
6b0be1d088e6
- subtune handling is now done in playlist core, using tuple fields subsong-id and subsong-num (requires subtune-able plugins to be updated)
Giacomo Lozito <james@develia.org>
parents:
3512
diff
changeset
|
698 gchar *filename_entry; |
3635 | 699 |
700 if (nsubtunes > 0) { | |
3640
d5309028af21
Simplify adding of all sub-tunes.
Matti Hamalainen <ccr@tnsp.org>
parents:
3638
diff
changeset
|
701 filename_entry = g_strdup_printf("%s?%d", filename, |
3782
a3fc112b10f1
Fix insertion into playlist for plugins that _don't_ have subtunes. Sorry
Matti Hamalainen <ccr@tnsp.org>
parents:
3780
diff
changeset
|
702 parent_tuple->subtunes ? parent_tuple->subtunes[subtune - 1] : subtune); |
3640
d5309028af21
Simplify adding of all sub-tunes.
Matti Hamalainen <ccr@tnsp.org>
parents:
3638
diff
changeset
|
703 |
3635 | 704 /* We're dealing with subtune, let's ask again tuple information |
705 * to plugin, by passing the ?subtune suffix; this way we get | |
706 * specific subtune information in the tuple, if available. | |
707 */ | |
3550
6b0be1d088e6
- subtune handling is now done in playlist core, using tuple fields subsong-id and subsong-num (requires subtune-able plugins to be updated)
Giacomo Lozito <james@develia.org>
parents:
3512
diff
changeset
|
708 tuple = dec->get_song_tuple(filename_entry); |
3635 | 709 } else |
3550
6b0be1d088e6
- subtune handling is now done in playlist core, using tuple fields subsong-id and subsong-num (requires subtune-able plugins to be updated)
Giacomo Lozito <james@develia.org>
parents:
3512
diff
changeset
|
710 filename_entry = g_strdup(filename); |
3583 | 711 |
712 | |
3550
6b0be1d088e6
- subtune handling is now done in playlist core, using tuple fields subsong-id and subsong-num (requires subtune-able plugins to be updated)
Giacomo Lozito <james@develia.org>
parents:
3512
diff
changeset
|
713 entry = playlist_entry_new(filename_entry, |
6b0be1d088e6
- subtune handling is now done in playlist core, using tuple fields subsong-id and subsong-num (requires subtune-able plugins to be updated)
Giacomo Lozito <james@develia.org>
parents:
3512
diff
changeset
|
714 tuple ? tuple_get_string(tuple, FIELD_TITLE, NULL) : NULL, |
6b0be1d088e6
- subtune handling is now done in playlist core, using tuple fields subsong-id and subsong-num (requires subtune-able plugins to be updated)
Giacomo Lozito <james@develia.org>
parents:
3512
diff
changeset
|
715 tuple ? tuple_get_int(tuple, FIELD_LENGTH, NULL) : -1, dec); |
6b0be1d088e6
- subtune handling is now done in playlist core, using tuple fields subsong-id and subsong-num (requires subtune-able plugins to be updated)
Giacomo Lozito <james@develia.org>
parents:
3512
diff
changeset
|
716 g_free(filename_entry); |
6b0be1d088e6
- subtune handling is now done in playlist core, using tuple fields subsong-id and subsong-num (requires subtune-able plugins to be updated)
Giacomo Lozito <james@develia.org>
parents:
3512
diff
changeset
|
717 |
3784 | 718 PLAYLIST_LOCK(playlist); |
719 | |
3636
65b750891387
Possibly fix a lockup problem.
Matti Hamalainen <ccr@tnsp.org>
parents:
3635
diff
changeset
|
720 if (!playlist->tail) |
3550
6b0be1d088e6
- subtune handling is now done in playlist core, using tuple fields subsong-id and subsong-num (requires subtune-able plugins to be updated)
Giacomo Lozito <james@develia.org>
parents:
3512
diff
changeset
|
721 playlist->tail = g_list_last(playlist->entries); |
6b0be1d088e6
- subtune handling is now done in playlist core, using tuple fields subsong-id and subsong-num (requires subtune-able plugins to be updated)
Giacomo Lozito <james@develia.org>
parents:
3512
diff
changeset
|
722 |
3782
a3fc112b10f1
Fix insertion into playlist for plugins that _don't_ have subtunes. Sorry
Matti Hamalainen <ccr@tnsp.org>
parents:
3780
diff
changeset
|
723 if (pos == -1) { // the common case |
3550
6b0be1d088e6
- subtune handling is now done in playlist core, using tuple fields subsong-id and subsong-num (requires subtune-able plugins to be updated)
Giacomo Lozito <james@develia.org>
parents:
3512
diff
changeset
|
724 GList *element; |
6b0be1d088e6
- subtune handling is now done in playlist core, using tuple fields subsong-id and subsong-num (requires subtune-able plugins to be updated)
Giacomo Lozito <james@develia.org>
parents:
3512
diff
changeset
|
725 element = g_list_alloc(); |
6b0be1d088e6
- subtune handling is now done in playlist core, using tuple fields subsong-id and subsong-num (requires subtune-able plugins to be updated)
Giacomo Lozito <james@develia.org>
parents:
3512
diff
changeset
|
726 element->data = entry; |
6b0be1d088e6
- subtune handling is now done in playlist core, using tuple fields subsong-id and subsong-num (requires subtune-able plugins to be updated)
Giacomo Lozito <james@develia.org>
parents:
3512
diff
changeset
|
727 element->prev = playlist->tail; // NULL is allowed here. |
6b0be1d088e6
- subtune handling is now done in playlist core, using tuple fields subsong-id and subsong-num (requires subtune-able plugins to be updated)
Giacomo Lozito <james@develia.org>
parents:
3512
diff
changeset
|
728 element->next = NULL; |
6b0be1d088e6
- subtune handling is now done in playlist core, using tuple fields subsong-id and subsong-num (requires subtune-able plugins to be updated)
Giacomo Lozito <james@develia.org>
parents:
3512
diff
changeset
|
729 |
6b0be1d088e6
- subtune handling is now done in playlist core, using tuple fields subsong-id and subsong-num (requires subtune-able plugins to be updated)
Giacomo Lozito <james@develia.org>
parents:
3512
diff
changeset
|
730 if(!playlist->entries) { // this is the first element |
6b0be1d088e6
- subtune handling is now done in playlist core, using tuple fields subsong-id and subsong-num (requires subtune-able plugins to be updated)
Giacomo Lozito <james@develia.org>
parents:
3512
diff
changeset
|
731 playlist->entries = element; |
6b0be1d088e6
- subtune handling is now done in playlist core, using tuple fields subsong-id and subsong-num (requires subtune-able plugins to be updated)
Giacomo Lozito <james@develia.org>
parents:
3512
diff
changeset
|
732 playlist->tail = element; |
3635 | 733 } else { // the rests |
3636
65b750891387
Possibly fix a lockup problem.
Matti Hamalainen <ccr@tnsp.org>
parents:
3635
diff
changeset
|
734 if (playlist->tail != NULL) { |
65b750891387
Possibly fix a lockup problem.
Matti Hamalainen <ccr@tnsp.org>
parents:
3635
diff
changeset
|
735 playlist->tail->next = element; |
65b750891387
Possibly fix a lockup problem.
Matti Hamalainen <ccr@tnsp.org>
parents:
3635
diff
changeset
|
736 playlist->tail = element; |
65b750891387
Possibly fix a lockup problem.
Matti Hamalainen <ccr@tnsp.org>
parents:
3635
diff
changeset
|
737 } else |
65b750891387
Possibly fix a lockup problem.
Matti Hamalainen <ccr@tnsp.org>
parents:
3635
diff
changeset
|
738 add_flag = FALSE; |
3550
6b0be1d088e6
- subtune handling is now done in playlist core, using tuple fields subsong-id and subsong-num (requires subtune-able plugins to be updated)
Giacomo Lozito <james@develia.org>
parents:
3512
diff
changeset
|
739 } |
3782
a3fc112b10f1
Fix insertion into playlist for plugins that _don't_ have subtunes. Sorry
Matti Hamalainen <ccr@tnsp.org>
parents:
3780
diff
changeset
|
740 } else |
a3fc112b10f1
Fix insertion into playlist for plugins that _don't_ have subtunes. Sorry
Matti Hamalainen <ccr@tnsp.org>
parents:
3780
diff
changeset
|
741 playlist->entries = g_list_insert(playlist->entries, entry, pos++); |
a3fc112b10f1
Fix insertion into playlist for plugins that _don't_ have subtunes. Sorry
Matti Hamalainen <ccr@tnsp.org>
parents:
3780
diff
changeset
|
742 |
3550
6b0be1d088e6
- subtune handling is now done in playlist core, using tuple fields subsong-id and subsong-num (requires subtune-able plugins to be updated)
Giacomo Lozito <james@develia.org>
parents:
3512
diff
changeset
|
743 if (tuple != NULL) { |
6b0be1d088e6
- subtune handling is now done in playlist core, using tuple fields subsong-id and subsong-num (requires subtune-able plugins to be updated)
Giacomo Lozito <james@develia.org>
parents:
3512
diff
changeset
|
744 const gchar *formatter = tuple_get_string(tuple, FIELD_FORMATTER, NULL); |
3635 | 745 entry->title = tuple_formatter_make_title_string(tuple, |
746 formatter ? formatter : get_gentitle_format()); | |
3550
6b0be1d088e6
- subtune handling is now done in playlist core, using tuple fields subsong-id and subsong-num (requires subtune-able plugins to be updated)
Giacomo Lozito <james@develia.org>
parents:
3512
diff
changeset
|
747 entry->length = tuple_get_int(tuple, FIELD_LENGTH, NULL); |
6b0be1d088e6
- subtune handling is now done in playlist core, using tuple fields subsong-id and subsong-num (requires subtune-able plugins to be updated)
Giacomo Lozito <james@develia.org>
parents:
3512
diff
changeset
|
748 entry->tuple = tuple; |
6b0be1d088e6
- subtune handling is now done in playlist core, using tuple fields subsong-id and subsong-num (requires subtune-able plugins to be updated)
Giacomo Lozito <james@develia.org>
parents:
3512
diff
changeset
|
749 } |
3782
a3fc112b10f1
Fix insertion into playlist for plugins that _don't_ have subtunes. Sorry
Matti Hamalainen <ccr@tnsp.org>
parents:
3780
diff
changeset
|
750 |
a3fc112b10f1
Fix insertion into playlist for plugins that _don't_ have subtunes. Sorry
Matti Hamalainen <ccr@tnsp.org>
parents:
3780
diff
changeset
|
751 PLAYLIST_UNLOCK(playlist); |
2313 | 752 } |
3782
a3fc112b10f1
Fix insertion into playlist for plugins that _don't_ have subtunes. Sorry
Matti Hamalainen <ccr@tnsp.org>
parents:
3780
diff
changeset
|
753 |
3778
b4fe7d2a0d0d
Use a more describing variable name.
Matti Hamalainen <ccr@tnsp.org>
parents:
3733
diff
changeset
|
754 if (parent_tuple) |
b4fe7d2a0d0d
Use a more describing variable name.
Matti Hamalainen <ccr@tnsp.org>
parents:
3733
diff
changeset
|
755 tuple_free(parent_tuple); |
2313 | 756 |
3934
e924c9ee3958
when "Detect file formats on demand" is specified, filter unplayable files on loading by the hash table of all available extensions.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3923
diff
changeset
|
757 if (!tuple || (tuple && tuple_get_int(tuple, FIELD_MTIME, NULL) == -1)) { |
e924c9ee3958
when "Detect file formats on demand" is specified, filter unplayable files on loading by the hash table of all available extensions.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3923
diff
changeset
|
758 // kick the scanner thread when tuple == NULL or mtime = -1 (uninitialized) |
2545
610d85b8a22b
[svn] - on loading a playlist with tuple, invoke the scanner thread only if mtime is -1.
yaz
parents:
2504
diff
changeset
|
759 g_mutex_lock(mutex_scan); |
610d85b8a22b
[svn] - on loading a playlist with tuple, invoke the scanner thread only if mtime is -1.
yaz
parents:
2504
diff
changeset
|
760 playlist_get_info_scan_active = TRUE; |
610d85b8a22b
[svn] - on loading a playlist with tuple, invoke the scanner thread only if mtime is -1.
yaz
parents:
2504
diff
changeset
|
761 g_mutex_unlock(mutex_scan); |
610d85b8a22b
[svn] - on loading a playlist with tuple, invoke the scanner thread only if mtime is -1.
yaz
parents:
2504
diff
changeset
|
762 g_cond_signal(cond_scan); |
610d85b8a22b
[svn] - on loading a playlist with tuple, invoke the scanner thread only if mtime is -1.
yaz
parents:
2504
diff
changeset
|
763 } |
3923
e9fd46b0893b
- redefine playlist_incr_serial as a macro.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3922
diff
changeset
|
764 PLAYLIST_INCR_SERIAL(playlist); |
2313 | 765 } |
766 | |
767 gboolean | |
768 playlist_ins(Playlist * playlist, const gchar * filename, gint pos) | |
769 { | |
770 gchar buf[64], *p; | |
771 gint r; | |
772 VFSFile *file; | |
3127
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
773 ProbeResult *pr = NULL; |
2667
8c56926de2ad
[svn] - probe remote sources (hardcoded to http://, https://) in the background.
nenolod
parents:
2637
diff
changeset
|
774 InputPlugin *dec = NULL; |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
775 Tuple *tuple = NULL; |
2313 | 776 |
777 g_return_val_if_fail(playlist != NULL, FALSE); | |
778 g_return_val_if_fail(filename != NULL, FALSE); | |
779 | |
3959
a575c29cee05
- revive on-demand metadata retrieving. in the combination with "Detect file formats on demand", now audacious can load large directory in a few seconds.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3947
diff
changeset
|
780 /* load playlist */ |
2313 | 781 if (is_playlist_name(filename)) { |
782 playlist->loading_playlist = TRUE; | |
783 playlist_load_ins(playlist, filename, pos); | |
784 playlist->loading_playlist = FALSE; | |
785 return TRUE; | |
786 } | |
787 | |
3959
a575c29cee05
- revive on-demand metadata retrieving. in the combination with "Detect file formats on demand", now audacious can load large directory in a few seconds.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3947
diff
changeset
|
788 /* audio file or uri */ |
a575c29cee05
- revive on-demand metadata retrieving. in the combination with "Detect file formats on demand", now audacious can load large directory in a few seconds.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3947
diff
changeset
|
789 if (playlist->loading_playlist == TRUE) |
3934
e924c9ee3958
when "Detect file formats on demand" is specified, filter unplayable files on loading by the hash table of all available extensions.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3923
diff
changeset
|
790 dec = NULL; |
3959
a575c29cee05
- revive on-demand metadata retrieving. in the combination with "Detect file formats on demand", now audacious can load large directory in a few seconds.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3947
diff
changeset
|
791 |
a575c29cee05
- revive on-demand metadata retrieving. in the combination with "Detect file formats on demand", now audacious can load large directory in a few seconds.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3947
diff
changeset
|
792 /* on demand probing is on */ |
a575c29cee05
- revive on-demand metadata retrieving. in the combination with "Detect file formats on demand", now audacious can load large directory in a few seconds.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3947
diff
changeset
|
793 if (cfg.playlist_detect == TRUE) { |
a575c29cee05
- revive on-demand metadata retrieving. in the combination with "Detect file formats on demand", now audacious can load large directory in a few seconds.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3947
diff
changeset
|
794 dec = NULL; |
a575c29cee05
- revive on-demand metadata retrieving. in the combination with "Detect file formats on demand", now audacious can load large directory in a few seconds.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3947
diff
changeset
|
795 if(cfg.use_extension_probing && !filter_by_extension(filename)) |
3934
e924c9ee3958
when "Detect file formats on demand" is specified, filter unplayable files on loading by the hash table of all available extensions.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3923
diff
changeset
|
796 return FALSE; |
e924c9ee3958
when "Detect file formats on demand" is specified, filter unplayable files on loading by the hash table of all available extensions.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3923
diff
changeset
|
797 } |
3959
a575c29cee05
- revive on-demand metadata retrieving. in the combination with "Detect file formats on demand", now audacious can load large directory in a few seconds.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3947
diff
changeset
|
798 /* find decorder for non-remote uri i.e. local file */ |
2667
8c56926de2ad
[svn] - probe remote sources (hardcoded to http://, https://) in the background.
nenolod
parents:
2637
diff
changeset
|
799 else if (!str_has_prefix_nocase(filename, "http://") && |
3959
a575c29cee05
- revive on-demand metadata retrieving. in the combination with "Detect file formats on demand", now audacious can load large directory in a few seconds.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3947
diff
changeset
|
800 !str_has_prefix_nocase(filename, "https://")) { |
a575c29cee05
- revive on-demand metadata retrieving. in the combination with "Detect file formats on demand", now audacious can load large directory in a few seconds.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3947
diff
changeset
|
801 |
3127
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
802 pr = input_check_file(filename, TRUE); |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
803 |
3635 | 804 if (pr) { |
3127
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
805 dec = pr->ip; |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
806 tuple = pr->tuple; |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
807 } |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
808 g_free(pr); |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
809 } |
2313 | 810 |
3959
a575c29cee05
- revive on-demand metadata retrieving. in the combination with "Detect file formats on demand", now audacious can load large directory in a few seconds.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3947
diff
changeset
|
811 /* add filename to playlist */ |
a575c29cee05
- revive on-demand metadata retrieving. in the combination with "Detect file formats on demand", now audacious can load large directory in a few seconds.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3947
diff
changeset
|
812 if (cfg.playlist_detect == TRUE || |
a575c29cee05
- revive on-demand metadata retrieving. in the combination with "Detect file formats on demand", now audacious can load large directory in a few seconds.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3947
diff
changeset
|
813 playlist->loading_playlist == TRUE || |
3635 | 814 (playlist->loading_playlist == FALSE && dec != NULL) || |
815 (playlist->loading_playlist == FALSE && !is_playlist_name(filename) && | |
3934
e924c9ee3958
when "Detect file formats on demand" is specified, filter unplayable files on loading by the hash table of all available extensions.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3923
diff
changeset
|
816 str_has_prefix_nocase(filename, "http"))) { |
3959
a575c29cee05
- revive on-demand metadata retrieving. in the combination with "Detect file formats on demand", now audacious can load large directory in a few seconds.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3947
diff
changeset
|
817 |
3127
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
818 __playlist_ins_with_info_tuple(playlist, filename, pos, tuple, dec); |
3959
a575c29cee05
- revive on-demand metadata retrieving. in the combination with "Detect file formats on demand", now audacious can load large directory in a few seconds.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3947
diff
changeset
|
819 |
2545
610d85b8a22b
[svn] - on loading a playlist with tuple, invoke the scanner thread only if mtime is -1.
yaz
parents:
2504
diff
changeset
|
820 playlist_generate_shuffle_list(playlist); |
610d85b8a22b
[svn] - on loading a playlist with tuple, invoke the scanner thread only if mtime is -1.
yaz
parents:
2504
diff
changeset
|
821 playlistwin_update_list(playlist); |
3621
2d6106656276
Notify playlist manager of more changes
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3583
diff
changeset
|
822 playlist_manager_update(); |
2313 | 823 return TRUE; |
824 } | |
825 | |
826 /* Some files (typically produced by some cgi-scripts) don't have | |
827 * the correct extension. Try to recognize these files by looking | |
828 * at their content. We only check for http entries since it does | |
829 * not make sense to have file entries in a playlist fetched from | |
830 * the net. */ | |
831 | |
832 /* Some strange people put fifo's with the .mp3 extension, so we | |
833 * need to make sure it's a real file (otherwise fread() may block | |
834 * and stall the entire program) */ | |
835 | |
836 /* FIXME: bah, FIFOs actually pass this regular file test */ | |
837 if (!vfs_file_test(filename, G_FILE_TEST_IS_REGULAR)) | |
838 return FALSE; | |
839 | |
3635 | 840 if ((file = vfs_fopen(filename, "rb")) == NULL) |
2313 | 841 return FALSE; |
842 | |
843 r = vfs_fread(buf, 1, sizeof(buf), file); | |
844 vfs_fclose(file); | |
845 | |
846 for (p = buf; r-- > 0 && (*p == '\r' || *p == '\n'); p++); | |
847 | |
848 if (r > 5 && str_has_prefix_nocase(p, "http:")) { | |
849 playlist_load_ins(playlist, filename, pos); | |
850 return TRUE; | |
851 } | |
852 | |
2493
b7f48f00a342
[svn] - patch from Mark Glines to ad https:// URI support to playlists.
nenolod
parents:
2489
diff
changeset
|
853 if (r > 6 && str_has_prefix_nocase(p, "https:")) { |
b7f48f00a342
[svn] - patch from Mark Glines to ad https:// URI support to playlists.
nenolod
parents:
2489
diff
changeset
|
854 playlist_load_ins(playlist, filename, pos); |
b7f48f00a342
[svn] - patch from Mark Glines to ad https:// URI support to playlists.
nenolod
parents:
2489
diff
changeset
|
855 return TRUE; |
b7f48f00a342
[svn] - patch from Mark Glines to ad https:// URI support to playlists.
nenolod
parents:
2489
diff
changeset
|
856 } |
b7f48f00a342
[svn] - patch from Mark Glines to ad https:// URI support to playlists.
nenolod
parents:
2489
diff
changeset
|
857 |
2313 | 858 return FALSE; |
859 } | |
860 | |
861 /* FIXME: The next few functions are specific to Unix | |
862 * filesystems. Either abstract it away, or don't even bother checking | |
863 * at such low level */ | |
864 | |
865 typedef struct { | |
866 dev_t dev; | |
867 ino_t ino; | |
868 } DeviceInode; | |
869 | |
870 static DeviceInode * | |
871 devino_new(dev_t device, | |
872 ino_t inode) | |
873 { | |
874 DeviceInode *devino = g_new0(DeviceInode, 1); | |
875 | |
3635 | 876 if (devino) { |
2313 | 877 devino->dev = device; |
878 devino->ino = inode; | |
879 } | |
880 | |
881 return devino; | |
882 } | |
883 | |
884 static guint | |
885 devino_hash(gconstpointer key) | |
886 { | |
887 const DeviceInode *d = key; | |
888 return d->ino; | |
889 } | |
890 | |
891 static gint | |
892 devino_compare(gconstpointer a, | |
893 gconstpointer b) | |
894 { | |
895 const DeviceInode *da = a, *db = b; | |
896 return (da->dev == db->dev && da->ino == db->ino); | |
897 } | |
898 | |
899 static gboolean | |
900 devino_destroy(gpointer key, | |
901 gpointer value, | |
902 gpointer data) | |
903 { | |
904 g_free(key); | |
905 return TRUE; | |
906 } | |
907 | |
908 static gboolean | |
909 file_is_hidden(const gchar * filename) | |
910 { | |
911 g_return_val_if_fail(filename != NULL, FALSE); | |
2570 | 912 return (g_basename(filename)[0] == '.'); |
2313 | 913 } |
914 | |
915 static GList * | |
916 playlist_dir_find_files(const gchar * path, | |
917 gboolean background, | |
918 GHashTable * htab) | |
919 { | |
920 GDir *dir; | |
921 GList *list = NULL, *ilist; | |
922 const gchar *dir_entry; | |
3127
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
923 ProbeResult *pr = NULL; |
2313 | 924 |
925 struct stat statbuf; | |
926 DeviceInode *devino; | |
927 | |
3079
72766f2e8713
recursive directory scan for add file dialog works again
Giacomo Lozito <james@develia.org>
parents:
2994
diff
changeset
|
928 if (!path) |
72766f2e8713
recursive directory scan for add file dialog works again
Giacomo Lozito <james@develia.org>
parents:
2994
diff
changeset
|
929 return NULL; |
72766f2e8713
recursive directory scan for add file dialog works again
Giacomo Lozito <james@develia.org>
parents:
2994
diff
changeset
|
930 |
2993
83727fbfec54
Use vfs_file_test() where appropriate.
William Pitcock <nenolod@atheme-project.org>
parents:
2978
diff
changeset
|
931 if (!vfs_file_test(path, G_FILE_TEST_IS_DIR)) |
2313 | 932 return NULL; |
933 | |
934 stat(path, &statbuf); | |
935 devino = devino_new(statbuf.st_dev, statbuf.st_ino); | |
936 | |
937 if (g_hash_table_lookup(htab, devino)) { | |
938 g_free(devino); | |
939 return NULL; | |
940 } | |
941 | |
942 g_hash_table_insert(htab, devino, GINT_TO_POINTER(1)); | |
943 | |
2994
750c530b1bf5
playlist_dir_find_files(): Return list of URIs.
William Pitcock <nenolod@atheme-project.org>
parents:
2993
diff
changeset
|
944 /* XXX: what the hell is this for? --nenolod */ |
2313 | 945 if ((ilist = input_scan_dir(path))) { |
946 GList *node; | |
947 for (node = ilist; node; node = g_list_next(node)) { | |
948 gchar *name = g_build_filename(path, node->data, NULL); | |
949 list = g_list_prepend(list, name); | |
950 g_free(node->data); | |
951 } | |
952 g_list_free(ilist); | |
953 return list; | |
954 } | |
955 | |
3079
72766f2e8713
recursive directory scan for add file dialog works again
Giacomo Lozito <james@develia.org>
parents:
2994
diff
changeset
|
956 /* g_dir_open does not handle URI, so path should come here not-urified. --giacomo */ |
2313 | 957 if (!(dir = g_dir_open(path, 0, NULL))) |
958 return NULL; | |
959 | |
960 while ((dir_entry = g_dir_read_name(dir))) { | |
2994
750c530b1bf5
playlist_dir_find_files(): Return list of URIs.
William Pitcock <nenolod@atheme-project.org>
parents:
2993
diff
changeset
|
961 gchar *filename, *tmp; |
2313 | 962 |
963 if (file_is_hidden(dir_entry)) | |
964 continue; | |
965 | |
2994
750c530b1bf5
playlist_dir_find_files(): Return list of URIs.
William Pitcock <nenolod@atheme-project.org>
parents:
2993
diff
changeset
|
966 tmp = g_build_filename(path, dir_entry, NULL); |
750c530b1bf5
playlist_dir_find_files(): Return list of URIs.
William Pitcock <nenolod@atheme-project.org>
parents:
2993
diff
changeset
|
967 filename = g_filename_to_uri(tmp, NULL, NULL); |
750c530b1bf5
playlist_dir_find_files(): Return list of URIs.
William Pitcock <nenolod@atheme-project.org>
parents:
2993
diff
changeset
|
968 g_free(tmp); |
2313 | 969 |
3959
a575c29cee05
- revive on-demand metadata retrieving. in the combination with "Detect file formats on demand", now audacious can load large directory in a few seconds.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3947
diff
changeset
|
970 if (vfs_file_test(filename, G_FILE_TEST_IS_DIR)) { /* directory */ |
2313 | 971 GList *sub; |
3079
72766f2e8713
recursive directory scan for add file dialog works again
Giacomo Lozito <james@develia.org>
parents:
2994
diff
changeset
|
972 gchar *dirfilename = g_filename_from_uri(filename, NULL, NULL); |
72766f2e8713
recursive directory scan for add file dialog works again
Giacomo Lozito <james@develia.org>
parents:
2994
diff
changeset
|
973 sub = playlist_dir_find_files(dirfilename, background, htab); |
72766f2e8713
recursive directory scan for add file dialog works again
Giacomo Lozito <james@develia.org>
parents:
2994
diff
changeset
|
974 g_free(dirfilename); |
2313 | 975 g_free(filename); |
976 list = g_list_concat(list, sub); | |
977 } | |
3959
a575c29cee05
- revive on-demand metadata retrieving. in the combination with "Detect file formats on demand", now audacious can load large directory in a few seconds.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3947
diff
changeset
|
978 else if (cfg.playlist_detect) { /* local file, no probing */ |
a575c29cee05
- revive on-demand metadata retrieving. in the combination with "Detect file formats on demand", now audacious can load large directory in a few seconds.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3947
diff
changeset
|
979 if(cfg.use_extension_probing) { |
a575c29cee05
- revive on-demand metadata retrieving. in the combination with "Detect file formats on demand", now audacious can load large directory in a few seconds.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3947
diff
changeset
|
980 if(filter_by_extension(filename)) |
a575c29cee05
- revive on-demand metadata retrieving. in the combination with "Detect file formats on demand", now audacious can load large directory in a few seconds.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3947
diff
changeset
|
981 list = g_list_prepend(list, filename); |
a575c29cee05
- revive on-demand metadata retrieving. in the combination with "Detect file formats on demand", now audacious can load large directory in a few seconds.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3947
diff
changeset
|
982 } |
a575c29cee05
- revive on-demand metadata retrieving. in the combination with "Detect file formats on demand", now audacious can load large directory in a few seconds.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3947
diff
changeset
|
983 else |
3934
e924c9ee3958
when "Detect file formats on demand" is specified, filter unplayable files on loading by the hash table of all available extensions.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3923
diff
changeset
|
984 list = g_list_prepend(list, filename); |
e924c9ee3958
when "Detect file formats on demand" is specified, filter unplayable files on loading by the hash table of all available extensions.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3923
diff
changeset
|
985 } |
3127
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
986 else if ((pr = input_check_file(filename, TRUE)) != NULL) |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
987 { |
2313 | 988 list = g_list_prepend(list, filename); |
3127
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
989 |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
990 g_free(pr); |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
991 pr = NULL; |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
992 } |
2313 | 993 else |
994 g_free(filename); | |
995 | |
996 while (background && gtk_events_pending()) | |
997 gtk_main_iteration(); | |
998 } | |
999 g_dir_close(dir); | |
1000 | |
1001 return list; | |
1002 } | |
1003 | |
1004 gboolean | |
1005 playlist_add(Playlist * playlist, const gchar * filename) | |
1006 { | |
1007 return playlist_ins(playlist, filename, -1); | |
1008 } | |
1009 | |
1010 guint | |
1011 playlist_add_dir(Playlist * playlist, const gchar * directory) | |
1012 { | |
1013 return playlist_ins_dir(playlist, directory, -1, TRUE); | |
1014 } | |
1015 | |
1016 guint | |
1017 playlist_add_url(Playlist * playlist, const gchar * url) | |
1018 { | |
3337
99f34db2c3fc
- fix a bug that playlist_ins_url() always returns 1 even if no url has been added. now playlist_ins_url() returns number of new entries which actually added to the playlist.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3334
diff
changeset
|
1019 guint entries; |
99f34db2c3fc
- fix a bug that playlist_ins_url() always returns 1 even if no url has been added. now playlist_ins_url() returns number of new entries which actually added to the playlist.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3334
diff
changeset
|
1020 entries = playlist_ins_url(playlist, url, -1); |
99f34db2c3fc
- fix a bug that playlist_ins_url() always returns 1 even if no url has been added. now playlist_ins_url() returns number of new entries which actually added to the playlist.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3334
diff
changeset
|
1021 return entries; |
2313 | 1022 } |
1023 | |
1024 guint | |
1025 playlist_ins_dir(Playlist * playlist, const gchar * path, | |
1026 gint pos, | |
1027 gboolean background) | |
1028 { | |
1029 guint entries = 0; | |
1030 GList *list, *node; | |
1031 GHashTable *htab; | |
2978
f4971c7d6384
Remove inlined urldecoding functions and use g_filename_from_uri() instead where appropriate.
William Pitcock <nenolod@atheme-project.org>
parents:
2976
diff
changeset
|
1032 gchar *path2 = g_filename_from_uri(path, NULL, NULL); |
2313 | 1033 |
2580
48288757d7c7
[svn] - fix a regression introduced by the DnD fix.
nenolod
parents:
2579
diff
changeset
|
1034 if (path2 == NULL) |
48288757d7c7
[svn] - fix a regression introduced by the DnD fix.
nenolod
parents:
2579
diff
changeset
|
1035 path2 = g_strdup(path); |
48288757d7c7
[svn] - fix a regression introduced by the DnD fix.
nenolod
parents:
2579
diff
changeset
|
1036 |
2313 | 1037 htab = g_hash_table_new(devino_hash, devino_compare); |
1038 | |
2579 | 1039 list = playlist_dir_find_files(path2, background, htab); |
2313 | 1040 list = g_list_sort(list, (GCompareFunc) path_compare); |
1041 | |
1042 g_hash_table_foreach_remove(htab, devino_destroy, NULL); | |
1043 | |
1044 for (node = list; node; node = g_list_next(node)) { | |
3129
f416657ee9b7
Call playlist_ins() instead of __playlist_ins().
William Pitcock <nenolod@atheme-project.org>
parents:
3128
diff
changeset
|
1045 playlist_ins(playlist, node->data, pos); |
2313 | 1046 g_free(node->data); |
1047 entries++; | |
1048 if (pos >= 0) | |
1049 pos++; | |
1050 } | |
1051 | |
1052 g_list_free(list); | |
2579 | 1053 g_free(path2); |
2313 | 1054 |
1055 playlist_recalc_total_time(playlist); | |
1056 playlist_generate_shuffle_list(playlist); | |
1057 playlistwin_update_list(playlist); | |
1058 playlist_manager_update(); | |
1059 return entries; | |
1060 } | |
1061 | |
1062 guint | |
1063 playlist_ins_url(Playlist * playlist, const gchar * string, | |
1064 gint pos) | |
1065 { | |
1066 gchar *tmp; | |
3337
99f34db2c3fc
- fix a bug that playlist_ins_url() always returns 1 even if no url has been added. now playlist_ins_url() returns number of new entries which actually added to the playlist.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3334
diff
changeset
|
1067 gint entries = 0; |
2313 | 1068 gchar *decoded = NULL; |
1069 | |
1070 g_return_val_if_fail(playlist != NULL, 0); | |
1071 g_return_val_if_fail(string != NULL, 0); | |
1072 | |
1073 while (*string) { | |
1074 GList *node; | |
3337
99f34db2c3fc
- fix a bug that playlist_ins_url() always returns 1 even if no url has been added. now playlist_ins_url() returns number of new entries which actually added to the playlist.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3334
diff
changeset
|
1075 guint i = 0; |
2313 | 1076 tmp = strchr(string, '\n'); |
1077 if (tmp) { | |
1078 if (*(tmp - 1) == '\r') | |
1079 *(tmp - 1) = '\0'; | |
1080 *tmp = '\0'; | |
1081 } | |
1082 | |
1083 decoded = g_strdup(string); | |
1084 | |
2575 | 1085 if (vfs_file_test(decoded, G_FILE_TEST_IS_DIR)) { |
2313 | 1086 i = playlist_ins_dir(playlist, decoded, pos, FALSE); |
1087 } | |
1088 else { | |
1089 if (is_playlist_name(decoded)) { | |
1090 i = playlist_load_ins(playlist, decoded, pos); | |
1091 } | |
3337
99f34db2c3fc
- fix a bug that playlist_ins_url() always returns 1 even if no url has been added. now playlist_ins_url() returns number of new entries which actually added to the playlist.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3334
diff
changeset
|
1092 else if (playlist_ins(playlist, decoded, pos)) { |
2313 | 1093 i = 1; |
1094 } | |
1095 } | |
1096 | |
1097 g_free(decoded); | |
1098 | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
1099 PLAYLIST_LOCK(playlist); |
2313 | 1100 node = g_list_nth(playlist->entries, pos); |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
1101 PLAYLIST_UNLOCK(playlist); |
2313 | 1102 |
1103 entries += i; | |
1104 | |
1105 if (pos >= 0) | |
1106 pos += i; | |
1107 if (!tmp) | |
1108 break; | |
1109 | |
1110 string = tmp + 1; | |
1111 } | |
1112 | |
1113 playlist_recalc_total_time(playlist); | |
3923
e9fd46b0893b
- redefine playlist_incr_serial as a macro.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3922
diff
changeset
|
1114 PLAYLIST_INCR_SERIAL(playlist); //probably necessary because there is no underlying __playlist_ins --yaz |
2313 | 1115 playlist_generate_shuffle_list(playlist); |
1116 playlistwin_update_list(playlist); | |
1117 | |
1118 playlist_manager_update(); | |
1119 | |
1120 return entries; | |
1121 } | |
1122 | |
1123 void | |
1124 playlist_set_info_old_abi(const gchar * title, gint length, gint rate, | |
1125 gint freq, gint nch) | |
1126 { | |
1127 Playlist *playlist = playlist_get_active(); | |
3159
a2d552ea48f0
Use message passing to make sure the UI is updated in the main thread.
William Pitcock <nenolod@atheme-project.org>
parents:
3132
diff
changeset
|
1128 PlaylistEventInfoChange *msg; |
3165
8775dfc57ead
Remove mainwin_set_info_text() craq. Still some work to do.
William Pitcock <nenolod@atheme-project.org>
parents:
3159
diff
changeset
|
1129 gchar *text; |
2313 | 1130 |
3197
5dd8bc77a590
now "hide seekbar on streaming" uses message passing.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3165
diff
changeset
|
1131 if(length == -1) { |
5dd8bc77a590
now "hide seekbar on streaming" uses message passing.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3165
diff
changeset
|
1132 event_queue("hide seekbar", (gpointer)0xdeadbeef); // event_queue hates NULL --yaz |
5dd8bc77a590
now "hide seekbar on streaming" uses message passing.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3165
diff
changeset
|
1133 } |
5dd8bc77a590
now "hide seekbar on streaming" uses message passing.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3165
diff
changeset
|
1134 |
2313 | 1135 g_return_if_fail(playlist != NULL); |
1136 | |
1137 if (playlist->position) { | |
1138 g_free(playlist->position->title); | |
1139 playlist->position->title = g_strdup(title); | |
1140 playlist->position->length = length; | |
2488
c5075a79f1aa
[svn] make input->set_info overwrite tuple->track_name. it allows input
yaz
parents:
2480
diff
changeset
|
1141 |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
1142 // overwrite tuple::title, mainly for streaming. it may incur side effects. --yaz |
3635 | 1143 if (playlist->position->tuple && tuple_get_int(playlist->position->tuple, FIELD_LENGTH, NULL) == -1){ |
3490
602ec8c40d0d
Fixed to comply with the Tuple API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
3401
diff
changeset
|
1144 tuple_disassociate(playlist->position->tuple, FIELD_TITLE, NULL); |
602ec8c40d0d
Fixed to comply with the Tuple API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
3401
diff
changeset
|
1145 tuple_associate_string(playlist->position->tuple, FIELD_TITLE, NULL, title); |
2488
c5075a79f1aa
[svn] make input->set_info overwrite tuple->track_name. it allows input
yaz
parents:
2480
diff
changeset
|
1146 } |
2313 | 1147 } |
1148 | |
3922
23e5b148ae7c
to get rid of annoying side effects, an independent function for playlist serial increment has been provided.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3921
diff
changeset
|
1149 playlist_recalc_total_time(playlist); |
2313 | 1150 |
3159
a2d552ea48f0
Use message passing to make sure the UI is updated in the main thread.
William Pitcock <nenolod@atheme-project.org>
parents:
3132
diff
changeset
|
1151 /* broadcast a PlaylistEventInfoChange message. */ |
a2d552ea48f0
Use message passing to make sure the UI is updated in the main thread.
William Pitcock <nenolod@atheme-project.org>
parents:
3132
diff
changeset
|
1152 msg = g_new0(PlaylistEventInfoChange, 1); |
a2d552ea48f0
Use message passing to make sure the UI is updated in the main thread.
William Pitcock <nenolod@atheme-project.org>
parents:
3132
diff
changeset
|
1153 msg->bitrate = rate; |
a2d552ea48f0
Use message passing to make sure the UI is updated in the main thread.
William Pitcock <nenolod@atheme-project.org>
parents:
3132
diff
changeset
|
1154 msg->samplerate = freq; |
a2d552ea48f0
Use message passing to make sure the UI is updated in the main thread.
William Pitcock <nenolod@atheme-project.org>
parents:
3132
diff
changeset
|
1155 msg->channels = nch; |
a2d552ea48f0
Use message passing to make sure the UI is updated in the main thread.
William Pitcock <nenolod@atheme-project.org>
parents:
3132
diff
changeset
|
1156 |
a2d552ea48f0
Use message passing to make sure the UI is updated in the main thread.
William Pitcock <nenolod@atheme-project.org>
parents:
3132
diff
changeset
|
1157 event_queue("playlist info change", msg); |
2460 | 1158 |
3165
8775dfc57ead
Remove mainwin_set_info_text() craq. Still some work to do.
William Pitcock <nenolod@atheme-project.org>
parents:
3159
diff
changeset
|
1159 text = playlist_get_info_text(playlist); |
8775dfc57ead
Remove mainwin_set_info_text() craq. Still some work to do.
William Pitcock <nenolod@atheme-project.org>
parents:
3159
diff
changeset
|
1160 event_queue("title change", text); |
8775dfc57ead
Remove mainwin_set_info_text() craq. Still some work to do.
William Pitcock <nenolod@atheme-project.org>
parents:
3159
diff
changeset
|
1161 |
2460 | 1162 if ( playlist->position ) |
1163 hook_call( "playlist set info" , playlist->position ); | |
2313 | 1164 } |
1165 | |
1166 void | |
1167 playlist_set_info(Playlist * playlist, const gchar * title, gint length, gint rate, | |
1168 gint freq, gint nch) | |
1169 { | |
1170 g_return_if_fail(playlist != NULL); | |
1171 | |
1172 if (playlist->position) { | |
1173 g_free(playlist->position->title); | |
1174 playlist->position->title = g_strdup(title); | |
1175 playlist->position->length = length; | |
1176 } | |
1177 | |
1178 playlist_recalc_total_time(playlist); | |
3923
e9fd46b0893b
- redefine playlist_incr_serial as a macro.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3922
diff
changeset
|
1179 PLAYLIST_INCR_SERIAL(playlist); //tentative --yaz |
2313 | 1180 |
1181 mainwin_set_song_info(rate, freq, nch); | |
2460 | 1182 |
3635 | 1183 if (playlist->position) |
2460 | 1184 hook_call( "playlist set info" , playlist->position ); |
2313 | 1185 } |
1186 | |
1187 void | |
1188 playlist_check_pos_current(Playlist *playlist) | |
1189 { | |
1190 gint pos, row, bottom; | |
1191 | |
1192 if (!playlist) | |
1193 return; | |
1194 | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
1195 PLAYLIST_LOCK(playlist); |
2313 | 1196 if (!playlist->position || !playlistwin_list) { |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
1197 PLAYLIST_UNLOCK(playlist); |
2313 | 1198 return; |
1199 } | |
1200 | |
1201 pos = g_list_index(playlist->entries, playlist->position); | |
1202 | |
1203 if (playlistwin_item_visible(pos)) { | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
1204 PLAYLIST_UNLOCK(playlist); |
2313 | 1205 return; |
1206 } | |
1207 | |
2671
e9b379528fbc
[svn] - playlist_get_length_nolock() -> playlist_get_length(), no need for
nenolod
parents:
2670
diff
changeset
|
1208 bottom = MAX(0, playlist_get_length(playlist) - |
3217 | 1209 UI_SKINNED_PLAYLIST(playlistwin_list)->num_visible); |
1210 row = CLAMP(pos - UI_SKINNED_PLAYLIST(playlistwin_list)->num_visible / 2, 0, bottom); | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
1211 PLAYLIST_UNLOCK(playlist); |
2313 | 1212 playlistwin_set_toprow(row); |
1213 g_cond_signal(cond_scan); | |
1214 } | |
1215 | |
1216 void | |
1217 playlist_next(Playlist *playlist) | |
1218 { | |
1219 GList *plist_pos_list; | |
1220 gboolean restart_playing = FALSE; | |
3635 | 1221 |
2480
bb2f191895ce
[svn] - fixed crash when skipping to next song with an empty playlist
marvin
parents:
2460
diff
changeset
|
1222 if (!playlist_get_length(playlist)) |
2313 | 1223 return; |
1224 | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
1225 PLAYLIST_LOCK(playlist); |
2313 | 1226 |
3635 | 1227 if ((playlist_position_before_jump != NULL) && playlist->queue == NULL) { |
2313 | 1228 playlist->position = playlist_position_before_jump; |
1229 playlist_position_before_jump = NULL; | |
1230 } | |
1231 | |
1232 plist_pos_list = find_playlist_position_list(playlist); | |
1233 | |
1234 if (!cfg.repeat && !g_list_next(plist_pos_list) && playlist->queue == NULL) { | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
1235 PLAYLIST_UNLOCK(playlist); |
2313 | 1236 return; |
1237 } | |
1238 | |
1239 if (playback_get_playing()) { | |
1240 /* We need to stop before changing playlist_position */ | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
1241 PLAYLIST_UNLOCK(playlist); |
2313 | 1242 ip_data.stop = TRUE; |
1243 playback_stop(); | |
1244 ip_data.stop = FALSE; | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
1245 PLAYLIST_LOCK(playlist); |
2313 | 1246 restart_playing = TRUE; |
1247 } | |
1248 | |
1249 plist_pos_list = find_playlist_position_list(playlist); | |
1250 if (playlist->queue != NULL) | |
1251 play_queued(playlist); | |
1252 else if (g_list_next(plist_pos_list)) | |
1253 playlist->position = g_list_next(plist_pos_list)->data; | |
1254 else if (cfg.repeat) { | |
1255 playlist->position = NULL; | |
1256 playlist_generate_shuffle_list_nolock(playlist); | |
1257 if (cfg.shuffle) | |
1258 playlist->position = playlist->shuffle->data; | |
1259 else | |
1260 playlist->position = playlist->entries->data; | |
1261 } | |
3635 | 1262 |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
1263 PLAYLIST_UNLOCK(playlist); |
3635 | 1264 |
2313 | 1265 playlist_check_pos_current(playlist); |
1266 | |
3348
2a081105513c
-Set the track "title" in metadata instead of "name"
Ben Tucker <ben.tucker@gmail.com>
parents:
3346
diff
changeset
|
1267 if (restart_playing) |
2313 | 1268 playback_initiate(); |
3246
2127f7108033
- fixed some cases where the playlist wasn't redrawn
mf0102 <0102@gmx.at>
parents:
3217
diff
changeset
|
1269 |
2127f7108033
- fixed some cases where the playlist wasn't redrawn
mf0102 <0102@gmx.at>
parents:
3217
diff
changeset
|
1270 playlistwin_update_list(playlist); |
3621
2d6106656276
Notify playlist manager of more changes
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3583
diff
changeset
|
1271 playlist_manager_update(); |
2313 | 1272 } |
1273 | |
1274 void | |
1275 playlist_prev(Playlist *playlist) | |
1276 { | |
1277 GList *plist_pos_list; | |
1278 gboolean restart_playing = FALSE; | |
1279 | |
2480
bb2f191895ce
[svn] - fixed crash when skipping to next song with an empty playlist
marvin
parents:
2460
diff
changeset
|
1280 if (!playlist_get_length(playlist)) |
2313 | 1281 return; |
1282 | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
1283 PLAYLIST_LOCK(playlist); |
2313 | 1284 |
3635 | 1285 if ((playlist_position_before_jump != NULL) && playlist->queue == NULL) { |
2313 | 1286 playlist->position = playlist_position_before_jump; |
1287 playlist_position_before_jump = NULL; | |
1288 } | |
1289 | |
1290 plist_pos_list = find_playlist_position_list(playlist); | |
1291 | |
1292 if (!cfg.repeat && !g_list_previous(plist_pos_list)) { | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
1293 PLAYLIST_UNLOCK(playlist); |
2313 | 1294 return; |
1295 } | |
1296 | |
1297 if (playback_get_playing()) { | |
1298 /* We need to stop before changing playlist_position */ | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
1299 PLAYLIST_UNLOCK(playlist); |
2313 | 1300 ip_data.stop = TRUE; |
1301 playback_stop(); | |
1302 ip_data.stop = FALSE; | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
1303 PLAYLIST_LOCK(playlist); |
2313 | 1304 restart_playing = TRUE; |
1305 } | |
1306 | |
1307 plist_pos_list = find_playlist_position_list(playlist); | |
1308 if (g_list_previous(plist_pos_list)) { | |
1309 playlist->position = g_list_previous(plist_pos_list)->data; | |
1310 } | |
1311 else if (cfg.repeat) { | |
1312 GList *node; | |
1313 playlist->position = NULL; | |
1314 playlist_generate_shuffle_list_nolock(playlist); | |
1315 if (cfg.shuffle) | |
1316 node = g_list_last(playlist->shuffle); | |
1317 else | |
1318 node = g_list_last(playlist->entries); | |
1319 if (node) | |
1320 playlist->position = node->data; | |
1321 } | |
1322 | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
1323 PLAYLIST_UNLOCK(playlist); |
2313 | 1324 |
1325 playlist_check_pos_current(playlist); | |
1326 | |
3348
2a081105513c
-Set the track "title" in metadata instead of "name"
Ben Tucker <ben.tucker@gmail.com>
parents:
3346
diff
changeset
|
1327 if (restart_playing) |
2313 | 1328 playback_initiate(); |
3348
2a081105513c
-Set the track "title" in metadata instead of "name"
Ben Tucker <ben.tucker@gmail.com>
parents:
3346
diff
changeset
|
1329 else |
2313 | 1330 playlistwin_update_list(playlist); |
3621
2d6106656276
Notify playlist manager of more changes
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3583
diff
changeset
|
1331 |
2d6106656276
Notify playlist manager of more changes
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3583
diff
changeset
|
1332 playlist_manager_update(); |
2313 | 1333 } |
1334 | |
1335 void | |
1336 playlist_queue(Playlist *playlist) | |
1337 { | |
1338 GList *list = playlist_get_selected(playlist); | |
1339 GList *it = list; | |
1340 | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
1341 PLAYLIST_LOCK(playlist); |
2313 | 1342 |
3635 | 1343 if ((cfg.shuffle) && (playlist_position_before_jump == NULL)) { |
2313 | 1344 /* Shuffling and this is our first manual jump. */ |
1345 playlist_position_before_jump = playlist->position; | |
1346 } | |
1347 | |
1348 while (it) { | |
1349 GList *next = g_list_next(it); | |
1350 GList *tmp; | |
1351 | |
1352 /* XXX: WTF? --nenolod */ | |
1353 it->data = g_list_nth_data(playlist->entries, GPOINTER_TO_INT(it->data)); | |
1354 if ((tmp = g_list_find(playlist->queue, it->data))) { | |
1355 playlist->queue = g_list_remove_link(playlist->queue, tmp); | |
1356 g_list_free_1(tmp); | |
1357 list = g_list_remove_link(list, it); | |
1358 g_list_free_1(it); | |
1359 } | |
1360 | |
1361 it = next; | |
1362 } | |
1363 | |
1364 playlist->queue = g_list_concat(playlist->queue, list); | |
1365 | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
1366 PLAYLIST_UNLOCK(playlist); |
2313 | 1367 |
1368 playlist_recalc_total_time(playlist); | |
1369 playlistwin_update_list(playlist); | |
1370 } | |
1371 | |
1372 void | |
1373 playlist_queue_position(Playlist *playlist, guint pos) | |
1374 { | |
1375 GList *tmp; | |
1376 PlaylistEntry *entry; | |
1377 | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
1378 PLAYLIST_LOCK(playlist); |
2313 | 1379 |
1380 if ((cfg.shuffle) && (playlist_position_before_jump == NULL)) | |
1381 { | |
1382 /* Shuffling and this is our first manual jump. */ | |
1383 playlist_position_before_jump = playlist->position; | |
1384 } | |
1385 | |
1386 entry = g_list_nth_data(playlist->entries, pos); | |
1387 if ((tmp = g_list_find(playlist->queue, entry))) { | |
1388 playlist->queue = g_list_remove_link(playlist->queue, tmp); | |
1389 g_list_free_1(tmp); | |
1390 } | |
1391 else | |
1392 playlist->queue = g_list_append(playlist->queue, entry); | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
1393 PLAYLIST_UNLOCK(playlist); |
2313 | 1394 |
1395 playlist_recalc_total_time(playlist); | |
1396 playlistwin_update_list(playlist); | |
1397 } | |
1398 | |
1399 gboolean | |
1400 playlist_is_position_queued(Playlist *playlist, guint pos) | |
1401 { | |
1402 PlaylistEntry *entry; | |
3867
e48f2f4c116d
- many remained audacious remote functions have been implemented.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3863
diff
changeset
|
1403 GList *tmp = NULL; |
2313 | 1404 |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
1405 PLAYLIST_LOCK(playlist); |
2313 | 1406 entry = g_list_nth_data(playlist->entries, pos); |
1407 tmp = g_list_find(playlist->queue, entry); | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
1408 PLAYLIST_UNLOCK(playlist); |
2313 | 1409 |
1410 return tmp != NULL; | |
1411 } | |
1412 | |
1413 gint | |
1414 playlist_get_queue_position_number(Playlist *playlist, guint pos) | |
1415 { | |
1416 PlaylistEntry *entry; | |
1417 gint tmp; | |
1418 | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
1419 PLAYLIST_LOCK(playlist); |
2313 | 1420 entry = g_list_nth_data(playlist->entries, pos); |
1421 tmp = g_list_index(playlist->queue, entry); | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
1422 PLAYLIST_UNLOCK(playlist); |
2313 | 1423 |
1424 return tmp; | |
1425 } | |
1426 | |
1427 gint | |
1428 playlist_get_queue_qposition_number(Playlist *playlist, guint pos) | |
1429 { | |
1430 PlaylistEntry *entry; | |
1431 gint tmp; | |
1432 | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
1433 PLAYLIST_LOCK(playlist); |
2313 | 1434 entry = g_list_nth_data(playlist->queue, pos); |
1435 tmp = g_list_index(playlist->entries, entry); | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
1436 PLAYLIST_UNLOCK(playlist); |
2313 | 1437 |
1438 return tmp; | |
1439 } | |
1440 | |
1441 void | |
1442 playlist_clear_queue(Playlist *playlist) | |
1443 { | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
1444 PLAYLIST_LOCK(playlist); |
2313 | 1445 g_list_free(playlist->queue); |
1446 playlist->queue = NULL; | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
1447 PLAYLIST_UNLOCK(playlist); |
2313 | 1448 |
1449 playlist_recalc_total_time(playlist); | |
1450 playlistwin_update_list(playlist); | |
1451 } | |
1452 | |
1453 void | |
1454 playlist_queue_remove(Playlist *playlist, guint pos) | |
1455 { | |
1456 void *entry; | |
1457 | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
1458 PLAYLIST_LOCK(playlist); |
2313 | 1459 entry = g_list_nth_data(playlist->entries, pos); |
1460 playlist->queue = g_list_remove(playlist->queue, entry); | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
1461 PLAYLIST_UNLOCK(playlist); |
2313 | 1462 |
1463 playlistwin_update_list(playlist); | |
1464 } | |
1465 | |
1466 gint | |
1467 playlist_get_queue_position(Playlist *playlist, PlaylistEntry * entry) | |
1468 { | |
1469 return g_list_index(playlist->queue, entry); | |
1470 } | |
1471 | |
1472 void | |
1473 playlist_set_position(Playlist *playlist, guint pos) | |
1474 { | |
1475 GList *node; | |
1476 gboolean restart_playing = FALSE; | |
1477 | |
1478 if (!playlist) | |
1479 return; | |
1480 | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
1481 PLAYLIST_LOCK(playlist); |
2313 | 1482 |
1483 node = g_list_nth(playlist->entries, pos); | |
1484 if (!node) { | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
1485 PLAYLIST_UNLOCK(playlist); |
2313 | 1486 return; |
1487 } | |
1488 | |
1489 if (playback_get_playing()) { | |
1490 /* We need to stop before changing playlist_position */ | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
1491 PLAYLIST_UNLOCK(playlist); |
2313 | 1492 ip_data.stop = TRUE; |
1493 playback_stop(); | |
1494 ip_data.stop = FALSE; | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
1495 PLAYLIST_LOCK(playlist); |
2313 | 1496 restart_playing = TRUE; |
1497 } | |
1498 | |
1499 if ((cfg.shuffle) && (playlist_position_before_jump == NULL)) | |
1500 { | |
1501 /* Shuffling and this is our first manual jump. */ | |
1502 playlist_position_before_jump = playlist->position; | |
1503 } | |
3246
2127f7108033
- fixed some cases where the playlist wasn't redrawn
mf0102 <0102@gmx.at>
parents:
3217
diff
changeset
|
1504 |
2313 | 1505 playlist->position = node->data; |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
1506 PLAYLIST_UNLOCK(playlist); |
2313 | 1507 playlist_check_pos_current(playlist); |
1508 | |
3348
2a081105513c
-Set the track "title" in metadata instead of "name"
Ben Tucker <ben.tucker@gmail.com>
parents:
3346
diff
changeset
|
1509 if (restart_playing) |
2313 | 1510 playback_initiate(); |
3348
2a081105513c
-Set the track "title" in metadata instead of "name"
Ben Tucker <ben.tucker@gmail.com>
parents:
3346
diff
changeset
|
1511 else |
2313 | 1512 playlistwin_update_list(playlist); |
1513 } | |
1514 | |
1515 void | |
1516 playlist_eof_reached(Playlist *playlist) | |
1517 { | |
1518 GList *plist_pos_list; | |
1519 | |
1520 if ((cfg.no_playlist_advance && !cfg.repeat) || cfg.stopaftersong) | |
1521 ip_data.stop = TRUE; | |
1522 playback_stop(); | |
1523 if ((cfg.no_playlist_advance && !cfg.repeat) || cfg.stopaftersong) | |
1524 ip_data.stop = FALSE; | |
1525 | |
2408
b380e84148bb
[svn] - rename some hooks so that they are more logical
nenolod
parents:
2407
diff
changeset
|
1526 hook_call("playback end", playlist->position); |
2407
1dc1d36d0347
[svn] - add hooks: playback begin, playback end, playlist reached end
nenolod
parents:
2380
diff
changeset
|
1527 |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
1528 PLAYLIST_LOCK(playlist); |
2313 | 1529 |
1530 if ((playlist_position_before_jump != NULL) && playlist->queue == NULL) | |
1531 { | |
1532 playlist->position = playlist_position_before_jump; | |
1533 playlist_position_before_jump = NULL; | |
1534 } | |
3246
2127f7108033
- fixed some cases where the playlist wasn't redrawn
mf0102 <0102@gmx.at>
parents:
3217
diff
changeset
|
1535 |
2313 | 1536 plist_pos_list = find_playlist_position_list(playlist); |
1537 | |
1538 if (cfg.no_playlist_advance) { | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
1539 PLAYLIST_UNLOCK(playlist); |
2313 | 1540 mainwin_clear_song_info(); |
1541 if (cfg.repeat) | |
1542 playback_initiate(); | |
1543 return; | |
1544 } | |
1545 | |
1546 if (cfg.stopaftersong) { | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
1547 PLAYLIST_UNLOCK(playlist); |
2313 | 1548 mainwin_clear_song_info(); |
1549 mainwin_set_stopaftersong(FALSE); | |
1550 return; | |
1551 } | |
1552 | |
1553 if (playlist->queue != NULL) { | |
1554 play_queued(playlist); | |
1555 } | |
1556 else if (!g_list_next(plist_pos_list)) { | |
1557 if (cfg.shuffle) { | |
1558 playlist->position = NULL; | |
1559 playlist_generate_shuffle_list_nolock(playlist); | |
1560 } | |
2380 | 1561 else if (playlist->entries != NULL) |
2313 | 1562 playlist->position = playlist->entries->data; |
1563 | |
1564 if (!cfg.repeat) { | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
1565 PLAYLIST_UNLOCK(playlist); |
2408
b380e84148bb
[svn] - rename some hooks so that they are more logical
nenolod
parents:
2407
diff
changeset
|
1566 hook_call("playlist end reached", playlist->position); |
2313 | 1567 mainwin_clear_song_info(); |
1568 return; | |
1569 } | |
1570 } | |
1571 else | |
1572 playlist->position = g_list_next(plist_pos_list)->data; | |
1573 | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
1574 PLAYLIST_UNLOCK(playlist); |
2313 | 1575 |
1576 playlist_check_pos_current(playlist); | |
1577 playback_initiate(); | |
1578 playlistwin_update_list(playlist); | |
1579 } | |
1580 | |
1581 gint | |
1582 playlist_queue_get_length(Playlist *playlist) | |
1583 { | |
1584 gint length; | |
1585 | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
1586 PLAYLIST_LOCK(playlist); |
2313 | 1587 length = g_list_length(playlist->queue); |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
1588 PLAYLIST_UNLOCK(playlist); |
2313 | 1589 |
1590 return length; | |
1591 } | |
1592 | |
1593 gint | |
2671
e9b379528fbc
[svn] - playlist_get_length_nolock() -> playlist_get_length(), no need for
nenolod
parents:
2670
diff
changeset
|
1594 playlist_get_length(Playlist *playlist) |
2313 | 1595 { |
1596 return g_list_length(playlist->entries); | |
1597 } | |
1598 | |
1599 gchar * | |
1600 playlist_get_info_text(Playlist *playlist) | |
1601 { | |
1602 gchar *text, *title, *numbers, *length; | |
1603 | |
1604 g_return_val_if_fail(playlist != NULL, NULL); | |
1605 | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
1606 PLAYLIST_LOCK(playlist); |
2313 | 1607 if (!playlist->position) { |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
1608 PLAYLIST_UNLOCK(playlist); |
2313 | 1609 return NULL; |
1610 } | |
1611 | |
1612 /* FIXME: there should not be a need to do additional conversion, | |
1613 * if playlist is properly maintained */ | |
1614 if (playlist->position->title) { | |
1615 title = str_to_utf8(playlist->position->title); | |
1616 } | |
1617 else { | |
3635 | 1618 gchar *realfn = g_filename_from_uri(playlist->position->filename, NULL, NULL); |
1619 gchar *basename = g_path_get_basename(realfn ? realfn : playlist->position->filename); | |
2313 | 1620 title = filename_to_utf8(basename); |
3635 | 1621 g_free(realfn); |
1622 g_free(basename); | |
2313 | 1623 } |
1624 | |
1625 /* | |
1626 * If the user don't want numbers in the playlist, don't | |
1627 * display them in other parts of XMMS | |
1628 */ | |
1629 | |
1630 if (cfg.show_numbers_in_pl) | |
1631 numbers = g_strdup_printf("%d. ", playlist_get_position_nolock(playlist) + 1); | |
1632 else | |
1633 numbers = g_strdup(""); | |
1634 | |
1635 if (playlist->position->length != -1) | |
1636 length = g_strdup_printf(" (%d:%-2.2d)", | |
1637 playlist->position->length / 60000, | |
1638 (playlist->position->length / 1000) % 60); | |
1639 else | |
1640 length = g_strdup(""); | |
1641 | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
1642 PLAYLIST_UNLOCK(playlist); |
2313 | 1643 |
1644 text = convert_title_text(g_strconcat(numbers, title, length, NULL)); | |
1645 | |
1646 g_free(numbers); | |
1647 g_free(title); | |
1648 g_free(length); | |
1649 | |
1650 return text; | |
1651 } | |
1652 | |
1653 gint | |
1654 playlist_get_current_length(Playlist * playlist) | |
1655 { | |
1656 gint len = 0; | |
1657 | |
1658 if (!playlist) | |
1659 return 0; | |
1660 | |
1661 if (playlist->position) | |
1662 len = playlist->position->length; | |
1663 | |
1664 return len; | |
1665 } | |
1666 | |
1667 gboolean | |
1668 playlist_save(Playlist * playlist, const gchar * filename) | |
1669 { | |
1670 PlaylistContainer *plc = NULL; | |
3476
9152829f3c19
Allow non-active playlist to be saved to file
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3474
diff
changeset
|
1671 GList *old_iter; |
2313 | 1672 gchar *ext; |
1673 | |
1674 g_return_val_if_fail(playlist != NULL, FALSE); | |
1675 g_return_val_if_fail(filename != NULL, FALSE); | |
1676 | |
1677 ext = strrchr(filename, '.') + 1; | |
1678 | |
1679 if ((plc = playlist_container_find(ext)) == NULL) | |
1680 return FALSE; | |
1681 | |
1682 if (plc->plc_write == NULL) | |
1683 return FALSE; | |
1684 | |
3476
9152829f3c19
Allow non-active playlist to be saved to file
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3474
diff
changeset
|
1685 /* Save the right playlist to disk */ |
9152829f3c19
Allow non-active playlist to be saved to file
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3474
diff
changeset
|
1686 if (playlist != playlist_get_active()) { |
9152829f3c19
Allow non-active playlist to be saved to file
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3474
diff
changeset
|
1687 old_iter = playlists_iter; |
9152829f3c19
Allow non-active playlist to be saved to file
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3474
diff
changeset
|
1688 playlists_iter = g_list_find(playlists, playlist); |
9152829f3c19
Allow non-active playlist to be saved to file
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3474
diff
changeset
|
1689 if(!playlists_iter) playlists_iter = old_iter; |
9152829f3c19
Allow non-active playlist to be saved to file
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3474
diff
changeset
|
1690 plc->plc_write(filename, 0); |
9152829f3c19
Allow non-active playlist to be saved to file
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3474
diff
changeset
|
1691 playlists_iter = old_iter; |
9152829f3c19
Allow non-active playlist to be saved to file
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3474
diff
changeset
|
1692 } else { |
9152829f3c19
Allow non-active playlist to be saved to file
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3474
diff
changeset
|
1693 plc->plc_write(filename, 0); |
9152829f3c19
Allow non-active playlist to be saved to file
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3474
diff
changeset
|
1694 } |
2313 | 1695 |
1696 return TRUE; | |
1697 } | |
1698 | |
1699 gboolean | |
1700 playlist_load(Playlist * playlist, const gchar * filename) | |
1701 { | |
3337
99f34db2c3fc
- fix a bug that playlist_ins_url() always returns 1 even if no url has been added. now playlist_ins_url() returns number of new entries which actually added to the playlist.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3334
diff
changeset
|
1702 guint ret = 0; |
2313 | 1703 g_return_val_if_fail(playlist != NULL, FALSE); |
1704 | |
1705 playlist->loading_playlist = TRUE; | |
3477
57f4971b7086
New functions for associating a filename with a playlist. Made title/filename setting more consistent.
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3476
diff
changeset
|
1706 if(!playlist_get_length(playlist)) { |
57f4971b7086
New functions for associating a filename with a playlist. Made title/filename setting more consistent.
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3476
diff
changeset
|
1707 /* Loading new playlist */ |
57f4971b7086
New functions for associating a filename with a playlist. Made title/filename setting more consistent.
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3476
diff
changeset
|
1708 playlist_filename_set(playlist, filename); |
57f4971b7086
New functions for associating a filename with a playlist. Made title/filename setting more consistent.
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3476
diff
changeset
|
1709 } |
2313 | 1710 ret = playlist_load_ins(playlist, filename, -1); |
1711 playlist->loading_playlist = FALSE; | |
1712 | |
3337
99f34db2c3fc
- fix a bug that playlist_ins_url() always returns 1 even if no url has been added. now playlist_ins_url() returns number of new entries which actually added to the playlist.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3334
diff
changeset
|
1713 return ret ? TRUE : FALSE; |
2313 | 1714 } |
1715 | |
1716 void | |
1717 playlist_load_ins_file(Playlist *playlist, | |
3934
e924c9ee3958
when "Detect file formats on demand" is specified, filter unplayable files on loading by the hash table of all available extensions.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3923
diff
changeset
|
1718 const gchar * filename_p, |
2313 | 1719 const gchar * playlist_name, gint pos, |
1720 const gchar * title, gint len) | |
1721 { | |
1722 gchar *filename; | |
1723 gchar *tmp, *path; | |
3127
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1724 ProbeResult *pr = NULL; |
2313 | 1725 |
1726 g_return_if_fail(filename_p != NULL); | |
1727 g_return_if_fail(playlist != NULL); | |
1728 g_return_if_fail(playlist_name != NULL); | |
1729 | |
1730 filename = g_strchug(g_strdup(filename_p)); | |
1731 | |
3635 | 1732 if (cfg.convert_slash) |
3087
030b956c73b2
Fix a bug in backslash to slash conversion. Closes #1006.
William Pitcock <nenolod@atheme-project.org>
parents:
3081
diff
changeset
|
1733 while ((tmp = strchr(filename, '\\')) != NULL) |
030b956c73b2
Fix a bug in backslash to slash conversion. Closes #1006.
William Pitcock <nenolod@atheme-project.org>
parents:
3081
diff
changeset
|
1734 *tmp = '/'; |
2313 | 1735 |
1736 if (filename[0] != '/' && !strstr(filename, "://")) { | |
1737 path = g_strdup(playlist_name); | |
1738 if ((tmp = strrchr(path, '/'))) | |
1739 *tmp = '\0'; | |
1740 else { | |
3959
a575c29cee05
- revive on-demand metadata retrieving. in the combination with "Detect file formats on demand", now audacious can load large directory in a few seconds.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3947
diff
changeset
|
1741 if ((playlist->loading_playlist == TRUE || |
a575c29cee05
- revive on-demand metadata retrieving. in the combination with "Detect file formats on demand", now audacious can load large directory in a few seconds.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3947
diff
changeset
|
1742 cfg.playlist_detect == TRUE)) { |
3127
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1743 pr = NULL; |
3934
e924c9ee3958
when "Detect file formats on demand" is specified, filter unplayable files on loading by the hash table of all available extensions.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3923
diff
changeset
|
1744 if(!filter_by_extension(filename)) |
e924c9ee3958
when "Detect file formats on demand" is specified, filter unplayable files on loading by the hash table of all available extensions.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3923
diff
changeset
|
1745 return; |
3959
a575c29cee05
- revive on-demand metadata retrieving. in the combination with "Detect file formats on demand", now audacious can load large directory in a few seconds.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3947
diff
changeset
|
1746 } |
a575c29cee05
- revive on-demand metadata retrieving. in the combination with "Detect file formats on demand", now audacious can load large directory in a few seconds.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3947
diff
changeset
|
1747 else if (!str_has_prefix_nocase(filename, "http://") && |
a575c29cee05
- revive on-demand metadata retrieving. in the combination with "Detect file formats on demand", now audacious can load large directory in a few seconds.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3947
diff
changeset
|
1748 !str_has_prefix_nocase(filename, "https://")) { |
a575c29cee05
- revive on-demand metadata retrieving. in the combination with "Detect file formats on demand", now audacious can load large directory in a few seconds.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3947
diff
changeset
|
1749 pr = input_check_file(filename, TRUE); |
a575c29cee05
- revive on-demand metadata retrieving. in the combination with "Detect file formats on demand", now audacious can load large directory in a few seconds.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3947
diff
changeset
|
1750 } |
3127
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1751 __playlist_ins_with_info(playlist, filename, pos, title, len, pr ? pr->ip : NULL); |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1752 g_free(pr); |
2313 | 1753 return; |
1754 } | |
1755 tmp = g_build_filename(path, filename, NULL); | |
1756 | |
3934
e924c9ee3958
when "Detect file formats on demand" is specified, filter unplayable files on loading by the hash table of all available extensions.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3923
diff
changeset
|
1757 if (playlist->loading_playlist == TRUE && cfg.playlist_detect == TRUE) { |
e924c9ee3958
when "Detect file formats on demand" is specified, filter unplayable files on loading by the hash table of all available extensions.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3923
diff
changeset
|
1758 pr = NULL; |
e924c9ee3958
when "Detect file formats on demand" is specified, filter unplayable files on loading by the hash table of all available extensions.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3923
diff
changeset
|
1759 if(!filter_by_extension(filename)) |
e924c9ee3958
when "Detect file formats on demand" is specified, filter unplayable files on loading by the hash table of all available extensions.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3923
diff
changeset
|
1760 return; |
e924c9ee3958
when "Detect file formats on demand" is specified, filter unplayable files on loading by the hash table of all available extensions.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3923
diff
changeset
|
1761 } |
3959
a575c29cee05
- revive on-demand metadata retrieving. in the combination with "Detect file formats on demand", now audacious can load large directory in a few seconds.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3947
diff
changeset
|
1762 else if (!str_has_prefix_nocase(tmp, "http://") && |
a575c29cee05
- revive on-demand metadata retrieving. in the combination with "Detect file formats on demand", now audacious can load large directory in a few seconds.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3947
diff
changeset
|
1763 !str_has_prefix_nocase(tmp, "https://")) { |
a575c29cee05
- revive on-demand metadata retrieving. in the combination with "Detect file formats on demand", now audacious can load large directory in a few seconds.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3947
diff
changeset
|
1764 pr = input_check_file(tmp, TRUE); |
a575c29cee05
- revive on-demand metadata retrieving. in the combination with "Detect file formats on demand", now audacious can load large directory in a few seconds.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3947
diff
changeset
|
1765 } |
3127
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1766 |
3128
343504d43afc
Fix warnings.
William Pitcock <nenolod@atheme-project.org>
parents:
3127
diff
changeset
|
1767 __playlist_ins_with_info(playlist, tmp, pos, title, len, pr ? pr->ip : NULL); |
2313 | 1768 g_free(tmp); |
1769 g_free(path); | |
3127
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1770 g_free(pr); |
2313 | 1771 } |
1772 else | |
1773 { | |
2667
8c56926de2ad
[svn] - probe remote sources (hardcoded to http://, https://) in the background.
nenolod
parents:
2637
diff
changeset
|
1774 if ((playlist->loading_playlist == TRUE || |
3934
e924c9ee3958
when "Detect file formats on demand" is specified, filter unplayable files on loading by the hash table of all available extensions.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3923
diff
changeset
|
1775 cfg.playlist_detect == TRUE)) { |
3127
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1776 pr = NULL; |
3959
a575c29cee05
- revive on-demand metadata retrieving. in the combination with "Detect file formats on demand", now audacious can load large directory in a few seconds.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3947
diff
changeset
|
1777 if(!filter_by_extension(filename)) |
a575c29cee05
- revive on-demand metadata retrieving. in the combination with "Detect file formats on demand", now audacious can load large directory in a few seconds.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3947
diff
changeset
|
1778 return; |
3934
e924c9ee3958
when "Detect file formats on demand" is specified, filter unplayable files on loading by the hash table of all available extensions.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3923
diff
changeset
|
1779 } |
3959
a575c29cee05
- revive on-demand metadata retrieving. in the combination with "Detect file formats on demand", now audacious can load large directory in a few seconds.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3947
diff
changeset
|
1780 else if (!str_has_prefix_nocase(filename, "http://") && |
a575c29cee05
- revive on-demand metadata retrieving. in the combination with "Detect file formats on demand", now audacious can load large directory in a few seconds.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3947
diff
changeset
|
1781 !str_has_prefix_nocase(filename, "https://")) { |
a575c29cee05
- revive on-demand metadata retrieving. in the combination with "Detect file formats on demand", now audacious can load large directory in a few seconds.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3947
diff
changeset
|
1782 pr = input_check_file(filename, TRUE); |
a575c29cee05
- revive on-demand metadata retrieving. in the combination with "Detect file formats on demand", now audacious can load large directory in a few seconds.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3947
diff
changeset
|
1783 } |
3127
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1784 __playlist_ins_with_info(playlist, filename, pos, title, len, pr ? pr->ip : NULL); |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1785 g_free(pr); |
2313 | 1786 } |
1787 | |
1788 g_free(filename); | |
1789 } | |
1790 | |
1791 void | |
1792 playlist_load_ins_file_tuple(Playlist * playlist, | |
1793 const gchar * filename_p, | |
1794 const gchar * playlist_name, | |
1795 gint pos, | |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
1796 Tuple *tuple) |
2313 | 1797 { |
1798 gchar *filename; | |
1799 gchar *tmp, *path; | |
3127
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1800 ProbeResult *pr = NULL; /* for decoder cache */ |
2313 | 1801 |
1802 g_return_if_fail(filename_p != NULL); | |
1803 g_return_if_fail(playlist_name != NULL); | |
1804 g_return_if_fail(playlist != NULL); | |
1805 | |
1806 filename = g_strchug(g_strdup(filename_p)); | |
1807 | |
3635 | 1808 if (cfg.convert_slash) |
3087
030b956c73b2
Fix a bug in backslash to slash conversion. Closes #1006.
William Pitcock <nenolod@atheme-project.org>
parents:
3081
diff
changeset
|
1809 while ((tmp = strchr(filename, '\\')) != NULL) |
030b956c73b2
Fix a bug in backslash to slash conversion. Closes #1006.
William Pitcock <nenolod@atheme-project.org>
parents:
3081
diff
changeset
|
1810 *tmp = '/'; |
2313 | 1811 |
1812 if (filename[0] != '/' && !strstr(filename, "://")) { | |
1813 path = g_strdup(playlist_name); | |
1814 if ((tmp = strrchr(path, '/'))) | |
1815 *tmp = '\0'; | |
1816 else { | |
2667
8c56926de2ad
[svn] - probe remote sources (hardcoded to http://, https://) in the background.
nenolod
parents:
2637
diff
changeset
|
1817 if ((playlist->loading_playlist == TRUE || |
3934
e924c9ee3958
when "Detect file formats on demand" is specified, filter unplayable files on loading by the hash table of all available extensions.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3923
diff
changeset
|
1818 cfg.playlist_detect == TRUE)) { |
3127
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1819 pr = NULL; |
3934
e924c9ee3958
when "Detect file formats on demand" is specified, filter unplayable files on loading by the hash table of all available extensions.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3923
diff
changeset
|
1820 if(!filter_by_extension(filename)) |
e924c9ee3958
when "Detect file formats on demand" is specified, filter unplayable files on loading by the hash table of all available extensions.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3923
diff
changeset
|
1821 return; |
e924c9ee3958
when "Detect file formats on demand" is specified, filter unplayable files on loading by the hash table of all available extensions.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3923
diff
changeset
|
1822 } |
2667
8c56926de2ad
[svn] - probe remote sources (hardcoded to http://, https://) in the background.
nenolod
parents:
2637
diff
changeset
|
1823 else if (!str_has_prefix_nocase(filename, "http://") && |
8c56926de2ad
[svn] - probe remote sources (hardcoded to http://, https://) in the background.
nenolod
parents:
2637
diff
changeset
|
1824 !str_has_prefix_nocase(filename, "https://")) |
3959
a575c29cee05
- revive on-demand metadata retrieving. in the combination with "Detect file formats on demand", now audacious can load large directory in a few seconds.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3947
diff
changeset
|
1825 pr = input_check_file(filename, TRUE); |
3127
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1826 |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1827 __playlist_ins_with_info_tuple(playlist, filename, pos, tuple, pr ? pr->ip : NULL); |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1828 g_free(pr); |
2313 | 1829 return; |
1830 } | |
1831 tmp = g_build_filename(path, filename, NULL); | |
1832 | |
2667
8c56926de2ad
[svn] - probe remote sources (hardcoded to http://, https://) in the background.
nenolod
parents:
2637
diff
changeset
|
1833 if ((playlist->loading_playlist == TRUE || |
3934
e924c9ee3958
when "Detect file formats on demand" is specified, filter unplayable files on loading by the hash table of all available extensions.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3923
diff
changeset
|
1834 cfg.playlist_detect == TRUE)) { |
3127
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1835 pr = NULL; |
3934
e924c9ee3958
when "Detect file formats on demand" is specified, filter unplayable files on loading by the hash table of all available extensions.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3923
diff
changeset
|
1836 if(!filter_by_extension(filename)) |
e924c9ee3958
when "Detect file formats on demand" is specified, filter unplayable files on loading by the hash table of all available extensions.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3923
diff
changeset
|
1837 return; |
e924c9ee3958
when "Detect file formats on demand" is specified, filter unplayable files on loading by the hash table of all available extensions.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3923
diff
changeset
|
1838 } |
2667
8c56926de2ad
[svn] - probe remote sources (hardcoded to http://, https://) in the background.
nenolod
parents:
2637
diff
changeset
|
1839 else if (!str_has_prefix_nocase(filename, "http://") && |
8c56926de2ad
[svn] - probe remote sources (hardcoded to http://, https://) in the background.
nenolod
parents:
2637
diff
changeset
|
1840 !str_has_prefix_nocase(filename, "https://")) |
3959
a575c29cee05
- revive on-demand metadata retrieving. in the combination with "Detect file formats on demand", now audacious can load large directory in a few seconds.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3947
diff
changeset
|
1841 pr = input_check_file(filename, TRUE); |
3127
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1842 |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1843 __playlist_ins_with_info_tuple(playlist, tmp, pos, tuple, pr ? pr->ip : NULL); |
2313 | 1844 g_free(tmp); |
1845 g_free(path); | |
3127
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1846 g_free(pr); |
2313 | 1847 } |
1848 else | |
1849 { | |
2667
8c56926de2ad
[svn] - probe remote sources (hardcoded to http://, https://) in the background.
nenolod
parents:
2637
diff
changeset
|
1850 if ((playlist->loading_playlist == TRUE || |
3934
e924c9ee3958
when "Detect file formats on demand" is specified, filter unplayable files on loading by the hash table of all available extensions.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3923
diff
changeset
|
1851 cfg.playlist_detect == TRUE)) { |
3127
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1852 pr = NULL; |
3934
e924c9ee3958
when "Detect file formats on demand" is specified, filter unplayable files on loading by the hash table of all available extensions.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3923
diff
changeset
|
1853 if(!filter_by_extension(filename)) |
e924c9ee3958
when "Detect file formats on demand" is specified, filter unplayable files on loading by the hash table of all available extensions.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3923
diff
changeset
|
1854 return; |
e924c9ee3958
when "Detect file formats on demand" is specified, filter unplayable files on loading by the hash table of all available extensions.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3923
diff
changeset
|
1855 } |
2667
8c56926de2ad
[svn] - probe remote sources (hardcoded to http://, https://) in the background.
nenolod
parents:
2637
diff
changeset
|
1856 else if (!str_has_prefix_nocase(filename, "http://") && |
8c56926de2ad
[svn] - probe remote sources (hardcoded to http://, https://) in the background.
nenolod
parents:
2637
diff
changeset
|
1857 !str_has_prefix_nocase(filename, "https://")) |
3959
a575c29cee05
- revive on-demand metadata retrieving. in the combination with "Detect file formats on demand", now audacious can load large directory in a few seconds.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3947
diff
changeset
|
1858 pr = input_check_file(filename, TRUE); |
3127
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1859 |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1860 __playlist_ins_with_info_tuple(playlist, filename, pos, tuple, pr ? pr->ip : NULL); |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
1861 g_free(pr); |
2313 | 1862 } |
1863 | |
1864 g_free(filename); | |
1865 } | |
1866 | |
1867 static guint | |
1868 playlist_load_ins(Playlist * playlist, const gchar * filename, gint pos) | |
1869 { | |
1870 PlaylistContainer *plc; | |
3383
e2e875f3d02b
Make playlist_load_ins handle the case when playlist is not the currently active one
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3382
diff
changeset
|
1871 GList *old_iter; |
2313 | 1872 gchar *ext; |
3337
99f34db2c3fc
- fix a bug that playlist_ins_url() always returns 1 even if no url has been added. now playlist_ins_url() returns number of new entries which actually added to the playlist.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3334
diff
changeset
|
1873 gint old_len, new_len; |
99f34db2c3fc
- fix a bug that playlist_ins_url() always returns 1 even if no url has been added. now playlist_ins_url() returns number of new entries which actually added to the playlist.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3334
diff
changeset
|
1874 |
2313 | 1875 g_return_val_if_fail(playlist != NULL, 0); |
1876 g_return_val_if_fail(filename != NULL, 0); | |
1877 | |
1878 ext = strrchr(filename, '.') + 1; | |
1879 plc = playlist_container_find(ext); | |
1880 | |
1881 g_return_val_if_fail(plc != NULL, 0); | |
1882 g_return_val_if_fail(plc->plc_read != NULL, 0); | |
1883 | |
3337
99f34db2c3fc
- fix a bug that playlist_ins_url() always returns 1 even if no url has been added. now playlist_ins_url() returns number of new entries which actually added to the playlist.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3334
diff
changeset
|
1884 old_len = playlist_get_length(playlist); |
3383
e2e875f3d02b
Make playlist_load_ins handle the case when playlist is not the currently active one
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3382
diff
changeset
|
1885 /* make sure it adds files to the right playlist */ |
e2e875f3d02b
Make playlist_load_ins handle the case when playlist is not the currently active one
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3382
diff
changeset
|
1886 if (playlist != playlist_get_active()) { |
e2e875f3d02b
Make playlist_load_ins handle the case when playlist is not the currently active one
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3382
diff
changeset
|
1887 old_iter = playlists_iter; |
e2e875f3d02b
Make playlist_load_ins handle the case when playlist is not the currently active one
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3382
diff
changeset
|
1888 playlists_iter = g_list_find(playlists, playlist); |
3478
481a4a88d3ec
Use old iterator when new one isn't found
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3477
diff
changeset
|
1889 if (!playlists_iter) playlists_iter = old_iter; |
3383
e2e875f3d02b
Make playlist_load_ins handle the case when playlist is not the currently active one
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3382
diff
changeset
|
1890 plc->plc_read(filename, pos); |
e2e875f3d02b
Make playlist_load_ins handle the case when playlist is not the currently active one
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3382
diff
changeset
|
1891 playlists_iter = old_iter; |
e2e875f3d02b
Make playlist_load_ins handle the case when playlist is not the currently active one
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3382
diff
changeset
|
1892 } else { |
e2e875f3d02b
Make playlist_load_ins handle the case when playlist is not the currently active one
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3382
diff
changeset
|
1893 plc->plc_read(filename, pos); |
e2e875f3d02b
Make playlist_load_ins handle the case when playlist is not the currently active one
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3382
diff
changeset
|
1894 } |
3337
99f34db2c3fc
- fix a bug that playlist_ins_url() always returns 1 even if no url has been added. now playlist_ins_url() returns number of new entries which actually added to the playlist.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3334
diff
changeset
|
1895 new_len = playlist_get_length(playlist); |
2313 | 1896 |
1897 playlist_generate_shuffle_list(playlist); | |
1898 playlistwin_update_list(playlist); | |
3621
2d6106656276
Notify playlist manager of more changes
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3583
diff
changeset
|
1899 playlist_manager_update(); |
3923
e9fd46b0893b
- redefine playlist_incr_serial as a macro.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3922
diff
changeset
|
1900 |
e9fd46b0893b
- redefine playlist_incr_serial as a macro.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3922
diff
changeset
|
1901 playlist_recalc_total_time(playlist); //tentative --yaz |
e9fd46b0893b
- redefine playlist_incr_serial as a macro.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3922
diff
changeset
|
1902 PLAYLIST_INCR_SERIAL(playlist); |
e9fd46b0893b
- redefine playlist_incr_serial as a macro.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3922
diff
changeset
|
1903 |
3337
99f34db2c3fc
- fix a bug that playlist_ins_url() always returns 1 even if no url has been added. now playlist_ins_url() returns number of new entries which actually added to the playlist.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3334
diff
changeset
|
1904 return new_len - old_len; |
2313 | 1905 } |
1906 | |
1907 GList * | |
1908 get_playlist_nth(Playlist *playlist, guint nth) | |
1909 { | |
1910 g_warning("deprecated function get_playlist_nth() was called"); | |
1911 REQUIRE_LOCK(playlist->mutex); | |
1912 return g_list_nth(playlist->entries, nth); | |
1913 } | |
1914 | |
1915 gint | |
1916 playlist_get_position_nolock(Playlist *playlist) | |
1917 { | |
1918 if (playlist && playlist->position) | |
1919 return g_list_index(playlist->entries, playlist->position); | |
1920 return 0; | |
1921 } | |
1922 | |
1923 gint | |
1924 playlist_get_position(Playlist *playlist) | |
1925 { | |
1926 gint pos; | |
1927 | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
1928 PLAYLIST_LOCK(playlist); |
2313 | 1929 pos = playlist_get_position_nolock(playlist); |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
1930 PLAYLIST_UNLOCK(playlist); |
2313 | 1931 |
1932 return pos; | |
1933 } | |
1934 | |
1935 gchar * | |
1936 playlist_get_filename(Playlist *playlist, guint pos) | |
1937 { | |
1938 gchar *filename; | |
1939 PlaylistEntry *entry; | |
1940 GList *node; | |
1941 | |
1942 if (!playlist) | |
1943 return NULL; | |
1944 | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
1945 PLAYLIST_LOCK(playlist); |
2313 | 1946 node = g_list_nth(playlist->entries, pos); |
1947 if (!node) { | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
1948 PLAYLIST_UNLOCK(playlist); |
2313 | 1949 return NULL; |
1950 } | |
1951 entry = node->data; | |
1952 | |
1953 filename = g_strdup(entry->filename); | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
1954 PLAYLIST_UNLOCK(playlist); |
2313 | 1955 |
1956 return filename; | |
1957 } | |
1958 | |
1959 gchar * | |
1960 playlist_get_songtitle(Playlist *playlist, guint pos) | |
1961 { | |
1962 gchar *title = NULL; | |
1963 PlaylistEntry *entry; | |
1964 GList *node; | |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
1965 time_t mtime; |
2313 | 1966 |
1967 if (!playlist) | |
1968 return NULL; | |
1969 | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
1970 PLAYLIST_LOCK(playlist); |
2313 | 1971 |
1972 if (!(node = g_list_nth(playlist->entries, pos))) { | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
1973 PLAYLIST_UNLOCK(playlist); |
2313 | 1974 return NULL; |
1975 } | |
1976 | |
1977 entry = node->data; | |
1978 | |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
1979 if (entry->tuple) |
3490
602ec8c40d0d
Fixed to comply with the Tuple API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
3401
diff
changeset
|
1980 mtime = tuple_get_int(entry->tuple, FIELD_MTIME, NULL); |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
1981 else |
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
1982 mtime = 0; |
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
1983 |
2313 | 1984 /* FIXME: simplify this logic */ |
1985 if ((entry->title == NULL && entry->length == -1) || | |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
1986 (entry->tuple && mtime != 0 && (mtime == -1 || mtime != playlist_get_mtime(entry->filename)))) |
2313 | 1987 { |
1988 if (playlist_entry_get_info(entry)) | |
1989 title = entry->title; | |
1990 } | |
1991 else { | |
1992 title = entry->title; | |
1993 } | |
1994 | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
1995 PLAYLIST_UNLOCK(playlist); |
2313 | 1996 |
1997 if (!title) { | |
3081
ba2143c1c6f5
unescape url encoded filename where real filename is needed.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3079
diff
changeset
|
1998 gchar *realfn = NULL; |
ba2143c1c6f5
unescape url encoded filename where real filename is needed.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3079
diff
changeset
|
1999 realfn = g_filename_from_uri(entry->filename, NULL, NULL); |
ba2143c1c6f5
unescape url encoded filename where real filename is needed.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3079
diff
changeset
|
2000 title = g_path_get_basename(realfn ? realfn : entry->filename); |
ba2143c1c6f5
unescape url encoded filename where real filename is needed.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3079
diff
changeset
|
2001 g_free(realfn); realfn = NULL; |
2313 | 2002 return str_replace(title, filename_to_utf8(title)); |
2003 } | |
2004 | |
2005 return str_to_utf8(title); | |
2006 } | |
2007 | |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
2008 Tuple * |
2313 | 2009 playlist_get_tuple(Playlist *playlist, guint pos) |
2010 { | |
2011 PlaylistEntry *entry; | |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
2012 Tuple *tuple = NULL; |
2313 | 2013 GList *node; |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
2014 time_t mtime; |
2313 | 2015 |
2016 if (!playlist) | |
2017 return NULL; | |
2018 | |
2019 if (!(node = g_list_nth(playlist->entries, pos))) { | |
2020 return NULL; | |
2021 } | |
2022 | |
2023 entry = (PlaylistEntry *) node->data; | |
2024 | |
2025 tuple = entry->tuple; | |
2026 | |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
2027 if (tuple) |
3490
602ec8c40d0d
Fixed to comply with the Tuple API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
3401
diff
changeset
|
2028 mtime = tuple_get_int(tuple, FIELD_MTIME, NULL); |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
2029 else |
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
2030 mtime = 0; |
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
2031 |
2313 | 2032 // if no tuple or tuple with old mtime, get new one. |
2033 if (tuple == NULL || | |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
2034 (entry->tuple && mtime != 0 && (mtime == -1 || mtime != playlist_get_mtime(entry->filename)))) |
2313 | 2035 { |
2036 playlist_entry_get_info(entry); | |
2037 tuple = entry->tuple; | |
2038 } | |
2039 | |
2040 return tuple; | |
2041 } | |
2042 | |
2043 gint | |
2044 playlist_get_songtime(Playlist *playlist, guint pos) | |
2045 { | |
2046 gint song_time = -1; | |
2047 PlaylistEntry *entry; | |
2048 GList *node; | |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
2049 time_t mtime; |
2313 | 2050 |
2051 if (!playlist) | |
2052 return -1; | |
2053 | |
3635 | 2054 if (!(node = g_list_nth(playlist->entries, pos))) |
2313 | 2055 return -1; |
2056 | |
2057 entry = node->data; | |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
2058 |
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
2059 if (entry->tuple) |
3490
602ec8c40d0d
Fixed to comply with the Tuple API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
3401
diff
changeset
|
2060 mtime = tuple_get_int(entry->tuple, FIELD_MTIME, NULL); |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
2061 else |
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
2062 mtime = 0; |
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
2063 |
2313 | 2064 if (entry->tuple == NULL || |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
2065 (mtime != 0 && (mtime == -1 || mtime != playlist_get_mtime(entry->filename)))) { |
2313 | 2066 |
2067 if (playlist_entry_get_info(entry)) | |
2068 song_time = entry->length; | |
3635 | 2069 } else |
2313 | 2070 song_time = entry->length; |
2071 | |
2072 return song_time; | |
2073 } | |
2074 | |
2075 static gint | |
2076 playlist_compare_track(PlaylistEntry * a, | |
2077 PlaylistEntry * b) | |
2078 { | |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
2079 gint tracknumber_a; |
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
2080 gint tracknumber_b; |
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
2081 |
2313 | 2082 g_return_val_if_fail(a != NULL, 0); |
2083 g_return_val_if_fail(b != NULL, 0); | |
2084 | |
2614
deb09bfd716b
[svn] - now sort by track number and sort by title work even if on display metadata loading is specified.
yaz
parents:
2580
diff
changeset
|
2085 if(!a->tuple) |
deb09bfd716b
[svn] - now sort by track number and sort by title work even if on display metadata loading is specified.
yaz
parents:
2580
diff
changeset
|
2086 playlist_entry_get_info(a); |
deb09bfd716b
[svn] - now sort by track number and sort by title work even if on display metadata loading is specified.
yaz
parents:
2580
diff
changeset
|
2087 if(!b->tuple) |
deb09bfd716b
[svn] - now sort by track number and sort by title work even if on display metadata loading is specified.
yaz
parents:
2580
diff
changeset
|
2088 playlist_entry_get_info(b); |
deb09bfd716b
[svn] - now sort by track number and sort by title work even if on display metadata loading is specified.
yaz
parents:
2580
diff
changeset
|
2089 |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
2090 if (a->tuple == NULL) |
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
2091 return 0; |
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
2092 if (b->tuple == NULL) |
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
2093 return 0; |
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
2094 |
3490
602ec8c40d0d
Fixed to comply with the Tuple API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
3401
diff
changeset
|
2095 tracknumber_a = tuple_get_int(a->tuple, FIELD_TRACK_NUMBER, NULL); |
602ec8c40d0d
Fixed to comply with the Tuple API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
3401
diff
changeset
|
2096 tracknumber_b = tuple_get_int(b->tuple, FIELD_TRACK_NUMBER, NULL); |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
2097 |
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
2098 return (tracknumber_a && tracknumber_b ? |
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
2099 tracknumber_a - tracknumber_b : 0); |
2313 | 2100 } |
2101 | |
3638
8d2f06fc841c
Slight cleanup of few functions and fix a potential segfault.
Matti Hamalainen <ccr@tnsp.org>
parents:
3636
diff
changeset
|
2102 static void |
8d2f06fc841c
Slight cleanup of few functions and fix a potential segfault.
Matti Hamalainen <ccr@tnsp.org>
parents:
3636
diff
changeset
|
2103 playlist_get_entry_title(PlaylistEntry * e, const gchar ** title) |
8d2f06fc841c
Slight cleanup of few functions and fix a potential segfault.
Matti Hamalainen <ccr@tnsp.org>
parents:
3636
diff
changeset
|
2104 { |
8d2f06fc841c
Slight cleanup of few functions and fix a potential segfault.
Matti Hamalainen <ccr@tnsp.org>
parents:
3636
diff
changeset
|
2105 if (e->title) |
8d2f06fc841c
Slight cleanup of few functions and fix a potential segfault.
Matti Hamalainen <ccr@tnsp.org>
parents:
3636
diff
changeset
|
2106 *title = e->title; |
8d2f06fc841c
Slight cleanup of few functions and fix a potential segfault.
Matti Hamalainen <ccr@tnsp.org>
parents:
3636
diff
changeset
|
2107 else { |
8d2f06fc841c
Slight cleanup of few functions and fix a potential segfault.
Matti Hamalainen <ccr@tnsp.org>
parents:
3636
diff
changeset
|
2108 if (strrchr(e->filename, '/')) |
8d2f06fc841c
Slight cleanup of few functions and fix a potential segfault.
Matti Hamalainen <ccr@tnsp.org>
parents:
3636
diff
changeset
|
2109 *title = strrchr(e->filename, '/') + 1; |
8d2f06fc841c
Slight cleanup of few functions and fix a potential segfault.
Matti Hamalainen <ccr@tnsp.org>
parents:
3636
diff
changeset
|
2110 else |
8d2f06fc841c
Slight cleanup of few functions and fix a potential segfault.
Matti Hamalainen <ccr@tnsp.org>
parents:
3636
diff
changeset
|
2111 *title = e->filename; |
8d2f06fc841c
Slight cleanup of few functions and fix a potential segfault.
Matti Hamalainen <ccr@tnsp.org>
parents:
3636
diff
changeset
|
2112 } |
8d2f06fc841c
Slight cleanup of few functions and fix a potential segfault.
Matti Hamalainen <ccr@tnsp.org>
parents:
3636
diff
changeset
|
2113 } |
8d2f06fc841c
Slight cleanup of few functions and fix a potential segfault.
Matti Hamalainen <ccr@tnsp.org>
parents:
3636
diff
changeset
|
2114 |
2313 | 2115 static gint |
2116 playlist_compare_playlist(PlaylistEntry * a, | |
2117 PlaylistEntry * b) | |
2118 { | |
2119 const gchar *a_title = NULL, *b_title = NULL; | |
2120 | |
2121 g_return_val_if_fail(a != NULL, 0); | |
2122 g_return_val_if_fail(b != NULL, 0); | |
3638
8d2f06fc841c
Slight cleanup of few functions and fix a potential segfault.
Matti Hamalainen <ccr@tnsp.org>
parents:
3636
diff
changeset
|
2123 |
8d2f06fc841c
Slight cleanup of few functions and fix a potential segfault.
Matti Hamalainen <ccr@tnsp.org>
parents:
3636
diff
changeset
|
2124 playlist_get_entry_title(a, &a_title); |
8d2f06fc841c
Slight cleanup of few functions and fix a potential segfault.
Matti Hamalainen <ccr@tnsp.org>
parents:
3636
diff
changeset
|
2125 playlist_get_entry_title(b, &b_title); |
2313 | 2126 |
2127 return strcasecmp(a_title, b_title); | |
2128 } | |
2129 | |
2130 static gint | |
2131 playlist_compare_title(PlaylistEntry * a, | |
2132 PlaylistEntry * b) | |
2133 { | |
2134 const gchar *a_title = NULL, *b_title = NULL; | |
2135 | |
2136 g_return_val_if_fail(a != NULL, 0); | |
2137 g_return_val_if_fail(b != NULL, 0); | |
2138 | |
3638
8d2f06fc841c
Slight cleanup of few functions and fix a potential segfault.
Matti Hamalainen <ccr@tnsp.org>
parents:
3636
diff
changeset
|
2139 if (a->tuple == NULL) |
2614
deb09bfd716b
[svn] - now sort by track number and sort by title work even if on display metadata loading is specified.
yaz
parents:
2580
diff
changeset
|
2140 playlist_entry_get_info(a); |
3638
8d2f06fc841c
Slight cleanup of few functions and fix a potential segfault.
Matti Hamalainen <ccr@tnsp.org>
parents:
3636
diff
changeset
|
2141 if (b->tuple == NULL) |
2614
deb09bfd716b
[svn] - now sort by track number and sort by title work even if on display metadata loading is specified.
yaz
parents:
2580
diff
changeset
|
2142 playlist_entry_get_info(b); |
deb09bfd716b
[svn] - now sort by track number and sort by title work even if on display metadata loading is specified.
yaz
parents:
2580
diff
changeset
|
2143 |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
2144 if (a->tuple != NULL) |
3490
602ec8c40d0d
Fixed to comply with the Tuple API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
3401
diff
changeset
|
2145 a_title = tuple_get_string(a->tuple, FIELD_TITLE, NULL); |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
2146 if (b->tuple != NULL) |
3490
602ec8c40d0d
Fixed to comply with the Tuple API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
3401
diff
changeset
|
2147 b_title = tuple_get_string(b->tuple, FIELD_TITLE, NULL); |
2313 | 2148 |
2149 if (a_title != NULL && b_title != NULL) | |
2150 return strcasecmp(a_title, b_title); | |
2151 | |
3638
8d2f06fc841c
Slight cleanup of few functions and fix a potential segfault.
Matti Hamalainen <ccr@tnsp.org>
parents:
3636
diff
changeset
|
2152 playlist_get_entry_title(a, &a_title); |
8d2f06fc841c
Slight cleanup of few functions and fix a potential segfault.
Matti Hamalainen <ccr@tnsp.org>
parents:
3636
diff
changeset
|
2153 playlist_get_entry_title(b, &b_title); |
2313 | 2154 |
2155 return strcasecmp(a_title, b_title); | |
2156 } | |
2157 | |
2158 static gint | |
2159 playlist_compare_artist(PlaylistEntry * a, | |
2160 PlaylistEntry * b) | |
2161 { | |
2162 const gchar *a_artist = NULL, *b_artist = NULL; | |
2163 | |
2164 g_return_val_if_fail(a != NULL, 0); | |
2165 g_return_val_if_fail(b != NULL, 0); | |
2166 | |
2167 if (a->tuple != NULL) | |
2168 playlist_entry_get_info(a); | |
2169 | |
2170 if (b->tuple != NULL) | |
2171 playlist_entry_get_info(b); | |
2172 | |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
2173 if (a->tuple != NULL) { |
3490
602ec8c40d0d
Fixed to comply with the Tuple API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
3401
diff
changeset
|
2174 a_artist = tuple_get_string(a->tuple, FIELD_ARTIST, NULL); |
2683
d2ffabee3ced
[svn] Modified playlist_compare_artist so that a leading "the" in an artist's
magma
parents:
2671
diff
changeset
|
2175 if (str_has_prefix_nocase(a_artist, "the ")) |
d2ffabee3ced
[svn] Modified playlist_compare_artist so that a leading "the" in an artist's
magma
parents:
2671
diff
changeset
|
2176 a_artist += 4; |
d2ffabee3ced
[svn] Modified playlist_compare_artist so that a leading "the" in an artist's
magma
parents:
2671
diff
changeset
|
2177 } |
d2ffabee3ced
[svn] Modified playlist_compare_artist so that a leading "the" in an artist's
magma
parents:
2671
diff
changeset
|
2178 |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
2179 if (b->tuple != NULL) { |
3490
602ec8c40d0d
Fixed to comply with the Tuple API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
3401
diff
changeset
|
2180 b_artist = tuple_get_string(b->tuple, FIELD_ARTIST, NULL); |
2683
d2ffabee3ced
[svn] Modified playlist_compare_artist so that a leading "the" in an artist's
magma
parents:
2671
diff
changeset
|
2181 if (str_has_prefix_nocase(b_artist, "the ")) |
d2ffabee3ced
[svn] Modified playlist_compare_artist so that a leading "the" in an artist's
magma
parents:
2671
diff
changeset
|
2182 b_artist += 4; |
d2ffabee3ced
[svn] Modified playlist_compare_artist so that a leading "the" in an artist's
magma
parents:
2671
diff
changeset
|
2183 } |
2313 | 2184 |
2185 if (a_artist != NULL && b_artist != NULL) | |
2186 return strcasecmp(a_artist, b_artist); | |
2187 | |
2188 return 0; | |
2189 } | |
2190 | |
2191 static gint | |
2192 playlist_compare_filename(PlaylistEntry * a, | |
2193 PlaylistEntry * b) | |
2194 { | |
2195 gchar *a_filename, *b_filename; | |
2196 | |
2197 g_return_val_if_fail(a != NULL, 0); | |
2198 g_return_val_if_fail(b != NULL, 0); | |
2199 | |
2200 if (strrchr(a->filename, '/')) | |
2201 a_filename = strrchr(a->filename, '/') + 1; | |
2202 else | |
2203 a_filename = a->filename; | |
2204 | |
2205 if (strrchr(b->filename, '/')) | |
2206 b_filename = strrchr(b->filename, '/') + 1; | |
2207 else | |
2208 b_filename = b->filename; | |
2209 | |
2210 | |
2211 return strcasecmp(a_filename, b_filename); | |
2212 } | |
2213 | |
2214 static gint | |
2215 path_compare(const gchar * a, const gchar * b) | |
2216 { | |
2217 gchar *posa, *posb; | |
2218 gint len, ret; | |
2219 | |
2220 posa = strrchr(a, '/'); | |
2221 posb = strrchr(b, '/'); | |
2222 | |
2223 /* | |
2224 * Sort directories before files | |
2225 */ | |
2226 if (posa && posb && (posa - a != posb - b)) { | |
2227 if (posa - a > posb - b) { | |
2228 len = posb - b; | |
2229 ret = -1; | |
2230 } | |
2231 else { | |
2232 len = posa - a; | |
2233 ret = 1; | |
2234 } | |
2235 if (!strncasecmp(a, b, len)) | |
2236 return ret; | |
2237 } | |
2238 return strcasecmp(a, b); | |
2239 } | |
2240 | |
2241 static gint | |
2242 playlist_compare_path(PlaylistEntry * a, | |
2243 PlaylistEntry * b) | |
2244 { | |
2245 return path_compare(a->filename, b->filename); | |
2246 } | |
2247 | |
2248 | |
2249 static time_t | |
2250 playlist_get_mtime(const gchar *filename) | |
2251 { | |
2252 struct stat buf; | |
2253 gint rv; | |
3081
ba2143c1c6f5
unescape url encoded filename where real filename is needed.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3079
diff
changeset
|
2254 gchar *realfn = NULL; |
ba2143c1c6f5
unescape url encoded filename where real filename is needed.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3079
diff
changeset
|
2255 |
ba2143c1c6f5
unescape url encoded filename where real filename is needed.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3079
diff
changeset
|
2256 /* stat() does not accept file:// --yaz */ |
ba2143c1c6f5
unescape url encoded filename where real filename is needed.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3079
diff
changeset
|
2257 realfn = g_filename_from_uri(filename, NULL, NULL); |
ba2143c1c6f5
unescape url encoded filename where real filename is needed.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3079
diff
changeset
|
2258 rv = stat(realfn ? realfn : filename, &buf); |
ba2143c1c6f5
unescape url encoded filename where real filename is needed.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3079
diff
changeset
|
2259 g_free(realfn); realfn = NULL; |
2313 | 2260 |
2261 if (rv == 0) { | |
2262 return buf.st_mtime; | |
2263 } else { | |
2264 return 0; //error | |
2265 } | |
2266 } | |
2267 | |
2268 | |
2269 static gint | |
2270 playlist_compare_date(PlaylistEntry * a, | |
2271 PlaylistEntry * b) | |
2272 { | |
2273 struct stat buf; | |
2274 time_t modtime; | |
2275 | |
2276 gint rv; | |
2277 | |
2278 | |
2279 rv = stat(a->filename, &buf); | |
2280 | |
2281 if (rv == 0) { | |
2282 modtime = buf.st_mtime; | |
2283 rv = stat(b->filename, &buf); | |
2284 | |
2285 if (stat(b->filename, &buf) == 0) { | |
2286 if (buf.st_mtime == modtime) | |
2287 return 0; | |
2288 else | |
2289 return (buf.st_mtime - modtime) > 0 ? -1 : 1; | |
2290 } | |
2291 else | |
2292 return -1; | |
2293 } | |
2294 else if (!lstat(b->filename, &buf)) | |
2295 return 1; | |
2296 else | |
2297 return playlist_compare_filename(a, b); | |
2298 } | |
2299 | |
2300 | |
2301 void | |
2302 playlist_sort(Playlist *playlist, PlaylistSortType type) | |
2303 { | |
2304 playlist_remove_dead_files(playlist); | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
2305 PLAYLIST_LOCK(playlist); |
2313 | 2306 playlist->entries = |
2307 g_list_sort(playlist->entries, | |
2308 (GCompareFunc) playlist_compare_func_table[type]); | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
2309 PLAYLIST_UNLOCK(playlist); |
2313 | 2310 } |
2311 | |
2312 static GList * | |
2313 playlist_sort_selected_generic(GList * list, GCompareFunc cmpfunc) | |
2314 { | |
2315 GList *list1, *list2; | |
2316 GList *tmp_list = NULL; | |
2317 GList *index_list = NULL; | |
2318 | |
2319 /* | |
2320 * We take all the selected entries out of the playlist, | |
2321 * sorts them, and then put them back in again. | |
2322 */ | |
2323 | |
2324 list1 = g_list_last(list); | |
2325 | |
2326 while (list1) { | |
2327 list2 = g_list_previous(list1); | |
2328 if (PLAYLIST_ENTRY(list1->data)->selected) { | |
2329 gpointer idx; | |
2330 idx = GINT_TO_POINTER(g_list_position(list, list1)); | |
2331 index_list = g_list_prepend(index_list, idx); | |
2332 list = g_list_remove_link(list, list1); | |
2333 tmp_list = g_list_concat(list1, tmp_list); | |
2334 } | |
2335 list1 = list2; | |
2336 } | |
2337 | |
2338 tmp_list = g_list_sort(tmp_list, cmpfunc); | |
2339 list1 = tmp_list; | |
2340 list2 = index_list; | |
2341 | |
2342 while (list2) { | |
2343 if (!list1) { | |
2344 g_critical(G_STRLOC ": Error during list sorting. " | |
2345 "Possibly dropped some playlist-entries."); | |
2346 break; | |
2347 } | |
2348 | |
2349 list = g_list_insert(list, list1->data, GPOINTER_TO_INT(list2->data)); | |
2350 | |
2351 list2 = g_list_next(list2); | |
2352 list1 = g_list_next(list1); | |
2353 } | |
2354 | |
2355 g_list_free(index_list); | |
2356 g_list_free(tmp_list); | |
2357 | |
2358 return list; | |
2359 } | |
2360 | |
2361 void | |
2362 playlist_sort_selected(Playlist *playlist, PlaylistSortType type) | |
2363 { | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
2364 PLAYLIST_LOCK(playlist); |
2313 | 2365 playlist->entries = playlist_sort_selected_generic(playlist->entries, (GCompareFunc) |
2366 playlist_compare_func_table | |
2367 [type]); | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
2368 PLAYLIST_UNLOCK(playlist); |
2313 | 2369 } |
2370 | |
2371 void | |
2372 playlist_reverse(Playlist *playlist) | |
2373 { | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
2374 PLAYLIST_LOCK(playlist); |
2313 | 2375 playlist->entries = g_list_reverse(playlist->entries); |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
2376 PLAYLIST_UNLOCK(playlist); |
2313 | 2377 } |
2378 | |
2379 static GList * | |
2380 playlist_shuffle_list(Playlist *playlist, GList * list) | |
2381 { | |
2382 /* | |
2383 * Note that this doesn't make a copy of the original list. | |
2384 * The pointer to the original list is not valid after this | |
2385 * fuction is run. | |
2386 */ | |
2387 gint len = g_list_length(list); | |
2388 gint i, j; | |
2389 GList *node, **ptrs; | |
2390 | |
2391 if (!playlist) | |
2392 return NULL; | |
2393 | |
2394 REQUIRE_LOCK(playlist->mutex); | |
2395 | |
2396 if (!len) | |
2397 return NULL; | |
2398 | |
2399 ptrs = g_new(GList *, len); | |
2400 | |
2401 for (node = list, i = 0; i < len; node = g_list_next(node), i++) | |
2402 ptrs[i] = node; | |
2403 | |
2404 j = g_random_int_range(0, len); | |
2405 list = ptrs[j]; | |
2406 ptrs[j]->next = NULL; | |
2407 ptrs[j] = ptrs[0]; | |
2408 | |
2409 for (i = 1; i < len; i++) { | |
2410 j = g_random_int_range(0, len - i); | |
2411 list->prev = ptrs[i + j]; | |
2412 ptrs[i + j]->next = list; | |
2413 list = ptrs[i + j]; | |
2414 ptrs[i + j] = ptrs[i]; | |
2415 } | |
2416 list->prev = NULL; | |
2417 | |
2418 g_free(ptrs); | |
2419 | |
2420 return list; | |
2421 } | |
2422 | |
2423 void | |
2424 playlist_random(Playlist *playlist) | |
2425 { | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
2426 PLAYLIST_LOCK(playlist); |
2313 | 2427 playlist->entries = playlist_shuffle_list(playlist, playlist->entries); |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
2428 PLAYLIST_UNLOCK(playlist); |
2313 | 2429 } |
2430 | |
2431 GList * | |
2432 playlist_get_selected(Playlist *playlist) | |
2433 { | |
2434 GList *node, *list = NULL; | |
2435 gint i = 0; | |
2436 | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
2437 PLAYLIST_LOCK(playlist); |
2313 | 2438 for (node = playlist->entries; node; node = g_list_next(node), i++) { |
2439 PlaylistEntry *entry = node->data; | |
2440 if (entry->selected) | |
2441 list = g_list_prepend(list, GINT_TO_POINTER(i)); | |
2442 } | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
2443 PLAYLIST_UNLOCK(playlist); |
2313 | 2444 return g_list_reverse(list); |
2445 } | |
2446 | |
2447 void | |
2448 playlist_clear_selected(Playlist *playlist) | |
2449 { | |
2450 GList *node = NULL; | |
2451 gint i = 0; | |
2452 | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
2453 PLAYLIST_LOCK(playlist); |
2313 | 2454 for (node = playlist->entries; node; node = g_list_next(node), i++) { |
2455 PLAYLIST_ENTRY(node->data)->selected = FALSE; | |
2456 } | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
2457 PLAYLIST_UNLOCK(playlist); |
2313 | 2458 playlist_recalc_total_time(playlist); |
2459 playlist_manager_update(); | |
2460 } | |
2461 | |
2462 gint | |
2463 playlist_get_num_selected(Playlist *playlist) | |
2464 { | |
2465 GList *node; | |
2466 gint num = 0; | |
2467 | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
2468 PLAYLIST_LOCK(playlist); |
2313 | 2469 for (node = playlist->entries; node; node = g_list_next(node)) { |
2470 PlaylistEntry *entry = node->data; | |
2471 if (entry->selected) | |
2472 num++; | |
2473 } | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
2474 PLAYLIST_UNLOCK(playlist); |
2313 | 2475 return num; |
2476 } | |
2477 | |
2478 | |
2479 static void | |
2480 playlist_generate_shuffle_list(Playlist *playlist) | |
2481 { | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
2482 PLAYLIST_LOCK(playlist); |
2313 | 2483 playlist_generate_shuffle_list_nolock(playlist); |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
2484 PLAYLIST_UNLOCK(playlist); |
2313 | 2485 } |
2486 | |
2487 static void | |
2488 playlist_generate_shuffle_list_nolock(Playlist *playlist) | |
2489 { | |
2490 GList *node; | |
2491 gint numsongs; | |
2492 | |
2493 if (!cfg.shuffle || !playlist) | |
2494 return; | |
2495 | |
2496 REQUIRE_LOCK(playlist->mutex); | |
2497 | |
2498 if (playlist->shuffle) { | |
2499 g_list_free(playlist->shuffle); | |
2500 playlist->shuffle = NULL; | |
2501 } | |
2502 | |
2503 playlist->shuffle = playlist_shuffle_list(playlist, g_list_copy(playlist->entries)); | |
2504 numsongs = g_list_length(playlist->shuffle); | |
2505 | |
2506 if (playlist->position) { | |
2507 gint i = g_list_index(playlist->shuffle, playlist->position); | |
2508 node = g_list_nth(playlist->shuffle, i); | |
2509 playlist->shuffle = g_list_remove_link(playlist->shuffle, node); | |
2510 playlist->shuffle = g_list_prepend(playlist->shuffle, node->data); | |
2511 } | |
2512 } | |
2513 | |
2514 void | |
2515 playlist_fileinfo(Playlist *playlist, guint pos) | |
2516 { | |
2517 gchar *path = NULL; | |
2518 GList *node; | |
2519 PlaylistEntry *entry = NULL; | |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
2520 Tuple *tuple = NULL; |
3127
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
2521 ProbeResult *pr = NULL; |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
2522 time_t mtime; |
2313 | 2523 |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
2524 PLAYLIST_LOCK(playlist); |
2313 | 2525 |
2526 if ((node = g_list_nth(playlist->entries, pos))) | |
2527 { | |
2528 entry = node->data; | |
2529 tuple = entry->tuple; | |
2530 path = g_strdup(entry->filename); | |
2531 } | |
2532 | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
2533 PLAYLIST_UNLOCK(playlist); |
2313 | 2534 |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
2535 if (entry->tuple) |
3490
602ec8c40d0d
Fixed to comply with the Tuple API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
3401
diff
changeset
|
2536 mtime = tuple_get_int(entry->tuple, FIELD_MTIME, NULL); |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
2537 else |
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
2538 mtime = 0; |
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
2539 |
2313 | 2540 /* No tuple? Try to set this entry up properly. --nenolod */ |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
2541 if (entry->tuple == NULL || mtime == -1 || |
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
2542 mtime == 0 || mtime != playlist_get_mtime(entry->filename)) |
2313 | 2543 { |
2544 playlist_entry_get_info(entry); | |
2545 tuple = entry->tuple; | |
2546 } | |
2547 | |
2548 if (tuple != NULL) | |
2549 { | |
2550 if (entry->decoder == NULL) | |
3127
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
2551 { |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
2552 pr = input_check_file(entry->filename, FALSE); /* try to find a decoder */ |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
2553 entry->decoder = pr ? pr->ip : NULL; |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
2554 |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
2555 g_free(pr); |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
2556 } |
2313 | 2557 |
2558 if (entry->decoder != NULL && entry->decoder->file_info_box == NULL) | |
2559 fileinfo_show_for_tuple(tuple); | |
2560 else if (entry->decoder != NULL && entry->decoder->file_info_box != NULL) | |
2561 entry->decoder->file_info_box(path); | |
2562 else | |
2563 fileinfo_show_for_path(path); | |
2564 g_free(path); | |
2565 } | |
2566 else if (path != NULL) | |
2567 { | |
2568 if (entry != NULL && entry->decoder != NULL && entry->decoder->file_info_box != NULL) | |
2569 entry->decoder->file_info_box(path); | |
2570 else | |
2571 fileinfo_show_for_path(path); | |
2572 g_free(path); | |
2573 } | |
2574 } | |
2575 | |
2576 void | |
2577 playlist_fileinfo_current(Playlist *playlist) | |
2578 { | |
2579 gchar *path = NULL; | |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
2580 Tuple *tuple = NULL; |
2313 | 2581 |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
2582 PLAYLIST_LOCK(playlist); |
2313 | 2583 |
2584 if (playlist->entries && playlist->position) | |
2585 { | |
2586 path = g_strdup(playlist->position->filename); | |
2587 if (( playlist->position->tuple == NULL ) || ( playlist->position->decoder == NULL )) | |
2588 playlist_entry_get_info(playlist->position); | |
2589 tuple = playlist->position->tuple; | |
2590 } | |
2591 | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
2592 PLAYLIST_UNLOCK(playlist); |
2313 | 2593 |
2594 if (tuple != NULL) | |
2595 { | |
2596 if (playlist->position->decoder != NULL && playlist->position->decoder->file_info_box == NULL) | |
2597 fileinfo_show_for_tuple(tuple); | |
2598 else if (playlist->position->decoder != NULL && playlist->position->decoder->file_info_box != NULL) | |
2599 playlist->position->decoder->file_info_box(path); | |
2600 else | |
2601 fileinfo_show_for_path(path); | |
2602 g_free(path); | |
2603 } | |
2604 else if (path != NULL) | |
2605 { | |
2606 if (playlist->position != NULL && playlist->position->decoder != NULL && playlist->position->decoder->file_info_box != NULL) | |
2607 playlist->position->decoder->file_info_box(path); | |
2608 else | |
2609 fileinfo_show_for_path(path); | |
2610 g_free(path); | |
2611 } | |
2612 } | |
2613 | |
2614 | |
2615 static gboolean | |
2616 playlist_get_info_is_going(void) | |
2617 { | |
2618 gboolean result; | |
2619 | |
3460
0fcff78c0c2c
Make the shutdown procedure more sane and improve playlist clearing
Matti Hamalainen <ccr@tnsp.org>
parents:
3401
diff
changeset
|
2620 g_static_rw_lock_reader_lock(&playlist_get_info_rwlock); |
2313 | 2621 result = playlist_get_info_going; |
3460
0fcff78c0c2c
Make the shutdown procedure more sane and improve playlist clearing
Matti Hamalainen <ccr@tnsp.org>
parents:
3401
diff
changeset
|
2622 g_static_rw_lock_reader_unlock(&playlist_get_info_rwlock); |
2313 | 2623 |
2624 return result; | |
2625 } | |
2626 | |
3460
0fcff78c0c2c
Make the shutdown procedure more sane and improve playlist clearing
Matti Hamalainen <ccr@tnsp.org>
parents:
3401
diff
changeset
|
2627 |
2313 | 2628 static gpointer |
2629 playlist_get_info_func(gpointer arg) | |
2630 { | |
2631 GList *node; | |
2632 gboolean update_playlistwin = FALSE; | |
2633 | |
2634 while (playlist_get_info_is_going()) { | |
2635 PlaylistEntry *entry; | |
2636 Playlist *playlist = playlist_get_active(); | |
2637 | |
2638 // on_load | |
3460
0fcff78c0c2c
Make the shutdown procedure more sane and improve playlist clearing
Matti Hamalainen <ccr@tnsp.org>
parents:
3401
diff
changeset
|
2639 if (cfg.use_pl_metadata && cfg.get_info_on_load && |
3959
a575c29cee05
- revive on-demand metadata retrieving. in the combination with "Detect file formats on demand", now audacious can load large directory in a few seconds.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3947
diff
changeset
|
2640 playlist_get_info_scan_active) { |
2313 | 2641 |
2642 for (node = playlist->entries; node; node = g_list_next(node)) { | |
2643 entry = node->data; | |
2644 | |
3934
e924c9ee3958
when "Detect file formats on demand" is specified, filter unplayable files on loading by the hash table of all available extensions.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3923
diff
changeset
|
2645 if(playlist->attribute & PLAYLIST_STATIC || // live lock fix |
3490
602ec8c40d0d
Fixed to comply with the Tuple API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
3401
diff
changeset
|
2646 (entry->tuple && tuple_get_int(entry->tuple, FIELD_LENGTH, NULL) > -1 && |
602ec8c40d0d
Fixed to comply with the Tuple API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
3401
diff
changeset
|
2647 tuple_get_int(entry->tuple, FIELD_MTIME, NULL) != -1)) { |
2313 | 2648 update_playlistwin = TRUE; |
2649 continue; | |
2650 } | |
2651 | |
2652 if (!playlist_entry_get_info(entry)) { | |
2653 if (g_list_index(playlist->entries, entry) == -1) | |
2654 /* Entry disappeared while we looked it up. | |
2655 Restart. */ | |
2656 node = playlist->entries; | |
2657 } | |
3733
da090f448c88
fix for livelock reported by joker...
William Pitcock <nenolod@atheme.org>
parents:
3640
diff
changeset
|
2658 else if ((entry->tuple != NULL || entry->title != NULL) && |
da090f448c88
fix for livelock reported by joker...
William Pitcock <nenolod@atheme.org>
parents:
3640
diff
changeset
|
2659 tuple_get_int(entry->tuple, FIELD_LENGTH, NULL) > -1 && |
da090f448c88
fix for livelock reported by joker...
William Pitcock <nenolod@atheme.org>
parents:
3640
diff
changeset
|
2660 tuple_get_int(entry->tuple, FIELD_MTIME, NULL) != -1) { |
2313 | 2661 update_playlistwin = TRUE; |
2662 break; | |
2663 } | |
2664 } | |
2665 | |
2666 if (!node) { | |
2667 g_mutex_lock(mutex_scan); | |
2668 playlist_get_info_scan_active = FALSE; | |
2669 g_mutex_unlock(mutex_scan); | |
2670 } | |
2671 } // on_load | |
2672 | |
2673 // on_demand | |
2674 else if (!cfg.get_info_on_load && | |
2675 cfg.get_info_on_demand && | |
2676 cfg.playlist_visible && | |
2677 !cfg.playlist_shaded && | |
2678 cfg.use_pl_metadata) { | |
2679 | |
2680 g_mutex_lock(mutex_scan); | |
2681 playlist_get_info_scan_active = FALSE; | |
2682 g_mutex_unlock(mutex_scan); | |
2683 | |
2668
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
2684 for (node = g_list_nth(playlist->entries, playlistwin_get_toprow()); |
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
2685 node && playlistwin_item_visible(g_list_position(playlist->entries, node)); |
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
2686 node = g_list_next(node)) { |
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
2687 |
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
2688 entry = node->data; |
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
2689 |
3959
a575c29cee05
- revive on-demand metadata retrieving. in the combination with "Detect file formats on demand", now audacious can load large directory in a few seconds.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3947
diff
changeset
|
2690 if(playlist->attribute & PLAYLIST_STATIC || |
3490
602ec8c40d0d
Fixed to comply with the Tuple API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
3401
diff
changeset
|
2691 (entry->tuple && tuple_get_int(entry->tuple, FIELD_LENGTH, NULL) > -1 && |
602ec8c40d0d
Fixed to comply with the Tuple API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
3401
diff
changeset
|
2692 tuple_get_int(entry->tuple, FIELD_MTIME, NULL) != -1)) { |
2668
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
2693 update_playlistwin = TRUE; |
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
2694 continue; |
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
2695 } |
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
2696 |
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
2697 if (!playlist_entry_get_info(entry)) { |
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
2698 if (g_list_index(playlist->entries, entry) == -1) |
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
2699 /* Entry disapeared while we |
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
2700 looked it up. Restart. */ |
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
2701 node = g_list_nth(playlist->entries, |
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
2702 playlistwin_get_toprow()); |
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
2703 } |
3733
da090f448c88
fix for livelock reported by joker...
William Pitcock <nenolod@atheme.org>
parents:
3640
diff
changeset
|
2704 else if ((entry->tuple != NULL || entry->title != NULL) && |
da090f448c88
fix for livelock reported by joker...
William Pitcock <nenolod@atheme.org>
parents:
3640
diff
changeset
|
2705 tuple_get_int(entry->tuple, FIELD_LENGTH, NULL) > -1 && |
da090f448c88
fix for livelock reported by joker...
William Pitcock <nenolod@atheme.org>
parents:
3640
diff
changeset
|
2706 tuple_get_int(entry->tuple, FIELD_MTIME, NULL) != -1) { |
2668
d5da5d37ec8b
[svn] - unlock many playlist operations that do not really need locking
nenolod
parents:
2667
diff
changeset
|
2707 update_playlistwin = TRUE; |
3733
da090f448c88
fix for livelock reported by joker...
William Pitcock <nenolod@atheme.org>
parents:
3640
diff
changeset
|
2708 } |
2313 | 2709 } |
2710 } // on_demand | |
3460
0fcff78c0c2c
Make the shutdown procedure more sane and improve playlist clearing
Matti Hamalainen <ccr@tnsp.org>
parents:
3401
diff
changeset
|
2711 else if (cfg.get_info_on_demand && |
0fcff78c0c2c
Make the shutdown procedure more sane and improve playlist clearing
Matti Hamalainen <ccr@tnsp.org>
parents:
3401
diff
changeset
|
2712 (!cfg.playlist_visible || cfg.playlist_shaded || !cfg.use_pl_metadata)) |
2313 | 2713 { |
2714 g_mutex_lock(mutex_scan); | |
2715 playlist_get_info_scan_active = FALSE; | |
2716 g_mutex_unlock(mutex_scan); | |
2717 } | |
2718 else /* not on_demand and not on_load... | |
2719 NOTE: this shouldn't happen anymore, sanity check in bmp_config_load now */ | |
2720 { | |
2721 g_mutex_lock(mutex_scan); | |
2722 playlist_get_info_scan_active = FALSE; | |
2723 g_mutex_unlock(mutex_scan); | |
2724 } | |
2725 | |
2726 if (update_playlistwin) { | |
3959
a575c29cee05
- revive on-demand metadata retrieving. in the combination with "Detect file formats on demand", now audacious can load large directory in a few seconds.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3947
diff
changeset
|
2727 event_queue("playlistwin update list", playlist_get_active()); |
2313 | 2728 update_playlistwin = FALSE; |
2729 } | |
2730 | |
3959
a575c29cee05
- revive on-demand metadata retrieving. in the combination with "Detect file formats on demand", now audacious can load large directory in a few seconds.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3947
diff
changeset
|
2731 if (playlist_get_info_scan_active) { |
2313 | 2732 continue; |
2733 } | |
2734 | |
2735 g_mutex_lock(mutex_scan); | |
2736 g_cond_wait(cond_scan, mutex_scan); | |
2737 g_mutex_unlock(mutex_scan); | |
2738 | |
3934
e924c9ee3958
when "Detect file formats on demand" is specified, filter unplayable files on loading by the hash table of all available extensions.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3923
diff
changeset
|
2739 // g_print("scanner invoked\n"); |
e924c9ee3958
when "Detect file formats on demand" is specified, filter unplayable files on loading by the hash table of all available extensions.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3923
diff
changeset
|
2740 |
2313 | 2741 } // while |
2742 | |
2743 g_thread_exit(NULL); | |
2744 return NULL; | |
2745 } | |
2746 | |
2747 void | |
2748 playlist_start_get_info_thread(void) | |
2749 { | |
3460
0fcff78c0c2c
Make the shutdown procedure more sane and improve playlist clearing
Matti Hamalainen <ccr@tnsp.org>
parents:
3401
diff
changeset
|
2750 g_static_rw_lock_writer_lock(&playlist_get_info_rwlock); |
2313 | 2751 playlist_get_info_going = TRUE; |
3460
0fcff78c0c2c
Make the shutdown procedure more sane and improve playlist clearing
Matti Hamalainen <ccr@tnsp.org>
parents:
3401
diff
changeset
|
2752 g_static_rw_lock_writer_unlock(&playlist_get_info_rwlock); |
2313 | 2753 |
2754 playlist_get_info_thread = g_thread_create(playlist_get_info_func, | |
2755 NULL, TRUE, NULL); | |
2756 } | |
2757 | |
2758 void | |
2759 playlist_stop_get_info_thread(void) | |
2760 { | |
3460
0fcff78c0c2c
Make the shutdown procedure more sane and improve playlist clearing
Matti Hamalainen <ccr@tnsp.org>
parents:
3401
diff
changeset
|
2761 g_static_rw_lock_writer_lock(&playlist_get_info_rwlock); |
2313 | 2762 playlist_get_info_going = FALSE; |
3460
0fcff78c0c2c
Make the shutdown procedure more sane and improve playlist clearing
Matti Hamalainen <ccr@tnsp.org>
parents:
3401
diff
changeset
|
2763 g_static_rw_lock_writer_unlock(&playlist_get_info_rwlock); |
2313 | 2764 |
2765 g_cond_broadcast(cond_scan); | |
2766 g_thread_join(playlist_get_info_thread); | |
2767 } | |
2768 | |
2769 void | |
2770 playlist_start_get_info_scan(void) | |
2771 { | |
2772 g_mutex_lock(mutex_scan); | |
2773 playlist_get_info_scan_active = TRUE; | |
2774 g_mutex_unlock(mutex_scan); | |
3460
0fcff78c0c2c
Make the shutdown procedure more sane and improve playlist clearing
Matti Hamalainen <ccr@tnsp.org>
parents:
3401
diff
changeset
|
2775 |
2313 | 2776 g_cond_signal(cond_scan); |
2777 } | |
2778 | |
2779 void | |
2780 playlist_remove_dead_files(Playlist *playlist) | |
2781 { | |
2782 GList *node, *next_node; | |
2783 | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
2784 PLAYLIST_LOCK(playlist); |
2313 | 2785 |
2786 for (node = playlist->entries; node; node = next_node) { | |
2787 PlaylistEntry *entry = PLAYLIST_ENTRY(node->data); | |
2788 next_node = g_list_next(node); | |
2789 | |
2790 if (!entry || !entry->filename) { | |
2791 g_message(G_STRLOC ": Playlist entry is invalid!"); | |
2792 continue; | |
2793 } | |
2794 | |
2795 /* FIXME: What about 'file:///'? */ | |
2796 /* Don't kill URLs */ | |
2797 if (strstr(entry->filename, "://")) | |
2798 continue; | |
2799 | |
2800 /* FIXME: Should test for readability */ | |
2801 if (vfs_file_test(entry->filename, G_FILE_TEST_EXISTS)) | |
2802 continue; | |
2803 | |
2804 if (entry == playlist->position) { | |
2805 /* Don't remove the currently playing song */ | |
2806 if (playback_get_playing()) | |
2807 continue; | |
2808 | |
2809 if (next_node) | |
2810 playlist->position = PLAYLIST_ENTRY(next_node->data); | |
2811 else | |
2812 playlist->position = NULL; | |
2813 } | |
2814 | |
2815 playlist_entry_free(entry); | |
2816 playlist->entries = g_list_delete_link(playlist->entries, node); | |
2817 } | |
2818 | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
2819 PLAYLIST_UNLOCK(playlist); |
2313 | 2820 |
2821 playlist_generate_shuffle_list(playlist); | |
2822 playlistwin_update_list(playlist); | |
2823 playlist_recalc_total_time(playlist); | |
3923
e9fd46b0893b
- redefine playlist_incr_serial as a macro.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3922
diff
changeset
|
2824 PLAYLIST_INCR_SERIAL(playlist); |
2313 | 2825 playlist_manager_update(); |
2826 } | |
2827 | |
2828 | |
2829 static gint | |
2830 playlist_dupscmp_title(PlaylistEntry * a, | |
2831 PlaylistEntry * b) | |
2832 { | |
2833 const gchar *a_title, *b_title; | |
2834 | |
2835 g_return_val_if_fail(a != NULL, 0); | |
2836 g_return_val_if_fail(b != NULL, 0); | |
2837 | |
3638
8d2f06fc841c
Slight cleanup of few functions and fix a potential segfault.
Matti Hamalainen <ccr@tnsp.org>
parents:
3636
diff
changeset
|
2838 playlist_get_entry_title(a, &a_title); |
8d2f06fc841c
Slight cleanup of few functions and fix a potential segfault.
Matti Hamalainen <ccr@tnsp.org>
parents:
3636
diff
changeset
|
2839 playlist_get_entry_title(b, &b_title); |
2313 | 2840 |
2841 return strcmp(a_title, b_title); | |
2842 } | |
2843 | |
2844 static gint | |
2845 playlist_dupscmp_filename(PlaylistEntry * a, | |
2846 PlaylistEntry * b ) | |
2847 { | |
2848 gchar *a_filename, *b_filename; | |
2849 | |
2850 g_return_val_if_fail(a != NULL, 0); | |
2851 g_return_val_if_fail(b != NULL, 0); | |
2852 | |
2853 if (strrchr(a->filename, '/')) | |
2854 a_filename = strrchr(a->filename, '/') + 1; | |
2855 else | |
2856 a_filename = a->filename; | |
2857 | |
2858 if (strrchr(b->filename, '/')) | |
2859 b_filename = strrchr(b->filename, '/') + 1; | |
2860 else | |
2861 b_filename = b->filename; | |
2862 | |
2863 return strcmp(a_filename, b_filename); | |
2864 } | |
2865 | |
2866 static gint | |
2867 playlist_dupscmp_path(PlaylistEntry * a, | |
2868 PlaylistEntry * b) | |
2869 { | |
2870 /* simply compare the entire filename string */ | |
2871 return strcmp(a->filename, b->filename); | |
2872 } | |
2873 | |
2874 void | |
2875 playlist_remove_duplicates(Playlist *playlist, PlaylistDupsType type) | |
2876 { | |
2877 GList *node, *next_node; | |
2878 GList *node_cmp, *next_node_cmp; | |
2879 gint (*dups_compare_func)(PlaylistEntry * , PlaylistEntry *); | |
2880 | |
2881 switch ( type ) | |
2882 { | |
2883 case PLAYLIST_DUPS_TITLE: | |
2884 dups_compare_func = playlist_dupscmp_title; | |
2885 break; | |
2886 case PLAYLIST_DUPS_PATH: | |
2887 dups_compare_func = playlist_dupscmp_path; | |
2888 break; | |
2889 case PLAYLIST_DUPS_FILENAME: | |
2890 default: | |
2891 dups_compare_func = playlist_dupscmp_filename; | |
2892 break; | |
2893 } | |
2894 | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
2895 PLAYLIST_LOCK(playlist); |
2313 | 2896 |
2897 for (node = playlist->entries; node; node = next_node) { | |
2898 PlaylistEntry *entry = PLAYLIST_ENTRY(node->data); | |
2899 next_node = g_list_next(node); | |
2900 | |
2901 if (!entry || !entry->filename) { | |
2902 g_message(G_STRLOC ": Playlist entry is invalid!"); | |
2903 continue; | |
2904 } | |
2905 | |
2906 for (node_cmp = next_node; node_cmp; node_cmp = next_node_cmp) { | |
2907 PlaylistEntry *entry_cmp = PLAYLIST_ENTRY(node_cmp->data); | |
2908 next_node_cmp = g_list_next(node_cmp); | |
2909 | |
2910 if (!entry_cmp || !entry_cmp->filename) { | |
2911 g_message(G_STRLOC ": Playlist entry is invalid!"); | |
2912 continue; | |
2913 } | |
2914 | |
2915 /* compare using the chosen dups_compare_func */ | |
2916 if ( !dups_compare_func( entry , entry_cmp ) ) { | |
2917 | |
2918 if (entry_cmp == playlist->position) { | |
2919 /* Don't remove the currently playing song */ | |
2920 if (playback_get_playing()) | |
2921 continue; | |
2922 | |
2923 if (next_node_cmp) | |
2924 playlist->position = PLAYLIST_ENTRY(next_node_cmp->data); | |
2925 else | |
2926 playlist->position = NULL; | |
2927 } | |
2928 | |
2929 /* check if this was the next item of the external | |
2930 loop; if true, replace it with the next of the next*/ | |
2931 if ( node_cmp == next_node ) | |
2932 next_node = g_list_next(next_node); | |
2933 | |
2934 playlist_entry_free(entry_cmp); | |
2935 playlist->entries = g_list_delete_link(playlist->entries, node_cmp); | |
2936 } | |
2937 } | |
2938 } | |
2939 | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
2940 PLAYLIST_UNLOCK(playlist); |
2313 | 2941 |
2942 playlistwin_update_list(playlist); | |
2943 playlist_recalc_total_time(playlist); | |
3923
e9fd46b0893b
- redefine playlist_incr_serial as a macro.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3922
diff
changeset
|
2944 PLAYLIST_INCR_SERIAL(playlist); |
2313 | 2945 |
2946 playlist_manager_update(); | |
2947 } | |
2948 | |
2949 void | |
2950 playlist_get_total_time(Playlist * playlist, | |
2951 gulong * total_time, | |
2952 gulong * selection_time, | |
2953 gboolean * total_more, | |
2954 gboolean * selection_more) | |
2955 { | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
2956 PLAYLIST_LOCK(playlist); |
2313 | 2957 *total_time = playlist->pl_total_time; |
2958 *selection_time = playlist->pl_selection_time; | |
2959 *total_more = playlist->pl_total_more; | |
2960 *selection_more = playlist->pl_selection_more; | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
2961 PLAYLIST_UNLOCK(playlist); |
2313 | 2962 } |
2963 | |
3922
23e5b148ae7c
to get rid of annoying side effects, an independent function for playlist serial increment has been provided.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3921
diff
changeset
|
2964 static void |
2313 | 2965 playlist_recalc_total_time_nolock(Playlist *playlist) |
2966 { | |
2967 GList *list; | |
2968 PlaylistEntry *entry; | |
2969 | |
2970 REQUIRE_LOCK(playlist->mutex); | |
2971 | |
2972 playlist->pl_total_time = 0; | |
2973 playlist->pl_selection_time = 0; | |
2974 playlist->pl_total_more = FALSE; | |
2975 playlist->pl_selection_more = FALSE; | |
2976 | |
2977 for (list = playlist->entries; list; list = g_list_next(list)) { | |
2978 entry = list->data; | |
2979 | |
2980 if (entry->length != -1) | |
2981 playlist->pl_total_time += entry->length / 1000; | |
2982 else | |
2983 playlist->pl_total_more = TRUE; | |
2984 | |
2985 if (entry->selected) { | |
2986 if (entry->length != -1) | |
2987 playlist->pl_selection_time += entry->length / 1000; | |
2988 else | |
2989 playlist->pl_selection_more = TRUE; | |
2990 } | |
2991 } | |
2992 } | |
2993 | |
2994 static void | |
2995 playlist_recalc_total_time(Playlist *playlist) | |
2996 { | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
2997 PLAYLIST_LOCK(playlist); |
2313 | 2998 playlist_recalc_total_time_nolock(playlist); |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
2999 PLAYLIST_UNLOCK(playlist); |
2313 | 3000 } |
3001 | |
3002 gint | |
3298
f985357757e0
audacious-core: convert to tuple-ng, remove titlestring API.
William Pitcock <nenolod@atheme-project.org>
parents:
3246
diff
changeset
|
3003 playlist_select_search( Playlist *playlist , Tuple *tuple , gint action ) |
2313 | 3004 { |
3005 GList *entry_list = NULL, *found_list = NULL, *sel_list = NULL; | |
3006 gboolean is_first_search = TRUE; | |
3007 gint num_of_entries_found = 0; | |
3490
602ec8c40d0d
Fixed to comply with the Tuple API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
3401
diff
changeset
|
3008 const gchar *regex_pattern; |
3863
dd5c459c5f2d
fix search and select. (bugzilla #29)
William Pitcock <nenolod@atheme.org>
parents:
3784
diff
changeset
|
3009 const gchar *track_name; |
dd5c459c5f2d
fix search and select. (bugzilla #29)
William Pitcock <nenolod@atheme.org>
parents:
3784
diff
changeset
|
3010 const gchar *album_name; |
dd5c459c5f2d
fix search and select. (bugzilla #29)
William Pitcock <nenolod@atheme.org>
parents:
3784
diff
changeset
|
3011 const gchar *performer; |
dd5c459c5f2d
fix search and select. (bugzilla #29)
William Pitcock <nenolod@atheme.org>
parents:
3784
diff
changeset
|
3012 const gchar *file_name; |
3490
602ec8c40d0d
Fixed to comply with the Tuple API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
3401
diff
changeset
|
3013 |
602ec8c40d0d
Fixed to comply with the Tuple API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
3401
diff
changeset
|
3014 #if defined(USE_REGEX_ONIGURUMA) |
2313 | 3015 /* set encoding for Oniguruma regex to UTF-8 */ |
3016 reg_set_encoding( REG_POSIX_ENCODING_UTF8 ); | |
3017 onig_set_default_syntax( ONIG_SYNTAX_POSIX_BASIC ); | |
3490
602ec8c40d0d
Fixed to comply with the Tuple API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
3401
diff
changeset
|
3018 #endif |
2313 | 3019 |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
3020 PLAYLIST_LOCK(playlist); |
2313 | 3021 |
3863
dd5c459c5f2d
fix search and select. (bugzilla #29)
William Pitcock <nenolod@atheme.org>
parents:
3784
diff
changeset
|
3022 if ( (regex_pattern = tuple_get_string(tuple, FIELD_TITLE, NULL)) != NULL && |
dd5c459c5f2d
fix search and select. (bugzilla #29)
William Pitcock <nenolod@atheme.org>
parents:
3784
diff
changeset
|
3023 (*regex_pattern != '\0') ) |
2313 | 3024 { |
3025 /* match by track_name */ | |
3026 regex_t regex; | |
3490
602ec8c40d0d
Fixed to comply with the Tuple API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
3401
diff
changeset
|
3027 #if defined(USE_REGEX_PCRE) |
2313 | 3028 if ( regcomp( ®ex , regex_pattern , REG_NOSUB | REG_ICASE | REG_UTF8 ) == 0 ) |
3490
602ec8c40d0d
Fixed to comply with the Tuple API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
3401
diff
changeset
|
3029 #else |
2313 | 3030 if ( regcomp( ®ex , regex_pattern , REG_NOSUB | REG_ICASE ) == 0 ) |
3490
602ec8c40d0d
Fixed to comply with the Tuple API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
3401
diff
changeset
|
3031 #endif |
2313 | 3032 { |
3033 GList *tfound_list = NULL; | |
3034 if ( is_first_search == TRUE ) entry_list = playlist->entries; | |
3035 else entry_list = found_list; /* use found_list */ | |
3036 for ( ; entry_list ; entry_list = g_list_next(entry_list) ) | |
3037 { | |
3038 PlaylistEntry *entry = entry_list->data; | |
3863
dd5c459c5f2d
fix search and select. (bugzilla #29)
William Pitcock <nenolod@atheme.org>
parents:
3784
diff
changeset
|
3039 if ( entry->tuple != NULL ) |
2313 | 3040 { |
3863
dd5c459c5f2d
fix search and select. (bugzilla #29)
William Pitcock <nenolod@atheme.org>
parents:
3784
diff
changeset
|
3041 track_name = tuple_get_string( entry->tuple, FIELD_TITLE, NULL ); |
dd5c459c5f2d
fix search and select. (bugzilla #29)
William Pitcock <nenolod@atheme.org>
parents:
3784
diff
changeset
|
3042 if (( track_name != NULL ) && |
dd5c459c5f2d
fix search and select. (bugzilla #29)
William Pitcock <nenolod@atheme.org>
parents:
3784
diff
changeset
|
3043 ( regexec( ®ex , track_name , 0 , NULL , 0 ) == 0 ) ) |
dd5c459c5f2d
fix search and select. (bugzilla #29)
William Pitcock <nenolod@atheme.org>
parents:
3784
diff
changeset
|
3044 { |
dd5c459c5f2d
fix search and select. (bugzilla #29)
William Pitcock <nenolod@atheme.org>
parents:
3784
diff
changeset
|
3045 tfound_list = g_list_append( tfound_list , entry ); |
dd5c459c5f2d
fix search and select. (bugzilla #29)
William Pitcock <nenolod@atheme.org>
parents:
3784
diff
changeset
|
3046 } |
2313 | 3047 } |
3048 } | |
3049 g_list_free( found_list ); /* wipe old found_list */ | |
3050 found_list = tfound_list; /* move tfound_list in found_list */ | |
3051 regfree( ®ex ); | |
3052 } | |
3053 is_first_search = FALSE; | |
3054 } | |
3055 | |
3863
dd5c459c5f2d
fix search and select. (bugzilla #29)
William Pitcock <nenolod@atheme.org>
parents:
3784
diff
changeset
|
3056 if ( (regex_pattern = tuple_get_string(tuple, FIELD_ALBUM, NULL)) != NULL && |
dd5c459c5f2d
fix search and select. (bugzilla #29)
William Pitcock <nenolod@atheme.org>
parents:
3784
diff
changeset
|
3057 (*regex_pattern != '\0') ) |
2313 | 3058 { |
3059 /* match by album_name */ | |
3060 regex_t regex; | |
3490
602ec8c40d0d
Fixed to comply with the Tuple API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
3401
diff
changeset
|
3061 #if defined(USE_REGEX_PCRE) |
2313 | 3062 if ( regcomp( ®ex , regex_pattern , REG_NOSUB | REG_ICASE | REG_UTF8 ) == 0 ) |
3490
602ec8c40d0d
Fixed to comply with the Tuple API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
3401
diff
changeset
|
3063 #else |
2313 | 3064 if ( regcomp( ®ex , regex_pattern , REG_NOSUB | REG_ICASE ) == 0 ) |
3490
602ec8c40d0d
Fixed to comply with the Tuple API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
3401
diff
changeset
|
3065 #endif |
2313 | 3066 { |
3067 GList *tfound_list = NULL; | |
3068 if ( is_first_search == TRUE ) entry_list = playlist->entries; | |
3069 else entry_list = found_list; /* use found_list */ | |
3070 for ( ; entry_list ; entry_list = g_list_next(entry_list) ) | |
3071 { | |
3072 PlaylistEntry *entry = entry_list->data; | |
3863
dd5c459c5f2d
fix search and select. (bugzilla #29)
William Pitcock <nenolod@atheme.org>
parents:
3784
diff
changeset
|
3073 if ( entry->tuple != NULL ) |
2313 | 3074 { |
3863
dd5c459c5f2d
fix search and select. (bugzilla #29)
William Pitcock <nenolod@atheme.org>
parents:
3784
diff
changeset
|
3075 album_name = tuple_get_string( entry->tuple, FIELD_ALBUM, NULL ); |
dd5c459c5f2d
fix search and select. (bugzilla #29)
William Pitcock <nenolod@atheme.org>
parents:
3784
diff
changeset
|
3076 if ( ( album_name != NULL ) && |
dd5c459c5f2d
fix search and select. (bugzilla #29)
William Pitcock <nenolod@atheme.org>
parents:
3784
diff
changeset
|
3077 ( regexec( ®ex , album_name , 0 , NULL , 0 ) == 0 ) ) |
dd5c459c5f2d
fix search and select. (bugzilla #29)
William Pitcock <nenolod@atheme.org>
parents:
3784
diff
changeset
|
3078 { |
dd5c459c5f2d
fix search and select. (bugzilla #29)
William Pitcock <nenolod@atheme.org>
parents:
3784
diff
changeset
|
3079 tfound_list = g_list_append( tfound_list , entry ); |
dd5c459c5f2d
fix search and select. (bugzilla #29)
William Pitcock <nenolod@atheme.org>
parents:
3784
diff
changeset
|
3080 } |
2313 | 3081 } |
3082 } | |
3083 g_list_free( found_list ); /* wipe old found_list */ | |
3084 found_list = tfound_list; /* move tfound_list in found_list */ | |
3085 regfree( ®ex ); | |
3086 } | |
3087 is_first_search = FALSE; | |
3088 } | |
3089 | |
3863
dd5c459c5f2d
fix search and select. (bugzilla #29)
William Pitcock <nenolod@atheme.org>
parents:
3784
diff
changeset
|
3090 if ( (regex_pattern = tuple_get_string(tuple, FIELD_ARTIST, NULL)) != NULL && |
dd5c459c5f2d
fix search and select. (bugzilla #29)
William Pitcock <nenolod@atheme.org>
parents:
3784
diff
changeset
|
3091 (*regex_pattern != '\0') ) |
2313 | 3092 { |
3093 /* match by performer */ | |
3094 regex_t regex; | |
3490
602ec8c40d0d
Fixed to comply with the Tuple API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
3401
diff
changeset
|
3095 #if defined(USE_REGEX_PCRE) |
2313 | 3096 if ( regcomp( ®ex , regex_pattern , REG_NOSUB | REG_ICASE | REG_UTF8 ) == 0 ) |
3490
602ec8c40d0d
Fixed to comply with the Tuple API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
3401
diff
changeset
|
3097 #else |
2313 | 3098 if ( regcomp( ®ex , regex_pattern , REG_NOSUB | REG_ICASE ) == 0 ) |
3490
602ec8c40d0d
Fixed to comply with the Tuple API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
3401
diff
changeset
|
3099 #endif |
2313 | 3100 { |
3101 GList *tfound_list = NULL; | |
3102 if ( is_first_search == TRUE ) entry_list = playlist->entries; | |
3103 else entry_list = found_list; /* use found_list */ | |
3104 for ( ; entry_list ; entry_list = g_list_next(entry_list) ) | |
3105 { | |
3106 PlaylistEntry *entry = entry_list->data; | |
3863
dd5c459c5f2d
fix search and select. (bugzilla #29)
William Pitcock <nenolod@atheme.org>
parents:
3784
diff
changeset
|
3107 if ( entry->tuple != NULL ) |
2313 | 3108 { |
3863
dd5c459c5f2d
fix search and select. (bugzilla #29)
William Pitcock <nenolod@atheme.org>
parents:
3784
diff
changeset
|
3109 performer = tuple_get_string( entry->tuple, FIELD_ARTIST, NULL ); |
dd5c459c5f2d
fix search and select. (bugzilla #29)
William Pitcock <nenolod@atheme.org>
parents:
3784
diff
changeset
|
3110 if ( ( entry->tuple != NULL ) && ( performer != NULL ) && |
dd5c459c5f2d
fix search and select. (bugzilla #29)
William Pitcock <nenolod@atheme.org>
parents:
3784
diff
changeset
|
3111 ( regexec( ®ex , performer , 0 , NULL , 0 ) == 0 ) ) |
dd5c459c5f2d
fix search and select. (bugzilla #29)
William Pitcock <nenolod@atheme.org>
parents:
3784
diff
changeset
|
3112 { |
dd5c459c5f2d
fix search and select. (bugzilla #29)
William Pitcock <nenolod@atheme.org>
parents:
3784
diff
changeset
|
3113 tfound_list = g_list_append( tfound_list , entry ); |
dd5c459c5f2d
fix search and select. (bugzilla #29)
William Pitcock <nenolod@atheme.org>
parents:
3784
diff
changeset
|
3114 } |
2313 | 3115 } |
3116 } | |
3117 g_list_free( found_list ); /* wipe old found_list */ | |
3118 found_list = tfound_list; /* move tfound_list in found_list */ | |
3119 regfree( ®ex ); | |
3120 } | |
3121 is_first_search = FALSE; | |
3122 } | |
3123 | |
3863
dd5c459c5f2d
fix search and select. (bugzilla #29)
William Pitcock <nenolod@atheme.org>
parents:
3784
diff
changeset
|
3124 if ( (regex_pattern = tuple_get_string(tuple, FIELD_FILE_NAME, NULL)) != NULL && |
dd5c459c5f2d
fix search and select. (bugzilla #29)
William Pitcock <nenolod@atheme.org>
parents:
3784
diff
changeset
|
3125 (*regex_pattern != '\0') ) |
2313 | 3126 { |
3127 /* match by file_name */ | |
3128 regex_t regex; | |
3490
602ec8c40d0d
Fixed to comply with the Tuple API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
3401
diff
changeset
|
3129 #if defined(USE_REGEX_PCRE) |
2313 | 3130 if ( regcomp( ®ex , regex_pattern , REG_NOSUB | REG_ICASE | REG_UTF8 ) == 0 ) |
3490
602ec8c40d0d
Fixed to comply with the Tuple API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
3401
diff
changeset
|
3131 #else |
2313 | 3132 if ( regcomp( ®ex , regex_pattern , REG_NOSUB | REG_ICASE ) == 0 ) |
3490
602ec8c40d0d
Fixed to comply with the Tuple API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
3401
diff
changeset
|
3133 #endif |
2313 | 3134 { |
3135 GList *tfound_list = NULL; | |
3136 if ( is_first_search == TRUE ) entry_list = playlist->entries; | |
3137 else entry_list = found_list; /* use found_list */ | |
3138 for ( ; entry_list ; entry_list = g_list_next(entry_list) ) | |
3139 { | |
3140 PlaylistEntry *entry = entry_list->data; | |
3863
dd5c459c5f2d
fix search and select. (bugzilla #29)
William Pitcock <nenolod@atheme.org>
parents:
3784
diff
changeset
|
3141 if ( entry->tuple != NULL ) |
2313 | 3142 { |
3863
dd5c459c5f2d
fix search and select. (bugzilla #29)
William Pitcock <nenolod@atheme.org>
parents:
3784
diff
changeset
|
3143 file_name = tuple_get_string( entry->tuple, FIELD_FILE_NAME, NULL ); |
dd5c459c5f2d
fix search and select. (bugzilla #29)
William Pitcock <nenolod@atheme.org>
parents:
3784
diff
changeset
|
3144 if ( ( file_name != NULL ) && |
dd5c459c5f2d
fix search and select. (bugzilla #29)
William Pitcock <nenolod@atheme.org>
parents:
3784
diff
changeset
|
3145 ( regexec( ®ex , file_name , 0 , NULL , 0 ) == 0 ) ) |
dd5c459c5f2d
fix search and select. (bugzilla #29)
William Pitcock <nenolod@atheme.org>
parents:
3784
diff
changeset
|
3146 { |
dd5c459c5f2d
fix search and select. (bugzilla #29)
William Pitcock <nenolod@atheme.org>
parents:
3784
diff
changeset
|
3147 tfound_list = g_list_append( tfound_list , entry ); |
dd5c459c5f2d
fix search and select. (bugzilla #29)
William Pitcock <nenolod@atheme.org>
parents:
3784
diff
changeset
|
3148 } |
2313 | 3149 } |
3150 } | |
3151 g_list_free( found_list ); /* wipe old found_list */ | |
3152 found_list = tfound_list; /* move tfound_list in found_list */ | |
3153 regfree( ®ex ); | |
3154 } | |
3155 is_first_search = FALSE; | |
3156 } | |
3157 | |
3158 /* NOTE: action = 0 -> default behaviour, select all matching entries */ | |
3159 /* if some entries are still in found_list, those | |
3160 are what the user is searching for; select them */ | |
3161 for ( sel_list = found_list ; sel_list ; sel_list = g_list_next(sel_list) ) | |
3162 { | |
3163 PlaylistEntry *entry = sel_list->data; | |
3164 entry->selected = TRUE; | |
3165 num_of_entries_found++; | |
3166 } | |
3167 | |
3168 g_list_free( found_list ); | |
3169 | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
3170 PLAYLIST_UNLOCK(playlist); |
2313 | 3171 playlist_recalc_total_time(playlist); |
3923
e9fd46b0893b
- redefine playlist_incr_serial as a macro.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3922
diff
changeset
|
3172 // PLAYLIST_INCR_SERIAL(playlist); //unnecessary? --yaz |
2313 | 3173 |
3174 return num_of_entries_found; | |
3175 } | |
3176 | |
3177 void | |
3178 playlist_select_all(Playlist *playlist, gboolean set) | |
3179 { | |
3180 GList *list; | |
3181 | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
3182 PLAYLIST_LOCK(playlist); |
2313 | 3183 |
3184 for (list = playlist->entries; list; list = g_list_next(list)) { | |
3185 PlaylistEntry *entry = list->data; | |
3186 entry->selected = set; | |
3187 } | |
3188 | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
3189 PLAYLIST_UNLOCK(playlist); |
3922
23e5b148ae7c
to get rid of annoying side effects, an independent function for playlist serial increment has been provided.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3921
diff
changeset
|
3190 playlist_recalc_total_time(playlist); |
2313 | 3191 } |
3192 | |
3193 void | |
3194 playlist_select_invert_all(Playlist *playlist) | |
3195 { | |
3196 GList *list; | |
3197 | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
3198 PLAYLIST_LOCK(playlist); |
2313 | 3199 |
3200 for (list = playlist->entries; list; list = g_list_next(list)) { | |
3201 PlaylistEntry *entry = list->data; | |
3202 entry->selected = !entry->selected; | |
3203 } | |
3204 | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
3205 PLAYLIST_UNLOCK(playlist); |
2313 | 3206 playlist_recalc_total_time(playlist); |
3207 } | |
3208 | |
3209 gboolean | |
3210 playlist_select_invert(Playlist *playlist, guint pos) | |
3211 { | |
3212 GList *list; | |
3213 gboolean invert_ok = FALSE; | |
3214 | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
3215 PLAYLIST_LOCK(playlist); |
2313 | 3216 |
3217 if ((list = g_list_nth(playlist->entries, pos))) { | |
3218 PlaylistEntry *entry = list->data; | |
3219 entry->selected = !entry->selected; | |
3220 invert_ok = TRUE; | |
3221 } | |
3222 | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
3223 PLAYLIST_UNLOCK(playlist); |
3922
23e5b148ae7c
to get rid of annoying side effects, an independent function for playlist serial increment has been provided.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3921
diff
changeset
|
3224 playlist_recalc_total_time(playlist); |
2313 | 3225 |
3226 return invert_ok; | |
3227 } | |
3228 | |
3229 | |
3230 void | |
3231 playlist_select_range(Playlist *playlist, gint min_pos, gint max_pos, gboolean select) | |
3232 { | |
3233 GList *list; | |
3234 gint i; | |
3235 | |
3236 if (min_pos > max_pos) | |
3237 SWAP(min_pos, max_pos); | |
3238 | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
3239 PLAYLIST_LOCK(playlist); |
2313 | 3240 |
3241 list = g_list_nth(playlist->entries, min_pos); | |
3242 for (i = min_pos; i <= max_pos && list; i++) { | |
3243 PlaylistEntry *entry = list->data; | |
3244 entry->selected = select; | |
3245 list = g_list_next(list); | |
3246 } | |
3247 | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
3248 PLAYLIST_UNLOCK(playlist); |
2313 | 3249 |
3250 playlist_recalc_total_time(playlist); | |
3251 } | |
3252 | |
3253 gboolean | |
3254 playlist_read_info_selection(Playlist *playlist) | |
3255 { | |
3256 GList *node; | |
3257 gboolean retval = FALSE; | |
3258 | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
3259 PLAYLIST_LOCK(playlist); |
2313 | 3260 |
3261 for (node = playlist->entries; node; node = g_list_next(node)) { | |
3262 PlaylistEntry *entry = node->data; | |
3263 if (!entry->selected) | |
3264 continue; | |
3265 | |
3266 retval = TRUE; | |
3267 | |
3268 str_replace_in(&entry->title, NULL); | |
3269 entry->length = -1; | |
3270 | |
3271 /* invalidate mtime to reread */ | |
3272 if (entry->tuple != NULL) | |
3490
602ec8c40d0d
Fixed to comply with the Tuple API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
3401
diff
changeset
|
3273 tuple_associate_int(entry->tuple, FIELD_MTIME, NULL, -1); /* -1 denotes "non-initialized". now 0 is for stream etc. yaz */ |
2313 | 3274 |
3275 if (!playlist_entry_get_info(entry)) { | |
3276 if (g_list_index(playlist->entries, entry) == -1) | |
3277 /* Entry disappeared while we looked it up. Restart. */ | |
3278 node = playlist->entries; | |
3279 } | |
3280 } | |
3281 | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
3282 PLAYLIST_UNLOCK(playlist); |
2313 | 3283 |
3284 playlistwin_update_list(playlist); | |
3285 playlist_recalc_total_time(playlist); | |
3923
e9fd46b0893b
- redefine playlist_incr_serial as a macro.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3922
diff
changeset
|
3286 PLAYLIST_INCR_SERIAL(playlist); //tentative --yaz |
2313 | 3287 |
3288 return retval; | |
3289 } | |
3290 | |
3291 void | |
3292 playlist_read_info(Playlist *playlist, guint pos) | |
3293 { | |
3294 GList *node; | |
3295 | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
3296 PLAYLIST_LOCK(playlist); |
2313 | 3297 |
3298 if ((node = g_list_nth(playlist->entries, pos))) { | |
3299 PlaylistEntry *entry = node->data; | |
3300 str_replace_in(&entry->title, NULL); | |
3301 entry->length = -1; | |
3302 playlist_entry_get_info(entry); | |
3303 } | |
3304 | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
3305 PLAYLIST_UNLOCK(playlist); |
2313 | 3306 |
3307 playlistwin_update_list(playlist); | |
3308 playlist_recalc_total_time(playlist); | |
3923
e9fd46b0893b
- redefine playlist_incr_serial as a macro.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3922
diff
changeset
|
3309 PLAYLIST_INCR_SERIAL(playlist); //tentative --yaz |
2313 | 3310 } |
3311 | |
3312 Playlist * | |
3313 playlist_get_active(void) | |
3314 { | |
3315 if (playlists_iter != NULL) | |
3316 return (Playlist *) playlists_iter->data; | |
3317 | |
2736 | 3318 if (playlists) |
3319 return (Playlist *) playlists->data; | |
3320 | |
3321 return NULL; | |
2313 | 3322 } |
3323 | |
3324 void | |
3325 playlist_set_shuffle(gboolean shuffle) | |
3326 { | |
3327 Playlist *playlist = playlist_get_active(); | |
3328 if (!playlist) | |
3329 return; | |
3330 | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
3331 PLAYLIST_LOCK(playlist); |
2313 | 3332 |
3333 playlist_position_before_jump = NULL; | |
3334 | |
3335 cfg.shuffle = shuffle; | |
3336 playlist_generate_shuffle_list_nolock(playlist); | |
3337 | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
3338 PLAYLIST_UNLOCK(playlist); |
2313 | 3339 } |
3340 | |
3341 Playlist * | |
3342 playlist_new(void) | |
3343 { | |
3344 Playlist *playlist = g_new0(Playlist, 1); | |
3345 playlist->mutex = g_mutex_new(); | |
3346 playlist->loading_playlist = FALSE; | |
3477
57f4971b7086
New functions for associating a filename with a playlist. Made title/filename setting more consistent.
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3476
diff
changeset
|
3347 playlist->title = NULL; |
57f4971b7086
New functions for associating a filename with a playlist. Made title/filename setting more consistent.
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3476
diff
changeset
|
3348 playlist->filename = NULL; |
2313 | 3349 playlist_clear(playlist); |
3920
c2b2828186ba
- serial number has been added to playlist structure so that changes of the current playlist can be notified.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3867
diff
changeset
|
3350 playlist->tail = NULL; |
c2b2828186ba
- serial number has been added to playlist structure so that changes of the current playlist can be notified.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3867
diff
changeset
|
3351 playlist->attribute = PLAYLIST_PLAIN; |
c2b2828186ba
- serial number has been added to playlist structure so that changes of the current playlist can be notified.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3867
diff
changeset
|
3352 playlist->serial = 0; |
2313 | 3353 |
3354 return playlist; | |
3355 } | |
3356 | |
3357 void | |
3358 playlist_free(Playlist *playlist) | |
3359 { | |
3467
5a6896b6000f
Implement playlist_get_info_scanning() with mutex locking.
Matti Hamalainen <ccr@tnsp.org>
parents:
3460
diff
changeset
|
3360 if (!playlist) |
5a6896b6000f
Implement playlist_get_info_scanning() with mutex locking.
Matti Hamalainen <ccr@tnsp.org>
parents:
3460
diff
changeset
|
3361 return; |
5a6896b6000f
Implement playlist_get_info_scanning() with mutex locking.
Matti Hamalainen <ccr@tnsp.org>
parents:
3460
diff
changeset
|
3362 |
2313 | 3363 g_mutex_free( playlist->mutex ); |
3364 g_free( playlist ); | |
3920
c2b2828186ba
- serial number has been added to playlist structure so that changes of the current playlist can be notified.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3867
diff
changeset
|
3365 playlist = NULL; //XXX lead to crash? --yaz |
2313 | 3366 } |
3367 | |
3368 Playlist * | |
3369 playlist_new_from_selected(void) | |
3370 { | |
3371 Playlist *newpl = playlist_new(); | |
3372 Playlist *playlist = playlist_get_active(); | |
3373 GList *list = playlist_get_selected(playlist); | |
3374 | |
3375 playlist_add_playlist( newpl ); | |
3376 | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
3377 PLAYLIST_LOCK(playlist); |
2313 | 3378 |
3379 while ( list != NULL ) | |
3380 { | |
3381 PlaylistEntry *entry = g_list_nth_data(playlist->entries, GPOINTER_TO_INT(list->data)); | |
3382 if ( entry->filename != NULL ) /* paranoid? oh well... */ | |
3383 playlist_add( newpl , entry->filename ); | |
3384 list = g_list_next(list); | |
3385 } | |
3386 | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
3387 PLAYLIST_UNLOCK(playlist); |
2313 | 3388 |
3389 playlist_recalc_total_time(newpl); | |
3390 playlistwin_update_list(playlist); | |
3621
2d6106656276
Notify playlist manager of more changes
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3583
diff
changeset
|
3391 playlist_manager_update(); |
2313 | 3392 |
3393 return newpl; | |
3394 } | |
3395 | |
3396 const gchar * | |
3397 playlist_get_filename_to_play(Playlist *playlist) | |
3398 { | |
3399 const gchar *filename = NULL; | |
3400 | |
3401 if (!playlist) | |
3402 return NULL; | |
3403 | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
3404 PLAYLIST_LOCK(playlist); |
2313 | 3405 |
3406 if (!playlist->position) { | |
3407 if (cfg.shuffle) | |
3408 playlist->position = playlist->shuffle->data; | |
3409 else | |
3410 playlist->position = playlist->entries->data; | |
3411 } | |
3412 | |
3413 filename = playlist->position->filename; | |
3414 | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
3415 PLAYLIST_UNLOCK(playlist); |
2313 | 3416 |
3417 return filename; | |
3418 } | |
3419 | |
3420 PlaylistEntry * | |
3421 playlist_get_entry_to_play(Playlist *playlist) | |
3422 { | |
3423 if (!playlist) | |
3424 return NULL; | |
3425 | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
3426 PLAYLIST_LOCK(playlist); |
2313 | 3427 |
3428 if (!playlist->position) { | |
3429 if (cfg.shuffle) | |
3430 playlist->position = playlist->shuffle->data; | |
3431 else | |
3432 playlist->position = playlist->entries->data; | |
3433 } | |
3434 | |
3468
440877c9360e
Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not
Matti Hamalainen <ccr@tnsp.org>
parents:
3467
diff
changeset
|
3435 PLAYLIST_UNLOCK(playlist); |
2313 | 3436 |
3437 return playlist->position; | |
3438 } | |
3474
adc785ee517b
Add playlist_playlists_equal for comparing entire playlists
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3473
diff
changeset
|
3439 |
adc785ee517b
Add playlist_playlists_equal for comparing entire playlists
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3473
diff
changeset
|
3440 gboolean |
adc785ee517b
Add playlist_playlists_equal for comparing entire playlists
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3473
diff
changeset
|
3441 playlist_playlists_equal(Playlist *p1, Playlist *p2) |
adc785ee517b
Add playlist_playlists_equal for comparing entire playlists
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3473
diff
changeset
|
3442 { |
adc785ee517b
Add playlist_playlists_equal for comparing entire playlists
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3473
diff
changeset
|
3443 GList *l1, *l2; |
adc785ee517b
Add playlist_playlists_equal for comparing entire playlists
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3473
diff
changeset
|
3444 PlaylistEntry *e1, *e2; |
adc785ee517b
Add playlist_playlists_equal for comparing entire playlists
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3473
diff
changeset
|
3445 if (!p1 || !p2) return FALSE; |
adc785ee517b
Add playlist_playlists_equal for comparing entire playlists
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3473
diff
changeset
|
3446 l1 = p1->entries; |
adc785ee517b
Add playlist_playlists_equal for comparing entire playlists
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3473
diff
changeset
|
3447 l2 = p2->entries; |
adc785ee517b
Add playlist_playlists_equal for comparing entire playlists
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3473
diff
changeset
|
3448 do { |
adc785ee517b
Add playlist_playlists_equal for comparing entire playlists
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3473
diff
changeset
|
3449 if (!l1 && !l2) break; |
adc785ee517b
Add playlist_playlists_equal for comparing entire playlists
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3473
diff
changeset
|
3450 if (!l1 || !l2) return FALSE; /* different length */ |
adc785ee517b
Add playlist_playlists_equal for comparing entire playlists
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3473
diff
changeset
|
3451 e1 = (PlaylistEntry *) l1->data; |
adc785ee517b
Add playlist_playlists_equal for comparing entire playlists
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3473
diff
changeset
|
3452 e2 = (PlaylistEntry *) l2->data; |
adc785ee517b
Add playlist_playlists_equal for comparing entire playlists
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3473
diff
changeset
|
3453 if (strcmp(e1->filename, e2->filename) != 0) return FALSE; |
adc785ee517b
Add playlist_playlists_equal for comparing entire playlists
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3473
diff
changeset
|
3454 l1 = l1->next; |
adc785ee517b
Add playlist_playlists_equal for comparing entire playlists
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3473
diff
changeset
|
3455 l2 = l2->next; |
adc785ee517b
Add playlist_playlists_equal for comparing entire playlists
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3473
diff
changeset
|
3456 } while(1); |
adc785ee517b
Add playlist_playlists_equal for comparing entire playlists
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3473
diff
changeset
|
3457 return TRUE; |
adc785ee517b
Add playlist_playlists_equal for comparing entire playlists
Kieran Clancy <clancy.kieran+audacious@gmail.com>
parents:
3473
diff
changeset
|
3458 } |
3934
e924c9ee3958
when "Detect file formats on demand" is specified, filter unplayable files on loading by the hash table of all available extensions.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3923
diff
changeset
|
3459 |
e924c9ee3958
when "Detect file formats on demand" is specified, filter unplayable files on loading by the hash table of all available extensions.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3923
diff
changeset
|
3460 static gboolean |
e924c9ee3958
when "Detect file formats on demand" is specified, filter unplayable files on loading by the hash table of all available extensions.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3923
diff
changeset
|
3461 filter_by_extension(const gchar *uri) |
e924c9ee3958
when "Detect file formats on demand" is specified, filter unplayable files on loading by the hash table of all available extensions.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3923
diff
changeset
|
3462 { |
3945
0b93c2b0cd59
make filter_by_extension() case insensitive.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3934
diff
changeset
|
3463 gchar *base, *ext, *lext, *filename; |
3934
e924c9ee3958
when "Detect file formats on demand" is specified, filter unplayable files on loading by the hash table of all available extensions.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3923
diff
changeset
|
3464 gchar *tmp = g_filename_from_uri(uri, NULL, NULL); |
3945
0b93c2b0cd59
make filter_by_extension() case insensitive.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3934
diff
changeset
|
3465 gboolean rv; |
0b93c2b0cd59
make filter_by_extension() case insensitive.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3934
diff
changeset
|
3466 |
3934
e924c9ee3958
when "Detect file formats on demand" is specified, filter unplayable files on loading by the hash table of all available extensions.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3923
diff
changeset
|
3467 filename = g_strdup(tmp ? tmp : uri); |
e924c9ee3958
when "Detect file formats on demand" is specified, filter unplayable files on loading by the hash table of all available extensions.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3923
diff
changeset
|
3468 g_free(tmp); |
3947
eb20411bb9e1
fixed bug in extension filtering function
mf0102 <0102@gmx.at>
parents:
3945
diff
changeset
|
3469 |
3934
e924c9ee3958
when "Detect file formats on demand" is specified, filter unplayable files on loading by the hash table of all available extensions.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3923
diff
changeset
|
3470 base = g_path_get_basename(filename); |
3959
a575c29cee05
- revive on-demand metadata retrieving. in the combination with "Detect file formats on demand", now audacious can load large directory in a few seconds.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3947
diff
changeset
|
3471 ext = strrchr(base, '.'); |
3934
e924c9ee3958
when "Detect file formats on demand" is specified, filter unplayable files on loading by the hash table of all available extensions.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3923
diff
changeset
|
3472 |
e924c9ee3958
when "Detect file formats on demand" is specified, filter unplayable files on loading by the hash table of all available extensions.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3923
diff
changeset
|
3473 if(!ext) { |
3947
eb20411bb9e1
fixed bug in extension filtering function
mf0102 <0102@gmx.at>
parents:
3945
diff
changeset
|
3474 g_free(base); |
eb20411bb9e1
fixed bug in extension filtering function
mf0102 <0102@gmx.at>
parents:
3945
diff
changeset
|
3475 return FALSE; |
3934
e924c9ee3958
when "Detect file formats on demand" is specified, filter unplayable files on loading by the hash table of all available extensions.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3923
diff
changeset
|
3476 } |
e924c9ee3958
when "Detect file formats on demand" is specified, filter unplayable files on loading by the hash table of all available extensions.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3923
diff
changeset
|
3477 |
3959
a575c29cee05
- revive on-demand metadata retrieving. in the combination with "Detect file formats on demand", now audacious can load large directory in a few seconds.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3947
diff
changeset
|
3478 lext = g_ascii_strdown(ext+1, -1); |
a575c29cee05
- revive on-demand metadata retrieving. in the combination with "Detect file formats on demand", now audacious can load large directory in a few seconds.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3947
diff
changeset
|
3479 g_free(base); |
3945
0b93c2b0cd59
make filter_by_extension() case insensitive.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3934
diff
changeset
|
3480 |
0b93c2b0cd59
make filter_by_extension() case insensitive.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3934
diff
changeset
|
3481 if(g_hash_table_lookup(ext_hash, lext)) |
0b93c2b0cd59
make filter_by_extension() case insensitive.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3934
diff
changeset
|
3482 rv = TRUE; |
3934
e924c9ee3958
when "Detect file formats on demand" is specified, filter unplayable files on loading by the hash table of all available extensions.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3923
diff
changeset
|
3483 else |
3945
0b93c2b0cd59
make filter_by_extension() case insensitive.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3934
diff
changeset
|
3484 rv = FALSE; |
0b93c2b0cd59
make filter_by_extension() case insensitive.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3934
diff
changeset
|
3485 |
0b93c2b0cd59
make filter_by_extension() case insensitive.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3934
diff
changeset
|
3486 g_free(lext); |
0b93c2b0cd59
make filter_by_extension() case insensitive.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3934
diff
changeset
|
3487 return rv; |
3934
e924c9ee3958
when "Detect file formats on demand" is specified, filter unplayable files on loading by the hash table of all available extensions.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3923
diff
changeset
|
3488 } |