Class: HeadMusic::Style::Guidelines::MaximumNotes
- Inherits:
-
Annotation
- Object
- Annotation
- HeadMusic::Style::Guidelines::MaximumNotes
show all
- Defined in:
- lib/head_music/style/guidelines/maximum_notes.rb
Overview
Flags a melody with more than the allowed number of notes.
Configure the threshold with the factory, e.g. MaximumNotes.with(14).
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.with(maximum, **options) ⇒ Object
7
8
9
|
# File 'lib/head_music/style/guidelines/maximum_notes.rb', line 7
def self.with(maximum, **options)
super(maximum: maximum, **options)
end
|
Instance Method Details
#fitness_denominator ⇒ Object
Score by the rate of overage notes rather than the raw count,
so fitness is invariant to melody length.
23
24
25
|
# File 'lib/head_music/style/guidelines/maximum_notes.rb', line 23
def fitness_denominator
notes.length
end
|
#marks ⇒ Object
11
12
13
|
# File 'lib/head_music/style/guidelines/maximum_notes.rb', line 11
def marks
HeadMusic::Style::Mark.for_each(notes[maximum..]) if overage.positive?
end
|
#maximum ⇒ Object
29
30
31
|
# File 'lib/head_music/style/guidelines/maximum_notes.rb', line 29
def maximum
options.fetch(:maximum)
end
|
#message ⇒ Object
15
16
17
|
# File 'lib/head_music/style/guidelines/maximum_notes.rb', line 15
def message
"Write up to #{maximum.humanize} notes."
end
|
#overage ⇒ Object
33
34
35
|
# File 'lib/head_music/style/guidelines/maximum_notes.rb', line 33
def overage
[notes.length - maximum, 0].max
end
|