4 * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
5 * Copyright (C) 2003-2016 Cinelerra CV contributors
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 // Automation point that takes floating point values
32 #include "floatautos.inc"
34 class FloatAuto : public Auto
36 friend class FloatAutos;
39 FloatAuto(EDL *edl, FloatAutos *autos);
42 bool is_floatauto() { return true; }
43 int operator==(Auto &that);
44 int operator==(FloatAuto &that);
45 int identical(FloatAuto *src);
46 int equals(FloatAuto *src);
47 void copy_from(Auto *that);
48 void copy_from(FloatAuto *that);
49 int interpolate_from(Auto *a1, Auto *a2, int64_t pos, Auto *templ=0); // bezier interpolation
50 void copy(int64_t start, int64_t end, FileXML *file, int default_only);
51 void load(FileXML *xml);
53 // for curves, edge==0: the right value, for bumps, edge!=0: the left value1
54 float get_value(int edge=0) {
55 return curve_mode==BUMP && edge ? this->value1 : this->value;
57 // edge==0: set value, for bumps: edge>0, set value1, edge<0: set both
58 void set_value(float value, int edge=-1);
59 void bump_update(int64_t pos, float dv, int edge, int span);
60 void bump_value(float v, int edge, int span);
62 // Possible policies to handle the tagents for the
63 // bézier curves connecting adjacent automation points
66 SMOOTH, // curves are coupled in order to yield a smooth curve
67 LINEAR, // curves always pointing directly to neighbouring automation points
68 TFREE, // curves on both sides coupled but editable by dragging the handles
69 FREE, // curves on both sides are independent and editable via GUI
70 BUMP, // curves and values both sides are independent and editable via GUI
74 void change_curve_mode(t_mode, int adjust=1); // recalculates curves as well
75 void toggle_curve_mode(); // cycles through all modes (e.g. by ctrl-click)
76 int is_bump() { return curve_mode == BUMP ? 1 : 0; }
78 // Control values (y coords of bézier control point), relative to value
79 float get_control_in_value() {check_pos(); return this->control_in_value;}
80 float get_control_out_value() {check_pos(); return this->control_out_value;}
81 void set_control_in_value(float newval);
82 void set_control_out_value(float newval);
84 // get calculated x-position of control points for drawing,
85 // relative to auto position, in native units of the track.
86 int64_t get_control_in_position() {check_pos(); return this->control_in_position;}
87 int64_t get_control_out_position() {check_pos(); return this->control_out_position;}
89 // define new position and value, re-adjust ctrl point, notify neighbours
90 void adjust_to_new_coordinates(int64_t position, float value);
91 // text name for curve mode
92 static const char *curve_name(int curve_mode);
94 void adjust_curves(); // recalc. ctrk in and out points, if automatic curve mode (SMOOTH or LINEAR)
95 void adjust_ctrl_positions(FloatAuto *p=0, FloatAuto *n=0); // recalc. x location of ctrl points, notify neighbours
96 void set_ctrl_positions(FloatAuto*, FloatAuto*);
97 void calculate_slope(FloatAuto* a1, FloatAuto* a2, float& dvdx, float& dx);
98 void check_pos() { if(position != pos_valid) adjust_ctrl_positions(); }
99 void curve_dirty() { pos_valid=-1; }
100 void handle_automatic_curve_after_copy();
102 // Control values are relative to value
103 float value, control_in_value, control_out_value, value1;
104 // X control positions relative to value position for drawing.
105 // In native units of the track.
106 int64_t control_in_position, control_out_position;
108 int64_t pos_valid; // 'dirty flag' to recalculate ctrl point positions on demand
109 int value_to_str(char *string, float value);