Sha256: bddefba223e7e15601f116a313e720697cdf0926963625462b2f6d787b393002

Contents?: true

Size: 740 Bytes

Versions: 3

Compression:

Stored size: 740 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_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

3 entries across 3 versions & 1 rubygems

Version Path
head_music-0.17.0 lib/head_music/style/annotations/prefer_imperfect.rb
head_music-0.16.2 lib/head_music/style/annotations/prefer_imperfect.rb
head_music-0.16.0 lib/head_music/style/annotations/prefer_imperfect.rb