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