be.hogent.tarsos.sampled.pitch
Class Pitch

java.lang.Object
  extended by be.hogent.tarsos.sampled.pitch.Pitch

public final class Pitch
extends java.lang.Object

A class representing pitch. Can be used to convert pitch units or to base pitch interval calculations on.

Author:
Joren Six

Method Summary
static Pitch getInstance(PitchUnit unit, double value)
          Return a new pitch object using value in a certain unit.
 double getPitch(PitchUnit unit)
          Get the pitch value in a given unit.
 boolean isWesternMusicalPitch()
          A pitch is seen as a western musical pitch if it is less than 15 cents removed from the 'correct' pitch.
 java.lang.String noteName()
          Returns the name of the MIDI key corresponding to the given hertzValue.
 int octaveIndex()
          Calculates which octave this pitch falls into.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Method Detail

getPitch

public double getPitch(PitchUnit unit)
Get the pitch value in a given unit.

Parameters:
unit - The requested unit.
Returns:
A pitch value in the requested unit.

octaveIndex

public int octaveIndex()
Calculates which octave this pitch falls into. The octave index is based on MIDI keys. Keys [0,11] fall in octave -1, [11,23] in octave 0,...

Returns:
The octave the pitch falls into, calculated using MIDI key.
Throws:
java.lang.IllegalArgumentException - If the pitch does not fall within the range of valid MIDI KEYS.

noteName

public java.lang.String noteName()
Returns the name of the MIDI key corresponding to the given hertzValue. The MIDI key is the key returned by the convertHertzToMidiKey method.

Returns:
A note name like C3, A4 or A3#/B3b.
Throws:
java.lang.IllegalArgumentException - When the hertzValue is outside the valid MIDI key range.

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

isWesternMusicalPitch

public boolean isWesternMusicalPitch()
A pitch is seen as a western musical pitch if it is less than 15 cents removed from the 'correct' pitch. The correct pitch is tuned using A4 = 440Hz.

Returns:
True if the pitch is western and musical, false otherwise.

getInstance

public static Pitch getInstance(PitchUnit unit,
                                double value)
Return a new pitch object using value in a certain unit.

Parameters:
unit - The unit of the pitch value.
value - The value Itself.
Returns:
A new Pitch object.
Throws:
java.lang.IllegalArgumentException - If RELATIVE_CENTS is given: Cannot convert relative cent value to absolute frequency.