From 605b8403bec9607b2aa818ca9e1daeea607e89fa Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Thu, 17 Oct 2013 06:13:33 +0000 Subject: trimfx: flesh out parsing of commands Only lightly tested, but this should give us some idea of where we'll be going... --- lib/dtas/parse_time.rb | 29 ++++++++++++++++++++++++++++ lib/dtas/trimfx.rb | 51 +++++++++++++++++++++++++------------------------- 2 files changed, 55 insertions(+), 25 deletions(-) create mode 100644 lib/dtas/parse_time.rb (limited to 'lib') 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 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 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/ -- cgit v1.2.3-24-ge0c7