Class: Musicality::NoteArray
- Inherits:
-
Object
- Object
- Musicality::NoteArray
- Includes:
- Sequenceable
- Defined in:
- lib/musicality/composition/sequencing/note_array.rb
Instance Attribute Summary collapse
-
#duration ⇒ Object
readonly
Returns the value of attribute duration.
-
#notes ⇒ Object
readonly
Returns the value of attribute notes.
Instance Method Summary collapse
-
#initialize(notes) ⇒ NoteArray
constructor
A new instance of NoteArray.
- #next_note ⇒ Object
- #reset ⇒ Object
Constructor Details
#initialize(notes) ⇒ NoteArray
Returns a new instance of NoteArray.
7 8 9 10 11 12 13 14 15 |
# File 'lib/musicality/composition/sequencing/note_array.rb', line 7 def initialize notes raise ArgumentError if notes.empty? @notes = notes.clone.freeze @notes_idx = 0 @notes_count = notes.size @duration = @notes.inject(0) {|sum, note| sum + note.duration} end |
Instance Attribute Details
#duration ⇒ Object (readonly)
Returns the value of attribute duration.
6 7 8 |
# File 'lib/musicality/composition/sequencing/note_array.rb', line 6 def duration @duration end |
#notes ⇒ Object (readonly)
Returns the value of attribute notes.
6 7 8 |
# File 'lib/musicality/composition/sequencing/note_array.rb', line 6 def notes @notes end |
Instance Method Details
#next_note ⇒ Object
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/musicality/composition/sequencing/note_array.rb', line 17 def next_note note = @notes[@notes_idx] @notes_idx += 1 if @notes_idx >= @notes_count @notes_idx = 0 end return note end |
#reset ⇒ Object
28 29 30 |
# File 'lib/musicality/composition/sequencing/note_array.rb', line 28 def reset @notes_idx = 0 end |