Class: HeadMusic::Style::Guidelines::TwoToOne

Inherits:
Annotation
  • Object
show all
Defined in:
lib/head_music/style/guidelines/two_to_one.rb

Overview

A counterpoint guideline

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

Constructor Details

This class inherits a constructor from HeadMusic::Style::Annotation

Instance Method Details

#check_final_bar(bar_number) ⇒ Object (private)



45
46
47
48
49
50
# File 'lib/head_music/style/guidelines/two_to_one.rb', line 45

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 (private)



28
29
30
31
32
33
34
35
36
# 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)
  return if single_half_note_after_downbeat?(bar_notes)

  mark_bar(bar_number)
end

#check_middle_bar(bar_number) ⇒ Object (private)



38
39
40
41
42
43
# File 'lib/head_music/style/guidelines/two_to_one.rb', line 38

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 (private)



81
82
83
84
85
86
87
88
89
# File 'lib/head_music/style/guidelines/two_to_one.rb', line 81

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

#marksObject



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 (private)



73
74
75
# File 'lib/head_music/style/guidelines/two_to_one.rb', line 73

def notes_in_bar(bar_number)
  notes.select { |n| n.position.bar_number == bar_number }
end

#one_whole_note?(bar_notes) ⇒ Boolean (private)

Returns:

  • (Boolean)


56
57
58
# File 'lib/head_music/style/guidelines/two_to_one.rb', line 56

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 (private)

Returns:

  • (Boolean)


60
61
62
63
64
65
# File 'lib/head_music/style/guidelines/two_to_one.rb', line 60

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 (private)



77
78
79
# File 'lib/head_music/style/guidelines/two_to_one.rb', line 77

def rests_in_bar(bar_number)
  rests.select { |r| r.position.bar_number == bar_number }
end

#single_half_note_after_downbeat?(bar_notes) ⇒ Boolean (private)

Returns:

  • (Boolean)


67
68
69
70
71
# File 'lib/head_music/style/guidelines/two_to_one.rb', line 67

def single_half_note_after_downbeat?(bar_notes)
  bar_notes.length == 1 &&
    bar_notes.first.rhythmic_value == HALF &&
    bar_notes.first.position.count > 1
end

#two_half_notes?(bar_notes) ⇒ Boolean (private)

Returns:

  • (Boolean)


52
53
54
# File 'lib/head_music/style/guidelines/two_to_one.rb', line 52

def two_half_notes?(bar_notes)
  bar_notes.length == 2 && bar_notes.all? { |n| n.rhythmic_value == HALF }
end