Merge CV, ver=5.1; ops/methods from HV, and interface from CV where possible
[goodguy/history.git] / cinelerra-5.1 / cinelerra / floatauto.h
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 #ifndef FLOATAUTO_H
23 #define FLOATAUTO_H
24
25 // Automation point that takes floating point values
26
27 class FloatAuto;
28
29 #include "auto.h"
30 #include "edl.inc"
31 #include "floatautos.inc"
32
33 class FloatAuto : public Auto
34 {
35 public:
36         FloatAuto() {};
37         FloatAuto(EDL *edl, FloatAutos *autos);
38         ~FloatAuto();
39
40         bool is_floatauto() { return true; }
41         int operator==(Auto &that);
42         int operator==(FloatAuto &that);
43         int identical(FloatAuto *src);
44         void copy_from(Auto *that);
45         void copy_from(FloatAuto *that);
46         int interpolate_from(Auto *a1, Auto *a2, int64_t pos, Auto *templ=0); // bezier interpolation
47         void copy(int64_t start, int64_t end, FileXML *file, int default_only);
48         void load(FileXML *xml);
49
50 // "the value" (=payload of this keyframe)
51         float get_value() {return this->value;}
52         void  set_value(float newval);
53
54 // Possible policies to handle the tagents for the 
55 // bézier curves connecting adjacent automation points
56         enum t_mode 
57         {
58                 SMOOTH,     // curves are coupled in order to yield a smooth curve
59                 LINEAR,     // curves always pointing directly to neighbouring automation points
60                 TFREE,      // curves on both sides coupled but editable by dragging the handles
61                 FREE        // curves on both sides are independent and editable via GUI
62         };
63
64         t_mode curve_mode;
65         void change_curve_mode(t_mode); // recalculates curves as well
66         void toggle_curve_mode();       // cycles through all modes (e.g. by ctrl-click)
67
68 // Control values (y coords of bézier control point), relative to value
69         float get_control_in_value()            {check_pos(); return this->control_in_value;}
70         float get_control_out_value()           {check_pos(); return this->control_out_value;}
71         void set_control_in_value(float newval);
72         void set_control_out_value(float newval);
73         
74 // get calculated x-position of control points for drawing, 
75 // relative to auto position, in native units of the track.
76         int64_t get_control_in_position()       {check_pos(); return this->control_in_position;}
77         int64_t get_control_out_position()      {check_pos(); return this->control_out_position;}
78         
79 // define new position and value, re-adjust ctrl point, notify neighbours
80         void adjust_to_new_coordinates(int64_t position, float value);
81 // text name for curve mode
82         static const char *curve_name(int curve_mode);
83
84 private:
85         void adjust_curves();             // recalc. ctrk in and out points, if automatic curve mode (SMOOTH or LINEAR)
86         void adjust_ctrl_positions(FloatAuto *p=0, FloatAuto *n=0); // recalc. x location of ctrl points, notify neighbours
87         void set_ctrl_positions(FloatAuto*, FloatAuto*);
88         void calculate_slope(FloatAuto* a1, FloatAuto* a2, float& dvdx, float& dx);
89         void check_pos()                    { if(position != pos_valid) adjust_ctrl_positions(); }
90         void curve_dirty()                { pos_valid=-1; }
91         void handle_automatic_curve_after_copy();       
92
93 // Control values are relative to value
94         float value, control_in_value, control_out_value;
95 // X control positions relative to value position for drawing.
96 // In native units of the track.
97         int64_t control_in_position, control_out_position;
98
99         int64_t pos_valid;                  // 'dirty flag' to recalculate ctrl point positions on demand
100         int value_to_str(char *string, float value);
101 };
102
103
104
105 #endif