4 * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
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.
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.
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
22 #include "automation.inc"
27 IntAutos::IntAutos(EDL *edl, Track *track, int default_)
30 this->default_ = default_;
31 type = AUTOMATION_TYPE_INT;
39 Auto* IntAutos::new_auto()
41 IntAuto *result = new IntAuto(edl, this);
42 result->value = default_;
46 int IntAutos::automation_is_constant(int64_t start, int64_t end)
48 Auto *current_auto, *before = 0, *after = 0;
51 result = 1; // default to constant
52 if(!last && !first) return result; // no automation at all
54 // quickly get autos just outside range
55 get_neighbors(start, end, &before, &after);
59 current_auto = before; // try first auto
63 // test autos in range
67 current_auto->position < end;
68 current_auto = current_auto->next)
71 if(((IntAuto*)current_auto->next)->value != ((IntAuto*)current_auto)->value)
78 double IntAutos::get_automation_constant(int64_t start, int64_t end)
80 Auto *current_auto, *before = 0, *after = 0;
82 // quickly get autos just outside range
83 get_neighbors(start, end, &before, &after);
85 // no auto before range so use first
87 current_auto = before;
91 // no autos at all so use default value
92 if(!current_auto) current_auto = default_auto;
94 return ((IntAuto*)current_auto)->value;
98 void IntAutos::get_extents(float *min,
100 int *coords_undefined,
106 IntAuto *current = (IntAuto*)default_auto;
107 if(*coords_undefined)
109 *min = *max = current->value;
110 *coords_undefined = 0;
113 *min = MIN(current->value, *min);
114 *max = MAX(current->value, *max);
117 for(IntAuto *current = (IntAuto*)first; current; current = (IntAuto*)NEXT)
119 if(current->position >= unit_start && current->position < unit_end)
123 *max = *min = current->value;
124 *coords_undefined = 0;
128 *min = MIN(current->value, *min);
129 *max = MAX(current->value, *max);
135 void IntAutos::dump()
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)
140 printf(" %p position: %jd value: %d\n", current, current->position, ((IntAuto*)current)->value);