playlist/Queue: add one-shot to single mode
This commit is contained in:

committed by
Max Kellermann

parent
1fb358249b
commit
1628d801f9
@@ -23,6 +23,7 @@
|
||||
#include "PlaylistError.hxx"
|
||||
#include "player/Control.hxx"
|
||||
#include "DetachedSong.hxx"
|
||||
#include "SingleMode.hxx"
|
||||
#include "Log.hxx"
|
||||
|
||||
#include <assert.h>
|
||||
@@ -136,7 +137,7 @@ playlist::UpdateQueuedSong(PlayerControl &pc, const DetachedSong *prev)
|
||||
? queue.GetNextOrder(current)
|
||||
: 0;
|
||||
|
||||
if (next_order == 0 && queue.random && !queue.single) {
|
||||
if (next_order == 0 && queue.random && queue.single == SingleMode::OFF) {
|
||||
/* shuffle the song order again, so we get a different
|
||||
order each time the playlist is played
|
||||
completely */
|
||||
@@ -257,7 +258,7 @@ playlist::SetRepeat(PlayerControl &pc, bool status)
|
||||
|
||||
queue.repeat = status;
|
||||
|
||||
pc.LockSetBorderPause(queue.single && !queue.repeat);
|
||||
pc.LockSetBorderPause(queue.single != SingleMode::OFF && !queue.repeat);
|
||||
|
||||
/* if the last song is currently being played, the "next song"
|
||||
might change when repeat mode is toggled */
|
||||
@@ -277,14 +278,15 @@ playlist_order(playlist &playlist)
|
||||
}
|
||||
|
||||
void
|
||||
playlist::SetSingle(PlayerControl &pc, bool status)
|
||||
playlist::SetSingle(PlayerControl &pc, SingleMode status)
|
||||
{
|
||||
if (status == queue.single)
|
||||
return;
|
||||
|
||||
queue.single = status;
|
||||
|
||||
pc.LockSetBorderPause(queue.single && !queue.repeat);
|
||||
|
||||
pc.LockSetBorderPause(queue.single != SingleMode::OFF && !queue.repeat);
|
||||
|
||||
/* if the last song is currently being played, the "next song"
|
||||
might change when single mode is toggled */
|
||||
@@ -353,7 +355,7 @@ playlist::GetNextPosition() const noexcept
|
||||
if (current < 0)
|
||||
return -1;
|
||||
|
||||
if (queue.single && queue.repeat)
|
||||
if (queue.single != SingleMode::OFF && queue.repeat)
|
||||
return queue.OrderToPosition(current);
|
||||
else if (queue.IsValidOrder(current + 1))
|
||||
return queue.OrderToPosition(current + 1);
|
||||
@@ -362,3 +364,14 @@ playlist::GetNextPosition() const noexcept
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
void
|
||||
playlist::BorderPause(PlayerControl &pc)
|
||||
{
|
||||
if (queue.single == SingleMode::ONE_SHOT) {
|
||||
queue.single = SingleMode::OFF;
|
||||
pc.LockSetBorderPause(false);
|
||||
|
||||
listener.OnQueueOptionsChanged();
|
||||
}
|
||||
}
|
||||
|
@@ -20,6 +20,7 @@
|
||||
#ifndef MPD_PLAYLIST_HXX
|
||||
#define MPD_PLAYLIST_HXX
|
||||
|
||||
#include "SingleMode.hxx"
|
||||
#include "queue/Queue.hxx"
|
||||
|
||||
enum TagType : uint8_t;
|
||||
@@ -133,6 +134,12 @@ struct playlist {
|
||||
*/
|
||||
void SyncWithPlayer(PlayerControl &pc);
|
||||
|
||||
/**
|
||||
* This is the "BORDER_PAUSE" event handler. It is invoked by
|
||||
* the player thread whenever playback goes into border pause.
|
||||
*/
|
||||
void BorderPause(PlayerControl &pc);
|
||||
|
||||
protected:
|
||||
/**
|
||||
* Called by all editing methods after a modification.
|
||||
@@ -347,11 +354,11 @@ public:
|
||||
|
||||
void SetRandom(PlayerControl &pc, bool new_value);
|
||||
|
||||
bool GetSingle() const {
|
||||
SingleMode GetSingle() const {
|
||||
return queue.single;
|
||||
}
|
||||
|
||||
void SetSingle(PlayerControl &pc, bool new_value);
|
||||
void SetSingle(PlayerControl &pc, SingleMode new_value);
|
||||
|
||||
bool GetConsume() const {
|
||||
return queue.consume;
|
||||
|
@@ -26,6 +26,7 @@
|
||||
#include "PlaylistState.hxx"
|
||||
#include "PlaylistError.hxx"
|
||||
#include "Playlist.hxx"
|
||||
#include "SingleMode.hxx"
|
||||
#include "queue/QueueSave.hxx"
|
||||
#include "fs/io/TextFile.hxx"
|
||||
#include "fs/io/BufferedOutputStream.hxx"
|
||||
@@ -88,7 +89,8 @@ playlist_state_save(BufferedOutputStream &os, const struct playlist &playlist,
|
||||
|
||||
os.Format(PLAYLIST_STATE_FILE_RANDOM "%i\n", playlist.queue.random);
|
||||
os.Format(PLAYLIST_STATE_FILE_REPEAT "%i\n", playlist.queue.repeat);
|
||||
os.Format(PLAYLIST_STATE_FILE_SINGLE "%i\n", playlist.queue.single);
|
||||
os.Format(PLAYLIST_STATE_FILE_SINGLE "%i\n",
|
||||
(int)playlist.queue.single);
|
||||
os.Format(PLAYLIST_STATE_FILE_CONSUME "%i\n", playlist.queue.consume);
|
||||
os.Format(PLAYLIST_STATE_FILE_CROSSFADE "%i\n",
|
||||
(int)pc.GetCrossFade());
|
||||
@@ -153,7 +155,7 @@ playlist_state_restore(const char *line, TextFile &file,
|
||||
} else if ((p = StringAfterPrefix(line, PLAYLIST_STATE_FILE_REPEAT))) {
|
||||
playlist.SetRepeat(pc, StringIsEqual(p, "1"));
|
||||
} else if ((p = StringAfterPrefix(line, PLAYLIST_STATE_FILE_SINGLE))) {
|
||||
playlist.SetSingle(pc, StringIsEqual(p, "1"));
|
||||
playlist.SetSingle(pc, SingleFromString(p));
|
||||
} else if ((p = StringAfterPrefix(line, PLAYLIST_STATE_FILE_CONSUME))) {
|
||||
playlist.SetConsume(StringIsEqual(p, "1"));
|
||||
} else if ((p = StringAfterPrefix(line, PLAYLIST_STATE_FILE_CROSSFADE))) {
|
||||
@@ -233,9 +235,10 @@ playlist_state_get_hash(const playlist &playlist,
|
||||
: 0) ^
|
||||
((int)pc.GetCrossFade() << 20) ^
|
||||
(unsigned(player_status.state) << 24) ^
|
||||
/* note that this takes 2 bits */
|
||||
((int)playlist.queue.single << 25) ^
|
||||
(playlist.queue.random << 27) ^
|
||||
(playlist.queue.repeat << 28) ^
|
||||
(playlist.queue.single << 29) ^
|
||||
(playlist.queue.consume << 30) ^
|
||||
(playlist.queue.random << 31);
|
||||
}
|
||||
|
@@ -42,7 +42,7 @@ Queue::GetNextOrder(unsigned _order) const noexcept
|
||||
{
|
||||
assert(_order < length);
|
||||
|
||||
if (single && repeat && !consume)
|
||||
if (single != SingleMode::OFF && repeat && !consume)
|
||||
return _order;
|
||||
else if (_order + 1 < length)
|
||||
return _order + 1;
|
||||
|
@@ -22,6 +22,7 @@
|
||||
|
||||
#include "Compiler.h"
|
||||
#include "IdTable.hxx"
|
||||
#include "SingleMode.hxx"
|
||||
#include "util/LazyRandomEngine.hxx"
|
||||
|
||||
#include <algorithm>
|
||||
@@ -92,7 +93,7 @@ struct Queue {
|
||||
bool repeat = false;
|
||||
|
||||
/** play only current song. */
|
||||
bool single = false;
|
||||
SingleMode single = SingleMode::OFF;
|
||||
|
||||
/** remove each played files. */
|
||||
bool consume = false;
|
||||
|
Reference in New Issue
Block a user