aboutsummaryrefslogtreecommitdiffstats
path: root/src/command/QueueCommands.cxx
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2014-07-12 03:00:01 +0200
committerMax Kellermann <max@duempel.org>2014-07-12 18:55:41 +0200
commit751995ab95298bbc0afad6958bfccce535edf53c (patch)
tree29e8b8d35536e98fc503963d86260d74a872db91 /src/command/QueueCommands.cxx
parent5ca6e2910ae0a8a2d1fa7b16f56130d533251ff9 (diff)
downloadmpd-751995ab95298bbc0afad6958bfccce535edf53c.tar.gz
mpd-751995ab95298bbc0afad6958bfccce535edf53c.tar.xz
mpd-751995ab95298bbc0afad6958bfccce535edf53c.zip
QueueCommands: new command "rangeid"
Manipulates the playback range of a queued song.
Diffstat (limited to '')
-rw-r--r--src/command/QueueCommands.cxx54
1 files changed, 54 insertions, 0 deletions
diff --git a/src/command/QueueCommands.cxx b/src/command/QueueCommands.cxx
index 1ff7a732b..c99a6687a 100644
--- a/src/command/QueueCommands.cxx
+++ b/src/command/QueueCommands.cxx
@@ -34,6 +34,7 @@
#include "ls.hxx"
#include "util/ConstBuffer.hxx"
#include "util/UriUtil.hxx"
+#include "util/NumberParser.hxx"
#include "util/Error.hxx"
#include "fs/AllocatedPath.hxx"
@@ -118,6 +119,59 @@ handle_addid(Client &client, unsigned argc, char *argv[])
return CommandResult::OK;
}
+/**
+ * Parse a string in the form "START:END", both being (optional)
+ * fractional non-negative time offsets in seconds. Returns both in
+ * integer milliseconds. Omitted values are zero.
+ */
+static bool
+parse_time_range(const char *p, unsigned &start_ms, unsigned &end_ms)
+{
+ char *endptr;
+
+ const float start = ParseFloat(p, &endptr);
+ if (*endptr != ':' || start < 0)
+ return false;
+
+ start_ms = endptr > p
+ ? unsigned(start * 1000u)
+ : 0u;
+
+ p = endptr + 1;
+
+ const float end = ParseFloat(p, &endptr);
+ if (*endptr != 0 || end < 0)
+ return false;
+
+ end_ms = endptr > p
+ ? unsigned(end * 1000u)
+ : 0u;
+
+ return end_ms == 0 || end_ms > start_ms;
+}
+
+CommandResult
+handle_rangeid(Client &client, gcc_unused unsigned argc, char *argv[])
+{
+ unsigned id;
+ if (!check_unsigned(client, &id, argv[1]))
+ return CommandResult::ERROR;
+
+ unsigned start_ms, end_ms;
+ if (!parse_time_range(argv[2], start_ms, end_ms)) {
+ command_error(client, ACK_ERROR_ARG, "Bad range");
+ return CommandResult::ERROR;
+ }
+
+ Error error;
+ if (!client.partition.playlist.SetSongIdRange(client.partition.pc,
+ id, start_ms, end_ms,
+ error))
+ return print_error(client, error);
+
+ return CommandResult::OK;
+}
+
CommandResult
handle_delete(Client &client, gcc_unused unsigned argc, char *argv[])
{