dtas-all
[Top][All Lists]
Advanced

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

[PATCH 1/2] tracklist: remove_track updates tracklist position


From: Eric Wong
Subject: [PATCH 1/2] tracklist: remove_track updates tracklist position
Date: Wed, 9 Oct 2013 06:49:56 +0000

We should not have the position point too far past the end of the
list.  This allows playback to start when we do "tl add" on
an idle player after removing something from the tracklist.
---
 lib/dtas/tracklist.rb | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/lib/dtas/tracklist.rb b/lib/dtas/tracklist.rb
index 6856648..325db20 100644
--- a/lib/dtas/tracklist.rb
+++ b/lib/dtas/tracklist.rb
@@ -101,11 +101,15 @@ def add_track(track, after_track_id = nil, set_as_current 
= false)
 
   def remove_track(track_id)
     by_track_id = _track_id_map
-    if idx = by_track_id.delete(track_id)
-      @list[idx] = nil
-      @list.compact!
-      # TODO: what do we do with @pos (and the currently-playing track)
+    idx = by_track_id.delete(track_id) or return false
+    @list[idx] = nil
+    @list.compact!
+    len = @list.size
+    if @pos >= len
+      @pos = len == 0 ? TL_DEFAULTS["pos"] : len
     end
+    @goto_pos = @goto_pos = nil # TODO: reposition?
+    true
   end
 
   def go_to(track_id, offset_hhmmss = nil)
-- 
1.8.3.2.701.g8c4e4ec




reply via email to

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