00001 #include "asset.h"
00002 #include "autoconf.h"
00003 #include "cache.h"
00004 #include "clip.h"
00005 #include "datatype.h"
00006 #include "edit.h"
00007 #include "edits.h"
00008 #include "edl.h"
00009 #include "edlsession.h"
00010 #include "filexml.h"
00011 #include "floatauto.h"
00012 #include "floatautos.h"
00013 #include "language.h"
00014 #include "localsession.h"
00015 #include "patch.h"
00016 #include "mainsession.h"
00017 #include "theme.h"
00018 #include "trackcanvas.h"
00019 #include "tracks.h"
00020 #include "transportque.inc"
00021 #include "units.h"
00022 #include "vautomation.h"
00023 #include "vedit.h"
00024 #include "vedits.h"
00025 #include "vframe.h"
00026 #include "vmodule.h"
00027 #include "vpluginset.h"
00028 #include "vtrack.h"
00029
00030 VTrack::VTrack(EDL *edl, Tracks *tracks)
00031 : Track(edl, tracks)
00032 {
00033 data_type = TRACK_VIDEO;
00034 draw = 1;
00035 }
00036
00037 VTrack::~VTrack()
00038 {
00039 }
00040
00041 int VTrack::create_objects()
00042 {
00043 Track::create_objects();
00044 automation = new VAutomation(edl, this);
00045 automation->create_objects();
00046 edits = new VEdits(edl, this);
00047 return 0;
00048 }
00049
00050
00051 void VTrack::synchronize_params(Track *track)
00052 {
00053 Track::synchronize_params(track);
00054
00055 VTrack *vtrack = (VTrack*)track;
00056 }
00057
00058
00059 int VTrack::copy_settings(Track *track)
00060 {
00061 Track::copy_settings(track);
00062
00063 VTrack *vtrack = (VTrack*)track;
00064 return 0;
00065 }
00066
00067 int VTrack::vertical_span(Theme *theme)
00068 {
00069 int track_h = Track::vertical_span(theme);
00070 int patch_h = 0;
00071 if(expand_view)
00072 {
00073 patch_h += theme->title_h + theme->play_h + theme->fade_h + theme->mode_h;
00074 }
00075 return MAX(track_h, patch_h);
00076 }
00077
00078
00079 PluginSet* VTrack::new_plugins()
00080 {
00081 return new VPluginSet(edl, this);
00082 }
00083
00084 int VTrack::load_defaults(BC_Hash *defaults)
00085 {
00086 Track::load_defaults(defaults);
00087 return 0;
00088 }
00089
00090 void VTrack::set_default_title()
00091 {
00092 Track *current = ListItem<Track>::owner->first;
00093 int i;
00094 for(i = 0; current; current = NEXT)
00095 {
00096 if(current->data_type == TRACK_VIDEO) i++;
00097 }
00098 sprintf(title, _("Video %d"), i);
00099 }
00100
00101 int64_t VTrack::to_units(double position, int round)
00102 {
00103 if(round)
00104 {
00105 return Units::round(position * edl->session->frame_rate);
00106 }
00107 else
00108 {
00109
00110 position *= edl->session->frame_rate;
00111 return Units::to_int64(position);
00112 }
00113 }
00114
00115 double VTrack::to_doubleunits(double position)
00116 {
00117 return position * edl->session->frame_rate;
00118 }
00119
00120
00121 double VTrack::from_units(int64_t position)
00122 {
00123 return (double)position / edl->session->frame_rate;
00124 }
00125
00126
00127
00128
00129 int VTrack::identical(int64_t sample1, int64_t sample2)
00130 {
00131
00132 if(labs(sample1 - sample2) <= 1) return 1; else return 0;
00133 }
00134
00135 int VTrack::save_header(FileXML *file)
00136 {
00137 file->tag.set_property("TYPE", "VIDEO");
00138 return 0;
00139 }
00140
00141 int VTrack::save_derived(FileXML *file)
00142 {
00143 return 0;
00144 }
00145
00146 int VTrack::load_header(FileXML *file, uint32_t load_flags)
00147 {
00148 return 0;
00149 }
00150
00151 int VTrack::load_derived(FileXML *file, uint32_t load_flags)
00152 {
00153 return 0;
00154 }
00155
00156
00157 int VTrack::direct_copy_possible(int64_t start, int direction, int use_nudge)
00158 {
00159 int i;
00160 if(use_nudge) start += nudge;
00161
00162
00163 if(track_w != edl->session->output_w || track_h != edl->session->output_h)
00164 return 0;
00165
00166
00167 if(!automation->direct_copy_possible(start, direction))
00168 return 0;
00169
00170
00171 if(plugin_used(start, direction))
00172 return 0;
00173
00174
00175 if(get_current_transition(start, direction, 0, 0))
00176 return 0;
00177
00178 return 1;
00179 }
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197 int VTrack::create_derived_objs(int flash)
00198 {
00199 int i;
00200 edits = new VEdits(edl, this);
00201 return 0;
00202 }
00203
00204
00205 int VTrack::get_dimensions(double &view_start,
00206 double &view_units,
00207 double &zoom_units)
00208 {
00209 view_start = edl->local_session->view_start * edl->session->frame_rate;
00210 view_units = 0;
00211
00212 zoom_units = edl->local_session->zoom_sample / edl->session->sample_rate * edl->session->frame_rate;
00213 }
00214
00215 int VTrack::copy_derived(int64_t start, int64_t end, FileXML *xml)
00216 {
00217
00218 return 0;
00219 }
00220
00221 int VTrack::copy_automation_derived(AutoConf *auto_conf, int64_t start, int64_t end, FileXML *file)
00222 {
00223 return 0;
00224 }
00225
00226 int VTrack::paste_derived(int64_t start, int64_t end, int64_t total_length, FileXML *xml, int ¤t_channel)
00227 {
00228 return 0;
00229 }
00230
00231 int VTrack::paste_output(int64_t startproject, int64_t endproject, int64_t startsource, int64_t endsource, int layer, Asset *asset)
00232 {
00233 return 0;
00234 }
00235
00236 int VTrack::clear_derived(int64_t start, int64_t end)
00237 {
00238 return 0;
00239 }
00240
00241 int VTrack::paste_automation_derived(int64_t start, int64_t end, int64_t total_length, FileXML *xml, int shift_autos, int ¤t_pan)
00242 {
00243 return 0;
00244 }
00245
00246 int VTrack::clear_automation_derived(AutoConf *auto_conf, int64_t start, int64_t end, int shift_autos)
00247 {
00248 return 0;
00249 }
00250
00251 int VTrack::draw_autos_derived(float view_start, float zoom_units, AutoConf *auto_conf)
00252 {
00253 return 0;
00254 }
00255
00256
00257 int VTrack::select_auto_derived(float zoom_units, float view_start, AutoConf *auto_conf, int cursor_x, int cursor_y)
00258 {
00259 return 0;
00260 }
00261
00262
00263 int VTrack::move_auto_derived(float zoom_units, float view_start, AutoConf *auto_conf, int cursor_x, int cursor_y, int shift_down)
00264 {
00265 return 0;
00266 }
00267
00268 int VTrack::draw_floating_autos_derived(float view_start, float zoom_units, AutoConf *auto_conf, int flash)
00269 {
00270 return 0;
00271 }
00272
00273 int VTrack::is_playable(int64_t position, int direction)
00274 {
00275 int result = 0;
00276 float in_x, in_y, in_w, in_h;
00277 float out_x, out_y, out_w, out_h;
00278
00279 calculate_output_transfer(position,
00280 direction,
00281 in_x, in_y, in_w, in_h,
00282 out_x, out_y, out_w, out_h);
00283
00284
00285
00286 if(out_w > 0 && out_h > 0)
00287 result = 1;
00288 return result;
00289 }
00290
00291 void VTrack::calculate_input_transfer(Asset *asset,
00292 int64_t position,
00293 int direction,
00294 float &in_x,
00295 float &in_y,
00296 float &in_w,
00297 float &in_h,
00298 float &out_x,
00299 float &out_y,
00300 float &out_w,
00301 float &out_h)
00302 {
00303 float auto_x, auto_y, auto_z;
00304 float camera_z = 1;
00305 float camera_x = asset->width / 2;
00306 float camera_y = asset->height / 2;
00307
00308 float z[6], x[6], y[6];
00309
00310
00311
00312
00313 automation->get_camera(&auto_x,
00314 &auto_y,
00315 &auto_z,
00316 position,
00317 direction);
00318
00319 camera_z *= auto_z;
00320 camera_x += auto_x;
00321 camera_y += auto_y;
00322
00323
00324 x[0] = camera_x - (float)track_w / 2 / camera_z;
00325 y[0] = camera_y - (float)track_h / 2 / camera_z;
00326 x[1] = x[0] + (float)track_w / camera_z;
00327 y[1] = y[0] + (float)track_h / camera_z;
00328
00329
00330 x[2] = 0;
00331 y[2] = 0;
00332 x[3] = track_w;
00333 y[3] = track_h;
00334
00335
00336 if(x[0] < 0)
00337 {
00338 x[2] -= x[0] * camera_z;
00339 x[0] = 0;
00340 }
00341 if(y[0] < 0)
00342 {
00343 y[2] -= y[0] * camera_z;
00344 y[0] = 0;
00345 }
00346 if(x[1] > asset->width)
00347 {
00348 x[3] -= (x[1] - asset->width) * camera_z;
00349 x[1] = asset->width;
00350 }
00351 if(y[1] > asset->height)
00352 {
00353 y[3] -= (y[1] - asset->height) * camera_z;
00354 y[1] = asset->height;
00355 }
00356
00357
00358 out_x = x[2];
00359 out_y = y[2];
00360 out_w = x[3] - x[2];
00361 out_h = y[3] - y[2];
00362
00363 in_x = x[0];
00364 in_y = y[0];
00365 in_w = x[1] - x[0];
00366 in_h = y[1] - y[0];
00367
00368
00369
00370 }
00371
00372 void VTrack::calculate_output_transfer(int64_t position,
00373 int direction,
00374 float &in_x,
00375 float &in_y,
00376 float &in_w,
00377 float &in_h,
00378 float &out_x,
00379 float &out_y,
00380 float &out_w,
00381 float &out_h)
00382 {
00383 float center_x, center_y, center_z;
00384 float x[4], y[4];
00385
00386 x[0] = 0;
00387 y[0] = 0;
00388 x[1] = track_w;
00389 y[1] = track_h;
00390
00391 automation->get_projector(¢er_x,
00392 ¢er_y,
00393 ¢er_z,
00394 position,
00395 direction);
00396
00397 center_x += edl->session->output_w / 2;
00398 center_y += edl->session->output_h / 2;
00399
00400 x[2] = center_x - (track_w / 2) * center_z;
00401 y[2] = center_y - (track_h / 2) * center_z;
00402 x[3] = x[2] + track_w * center_z;
00403 y[3] = y[2] + track_h * center_z;
00404
00405
00406 if(x[2] < 0)
00407 {
00408 x[0] -= (x[2] - 0) / center_z;
00409 x[2] = 0;
00410 }
00411 if(y[2] < 0)
00412 {
00413 y[0] -= (y[2] - 0) / center_z;
00414 y[2] = 0;
00415 }
00416 if(x[3] > edl->session->output_w)
00417 {
00418 x[1] -= (x[3] - edl->session->output_w) / center_z;
00419 x[3] = edl->session->output_w;
00420 }
00421 if(y[3] > edl->session->output_h)
00422 {
00423 y[1] -= (y[3] - edl->session->output_h) / center_z;
00424 y[3] = edl->session->output_h;
00425 }
00426
00427 in_x = x[0];
00428 in_y = y[0];
00429 in_w = x[1] - x[0];
00430 in_h = y[1] - y[0];
00431 out_x = x[2];
00432 out_y = y[2];
00433 out_w = x[3] - x[2];
00434 out_h = y[3] - y[2];
00435
00436
00437
00438 }
00439
00440
00441
00442 int VTrack::get_projection(float &in_x1,
00443 float &in_y1,
00444 float &in_x2,
00445 float &in_y2,
00446 float &out_x1,
00447 float &out_y1,
00448 float &out_x2,
00449 float &out_y2,
00450 int frame_w,
00451 int frame_h,
00452 int64_t real_position,
00453 int direction)
00454 {
00455 float center_x, center_y, center_z;
00456 float x[4], y[4];
00457
00458 automation->get_projector(¢er_x,
00459 ¢er_y,
00460 ¢er_z,
00461 real_position,
00462 direction);
00463
00464 x[0] = y[0] = 0;
00465 x[1] = frame_w;
00466 y[1] = frame_h;
00467
00468 center_x += edl->session->output_w / 2;
00469 center_y += edl->session->output_h / 2;
00470
00471 x[2] = center_x - (frame_w / 2) * center_z;
00472 y[2] = center_y - (frame_h / 2) * center_z;
00473 x[3] = x[2] + frame_w * center_z;
00474 y[3] = y[2] + frame_h * center_z;
00475
00476 if(x[2] < 0)
00477 {
00478 x[0] -= x[2] / center_z;
00479 x[2] = 0;
00480 }
00481 if(y[2] < 0)
00482 {
00483 y[0] -= y[2] / center_z;
00484 y[2] = 0;
00485 }
00486 if(x[3] > edl->session->output_w)
00487 {
00488 x[1] -= (x[3] - edl->session->output_w) / center_z;
00489 x[3] = edl->session->output_w;
00490 }
00491 if(y[3] > edl->session->output_h)
00492 {
00493 y[1] -= (y[3] - edl->session->output_h) / center_z;
00494 y[3] = edl->session->output_h;
00495 }
00496
00497 in_x1 = x[0];
00498 in_y1 = y[0];
00499 in_x2 = x[1];
00500 in_y2 = y[1];
00501 out_x1 = x[2];
00502 out_y1 = y[2];
00503 out_x2 = x[3];
00504 out_y2 = y[3];
00505 return 0;
00506 }
00507
00508
00509 void VTrack::translate(float offset_x, float offset_y, int do_camera)
00510 {
00511 int subscript;
00512 if(do_camera)
00513 subscript = AUTOMATION_CAMERA_X;
00514 else
00515 subscript = AUTOMATION_PROJECTOR_X;
00516
00517
00518 ((FloatAuto*)automation->autos[subscript]->default_auto)->value += offset_x;
00519 ((FloatAuto*)automation->autos[subscript + 1]->default_auto)->value += offset_y;
00520
00521
00522 for(Auto *current = automation->autos[subscript]->first;
00523 current;
00524 current = NEXT)
00525 {
00526 ((FloatAuto*)current)->value += offset_x;
00527 }
00528
00529 for(Auto *current = automation->autos[subscript + 1]->first;
00530 current;
00531 current = NEXT)
00532 {
00533 ((FloatAuto*)current)->value += offset_y;
00534 }
00535 }
00536
00537
00538
00539
00540
00541
00542
00543
00544