Class: HeadMusic::Style::Guidelines::NoteCountPerBar

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

Overview

Base class for guidelines that check note counts per bar against the cantus firmus.

Direct Known Subclasses

FourToOne, ThreeToOne, TwoToOne

Constant Summary collapse

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)



26
27
28
29
30
31
# File 'lib/head_music/style/guidelines/note_count_per_bar.rb', line 26

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

#mark_bar(bar_number) ⇒ Object (private)



45
46
47
48
49
50
51
52
53
# File 'lib/head_music/style/guidelines/note_count_per_bar.rb', line 45

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

#marksObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/head_music/style/guidelines/note_count_per_bar.rb', line 8

def marks
  return [] unless cantus_firmus&.notes&.any?

  cf_notes = cantus_firmus.notes
  cf_notes.each_with_index.filter_map do |cf_note, index|
    bar_number = cf_note.position.bar_number
    if index == cf_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)



37
38
39
# File 'lib/head_music/style/guidelines/note_count_per_bar.rb', line 37

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

#one_whole_note?(bar_notes) ⇒ Boolean (private)

Returns:

  • (Boolean)


33
34
35
# File 'lib/head_music/style/guidelines/note_count_per_bar.rb', line 33

def one_whole_note?(bar_notes)
  bar_notes.length == 1 && bar_notes.first.rhythmic_value == WHOLE
end

#rests_in_bar(bar_number) ⇒ Object (private)



41
42
43
# File 'lib/head_music/style/guidelines/note_count_per_bar.rb', line 41

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