r1005: Increase the number of displayed digits for resample audio dialog box
[cinelerra_cv/mob.git] / cinelerra / vtrack.C
blobf86b336b55adf0bb98b67a49d8eee60ff69d0055
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(BC_Hash *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::is_playable(int64_t position, int direction)
275         int result = 0;
276         float in_x, in_y, in_w, in_h;
277         float out_x, out_y, out_w, out_h;
279         calculate_output_transfer(position, 
280                 direction, 
281                 in_x, in_y, in_w, in_h,
282                 out_x, out_y, out_w, out_h);
284 //printf("VTrack::is_playable %0.0f %0.0f %0.0f %0.0f %0.0f %0.0f %0.0f %0.0f\n", 
285 //in_x, in_y, in_w, in_h, out_x, out_y, out_w, out_h);
286         if(out_w > 0 && out_h > 0) 
287                 result = 1;
288         return result;
291 void VTrack::calculate_input_transfer(Asset *asset, 
292         int64_t position, 
293         int direction, 
294         float &in_x, 
295         float &in_y, 
296         float &in_w, 
297         float &in_h,
298         float &out_x, 
299         float &out_y, 
300         float &out_w, 
301         float &out_h)
303         float auto_x, auto_y, auto_z;
304         float camera_z = 1;
305         float camera_x = asset->width / 2;
306         float camera_y = asset->height / 2;
307 // camera and output coords
308         float z[6], x[6], y[6];        
310 //printf("VTrack::calculate_input_transfer %lld\n", position);
312 // get camera center in asset
313         automation->get_camera(&auto_x, 
314                 &auto_y, 
315                 &auto_z, 
316                 position, 
317                 direction);
319         camera_z *= auto_z;
320         camera_x += auto_x;
321         camera_y += auto_y;
323 // get camera coords on asset
324         x[0] = camera_x - (float)track_w / 2 / camera_z;
325         y[0] = camera_y - (float)track_h / 2 / camera_z;
326         x[1] = x[0] + (float)track_w / camera_z;
327         y[1] = y[0] + (float)track_h / camera_z;
329 // get asset coords on camera
330         x[2] = 0;
331         y[2] = 0;
332         x[3] = track_w;
333         y[3] = track_h;
335 // crop asset coords on camera
336         if(x[0] < 0)
337         {
338                 x[2] -= x[0] * camera_z;
339                 x[0] = 0;
340         }
341         if(y[0] < 0)
342         {
343                 y[2] -= y[0] * camera_z;
344                 y[0] = 0;
345         }
346         if(x[1] > asset->width)
347         {
348                 x[3] -= (x[1] - asset->width) * camera_z;
349                 x[1] = asset->width;
350         }
351         if(y[1] > asset->height)
352         {
353                 y[3] -= (y[1] - asset->height) * camera_z;
354                 y[1] = asset->height;
355         }
357 // get output bounding box
358         out_x = x[2];
359         out_y = y[2];
360         out_w = x[3] - x[2];
361         out_h = y[3] - y[2];
363         in_x = x[0];
364         in_y = y[0];
365         in_w = x[1] - x[0];
366         in_h = y[1] - y[0];
367 // printf("VTrack::calculate_input_transfer %f %f %f %f -> %f %f %f %f\n", 
368 // in_x, in_y, in_w, in_h,
369 // out_x, out_y, out_w, out_h);
372 void VTrack::calculate_output_transfer(int64_t position, 
373         int direction, 
374         float &in_x, 
375         float &in_y, 
376         float &in_w, 
377         float &in_h,
378         float &out_x, 
379         float &out_y, 
380         float &out_w, 
381         float &out_h)
383         float center_x, center_y, center_z;
384         float x[4], y[4];
386         x[0] = 0;
387         y[0] = 0;
388         x[1] = track_w;
389         y[1] = track_h;
391         automation->get_projector(&center_x, 
392                 &center_y, 
393                 &center_z, 
394                 position, 
395                 direction);
397         center_x += edl->session->output_w / 2;
398         center_y += edl->session->output_h / 2;
400         x[2] = center_x - (track_w / 2) * center_z;
401         y[2] = center_y - (track_h / 2) * center_z;
402         x[3] = x[2] + track_w * center_z;
403         y[3] = y[2] + track_h * center_z;
405 // Clip to boundaries of output
406         if(x[2] < 0)
407         {
408                 x[0] -= (x[2] - 0) / center_z;
409                 x[2] = 0;
410         }
411         if(y[2] < 0)
412         {
413                 y[0] -= (y[2] - 0) / center_z;
414                 y[2] = 0;
415         }
416         if(x[3] > edl->session->output_w)
417         {
418                 x[1] -= (x[3] - edl->session->output_w) / center_z;
419                 x[3] = edl->session->output_w;
420         }
421         if(y[3] > edl->session->output_h)
422         {
423                 y[1] -= (y[3] - edl->session->output_h) / center_z;
424                 y[3] = edl->session->output_h;
425         }
427         in_x = x[0];
428         in_y = y[0];
429         in_w = x[1] - x[0];
430         in_h = y[1] - y[0];
431         out_x = x[2];
432         out_y = y[2];
433         out_w = x[3] - x[2];
434         out_h = y[3] - y[2];
435 // printf("VTrack::calculate_output_transfer %f %f %f %f -> %f %f %f %f\n", 
436 // in_x, in_y, in_w, in_h,
437 // out_x, out_y, out_w, out_h);
442 int VTrack::get_projection(float &in_x1, 
443         float &in_y1, 
444         float &in_x2, 
445         float &in_y2, 
446         float &out_x1, 
447         float &out_y1, 
448         float &out_x2, 
449         float &out_y2, 
450         int frame_w, 
451         int frame_h, 
452         int64_t real_position, 
453         int direction)
455         float center_x, center_y, center_z;
456         float x[4], y[4];
458         automation->get_projector(&center_x, 
459                 &center_y, 
460                 &center_z, 
461                 real_position, 
462                 direction);
464         x[0] = y[0] = 0;
465         x[1] = frame_w;
466         y[1] = frame_h;
468         center_x += edl->session->output_w / 2;
469         center_y += edl->session->output_h / 2;
471         x[2] = center_x - (frame_w / 2) * center_z;
472         y[2] = center_y - (frame_h / 2) * center_z;
473         x[3] = x[2] + frame_w * center_z;
474         y[3] = y[2] + frame_h * center_z;
476         if(x[2] < 0)
477         {
478                 x[0] -= x[2] / center_z;
479                 x[2] = 0;
480         }
481         if(y[2] < 0)
482         {
483                 y[0] -= y[2] / center_z;
484                 y[2] = 0;
485         }
486         if(x[3] > edl->session->output_w)
487         {
488                 x[1] -= (x[3] - edl->session->output_w) / center_z;
489                 x[3] = edl->session->output_w;
490         }
491         if(y[3] > edl->session->output_h)
492         {
493                 y[1] -= (y[3] - edl->session->output_h) / center_z;
494                 y[3] = edl->session->output_h;
495         }
497         in_x1 = x[0];
498         in_y1 = y[0];
499         in_x2 = x[1];
500         in_y2 = y[1];
501         out_x1 = x[2];
502         out_y1 = y[2];
503         out_x2 = x[3];
504         out_y2 = y[3];
505         return 0;
509 void VTrack::translate(float offset_x, float offset_y, int do_camera)
511         int subscript;
512         if(do_camera) 
513                 subscript = AUTOMATION_CAMERA_X;
514         else
515                 subscript = AUTOMATION_PROJECTOR_X;
516         
517 // Translate default keyframe
518         ((FloatAuto*)automation->autos[subscript]->default_auto)->value += offset_x;
519         ((FloatAuto*)automation->autos[subscript + 1]->default_auto)->value += offset_y;
521 // Translate everyone else
522         for(Auto *current = automation->autos[subscript]->first; 
523                 current; 
524                 current = NEXT)
525         {
526                 ((FloatAuto*)current)->value += offset_x;
527         }
529         for(Auto *current = automation->autos[subscript + 1]->first; 
530                 current; 
531                 current = NEXT)
532         {
533                 ((FloatAuto*)current)->value += offset_y;
534         }