From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-Status: No, score=-3.9 required=3.0 tests=AWL,BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dcvr.yhbt.net (Postfix) with ESMTPS id 1753B1F55B for ; Mon, 25 May 2020 09:10:54 +0000 (UTC) Received: from localhost ([::1]:54780 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jd98G-0004mV-VJ for e@80x24.org; Mon, 25 May 2020 05:10:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44714) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jd98G-0004mI-2p for dtas-all@nongnu.org; Mon, 25 May 2020 05:10:52 -0400 Received: from dcvr.yhbt.net ([64.71.152.64]:48048) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jd98F-0002rP-Az for dtas-all@nongnu.org; Mon, 25 May 2020 05:10:51 -0400 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 27F581F55B for ; Mon, 25 May 2020 09:10:46 +0000 (UTC) From: Eric Wong To: dtas-all@nongnu.org Subject: [PATCH] player: fix +/- directional seeks while paused Date: Mon, 25 May 2020 09:10:46 +0000 Message-Id: <20200525091046.8361-1-e@yhbt.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=64.71.152.64; envelope-from=e@yhbt.net; helo=dcvr.yhbt.net X-detected-operating-system: by eggs.gnu.org: First seen = 2020/05/25 05:10:46 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_PASS=-0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: dtas-all@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: duct tape audio suite List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dtas-all-bounces+e=80x24.org@nongnu.org Sender: "dtas-all" Using relative seek (Up/Dn/PgUp/PgDn) with dtas-console while dtas-player is paused was causing non-sensical/confusing results on unpause. So clamp the minimum seek time to 0s the same way we clamp during playback. --- lib/dtas/player/client_handler.rb | 36 +++++++++++++++++++------------ 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/lib/dtas/player/client_handler.rb b/lib/dtas/player/client_handler.rb index 6535f04..cf5442d 100644 --- a/lib/dtas/player/client_handler.rb +++ b/lib/dtas/player/client_handler.rb @@ -197,19 +197,20 @@ def __goto_offset_samples(offset) 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 @@ def seek_internal(cur, offset) 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 @@ def dpc_seek(io, msg) 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")