3 #include "bezierautos.h"
8 #include "floatautos.h"
11 #include "trackcanvas.h"
19 VTrack::VTrack(MWindow *mwindow, Tracks *tracks) : Track(mwindow, tracks)
21 data_type = TRACK_VIDEO;
28 delete projector_autos;
31 int VTrack::create_derived_objs(int flash)
34 edits = new VEdits(mwindow, this);
35 camera_autos = new BezierAutos(this,
43 projector_autos = new BezierAutos(this,
51 fade_autos = new FloatAutos(this, LTGREY, -100, 100);
52 fade_autos->create_objects();
56 if(mwindow->session->tracks_vertical)
57 draw(pixel, mwindow->zoom_track, 0, tracks->canvas->h, flash);
59 draw(0, tracks->canvas->w, pixel, mwindow->zoom_track, flash);
64 int VTrack::save_derived(FileXML *xml)
68 if(camera_autos->total())
70 xml->tag.set_title("CAMERAAUTOS");
72 xml->append_newline();
73 camera_autos->save(xml);
74 xml->tag.set_title("/CAMERAAUTOS");
76 xml->append_newline();
79 if(projector_autos->total())
81 xml->tag.set_title("PROJECTORAUTOS");
83 xml->append_newline();
84 projector_autos->save(xml);
85 xml->tag.set_title("/PROJECTORAUTOS");
87 xml->append_newline();
91 int VTrack::load_derived(FileXML *xml, int automation_only, int edits_only, int load_all, int &output_channel)
93 if(xml->tag.title_is("CAMERAAUTOS"))
95 camera_autos->load(xml, "/CAMERAAUTOS");
98 if(xml->tag.title_is("PROJECTORAUTOS"))
100 projector_autos->load(xml, "/PROJECTORAUTOS");
104 long VTrack::length()
106 return tosamples(edits->end(), mwindow->sample_rate, mwindow->frame_rate);
109 int VTrack::get_dimensions(float &view_start, float &view_units, float &zoom_units)
111 view_start = toframes(mwindow->view_start, mwindow->sample_rate, mwindow->frame_rate);
112 view_units = toframes(tracks->view_samples(), mwindow->sample_rate, mwindow->frame_rate);
113 zoom_units = toframes(mwindow->zoom_sample, mwindow->sample_rate, mwindow->frame_rate);
116 long VTrack::samples_to_units(long &samples)
118 samples = toframes_round(samples, mwindow->sample_rate, mwindow->frame_rate);
121 int VTrack::copy_derived(long start, long end, FileXML *xml)
123 // automation is copied in the Track::copy
126 int VTrack::copy_automation_derived(AutoConf *auto_conf, long start, long end, FileXML *xml)
128 // used for copying only automation
129 if(auto_conf->camera)
131 xml->tag.set_title("CAMERAAUTOS");
134 camera_autos->copy(start, end, xml, 1);
136 xml->tag.set_title("/CAMERAAUTOS");
138 xml->append_newline();
141 if(auto_conf->projector)
143 xml->tag.set_title("PROJECTORAUTOS");
146 projector_autos->copy(start, end, xml, 1);
148 xml->tag.set_title("/PROJECTORAUTOS");
150 xml->append_newline();
154 int VTrack::paste_derived(long start, long end, long total_length, FileXML *xml, int ¤t_channel)
156 if(xml->tag.title_is("CAMERAAUTOS"))
158 camera_autos->paste(start, end, total_length, xml, "/CAMERAAUTOS", 1);
161 if(xml->tag.title_is("PROJECTORAUTOS"))
163 projector_autos->paste(start, end, total_length, xml, "/PROJECTORAUTOS", 1);
167 int VTrack::paste_output(long startproject, long endproject, long startsource, long endsource, int layer, Asset_GC asset)
171 //printf("VTrack::paste_output startproject %ld endproject %ld\n", startproject, endproject);
172 //Track::samples_to_units(startproject, endproject);
174 result = ((VEdits*)edits)->paste_edit(startproject,
177 endsource - startsource,
184 //if(!result && mwindow->autos_follow_edits)
186 // paste_auto_silence(startproject, endproject);
191 int VTrack::clear_derived(long start, long end)
193 if(mwindow->autos_follow_edits)
195 camera_autos->clear(start, end, mwindow->autos_follow_edits, 1);
196 projector_autos->clear(start, end, mwindow->autos_follow_edits, 1);
200 int VTrack::paste_automation_derived(long start, long end, long total_length, FileXML *xml, int shift_autos, int ¤t_pan)
202 // only used for pasting automation
203 camera_autos->paste(start, end, total_length, xml, "/CAMERAUTOS", 1, shift_autos);
204 projector_autos->paste(start, end, total_length, xml, "/PROJECTORAUTOS", 1, shift_autos);
207 int VTrack::clear_automation_derived(AutoConf *auto_conf, long start, long end, int shift_autos)
209 if(auto_conf->camera)
210 camera_autos->clear(start, end, mwindow->autos_follow_edits, shift_autos);
212 if(auto_conf->projector)
213 projector_autos->clear(start, end, mwindow->autos_follow_edits, shift_autos);
216 int VTrack::paste_auto_silence_derived(long start, long end)
218 camera_autos->paste_silence(start, end);
219 projector_autos->paste_silence(start, end);
222 int VTrack::draw_autos_derived(float view_start, float zoom_units, AutoConf *auto_conf)
224 if(auto_conf->camera)
225 camera_autos->draw(tracks->canvas,
230 mwindow->session->tracks_vertical);
232 if(auto_conf->projector)
233 projector_autos->draw(tracks->canvas,
238 mwindow->session->tracks_vertical);
241 int VTrack::select_translation(int cursor_x, int cursor_y)
243 // cursor position is relative to time
245 float view_start, view_units, zoom_units;
246 get_dimensions(view_start, view_units, zoom_units);
248 if(cursor_y > pixel && cursor_y < pixel + mwindow->zoom_track)
250 for(Edit* current = edits->first; current && !result; current = NEXT)
252 result = ((VEdit*)current)->select_translation(cursor_x, cursor_y, view_start, zoom_units);
258 int VTrack::update_translation(int cursor_x, int cursor_y, int shift_down)
261 float view_start, view_units, zoom_units;
262 get_dimensions(view_start, view_units, zoom_units);
264 for(Edit* current = edits->first; current && !result; current = NEXT)
266 result = ((VEdit*)current)->update_translation(cursor_x, cursor_y, shift_down, view_start, zoom_units);
271 int VTrack::end_translation()
274 for(Edit* current = edits->first; current && !result; current = NEXT)
276 result = ((VEdit*)current)->end_translation();
281 int VTrack::reset_translation(long start, long end)
284 Track::samples_to_units(start, end);
285 for(Edit* current = edits->first; current && !result; current = NEXT)
287 result = ((VEdit*)current)->reset_translation(start, end);
293 int VTrack::select_auto_derived(float zoom_units, float view_start, AutoConf *auto_conf, int cursor_x, int cursor_y)
297 if(auto_conf->camera)
298 result = camera_autos->select_auto(tracks->canvas,
305 tracks->canvas->shift_down(),
306 tracks->canvas->ctrl_down(),
307 tracks->canvas->get_buttonpress(),
308 mwindow->session->tracks_vertical);
310 if(auto_conf->projector && !result)
311 result = projector_autos->select_auto(tracks->canvas,
318 tracks->canvas->shift_down(),
319 tracks->canvas->ctrl_down(),
320 tracks->canvas->get_buttonpress(),
321 mwindow->session->tracks_vertical);
327 int VTrack::move_auto_derived(float zoom_units, float view_start, AutoConf *auto_conf, int cursor_x, int cursor_y, int shift_down)
332 if(auto_conf->camera)
333 result = camera_autos->move_auto(tracks->canvas,
341 mwindow->session->tracks_vertical);
343 if(auto_conf->projector && !result)
344 result = projector_autos->move_auto(tracks->canvas,
352 mwindow->session->tracks_vertical);
356 mwindow->tracks->hide_overlays(0);
357 draw_clear(0, tracks->canvas->w, 0, tracks->canvas->h, 0);
358 draw(0, tracks->canvas->w, 0, tracks->canvas->h, 0);
359 mwindow->tracks->show_overlays(0);
365 int VTrack::draw_floating_autos_derived(float view_start, float zoom_units, AutoConf *auto_conf, int flash)
367 if(auto_conf->camera)
368 camera_autos->draw_floating_autos(tracks->canvas,
373 mwindow->session->tracks_vertical, flash);
375 if(auto_conf->projector)
376 projector_autos->draw_floating_autos(tracks->canvas,
381 mwindow->session->tracks_vertical, flash);
384 int VTrack::release_auto_derived()
389 result = camera_autos->release_auto();
390 if(!result) result = projector_autos->release_auto();
395 int VTrack::scale_video(float camera_scale, float projector_scale, int *offsets)
398 for(VEdit *current = (VEdit*)edits->first; current; current = (VEdit*)NEXT)
400 current->center_z *= camera_scale;
401 current->center_x = -offsets[0];
402 current->center_y = -offsets[1];
405 // Fix the projector.
406 projector_autos->scale_video(projector_scale, &offsets[2]);
409 int VTrack::render(VFrame **output, long input_len, long input_position, float step)
411 BezierAuto *before[4], *after[4]; // for bounding box
413 for(i = 0; i < 4; i++) { before[i] = 0; after[i] = 0; }
415 // clear output buffer
416 // for(i = 0; i < input_len; i++)
418 // output[i]->clear_frame();
420 output[0]->clear_frame();
422 // Render from the last edit to the first edit to accomidate feathering
423 for(VEdit *current = (VEdit*)edits->last; current; current = (VEdit*)PREVIOUS)
425 //if(current == (VEdit*)edits->first || current == (VEdit*)edits->first->next)
426 // printf("%d %d %d\n", input_position, current->startproject, current->startproject + current->length);
427 if(input_position < current->startproject + current->length + current->feather_right &&
428 input_position >= current->startproject)
429 current->render(output,
435 get_patch_of()->automate);
439 int VTrack::get_projection(float &in_x1, float &in_y1, float &in_x2, float &in_y2,
440 float &out_x1, float &out_y1, float &out_x2, float &out_y2,
441 int frame_w, int frame_h, long real_position,
442 BezierAuto **before, BezierAuto **after)
444 static float center_x, center_y, center_z;
445 static float x[4], y[4];
447 projector_autos->get_center(center_x, center_y, center_z, (float)real_position, 0, before, after);
452 center_x += mwindow->output_w / 2;
453 center_y += mwindow->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] > mwindow->output_w)
472 x[1] -= (x[3] - mwindow->output_w) / center_z;
473 x[3] = mwindow->output_w;
475 if(y[3] > mwindow->output_h)
477 y[1] -= (y[3] - mwindow->output_h) / center_z;
478 y[3] = mwindow->output_h;
491 int VTrack::scale_time_derived(float rate_scale, int scale_edits, int scale_autos, long start, long end)
493 camera_autos->scale_time(rate_scale, scale_edits, scale_autos, start, end);
494 projector_autos->scale_time(rate_scale, scale_edits, scale_autos, start, end);
500 // c-file-style: "linux"