Lumiverse  2.5
A framework for creating lighting control applications
Public Types | Public Member Functions | Private Member Functions | Private Attributes | List of all members
Lumiverse::LumiverseEnum Class Reference

Defines an enumeration in Lumiverse. More...

#include <LumiverseEnum.h>

Inheritance diagram for Lumiverse::LumiverseEnum:
Inheritance graph
[legend]
Collaboration diagram for Lumiverse::LumiverseEnum:
Collaboration graph
[legend]

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< LumiverseTypelerp (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)
 

Detailed Description

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.

See also
Lumiverse, LumiverseType

Member Enumeration Documentation

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.

See also
lerp()
Enumerator
SNAP 

Snap to new value immediately (no interpolation)

SMOOTH_WITHIN_OPTION 

This mode will interpolate within a particular setting. For example, if you have a color wheel rotate option where values closer to 128 are slow, and closer to 255 are fast, this would interpolate the value (the tweak) while you stayed within this particular option, but snap between options.

SMOOTH 

Smoothly interpolate everything.

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

Constructor & Destructor Documentation

Lumiverse::LumiverseEnum::LumiverseEnum ( Mode  mode = CENTER,
int  rangeMax = 255,
InterpolationMode  interpMode = SMOOTH_WITHIN_OPTION 
)

Constructs an enumeration with nothing in it.

Not particularly useful.

Parameters
modeDefault enumeration value selection mode
rangeMaxMaximum 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.
interpModeInterpolation 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.

Parameters
keysMap of enumeration options to the first value in their active range
modeDefault enumeration value selection mode
rangeMaxMaximum numerical range this enumeratino can generate values for
defDefault enumeration option to go to when reset is called. If not set, defaults to first enumeration option in the keys map.
interpModeInterpolation 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.

Parameters
keysMap of enumeration options to the first value in their active range
modeDefault enumeration value selection mode as a string
interpModeInterpolation mode as a string
rangeMaxMaximum numerical range this enumeratino can generate values for
defDefault enumeration option to go to when reset is called. If not set, defaults to first enumeration option in the keys map.
See also
stringToMode(), stringToInterpMode()
Lumiverse::LumiverseEnum::LumiverseEnum ( LumiverseEnum other)

Copies an enumeration.

Parameters
otherPointer to the other enum to copy
Lumiverse::LumiverseEnum::LumiverseEnum ( const LumiverseEnum other)

Copies an enumeration.

Parameters
otherThe 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.

Parameters
otherPointer to the other object to copy

Member Function Documentation

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.

Parameters
nameName of the option
startStarting 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

string Lumiverse::LumiverseEnum::asString ( )
virtual

Returns the current enumeration value as a string.

Returns in the format: Enumeration (tweak_val)

Implements Lumiverse::LumiverseType.

string Lumiverse::LumiverseEnum::getDefault ( )
inline

Gets the default value.

Returns
Default option as a string
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.

Returns
Value of the key with the higest starting value. -1 if there are no keys currently in the enumeration.
InterpolationMode Lumiverse::LumiverseEnum::getInterpMode ( )
inline

Returns the interpolation mode.

Returns
Currently active interpolation mode
Mode Lumiverse::LumiverseEnum::getMode ( )
inline

Returns the mode.

Returns
Currently active value selection mode
float Lumiverse::LumiverseEnum::getRangeVal ( )

Returns the exact value in the range given the active parameter and the tweak value.

Returns
Numeric value of the enum.
float Lumiverse::LumiverseEnum::getTweak ( )
inline

Gets the tweak value for the enumeration.

Returns
The current tweak value
virtual string Lumiverse::LumiverseEnum::getTypeName ( )
inlinevirtual

Says that this object is an enum.

Returns
String containing "enum"

Implements Lumiverse::LumiverseType.

string Lumiverse::LumiverseEnum::getVal ( )
inline

Gets the current state of the enumeration.

Returns
Active enumeration option
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.

void Lumiverse::LumiverseEnum::init ( map< string, int >  keys,
string  active,
Mode  mode,
string  def,
float  tweak,
int  rangeMax,
InterpolationMode  interpMode 
)
private

Initializes the enumeration. Called from constructors.

Parameters are pretty much the same here as in the constructor.

See also
LumiverseEnum()
void Lumiverse::LumiverseEnum::init ( map< string, int >  keys,
string  active,
Mode  mode,
string  def,
float  tweak,
int  rangeMax,
InterpolationMode  interpMode,
map< int, string >  vals 
)
private

Intializes the enumeration. Copies over the values too if they already exist.

Primarily used to copy data from one enum to another.

Parameters
keysMap of enumeration options to the first value in their active range
activeActive option
modeDefault enumeration value selection mode
defDefault enumeration option to go to when reset is called. If not set, defaults to first
tweakActive tweak value
rangeMaxMaximum numerical range this enumeratino can generate values for enumeration option in the keys map.
interpModeInterpolation mode as a string
valsReverse map of first value in active range to name of enumeration option
string Lumiverse::LumiverseEnum::interpModeAsString ( )
private

Returns the interpolation mode as a string.

Primarily used for internal serialization

Returns
Interpolation Mode converted to a string
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.

Parameters
rhsInitial value
tValue 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.
Returns
New LumiverseEnum containing the result of the interpolation.
See also
setVal(float)
string Lumiverse::LumiverseEnum::modeAsString ( )
private

Returns the current mode as a string.

Primarily used for internal serialization.

Returns
Mode in string form
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.

Parameters
nameName of the option to remove.
void Lumiverse::LumiverseEnum::setDefault ( string  name)
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.

Parameters
nameNew default option name
void Lumiverse::LumiverseEnum::setInterpMode ( InterpolationMode  mode)
inline

Sets the interpolation mode.

Parameters
modeNew interpoplation mode
void Lumiverse::LumiverseEnum::setMode ( Mode  mode)
inline

Sets the mode.

Parameters
modeDefault value selection mode
void Lumiverse::LumiverseEnum::setRangeMax ( int  newMax)
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.

Parameters
tweakTweak 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.

Parameters
nameName of the option
Returns
True if option exists, false otherwise.
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.

Parameters
nameName of the option
tweakTweak value between 0 and 1. Clamped if value given outside of that range.
Returns
True if option exists, false otherwise.
bool Lumiverse::LumiverseEnum::setVal ( string  name,
float  tweak,
Mode  enumMode,
InterpolationMode  interpMode 
)

Sets the value of the enumeration and other options.

Parameters
nameName of the option
tweajTweak value between 0 and 1.
enumModeThe Mode of the enumeration
interpModeInterpolation 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.

Parameters
valValue to convert to an enumeration. Typically between 0 and 255.
LumiverseEnum::InterpolationMode Lumiverse::LumiverseEnum::stringToInterpMode ( string  input)
private

Converts a string to an interpolation mode.

Primarily used for internal deserialization

Parameters
inputString to convert
Returns
InterpolationMode corresponding to input string. Returns SMOOTH_WITHIN_OPTION if invalid string passed in.
LumiverseEnum::Mode Lumiverse::LumiverseEnum::stringToMode ( string  input)
private

Converts a string to a mode.

Primarily used for internal deserialization

Parameters
inputString to convert
Returns
Mode corresponding to input string. Returns CENTER if an invalid string is passed in.
JSONNode Lumiverse::LumiverseEnum::toJSON ( string  name)
virtual

Converts the type to a JSON object with the specified name.

Required for proper serialiaztion.

Implements Lumiverse::LumiverseType.

Member Data Documentation

map<string, int> Lumiverse::LumiverseEnum::m_nameToStart
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)

int Lumiverse::LumiverseEnum::m_rangeMax
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.

float Lumiverse::LumiverseEnum::m_tweak
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.


The documentation for this class was generated from the following files: