From 7b065706d37df9e54c8b3299ce696545c6159fa4 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sat, 5 Dec 2015 02:32:19 +0000 Subject: tracklist: use lower number unique track IDs This is easier for users to read and type; and _might_ help with race conditions due to fast object recycling from GC. We'll also be implementing playist versioning on top of this in the next commits for MPD protocol compatibility. Unfortunately this adds an additional 40 bytes of per-track overhead (on 64-bit systems, its only 20 bytes on 32-bit). However, we may be able to save memory in the future by supporting dtas-mlib node IDs if we integrate dtas-player with DTAS::Mlib. While we're at it, include a minor speedup for DTAS::Tracklist#remove_track by using Array#delete_at instead of relying on Array#compact! after assignment This should improve "dtas-tl cat" output readability dramatically. The state file (~/.dtas/player_state.yml) remains compatible between dtas-player before and after this change. --- lib/dtas/player/client_handler.rb | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'lib/dtas/player/client_handler.rb') diff --git a/lib/dtas/player/client_handler.rb b/lib/dtas/player/client_handler.rb index fab60f3..0aa264f 100644 --- a/lib/dtas/player/client_handler.rb +++ b/lib/dtas/player/client_handler.rb @@ -587,15 +587,16 @@ module DTAS::Player::ClientHandler # :nodoc: when "remove" track_id = msg.shift or return io.emit("ERR track_id not specified") track_id = track_id.to_i - @tl.remove_track(track_id) or return io.emit("MISSING") + rm = @tl.remove_track(track_id) or return io.emit("MISSING") + rm = rm.object_id # skip if we're removing the currently playing track if @current && @current.respond_to?(:infile) && - @current.infile.object_id == track_id + @current.infile.object_id == rm _tl_skip end # drop it from the queue, too, in case it just got requeued or paused - @queue.delete_if { |t| Array === t && t[0].object_id == track_id } + @queue.delete_if { |t| Array === t && t[0].object_id == rm } io.emit("OK") when "get" res = @tl.get_tracks(msg.map!(&:to_i)) @@ -615,11 +616,11 @@ module DTAS::Player::ClientHandler # :nodoc: io.emit("MISSING") end when "current" - path = @tl.cur_track - io.emit(path ? path : "NONE") + track = @tl.cur_track + io.emit(track ? track.to_path : "NONE") when "current-id" - path = @tl.cur_track - io.emit(path ? path.object_id.to_s : "NONE") + track = @tl.cur_track + io.emit(track ? track.track_id.to_s : "NONE") when "next" _tl_skip io.emit("OK") -- cgit v1.2.3-24-ge0c7