Sha256: 26d69c8235434783e8aa4600944a4aa3932dad01879908b4c9f8c64bf7895593

Contents?: true

Size: 577 Bytes

Versions: 2

Compression:

Stored size: 577 Bytes

Contents

module HeadMusic::Style::Annotations
end

class HeadMusic::Style::Annotations::PreferContraryMotion < HeadMusic::Style::Annotation
  MESSAGE = "Prefer contrary motion. Move voices in different melodic directions."

  def marks
    return nil if notes.length < 2
    return nil if direct_motion_ratio <= 0.5
    direct_motions.map { |motion| HeadMusic::Style::Mark.for_all(motion.notes) }
  end

  private

  def direct_motions
    motions.select(&:direct?)
  end

  def direct_motion_ratio
    return 0 if motions.empty?
    direct_motions.count / motions.count.to_f
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

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