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"
28 IntAutos::IntAutos(EDL *edl, Track *track, int default_)
31 this->default_ = default_;
32 type = AUTOMATION_TYPE_INT;
40 Auto* IntAutos::new_auto()
42 IntAuto *result = new IntAuto(edl, this);
43 result->value = default_;
47 int IntAutos::automation_is_constant(int64_t start, int64_t end)
49 Auto *current_auto, *before = 0, *after = 0;
52 result = 1; // default to constant
53 if(!last && !first) return result; // no automation at all
55 // quickly get autos just outside range
56 get_neighbors(start, end, &before, &after);
60 current_auto = before; // try first auto
64 // test autos in range
68 current_auto->position < end;
69 current_auto = current_auto->next)
72 if(((IntAuto*)current_auto->next)->value != ((IntAuto*)current_auto)->value)
79 double IntAutos::get_automation_constant(int64_t start, int64_t end)
81 Auto *current_auto, *before = 0, *after = 0;
83 // quickly get autos just outside range
84 get_neighbors(start, end, &before, &after);
86 // no auto before range so use first
88 current_auto = before;
92 // no autos at all so use default value
93 if(!current_auto) current_auto = default_auto;
95 return ((IntAuto*)current_auto)->value;
99 void IntAutos::get_extents(float *min,
101 int *coords_undefined,
107 IntAuto *current = (IntAuto*)default_auto;
108 if(*coords_undefined)
110 *min = *max = current->value;
111 *coords_undefined = 0;
114 *min = MIN(current->value, *min);
115 *max = MAX(current->value, *max);
118 for(IntAuto *current = (IntAuto*)first; current; current = (IntAuto*)NEXT)
120 if(current->position >= unit_start && current->position < unit_end)
124 *max = *min = current->value;
125 *coords_undefined = 0;
129 *min = MIN(current->value, *min);
130 *max = MAX(current->value, *max);
136 void IntAutos::dump()
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)
141 printf(" %p position: " _LD " value: %d\n", current, current->position, ((IntAuto*)current)->value);