From 173c00415b27214b2bb67ac15359d7e50be60623 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Mon, 9 Sep 2013 04:35:22 +0000 Subject: tracklist: fix go_to functionality 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 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'lib') 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 -- cgit v1.2.3-24-ge0c7