Class RP_State

java.lang.Object
org.jjazz.rhythm.api.RP_State
All Implemented Interfaces:
Cloneable, RhythmParameter<String>, RpEnumerable<String>
Direct Known Subclasses:
RP_SYS_Feel, RP_SYS_Fill, RP_SYS_Marker, RP_SYS_Variation

public class RP_State extends Object implements RhythmParameter<String>, RpEnumerable<String>, Cloneable
A RhythmParameter whose value can be some specified strings.
  • Constructor Details

    • RP_State

      public RP_State(String id, String name, String description, boolean isPrimary, String defaultValue, String... possibleValues)
      Create a RP_State RhythmParameter.

      Created instance is primary by default.

      Parameters:
      id -
      name - The name of the RhythmParameter.
      description -
      isPrimary -
      defaultValue - String The default value.
      possibleValues - String[] The possible values for this parameter. By convention, min value is set to the 1st possible value, max value to the last one.
  • Method Details

    • getCopy

      public RP_State getCopy(Rhythm r)
      Description copied from interface: RhythmParameter
      Get a copy of this RhythmParameter.
      Specified by:
      getCopy in interface RhythmParameter<String>
      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<String>
      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<String>
      Returns:
      A unique identifier. Usually the english name.
    • getDefaultValue

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

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

      public final String 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<String>
      Parameters:
      y - A float between 0 and 1.
      Returns:
      A RhythmParameter value.
    • calculatePercentage

      public final double calculatePercentage(String value)
      Specified by:
      calculatePercentage in interface RpEnumerable<String>
      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<String>
      Returns:
    • getMaxValue

      public final String getMaxValue()
      Specified by:
      getMaxValue in interface RpEnumerable<String>
    • getMinValue

      public final String getMinValue()
      Specified by:
      getMinValue in interface RpEnumerable<String>
    • getDisplayName

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

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

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

      public final List<String> 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<String>
      Returns:
    • saveAsString

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

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

      public String getValueDescription(String value)
      Description copied from interface: RhythmParameter
      Provide an optional description or help text associated to the specified value.
      Specified by:
      getValueDescription in interface RhythmParameter<String>
      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<String>
      Parameters:
      rp -
      Returns:
      True if a rp's value can be converted to a value for this RhythmParameter.
    • convertValue

      public <T> String 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<String>
      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(String value)
      Description copied from interface: RhythmParameter
      Get a short String representation of the value.
      Specified by:
      getDisplayValue in interface RhythmParameter<String>
      Parameters:
      value -
      Returns:
      Can be an empty String.
    • toString

      public String toString()
      Overrides:
      toString in class Object