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"
35 #include "localsession.h"
37 #include "mainsession.h"
39 #include "trackcanvas.h"
41 #include "transportque.inc"
43 #include "vautomation.h"
48 #include "vpluginset.h"
51 VTrack::VTrack(EDL *edl, Tracks *tracks)
54 data_type = TRACK_VIDEO;
55 data_h = edl->local_session->zoom_vtrack;
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);
89 int patch_h = theme->title_h;
91 patch_h += theme->play_h + theme->fade_h + theme->mode_h;
92 return MAX(track_h, patch_h);
96 PluginSet* VTrack::new_plugins()
98 return new VPluginSet(edl, this);
101 int VTrack::load_defaults(BC_Hash *defaults)
103 Track::load_defaults(defaults);
107 void VTrack::set_default_title()
109 Track *current = ListItem<Track>::list->first;
111 for(i = 0; current; current = NEXT)
113 if(current->data_type == TRACK_VIDEO) i++;
115 sprintf(title, _("Video %d"), i);
116 BC_Resources::encode_to_utf8(title, BCTEXTLEN);
119 int64_t VTrack::to_units(double position, int round)
121 return round ? Units::round(position * edl->session->frame_rate) :
122 Units::to_int64(position * edl->session->frame_rate + 1e-6);
125 double VTrack::to_doubleunits(double position)
127 return position * edl->session->frame_rate;
131 double VTrack::from_units(int64_t position)
133 return (double)position / edl->session->frame_rate;
139 int VTrack::identical(int64_t sample1, int64_t sample2)
142 if(labs(sample1 - sample2) <= 1) return 1; else return 0;
145 int VTrack::save_header(FileXML *file)
147 file->tag.set_property("TYPE", "VIDEO");
151 int VTrack::save_derived(FileXML *file)
156 int VTrack::load_header(FileXML *file, uint32_t load_flags)
161 int VTrack::load_derived(FileXML *file, uint32_t load_flags)
167 int VTrack::direct_copy_possible(int64_t start, int direction, int use_nudge)
169 if(use_nudge) start += nudge;
171 // Track size must equal output size
172 if(track_w != edl->session->output_w || track_h != edl->session->output_h)
175 if(has_speed()) return 0;
177 // No automation must be present in the track
178 if(!automation->direct_copy_possible(start, direction))
181 // No plugin must be present
182 if(plugin_used(start, direction))
186 if(get_current_transition(start, direction, 0, 0))
208 int VTrack::create_derived_objs(int flash)
210 edits = new VEdits(edl, this);
215 // int VTrack::get_dimensions(double &view_start,
216 // double &view_units,
217 // double &zoom_units)
219 // view_start = edl->local_session->view_start * edl->session->frame_rate;
221 // zoom_units = edl->local_session->zoom_sample / edl->session->sample_rate * edl->session->frame_rate;
225 int VTrack::copy_derived(int64_t start, int64_t end, FileXML *xml)
227 // automation is copied in the Track::copy
231 int VTrack::copy_automation_derived(AutoConf *auto_conf, int64_t start, int64_t end, FileXML *file)
236 int VTrack::paste_derived(int64_t start, int64_t end, int64_t total_length, FileXML *xml, int ¤t_channel)
241 int VTrack::paste_output(int64_t startproject, int64_t endproject, int64_t startsource, int64_t endsource, int layer, Asset *asset)
246 int VTrack::clear_derived(int64_t start, int64_t end)
251 int VTrack::paste_automation_derived(int64_t start, int64_t end, int64_t total_length, FileXML *xml, int shift_autos, int ¤t_pan)
256 int VTrack::clear_automation_derived(AutoConf *auto_conf, int64_t start, int64_t end, int shift_autos)
261 int VTrack::draw_autos_derived(float view_start, float zoom_units, AutoConf *auto_conf)
267 int VTrack::select_auto_derived(float zoom_units, float view_start, AutoConf *auto_conf, int cursor_x, int cursor_y)
273 int VTrack::move_auto_derived(float zoom_units, float view_start, AutoConf *auto_conf, int cursor_x, int cursor_y, int shift_down)
278 int VTrack::draw_floating_autos_derived(float view_start, float zoom_units, AutoConf *auto_conf, int flash)
283 int VTrack::is_playable(int64_t position, int direction)
286 float in_x, in_y, in_w, in_h;
287 float out_x, out_y, out_w, out_h;
289 calculate_output_transfer(position,
291 in_x, in_y, in_w, in_h,
292 out_x, out_y, out_w, out_h);
294 //printf("VTrack::is_playable %0.0f %0.0f %0.0f %0.0f %0.0f %0.0f %0.0f %0.0f\n",
295 //in_x, in_y, in_w, in_h, out_x, out_y, out_w, out_h);
296 if(out_w > 0 && out_h > 0)
301 void VTrack::calculate_input_transfer(int asset_w, int asset_h,
302 int64_t position, int direction,
303 float &in_x, float &in_y, float &in_w, float &in_h,
304 float &out_x, float &out_y, float &out_w, float &out_h)
306 float auto_x, auto_y, auto_z;
308 float camera_x = asset_w / 2.;
309 float camera_y = asset_h / 2.;
310 // camera and output coords
313 //printf("VTrack::calculate_input_transfer %jd\n", position);
315 // get camera center in asset
316 automation->get_camera(&auto_x, &auto_y, &auto_z,
317 position, direction);
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;
348 x[3] -= (x[1] - asset_w) * camera_z;
353 y[3] -= (y[1] - asset_h) * camera_z;
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, int direction,
373 float &in_x, float &in_y, float &in_w, float &in_h,
374 float &out_x, float &out_y, float &out_w, float &out_h)
376 float center_x, center_y, center_z;
384 automation->get_projector(¢er_x,
390 center_x += edl->session->output_w / 2;
391 center_y += edl->session->output_h / 2;
393 x[2] = center_x - (track_w / 2) * center_z;
394 y[2] = center_y - (track_h / 2) * center_z;
395 x[3] = x[2] + track_w * center_z;
396 y[3] = y[2] + track_h * center_z;
398 // Clip to boundaries of output
401 x[0] -= (x[2] - 0) / center_z;
406 y[0] -= (y[2] - 0) / center_z;
409 if(x[3] > edl->session->output_w)
411 x[1] -= (x[3] - edl->session->output_w) / center_z;
412 x[3] = edl->session->output_w;
414 if(y[3] > edl->session->output_h)
416 y[1] -= (y[3] - edl->session->output_h) / center_z;
417 y[3] = edl->session->output_h;
428 // printf("VTrack::calculate_output_transfer %f %f %f %f -> %f %f %f %f\n",
429 // in_x, in_y, in_w, in_h,
430 // out_x, out_y, out_w, out_h);
435 int VTrack::get_projection(float &in_x1, float &in_y1, float &in_x2, float &in_y2,
436 float &out_x1, float &out_y1, float &out_x2, float &out_y2,
437 int frame_w, int frame_h, int64_t real_position, int direction)
439 float center_x, center_y, center_z;
442 automation->get_projector(¢er_x,
452 center_x += edl->session->output_w / 2;
453 center_y += edl->session->output_h / 2;
455 x[2] = center_x - (frame_w / 2) * center_z;
456 y[2] = center_y - (frame_h / 2) * center_z;
457 x[3] = x[2] + frame_w * center_z;
458 y[3] = y[2] + frame_h * center_z;
462 x[0] -= x[2] / center_z;
467 y[0] -= y[2] / center_z;
470 if(x[3] > edl->session->output_w)
472 x[1] -= (x[3] - edl->session->output_w) / center_z;
473 x[3] = edl->session->output_w;
475 if(y[3] > edl->session->output_h)
477 y[1] -= (y[3] - edl->session->output_h) / center_z;
478 y[3] = edl->session->output_h;
481 in_x1 = x[0]; in_y1 = y[0]; in_x2 = x[1]; in_y2 = y[1];
482 out_x1 = x[2]; out_y1 = y[2]; out_x2 = x[3]; out_y2 = y[3];
488 static inline void addto_value(FloatAuto *fauto, float offset)
490 fauto->set_value(fauto->get_value() + offset);
493 static inline void multiply_value(FloatAuto *fauto, float scale)
495 fauto->set_value(fauto->get_value() * scale);
499 void VTrack::set_fauto_xy(int fauto, float x, float y)
501 // set default keyframe
502 FloatAuto *xdft = (FloatAuto *)automation->autos[fauto+0]->default_auto;
503 FloatAuto *ydft = (FloatAuto *)automation->autos[fauto+1]->default_auto;
507 FloatAuto *xauto = (FloatAuto *)automation->autos[fauto+0]->first;
508 FloatAuto *yauto = (FloatAuto *)automation->autos[fauto+1]->first;
509 for( ; xauto; xauto=(FloatAuto *)xauto->next ) xauto->set_value(x);
510 for( ; yauto; yauto=(FloatAuto *)yauto->next ) yauto->set_value(y);
513 void VTrack::translate(int fauto, float dx, float dy, int all)
516 addto_value((FloatAuto*)automation->autos[fauto+0]->default_auto, dx);
517 addto_value((FloatAuto*)automation->autos[fauto+1]->default_auto, dy);
518 FloatAutos **fautos = (FloatAutos **)&automation->autos;
519 FloatAuto *xauto = (FloatAuto *)fautos[fauto+0]->first;
520 FloatAuto *yauto = (FloatAuto *)fautos[fauto+1]->first;
521 for( ; xauto; xauto=(FloatAuto *)xauto->next ) addto_value(xauto, dx);
522 for( ; yauto; yauto=(FloatAuto *)yauto->next ) addto_value(yauto, dy);
525 FloatAutos **fautos = (FloatAutos **)&automation->autos;
526 FloatAuto *xauto = (FloatAuto *)fautos[fauto+0]->get_auto_for_editing(-1, 1);
527 FloatAuto *yauto = (FloatAuto *)fautos[fauto+1]->get_auto_for_editing(-1, 1);
528 addto_value(xauto, dx);
529 addto_value(yauto, dy);