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::Device Class Reference

A Device in Lumiverse maintains information about a lighting device. More...

#include <Device.h>

Public Types

typedef function< void(Device *)> DeviceCallbackFunction
 

Public Member Functions

 Device (string id, unsigned int channel, string type)
 Default constructor. Every device needs an id, channel, and type. More...
 
 Device (string id, const JSONNode data)
 Constructs a device given a property formatted JSONNode. More...
 
 Device (const Device &other)
 Copies a Device.
 
 Device (Device *other)
 Copies a Device.
 
 Device (string id, Device *other)
 Copies a Device, but with a different ID.
 
 ~Device ()
 Destroys a device.
 
std::ostream & operator<< (std::ostream &str)
 Override for stream operator. More...
 
string getId ()
 Accessor for Device id. More...
 
unsigned int getChannel ()
 Accessor for channel. More...
 
void setChannel (unsigned int newChan)
 Assigns channel number. More...
 
string getType ()
 Accessor for Device type. More...
 
void setType (string newType)
 Assigns Device type. More...
 
template<class T >
T * getParam (string param)
 Templated parameter retrieval. More...
 
bool getParam (string param, float &val)
 Gets the value of a float parameter. More...
 
LumiverseTypegetParam (string param)
 Returns a pointer to the raw LumiverseType data associated with a parameter. More...
 
LumiverseFloatgetFloat (string param)
 Returns a pointer to the LumiverseFloat paramter. More...
 
LumiverseEnumgetEnum (string param)
 Returns a pointer to a LumiverseEnum paramters. More...
 
LumiverseColorgetColor (string param="color")
 Gets a pointer to a LumiverseColor parameter. More...
 
LumiverseOrientationgetOri (string param)
 Returns a pointer to a LumiverseOrientation.
 
bool setParam (string param, LumiverseType *val)
 Sets the value of a parameter. More...
 
bool setParam (string param, LumiverseFloat *val)
 Sets a parameter to a floating point value. More...
 
bool setParam (string param, LumiverseEnum *val)
 Sets a parameter to an enumeration type. More...
 
bool setParam (string param, LumiverseColor *val)
 Sets a parameter to a color value. More...
 
bool setParam (string param, LumiverseOrientation *val)
 Sets a parameter to a orientation value. More...
 
bool setParam (string param, float val)
 Sets the value of a LumiverseFloat or LumiverseOrientation parameter. More...
 
bool setParam (string param, string val, float val2=-1.0f)
 Sets the value of a LumiverseEnum parameter. More...
 
bool setParam (string param, string val, float val2, LumiverseEnum::Mode mode, LumiverseEnum::InterpolationMode interpMode)
 Fully specify the value of an enumeration. More...
 
bool setParam (string param, string channel, double val)
 Sets the value of a LumiverseColor parameter. More...
 
bool setParam (string param, double x, double y, double weight=1.0)
 Sets the value of a LumiverseColor parameter using LumiverseColor::setxy() More...
 
bool addFloatParam (string name, float val, float def, float max=1.0f, float min=0.0f)
 
bool addColorParam (string name, int m)
 
bool setColorRGBRaw (string param, double r, double g, double b, double weight=1.0)
 Sets the value of a LumiverseColor parameter. More...
 
bool setColorRGB (string param, double r, double g, double b, double weight=1.0, RGBColorSpace cs=sRGB)
 Sets the value of a LumiverseColor parameter. More...
 
bool setColorHSV (string param, double H, double S, double V, double weight=1.0)
 Sets the value of a LumiverseColor parameter using HSV.
 
bool setColorWeight (string param, double weight)
 Sets the value of a LumiverseColor.
 
bool setRGBRaw (double r, double g, double b, double weight=1.0)
 Proxy for setColorRGBRaw assuming the existence of a "color" parameter.
 
bool setIntensity (float val)
 Proxy for setParam("intensity", val). Assumes the existence of an "intensity" parameter.
 
LumiverseFloatgetIntensity ()
 Returns the intensity parameter if it exists.
 
bool setColorChannel (string param, string channel, double val)
 Sets the value of a LumiverseColor parameter. More...
 
void copyParamByValue (string param, LumiverseType *source)
 Copies the data from source into target parameter. More...
 
bool paramExists (string param)
 Checks for the existance of a parameter. More...
 
size_t numParams ()
 Get the number of parameters in the device. More...
 
vector< string > getParamNames ()
 Get list of parameter names in the device. More...
 
bool metadataExists (string key)
 Returns true if a specified metadata key exists for this device.
 
bool getMetadata (string key, string &val)
 Retrieve metatata value for a given key. More...
 
string getMetadata (string key)
 Retrieves metatada value for a given key. Will return "" if a key doesn't exist. More...
 
bool setMetadata (string key, string val)
 Sets the metadata value for a given key. More...
 
void deleteMetadata (string key)
 Deletes the metadata entry for a given key. More...
 
void deleteParameter (string key)
 Deletes a parameter from the device. More...
 
void clearMetadataValues ()
 Erases all values in the metadata fields. More...
 
void clearAllMetadata ()
 Deletes the entire metadata map. More...
 
size_t numMetadataKeys ()
 Get the number of metadata keys in the Device.
 
vector< string > getMetadataKeyNames ()
 Gets list of metadata keys the device currently has values for.
 
void reset ()
 Resets the values in the parameters to 0 (or equivalent default) Defaults are defined in the implementations of LumiverseType. More...
 
string toString ()
 Converts the device data into a string. More...
 
JSONNode toJSON ()
 Converts the device to a JSONNode. More...
 
unordered_map< string, LumiverseType * > & getRawParameters ()
 Gets the raw map of parameters to data. More...
 
int addParameterChangedCallback (DeviceCallbackFunction func)
 Registers a callback function for parameter changed event. More...
 
int addMetadataChangedCallback (DeviceCallbackFunction func)
 Registers a callback function for metadata changed event. More...
 
void deleteParameterChangedCallback (int id)
 Deletes a registered callback for parameter change. More...
 
void deleteMetadataChangedCallback (int id)
 Deletes a registered callback for metadata change. More...
 
bool isIdentical (Device *d)
 Returns true if the device is identical to the given device. More...
 
Eigen::Vector3d getGelColor ()
 Gets the color for this device if it has a gel assigned to it. More...
 
void addFocusPalette (FocusPalette fp)
 Adds a new focus palette to the device. More...
 
FocusPalettegetFocusPalette (string name)
 Returns a pointer to the specified focus palette. This will be nullptr if specified palette doesn't exist.
 
void deleteFocusPalette (string name)
 Deletes a focus palette.
 
void setFocusPalette (string name)
 Sets device parameters to the specified focus palette.
 
vector< string > getFocusPaletteNames ()
 Gets a list of focus palette names.
 
FocusPaletteclosestPalette ()
 Gets the closest palette to the current parameters of the light. More...
 

Private Member Functions

void setId (string newId)
 Sets the id for the device. More...
 
void loadJSON (const JSONNode data)
 Takes parsed JSON data and makes a device. More...
 
void loadParams (const JSONNode data)
 Loads the parameters of the device from JSON data. Helper for loadJSON. More...
 
JSONNode parametersToJSON ()
 Serializes the parameters into a JSON node. More...
 
JSONNode metadataToJSON ()
 Serializes the metadata to a JSON node. More...
 
void onParameterChanged ()
 Calls all the registered callbacks of parameter changed iterately. More...
 
void onMetadataChanged ()
 Calls all the registered callbacks of metadata changed iterately. More...
 

Private Attributes

string m_id
 Unique identifier for the device. More...
 
unsigned int m_channel
 Channel number for the fixture. Does not have to be unique.
 
string m_type
 Device type name. "Source Four ERS" for example.
 
unordered_map< string, LumiverseType * > m_parameters
 Map for time-varying parameters. More...
 
map< string, string > m_metadata
 Map for program-side information. More...
 
map< int, DeviceCallbackFunctionm_onParameterChangedFunctions
 List of functions to run when a parameter is changed. Each function has an int id. More...
 
map< int, DeviceCallbackFunctionm_onMetadataChangedFunctions
 List of functions to run when a metadata is changed. Each function has an int id. More...
 
map< string, FocusPalettem_fp
 List of focus palettes known by the device.
 

Detailed Description

A Device in Lumiverse maintains information about a lighting device.

This class is meant to hold information about different parameters in a Lumiverse friendly way. Conversion to network values happens in a different class to separate the abstract representation of a device from the practical network control details.

Member Typedef Documentation

Indicates the function signature for parameter and metadata callbacks. Currently a device has to pass in "this" pointer. It seems to be other way to access fields inside Device class. This typedef makes it easier to change signature.

Constructor & Destructor Documentation

Lumiverse::Device::Device ( string  id,
unsigned int  channel,
string  type 
)

Default constructor. Every device needs an id, channel, and type.

May in the future pull default parameter map from a database of known fixture types.

Parameters
idUnique identifier for the device.
channelChannel number for the device. Multiple devices can be part of the same channel.
typeString identifying the type of fixture ("Source Four 26deg" for example).
See also
Device(string, const JSONNode), ~Device()
Lumiverse::Device::Device ( string  id,
const JSONNode  data 
)

Constructs a device given a property formatted JSONNode.

Primarily used to load data from a Lumiverse Rig file.

Parameters
idUnique identifier for the device.
dataJSONNode containing the device information.
See also
Rig, Device(string, unsigned int, string), ~Device()

Member Function Documentation

bool Lumiverse::Device::addColorParam ( string  name,
int  m 
)

\ brief Adds a color parameter with the specified name to the Device

bool Lumiverse::Device::addFloatParam ( string  name,
float  val,
float  def,
float  max = 1.0f,
float  min = 0.0f 
)

\ brief Adds a float parameter with the specified name to the Device

void Lumiverse::Device::addFocusPalette ( FocusPalette  fp)

Adds a new focus palette to the device.

This function overwrites existing palettes.

int Lumiverse::Device::addMetadataChangedCallback ( DeviceCallbackFunction  func)

Registers a callback function for metadata changed event.

All registered functions would be called when a metadata is changed by Device::setMetadata, Device::clearMetadataValues, Device::clearAllMetadata, and Device::reset.

Parameters
funcThe callback function.
Returns
The int id for the registered function.
See also
addParameterChangedCallback(DeviceCallbackFunction func)
int Lumiverse::Device::addParameterChangedCallback ( DeviceCallbackFunction  func)

Registers a callback function for parameter changed event.

All registered functions would be called when a parameter is changed by Device::setParam and Device::reset function.

Parameters
funcThe callback function.
Returns
The int id for the registered function.
See also
addMetadataChangedCallback(DeviceCallbackFunction func)
void Lumiverse::Device::clearAllMetadata ( )

Deletes the entire metadata map.

Empties everything in the metadata hash: keys and values. All gone.

void Lumiverse::Device::clearMetadataValues ( )

Erases all values in the metadata fields.

Resets metadata values to "" but leaves the keys intact.

FocusPalette * Lumiverse::Device::closestPalette ( )

Gets the closest palette to the current parameters of the light.

Specifically, takes the palette with the smallest distance from current parameter values. Note that this is not the same as matching the closest palette in 3D space.

void Lumiverse::Device::copyParamByValue ( string  param,
LumiverseType source 
)

Copies the data from source into target parameter.

Parameters
paramId of the target parameter
sourcePointer to the data source
void Lumiverse::Device::deleteMetadata ( string  key)

Deletes the metadata entry for a given key.

Parameters
keyMetadata key
void Lumiverse::Device::deleteMetadataChangedCallback ( int  id)

Deletes a registered callback for metadata change.

Parameters
idThe id returned when the callback is registered
See also
addMetadataChangedCallback(DeviceCallbackFunction func)
void Lumiverse::Device::deleteParameter ( string  key)

Deletes a parameter from the device.

Be careful when calling this while the Rig is active.

void Lumiverse::Device::deleteParameterChangedCallback ( int  id)

Deletes a registered callback for parameter change.

Parameters
idThe id returned when the callback is registered
See also
addParameterChangedCallback(DeviceCallbackFunction func)
unsigned int Lumiverse::Device::getChannel ( )
inline

Accessor for channel.

Returns
The Device's channel number
LumiverseColor * Lumiverse::Device::getColor ( string  param = "color")

Gets a pointer to a LumiverseColor parameter.

Gives direct access to a color parameter. Probably the easiest way to modify a color for a device.

Parameters
paramParameter name. Defaults to "color" assuming that most people will call the color parameter "color" in their devices.
Returns
Pointer to LumiverseColor object associated with parameter. nullptr is returned if the parameter does not exist.
See also
LumiverseColor, LumiverseType
LumiverseEnum * Lumiverse::Device::getEnum ( string  param)

Returns a pointer to a LumiverseEnum paramters.

Gives direct access to a enum paramters.

Parameters
paramParamter name
Returns
Pointer to the LumiverseEnum object associated with the parameter. nullptr is returned if the paramter doesn't exist or is not an enum.
See also
LumiverseEnum, LumiverseType
LumiverseFloat * Lumiverse::Device::getFloat ( string  param)

Returns a pointer to the LumiverseFloat paramter.

Gives direct access to a floating point paramter.

Parameters
paramParameter name
Returns
Pointer to the LumiverseFloat object associated with the paramteter. nullptr is returned if the parameter doesn't exist or is not a float.
See also
LumiverseFloat, LumiverseType
Eigen::Vector3d Lumiverse::Device::getGelColor ( )

Gets the color for this device if it has a gel assigned to it.

Note that this function should only be used for devices that are unable to change color with a LumiverseColor paramter.

Returns
The Y-normalized XYZ color of the device based on the gel and intensity.
string Lumiverse::Device::getId ( )
inline

Accessor for Device id.

Returns
The Device's id
bool Lumiverse::Device::getMetadata ( string  key,
string &  val 
)

Retrieve metatata value for a given key.

Parameters
keyMetadata key
[out]valValue of the metadata field if it exists.
Returns
False if no key exists. True and the value in val if it does exist.
string Lumiverse::Device::getMetadata ( string  key)

Retrieves metatada value for a given key. Will return "" if a key doesn't exist.

Parameters
keyMetadata key.
Returns
The value associated with the key or "" otherwise.
template<class T >
T * Lumiverse::Device::getParam ( string  param)

Templated parameter retrieval.

Returns a pointer of the specified class, or nullptr if the specified parameter does not exist.

Parameters
paramParameter name
Returns
Pointer of type T
bool Lumiverse::Device::getParam ( string  param,
float &  val 
)

Gets the value of a float parameter.

This function only returns true if the parameter exists, and if the parameter is a LumiverseFloat. If successful, the value will be copied to val.

Parameters
paramParameter name
[out]valOutput value of the parameter if it exists and is a float.
Returns
False if no parameter with the given name exists, true with the parameter value in val if successful.
See also
getParam(string), LumiverseType, LumiverseFloat
LumiverseType * Lumiverse::Device::getParam ( string  param)

Returns a pointer to the raw LumiverseType data associated with a parameter.

This function gives you direct access to the object stored in the Device. Modifying the data in the returned pointer will propagate throughout the Rig.

Parameters
paramParameter name
Returns
Pointer to LumiverseType object associated with the paramater. nullptr if parameter does not exist in the device.
See also
getParam(string, float&), LumiverseType, LumiverseFloat
vector< string > Lumiverse::Device::getParamNames ( )

Get list of parameter names in the device.

Returns
List of parameters in the device.
unordered_map<string, LumiverseType*>& Lumiverse::Device::getRawParameters ( )
inline

Gets the raw map of parameters to data.

This function is intended to provide the collection of parameters for a calling function to iterate though. You may modify the data contained by the map in a calling function.

Returns
Reference to the map of parameter data.
string Lumiverse::Device::getType ( )
inline

Accessor for Device type.

Returns
The Device's type as a string
bool Lumiverse::Device::isIdentical ( Device d)

Returns true if the device is identical to the given device.

Identical means that the parameters are all the same, the metadata is all the same, and the other properties of the device are the same.

void Lumiverse::Device::loadJSON ( const JSONNode  data)
private

Takes parsed JSON data and makes a device.

Parameters
dataJSON data to turn into a device.
void Lumiverse::Device::loadParams ( const JSONNode  data)
private

Loads the parameters of the device from JSON data. Helper for loadJSON.

Parameters
dataJSON node containing the parameters of the device.
See also
loadJSON()
JSONNode Lumiverse::Device::metadataToJSON ( )
private

Serializes the metadata to a JSON node.

Returns
JSONNode representation of the metadata
See also
toJSON()
size_t Lumiverse::Device::numParams ( )

Get the number of parameters in the device.

Returns
Number of parameters in the device.
void Lumiverse::Device::onMetadataChanged ( )
private

Calls all the registered callbacks of metadata changed iterately.

See also
onParameterChanged()
void Lumiverse::Device::onParameterChanged ( )
private

Calls all the registered callbacks of parameter changed iterately.

See also
onMetadataChanged()
std::ostream& Lumiverse::Device::operator<< ( std::ostream &  str)
inline

Override for stream operator.

Dumps the output of Device::toString() into the stream.

See also
toString()
JSONNode Lumiverse::Device::parametersToJSON ( )
private

Serializes the parameters into a JSON node.

Returns
JSONNode representation of the parameters
See also
toJSON()
bool Lumiverse::Device::paramExists ( string  param)

Checks for the existance of a parameter.

Existance is defined by the parameter map containing a value for the key param.

Parameters
paramParameter name
Returns
True if the parameter exists.
void Lumiverse::Device::reset ( )

Resets the values in the parameters to 0 (or equivalent default) Defaults are defined in the implementations of LumiverseType.

See also
LumiverseType
void Lumiverse::Device::setChannel ( unsigned int  newChan)
inline

Assigns channel number.

Parameters
newChanNew channel number for the device
bool Lumiverse::Device::setColorChannel ( string  param,
string  channel,
double  val 
)

Sets the value of a LumiverseColor parameter.

Does not create a new parameter if they key doesn't exist. Proxy for LumiverseColor::setColorChannel().

Parameters
paramParameter name.
channelChannel name.
valChannel value.
Returns
true on success, false on failure
See also
LumiverseColor::setColorChannel(), LumiverseColor, LumiverseType
bool Lumiverse::Device::setColorRGB ( string  param,
double  r,
double  g,
double  b,
double  weight = 1.0,
RGBColorSpace  cs = sRGB 
)

Sets the value of a LumiverseColor parameter.

Proxy for LumiverseColor::setRGB().

Returns
False if parameter changed does not exist prior to set.
See also
LumiverseColor::setRGB(), LumiverseColor, LumiverseType
bool Lumiverse::Device::setColorRGBRaw ( string  param,
double  r,
double  g,
double  b,
double  weight = 1.0 
)

Sets the value of a LumiverseColor parameter.

Does not create a new parameter if the key doesn't exist. Proxy for LumiverseColor::setRGBRaw().

Returns
true on success, false on failure
See also
LumiverseColor::setRGBRaw(), LumiverseColor, LumiverseType
void Lumiverse::Device::setId ( string  newId)
inlineprivate

Sets the id for the device.

Note that this is private because changing the unique ID after creation can lead to a number of unintended side effects (DMX patch doesn't work, Rig can't find the device, other indexes may fail). This is a little annoying, but in the big scheme of devices and rigs, the ID shouldn't change after initial creation. If the user needs a different display name, the metadata fields say hi. In ACN terms, this would be the CID (if I remember this right), which is unique and immutable for each device). Making this function public would require some additional checks in the Rig to make sure the change propagates correctly.

Parameters
newIdNew deivce id
bool Lumiverse::Device::setMetadata ( string  key,
string  val 
)

Sets the metadata value for a given key.

Parameters
keyMetadata key
valNew value of the metadata field.
Returns
False if metadata key does not exist prior to set, true otherwise.
bool Lumiverse::Device::setParam ( string  param,
LumiverseType val 
)

Sets the value of a parameter.

Can set arbitrary data with this version of the function. When you pass a LumiverseType* into a Device with this function, the memory is now owned by the Device, which will attempt to free it when it's destroyed. For this reason, you should not use heap-allocated variables with this function. This function will create new parameters if the specified key doesn't exist.

Parameters
paramParameter name
valobject to assign to the parameter
Returns
False if the parameter does not exist prior to set. True otherwise.
See also
LumiverseType
bool Lumiverse::Device::setParam ( string  param,
LumiverseFloat val 
)
inline

Sets a parameter to a floating point value.

See also
setParam(string, LumiverseType*)
bool Lumiverse::Device::setParam ( string  param,
LumiverseEnum val 
)
inline

Sets a parameter to an enumeration type.

See also
setParam(string, LumiverseType*)
bool Lumiverse::Device::setParam ( string  param,
LumiverseColor val 
)
inline

Sets a parameter to a color value.

See also
setParam(string, LumiverseType*)
bool Lumiverse::Device::setParam ( string  param,
LumiverseOrientation val 
)
inline

Sets a parameter to a orientation value.

See also
setParam(string, LumiverseType*)
bool Lumiverse::Device::setParam ( string  param,
float  val 
)

Sets the value of a LumiverseFloat or LumiverseOrientation parameter.

This function will not create a new parameter if the key doesn't exist. Use of this function is reserved specifically for floating point valued parameters. It is up to the caller to insure that the parameter is actually a LumiverseFloat, however messing that up won't kill the program.

Parameters
paramParameter name
valValue to assign to the parameter
Returns
true on success, false on failure.
See also
LumiverseType, LumiverseFloat, LumiverseOrientation
bool Lumiverse::Device::setParam ( string  param,
string  val,
float  val2 = -1.0f 
)

Sets the value of a LumiverseEnum parameter.

This function will not create a new parameter if the key doesn't exist. If val2 is not set, the tweak value isn't passed to the enumeration, allowing it to do default behavior.

Parameters
paramParameter name
valEnumeration name
val2The tweak value for the enumeration. See LumiverseEnum for details.
Returns
true on success, false on failure.
See also
LumiverseType, LumiverseEnum
bool Lumiverse::Device::setParam ( string  param,
string  val,
float  val2,
LumiverseEnum::Mode  mode,
LumiverseEnum::InterpolationMode  interpMode 
)

Fully specify the value of an enumeration.

This function will not create a new parameter if the key doesn't exist.

Returns
true on success, false on failure.
See also
LumiverseEnum
bool Lumiverse::Device::setParam ( string  param,
string  channel,
double  val 
)

Sets the value of a LumiverseColor parameter.

Does not create a new parameter if the key doesn't exist.

Parameters
paramParameter name
channelColor channel name
valValue of the color channel
Returns
true on success, false on failure.
See also
LumiverseColor, LumiverseType
bool Lumiverse::Device::setParam ( string  param,
double  x,
double  y,
double  weight = 1.0 
)

Sets the value of a LumiverseColor parameter using LumiverseColor::setxy()

Does not create a new parameter if the key doesn't exist. x and y are chromaticity coordinates in the xyY color space.

Parameters
paramParameter name.
xx coordinate
yy coordinate
Returns
true on success, false on failure
See also
LumiverseColor, LumiverseType, setParam(string, string, double)
void Lumiverse::Device::setType ( string  newType)
inline

Assigns Device type.

Parameters
newTypeNew type for the device.
JSONNode Lumiverse::Device::toJSON ( )

Converts the device to a JSONNode.

Returns
JSONNode representing the Device. Can be written to file.
string Lumiverse::Device::toString ( )

Converts the device data into a string.

Returns
JSON representation of the device formatted into a string.

Member Data Documentation

string Lumiverse::Device::m_id
private

Unique identifier for the device.

Note that while you can use any characters you want in this, you really shouldn't use special characters such as #$%^=()[]/{} etc.

map<string, string> Lumiverse::Device::m_metadata
private

Map for program-side information.

This data can be anything you want. The core system uses it to add search filters and automatic device grouping. Any sort of data can be stored in it, assuming it can be serialized to a string.

map<int, DeviceCallbackFunction> Lumiverse::Device::m_onMetadataChangedFunctions
private

List of functions to run when a metadata is changed. Each function has an int id.

Currently a device have to pass in "this" pointer. It seems to be other way to access fields inside Device class. This function would inform instances which need to respond to the update.

map<int, DeviceCallbackFunction> Lumiverse::Device::m_onParameterChangedFunctions
private

List of functions to run when a parameter is changed. Each function has an int id.

Currently a device have to pass in "this" pointer. It seems to be other way to access fields inside Device class. This function would inform instances which need to respond to the update.

unordered_map<string, LumiverseType*> Lumiverse::Device::m_parameters
private

Map for time-varying parameters.

These parameters correspond to network-controllable functions of the lighting fixtures. If you can't control it over DMX, Ethernet, or other protocol, it's not a parameter.


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