Class: HeadMusic::Style::Guidelines::AvoidOverlappingVoices

Inherits:
HeadMusic::Style::Guideline show all
Defined in:
lib/head_music/style/guidelines/avoid_overlapping_voices.rb

Overview

A counterpoint guideline

Instance Method Summary collapse

Constructor Details

This class inherits a constructor from HeadMusic::Style::Guideline

Instance Method Details

#marksObject



6
7
8
# File 'lib/head_music/style/guidelines/avoid_overlapping_voices.rb', line 6

def marks
  overlappings
end

#overlappingsObject (private)



12
13
14
# File 'lib/head_music/style/guidelines/avoid_overlapping_voices.rb', line 12

def overlappings
  overlappings_of_lower_voices + overlappings_of_higher_voices
end

#overlappings_for_voices(voices, comparison_operator) ⇒ Object (private)



24
25
26
27
28
29
30
31
# File 'lib/head_music/style/guidelines/avoid_overlapping_voices.rb', line 24

def overlappings_for_voices(voices, comparison_operator)
  [].tap do |marks|
    voices.each do |a_voice|
      overlapped_notes = overlappings_with_voice(a_voice, comparison_operator)
      marks << HeadMusic::Style::Mark.for_each(overlapped_notes)
    end
  end.flatten.compact
end

#overlappings_of_higher_voicesObject (private)



20
21
22
# File 'lib/head_music/style/guidelines/avoid_overlapping_voices.rb', line 20

def overlappings_of_higher_voices
  overlappings_for_voices(higher_voices, :<)
end

#overlappings_of_lower_voicesObject (private)



16
17
18
# File 'lib/head_music/style/guidelines/avoid_overlapping_voices.rb', line 16

def overlappings_of_lower_voices
  overlappings_for_voices(lower_voices, :>)
end

#overlappings_with_voice(other_voice, comparison_operator) ⇒ Object (private)



33
34
35
36
37
38
39
40
# File 'lib/head_music/style/guidelines/avoid_overlapping_voices.rb', line 33

def overlappings_with_voice(other_voice, comparison_operator)
  voice.notes.drop(1).select do |note|
    preceding_note = other_voice.note_preceding(note.position)
    following_note = other_voice.note_following(note.position)
    preceding_note&.pitch&.send(comparison_operator, note.pitch) ||
      following_note&.pitch&.send(comparison_operator, note.pitch)
  end
end