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);
91 patch_h += theme->title_h + theme->play_h + theme->fade_h + theme->mode_h;
93 return MAX(track_h, patch_h);
97 PluginSet* VTrack::new_plugins()
99 return new VPluginSet(edl, this);
102 int VTrack::load_defaults(BC_Hash *defaults)
104 Track::load_defaults(defaults);
108 void VTrack::set_default_title()
110 Track *current = ListItem<Track>::list->first;
112 for(i = 0; current; current = NEXT)
114 if(current->data_type == TRACK_VIDEO) i++;
116 sprintf(title, _("Video %d"), i);
117 BC_Resources::encode_to_utf8(title, BCTEXTLEN);
120 int64_t VTrack::to_units(double position, int round)
122 return round ? Units::round(position * edl->session->frame_rate) :
123 Units::to_int64(position * edl->session->frame_rate + 1e-6);
126 double VTrack::to_doubleunits(double position)
128 return position * edl->session->frame_rate;
132 double VTrack::from_units(int64_t position)
134 return (double)position / edl->session->frame_rate;
140 int VTrack::identical(int64_t sample1, int64_t sample2)
143 if(labs(sample1 - sample2) <= 1) return 1; else return 0;
146 int VTrack::save_header(FileXML *file)
148 file->tag.set_property("TYPE", "VIDEO");
152 int VTrack::save_derived(FileXML *file)
157 int VTrack::load_header(FileXML *file, uint32_t load_flags)
162 int VTrack::load_derived(FileXML *file, uint32_t load_flags)
168 int VTrack::direct_copy_possible(int64_t start, int direction, int use_nudge)
170 if(use_nudge) start += nudge;
172 // Track size must equal output size
173 if(track_w != edl->session->output_w || track_h != edl->session->output_h)
176 if(has_speed()) return 0;
178 // No automation must be present in the track
179 if(!automation->direct_copy_possible(start, direction))
182 // No plugin must be present
183 if(plugin_used(start, direction))
187 if(get_current_transition(start, direction, 0, 0))
209 int VTrack::create_derived_objs(int flash)
211 edits = new VEdits(edl, this);
216 // int VTrack::get_dimensions(double &view_start,
217 // double &view_units,
218 // double &zoom_units)
220 // view_start = edl->local_session->view_start * edl->session->frame_rate;
222 // zoom_units = edl->local_session->zoom_sample / edl->session->sample_rate * edl->session->frame_rate;
226 int VTrack::copy_derived(int64_t start, int64_t end, FileXML *xml)
228 // automation is copied in the Track::copy
232 int VTrack::copy_automation_derived(AutoConf *auto_conf, int64_t start, int64_t end, FileXML *file)
237 int VTrack::paste_derived(int64_t start, int64_t end, int64_t total_length, FileXML *xml, int ¤t_channel)
242 int VTrack::paste_output(int64_t startproject, int64_t endproject, int64_t startsource, int64_t endsource, int layer, Asset *asset)
247 int VTrack::clear_derived(int64_t start, int64_t end)
252 int VTrack::paste_automation_derived(int64_t start, int64_t end, int64_t total_length, FileXML *xml, int shift_autos, int ¤t_pan)
257 int VTrack::clear_automation_derived(AutoConf *auto_conf, int64_t start, int64_t end, int shift_autos)
262 int VTrack::draw_autos_derived(float view_start, float zoom_units, AutoConf *auto_conf)
268 int VTrack::select_auto_derived(float zoom_units, float view_start, AutoConf *auto_conf, int cursor_x, int cursor_y)
274 int VTrack::move_auto_derived(float zoom_units, float view_start, AutoConf *auto_conf, int cursor_x, int cursor_y, int shift_down)
279 int VTrack::draw_floating_autos_derived(float view_start, float zoom_units, AutoConf *auto_conf, int flash)
284 int VTrack::is_playable(int64_t position, int direction)
287 float in_x, in_y, in_w, in_h;
288 float out_x, out_y, out_w, out_h;
290 calculate_output_transfer(position,
292 in_x, in_y, in_w, in_h,
293 out_x, out_y, out_w, out_h);
295 //printf("VTrack::is_playable %0.0f %0.0f %0.0f %0.0f %0.0f %0.0f %0.0f %0.0f\n",
296 //in_x, in_y, in_w, in_h, out_x, out_y, out_w, out_h);
297 if(out_w > 0 && out_h > 0)
302 void VTrack::calculate_input_transfer(int asset_w, int asset_h,
303 int64_t position, int direction,
304 float &in_x, float &in_y, float &in_w, float &in_h,
305 float &out_x, float &out_y, float &out_w, float &out_h)
307 float auto_x, auto_y, auto_z;
309 float camera_x = asset_w / 2.;
310 float camera_y = asset_h / 2.;
311 // camera and output coords
314 //printf("VTrack::calculate_input_transfer %jd\n", position);
316 // get camera center in asset
317 automation->get_camera(&auto_x, &auto_y, &auto_z,
318 position, direction);
324 // get camera coords on asset
325 x[0] = camera_x - (float)track_w / 2 / camera_z;
326 y[0] = camera_y - (float)track_h / 2 / camera_z;
327 x[1] = x[0] + (float)track_w / camera_z;
328 y[1] = y[0] + (float)track_h / camera_z;
330 // get asset coords on camera
336 // crop asset coords on camera
339 x[2] -= x[0] * camera_z;
344 y[2] -= y[0] * camera_z;
349 x[3] -= (x[1] - asset_w) * camera_z;
354 y[3] -= (y[1] - asset_h) * camera_z;
358 // get output bounding box
368 // printf("VTrack::calculate_input_transfer %f %f %f %f -> %f %f %f %f\n",
369 // in_x, in_y, in_w, in_h,
370 // out_x, out_y, out_w, out_h);
373 void VTrack::calculate_output_transfer(int64_t position, int direction,
374 float &in_x, float &in_y, float &in_w, float &in_h,
375 float &out_x, float &out_y, float &out_w, float &out_h)
377 float center_x, center_y, center_z;
385 automation->get_projector(¢er_x,
391 center_x += edl->session->output_w / 2;
392 center_y += edl->session->output_h / 2;
394 x[2] = center_x - (track_w / 2) * center_z;
395 y[2] = center_y - (track_h / 2) * center_z;
396 x[3] = x[2] + track_w * center_z;
397 y[3] = y[2] + track_h * center_z;
399 // Clip to boundaries of output
402 x[0] -= (x[2] - 0) / center_z;
407 y[0] -= (y[2] - 0) / center_z;
410 if(x[3] > edl->session->output_w)
412 x[1] -= (x[3] - edl->session->output_w) / center_z;
413 x[3] = edl->session->output_w;
415 if(y[3] > edl->session->output_h)
417 y[1] -= (y[3] - edl->session->output_h) / center_z;
418 y[3] = edl->session->output_h;
429 // printf("VTrack::calculate_output_transfer %f %f %f %f -> %f %f %f %f\n",
430 // in_x, in_y, in_w, in_h,
431 // out_x, out_y, out_w, out_h);
436 int VTrack::get_projection(float &in_x1, float &in_y1, float &in_x2, float &in_y2,
437 float &out_x1, float &out_y1, float &out_x2, float &out_y2,
438 int frame_w, int frame_h, int64_t real_position, int direction)
440 float center_x, center_y, center_z;
443 automation->get_projector(¢er_x,
453 center_x += edl->session->output_w / 2;
454 center_y += edl->session->output_h / 2;
456 x[2] = center_x - (frame_w / 2) * center_z;
457 y[2] = center_y - (frame_h / 2) * center_z;
458 x[3] = x[2] + frame_w * center_z;
459 y[3] = y[2] + frame_h * center_z;
463 x[0] -= x[2] / center_z;
468 y[0] -= y[2] / center_z;
471 if(x[3] > edl->session->output_w)
473 x[1] -= (x[3] - edl->session->output_w) / center_z;
474 x[3] = edl->session->output_w;
476 if(y[3] > edl->session->output_h)
478 y[1] -= (y[3] - edl->session->output_h) / center_z;
479 y[3] = edl->session->output_h;
482 in_x1 = x[0]; in_y1 = y[0]; in_x2 = x[1]; in_y2 = y[1];
483 out_x1 = x[2]; out_y1 = y[2]; out_x2 = x[3]; out_y2 = y[3];
489 inline void addto_value(FloatAuto *fauto, float offset)
491 fauto->set_value(fauto->get_value() + offset);
495 void VTrack::translate(float offset_x, float offset_y, int do_camera)
499 subscript = AUTOMATION_CAMERA_X;
501 subscript = AUTOMATION_PROJECTOR_X;
503 // Translate default keyframe
504 addto_value((FloatAuto*)automation->autos[subscript]->default_auto, offset_x);
505 addto_value((FloatAuto*)automation->autos[subscript + 1]->default_auto, offset_y);
507 // Translate everyone else
508 for(Auto *current = automation->autos[subscript]->first;
512 addto_value((FloatAuto*)current, offset_x);
515 for(Auto *current = automation->autos[subscript + 1]->first;
519 addto_value((FloatAuto*)current, offset_y);