Class KeyFactory


  • public final class KeyFactory
    extends Object
    Parses key values usually found in id3 tags or the like.
    Author:
    Hendrik Schreiber
    • Field Detail

      • SUPPORTED_LOCALES

        public static final List<Locale> SUPPORTED_LOCALES
    • Method Detail

      • guessFromTags

        public static Key guessFromTags​(AudioSong song)
        Guess the key by interpreting other textual metadata like album, work and track name.
        Parameters:
        song - track
        Returns:
        key or null, if no unambiguous key could be found
      • guessFromTag

        public static Key guessFromTag​(String tag)
        Guess the key by interpreting the given textual tag.
        Parameters:
        tag - textual tag
        Returns:
        key or null, if no unambiguous key could be found
      • get

        public static Key get​(Tone tone,
                              Mode mode)
        Same as tone.getKey(mode).
        Parameters:
        tone - tone
        mode - mode
        Returns:
        key
      • parseTKEY

        public static Key parseTKEY​(String id3TkeyTag)
        TKEY

        The 'Initial key' frame contains the musical key in which the sound starts. It is represented as a string with a maximum length of three characters. The ground keys are represented with "A","B","C","D","E", "F" and "G" and halfkeys represented with "b" and "#". Minor is represented as "m", e.g. "Dbm". Off key is represented with an "o" only.

        Parameters:
        id3TkeyTag - id3 key tag
        Returns:
        key
        See Also:
        http://www.id3.org/id3v2.4.0-frames.txt
      • parseKeyCode

        public static Key parseKeyCode​(String keyCode)
        Parses a key code.
        Parameters:
        keyCode - key code
        Returns:
        key
        See Also:
        Key.getKeyCode()
      • keyForAccidentals

        public static Key keyForAccidentals​(boolean major,
                                            int accidentals)
        Convert the number of accidentals to a key.
        Parameters:
        major - major key?
        accidentals - number of accidentals (positive for sharps, negative for flats)
        Returns:
        key
      • parse

        public static Key parse​(MidiMessage message)
        Parse MidiMessage and return the corresponding key, if possible.
        Parameters:
        message - midi message
        Returns:
        key or null, if the message is not a key change message