Class: HeadMusic::Style::Guidelines::TwoToOne
- Inherits:
-
Annotation
- Object
- Annotation
- HeadMusic::Style::Guidelines::TwoToOne
show all
- Defined in:
- lib/head_music/style/guidelines/two_to_one.rb
Overview
Constant Summary
collapse
- MESSAGE =
"Use two half notes against each whole note in the cantus firmus."
- HALF =
HeadMusic::Rudiment::RhythmicValue.get(:half)
- WHOLE =
HeadMusic::Rudiment::RhythmicValue.get(:whole)
Instance Method Summary
collapse
Instance Method Details
#check_final_bar(bar_number) ⇒ Object
44
45
46
47
48
49
|
# File 'lib/head_music/style/guidelines/two_to_one.rb', line 44
def check_final_bar(bar_number)
bar_notes = notes_in_bar(bar_number)
return if one_whole_note?(bar_notes)
mark_bar(bar_number)
end
|
#check_first_bar(bar_number) ⇒ Object
28
29
30
31
32
33
34
35
|
# File 'lib/head_music/style/guidelines/two_to_one.rb', line 28
def check_first_bar(bar_number)
bar_notes = notes_in_bar(bar_number)
bar_rests = rests_in_bar(bar_number)
return if two_half_notes?(bar_notes)
return if rest_then_half_note?(bar_notes, bar_rests)
mark_bar(bar_number)
end
|
#check_middle_bar(bar_number) ⇒ Object
37
38
39
40
41
42
|
# File 'lib/head_music/style/guidelines/two_to_one.rb', line 37
def check_middle_bar(bar_number)
bar_notes = notes_in_bar(bar_number)
return if two_half_notes?(bar_notes)
mark_bar(bar_number)
end
|
#mark_bar(bar_number) ⇒ Object
74
75
76
77
78
79
80
81
82
|
# File 'lib/head_music/style/guidelines/two_to_one.rb', line 74
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 { |n| n.position.bar_number == bar_number }
HeadMusic::Style::Mark.for(cf_note) if cf_note
end
end
|
#marks ⇒ Object
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
# File 'lib/head_music/style/guidelines/two_to_one.rb', line 11
def marks
return [] unless cantus_firmus&.notes&.any?
cantus_firmus.notes.each_with_index.filter_map do |cf_note, index|
bar_number = cf_note.position.bar_number
if index == cantus_firmus.notes.length - 1
check_final_bar(bar_number)
elsif index == 0
check_first_bar(bar_number)
else
check_middle_bar(bar_number)
end
end
end
|
#notes_in_bar(bar_number) ⇒ Object
66
67
68
|
# File 'lib/head_music/style/guidelines/two_to_one.rb', line 66
def notes_in_bar(bar_number)
notes.select { |n| n.position.bar_number == bar_number }
end
|
#one_whole_note?(bar_notes) ⇒ Boolean
55
56
57
|
# File 'lib/head_music/style/guidelines/two_to_one.rb', line 55
def one_whole_note?(bar_notes)
bar_notes.length == 1 && bar_notes.first.rhythmic_value == WHOLE
end
|
#rest_then_half_note?(bar_notes, bar_rests) ⇒ Boolean
59
60
61
62
63
64
|
# File 'lib/head_music/style/guidelines/two_to_one.rb', line 59
def rest_then_half_note?(bar_notes, bar_rests)
bar_notes.length == 1 &&
bar_notes.first.rhythmic_value == HALF &&
bar_rests.length == 1 &&
bar_rests.first.rhythmic_value == HALF
end
|
#rests_in_bar(bar_number) ⇒ Object
70
71
72
|
# File 'lib/head_music/style/guidelines/two_to_one.rb', line 70
def rests_in_bar(bar_number)
rests.select { |r| r.position.bar_number == bar_number }
end
|
#two_half_notes?(bar_notes) ⇒ Boolean
51
52
53
|
# File 'lib/head_music/style/guidelines/two_to_one.rb', line 51
def two_half_notes?(bar_notes)
bar_notes.length == 2 && bar_notes.all? { |n| n.rhythmic_value == HALF }
end
|