4 * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
5 * Copyright (C) 2003-2016 Cinelerra CV contributors
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
31 #include "edlsession.h"
33 #include "floatauto.h"
34 #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;
56 data_h = edl->local_session->zoom_vtrack;
64 void VTrack::create_objects()
66 Track::create_objects();
67 automation = new VAutomation(edl, this);
68 automation->create_objects();
69 edits = new VEdits(edl, this);
72 // Used by PlaybackEngine
73 void VTrack::synchronize_params(Track *track)
75 Track::synchronize_params(track);
76 //VTrack *vtrack = (VTrack*)track;
79 // Used by EDL::operator=
80 int VTrack::copy_settings(Track *track)
82 Track::copy_settings(track);
83 //VTrack *vtrack = (VTrack*)track;
87 int VTrack::vertical_span(Theme *theme)
89 int track_h = Track::vertical_span(theme);
90 int patch_h = theme->title_h;
92 patch_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 static inline void addto_value(FloatAuto *fauto, float offset)
491 fauto->set_value(fauto->get_value() + offset);
494 static inline void multiply_value(FloatAuto *fauto, float scale)
496 fauto->set_value(fauto->get_value() * scale);
500 void VTrack::set_fauto_xy(int fauto, float x, float y)
502 // set default keyframe
503 FloatAuto *xdft = (FloatAuto *)automation->autos[fauto+0]->default_auto;
504 FloatAuto *ydft = (FloatAuto *)automation->autos[fauto+1]->default_auto;
508 FloatAuto *xauto = (FloatAuto *)automation->autos[fauto+0]->first;
509 FloatAuto *yauto = (FloatAuto *)automation->autos[fauto+1]->first;
510 for( ; xauto; xauto=(FloatAuto *)xauto->next ) xauto->set_value(x);
511 for( ; yauto; yauto=(FloatAuto *)yauto->next ) yauto->set_value(y);
514 void VTrack::translate(int fauto, float dx, float dy, int all)
517 addto_value((FloatAuto*)automation->autos[fauto+0]->default_auto, dx);
518 addto_value((FloatAuto*)automation->autos[fauto+1]->default_auto, dy);
519 FloatAutos **fautos = (FloatAutos **)&automation->autos;
520 FloatAuto *xauto = (FloatAuto *)fautos[fauto+0]->first;
521 FloatAuto *yauto = (FloatAuto *)fautos[fauto+1]->first;
522 for( ; xauto; xauto=(FloatAuto *)xauto->next ) addto_value(xauto, dx);
523 for( ; yauto; yauto=(FloatAuto *)yauto->next ) addto_value(yauto, dy);
526 FloatAutos **fautos = (FloatAutos **)&automation->autos;
527 FloatAuto *xauto = (FloatAuto *)fautos[fauto+0]->get_auto_for_editing(-1, 1);
528 FloatAuto *yauto = (FloatAuto *)fautos[fauto+1]->get_auto_for_editing(-1, 1);
529 addto_value(xauto, dx);
530 addto_value(yauto, dy);