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
26 #include "floatauto.h"
27 #include "localsession.h"
29 FloatAuto::FloatAuto(EDL *edl, FloatAutos *autos)
30 : Auto(edl, (Autos*)autos)
34 control_out_value = 0;
36 // control_in_position = 0;
37 // control_out_position = 0;
40 FloatAuto::~FloatAuto()
44 int FloatAuto::operator==(Auto &that)
46 return identical((FloatAuto*)&that);
50 int FloatAuto::operator==(FloatAuto &that)
52 return identical((FloatAuto*)&that);
56 int FloatAuto::identical(FloatAuto *src)
58 return EQUIV(value, src->value) &&
59 EQUIV(control_in_value, src->control_in_value) &&
60 EQUIV(control_out_value, src->control_out_value) &&
64 float FloatAuto::value_to_percentage()
67 float automation_min = edl->local_session->automation_min;
68 float automation_max = edl->local_session->automation_max;
69 float automation_range = automation_max - automation_min;
70 return (value - automation_min) / automation_range;
73 float FloatAuto::invalue_to_percentage()
76 float automation_min = edl->local_session->automation_min;
77 float automation_max = edl->local_session->automation_max;
78 float automation_range = automation_max - automation_min;
79 return (value + control_in_value - automation_min) /
83 float FloatAuto::outvalue_to_percentage()
86 float automation_min = edl->local_session->automation_min;
87 float automation_max = edl->local_session->automation_max;
88 float automation_range = automation_max - automation_min;
89 return (value + control_out_value - automation_min) /
94 void FloatAuto::copy_from(Auto *that)
96 copy_from((FloatAuto*)that);
99 void FloatAuto::copy_from(FloatAuto *that)
101 Auto::copy_from(that);
102 this->value = that->value;
103 this->control_in_value = that->control_in_value;
104 this->control_out_value = that->control_out_value;
105 this->mode = that->mode;
108 int FloatAuto::value_to_str(char *string, float value)
112 sprintf(string, "+%.2f", value);
114 sprintf(string, "%.2f", value);
123 if(value < 1 && value > -1)
126 string[j] = string[0];
134 while(string[j] != 0) string[i++] = string[j++];
140 void FloatAuto::copy(int64_t start, int64_t end, FileXML *file, int default_auto)
142 file->tag.set_title("AUTO");
144 file->tag.set_property("POSITION", 0);
146 file->tag.set_property("POSITION", position - start);
147 file->tag.set_property("VALUE", value);
148 file->tag.set_property("CONTROL_IN_VALUE", control_in_value);
149 file->tag.set_property("CONTROL_OUT_VALUE", control_out_value);
150 file->tag.set_property("MODE", mode);
152 file->append_newline();
155 void FloatAuto::load(FileXML *file)
157 value = file->tag.get_property("VALUE", value);
158 control_in_value = file->tag.get_property("CONTROL_IN_VALUE", control_in_value);
159 control_out_value = file->tag.get_property("CONTROL_OUT_VALUE", control_out_value);
160 mode = file->tag.get_property("MODE", mode);