Class: Juicy::Song

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSong

Returns a new instance of Song.



8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/juicy/song.rb', line 8

def initialize

  #a song has a key, a mode, voices, tempo, time signature, 
  @voices = []
  @voices << Voice.new
  @key = :A
  @mode = :major
  @tempo = 150.0
  @time_signature = [4,4]
  @measures = []
  4.times {@measures << Measure.new(@time_signature)}
  
end

Instance Attribute Details

#measuresObject (readonly)

Returns the value of attribute measures.



6
7
8
# File 'lib/juicy/song.rb', line 6

def measures
  @measures
end

#tempoObject (readonly)

Returns the value of attribute tempo.



6
7
8
# File 'lib/juicy/song.rb', line 6

def tempo
  @tempo
end

Instance Method Details

#beat_length_in_millisecondsObject



52
53
54
# File 'lib/juicy/song.rb', line 52

def beat_length_in_milliseconds
  60_000.0/@tempo
end

#playObject



22
23
24
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
# File 'lib/juicy/song.rb', line 22

def play

  #  have musical construct yield notes up to a note manager/beat sequencer for each track
  #  chords will eventually have a play style (various types of arpeggiation and such), but
  #  for now they'll all just play all their notes at once for the given duration
  
  tracks = []

  chord_progression = ChordProgression.new
  
  #tracks << Track.new(chord_progression.initial_play_time, chord_progression.to_a, @tempo)
  
  melody = Melody.new(chord_progression, self)
  puts melody.inspect
  tracks << Track.new(melody.initial_play_time, melody.to_a, @tempo)
  melody = Melody.new(chord_progression, self)
  puts melody.inspect
  tracks << Track.new(melody.initial_play_time, melody.to_a, @tempo)
  melody = Melody.new(chord_progression, self)
  puts melody.inspect
  tracks << Track.new(melody.initial_play_time, melody.to_a, @tempo)
  melody = Melody.new(chord_progression, self)
  puts melody.inspect
  tracks << Track.new(melody.initial_play_time, melody.to_a, @tempo)
  
  Track.play_concurrently(tracks, @tempo)
  

end