Class: AudioMixer::Sox::Composition

Inherits:
Object
  • Object
show all
Defined in:
lib/audio_mixer/sox/composition.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename) ⇒ Composition

Returns a new instance of Composition.



8
9
10
11
# File 'lib/audio_mixer/sox/composition.rb', line 8

def initialize(filename)
  @filename = filename
  update!
end

Instance Attribute Details

#soundsObject (readonly)

Returns the value of attribute sounds.



6
7
8
# File 'lib/audio_mixer/sox/composition.rb', line 6

def sounds
  @sounds
end

Instance Method Details

#has_changed?Boolean

Returns:

  • (Boolean)


13
14
15
16
17
# File 'lib/audio_mixer/sox/composition.rb', line 13

def has_changed?
  File.new(@filename, "r").mtime > @last_mtime
rescue Errno::ENOENT
  puts "Composition file unavailable!"
end

#update!Object



19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/audio_mixer/sox/composition.rb', line 19

def update!
  YAML.load_file(@filename).tap do |collection|
    if collection_is_valid?(collection)
      @sounds = collection
      puts "Composition file updated..."
    end
  end
rescue Psych::SyntaxError
  puts "Composition file corrupted, ignoring..."
ensure
  @last_mtime = Time.now
end