Module hw06

Class KeySignature

java.lang.Object
provided.abcMusic.utils.KeySignature

public class KeySignature extends Object
Utility class to simplify dealing with key signatures
Usage:
KeySignature keySig = new KeySignature(aKey); // aKey is a string representing a key, e.g. "C", "Bb", "Am"
Note adjustedNote = keySig.adjust(originalNote); // returns the Note object, adjusted so that it matches the key, e.g for key of "D", an "F" --> "F#".
  • Field Details

    • logger

      private ILogger logger
      logger to use
    • _major

      private static final int[] _major
      Half steps in a Major key
    • _minor

      private static final int[] _minor
      Half steps in a Minor key
    • keymap

      private Map<Character,​Integer> keymap
      Map of sharps/flats in the key signature
    • notes

      private KeySignature.KeyNote[] notes
      Ordering of notes (using only sharps)
    • fs_dsm

      private KeySignature.KeyNote[] fs_dsm
      Special case for F# and D#m
  • Constructor Details

    • KeySignature

      public KeySignature(String key)
      Generate a "Key" object that enables easy access to the key signature.
      Parameters:
      key - - String indicating key (i.e., "C" or "D#m")
  • Method Details

    • convertflat

      private KeySignature.KeyNote convertflat(char n)
      Helper method to convert a note to its equivalent flat version.
      Parameters:
      n - - note letter
      Returns:
      - equivalent flat version of note n
    • insert

      private void insert(KeySignature.KeyNote n)
      Helper method to insert the given note into the keymap.
      Parameters:
      n - - note to add to the map
    • map

      private int map(Character note)
      Takes a note (with no accidentals) and returns the accidental for this key signature.
      Parameters:
      note - - in [A, B, C, D, E, F, G]
      Returns:
      accidental for the note in this key signature [-1, 0, 1]
    • adjust

      public Note adjust(Note n)
      Takes a note and returns the properly transposed note in this key signature
      Parameters:
      n - - note to be adjusted
      Returns:
      A new, adjusted Note
    • printmap

      public void printmap()
      Print the mapping for this key signature