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