Add ConsumeMode oneshot, closes #925
This commit is contained in:
parent
b2fb920d28
commit
48a936ef5b
1
NEWS
1
NEWS
|
@ -11,6 +11,7 @@ ver 0.24 (not yet released)
|
||||||
- wavpack: require libwavpack version 5
|
- wavpack: require libwavpack version 5
|
||||||
* player
|
* player
|
||||||
- add option "mixramp_analyzer" to scan MixRamp tags on-the-fly
|
- add option "mixramp_analyzer" to scan MixRamp tags on-the-fly
|
||||||
|
- "one-shot" consume mode
|
||||||
* tags
|
* tags
|
||||||
- new tags "TitleSort", "Mood"
|
- new tags "TitleSort", "Mood"
|
||||||
* switch to C++20
|
* switch to C++20
|
||||||
|
|
|
@ -468,6 +468,7 @@ basic = static_library(
|
||||||
'basic',
|
'basic',
|
||||||
'src/ReplayGainMode.cxx',
|
'src/ReplayGainMode.cxx',
|
||||||
'src/SingleMode.cxx',
|
'src/SingleMode.cxx',
|
||||||
|
'src/ConsumeMode.cxx',
|
||||||
include_directories: inc,
|
include_directories: inc,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,59 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2003-2022 The Music Player Daemon Project
|
||||||
|
* http://www.musicpd.org
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along
|
||||||
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "ConsumeMode.hxx"
|
||||||
|
#include "util/Compiler.h"
|
||||||
|
|
||||||
|
#include <cassert>
|
||||||
|
#include <stdexcept>
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
const char *
|
||||||
|
ConsumeToString(ConsumeMode mode) noexcept
|
||||||
|
{
|
||||||
|
switch (mode) {
|
||||||
|
case ConsumeMode::OFF:
|
||||||
|
return "0";
|
||||||
|
|
||||||
|
case ConsumeMode::ON:
|
||||||
|
return "1";
|
||||||
|
|
||||||
|
case ConsumeMode::ONE_SHOT:
|
||||||
|
return "oneshot";
|
||||||
|
}
|
||||||
|
|
||||||
|
assert(false);
|
||||||
|
gcc_unreachable();
|
||||||
|
}
|
||||||
|
|
||||||
|
ConsumeMode
|
||||||
|
ConsumeFromString(const char *s)
|
||||||
|
{
|
||||||
|
assert(s != nullptr);
|
||||||
|
|
||||||
|
if (strcmp(s, "0") == 0)
|
||||||
|
return ConsumeMode::OFF;
|
||||||
|
else if (strcmp(s, "1") == 0)
|
||||||
|
return ConsumeMode::ON;
|
||||||
|
else if (strcmp(s, "oneshot") == 0)
|
||||||
|
return ConsumeMode::ONE_SHOT;
|
||||||
|
else
|
||||||
|
throw std::invalid_argument("Unrecognized consume mode, expected 0, 1, or oneshot");
|
||||||
|
}
|
|
@ -0,0 +1,44 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2003-2022 The Music Player Daemon Project
|
||||||
|
* http://www.musicpd.org
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along
|
||||||
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef MPD_CONSUME_MODE_HXX
|
||||||
|
#define MPD_CONSUME_MODE_HXX
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
|
|
||||||
|
enum class ConsumeMode : uint8_t {
|
||||||
|
OFF,
|
||||||
|
ON,
|
||||||
|
ONE_SHOT,
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the string representation of a #ConsumeMode.
|
||||||
|
*/
|
||||||
|
[[gnu::const]]
|
||||||
|
const char *
|
||||||
|
ConsumeToString(ConsumeMode mode) noexcept;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parse a string to a #ConsumeMode. Throws std::invalid_argument on error.
|
||||||
|
*/
|
||||||
|
ConsumeMode
|
||||||
|
ConsumeFromString(const char *s);
|
||||||
|
|
||||||
|
#endif
|
|
@ -31,6 +31,7 @@
|
||||||
#include "protocol/RangeArg.hxx"
|
#include "protocol/RangeArg.hxx"
|
||||||
#include "ReplayGainMode.hxx"
|
#include "ReplayGainMode.hxx"
|
||||||
#include "SingleMode.hxx"
|
#include "SingleMode.hxx"
|
||||||
|
#include "ConsumeMode.hxx"
|
||||||
#include "Chrono.hxx"
|
#include "Chrono.hxx"
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
|
@ -218,7 +219,7 @@ struct Partition final : QueueListener, PlayerListener, MixerListener {
|
||||||
playlist.SetSingle(pc, new_value);
|
playlist.SetSingle(pc, new_value);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetConsume(bool new_value) noexcept {
|
void SetConsume(ConsumeMode new_value) noexcept {
|
||||||
playlist.SetConsume(new_value);
|
playlist.SetConsume(new_value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
#include "Request.hxx"
|
#include "Request.hxx"
|
||||||
#include "queue/Playlist.hxx"
|
#include "queue/Playlist.hxx"
|
||||||
#include "PlaylistPrint.hxx"
|
#include "PlaylistPrint.hxx"
|
||||||
|
#include "ConsumeMode.hxx"
|
||||||
#include "SingleMode.hxx"
|
#include "SingleMode.hxx"
|
||||||
#include "client/Client.hxx"
|
#include "client/Client.hxx"
|
||||||
#include "client/Response.hxx"
|
#include "client/Response.hxx"
|
||||||
|
@ -146,7 +147,7 @@ handle_status(Client &client, [[maybe_unused]] Request args, Response &r)
|
||||||
(unsigned)playlist.GetRepeat(),
|
(unsigned)playlist.GetRepeat(),
|
||||||
(unsigned)playlist.GetRandom(),
|
(unsigned)playlist.GetRandom(),
|
||||||
SingleToString(playlist.GetSingle()),
|
SingleToString(playlist.GetSingle()),
|
||||||
(unsigned)playlist.GetConsume(),
|
ConsumeToString(playlist.GetConsume()),
|
||||||
partition.name.c_str(),
|
partition.name.c_str(),
|
||||||
playlist.GetVersion(),
|
playlist.GetVersion(),
|
||||||
playlist.GetLength(),
|
playlist.GetLength(),
|
||||||
|
@ -260,8 +261,8 @@ handle_single(Client &client, Request args, [[maybe_unused]] Response &r)
|
||||||
CommandResult
|
CommandResult
|
||||||
handle_consume(Client &client, Request args, [[maybe_unused]] Response &r)
|
handle_consume(Client &client, Request args, [[maybe_unused]] Response &r)
|
||||||
{
|
{
|
||||||
bool status = args.ParseBool(0);
|
auto new_mode = ConsumeFromString(args.front());
|
||||||
client.GetPartition().SetConsume(status);
|
client.GetPartition().SetConsume(new_mode);
|
||||||
return CommandResult::OK;
|
return CommandResult::OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
#include "player/Control.hxx"
|
#include "player/Control.hxx"
|
||||||
#include "song/DetachedSong.hxx"
|
#include "song/DetachedSong.hxx"
|
||||||
#include "SingleMode.hxx"
|
#include "SingleMode.hxx"
|
||||||
|
#include "ConsumeMode.hxx"
|
||||||
#include "Log.hxx"
|
#include "Log.hxx"
|
||||||
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
@ -101,9 +102,14 @@ playlist::QueuedSongStarted(PlayerControl &pc) noexcept
|
||||||
current = queued;
|
current = queued;
|
||||||
queued = -1;
|
queued = -1;
|
||||||
|
|
||||||
if (queue.consume)
|
if (queue.consume != ConsumeMode::OFF)
|
||||||
DeleteOrder(pc, old_current);
|
DeleteOrder(pc, old_current);
|
||||||
|
|
||||||
|
if (queue.consume == ConsumeMode::ONE_SHOT) {
|
||||||
|
queue.consume = ConsumeMode::OFF;
|
||||||
|
listener.OnQueueOptionsChanged();
|
||||||
|
}
|
||||||
|
|
||||||
listener.OnQueueSongStarted();
|
listener.OnQueueSongStarted();
|
||||||
|
|
||||||
SongStarted();
|
SongStarted();
|
||||||
|
@ -289,12 +295,13 @@ playlist::SetSingle(PlayerControl &pc, SingleMode status) noexcept
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
playlist::SetConsume(bool status) noexcept
|
playlist::SetConsume(ConsumeMode status) noexcept
|
||||||
{
|
{
|
||||||
if (status == queue.consume)
|
if (status == queue.consume)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
queue.consume = status;
|
queue.consume = status;
|
||||||
|
|
||||||
listener.OnQueueOptionsChanged();
|
listener.OnQueueOptionsChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
#define MPD_PLAYLIST_HXX
|
#define MPD_PLAYLIST_HXX
|
||||||
|
|
||||||
#include "SingleMode.hxx"
|
#include "SingleMode.hxx"
|
||||||
|
#include "ConsumeMode.hxx"
|
||||||
#include "queue/Queue.hxx"
|
#include "queue/Queue.hxx"
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
|
@ -369,11 +370,11 @@ public:
|
||||||
|
|
||||||
void SetSingle(PlayerControl &pc, SingleMode new_value) noexcept;
|
void SetSingle(PlayerControl &pc, SingleMode new_value) noexcept;
|
||||||
|
|
||||||
bool GetConsume() const noexcept {
|
ConsumeMode GetConsume() const noexcept {
|
||||||
return queue.consume;
|
return queue.consume;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetConsume(bool new_value) noexcept;
|
void SetConsume(ConsumeMode new_value) noexcept;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
#include "PlaylistError.hxx"
|
#include "PlaylistError.hxx"
|
||||||
#include "player/Control.hxx"
|
#include "player/Control.hxx"
|
||||||
#include "song/DetachedSong.hxx"
|
#include "song/DetachedSong.hxx"
|
||||||
|
#include "Listener.hxx"
|
||||||
#include "Log.hxx"
|
#include "Log.hxx"
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -178,8 +179,14 @@ playlist::PlayNext(PlayerControl &pc)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Consume mode removes each played songs. */
|
/* Consume mode removes each played songs. */
|
||||||
if (queue.consume)
|
if (queue.consume != ConsumeMode::OFF)
|
||||||
DeleteOrder(pc, old_current);
|
DeleteOrder(pc, old_current);
|
||||||
|
|
||||||
|
/* Disable consume mode after consuming one song in oneshot mode. */
|
||||||
|
if (queue.consume == ConsumeMode::ONE_SHOT) {
|
||||||
|
queue.consume = ConsumeMode::OFF;
|
||||||
|
listener.OnQueueOptionsChanged();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
|
@ -162,7 +162,7 @@ playlist_state_restore(const StateFileConfig &config,
|
||||||
} else if ((p = StringAfterPrefix(line, PLAYLIST_STATE_FILE_SINGLE))) {
|
} else if ((p = StringAfterPrefix(line, PLAYLIST_STATE_FILE_SINGLE))) {
|
||||||
playlist.SetSingle(pc, SingleFromString(p));
|
playlist.SetSingle(pc, SingleFromString(p));
|
||||||
} else if ((p = StringAfterPrefix(line, PLAYLIST_STATE_FILE_CONSUME))) {
|
} else if ((p = StringAfterPrefix(line, PLAYLIST_STATE_FILE_CONSUME))) {
|
||||||
playlist.SetConsume(StringIsEqual(p, "1"));
|
playlist.SetConsume(ConsumeFromString(p));
|
||||||
} else if ((p = StringAfterPrefix(line, PLAYLIST_STATE_FILE_CROSSFADE))) {
|
} else if ((p = StringAfterPrefix(line, PLAYLIST_STATE_FILE_CROSSFADE))) {
|
||||||
pc.SetCrossFade(FloatDuration(atoi(p)));
|
pc.SetCrossFade(FloatDuration(atoi(p)));
|
||||||
} else if ((p = StringAfterPrefix(line, PLAYLIST_STATE_FILE_MIXRAMPDB))) {
|
} else if ((p = StringAfterPrefix(line, PLAYLIST_STATE_FILE_MIXRAMPDB))) {
|
||||||
|
@ -243,6 +243,7 @@ playlist_state_get_hash(const playlist &playlist,
|
||||||
((int)playlist.queue.single << 25) ^
|
((int)playlist.queue.single << 25) ^
|
||||||
(playlist.queue.random << 27) ^
|
(playlist.queue.random << 27) ^
|
||||||
(playlist.queue.repeat << 28) ^
|
(playlist.queue.repeat << 28) ^
|
||||||
(playlist.queue.consume << 30) ^
|
/* note that this takes 2 bits */
|
||||||
|
((int)playlist.queue.consume << 29) ^
|
||||||
(playlist.queue.random << 31);
|
(playlist.queue.random << 31);
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,11 +54,11 @@ Queue::GetNextOrder(unsigned _order) const noexcept
|
||||||
{
|
{
|
||||||
assert(_order < length);
|
assert(_order < length);
|
||||||
|
|
||||||
if (single != SingleMode::OFF && repeat && !consume)
|
if (single != SingleMode::OFF && repeat && consume == ConsumeMode::OFF )
|
||||||
return _order;
|
return _order;
|
||||||
else if (_order + 1 < length)
|
else if (_order + 1 < length)
|
||||||
return _order + 1;
|
return _order + 1;
|
||||||
else if (repeat && (_order > 0 || !consume))
|
else if (repeat && (_order > 0 || consume == ConsumeMode::OFF))
|
||||||
/* restart at first song */
|
/* restart at first song */
|
||||||
return 0;
|
return 0;
|
||||||
else
|
else
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
#include "util/Compiler.h"
|
#include "util/Compiler.h"
|
||||||
#include "IdTable.hxx"
|
#include "IdTable.hxx"
|
||||||
#include "SingleMode.hxx"
|
#include "SingleMode.hxx"
|
||||||
|
#include "ConsumeMode.hxx"
|
||||||
#include "util/LazyRandomEngine.hxx"
|
#include "util/LazyRandomEngine.hxx"
|
||||||
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
@ -96,7 +97,7 @@ struct Queue {
|
||||||
SingleMode single = SingleMode::OFF;
|
SingleMode single = SingleMode::OFF;
|
||||||
|
|
||||||
/** remove each played files. */
|
/** remove each played files. */
|
||||||
bool consume = false;
|
ConsumeMode consume = ConsumeMode::OFF;
|
||||||
|
|
||||||
/** play back songs in random order? */
|
/** play back songs in random order? */
|
||||||
bool random = false;
|
bool random = false;
|
||||||
|
|
Loading…
Reference in New Issue