Class: HeadMusic::Style::Guidelines::NotesSameLength
Overview
Instance Method Summary
collapse
Instance Method Details
#acceptable_duration_of_last_note? ⇒ Boolean
42
43
44
45
46
47
48
|
# File 'lib/head_music/style/guidelines/notes_same_length.rb', line 42
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
50
51
52
|
# File 'lib/head_music/style/guidelines/notes_same_length.rb', line 50
def all_but_last_note
notes[0..-2]
end
|
#all_wrong_length_notes ⇒ Object
28
29
30
|
# File 'lib/head_music/style/guidelines/notes_same_length.rb', line 28
def all_wrong_length_notes
(wrong_length_notes + [wrong_length_last_note]).compact
end
|
#first_most_common_rhythmic_value ⇒ Object
10
11
12
13
14
15
16
|
# File 'lib/head_music/style/guidelines/notes_same_length.rb', line 10
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
6
7
8
|
# File 'lib/head_music/style/guidelines/notes_same_length.rb', line 6
def marks
HeadMusic::Style::Mark.for_each(all_wrong_length_notes)
end
|
#most_common_rhythmic_values ⇒ Object
18
19
20
21
22
23
24
|
# File 'lib/head_music/style/guidelines/notes_same_length.rb', line 18
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
54
55
56
|
# File 'lib/head_music/style/guidelines/notes_same_length.rb', line 54
def occurrences_by_rhythmic_value
rhythmic_values.tally
end
|
#rhythmic_values ⇒ Object
58
59
60
|
# File 'lib/head_music/style/guidelines/notes_same_length.rb', line 58
def rhythmic_values
notes.map(&:rhythmic_value)
end
|
#wrong_length_last_note ⇒ Object
38
39
40
|
# File 'lib/head_music/style/guidelines/notes_same_length.rb', line 38
def wrong_length_last_note
last_note unless acceptable_duration_of_last_note?
end
|
#wrong_length_notes ⇒ Object
32
33
34
35
36
|
# File 'lib/head_music/style/guidelines/notes_same_length.rb', line 32
def wrong_length_notes
all_but_last_note.reject do |note|
note.rhythmic_value == first_most_common_rhythmic_value
end
end
|