Lumiverse  2.5
A framework for creating lighting control applications
Device.h
Go to the documentation of this file.
1 #ifndef _DEVICE_H_
2 #define _DEVICE_H_
3 
7 #pragma once
8 
9 #include <map>
10 #include <vector>
11 #include <string>
12 #include <memory>
13 #include <sstream>
14 
15 #include "LumiverseCoreConfig.h"
16 #include "Logger.h"
17 #include "LumiverseType.h"
18 #include "types/LumiverseFloat.h"
19 #include "types/LumiverseEnum.h"
20 #include "types/LumiverseColor.h"
22 #include "lib/libjson/libjson.h"
23 #include "lib/Eigen/Dense"
24 using namespace std;
25 
26 namespace Lumiverse {
34  struct FocusPalette {
35  FocusPalette() { }
36  FocusPalette(string name, float pan, float tilt, string area, string system, string image) :
37  _name(name), _pan(pan), _tilt(tilt), _area(area), _system(system), _image(image) {}
38 
39  string _name;
40  float _pan;
41  float _tilt;
42  string _area;
43  string _system;
44  string _image;
45  };
46 
55  class Device
56  {
57  public:
68  Device(string id, unsigned int channel, string type);
69 
78  Device(string id, const JSONNode data);
79 
83  Device(const Device& other);
84 
88  Device(Device* other);
89 
93  Device(string id, Device* other);
94 
98  ~Device();
99 
106  std::ostream & operator<< (std::ostream &str) {
107  str << toString();
108  return str;
109  };
110 
116  inline string getId() { return m_id; }
117 
123  inline unsigned int getChannel() { return m_channel; }
124 
130  inline void setChannel(unsigned int newChan) { m_channel = newChan; }
131 
137  inline string getType() { return m_type; }
138 
144  inline void setType(string newType) { m_type = newType; }
145 
154  template <class T>
155  T* getParam(string param);
156 
168  bool getParam(string param, float& val);
169 
180  LumiverseType* getParam(string param);
181 
191  LumiverseFloat* getFloat(string param);
192 
202  LumiverseEnum* getEnum(string param);
203 
215  LumiverseColor* getColor(string param = "color");
216 
220  LumiverseOrientation* getOri(string param);
221 
235  bool setParam(string param, LumiverseType* val);
236 
241  bool setParam(string param, LumiverseFloat* val) { return setParam(param, (LumiverseType*)val); }
242 
247  bool setParam(string param, LumiverseEnum* val) { return setParam(param, (LumiverseType*)val); }
248 
253  bool setParam(string param, LumiverseColor* val) { return setParam(param, (LumiverseType*)val); }
254 
259  bool setParam(string param, LumiverseOrientation* val) { return setParam(param, (LumiverseType*)val); }
260 
261  // Mainly used for the python version of Lumiverse.
262  //bool setParam(string param, shared_ptr<LumiverseFloat>* val);
263  //bool setParam(string param, shared_ptr<LumiverseEnum>* val);
264  //bool setParam(string param, shared_ptr<LumiverseColor>* val);
265  //bool setParam(string param, shared_ptr<LumiverseOrientation>* val);
266 
279  bool setParam(string param, float val);
280 
292  bool setParam(string param, string val, float val2 = -1.0f);
293 
301  bool setParam(string param, string val, float val2, LumiverseEnum::Mode mode, LumiverseEnum::InterpolationMode interpMode);
302 
312  bool setParam(string param, string channel, double val);
313 
324  bool setParam(string param, double x, double y, double weight = 1.0);
325 
329  bool addFloatParam(string name, float val, float def, float max = 1.0f, float min = 0.0f);
330 
334  bool addColorParam(string name, int m);
335 
343  bool setColorRGBRaw(string param, double r, double g, double b, double weight = 1.0);
344 
351  bool setColorRGB(string param, double r, double g, double b, double weight = 1.0, RGBColorSpace cs = sRGB);
352 
356  bool setColorHSV(string param, double H, double S, double V, double weight = 1.0);
357 
361  bool setColorWeight(string param, double weight);
362 
366  bool setRGBRaw(double r, double g, double b, double weight = 1.0);
367 
371  bool setIntensity(float val) { return setParam("intensity", val); }
372 
376  LumiverseFloat* getIntensity();
377 
388  bool setColorChannel(string param, string channel, double val);
389 
390 
391  // Will need additional overloads for each new type. Which kinda sucks.
392 
399  void copyParamByValue(string param, LumiverseType* source);
400 
408  bool paramExists(string param);
409 
414  size_t numParams();
415 
420  vector<string> getParamNames();
421 
425  bool metadataExists(string key);
426 
434  bool getMetadata(string key, string& val);
435 
442  string getMetadata(string key);
443 
451  bool setMetadata(string key, string val);
452 
458  void deleteMetadata(string key);
459 
465  void deleteParameter(string key);
466 
472  void clearMetadataValues();
473 
479  void clearAllMetadata();
480 
484  size_t numMetadataKeys();
485 
489  vector<string> getMetadataKeyNames();
490 
496  void reset();
497 
503  string toString();
504 
509  JSONNode toJSON();
510 
519  unordered_map<string, LumiverseType*>& getRawParameters() { return m_parameters; }
520 
525  typedef function<void(Device*)> DeviceCallbackFunction;
526 
536  int addParameterChangedCallback(DeviceCallbackFunction func);
537 
548  int addMetadataChangedCallback(DeviceCallbackFunction func);
549 
556  void deleteParameterChangedCallback(int id);
557 
564  void deleteMetadataChangedCallback(int id);
565 
572  bool isIdentical(Device* d);
573 
581  Eigen::Vector3d getGelColor();
582 
588  void addFocusPalette(FocusPalette fp);
589 
593  FocusPalette* getFocusPalette(string name);
594 
598  void deleteFocusPalette(string name);
599 
603  void setFocusPalette(string name);
604 
608  vector<string> getFocusPaletteNames();
609 
616  FocusPalette* closestPalette();
617 
618  private:
631  void setId(string newId) { m_id = newId; }
632 
637  void loadJSON(const JSONNode data);
638 
645  void loadParams(const JSONNode data);
646 
652  JSONNode parametersToJSON();
653 
659  JSONNode metadataToJSON();
660 
665  void onParameterChanged();
666 
671  void onMetadataChanged();
672 
679  // TODO: This should be built in to the set ID function at some point
680  // Uniqueness isn't quite enforceable at the device level.
681  string m_id;
682 
686  unsigned int m_channel;
687 
692  string m_type;
693 
701  // Type may change in the future as more specialized datatypes come up.
702  unordered_map<string, LumiverseType*> m_parameters;
703 
711  map<string, string> m_metadata;
712 
720  map<int, DeviceCallbackFunction> m_onParameterChangedFunctions;
721 
729  map<int, DeviceCallbackFunction> m_onMetadataChangedFunctions;
730 
734  map<string, FocusPalette> m_fp;
735  };
736 
737  // Template definition
738  template <class T>
739  T* Device::getParam(string param) {
740  return dynamic_cast<T*>(getParam(param));
741  }
742 }
743 
744 #endif
Defines an enumeration in Lumiverse.
Definition: LumiverseEnum.h:43
unsigned int getChannel()
Accessor for channel.
Definition: Device.h:123
Utility functions for manipulating LumiverseTypes.
map< int, DeviceCallbackFunction > m_onParameterChangedFunctions
List of functions to run when a parameter is changed. Each function has an int id.
Definition: Device.h:720
This class is a wapper around a variety of different possible data types that might be needed by a De...
Definition: LumiverseType.h:33
This class describes a color.
Definition: LumiverseColor.h:83
Definition: Layer.h:437
A LumiverseType contains information about a Device Parameter.
Definition: LumiverseColorLib.h:30
RGBColorSpace
Selects a RGB color space to use in color conversion functions.
Definition: LumiverseColorLib.h:29
map< int, DeviceCallbackFunction > m_onMetadataChangedFunctions
List of functions to run when a metadata is changed. Each function has an int id. ...
Definition: Device.h:729
function< void(Device *)> DeviceCallbackFunction
Definition: Device.h:525
A Focus Palette is a preset configuration for the pan and tilt of a light.
Definition: Device.h:34
string getId()
Accessor for Device id.
Definition: Device.h:116
InterpolationMode
Sets the interpolation mode when transitioning between two LumiverseEnums.
Definition: LumiverseEnum.h:71
string getType()
Accessor for Device type.
Definition: Device.h:137
bool setParam(string param, LumiverseEnum *val)
Sets a parameter to an enumeration type.
Definition: Device.h:247
unordered_map< string, LumiverseType * > & getRawParameters()
Gets the raw map of parameters to data.
Definition: Device.h:519
Defines an orientation in Lumiverse.
Definition: LumiverseOrientation.h:61
string m_type
Device type name. "Source Four ERS" for example.
Definition: Device.h:692
bool setIntensity(float val)
Proxy for setParam("intensity", val). Assumes the existence of an "intensity" parameter.
Definition: Device.h:371
Contains functions for logging information to console or file.
Stores an enumeration in Lumiverse.
Stores a floating point value in Lumiverse.
Mode
When you select an enumeration, mode determines where in the range the calculated value will fall...
Definition: LumiverseEnum.h:56
A LumiverseColor contains information about a Device Color parameter.
map< string, FocusPalette > m_fp
List of focus palettes known by the device.
Definition: Device.h:734
map< string, string > m_metadata
Map for program-side information.
Definition: Device.h:711
bool setParam(string param, LumiverseColor *val)
Sets a parameter to a color value.
Definition: Device.h:253
void setId(string newId)
Sets the id for the device.
Definition: Device.h:631
Contains all core Lumiverse functions and variables.
Definition: Device.cpp:2
void setType(string newType)
Assigns Device type.
Definition: Device.h:144
Defines a float in Lumiverse.
Definition: LumiverseFloat.h:21
bool setParam(string param, LumiverseOrientation *val)
Sets a parameter to a orientation value.
Definition: Device.h:259
A Device in Lumiverse maintains information about a lighting device.
Definition: Device.h:55
unordered_map< string, LumiverseType * > m_parameters
Map for time-varying parameters.
Definition: Device.h:702
bool setParam(string param, LumiverseFloat *val)
Sets a parameter to a floating point value.
Definition: Device.h:241
string m_id
Unique identifier for the device.
Definition: Device.h:681
unsigned int m_channel
Channel number for the fixture. Does not have to be unique.
Definition: Device.h:686
void setChannel(unsigned int newChan)
Assigns channel number.
Definition: Device.h:130