diff options
author | Eric Wong <e@80x24.org> | 2015-12-05 02:32:19 +0000 |
---|---|---|
committer | Eric Wong <e@80x24.org> | 2015-12-05 02:33:29 +0000 |
commit | 7b065706d37df9e54c8b3299ce696545c6159fa4 (patch) | |
tree | b3079286e218fa40d9e0c65ee6de89d110b93d30 /lib/dtas/player/client_handler.rb | |
parent | 2d444cadc7c5dc42d89c02a9d999938c40bdcb9d (diff) | |
download | dtas-7b065706d37df9e54c8b3299ce696545c6159fa4.tar.gz |
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.
Diffstat (limited to 'lib/dtas/player/client_handler.rb')
-rw-r--r-- | lib/dtas/player/client_handler.rb | 15 |
1 files changed, 8 insertions, 7 deletions
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") |