diff options
Diffstat (limited to 'lib/dtas/player/client_handler.rb')
-rw-r--r-- | lib/dtas/player/client_handler.rb | 44 |
1 files changed, 26 insertions, 18 deletions
diff --git a/lib/dtas/player/client_handler.rb b/lib/dtas/player/client_handler.rb index 1e4ac96..3c5fe5d 100644 --- a/lib/dtas/player/client_handler.rb +++ b/lib/dtas/player/client_handler.rb @@ -1,4 +1,4 @@ -# Copyright (C) 2013-2016 all contributors <dtas-all@nongnu.org> +# Copyright (C) all contributors <dtas-all@nongnu.org> # License: GPL-3.0+ <https://www.gnu.org/licenses/gpl-3.0.txt> # frozen_string_literal: true require_relative '../xs' @@ -135,7 +135,7 @@ module DTAS::Player::ClientHandler # :nodoc: # or variable names. sink.valid_name?(name) or return io.emit("ERR sink name invalid") - sink.name = DTAS.dedupe_str(name) + sink.name = -name active_before = sink.active before = __sink_snapshot(sink) @@ -144,7 +144,7 @@ module DTAS::Player::ClientHandler # :nodoc: k, v = kv.split('=', 2) case k when %r{\Aenv\.([^=]+)\z} - sink.env[DTAS.dedupe_str($1)] = v + sink.env[$1] = v when %r{\Aenv#([^=]+)\z} v == nil or return io.emit("ERR unset env has no value") sink.env.delete($1) @@ -197,19 +197,20 @@ module DTAS::Player::ClientHandler # :nodoc: end end + def __offset_to_i(offset, src) + # either "999s" for 999 samples or HH:MM:SS for time + offset.sub!(/s\z/, '') ? offset.to_i : src.format.hhmmss_to_samples(offset) + end + def __offset_to_samples(offset) - offset.sub!(/s\z/, '') and return offset.to_i - @current.format.hhmmss_to_samples(offset) + __offset_to_i(offset, @current) end # returns seek offset as an Integer in sample count - def __seek_offset_adj(dir, offset) - if offset.sub!(/s\z/, '') - offset = offset.to_i - else # time - offset = @current.format.hhmmss_to_samples(offset) - end - n = __current_decoded_samples + (dir * offset) + def __seek_offset_adj(dir, offset, + src = @current, + current_decoded_samples = __current_decoded_samples) + n = current_decoded_samples + (dir * __offset_to_i(offset, src)) n = 0 if n < 0 "#{n}s" end @@ -391,15 +392,17 @@ module DTAS::Player::ClientHandler # :nodoc: end end + def __offset_direction(offset) + offset.sub!(/\A\+/, '') ? 1 : (offset.sub!(/\A-/, '') ? -1 : nil) + end + def dpc_seek(io, msg) offset = msg[0] or return io.emit('ERR usage: seek OFFSET') if @current if @current.respond_to?(:infile) begin - if offset.sub!(/\A\+/, '') - offset = __seek_offset_adj(1, offset) - elsif offset.sub!(/\A-/, '') - offset = __seek_offset_adj(-1, offset) + if direction = __offset_direction(offset) + offset = __seek_offset_adj(direction, offset) # else: pass to sox directly end rescue ArgumentError @@ -413,7 +416,12 @@ module DTAS::Player::ClientHandler # :nodoc: case file = @queue[0] when String @queue[0] = [ file, offset ] - when Array + when Array # offset already stored, adjust + if direction = __offset_direction(offset) + tmp = try_file(*file) + cur_off = __offset_to_i(file[1].dup, tmp) + offset = __seek_offset_adj(direction, offset, tmp, cur_off) + end file[1] = offset else return io.emit("ERR unseekable") @@ -556,7 +564,7 @@ module DTAS::Player::ClientHandler # :nodoc: rescue => e res = "ERR dumping to #{xs(sf.path)} #{e.message}" end - io.to_io.send(res, Socket::MSG_EOR) + io.to_io.send(res, 0) ensure exit!(0) end |