Class: HeadMusic::Notation::MusicXML::KeyMapper
- Inherits:
-
Object
- Object
- HeadMusic::Notation::MusicXML::KeyMapper
- Defined in:
- lib/head_music/notation/music_xml/key_mapper.rb
Overview
Converts a key signature into the fifths/mode pair MusicXML’s
Constant Summary collapse
- MODE_NAMES_BY_SCALE_TYPE =
MusicXML’s
element only names these seven modes, so scale types outside this set (harmonic minor, whole tone, etc.) cannot be rendered as a element and must raise instead. { "major" => "major", "ionian" => "major", "minor" => "minor", "aeolian" => "minor", "dorian" => "dorian", "phrygian" => "phrygian", "lydian" => "lydian", "mixolydian" => "mixolydian", "locrian" => "locrian" }.freeze
Class Method Summary collapse
-
.fifths(key_signature) ⇒ Object
Returns the number of sharps (positive) or flats (negative) for the
element. -
.mode(key_signature) ⇒ Object
Returns the
element value for a key signature. -
.raise_render_error(message) ⇒ Object
private
Class Method Details
.fifths(key_signature) ⇒ Object
Returns the number of sharps (positive) or flats (negative) for the
24 25 26 27 |
# File 'lib/head_music/notation/music_xml/key_mapper.rb', line 24 def self.fifths(key_signature) key_signature = HeadMusic::Rudiment::KeySignature.get(key_signature) key_signature.num_sharps - key_signature.num_flats end |
.mode(key_signature) ⇒ Object
Returns the
30 31 32 33 34 |
# File 'lib/head_music/notation/music_xml/key_mapper.rb', line 30 def self.mode(key_signature) key_signature = HeadMusic::Rudiment::KeySignature.get(key_signature) MODE_NAMES_BY_SCALE_TYPE[key_signature.scale_type.name.to_s] || raise_render_error("Cannot render scale type #{key_signature.scale_type} in a MusicXML <key> element") end |
.raise_render_error(message) ⇒ Object (private)
36 37 38 |
# File 'lib/head_music/notation/music_xml/key_mapper.rb', line 36 def self.raise_render_error() raise HeadMusic::Notation::MusicXML::RenderError, end |