00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef __CL_Clip__
00021 #define __CL_Clip__
00022
00023 #include "CL_API.h"
00024 #include <UT/UT_XformOrder.h>
00025 #include <UT/UT_PtrArray.h>
00026 #include <UT/UT_IntArray.h>
00027 #include <UT/UT_String.h>
00028 #include <UT/UT_Color.h>
00029 #include <UT/UT_NameManager.h>
00030 #include <SYS/SYS_Math.h>
00031
00032 #include "CL_Track.h"
00033
00034 class UT_IStream;
00035
00036 typedef void (*CL_InfoCallback)(UT_String &result, void *data, int idx);
00037
00038 class CL_API CL_Clip {
00039
00040 public:
00041
00042 CL_Clip(int size);
00043 CL_Clip(const CL_Clip &from);
00044 ~CL_Clip();
00045
00046 CL_Clip &operator= (const CL_Clip &v);
00047
00048
00049
00050
00051 void copyContents(const CL_Clip &v, int data, int slerps);
00052
00053
00054
00055
00056
00057 int getCheckDuplicateNames() const
00058 { return myCheckDuplicateNames; }
00059
00060 void setCheckDuplicateNames(int val)
00061 { myCheckDuplicateNames = val; }
00062
00063
00064
00065
00066
00067 void clearAndDestroy();
00068
00069 void setStart(float start)
00070 { myStart = start; }
00071
00072 float getStart(void) const
00073 { return myStart; }
00074
00075 float getEnd(void) const
00076 { return myStart + myTrackLength - 1; }
00077
00078 int getTrackLength(void) const
00079 { return myTrackLength; }
00080
00081 void setTrackLength(int length, int clear_extra=0);
00082
00083 void setSampleRate(float rate)
00084 { mySampleRate = SYSmax(rate, 1.0e-4); }
00085
00086 float getSampleRate(void) const
00087 { return mySampleRate; }
00088
00089 int getTrackNames(UT_PtrArray<const char *> &list) const;
00090 int getTracks(CL_TrackListC &list,
00091 const char *pattern = 0) const;
00092 int getTracks(UT_IntArray &list, const char *pat) const;
00093
00094
00095 int isTimeDependent() const;
00096
00097
00098
00099
00100
00101
00102 int numSlerps() const;
00103
00104 int copySlerpAttributes(const CL_Clip &v,
00105 int by_name = 0);
00106
00107 int resetSlerps();
00108
00109 int findSlerp(const CL_Track *track, int &idx) const;
00110
00111 int getSlerp(int slerp_idx,
00112 int &x_idx,
00113 int &y_idx,
00114 int &z_idx) const;
00115
00116 int getSlerp(const CL_Track *track,
00117 int &x_idx,
00118 int &y_idx,
00119 int &z_idx) const;
00120
00121 int setSlerp(int x_idx, int y_idx, int z_idx);
00122
00123 int slerpBlend(int slerp_idx,
00124 const float *xvalues,
00125 const float *yvalues,
00126 const float *zvalues,
00127 float start, int len, float base,
00128 const CL_Track *effect_track);
00129
00130 int slerpBlend(int slerp_idx,
00131 const float *xvalues,
00132 const float *yvalues,
00133 const float *zvalues,
00134 float start, int len, float base,
00135 const CL_SubRange *effect);
00136
00137 int validateSlerps();
00138
00139 void setSlerpOrder(UT_XformOrder::xyzOrder o)
00140 { mySRotOrder = o; }
00141
00142 UT_XformOrder::xyzOrder getSlerpOrder() const
00143 { return mySRotOrder; }
00144
00145
00146
00147
00148
00149
00150 void removeTrack(int idx);
00151
00152 CL_Track *addTrack(const char *name);
00153 CL_Track *dupTrackInfo(const CL_Track *,int data_too = 0,
00154 const char *name = 0);
00155
00156 int getNumTracks(void) const
00157 { return myTracks.entries(); }
00158
00159 CL_Track *getTrack(int index)
00160 { return (index >= 0 && index < myTracks.entries()) ?
00161 myTracks(index) : 0; }
00162
00163 const CL_Track *getTrack(int index) const
00164 { return (index >= 0 && index < myTracks.entries()) ?
00165 myTracks(index) : 0; }
00166
00167 CL_Track *getTrack(const char *name, int *index = 0);
00168 const CL_Track *getTrack(const char *name, int *index = 0) const;
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179 float evaluateSingle(const CL_Track *track, float index) const
00180 { return track->evaluateSingle(index - myStart); }
00181
00182 float evaluateSingleTime(const CL_Track *track, float t) const
00183 { return evaluateSingle(track, getIndex(t)); }
00184
00185 float evaluateSingleFrame(const CL_Track *track,
00186 float f, float fps) const
00187 { return evaluateSingle(track, getIndexF(f, fps)); }
00188
00189
00190
00191 void evaluate(const CL_Track *track,
00192 float start_index, float stop_index,
00193 float *data, int size) const;
00194
00195 int evaluateSlerp(int slerp_idx,
00196 float start_index, float stop_index,
00197 float *xdata, float *ydata, float *zdata,
00198 int size) const;
00199
00200 void evaluateTime(const CL_Track *track,
00201 float start_time, float stop_time,
00202 float *data, int size) const
00203 { evaluate(track, getIndex(start_time),
00204 getIndex(stop_time), data, size); }
00205
00206 void resampleTime(const CL_Track *track,
00207 float start_time, float stop_time,
00208 float *data, int size) const;
00209
00210
00211
00212
00213 void getHeight(const CL_Track *track,
00214 float start_index, float stop_index,
00215 int nsamples, float *imin, float *imax) const;
00216
00217
00218
00219
00220 void evaluateHeightRange(const CL_Track *track,
00221 float start_index, float stop_index,
00222 float *data, int size) const;
00223
00224
00225
00226
00227
00228
00229
00230
00231 int extendTime(float t, int *delta);
00232
00233
00234
00235
00236
00237
00238 float getStartTime() const
00239 { return getTime(myStart); }
00240
00241 float getEndTime() const
00242 { return getTime(myStart + myTrackLength - 1); }
00243
00244 void dupAttributes(const CL_Clip &);
00245
00246
00247
00248
00249
00250 float getIndex(float time) const
00251 { return time*mySampleRate; }
00252
00253 float getTime(float index) const
00254 { return index / mySampleRate; }
00255
00256 float getFrame(float index, float fps) const
00257 { return index*fps/mySampleRate + 1;}
00258
00259 float getIndexF(float frame, float fps) const
00260 { return getTimeF(frame, fps)*mySampleRate; }
00261
00262 static float getTimeF(float frame, float fps)
00263 { return (frame - 1) / fps; }
00264
00265 static float getFrameT(float time, float fps)
00266 { return time*fps + 1; }
00267
00268
00269
00270
00271
00272
00273 void trim(const CL_Clip *clip, float leftpos,
00274 float rightpos, int discard);
00275
00276
00277
00278
00279
00280 int crop(int newlen, int add);
00281
00282
00283
00284
00285
00286
00287
00288 int save(ostream &os, int binary) const;
00289 int save(const char *nm) const;
00290
00291
00292 bool load(UT_IStream &is, const char *path=0);
00293
00294 int load(const char *nm);
00295
00296 int64 getMemoryUsage(void) const;
00297 int info(ostream &os, float fps, float t,
00298 int limit=1, CL_InfoCallback cb=0,
00299 void *cbdata=0) const;
00300
00301 static float fixedDecimal(float num, int digits = 2);
00302 static void printNum(ostream &os,float num);
00303
00304
00305
00306
00307
00308 void reorder(CL_TrackList &list);
00309
00310
00311
00312
00313
00314
00315 void crackSmooth(int xidx, int yidx, int zidz,
00316 UT_XformOrder order,
00317 int use_hint,
00318 float hx, float hy, float hz);
00319
00320
00321
00322
00323 int isSameRange(const CL_Clip &v) const;
00324
00325
00326
00327
00328 void stashAll();
00329 void destroyStashed();
00330
00331 char *newName(const char *oldname) const;
00332
00333 void setDefaults(void);
00334
00335
00336 void trackRenamed(CL_Track *track,
00337 const char *oldname);
00338
00339 private:
00340 float mySampleRate;
00341 float myStart;
00342
00343 int myTrackLength;
00344 CL_TrackList myTracks;
00345 CL_TrackList myStashedTracks;
00346
00347 UT_IntArray mySXTracks;
00348 UT_IntArray mySYTracks;
00349 UT_IntArray mySZTracks;
00350
00351 UT_XformOrder::xyzOrder mySRotOrder;
00352
00353 bool myCheckDuplicateNames;
00354
00355 UT_NameManager<CL_Track*> myTrackNames;
00356
00357 bool myDisableRemovingTrackNames;
00358
00359 };
00360
00361 typedef UT_PtrArray<CL_Clip *> CL_ClipList;
00362 typedef UT_PtrArray<const CL_Clip *> CL_ClipListC;
00363
00364
00365 #endif
00366