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

The Rig contains information about the state of the lighting system. More...

#include <Rig.h>

Public Member Functions

 Rig ()
 Makes an empty rig. More...
 
 Rig (string filename)
 Initialize Rig from JSON file. More...
 
 ~Rig ()
 Destroys and frees all objects in the rig. More...
 
void init ()
 Initializes the rig. More...
 
void run ()
 Runs the update loop that sends updates to the network. More...
 
void stop ()
 Stops the update loop. More...
 
bool load (string filename)
 Loads a file into an existing rig. More...
 
void addDevice (Device *device)
 Adds a device to the Rig. More...
 
DevicegetDevice (string id)
 Gets a device from the rig. More...
 
void deleteDevice (string id)
 Removes the device with specified id from the rig. Also deletes it. More...
 
void addPatch (string id, Patch *patch)
 Adds a Patch to the rig. More...
 
PatchgetPatch (string id)
 Gets a patch from the rig. More...
 
const map< string, Patch * > & getPatches ()
 Returns the map of ID to Patch held by the Rig.
 
DMXPatchgetPatchAsDMXPatch (string id)
 Gets a patch from a rig and treats it as a DMXPatch. More...
 
void deletePatch (string id)
 Deletes an entire patch from the rig. More...
 
void setRefreshRate (unsigned int rate)
 Sets the refresh rate for the update loop in cycles / second. More...
 
unsigned int getRefreshRate ()
 Gets the refresh rate for the update loop. More...
 
Deviceoperator[] (string id)
 Shorthand for getDevice(string) More...
 
DeviceSet select (string q)
 Gets a DeviceSet based on a query string. More...
 
DeviceSet operator[] (unsigned int channel)
 Shorthand for getChannel(unsigned int) More...
 
DeviceSet getAllDevices ()
 Returns a set consisting of all devices in the rig. More...
 
DeviceSet getChannel (unsigned int channel)
 Gets all the devices in a channel. More...
 
DeviceSet getChannel (unsigned int lower, unsigned int upper)
 Gets a range of channels. More...
 
DeviceSet getDevices (string key, string val, bool isEqual)
 Gets devices by metadata info. More...
 
set< string > getAllUsedParams ()
 Gets a set of all the parameters used by the devices. More...
 
const set< Device * > & getDeviceRaw ()
 Gets the raw list of devices. More...
 
bool save (string filename, bool overwrite=true)
 Writes the rig out to a JSON file. More...
 
JSONNode toJSON ()
 Gets the JSON data for the rig. More...
 
bool addFunction (int pid, function< void()> func)
 Adds a function to the additional functions list. More...
 
bool removeFunction (int pid)
 Removes a function from the additional functions list. More...
 
void update ()
 Pushes data over the network. More...
 
void updateOnce ()
 Forces an update to happen when this function is called. More...
 
PatchgetSimulationPatch (string type)
 Get a simulation patch. More...
 
void setAllDevices (map< string, Device * > devices)
 Updates the parameters of the devices stored in the specified map. More...
 
size_t getNumDevices ()
 Returns the number of devices in the Rig.
 
void resetDevices ()
 Resets all devices in the rig to defaults.
 
bool isSlow ()
 Returns true if the Rig is running slowly.
 
set< string > getMetadataValues (string key)
 Returns a set containing all of the unique values for a metadata key. More...
 

Static Public Attributes

static map< string, patchParseFunc > patchParsers = {}
 Map containing functions to parse non-default patch types. More...
 

Private Member Functions

void loadJSON (JSONNode root)
 Loads the rig info from the parsed JSON data. More...
 
void loadDevices (JSONNode root)
 Loads the devices in the JSON file. More...
 
void loadPatches (JSONNode root)
 Load patches in the JSON file. More...
 
void reset ()
 Empties all the data from the rig.
 

Private Attributes

thread * m_updateLoop
 Thread that runs the update loop.
 
bool m_running
 Indicates the status of the update loop. More...
 
unsigned int m_refreshRate
 Sets the speed of the run loop in cycles/second. Default is 40. More...
 
float m_loopTime
 Amount of time an update loop can take in s. More...
 
set< Device * > m_devices
 Raw list of devices for sending to the Patch->update function. More...
 
map< string, Patch * > m_patches
 Maps Patch id to at Patch object. More...
 
map< string, Device * > m_devicesById
 Devices mapped by their device ID.
 
multimap< unsigned int, Device * > m_devicesByChannel
 Devices mapped by channel number.
 
map< int, function< void()> > m_updateFunctions
 List of functions to run at the end of the update loop. More...
 
bool m_slow
 Incidates if the Rig is updating slowly.
 

Friends

class DeviceSet
 

Detailed Description

The Rig contains information about the state of the lighting system.

A Rig is responsible for maintaining a list of all devices in the system, and for relaying changes to Lumiverse Device objects to the corresponding network interface. Rigs send Devices to a Patch, which then converts the Lumiverse data to a format that can be understood by the lights on the network.

Constructor & Destructor Documentation

Lumiverse::Rig::Rig ( )

Makes an empty rig.

See also
Rig(string), init()
Lumiverse::Rig::Rig ( string  filename)

Initialize Rig from JSON file.

This function will initialize Devices and Patches by calling functions in the appropriate class.

Parameters
Pathto file
See also
Rig(), loadJSON(), loadDevices(), loadPatches(), init()
Lumiverse::Rig::~Rig ( )

Destroys and frees all objects in the rig.

Once this is called all resources used by this class are free. Do not attempt to access a Device from a destroyed Rig as the Rig will destroy all objects that it manages.

Member Function Documentation

void Lumiverse::Rig::addDevice ( Device device)

Adds a device to the Rig.

Device memory is managed by the Rig. User should allocate memory, and the Rig is responsible for freeing it at the end.

Parameters
deviceDevice to add to the Rig.
bool Lumiverse::Rig::addFunction ( int  pid,
function< void()>  func 
)

Adds a function to the additional functions list.

The added function will be updated before the patch is updated as part of Rig::update(). The update loop will be stopped during the modification of the function list.

Parameters
pidID to assign to the function
funcFunction to execute
See also
m_updateFunctions
Returns
False if a function with specified pid already exists. True on success.
void Lumiverse::Rig::addPatch ( string  id,
Patch patch 
)

Adds a Patch to the rig.

User is responsible for allocating memory for the patch, Rig is responsible for freeing an allocated patch. Expects the patch to be configured before sending it to the rig. Not that it can't be edited later, but the rig only knows what you tell it.

Parameters
idIdentifier for the Patch. Used to retrieve patches from the Rig.
patchPointer to the patch.
See also
Patch
void Lumiverse::Rig::deleteDevice ( string  id)

Removes the device with specified id from the rig. Also deletes it.

This operation calls the device destructor too, so just be sure you actually want to completely get rid of a device before calling this. If you need to save the Device for some reason, get it with getDevice() first.

See also
getDevice()
void Lumiverse::Rig::deletePatch ( string  id)

Deletes an entire patch from the rig.

Memory is freed after delete. If you need to save it for some reason, get it with getPatch() first.

Parameters
Patchid
See also
getPatch()
DeviceSet Lumiverse::Rig::getAllDevices ( )

Returns a set consisting of all devices in the rig.

Returns
DeviceSet with all the Devices in it.
set< string > Lumiverse::Rig::getAllUsedParams ( )

Gets a set of all the parameters used by the devices.

Returned parameter names are not guaranteed to be in any particular order. Caller may choose to sort or arrange the parameter names as needed.

Returns
Set of strings. If a device uses a parameter in the rig, the name of that parameter will be returned in this set.
DeviceSet Lumiverse::Rig::getChannel ( unsigned int  channel)

Gets all the devices in a channel.

Parameters
channelChannel to retrieve
Returns
DeviceSet containing the specified devices
See also
DeviceSet::add(unsigned int)
DeviceSet Lumiverse::Rig::getChannel ( unsigned int  lower,
unsigned int  upper 
)

Gets a range of channels.

Parameters
lowerFirst channel to get (inclusive)
upperLast channel to get (inclusive)
Returns
DeviceSet containing the specified devices
See also
DeviceSet::add(unsigned int, unsigned int)
Device * Lumiverse::Rig::getDevice ( string  id)

Gets a device from the rig.

Return value can be modified to change the state of the device in the rig.

Parameters
idDevice id.
Returns
Pointer to the requested Device. If the device doesn't exist in the rig, a nullptr will be returned.
const set<Device *>& Lumiverse::Rig::getDeviceRaw ( )
inline

Gets the raw list of devices.

Users shouldn't modify the set of devices through this method, but may read the data and modify device parameters.

Returns
Set of Devices maintained by this Rig
DeviceSet Lumiverse::Rig::getDevices ( string  key,
string  val,
bool  isEqual 
)

Gets devices by metadata info.

Parameters
keyMetadata key
valValue to check
isEqualIf true, returns all devices that have data equal to val. If false, returns all devices that have data not equal to val.
Returns
DeviceSet containing the specified devices.
See also
DeviceSet::add(string, string, bool)
set< string > Lumiverse::Rig::getMetadataValues ( string  key)

Returns a set containing all of the unique values for a metadata key.

Parameters
keyMetadata key to get values for
Patch * Lumiverse::Rig::getPatch ( string  id)

Gets a patch from the rig.

Returns
Pointer to the requested patch. Returns a nullptr if patch with specified ID doesn't exist.
See also
Patch
DMXPatch* Lumiverse::Rig::getPatchAsDMXPatch ( string  id)
inline

Gets a patch from a rig and treats it as a DMXPatch.

Use carefully. The rig does not guarantee that the requested patch is actually a DMXPatch.

Returns
Pointer to the requested patch casted to a DMXPatch.\
See also
DMXPatch, Patch
unsigned int Lumiverse::Rig::getRefreshRate ( )
inline

Gets the refresh rate for the update loop.

Returns
Refresh rate in cycles/second
Patch * Lumiverse::Rig::getSimulationPatch ( string  type)

Get a simulation patch.

Checks against all the registered patches and returns the first simulation patch found.

Parameters
typeType name to distinguish different Simulation Patch.
Returns
A pointer to a simulation patch (the current implementation is the ArnoldPatch).
See also
Patch
void Lumiverse::Rig::init ( )

Initializes the rig.

Called after all patching has been done and configuration settings have been selected.

See also
Rig(), Rig(string)
bool Lumiverse::Rig::load ( string  filename)

Loads a file into an existing rig.

All existing devices and patches will be deleted and replaced by the contents of the specified file.

Returns
false if an error occurs, true if loaded successfully
void Lumiverse::Rig::loadDevices ( JSONNode  root)
private

Loads the devices in the JSON file.

Parameters
rootJSONNode containing the Devices in the Rig.
See also
loadJSON()
void Lumiverse::Rig::loadJSON ( JSONNode  root)
private

Loads the rig info from the parsed JSON data.

Parameters
rootJSONNode containing all Rig data.
See also
toJSON(), save(), loadDevices(), loadPatches()
void Lumiverse::Rig::loadPatches ( JSONNode  root)
private

Load patches in the JSON file.

Parameters
rootJSONNode containing the Patches in the Rig.
See also
loadJSON()
Device * Lumiverse::Rig::operator[] ( string  id)

Shorthand for getDevice(string)

Returns
Pointer to requested Device.
See also
getDevice()
DeviceSet Lumiverse::Rig::operator[] ( unsigned int  channel)

Shorthand for getChannel(unsigned int)

Returns
DeviceSet containing all devices in the specified channel
See also
getChannel(unsigned int)
bool Lumiverse::Rig::removeFunction ( int  pid)

Removes a function from the additional functions list.

This function will stop the update loop while it modifies the function list, and will automatically restart it.

Parameters
pidThe function number to remove.
Returns
True if function removed, false otherwise.
void Lumiverse::Rig::run ( )

Runs the update loop that sends updates to the network.

Spawns a child thread managed by this class.

See also
m_updateLoop
bool Lumiverse::Rig::save ( string  filename,
bool  overwrite = true 
)

Writes the rig out to a JSON file.

Parameters
filenamePath to file
overwriteIf the file specified by filename exists, the file will be overwritten if this variable is set to true (default)
Returns
True on success, false on failure.
See also
toJSON()
DeviceSet Lumiverse::Rig::select ( string  q)

Gets a DeviceSet based on a query string.

This will probably replace operator[](string) at some point, but that point is not now.

Parameters
qQuery string
Returns
DeviceSet containing all devices matching the query string.
See also
DeviceSet, DeviceSet::select()
void Lumiverse::Rig::setAllDevices ( map< string, Device * >  devices)

Updates the parameters of the devices stored in the specified map.

This function allows you to do mass updates of devices in a Rig. This function will only update parameters not metadata

Parameters
devicesMap of device id -> Device* containing the data to update the rig with.
void Lumiverse::Rig::setRefreshRate ( unsigned int  rate)

Sets the refresh rate for the update loop in cycles / second.

The DMX protocol is limited to 44Hz max, but you could run the loop faster.

Parameters
rateNumber of times the update loop should run per second.
void Lumiverse::Rig::stop ( )

Stops the update loop.

Do this before shutting down the network or potential reconfiguring.

See also
m_updateLoop
JSONNode Lumiverse::Rig::toJSON ( )

Gets the JSON data for the rig.

Returns
JSONNode containing all Rig information
void Lumiverse::Rig::update ( )

Pushes data over the network.

Actual transport is handled by the Patch objects in the Rig

See also
Patch
void Lumiverse::Rig::updateOnce ( )

Forces an update to happen when this function is called.

Can be used to write a custom update loop. Not recommended to call this function while the Rig is running (may create data races).

Friends And Related Function Documentation

friend class DeviceSet
friend
See also
DeviceSet

Member Data Documentation

set<Device *> Lumiverse::Rig::m_devices
private

Raw list of devices for sending to the Patch->update function.

This is the core list of Device objects that the Rig maintains. Indices are built off of this set as needed.

See also
Device
float Lumiverse::Rig::m_loopTime
private

Amount of time an update loop can take in s.

Automatically calculated by the rig based on m_refreshRate.

See also
m_refreshRate
map<string, Patch *> Lumiverse::Rig::m_patches
private

Maps Patch id to at Patch object.

The Patch id only matters to the Rig. The Patch doesn't really care what you call it.

See also
Patch
unsigned int Lumiverse::Rig::m_refreshRate
private

Sets the speed of the run loop in cycles/second. Default is 40.

See also
m_loopTime
bool Lumiverse::Rig::m_running
private

Indicates the status of the update loop.

True if running.

map<int, function<void()> > Lumiverse::Rig::m_updateFunctions
private

List of functions to run at the end of the update loop.

Allows a user to run an additional function during the update loop. This allows for a pretty easy update loop if you're updating things on a regular interval. Essentially the Rig's output loop becomes your graphics draw loop.

These functions must have a void() signature. I'm not entirely sure if you can have one access internal Rig variables, but if you have other sorts of things that need to run in a regularly timed loop, you have the option to attach it to the Rig update loop. These functions run before the patches are updated and could potentially be used to inject values into the rig before the patch happens.

map< string, patchParseFunc > Lumiverse::Rig::patchParsers = {}
static

Map containing functions to parse non-default patch types.

Lumiverse users may add functions to this map prior to loading JSON files to provide support for loading custom patch objects.

Note that you cannot override default patch types at this time.


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