Sha256: 4a3098d22b447d91798208d7c85bbc7514f99ce56ce63df218d3028c4c46b538

Contents?: true

Size: 914 Bytes

Versions: 21

Compression:

Stored size: 914 Bytes

Contents

# frozen_string_literal: true

# Module for style guidelines.
module HeadMusic::Style::Guidelines; end

# A counterpoint guideline
class HeadMusic::Style::Guidelines::AvoidCrossingVoices < HeadMusic::Style::Annotation
  MESSAGE = 'Avoid crossing voices. Maintain the high-low relationship between voices.'

  def marks
    crossings.map do |crossing|
      HeadMusic::Style::Mark.for_all(crossing.notes)
    end
  end

  private

  def crossings
    harmonic_intervals.select do |harmonic_interval|
      harmonic_interval.pitch_orientation && harmonic_interval.pitch_orientation != predominant_pitch_orientation
    end
  end

  def predominant_pitch_orientation
    pitch_orientations.
      compact.
      group_by { |orientation| orientation }.
      max { |a, b| a[1].length <=> b[1].length }.
      first
  end

  def pitch_orientations
    harmonic_intervals.map(&:pitch_orientation).compact.uniq
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
head_music-0.27.0 lib/head_music/style/guidelines/avoid_crossing_voices.rb
head_music-0.26.3 lib/head_music/style/guidelines/avoid_crossing_voices.rb
head_music-0.26.2 lib/head_music/style/guidelines/avoid_crossing_voices.rb
head_music-0.26.1 lib/head_music/style/guidelines/avoid_crossing_voices.rb
head_music-0.26.0 lib/head_music/style/guidelines/avoid_crossing_voices.rb
head_music-0.25.0 lib/head_music/style/guidelines/avoid_crossing_voices.rb
head_music-0.24.5 lib/head_music/style/guidelines/avoid_crossing_voices.rb
head_music-0.24.4 lib/head_music/style/guidelines/avoid_crossing_voices.rb
head_music-0.24.3 lib/head_music/style/guidelines/avoid_crossing_voices.rb
head_music-0.24.2 lib/head_music/style/guidelines/avoid_crossing_voices.rb
head_music-0.24.1 lib/head_music/style/guidelines/avoid_crossing_voices.rb
head_music-0.24.0 lib/head_music/style/guidelines/avoid_crossing_voices.rb
head_music-0.23.4 lib/head_music/style/guidelines/avoid_crossing_voices.rb
head_music-0.23.3 lib/head_music/style/guidelines/avoid_crossing_voices.rb
head_music-0.23.2 lib/head_music/style/guidelines/avoid_crossing_voices.rb
head_music-0.23.1 lib/head_music/style/guidelines/avoid_crossing_voices.rb
head_music-0.23.0 lib/head_music/style/guidelines/avoid_crossing_voices.rb
head_music-0.22.0 lib/head_music/style/guidelines/avoid_crossing_voices.rb
head_music-0.20.0 lib/head_music/style/guidelines/avoid_crossing_voices.rb
head_music-0.19.2 lib/head_music/style/guidelines/avoid_crossing_voices.rb