4 * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30 #include "edlsession.h"
32 #include "floatauto.h"
33 #include "floatautos.h"
36 #include "localsession.h"
38 #include "mainsession.h"
40 #include "trackcanvas.h"
42 #include "transportque.inc"
44 #include "vautomation.h"
49 #include "vpluginset.h"
52 VTrack::VTrack(EDL *edl, Tracks *tracks)
55 data_type = TRACK_VIDEO;
63 void VTrack::create_objects()
65 Track::create_objects();
66 automation = new VAutomation(edl, this);
67 automation->create_objects();
68 edits = new VEdits(edl, this);
71 // Used by PlaybackEngine
72 void VTrack::synchronize_params(Track *track)
74 Track::synchronize_params(track);
75 //VTrack *vtrack = (VTrack*)track;
78 // Used by EDL::operator=
79 int VTrack::copy_settings(Track *track)
81 Track::copy_settings(track);
82 //VTrack *vtrack = (VTrack*)track;
86 int VTrack::vertical_span(Theme *theme)
88 int track_h = Track::vertical_span(theme);
92 patch_h += theme->title_h + theme->play_h + theme->fade_h + theme->mode_h;
94 return MAX(track_h, patch_h);
98 PluginSet* VTrack::new_plugins()
100 return new VPluginSet(edl, this);
103 int VTrack::load_defaults(BC_Hash *defaults)
105 Track::load_defaults(defaults);
109 void VTrack::set_default_title()
111 Track *current = ListItem<Track>::owner->first;
113 for(i = 0; current; current = NEXT)
115 if(current->data_type == TRACK_VIDEO) i++;
117 sprintf(title, _("Video %d"), i);
120 int64_t VTrack::to_units(double position, int round)
124 return Units::round(position * edl->session->frame_rate);
128 // Kludge for rounding errors, just on a smaller scale than formal rounding
129 position *= edl->session->frame_rate;
130 return Units::to_int64(position);
134 double VTrack::to_doubleunits(double position)
136 return position * edl->session->frame_rate;
140 double VTrack::from_units(int64_t position)
142 return (double)position / edl->session->frame_rate;
148 int VTrack::identical(int64_t sample1, int64_t sample2)
151 if(labs(sample1 - sample2) <= 1) return 1; else return 0;
154 int VTrack::save_header(FileXML *file)
156 file->tag.set_property("TYPE", "VIDEO");
160 int VTrack::save_derived(FileXML *file)
165 int VTrack::load_header(FileXML *file, uint32_t load_flags)
170 int VTrack::load_derived(FileXML *file, uint32_t load_flags)
176 int VTrack::direct_copy_possible(int64_t start, int direction, int use_nudge)
178 if(use_nudge) start += nudge;
180 // Track size must equal output size
181 if(track_w != edl->session->output_w || track_h != edl->session->output_h)
184 if(has_speed()) return 0;
186 // No automation must be present in the track
187 if(!automation->direct_copy_possible(start, direction))
190 // No plugin must be present
191 if(plugin_used(start, direction))
195 if(get_current_transition(start, direction, 0, 0))
217 int VTrack::create_derived_objs(int flash)
219 edits = new VEdits(edl, this);
224 // int VTrack::get_dimensions(double &view_start,
225 // double &view_units,
226 // double &zoom_units)
228 // view_start = edl->local_session->view_start * edl->session->frame_rate;
230 // zoom_units = edl->local_session->zoom_sample / edl->session->sample_rate * edl->session->frame_rate;
234 int VTrack::copy_derived(int64_t start, int64_t end, FileXML *xml)
236 // automation is copied in the Track::copy
240 int VTrack::copy_automation_derived(AutoConf *auto_conf, int64_t start, int64_t end, FileXML *file)
245 int VTrack::paste_derived(int64_t start, int64_t end, int64_t total_length, FileXML *xml, int ¤t_channel)
250 int VTrack::paste_output(int64_t startproject, int64_t endproject, int64_t startsource, int64_t endsource, int layer, Asset *asset)
255 int VTrack::clear_derived(int64_t start, int64_t end)
260 int VTrack::paste_automation_derived(int64_t start, int64_t end, int64_t total_length, FileXML *xml, int shift_autos, int ¤t_pan)
265 int VTrack::clear_automation_derived(AutoConf *auto_conf, int64_t start, int64_t end, int shift_autos)
270 int VTrack::draw_autos_derived(float view_start, float zoom_units, AutoConf *auto_conf)
276 int VTrack::select_auto_derived(float zoom_units, float view_start, AutoConf *auto_conf, int cursor_x, int cursor_y)
282 int VTrack::move_auto_derived(float zoom_units, float view_start, AutoConf *auto_conf, int cursor_x, int cursor_y, int shift_down)
287 int VTrack::draw_floating_autos_derived(float view_start, float zoom_units, AutoConf *auto_conf, int flash)
292 int VTrack::is_playable(int64_t position, int direction)
295 float in_x, in_y, in_w, in_h;
296 float out_x, out_y, out_w, out_h;
298 calculate_output_transfer(position,
300 in_x, in_y, in_w, in_h,
301 out_x, out_y, out_w, out_h);
303 //printf("VTrack::is_playable %0.0f %0.0f %0.0f %0.0f %0.0f %0.0f %0.0f %0.0f\n",
304 //in_x, in_y, in_w, in_h, out_x, out_y, out_w, out_h);
305 if(out_w > 0 && out_h > 0)
310 void VTrack::calculate_input_transfer(int asset_w, int asset_h,
311 int64_t position, int direction,
312 float &in_x, float &in_y, float &in_w, float &in_h,
313 float &out_x, float &out_y, float &out_w, float &out_h)
315 float auto_x, auto_y, auto_z;
317 float camera_x = asset_w / 2.;
318 float camera_y = asset_h / 2.;
319 // camera and output coords
322 //printf("VTrack::calculate_input_transfer " _LD "\n", position);
324 // get camera center in asset
325 automation->get_camera(&auto_x, &auto_y, &auto_z,
326 position, direction);
332 // get camera coords on asset
333 x[0] = camera_x - (float)track_w / 2 / camera_z;
334 y[0] = camera_y - (float)track_h / 2 / camera_z;
335 x[1] = x[0] + (float)track_w / camera_z;
336 y[1] = y[0] + (float)track_h / camera_z;
338 // get asset coords on camera
344 // crop asset coords on camera
347 x[2] -= x[0] * camera_z;
352 y[2] -= y[0] * camera_z;
357 x[3] -= (x[1] - asset_w) * camera_z;
362 y[3] -= (y[1] - asset_h) * camera_z;
366 // get output bounding box
376 // printf("VTrack::calculate_input_transfer %f %f %f %f -> %f %f %f %f\n",
377 // in_x, in_y, in_w, in_h,
378 // out_x, out_y, out_w, out_h);
381 void VTrack::calculate_output_transfer(int64_t position, int direction,
382 float &in_x, float &in_y, float &in_w, float &in_h,
383 float &out_x, float &out_y, float &out_w, float &out_h)
385 float center_x, center_y, center_z;
393 automation->get_projector(¢er_x,
399 center_x += edl->session->output_w / 2;
400 center_y += edl->session->output_h / 2;
402 x[2] = center_x - (track_w / 2) * center_z;
403 y[2] = center_y - (track_h / 2) * center_z;
404 x[3] = x[2] + track_w * center_z;
405 y[3] = y[2] + track_h * center_z;
407 // Clip to boundaries of output
410 x[0] -= (x[2] - 0) / center_z;
415 y[0] -= (y[2] - 0) / center_z;
418 if(x[3] > edl->session->output_w)
420 x[1] -= (x[3] - edl->session->output_w) / center_z;
421 x[3] = edl->session->output_w;
423 if(y[3] > edl->session->output_h)
425 y[1] -= (y[3] - edl->session->output_h) / center_z;
426 y[3] = edl->session->output_h;
437 // printf("VTrack::calculate_output_transfer %f %f %f %f -> %f %f %f %f\n",
438 // in_x, in_y, in_w, in_h,
439 // out_x, out_y, out_w, out_h);
444 int VTrack::get_projection(float &in_x1, float &in_y1, float &in_x2, float &in_y2,
445 float &out_x1, float &out_y1, float &out_x2, float &out_y2,
446 int frame_w, int frame_h, int64_t real_position, int direction)
448 float center_x, center_y, center_z;
451 automation->get_projector(¢er_x,
461 center_x += edl->session->output_w / 2;
462 center_y += edl->session->output_h / 2;
464 x[2] = center_x - (frame_w / 2) * center_z;
465 y[2] = center_y - (frame_h / 2) * center_z;
466 x[3] = x[2] + frame_w * center_z;
467 y[3] = y[2] + frame_h * center_z;
471 x[0] -= x[2] / center_z;
476 y[0] -= y[2] / center_z;
479 if(x[3] > edl->session->output_w)
481 x[1] -= (x[3] - edl->session->output_w) / center_z;
482 x[3] = edl->session->output_w;
484 if(y[3] > edl->session->output_h)
486 y[1] -= (y[3] - edl->session->output_h) / center_z;
487 y[3] = edl->session->output_h;
490 in_x1 = x[0]; in_y1 = y[0]; in_x2 = x[1]; in_y2 = y[1];
491 out_x1 = x[2]; out_y1 = y[2]; out_x2 = x[3]; out_y2 = y[3];
496 void VTrack::translate(float offset_x, float offset_y, int do_camera)
500 subscript = AUTOMATION_CAMERA_X;
502 subscript = AUTOMATION_PROJECTOR_X;
504 // Translate default keyframe
505 ((FloatAuto*)automation->autos[subscript]->default_auto)->value += offset_x;
506 ((FloatAuto*)automation->autos[subscript + 1]->default_auto)->value += offset_y;
508 // Translate everyone else
509 for(Auto *current = automation->autos[subscript]->first;
513 ((FloatAuto*)current)->value += offset_x;
516 for(Auto *current = automation->autos[subscript + 1]->first;
520 ((FloatAuto*)current)->value += offset_y;