r802: Remove renderframfsclient and renderfarmfsserver .h and .C from Makefile.am...
[cinelerra_cv/mob.git] / cinelerra / vtrack.C
blob40d05239144271444aa276ef444cbf1b2bb6c5b0
1 #include "asset.h"
2 #include "autoconf.h"
3 #include "cache.h"
4 #include "clip.h"
5 #include "datatype.h"
6 #include "edit.h"
7 #include "edits.h"
8 #include "edl.h"
9 #include "edlsession.h"
10 #include "filexml.h"
11 #include "floatauto.h"
12 #include "floatautos.h"
13 #include "language.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 VTrack::VTrack(EDL *edl, Tracks *tracks)
31  : Track(edl, tracks)
33         data_type = TRACK_VIDEO;
34         draw = 1;
37 VTrack::~VTrack()
41 int VTrack::create_objects()
43         Track::create_objects();
44         automation = new VAutomation(edl, this);
45         automation->create_objects();
46         edits = new VEdits(edl, this);
47         return 0;
50 // Used by PlaybackEngine
51 void VTrack::synchronize_params(Track *track)
53         Track::synchronize_params(track);
55         VTrack *vtrack = (VTrack*)track;
58 // Used by EDL::operator=
59 int VTrack::copy_settings(Track *track)
61         Track::copy_settings(track);
63         VTrack *vtrack = (VTrack*)track;
64         return 0;
67 int VTrack::vertical_span(Theme *theme)
69         int track_h = Track::vertical_span(theme);
70         int patch_h = 0;
71         if(expand_view)
72         {
73                 patch_h += theme->title_h + theme->play_h + theme->fade_h + theme->mode_h;
74         }
75         return MAX(track_h, patch_h);
79 PluginSet* VTrack::new_plugins()
81         return new VPluginSet(edl, this);
84 int VTrack::load_defaults(Defaults *defaults)
86         Track::load_defaults(defaults);
87         return 0;
90 void VTrack::set_default_title()
92         Track *current = ListItem<Track>::owner->first;
93         int i;
94         for(i = 0; current; current = NEXT)
95         {
96                 if(current->data_type == TRACK_VIDEO) i++;
97         }
98         sprintf(title, _("Video %d"), i);
101 int64_t VTrack::to_units(double position, int round)
103         if(round)
104         {
105                 return Units::round(position * edl->session->frame_rate);
106         }
107         else
108         {
109 // Kludge for rounding errors, just on a smaller scale than formal rounding
110                 position *= edl->session->frame_rate;
111                 return Units::to_int64(position);
112         }
115 double VTrack::to_doubleunits(double position)
117         return position * edl->session->frame_rate;
121 double VTrack::from_units(int64_t position)
123         return (double)position / edl->session->frame_rate;
129 int VTrack::identical(int64_t sample1, int64_t sample2)
131 // Units of frames
132         if(labs(sample1 - sample2) <= 1) return 1; else return 0;
135 int VTrack::save_header(FileXML *file)
137         file->tag.set_property("TYPE", "VIDEO");
138         return 0;
141 int VTrack::save_derived(FileXML *file)
143         return 0;
146 int VTrack::load_header(FileXML *file, uint32_t load_flags)
148         return 0;
151 int VTrack::load_derived(FileXML *file, uint32_t load_flags)
153         return 0;
157 int VTrack::direct_copy_possible(int64_t start, int direction, int use_nudge)
159         int i;
160         if(use_nudge) start += nudge;
162 // Track size must equal output size
163         if(track_w != edl->session->output_w || track_h != edl->session->output_h)
164                 return 0;
166 // No automation must be present in the track
167         if(!automation->direct_copy_possible(start, direction))
168                 return 0;
170 // No plugin must be present
171         if(plugin_used(start, direction)) 
172                 return 0;
174 // No transition
175         if(get_current_transition(start, direction, 0, 0))
176                 return 0;
178         return 1;
197 int VTrack::create_derived_objs(int flash)
199         int i;
200         edits = new VEdits(edl, this);
201         return 0;
205 int VTrack::get_dimensions(double &view_start, 
206         double &view_units, 
207         double &zoom_units)
209         view_start = edl->local_session->view_start * edl->session->frame_rate;
210         view_units = 0;
211 //      view_units = Units::toframes(tracks->view_samples(), mwindow->session->sample_rate, mwindow->session->frame_rate);
212         zoom_units = edl->local_session->zoom_sample / edl->session->sample_rate * edl->session->frame_rate;
215 int VTrack::copy_derived(int64_t start, int64_t end, FileXML *xml)
217 // automation is copied in the Track::copy
218         return 0;
221 int VTrack::copy_automation_derived(AutoConf *auto_conf, int64_t start, int64_t end, FileXML *file)
223         return 0;
226 int VTrack::paste_derived(int64_t start, int64_t end, int64_t total_length, FileXML *xml, int &current_channel)
228         return 0;
231 int VTrack::paste_output(int64_t startproject, int64_t endproject, int64_t startsource, int64_t endsource, int layer, Asset *asset)
233         return 0;
236 int VTrack::clear_derived(int64_t start, int64_t end)
238         return 0;
241 int VTrack::paste_automation_derived(int64_t start, int64_t end, int64_t total_length, FileXML *xml, int shift_autos, int &current_pan)
243         return 0;
246 int VTrack::clear_automation_derived(AutoConf *auto_conf, int64_t start, int64_t end, int shift_autos)
248         return 0;
251 int VTrack::draw_autos_derived(float view_start, float zoom_units, AutoConf *auto_conf)
253         return 0;
257 int VTrack::select_auto_derived(float zoom_units, float view_start, AutoConf *auto_conf, int cursor_x, int cursor_y)
259         return 0;
263 int VTrack::move_auto_derived(float zoom_units, float view_start, AutoConf *auto_conf, int cursor_x, int cursor_y, int shift_down)
265         return 0;
268 int VTrack::draw_floating_autos_derived(float view_start, float zoom_units, AutoConf *auto_conf, int flash)
270         return 0;
273 int VTrack::channel_is_playable(int64_t position, int direction, int *do_channel)
275         int result = 0;
276 //printf("VTrack::channel_is_playable 1 %d\n", do_channel[0]);
277         for(int i = 0; i < edl->session->video_channels && !result; i++)
278         {
279                 if(do_channel[i])
280                 {
281                         float in_x, in_y, in_w, in_h;
282                         float out_x, out_y, out_w, out_h;
284                         calculate_output_transfer(i, position, direction, 
285                                 in_x, in_y, in_w, in_h,
286                                 out_x, out_y, out_w, out_h);
288 //printf("VTrack::channel_is_playable %0.0f %0.0f %0.0f %0.0f %0.0f %0.0f %0.0f %0.0f\n", 
289 //in_x, in_y, in_w, in_h, out_x, out_y, out_w, out_h);
290                         if(out_w > 0 && out_h > 0) 
291                                 result = 1;
292                 }
293         }
294         return result;
297 void VTrack::calculate_input_transfer(Asset *asset, 
298         int64_t position, 
299         int direction, 
300         float &in_x, 
301         float &in_y, 
302         float &in_w, 
303         float &in_h,
304         float &out_x, 
305         float &out_y, 
306         float &out_w, 
307         float &out_h)
309         float auto_x, auto_y, auto_z;
310         float camera_z = 1;
311         float camera_x = asset->width / 2;
312         float camera_y = asset->height / 2;
313 // camera and output coords
314         float z[6], x[6], y[6];        
316 //printf("VTrack::calculate_input_transfer %lld\n", position);
318 // get camera center in asset
319         automation->get_camera(&auto_x, 
320                 &auto_y, 
321                 &auto_z, 
322                 position, 
323                 direction);
325         camera_z *= auto_z;
326         camera_x += auto_x;
327         camera_y += auto_y;
329 // get camera coords on asset
330         x[0] = camera_x - (float)track_w / 2 / camera_z;
331         y[0] = camera_y - (float)track_h / 2 / camera_z;
332         x[1] = x[0] + (float)track_w / camera_z;
333         y[1] = y[0] + (float)track_h / camera_z;
335 // get asset coords on camera
336         x[2] = 0;
337         y[2] = 0;
338         x[3] = track_w;
339         y[3] = track_h;
341 // crop asset coords on camera
342         if(x[0] < 0)
343         {
344                 x[2] -= x[0] * camera_z;
345                 x[0] = 0;
346         }
347         if(y[0] < 0)
348         {
349                 y[2] -= y[0] * camera_z;
350                 y[0] = 0;
351         }
352         if(x[1] > asset->width)
353         {
354                 x[3] -= (x[1] - asset->width) * camera_z;
355                 x[1] = asset->width;
356         }
357         if(y[1] > asset->height)
358         {
359                 y[3] -= (y[1] - asset->height) * camera_z;
360                 y[1] = asset->height;
361         }
363 // get output bounding box
364         out_x = x[2];
365         out_y = y[2];
366         out_w = x[3] - x[2];
367         out_h = y[3] - y[2];
369         in_x = x[0];
370         in_y = y[0];
371         in_w = x[1] - x[0];
372         in_h = y[1] - y[0];
373 // printf("VTrack::calculate_input_transfer %f %f %f %f -> %f %f %f %f\n", 
374 // in_x, in_y, in_w, in_h,
375 // out_x, out_y, out_w, out_h);
378 void VTrack::calculate_output_transfer(int channel, 
379         int64_t position, 
380         int direction, 
381         float &in_x, 
382         float &in_y, 
383         float &in_w, 
384         float &in_h,
385         float &out_x, 
386         float &out_y, 
387         float &out_w, 
388         float &out_h)
390         float center_x, center_y, center_z;
391         float x[4], y[4];
392         float channel_x1 = edl->session->vchannel_x[channel];
393         float channel_y1 = edl->session->vchannel_y[channel];
394         float channel_x2 = channel_x1 + edl->session->output_w;
395         float channel_y2 = channel_y1 + edl->session->output_h;
397         x[0] = 0;
398         y[0] = 0;
399         x[1] = track_w;
400         y[1] = track_h;
402         automation->get_projector(&center_x, 
403                 &center_y, 
404                 &center_z, 
405                 position, 
406                 direction);
408         center_x += edl->session->output_w / 2;
409         center_y += edl->session->output_h / 2;
411         x[2] = center_x - (track_w / 2) * center_z;
412         y[2] = center_y - (track_h / 2) * center_z;
413         x[3] = x[2] + track_w * center_z;
414         y[3] = y[2] + track_h * center_z;
416 // Clip to boundaries of channel
417         if(x[2] < channel_x1)
418         {
419                 x[0] -= (x[2] - channel_x1) / center_z;
420                 x[2] = channel_x1;
421         }
422         if(y[2] < 0)
423         {
424                 y[0] -= (y[2] - channel_y1) / center_z;
425                 y[2] = 0;
426         }
427         if(x[3] > channel_x2)
428         {
429                 x[1] -= (x[3] - channel_x2) / center_z;
430                 x[3] = channel_x2;
431         }
432         if(y[3] > channel_y2)
433         {
434                 y[1] -= (y[3] - channel_y2) / center_z;
435                 y[3] = channel_y2;
436         }
438         in_x = x[0];
439         in_y = y[0];
440         in_w = x[1] - x[0];
441         in_h = y[1] - y[0];
442         out_x = x[2];
443         out_y = y[2];
444         out_w = x[3] - x[2];
445         out_h = y[3] - y[2];
446 // printf("VTrack::calculate_output_transfer %f %f %f %f -> %f %f %f %f\n", 
447 // in_x, in_y, in_w, in_h,
448 // out_x, out_y, out_w, out_h);
453 int VTrack::get_projection(int channel, 
454         float &in_x1, 
455         float &in_y1, 
456         float &in_x2, 
457         float &in_y2, 
458         float &out_x1, 
459         float &out_y1, 
460         float &out_x2, 
461         float &out_y2, 
462         int frame_w, 
463         int frame_h, 
464         int64_t real_position, 
465         int direction)
467         float center_x, center_y, center_z;
468         float x[4], y[4];
470         automation->get_projector(&center_x, 
471                 &center_y, 
472                 &center_z, 
473                 real_position, 
474                 direction);
476         x[0] = y[0] = 0;
477         x[1] = frame_w;
478         y[1] = frame_h;
480         center_x += edl->session->output_w / 2;
481         center_y += edl->session->output_h / 2;
483         x[2] = center_x - (frame_w / 2) * center_z;
484         y[2] = center_y - (frame_h / 2) * center_z;
485         x[3] = x[2] + frame_w * center_z;
486         y[3] = y[2] + frame_h * center_z;
488         if(x[2] < 0)
489         {
490                 x[0] -= x[2] / center_z;
491                 x[2] = 0;
492         }
493         if(y[2] < 0)
494         {
495                 y[0] -= y[2] / center_z;
496                 y[2] = 0;
497         }
498         if(x[3] > edl->session->output_w)
499         {
500                 x[1] -= (x[3] - edl->session->output_w) / center_z;
501                 x[3] = edl->session->output_w;
502         }
503         if(y[3] > edl->session->output_h)
504         {
505                 y[1] -= (y[3] - edl->session->output_h) / center_z;
506                 y[3] = edl->session->output_h;
507         }
509         in_x1 = x[0];
510         in_y1 = y[0];
511         in_x2 = x[1];
512         in_y2 = y[1];
513         out_x1 = x[2];
514         out_y1 = y[2];
515         out_x2 = x[3];
516         out_y2 = y[3];
517         return 0;
521 void VTrack::translate(float offset_x, float offset_y, int do_camera)
523         int subscript;
524         if(do_camera) 
525                 subscript = AUTOMATION_CAMERA_X;
526         else
527                 subscript = AUTOMATION_PROJECTOR_X;
528         
529 // Translate default keyframe
530         ((FloatAuto*)automation->autos[subscript]->default_auto)->value += offset_x;
531         ((FloatAuto*)automation->autos[subscript + 1]->default_auto)->value += offset_y;
533 // Translate everyone else
534         for(Auto *current = automation->autos[subscript]->first; 
535                 current; 
536                 current = NEXT)
537         {
538                 ((FloatAuto*)current)->value += offset_x;
539         }
541         for(Auto *current = automation->autos[subscript + 1]->first; 
542                 current; 
543                 current = NEXT)
544         {
545                 ((FloatAuto*)current)->value += offset_y;
546         }