Sha256: 36d22666c416a1e5071cc8bdfa64b3b765605cd3dfdbee9a63abaf99434ebca2

Contents?: true

Size: 665 Bytes

Versions: 3

Compression:

Stored size: 665 Bytes

Contents

# frozen_string_literal: true

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

# A counterpoint guideline
class HeadMusic::Style::Guidelines::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

3 entries across 3 versions & 1 rubygems

Version Path
head_music-0.20.0 lib/head_music/style/guidelines/prefer_contrary_motion.rb
head_music-0.19.2 lib/head_music/style/guidelines/prefer_contrary_motion.rb
head_music-0.19.1 lib/head_music/style/guidelines/prefer_contrary_motion.rb