HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
UT_Playback.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: UT_Playback.h ( UT Library, C++)
7  *
8  * COMMENTS:
9  *
10  * This class is used to store framebar info for
11  * classes above the SI library.
12  *
13  * This is primarily read-only for users - the set
14  * methods are used to update from the UI, but can't be
15  * used to update the UI. stopPlayback() is the exception.
16  *
17  */
18 
19 #ifndef __UT_Playback__
20 #define __UT_Playback__
21 
22 #include "UT_API.h"
23 #include "UT_ValArray.h"
24 #include <SYS/SYS_StaticInit.h>
25 #include <SYS/SYS_Types.h>
26 #include "UT_Function.h"
27 #include "UT_Lock.h"
28 #include "UT_Set.h"
29 #include "UT_Map.h"
30 
31 #include <iosfwd>
32 #include <utility>
33 
34 class ut_PlayCB;
35 
36 // cbdata, UT_PlaybackMode, oldframe, newframe
37 typedef void (*UT_PlayCallback)(void *, int, fpreal, fpreal);
38 typedef bool (*UT_PlayAdvanceCB)(void *);
39 
41 {
42 public:
43 
44  UT_Playback();
45 
52 
53  FLIPBOOKING
54  };
55 
56  enum class RealtimeBehaviour
57  {
58  MAINTAIN_PLAYBACK_SPEED = 0,
59  PLAY_EVERY_FRAME
60  };
61 
62  void setPlaybackMode(UT_PlaybackMode mode);
63 
65  { return myPlayback; }
66 
67  void setContinuousCook(bool continuous);
68  bool isContinuousCook() const
69  { return myContinuousCook; }
70 
71  int getStopCount() const
72  { return myStopCount; }
73 
74  void setRealtimeMode(bool mode)
75  { myRealtimeMode = mode; }
76 
77  bool getRealtimeMode() const
78  { return myRealtimeMode; }
79 
81  { myStartRange = start; myEndRange = end; }
82 
84  { start = myStartRange; end = myEndRange; }
85 
86  bool isPlaybackReset();
87  bool isPlaying() const { return (myPlayback == FORWARD ||
88  myPlayback == REVERSE); }
89  bool isScrubbing() const { return myPlayback == SCRUB; }
90 
91  void setCurrentFrame(fpreal frame);
92  fpreal getCurrentFrame() { return myCurrentFrame; }
93 
94  void resetAbsoluteFrame();
95  unsigned long getAbsoluteFrame() { return myAbsoluteFrame; }
96 
97  // tells SI_Playback to stop.
98  void stopPlayback();
99  void setStopCallback(void (*cb)(void *), void *data);
100 
101  void setInterceptMode(int mode) { myInterceptMode = mode; }
102  int getInterceptMode() const { return myInterceptMode; }
103 
104  void setLastFrameTime(fpreal time_sec)
105  { myLastFrameTime = time_sec; }
106  fpreal getLastFrameTime() const { return myLastFrameTime; }
107 
108  void setSamplesPerSec(fpreal samples_sec)
109  { mySamplesPerSec = samples_sec; }
110  fpreal getSamplesPerSec() const { return mySamplesPerSec; }
111 
112  // Callbacks are passed the UT_PlaybackMode and 'data'.
113  void addPlayCallback(UT_PlayCallback cb, void *cbdata);
114  void removePlayCallback(UT_PlayCallback cb, void *cbdata);
115 
116  void addPlayAdvanceCB(UT_PlayAdvanceCB, void *cbdata);
117  void removePlayAdvanceCB(UT_PlayAdvanceCB, void *cbdata);
118  bool canAdvancePlay();
119 
120  /// Register callbacks for when flipbooks are started and/or finished, returning
121  /// the callback id.
122  int addFlipbookCallbacks(UT_Function<void()> started_cb = nullptr,
123  UT_Function<void()> finished_cb = nullptr);
124 
125  /// Remove flipbook callbacks by the respective id.
126  void removeFlipbookCallbacks(int id);
127 
128 
129  /// Register nodes as continuous playback nodes, these will have
130  /// their continuouscook_tick incremented on continuouscook
131  /// frames
132  void registerContinuousCookNode(int nodeid);
133  void unregisterContinuousCookNode(int nodeid);
134  void getContinuousCookNodes(UT_IntArray &nodeids) const;
135 
137  { myRealtimeBehaviour = behaviour; }
138  RealtimeBehaviour getRealtimeBehaviour() const { return myRealtimeBehaviour; }
139 
140  static UT_Playback *getPlayback();
141 
142 private:
143 
144  using CallbackPair = std::pair<UT_PlayAdvanceCB, void *>;
145 
146  UT_PlaybackMode myPlayback;
147  bool myContinuousCook;
148  fpreal myStartRange;
149  fpreal myEndRange;
150  fpreal myCurrentFrame;
151  unsigned long myAbsoluteFrame;
152  fpreal myLastFrameTime;
153  fpreal mySamplesPerSec;
154  bool myRealtimeMode;
155  bool myResetFlag;
156  int myInterceptMode;
157  UT_ValArray<ut_PlayCB *> myPlayCallbacks;
158  UT_Array<CallbackPair> myPlayAdvanceCBs;
159  RealtimeBehaviour myRealtimeBehaviour;
160 
161  int myStopCount;
162 
163  mutable UT_Lock myLock;
164  UT_Set<int> myContinuousNodes;
165 
167 
168  static int theNextFlipbookCallbackId;
169 
170  void handleFlipbookStarted() const;
171  void handleFlipbookFinished() const;
172 };
173 
174 SYSdeclareStaticObject(UT_API, UTplaybackObject);
175 
176 #endif
177 
typedef int(APIENTRYP RE_PFNGLXSWAPINTERVALSGIPROC)(int)
bool isContinuousCook() const
Definition: UT_Playback.h:68
void setPlaybackRange(fpreal start, fpreal end)
Definition: UT_Playback.h:80
Unsorted map container.
Definition: UT_Map.h:109
void
Definition: png.h:1083
GLuint start
Definition: glcorearb.h:475
#define UT_API
Definition: UT_API.h:14
void getPlaybackRange(fpreal &start, fpreal &end) const
Definition: UT_Playback.h:83
UT_PlaybackMode getPlaybackMode() const
Definition: UT_Playback.h:64
OutGridT const XformOp bool bool
void(* UT_PlayCallback)(void *, int, fpreal, fpreal)
Definition: UT_Playback.h:37
void setRealtimeBehaviour(const RealtimeBehaviour behaviour)
Definition: UT_Playback.h:136
void setInterceptMode(int mode)
Definition: UT_Playback.h:101
void setLastFrameTime(fpreal time_sec)
Definition: UT_Playback.h:104
void setRealtimeMode(bool mode)
Definition: UT_Playback.h:74
bool isScrubbing() const
Definition: UT_Playback.h:89
int getInterceptMode() const
Definition: UT_Playback.h:102
GLuint GLuint end
Definition: glcorearb.h:475
bool getRealtimeMode() const
Definition: UT_Playback.h:77
int getStopCount() const
Definition: UT_Playback.h:71
fpreal getSamplesPerSec() const
Definition: UT_Playback.h:110
SYSdeclareStaticObject(UT_API, UTplaybackObject)
std::function< T > UT_Function
Definition: UT_Function.h:37
fpreal getLastFrameTime() const
Definition: UT_Playback.h:106
fpreal getCurrentFrame()
Definition: UT_Playback.h:92
void setSamplesPerSec(fpreal samples_sec)
Definition: UT_Playback.h:108
GLenum mode
Definition: glcorearb.h:99
RealtimeBehaviour getRealtimeBehaviour() const
Definition: UT_Playback.h:138
fpreal64 fpreal
Definition: SYS_Types.h:278
unsigned long getAbsoluteFrame()
Definition: UT_Playback.h:95
bool(* UT_PlayAdvanceCB)(void *)
Definition: UT_Playback.h:38
bool isPlaying() const
Definition: UT_Playback.h:87
Definition: format.h:1821