add auto zoombar/status color, fix 3 batchrender boobies, rotate plugin tweaks, add...
[goodguy/cinelerra.git] / cinelerra-5.1 / cinelerra / intautos.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 "automation.inc"
23 #include "clip.h"
24 #include "intauto.h"
25 #include "intautos.h"
26
27 IntAutos::IntAutos(EDL *edl, Track *track, int default_)
28  : Autos(edl, track)
29 {
30         this->default_ = default_;
31         type = AUTOMATION_TYPE_INT;
32 }
33
34 IntAutos::~IntAutos()
35 {
36 }
37
38
39 Auto* IntAutos::new_auto()
40 {
41         IntAuto *result = new IntAuto(edl, this);
42         result->value = default_;
43         return result;
44 }
45
46 int IntAutos::automation_is_constant(int64_t start, int64_t end)
47 {
48         Auto *current_auto, *before = 0, *after = 0;
49         int result;
50
51         result = 1;          // default to constant
52         if(!last && !first) return result; // no automation at all
53
54 // quickly get autos just outside range
55         get_neighbors(start, end, &before, &after);
56
57 // autos before range
58         if(before)
59                 current_auto = before;   // try first auto
60         else
61                 current_auto = first;
62
63 // test autos in range
64         for( ; result &&
65                 current_auto &&
66                 current_auto->next &&
67                 current_auto->position < end;
68                 current_auto = current_auto->next)
69         {
70 // not constant
71                 if(((IntAuto*)current_auto->next)->value != ((IntAuto*)current_auto)->value)
72                         result = 0;
73         }
74
75         return result;
76 }
77
78 double IntAutos::get_automation_constant(int64_t start, int64_t end)
79 {
80         Auto *current_auto, *before = 0, *after = 0;
81
82 // quickly get autos just outside range
83         get_neighbors(start, end, &before, &after);
84
85 // no auto before range so use first
86         if(before)
87                 current_auto = before;
88         else
89                 current_auto = first;
90
91 // no autos at all so use default value
92         if(!current_auto) current_auto = default_auto;
93
94         return ((IntAuto*)current_auto)->value;
95 }
96
97
98 void IntAutos::get_extents(float *min,
99         float *max,
100         int *coords_undefined,
101         int64_t unit_start,
102         int64_t unit_end)
103 {
104         if(!first)
105         {
106                 IntAuto *current = (IntAuto*)default_auto;
107                 if(*coords_undefined)
108                 {
109                         *min = *max = current->value;
110                         *coords_undefined = 0;
111                 }
112
113                 *min = MIN(current->value, *min);
114                 *max = MAX(current->value, *max);
115         }
116
117         for(IntAuto *current = (IntAuto*)first; current; current = (IntAuto*)NEXT)
118         {
119                 if(current->position >= unit_start && current->position < unit_end)
120                 {
121                         if(coords_undefined)
122                         {
123                                 *max = *min = current->value;
124                                 *coords_undefined = 0;
125                         }
126                         else
127                         {
128                                 *min = MIN(current->value, *min);
129                                 *max = MAX(current->value, *max);
130                         }
131                 }
132         }
133 }
134
135 void IntAutos::dump()
136 {
137         printf("        Default %p: position: %jd value: %d\n", default_auto, default_auto->position, ((IntAuto*)default_auto)->value);
138         for(Auto* current = first; current; current = NEXT)
139         {
140                 printf("        %p position: %jd value: %d\n", current, current->position, ((IntAuto*)current)->value);
141         }
142 }