Commit 127fe6ec authored by Max Kellermann's avatar Max Kellermann

PlaylistEdit: pass std::chrono::duration to SetSongIdRange()

parent 888ab0c8
......@@ -125,7 +125,7 @@ handle_addid(Client &client, unsigned argc, char *argv[])
* integer milliseconds. Omitted values are zero.
*/
static bool
parse_time_range(const char *p, unsigned &start_ms, unsigned &end_ms)
parse_time_range(const char *p, SongTime &start_r, SongTime &end_r)
{
char *endptr;
......@@ -133,9 +133,9 @@ parse_time_range(const char *p, unsigned &start_ms, unsigned &end_ms)
if (*endptr != ':' || start < 0)
return false;
start_ms = endptr > p
? unsigned(start * 1000u)
: 0u;
start_r = endptr > p
? SongTime::FromS(start)
: SongTime::zero();
p = endptr + 1;
......@@ -143,11 +143,11 @@ parse_time_range(const char *p, unsigned &start_ms, unsigned &end_ms)
if (*endptr != 0 || end < 0)
return false;
end_ms = endptr > p
? unsigned(end * 1000u)
: 0u;
end_r = endptr > p
? SongTime::FromS(end)
: SongTime::zero();
return end_ms == 0 || end_ms > start_ms;
return end_r.IsZero() || end_r > start_r;
}
CommandResult
......@@ -157,15 +157,15 @@ handle_rangeid(Client &client, gcc_unused unsigned argc, char *argv[])
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)) {
SongTime start, end;
if (!parse_time_range(argv[2], start, end)) {
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,
id, start, end,
error))
return print_error(client, error);
......
......@@ -228,11 +228,11 @@ public:
unsigned song_id, uint8_t priority);
/**
* Sets the start_ms and end_ms attributes on the song
* Sets the start_time and end_time attributes on the song
* with the specified id.
*/
bool SetSongIdRange(PlayerControl &pc, unsigned id,
unsigned start_ms, unsigned end_ms,
SongTime start, SongTime end,
Error &error);
bool AddSongIdTag(unsigned id, TagType tag_type, const char *value,
......
......@@ -434,10 +434,10 @@ playlist::Shuffle(PlayerControl &pc, unsigned start, unsigned end)
bool
playlist::SetSongIdRange(PlayerControl &pc, unsigned id,
unsigned start_ms, unsigned end_ms,
SongTime start, SongTime end,
Error &error)
{
assert(end_ms == 0 || start_ms < end_ms);
assert(end.IsZero() || start < end);
int position = queue.IdToPosition(id);
if (position < 0) {
......@@ -467,20 +467,20 @@ playlist::SetSongIdRange(PlayerControl &pc, unsigned id,
/* validate the offsets */
const unsigned duration = song.GetTag().time;
if (start_ms / 1000u > duration) {
if (start.ToMS() / 1000u > duration) {
error.Set(playlist_domain,
int(PlaylistResult::BAD_RANGE),
"Invalid start offset");
return false;
}
if (end_ms / 1000u > duration)
end_ms = 0;
if (end.ToMS() / 1000u > duration)
end = SongTime::zero();
}
/* edit it */
song.SetStartTime(SongTime::FromMS(start_ms));
song.SetEndTime(SongTime::FromMS(end_ms));
song.SetStartTime(start);
song.SetEndTime(end);
/* announce the change to all interested subsystems */
UpdateQueuedSong(pc, nullptr);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment