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