Second set of 50 GPL attribution for CV-Contributors added
[goodguy/cinelerra.git] / cinelerra-5.1 / cinelerra / vautomation.C
1
2 /*
3  * CINELERRA
4  * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
5  * Copyright (C) 2003-2016 Cinelerra CV contributors
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20  *
21  */
22
23 #include "clip.h"
24 #include "bccolors.h"
25 #include "edl.h"
26 #include "edlsession.h"
27 #include "floatauto.h"
28 #include "floatautos.h"
29 #include "intauto.h"
30 #include "intautos.h"
31 #include "maskautos.h"
32 #include "overlayframe.inc"
33 #include "transportque.inc"
34 #include "vautomation.h"
35
36
37 VAutomation::VAutomation(EDL *edl, Track *track)
38  : Automation(edl, track)
39 {
40 }
41
42
43
44 VAutomation::~VAutomation()
45 {
46 }
47
48
49 void VAutomation::create_objects()
50 {
51         Automation::create_objects();
52
53         autos[AUTOMATION_FADE] = new FloatAutos(edl, track, 100);
54         autos[AUTOMATION_FADE]->create_objects();
55
56         autos[AUTOMATION_SPEED] = new FloatAutos(edl, track, 1.);
57         autos[AUTOMATION_SPEED]->create_objects();
58         ((FloatAutos*)autos[AUTOMATION_SPEED])->set_float_min(SPEED_MIN);
59
60         autos[AUTOMATION_MODE] = new IntAutos(edl, track, TRANSFER_NORMAL);
61         autos[AUTOMATION_MODE]->create_objects();
62
63         autos[AUTOMATION_MASK] = new MaskAutos(edl, track);
64         autos[AUTOMATION_MASK]->create_objects();
65
66         autos[AUTOMATION_CAMERA_X] = new FloatAutos(edl, track, 0.0);
67         autos[AUTOMATION_CAMERA_X]->create_objects();
68
69         autos[AUTOMATION_CAMERA_Y] = new FloatAutos(edl, track, 0.0);
70         autos[AUTOMATION_CAMERA_Y]->create_objects();
71
72         autos[AUTOMATION_PROJECTOR_X] = new FloatAutos(edl, track, 0.0);
73         autos[AUTOMATION_PROJECTOR_X]->create_objects();
74
75         autos[AUTOMATION_PROJECTOR_Y] = new FloatAutos(edl, track, 0.0);
76         autos[AUTOMATION_PROJECTOR_Y]->create_objects();
77
78         autos[AUTOMATION_CAMERA_Z] = new FloatAutos(edl, track, 1.0);
79         autos[AUTOMATION_CAMERA_Z]->create_objects();
80
81         autos[AUTOMATION_PROJECTOR_Z] = new FloatAutos(edl, track, 1.0);
82         autos[AUTOMATION_PROJECTOR_Z]->create_objects();
83         for(int i = 0; i < AUTOMATION_TOTAL; i++) {
84                 if( !autos[i] ) continue;
85                 autos[i]->autoidx = i;
86                 autos[i]->autogrouptype = autogrouptype(i, autos[i]->track);
87         }
88 }
89
90 int VAutomation::direct_copy_possible(int64_t start, int direction)
91 {
92         int64_t end = (direction == PLAY_FORWARD) ? (start + 1) : (start - 1);
93
94         if(!Automation::direct_copy_possible(start, direction))
95                 return 0;
96
97 // Automation is constant
98         double constant;
99         if(((FloatAutos*)autos[AUTOMATION_FADE])->automation_is_constant(
100                 start, end, direction, constant))
101         {
102                 if(!EQUIV(constant, 100))
103                         return 0;
104         }
105         else
106 // Automation varies
107                 return 0;
108
109 // Track must not be muted
110         if(autos[AUTOMATION_MUTE]->automation_is_constant(start, end))
111         {
112                 if(autos[AUTOMATION_MUTE]->get_automation_constant(start, end) > 0)
113                         return 0;
114         }
115         else
116                 return 0;
117
118 // Projector must be centered.
119         FloatAuto *previous = 0, *next = 0;
120         float z = ((FloatAutos*)autos[AUTOMATION_PROJECTOR_Z])->
121                 get_value(start, direction, previous, next);
122         if(!EQUIV(z, 1)) return 0;
123
124         previous = 0;
125         next = 0;
126         float x = ((FloatAutos*)autos[AUTOMATION_PROJECTOR_X])->
127                 get_value(start, direction, previous, next);
128         if(!EQUIV(x, 0)) return 0;
129         previous = 0;
130         next = 0;
131         float y = ((FloatAutos*)autos[AUTOMATION_PROJECTOR_Y])->
132                 get_value(start, direction, previous, next);
133         if(!EQUIV(y, 0)) return 0;
134
135
136
137
138 // Camera must be centered
139         previous = 0;
140         next = 0;
141         z = ((FloatAutos*)autos[AUTOMATION_CAMERA_Z])->
142                 get_value(start, direction, previous, next);
143         if(!EQUIV(z, 1)) return 0;
144
145
146
147         previous = 0;
148         next = 0;
149         x = ((FloatAutos*)autos[AUTOMATION_CAMERA_X])->
150                 get_value(start, direction, previous, next);
151         if(!EQUIV(x, 0)) return 0;
152
153         previous = 0;
154         next = 0;
155         y = ((FloatAutos*)autos[AUTOMATION_CAMERA_Y])->
156                 get_value(start, direction, previous, next);
157
158         if(!EQUIV(y, 0)) return 0;
159
160 // No mask must exist
161         if(((MaskAutos*)autos[AUTOMATION_MASK])->mask_exists(start, direction))
162                 return 0;
163
164         return 1;
165 }
166
167 void VAutomation::get_projector(float *x,
168         float *y,
169         float *z,
170         int64_t position,
171         int direction)
172 {
173         FloatAuto *before, *after;
174         before = 0;
175         after = 0;
176         *x = ((FloatAutos*)autos[AUTOMATION_PROJECTOR_X])->
177                 get_value(position, direction, before, after);
178         before = 0;
179         after = 0;
180         *y = ((FloatAutos*)autos[AUTOMATION_PROJECTOR_Y])->
181                 get_value(position, direction, before, after);
182         before = 0;
183         after = 0;
184         *z = ((FloatAutos*)autos[AUTOMATION_PROJECTOR_Z])->
185                 get_value(position, direction, before, after);
186 }
187
188
189 void VAutomation::get_camera(float *x,
190         float *y,
191         float *z,
192         int64_t position,
193         int direction)
194 {
195         FloatAuto *before, *after;
196         before = 0;
197         after = 0;
198         *x = ((FloatAutos*)autos[AUTOMATION_CAMERA_X])->
199                 get_value(position, direction, before, after);
200         before = 0;
201         after = 0;
202         *y = ((FloatAutos*)autos[AUTOMATION_CAMERA_Y])->
203                 get_value(position, direction, before, after);
204         before = 0;
205         after = 0;
206         *z = ((FloatAutos*)autos[AUTOMATION_CAMERA_Z])->
207                 get_value(position, direction, before, after);
208 }
209