Class: Music::Performance::NoteLinker

Inherits:
Object
  • Object
show all
Defined in:
lib/music-performance/util/note_linker.rb

Class Method Summary collapse

Class Method Details



16
17
18
19
20
# File 'lib/music-performance/util/note_linker.rb', line 16

def self.figure_links note, next_note
  unlinked = find_unlinked_pitches(note)
  untargeted = find_untargeted_pitches(note, next_note)
  Optimization.linking(unlinked, untargeted)
end

.find_unlinked_pitches(note) ⇒ Object



5
6
7
8
# File 'lib/music-performance/util/note_linker.rb', line 5

def self.find_unlinked_pitches note
  linked = Set.new(note.pitches) & note.links.keys
  (Set.new(note.pitches) - linked).to_a
end

.find_untargeted_pitches(note, next_note) ⇒ Object



10
11
12
13
14
# File 'lib/music-performance/util/note_linker.rb', line 10

def self.find_untargeted_pitches note, next_note
  linked = Set.new(note.pitches) & note.links.keys
  targeted = Set.new(linked.map {|p| note.links[p].target_pitch })
  (Set.new(next_note.pitches) - targeted).to_a
end


22
23
24
25
26
# File 'lib/music-performance/util/note_linker.rb', line 22

def self.fully_link note, next_note, link_class
  figure_links(note,next_note).each do |pitch,tgt_pitch|
    note.links[pitch] = link_class.new(tgt_pitch)
  end
end