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