uk.org.toot.music.tonality
Class Key

java.lang.Object
  extended by java.util.Observable
      extended by uk.org.toot.music.tonality.Key

public class Key
extends java.util.Observable

A Key has a root pitch class and a Scale It does not have a register. It is Observable to simplify modulation


Nested Class Summary
static interface Key.Provider
          A Provider provides a mutable Key for Observers to observe.
 
Constructor Summary
Key()
           
Key(int root)
           
Key(int root, Scale scale)
          Constructor
Key(java.lang.String root, Scale scale)
           
 
Method Summary
 boolean contains(int pitch)
          Return whether this Key contains the specified pitch.
 boolean contains(int[] pitches)
          Return whether this Key contains all the specified pitches.
 int diatonicPitch(int pitch)
          Returns the nearest diatonic pitch, preference to lower
 boolean equals(java.lang.Object o)
           
 int[] getChordNotes(int index, int poly, int lowInterval)
          Return the notes of a chord with specified polyphony and interval.
 java.lang.String[] getNames()
          Get the note names for this Key
 int getNote(int index)
          Return the note derived from the index into the Key.
 int getRelativePitch(int pitch, int offset)
           
 int getRoot()
          Get the root pitch class of this Key.
 Scale getScale()
          Get the Scale for this Key.
 int index(int pitch)
          Return the index of a pitch into this Key's Scale, effectively a linear measure of the degree.
 java.lang.String name()
          Return the name of this Key as root note (pitch class) and Scale.
 java.lang.String name(int index)
          Return the name of a note indexed into the Key
 void setNames(java.lang.String[] names)
          Set the not names for this Key.
 void setRoot(int root)
          Set the root pitch class for this Key and notify Observers.
 void setScale(Scale scale)
          Set the Scale for this Key and notify Observers.
 java.lang.String toString()
          Return the name of this Key, e.g.
 
Methods inherited from class java.util.Observable
addObserver, countObservers, deleteObserver, deleteObservers, hasChanged, notifyObservers, notifyObservers
 
Methods inherited from class java.lang.Object
getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Key

public Key(int root,
           Scale scale)
Constructor


Key

public Key(java.lang.String root,
           Scale scale)

Key

public Key(int root)

Key

public Key()
Method Detail

contains

public boolean contains(int[] pitches)
Return whether this Key contains all the specified pitches.

Parameters:
pitches - the array of int values of the pitches
Returns:
true if this Key contains all the pitches, false otherwise

contains

public boolean contains(int pitch)
Return whether this Key contains the specified pitch.

Parameters:
pitch - the int value of the pitch
Returns:
true if this Key contains the pitch, false otherwise

index

public int index(int pitch)
Return the index of a pitch into this Key's Scale, effectively a linear measure of the degree.

Parameters:
pitch - the int value of the pitch
Returns:
the index into the Key's Scale or -1 if not a diatonic pitch

getNames

public java.lang.String[] getNames()
Get the note names for this Key

Returns:
the array of names or null if names have not been explicitly set

setNames

public void setNames(java.lang.String[] names)
Set the not names for this Key. permits correction of enharmonic spelling!


getRoot

public int getRoot()
Get the root pitch class of this Key.

Returns:
the int value of the root pitch class

setRoot

public void setRoot(int root)
Set the root pitch class for this Key and notify Observers.

Parameters:
root - the new root pitch class for this key

getScale

public Scale getScale()
Get the Scale for this Key.

Returns:
the Scale

setScale

public void setScale(Scale scale)
Set the Scale for this Key and notify Observers.

Parameters:
scale - the new Scale for this Key.

diatonicPitch

public int diatonicPitch(int pitch)
Returns the nearest diatonic pitch, preference to lower

Parameters:
pitch - the possibly non-diatonic pitch
Returns:
the int value of the nearest diatonic pitch

getRelativePitch

public int getRelativePitch(int pitch,
                            int offset)

getNote

public int getNote(int index)
Return the note derived from the index into the Key. A returned note may no longer be a pitch class, it may extend into the second octave of pitches.

Parameters:
index - the index into the Key's Scale
Returns:
the note

getChordNotes

public int[] getChordNotes(int index,
                           int poly,
                           int lowInterval)
Return the notes of a chord with specified polyphony and interval. The notes may no longer all be pitch classes since they may extend into the second octave of pitches.

Parameters:
index - the index into the Key's Scale
poly - the number of notes, 2 .. 7
lowInterval - ChordMode.SECUNDAL, ChordMode.TERTIARY or ChordMode.QUARTAL
Returns:
the notes of the chord

toString

public java.lang.String toString()
Return the name of this Key, e.g. "C Major" and it's notes

Overrides:
toString in class java.lang.Object

equals

public boolean equals(java.lang.Object o)
Overrides:
equals in class java.lang.Object

name

public java.lang.String name()
Return the name of this Key as root note (pitch class) and Scale.


name

public java.lang.String name(int index)
Return the name of a note indexed into the Key

Parameters:
index -


Copyright © 2004, 2005, 2006, 2007 Steve Taylor. All Rights Reserved.