Class: HeadMusic::Style::Guidelines::FirstBarEntry
- Inherits:
-
Annotation
- Object
- Annotation
- HeadMusic::Style::Guidelines::FirstBarEntry
show all
- Defined in:
- lib/head_music/style/guidelines/first_bar_entry.rb
Overview
Base class for first-bar guidelines.
Rules: (a) at least one note, (b) each note is the correct beat unit,
(c) at most one rest, and only on the first beat.
Instance Method Summary
collapse
Instance Method Details
#all_correct_beat_unit?(bar_notes) ⇒ Boolean
30
31
32
|
# File 'lib/head_music/style/guidelines/first_bar_entry.rb', line 30
def all_correct_beat_unit?(bar_notes)
bar_notes.all? { |note| note.rhythmic_value == expected_rhythmic_value }
end
|
#expected_rhythmic_value ⇒ Object
20
21
22
|
# File 'lib/head_music/style/guidelines/first_bar_entry.rb', line 20
def expected_rhythmic_value
raise NotImplementedError
end
|
#marks ⇒ Object
8
9
10
11
12
13
14
15
16
|
# File 'lib/head_music/style/guidelines/first_bar_entry.rb', line 8
def marks
return unless notes.any?
bar_notes = notes_in_first_bar
bar_rests = rests_in_first_bar
return if valid_first_bar?(bar_notes, bar_rests)
HeadMusic::Style::Mark.for_all(bar_notes.any? ? bar_notes : [first_note])
end
|
#notes_in_first_bar ⇒ Object
41
42
43
|
# File 'lib/head_music/style/guidelines/first_bar_entry.rb', line 41
def notes_in_first_bar
notes.select { |note| note.position.bar_number == 1 }
end
|
#rests_in_first_bar ⇒ Object
45
46
47
|
# File 'lib/head_music/style/guidelines/first_bar_entry.rb', line 45
def rests_in_first_bar
rests.select { |rest| rest.position.bar_number == 1 }
end
|
#valid_first_bar?(bar_notes, bar_rests) ⇒ Boolean
24
25
26
27
28
|
# File 'lib/head_music/style/guidelines/first_bar_entry.rb', line 24
def valid_first_bar?(bar_notes, bar_rests)
bar_notes.any? &&
all_correct_beat_unit?(bar_notes) &&
valid_rests?(bar_rests)
end
|
#valid_rests?(bar_rests) ⇒ Boolean
34
35
36
37
38
39
|
# File 'lib/head_music/style/guidelines/first_bar_entry.rb', line 34
def valid_rests?(bar_rests)
bar_rests.empty? ||
(bar_rests.length == 1 &&
bar_rests.first.position.count == 1 &&
bar_rests.first.rhythmic_value == expected_rhythmic_value)
end
|