Class: HeadMusic::Style::Guidelines::PreferContraryMotion

Inherits:
Annotation
  • Object
show all
Defined in:
lib/head_music/style/guidelines/prefer_contrary_motion.rb

Overview

A counterpoint guideline

Constant Summary collapse

MESSAGE =
"Prefer contrary motion. Move voices in different melodic directions."

Instance Method Summary collapse

Constructor Details

This class inherits a constructor from HeadMusic::Style::Annotation

Instance Method Details

#direct_motion_ratioObject (private)



21
22
23
24
25
# File 'lib/head_music/style/guidelines/prefer_contrary_motion.rb', line 21

def direct_motion_ratio
  return 0 if motions.empty?

  direct_motions.count / motions.count.to_f
end

#direct_motionsObject (private)



17
18
19
# File 'lib/head_music/style/guidelines/prefer_contrary_motion.rb', line 17

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

#marksObject



8
9
10
11
12
13
# File 'lib/head_music/style/guidelines/prefer_contrary_motion.rb', line 8

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