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