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 
173  auto getEvaluateDataLambda(const CL_Track *track)
174  {
175  return [track](fpreal start_index, fpreal stop_index,
176  fpreal *data, int size)
177  {
178  track->getClip()->evaluate(track, start_index, stop_index,
179  data, size);
180  };
181  }
182 
183  OP_ERROR save(std::ostream &os,
184  const OP_SaveFlags &flags,
185  const char *pathPrefix,
186  const UT_String &name_override=UT_String()
187  ) override;
188 
189  bool load(UT_IStream &is, const char *extension,
190  const char *path) override;
191 
192  virtual OP_ERROR saveStates(UT_OStream &os);
193  virtual bool loadStates(UT_IStream &is, int version);
194 
195  // Allow the Reset At First Frame playbar button to clear all data in
196  // doRealtimeCook()
198  { return isRealtimeActive(ctx); }
199 
200 protected:
201 
202  chop_RealtimeData *newRealtimeBlock();
203 
204  chop_RealtimeData *myRealtimeData;
205 
206 private:
207  void getParentTimeSlice(int &start,int &end);
208 
209 public:
210  chop_RealtimeData *getRealtimeData() { return myRealtimeData; }
211  void setRealtimeData(chop_RealtimeData *d)
212  { myRealtimeData = d; }
213  static void deleteRealtimeData(chop_RealtimeData *data);
214 
215 };
216 
217 #endif
chop_RealtimeData * getRealtimeData()
GLint first
Definition: glcorearb.h:405
#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
GLbitfield flags
Definition: glcorearb.h:1596
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)
auto getEvaluateDataLambda(const CL_Track *track)
GLboolean * data
Definition: glcorearb.h:131
GLuint start
Definition: glcorearb.h:475
virtual void realtimeInit(fpreal t)
GLsizei const GLchar *const * path
Definition: glcorearb.h:3341
UT_ErrorSeverity
Definition: UT_Error.h:25
OP_DataBlockPtr getDataBlock(const char *key) const
bool isTimeDependent(const OP_Context &context)
CL_Filter * myFilter
Definition: CHOP_Realtime.h:63
chop_RealtimeData * myRealtimeData
int REALTIME() const
Definition: CHOP_Node.h:574
virtual void realtimeCleanup()
int isRealtimeCook() override
Definition: CHOP_Realtime.h:98
GLdouble n
Definition: glcorearb.h:2008
virtual bool allowResetAtFirstFrame(OP_Context &ctx)
void evaluate(const CL_Track *track, fpreal start_index, fpreal stop_index, fpreal *data, int size) const
GLuint GLuint end
Definition: glcorearb.h:475
void setInput(int n)
Definition: CHOP_Realtime.h:43
GLuint const GLchar * name
Definition: glcorearb.h:786
GLdouble t
Definition: glad.h:2397
virtual OP_ERROR doCookRealtime(OP_Context &context)
GT_API const UT_StringHolder version
CL_Clip * getClip()
Definition: CL_Track.h:142
__hostdev__ uint64_t last(uint32_t i) const
Definition: NanoVDB.h:5976
virtual int isRealtimeActive(OP_Context &)
Definition: CHOP_Realtime.h:99
const UT_String & tag()
Definition: CHOP_Realtime.h:41
GLsizeiptr size
Definition: glcorearb.h:664
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:786
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
IMATH_INTERNAL_NAMESPACE_HEADER_ENTER IMATH_HOSTDEVICE IMATH_CONSTEXPR14 T clip(const T &p, const Box< T > &box) IMATH_NOEXCEPT
Definition: ImathBoxAlgo.h:29
void setRealtimeData(chop_RealtimeData *d)
virtual int getSettlingTime() const
OIIO_UTIL_API std::string extension(string_view filepath, bool include_dot=true) noexcept
virtual fpreal getRealtimeFrameAdjustment(fpreal)
Definition: format.h:895
virtual int adjustClip()