Class: HeadMusic::Style::Guidelines::NotesSameLength
- Inherits:
-
Annotation
- Object
- Annotation
- HeadMusic::Style::Guidelines::NotesSameLength
show all
- Defined in:
- lib/head_music/style/guidelines/notes_same_length.rb
Overview
Constant Summary
collapse
- MESSAGE =
"Use consistent rhythmic unit."
Instance Method Summary
collapse
Instance Method Details
#acceptable_duration_of_last_note? ⇒ Boolean
44
45
46
47
48
49
50
|
# File 'lib/head_music/style/guidelines/notes_same_length.rb', line 44
def acceptable_duration_of_last_note?
last_note.nil? ||
[
first_most_common_rhythmic_value.total_value,
first_most_common_rhythmic_value.total_value * 2
].include?(last_note.rhythmic_value.total_value)
end
|
#all_but_last_note ⇒ Object
52
53
54
|
# File 'lib/head_music/style/guidelines/notes_same_length.rb', line 52
def all_but_last_note
notes[0..-2]
end
|
#all_wrong_length_notes ⇒ Object
30
31
32
|
# File 'lib/head_music/style/guidelines/notes_same_length.rb', line 30
def all_wrong_length_notes
(wrong_length_notes + [wrong_length_last_note]).compact
end
|
#first_most_common_rhythmic_value ⇒ Object
12
13
14
15
16
17
18
|
# File 'lib/head_music/style/guidelines/notes_same_length.rb', line 12
def first_most_common_rhythmic_value
@first_most_common_rhythmic_value ||= begin
candidates = most_common_rhythmic_values
first_match = notes.detect { |note| candidates.include?(note.rhythmic_value) }
first_match&.rhythmic_value
end
end
|
#marks ⇒ Object
8
9
10
|
# File 'lib/head_music/style/guidelines/notes_same_length.rb', line 8
def marks
HeadMusic::Style::Mark.for_each(all_wrong_length_notes)
end
|
#most_common_rhythmic_values ⇒ Object
20
21
22
23
24
25
26
|
# File 'lib/head_music/style/guidelines/notes_same_length.rb', line 20
def most_common_rhythmic_values
return [] if notes.empty?
occurrences = occurrences_by_rhythmic_value
highest_count = occurrences.values.max
occurrences.select { |_rhythmic_value, count| count == highest_count }.keys
end
|
#occurrences_by_rhythmic_value ⇒ Object
56
57
58
|
# File 'lib/head_music/style/guidelines/notes_same_length.rb', line 56
def occurrences_by_rhythmic_value
rhythmic_values.each_with_object(Hash.new(0)) { |value, hash| hash[value] += 1 }
end
|
#rhythmic_values ⇒ Object
60
61
62
|
# File 'lib/head_music/style/guidelines/notes_same_length.rb', line 60
def rhythmic_values
notes.map(&:rhythmic_value)
end
|
#wrong_length_last_note ⇒ Object
40
41
42
|
# File 'lib/head_music/style/guidelines/notes_same_length.rb', line 40
def wrong_length_last_note
last_note unless acceptable_duration_of_last_note?
end
|
#wrong_length_notes ⇒ Object
34
35
36
37
38
|
# File 'lib/head_music/style/guidelines/notes_same_length.rb', line 34
def wrong_length_notes
all_but_last_note.reject do |note|
note.rhythmic_value == first_most_common_rhythmic_value
end
end
|