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(Defaults *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::channel_is_playable(int64_t position, int direction, int *do_channel)
00274 {
00275 int result = 0;
00276
00277 for(int i = 0; i < edl->session->video_channels && !result; i++)
00278 {
00279 if(do_channel[i])
00280 {
00281 float in_x, in_y, in_w, in_h;
00282 float out_x, out_y, out_w, out_h;
00283
00284 calculate_output_transfer(i, position, direction,
00285 in_x, in_y, in_w, in_h,
00286 out_x, out_y, out_w, out_h);
00287
00288
00289
00290 if(out_w > 0 && out_h > 0)
00291 result = 1;
00292 }
00293 }
00294 return result;
00295 }
00296
00297 void VTrack::calculate_input_transfer(Asset *asset,
00298 int64_t position,
00299 int direction,
00300 float &in_x,
00301 float &in_y,
00302 float &in_w,
00303 float &in_h,
00304 float &out_x,
00305 float &out_y,
00306 float &out_w,
00307 float &out_h)
00308 {
00309 float auto_x, auto_y, auto_z;
00310 float camera_z = 1;
00311 float camera_x = asset->width / 2;
00312 float camera_y = asset->height / 2;
00313
00314 float z[6], x[6], y[6];
00315
00316
00317
00318
00319 automation->get_camera(&auto_x,
00320 &auto_y,
00321 &auto_z,
00322 position,
00323 direction);
00324
00325 camera_z *= auto_z;
00326 camera_x += auto_x;
00327 camera_y += auto_y;
00328
00329
00330 x[0] = camera_x - (float)track_w / 2 / camera_z;
00331 y[0] = camera_y - (float)track_h / 2 / camera_z;
00332 x[1] = x[0] + (float)track_w / camera_z;
00333 y[1] = y[0] + (float)track_h / camera_z;
00334
00335
00336 x[2] = 0;
00337 y[2] = 0;
00338 x[3] = track_w;
00339 y[3] = track_h;
00340
00341
00342 if(x[0] < 0)
00343 {
00344 x[2] -= x[0] * camera_z;
00345 x[0] = 0;
00346 }
00347 if(y[0] < 0)
00348 {
00349 y[2] -= y[0] * camera_z;
00350 y[0] = 0;
00351 }
00352 if(x[1] > asset->width)
00353 {
00354 x[3] -= (x[1] - asset->width) * camera_z;
00355 x[1] = asset->width;
00356 }
00357 if(y[1] > asset->height)
00358 {
00359 y[3] -= (y[1] - asset->height) * camera_z;
00360 y[1] = asset->height;
00361 }
00362
00363
00364 out_x = x[2];
00365 out_y = y[2];
00366 out_w = x[3] - x[2];
00367 out_h = y[3] - y[2];
00368
00369 in_x = x[0];
00370 in_y = y[0];
00371 in_w = x[1] - x[0];
00372 in_h = y[1] - y[0];
00373
00374
00375
00376 }
00377
00378 void VTrack::calculate_output_transfer(int channel,
00379 int64_t position,
00380 int direction,
00381 float &in_x,
00382 float &in_y,
00383 float &in_w,
00384 float &in_h,
00385 float &out_x,
00386 float &out_y,
00387 float &out_w,
00388 float &out_h)
00389 {
00390 float center_x, center_y, center_z;
00391 float x[4], y[4];
00392 float channel_x1 = edl->session->vchannel_x[channel];
00393 float channel_y1 = edl->session->vchannel_y[channel];
00394 float channel_x2 = channel_x1 + edl->session->output_w;
00395 float channel_y2 = channel_y1 + edl->session->output_h;
00396
00397 x[0] = 0;
00398 y[0] = 0;
00399 x[1] = track_w;
00400 y[1] = track_h;
00401
00402 automation->get_projector(¢er_x,
00403 ¢er_y,
00404 ¢er_z,
00405 position,
00406 direction);
00407
00408 center_x += edl->session->output_w / 2;
00409 center_y += edl->session->output_h / 2;
00410
00411 x[2] = center_x - (track_w / 2) * center_z;
00412 y[2] = center_y - (track_h / 2) * center_z;
00413 x[3] = x[2] + track_w * center_z;
00414 y[3] = y[2] + track_h * center_z;
00415
00416
00417 if(x[2] < channel_x1)
00418 {
00419 x[0] -= (x[2] - channel_x1) / center_z;
00420 x[2] = channel_x1;
00421 }
00422 if(y[2] < 0)
00423 {
00424 y[0] -= (y[2] - channel_y1) / center_z;
00425 y[2] = 0;
00426 }
00427 if(x[3] > channel_x2)
00428 {
00429 x[1] -= (x[3] - channel_x2) / center_z;
00430 x[3] = channel_x2;
00431 }
00432 if(y[3] > channel_y2)
00433 {
00434 y[1] -= (y[3] - channel_y2) / center_z;
00435 y[3] = channel_y2;
00436 }
00437
00438 in_x = x[0];
00439 in_y = y[0];
00440 in_w = x[1] - x[0];
00441 in_h = y[1] - y[0];
00442 out_x = x[2];
00443 out_y = y[2];
00444 out_w = x[3] - x[2];
00445 out_h = y[3] - y[2];
00446
00447
00448
00449 }
00450
00451
00452
00453 int VTrack::get_projection(int channel,
00454 float &in_x1,
00455 float &in_y1,
00456 float &in_x2,
00457 float &in_y2,
00458 float &out_x1,
00459 float &out_y1,
00460 float &out_x2,
00461 float &out_y2,
00462 int frame_w,
00463 int frame_h,
00464 int64_t real_position,
00465 int direction)
00466 {
00467 float center_x, center_y, center_z;
00468 float x[4], y[4];
00469
00470 automation->get_projector(¢er_x,
00471 ¢er_y,
00472 ¢er_z,
00473 real_position,
00474 direction);
00475
00476 x[0] = y[0] = 0;
00477 x[1] = frame_w;
00478 y[1] = frame_h;
00479
00480 center_x += edl->session->output_w / 2;
00481 center_y += edl->session->output_h / 2;
00482
00483 x[2] = center_x - (frame_w / 2) * center_z;
00484 y[2] = center_y - (frame_h / 2) * center_z;
00485 x[3] = x[2] + frame_w * center_z;
00486 y[3] = y[2] + frame_h * center_z;
00487
00488 if(x[2] < 0)
00489 {
00490 x[0] -= x[2] / center_z;
00491 x[2] = 0;
00492 }
00493 if(y[2] < 0)
00494 {
00495 y[0] -= y[2] / center_z;
00496 y[2] = 0;
00497 }
00498 if(x[3] > edl->session->output_w)
00499 {
00500 x[1] -= (x[3] - edl->session->output_w) / center_z;
00501 x[3] = edl->session->output_w;
00502 }
00503 if(y[3] > edl->session->output_h)
00504 {
00505 y[1] -= (y[3] - edl->session->output_h) / center_z;
00506 y[3] = edl->session->output_h;
00507 }
00508
00509 in_x1 = x[0];
00510 in_y1 = y[0];
00511 in_x2 = x[1];
00512 in_y2 = y[1];
00513 out_x1 = x[2];
00514 out_y1 = y[2];
00515 out_x2 = x[3];
00516 out_y2 = y[3];
00517 return 0;
00518 }
00519
00520
00521 void VTrack::translate(float offset_x, float offset_y, int do_camera)
00522 {
00523 int subscript;
00524 if(do_camera)
00525 subscript = AUTOMATION_CAMERA_X;
00526 else
00527 subscript = AUTOMATION_PROJECTOR_X;
00528
00529
00530 ((FloatAuto*)automation->autos[subscript]->default_auto)->value += offset_x;
00531 ((FloatAuto*)automation->autos[subscript + 1]->default_auto)->value += offset_y;
00532
00533
00534 for(Auto *current = automation->autos[subscript]->first;
00535 current;
00536 current = NEXT)
00537 {
00538 ((FloatAuto*)current)->value += offset_x;
00539 }
00540
00541 for(Auto *current = automation->autos[subscript + 1]->first;
00542 current;
00543 current = NEXT)
00544 {
00545 ((FloatAuto*)current)->value += offset_y;
00546 }
00547 }
00548
00549
00550
00551
00552
00553
00554
00555
00556