prevent popup deactivation while button_down
[goodguy/history.git] / cinelerra-5.0 / cinelerra / floatauto.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 "autos.h"
23 #include "clip.h"
24 #include "edl.h"
25 #include "filexml.h"
26 #include "floatauto.h"
27 #include "localsession.h"
28
29 FloatAuto::FloatAuto(EDL *edl, FloatAutos *autos)
30  : Auto(edl, (Autos*)autos)
31 {
32         value = 0;
33         control_in_value = 0;
34         control_out_value = 0;
35         mode = BEZIER;
36 //      control_in_position = 0;
37 //      control_out_position = 0;
38 }
39
40 FloatAuto::~FloatAuto()
41 {
42 }
43
44 int FloatAuto::operator==(Auto &that)
45 {
46         return identical((FloatAuto*)&that);
47 }
48
49
50 int FloatAuto::operator==(FloatAuto &that)
51 {
52         return identical((FloatAuto*)&that);
53 }
54
55
56 int FloatAuto::identical(FloatAuto *src)
57 {
58         return EQUIV(value, src->value) &&
59                 EQUIV(control_in_value, src->control_in_value) &&
60                 EQUIV(control_out_value, src->control_out_value) &&
61                 mode == src->mode;
62 }
63
64 float FloatAuto::value_to_percentage()
65 {
66         if(!edl) return 0;
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;
71 }
72
73 float FloatAuto::invalue_to_percentage()
74 {
75         if(!edl) return 0;
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) / 
80                 automation_range;
81 }
82
83 float FloatAuto::outvalue_to_percentage()
84 {
85         if(!edl) return 0;
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) / 
90                 automation_range;
91 }
92
93
94 void FloatAuto::copy_from(Auto *that)
95 {
96         copy_from((FloatAuto*)that);
97 }
98
99 void FloatAuto::copy_from(FloatAuto *that)
100 {
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;
106 }
107
108 int FloatAuto::value_to_str(char *string, float value)
109 {
110         int j = 0, i = 0;
111         if(value > 0) 
112                 sprintf(string, "+%.2f", value);
113         else
114                 sprintf(string, "%.2f", value);
115
116 // fix number
117         if(value == 0)
118         {
119                 j = 0;
120                 string[1] = 0;
121         }
122         else
123         if(value < 1 && value > -1) 
124         {
125                 j = 1;
126                 string[j] = string[0];
127         }
128         else 
129         {
130                 j = 0;
131                 string[3] = 0;
132         }
133         
134         while(string[j] != 0) string[i++] = string[j++];
135         string[i] = 0;
136
137         return 0;
138 }
139
140 void FloatAuto::copy(int64_t start, int64_t end, FileXML *file, int default_auto)
141 {
142         file->tag.set_title("AUTO");
143         if(default_auto)
144                 file->tag.set_property("POSITION", 0);
145         else
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);
151         file->append_tag();
152         file->append_newline();
153 }
154
155 void FloatAuto::load(FileXML *file)
156 {
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);
161 }