about summary refs log tree commit homepage
path: root/lib/dtas/tracklist.rb
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2013-09-09 04:35:22 +0000
committerEric Wong <normalperson@yhbt.net>2013-09-09 04:38:57 +0000
commit173c00415b27214b2bb67ac15359d7e50be60623 (patch)
tree42dbcbb142ae358e1e799b8d92a68210e11ef379 /lib/dtas/tracklist.rb
parent6de01f03d5d9d248046853af45ed2eeef3b1308e (diff)
downloaddtas-173c00415b27214b2bb67ac15359d7e50be60623.tar.gz
We need to preserve the go_to-specified position for next_track,
doing otherwise would cause us to always be off-by-one.
Diffstat (limited to 'lib/dtas/tracklist.rb')
-rw-r--r--lib/dtas/tracklist.rb7
1 files changed, 5 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 @list[@pos = idx]
+      return @list[@goto_pos = idx]
     end
+    @goto_pos = nil
     # noop if track_id is invalid
   end
 end