Class: HeadMusic::Style::Guidelines::Diatonic

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

Overview

A counterpoint guideline

Constant Summary collapse

MESSAGE =
"Use only notes in the key signature."

Instance Method Summary collapse

Constructor Details

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

Instance Method Details

#fitness_denominatorObject (protected)

Score by the rate of out-of-key notes rather than the raw count, so fitness is invariant to melody length.



16
17
18
# File 'lib/head_music/style/guidelines/diatonic.rb', line 16

def fitness_denominator
  notes.length
end

#marksObject



8
9
10
# File 'lib/head_music/style/guidelines/diatonic.rb', line 8

def marks
  HeadMusic::Style::Mark.for_each(notes_not_in_key_excluding_penultimate_leading_tone)
end

#notes_not_in_key_excluding_penultimate_leading_toneObject (private)



22
23
24
25
26
27
28
# File 'lib/head_music/style/guidelines/diatonic.rb', line 22

def notes_not_in_key_excluding_penultimate_leading_tone
  notes_not_in_key.reject do |note|
    penultimate_note &&
      note == penultimate_note &&
      HeadMusic::Rudiment::ScaleDegree.new(key_signature, note.pitch.spelling).alteration == "#"
  end
end

#penultimate_noteObject (private)



30
31
32
# File 'lib/head_music/style/guidelines/diatonic.rb', line 30

def penultimate_note
  voice.note_preceding(positions.last) if positions.last
end