Sha256: 324548ce058ab5e5889f89a17e58acf986507f5081641bf8be34d4906f911c58

Contents?: true

Size: 631 Bytes

Versions: 6

Compression:

Stored size: 631 Bytes

Contents

module HeadMusic::Style::Annotations
end

class HeadMusic::Style::Annotations::PreferImperfect < HeadMusic::Style::Annotation
  MESSAGE = "Prefer imperfect harmonic intervals."

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

  private

  def ratio_of_perfect_intervals
    return 0 if downbeat_harmonic_intervals.empty?
    perfect_intervals.length.to_f / downbeat_harmonic_intervals.length
  end

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

Version data entries

6 entries across 6 versions & 1 rubygems

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