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