Class: HeadMusic::Rudiment::Key
- Inherits:
-
QualifiedDiatonicContext
- Object
- Base
- TonalContext
- DiatonicContext
- QualifiedDiatonicContext
- HeadMusic::Rudiment::Key
- Defined in:
- lib/head_music/rudiment/key.rb
Overview
Represents a musical key (major or minor)
Constant Summary collapse
- QUALITIES =
%i[major minor].freeze
- MAJOR_KEY_NAMES_BY_FIFTHS =
The conventional reading of a signature that carries no interpretation of its own: the major key with that many sharps or flats.
A signature underdetermines its key -- two sharps is D major, B minor, E dorian, or A mixolydian -- so this is a fallback for the consumers that cannot proceed without a tonic (LilyPond's \key, and the Diatonic guideline), not a claim about the music.
Signatures themselves are unbounded: a theoretical key such as G♯ major counts each double accidental twice and reaches eight. The table stops at seven, because past that there is no conventional major key to name.
{ -7 => "C♭", -6 => "G♭", -5 => "D♭", -4 => "A♭", -3 => "E♭", -2 => "B♭", -1 => "F", 0 => "C", 1 => "G", 2 => "D", 3 => "A", 4 => "E", 5 => "B", 6 => "F♯", 7 => "C♯" }.freeze
Instance Attribute Summary collapse
-
#alias_name_keys ⇒ Object
included
from Named
readonly
Returns the value of attribute alias_name_keys.
-
#name_key ⇒ Object
included
from Named
readonly
Returns the value of attribute name_key.
Class Method Summary collapse
- .default_qualifier ⇒ Object
-
.for_fifths(fifths) ⇒ HeadMusic::Rudiment::Key
The major key with that signature.
- .invalid_qualifier_message ⇒ Object
- .valid_qualifiers ⇒ Object
Instance Method Summary collapse
Constructor Details
This class inherits a constructor from HeadMusic::Rudiment::QualifiedDiatonicContext
Instance Attribute Details
#alias_name_keys ⇒ Object (readonly) Originally defined in module Named
Returns the value of attribute alias_name_keys.
#name_key ⇒ Object (readonly) Originally defined in module Named
Returns the value of attribute name_key.
Class Method Details
.default_qualifier ⇒ Object
36 37 38 |
# File 'lib/head_music/rudiment/key.rb', line 36 def self.default_qualifier :major end |
.for_fifths(fifths) ⇒ HeadMusic::Rudiment::Key
Returns the major key with that signature.
29 30 31 32 33 34 |
# File 'lib/head_music/rudiment/key.rb', line 29 def self.for_fifths(fifths) tonic = MAJOR_KEY_NAMES_BY_FIFTHS[fifths] raise ArgumentError, "no conventional key for a signature of #{fifths} fifths" if tonic.nil? get("#{tonic} major") end |
.invalid_qualifier_message ⇒ Object
44 45 46 |
# File 'lib/head_music/rudiment/key.rb', line 44 def self. "Quality must be :major or :minor" end |
.valid_qualifiers ⇒ Object
40 41 42 |
# File 'lib/head_music/rudiment/key.rb', line 40 def self.valid_qualifiers QUALITIES end |
Instance Method Details
#major? ⇒ Boolean
50 51 52 |
# File 'lib/head_music/rudiment/key.rb', line 50 def major? quality == :major end |
#minor? ⇒ Boolean
54 55 56 |
# File 'lib/head_music/rudiment/key.rb', line 54 def minor? quality == :minor end |
#parallel ⇒ Object
70 71 72 73 74 75 76 |
# File 'lib/head_music/rudiment/key.rb', line 70 def parallel if major? self.class.get("#{tonic_spelling} minor") else self.class.get("#{tonic_spelling} major") end end |
#relative ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/head_music/rudiment/key.rb', line 58 def relative if major? # Major to relative minor: down a minor third (3 semitones) relative_pitch = tonic_pitch + -3 self.class.get("#{relative_pitch.spelling} minor") else # Minor to relative major: up a minor third (3 semitones) relative_pitch = tonic_pitch + 3 self.class.get("#{relative_pitch.spelling} major") end end |