Lumiverse
2.5
A framework for creating lighting control applications
|
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... | |
Device * | getDevice (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... | |
Patch * | getPatch (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. | |
DMXPatch * | getPatchAsDMXPatch (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... | |
Device * | operator[] (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... | |
Patch * | getSimulationPatch (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 |
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.
Lumiverse::Rig::Rig | ( | ) |
Makes an empty rig.
Lumiverse::Rig::Rig | ( | string | filename | ) |
Initialize Rig from JSON file.
This function will initialize Devices and Patches by calling functions in the appropriate class.
Path | to file |
Lumiverse::Rig::~Rig | ( | ) |
void Lumiverse::Rig::addDevice | ( | Device * | device | ) |
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.
pid | ID to assign to the function |
func | Function to execute |
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.
id | Identifier for the Patch. Used to retrieve patches from the Rig. |
patch | Pointer to the 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.
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.
Patch | id |
DeviceSet Lumiverse::Rig::getAllDevices | ( | ) |
Returns a set consisting of all devices in the rig.
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.
DeviceSet Lumiverse::Rig::getChannel | ( | unsigned int | channel | ) |
Gets all the devices in a channel.
channel | Channel to retrieve |
DeviceSet Lumiverse::Rig::getChannel | ( | unsigned int | lower, |
unsigned int | upper | ||
) |
Gets a range of channels.
lower | First channel to get (inclusive) |
upper | Last channel to get (inclusive) |
Device * Lumiverse::Rig::getDevice | ( | string | id | ) |
|
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.
DeviceSet Lumiverse::Rig::getDevices | ( | string | key, |
string | val, | ||
bool | isEqual | ||
) |
Gets devices by metadata info.
key | Metadata key |
val | Value to check |
isEqual | If true, returns all devices that have data equal to val. If false, returns all devices that have data not equal to val. |
set< string > Lumiverse::Rig::getMetadataValues | ( | string | key | ) |
Returns a set containing all of the unique values for a metadata key.
key | Metadata key to get values for |
Patch * Lumiverse::Rig::getPatch | ( | string | id | ) |
Gets a patch from the rig.
|
inline |
|
inline |
Gets the refresh rate for the update loop.
Patch * Lumiverse::Rig::getSimulationPatch | ( | string | type | ) |
Get a simulation patch.
Checks against all the registered patches and returns the first simulation patch found.
type | Type name to distinguish different Simulation Patch. |
void Lumiverse::Rig::init | ( | ) |
Initializes the rig.
Called after all patching has been done and configuration settings have been selected.
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.
|
private |
Loads the devices in the JSON file.
root | JSONNode containing the Devices in the Rig. |
|
private |
Loads the rig info from the parsed JSON data.
root | JSONNode containing all Rig data. |
|
private |
Load patches in the JSON file.
root | JSONNode containing the Patches in the Rig. |
Device * Lumiverse::Rig::operator[] | ( | string | id | ) |
DeviceSet Lumiverse::Rig::operator[] | ( | unsigned int | channel | ) |
Shorthand for 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.
pid | The function number to remove. |
void Lumiverse::Rig::run | ( | ) |
Runs the update loop that sends updates to the network.
Spawns a child thread managed by this class.
bool Lumiverse::Rig::save | ( | string | filename, |
bool | overwrite = true |
||
) |
Writes the rig out to a JSON file.
filename | Path to file |
overwrite | If the file specified by filename exists, the file will be overwritten if this variable is set to true (default) |
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.
q | Query string |
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
devices | Map 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.
rate | Number 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.
JSONNode Lumiverse::Rig::toJSON | ( | ) |
Gets the JSON data for the rig.
void Lumiverse::Rig::update | ( | ) |
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).
|
private |
|
private |
Amount of time an update loop can take in s.
Automatically calculated by the rig based on m_refreshRate.
|
private |
|
private |
Sets the speed of the run loop in cycles/second. Default is 40.
|
private |
Indicates the status of the update loop.
True if running.
|
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.
|
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.