[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 5/7] player: "tl goto" takes optional offset arg in HHMMSS.SUBSEC
From: |
Eric Wong |
Subject: |
[PATCH 5/7] player: "tl goto" takes optional offset arg in HHMMSS.SUBSEC |
Date: |
Mon, 9 Sep 2013 08:31:07 +0000 |
This should make implementing SetPosition in the MPRIS 2.0 spec
possible.
---
lib/dtas/player.rb | 4 ++--
lib/dtas/player/client_handler.rb | 3 ++-
lib/dtas/tracklist.rb | 12 +++++++-----
test/test_tracklist.rb | 8 ++++----
4 files changed, 15 insertions(+), 12 deletions(-)
diff --git a/lib/dtas/player.rb b/lib/dtas/player.rb
index 5e78d8e..9ab45fc 100644
--- a/lib/dtas/player.rb
+++ b/lib/dtas/player.rb
@@ -353,9 +353,9 @@ class DTAS::Player # :nodoc:
# don't get stuck in an infinite loop if @tl.repeat==true and we can't
# decode anything (FS errors, sox uninstalled, etc...)
- while path = @tl.advance_track(false)
+ while path_off = @tl.advance_track(false)
@sources.each do |src|
- rv = src.try(path) and return rv
+ rv = src.try(*path_off) and return rv
end
end
diff --git a/lib/dtas/player/client_handler.rb
b/lib/dtas/player/client_handler.rb
index 33cae05..c7dd31d 100644
--- a/lib/dtas/player/client_handler.rb
+++ b/lib/dtas/player/client_handler.rb
@@ -571,7 +571,8 @@ module DTAS::Player::ClientHandler # :nodoc:
io.emit(@tl.tracks.map! { |i| i.to_s }.join(' '))
when "goto"
track_id = msg.shift or return io.emit("ERR track_id not specified")
- if @tl.go_to(track_id.to_i)
+ offset = msg.shift # may be nil
+ if @tl.go_to(track_id.to_i, offset)
_tl_skip
io.emit("OK")
else
diff --git a/lib/dtas/tracklist.rb b/lib/dtas/tracklist.rb
index c3cd3ff..094c22d 100644
--- a/lib/dtas/tracklist.rb
+++ b/lib/dtas/tracklist.rb
@@ -32,11 +32,11 @@ class DTAS::Tracklist
def initialize
TL_DEFAULTS.each { |k,v| instance_variable_set("@#{k}", v) }
@list = []
- @goto_pos = nil
+ @goto_off = @goto_pos = nil
end
def reset
- @goto_pos = nil
+ @goto_off = @goto_pos = nil
@pos = TL_DEFAULTS["pos"]
end
@@ -68,7 +68,8 @@ class DTAS::Tracklist
def advance_track(repeat_ok = true)
return if @list.empty?
next_pos = @goto_pos || @pos + 1
- @goto_pos = nil
+ next_off = @goto_off # nil by default
+ @goto_pos = @goto_off = nil
if @list[next_pos]
@pos = next_pos
elsif @repeat && repeat_ok
@@ -76,7 +77,7 @@ class DTAS::Tracklist
else
return
end
- @list[next_pos]
+ [ @list[next_pos], next_off ]
end
def cur_track
@@ -106,9 +107,10 @@ class DTAS::Tracklist
end
end
- def go_to(track_id)
+ def go_to(track_id, offset_hhmmss = nil)
by_track_id = _track_id_map
if idx = by_track_id[track_id]
+ @goto_off = offset_hhmmss
return @address@hidden = idx]
end
@goto_pos = nil
diff --git a/test/test_tracklist.rb b/test/test_tracklist.rb
index fb5cc3e..74dcea2 100644
--- a/test/test_tracklist.rb
+++ b/test/test_tracklist.rb
@@ -32,11 +32,11 @@ class TestTracklist < Testcase
tl = DTAS::Tracklist.new
tl.instance_variable_get(:@list).replace(%w(a b c d e f g))
%w(a b c d e f g).each do |t|
- assert_equal t, tl.advance_track
+ assert_equal t, tl.advance_track[0]
end
assert_nil tl.advance_track
tl.repeat = true
- assert_equal 'a', tl.advance_track
+ assert_equal 'a', tl.advance_track[0]
end
def _build_mapping(tl)
@@ -49,9 +49,9 @@ class TestTracklist < Testcase
tl.instance_variable_get(:@list).replace(%w(a b c d e f g))
mapping = _build_mapping(tl)
assert_equal 'f', tl.go_to(mapping['f'])
- assert_equal 'f', tl.advance_track
+ assert_equal 'f', tl.advance_track[0]
assert_nil tl.go_to(1 << 128)
- assert_equal 'g', tl.advance_track
+ assert_equal 'g', tl.advance_track[0]
end
def test_remove_track
--
1.8.4
- [PATCH 1/7] dtas-console: avoid using current if it is nil, Eric Wong, 2013/09/09
- [PATCH 3/7] tracklist: next_track -> advance_track, Eric Wong, 2013/09/09
- [PATCH 5/7] player: "tl goto" takes optional offset arg in HHMMSS.SUBSEC,
Eric Wong <=
- [PATCH 7/7] tracklist: implement single-track repeat, Eric Wong, 2013/09/09
- [PATCH 2/7] player: reset tracklist when idle stat is detected, Eric Wong, 2013/09/09
- [PATCH 6/7] tracklist: previous! only wraps around when repeat is enabled, Eric Wong, 2013/09/09
- [PATCH 4/7] player: implement previous/next commands, Eric Wong, 2013/09/09