Sha256: c6b7cf4c21fa36aff52cf178691af6660ba427bb39d7e2105df1c012b3fcbbfd

Contents?: true

Size: 667 Bytes

Versions: 18

Compression:

Stored size: 667 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

18 entries across 18 versions & 1 rubygems

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