Class: Musicality::Sequencer
- Inherits:
-
Object
- Object
- Musicality::Sequencer
- Defined in:
- lib/musicality/composition/sequencing/sequencer.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#part_names ⇒ Object
readonly
Returns the value of attribute part_names.
-
#part_sequenceables ⇒ Object
readonly
Returns the value of attribute part_sequenceables.
Instance Method Summary collapse
-
#initialize(part_sequenceables) ⇒ Sequencer
constructor
A new instance of Sequencer.
- #next_part_notes(target_duration) ⇒ Object
- #reset ⇒ Object
Constructor Details
#initialize(part_sequenceables) ⇒ Sequencer
Returns a new instance of Sequencer.
6 7 8 9 10 |
# File 'lib/musicality/composition/sequencing/sequencer.rb', line 6 def initialize part_sequenceables @part_sequenceables = part_sequenceables.freeze @part_note_fifos = Hash[ part_sequenceables.keys.map {|partname| [ partname, NoteFIFO.new ] } ] @part_names = @part_sequenceables.keys end |
Instance Attribute Details
#part_names ⇒ Object (readonly)
Returns the value of attribute part_names.
4 5 6 |
# File 'lib/musicality/composition/sequencing/sequencer.rb', line 4 def part_names @part_names end |
#part_sequenceables ⇒ Object (readonly)
Returns the value of attribute part_sequenceables.
4 5 6 |
# File 'lib/musicality/composition/sequencing/sequencer.rb', line 4 def part_sequenceables @part_sequenceables end |
Instance Method Details
#next_part_notes(target_duration) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/musicality/composition/sequencing/sequencer.rb', line 12 def next_part_notes target_duration if target_duration <= 0 raise ArgumentError, "Target duration #{target_duration} is non-positive}" end part_notes = {} @part_sequenceables.each do |partname, sequenceable| note_fifo = @part_note_fifos[partname] while note_fifo.duration < target_duration note_fifo.add_note(sequenceable.next_note) end part_notes[partname] = note_fifo.remove_notes(target_duration) end return part_notes end |
#reset ⇒ Object
30 31 32 |
# File 'lib/musicality/composition/sequencing/sequencer.rb', line 30 def reset @part_sequenceables.values.each { |s| s.reset } end |