From 1a63ca046d42dc9d35fe656c034e0c791834ae67 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Mon, 7 Dec 2015 11:04:32 +0000 Subject: player: tl (repeat|shuffle|max) and trim swap values It makes more sense to return the previous value rather than the newly-set one, since the user presumably knows what they're setting and might care about the previous value. --- Documentation/dtas-player_protocol.txt | 4 ++-- lib/dtas/player/client_handler.rb | 20 +++++++++++++------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/Documentation/dtas-player_protocol.txt b/Documentation/dtas-player_protocol.txt index e6466b7..7315411 100644 --- a/Documentation/dtas-player_protocol.txt +++ b/Documentation/dtas-player_protocol.txt @@ -284,10 +284,10 @@ Commands here should be alphabetized according to `LC_ALL=C sort' * tl repeat [BOOLEAN|1] - show/or change repeat status of the tracklist. With no args, this will show "true", "false", or "1" If set to "1", dtas-player will repeat the current track. - Returns current repeat status. + Returns the previous repeat status. * tl shuffle [BOOLEAN] - show/or change the current shuffle status of - the tracklist + the tracklist. Returns the previous shuffle status. * tl tracks returns a list of all TRACKIDS in the tracklist diff --git a/lib/dtas/player/client_handler.rb b/lib/dtas/player/client_handler.rb index 6ec9672..4827840 100644 --- a/lib/dtas/player/client_handler.rb +++ b/lib/dtas/player/client_handler.rb @@ -583,16 +583,18 @@ module DTAS::Player::ClientHandler # :nodoc: end def _dpc_tl_repeat(io, msg) + prev = @tl.repeat.to_s case msg.shift when 'true' then @tl.repeat = true when 'false' then @tl.repeat = false when '1' then @tl.repeat = 1 when nil end - io.emit("repeat #{@tl.repeat.to_s}") + io.emit("tl repeat #{prev}") end def _dpc_tl_shuffle(io, msg) + prev = (!!@tl.shuffle).to_s v = msg.shift case v when 'debug' then return io.emit(@tl.shuffle.to_yaml) # TODO: remove @@ -600,16 +602,18 @@ module DTAS::Player::ClientHandler # :nodoc: else set_bool(io, 'tl shuffle', v) { |b| @tl.shuffle = b } end - io.emit("shuffle #{(!!@tl.shuffle).to_s}") + io.emit("tl shuffle #{prev}") end def _dpc_tl_max(io, msg) + prev = @tl.max case msg.shift - when nil then io.emit("tl max #{@tl.max}") - when %r{\A(\d[\d_]*)\z} then io.emit("tl max #{@tl.max = $1.to_i}") + when nil + when %r{\A(\d[\d_]*)\z} then @tl.max = $1.to_i else return io.emit('ERR tl max must a non-negative integer') end + io.emit("tl max #{prev}") end def _dpc_tl_remove(io, msg) @@ -733,9 +737,9 @@ module DTAS::Player::ClientHandler # :nodoc: end def dpc_trim(io, msg) + t = @trim case msg.size - when 0 - io.emit({ 'trim' => @trim }.to_yaml) + when 0 # OK when 1, 2 case msg[0] when 'off' @@ -754,8 +758,10 @@ module DTAS::Player::ClientHandler # :nodoc: end end __current_requeue - io.emit('OK') + else + return io.emit('ERR usage: trim [off|TBEG [TLEN]]') end + io.emit(t ? t.map(&:to_s).join(' ') : 'off') end end # :startdoc: -- cgit v1.2.3-24-ge0c7