dtas-all
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 3/3] tracklist: fix go_to functionality


From: Eric Wong
Subject: [PATCH 3/3] tracklist: fix go_to functionality
Date: Mon, 9 Sep 2013 04:39:46 +0000

We need to preserve the go_to-specified position for next_track,
doing otherwise would cause us to always be off-by-one.
---
 lib/dtas/tracklist.rb  | 7 +++++--
 test/test_tracklist.rb | 1 +
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/lib/dtas/tracklist.rb b/lib/dtas/tracklist.rb
index 2336545..01339cc 100644
--- a/lib/dtas/tracklist.rb
+++ b/lib/dtas/tracklist.rb
@@ -32,6 +32,7 @@ class DTAS::Tracklist
   def initialize
     TL_DEFAULTS.each { |k,v| instance_variable_set("@#{k}", v) }
     @list = []
+    @goto_pos = nil
   end
 
   def size
@@ -61,7 +62,8 @@ class DTAS::Tracklist
 
   def next_track(repeat_ok = true)
     return if @list.empty?
-    next_pos = @pos + 1
+    next_pos = @goto_pos || @pos + 1
+    @goto_pos = nil
     if @list[next_pos]
       @pos = next_pos
     elsif @repeat && repeat_ok
@@ -102,8 +104,9 @@ class DTAS::Tracklist
   def go_to(track_id)
     by_track_id = _track_id_map
     if idx = by_track_id[track_id]
-      return @address@hidden = idx]
+      return @address@hidden = idx]
     end
+    @goto_pos = nil
     # noop if track_id is invalid
   end
 end
diff --git a/test/test_tracklist.rb b/test/test_tracklist.rb
index cc462c5..e4ca9ac 100644
--- a/test/test_tracklist.rb
+++ b/test/test_tracklist.rb
@@ -49,6 +49,7 @@ 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.next_track
     assert_nil tl.go_to(1 << 128)
     assert_equal 'g', tl.next_track
   end
-- 
1.8.4




reply via email to

[Prev in Thread] Current Thread [Next in Thread]