about summary refs log tree commit homepage
path: root/lib/dtas/splitfx.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/dtas/splitfx.rb')
-rw-r--r--lib/dtas/splitfx.rb39
1 files changed, 27 insertions, 12 deletions
diff --git a/lib/dtas/splitfx.rb b/lib/dtas/splitfx.rb
index c0c7ac9..1150ee0 100644
--- a/lib/dtas/splitfx.rb
+++ b/lib/dtas/splitfx.rb
@@ -1,19 +1,18 @@
-# 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 '../dtas'
 require_relative 'format'
 require_relative 'process'
-require_relative 'xs'
 require 'tempfile'
 
 # The backend for dtas-splitfx(1) command, but also supported by dtas-player
 # 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 $OUTDST $TRIMFX $FX $RATEFX $DITHERFX'
+  CMD = 'sox "$INFILE" $COMMENTS $OUTFMT $OUTDST $TRIMFX $FX' \
+        ' $RATEFX $DITHERFX $STATS'
   include DTAS::Process
-  include DTAS::XS
   attr_reader :infile, :env, :command
 
   # for --trim on the command-line
@@ -115,7 +114,7 @@ class DTAS::SplitFX # :nodoc:
     end
 
     case v = hash["track_zpad"]
-    when Integer then @track_zpad = val
+    when Integer then @track_zpad = v
     else
       _bool(hash, "track_zpad") { |val| @track_zpad = val }
     end
@@ -206,12 +205,13 @@ class DTAS::SplitFX # :nodoc:
     elsif outfmt.bits && outfmt.bits <= 16
       env["DITHERFX"] = "dither -s"
     end
+    env['STATS'] = 'stats' if opts[:stats]
     comments = Tempfile.new(%W(dtas-splitfx-#{t.comments["TRACKNUMBER"]} .txt))
-    comments.sync = true
     t.comments.each do |k,v|
       env[k] = v.to_s
       comments.puts("#{k}=#{v}")
     end
+    comments.flush
     env["COMMENTS"] = "--comment-file=#{comments.path}"
     infile_env(env, @infile)
     outarg = outfmt.to_sox_arg
@@ -250,7 +250,10 @@ class DTAS::SplitFX # :nodoc:
     command = 'true' if opts[:dryrun] # still gotta fork
 
     # pgroup: false so Ctrl-C on command-line will immediately stop everything
-    [ dtas_spawn(env, command, pgroup: false), comments ]
+    o = { pgroup: false }
+    e = opts[:err_suffix] and
+      o[:err] = [ "#{env['OUTDIR']}#{env['TRACKNUMBER']}#{e}", 'a' ]
+    [ dtas_spawn(env, command, o), comments ]
   end
 
   def load_tracks!(hash)
@@ -289,6 +292,7 @@ class DTAS::SplitFX # :nodoc:
       t = T.new
       t.tbeg = @t2s.call(start_time)
       t.comments = @comments.dup
+      title.valid_encoding? or warn "#{title.inspect} encoding invalid"
       t.comments["TITLE"] = title
       t.env = @env.dup
 
@@ -298,6 +302,7 @@ class DTAS::SplitFX # :nodoc:
           t.fade_in = $1.split(/\s+/)
         when %r{\Afade_out=(.+)\z} # $1 = "t 4" or just "4"
           t.fade_out = $1.split(/\s+/)
+        when %r{\Aenv\.([^=]+)=(.+)\z} then t.env[$1] = -$2
         when %r{\A\.(\w+)=(.+)\z} then t.comments[$1] = $2
         else
           raise ArgumentError, "unrecognized arg(s): #{xs(argv)}"
@@ -355,9 +360,19 @@ class DTAS::SplitFX # :nodoc:
     @rate = opts[:rate]
     @bits = opts[:bits]
     trim = opts[:trim] and @tracks = [ UTrim.new(trim, @env, @comments) ]
-
+    if trim && opts[:filter]
+      raise ArgumentError, 'trim and filter are mutually exclusive'
+    end
     fails = []
     tracks = @tracks.dup
+    (opts[:filter] || []).each do |re|
+      field, val = re.split(/=/, 2)
+      if val
+        tracks.delete_if { |t| (t.comments[field] || '') !~ /#{val}/ }
+      else
+        tracks.delete_if { |t| t.comments.values.grep(/#{re}/).empty? }
+      end
+    end
     pids = {}
     jobs = opts[:jobs] || tracks.size # jobs == nil => everything at once
     if opts[:sox_pipe]
@@ -383,7 +398,7 @@ class DTAS::SplitFX # :nodoc:
         @out.puts "DONE #{done[0].inspect}" if $DEBUG
         done[1].close!
       else
-        fails << [ t, status ]
+        fails << [ done[0], status ]
       end
     end
 
@@ -401,10 +416,10 @@ class DTAS::SplitFX # :nodoc:
   end
 
   def infile_env(env, infile)
-    env["INFILE"] = xs(infile)
+    env["INFILE"] = infile
     dir, base = File.split(File.expand_path(infile))
-    env["INDIR"] = xs(dir)
-    env["INBASE"] = xs(base)
+    env["INDIR"] = dir
+    env["INBASE"] = base
   end
 
   def expand_cmd(env, command) # for display purposes only