Class: Clef::Core::KeySignature
- Inherits:
-
Object
- Object
- Clef::Core::KeySignature
- Defined in:
- lib/clef/core/key_signature.rb
Constant Summary collapse
- MAJOR_ACCIDENTALS =
{ c: {count: 0, type: :natural}, g: {count: 1, type: :sharp}, d: {count: 2, type: :sharp}, a: {count: 3, type: :sharp}, e: {count: 4, type: :sharp}, b: {count: 5, type: :sharp}, fis: {count: 6, type: :sharp}, cis: {count: 7, type: :sharp}, f: {count: 1, type: :flat}, bes: {count: 2, type: :flat}, ees: {count: 3, type: :flat}, aes: {count: 4, type: :flat}, des: {count: 5, type: :flat}, ges: {count: 6, type: :flat}, ces: {count: 7, type: :flat} }.freeze
- MINOR_ACCIDENTALS =
{ a: {count: 0, type: :natural}, e: {count: 1, type: :sharp}, b: {count: 2, type: :sharp}, fis: {count: 3, type: :sharp}, cis: {count: 4, type: :sharp}, gis: {count: 5, type: :sharp}, dis: {count: 6, type: :sharp}, ais: {count: 7, type: :sharp}, d: {count: 1, type: :flat}, g: {count: 2, type: :flat}, c: {count: 3, type: :flat}, f: {count: 4, type: :flat}, bes: {count: 5, type: :flat}, ees: {count: 6, type: :flat}, aes: {count: 7, type: :flat} }.freeze
Instance Attribute Summary collapse
-
#mode ⇒ Object
readonly
Returns the value of attribute mode.
-
#tonic ⇒ Object
readonly
Returns the value of attribute tonic.
Instance Method Summary collapse
- #accidentals ⇒ Hash
-
#initialize(tonic, mode = :major) ⇒ KeySignature
constructor
A new instance of KeySignature.
- #preferred_transpose_spelling ⇒ Symbol
Constructor Details
#initialize(tonic, mode = :major) ⇒ KeySignature
Returns a new instance of KeySignature.
45 46 47 48 49 |
# File 'lib/clef/core/key_signature.rb', line 45 def initialize(tonic, mode = :major) @tonic = normalize_tonic(tonic) validate_mode!(mode) @mode = mode end |
Instance Attribute Details
#mode ⇒ Object (readonly)
Returns the value of attribute mode.
41 42 43 |
# File 'lib/clef/core/key_signature.rb', line 41 def mode @mode end |
#tonic ⇒ Object (readonly)
Returns the value of attribute tonic.
41 42 43 |
# File 'lib/clef/core/key_signature.rb', line 41 def tonic @tonic end |
Instance Method Details
#accidentals ⇒ Hash
52 53 54 55 56 57 |
# File 'lib/clef/core/key_signature.rb', line 52 def accidentals table = (mode == :major) ? MAJOR_ACCIDENTALS : MINOR_ACCIDENTALS table.fetch(tonic_key) rescue KeyError raise ArgumentError, "unsupported #{mode} key tonic: #{tonic.to_lilypond}" end |
#preferred_transpose_spelling ⇒ Symbol
60 61 62 |
# File 'lib/clef/core/key_signature.rb', line 60 def preferred_transpose_spelling (accidentals[:type] == :flat) ? :flat : :sharp end |