Class: HeadMusic::Notation::MusicXML::PitchWriter

Inherits:
Object
  • Object
show all
Defined in:
lib/head_music/notation/music_xml/pitch_writer.rb

Overview

Converts pitches into the trio of values MusicXML’s element needs.

Unlike ABC, MusicXML’s is absolute rather than bar-persistent, so no oracle or mutable state is required: each pitch maps to its attributes independent of any other pitch that came before it.

Class Method Summary collapse

Class Method Details

.attributes(pitch) ⇒ Object

Returns a Hash of the step, alter, and octave for the pitch’s

element. Alter is nil when the pitch is natural, in which case the caller should omit the element entirely.


12
13
14
15
16
17
18
19
# File 'lib/head_music/notation/music_xml/pitch_writer.rb', line 12

def self.attributes(pitch)
  pitch = HeadMusic::Rudiment::Pitch.get(pitch)
  {
    step: pitch.letter_name.to_s,
    alter: pitch.alteration_semitones,
    octave: pitch.register
  }
end