Class: DTAS::FadeFX

Inherits:
Object
  • Object
show all
Includes:
ParseTime, XS
Defined in:
lib/dtas/fadefx.rb

Overview

note: This is sox-specific ——— 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

Defined Under Namespace

Classes: F

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from XS

#xs

Methods included from ParseTime

#parse_time

Constructor Details

#initialize(args) ⇒ FadeFX

Returns a new instance of FadeFX.



26
27
28
29
30
31
32
33
# File 'lib/dtas/fadefx.rb', line 26

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

Instance Attribute Details

#in_curObject (readonly)

Returns the value of attribute in_cur.



23
24
25
# File 'lib/dtas/fadefx.rb', line 23

def in_cur
  @in_cur
end

#in_nextObject (readonly)

Returns the value of attribute in_next.



23
24
25
# File 'lib/dtas/fadefx.rb', line 23

def in_next
  @in_next
end

#out_curObject (readonly)

Returns the value of attribute out_cur.



23
24
25
# File 'lib/dtas/fadefx.rb', line 23

def out_cur
  @out_cur
end

#out_prevObject (readonly)

Returns the value of attribute out_prev.



23
24
25
# File 'lib/dtas/fadefx.rb', line 23

def out_prev
  @out_prev
end

Instance Method Details

#fade_cur_fx(format, tbeg, tlen, args = []) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/dtas/fadefx.rb', line 35

def fade_cur_fx(format, tbeg, tlen, args = [])
  fx = %W(trim #{tbeg}s #{tlen}s)
  fx.concat(args)
  if @in_cur && @out_cur && @in_cur.type == @out_cur.type
    f = %W(fade #{@in_cur.type} #{@in_cur.flen} #{tlen}s #{@out_cur.flen})
    fx.concat(f)
  else # differing fade types for in/out, chain them:
    fpart = @in_cur and
      fx.concat(%W(fade #{fpart.type} #{fpart.flen} 0 0))
    fpart = @out_cur and
      fx.concat(%W(fade #{fpart.type} 0 #{tlen}s #{fpart.flen}))
  end
  fx
end

#fade_in_next_fx(format, tbeg, tlen) ⇒ Object



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/dtas/fadefx.rb', line 67

def fade_in_next_fx(format, tbeg, tlen)
  fpart = @in_next
  flen = fpart ? fpart.flen : 0
  nlen = format.hhmmss_to_samples(flen)
  nbeg = tbeg + tlen - nlen
  npad = nbeg - tbeg
  if npad < 0
    warn("in_next should not exceed range: #{inspect} @trim " \
         "#{tbeg}s #{tlen}s\nclamping to #{tbeg}")
    nbeg = tbeg
  end

  fx = %W(trim #{nbeg}s #{nlen}s)
  nlen != 0 and
    fx.concat(%W(fade #{fpart.type} #{nlen}s 0 0))

  # likely, the pad section is where fade_cur_fx goes
  npad > 0 and fx.concat(%W(pad #{npad}s@0s))
  fx
end

#fade_out_prev_fx(format, tbeg, tlen) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/dtas/fadefx.rb', line 50

def fade_out_prev_fx(format, tbeg, tlen)
  fx = %W(trim #{tbeg}s)

  if fpart = @out_prev
    out_len = format.hhmmss_to_samples(fpart.flen)
    fx.concat(%W(fade #{fpart.type} 0 #{out_len}s #{out_len}s))
    remain = tlen - out_len

    # fade-out is longer than tlen, so truncate again:
    remain < 0 and fx.concat(%W(trim 0 #{tlen}s))

    # pad with silence, this is where fade_cur_fx goes
    remain > 0 and fx.concat(%W(pad #{remain}s@#{out_len}s))
  end
  fx
end

#parse!(str) ⇒ Object

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



95
96
97
98
99
100
# File 'lib/dtas/fadefx.rb', line 95

def parse!(str)
  return nil if str.empty?
  type = "t"
  str.sub!(/\A([a-z])/, "") and type = DTAS.dedupe_str($1)
  F.new(type, parse_time(str))
end