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(Defaults *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::channel_is_playable(int64_t position, int direction, int *do_channel)
276 //printf("VTrack::channel_is_playable 1 %d\n", do_channel[0]);
277 for(int i = 0; i < edl->session->video_channels && !result; i++)
281 float in_x, in_y, in_w, in_h;
282 float out_x, out_y, out_w, out_h;
284 calculate_output_transfer(i, position, direction,
285 in_x, in_y, in_w, in_h,
286 out_x, out_y, out_w, out_h);
288 //printf("VTrack::channel_is_playable %0.0f %0.0f %0.0f %0.0f %0.0f %0.0f %0.0f %0.0f\n",
289 //in_x, in_y, in_w, in_h, out_x, out_y, out_w, out_h);
290 if(out_w > 0 && out_h > 0)
297 void VTrack::calculate_input_transfer(Asset *asset,
309 float auto_x, auto_y, auto_z;
311 float camera_x = asset->width / 2;
312 float camera_y = asset->height / 2;
313 // camera and output coords
314 float z[6], x[6], y[6];
316 //printf("VTrack::calculate_input_transfer %lld\n", position);
318 // get camera center in asset
319 automation->get_camera(&auto_x,
329 // get camera coords on asset
330 x[0] = camera_x - (float)track_w / 2 / camera_z;
331 y[0] = camera_y - (float)track_h / 2 / camera_z;
332 x[1] = x[0] + (float)track_w / camera_z;
333 y[1] = y[0] + (float)track_h / camera_z;
335 // get asset coords on camera
341 // crop asset coords on camera
344 x[2] -= x[0] * camera_z;
349 y[2] -= y[0] * camera_z;
352 if(x[1] > asset->width)
354 x[3] -= (x[1] - asset->width) * camera_z;
357 if(y[1] > asset->height)
359 y[3] -= (y[1] - asset->height) * camera_z;
360 y[1] = asset->height;
363 // get output bounding box
373 // printf("VTrack::calculate_input_transfer %f %f %f %f -> %f %f %f %f\n",
374 // in_x, in_y, in_w, in_h,
375 // out_x, out_y, out_w, out_h);
378 void VTrack::calculate_output_transfer(int channel,
390 float center_x, center_y, center_z;
392 float channel_x1 = edl->session->vchannel_x[channel];
393 float channel_y1 = edl->session->vchannel_y[channel];
394 float channel_x2 = channel_x1 + edl->session->output_w;
395 float channel_y2 = channel_y1 + edl->session->output_h;
402 automation->get_projector(¢er_x,
408 center_x += edl->session->output_w / 2;
409 center_y += edl->session->output_h / 2;
411 x[2] = center_x - (track_w / 2) * center_z;
412 y[2] = center_y - (track_h / 2) * center_z;
413 x[3] = x[2] + track_w * center_z;
414 y[3] = y[2] + track_h * center_z;
416 // Clip to boundaries of channel
417 if(x[2] < channel_x1)
419 x[0] -= (x[2] - channel_x1) / center_z;
424 y[0] -= (y[2] - channel_y1) / center_z;
427 if(x[3] > channel_x2)
429 x[1] -= (x[3] - channel_x2) / center_z;
432 if(y[3] > channel_y2)
434 y[1] -= (y[3] - channel_y2) / center_z;
446 // printf("VTrack::calculate_output_transfer %f %f %f %f -> %f %f %f %f\n",
447 // in_x, in_y, in_w, in_h,
448 // out_x, out_y, out_w, out_h);
453 int VTrack::get_projection(int channel,
464 int64_t real_position,
467 float center_x, center_y, center_z;
470 automation->get_projector(¢er_x,
480 center_x += edl->session->output_w / 2;
481 center_y += edl->session->output_h / 2;
483 x[2] = center_x - (frame_w / 2) * center_z;
484 y[2] = center_y - (frame_h / 2) * center_z;
485 x[3] = x[2] + frame_w * center_z;
486 y[3] = y[2] + frame_h * center_z;
490 x[0] -= x[2] / center_z;
495 y[0] -= y[2] / center_z;
498 if(x[3] > edl->session->output_w)
500 x[1] -= (x[3] - edl->session->output_w) / center_z;
501 x[3] = edl->session->output_w;
503 if(y[3] > edl->session->output_h)
505 y[1] -= (y[3] - edl->session->output_h) / center_z;
506 y[3] = edl->session->output_h;
521 void VTrack::translate(float offset_x, float offset_y, int do_camera)
525 subscript = AUTOMATION_CAMERA_X;
527 subscript = AUTOMATION_PROJECTOR_X;
529 // Translate default keyframe
530 ((FloatAuto*)automation->autos[subscript]->default_auto)->value += offset_x;
531 ((FloatAuto*)automation->autos[subscript + 1]->default_auto)->value += offset_y;
533 // Translate everyone else
534 for(Auto *current = automation->autos[subscript]->first;
538 ((FloatAuto*)current)->value += offset_x;
541 for(Auto *current = automation->autos[subscript + 1]->first;
545 ((FloatAuto*)current)->value += offset_y;