From 55d5289c0568c0966881da63e408e3ff390460e1 Mon Sep 17 00:00:00 2001 From: ejurgensen Date: Thu, 16 Jul 2020 15:19:33 +0200 Subject: [PATCH] [player] Add settings for persisting repeat, shuffle and consume Closes issue #963 --- src/player.c | 25 +++++++++++++++++++++++-- src/settings.c | 30 ++++++++++++++++++++---------- 2 files changed, 43 insertions(+), 12 deletions(-) diff --git a/src/player.c b/src/player.c index f1e294f9..5d9cb445 100644 --- a/src/player.c +++ b/src/player.c @@ -77,6 +77,7 @@ #include "db.h" #include "logger.h" #include "conffile.h" +#include "settings.h" #include "misc.h" #include "player.h" #include "worker.h" @@ -125,6 +126,11 @@ // know if they should only probe the device, or fully start it. #define PLAYER_ONLY_PROBE (player_state != PLAY_PLAYING) +// Name of settings used by player +#define PLAYER_SETTINGS_MODE_REPEAT "player_mode_repeat" +#define PLAYER_SETTINGS_MODE_SHUFFLE "player_mode_shuffle" +#define PLAYER_SETTINGS_MODE_CONSUME "player_mode_consume" + //#define DEBUG_PLAYER 1 struct spk_enum @@ -294,9 +300,10 @@ static struct commands_base *cmdbase; // from the player thread (where we can't use player_playback_pause) static int player_flush_pending; -// Config values +// Config values and player settings category static int speaker_autoselect; static int clear_queue_on_stop_disabled; +static struct settings_category *player_settings_category; // Player status static enum play_status player_state; @@ -2935,6 +2942,9 @@ repeat_set(void *arg, int *retval) return COMMAND_END; } + // Persist + SETTINGS_SETINT(player_settings_category, PLAYER_SETTINGS_MODE_REPEAT, repeat); + *retval = 0; return COMMAND_END; } @@ -2967,6 +2977,9 @@ shuffle_set(void *arg, int *retval) // Update shuffle mode shuffle = new_shuffle; + // Persist + SETTINGS_SETBOOL(player_settings_category, PLAYER_SETTINGS_MODE_SHUFFLE, shuffle); + out: *retval = 0; return COMMAND_END; @@ -2979,6 +2992,9 @@ consume_set(void *arg, int *retval) consume = cmdarg->intval; + // Persist + SETTINGS_SETBOOL(player_settings_category, PLAYER_SETTINGS_MODE_CONSUME, consume); + *retval = 0; return COMMAND_END; } @@ -3540,8 +3556,13 @@ player_init(void) speaker_autoselect = cfg_getbool(cfg_getsec(cfg, "general"), "speaker_autoselect"); clear_queue_on_stop_disabled = cfg_getbool(cfg_getsec(cfg, "mpd"), "clear_queue_on_stop_disable"); + CHECK_NULL(L_PLAYER, player_settings_category = settings_category_get("player")); + ret = SETTINGS_GETINT(player_settings_category, PLAYER_SETTINGS_MODE_REPEAT); + repeat = (ret > 0) ? ret : REPEAT_OFF; + shuffle = SETTINGS_GETBOOL(player_settings_category, PLAYER_SETTINGS_MODE_SHUFFLE); + consume = SETTINGS_GETBOOL(player_settings_category, PLAYER_SETTINGS_MODE_CONSUME); + player_state = PLAY_STOPPED; - repeat = REPEAT_OFF; CHECK_NULL(L_PLAYER, history = calloc(1, sizeof(struct player_history))); diff --git a/src/settings.c b/src/settings.c index 50e10882..54e6e539 100644 --- a/src/settings.c +++ b/src/settings.c @@ -48,11 +48,19 @@ static struct settings_option misc_options[] = { "streamurl_keywords_length", SETTINGS_TYPE_STR }, }; +static struct settings_option player_options[] = + { + { "player_mode_repeat", SETTINGS_TYPE_INT }, + { "player_mode_shuffle", SETTINGS_TYPE_BOOL }, + { "player_mode_consume", SETTINGS_TYPE_BOOL }, + }; + static struct settings_category categories[] = { { "webinterface", webinterface_options, ARRAY_SIZE(webinterface_options) }, { "artwork", artwork_options, ARRAY_SIZE(artwork_options) }, { "misc", misc_options, ARRAY_SIZE(misc_options) }, + { "player", player_options, ARRAY_SIZE(player_options) }, }; @@ -104,7 +112,7 @@ artwork_coverartarchive_default_getbool(struct settings_option *option) /* ------------------------------ IMPLEMENTATION -----------------------------*/ int -settings_categories_count() +settings_categories_count(void) { return ARRAY_SIZE(categories); } @@ -137,15 +145,6 @@ settings_option_count(struct settings_category *category) return category->count_options; } -struct settings_option * -settings_option_get_byindex(struct settings_category *category, int index) -{ - if (index < 0 || !category || category->count_options <= index) - return NULL; - - return &category->options[index]; -} - struct settings_option * settings_option_get(struct settings_category *category, const char *name) { @@ -163,6 +162,15 @@ settings_option_get(struct settings_category *category, const char *name) return NULL; } +struct settings_option * +settings_option_get_byindex(struct settings_category *category, int index) +{ + if (index < 0 || !category || category->count_options <= index) + return NULL; + + return &category->options[index]; +} + int settings_option_getint(struct settings_option *option) @@ -221,6 +229,7 @@ settings_option_getstr(struct settings_option *option) return NULL; } + int settings_option_setint(struct settings_option *option, int value) { @@ -248,6 +257,7 @@ settings_option_setstr(struct settings_option *option, const char *value) return db_admin_set(option->name, value); } + int settings_option_delete(struct settings_option *option) {