Class: Musicality::NoteSequenceExtractor

Inherits:
Object
  • Object
show all
Defined in:
lib/musicality/performance/conversion/note_sequence_extractor.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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
  establish_maps
  # now, ready to extract sequences!
end

Instance Attribute Details

#notesObject (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
# File 'lib/musicality/performance/conversion/note_sequence_extractor.rb', line 14

def extract_sequences cents_per_step = 10
  return [] if @notes.empty?
  
  next_seqs = seqs_from_note(@notes.size-1, cents_per_step)
  return next_seqs if @notes.one?
  
  complete_seqs = []
  (@notes.size-2).downto(0) do |i|
    cur_seqs = seqs_from_note(i, cents_per_step)
    map = @maps[i]
    
    next_seqs.each do |next_seq|
      p1 = nil
      p2 = next_seq.elements.first.pitch
      if p1 = map[:ties].key(p2)
        cur_seq = cur_seqs.find {|x| x.elements.first.pitch == p1 }
        NoteSequenceExtractor.tie_seqs(cur_seq, next_seq)
      elsif p1 = map[:slurs].key(p2)
        cur_seq = cur_seqs.find {|x| x.elements.first.pitch == p1 }
        NoteSequenceExtractor.slur_seqs(cur_seq, next_seq)
      elsif p1 = map[:full_glissandos].key(p2)
        cur_seq = cur_seqs.find {|x| x.elements.first.pitch == p1 }
        NoteSequenceExtractor.glissando_seqs(cur_seq, next_seq)
      elsif p1 = map[:full_portamentos].key(p2)
        cur_seq = cur_seqs.find {|x| x.elements.first.pitch == p1 }
        NoteSequenceExtractor.portamento_seqs(cur_seq, next_seq, cents_per_step)
      else
        complete_seqs.push next_seq
      end
    end      
    next_seqs = cur_seqs
  end
  complete_seqs += next_seqs
  return complete_seqs
end