Sha256: 91d8dd83ba30eaf6789b2a44d4f4a60ca0bdd4b579a74c2ae9b8f1de2ae5064d

Contents?: true

Size: 815 Bytes

Versions: 18

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

18 entries across 18 versions & 1 rubygems

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