r553: Modern gccs require __attribute__((used)) for variables used only in assembly.
[cinelerra_cv/mob.git] / cinelerra / vtrack.C
blobeb60485bf4916143782e523794344bc544a02122
1 #include "asset.h"
2 #include "autoconf.h"
3 #include "bezierauto.h"
4 #include "bezierautos.h"
5 #include "cache.h"
6 #include "clip.h"
7 #include "datatype.h"
8 #include "edit.h"
9 #include "edits.h"
10 #include "edl.h"
11 #include "edlsession.h"
12 #include "filexml.h"
13 #include "floatautos.h"
14 #include "language.h"
15 #include "localsession.h"
16 #include "patch.h"
17 #include "mainsession.h"
18 #include "theme.h"
19 #include "trackcanvas.h"
20 #include "tracks.h"
21 #include "transportque.inc"
22 #include "units.h"
23 #include "vautomation.h"
24 #include "vedit.h"
25 #include "vedits.h"
26 #include "vframe.h"
27 #include "vmodule.h"
28 #include "vpluginset.h"
29 #include "vtrack.h"
31 VTrack::VTrack(EDL *edl, Tracks *tracks)
32  : Track(edl, tracks)
34         data_type = TRACK_VIDEO;
35         draw = 1;
38 VTrack::~VTrack()
42 int VTrack::create_objects()
44         Track::create_objects();
45         automation = new VAutomation(edl, this);
46         automation->create_objects();
47         edits = new VEdits(edl, this);
48         return 0;
51 // Used by PlaybackEngine
52 void VTrack::synchronize_params(Track *track)
54         Track::synchronize_params(track);
56         VTrack *vtrack = (VTrack*)track;
59 // Used by EDL::operator=
60 int VTrack::copy_settings(Track *track)
62         Track::copy_settings(track);
64         VTrack *vtrack = (VTrack*)track;
65         return 0;
68 int VTrack::vertical_span(Theme *theme)
70         int track_h = Track::vertical_span(theme);
71         int patch_h = 0;
72         if(expand_view)
73         {
74                 patch_h += theme->title_h + theme->play_h + theme->fade_h + theme->mode_h;
75         }
76         return MAX(track_h, patch_h);
80 PluginSet* VTrack::new_plugins()
82         return new VPluginSet(edl, this);
85 int VTrack::load_defaults(Defaults *defaults)
87         Track::load_defaults(defaults);
88         return 0;
91 void VTrack::set_default_title()
93         Track *current = ListItem<Track>::owner->first;
94         int i;
95         for(i = 0; current; current = NEXT)
96         {
97                 if(current->data_type == TRACK_VIDEO) i++;
98         }
99         sprintf(title, _("Video %d"), i);
102 int64_t VTrack::to_units(double position, int round)
104         if(round)
105         {
106                 return Units::round(position * edl->session->frame_rate);
107         }
108         else
109         {
110 // Kludge for rounding errors, just on a smaller scale than formal rounding
111                 position *= edl->session->frame_rate;
112                 return Units::to_int64(position);
113         }
116 double VTrack::to_doubleunits(double position)
118         return position * edl->session->frame_rate;
122 double VTrack::from_units(int64_t position)
124         return (double)position / edl->session->frame_rate;
130 int VTrack::identical(int64_t sample1, int64_t sample2)
132 // Units of frames
133         if(labs(sample1 - sample2) <= 1) return 1; else return 0;
136 int VTrack::save_header(FileXML *file)
138         file->tag.set_property("TYPE", "VIDEO");
139         return 0;
142 int VTrack::save_derived(FileXML *file)
144         return 0;
147 int VTrack::load_header(FileXML *file, uint32_t load_flags)
149         return 0;
152 int VTrack::load_derived(FileXML *file, uint32_t load_flags)
154         return 0;
158 int VTrack::direct_copy_possible(int64_t start, int direction, int use_nudge)
160         int i;
161         if(use_nudge) start += nudge;
163 // Track size must equal output size
164         if(track_w != edl->session->output_w || track_h != edl->session->output_h)
165                 return 0;
167 // No automation must be present in the track
168         if(!automation->direct_copy_possible(start, direction))
169                 return 0;
171 // No plugin must be present
172         if(plugin_used(start, direction)) 
173                 return 0;
175 // No transition
176         if(get_current_transition(start, direction, 0, 0))
177                 return 0;
179         return 1;
198 int VTrack::create_derived_objs(int flash)
200         int i;
201         edits = new VEdits(edl, this);
202         return 0;
206 int VTrack::get_dimensions(double &view_start, 
207         double &view_units, 
208         double &zoom_units)
210         view_start = edl->local_session->view_start * edl->session->frame_rate;
211         view_units = 0;
212 //      view_units = Units::toframes(tracks->view_samples(), mwindow->session->sample_rate, mwindow->session->frame_rate);
213         zoom_units = edl->local_session->zoom_sample / edl->session->sample_rate * edl->session->frame_rate;
216 int VTrack::copy_derived(int64_t start, int64_t end, FileXML *xml)
218 // automation is copied in the Track::copy
219         return 0;
222 int VTrack::copy_automation_derived(AutoConf *auto_conf, int64_t start, int64_t end, FileXML *file)
224         return 0;
227 int VTrack::paste_derived(int64_t start, int64_t end, int64_t total_length, FileXML *xml, int &current_channel)
229         return 0;
232 int VTrack::paste_output(int64_t startproject, int64_t endproject, int64_t startsource, int64_t endsource, int layer, Asset *asset)
234         return 0;
237 int VTrack::clear_derived(int64_t start, int64_t end)
239         return 0;
242 int VTrack::paste_automation_derived(int64_t start, int64_t end, int64_t total_length, FileXML *xml, int shift_autos, int &current_pan)
244         return 0;
247 int VTrack::clear_automation_derived(AutoConf *auto_conf, int64_t start, int64_t end, int shift_autos)
249         return 0;
252 int VTrack::draw_autos_derived(float view_start, float zoom_units, AutoConf *auto_conf)
254         return 0;
258 int VTrack::select_auto_derived(float zoom_units, float view_start, AutoConf *auto_conf, int cursor_x, int cursor_y)
260         return 0;
264 int VTrack::move_auto_derived(float zoom_units, float view_start, AutoConf *auto_conf, int cursor_x, int cursor_y, int shift_down)
266         return 0;
269 int VTrack::draw_floating_autos_derived(float view_start, float zoom_units, AutoConf *auto_conf, int flash)
271         return 0;
274 int VTrack::channel_is_playable(int64_t position, int direction, int *do_channel)
276         int result = 0;
277 //printf("VTrack::channel_is_playable 1 %d\n", do_channel[0]);
278         for(int i = 0; i < edl->session->video_channels && !result; i++)
279         {
280                 if(do_channel[i])
281                 {
282                         float in_x, in_y, in_w, in_h;
283                         float out_x, out_y, out_w, out_h;
285                         calculate_output_transfer(i, position, direction, 
286                                 in_x, in_y, in_w, in_h,
287                                 out_x, out_y, out_w, out_h);
289 //printf("VTrack::channel_is_playable %0.0f %0.0f %0.0f %0.0f %0.0f %0.0f %0.0f %0.0f\n", 
290 //in_x, in_y, in_w, in_h, out_x, out_y, out_w, out_h);
291                         if(out_w > 0 && out_h > 0) 
292                                 result = 1;
293                 }
294         }
295         return result;
298 void VTrack::calculate_input_transfer(Asset *asset, 
299         int64_t position, 
300         int direction, 
301         float &in_x, 
302         float &in_y, 
303         float &in_w, 
304         float &in_h,
305         float &out_x, 
306         float &out_y, 
307         float &out_w, 
308         float &out_h)
310         float auto_x, auto_y, auto_z;
311         BezierAuto *before = 0, *after = 0;
312         FloatAuto *previous = 0, *next = 0;
313         float camera_z = 1;
314         float camera_x = asset->width / 2;
315         float camera_y = asset->height / 2;
316         float z[6], x[6], y[6];        // camera and output coords
318 //printf("VTrack::calculate_input_transfer %lld\n", position);
320 // get camera center in asset
321         automation->camera_autos->get_center(auto_x, 
322                 auto_y, 
323                 auto_z, 
324                 position, 
325                 direction, 
326                 &before, 
327                 &after);
328         auto_z = automation->czoom_autos->get_value(position,
329                 direction,
330                 previous,
331                 next);
333         camera_z *= auto_z;
334         camera_x += auto_x;
335         camera_y += auto_y;
337 // get camera coords on asset
338         x[0] = camera_x - (float)track_w / 2 / camera_z;
339         y[0] = camera_y - (float)track_h / 2 / camera_z;
340         x[1] = x[0] + (float)track_w / camera_z;
341         y[1] = y[0] + (float)track_h / camera_z;
343 // get asset coords on camera
344         x[2] = 0;
345         y[2] = 0;
346         x[3] = track_w;
347         y[3] = track_h;
349 // crop asset coords on camera
350         if(x[0] < 0)
351         {
352                 x[2] -= x[0] * camera_z;
353                 x[0] = 0;
354         }
355         if(y[0] < 0)
356         {
357                 y[2] -= y[0] * camera_z;
358                 y[0] = 0;
359         }
360         if(x[1] > asset->width)
361         {
362                 x[3] -= (x[1] - asset->width) * camera_z;
363                 x[1] = asset->width;
364         }
365         if(y[1] > asset->height)
366         {
367                 y[3] -= (y[1] - asset->height) * camera_z;
368                 y[1] = asset->height;
369         }
371 // get output bounding box
372         out_x = x[2];
373         out_y = y[2];
374         out_w = x[3] - x[2];
375         out_h = y[3] - y[2];
377         in_x = x[0];
378         in_y = y[0];
379         in_w = x[1] - x[0];
380         in_h = y[1] - y[0];
383 void VTrack::calculate_output_transfer(int channel, 
384         int64_t position, 
385         int direction, 
386         float &in_x, 
387         float &in_y, 
388         float &in_w, 
389         float &in_h,
390         float &out_x, 
391         float &out_y, 
392         float &out_w, 
393         float &out_h)
395         BezierAuto *before = 0, *after = 0;
396         FloatAuto *previous = 0, *next = 0;
397         float center_x, center_y, center_z;
398         float x[4], y[4];
399         float channel_x1 = edl->session->vchannel_x[channel];
400         float channel_y1 = edl->session->vchannel_y[channel];
401         float channel_x2 = channel_x1 + edl->session->output_w;
402         float channel_y2 = channel_y1 + edl->session->output_h;
404         x[0] = 0;
405         y[0] = 0;
406         x[1] = track_w;
407         y[1] = track_h;
409         automation->projector_autos->get_center(center_x, 
410                 center_y, 
411                 center_z, 
412                 position, 
413                 direction, 
414                 &before, 
415                 &after);
416         center_z = automation->pzoom_autos->get_value(position, 
417                 direction,
418                 previous,
419                 next);
421         center_x += edl->session->output_w / 2;
422         center_y += edl->session->output_h / 2;
424         x[2] = center_x - (track_w / 2) * center_z;
425         y[2] = center_y - (track_h / 2) * center_z;
426         x[3] = x[2] + track_w * center_z;
427         y[3] = y[2] + track_h * center_z;
429 // Clip to boundaries of channel
430         if(x[2] < channel_x1)
431         {
432                 x[0] -= (x[2] - channel_x1) / center_z;
433                 x[2] = channel_x1;
434         }
435         if(y[2] < 0)
436         {
437                 y[0] -= (y[2] - channel_y1) / center_z;
438                 y[2] = 0;
439         }
440         if(x[3] > channel_x2)
441         {
442                 x[1] -= (x[3] - channel_x2) / center_z;
443                 x[3] = channel_x2;
444         }
445         if(y[3] > channel_y2)
446         {
447                 y[1] -= (y[3] - channel_y2) / center_z;
448                 y[3] = channel_y2;
449         }
451         in_x = x[0];
452         in_y = y[0];
453         in_w = x[1] - x[0];
454         in_h = y[1] - y[0];
455         out_x = x[2];
456         out_y = y[2];
457         out_w = x[3] - x[2];
458         out_h = y[3] - y[2];
463 int VTrack::get_projection(int channel, 
464         float &in_x1, 
465         float &in_y1, 
466         float &in_x2, 
467         float &in_y2, 
468         float &out_x1, 
469         float &out_y1, 
470         float &out_x2, 
471         float &out_y2, 
472         int frame_w, 
473         int frame_h, 
474         int64_t real_position, 
475         int direction)
477         float center_x, center_y, center_z;
478         float x[4], y[4];
479         BezierAuto *before = 0, *after = 0;
480         FloatAuto *previous = 0, *next = 0;
482         automation->projector_autos->get_center(center_x, 
483                 center_y, 
484                 center_z, 
485                 real_position, 
486                 direction, 
487                 &before, 
488                 &after);
489         center_z = automation->pzoom_autos->get_value(real_position,
490                 direction,
491                 previous,
492                 next);
494         x[0] = y[0] = 0;
495         x[1] = frame_w;
496         y[1] = frame_h;
498         center_x += edl->session->output_w / 2;
499         center_y += edl->session->output_h / 2;
501         x[2] = center_x - (frame_w / 2) * center_z;
502         y[2] = center_y - (frame_h / 2) * center_z;
503         x[3] = x[2] + frame_w * center_z;
504         y[3] = y[2] + frame_h * center_z;
506         if(x[2] < 0)
507         {
508                 x[0] -= x[2] / center_z;
509                 x[2] = 0;
510         }
511         if(y[2] < 0)
512         {
513                 y[0] -= y[2] / center_z;
514                 y[2] = 0;
515         }
516         if(x[3] > edl->session->output_w)
517         {
518                 x[1] -= (x[3] - edl->session->output_w) / center_z;
519                 x[3] = edl->session->output_w;
520         }
521         if(y[3] > edl->session->output_h)
522         {
523                 y[1] -= (y[3] - edl->session->output_h) / center_z;
524                 y[3] = edl->session->output_h;
525         }
527         in_x1 = x[0];
528         in_y1 = y[0];
529         in_x2 = x[1];
530         in_y2 = y[1];
531         out_x1 = x[2];
532         out_y1 = y[2];
533         out_x2 = x[3];
534         out_y2 = y[3];
535         return 0;
539 void VTrack::translate_camera(float offset_x, float offset_y)
541         ((BezierAuto*)automation->camera_autos->default_auto)->center_x += offset_x;
542         ((BezierAuto*)automation->camera_autos->default_auto)->center_y += offset_y;
544         for(Auto *current = automation->camera_autos->first; 
545                 current; 
546                 current = NEXT)
547         {
548                 ((BezierAuto*)current)->center_x += offset_x;
549                 ((BezierAuto*)current)->center_y += offset_y;
550         }
553 void VTrack::translate_projector(float offset_x, float offset_y)
555         ((BezierAuto*)automation->projector_autos->default_auto)->center_x += offset_x;
556         ((BezierAuto*)automation->projector_autos->default_auto)->center_y += offset_y;
558         for(Auto *current = automation->projector_autos->first; 
559                 current; 
560                 current = NEXT)
561         {
562                 ((BezierAuto*)current)->center_x += offset_x;
563                 ((BezierAuto*)current)->center_y += offset_y;
564         }