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.rb32
1 files changed, 22 insertions, 10 deletions
diff --git a/lib/dtas/splitfx.rb b/lib/dtas/splitfx.rb
index 58c8ff4..1150ee0 100644
--- a/lib/dtas/splitfx.rb
+++ b/lib/dtas/splitfx.rb
@@ -1,19 +1,18 @@
-# Copyright (C) 2013-2020 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,6 +205,7 @@ 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))
     t.comments.each do |k,v|
       env[k] = v.to_s
@@ -292,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
 
@@ -301,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)}"
@@ -358,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]
@@ -386,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
 
@@ -404,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