core/playlist: Add playlist_selected() for selected tracks
In most cases this function just triggers a UI update, but system playlists have a little extra bookkeeping to do to remove the track from the Queued Tracks playlist. Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
parent
07bf09c2ad
commit
bd8df2a169
|
@ -52,7 +52,7 @@ static struct track *__audio_do_load(struct track *track, GstState state)
|
||||||
|
|
||||||
if (track) {
|
if (track) {
|
||||||
__audio_gst_load(track, state);
|
__audio_gst_load(track, state);
|
||||||
queue_updated(&playlist_lookup(PL_SYSTEM, "Collection")->pl_queue, track);
|
playlist_selected(track);
|
||||||
}
|
}
|
||||||
|
|
||||||
playlist_played(prev);
|
playlist_played(prev);
|
||||||
|
|
|
@ -72,6 +72,18 @@ void playlist_played(struct track *track)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void playlist_selected(struct track *track)
|
||||||
|
{
|
||||||
|
unsigned int i;
|
||||||
|
if (track) {
|
||||||
|
for (i = 0; i < PL_MAX_TYPE; i++)
|
||||||
|
playlist_types[i]->pl_selected(track);
|
||||||
|
|
||||||
|
if (playlist_size(current) == 0)
|
||||||
|
playlist_select(previous);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
struct playlist *playlist_new(enum playlist_type_t type, const gchar *name)
|
struct playlist *playlist_new(enum playlist_type_t type, const gchar *name)
|
||||||
{
|
{
|
||||||
if (type < PL_MAX_TYPE && playlist_types[type]->pl_new)
|
if (type < PL_MAX_TYPE && playlist_types[type]->pl_new)
|
||||||
|
@ -145,8 +157,6 @@ struct track *playlist_next(void)
|
||||||
track = current->pl_ops->pl_next(current);
|
track = current->pl_ops->pl_next(current);
|
||||||
if (track)
|
if (track)
|
||||||
playlist_types[current->pl_type]->pl_save();
|
playlist_types[current->pl_type]->pl_save();
|
||||||
if (playlist_size(current) == 0)
|
|
||||||
playlist_select(previous);
|
|
||||||
return track;
|
return track;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -121,10 +121,11 @@ static void pl_artist_played(struct track *track)
|
||||||
|
|
||||||
|
|
||||||
struct playlist_type pl_artist = {
|
struct playlist_type pl_artist = {
|
||||||
.pl_save = pl_artist_save,
|
.pl_save = pl_artist_save,
|
||||||
.pl_lookup = pl_artist_lookup,
|
.pl_lookup = pl_artist_lookup,
|
||||||
.pl_get = pl_artist_get,
|
.pl_get = pl_artist_get,
|
||||||
.pl_played = pl_artist_played,
|
.pl_played = pl_artist_played,
|
||||||
|
.pl_selected = pl_artist_played,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -252,11 +252,12 @@ static void pl_library_played(struct track *track)
|
||||||
|
|
||||||
|
|
||||||
struct playlist_type pl_library = {
|
struct playlist_type pl_library = {
|
||||||
.pl_save = pl_library_save,
|
.pl_save = pl_library_save,
|
||||||
.pl_lookup = pl_library_lookup,
|
.pl_lookup = pl_library_lookup,
|
||||||
.pl_get = pl_library_get,
|
.pl_get = pl_library_get,
|
||||||
.pl_new = pl_library_new,
|
.pl_new = pl_library_new,
|
||||||
.pl_played = pl_library_played,
|
.pl_played = pl_library_played,
|
||||||
|
.pl_selected = pl_library_played,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -163,21 +163,11 @@ static bool sys_pl_queued_load()
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct track *sys_pl_queued_next(struct playlist *playlist)
|
|
||||||
{
|
|
||||||
struct track *track = playlist_generic_next(playlist);
|
|
||||||
unsigned int pos = playlist->pl_queue.q_cur.it_pos;
|
|
||||||
|
|
||||||
queue_iter_prev(&playlist->pl_queue.q_cur);
|
|
||||||
queue_remove(&playlist->pl_queue, pos);
|
|
||||||
return track;
|
|
||||||
}
|
|
||||||
|
|
||||||
static struct playlist_ops queued_ops = {
|
static struct playlist_ops queued_ops = {
|
||||||
.pl_add = playlist_generic_add_track,
|
.pl_add = playlist_generic_add_track,
|
||||||
.pl_can_select = playlist_generic_can_select,
|
.pl_can_select = playlist_generic_can_select,
|
||||||
.pl_delete = sys_pl_delete_clear,
|
.pl_delete = sys_pl_delete_clear,
|
||||||
.pl_next = sys_pl_queued_next,
|
.pl_next = playlist_generic_next,
|
||||||
.pl_remove = playlist_generic_remove_track,
|
.pl_remove = playlist_generic_remove_track,
|
||||||
.pl_set_flag = playlist_generic_set_flag,
|
.pl_set_flag = playlist_generic_set_flag,
|
||||||
.pl_sort = playlist_generic_sort,
|
.pl_sort = playlist_generic_sort,
|
||||||
|
@ -382,12 +372,23 @@ static void pl_system_played(struct track *track)
|
||||||
sys_pl_update(pl_system_lookup("Least Played"));
|
sys_pl_update(pl_system_lookup("Least Played"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void pl_system_selected(struct track *track)
|
||||||
|
{
|
||||||
|
unsigned int i;
|
||||||
|
|
||||||
|
queue_iter_prev(&pl_system_get(SYS_PL_QUEUED)->pl_queue.q_cur);
|
||||||
|
queue_remove_all(&pl_system_get(SYS_PL_QUEUED)->pl_queue, track);
|
||||||
|
for (i = 0; i < SYS_PL_NUM_PLAYLISTS; i++)
|
||||||
|
queue_updated(&pl_system_get(i)->pl_queue, track);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
struct playlist_type pl_system = {
|
struct playlist_type pl_system = {
|
||||||
.pl_save = pl_system_save,
|
.pl_save = pl_system_save,
|
||||||
.pl_lookup = pl_system_lookup,
|
.pl_lookup = pl_system_lookup,
|
||||||
.pl_get = pl_system_get,
|
.pl_get = pl_system_get,
|
||||||
.pl_played = pl_system_played,
|
.pl_played = pl_system_played,
|
||||||
|
.pl_selected = pl_system_selected,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -127,11 +127,12 @@ static void pl_user_played(struct track *track)
|
||||||
|
|
||||||
|
|
||||||
struct playlist_type pl_user = {
|
struct playlist_type pl_user = {
|
||||||
.pl_save = pl_user_save,
|
.pl_save = pl_user_save,
|
||||||
.pl_lookup = pl_user_lookup,
|
.pl_lookup = pl_user_lookup,
|
||||||
.pl_get = pl_user_get,
|
.pl_get = pl_user_get,
|
||||||
.pl_new = pl_user_new,
|
.pl_new = pl_user_new,
|
||||||
.pl_played = pl_user_played,
|
.pl_played = pl_user_played,
|
||||||
|
.pl_selected = pl_user_played,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -25,6 +25,9 @@ void playlist_save();
|
||||||
/* Called to notify all playlists that a track has been played. */
|
/* Called to notify all playlists that a track has been played. */
|
||||||
void playlist_played(struct track *);
|
void playlist_played(struct track *);
|
||||||
|
|
||||||
|
/* Called to notify all playlists that a track has been selected. */
|
||||||
|
void playlist_selected(struct track *);
|
||||||
|
|
||||||
|
|
||||||
/* Called to create a new playlist. */
|
/* Called to create a new playlist. */
|
||||||
struct playlist *playlist_new(enum playlist_type_t, const gchar *);
|
struct playlist *playlist_new(enum playlist_type_t, const gchar *);
|
||||||
|
|
|
@ -75,6 +75,9 @@ struct playlist_type {
|
||||||
|
|
||||||
/* Called to notify that a track has been played. */
|
/* Called to notify that a track has been played. */
|
||||||
void (*pl_played)(struct track *);
|
void (*pl_played)(struct track *);
|
||||||
|
|
||||||
|
/* Called to notify that a track has been selected. */
|
||||||
|
void (*pl_selected)(struct track *);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -32,6 +32,8 @@ static void test_null()
|
||||||
g_assert(playlist_current() == playlist_lookup(PL_SYSTEM, "Collection"));
|
g_assert(playlist_current() == playlist_lookup(PL_SYSTEM, "Collection"));
|
||||||
g_assert_false(playlist_select(NULL));
|
g_assert_false(playlist_select(NULL));
|
||||||
g_assert(playlist_current() == playlist_lookup(PL_SYSTEM, "Collection"));
|
g_assert(playlist_current() == playlist_lookup(PL_SYSTEM, "Collection"));
|
||||||
|
playlist_selected(NULL);
|
||||||
|
playlist_played(NULL);
|
||||||
|
|
||||||
g_assert_false(playlist_add(NULL, NULL));
|
g_assert_false(playlist_add(NULL, NULL));
|
||||||
g_assert_false(playlist_add(NULL, track_get(0)));
|
g_assert_false(playlist_add(NULL, track_get(0)));
|
||||||
|
|
|
@ -43,6 +43,8 @@ void test_artist()
|
||||||
g_assert_cmpuint(settings_get("core.playlist.cur.id"), ==, 0);
|
g_assert_cmpuint(settings_get("core.playlist.cur.id"), ==, 0);
|
||||||
g_assert(playlist_current() == playlist);
|
g_assert(playlist_current() == playlist);
|
||||||
g_assert_false(playlist_select(playlist));
|
g_assert_false(playlist_select(playlist));
|
||||||
|
|
||||||
|
playlist_selected(track_get(0));
|
||||||
playlist_played(track_get(0));
|
playlist_played(track_get(0));
|
||||||
|
|
||||||
g_assert_cmpuint(playlist_next()->tr_track, ==, 1);
|
g_assert_cmpuint(playlist_next()->tr_track, ==, 1);
|
||||||
|
|
|
@ -65,6 +65,8 @@ void test_library()
|
||||||
g_assert_false(playlist_remove(playlist, track_get(0)));
|
g_assert_false(playlist_remove(playlist, track_get(0)));
|
||||||
g_assert_false(playlist_remove(playlist, track_get(1)));
|
g_assert_false(playlist_remove(playlist, track_get(1)));
|
||||||
g_assert_cmpuint(playlist_size(playlist), ==, 48);
|
g_assert_cmpuint(playlist_size(playlist), ==, 48);
|
||||||
|
|
||||||
|
playlist_selected(track_get(1));
|
||||||
playlist_played(track_get(1));
|
playlist_played(track_get(1));
|
||||||
|
|
||||||
g_assert_false(playlist_get_random(playlist));
|
g_assert_false(playlist_get_random(playlist));
|
||||||
|
|
|
@ -319,10 +319,14 @@ static void test_next()
|
||||||
g_assert(playlist_current() == __test_pl_queued());
|
g_assert(playlist_current() == __test_pl_queued());
|
||||||
|
|
||||||
g_assert(playlist_next() == track_get(0));
|
g_assert(playlist_next() == track_get(0));
|
||||||
|
g_assert_cmpuint(playlist_size(__test_pl_queued()), ==, 2);
|
||||||
|
playlist_selected(track_get(0));
|
||||||
g_assert_cmpuint(playlist_size(__test_pl_queued()), ==, 1);
|
g_assert_cmpuint(playlist_size(__test_pl_queued()), ==, 1);
|
||||||
g_assert(playlist_current() == __test_pl_queued());
|
g_assert(playlist_current() == __test_pl_queued());
|
||||||
|
|
||||||
g_assert(playlist_next() == track_get(1));
|
g_assert(playlist_next() == track_get(1));
|
||||||
|
g_assert_cmpuint(playlist_size(__test_pl_queued()), ==, 1);
|
||||||
|
playlist_selected(track_get(1));
|
||||||
g_assert_cmpuint(playlist_size(__test_pl_queued()), ==, 0);
|
g_assert_cmpuint(playlist_size(__test_pl_queued()), ==, 0);
|
||||||
g_assert(playlist_current() == __test_pl_collection());
|
g_assert(playlist_current() == __test_pl_collection());
|
||||||
|
|
||||||
|
|
|
@ -47,6 +47,8 @@ void test_user()
|
||||||
g_assert(playlist_next() == track_get(0));
|
g_assert(playlist_next() == track_get(0));
|
||||||
g_assert_true(playlist_has(playlist, track_get(0)));
|
g_assert_true(playlist_has(playlist, track_get(0)));
|
||||||
g_assert_cmpuint(playlist_size(playlist), ==, 1);
|
g_assert_cmpuint(playlist_size(playlist), ==, 1);
|
||||||
|
|
||||||
|
playlist_selected(track_get(0));
|
||||||
playlist_played(track_get(0));
|
playlist_played(track_get(0));
|
||||||
|
|
||||||
pl_user_deinit();
|
pl_user_deinit();
|
||||||
|
|
Loading…
Reference in New Issue