command/queue: add optional position parameter to "add"

Closes https://github.com/MusicPlayerDaemon/MPD/issues/1285
This commit is contained in:
Max Kellermann 2021-10-23 13:00:34 +02:00
parent 35c4c7e8bf
commit 6f595e9abb
5 changed files with 28 additions and 7 deletions

2
NEWS
View File

@ -1,4 +1,6 @@
ver 0.23.3 (not yet released)
* protocol
- add optional position parameter to "add"
* output
- alsa: add option "stop_dsd_silence" to work around DSD DAC noise
* macOS: fix libfmt related build failure

View File

@ -689,11 +689,14 @@ Whenever possible, ids should be used.
.. _command_add:
:command:`add {URI}`
:command:`add {URI} [POSITION]`
Adds the file ``URI`` to the playlist
(directories add recursively). ``URI``
can also be a single file.
The position parameter is the same as in :ref:`addid
<command_addid>`.
Clients that are connected via local socket may add arbitrary
local files (URI is an absolute path). Example::

View File

@ -44,7 +44,7 @@ version_conf = configuration_data()
version_conf.set_quoted('PACKAGE', meson.project_name())
version_conf.set_quoted('PACKAGE_NAME', meson.project_name())
version_conf.set_quoted('VERSION', meson.project_version())
version_conf.set_quoted('PROTOCOL_VERSION', '0.23.1')
version_conf.set_quoted('PROTOCOL_VERSION', '0.23.3')
configure_file(output: 'Version.h', configuration: version_conf)
conf = configuration_data()

View File

@ -85,7 +85,7 @@ handle_not_commands(Client &client, Request request, Response &response);
* This array must be sorted!
*/
static constexpr struct command commands[] = {
{ "add", PERMISSION_ADD, 1, 1, handle_add },
{ "add", PERMISSION_ADD, 1, 2, handle_add },
{ "addid", PERMISSION_ADD, 1, 2, handle_addid },
{ "addtagid", PERMISSION_ADD, 3, 3, handle_addtagid },
{ "albumart", PERMISSION_READ, 2, 2, handle_album_art },

View File

@ -79,6 +79,11 @@ handle_add(Client &client, Request args, [[maybe_unused]] Response &r)
here */
uri = "";
const auto old_size = partition.playlist.GetLength();
const unsigned position = args.size > 1
? ParseInsertPosition(args[1], partition.playlist)
: old_size;
const auto located_uri = LocateUri(UriPluginKind::INPUT, uri,
&client
#ifdef ENABLE_DATABASE
@ -89,23 +94,34 @@ handle_add(Client &client, Request args, [[maybe_unused]] Response &r)
case LocatedUri::Type::ABSOLUTE:
AddUri(client, located_uri);
client.GetInstance().LookupRemoteTag(located_uri.canonical_uri);
return CommandResult::OK;
break;
case LocatedUri::Type::PATH:
AddUri(client, located_uri);
return CommandResult::OK;
break;
case LocatedUri::Type::RELATIVE:
#ifdef ENABLE_DATABASE
AddDatabaseSelection(partition, located_uri.canonical_uri);
return CommandResult::OK;
break;
#else
r.Error(ACK_ERROR_NO_EXIST, "No database");
return CommandResult::ERROR;
#endif
}
gcc_unreachable();
if (position < old_size) {
const unsigned new_size = partition.playlist.GetLength();
const RangeArg move_range{old_size, new_size};
try {
partition.MoveRange(move_range, position);
} catch (...) {
/* ignore - shall we handle it? */
}
}
return CommandResult::OK;
}
CommandResult