6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
# File 'lib/juicy/melody.rb', line 6
def initialize(chord_progression = ChordProgression.new, song = Song.new)
@notes = [
Note.new("C", "half", 1),Note.new("E", "", 1),Note.new("G", "", 1),
Note.new("F", "", 1),Note.new("F", "eighth", 1),Note.new("G", "eighth", 1),Note.new("F", "half", 1),
Note.new("C", "half", 1),Note.new("E", "", 1),Note.new("G", "", 1),
Note.new("D", "", 1),Note.new("D", "eighth", 1),Note.new("E", "eighth", 1),Note.new("D", "half", 1)
]
@notes = []
song.measures.each do |measure|
end
(10).times do
@notes << Note.new((["A", "C", "E"]).sample + [""].sample, ["eighth"].sample, [*(-1)..1].sample)
end
(10).times do
@notes << Note.new((["E", "G#", "B"]).sample + [""].sample, ["eighth"].sample, [*(-1)..1].sample)
end
(10).times do
@notes << Note.new((["A", "C", "E"]).sample + [""].sample, ["eighth"].sample, [*(-1)..1].sample)
end
sum_of_durations = 0
@notes.each do |note|
sum_of_durations += note.duration_in_milliseconds(song.tempo)
note.distance_from_beat_in_milliseconds = (sum_of_durations.round % Duration.duration_of_quarter_note_in_milliseconds(song.tempo).round)
note.plays_during(sum_of_durations.round / Duration.duration_of_quarter_note_in_milliseconds(song.tempo).round + 1)
end
end
|