Lumiverse
2.5
A framework for creating lighting control applications
|
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... | |
LumiverseType * | getParam (string param) |
Returns a pointer to the raw LumiverseType data associated with a parameter. More... | |
LumiverseFloat * | getFloat (string param) |
Returns a pointer to the LumiverseFloat paramter. More... | |
LumiverseEnum * | getEnum (string param) |
Returns a pointer to a LumiverseEnum paramters. More... | |
LumiverseColor * | getColor (string param="color") |
Gets a pointer to a LumiverseColor parameter. More... | |
LumiverseOrientation * | getOri (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. | |
LumiverseFloat * | getIntensity () |
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... | |
FocusPalette * | getFocusPalette (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. | |
FocusPalette * | closestPalette () |
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, DeviceCallbackFunction > | m_onParameterChangedFunctions |
List of functions to run when a parameter is changed. Each function has an int id. More... | |
map< int, DeviceCallbackFunction > | m_onMetadataChangedFunctions |
List of functions to run when a metadata is changed. Each function has an int id. More... | |
map< string, FocusPalette > | m_fp |
List of focus palettes known by the device. | |
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.
typedef function<void(Device*)> Lumiverse::Device::DeviceCallbackFunction |
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.
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.
id | Unique identifier for the device. |
channel | Channel number for the device. Multiple devices can be part of the same channel. |
type | String identifying the type of fixture ("Source Four 26deg" for example). |
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.
id | Unique identifier for the device. |
data | JSONNode containing the device information. |
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.
func | The callback function. |
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.
func | The callback function. |
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.
param | Id of the target parameter |
source | Pointer to the data source |
void Lumiverse::Device::deleteMetadata | ( | string | key | ) |
Deletes the metadata entry for a given key.
key | Metadata key |
void Lumiverse::Device::deleteMetadataChangedCallback | ( | int | id | ) |
Deletes a registered callback for metadata change.
id | The id returned when the callback is registered |
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.
id | The id returned when the callback is registered |
|
inline |
Accessor for channel.
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.
param | Parameter name. Defaults to "color" assuming that most people will call the color parameter "color" in their devices. |
nullptr
is returned if the parameter does not exist. LumiverseEnum * Lumiverse::Device::getEnum | ( | string | param | ) |
Returns a pointer to a LumiverseEnum paramters.
Gives direct access to a enum paramters.
param | Paramter name |
nullptr
is returned if the paramter doesn't exist or is not an enum. LumiverseFloat * Lumiverse::Device::getFloat | ( | string | param | ) |
Returns a pointer to the LumiverseFloat paramter.
Gives direct access to a floating point paramter.
param | Parameter name |
nullptr
is returned if the parameter doesn't exist or is not a float. 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.
bool Lumiverse::Device::getMetadata | ( | string | key, |
string & | val | ||
) |
Retrieve metatata value for a given key.
key | Metadata key | |
[out] | val | Value of the metadata field if it exists. |
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.
key | Metadata key. |
""
otherwise. 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.
param | Parameter name |
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.
param | Parameter name | |
[out] | val | Output value of the parameter if it exists and is a float. |
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.
param | Parameter name |
nullptr
if parameter does not exist in the device. vector< string > Lumiverse::Device::getParamNames | ( | ) |
Get list of parameter names in the device.
|
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.
|
inline |
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.
|
private |
Takes parsed JSON data and makes a device.
data | JSON data to turn into a device. |
|
private |
Loads the parameters of the device from JSON data. Helper for loadJSON.
data | JSON node containing the parameters of the device. |
|
private |
Serializes the metadata to a JSON node.
size_t Lumiverse::Device::numParams | ( | ) |
Get the number of parameters in the device.
|
private |
Calls all the registered callbacks of metadata changed iterately.
|
private |
Calls all the registered callbacks of parameter changed iterately.
|
inline |
Override for stream operator.
Dumps the output of Device::toString() into the stream.
|
private |
Serializes the parameters into a JSON node.
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
.
param | Parameter name |
void Lumiverse::Device::reset | ( | ) |
Resets the values in the parameters to 0 (or equivalent default) Defaults are defined in the implementations of LumiverseType.
|
inline |
Assigns channel number.
newChan | New 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().
param | Parameter name. |
channel | Channel name. |
val | Channel value. |
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().
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().
|
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.
newId | New deivce id |
bool Lumiverse::Device::setMetadata | ( | string | key, |
string | val | ||
) |
Sets the metadata value for a given key.
key | Metadata key |
val | New value of the metadata field. |
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.
param | Parameter name |
val | object to assign to the parameter |
|
inline |
Sets a parameter to a floating point value.
|
inline |
Sets a parameter to an enumeration type.
|
inline |
Sets a parameter to a color value.
|
inline |
Sets a parameter to a orientation value.
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.
param | Parameter name |
val | Value to assign to the parameter |
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.
param | Parameter name |
val | Enumeration name |
val2 | The tweak value for the enumeration. See LumiverseEnum for details. |
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.
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.
param | Parameter name |
channel | Color channel name |
val | Value of the color channel |
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.
param | Parameter name. |
x | x coordinate |
y | y coordinate |
|
inline |
Assigns Device type.
newType | New type for the device. |
JSONNode Lumiverse::Device::toJSON | ( | ) |
Converts the device to a JSONNode.
string Lumiverse::Device::toString | ( | ) |
Converts the device data into a string.
|
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.
|
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.
|
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.
|
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.
|
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.