Sha256: d56fd2addcea447eff7c771dbb1ef75babf3e7500ccd378664a2e3c4703bc750

Contents?: true

Size: 775 Bytes

Versions: 7

Compression:

Stored size: 775 Bytes

Contents

module HeadMusic::Style::Annotations
end

class HeadMusic::Style::Annotations::AvoidCrossingVoices < HeadMusic::Style::Annotation
  MESSAGE = "Avoid crossing 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

7 entries across 7 versions & 1 rubygems

Version Path
head_music-0.16.0 lib/head_music/style/annotations/avoid_crossing_voices.rb
head_music-0.14.8 lib/head_music/style/annotations/avoid_crossing_voices.rb
head_music-0.14.7 lib/head_music/style/annotations/avoid_crossing_voices.rb
head_music-0.14.5 lib/head_music/style/annotations/avoid_crossing_voices.rb
head_music-0.14.4 lib/head_music/style/annotations/avoid_crossing_voices.rb
head_music-0.14.2 lib/head_music/style/annotations/avoid_crossing_voices.rb
head_music-0.14.1 lib/head_music/style/annotations/avoid_crossing_voices.rb