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;
62 void VTrack::create_objects()
64 Track::create_objects();
65 automation = new VAutomation(edl, this);
66 automation->create_objects();
67 edits = new VEdits(edl, this);
70 // Used by PlaybackEngine
71 void VTrack::synchronize_params(Track *track)
73 Track::synchronize_params(track);
74 //VTrack *vtrack = (VTrack*)track;
77 // Used by EDL::operator=
78 int VTrack::copy_settings(Track *track)
80 Track::copy_settings(track);
81 //VTrack *vtrack = (VTrack*)track;
85 int VTrack::vertical_span(Theme *theme)
87 int track_h = Track::vertical_span(theme);
88 int patch_h = theme->title_h;
90 patch_h += theme->play_h + theme->fade_h + theme->mode_h;
91 return MAX(track_h, patch_h);
95 PluginSet* VTrack::new_plugins()
97 return new VPluginSet(edl, this);
100 int VTrack::load_defaults(BC_Hash *defaults)
102 Track::load_defaults(defaults);
106 void VTrack::set_default_title()
108 Track *current = ListItem<Track>::list->first;
110 for(i = 0; current; current = NEXT)
112 if(current->data_type == TRACK_VIDEO) i++;
114 sprintf(title, _("Video %d"), i);
115 BC_Resources::encode_to_utf8(title, BCTEXTLEN);
118 int64_t VTrack::to_units(double position, int round)
120 return round ? Units::round(position * edl->session->frame_rate) :
121 Units::to_int64(position * edl->session->frame_rate + 1e-6);
124 double VTrack::to_doubleunits(double position)
126 return position * edl->session->frame_rate;
130 double VTrack::from_units(int64_t position)
132 return (double)position / edl->session->frame_rate;
138 int VTrack::identical(int64_t sample1, int64_t sample2)
141 if(labs(sample1 - sample2) <= 1) return 1; else return 0;
144 int VTrack::save_header(FileXML *file)
146 file->tag.set_property("TYPE", "VIDEO");
150 int VTrack::save_derived(FileXML *file)
155 int VTrack::load_header(FileXML *file, uint32_t load_flags)
160 int VTrack::load_derived(FileXML *file, uint32_t load_flags)
166 int VTrack::direct_copy_possible(int64_t start, int direction, int use_nudge)
168 if(use_nudge) start += nudge;
170 // Track size must equal output size
171 if(track_w != edl->session->output_w || track_h != edl->session->output_h)
174 if(has_speed()) return 0;
176 // No automation must be present in the track
177 if(!automation->direct_copy_possible(start, direction))
180 // No plugin must be present
181 if(plugin_used(start, direction))
185 if(get_current_transition(start, direction, 0, 0))
207 int VTrack::create_derived_objs(int flash)
209 edits = new VEdits(edl, this);
214 // int VTrack::get_dimensions(double &view_start,
215 // double &view_units,
216 // double &zoom_units)
218 // view_start = edl->local_session->view_start * edl->session->frame_rate;
220 // zoom_units = edl->local_session->zoom_sample / edl->session->sample_rate * edl->session->frame_rate;
224 int VTrack::copy_derived(int64_t start, int64_t end, FileXML *xml)
226 // automation is copied in the Track::copy
230 int VTrack::copy_automation_derived(AutoConf *auto_conf, int64_t start, int64_t end, FileXML *file)
235 int VTrack::paste_derived(int64_t start, int64_t end, int64_t total_length, FileXML *xml, int ¤t_channel)
240 int VTrack::paste_output(int64_t startproject, int64_t endproject, int64_t startsource, int64_t endsource, int layer, Asset *asset)
245 int VTrack::clear_derived(int64_t start, int64_t end)
250 int VTrack::paste_automation_derived(int64_t start, int64_t end, int64_t total_length, FileXML *xml, int shift_autos, int ¤t_pan)
255 int VTrack::clear_automation_derived(AutoConf *auto_conf, int64_t start, int64_t end, int shift_autos)
260 int VTrack::draw_autos_derived(float view_start, float zoom_units, AutoConf *auto_conf)
266 int VTrack::select_auto_derived(float zoom_units, float view_start, AutoConf *auto_conf, int cursor_x, int cursor_y)
272 int VTrack::move_auto_derived(float zoom_units, float view_start, AutoConf *auto_conf, int cursor_x, int cursor_y, int shift_down)
277 int VTrack::draw_floating_autos_derived(float view_start, float zoom_units, AutoConf *auto_conf, int flash)
282 int VTrack::is_playable(int64_t position, int direction)
285 float in_x, in_y, in_w, in_h;
286 float out_x, out_y, out_w, out_h;
288 calculate_output_transfer(position,
290 in_x, in_y, in_w, in_h,
291 out_x, out_y, out_w, out_h);
293 //printf("VTrack::is_playable %0.0f %0.0f %0.0f %0.0f %0.0f %0.0f %0.0f %0.0f\n",
294 //in_x, in_y, in_w, in_h, out_x, out_y, out_w, out_h);
295 if(out_w > 0 && out_h > 0)
300 void VTrack::calculate_input_transfer(int asset_w, int asset_h,
301 int64_t position, int direction,
302 float &in_x, float &in_y, float &in_w, float &in_h,
303 float &out_x, float &out_y, float &out_w, float &out_h)
305 float auto_x, auto_y, auto_z;
307 float camera_x = asset_w / 2.;
308 float camera_y = asset_h / 2.;
309 // camera and output coords
312 //printf("VTrack::calculate_input_transfer %jd\n", position);
314 // get camera center in asset
315 automation->get_camera(&auto_x, &auto_y, &auto_z,
316 position, direction);
322 // get camera coords on asset
323 x[0] = camera_x - (float)track_w / 2 / camera_z;
324 y[0] = camera_y - (float)track_h / 2 / camera_z;
325 x[1] = x[0] + (float)track_w / camera_z;
326 y[1] = y[0] + (float)track_h / camera_z;
328 // get asset coords on camera
334 // crop asset coords on camera
337 x[2] -= x[0] * camera_z;
342 y[2] -= y[0] * camera_z;
347 x[3] -= (x[1] - asset_w) * camera_z;
352 y[3] -= (y[1] - asset_h) * camera_z;
356 // get output bounding box
366 // printf("VTrack::calculate_input_transfer %f %f %f %f -> %f %f %f %f\n",
367 // in_x, in_y, in_w, in_h,
368 // out_x, out_y, out_w, out_h);
371 void VTrack::calculate_output_transfer(int64_t position, int direction,
372 float &in_x, float &in_y, float &in_w, float &in_h,
373 float &out_x, float &out_y, float &out_w, float &out_h)
375 float center_x, center_y, center_z;
383 automation->get_projector(¢er_x,
389 center_x += edl->session->output_w / 2;
390 center_y += edl->session->output_h / 2;
392 x[2] = center_x - (track_w / 2) * center_z;
393 y[2] = center_y - (track_h / 2) * center_z;
394 x[3] = x[2] + track_w * center_z;
395 y[3] = y[2] + track_h * center_z;
397 // Clip to boundaries of output
400 x[0] -= (x[2] - 0) / center_z;
405 y[0] -= (y[2] - 0) / center_z;
408 if(x[3] > edl->session->output_w)
410 x[1] -= (x[3] - edl->session->output_w) / center_z;
411 x[3] = edl->session->output_w;
413 if(y[3] > edl->session->output_h)
415 y[1] -= (y[3] - edl->session->output_h) / center_z;
416 y[3] = edl->session->output_h;
427 // printf("VTrack::calculate_output_transfer %f %f %f %f -> %f %f %f %f\n",
428 // in_x, in_y, in_w, in_h,
429 // out_x, out_y, out_w, out_h);
434 int VTrack::get_projection(float &in_x1, float &in_y1, float &in_x2, float &in_y2,
435 float &out_x1, float &out_y1, float &out_x2, float &out_y2,
436 int frame_w, int frame_h, int64_t real_position, int direction)
438 float center_x, center_y, center_z;
441 automation->get_projector(¢er_x,
451 center_x += edl->session->output_w / 2;
452 center_y += edl->session->output_h / 2;
454 x[2] = center_x - (frame_w / 2) * center_z;
455 y[2] = center_y - (frame_h / 2) * center_z;
456 x[3] = x[2] + frame_w * center_z;
457 y[3] = y[2] + frame_h * center_z;
461 x[0] -= x[2] / center_z;
466 y[0] -= y[2] / center_z;
469 if(x[3] > edl->session->output_w)
471 x[1] -= (x[3] - edl->session->output_w) / center_z;
472 x[3] = edl->session->output_w;
474 if(y[3] > edl->session->output_h)
476 y[1] -= (y[3] - edl->session->output_h) / center_z;
477 y[3] = edl->session->output_h;
480 in_x1 = x[0]; in_y1 = y[0]; in_x2 = x[1]; in_y2 = y[1];
481 out_x1 = x[2]; out_y1 = y[2]; out_x2 = x[3]; out_y2 = y[3];
487 static inline void addto_value(FloatAuto *fauto, float offset)
489 fauto->set_value(fauto->get_value() + offset);
492 static inline void multiply_value(FloatAuto *fauto, float scale)
494 fauto->set_value(fauto->get_value() * scale);
498 void VTrack::set_fauto_xy(int fauto, float x, float y)
500 // set default keyframe
501 FloatAuto *xdft = (FloatAuto *)automation->autos[fauto+0]->default_auto;
502 FloatAuto *ydft = (FloatAuto *)automation->autos[fauto+1]->default_auto;
506 FloatAuto *xauto = (FloatAuto *)automation->autos[fauto+0]->first;
507 FloatAuto *yauto = (FloatAuto *)automation->autos[fauto+1]->first;
508 for( ; xauto; xauto=(FloatAuto *)xauto->next ) xauto->set_value(x);
509 for( ; yauto; yauto=(FloatAuto *)yauto->next ) yauto->set_value(y);
512 void VTrack::translate(int fauto, float dx, float dy, int all)
515 addto_value((FloatAuto*)automation->autos[fauto+0]->default_auto, dx);
516 addto_value((FloatAuto*)automation->autos[fauto+1]->default_auto, dy);
517 FloatAutos **fautos = (FloatAutos **)&automation->autos;
518 FloatAuto *xauto = (FloatAuto *)fautos[fauto+0]->first;
519 FloatAuto *yauto = (FloatAuto *)fautos[fauto+1]->first;
520 for( ; xauto; xauto=(FloatAuto *)xauto->next ) addto_value(xauto, dx);
521 for( ; yauto; yauto=(FloatAuto *)yauto->next ) addto_value(yauto, dy);
524 FloatAutos **fautos = (FloatAutos **)&automation->autos;
525 FloatAuto *xauto = (FloatAuto *)fautos[fauto+0]->get_auto_for_editing(-1, 1);
526 FloatAuto *yauto = (FloatAuto *)fautos[fauto+1]->get_auto_for_editing(-1, 1);
527 addto_value(xauto, dx);
528 addto_value(yauto, dy);