about summary refs log tree commit homepage
path: root/lib
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2013-10-17 06:13:33 +0000
committerEric Wong <normalperson@yhbt.net>2013-10-17 06:13:33 +0000
commit605b8403bec9607b2aa818ca9e1daeea607e89fa (patch)
tree87125cd0bc710879572ad7eb70f60f6efae9f876 /lib
parent1c77d0d7c414d43f751eeb308a1a47d87de6cc1e (diff)
downloaddtas-605b8403bec9607b2aa818ca9e1daeea607e89fa.tar.gz
Only lightly tested, but this should give us some idea of where
we'll be going...
Diffstat (limited to 'lib')
-rw-r--r--lib/dtas/parse_time.rb29
-rw-r--r--lib/dtas/trimfx.rb51
2 files changed, 55 insertions, 25 deletions
diff --git a/lib/dtas/parse_time.rb b/lib/dtas/parse_time.rb
new file mode 100644
index 0000000..c2ca777
--- /dev/null
+++ b/lib/dtas/parse_time.rb
@@ -0,0 +1,29 @@
+# Copyright (C) 2013, Eric Wong <normalperson@yhbt.net> and all contributors
+# License: GPLv3 or later (https://www.gnu.org/licenses/gpl-3.0.txt)
+require_relative '../dtas'
+module DTAS::ParseTime
+  def parse_time(time)
+    case time
+    when /\A\d+\z/
+      time.to_i
+    when /\A[\d\.]+\z/
+      time.to_f
+    when /\A[:\d\.]+\z/
+      hhmmss = time.dup
+      rv = hhmmss.sub!(/\.(\d+)\z/, "") ? "0.#$1".to_f : 0
+
+      # deal with HH:MM:SS
+      t = hhmmss.split(/:/)
+      raise ArgumentError, "Bad time format: #{hhmmss}" if t.size > 3
+
+      mult = 1
+      while part = t.pop
+        rv += part.to_i * mult
+        mult *= 60
+      end
+      rv
+    else
+      raise ArgumentError, "unparseable: #{time.inspect}"
+    end
+  end
+end
diff --git a/lib/dtas/trimfx.rb b/lib/dtas/trimfx.rb
index cbb2fa6..794e657 100644
--- a/lib/dtas/trimfx.rb
+++ b/lib/dtas/trimfx.rb
@@ -1,11 +1,15 @@
 # Copyright (C) 2013, Eric Wong <normalperson@yhbt.net> and all contributors
 # License: GPLv3 or later (https://www.gnu.org/licenses/gpl-3.0.txt)
 require_relative '../dtas'
+require_relative 'parse_time'
 require 'shellwords'
 
 class DTAS::TrimFX
+  include DTAS::ParseTime
+
   attr_reader :tbeg
   attr_reader :tlen
+  attr_reader :cmd
 
   def initialize(args)
     args = args.dup
@@ -18,6 +22,28 @@ class DTAS::TrimFX
     else
       raise ArgumentError, "#{args.inspect} not understood"
     end
+    case tmp =  args.shift
+    when "sh" then @cmd = args
+    when "sox" then tfx_sox(args)
+    when "eca" then tfx_eca(args)
+    when nil
+      @cmd = []
+    else
+      raise ArgumentError, "unknown effect type: #{tmp}"
+    end
+  end
+
+  def tfx_sox(args)
+    @cmd = %w(sox $SOXIN $SOXOUT $TRIMFX)
+    @cmd.concat(args)
+    @cmd.concat(%w($FADEFX))
+  end
+
+  def tfx_eca(args)
+    @cmd = %w(sox $SOXIN $SOX2ECA $TRIMFX)
+    @cmd.concat(%w(| ecasound $ECAFMT -i stdin -o stdout))
+    @cmd.concat(args)
+    @cmd.concat(%w(| sox $ECA2SOX - $SOXOUT $FADEFX))
   end
 
   def to_sox_arg(format)
@@ -34,31 +60,6 @@ class DTAS::TrimFX
     end
   end
 
-  def parse_time(tbeg)
-    case tbeg
-    when /\A\d+\z/
-      tbeg.to_i
-    when /\A[\d\.]+\z/
-      tbeg.to_f
-    when /\A[:\d\.]+\z/
-      hhmmss = tbeg.dup
-      rv = hhmmss.sub!(/\.(\d+)\z/, "") ? "0.#$1".to_f : 0
-
-      # deal with HH:MM:SS
-      t = hhmmss.split(/:/)
-      raise ArgumentError, "Bad time format: #{hhmmss}" if t.size > 3
-
-      mult = 1
-      while part = t.pop
-        rv += part.to_i * mult
-        mult *= 60
-      end
-      rv
-    else
-      raise ArgumentError, "unparseable: #{tbeg.inspect}"
-    end
-  end
-
   def parse_trim!(args)
     tbeg = parse_time(args.shift)
     if args[0] =~ /\A=?[\d\.]+\z/