r125: This commit was manufactured by cvs2svn to create tag 'r1_1_7-last'.
[cinelerra_cv/mob.git] / hvirtual / cinelerra / vtrack.C
bloba8d204c94caa21d0afc1d0f8639838f37e485a11
1 #include "assets.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 "localsession.h"
15 #include "patch.h"
16 #include "mainsession.h"
17 #include "theme.h"
18 #include "trackcanvas.h"
19 #include "tracks.h"
20 #include "transportque.inc"
21 #include "units.h"
22 #include "vautomation.h"
23 #include "vedit.h"
24 #include "vedits.h"
25 #include "vframe.h"
26 #include "vmodule.h"
27 #include "vpluginset.h"
28 #include "vtrack.h"
30 #include <libintl.h>
31 #define _(String) gettext(String)
32 #define gettext_noop(String) String
33 #define N_(String) gettext_noop (String)
35 VTrack::VTrack(EDL *edl, Tracks *tracks)
36  : Track(edl, tracks)
38         data_type = TRACK_VIDEO;
39         draw = 1;
42 VTrack::~VTrack()
46 int VTrack::create_objects()
48         Track::create_objects();
49         automation = new VAutomation(edl, this);
50         automation->create_objects();
51         edits = new VEdits(edl, this);
52         return 0;
55 // Used by PlaybackEngine
56 void VTrack::synchronize_params(Track *track)
58         Track::synchronize_params(track);
60         VTrack *vtrack = (VTrack*)track;
63 // Used by EDL::operator=
64 int VTrack::copy_settings(Track *track)
66         Track::copy_settings(track);
68         VTrack *vtrack = (VTrack*)track;
69         return 0;
72 int VTrack::vertical_span(Theme *theme)
74         int track_h = Track::vertical_span(theme);
75         int patch_h = 0;
76         if(expand_view)
77         {
78                 patch_h += theme->title_h + theme->play_h + theme->fade_h + theme->mode_h;
79         }
80         return MAX(track_h, patch_h);
84 PluginSet* VTrack::new_plugins()
86         return new VPluginSet(edl, this);
89 int VTrack::load_defaults(Defaults *defaults)
91         Track::load_defaults(defaults);
92         return 0;
95 void VTrack::set_default_title()
97         Track *current = ListItem<Track>::owner->first;
98         int i;
99         for(i = 0; current; current = NEXT)
100         {
101                 if(current->data_type == TRACK_VIDEO) i++;
102         }
103         sprintf(title, _("Video %d"), i);
106 int64_t VTrack::to_units(double position, int round)
108         if(round)
109         {
110                 return Units::round(position * edl->session->frame_rate);
111         }
112         else
113         {
114 // Kludge for rounding errors, just on a smaller scale than formal rounding
115                 position *= edl->session->frame_rate;
116                 return Units::to_int64(position);
117         }
120 double VTrack::to_doubleunits(double position)
122         return position * edl->session->frame_rate;
126 double VTrack::from_units(int64_t position)
128         return (double)position / edl->session->frame_rate;
134 int VTrack::identical(int64_t sample1, int64_t sample2)
136 // Units of frames
137         if(labs(sample1 - sample2) <= 1) return 1; else return 0;
140 int VTrack::save_header(FileXML *file)
142         file->tag.set_property("TYPE", "VIDEO");
143         return 0;
146 int VTrack::save_derived(FileXML *file)
148         return 0;
151 int VTrack::load_header(FileXML *file, uint32_t load_flags)
153         return 0;
156 int VTrack::load_derived(FileXML *file, uint32_t load_flags)
158         return 0;
162 int VTrack::direct_copy_possible(int64_t start, int direction)
164         int i;
166 // Track size must equal output size
167         if(track_w != edl->session->output_w || track_h != edl->session->output_h)
168                 return 0;
170 // No automation must be present in the track
171 //printf("VTrack::direct_copy_possible 1\n");
172         if(!automation->direct_copy_possible(start, direction))
173                 return 0;
174 //printf("VTrack::direct_copy_possible 2\n");
176 // No plugin must be present
177         if(plugin_used(start, direction)) 
178                 return 0;
180 //printf("VTrack::direct_copy_possible 3\n");
181 // No transition
182         if(get_current_transition(start, direction, 0))
183                 return 0;
184 //printf("VTrack::direct_copy_possible 4\n");
186         return 1;
205 int VTrack::create_derived_objs(int flash)
207         int i;
208         edits = new VEdits(edl, this);
209         return 0;
213 int VTrack::get_dimensions(double &view_start, 
214         double &view_units, 
215         double &zoom_units)
217         view_start = edl->local_session->view_start * edl->session->frame_rate;
218         view_units = 0;
219 //      view_units = Units::toframes(tracks->view_samples(), mwindow->session->sample_rate, mwindow->session->frame_rate);
220         zoom_units = edl->local_session->zoom_sample / edl->session->sample_rate * edl->session->frame_rate;
223 int VTrack::copy_derived(int64_t start, int64_t end, FileXML *xml)
225 // automation is copied in the Track::copy
226         return 0;
229 int VTrack::copy_automation_derived(AutoConf *auto_conf, int64_t start, int64_t end, FileXML *file)
231         return 0;
234 int VTrack::paste_derived(int64_t start, int64_t end, int64_t total_length, FileXML *xml, int &current_channel)
236         return 0;
239 int VTrack::paste_output(int64_t startproject, int64_t endproject, int64_t startsource, int64_t endsource, int layer, Asset *asset)
241         return 0;
244 int VTrack::clear_derived(int64_t start, int64_t end)
246         return 0;
249 int VTrack::paste_automation_derived(int64_t start, int64_t end, int64_t total_length, FileXML *xml, int shift_autos, int &current_pan)
251         return 0;
254 int VTrack::clear_automation_derived(AutoConf *auto_conf, int64_t start, int64_t end, int shift_autos)
256         return 0;
259 int VTrack::draw_autos_derived(float view_start, float zoom_units, AutoConf *auto_conf)
261         return 0;
265 int VTrack::select_auto_derived(float zoom_units, float view_start, AutoConf *auto_conf, int cursor_x, int cursor_y)
267         return 0;
271 int VTrack::move_auto_derived(float zoom_units, float view_start, AutoConf *auto_conf, int cursor_x, int cursor_y, int shift_down)
273         return 0;
276 int VTrack::draw_floating_autos_derived(float view_start, float zoom_units, AutoConf *auto_conf, int flash)
278         return 0;
281 int VTrack::channel_is_playable(int64_t position, int direction, int *do_channel)
283         int result = 0;
284 //printf("VTrack::channel_is_playable 1 %d\n", do_channel[0]);
285         for(int i = 0; i < edl->session->video_channels && !result; i++)
286         {
287                 if(do_channel[i])
288                 {
289                         float in_x, in_y, in_w, in_h;
290                         float out_x, out_y, out_w, out_h;
292                         calculate_output_transfer(i, position, direction, 
293                                 in_x, in_y, in_w, in_h,
294                                 out_x, out_y, out_w, out_h);
296 //printf("VTrack::channel_is_playable %0.0f %0.0f %0.0f %0.0f %0.0f %0.0f %0.0f %0.0f\n", 
297 //in_x, in_y, in_w, in_h, out_x, out_y, out_w, out_h);
298                         if(out_w > 0 && out_h > 0) 
299                                 result = 1;
300                 }
301         }
302         return result;
305 void VTrack::calculate_input_transfer(Asset *asset, 
306         int64_t position, 
307         int direction, 
308         float &in_x, 
309         float &in_y, 
310         float &in_w, 
311         float &in_h,
312         float &out_x, 
313         float &out_y, 
314         float &out_w, 
315         float &out_h)
317         float auto_x, auto_y, auto_z;
318         BezierAuto *before = 0, *after = 0;
319         FloatAuto *previous = 0, *next = 0;
320         float camera_z = 1;
321         float camera_x = asset->width / 2;
322         float camera_y = asset->height / 2;
323         float z[6], x[6], y[6];        // camera and output coords
325 // get camera center in asset
326         automation->camera_autos->get_center(auto_x, 
327                 auto_y, 
328                 auto_z, 
329                 (float)position, 
330                 direction, 
331                 &before, 
332                 &after);
333         auto_z = automation->czoom_autos->get_value(position,
334                 direction,
335                 previous,
336                 next);
338         camera_z *= auto_z;
339         camera_x += auto_x;
340         camera_y += auto_y;
342 // get camera coords on asset
343         x[0] = camera_x - (float)track_w / 2 / camera_z;
344         y[0] = camera_y - (float)track_h / 2 / camera_z;
345         x[1] = x[0] + (float)track_w / camera_z;
346         y[1] = y[0] + (float)track_h / camera_z;
348 // get asset coords on camera
349         x[2] = 0;
350         y[2] = 0;
351         x[3] = track_w;
352         y[3] = track_h;
354 // crop asset coords on camera
355         if(x[0] < 0)
356         {
357                 x[2] -= x[0] * camera_z;
358                 x[0] = 0;
359         }
360         if(y[0] < 0)
361         {
362                 y[2] -= y[0] * camera_z;
363                 y[0] = 0;
364         }
365         if(x[1] > asset->width)
366         {
367                 x[3] -= (x[1] - asset->width) * camera_z;
368                 x[1] = asset->width;
369         }
370         if(y[1] > asset->height)
371         {
372                 y[3] -= (y[1] - asset->height) * camera_z;
373                 y[1] = asset->height;
374         }
376 // get output bounding box
377         out_x = x[2];
378         out_y = y[2];
379         out_w = x[3] - x[2];
380         out_h = y[3] - y[2];
382         in_x = x[0];
383         in_y = y[0];
384         in_w = x[1] - x[0];
385         in_h = y[1] - y[0];
388 void VTrack::calculate_output_transfer(int channel, 
389         int64_t position, 
390         int direction, 
391         float &in_x, 
392         float &in_y, 
393         float &in_w, 
394         float &in_h,
395         float &out_x, 
396         float &out_y, 
397         float &out_w, 
398         float &out_h)
400         BezierAuto *before = 0, *after = 0;
401         FloatAuto *previous = 0, *next = 0;
402         float center_x, center_y, center_z;
403         float x[4], y[4];
404         float channel_x1 = edl->session->vchannel_x[channel];
405         float channel_y1 = edl->session->vchannel_y[channel];
406         float channel_x2 = channel_x1 + edl->session->output_w;
407         float channel_y2 = channel_y1 + edl->session->output_h;
409         x[0] = 0;
410         y[0] = 0;
411         x[1] = track_w;
412         y[1] = track_h;
414         automation->projector_autos->get_center(center_x, 
415                 center_y, 
416                 center_z, 
417                 (float)position, 
418                 direction, 
419                 &before, 
420                 &after);
421         center_z = automation->pzoom_autos->get_value(position, 
422                 direction,
423                 previous,
424                 next);
426         center_x += edl->session->output_w / 2;
427         center_y += edl->session->output_h / 2;
429         x[2] = center_x - (track_w / 2) * center_z;
430         y[2] = center_y - (track_h / 2) * center_z;
431         x[3] = x[2] + track_w * center_z;
432         y[3] = y[2] + track_h * center_z;
434 // Clip to boundaries of channel
435         if(x[2] < channel_x1)
436         {
437                 x[0] -= (x[2] - channel_x1) / center_z;
438                 x[2] = channel_x1;
439         }
440         if(y[2] < 0)
441         {
442                 y[0] -= (y[2] - channel_y1) / center_z;
443                 y[2] = 0;
444         }
445         if(x[3] > channel_x2)
446         {
447                 x[1] -= (x[3] - channel_x2) / center_z;
448                 x[3] = channel_x2;
449         }
450         if(y[3] > channel_y2)
451         {
452                 y[1] -= (y[3] - channel_y2) / center_z;
453                 y[3] = channel_y2;
454         }
456         in_x = x[0];
457         in_y = y[0];
458         in_w = x[1] - x[0];
459         in_h = y[1] - y[0];
460         out_x = x[2];
461         out_y = y[2];
462         out_w = x[3] - x[2];
463         out_h = y[3] - y[2];
468 int VTrack::get_projection(int channel, 
469         float &in_x1, 
470         float &in_y1, 
471         float &in_x2, 
472         float &in_y2, 
473         float &out_x1, 
474         float &out_y1, 
475         float &out_x2, 
476         float &out_y2, 
477         int frame_w, 
478         int frame_h, 
479         int64_t real_position, 
480         int direction)
482         float center_x, center_y, center_z;
483         float x[4], y[4];
484         BezierAuto *before = 0, *after = 0;
485         FloatAuto *previous = 0, *next = 0;
487         automation->projector_autos->get_center(center_x, 
488                 center_y, 
489                 center_z, 
490                 (float)real_position, 
491                 direction, 
492                 &before, 
493                 &after);
494         center_z = automation->pzoom_autos->get_value(real_position,
495                 direction,
496                 previous,
497                 next);
499         x[0] = y[0] = 0;
500         x[1] = frame_w;
501         y[1] = frame_h;
503         center_x += edl->session->output_w / 2;
504         center_y += edl->session->output_h / 2;
506         x[2] = center_x - (frame_w / 2) * center_z;
507         y[2] = center_y - (frame_h / 2) * center_z;
508         x[3] = x[2] + frame_w * center_z;
509         y[3] = y[2] + frame_h * center_z;
511         if(x[2] < 0)
512         {
513                 x[0] -= x[2] / center_z;
514                 x[2] = 0;
515         }
516         if(y[2] < 0)
517         {
518                 y[0] -= y[2] / center_z;
519                 y[2] = 0;
520         }
521         if(x[3] > edl->session->output_w)
522         {
523                 x[1] -= (x[3] - edl->session->output_w) / center_z;
524                 x[3] = edl->session->output_w;
525         }
526         if(y[3] > edl->session->output_h)
527         {
528                 y[1] -= (y[3] - edl->session->output_h) / center_z;
529                 y[3] = edl->session->output_h;
530         }
532         in_x1 = x[0];
533         in_y1 = y[0];
534         in_x2 = x[1];
535         in_y2 = y[1];
536         out_x1 = x[2];
537         out_y1 = y[2];
538         out_x2 = x[3];
539         out_y2 = y[3];
540         return 0;
544 void VTrack::translate_camera(float offset_x, float offset_y)
546         ((BezierAuto*)automation->camera_autos->default_auto)->center_x += offset_x;
547         ((BezierAuto*)automation->camera_autos->default_auto)->center_y += offset_y;
549         for(Auto *current = automation->camera_autos->first; 
550                 current; 
551                 current = NEXT)
552         {
553                 ((BezierAuto*)current)->center_x += offset_x;
554                 ((BezierAuto*)current)->center_y += offset_y;
555         }
558 void VTrack::translate_projector(float offset_x, float offset_y)
560         ((BezierAuto*)automation->projector_autos->default_auto)->center_x += offset_x;
561         ((BezierAuto*)automation->projector_autos->default_auto)->center_y += offset_y;
563         for(Auto *current = automation->projector_autos->first; 
564                 current; 
565                 current = NEXT)
566         {
567                 ((BezierAuto*)current)->center_x += offset_x;
568                 ((BezierAuto*)current)->center_y += offset_y;
569         }