core/playlists: Select queued tracks playlist when adding tracks
This lets me "pause" playing queued tracks in favor of other playlists. I remember the previous playlist so we can resume track picking once the queued tracks playlist is empty. Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
parent
f0e9e1f1e4
commit
ecebd20a0b
|
@ -3,9 +3,12 @@
|
|||
*/
|
||||
#include <core/playlist.h>
|
||||
#include <core/settings.h>
|
||||
#include <core/string.h>
|
||||
|
||||
static const gchar *SETTINGS_CUR_TYPE = "core.playlist.cur.type";
|
||||
static const gchar *SETTINGS_CUR_ID = "core.playlist.cur.id";
|
||||
static const gchar *SETTINGS_CUR_TYPE = "core.playlist.cur.type";
|
||||
static const gchar *SETTINGS_CUR_ID = "core.playlist.cur.id";
|
||||
static const gchar *SETTINGS_PREV_TYPE = "core.playlist.prev.type";
|
||||
static const gchar *SETTINGS_PREV_ID = "core.playlist.prev.id";
|
||||
|
||||
struct playlist_type *playlist_types[] = {
|
||||
[PL_SYSTEM] = &pl_system,
|
||||
|
@ -23,8 +26,11 @@ void playlist_init(struct queue_ops *ops)
|
|||
pl_library_init(ops);
|
||||
|
||||
if (!settings_has(SETTINGS_CUR_TYPE) ||
|
||||
!settings_has(SETTINGS_CUR_ID))
|
||||
!settings_has(SETTINGS_CUR_ID)) {
|
||||
playlist_select(PL_SYSTEM, "Collection");
|
||||
if (playlist_size(PL_SYSTEM, "Queued Tracks") > 0)
|
||||
playlist_select(PL_SYSTEM, "Queued Tracks");
|
||||
}
|
||||
}
|
||||
|
||||
void playlist_deinit()
|
||||
|
@ -47,8 +53,10 @@ bool playlist_select(enum playlist_type_t type, const gchar *name)
|
|||
if (!playlist_types[type]->pl_can_select(name))
|
||||
return false;
|
||||
|
||||
settings_set(SETTINGS_CUR_TYPE, type);
|
||||
settings_set(SETTINGS_CUR_ID, playlist_get_id(type, name));
|
||||
settings_set(SETTINGS_PREV_TYPE, settings_get(SETTINGS_CUR_TYPE));
|
||||
settings_set(SETTINGS_PREV_ID, settings_get(SETTINGS_CUR_ID));
|
||||
settings_set(SETTINGS_CUR_TYPE, type);
|
||||
settings_set(SETTINGS_CUR_ID, playlist_get_id(type, name));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -65,9 +73,15 @@ bool playlist_delete(enum playlist_type_t type, const gchar *name)
|
|||
bool playlist_add(enum playlist_type_t type, const gchar *name,
|
||||
struct track *track)
|
||||
{
|
||||
bool ret;
|
||||
|
||||
if (!track)
|
||||
return false;
|
||||
return playlist_types[type]->pl_add_track(name, track);
|
||||
|
||||
ret = playlist_types[type]->pl_add_track(name, track);
|
||||
if (type == PL_SYSTEM && string_match(name, "Queued Tracks"))
|
||||
playlist_select(PL_SYSTEM, "Queued Tracks");
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool playlist_remove(enum playlist_type_t type, const gchar *name,
|
||||
|
@ -119,17 +133,15 @@ void playlist_sort(enum playlist_type_t type, const gchar *name,
|
|||
struct track *playlist_next(void)
|
||||
{
|
||||
enum playlist_type_t type = settings_get(SETTINGS_CUR_TYPE);
|
||||
unsigned int id = settings_get(SETTINGS_CUR_ID);
|
||||
struct track *track;
|
||||
gchar *name;
|
||||
unsigned int id = settings_get(SETTINGS_CUR_ID);
|
||||
gchar *name = playlist_get_name(type, id);
|
||||
struct track *track = playlist_types[type]->pl_next(name);
|
||||
|
||||
if (playlist_size(PL_SYSTEM, "Queued Tracks") > 0) {
|
||||
type = PL_SYSTEM;
|
||||
id = SYS_PL_QUEUED;
|
||||
if (playlist_size(type, name) == 0) {
|
||||
settings_set(SETTINGS_CUR_ID, settings_get(SETTINGS_PREV_ID));
|
||||
settings_set(SETTINGS_CUR_TYPE, settings_get(SETTINGS_PREV_TYPE));
|
||||
}
|
||||
|
||||
name = playlist_get_name(type, id);
|
||||
track = playlist_types[type]->pl_next(name);
|
||||
g_free(name);
|
||||
return track;
|
||||
}
|
||||
|
|
|
@ -170,7 +170,7 @@ static struct sys_playlist sys_queued = {
|
|||
.spl_init = sys_pl_queued_init,
|
||||
.spl_save = sys_pl_save_full,
|
||||
.spl_load = sys_pl_load_full,
|
||||
.spl_can_select = playlist_noop_can_select,
|
||||
.spl_can_select = playlist_generic_can_select,
|
||||
.spl_add = playlist_generic_add_track,
|
||||
.spl_remove = playlist_generic_remove_track,
|
||||
.spl_clear = playlist_generic_clear,
|
||||
|
|
|
@ -146,6 +146,7 @@ static void test_next()
|
|||
g_assert_cmpuint(playlist_size(PL_SYSTEM, "Queued Tracks"), ==, 0);
|
||||
|
||||
/* Tracks should now be picked from the collection. */
|
||||
playlist_select(PL_SYSTEM, "Collection");
|
||||
for (i = 1; i <= 3; i++) {
|
||||
if (i < 3)
|
||||
g_assert_cmpuint(audio_next()->tr_track, ==, i);
|
||||
|
|
|
@ -178,15 +178,18 @@ static void test_queued()
|
|||
__test_playlist_noselect("Queued Tracks");
|
||||
__test_playlist_random("Queued Tracks");
|
||||
__test_playlist_add("Queued Tracks");
|
||||
__test_playlist_noselect("Queued Tracks");
|
||||
__test_playlist_select("Queued Tracks", SYS_PL_QUEUED);
|
||||
__test_playlist_reinit("Queued Tracks", 2, true, true);
|
||||
|
||||
g_assert(playlist_next() == track_get(0));
|
||||
g_assert_cmpuint(playlist_size(PL_SYSTEM, "Queued Tracks"), ==, 1);
|
||||
playlist_select(PL_SYSTEM, "Collection");
|
||||
g_assert(playlist_next() == track_get(0));
|
||||
g_assert_cmpuint(playlist_size(PL_SYSTEM, "Queued Tracks"), ==, 1);
|
||||
playlist_select(PL_SYSTEM, "Queued Tracks");
|
||||
g_assert(playlist_next() == track_get(1));
|
||||
g_assert_cmpuint(playlist_size(PL_SYSTEM, "Queued Tracks"), ==, 0);
|
||||
g_assert_nonnull(playlist_next());
|
||||
g_assert(playlist_next() == track_get(1));
|
||||
|
||||
__test_playlist_add("Queued Tracks");
|
||||
__test_playlist_remove("Queued Tracks");
|
||||
|
|
Loading…
Reference in New Issue