Lumiverse  2.5
A framework for creating lighting control applications
Layer.h
1 #ifndef _LAYER_H_
2 #define _LAYER_H_
3 
4 #pragma once
5 
6 #include "LumiverseCore.h"
7 #include "Timeline.h"
8 #include "Playback.h"
9 #include "CueList.h"
10 #include "Cue.h"
11 
12 #include <memory>
13 #include <chrono>
14 #include <unordered_map>
15 
16 namespace Lumiverse {
17 namespace ShowControl {
18  class Playback;
19  class CueList;
20 
22  struct PlaybackData {
23  chrono::time_point<chrono::high_resolution_clock> start; // Timeline start time. More accurate to take difference between now and start instead of summing.
24  map<string, set<string> > activeParams;
25  string timelineID;
26  bool complete;
27  chrono::time_point<chrono::high_resolution_clock> elapsed;
28  size_t length;
29  };
30 
41  class Layer
42  {
43  public:
44  enum BlendMode {
47  MAX,
48  MIN
49  };
50 
57  Layer(Rig* rig, Playback* pb, string name, int priority, BlendMode mode = ALPHA);
58 
64  Layer(Rig* rig, Playback* pb, string name, int priority, float opacity);
65 
69  Layer(DeviceSet set, Playback* pb, string name, int priority, BlendMode mode = ALPHA);
70 
74  Layer(Playback* pb, string name, int priority, BlendMode mode = ALPHA);
75 
79  Layer(Playback* pb, JSONNode node);
80 
82  ~Layer();
83 
93  void play(string id);
94 
100  void pause();
101 
107  void resume();
108 
115  void stop();
116 
118  BlendMode getMode() { return m_mode; }
119 
121  void setMode(BlendMode mode) { m_mode = mode; }
122 
124  float getOpacity() { return m_opacity; }
125 
127  void setOpacity(float val);
128 
130  bool isActive() { return m_active; }
131 
133  void activate() { m_active = true; }
134 
136  void deactivate() { m_active = false; }
137 
139  void setName(string name) { m_name = name; }
140 
142  string getName() { return m_name; }
143 
145  void setPriority(int priority) { m_priority = priority; }
146 
148  int getPriority() { return m_priority; }
149 
154  bool addDevices(DeviceSet d);
155 
160  bool addDevice(Device* d, string param);
161 
166  bool addDevicesWithParams(DeviceSet d, set<string> params);
167 
175  bool addParamToAllDevices(string param, LumiverseType* type);
176 
178  bool deleteParameter(string id, string param);
179 
185  bool deleteDevices(DeviceSet d);
186 
188  bool deleteParametersFromDevices(DeviceSet d, set<string> params);
189 
191  bool deleteParametersFromAllDevices(set<string> params);
192 
198  string getRecentTimeline();
199 
205  map<string, map<string, LumiverseType*> >& getLayerState() { return m_layerState; }
206 
212  void update(chrono::time_point<chrono::high_resolution_clock> updateStart);
213 
225  void blend(map<string, Device*> currentState);
226 
228  JSONNode toJSON();
229 
231  void reset();
232 
236  void setCueList(shared_ptr<CueList> list, bool resetCurrentCue = true);
237 
241  void removeCueList();
242 
246  bool hasCueList();
247 
251  const shared_ptr<CueList>& getCueList();
252 
256  float getCurrentCue();
257 
261  void go();
262 
266  void back();
267 
271  void goToCue(float num, float up = 3, float down = 3, float delay = 0);
272 
273  private:
281  map<string, map<string, LumiverseType*> > m_layerState;
282 
289 
291  string m_name;
292 
295 
297  bool m_active;
298 
301 
303  float m_opacity;
304 
306  bool m_pause;
307 
312  bool m_stop;
313 
317  bool m_playing;
318 
324  chrono::time_point<chrono::high_resolution_clock> m_previousLoopStart;
325 
330 
331  shared_ptr<CueList> m_cueList;
332 
333  float m_currentCue;
334 
336  void init(Rig* rig);
337 
338  // unsure if this function should remain in this rework.
346  //map<string, set<string> > diff(Cue* a, Cue* b, bool assert = false);
347 
354 
357 
358  mutex m_queue;
359  };
360 
361 #ifdef USE_C11_MAPS
362 
363  static unordered_map<Layer::BlendMode, string, std::hash<unsigned int>> BlendModeToString {
364  { Layer::ALPHA, "ALPHA" },
365  { Layer::OVERWRITE, "OVERWRITE" },
366  { Layer::MAX, "MAX" },
367  { Layer::MIN, "MIN" }
368  };
369 
371  static unordered_map<string, Layer::BlendMode> StringToBlendMode {
372  { "ALPHA", Layer::ALPHA },
373  { "OVERWRITE", Layer::OVERWRITE },
374  { "MAX", Layer::MAX },
375  { "MIN", Layer::MIN }
376  };
377 #else
378  static string BlendModeToString(Layer::BlendMode b) {
379  switch (b) {
380  case Layer::ALPHA: return "ALPHA";
381  case Layer::OVERWRITE: return "OVERWRITE";
382  case Layer::MAX: return "MAX";
383  case Layer::MIN: return "MIN";
384  default: return "";
385  }
386  }
387 
388  static Layer::BlendMode StringToBlendMode(string b) {
389  if (b == "ALPHA") return Layer::ALPHA;
390  if (b == "OVERWRITE") return Layer::OVERWRITE;
391  if (b == "MAX") return Layer::MAX;
392  if (b == "MIN") return Layer::MIN;
393  return Layer::BLEND_OPAQUE;
394  }
395 #endif
396 
397 
398 }
399 
400 // Note that for some reason when generating SWIG bindings, having these outside of the Lumiverse
401 // Namespace (they were in Lumiverse::ShowControl) causes some problems with SWIG's intermediate code
402 // generator.
403 // Comparison op overloads
408 inline bool operator==(ShowControl::Layer& lhs, ShowControl::Layer& rhs) {
409  return (lhs.getPriority() == rhs.getPriority());
410 }
411 
412 inline bool operator!=(ShowControl::Layer& lhs, ShowControl::Layer& rhs) {
413  return !(lhs == rhs);
414 }
415 
420 inline bool operator<(ShowControl::Layer& lhs, ShowControl::Layer& rhs) {
421  return (lhs.getPriority() < rhs.getPriority());
422 }
423 
424 inline bool operator>(ShowControl::Layer& lhs, ShowControl::Layer& rhs) {
425  return rhs < lhs;
426 }
427 
428 inline bool operator<=(ShowControl::Layer& lhs, ShowControl::Layer& rhs) {
429  return !(lhs > rhs);
430 }
431 
432 inline bool operator>=(ShowControl::Layer& lhs, ShowControl::Layer& rhs) {
433  return !(lhs < rhs);
434 }
435 }
436 
437 namespace std
438 {
439  template<>
440  struct hash<Lumiverse::ShowControl::Layer::BlendMode>
441  {
442  size_t operator()( const Lumiverse::ShowControl::Layer::BlendMode& arg ) const
443  {
444  std::hash<unsigned int> hasher;
445  return hasher( static_cast<unsigned int>( arg ) );
446  }
447  };
448 }
449 
450 #endif
float getCurrentCue()
Gets the most recently played cue on the Layer.
Definition: Layer.cpp:526
BlendMode m_mode
Layer blend mode.
Definition: Layer.h:300
Include file for all of LumiverseCore in one conveninent location.
bool isActive()
Retrieves the visibility of the layer.
Definition: Layer.h:130
void setOpacity(float val)
Set the layer's opactiy.
Definition: Layer.cpp:122
bool addDevicesWithParams(DeviceSet d, set< string > params)
Adds the selected devices and selected parameters to the Layer state.
Definition: Layer.cpp:161
Layer(Rig *rig, Playback *pb, string name, int priority, BlendMode mode=ALPHA)
Constructs a Layer.
Definition: Layer.cpp:6
This class is a wapper around a variety of different possible data types that might be needed by a De...
Definition: LumiverseType.h:33
const shared_ptr< CueList > & getCueList()
Retrieves the CueList assigned to the layer.
Definition: Layer.cpp:521
float m_opacity
If using alpha blending, the opacity of the layer.
Definition: Layer.h:303
map< string, map< string, LumiverseType * > > m_layerState
Holds the information on the current state of the layer.
Definition: Layer.h:281
BlendMode getMode()
Gets the layer's blend mode.
Definition: Layer.h:118
map< string, map< string, LumiverseType * > > & getLayerState()
Gets the layer state.
Definition: Layer.h:205
Definition: Layer.h:437
string getName()
Get the layer name.
Definition: Layer.h:142
Playback * m_pb
Playback object associated with the Layer.
Definition: Layer.h:288
A DeviceSet is a set of devices.
Definition: DeviceSet.h:41
A playback object manages layers, timelines, and coordinates their actions and updates.
Definition: Playback.h:32
float getOpacity()
Get the layer's opacity.
Definition: Layer.h:124
void reset()
Restores the layer state to defaults and gets out of the current cue.
Definition: Layer.cpp:492
string m_name
Layer Name.
Definition: Layer.h:291
void init(Rig *rig)
Copies the devices and does other Layer initialization.
Definition: Layer.cpp:95
bool deleteParametersFromDevices(DeviceSet d, set< string > params)
Deletes the selected parameter values from the layer.
Definition: Layer.cpp:238
A Layer stores a state of the Rig.
Definition: Layer.h:41
void setName(string name)
Set the layer name.
Definition: Layer.h:139
bool m_pause
Indicates if playback is paused on this layer.
Definition: Layer.h:306
bool deleteDevices(DeviceSet d)
Deletes the selected devices from the layer along with all of their parameters.
Definition: Layer.cpp:218
bool deleteParametersFromAllDevices(set< string > params)
Deletes all parameters from all devices in the layer.
Definition: Layer.cpp:255
void goToCue(float num, float up=3, float down=3, float delay=0)
Goes to the selected cue in the selected time.
Definition: Layer.cpp:562
int getPriority()
Gets the priority.
Definition: Layer.h:148
void blend(map< string, Device * > currentState)
Blends this layer with the given state.
Definition: Layer.cpp:407
void setMode(BlendMode mode)
Sets the Layer's blend mode.
Definition: Layer.h:121
~Layer()
Destroys a layer.
Definition: Layer.cpp:113
bool addDevice(Device *d, string param)
Adds a single device and parameter to the layer.
Definition: Layer.cpp:143
bool m_stop
Indicates that the Layer is stopping playback.
Definition: Layer.h:312
void activate()
Set m_active to true.
Definition: Layer.h:133
JSONNode toJSON()
Returns the JSON representation of a Layer.
Definition: Layer.cpp:452
bool m_playing
Indicates if the layer is currently playing back a timeline.
Definition: Layer.h:317
void pause()
Pauses playback of the current Timeline(s).
Definition: Layer.cpp:313
bool hasCueList()
Indicates whether or not the Layer has a CueList assigned to it.
Definition: Layer.cpp:516
void update(chrono::time_point< chrono::high_resolution_clock > updateStart)
Updates the Layer. If cues a running, the cues get updated.
Definition: Layer.cpp:333
string m_lastPlayedTimeline
Stores the ID of the most recently played back Timeline.
Definition: Layer.h:329
void back()
Goes to the previous cue in the list.
Definition: Layer.cpp:549
void deactivate()
Set m_active to false.
Definition: Layer.h:136
void stop()
Stops and clears all current playback information from the Layer.
Definition: Layer.cpp:324
void removeCueList()
Remvoes a CueList from the Layer.
Definition: Layer.cpp:511
bool addDevices(DeviceSet d)
Adds the selected devices and all parameters to the Layer state.
Definition: Layer.cpp:126
string getRecentTimeline()
Returns the ID of the Timeline most being played on the Layer.
Definition: Layer.cpp:329
Contains all core Lumiverse functions and variables.
Definition: Device.cpp:2
void play(string id)
Plays a Timeline on the layer.
Definition: Layer.cpp:271
BlendMode
Definition: Layer.h:44
PlaybackData * m_playbackData
Returns the set of parameters to animate.
Definition: Layer.h:353
void setPriority(int priority)
Sets the priority.
Definition: Layer.h:145
bool deleteParameter(string id, string param)
Deletes a single parameter from a single device in the layer.
Definition: Layer.cpp:203
The Rig contains information about the state of the lighting system.
Definition: Rig.h:58
bool addParamToAllDevices(string param, LumiverseType *type)
Adds the specified parameter with the specified type to the existing devices in the Layer...
Definition: Layer.cpp:184
A Device in Lumiverse maintains information about a lighting device.
Definition: Device.h:55
chrono::time_point< chrono::high_resolution_clock > m_previousLoopStart
Stores the previous loop start time in milliseconds.
Definition: Layer.h:324
bool m_active
Layer visibility flag.
Definition: Layer.h:297
void setCueList(shared_ptr< CueList > list, bool resetCurrentCue=true)
Assigns a CueList to the Layer.
Definition: Layer.cpp:503
void resume()
Resumes playback of the current Timeline(s).
Definition: Layer.cpp:318
Data that tracks the progress of a Timeline.
Definition: Layer.h:22
void go()
Goes to the next cue in the list.
Definition: Layer.cpp:531
PlaybackData * m_queuedPlayback
Next timeline to run.
Definition: Layer.h:356
int m_priority
Layer priority. High priority layers are on top of low priority ones.
Definition: Layer.h:294