Enum Tone

    • 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 name
        NullPointerException - 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 or false
      • 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 hz
        tone2 - 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 and 50
        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 Hz
        resolution - to get cents, this needs to be 100, to get thirds, this needs to be 3
        Returns:
        deviation from standard tuning in fractions - e.g. for a resolution of 100 this returns a value between -49 and 50. For a resolution of 3, 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 frequency
        cents - 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
      • 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