r1009: Move the dependencies to newer package names
[cinelerra_cv/mob.git] / cinelerra / vtransition.C
blobe241d612a8283b3ae113bec4f4d171af671632f0
1 #include "assets.h"
2 #include "autoconf.h"
3 #include "bezierautos.h"
4 #include "cache.h"
5 #include "edit.h"
6 #include "edits.h"
7 #include "filexml.h"
8 #include "floatautos.h"
9 #include "mwindow.h"
10 #include "patch.h"
11 #include "trackcanvas.h"
12 #include "tracks.h"
13 #include "vedit.h"
14 #include "vedits.h"
15 #include "vframe.h"
16 #include "vtrack.h"
17 #include "datatype.h"
19 VTrack::VTrack(MWindow *mwindow, Tracks *tracks) : Track(mwindow, tracks)
21         data_type = TRACK_VIDEO;
24 VTrack::~VTrack()
26         delete edits;
27         delete camera_autos;
28         delete projector_autos;
31 int VTrack::create_derived_objs(int flash)
33         int i;
34         edits = new VEdits(mwindow, this);
35         camera_autos = new BezierAutos(this, 
36                                                                         WHITE, 
37                                                                         0, 
38                                                                         0, 
39                                                                         1, 
40                                                                         mwindow->track_w,
41                                                                         mwindow->track_h);
42         
43         projector_autos = new BezierAutos(this,
44                                                                         WHITE,
45                                                                         0,
46                                                                         0,
47                                                                         1,
48                                                                         mwindow->output_w,
49                                                                         mwindow->output_h);
50         
51         fade_autos = new FloatAutos(this, LTGREY, -100, 100);
52         fade_autos->create_objects();
54         if(mwindow->gui)
55         {
56                 if(mwindow->session->tracks_vertical)
57                 draw(pixel, mwindow->zoom_track, 0, tracks->canvas->h, flash);
58                 else
59                 draw(0, tracks->canvas->w, pixel, mwindow->zoom_track, flash);
60         }
64 int VTrack::save_derived(FileXML *xml)
66         edits->save(xml);
68         if(camera_autos->total())
69         {
70                 xml->tag.set_title("CAMERAAUTOS");
71                 xml->append_tag();
72                 xml->append_newline();
73                 camera_autos->save(xml);
74                 xml->tag.set_title("/CAMERAAUTOS");
75                 xml->append_tag();
76                 xml->append_newline();
77         }
79         if(projector_autos->total())
80         {
81                 xml->tag.set_title("PROJECTORAUTOS");
82                 xml->append_tag();
83                 xml->append_newline();
84                 projector_autos->save(xml);
85                 xml->tag.set_title("/PROJECTORAUTOS");
86                 xml->append_tag();
87                 xml->append_newline();
88         }
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"))
94         {
95                 camera_autos->load(xml, "/CAMERAAUTOS");
96         }
97         else
98         if(xml->tag.title_is("PROJECTORAUTOS"))
99         {
100                 projector_autos->load(xml, "/PROJECTORAUTOS");
101         }
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)
130         {
131                 xml->tag.set_title("CAMERAAUTOS");
132                 xml->append_tag();
134                 camera_autos->copy(start, end, xml, 1);
136                 xml->tag.set_title("/CAMERAAUTOS");
137                 xml->append_tag();
138                 xml->append_newline();
139         }
141         if(auto_conf->projector)
142         {
143                 xml->tag.set_title("PROJECTORAUTOS");
144                 xml->append_tag();
146                 projector_autos->copy(start, end, xml, 1);
148                 xml->tag.set_title("/PROJECTORAUTOS");
149                 xml->append_tag();
150                 xml->append_newline();
151         }
154 int VTrack::paste_derived(long start, long end, long total_length, FileXML *xml, int &current_channel)
156         if(xml->tag.title_is("CAMERAAUTOS"))
157         {
158                 camera_autos->paste(start, end, total_length, xml, "/CAMERAAUTOS", 1);
159         }
160         else
161         if(xml->tag.title_is("PROJECTORAUTOS"))
162         {
163                 projector_autos->paste(start, end, total_length, xml, "/PROJECTORAUTOS", 1);
164         }
167 int VTrack::paste_output(long startproject, long endproject, long startsource, long endsource, int layer, Asset *asset)
169         int result = 0;
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, 
175                                                 endproject, 
176                                                 startsource, 
177                                                 endsource - startsource, 
178                                                 layer, 
179                                                 0,
180                                                 0,
181                                                 1,
182                                                 asset);
184         //if(!result && mwindow->autos_follow_edits)
185         //{
186         //      paste_auto_silence(startproject, endproject);
187         //}
188         return result;
191 int VTrack::clear_derived(long start, long end)
193         if(mwindow->autos_follow_edits)
194         {
195                 camera_autos->clear(start, end, mwindow->autos_follow_edits, 1);
196                 projector_autos->clear(start, end, mwindow->autos_follow_edits, 1);
197         }
200 int VTrack::paste_automation_derived(long start, long end, long total_length, FileXML *xml, int shift_autos, int &current_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, 
226                                                         pixel,
227                                                         mwindow->zoom_track, 
228                                                         zoom_units, 
229                                                         view_start, 
230                                                         mwindow->session->tracks_vertical);
232                 if(auto_conf->projector)
233                         projector_autos->draw(tracks->canvas, 
234                                                         pixel,
235                                                         mwindow->zoom_track, 
236                                                         zoom_units, 
237                                                         view_start, 
238                                                         mwindow->session->tracks_vertical);
241 int VTrack::select_translation(int cursor_x, int cursor_y)
243 // cursor position is relative to time
244         int result = 0;
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)
249         {
250                 for(Edit* current = edits->first; current && !result; current = NEXT)
251                 {
252                         result = ((VEdit*)current)->select_translation(cursor_x, cursor_y, view_start, zoom_units);
253                 }
254         }
255         return result;
258 int VTrack::update_translation(int cursor_x, int cursor_y, int shift_down)
260         int result = 0;
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)
265         {
266                 result = ((VEdit*)current)->update_translation(cursor_x, cursor_y, shift_down, view_start, zoom_units);
267         }
268         return result;
271 int VTrack::end_translation()
273         int result = 0;
274         for(Edit* current = edits->first; current && !result; current = NEXT)
275         {
276                 result = ((VEdit*)current)->end_translation();
277         }
278         return result;
281 int VTrack::reset_translation(long start, long end)
283         int result = 0;
284         Track::samples_to_units(start, end);
285         for(Edit* current = edits->first; current && !result; current = NEXT)
286         {
287                 result = ((VEdit*)current)->reset_translation(start, end);
288         }
289         return result;
293 int VTrack::select_auto_derived(float zoom_units, float view_start, AutoConf *auto_conf, int cursor_x, int cursor_y)
295         int result = 0;
297         if(auto_conf->camera) 
298                 result = camera_autos->select_auto(tracks->canvas, 
299                                                                                 pixel, 
300                                                                                 mwindow->zoom_track, 
301                                                                                 zoom_units, 
302                                                                                 view_start, 
303                                                                                 cursor_x, 
304                                                                                 cursor_y, 
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, 
312                                                                                 pixel, 
313                                                                                 mwindow->zoom_track, 
314                                                                                 zoom_units, 
315                                                                                 view_start, 
316                                                                                 cursor_x, 
317                                                                                 cursor_y, 
318                                                                                 tracks->canvas->shift_down(),
319                                                                                 tracks->canvas->ctrl_down(),
320                                                                                 tracks->canvas->get_buttonpress(),
321                                                                                 mwindow->session->tracks_vertical);
323         return result;
327 int VTrack::move_auto_derived(float zoom_units, float view_start, AutoConf *auto_conf, int cursor_x, int cursor_y, int shift_down)
329         int result;
330         result = 0;
332         if(auto_conf->camera)
333                 result = camera_autos->move_auto(tracks->canvas, 
334                                                                         pixel, 
335                                                                         mwindow->zoom_track, 
336                                                                         zoom_units, 
337                                                                         view_start, 
338                                                                         cursor_x, 
339                                                                         cursor_y, 
340                                                                         shift_down, 
341                                                                         mwindow->session->tracks_vertical);
343         if(auto_conf->projector && !result)
344                 result = projector_autos->move_auto(tracks->canvas, 
345                                                                         pixel, 
346                                                                         mwindow->zoom_track, 
347                                                                         zoom_units, 
348                                                                         view_start, 
349                                                                         cursor_x, 
350                                                                         cursor_y, 
351                                                                         shift_down, 
352                                                                         mwindow->session->tracks_vertical);
354         if(result)
355         {
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);
360         }
362         return result;
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, 
369                                                                 pixel, 
370                                                                 mwindow->zoom_track, 
371                                                                 zoom_units, 
372                                                                 view_start, 
373                                                                 mwindow->session->tracks_vertical, flash);
375         if(auto_conf->projector) 
376                 projector_autos->draw_floating_autos(tracks->canvas, 
377                                                                 pixel, 
378                                                                 mwindow->zoom_track, 
379                                                                 zoom_units, 
380                                                                 view_start, 
381                                                                 mwindow->session->tracks_vertical, flash);
384 int VTrack::release_auto_derived()
386         int result;
387         result = 0;
389         result = camera_autos->release_auto();
390         if(!result) result = projector_autos->release_auto();
391                 
392         return result;
395 int VTrack::scale_video(float camera_scale, float projector_scale, int *offsets)
397 // Fix the camera.
398         for(VEdit *current = (VEdit*)edits->first; current; current = (VEdit*)NEXT)
399         {
400                 current->center_z *= camera_scale;
401                 current->center_x = -offsets[0];
402                 current->center_y = -offsets[1];
403         }
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
412         int i;
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++)
417 //      {
418 //              output[i]->clear_frame();
419 //      }
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)
424         {
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, 
430                                 input_len, 
431                                 input_position, 
432                                 step, 
433                                 before, 
434                                 after, 
435                                 get_patch_of()->automate);
436         }
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);
448         x[0] = y[0] = 0;
449         x[1] = frame_w;
450         y[1] = frame_h;
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;
460         if(x[2] < 0)
461         {
462                 x[0] -= x[2] / center_z;
463                 x[2] = 0;
464         }
465         if(y[2] < 0)
466         {
467                 y[0] -= y[2] / center_z;
468                 y[2] = 0;
469         }
470         if(x[3] > mwindow->output_w)
471         {
472                 x[1] -= (x[3] - mwindow->output_w) / center_z;
473                 x[3] = mwindow->output_w;
474         }
475         if(y[3] > mwindow->output_h)
476         {
477                 y[1] -= (y[3] - mwindow->output_h) / center_z;
478                 y[3] = mwindow->output_h;
479         }
480         
481         in_x1 = x[0];
482         in_y1 = y[0];
483         in_x2 = x[1];
484         in_y2 = y[1];
485         out_x1 = x[2];
486         out_y1 = y[2];
487         out_x2 = x[3];
488         out_y2 = y[3];
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);