Lumiverse  2.5
A framework for creating lighting control applications
Timeline.h
1 #ifndef _TIMELINE_H_
2 #define _TIMELINE_H_
3 
4 #pragma once
5 
6 #include "LumiverseCore.h"
7 #include "Keyframe.h"
8 
9 namespace Lumiverse {
10 namespace ShowControl {
11 
34 class Timeline {
35 public:
39  Timeline();
40 
46  Timeline(JSONNode data);
47 
51  Timeline(const Timeline& other);
52 
53  void operator=(const Timeline& other);
54 
58  virtual ~Timeline();
59 
63  string getTimelineKey(Device* d, string paramName);
64 
68  string getTimelineKey(string id, string paramName);
69 
75  Keyframe getKeyframe(string identifier, size_t time);
76 
82  map<string, Keyframe> getKeyframes(Device* d, size_t time);
83 
87  map<string, map<size_t, Keyframe> >& getAllKeyframes();
88 
94  void setKeyframe(string identifier, size_t time, LumiverseType* data, bool ucs = false);
95 
99  void setKeyframe(Device* d, size_t time, bool ucs = false);
100 
104  void setKeyframe(Rig* rig, size_t time, bool ucs = false);
105 
109  void setKeyframe(DeviceSet devices, size_t time, bool ucs = false);
110 
114  void setKeyframe(string identifier, size_t time, string timelineID, size_t offset = 0);
115 
119  void setKeyframe(Device* d, size_t time, string timelineID, size_t offset = 0);
120 
124  void setKeyframe(DeviceSet devices, size_t time, string timelineID, size_t offset = 0);
125 
129  void deleteKeyframe(string identifier, size_t time);
130 
134  void deleteKeyframe(Device* d, size_t time);
135 
139  void deleteKeyframe(DeviceSet devices, size_t time);
140 
145  void moveKeyframe(string id, size_t oldTime, size_t newTime);
146 
150  void deleteKeyframesAfter(string id, size_t start);
151 
155  void deleteKeyframesBetween(size_t start, size_t end);
156 
165  bool addEndEvent(string id, shared_ptr<Event> e);
166 
172  void deleteEndEvent(string id);
173 
180  bool addEvent(size_t time, shared_ptr<Event> e);
181 
189  void deleteEvent(size_t time, string id = "");
190 
198  vector<shared_ptr<Event> > getEvents(size_t time, string id = "");
199 
206  shared_ptr<Event> getEndEvent(string id);
207 
211  multimap<size_t, shared_ptr<Event> >& getAllEvents();
212 
216  map<string, shared_ptr<Event> >& getAllEndEvents();
217 
226  virtual shared_ptr<LumiverseType> getValueAtTime(string id, string paramName, LumiverseType* currentVal, size_t time, map<string, shared_ptr<Timeline> >& tls);
227 
239  virtual void executeEvents(size_t prevTime, size_t currentTime);
240 
244  virtual void executeEndEvents();
245 
251  virtual int getLoops();
252 
258  virtual void setLoops(int loops);
259 
265  virtual size_t getLength();
266 
272  virtual size_t getLoopLength();
273 
277  virtual JSONNode toJSON();
278 
289  virtual bool isDone(size_t time, map<string, shared_ptr<Timeline> >& tls);
290 
297  virtual void setCurrentState(map<string, map<string, LumiverseType*> >& state, shared_ptr<Timeline> active, size_t time);
298 
305  Keyframe getPreviousKeyframe(string identifier, size_t time);
306 
310  virtual size_t getLoopTime(size_t time);
311 
315  virtual string getTimelineTypeName() { return "timeline"; }
316 
317 protected:
324  size_t _length;
325 
331  size_t _loopLength;
332 
338  int _loops;
339 
344 
349 
350  // right so the map should at some point be changed to a specialized data structure that meets
351  // the following properties:
352  // -given a time, can find the first and next keyframes (if they exist) as quickly as possible
353  // -can handle insertions and deletions quickly (doesn't have to be as fast as possible)
359  map<string, map<size_t, Keyframe> > _timelineData;
360 
364  multimap<size_t, shared_ptr<Event> > _events;
365 
372  map<string, shared_ptr<Event> > _endEvents;
373 
377  void updateKeyframeState(string id, string paramName, LumiverseType* param, shared_ptr<Timeline> tl, size_t time);
378 
382  void loadJSON(JSONNode node);
383 };
384 
385 }
386 }
387 #endif
void setKeyframe(string identifier, size_t time, LumiverseType *data, bool ucs=false)
Sets the value for the specified keyframe.
Definition: Timeline.cpp:58
void deleteKeyframe(string identifier, size_t time)
Deletes the keyframe with the specified identifier at the specified time.
Definition: Timeline.cpp:98
Include file for all of LumiverseCore in one conveninent location.
virtual void setLoops(int loops)
Set the number of loops the timeline should execute.
Definition: Timeline.cpp:330
virtual shared_ptr< LumiverseType > getValueAtTime(string id, string paramName, LumiverseType *currentVal, size_t time, map< string, shared_ptr< Timeline > > &tls)
Returns the value of the specified parameter for the specified device at the specified time...
Definition: Timeline.cpp:223
map< string, shared_ptr< Event > > & getAllEndEvents()
Returns the end Events for this Timeline.
Definition: Timeline.cpp:219
bool addEvent(size_t time, shared_ptr< Event > e)
Adds an Event to the Timeline.
Definition: Timeline.cpp:166
This class is a wapper around a variety of different possible data types that might be needed by a De...
Definition: LumiverseType.h:33
Keyframe getKeyframe(string identifier, size_t time)
Gets the keyframe for a given identifier and time. Read-only.
Definition: Timeline.cpp:36
void deleteEvent(size_t time, string id="")
Deletes Events from the Timeline.
Definition: Timeline.cpp:171
map< string, Keyframe > getKeyframes(Device *d, size_t time)
Gets the keyframes for a given device and time. Read-only.
Definition: Timeline.cpp:40
virtual bool isDone(size_t time, map< string, shared_ptr< Timeline > > &tls)
Indicates if the Timeline has no more keyframes after the specified time.
Definition: Timeline.cpp:377
void updateKeyframeState(string id, string paramName, LumiverseType *param, shared_ptr< Timeline > tl, size_t time)
Updates the Keyframes marked as "Use Current State" in the Timeline's data.
Definition: Timeline.cpp:416
virtual JSONNode toJSON()
Gets the JSON representation of the timeline object.
Definition: Timeline.cpp:334
A Timeline is a list of device parameter values at arbitrary times.
Definition: Timeline.h:34
virtual ~Timeline()
Deletes a timeline.
Definition: Timeline.cpp:23
map< string, shared_ptr< Event > > _endEvents
List of events to call at the end.
Definition: Timeline.h:372
A DeviceSet is a set of devices.
Definition: DeviceSet.h:41
Timeline()
Creates an empty timeline.
Definition: Timeline.cpp:6
virtual void executeEvents(size_t prevTime, size_t currentTime)
Executes the events between the specified times.
Definition: Timeline.cpp:304
Keyframe getPreviousKeyframe(string identifier, size_t time)
Gets the keyframe closest to happen at or before the given time.
Definition: Timeline.cpp:438
shared_ptr< Event > getEndEvent(string id)
Gets an end Event.
Definition: Timeline.cpp:207
bool _loopLengthIsUpdated
Indicates if the timeline's loop length is updated.
Definition: Timeline.h:348
bool _lengthIsUpdated
Indicates if the timeline's length is updated.
Definition: Timeline.h:343
virtual void executeEndEvents()
Executes all end events in the timeline's list.
Definition: Timeline.cpp:320
A Keyframe stores the value of a parameter at the specified time.
Definition: Keyframe.h:17
virtual size_t getLength()
Gets the length of the timeline based on stored keyframes.
Definition: Timeline.cpp:471
void moveKeyframe(string id, size_t oldTime, size_t newTime)
Moves a keyframe from one time to a different time. If a keyframe already exists at the target time...
Definition: Timeline.cpp:116
void deleteKeyframesAfter(string id, size_t start)
Deletes all keyframes for an id that occur after (>) the start time.
Definition: Timeline.cpp:123
virtual void setCurrentState(map< string, map< string, LumiverseType * > > &state, shared_ptr< Timeline > active, size_t time)
Takes a state from the layer and updates the keyframes marked with "Use Current State".
Definition: Timeline.cpp:408
void deleteKeyframesBetween(size_t start, size_t end)
Deletes all keyframes between (start < keyframe < end) the specified times.
Definition: Timeline.cpp:137
int _loops
Describes how many times the timeline should loop.
Definition: Timeline.h:338
virtual int getLoops()
Returns the looping setting for this timeline.
Definition: Timeline.cpp:326
size_t _loopLength
Stores the loop length of the timleine.
Definition: Timeline.h:331
void deleteEndEvent(string id)
Deletes an end event.
Definition: Timeline.cpp:162
Contains all core Lumiverse functions and variables.
Definition: Device.cpp:2
multimap< size_t, shared_ptr< Event > > _events
List of events and times that the events happen.
Definition: Timeline.h:364
map< string, map< size_t, Keyframe > > _timelineData
Map from unique identifier to timeline keyframes.
Definition: Timeline.h:359
bool addEndEvent(string id, shared_ptr< Event > e)
Adds a new event to the end of the timeline.
Definition: Timeline.cpp:153
size_t _length
Stores the length of the timeline.
Definition: Timeline.h:324
map< string, map< size_t, Keyframe > > & getAllKeyframes()
Gets the keyframes for the entire timeline.
Definition: Timeline.cpp:52
multimap< size_t, shared_ptr< Event > > & getAllEvents()
Returns the multimap containing the Events for this Timeline.
Definition: Timeline.cpp:215
The Rig contains information about the state of the lighting system.
Definition: Rig.h:58
A Device in Lumiverse maintains information about a lighting device.
Definition: Device.h:55
virtual string getTimelineTypeName()
Used for identifying different kinds of timelines.
Definition: Timeline.h:315
virtual size_t getLoopTime(size_t time)
Returns the time adjusted for the number of loops the timeline can perfrom.
Definition: Timeline.cpp:525
vector< shared_ptr< Event > > getEvents(size_t time, string id="")
Gets Events at the specified time.
Definition: Timeline.cpp:189
string getTimelineKey(Device *d, string paramName)
Gets the identifier used to refer to a device-parameter keyframe set.
Definition: Timeline.cpp:27
void loadJSON(JSONNode node)
Initializes the timeline with the given JSONNode's data.
Definition: Timeline.cpp:542
virtual size_t getLoopLength()
Gets the length of the timeline for a single loop.
Definition: Timeline.cpp:492