3 #include "bezierauto.h"
4 #include "bezierautos.h"
11 #include "edlsession.h"
13 #include "floatautos.h"
15 #include "localsession.h"
17 #include "mainsession.h"
19 #include "trackcanvas.h"
21 #include "transportque.inc"
23 #include "vautomation.h"
28 #include "vpluginset.h"
31 VTrack::VTrack(EDL *edl, Tracks *tracks)
34 data_type = TRACK_VIDEO;
42 int VTrack::create_objects()
44 Track::create_objects();
45 automation = new VAutomation(edl, this);
46 automation->create_objects();
47 edits = new VEdits(edl, this);
51 // Used by PlaybackEngine
52 void VTrack::synchronize_params(Track *track)
54 Track::synchronize_params(track);
56 VTrack *vtrack = (VTrack*)track;
59 // Used by EDL::operator=
60 int VTrack::copy_settings(Track *track)
62 Track::copy_settings(track);
64 VTrack *vtrack = (VTrack*)track;
68 int VTrack::vertical_span(Theme *theme)
70 int track_h = Track::vertical_span(theme);
74 patch_h += theme->title_h + theme->play_h + theme->fade_h + theme->mode_h;
76 return MAX(track_h, patch_h);
80 PluginSet* VTrack::new_plugins()
82 return new VPluginSet(edl, this);
85 int VTrack::load_defaults(Defaults *defaults)
87 Track::load_defaults(defaults);
91 void VTrack::set_default_title()
93 Track *current = ListItem<Track>::owner->first;
95 for(i = 0; current; current = NEXT)
97 if(current->data_type == TRACK_VIDEO) i++;
99 sprintf(title, _("Video %d"), i);
102 int64_t VTrack::to_units(double position, int round)
106 return Units::round(position * edl->session->frame_rate);
110 // Kludge for rounding errors, just on a smaller scale than formal rounding
111 position *= edl->session->frame_rate;
112 return Units::to_int64(position);
116 double VTrack::to_doubleunits(double position)
118 return position * edl->session->frame_rate;
122 double VTrack::from_units(int64_t position)
124 return (double)position / edl->session->frame_rate;
130 int VTrack::identical(int64_t sample1, int64_t sample2)
133 if(labs(sample1 - sample2) <= 1) return 1; else return 0;
136 int VTrack::save_header(FileXML *file)
138 file->tag.set_property("TYPE", "VIDEO");
142 int VTrack::save_derived(FileXML *file)
147 int VTrack::load_header(FileXML *file, uint32_t load_flags)
152 int VTrack::load_derived(FileXML *file, uint32_t load_flags)
158 int VTrack::direct_copy_possible(int64_t start, int direction, int use_nudge)
161 if(use_nudge) start += nudge;
163 // Track size must equal output size
164 if(track_w != edl->session->output_w || track_h != edl->session->output_h)
167 // No automation must be present in the track
168 if(!automation->direct_copy_possible(start, direction))
171 // No plugin must be present
172 if(plugin_used(start, direction))
176 if(get_current_transition(start, direction, 0, 0))
198 int VTrack::create_derived_objs(int flash)
201 edits = new VEdits(edl, this);
206 int VTrack::get_dimensions(double &view_start,
210 view_start = edl->local_session->view_start * edl->session->frame_rate;
212 // view_units = Units::toframes(tracks->view_samples(), mwindow->session->sample_rate, mwindow->session->frame_rate);
213 zoom_units = edl->local_session->zoom_sample / edl->session->sample_rate * edl->session->frame_rate;
216 int VTrack::copy_derived(int64_t start, int64_t end, FileXML *xml)
218 // automation is copied in the Track::copy
222 int VTrack::copy_automation_derived(AutoConf *auto_conf, int64_t start, int64_t end, FileXML *file)
227 int VTrack::paste_derived(int64_t start, int64_t end, int64_t total_length, FileXML *xml, int ¤t_channel)
232 int VTrack::paste_output(int64_t startproject, int64_t endproject, int64_t startsource, int64_t endsource, int layer, Asset *asset)
237 int VTrack::clear_derived(int64_t start, int64_t end)
242 int VTrack::paste_automation_derived(int64_t start, int64_t end, int64_t total_length, FileXML *xml, int shift_autos, int ¤t_pan)
247 int VTrack::clear_automation_derived(AutoConf *auto_conf, int64_t start, int64_t end, int shift_autos)
252 int VTrack::draw_autos_derived(float view_start, float zoom_units, AutoConf *auto_conf)
258 int VTrack::select_auto_derived(float zoom_units, float view_start, AutoConf *auto_conf, int cursor_x, int cursor_y)
264 int VTrack::move_auto_derived(float zoom_units, float view_start, AutoConf *auto_conf, int cursor_x, int cursor_y, int shift_down)
269 int VTrack::draw_floating_autos_derived(float view_start, float zoom_units, AutoConf *auto_conf, int flash)
274 int VTrack::channel_is_playable(int64_t position, int direction, int *do_channel)
277 //printf("VTrack::channel_is_playable 1 %d\n", do_channel[0]);
278 for(int i = 0; i < edl->session->video_channels && !result; i++)
282 float in_x, in_y, in_w, in_h;
283 float out_x, out_y, out_w, out_h;
285 calculate_output_transfer(i, position, direction,
286 in_x, in_y, in_w, in_h,
287 out_x, out_y, out_w, out_h);
289 //printf("VTrack::channel_is_playable %0.0f %0.0f %0.0f %0.0f %0.0f %0.0f %0.0f %0.0f\n",
290 //in_x, in_y, in_w, in_h, out_x, out_y, out_w, out_h);
291 if(out_w > 0 && out_h > 0)
298 void VTrack::calculate_input_transfer(Asset *asset,
310 float auto_x, auto_y, auto_z;
311 BezierAuto *before = 0, *after = 0;
312 FloatAuto *previous = 0, *next = 0;
314 float camera_x = asset->width / 2;
315 float camera_y = asset->height / 2;
316 float z[6], x[6], y[6]; // camera and output coords
318 //printf("VTrack::calculate_input_transfer %lld\n", position);
320 // get camera center in asset
321 automation->camera_autos->get_center(auto_x,
328 auto_z = automation->czoom_autos->get_value(position,
337 // get camera coords on asset
338 x[0] = camera_x - (float)track_w / 2 / camera_z;
339 y[0] = camera_y - (float)track_h / 2 / camera_z;
340 x[1] = x[0] + (float)track_w / camera_z;
341 y[1] = y[0] + (float)track_h / camera_z;
343 // get asset coords on camera
349 // crop asset coords on camera
352 x[2] -= x[0] * camera_z;
357 y[2] -= y[0] * camera_z;
360 if(x[1] > asset->width)
362 x[3] -= (x[1] - asset->width) * camera_z;
365 if(y[1] > asset->height)
367 y[3] -= (y[1] - asset->height) * camera_z;
368 y[1] = asset->height;
371 // get output bounding box
383 void VTrack::calculate_output_transfer(int channel,
395 BezierAuto *before = 0, *after = 0;
396 FloatAuto *previous = 0, *next = 0;
397 float center_x, center_y, center_z;
399 float channel_x1 = edl->session->vchannel_x[channel];
400 float channel_y1 = edl->session->vchannel_y[channel];
401 float channel_x2 = channel_x1 + edl->session->output_w;
402 float channel_y2 = channel_y1 + edl->session->output_h;
409 automation->projector_autos->get_center(center_x,
416 center_z = automation->pzoom_autos->get_value(position,
421 center_x += edl->session->output_w / 2;
422 center_y += edl->session->output_h / 2;
424 x[2] = center_x - (track_w / 2) * center_z;
425 y[2] = center_y - (track_h / 2) * center_z;
426 x[3] = x[2] + track_w * center_z;
427 y[3] = y[2] + track_h * center_z;
429 // Clip to boundaries of channel
430 if(x[2] < channel_x1)
432 x[0] -= (x[2] - channel_x1) / center_z;
437 y[0] -= (y[2] - channel_y1) / center_z;
440 if(x[3] > channel_x2)
442 x[1] -= (x[3] - channel_x2) / center_z;
445 if(y[3] > channel_y2)
447 y[1] -= (y[3] - channel_y2) / center_z;
463 int VTrack::get_projection(int channel,
474 int64_t real_position,
477 float center_x, center_y, center_z;
479 BezierAuto *before = 0, *after = 0;
480 FloatAuto *previous = 0, *next = 0;
482 automation->projector_autos->get_center(center_x,
489 center_z = automation->pzoom_autos->get_value(real_position,
498 center_x += edl->session->output_w / 2;
499 center_y += edl->session->output_h / 2;
501 x[2] = center_x - (frame_w / 2) * center_z;
502 y[2] = center_y - (frame_h / 2) * center_z;
503 x[3] = x[2] + frame_w * center_z;
504 y[3] = y[2] + frame_h * center_z;
508 x[0] -= x[2] / center_z;
513 y[0] -= y[2] / center_z;
516 if(x[3] > edl->session->output_w)
518 x[1] -= (x[3] - edl->session->output_w) / center_z;
519 x[3] = edl->session->output_w;
521 if(y[3] > edl->session->output_h)
523 y[1] -= (y[3] - edl->session->output_h) / center_z;
524 y[3] = edl->session->output_h;
539 void VTrack::translate_camera(float offset_x, float offset_y)
541 ((BezierAuto*)automation->camera_autos->default_auto)->center_x += offset_x;
542 ((BezierAuto*)automation->camera_autos->default_auto)->center_y += offset_y;
544 for(Auto *current = automation->camera_autos->first;
548 ((BezierAuto*)current)->center_x += offset_x;
549 ((BezierAuto*)current)->center_y += offset_y;
553 void VTrack::translate_projector(float offset_x, float offset_y)
555 ((BezierAuto*)automation->projector_autos->default_auto)->center_x += offset_x;
556 ((BezierAuto*)automation->projector_autos->default_auto)->center_y += offset_y;
558 for(Auto *current = automation->projector_autos->first;
562 ((BezierAuto*)current)->center_x += offset_x;
563 ((BezierAuto*)current)->center_y += offset_y;