Class: Juicy::Song
- Inherits:
-
Object
- Object
- Juicy::Song
- Defined in:
- lib/juicy/song.rb
Instance Attribute Summary collapse
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#measures ⇒ Object
readonly
Returns the value of attribute measures.
-
#mode ⇒ Object
readonly
Returns the value of attribute mode.
-
#tempo ⇒ Object
readonly
Returns the value of attribute tempo.
Instance Method Summary collapse
- #beat_length_in_milliseconds ⇒ Object
- #demo_melody ⇒ Object
-
#initialize ⇒ Song
constructor
A new instance of Song.
- #play ⇒ Object
Constructor Details
#initialize ⇒ Song
Returns a new instance of Song.
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 |
# 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 = 100.0 @time_signature = [4,4] @measures = [] 4.times {@measures << Measure.new(@time_signature)} # 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 = [] key = Key.new chord_progression = ChordProgression.new(@key, @mode) @tracks << Track.new(0, demo_melody, @tempo) number_of_tracks = 1 number_of_tracks.times do melody = Melody.new(chord_progression, self) @tracks << Track.new(melody.initial_play_time, melody, @tempo) end end |
Instance Attribute Details
#key ⇒ Object (readonly)
Returns the value of attribute key.
6 7 8 |
# File 'lib/juicy/song.rb', line 6 def key @key end |
#measures ⇒ Object (readonly)
Returns the value of attribute measures.
6 7 8 |
# File 'lib/juicy/song.rb', line 6 def measures @measures end |
#mode ⇒ Object (readonly)
Returns the value of attribute mode.
6 7 8 |
# File 'lib/juicy/song.rb', line 6 def mode @mode end |
#tempo ⇒ Object (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_milliseconds ⇒ Object
44 45 46 |
# File 'lib/juicy/song.rb', line 44 def beat_length_in_milliseconds 60_000.0/@tempo end |
#demo_melody ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/juicy/song.rb', line 48 def demo_melody @demo_melody ||= [ Note.new(name: "A", duration: :eighth, octave_change: -1), Note.new(name: "E", duration: :eighth, octave_change: -1), Note.new(name: "C#", duration: :eighth, octave_change: -1), Note.new(name: "E", duration: :eighth, octave_change: -1), Note.new(name: "A", duration: :eighth, octave_change: 0), Note.new(name: "E", duration: :eighth, octave_change: -1), Note.new(name: "C#", duration: :eighth, octave_change: -1), Note.new(name: "E", duration: :eighth, octave_change: -1), Note.new(name: "A", duration: :eighth, octave_change: -1), Note.new(name: "E", duration: :eighth, octave_change: -1), Note.new(name: "C#", duration: :eighth, octave_change: -1), Note.new(name: "E", duration: :eighth, octave_change: -1), Note.new(name: "A", duration: :eighth, octave_change: 0), Note.new(name: "E", duration: :eighth, octave_change: -1), Note.new(name: "C#", duration: :eighth, octave_change: -1), Note.new(name: "E", duration: :eighth, octave_change: -1), Note.new(name: "D", duration: :eighth, octave_change: -1), Note.new(name: "A", duration: :eighth, octave_change: 0), Note.new(name: "F#", duration: :eighth, octave_change: -1), Note.new(name: "A", duration: :eighth, octave_change: 0), Note.new(name: "D", duration: :eighth, octave_change: 0), Note.new(name: "A", duration: :eighth, octave_change: 0), Note.new(name: "F#", duration: :eighth, octave_change: -1), Note.new(name: "A", duration: :eighth, octave_change: 0), Note.new(name: "D", duration: :eighth, octave_change: -1), Note.new(name: "A", duration: :eighth, octave_change: 0), Note.new(name: "F#", duration: :eighth, octave_change: -1), Note.new(name: "A", duration: :eighth, octave_change: 0), Note.new(name: "D", duration: :eighth, octave_change: 0), Note.new(name: "A", duration: :eighth, octave_change: 0), Note.new(name: "F#", duration: :eighth, octave_change: -1), Note.new(name: "A", duration: :eighth, octave_change: 0) ] end |
#play ⇒ Object
38 39 40 41 42 |
# File 'lib/juicy/song.rb', line 38 def play Track.play_concurrently(@tracks, @tempo) end |