Class: Musicality::NoteSequenceExtractor
- Inherits:
-
Object
- Object
- Musicality::NoteSequenceExtractor
- Defined in:
- lib/musicality/performance/conversion/note_sequence_extractor.rb
Instance Attribute Summary collapse
-
#notes ⇒ Object
readonly
Returns the value of attribute notes.
Instance Method Summary collapse
- #extract_sequences(cents_per_step = 10) ⇒ Object
-
#initialize(notes) ⇒ NoteSequenceExtractor
constructor
A new instance of NoteSequenceExtractor.
Constructor Details
#initialize(notes) ⇒ NoteSequenceExtractor
Returns a new instance of NoteSequenceExtractor.
5 6 7 8 9 10 11 12 |
# File 'lib/musicality/performance/conversion/note_sequence_extractor.rb', line 5 def initialize notes @notes = notes.map {|n| n.clone } mark_slurring remove_bad_links calculate_offsets # now, ready to extract sequences! end |
Instance Attribute Details
#notes ⇒ Object (readonly)
Returns the value of attribute notes.
4 5 6 |
# File 'lib/musicality/performance/conversion/note_sequence_extractor.rb', line 4 def notes @notes end |
Instance Method Details
#extract_sequences(cents_per_step = 10) ⇒ Object
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 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/musicality/performance/conversion/note_sequence_extractor.rb', line 14 def extract_sequences cents_per_step = 10 completed_seqs = [] continuing_sequences = {} @notes.each_with_index do |note, idx| offset = @offsets[idx] duration = note.duration attack = NoteSequenceExtractor.note_attack(note.articulation) separation = NoteSequenceExtractor.note_separation(note.articulation, @slurring_flags[idx]) next_note = (idx == (@notes.size-1)) ? Note.quarter : @notes[idx+1] continuation_map = NoteSequenceExtractor.continuation_map(note, next_note, separation) new_continuing_sequences = {} note.pitches.each do |p| seq = if continuing_sequences.has_key?(p) continuing_sequences[p].elements += note_pitch_elements(note, p, Attack::NONE, cents_per_step) continuing_sequences.delete(p) else NoteSequence.new(offset, separation, note_pitch_elements(note, p, attack, cents_per_step)) end if continuation_map.include?(p) new_continuing_sequences[continuation_map[p]] = seq else completed_seqs.push seq end end if continuing_sequences.any? require 'pry' binding.pry # raise "Should be no previous continuing sequences remaining" end continuing_sequences = new_continuing_sequences end raise "Should be no previous continuing sequences remaining" if continuing_sequences.any? completed_seqs.each {|seq| seq.simplify! } return completed_seqs end |