HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CHOP_Realtime.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: CHOP Library (C++)
7  *
8  * COMMENTS: All realtime Channel Filters should derive from this class.
9  *
10  */
11 
12 #ifndef __CHOP_Realtime_h__
13 #define __CHOP_Realtime_h__
14 
15 #include "CHOP_API.h"
16 #include "CHOP_Node.h"
17 #include <CL/CL_SaveVersion.h>
18 
19 #define REALTIME_MODE_TRIM 0
20 #define REALTIME_MODE_ACCUM 1
21 #define REALTIME_MODE_CONTINUOUS 2
22 #define REALTIME_MODE_CURRENT_FRAME 3
23 #define REALTIME_MODE_FRAME_ONE 4
24 
25 #define REALTIME_INPUT_INTEREST_NONE (-1)
26 #define REALTIME_INPUT_INTEREST_ALL (-2)
27 
28 #define DEF_REALTIME_SETTLING_TIME 3
29 
30 class UT_OStream;
31 class CL_Filter;
32 class chop_RealtimeData;
33 
34 // Base Class for realtime Data blocks
36 {
37 public:
38  ut_RealtimeData(const char *name, int input = -1);
39  virtual ~ut_RealtimeData();
40 
41  const UT_String & tag() { return myTag; }
42  int inputNum() { return myInputNum; }
43  void setInput(int n) { myInputNum = n; }
44 
45  virtual bool loadStates(UT_IStream &is, int version);
46  virtual bool saveStates(UT_OStream &os);
47 
48 private:
49  UT_String myTag;
50  int myInputNum;
51 };
52 
53 // class for filtering data blocks (para eq, band eq, filter, etc).
55 {
56 public:
57  ut_FilterData(const char *name, int filter_size, int overlap);
58  ~ut_FilterData() override;
59 
60  bool loadStates(UT_IStream &is, int version) override;
61  bool saveStates(UT_OStream &os) override;
62 
64 };
65 
67 {
68 protected:
69 
70  CHOP_Realtime(OP_Network *parent,
71  const char *name,
72  OP_Operator *entry);
73  ~CHOP_Realtime() override;
74 
75  virtual OP_ERROR cookMySlice(OP_Context &, int start, int end) =0;
76  virtual const char *getTimeSliceExtension() = 0;
77  virtual int getSaveVersion()
78  { return CL_SAVE_VERSION; }
79 
80 
81  // called when the realtime button is turned on or off.
82  void realtimeInit(fpreal t) override;
83  void realtimeCleanup() override;
84 
85  // these methods are called when the framebar is started or stopped.
86  virtual void realtimeStart(fpreal t);
87  virtual void realtimeStop();
88 
89  // this method returns a newly allocated ut_RealtimeData block.
90  // override this if you have subclassed ut_RealtimeData.
91  // One data block per channel.
92  virtual ut_RealtimeData * newRealtimeDataBlock(const char *name,
93  const CL_Track *track,
94  fpreal t);
95 
96  // overridden from CHOP_Node.
97  int usesRealtime() override { return 1; }
98  int isRealtimeCook() override { return REALTIME(); }
99  virtual int isRealtimeActive(OP_Context &) { return 1; }
100 
101  // normally all realtime chops are time dependent
102  virtual int isTimeDependent();
103  virtual int isSteady() const;
104  virtual int getSettlingTime() const
105  { return DEF_REALTIME_SETTLING_TIME; }
106  virtual int allowDoubleCooking() const { return 0; }
107 
108  int isFirstRealtimeCook() const;
109  void setFirstRealtimeCook(bool first);
110 
111  // if true, this will trim out only the current slice.
112  virtual int realtimeMode() { return REALTIME_MODE_TRIM; }
113 
114  // if true, the realtime CHOP will change the start/end of the CHOP.
115  // otherwise, it leaves it alone.
116  virtual int adjustClip() { return 1; }
117 
118  // do not override this method.
119  OP_ERROR doCookRealtime(OP_Context &context) override;
120 
121  // which input's channels are our names & number of channels dependent on
122  // (-1 for none)
123  virtual int getInputInterest() { return 0; } // first input
124 
125  // override if you need the slice to end at a time other than the
126  // current frame (+/- adjustment).
127  virtual fpreal getRealtimeFrameAdjustment(fpreal ) { return 0.0; }
128 
129  // override if the sample rate is set by the chop, and not the input.
131 
132  // returns true if a range has been modified, plus that range.
133  int getModifiedRange(int &first, int &last,
134  int clear = 1) override;
135 
136  // returns true if wraparound occured before this cook.
137  int isWraparound() const;
138 
139  int getNumDataBlocks() const;
141  ut_RealtimeData * getDataBlock(const char *tag);
142 
143  void getFrameRange(int &start, int &end);
144  unsigned int getAbsoluteFrame();
145 
146  // input channel name & data cache management for straight through
147  // filters.
148  virtual void cacheChannelData(fpreal t);
149  virtual void resetDataCache();
150 
151  void setPreviousCookTime(fpreal t);
152 
153  void getCurrentRange(int &start, int &end) const;
154  void setCurrentRange(int start, int end);
155 
156  // for classes that manage their own data blocks; use with caution.
157  ut_RealtimeData *addDataBlock(const char *name,
158  const CL_Track *track =0,
159  fpreal t = 0.0);
160  ut_RealtimeData *insertDataBlock(int index,
161  const char *name,
162  const CL_Track *track =0,
163  fpreal t = 0.0);
164  void removeDataBlock(const char *name);
165  void removeDataBlock(int index);
166 
167  void updateDataBlocks();
168 
169  void copyRealtimeInput(const CL_Clip *clip,
170  int start, int end);
171 
172  OP_ERROR save(std::ostream &os,
173  const OP_SaveFlags &flags,
174  const char *pathPrefix,
175  const UT_String &name_override=UT_String()
176  ) override;
177 
178  bool load(UT_IStream &is, const char *extension,
179  const char *path) override;
180 
181  virtual OP_ERROR saveStates(UT_OStream &os);
182  virtual bool loadStates(UT_IStream &is, int version);
183 
184  // Allow the Reset At First Frame playbar button to clear all data in
185  // doRealtimeCook()
187  { return isRealtimeActive(ctx); }
188 
189 protected:
190 
191  chop_RealtimeData *newRealtimeBlock();
192 
193  chop_RealtimeData *myRealtimeData;
194 
195 private:
196  void getParentTimeSlice(int &start,int &end);
197 
198 public:
199  chop_RealtimeData *getRealtimeData() { return myRealtimeData; }
200  void setRealtimeData(chop_RealtimeData *d)
201  { myRealtimeData = d; }
202  static void deleteRealtimeData(chop_RealtimeData *data);
203 
204 };
205 
206 #endif
chop_RealtimeData * getRealtimeData()
#define DEF_REALTIME_SETTLING_TIME
Definition: CHOP_Realtime.h:28
OP_ERROR save(std::ostream &os, const OP_SaveFlags &flags, const char *pathPrefix, const UT_String &name_override=UT_String()) override
#define REALTIME_MODE_TRIM
Definition: CHOP_Realtime.h:19
virtual int allowDoubleCooking() const
#define CHOP_API
Definition: CHOP_API.h:10
virtual bool saveStates(UT_OStream &os)
virtual int getModifiedRange(int &first, int &last, int clear=1)
GLint first
Definition: glcorearb.h:404
GLuint start
Definition: glcorearb.h:474
virtual void realtimeInit(fpreal t)
GLsizei const GLchar *const * path
Definition: glcorearb.h:3340
GLenum GLenum GLenum input
Definition: glew.h:14162
OIIO_API std::string extension(const std::string &filepath, bool include_dot=true) noexcept
UT_ErrorSeverity
Definition: UT_Error.h:25
OP_DataBlockPtr getDataBlock(const char *key) const
GLuint const GLchar * name
Definition: glcorearb.h:785
bool isTimeDependent(const OP_Context &context)
CL_Filter * myFilter
Definition: CHOP_Realtime.h:63
GLdouble GLdouble t
Definition: glew.h:1403
chop_RealtimeData * myRealtimeData
int REALTIME() const
Definition: CHOP_Node.h:574
virtual void realtimeCleanup()
int isRealtimeCook() override
Definition: CHOP_Realtime.h:98
virtual bool allowResetAtFirstFrame(OP_Context &ctx)
GLuint GLuint end
Definition: glcorearb.h:474
void setInput(int n)
Definition: CHOP_Realtime.h:43
GLbitfield flags
Definition: glcorearb.h:1595
virtual OP_ERROR doCookRealtime(OP_Context &context)
GT_API const UT_StringHolder version
GLdouble n
Definition: glcorearb.h:2007
GLboolean * data
Definition: glcorearb.h:130
virtual int isRealtimeActive(OP_Context &)
Definition: CHOP_Realtime.h:99
const UT_String & tag()
Definition: CHOP_Realtime.h:41
IMATH_INTERNAL_NAMESPACE_HEADER_ENTER T clip(const T &p, const Box< T > &box)
Definition: ImathBoxAlgo.h:89
fpreal getSampleRate()
virtual int getSaveVersion()
Definition: CHOP_Realtime.h:77
fpreal64 fpreal
Definition: SYS_Types.h:277
virtual int realtimeMode()
GLuint index
Definition: glcorearb.h:785
virtual int getInputInterest()
bool load(UT_IStream &is, const char *extension, const char *path=0) override
virtual fpreal getRealtimeSampleRate()
virtual bool loadStates(UT_IStream &is, int version)
int usesRealtime() override
Definition: CHOP_Realtime.h:97
#define CL_SAVE_VERSION
void setRealtimeData(chop_RealtimeData *d)
virtual int getSettlingTime() const
virtual fpreal getRealtimeFrameAdjustment(fpreal)
virtual int adjustClip()