9 #include "edlsession.h"
11 #include "floatauto.h"
12 #include "floatautos.h"
14 #include "localsession.h"
16 #include "mainsession.h"
18 #include "trackcanvas.h"
20 #include "transportque.inc"
22 #include "vautomation.h"
27 #include "vpluginset.h"
30 VTrack::VTrack(EDL *edl, Tracks *tracks)
33 data_type = TRACK_VIDEO;
41 int VTrack::create_objects()
43 Track::create_objects();
44 automation = new VAutomation(edl, this);
45 automation->create_objects();
46 edits = new VEdits(edl, this);
50 // Used by PlaybackEngine
51 void VTrack::synchronize_params(Track *track)
53 Track::synchronize_params(track);
55 VTrack *vtrack = (VTrack*)track;
58 // Used by EDL::operator=
59 int VTrack::copy_settings(Track *track)
61 Track::copy_settings(track);
63 VTrack *vtrack = (VTrack*)track;
67 int VTrack::vertical_span(Theme *theme)
69 int track_h = Track::vertical_span(theme);
73 patch_h += theme->title_h + theme->play_h + theme->fade_h + theme->mode_h;
75 return MAX(track_h, patch_h);
79 PluginSet* VTrack::new_plugins()
81 return new VPluginSet(edl, this);
84 int VTrack::load_defaults(BC_Hash *defaults)
86 Track::load_defaults(defaults);
90 void VTrack::set_default_title()
92 Track *current = ListItem<Track>::owner->first;
94 for(i = 0; current; current = NEXT)
96 if(current->data_type == TRACK_VIDEO) i++;
98 sprintf(title, _("Video %d"), i);
101 int64_t VTrack::to_units(double position, int round)
105 return Units::round(position * edl->session->frame_rate);
109 // Kludge for rounding errors, just on a smaller scale than formal rounding
110 position *= edl->session->frame_rate;
111 return Units::to_int64(position);
115 double VTrack::to_doubleunits(double position)
117 return position * edl->session->frame_rate;
121 double VTrack::from_units(int64_t position)
123 return (double)position / edl->session->frame_rate;
129 int VTrack::identical(int64_t sample1, int64_t sample2)
132 if(labs(sample1 - sample2) <= 1) return 1; else return 0;
135 int VTrack::save_header(FileXML *file)
137 file->tag.set_property("TYPE", "VIDEO");
141 int VTrack::save_derived(FileXML *file)
146 int VTrack::load_header(FileXML *file, uint32_t load_flags)
151 int VTrack::load_derived(FileXML *file, uint32_t load_flags)
157 int VTrack::direct_copy_possible(int64_t start, int direction, int use_nudge)
160 if(use_nudge) start += nudge;
162 // Track size must equal output size
163 if(track_w != edl->session->output_w || track_h != edl->session->output_h)
166 // No automation must be present in the track
167 if(!automation->direct_copy_possible(start, direction))
170 // No plugin must be present
171 if(plugin_used(start, direction))
175 if(get_current_transition(start, direction, 0, 0))
197 int VTrack::create_derived_objs(int flash)
200 edits = new VEdits(edl, this);
205 int VTrack::get_dimensions(double &view_start,
209 view_start = edl->local_session->view_start * edl->session->frame_rate;
211 // view_units = Units::toframes(tracks->view_samples(), mwindow->session->sample_rate, mwindow->session->frame_rate);
212 zoom_units = edl->local_session->zoom_sample / edl->session->sample_rate * edl->session->frame_rate;
215 int VTrack::copy_derived(int64_t start, int64_t end, FileXML *xml)
217 // automation is copied in the Track::copy
221 int VTrack::copy_automation_derived(AutoConf *auto_conf, int64_t start, int64_t end, FileXML *file)
226 int VTrack::paste_derived(int64_t start, int64_t end, int64_t total_length, FileXML *xml, int ¤t_channel)
231 int VTrack::paste_output(int64_t startproject, int64_t endproject, int64_t startsource, int64_t endsource, int layer, Asset *asset)
236 int VTrack::clear_derived(int64_t start, int64_t end)
241 int VTrack::paste_automation_derived(int64_t start, int64_t end, int64_t total_length, FileXML *xml, int shift_autos, int ¤t_pan)
246 int VTrack::clear_automation_derived(AutoConf *auto_conf, int64_t start, int64_t end, int shift_autos)
251 int VTrack::draw_autos_derived(float view_start, float zoom_units, AutoConf *auto_conf)
257 int VTrack::select_auto_derived(float zoom_units, float view_start, AutoConf *auto_conf, int cursor_x, int cursor_y)
263 int VTrack::move_auto_derived(float zoom_units, float view_start, AutoConf *auto_conf, int cursor_x, int cursor_y, int shift_down)
268 int VTrack::draw_floating_autos_derived(float view_start, float zoom_units, AutoConf *auto_conf, int flash)
273 int VTrack::is_playable(int64_t position, int direction)
276 float in_x, in_y, in_w, in_h;
277 float out_x, out_y, out_w, out_h;
279 calculate_output_transfer(position,
281 in_x, in_y, in_w, in_h,
282 out_x, out_y, out_w, out_h);
284 //printf("VTrack::is_playable %0.0f %0.0f %0.0f %0.0f %0.0f %0.0f %0.0f %0.0f\n",
285 //in_x, in_y, in_w, in_h, out_x, out_y, out_w, out_h);
286 if(out_w > 0 && out_h > 0)
291 void VTrack::calculate_input_transfer(Asset *asset,
303 float auto_x, auto_y, auto_z;
305 float camera_x = asset->width / 2;
306 float camera_y = asset->height / 2;
307 // camera and output coords
308 float z[6], x[6], y[6];
310 //printf("VTrack::calculate_input_transfer %lld\n", position);
312 // get camera center in asset
313 automation->get_camera(&auto_x,
323 // get camera coords on asset
324 x[0] = camera_x - (float)track_w / 2 / camera_z;
325 y[0] = camera_y - (float)track_h / 2 / camera_z;
326 x[1] = x[0] + (float)track_w / camera_z;
327 y[1] = y[0] + (float)track_h / camera_z;
329 // get asset coords on camera
335 // crop asset coords on camera
338 x[2] -= x[0] * camera_z;
343 y[2] -= y[0] * camera_z;
346 if(x[1] > asset->width)
348 x[3] -= (x[1] - asset->width) * camera_z;
351 if(y[1] > asset->height)
353 y[3] -= (y[1] - asset->height) * camera_z;
354 y[1] = asset->height;
357 // get output bounding box
367 // printf("VTrack::calculate_input_transfer %f %f %f %f -> %f %f %f %f\n",
368 // in_x, in_y, in_w, in_h,
369 // out_x, out_y, out_w, out_h);
372 void VTrack::calculate_output_transfer(int64_t position,
383 float center_x, center_y, center_z;
391 automation->get_projector(¢er_x,
397 center_x += edl->session->output_w / 2;
398 center_y += edl->session->output_h / 2;
400 x[2] = center_x - (track_w / 2) * center_z;
401 y[2] = center_y - (track_h / 2) * center_z;
402 x[3] = x[2] + track_w * center_z;
403 y[3] = y[2] + track_h * center_z;
405 // Clip to boundaries of output
408 x[0] -= (x[2] - 0) / center_z;
413 y[0] -= (y[2] - 0) / center_z;
416 if(x[3] > edl->session->output_w)
418 x[1] -= (x[3] - edl->session->output_w) / center_z;
419 x[3] = edl->session->output_w;
421 if(y[3] > edl->session->output_h)
423 y[1] -= (y[3] - edl->session->output_h) / center_z;
424 y[3] = edl->session->output_h;
435 // printf("VTrack::calculate_output_transfer %f %f %f %f -> %f %f %f %f\n",
436 // in_x, in_y, in_w, in_h,
437 // out_x, out_y, out_w, out_h);
442 int VTrack::get_projection(float &in_x1,
452 int64_t real_position,
455 float center_x, center_y, center_z;
458 automation->get_projector(¢er_x,
468 center_x += edl->session->output_w / 2;
469 center_y += edl->session->output_h / 2;
471 x[2] = center_x - (frame_w / 2) * center_z;
472 y[2] = center_y - (frame_h / 2) * center_z;
473 x[3] = x[2] + frame_w * center_z;
474 y[3] = y[2] + frame_h * center_z;
478 x[0] -= x[2] / center_z;
483 y[0] -= y[2] / center_z;
486 if(x[3] > edl->session->output_w)
488 x[1] -= (x[3] - edl->session->output_w) / center_z;
489 x[3] = edl->session->output_w;
491 if(y[3] > edl->session->output_h)
493 y[1] -= (y[3] - edl->session->output_h) / center_z;
494 y[3] = edl->session->output_h;
509 void VTrack::translate(float offset_x, float offset_y, int do_camera)
513 subscript = AUTOMATION_CAMERA_X;
515 subscript = AUTOMATION_PROJECTOR_X;
517 // Translate default keyframe
518 ((FloatAuto*)automation->autos[subscript]->default_auto)->value += offset_x;
519 ((FloatAuto*)automation->autos[subscript + 1]->default_auto)->value += offset_y;
521 // Translate everyone else
522 for(Auto *current = automation->autos[subscript]->first;
526 ((FloatAuto*)current)->value += offset_x;
529 for(Auto *current = automation->autos[subscript + 1]->first;
533 ((FloatAuto*)current)->value += offset_y;