Class: Song

Inherits:
Object
  • Object
show all
Defined in:
lib/serinette/song.rb

Constant Summary collapse

LOWEST_DURATION =
60
HIGHEST_DURATION =
180
OUTPUT_FILE_NAME =
'tmp/output.wav'
CHANNELS =
2
RATE =
99600
TRACK_NUMBER =
2
EFFECT_NUMBER =
1

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSong

Returns a new instance of Song



17
18
19
20
21
# File 'lib/serinette/song.rb', line 17

def initialize
  set_duration
  set_tracks
  set_effects
end

Instance Attribute Details

#durationObject

Returns the value of attribute duration



15
16
17
# File 'lib/serinette/song.rb', line 15

def duration
  @duration
end

#effectsObject

Returns the value of attribute effects



15
16
17
# File 'lib/serinette/song.rb', line 15

def effects
  @effects
end

#tracksObject

Returns the value of attribute tracks



15
16
17
# File 'lib/serinette/song.rb', line 15

def tracks
  @tracks
end

Instance Method Details

#orchestrateObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/serinette/song.rb', line 23

def orchestrate
  # clear tmp dir
  clean

  # get file names from tracks
  track_files = render

  # build sox command
  sox = Sox::Cmd.new(:combine => :mix)

  track_files.each do |file|
    sox.add_input(file)
  end

  sox.set_output(OUTPUT_FILE_NAME)
  sox.set_effects(get_effects)

  # execute command
  sox.run
end

#renderObject



44
45
46
47
48
# File 'lib/serinette/song.rb', line 44

def render
  @tracks.map do |track|
    track.render
  end
end