class HeadMusic::Style::Guidelines::NotesSameLength
A counterpoint guideline
Constants
- MESSAGE
Public Instance Methods
marks()
click to toggle source
# File lib/head_music/style/guidelines/notes_same_length.rb, line 10 def marks HeadMusic::Style::Mark.for_each(all_wrong_length_notes) end
Private Instance Methods
acceptable_duration_of_last_note?()
click to toggle source
# File lib/head_music/style/guidelines/notes_same_length.rb, line 30 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()
click to toggle source
# File lib/head_music/style/guidelines/notes_same_length.rb, line 38 def all_but_last_note notes[0..-2] end
all_wrong_length_notes()
click to toggle source
# File lib/head_music/style/guidelines/notes_same_length.rb, line 16 def all_wrong_length_notes (wrong_length_notes + [wrong_length_last_note]).compact end
distinct_values()
click to toggle source
# File lib/head_music/style/guidelines/notes_same_length.rb, line 42 def distinct_values all_but_last_note.map(&:rhythmic_value).uniq.length end
first_most_common_rhythmic_value()
click to toggle source
# File lib/head_music/style/guidelines/notes_same_length.rb, line 46 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 ? first_match.rhythmic_value : nil end end
most_common_rhythmic_values()
click to toggle source
# File lib/head_music/style/guidelines/notes_same_length.rb, line 54 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()
click to toggle source
# File lib/head_music/style/guidelines/notes_same_length.rb, line 62 def occurrences_by_rhythmic_value rhythmic_values.each_with_object(Hash.new(0)) { |value, hash| hash[value] += 1; } end
rhythmic_values()
click to toggle source
# File lib/head_music/style/guidelines/notes_same_length.rb, line 66 def rhythmic_values notes.map(&:rhythmic_value) end
wrong_length_last_note()
click to toggle source
# File lib/head_music/style/guidelines/notes_same_length.rb, line 26 def wrong_length_last_note last_note unless acceptable_duration_of_last_note? end
wrong_length_notes()
click to toggle source
# File lib/head_music/style/guidelines/notes_same_length.rb, line 20 def wrong_length_notes all_but_last_note.reject do |note| note.rhythmic_value == first_most_common_rhythmic_value end end