Class: HeadMusic::Notation::LilyPond::PitchWriter
- Inherits:
-
Object
- Object
- HeadMusic::Notation::LilyPond::PitchWriter
- Defined in:
- lib/head_music/notation/lily_pond/pitch_writer.rb
Overview
Converts a pitch into a LilyPond absolute-mode pitch token using the default (Dutch) note names: letter, is/es alteration suffixes, and octave marks relative to c’ as middle C.
Constant Summary collapse
- ALTERATION_SUFFIXES =
{ 0 => "", 1 => "is", -1 => "es", 2 => "isis", -2 => "eses" }.freeze
Class Method Summary collapse
-
.alteration_suffix(semitones) ⇒ Object
Public so KeyMapper spells its tonic with the same table.
-
.octave_marks(register) ⇒ Object
private
The gem’s middle C is register 4 and LilyPond’s absolute-mode c’ is middle C (plain c is C3), so the mark count is register - 3.
-
.token(pitch) ⇒ Object
Class Method Details
.alteration_suffix(semitones) ⇒ Object
Public so KeyMapper spells its tonic with the same table.
22 23 24 25 26 |
# File 'lib/head_music/notation/lily_pond/pitch_writer.rb', line 22 def self.alteration_suffix(semitones) ALTERATION_SUFFIXES.fetch(semitones.to_i) do raise RenderError, "no LilyPond spelling is known for an alteration of #{semitones} semitones" end end |
.octave_marks(register) ⇒ Object (private)
The gem’s middle C is register 4 and LilyPond’s absolute-mode c’ is middle C (plain c is C3), so the mark count is register - 3.
30 31 32 33 |
# File 'lib/head_music/notation/lily_pond/pitch_writer.rb', line 30 def self.octave_marks(register) marks = register - 3 (marks >= 0) ? "'" * marks : "," * -marks end |
.token(pitch) ⇒ Object
15 16 17 18 19 |
# File 'lib/head_music/notation/lily_pond/pitch_writer.rb', line 15 def self.token(pitch) pitch = HeadMusic::Rudiment::Pitch.get(pitch) letter = pitch.letter_name.to_s.downcase "#{letter}#{alteration_suffix(pitch.alteration_semitones)}#{octave_marks(pitch.register)}" end |