Class: Stretto::MusicElements::KeySignature
- Inherits:
-
MusicElement
- Object
- MusicElement
- Stretto::MusicElements::KeySignature
- Defined in:
- lib/stretto/music_elements/key_signature.rb
Overview
A key signature indicates the channel to play in the indicated key or scale.
This increases or decreases note values for certain notes, according to music theory (see en.wikipedia.org/wiki/Key_signature). The key signature is specified by the letter K
, followed by a key (for example C
, D#
or Eb
) and the scale (maj
or min
)
Note that notes and chords specified with a pitch value will not be affected. That is, given the following pattern “KGmaj F [65]”, the first note will raise its pitch to 66 (due to the sharp accidental in the F notes), while the second note will keep its given value of 65
Instance Attribute Summary collapse
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#scale ⇒ Object
readonly
Returns the value of attribute scale.
Attributes inherited from MusicElement
Attributes included from Node
Instance Method Summary collapse
-
#initialize(string_or_options, pattern = nil) ⇒ KeySignature
constructor
A new instance of KeySignature.
-
#modifier_for(note_key) ⇒ Number
+1, 0 or -1, if the note key has a flat, none or sharp accidental respectively for the given
note_key
.
Methods inherited from MusicElement
#build_music_string, #duration, #end_of_tie?, #start_of_tie?, #substitute_variables!, #to_s
Constructor Details
#initialize(string_or_options, pattern = nil) ⇒ KeySignature
Returns a new instance of KeySignature.
21 22 23 24 25 26 27 28 29 |
# File 'lib/stretto/music_elements/key_signature.rb', line 21 def initialize(, pattern = nil) token = case when String then Stretto::Parser.parse_key_signature!() else end super(token[:text_value], pattern) @key = normalize_keysig(token[:key]) @scale = SCALES[token[:scale].downcase] end |
Instance Attribute Details
#key ⇒ Object (readonly)
Returns the value of attribute key.
19 20 21 |
# File 'lib/stretto/music_elements/key_signature.rb', line 19 def key @key end |
#scale ⇒ Object (readonly)
Returns the value of attribute scale.
19 20 21 |
# File 'lib/stretto/music_elements/key_signature.rb', line 19 def scale @scale end |
Instance Method Details
#modifier_for(note_key) ⇒ Number
Returns +1, 0 or -1, if the note key has a flat, none or sharp accidental respectively for the given note_key
.
33 34 35 |
# File 'lib/stretto/music_elements/key_signature.rb', line 33 def modifier_for(note_key) MODIFIERS[@scale][@key][note_key] end |