Class: DTAS::Source::SplitFX

Inherits:
Sox
  • Object
show all
Includes:
Watchable
Defined in:
lib/dtas/source/splitfx.rb

Overview

:nodoc:

Constant Summary collapse

MAX_YAML_SIZE =
512 * 1024
SPLITFX_DEFAULTS =
SOX_DEFAULTS.merge(
  "command" => "#{SOX_DEFAULTS["command"]} $FX",
  "tryorder" => 3,
)

Constants inherited from Sox

DTAS::Source::Sox::SOX_DEFAULTS

Constants included from File

File::FILE_SIVS, File::SRC_SIVS

Constants included from Process

Process::PIDS

Constants included from Command

Command::COMMAND_DEFAULTS

Instance Attribute Summary collapse

Attributes included from File

#infile, #offset, #tryorder

Attributes included from Common

#dst, #dst_zero_byte, #requeued

Attributes included from Command

#command, #env, #pid, #spawn_at, #to_io

Instance Method Summary collapse

Methods inherited from Sox

#mcache_lookup, #soxi_failed

Methods included from XS

#xs

Methods included from File

#__file_init, #__offset_samples, #comments, #load!, #offset_samples, #offset_us, #replaygain, #source_file_dup, #to_hash, #to_source_cat, #to_state_hash, #trimfx

Methods included from Mp3gain

#__mp3gain_peak, #mp3gain_comments

Methods included from Process

#dtas_spawn, #env_expand, #env_expand_ary, #env_expand_i, #qx, reaper

Methods included from DTAS::SpawnFix

#spawn

Methods included from Common

#dst_assoc

Methods included from Command

#command_init, #on_death

Methods included from DTAS::Serialize

#ivars_to_hash

Constructor Details

#initialize(sox = DTAS::Source::Sox.new) ⇒ SplitFX

Returns a new instance of SplitFX.



19
20
21
22
23
# File 'lib/dtas/source/splitfx.rb', line 19

def initialize(sox = DTAS::Source::Sox.new)
  command_init(SPLITFX_DEFAULTS)
  @watch_extra = []
  @sox = sox
end

Instance Attribute Details

#sfx=(value) ⇒ Object (writeonly)

Sets the attribute sfx

Parameters:

  • value

    the value to set the attribute sfx to.



11
12
13
# File 'lib/dtas/source/splitfx.rb', line 11

def sfx=(value)
  @sfx = value
end

#sox=(value) ⇒ Object (writeonly)

Sets the attribute sox

Parameters:

  • value

    the value to set the attribute sox to.



11
12
13
# File 'lib/dtas/source/splitfx.rb', line 11

def sox=(value)
  @sox = value
end

Instance Method Details

#__load_commentsObject



57
58
59
60
61
62
# File 'lib/dtas/source/splitfx.rb', line 57

def __load_comments
  if c = @ymlhash["comments"]
    return c.each { |k,v| c[k] = v.to_s }
  end
  @sox.__load_comments
end

#command_stringObject



64
65
66
# File 'lib/dtas/source/splitfx.rb', line 64

def command_string
  @ymlhash["command"] || super
end

#cuebreakpointsObject



118
119
120
# File 'lib/dtas/source/splitfx.rb', line 118

def cuebreakpoints
  @splitfx.cuebreakpoints
end

#durationObject



110
111
112
# File 'lib/dtas/source/splitfx.rb', line 110

def duration
  @sox.duration
end

#formatObject



98
99
100
# File 'lib/dtas/source/splitfx.rb', line 98

def format
  @sox.format
end

#samplesObject



106
107
108
# File 'lib/dtas/source/splitfx.rb', line 106

def samples
  @sox.samples
end

#samples!Object



102
103
104
# File 'lib/dtas/source/splitfx.rb', line 102

def samples!
  @sox.samples!
end

#source_defaultsObject



114
115
116
# File 'lib/dtas/source/splitfx.rb', line 114

def source_defaults
  SPLITFX_DEFAULTS
end

#src_spawn(player_format, rg_state, opts) ⇒ Object



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/dtas/source/splitfx.rb', line 68

def src_spawn(player_format, rg_state, opts)
  raise "BUG: #{self.inspect}#src_spawn called twice" if @to_io
  e = @env.merge!(player_format.to_env)
  @sfx.infile_env(e, @sox.infile)

  # watch any scripts or files the command in the YAML file refers to
  if c = @sfx.command
    @sfx.expand_cmd(e, c).each do |f|
      File.readable?(f) and @watch_extra << f
    end
  end

  # allow users to specify explicit depdendencies to watch for edit
  case extra = @ymlhash['deps']
  when Array, String
    @watch_extra.concat(Array(extra))
  end

  # make sure these are visible to the "current" command...
  e["TRIMFX"] = trimfx
  e["RGFX"] = rg_state.effect(self) || nil
  e.merge!(@rg.to_env) if @rg

  @pid = dtas_spawn(e, command_string, opts)
end

#to_hshObject



94
95
96
# File 'lib/dtas/source/splitfx.rb', line 94

def to_hsh
  to_hash.delete_if { |k,v| v == SPLITFX_DEFAULTS[k] }
end

#try(ymlfile, offset = nil, trim = nil) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/dtas/source/splitfx.rb', line 25

def try(ymlfile, offset = nil, trim = nil)
  @splitfx = @ymlhash = nil
  st = File.stat(ymlfile)
  return false if !st.file? || st.size > MAX_YAML_SIZE

  # read 4 bytes first to ensure we have a YAML file with a hash:
  buf = "".dup
  File.open(ymlfile, "rb") do |fp|
    return false if fp.read(4, buf) != "---\n"
    buf << fp.read
  end

  sfx = DTAS::SplitFX.new
  Dir.chdir(File.dirname(ymlfile)) do # ugh
    @ymlhash = YAML.load(buf)
    @ymlhash['tracks'] ||= [ "t 0 default" ]
    sfx.import(@ymlhash)
    sfx.infile.replace(File.expand_path(sfx.infile))
  end
  @splitfx = sfx
  @infile = ymlfile
  sox = @sox.try(sfx.infile, offset, trim) or return false
  rv = source_file_dup(ymlfile, offset, trim)
  rv.sox = sox
  rv.env = sfx.env
  rv.sfx = sfx
  rv
rescue => e
  warn "#{e.message} (#{e.class})"
  false
end