Class: HeadMusic::Style::Guidelines::NoteCountPerBar
- Inherits:
-
Annotation
- Object
- Annotation
- HeadMusic::Style::Guidelines::NoteCountPerBar
show all
- Defined in:
- lib/head_music/style/guidelines/note_count_per_bar.rb
Overview
Checks that each middle bar (not first or last) contains an exact number of
notes of a given rhythmic value. Configurable via the count: and
rhythmic_value: options; subclasses may set COUNT and RHYTHMIC_VALUE defaults.
Instance Method Summary
collapse
Instance Method Details
#check_middle_bar(bar_number) ⇒ Object
32
33
34
35
36
37
|
# File 'lib/head_music/style/guidelines/note_count_per_bar.rb', line 32
def check_middle_bar(bar_number)
bar_notes = notes_in_bar(bar_number)
return if bar_notes.length == count && bar_notes.all? { |note| note.rhythmic_value == rhythmic_value }
mark_bar(bar_number)
end
|
#count ⇒ Object
20
21
22
|
# File 'lib/head_music/style/guidelines/note_count_per_bar.rb', line 20
def count
options.fetch(:count) { self.class::COUNT }
end
|
#mark_bar(bar_number) ⇒ Object
50
51
52
53
54
55
56
57
58
|
# File 'lib/head_music/style/guidelines/note_count_per_bar.rb', line 50
def mark_bar(bar_number)
bar_placements = notes_in_bar(bar_number)
if bar_placements.any?
HeadMusic::Style::Mark.for_all(bar_placements)
else
cf_note = cantus_firmus.notes.detect { |note| note.position.bar_number == bar_number }
HeadMusic::Style::Mark.for(cf_note) if cf_note
end
end
|
#marks ⇒ Object
8
9
10
11
12
|
# File 'lib/head_music/style/guidelines/note_count_per_bar.rb', line 8
def marks
return [] unless cantus_firmus&.notes&.any?
middle_bars.filter_map { |bar_number| check_middle_bar(bar_number) }
end
|
#message ⇒ Object
14
15
16
|
# File 'lib/head_music/style/guidelines/note_count_per_bar.rb', line 14
def message
"Use #{count.humanize} #{rhythmic_unit} #{(count == 1) ? "note" : "notes"} in each middle bar."
end
|
#middle_bars ⇒ Object
39
40
41
42
43
44
|
# File 'lib/head_music/style/guidelines/note_count_per_bar.rb', line 39
def middle_bars
cf_notes = cantus_firmus.notes
return [] if cf_notes.length <= 2
cf_notes[1..-2].map { |note| note.position.bar_number }
end
|
#notes_in_bar(bar_number) ⇒ Object
46
47
48
|
# File 'lib/head_music/style/guidelines/note_count_per_bar.rb', line 46
def notes_in_bar(bar_number)
notes.select { |note| note.position.bar_number == bar_number }
end
|
#rhythmic_unit ⇒ Object
24
25
26
|
# File 'lib/head_music/style/guidelines/note_count_per_bar.rb', line 24
def rhythmic_unit
options.fetch(:rhythmic_value) { self.class::RHYTHMIC_VALUE }
end
|
#rhythmic_value ⇒ Object
28
29
30
|
# File 'lib/head_music/style/guidelines/note_count_per_bar.rb', line 28
def rhythmic_value
@rhythmic_value ||= HeadMusic::Rudiment::RhythmicValue.get(rhythmic_unit)
end
|