Lumiverse
2.5
A framework for creating lighting control applications
|
Defines an enumeration in Lumiverse. More...
#include <LumiverseEnum.h>
Public Types | |
enum | Mode { FIRST, CENTER, LAST } |
When you select an enumeration, mode determines where in the range the calculated value will fall. More... | |
enum | InterpolationMode { SNAP, SMOOTH_WITHIN_OPTION, SMOOTH } |
Sets the interpolation mode when transitioning between two LumiverseEnums. More... | |
Public Member Functions | |
LumiverseEnum (Mode mode=CENTER, int rangeMax=255, InterpolationMode interpMode=SMOOTH_WITHIN_OPTION) | |
Constructs an enumeration with nothing in it. More... | |
LumiverseEnum (map< string, int > keys, Mode mode=CENTER, int rangeMax=255, string def="", InterpolationMode interpMode=SMOOTH_WITHIN_OPTION) | |
Constructs an enumeration with the given keys and range start values. More... | |
LumiverseEnum (map< string, int > keys, string mode, string interpMode, int rangeMax=255, string def="") | |
Constructs an enumeration with the given keys and range start values. More... | |
LumiverseEnum (LumiverseEnum *other) | |
Copies an enumeration. More... | |
LumiverseEnum (const LumiverseEnum &other) | |
Copies an enumeration. More... | |
LumiverseEnum (LumiverseType *other) | |
Copies a generic type. More... | |
~LumiverseEnum () | |
Destructor fun times. | |
virtual string | getTypeName () |
Says that this object is an enum. More... | |
virtual void | reset () |
Resets the enum to default. | |
virtual JSONNode | toJSON (string name) |
Converts the type to a JSON object with the specified name. More... | |
virtual string | asString () |
Returns the current enumeration value as a string. More... | |
void | addVal (string name, int start) |
Adds an option to the enumeration. More... | |
void | removeVal (string name) |
Removes an option from the enumeration. More... | |
bool | setVal (string name) |
Sets the value of the enumeration. More... | |
bool | setVal (string name, float tweak) |
Sets the value of the enumeration and the tweak value. More... | |
bool | setVal (string name, float tweak, Mode enumMode, InterpolationMode interpMode) |
Sets the value of the enumeration and other options. More... | |
bool | setVal (float val) |
Sets the value of the enumeration numerically. More... | |
void | setTweak (float tweak) |
Tweaks the value of the enum. More... | |
void | setDefault (string name) |
Sets the default value of the enumeration. More... | |
string | getVal () |
Gets the current state of the enumeration. More... | |
int | getValIndex () |
Gets the first value in the active range. | |
float | getTweak () |
Gets the tweak value for the enumeration. More... | |
string | getDefault () |
Gets the default value. More... | |
void | setMode (Mode mode) |
Sets the mode. More... | |
Mode | getMode () |
Returns the mode. More... | |
void | setInterpMode (InterpolationMode mode) |
Sets the interpolation mode. More... | |
InterpolationMode | getInterpMode () |
Returns the interpolation mode. More... | |
int | getRangeMax () |
Returns the maximum numeric value this LumiverseEnum can take. | |
void | setRangeMax (int newMax) |
Sets the maximum numeric value this LumiverseEnum can take. More... | |
shared_ptr< LumiverseType > | lerp (LumiverseEnum *rhs, float t) |
Does a linear interpolation based on the interpolation mode. More... | |
float | getRangeVal () |
Returns the exact value in the range given the active parameter and the tweak value. More... | |
void | setValAsPercent (float val) |
Sets the value of the LumiverseFloat proportionally. | |
float | asPercent () |
Gets the value of the enum in terms of a percentage. More... | |
void | operator= (string name) |
void | operator= (const LumiverseEnum &val) |
virtual bool | isDefault () |
Returns true if the current value of the enumeration is equal to the default. | |
vector< string > | getVals () |
Gets a list of all the possible values the enumeration can take. More... | |
const map< string, int > & | getValsToStart () |
Returns a reference to the map of values to the start of their range. | |
const map< int, string > & | getStartToVals () |
Returns a reference to the map of range starts to values. | |
int | getHighestStartValue () |
Gets the highest start value for an enumeration option. More... | |
int | getLowestStartValue () |
Gets the lowest start value for an enumeration option. | |
Public Member Functions inherited from Lumiverse::LumiverseType | |
virtual | ~LumiverseType () |
Destroys the object. | |
Private Member Functions | |
void | init (map< string, int > keys, string active, Mode mode, string def, float tweak, int rangeMax, InterpolationMode interpMode) |
Initializes the enumeration. Called from constructors. More... | |
void | init (map< string, int > keys, string active, Mode mode, string def, float tweak, int rangeMax, InterpolationMode interpMode, map< int, string > vals) |
Intializes the enumeration. Copies over the values too if they already exist. More... | |
void | setTweakWithMode () |
Sets the tweak value based on the mode. | |
string | modeAsString () |
Returns the current mode as a string. More... | |
Mode | stringToMode (string input) |
Converts a string to a mode. More... | |
string | interpModeAsString () |
Returns the interpolation mode as a string. More... | |
InterpolationMode | stringToInterpMode (string input) |
Converts a string to an interpolation mode. More... | |
Private Attributes | |
string | m_active |
The active enumeration option. | |
string | m_default |
The default option for the enumeration. | |
map< string, int > | m_nameToStart |
Map of the name of the enumeration option to the start of the range. More... | |
map< int, string > | m_startToName |
Maps the start of a range to the name of the enumeration option. | |
Mode | m_mode |
Enumeration mode. | |
InterpolationMode | m_interpMode |
Interpolation mode. | |
float | m_tweak |
Tweak determines where in the range we are. More... | |
int | m_rangeMax |
Maximum value for the enumeration range. More... | |
mutex | m_enumMapMutex |
Protects the access of the m_nameToStart and m_startToName maps during assignment and read (can't modify the map during a read) | |
Defines an enumeration in Lumiverse.
Moving lights often have various parameters that are enumerated and encoded in a DMX range (ex. 10-19 on channel 6 = use gobo 1). This class allows specification of settings by name or number and also allows users to tweak the values in the range for controls that may use the range as a speed control. Comparison op overloads are located in the Lumiverse namespace. Note that arithmetic ops have for the most part not been implemented for LumiverseEnum since it doesn't make much sense to add two enumerations together.
Enumerations ranges are stored in a map, with the name of the enumeration option associated with the first value in the range. The side of the enumeration range is then just the difference between the first value and the next value.
This is a bit confusing, so let's have an example. Let's say we have a simple light that has an enumeration with 3 values. "Red" from 0-100, "Blue" from 101-200, and "Green" from 201-255. This enumeration would be stored in a LumiverseEnum like this: [{"Red", 0}, {"Blue", 101}, {"Green", 201}]
and m_rangeMax = 255
With the CENTER option selected, setting the value of the enum to "Red" would result in the numeric value 50. The tweak
adjusts the value inside of an option. So in this example, if you set the value of the enum to "Red" with tweak = 0.75, the numeric value would be 75.
Sets the interpolation mode when transitioning between two LumiverseEnums.
Enumerations on lighting devices can be tricky to deal with in transitions. This setting provides a way for LumiverseTypeUtils to do a linear (or other) interpolation between two enums. Default is SMOOTH_WITHIN_OPTION.
When you select an enumeration, mode determines where in the range the calculated value will fall.
Note that this is only used when a tweak value is not provided. For example, if setting this enumeration to a value between 10 and 19 means the light puts in a blue filter, FIRST will set the actual value of this enumeration to 10, CENTER will set it to 14.5, and LAST will set it to 19.
Enumerator | |
---|---|
FIRST |
Set value to start of range |
CENTER |
Set value to middle of the range (default) |
LAST |
Set value to end of range |
Lumiverse::LumiverseEnum::LumiverseEnum | ( | Mode | mode = CENTER , |
int | rangeMax = 255 , |
||
InterpolationMode | interpMode = SMOOTH_WITHIN_OPTION |
||
) |
Constructs an enumeration with nothing in it.
Not particularly useful.
mode | Default enumeration value selection mode |
rangeMax | Maximum numerical range this enumeration can generate values for. Generally this will be set to 255 since that's the maximum number of DMX channels. If something else comes along and still uses this kind of enumeration, it can be adjusted. |
interpMode | Interpolation mode |
Lumiverse::LumiverseEnum::LumiverseEnum | ( | map< string, int > | keys, |
Mode | mode = CENTER , |
||
int | rangeMax = 255 , |
||
string | def = "" , |
||
InterpolationMode | interpMode = SMOOTH_WITHIN_OPTION |
||
) |
Constructs an enumeration with the given keys and range start values.
More useful form of the default constructor.
keys | Map of enumeration options to the first value in their active range |
mode | Default enumeration value selection mode |
rangeMax | Maximum numerical range this enumeratino can generate values for |
def | Default enumeration option to go to when reset is called. If not set, defaults to first enumeration option in the keys map. |
interpMode | Interpolation mode |
Lumiverse::LumiverseEnum::LumiverseEnum | ( | map< string, int > | keys, |
string | mode, | ||
string | interpMode, | ||
int | rangeMax = 255 , |
||
string | def = "" |
||
) |
Constructs an enumeration with the given keys and range start values.
Pretty much the same as LumiverseEnum(map<string, int>, Mode, int, string, InterpolationMode) except that Mode and InterpolationMode must be explicitly specified as strings.
keys | Map of enumeration options to the first value in their active range |
mode | Default enumeration value selection mode as a string |
interpMode | Interpolation mode as a string |
rangeMax | Maximum numerical range this enumeratino can generate values for |
def | Default enumeration option to go to when reset is called. If not set, defaults to first enumeration option in the keys map. |
Lumiverse::LumiverseEnum::LumiverseEnum | ( | LumiverseEnum * | other | ) |
Copies an enumeration.
other | Pointer to the other enum to copy |
Lumiverse::LumiverseEnum::LumiverseEnum | ( | const LumiverseEnum & | other | ) |
Copies an enumeration.
other | The object to copy |
Lumiverse::LumiverseEnum::LumiverseEnum | ( | LumiverseType * | other | ) |
Copies a generic type.
Marginally useful. If other isn't actually a LumiverseEnum, the default constructor will be called, and you'll have an empty enumeration.
other | Pointer to the other object to copy |
void Lumiverse::LumiverseEnum::addVal | ( | string | name, |
int | start | ||
) |
Adds an option to the enumeration.
Will overwrite an existing set of values if it already exists.
name | Name of the option |
start | Starting value in the option's range |
float Lumiverse::LumiverseEnum::asPercent | ( | ) |
Gets the value of the enum in terms of a percentage.
Example: if the range of the enum is [0,255] and the current numeric value is 127, this returns .498
|
virtual |
Returns the current enumeration value as a string.
Returns in the format: Enumeration (tweak_val)
Implements Lumiverse::LumiverseType.
|
inline |
Gets the default value.
int Lumiverse::LumiverseEnum::getHighestStartValue | ( | ) |
Gets the highest start value for an enumeration option.
This should be a value less than m_rangeMax if the enumeration is formatted correctly.
|
inline |
Returns the interpolation mode.
|
inline |
Returns the mode.
float Lumiverse::LumiverseEnum::getRangeVal | ( | ) |
Returns the exact value in the range given the active parameter and the tweak value.
|
inline |
Gets the tweak value for the enumeration.
|
inlinevirtual |
Says that this object is an enum.
"enum"
Implements Lumiverse::LumiverseType.
|
inline |
Gets the current state of the enumeration.
vector< string > Lumiverse::LumiverseEnum::getVals | ( | ) |
Gets a list of all the possible values the enumeration can take.
This list is sorted by enumeration option start value.
|
private |
Initializes the enumeration. Called from constructors.
Parameters are pretty much the same here as in the constructor.
|
private |
Intializes the enumeration. Copies over the values too if they already exist.
Primarily used to copy data from one enum to another.
keys | Map of enumeration options to the first value in their active range |
active | Active option |
mode | Default enumeration value selection mode |
def | Default enumeration option to go to when reset is called. If not set, defaults to first |
tweak | Active tweak value |
rangeMax | Maximum numerical range this enumeratino can generate values for enumeration option in the keys map. |
interpMode | Interpolation mode as a string |
vals | Reverse map of first value in active range to name of enumeration option |
|
private |
Returns the interpolation mode as a string.
Primarily used for internal serialization
shared_ptr< LumiverseType > Lumiverse::LumiverseEnum::lerp | ( | LumiverseEnum * | rhs, |
float | t | ||
) |
Does a linear interpolation based on the interpolation mode.
The object this function is called on is treated as the left hand side. The interp mode for the left hand side takes precedence. If the enumerations don't have the same options, this function will have some weird behavior, but otherwise will do the interpolation according to the numeric values.
rhs | Initial value |
t | Value between 0 and 1. When t = 0 , this function returns the value of this object. When t = 1 , this function returns the value of rhs. |
|
private |
Returns the current mode as a string.
Primarily used for internal serialization.
void Lumiverse::LumiverseEnum::removeVal | ( | string | name | ) |
Removes an option from the enumeration.
Nothing bad happens if the option doesn't exist in the enumeration. It's technically still removed from the enumeration at the end of the function anyway.
name | Name of the option to remove. |
|
inline |
Sets the default value of the enumeration.
Note that this function doesn't check to see if the new default value actually exists. It should probably do that and will probably be updated in a new version soon.
name | New default option name |
|
inline |
Sets the interpolation mode.
mode | New interpoplation mode |
|
inline |
Sets the mode.
mode | Default value selection mode |
|
inline |
Sets the maximum numeric value this LumiverseEnum can take.
Setting this to a value below the highest valued option in the LumiverseEnum results in undefined behavior.
void Lumiverse::LumiverseEnum::setTweak | ( | float | tweak | ) |
Tweaks the value of the enum.
Shifts it proportionally in the active option's range.
tweak | Tweak value between 0 and 1 |
bool Lumiverse::LumiverseEnum::setVal | ( | string | name | ) |
Sets the value of the enumeration.
Sets the value to the specified option, using the active Mode of the enum to get the actual value.
name | Name of the option |
bool Lumiverse::LumiverseEnum::setVal | ( | string | name, |
float | tweak | ||
) |
Sets the value of the enumeration and the tweak value.
The tweak is a value between 0 and 1 that proportionally adjusts where in the option's range the value actually sits.
name | Name of the option |
tweak | Tweak value between 0 and 1. Clamped if value given outside of that range. |
bool Lumiverse::LumiverseEnum::setVal | ( | string | name, |
float | tweak, | ||
Mode | enumMode, | ||
InterpolationMode | interpMode | ||
) |
Sets the value of the enumeration and other options.
name | Name of the option |
tweaj | Tweak value between 0 and 1. |
enumMode | The Mode of the enumeration |
interpMode | Interpolation mode of the enumeration. |
bool Lumiverse::LumiverseEnum::setVal | ( | float | val | ) |
Sets the value of the enumeration numerically.
This will take a value and convert it to the proper enumeration option and tweak for the particular enum. If out of range, it will clamp.
val | Value to convert to an enumeration. Typically between 0 and 255. |
|
private |
Converts a string to an interpolation mode.
Primarily used for internal deserialization
input | String to convert |
|
private |
Converts a string to a mode.
Primarily used for internal deserialization
input | String to convert |
|
virtual |
Converts the type to a JSON object with the specified name.
Required for proper serialiaztion.
Implements Lumiverse::LumiverseType.
|
private |
Map of the name of the enumeration option to the start of the range.
The start of the range is typically stated as a DMX value (0-255)
|
private |
Maximum value for the enumeration range.
Typically this will be 255, but if someone comes out with a different protocol not limited by DMX this will change.
|
private |
Tweak determines where in the range we are.
Middle = 0.5 and the value can go from 0 to 1, with 0 being the front of the range, and 1 being the end. This value can be adjusted to get the exact value in the active option.