HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CL_Track.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: CL_Track.h ( Clip Library, C++)
7  *
8  * COMMENTS:
9  * A set of raw data
10  *
11  */
12 
13 
14 #ifndef __CL_Track__
15 #define __CL_Track__
16 
17 #include "CL_API.h"
18 #include <UT/UT_ValArray.h>
19 #include <UT/UT_FloatArray.h>
20 #include <UT/UT_StringHolder.h>
21 #include <SYS/SYS_Types.h>
22 
23 class UT_IStream;
24 class UT_OStream;
25 class CL_Clip;
26 class CL_Track;
28 
31 
32 //
33 // how to evaluate the track outside its defined range
34 //
35 
36 typedef enum {
37  CL_TRACK_HOLD, // Track is start/end value before/after
38  CL_TRACK_SLOPE, // Track extends at start/end slope
39  CL_TRACK_CYCLE, // Track wraps to defined range (repeat)
40  CL_TRACK_MIRROR, // Track wraps+reflects to defined range
41  CL_TRACK_DEFAULT, // Track is default value beyond defined range
42  CL_TRACK_CYCLE_STEP // Track is cycled and advanced
44 
46 {
51 };
52 
54 {
59 };
60 
62 {
67 };
68 
69 
71 
72 public:
73 
74  CL_Track(CL_Clip &dad, const CL_Track &from);
75  CL_Track(CL_Clip &dad, const UT_StringHolder &name);
76  ~CL_Track();
77 
78 
79  CL_Track &operator= (const CL_Track &from);
80 
81  void init(CL_Clip &dad, const UT_StringHolder &name);
82 
84  { return myData.array(); }
85 
86  const fpreal *getData() const
87  { return myData.getRawArray(); }
88 
89  int getTrackLength() const
90  { return myData.entries(); }
91 
92  const UT_StringHolder &getName() const
93  { return myName; }
94 
95  //
96  // Warning this method must be used with extreme caution
97  void setName(const UT_StringHolder &name);
98 
99  // These methods are used for special cases, to access tracks more quickly.
100  // Normally a symboltable in CL_Clip is used to track access by name.
101  unsigned short getNameHash() const
102  { return (unsigned short)myName.hash(); }
103 
104  unsigned short getNameBaseLength() const
105  { return myNameBaseLength; }
106 
107  unsigned short getNameBaseHash() const
108  { return myNameBaseHash; }
109 
110  int getNameNumber() const
111  {
112  if (myNameNumberDirty)
113  ((CL_Track *)this)->calcNameNumber();
114  return myNameNumber;
115  }
116 
117  static void getNameComposition(const UT_StringRef &name,
118  unsigned short &base_length,
119  unsigned short &base_hash);
120 
121 
122  const char *info(fpreal t, const char *prefix = 0,
123  const char *suffix = 0) const;
124 
125  int isTimeDependent() const;
126 
127  int isWithinRange(fpreal low,fpreal hi,int completely=1) const;
128 
129  // these methods define the evaluation of the array outside
130  // its defined interval
131 
132  void setLeft(CL_TrackOutside type);
133  void setRight(CL_TrackOutside type);
134  void setDefault(fpreal value);
135 
137  { return myParent; }
138 
139  const CL_Clip *getClip(void) const
140  { return myParent; }
141 
142 
143  const char *getLeft(void) const;
144  const char *getRight(void) const;
145 
146  int64 getMemoryUsage(bool inclusive) const;
147 
148  void getExtendCond(CL_TrackOutside &left,
149  CL_TrackOutside &right) const;
151  { return myDefault; }
152 
153  void dupAttributes(const CL_Track *,
154  int data_too=0, int name_too=0);
155 
156  // data methods
157 
158  void reverse();
159  void constant(fpreal value=0);
160  void cycle(int howmany);
161 
162  int convolve(const CL_Track &t1, const CL_Track &t2,
163  int add = 0);
164 
165  int convolveCenter(fpreal *data2, int n2, int passes = 1);
166  int convolveCenterDirect(fpreal *data2, int n2, int passes);
167  int convolveCenterFFT(fpreal *data2,int n2,int passes);
168 
169  int copyStamp(const CL_Track &t1, fpreal toffset, int clr);
170 
171  int getThresholdTimes(fpreal thresh,
172  UT_FprealArray &toffsets,
173  UT_FprealArray &values) const;
174 
175  void despike(fpreal tol, fpreal effect=1.0, int maxwidth=1);
176 
177  void blend(fpreal start, const fpreal *values, int len,
178  fpreal base, const CL_SubRange *effect,
179  fpreal cycle);
180 
181  void blend(fpreal start, const fpreal *values, int len,
182  fpreal base, const CL_Track *effect_track,
183  fpreal cycle);
184 
185  void limitValues(fpreal max, fpreal min,
187  int start, int end);
188 
189  static fpreal limitValue(fpreal max, fpreal min,
191 
192  // Resample from the given source into ourselves
193 
194  int resample(const fpreal *values, int num,
196  int constant_area, int iscycle = 0,
197  fpreal cycle = 0);
198 
199  // Resample from ourselves into the given destination
200 
201  int resample(fpreal *data, int size, int start, int end,
203  int constant_area,
204  int iscycle = 0,
205  fpreal cycle = 0) const;
206 
207  void quantizeValue(fpreal max, fpreal min,
209  fpreal step, fpreal offset,
210  int clamp, int start, int end);
211 
212  void normalize();
213  void absolute();
214  void smoothRotate(fpreal delta = 180.0);
215 
216 
217  // Filter size must be a power of 2, and the filter itself should be
218  // in the form of a DFT filter
219  // the callback function takes parms 'node' 'size', 'freq step'
220  // 'mag filter' 'phase filter'
221  // 'index' and 'chunk' -- mag & phase filter are the arrays to be filted
222  // by the callback function. Called before filtering each chunk, if
223  // not null.
224  void filterFrequency(int filter_size,
225  fpreal freqstep,
226  fpreal overlap,
227  fpreal discard,
228  fpreal *filter,
229  fpreal *phase_filter = 0,
230  void (*filter_design)(void *,int,fpreal,fpreal *,fpreal *,int,int)=0,
231  void *node = 0,
232  int doblend = 1);
233 
234 
235  void pitchShift(fpreal shift,int chunk,
236  const CL_Track *animate=0,
237  fpreal (*callback)(void *,int,int)=0,
238  void *node=0);
239 
240  // This actually is a DFT followed by a multipy, and an IDFT
241  void fastConvolve(int chunk,fpreal *data);
242 
243 
244  // This method allows this track to assume the same data array as 'track'.
245  // They will share the same buffer until unalias() is called. aliasTrack()
246  // may be called multiple times before unalias() is called. Both tracks
247  // must have the same number of samples.
248  void aliasTrack(CL_Track &track);
249  void unalias();
250  bool isAliased() const { return myPrevDataAlias != 0; }
251 
252  // swaps data with 'track'.
253  void swapData(CL_Track &track);
254 
255  int getIndex() const;
256 
257  static UT_StringHolder fixName(const UT_StringHolder &old);
258 
259 private:
260 
261  // should only be called by CL_Clip
262 
263  void evaluate(fpreal start_index, fpreal stop_index,
264  fpreal *data, int size) const;
265 
266 
267  // this single version is much less efficient than the range methods
268  fpreal evaluateSingle(fpreal index) const;
269 
270  // optimizied evaluations which work on a range
271  // entire range is evaluated with a particular extend condition
272 
273  void evaluatePortion(fpreal i0, fpreal i1,
274  fpreal start_index, fpreal
275  stop_index, fpreal *data, int size,
276  fpreal *fix, int portion) const;
277 
278  void evaluateCenter(fpreal start_index, fpreal stop_index,
279  fpreal *data, int size) const;
280 
281  void evaluateLeftSlope(fpreal start_index, fpreal stop_index,
282  fpreal *data, int size) const;
283  void evaluateRightSlope(fpreal start_index, fpreal stop_index,
284  fpreal *data, int size) const;
285 
286  void evaluateLeftHold(fpreal *data, int size) const;
287  void evaluateRightHold(fpreal *data, int size) const;
288 
289  void evaluateDefault(fpreal *data, int size) const;
290  void evaluateCycle(fpreal start_index, fpreal stop_index,
291  fpreal *data, int size) const;
292  void evaluateMirror(fpreal start_index, fpreal stop_index,
293  fpreal *data, int size) const;
294  void evaluateCycleStep(fpreal start_index, fpreal stop_index,
295  fpreal *data, int size) const;
296 
297  void updateName();
298  //
299  // I/O methods
300  //
301  class CL_API BinaryIO
302  {
303  public:
304  BinaryIO() : myTaintVersion(0), myOffset(0), myDoubleFlag(false) {}
305 
306  int myTaintVersion;
307  int myOffset;
308  bool myDoubleFlag;
309  };
310 
311  int save(UT_OStream &os, BinaryIO *binary_options) const;
312  bool load(UT_IStream &is, BinaryIO *binary_options,
313  const char *path = 0);
314 
315  void setDefaults();
316  void calcNameNumber();
317  void setIndex(int);
318 
319  UT_StringHolder myName;
320  UT_FprealArray myData;
321  CL_Clip *myParent;
322 
323  unsigned short myNameBaseLength;
324  unsigned short myNameNumber;
325  unsigned short myNameBaseHash;
326 
327  char myNameNumberDirty;
328 
329 
330  CL_TrackOutside myLeft; // eval method outside range
331  CL_TrackOutside myRight; // eval method outside range
332  fpreal myDefault; // used in CL_TRACK_DEFAULT
333  fpreal *myPrevDataAlias; // used by alias/unalias.
334 
335  int myIndex; // track index in the clip array.
336 
337  friend class CL_Clip;
338  friend class CL_AsciiClipReader;
339  friend class CL_AsciiClipWriter;
340  friend class CL_BinaryClipReader;
341  friend class CL_BinaryClipWriter;
342 };
343 
344 
345 #endif
const UT_StringHolder & getName() const
Definition: CL_Track.h:92
UT_ValArray< const CL_Track * > CL_TrackListC
Definition: CL_Track.h:30
GLint left
Definition: glcorearb.h:2004
CL_Clip * getClip(void)
Definition: CL_Track.h:136
const GLdouble * v
Definition: glcorearb.h:836
GLuint start
Definition: glcorearb.h:474
GLsizei const GLchar *const * path
Definition: glcorearb.h:3340
GLsizeiptr size
Definition: glcorearb.h:663
int getNameNumber() const
Definition: CL_Track.h:110
unsigned short getNameBaseLength() const
Definition: CL_Track.h:104
#define CL_API
Definition: CL_API.h:10
long long int64
Definition: SYS_Types.h:107
bool isAliased() const
Definition: CL_Track.h:250
CL_TrackLimitMethod
Definition: CL_Track.h:45
unsigned short getNameHash() const
Definition: CL_Track.h:101
const std::enable_if<!VecTraits< T >::IsVec, T >::type & max(const T &a, const T &b)
Definition: Composite.h:133
CL_QuantizeValueMethod
Definition: CL_Track.h:53
GLuint GLuint end
Definition: glcorearb.h:474
int method
Definition: png.h:1924
GLintptr offset
Definition: glcorearb.h:664
GLenum GLsizei GLsizei GLint * values
Definition: glcorearb.h:1601
GLboolean * data
Definition: glcorearb.h:130
GLuint const GLchar * name
Definition: glcorearb.h:785
GridType::Ptr normalize(const GridType &grid, bool threaded, InterruptT *interrupt)
Normalize the vectors of the given vector-valued grid.
unsigned short getNameBaseHash() const
Definition: CL_Track.h:107
const CL_Clip * getClip(void) const
Definition: CL_Track.h:139
CL_TrackOutside
Definition: CL_Track.h:36
GLsizei const GLfloat * value
Definition: glcorearb.h:823
double fpreal
Definition: SYS_Types.h:270
CL_TrackResampleMethod
Definition: CL_Track.h:61
int getTrackLength() const
Definition: CL_Track.h:89
fpreal getDefault() const
Definition: CL_Track.h:150
const fpreal * getData() const
Definition: CL_Track.h:86
GLuint index
Definition: glcorearb.h:785
fpreal * getData()
Definition: CL_Track.h:83
GLint GLint GLsizei GLint GLenum GLenum type
Definition: glcorearb.h:107
png_infop png_uint_32 int num
Definition: png.h:2158
png_infop int chunk
Definition: png.h:2576
UT_ValArray< CL_Track * > CL_TrackList
Definition: CL_Track.h:27
const std::enable_if<!VecTraits< T >::IsVec, T >::type & min(const T &a, const T &b)
Definition: Composite.h:129
GLenum clamp
Definition: glcorearb.h:1233
GLint GLint GLint GLint GLint GLint GLint GLbitfield GLenum filter
Definition: glcorearb.h:1296