Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Store last loaded playlist #2101

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/command/PlayerCommands.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
#define COMMAND_STATUS_MIXRAMPDELAY "mixrampdelay"
#define COMMAND_STATUS_AUDIO "audio"
#define COMMAND_STATUS_UPDATING_DB "updating_db"
#define COMMAND_STATUS_LOADED_PLAYLIST "lastloadedplaylist"

CommandResult
handle_play(Client &client, Request args, [[maybe_unused]] Response &r)
Expand Down Expand Up @@ -128,7 +129,8 @@ handle_status(Client &client, [[maybe_unused]] Request args, Response &r)
COMMAND_STATUS_PLAYLIST ": {}\n"
COMMAND_STATUS_PLAYLIST_LENGTH ": {}\n"
COMMAND_STATUS_MIXRAMPDB ": {}\n"
COMMAND_STATUS_STATE ": {}\n"),
COMMAND_STATUS_STATE ": {}\n"
COMMAND_STATUS_LOADED_PLAYLIST ": {}\n"),
(unsigned)playlist.GetRepeat(),
(unsigned)playlist.GetRandom(),
SingleToString(playlist.GetSingle()),
Expand All @@ -137,7 +139,8 @@ handle_status(Client &client, [[maybe_unused]] Request args, Response &r)
playlist.GetVersion(),
playlist.GetLength(),
pc.GetMixRampDb(),
state);
state,
playlist.GetLastLoadedPlaylist());

if (pc.GetCrossFade() > FloatDuration::zero())
r.Fmt(FMT_STRING(COMMAND_STATUS_CROSSFADE ": {}\n"),
Expand Down
1 change: 1 addition & 0 deletions src/playlist/PlaylistQueue.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ playlist_load_into_queue(const char *uri, SongEnumerator &e,

dest.AppendSong(pc, std::move(*song));
}
dest.SetLastLoadedPlaylist(uri);
}

void
Expand Down
12 changes: 12 additions & 0 deletions src/queue/Playlist.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -359,3 +359,15 @@ playlist::BorderPause(PlayerControl &pc) noexcept
listener.OnQueueOptionsChanged();
}
}

const std::string_view
playlist::GetLastLoadedPlaylist() const noexcept
{
return queue.last_loaded_playlist;
}

void
playlist::SetLastLoadedPlaylist(const char *playlist_name) noexcept
{
queue.last_loaded_playlist = playlist_name;
}
3 changes: 3 additions & 0 deletions src/queue/Playlist.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ struct playlist {
[[gnu::pure]]
int GetNextPosition() const noexcept;

const std::string_view GetLastLoadedPlaylist() const noexcept;
void SetLastLoadedPlaylist(const char *playlist_name) noexcept;

/**
* Returns the song object which is currently queued. Returns
* none if there is none (yet?) or if MPD isn't playing.
Expand Down
5 changes: 5 additions & 0 deletions src/queue/PlaylistState.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#define PLAYLIST_STATE_FILE_CROSSFADE "crossfade: "
#define PLAYLIST_STATE_FILE_MIXRAMPDB "mixrampdb: "
#define PLAYLIST_STATE_FILE_MIXRAMPDELAY "mixrampdelay: "
#define PLAYLIST_STATE_FILE_LOADED_PLAYLIST "lastloadedplaylist: "
#define PLAYLIST_STATE_FILE_PLAYLIST_BEGIN "playlist_begin"
#define PLAYLIST_STATE_FILE_PLAYLIST_END "playlist_end"

Expand Down Expand Up @@ -85,6 +86,8 @@ playlist_state_save(BufferedOutputStream &os, const struct playlist &playlist,
pc.GetMixRampDb());
os.Fmt(FMT_STRING(PLAYLIST_STATE_FILE_MIXRAMPDELAY "{}\n"),
pc.GetMixRampDelay().count());
os.Fmt(FMT_STRING(PLAYLIST_STATE_FILE_LOADED_PLAYLIST "{}\n"),
playlist.GetLastLoadedPlaylist());
os.Write(PLAYLIST_STATE_FILE_PLAYLIST_BEGIN "\n");
queue_save(os, playlist.queue);
os.Write(PLAYLIST_STATE_FILE_PLAYLIST_END "\n");
Expand Down Expand Up @@ -156,6 +159,8 @@ playlist_state_restore(const StateFileConfig &config,
prior to MPD 0.18 */
if (IsDigitASCII(*p))
pc.SetMixRampDelay(FloatDuration(ParseFloat(p)));
} else if ((p = StringAfterPrefix(line, PLAYLIST_STATE_FILE_LOADED_PLAYLIST))) {
playlist.SetLastLoadedPlaylist(p);
} else if ((p = StringAfterPrefix(line, PLAYLIST_STATE_FILE_RANDOM))) {
random_mode = StringIsEqual(p, "1");
} else if ((p = StringAfterPrefix(line, PLAYLIST_STATE_FILE_CURRENT))) {
Expand Down
1 change: 1 addition & 0 deletions src/queue/Queue.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ Queue::Clear() noexcept
}

length = 0;
last_loaded_playlist.clear();
}

static void
Expand Down
3 changes: 3 additions & 0 deletions src/queue/Queue.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ struct Queue {
/** play back songs in random order? */
bool random = false;

/** Last loaded playlist */
std::string last_loaded_playlist;

/** random number generator for shuffle and random mode */
LazyRandomEngine rand;

Expand Down