3 #include "bezierauto.h"
4 #include "bezierautos.h"
11 #include "edlsession.h"
13 #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"
31 #define _(String) gettext(String)
32 #define gettext_noop(String) String
33 #define N_(String) gettext_noop (String)
35 VTrack::VTrack(EDL *edl, Tracks *tracks)
38 data_type = TRACK_VIDEO;
46 int VTrack::create_objects()
48 Track::create_objects();
49 automation = new VAutomation(edl, this);
50 automation->create_objects();
51 edits = new VEdits(edl, this);
55 // Used by PlaybackEngine
56 void VTrack::synchronize_params(Track *track)
58 Track::synchronize_params(track);
60 VTrack *vtrack = (VTrack*)track;
63 // Used by EDL::operator=
64 int VTrack::copy_settings(Track *track)
66 Track::copy_settings(track);
68 VTrack *vtrack = (VTrack*)track;
72 int VTrack::vertical_span(Theme *theme)
74 int track_h = Track::vertical_span(theme);
78 patch_h += theme->title_h + theme->play_h + theme->fade_h + theme->mode_h;
80 return MAX(track_h, patch_h);
84 PluginSet* VTrack::new_plugins()
86 return new VPluginSet(edl, this);
89 int VTrack::load_defaults(Defaults *defaults)
91 Track::load_defaults(defaults);
95 void VTrack::set_default_title()
97 Track *current = ListItem<Track>::owner->first;
99 for(i = 0; current; current = NEXT)
101 if(current->data_type == TRACK_VIDEO) i++;
103 sprintf(title, _("Video %d"), i);
106 int64_t VTrack::to_units(double position, int round)
110 return Units::round(position * edl->session->frame_rate);
114 // Kludge for rounding errors, just on a smaller scale than formal rounding
115 position *= edl->session->frame_rate;
116 return Units::to_int64(position);
120 double VTrack::to_doubleunits(double position)
122 return position * edl->session->frame_rate;
126 double VTrack::from_units(int64_t position)
128 return (double)position / edl->session->frame_rate;
134 int VTrack::identical(int64_t sample1, int64_t sample2)
137 if(labs(sample1 - sample2) <= 1) return 1; else return 0;
140 int VTrack::save_header(FileXML *file)
142 file->tag.set_property("TYPE", "VIDEO");
146 int VTrack::save_derived(FileXML *file)
151 int VTrack::load_header(FileXML *file, uint32_t load_flags)
156 int VTrack::load_derived(FileXML *file, uint32_t load_flags)
162 int VTrack::direct_copy_possible(int64_t start, int direction)
166 // Track size must equal output size
167 if(track_w != edl->session->output_w || track_h != edl->session->output_h)
170 // No automation must be present in the track
171 //printf("VTrack::direct_copy_possible 1\n");
172 if(!automation->direct_copy_possible(start, direction))
174 //printf("VTrack::direct_copy_possible 2\n");
176 // No plugin must be present
177 if(plugin_used(start, direction))
180 //printf("VTrack::direct_copy_possible 3\n");
182 if(get_current_transition(start, direction, 0))
184 //printf("VTrack::direct_copy_possible 4\n");
205 int VTrack::create_derived_objs(int flash)
208 edits = new VEdits(edl, this);
213 int VTrack::get_dimensions(double &view_start,
217 view_start = edl->local_session->view_start * edl->session->frame_rate;
219 // view_units = Units::toframes(tracks->view_samples(), mwindow->session->sample_rate, mwindow->session->frame_rate);
220 zoom_units = edl->local_session->zoom_sample / edl->session->sample_rate * edl->session->frame_rate;
223 int VTrack::copy_derived(int64_t start, int64_t end, FileXML *xml)
225 // automation is copied in the Track::copy
229 int VTrack::copy_automation_derived(AutoConf *auto_conf, int64_t start, int64_t end, FileXML *file)
234 int VTrack::paste_derived(int64_t start, int64_t end, int64_t total_length, FileXML *xml, int ¤t_channel)
239 int VTrack::paste_output(int64_t startproject, int64_t endproject, int64_t startsource, int64_t endsource, int layer, Asset *asset)
244 int VTrack::clear_derived(int64_t start, int64_t end)
249 int VTrack::paste_automation_derived(int64_t start, int64_t end, int64_t total_length, FileXML *xml, int shift_autos, int ¤t_pan)
254 int VTrack::clear_automation_derived(AutoConf *auto_conf, int64_t start, int64_t end, int shift_autos)
259 int VTrack::draw_autos_derived(float view_start, float zoom_units, AutoConf *auto_conf)
265 int VTrack::select_auto_derived(float zoom_units, float view_start, AutoConf *auto_conf, int cursor_x, int cursor_y)
271 int VTrack::move_auto_derived(float zoom_units, float view_start, AutoConf *auto_conf, int cursor_x, int cursor_y, int shift_down)
276 int VTrack::draw_floating_autos_derived(float view_start, float zoom_units, AutoConf *auto_conf, int flash)
281 int VTrack::channel_is_playable(int64_t position, int direction, int *do_channel)
284 //printf("VTrack::channel_is_playable 1 %d\n", do_channel[0]);
285 for(int i = 0; i < edl->session->video_channels && !result; i++)
289 float in_x, in_y, in_w, in_h;
290 float out_x, out_y, out_w, out_h;
292 calculate_output_transfer(i, position, direction,
293 in_x, in_y, in_w, in_h,
294 out_x, out_y, out_w, out_h);
296 //printf("VTrack::channel_is_playable %0.0f %0.0f %0.0f %0.0f %0.0f %0.0f %0.0f %0.0f\n",
297 //in_x, in_y, in_w, in_h, out_x, out_y, out_w, out_h);
298 if(out_w > 0 && out_h > 0)
305 void VTrack::calculate_input_transfer(Asset *asset,
317 float auto_x, auto_y, auto_z;
318 BezierAuto *before = 0, *after = 0;
319 FloatAuto *previous = 0, *next = 0;
321 float camera_x = asset->width / 2;
322 float camera_y = asset->height / 2;
323 float z[6], x[6], y[6]; // camera and output coords
325 // get camera center in asset
326 automation->camera_autos->get_center(auto_x,
333 auto_z = automation->czoom_autos->get_value(position,
342 // get camera coords on asset
343 x[0] = camera_x - (float)track_w / 2 / camera_z;
344 y[0] = camera_y - (float)track_h / 2 / camera_z;
345 x[1] = x[0] + (float)track_w / camera_z;
346 y[1] = y[0] + (float)track_h / camera_z;
348 // get asset coords on camera
354 // crop asset coords on camera
357 x[2] -= x[0] * camera_z;
362 y[2] -= y[0] * camera_z;
365 if(x[1] > asset->width)
367 x[3] -= (x[1] - asset->width) * camera_z;
370 if(y[1] > asset->height)
372 y[3] -= (y[1] - asset->height) * camera_z;
373 y[1] = asset->height;
376 // get output bounding box
388 void VTrack::calculate_output_transfer(int channel,
400 BezierAuto *before = 0, *after = 0;
401 FloatAuto *previous = 0, *next = 0;
402 float center_x, center_y, center_z;
404 float channel_x1 = edl->session->vchannel_x[channel];
405 float channel_y1 = edl->session->vchannel_y[channel];
406 float channel_x2 = channel_x1 + edl->session->output_w;
407 float channel_y2 = channel_y1 + edl->session->output_h;
414 automation->projector_autos->get_center(center_x,
421 center_z = automation->pzoom_autos->get_value(position,
426 center_x += edl->session->output_w / 2;
427 center_y += edl->session->output_h / 2;
429 x[2] = center_x - (track_w / 2) * center_z;
430 y[2] = center_y - (track_h / 2) * center_z;
431 x[3] = x[2] + track_w * center_z;
432 y[3] = y[2] + track_h * center_z;
434 // Clip to boundaries of channel
435 if(x[2] < channel_x1)
437 x[0] -= (x[2] - channel_x1) / center_z;
442 y[0] -= (y[2] - channel_y1) / center_z;
445 if(x[3] > channel_x2)
447 x[1] -= (x[3] - channel_x2) / center_z;
450 if(y[3] > channel_y2)
452 y[1] -= (y[3] - channel_y2) / center_z;
468 int VTrack::get_projection(int channel,
479 int64_t real_position,
482 float center_x, center_y, center_z;
484 BezierAuto *before = 0, *after = 0;
485 FloatAuto *previous = 0, *next = 0;
487 automation->projector_autos->get_center(center_x,
490 (float)real_position,
494 center_z = automation->pzoom_autos->get_value(real_position,
503 center_x += edl->session->output_w / 2;
504 center_y += edl->session->output_h / 2;
506 x[2] = center_x - (frame_w / 2) * center_z;
507 y[2] = center_y - (frame_h / 2) * center_z;
508 x[3] = x[2] + frame_w * center_z;
509 y[3] = y[2] + frame_h * center_z;
513 x[0] -= x[2] / center_z;
518 y[0] -= y[2] / center_z;
521 if(x[3] > edl->session->output_w)
523 x[1] -= (x[3] - edl->session->output_w) / center_z;
524 x[3] = edl->session->output_w;
526 if(y[3] > edl->session->output_h)
528 y[1] -= (y[3] - edl->session->output_h) / center_z;
529 y[3] = edl->session->output_h;
544 void VTrack::translate_camera(float offset_x, float offset_y)
546 ((BezierAuto*)automation->camera_autos->default_auto)->center_x += offset_x;
547 ((BezierAuto*)automation->camera_autos->default_auto)->center_y += offset_y;
549 for(Auto *current = automation->camera_autos->first;
553 ((BezierAuto*)current)->center_x += offset_x;
554 ((BezierAuto*)current)->center_y += offset_y;
558 void VTrack::translate_projector(float offset_x, float offset_y)
560 ((BezierAuto*)automation->projector_autos->default_auto)->center_x += offset_x;
561 ((BezierAuto*)automation->projector_autos->default_auto)->center_y += offset_y;
563 for(Auto *current = automation->projector_autos->first;
567 ((BezierAuto*)current)->center_x += offset_x;
568 ((BezierAuto*)current)->center_y += offset_y;