remove auto kfrm for gang, btn2 select kfrm pos
[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  *
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 "bccolors.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_SPEED] = new FloatAutos(edl, track, 1.);
56         autos[AUTOMATION_SPEED]->create_objects();
57
58         autos[AUTOMATION_MODE] = new IntAutos(edl, track, TRANSFER_NORMAL);
59         autos[AUTOMATION_MODE]->create_objects();
60
61         autos[AUTOMATION_MASK] = new MaskAutos(edl, track);
62         autos[AUTOMATION_MASK]->create_objects();
63
64         autos[AUTOMATION_CAMERA_X] = new FloatAutos(edl, track, 0.0);
65         autos[AUTOMATION_CAMERA_X]->create_objects();
66
67         autos[AUTOMATION_CAMERA_Y] = new FloatAutos(edl, track, 0.0);
68         autos[AUTOMATION_CAMERA_Y]->create_objects();
69
70         autos[AUTOMATION_PROJECTOR_X] = new FloatAutos(edl, track, 0.0);
71         autos[AUTOMATION_PROJECTOR_X]->create_objects();
72
73         autos[AUTOMATION_PROJECTOR_Y] = new FloatAutos(edl, track, 0.0);
74         autos[AUTOMATION_PROJECTOR_Y]->create_objects();
75
76         autos[AUTOMATION_CAMERA_Z] = new FloatAutos(edl, track, 1.0);
77         autos[AUTOMATION_CAMERA_Z]->create_objects();
78
79         autos[AUTOMATION_PROJECTOR_Z] = new FloatAutos(edl, track, 1.0);
80         autos[AUTOMATION_PROJECTOR_Z]->create_objects();
81         for(int i = 0; i < AUTOMATION_TOTAL; i++) {
82                 if( !autos[i] ) continue;
83                 autos[i]->autoidx = i;
84                 autos[i]->autogrouptype = autogrouptype(i, autos[i]->track);
85         }
86 }
87
88 int VAutomation::direct_copy_possible(int64_t start, int direction)
89 {
90         int64_t end = (direction == PLAY_FORWARD) ? (start + 1) : (start - 1);
91
92         if(!Automation::direct_copy_possible(start, direction))
93                 return 0;
94
95 // Automation is constant
96         double constant;
97         if(((FloatAutos*)autos[AUTOMATION_FADE])->automation_is_constant(
98                 start, end, direction, constant))
99         {
100                 if(!EQUIV(constant, 100))
101                         return 0;
102         }
103         else
104 // Automation varies
105                 return 0;
106
107 // Track must not be muted
108         if(autos[AUTOMATION_MUTE]->automation_is_constant(start, end))
109         {
110                 if(autos[AUTOMATION_MUTE]->get_automation_constant(start, end) > 0)
111                         return 0;
112         }
113         else
114                 return 0;
115
116 // Projector must be centered.
117         FloatAuto *previous = 0, *next = 0;
118         float z = ((FloatAutos*)autos[AUTOMATION_PROJECTOR_Z])->
119                 get_value(start, direction, previous, next);
120         if(!EQUIV(z, 1)) return 0;
121
122         previous = 0;
123         next = 0;
124         float x = ((FloatAutos*)autos[AUTOMATION_PROJECTOR_X])->
125                 get_value(start, direction, previous, next);
126         if(!EQUIV(x, 0)) return 0;
127         previous = 0;
128         next = 0;
129         float y = ((FloatAutos*)autos[AUTOMATION_PROJECTOR_Y])->
130                 get_value(start, direction, previous, next);
131         if(!EQUIV(y, 0)) return 0;
132
133
134
135
136 // Camera must be centered
137         previous = 0;
138         next = 0;
139         z = ((FloatAutos*)autos[AUTOMATION_CAMERA_Z])->
140                 get_value(start, direction, previous, next);
141         if(!EQUIV(z, 1)) return 0;
142
143
144
145         previous = 0;
146         next = 0;
147         x = ((FloatAutos*)autos[AUTOMATION_CAMERA_X])->
148                 get_value(start, direction, previous, next);
149         if(!EQUIV(x, 0)) return 0;
150
151         previous = 0;
152         next = 0;
153         y = ((FloatAutos*)autos[AUTOMATION_CAMERA_Y])->
154                 get_value(start, direction, previous, next);
155
156         if(!EQUIV(y, 0)) return 0;
157
158 // No mask must exist
159         if(((MaskAutos*)autos[AUTOMATION_MASK])->mask_exists(start, direction))
160                 return 0;
161
162         return 1;
163 }
164
165 void VAutomation::get_projector(float *x,
166         float *y,
167         float *z,
168         int64_t position,
169         int direction)
170 {
171         FloatAuto *before, *after;
172         before = 0;
173         after = 0;
174         *x = ((FloatAutos*)autos[AUTOMATION_PROJECTOR_X])->
175                 get_value(position, direction, before, after);
176         before = 0;
177         after = 0;
178         *y = ((FloatAutos*)autos[AUTOMATION_PROJECTOR_Y])->
179                 get_value(position, direction, before, after);
180         before = 0;
181         after = 0;
182         *z = ((FloatAutos*)autos[AUTOMATION_PROJECTOR_Z])->
183                 get_value(position, direction, before, after);
184 }
185
186
187 void VAutomation::get_camera(float *x,
188         float *y,
189         float *z,
190         int64_t position,
191         int direction)
192 {
193         FloatAuto *before, *after;
194         before = 0;
195         after = 0;
196         *x = ((FloatAutos*)autos[AUTOMATION_CAMERA_X])->
197                 get_value(position, direction, before, after);
198         before = 0;
199         after = 0;
200         *y = ((FloatAutos*)autos[AUTOMATION_CAMERA_Y])->
201                 get_value(position, direction, before, after);
202         before = 0;
203         after = 0;
204         *z = ((FloatAutos*)autos[AUTOMATION_CAMERA_Z])->
205                 get_value(position, direction, before, after);
206 }
207