Class: KeySignature

music21.key. KeySignature

new KeySignature(sharps)

Represents a key signature

Parameters:
Name Type Argument Default Description
sharps Int <optional>
0
  • the number of sharps (negative for flats)
Properties:
Name Type Argument Default Description
sharps Int <optional>
0
  • number of sharps (negative for flats)
Source:
Example
var ks = new music21.key.KeySignature(-3); //E-flat major or c minor
var s = new music21.stream.Stream();
s.keySignature = ks;
var n = new music21.note.Note('A-'); // A-flat
s.append(n);
s.appendNewDOM();

Extends

Members

<readonly> alteredPitches :Array.<music21.pitch.Pitch>

An Array of Altered Pitches in KeySignature order (i.e., for flats, Bb, Eb, etc.)

Type:
Source:
Example
var ks = new music21.key.KeySignature(3)
var ap = ks.alteredPitches
var apName = [];
for (var i = 0; i < ap.length; i++) {
    apName.push(ap[i].name);
}
apName
// ["F#", "C#", "G#"]

<readonly> width :number

Gives the width in pixels necessary to represent the key signature.

Type:
  • number
Source:

Methods

<static> KeySignature#accidentalByStep(step) → {music21.pitch.Accidental|undefined}

Returns the accidental associated with a step in this key, or undefined if none.

Parameters:
Name Type Description
step string

a valid step name such as "C","D", etc., but not "C#" etc.

Source:
Returns:
Type
music21.pitch.Accidental | undefined

<static> KeySignature#majorName() → {string|undefined}

Return the name of the major key with this many sharps

Source:
Returns:

name of key

Type
string | undefined
Example
var ks = new music21.key.KeySignature(-3)
ks.majorName()
// "E-"

<static> KeySignature#minorName() → {string|undefined}

Return the name of the minor key with this many sharps

Source:
Returns:
Type
string | undefined

<static> KeySignature#transposePitchFromC() → {music21.pitch.Pitch}

Takes a pitch in C major and transposes it so that it has
the same step position in the current key signature.

Source:
Returns:
Type
music21.pitch.Pitch
Example
var ks = new music21.key.KeySignature(-3)
var p1 = new music21.pitch.Pitch('B')
var p2 = ks.transposePitchFromC(p1)
p2.name
// "D"
var p3 = new music21.pitch.Pitch('G-')
var p4 = ks.transposePitchFromC(p3)
p4.name
// "B--"

<static> KeySignature#vexflow() → {string}

returns the vexflow name (just the majorName() with "b" for "-") for
the key signature. Does not create the object.

Deprecated.

Source:
Returns:
Type
string
Music21j, Copyright © 2013-2018 Michael Scott Cuthbert and cuthbertLab.
Documentation generated by JSDoc 3.5.5 on Wed Jul 4th 2018 using the DocStrap template.