|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.amx.duet.tools.math.Range
A utility class to handle ranges used within Duet modules. These ranges can be especially useful when adjusting values between the panel and the device.
Constructor Summary | |
Range(double minValue,
double maxValue,
double increment)
Constructs and initializes the Range class. |
|
Range(double minValue,
double maxValue,
double increment,
double currentValue)
Constructs and initializes the Range class. |
Method Summary | |
double |
getCurrentValue()
Returns the current value of the rnage. |
double |
getIncrement()
Returns the value of the increment used to determin discrete values within the range. |
double |
getMaxValue()
Returns the maximum value of the range. |
double |
getMinValue()
Returns the minimum value of the Range. |
int |
getPosition()
Returns the discrete position of the currentValue of the range. |
int |
getPosition(double value)
Returns the discrete position of the range that most closely matches the value. |
double |
getScaledValue(Range sourceRange)
Returns the value of this range based on the scaled position of the sourceRange. |
double |
getValue(int step)
Returns the value of the discrete position of this range. |
double |
getValueForOffset(int offset)
Returns the value of the discrete position of the current value plus the offset. |
int |
numberOfSteps()
Returns the number of discrete values contained within this range. |
int |
scale(Range sourceRange)
Returns the position the value of the sourceRange would have within this range. |
void |
setCurrentValue(double value)
Sets the current value of the range. |
Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public Range(double minValue, double maxValue, double increment, double currentValue)
Example usage:
Range panelRange = new Range( 0, 255, 1); Range volumeRange = new Range( -95.5, 31.5, .5); ... public void setVolume(int level) { panelRange.setCurrentValue( level ); double deviceVolume = volumeRange.getScaledValue(panelRange); // If your device only needs an integer value, you can cast // the deviceVolume returned from getScaled value as shown below: // int deviceVolume = (int) volumeRange.getScaledValue(panelRange); enQueue( setVolumeCommand(deviceVolume) ); } private void parseResponse(ByteBuffer data) { ... // Handling Volume response String volumeValue = data.toString().substring(volumeStart,volumeEnd); double deviceVolume = Double.parseDouble(volumeValue); // If your device only needs an integer value, you can cast // the deviceVolume returned from getScaled value as shown below: // int deviceVolume = Integer.parseInt(volumeValue); volumeRange.setCurrentValue( deviceVolume ); int panelVolume = panelRange.scale( volumeRange ); updateVolume( panelVolume ); }
minValue
- The minimum value of the range.maxValue
- The maximum value of the range.increment
- The increment between each discrete value of the range.currentValue
- The current value of range.public Range(double minValue, double maxValue, double increment)
minValue
- The minimum value of the range.maxValue
- The maximum value of the range.increment
- The increment between each discrete value of the range.Range(double,double,double,double)
Method Detail |
public double getCurrentValue()
public double getIncrement()
public double getMaxValue()
public double getMinValue()
public int getPosition()
getPosition(double)
public int getPosition(double value)
value
- The value you want to evaluate the position of.
public double getScaledValue(Range sourceRange)
sourceRange
- The range you want to evaluate the discrete position of the
value.
getValue(int)
,
scale(Range)
public double getValue(int step)
step
- The discrete position of this range.
public double getValueForOffset(int offset)
Example usage:
public void adjustVolume(int offset) { double deviceVolume = volumeRange.getValueForOffset( offset ); enQueue( setVolumeCommand(deviceVolume) ); }Review
getValue(int)
for more information....
offset
- The number of discrete units to adjust.
public int numberOfSteps()
public int scale(Range sourceRange)
sourceRange
- The range you want to evaluate the discrete position of the
value.
public void setCurrentValue(double value)
value
- The currentValue to set.
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |