about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2013-10-17 06:36:28 +0000
committerEric Wong <normalperson@yhbt.net>2013-10-17 06:36:28 +0000
commit27157b3a8cf6d2e37d80dfa130b56711dcb8cd28 (patch)
tree37dedc444a2b2d723954ae67214d6e03ad9a86ca
parent605b8403bec9607b2aa818ca9e1daeea607e89fa (diff)
downloaddtas-27157b3a8cf6d2e37d80dfa130b56711dcb8cd28.tar.gz
This allows parsing and will eventually interact with trimfx.
-rw-r--r--examples/trimfx.sample.yml2
-rw-r--r--lib/dtas/fadefx.rb32
-rw-r--r--test/test_fadefx.rb18
3 files changed, 51 insertions, 1 deletions
diff --git a/examples/trimfx.sample.yml b/examples/trimfx.sample.yml
index e205b03..3a45401 100644
--- a/examples/trimfx.sample.yml
+++ b/examples/trimfx.sample.yml
@@ -16,7 +16,7 @@ comments:
 track_start: 1
 effects:
 # the fade parameter sets the default fade for every subsequent effect
-- fade=t1,t1;t1,t1 # fade-out-orig,fade-in-new;fade-out-orig;fade-in-new
+- fade=t1,t1;t1,t1 # fade-out-prev,fade-in-main;fade-out-main,fade-in-next
 
 # the following commands are equivalent
 - trim 52 =53 sh sox $SOXIN $SOXOUT $TRIMFX vol -6dB $FADEFX
diff --git a/lib/dtas/fadefx.rb b/lib/dtas/fadefx.rb
new file mode 100644
index 0000000..7e0e65f
--- /dev/null
+++ b/lib/dtas/fadefx.rb
@@ -0,0 +1,32 @@
+# 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'
+
+class DTAS::FadeFX
+  include DTAS::ParseTime
+  attr_reader :out_prev, :in_main, :out_main, :in_next
+  F = Struct.new(:type, :len)
+
+  def initialize(args)
+    args =~ /\Afade=([^,]*),([^,]*);([^,]*),([^,]*)\z/ or
+      raise ArgumentError, "bad fade format"
+    fades = [ $1, $2, $3, $4 ]
+    %w(out_prev in_main out_main in_next).each do |iv|
+      instance_variable_set("@#{iv}", parse!(fades.shift))
+    end
+  end
+
+  # q - quarter of a sine wave
+  # h - half a sine wave
+  # t - linear (`triangular') slope
+  # l - logarithmic
+  # p - inverted parabola
+  # default is 't' (sox defaults to 'l', but triangular makes more sense
+  # when concatenating
+  def parse!(str)
+    type = "t"
+    str.sub!(/\A([a-z])/, "") and type = $1
+    F[type, parse_time(str)]
+  end
+end
diff --git a/test/test_fadefx.rb b/test/test_fadefx.rb
new file mode 100644
index 0000000..57ddabd
--- /dev/null
+++ b/test/test_fadefx.rb
@@ -0,0 +1,18 @@
+# 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 'helper'
+require 'dtas/fadefx'
+
+class TestFadeFX < Testcase
+  def test_fadefx
+    ffx = DTAS::FadeFX.new("fade=t1,t3.1;l4,t1")
+    assert_equal 't', ffx.out_prev.type
+    assert_equal 1, ffx.out_prev.len
+    assert_equal 't', ffx.in_main.type
+    assert_equal 3.1, ffx.in_main.len
+    assert_equal 'l', ffx.out_main.type
+    assert_equal 4, ffx.out_main.len
+    assert_equal 't', ffx.in_next.type
+    assert_equal 1, ffx.in_next.len
+  end
+end