diff options
author | Eric Wong <e@80x24.org> | 2015-01-19 09:36:44 +0000 |
---|---|---|
committer | Eric Wong <e@80x24.org> | 2015-01-19 10:10:24 +0000 |
commit | b524cec0d86da22a3ff8fdb93328f54d7ccbdf29 (patch) | |
tree | 9ea701e9558aa161e15599dda26c69a61362ab5e | |
parent | ef39866fa6e6ac91cc64f18573dea22c3f75c6e1 (diff) | |
download | dtas-b524cec0d86da22a3ff8fdb93328f54d7ccbdf29.tar.gz |
This reverts commit 3471463325be6c990b3abd18b4d34f723440d19a. While not strictly necessary, it makes the user syntax in splitfx files much terser. Changes from the original version should make it easier-to-read and the diagram should help a lot with understanding.
-rw-r--r-- | lib/dtas/fadefx.rb | 44 | ||||
-rw-r--r-- | test/test_fadefx.rb | 28 |
2 files changed, 72 insertions, 0 deletions
diff --git a/lib/dtas/fadefx.rb b/lib/dtas/fadefx.rb new file mode 100644 index 0000000..1ef79ef --- /dev/null +++ b/lib/dtas/fadefx.rb @@ -0,0 +1,44 @@ +# Copyright (C) 2013-2015, all contributors <dtas-all@nongnu.org> +# License: GPLv3 or later (https://www.gnu.org/licenses/gpl-3.0.txt) +require_relative '../dtas' +require_relative 'parse_time' + +# --------- time ---------> +# _____ _______ ______ +# \ / \ / +# prev X cur X next +# _____/ \_______/ \______ +# +# out_prev - controls the downward slope from prev +# in_cur - controls the upward slope into cur +# out_cur - controls the downward slope from cur +# in_next - controls the upward slope into next +class DTAS::FadeFX # :nodoc: + include DTAS::ParseTime + + attr_reader :out_prev, :in_cur, :out_cur, :in_next + F = Struct.new(:type, :flen) + + def initialize(args) + args =~ /\A([^,]*),([^,]*);([^,]*),([^,]*)\z/ or + raise ArgumentError, "bad fade format" + fades = [ $1, $2, $3, $4 ] + %w(out_prev in_cur out_cur 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) + return nil if str.empty? + type = "t" + str.sub!(/\A([a-z])/, "") and type = $1 + F.new(type, parse_time(str)) + end +end diff --git a/test/test_fadefx.rb b/test/test_fadefx.rb new file mode 100644 index 0000000..e4f34fd --- /dev/null +++ b/test/test_fadefx.rb @@ -0,0 +1,28 @@ +# Copyright (C) 2013-2015, all contributors <dtas-all@nongnu.org> +# 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("t1,t3.1;l4,t1") + assert_equal 't', ffx.out_prev.type + assert_equal 1, ffx.out_prev.flen + assert_equal 't', ffx.in_cur.type + assert_equal 3.1, ffx.in_cur.flen + assert_equal 'l', ffx.out_cur.type + assert_equal 4, ffx.out_cur.flen + assert_equal 't', ffx.in_next.type + assert_equal 1, ffx.in_next.flen + end + + def test_fadefx_no_cur + ffx = DTAS::FadeFX.new("t1,;,t1") + assert_equal 't', ffx.out_prev.type + assert_equal 1, ffx.out_prev.flen + assert_nil ffx.in_cur + assert_nil ffx.out_cur + assert_equal 't', ffx.in_next.type + assert_equal 1, ffx.in_next.flen + end +end |