Sha256: 4a6a9eecbd20f61fe23c3de9c7db9d2897b3f283181e7578d53783e3090e6d9d
Contents?: true
Size: 1.31 KB
Versions: 21
Compression:
Stored size: 1.31 KB
Contents
# frozen_string_literal: true # Module for style guidelines. module HeadMusic::Style::Guidelines; end # A counterpoint guideline class HeadMusic::Style::Guidelines::AvoidOverlappingVoices < HeadMusic::Style::Annotation MESSAGE = 'Avoid overlapping voices. Maintain the high-low relationship between voices even for adjacent notes.' def marks overlappings end private def overlappings overlappings_of_lower_voices + overlappings_of_higher_voices end def overlappings_of_lower_voices overlappings_for_voices(lower_voices, :>) end def overlappings_of_higher_voices overlappings_for_voices(higher_voices, :<) end 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 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 end
Version data entries
21 entries across 21 versions & 1 rubygems