Class: HeadMusic::Style::Guidelines::DirectionChanges
Overview
A melodic line should change direction often enough. Configurable via the
maximum_notes_per_direction: option; subclasses may set a
MAXIMUM_NOTES_PER_DIRECTION default and their own MESSAGE.
Instance Method Summary
collapse
Instance Method Details
#marks ⇒ Object
8
9
10
11
12
13
|
# File 'lib/head_music/style/guidelines/direction_changes.rb', line 8
def marks
return unless overage.positive?
penalty_exponent = overage**0.5
HeadMusic::Style::Mark.for_all(notes, fitness: HeadMusic::PENALTY_FACTOR**penalty_exponent)
end
|
#maximum_notes_per_direction ⇒ Object
23
24
25
|
# File 'lib/head_music/style/guidelines/direction_changes.rb', line 23
def maximum_notes_per_direction
options.fetch(:maximum_notes_per_direction) { self.class::MAXIMUM_NOTES_PER_DIRECTION }
end
|
#melodic_intervals_changing_direction ⇒ Object
31
32
33
34
35
|
# File 'lib/head_music/style/guidelines/direction_changes.rb', line 31
def melodic_intervals_changing_direction
melodic_intervals.each_cons(2).reject do |interval_pair|
interval_pair[0].direction == interval_pair[1].direction
end
end
|
#notes_per_direction ⇒ Object
27
28
29
|
# File 'lib/head_music/style/guidelines/direction_changes.rb', line 27
def notes_per_direction
notes.length.to_f / (melodic_intervals_changing_direction.length + 1)
end
|
#overage ⇒ Object
17
18
19
20
21
|
# File 'lib/head_music/style/guidelines/direction_changes.rb', line 17
def overage
return 0 if notes.length < 2
[notes_per_direction - maximum_notes_per_direction, 0].max
end
|