Class: Stretto::MusicElements::KeySignature

Inherits:
MusicElement show all
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

Attributes inherited from MusicElement

#original_string, #pattern

Attributes included from Node

#next, #prev

Instance Method Summary collapse

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(string_or_options, pattern = nil)
  token = case string_or_options
    when String then Stretto::Parser.parse_key_signature!(string_or_options)
    else string_or_options
  end
  super(token[:text_value], pattern)
  @key = normalize_keysig(token[:key])
  @scale = SCALES[token[:scale].downcase]
end

Instance Attribute Details

#keyObject (readonly)

Returns the value of attribute key.



19
20
21
# File 'lib/stretto/music_elements/key_signature.rb', line 19

def key
  @key
end

#scaleObject (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.

Returns:

  • (Number)

    +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