From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS22989 208.118.235.0/24 X-Spam-Status: No, score=-1.9 required=3.0 tests=AWL,BAYES_00 shortcircuit=no autolearn=unavailable version=3.3.2 X-Original-To: dtas-all@80x24.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by dcvr.yhbt.net (Postfix) with ESMTPS id 1CDB01F5F2 for ; Sun, 24 May 2015 08:23:17 +0000 (UTC) Received: from localhost ([::1]:39375 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YwRBk-0004kw-71 for dtas-all@80x24.org; Sun, 24 May 2015 04:23:16 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34227) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YwRBe-0004ko-92 for dtas-all@nongnu.org; Sun, 24 May 2015 04:23:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YwRBZ-0007zy-G5 for dtas-all@nongnu.org; Sun, 24 May 2015 04:23:10 -0400 Received: from dcvr.yhbt.net ([64.71.152.64]:38209) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YwRBZ-0007zn-9z for dtas-all@nongnu.org; Sun, 24 May 2015 04:23:05 -0400 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 724B81F5F2; Sun, 24 May 2015 08:23:03 +0000 (UTC) From: Eric Wong To: Subject: [PATCH] splitfx: allow -p/--sox-pipe option Date: Sun, 24 May 2015 08:22:59 +0000 Message-Id: <1432455779-6096-1-git-send-email-e@80x24.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 64.71.152.64 Cc: Eric Wong X-BeenThere: dtas-all@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dtas-all-bounces+dtas-all=80x24.org@nongnu.org Sender: dtas-all-bounces+dtas-all=80x24.org@nongnu.org This allows splitfx YAML files to operate more seamlessly with external commands such as play(1) especially when combined with the -t/--trim option. --- Documentation/dtas-splitfx.txt | 5 +++++ bin/dtas-splitfx | 9 +++++++-- lib/dtas/splitfx.rb | 19 +++++++++++++------ 3 files changed, 25 insertions(+), 8 deletions(-) diff --git a/Documentation/dtas-splitfx.txt b/Documentation/dtas-splitfx.txt index 2a599ea..c077137 100644 --- a/Documentation/dtas-splitfx.txt +++ b/Documentation/dtas-splitfx.txt @@ -59,6 +59,11 @@ to use ecasound(1), too. of "000". For ease-of-typing, commas in this command-line argument are automatically expanded to spaces when passed to sox. +-p, \--sox-pipe +: Used in place of an output target to specify outputting audio data in + the native "sox" format to another sox(1) or play(1) command. This + moves printing of output to stderr and disables parallel job invocation. + # FILE FORMAT * infile - string, the pathname of the original audio file diff --git a/bin/dtas-splitfx b/bin/dtas-splitfx index d363ab9..fc8cc69 100755 --- a/bin/dtas-splitfx +++ b/bin/dtas-splitfx @@ -6,8 +6,8 @@ require 'optparse' require 'dtas/splitfx' usage = "#$0 [-n|--dry-run][-j [JOBS]][-s|--silent] SPLITFX_FILE.yml [TARGET]" overrides = {} # FIXME: not tested +default_target = "flac" opts = { jobs: 1 } -jobs = 1 OptionParser.new('', 24, ' ') do |op| op.banner = usage op.on('-n', '--dry-run') { opts[:dryrun] = true } @@ -19,6 +19,10 @@ OptionParser.new('', 24, ' ') do |op| op.on('-r', '--rate RATE') { |val| opts[:rate] = val } op.on('-b', '--bits RATE', Integer) { |val| opts[:bits] = val } op.on('-t', '--trim POSITION') { |val| opts[:trim] = val.tr(',', ' ') } + op.on('-p', '--sox-pipe') do + opts[:sox_pipe] = true + default_target = 'sox' + end op.parse!(ARGV) end @@ -39,8 +43,9 @@ ARGV.each do |arg| end end +trap(:INT) { exit 130 } file = args.shift or abort usage -target = args.shift || "flac" +target = args.shift || default_target splitfx = DTAS::SplitFX.new splitfx.import(YAML.load(File.read(file)), overrides) splitfx.run(target, opts) diff --git a/lib/dtas/splitfx.rb b/lib/dtas/splitfx.rb index adc6c77..97e6153 100644 --- a/lib/dtas/splitfx.rb +++ b/lib/dtas/splitfx.rb @@ -10,8 +10,7 @@ require 'tempfile' # Unlike the stuff for dtas-player, dtas-splitfx is fairly tied to sox # (but we may still pipe to ecasound or anything else) class DTAS::SplitFX # :nodoc: - CMD = 'sox "$INFILE" $COMMENTS $OUTFMT "$OUTDIR$TRACKNUMBER.$SUFFIX" '\ - '$TRIMFX $FX $RATEFX $DITHERFX' + CMD = 'sox "$INFILE" $COMMENTS $OUTFMT $OUTDST $TRIMFX $FX $RATEFX $DITHERFX' include DTAS::Process include DTAS::XS attr_reader :infile, :env, :command @@ -155,8 +154,6 @@ class DTAS::SplitFX # :nodoc: def generic_target(target = "flac") outfmt = @infmt.dup outfmt.type = target - outfmt.bits = @bits if @bits - outfmt.rate = @rate if @rate { "command" => CMD, "format" => outfmt } end @@ -174,6 +171,9 @@ class DTAS::SplitFX # :nodoc: outfmt.type = "flac" end + outfmt.bits = @bits if @bits + outfmt.rate = @rate if @rate + # player commands will use SOXFMT by default, so we must output that # as a self-describing format to the actual encoding instances player_cmd = @command @@ -211,6 +211,7 @@ class DTAS::SplitFX # :nodoc: env["OUTFMT"] = xs(outarg) env["SUFFIX"] = suffix env["OUTDIR"] = @outdir ? "#@outdir/".squeeze('/') : '' + env["OUTDST"] = opts[:sox_pipe] ? "-p" : "$OUTDIR$TRACKNUMBER.$SUFFIX" env.merge!(t.env) command = target["command"] @@ -237,7 +238,7 @@ class DTAS::SplitFX # :nodoc: show_cmd = expand_cmd(env, command) end - puts(show_cmd.join(' ')) unless opts[:silent] + @out.puts(show_cmd.join(' ')) unless opts[:silent] command = 'true' if opts[:dryrun] # still gotta fork # pgroup: false so Ctrl-C on command-line will immediately stop everything @@ -353,6 +354,12 @@ class DTAS::SplitFX # :nodoc: tracks = @tracks.dup pids = {} jobs = opts[:jobs] || tracks.size # jobs == nil => everything at once + if opts[:sox_pipe] + jobs = 1 + @out = $stderr + else + @out = $stdout + end jobs.times.each do t = tracks.shift or break pid, tmp = splitfx_spawn(target, t, opts) @@ -367,7 +374,7 @@ class DTAS::SplitFX # :nodoc: pid, tmp = splitfx_spawn(target, t, opts) pids[pid] = [ t, tmp ] end - puts "DONE #{done[0].inspect}" if $DEBUG + @out.puts "DONE #{done[0].inspect}" if $DEBUG done[1].close! else fails << [ t, status ] -- EW