Package com.tagtraum.audiokern.key
Enum Tone
- java.lang.Object
-
- java.lang.Enum<Tone>
-
- com.tagtraum.audiokern.key.Tone
-
- All Implemented Interfaces:
Serializable
,Comparable<Tone>
public enum Tone extends Enum<Tone> implements Serializable
Tone.- Author:
- Hendrik Schreiber
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static float
deviationFromStandardTuningInCents(double frequency)
Computes the deviation from standard 440Hz tuning in cents.static float
deviationFromStandardTuningInSemitoneFractions(double frequency, int resolution)
Computes the deviation from standard 440Hz tuning in fractions of a semitone.static double
distance(double tone1, double tone2)
Distance in halftone steps.double
frequency(double aFrequency)
String
getAlternativeName()
Alternative name for this tone.Key
getKey(Mode mode)
Gets the key with the given mode which has this tone as a tonic.String
getLocalizedAlternativeName()
Localized alternative name for this tone (default locale).String
getLocalizedAlternativeName(Locale locale)
Localized alternative name for this tone.String
getLocalizedName()
Localized name for this tone (default locale).String
getLocalizedName(Locale locale)
Localized name for this tone.Key
getMajorKey()
Gets the major key which has this tone as a tonic.Key
getMinorKey()
Gets the minor key which has this tone as a tonic.String
getName()
Name of this tone.static double
increase(double frequency, float cents)
Increases the given frequency by the given number of cents.boolean
isNatural()
Indicates whether this tone is a "natural" tone, i.e.static boolean
isTone(double frequency)
int
negativeDistance(Tone tone)
Negative distance in half tone steps from this tone to another.Tone
next()
Next semitone.int
positiveDistance(Tone tone)
Positive distance in half tone steps from this tone to another.Tone
previous()
Previous semitone.static float
toFrequency(float midi)
Converts a floating point MIDI value to a frequency.static float
toMIDI(double frequency)
Pitch in MIDI Tuning Standard (MTS) notation.String
toString()
static Tone
toTone(double frequency)
Finds the tone that's closest to the given frequency.static Tone
toTone(int midiNotation)
static Tone
toTone(String toneName)
Converts the given tone name into a tone instance.static Tone
valueOf(String name)
Returns the enum constant of this type with the specified name.static Tone[]
values()
Returns an array containing the constants of this enum type, in the order they are declared.
-
-
-
Enum Constant Detail
-
A
public static final Tone A
A.
-
B_FLAT
public static final Tone B_FLAT
A#.
-
B
public static final Tone B
B.
-
C
public static final Tone C
C.
-
D_FLAT
public static final Tone D_FLAT
C#.
-
D
public static final Tone D
D.
-
E_FLAT
public static final Tone E_FLAT
D#.
-
E
public static final Tone E
E.
-
F
public static final Tone F
F.
-
F_SHARP
public static final Tone F_SHARP
F#.
-
G
public static final Tone G
G.
-
A_FLAT
public static final Tone A_FLAT
G#.
-
-
Field Detail
-
B_SHARP
public static final Tone B_SHARP
B#.
-
E_SHARP
public static final Tone E_SHARP
E#.
-
G_SHARP
public static final Tone G_SHARP
Ab.
-
A_SHARP
public static final Tone A_SHARP
Bb.
-
C_FLAT
public static final Tone C_FLAT
Cb.
-
C_SHARP
public static final Tone C_SHARP
Db.
-
D_SHARP
public static final Tone D_SHARP
Eb.
-
F_FLAT
public static final Tone F_FLAT
Fb.
-
G_FLAT
public static final Tone G_FLAT
Gb.
-
-
Method Detail
-
values
public static Tone[] values()
Returns an array containing the constants of this enum type, in the order they are declared. This method may be used to iterate over the constants as follows:for (Tone c : Tone.values()) System.out.println(c);
- Returns:
- an array containing the constants of this enum type, in the order they are declared
-
valueOf
public static Tone valueOf(String name)
Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)- Parameters:
name
- the name of the enum constant to be returned.- Returns:
- the enum constant with the specified name
- Throws:
IllegalArgumentException
- if this enum type has no constant with the specified nameNullPointerException
- if the argument is null
-
isNatural
public boolean isNatural()
Indicates whether this tone is a "natural" tone, i.e. is a white key on the piano.- Returns:
true
orfalse
-
frequency
public double frequency(double aFrequency)
- Parameters:
aFrequency
- frequency of the next lowest A- Returns:
- frequency of this tone
-
toMIDI
public static float toMIDI(double frequency)
Pitch in MIDI Tuning Standard (MTS) notation.- Parameters:
frequency
- frequency- Returns:
- 69 + 12*log2(f/440)
-
toFrequency
public static float toFrequency(float midi)
Converts a floating point MIDI value to a frequency.- Parameters:
midi
- MIDI value- Returns:
- frequency
-
distance
public static double distance(double tone1, double tone2)
Distance in halftone steps.- Parameters:
tone1
- frequency in hztone2
- frequency in hz- Returns:
- the number of halftonesteps between the two frequencies
-
positiveDistance
public int positiveDistance(Tone tone)
Positive distance in half tone steps from this tone to another. The result is always positive, i.e. we always go up.- Parameters:
tone
- the other tone- Returns:
- positive distance in half tone steps
-
negativeDistance
public int negativeDistance(Tone tone)
Negative distance in half tone steps from this tone to another. The result is always negative, i.e. we always go down.- Parameters:
tone
- the other tone- Returns:
- negative distance in half tone steps
-
toTone
public static Tone toTone(int midiNotation)
-
toTone
public static Tone toTone(double frequency)
Finds the tone that's closest to the given frequency.- Parameters:
frequency
- a frequency- Returns:
- the closest tone
-
toTone
public static Tone toTone(String toneName)
Converts the given tone name into a tone instance.- Parameters:
toneName
- name- Returns:
- instance or
null
-
deviationFromStandardTuningInCents
public static float deviationFromStandardTuningInCents(double frequency)
Computes the deviation from standard 440Hz tuning in cents. The given frequency does not have to be an A4.- Parameters:
frequency
- frequency in Hz- Returns:
- deviation from standard tuning in cents - value between
-49
and50
- See Also:
deviationFromStandardTuningInSemitoneFractions(double, int)
-
deviationFromStandardTuningInSemitoneFractions
public static float deviationFromStandardTuningInSemitoneFractions(double frequency, int resolution)
Computes the deviation from standard 440Hz tuning in fractions of a semitone. The given frequency does not have to be an A4.- Parameters:
frequency
- frequency in Hzresolution
- to get cents, this needs to be100
, to get thirds, this needs to be3
- Returns:
- deviation from standard tuning in fractions - e.g. for a resolution of
100
this returns a value between-49
and50
. For a resolution of3
, this returns a value between-1
and+1
.
-
increase
public static double increase(double frequency, float cents)
Increases the given frequency by the given number of cents.- Parameters:
frequency
- base frequencycents
- cents, may be negative- Returns:
- increased frequency
-
isTone
public static boolean isTone(double frequency)
- Parameters:
frequency
- frequency to check- Returns:
- true or false
-
getKey
public Key getKey(Mode mode)
Gets the key with the given mode which has this tone as a tonic.- Parameters:
mode
- mode- Returns:
- key
-
getMajorKey
public Key getMajorKey()
Gets the major key which has this tone as a tonic.- Returns:
- key
-
getMinorKey
public Key getMinorKey()
Gets the minor key which has this tone as a tonic.- Returns:
- key
-
getName
public String getName()
Name of this tone.- Returns:
- tone
- See Also:
getAlternativeName()
-
getAlternativeName
public String getAlternativeName()
Alternative name for this tone. E.g. C# can also be called Db.- Returns:
- alternative name
- See Also:
getName()
-
getLocalizedName
public String getLocalizedName()
Localized name for this tone (default locale).- Returns:
- localized name
-
getLocalizedAlternativeName
public String getLocalizedAlternativeName()
Localized alternative name for this tone (default locale).- Returns:
- localized alternative name
-
getLocalizedName
public String getLocalizedName(Locale locale)
Localized name for this tone.- Parameters:
locale
- locale- Returns:
- localized name
-
getLocalizedAlternativeName
public String getLocalizedAlternativeName(Locale locale)
Localized alternative name for this tone.- Parameters:
locale
- locale- Returns:
- localized alternative name
-
next
public Tone next()
Next semitone.- Returns:
- next semitone
-
previous
public Tone previous()
Previous semitone.- Returns:
- previous semitone
-
-