forked from YCAMInterlab/ofxTimeline
/
ofxTimeline.h
executable file
·274 lines (214 loc) · 8.46 KB
/
ofxTimeline.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
/**
* ofxTimeline
*
* Copyright (c) 2011 James George
* http://jamesgeorge.org + http://flightphase.com
* http://github.com/obviousjim + http://github.com/flightphase
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*
* ----------------------
*
* ofxTimeline
* Lightweight SDK for creating graphic timeline tools in openFrameworks
*/
//controls to add:
// ofxTLColorTween
//TODO: Add global undo
//TODO: Account for image sequences and movies with different durations than the timeline
#pragma once
#include "ofMain.h"
#include "ofxTLElement.h"
#include "ofxTLElementHeader.h"
#include "ofxTLPage.h"
#include "ofxTLPageTabs.h"
#include "ofxTLZoomer.h"
#include "ofxTLTicker.h"
#include "ofxTLKeyframer.h"
#include "ofxTLTrigger.h"
#include "ofxTLSwitcher.h"
#include "ofxTLImageSequence.h"
#include "ofxTLVideoPlayer.h"
#include "ofxTLColors.h"
class ofxTimeline {
public:
ofxTimeline();
~ofxTimeline();
virtual void setup();
virtual void enable();
virtual void disable();
virtual bool toggleEnabled();
virtual void show();
virtual void hide();
virtual bool toggleShow();
virtual void setCurrentFrame(int currentFrame);
virtual void setCurrentTime(float time);
virtual void setPercentComplete(float percent);
virtual int getCurrentFrame();
virtual float getCurrentTime();
virtual float getPercentComplete();
virtual void play();
virtual void stop();
virtual bool togglePlay();
virtual bool getIsPlaying();
virtual void setInPointAtPercent(float percent);
virtual void setOutPointAtPercent(float percent);
virtual void setInPointAtFrame(int frame);
virtual void setOutPointAtFrame(float frame);
virtual void setInOutRange(ofRange inoutPercentRange);
virtual ofRange getInOutRange();
virtual int getInFrame();
virtual int getOutFrame();
virtual float getInTime();
virtual float getOutTime();
virtual void setCurrentTimeToInPoint();
virtual void setCurrentTimeToOutPoint();
//Setting the duration in seconds or frames determines
//wether the timeline is frame-based or time-based
//FRAME-BASED timelines will progress one frame each call to update
//at whatever framerate openFrameworks is running at, and will never skip frames
//TIME-BASED timelines will progress in real time regardless of openFrameworks
//framerate.
virtual void setDurationInFrames(int frames);
virtual void setDurationInSeconds(float seconds);
virtual bool getIsFrameBased();
virtual void setLoopType(ofLoopType newType);
virtual ofLoopType getLoopType();
virtual int getDurationInFrames();
virtual float getDurationInSeconds();
virtual void setOffset(ofVec2f offset);
virtual void setWidth(float width);
virtual void collapseAllElements(); //collapses all element heights to 0;
virtual ofRectangle getDrawRect();
virtual void setSnapping(bool snapping);
virtual void toggleSnapping();
void setMaxWidth( float _w );
//setting a BPM allows for a global measure across the timeline
//this is useful for snapping to intervals
virtual void enableSnapToBPM(float bpm); //beats per minute
virtual void toggleDrawBPMGrid();
virtual void enableDrawBPMGrid(bool enableGrid);
virtual void enableSnapToOtherElements(bool enableSnapToOther);
virtual void setMovePlayheadOnPaste(bool move);
virtual bool getMovePlayheadOnPaste();
string getPasteboard();
virtual void setMovePlayheadOnDrag(bool updatePlayhead);
virtual bool getMovePlayheadOnDrag();
virtual void unselectAll();
virtual void draw();
virtual void forceUpdateAllPages();
virtual void addPage(string name, bool makeCurrent = true);
virtual void setPageName(string newName);
virtual void setCurrentPage(string name);
virtual void setCurrentPage(int number);
virtual ofxTLElement* getElement(string name);
//adding elements always adds to the current page
virtual ofxTLKeyframer* addKeyframes(string name, string xmlFileName, ofRange valueRange);
virtual float getKeyframeValue(string name);
virtual float getKeyframeValue(string name, float atTime);
virtual float getKeyframeValue(string name, int atFrame);
virtual ofxTLSwitcher* addSwitcher(string name, string xmlFileName);
virtual bool getSwitcherOn(string name);
virtual bool getSwitcherOn(string name, float atTime);
virtual bool getSwitcherOn(string name, int atFrame);
virtual ofxTLTrigger* addTriggers(string name, string xmlFileName);
virtual string getNextTrigger(string name);
virtual string getNextTrigger(string name, float atTime);
virtual string getNextTrigger(string name, int atFrame);
virtual string getLastTrigger(string name);
virtual string getLastTrigger(string name, float atTime);
virtual string getLastTrigger(string name, int atFrame);
virtual ofxTLImageSequence* addImageSequence(string name);
virtual ofxTLImageSequence* addImageSequence(string name, string directory);
virtual ofImage* getImage(string name);
virtual ofImage* getImage(string name, float atTime);
virtual ofImage* getImage(string name, int atFrame);
//for custom elements
virtual void addElement(string name, ofxTLElement* element);
virtual void setAutosave(bool autosave);
virtual void mousePressed(ofMouseEventArgs& args);
virtual void mouseMoved(ofMouseEventArgs& args);
virtual void mouseDragged(ofMouseEventArgs& args);
virtual void mouseReleased(ofMouseEventArgs& args);
virtual void keyPressed(ofKeyEventArgs& args);
virtual void windowResized(ofResizeEventArgs& args);
ofxTLColors& getColors();
string formatTime(float time);
ofVec2f getNudgePercent();
ofVec2f getBigNudgePercent();
//do not call this yourself, called from within TLElement
//This is a bit subtle why it's here
//when multi keys are being dragged and snapping is enabled
//we need to compensate by the drag offset between the grabbed key
//and the mouse.
//TL elements should call this on mousedown if one of their elements is
//should be snapped directly to snap lines
void setDragAnchor(float dragAnchor);
float getDragAnchor();
ofxTLPlaybackEventArgs createPlaybackEvent();
protected:
bool isSetup;
bool usingEvents;
bool snappingEnabled;
bool movePlayheadOnPaste;
float globalDragAnchor;
bool dragAnchorSet; // will disable snapping if no drag anchor is set on mousedown
string pasteboard;
bool movePlayheadOnDrag;
//only enabled while playing
virtual void update(ofEventArgs& updateArgs);
ofxTLColors colors;
map<string, ofxTLPage*> elementNameToPage;
ofxTLPage* currentPage;
vector<ofxTLPage*> pages;
ofxTLTicker* ticker;
ofxTLPageTabs* tabs;
ofxTLZoomer* zoomer;
float width;
float maxWidth;
ofVec2f offset;
virtual void enableEvents();
virtual void disableEvents();
virtual void viewWasResized(ofEventArgs& args);
virtual void pageChanged(ofxTLPageEventArgs& args);
virtual void updatePagePositions();
virtual void recalculateBoundingRects();
ofRange inoutRange;
ofxXmlSettings settings;
string filenamePrefix;
ofRectangle totalDrawRect;
bool isEnabled; //allows for editing
bool isShowing; //allows for viewing
bool isPlaying; //moves playhead along
int currentFrame;
float currentTime;
ofLoopType loopType;
int playbackStartFrame;
float playbackStartTime;
float mouseoverPlayheadPosition;
float playbackPlayheadPosition;
bool modalIsShown;
bool autosave;
bool isFrameBased;
int durationInFrames;
float durationInSeconds;
};