annotate audacious/playlist.c @ 2142:959722e6e277 trunk

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