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 in middle bars (not first or last).

Direct Known Subclasses

FourPerBar, OnePerBar, ThreePerBar, TwoPerBar

Instance Method Summary collapse

Constructor Details

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

Instance Method Details

#mark_bar(bar_number) ⇒ Object (private)



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

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



6
7
8
9
10
# File 'lib/head_music/style/guidelines/note_count_per_bar.rb', line 6

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

  middle_bars.filter_map { |bar_number| check_middle_bar(bar_number) }
end

#middle_barsObject (private)



14
15
16
17
18
19
# File 'lib/head_music/style/guidelines/note_count_per_bar.rb', line 14

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



21
22
23
# File 'lib/head_music/style/guidelines/note_count_per_bar.rb', line 21

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