Class RP_EnumState<E extends Enum<E>>

java.lang.Object
org.jjazz.rhythm.api.RP_EnumState<E>
Type Parameters:
E -
All Implemented Interfaces:
Cloneable, RhythmParameter<E>, RpEnumerable<E>

public class RP_EnumState<E extends Enum<E>> extends Object implements RhythmParameter<E>, RpEnumerable<E>, Cloneable
A variant of RP_State built from an enum value.
  • Constructor Details

    • RP_EnumState

      public RP_EnumState(String id, String name, String description, boolean isPrimary, Class<E> enumClass, E defaultValue)
      Create a RP_EnumState RhythmParameter.

      The possible values are the possible enum values. The min value if the first value of the enum, the max value the last one.

      Parameters:
      id -
      name - The name of the RhythmParameter.
      description -
      isPrimary -
      enumClass -
      defaultValue - E The default value.
  • Method Details

    • getCopy

      public RP_EnumState<E> getCopy(Rhythm r)
      Description copied from interface: RhythmParameter
      Get a copy of this RhythmParameter.
      Specified by:
      getCopy in interface RhythmParameter<E extends Enum<E>>
      Parameters:
      r - Can be null. Optionally set the target Rhythm of the returned RhythmParameter -though it might be ignored by the implementing method.
      Returns:
    • isPrimary

      public boolean isPrimary()
      Description copied from interface: RhythmParameter
      Indicate if this RhythmParameter is a primary parameter for its rhythm.

      This information is made available mainly for the user interface, e.g. to select which RhythmParameters to show first.

      Default implementation returns true.

      Specified by:
      isPrimary in interface RhythmParameter<E extends Enum<E>>
      Returns:
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • getId

      public final String getId()
      Specified by:
      getId in interface RhythmParameter<E extends Enum<E>>
      Returns:
      A unique identifier. Usually the english name.
    • getDefaultValue

      public final E getDefaultValue()
      Specified by:
      getDefaultValue in interface RhythmParameter<E extends Enum<E>>
      Returns:
      Object The default value.
    • isValidValue

      public final boolean isValidValue(E value)
      Specified by:
      isValidValue in interface RhythmParameter<E extends Enum<E>>
      Parameters:
      value -
      Returns:
      True is value is valid.
    • calculateValue

      public final E calculateValue(double y)
      Description copied from interface: RpEnumerable
      Calculate the RhythmParameter value corresponding to a percentage of the value range.

      For example if RhythmParameter is an integer between 0 and 4: percentage=0 -> value=0 percentage=0.5 -> value=2 percentage=1 -> value=4.

      Specified by:
      calculateValue in interface RpEnumerable<E extends Enum<E>>
      Parameters:
      y - A float between 0 and 1.
      Returns:
      A RhythmParameter value.
    • calculatePercentage

      public final double calculatePercentage(E value)
      Specified by:
      calculatePercentage in interface RpEnumerable<E extends Enum<E>>
      Parameters:
      value -
      Returns:
      A percentage between 0 and 1 representing value in the range of the possible values.
    • getDescription

      public final String getDescription()
      Description copied from interface: RhythmParameter
      The description of this rhythm parameter.
      Specified by:
      getDescription in interface RhythmParameter<E extends Enum<E>>
      Returns:
    • getMaxValue

      public final E getMaxValue()
      Specified by:
      getMaxValue in interface RpEnumerable<E extends Enum<E>>
    • getMinValue

      public final E getMinValue()
      Specified by:
      getMinValue in interface RpEnumerable<E extends Enum<E>>
    • getDisplayName

      public final String getDisplayName()
      Specified by:
      getDisplayName in interface RhythmParameter<E extends Enum<E>>
      Returns:
      The localized display name of the rhythm parameter.
    • getNextValue

      public final E getNextValue(E value)
      Description copied from interface: RpEnumerable
      Get the next value after specified value.
      Specified by:
      getNextValue in interface RpEnumerable<E extends Enum<E>>
      Parameters:
      value -
      Returns:
      Object
    • getPreviousValue

      public final E getPreviousValue(E value)
      Description copied from interface: RpEnumerable
      Get the next value before specified value.
      Specified by:
      getPreviousValue in interface RpEnumerable<E extends Enum<E>>
      Parameters:
      value -
      Returns:
      Object
    • getPossibleValues

      public final List<E> getPossibleValues()
      Description copied from interface: RpEnumerable
      Get the list of possible values for this RhythmParameter.

      Only the first 10000 values are returned.

      Specified by:
      getPossibleValues in interface RpEnumerable<E extends Enum<E>>
      Returns:
    • saveAsString

      public String saveAsString(E value)
      Description copied from interface: RhythmParameter
      Try to convert the specified RhythmParameter value to a string.
      Specified by:
      saveAsString in interface RhythmParameter<E extends Enum<E>>
      Parameters:
      value -
      Returns:
      Can be null if value is invalid.
      See Also:
    • loadFromString

      public E loadFromString(String s)
      Description copied from interface: RhythmParameter
      Try to convert the specified string to a RhythmParameter value.
      Specified by:
      loadFromString in interface RhythmParameter<E extends Enum<E>>
      Parameters:
      s - A string produced by valueToString().
      Returns:
      Can be null if conversion failed.
      See Also:
    • getValueDescription

      public String getValueDescription(E value)
      Description copied from interface: RhythmParameter
      Provide an optional description or help text associated to the specified value.
      Specified by:
      getValueDescription in interface RhythmParameter<E extends Enum<E>>
      Parameters:
      value -
      Returns:
      Can be null.
    • isCompatibleWith

      public boolean isCompatibleWith(RhythmParameter<?> rp)
      Description copied from interface: RhythmParameter
      Indicate if rp is compatible with this RhythmParameter.

      NOTE: if rp1 is compatible with rp2, then rp2 must be compatible with rp1 as well.

      Specified by:
      isCompatibleWith in interface RhythmParameter<E extends Enum<E>>
      Parameters:
      rp -
      Returns:
      True if a rp's value can be converted to a value for this RhythmParameter.
    • convertValue

      public <T> E convertValue(RhythmParameter<T> rp, T value)
      Description copied from interface: RhythmParameter
      Convert the value of a compatible RhythmParameter to a value for this RhythmParameter.
      Specified by:
      convertValue in interface RhythmParameter<E extends Enum<E>>
      Type Parameters:
      T - A RhythmParameter value
      Parameters:
      rp - A compatible RhythmParameter
      value - The value to convert
      Returns:
      The rpValue converted for this RhythmParameter. Can't be null.
    • getDisplayValue

      public String getDisplayValue(E value)
      Description copied from interface: RhythmParameter
      Get a short String representation of the value.
      Specified by:
      getDisplayValue in interface RhythmParameter<E extends Enum<E>>
      Parameters:
      value -
      Returns:
      Can be an empty String.
    • toString

      public String toString()
      Overrides:
      toString in class Object