[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 1/2] player: add factor out redundant condition check
From: |
Eric Wong |
Subject: |
[PATCH 1/2] player: add factor out redundant condition check |
Date: |
Sun, 6 Oct 2013 07:08:46 +0000 |
The addition of a "need_to_queue" method should reduce the amount of
cognitive overhead required to parse these conditions
---
lib/dtas/player.rb | 8 ++++++--
lib/dtas/player/client_handler.rb | 6 ++----
2 files changed, 8 insertions(+), 6 deletions(-)
diff --git a/lib/dtas/player.rb b/lib/dtas/player.rb
index efefcbf..f94c575 100644
--- a/lib/dtas/player.rb
+++ b/lib/dtas/player.rb
@@ -165,9 +165,13 @@ class DTAS::Player # :nodoc:
rv
end
+ def need_to_queue
+ @current || @queue[0] || @paused
+ end
+
def enq_handler(io, msg)
# check @queue[0] in case we have no sinks
- if @current || @queue[0] || @paused
+ if need_to_queue
@queue << msg
else
next_source(msg)
@@ -177,7 +181,7 @@ class DTAS::Player # :nodoc:
def do_enq_head(io, msg)
# check @queue[0] in case we have no sinks
- if @current || @queue[0] || @paused
+ if need_to_queue
@queue.unshift(msg)
else
next_source(msg)
diff --git a/lib/dtas/player/client_handler.rb
b/lib/dtas/player/client_handler.rb
index 5c6653c..75e490d 100644
--- a/lib/dtas/player/client_handler.rb
+++ b/lib/dtas/player/client_handler.rb
@@ -552,7 +552,7 @@ module DTAS::Player::ClientHandler # :nodoc:
_tl_skip if set_as_current
# start playing if we're the only track
- if @tl.size == 1 && !(@current || @queue[0] || @paused)
+ if @tl.size == 1 && ! need_to_queue
next_source(_next)
end
io.emit("#{track_id}")
@@ -589,9 +589,7 @@ module DTAS::Player::ClientHandler # :nodoc:
offset = msg.shift # may be nil
if @tl.go_to(track_id.to_i, offset)
_tl_skip
- if !(@current || @queue[0] || @paused)
- next_source(_next)
- end
+ next_source(_next) unless need_to_queue
io.emit("OK")
else
io.emit("MISSING")
--
1.8.4
- [PATCH 1/2] player: add factor out redundant condition check,
Eric Wong <=