provided.util
Class KeySignature

java.lang.Object
  extended by provided.util.KeySignature

public class KeySignature
extends java.lang.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#".


Nested Class Summary
private  class KeySignature.KeyNote
          Utility class to keep track of the position of notes
 
Field Summary
private static int[] _major
          Half steps in a Major key
private static int[] _minor
          Half steps in a Minor key
private  KeySignature.KeyNote[] fs_dsm
          Special case for F# and D#m
private  java.util.Map<java.lang.Character,java.lang.Integer> keymap
          Map of sharps/flats in the key signature
private  KeySignature.KeyNote[] notes
          Ordering of notes (using only sharps)
 
Constructor Summary
KeySignature(java.lang.String key)
          Generate a "Key" object that enables easy access to the key signature.
 
Method Summary
 Note adjust(Note n)
          Takes a note and returns the properly transposed note in this key signature
private  KeySignature.KeyNote convertflat(char n)
          Helper method to convert a note to its equivalent flat version.
private  void insert(KeySignature.KeyNote n)
          Helper method to insert the given note into the keymap.
private  int map(java.lang.Character note)
          Takes a note (with no accidentals) and returns the accidental for this key signature.
 void printmap()
          Print the mapping for this key signature
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_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 java.util.Map<java.lang.Character,java.lang.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 Detail

KeySignature

public KeySignature(java.lang.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 Detail

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(java.lang.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

printmap

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