class HeadMusic::Style::Guidelines::AvoidOverlappingVoices

A counterpoint guideline

Constants

MESSAGE

Public Instance Methods

marks() click to toggle source
# File lib/head_music/style/guidelines/avoid_overlapping_voices.rb, line 10
def marks
  overlappings
end

Private Instance Methods

overlappings() click to toggle source
# File lib/head_music/style/guidelines/avoid_overlapping_voices.rb, line 16
def overlappings
  overlappings_of_lower_voices + overlappings_of_higher_voices
end
overlappings_for_voices(voices, comparison_operator) click to toggle source
# File lib/head_music/style/guidelines/avoid_overlapping_voices.rb, line 28
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_voices() click to toggle source
# File lib/head_music/style/guidelines/avoid_overlapping_voices.rb, line 24
def overlappings_of_higher_voices
  overlappings_for_voices(higher_voices, :<)
end
overlappings_of_lower_voices() click to toggle source
# File lib/head_music/style/guidelines/avoid_overlapping_voices.rb, line 20
def overlappings_of_lower_voices
  overlappings_for_voices(lower_voices, :>)
end
overlappings_with_voice(other_voice, comparison_operator) click to toggle source
# File lib/head_music/style/guidelines/avoid_overlapping_voices.rb, line 37
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