com.soundhelix.util
Class NoteUtils

java.lang.Object
  extended by com.soundhelix.util.NoteUtils

public final class NoteUtils
extends Object

Implements some static methods for converting notes to pitches and vice versa.

Author:
Thomas Schuerger (thomas@schuerger.com)

Method Summary
static String getNoteName(int pitch)
          Returns the note name of the given pitch in lower-case.
static int getNotePitch(String name)
          Returns the note pitch of the given note (between 0 and 11), ignoring case.
static int getTransitionPitch(Chord chord, Chord nextChord)
          Returns a transition pitch between the chord and the next chord, which is based on the base pitches of the two chords.
static boolean isOnScale(int pitch)
          Returns true iff the given pitch is on the C/Am scale (i.e., a white key on the piano keyboard).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getNoteName

public static String getNoteName(int pitch)
Returns the note name of the given pitch in lower-case. The pitch is normalized first (between 0 and 11).

Parameters:
pitch - the pitch
Returns:
the pitch name

getNotePitch

public static int getNotePitch(String name)
Returns the note pitch of the given note (between 0 and 11), ignoring case. If the note is invalid, Integer.MIN_VALUE is returned.

Parameters:
name - the note name
Returns:
the note pitch or Integer.MIN_VALUE

isOnScale

public static boolean isOnScale(int pitch)
Returns true iff the given pitch is on the C/Am scale (i.e., a white key on the piano keyboard).

Parameters:
pitch - the pitch to check
Returns:
true or false

getTransitionPitch

public static int getTransitionPitch(Chord chord,
                                     Chord nextChord)
Returns a transition pitch between the chord and the next chord, which is based on the base pitches of the two chords. If the next chord is null, the pitch of the first chord is used. If the pitch difference of the two chords is 2, the halftone in between is returned. If the pitch difference of the two chords is one or zero, the first pitch is returned. Otherwise, a pitch between the two pitches which is on the C/Am scale is returned.

Parameters:
chord - the current chord
nextChord - the next chord (or null)
Returns:
a transition pitch