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

Inherits:
HeadMusic::Style::Guideline show all
Includes:
HeadMusic::Style::Guideline::BarSpan
Defined in:
lib/head_music/style/guidelines/note_count_per_bar.rb

Overview

Checks that each middle bar (not first or last) contains an exact number of notes of a given rhythmic value. Configurable via the count: and rhythmic_value: options; subclasses may set COUNT and RHYTHMIC_VALUE defaults. Judged over the voice's own bars, as SustainAcrossBarlines is, so a solo line is held to it too.

Direct Known Subclasses

FourPerBar, OnePerBar, ThreePerBar, TwoPerBar

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

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

Class Method Details

.template_key ⇒ Object

One template for all four subclasses: they differ by count and unit, not by sentence. Named explicitly so the subclasses do not each need an entry.



20
# File 'lib/head_music/style/guidelines/note_count_per_bar.rb', line 20

def self.template_key = "note_count_per_bar"

.template_values(config) ⇒ Object



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

def self.template_values(config)
  count = config.fetch(:count) { self::COUNT }
  unit = config.fetch(:rhythmic_value) { self::RHYTHMIC_VALUE }
  {
    count: count,
    number: HeadMusic::Style::Template.number_word(count),
    # Pluralized because British names the value with a noun and drops the
    # "note" the American sentence carries: four crotchets, not four crotchet
    # notes. English's entries stay scalar, which I18n reads past the count.
    rhythmic_unit: HeadMusic::Style::Template.pluralize(
      "rhythmic_units.#{unit}", count: count, scope: HeadMusic::Style::Template::RUDIMENT_SCOPE
    )
  }
end

Instance Method Details

#body_bar_numbers ⇒ Object (protected) Originally defined in module HeadMusic::Style::Guideline::BarSpan

#check_middle_bar(bar_number) ⇒ Object (private)



51
52
53
54
55
56
# File 'lib/head_music/style/guidelines/note_count_per_bar.rb', line 51

def check_middle_bar(bar_number)
  bar_notes = notes_in_bar(bar_number)
  return if bar_notes.length == count && bar_notes.all? { |note| note.rhythmic_value == rhythmic_value }

  mark_bar(bar_number)
end

#count ⇒ Object (private)



39
40
41
# File 'lib/head_music/style/guidelines/note_count_per_bar.rb', line 39

def count
  options.fetch(:count) { self.class::COUNT }
end

#downbeat_of(bar_number) ⇒ Object (protected) Originally defined in module HeadMusic::Style::Guideline::BarSpan

#first_bar_number ⇒ Object (protected) Originally defined in module HeadMusic::Style::Guideline::BarSpan

#last_bar_number ⇒ Object (protected) Originally defined in module HeadMusic::Style::Guideline::BarSpan

#mark_bar(bar_number) ⇒ Object (protected) Originally defined in module HeadMusic::Style::Guideline::BarSpan

#marks ⇒ Object



12
13
14
15
16
# File 'lib/head_music/style/guidelines/note_count_per_bar.rb', line 12

def marks
  return [] if notes.empty?

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

#middle_bar_numbers ⇒ Object (protected) Originally defined in module HeadMusic::Style::Guideline::BarSpan

#notes_in_bar(bar_number) ⇒ Object (protected) Originally defined in module HeadMusic::Style::Guideline::BarSpan

#rhythmic_unit ⇒ Object (private)



43
44
45
# File 'lib/head_music/style/guidelines/note_count_per_bar.rb', line 43

def rhythmic_unit
  options.fetch(:rhythmic_value) { self.class::RHYTHMIC_VALUE }
end

#rhythmic_value ⇒ Object (private)



47
48
49
# File 'lib/head_music/style/guidelines/note_count_per_bar.rb', line 47

def rhythmic_value
  @rhythmic_value ||= HeadMusic::Rudiment::RhythmicValue.get(rhythmic_unit)
end