Class Key


  • public class Key
    extends Object
    A key, such as C major or A minor. Names of keys are like "Bb" and "F#m": they consist of the root note plus a suffix for major or minor.
    • Method Detail

      • getNotesInKey

        public Set<Integer> getNotesInKey()
        Returns the notes in this key, as relative note numbers.
        Returns:
      • getDirection

        public int getDirection()
        Returns 1 for keys that use sharps, -1 for keys that use flats. By convention, C major and A minor count as sharp keys.
        Returns:
      • getAccidentalNoteToBaseNote

        public Map<Integer,​Integer> getAccidentalNoteToBaseNote()
        Returns a mapping from the accidental notes in this key to their natural base notes. Both accidental and base notes are represented as relative note numbers. For instance, in Bb major, this mapping sends 10 (= Bb) to 11 (= B) and 3 (= Eb) to 4 (= E). Notes which are not accidentals in this key do not appear in the mapping; so the mapping can be used to check whether a certain note in this key has an accidental or not.
        Returns:
      • getAccidentalForNote

        public int getAccidentalForNote​(String note)
        Returns the accidental on the note with the given canonical name (-1, 0, or +1).
        Parameters:
        note -
        Returns:
      • getBaseNote

        public int getBaseNote​(int relativeNote)
        Returns the base note for the given note. If the note has an accidental in this key, the natural version of the note is returned; so Eb → E in Bb major. If the note doesn't have an accidental in the first place, it is returned unmodified.
        Parameters:
        relativeNote -
        Returns:
      • lookup

        public static Key lookup​(String name)
        Returns the key with the given name.
        Parameters:
        name -
        Returns:
      • toString

        public String toString()
        Returns the name of this key as a major key. Thus both C major and A minor are represented as "C".
        Overrides:
        toString in class Object
        Returns: