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
24 #include "bezierautos.h"
29 #include "floatautos.h"
32 #include "trackcanvas.h"
40 VTrack::VTrack(MWindow *mwindow, Tracks *tracks) : Track(mwindow, tracks)
42 data_type = TRACK_VIDEO;
49 delete projector_autos;
52 int VTrack::create_derived_objs(int flash)
55 edits = new VEdits(mwindow, this);
56 camera_autos = new BezierAutos(this,
64 projector_autos = new BezierAutos(this,
72 fade_autos = new FloatAutos(this, LTGREY, -100, 100);
73 fade_autos->create_objects();
77 if(mwindow->session->tracks_vertical)
78 draw(pixel, mwindow->zoom_track, 0, tracks->canvas->h, flash);
80 draw(0, tracks->canvas->w, pixel, mwindow->zoom_track, flash);
85 int VTrack::save_derived(FileXML *xml)
89 if(camera_autos->total())
91 xml->tag.set_title("CAMERAAUTOS");
93 xml->append_newline();
94 camera_autos->save(xml);
95 xml->tag.set_title("/CAMERAAUTOS");
97 xml->append_newline();
100 if(projector_autos->total())
102 xml->tag.set_title("PROJECTORAUTOS");
104 xml->append_newline();
105 projector_autos->save(xml);
106 xml->tag.set_title("/PROJECTORAUTOS");
108 xml->append_newline();
112 int VTrack::load_derived(FileXML *xml, int automation_only, int edits_only, int load_all, int &output_channel)
114 if(xml->tag.title_is("CAMERAAUTOS"))
116 camera_autos->load(xml, "/CAMERAAUTOS");
119 if(xml->tag.title_is("PROJECTORAUTOS"))
121 projector_autos->load(xml, "/PROJECTORAUTOS");
125 long VTrack::length()
127 return tosamples(edits->end(), mwindow->sample_rate, mwindow->frame_rate);
130 // int VTrack::get_dimensions(float &view_start, float &view_units, float &zoom_units)
132 // view_start = toframes(mwindow->view_start, mwindow->sample_rate, mwindow->frame_rate);
133 // view_units = toframes(tracks->view_samples(), mwindow->sample_rate, mwindow->frame_rate);
134 // zoom_units = toframes(mwindow->zoom_sample, mwindow->sample_rate, mwindow->frame_rate);
137 long VTrack::samples_to_units(long &samples)
139 samples = toframes_round(samples, mwindow->sample_rate, mwindow->frame_rate);
142 int VTrack::copy_derived(long start, long end, FileXML *xml)
144 // automation is copied in the Track::copy
147 int VTrack::copy_automation_derived(AutoConf *auto_conf, long start, long end, FileXML *xml)
149 // used for copying only automation
150 if(auto_conf->camera)
152 xml->tag.set_title("CAMERAAUTOS");
155 camera_autos->copy(start, end, xml, 1);
157 xml->tag.set_title("/CAMERAAUTOS");
159 xml->append_newline();
162 if(auto_conf->projector)
164 xml->tag.set_title("PROJECTORAUTOS");
167 projector_autos->copy(start, end, xml, 1);
169 xml->tag.set_title("/PROJECTORAUTOS");
171 xml->append_newline();
175 int VTrack::paste_derived(long start, long end, long total_length, FileXML *xml, int ¤t_channel)
177 if(xml->tag.title_is("CAMERAAUTOS"))
179 camera_autos->paste(start, end, total_length, xml, "/CAMERAAUTOS", 1);
182 if(xml->tag.title_is("PROJECTORAUTOS"))
184 projector_autos->paste(start, end, total_length, xml, "/PROJECTORAUTOS", 1);
188 int VTrack::paste_output(long startproject, long endproject, long startsource, long endsource, int layer, Asset *asset)
192 //printf("VTrack::paste_output startproject %ld endproject %ld\n", startproject, endproject);
193 //Track::samples_to_units(startproject, endproject);
195 result = ((VEdits*)edits)->paste_edit(startproject,
198 endsource - startsource,
205 //if(!result && mwindow->autos_follow_edits)
207 // paste_auto_silence(startproject, endproject);
212 int VTrack::clear_derived(long start, long end)
214 if(mwindow->autos_follow_edits)
216 camera_autos->clear(start, end, mwindow->autos_follow_edits, 1);
217 projector_autos->clear(start, end, mwindow->autos_follow_edits, 1);
221 int VTrack::paste_automation_derived(long start, long end, long total_length, FileXML *xml, int shift_autos, int ¤t_pan)
223 // only used for pasting automation
224 camera_autos->paste(start, end, total_length, xml, "/CAMERAUTOS", 1, shift_autos);
225 projector_autos->paste(start, end, total_length, xml, "/PROJECTORAUTOS", 1, shift_autos);
228 int VTrack::clear_automation_derived(AutoConf *auto_conf, long start, long end, int shift_autos)
230 if(auto_conf->camera)
231 camera_autos->clear(start, end, mwindow->autos_follow_edits, shift_autos);
233 if(auto_conf->projector)
234 projector_autos->clear(start, end, mwindow->autos_follow_edits, shift_autos);
237 int VTrack::paste_auto_silence_derived(long start, long end)
239 camera_autos->paste_silence(start, end);
240 projector_autos->paste_silence(start, end);
243 int VTrack::draw_autos_derived(float view_start, float zoom_units, AutoConf *auto_conf)
245 if(auto_conf->camera)
246 camera_autos->draw(tracks->canvas,
251 mwindow->session->tracks_vertical);
253 if(auto_conf->projector)
254 projector_autos->draw(tracks->canvas,
259 mwindow->session->tracks_vertical);
262 int VTrack::select_translation(int cursor_x, int cursor_y)
264 // cursor position is relative to time
266 float view_start, view_units, zoom_units;
267 get_dimensions(view_start, view_units, zoom_units);
269 if(cursor_y > pixel && cursor_y < pixel + mwindow->zoom_track)
271 for(Edit* current = edits->first; current && !result; current = NEXT)
273 result = ((VEdit*)current)->select_translation(cursor_x, cursor_y, view_start, zoom_units);
279 int VTrack::update_translation(int cursor_x, int cursor_y, int shift_down)
282 float view_start, view_units, zoom_units;
283 get_dimensions(view_start, view_units, zoom_units);
285 for(Edit* current = edits->first; current && !result; current = NEXT)
287 result = ((VEdit*)current)->update_translation(cursor_x, cursor_y, shift_down, view_start, zoom_units);
292 int VTrack::end_translation()
295 for(Edit* current = edits->first; current && !result; current = NEXT)
297 result = ((VEdit*)current)->end_translation();
302 int VTrack::reset_translation(long start, long end)
305 Track::samples_to_units(start, end);
306 for(Edit* current = edits->first; current && !result; current = NEXT)
308 result = ((VEdit*)current)->reset_translation(start, end);
314 int VTrack::select_auto_derived(float zoom_units, float view_start, AutoConf *auto_conf, int cursor_x, int cursor_y)
318 if(auto_conf->camera)
319 result = camera_autos->select_auto(tracks->canvas,
326 tracks->canvas->shift_down(),
327 tracks->canvas->ctrl_down(),
328 tracks->canvas->get_buttonpress(),
329 mwindow->session->tracks_vertical);
331 if(auto_conf->projector && !result)
332 result = projector_autos->select_auto(tracks->canvas,
339 tracks->canvas->shift_down(),
340 tracks->canvas->ctrl_down(),
341 tracks->canvas->get_buttonpress(),
342 mwindow->session->tracks_vertical);
348 int VTrack::move_auto_derived(float zoom_units, float view_start, AutoConf *auto_conf, int cursor_x, int cursor_y, int shift_down)
353 if(auto_conf->camera)
354 result = camera_autos->move_auto(tracks->canvas,
362 mwindow->session->tracks_vertical);
364 if(auto_conf->projector && !result)
365 result = projector_autos->move_auto(tracks->canvas,
373 mwindow->session->tracks_vertical);
377 mwindow->tracks->hide_overlays(0);
378 draw_clear(0, tracks->canvas->w, 0, tracks->canvas->h, 0);
379 draw(0, tracks->canvas->w, 0, tracks->canvas->h, 0);
380 mwindow->tracks->show_overlays(0);
386 int VTrack::draw_floating_autos_derived(float view_start, float zoom_units, AutoConf *auto_conf, int flash)
388 if(auto_conf->camera)
389 camera_autos->draw_floating_autos(tracks->canvas,
394 mwindow->session->tracks_vertical, flash);
396 if(auto_conf->projector)
397 projector_autos->draw_floating_autos(tracks->canvas,
402 mwindow->session->tracks_vertical, flash);
405 int VTrack::release_auto_derived()
410 result = camera_autos->release_auto();
411 if(!result) result = projector_autos->release_auto();
416 int VTrack::scale_video(float camera_scale, float projector_scale, int *offsets)
419 for(VEdit *current = (VEdit*)edits->first; current; current = (VEdit*)NEXT)
421 current->center_z *= camera_scale;
422 current->center_x = -offsets[0];
423 current->center_y = -offsets[1];
426 // Fix the projector.
427 projector_autos->scale_video(projector_scale, &offsets[2]);
430 int VTrack::render(VFrame **output, long input_len, long input_position, float step)
432 BezierAuto *before[4], *after[4]; // for bounding box
434 for(i = 0; i < 4; i++) { before[i] = 0; after[i] = 0; }
436 // clear output buffer
437 // for(i = 0; i < input_len; i++)
439 // output[i]->clear_frame();
441 output[0]->clear_frame();
443 // Render from the last edit to the first edit to accomidate feathering
444 for(VEdit *current = (VEdit*)edits->last; current; current = (VEdit*)PREVIOUS)
446 //if(current == (VEdit*)edits->first || current == (VEdit*)edits->first->next)
447 // printf("%d %d %d\n", input_position, current->startproject, current->startproject + current->length);
448 if(input_position < current->startproject + current->length + current->feather_right &&
449 input_position >= current->startproject)
450 current->render(output,
456 get_patch_of()->automate);
460 int VTrack::get_projection(float &in_x1, float &in_y1, float &in_x2, float &in_y2,
461 float &out_x1, float &out_y1, float &out_x2, float &out_y2,
462 int frame_w, int frame_h, long real_position,
463 BezierAuto **before, BezierAuto **after)
465 static float center_x, center_y, center_z;
466 static float x[4], y[4];
468 projector_autos->get_center(center_x, center_y, center_z, (float)real_position, 0, before, after);
473 center_x += mwindow->output_w / 2;
474 center_y += mwindow->output_h / 2;
476 x[2] = center_x - (frame_w / 2) * center_z;
477 y[2] = center_y - (frame_h / 2) * center_z;
478 x[3] = x[2] + frame_w * center_z;
479 y[3] = y[2] + frame_h * center_z;
483 x[0] -= x[2] / center_z;
488 y[0] -= y[2] / center_z;
491 if(x[3] > mwindow->output_w)
493 x[1] -= (x[3] - mwindow->output_w) / center_z;
494 x[3] = mwindow->output_w;
496 if(y[3] > mwindow->output_h)
498 y[1] -= (y[3] - mwindow->output_h) / center_z;
499 y[3] = mwindow->output_h;
512 int VTrack::scale_time_derived(float rate_scale, int scale_edits, int scale_autos, long start, long end)
514 camera_autos->scale_time(rate_scale, scale_edits, scale_autos, start, end);
515 projector_autos->scale_time(rate_scale, scale_edits, scale_autos, start, end);