Sha256: 69461822c5df8d3aff2b7486302091970a6b2a2be8e94019c2c0197e262b2ce9

Contents?: true

Size: 815 Bytes

Versions: 9

Compression:

Stored size: 815 Bytes

Contents

# frozen_string_literal: true

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

# A counterpoint guideline
class HeadMusic::Style::Guidelines::PreferImperfect < HeadMusic::Style::Annotation
  MESSAGE = "Prefer imperfect harmonic intervals."

  def marks
    HeadMusic::Style::Mark.for_all(perfect_intervals.map(&:notes).flatten) if ratio_of_perfect_intervals >= 0.5
  end

  private

  def ratio_of_perfect_intervals
    return 0 if downbeat_harmonic_intervals_in_middle.nil?

    perfect_intervals.length.to_f / downbeat_harmonic_intervals.length
  end

  def perfect_intervals
    downbeat_harmonic_intervals_in_middle.select { |interval| interval.perfect_consonance?(:two_part_harmony) }
  end

  def downbeat_harmonic_intervals_in_middle
    downbeat_harmonic_intervals[1..-2]
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
head_music-4.0.1 lib/head_music/style/guidelines/prefer_imperfect.rb
head_music-4.0.0 lib/head_music/style/guidelines/prefer_imperfect.rb
head_music-3.0.1 lib/head_music/style/guidelines/prefer_imperfect.rb
head_music-3.0.0 lib/head_music/style/guidelines/prefer_imperfect.rb
head_music-2.0.1 lib/head_music/style/guidelines/prefer_imperfect.rb
head_music-2.0.0 lib/head_music/style/guidelines/prefer_imperfect.rb
head_music-1.0.0 lib/head_music/style/guidelines/prefer_imperfect.rb
head_music-0.29.0 lib/head_music/style/guidelines/prefer_imperfect.rb
head_music-0.28.0 lib/head_music/style/guidelines/prefer_imperfect.rb