changes associated with save/restore of AutomationControl id's
[ardour2.git] / gtk2_ardour / automation_line.h
blob6fea1699ccd1a12460014189e9f2c79305a35a6f
1 /*
2 Copyright (C) 2002 Paul Davis
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 #ifndef __ardour_automation_line_h__
21 #define __ardour_automation_line_h__
23 #include <vector>
24 #include <list>
25 #include <string>
26 #include <sys/types.h>
28 #include <libgnomecanvasmm/line.h>
29 #include <sigc++/signal.h>
30 #include "canvas.h"
31 #include "simplerect.h"
33 #include "evoral/TimeConverter.hpp"
35 #include "pbd/undo.h"
36 #include "pbd/statefuldestructible.h"
37 #include "pbd/memento_command.h"
39 #include "ardour/automation_list.h"
40 #include "ardour/types.h"
42 class AutomationLine;
43 class ControlPoint;
44 class PointSelection;
45 class TimeAxisView;
46 class AutomationTimeAxisView;
47 class Selectable;
48 class Selection;
50 namespace Gnome {
51 namespace Canvas {
52 class SimpleRect;
56 /** A GUI representation of an ARDOUR::AutomationList */
57 class AutomationLine : public sigc::trackable, public PBD::StatefulDestructible
59 public:
60 AutomationLine (const std::string& name, TimeAxisView&, ArdourCanvas::Group&,
61 boost::shared_ptr<ARDOUR::AutomationList>,
62 const Evoral::TimeConverter<double, ARDOUR::framepos_t>* converter = 0);
63 virtual ~AutomationLine ();
65 void queue_reset ();
66 void reset ();
67 void clear ();
69 std::list<ControlPoint*> point_selection_to_control_points (PointSelection const &);
70 void set_selected_points (PointSelection&);
71 void get_selectables (ARDOUR::framepos_t, ARDOUR::framepos_t, double, double, std::list<Selectable*>&);
72 void get_inverted_selectables (Selection&, std::list<Selectable*>& results);
74 virtual void remove_point (ControlPoint&);
75 bool control_points_adjacent (double xval, uint32_t& before, uint32_t& after);
77 /* dragging API */
78 virtual void start_drag_single (ControlPoint*, double, float);
79 virtual void start_drag_line (uint32_t, uint32_t, float);
80 virtual void start_drag_multiple (std::list<ControlPoint*>, float, XMLNode *);
81 virtual std::pair<double, float> drag_motion (double, float, bool, bool);
82 virtual void end_drag ();
84 ControlPoint* nth (uint32_t);
85 ControlPoint const * nth (uint32_t) const;
86 uint32_t npoints() const { return control_points.size(); }
88 std::string name() const { return _name; }
89 bool visible() const { return _visible; }
90 guint32 height() const { return _height; }
92 void set_line_color (uint32_t);
93 uint32_t get_line_color() const { return _line_color; }
95 void show ();
96 void hide ();
97 void set_height (guint32);
98 void set_uses_gain_mapping (bool yn);
99 bool get_uses_gain_mapping () const { return _uses_gain_mapping; }
101 TimeAxisView& trackview;
103 ArdourCanvas::Group& canvas_group() const { return *group; }
104 ArdourCanvas::Item& parent_group() const { return _parent_group; }
105 ArdourCanvas::Item& grab_item() const { return *line; }
107 std::string get_verbose_cursor_string (double) const;
108 std::string fraction_to_string (double) const;
109 double string_to_fraction (std::string const &) const;
110 void view_to_model_coord (double& x, double& y) const;
111 void view_to_model_coord_y (double &) const;
112 void model_to_view_coord (double& x, double& y) const;
114 void set_list(boost::shared_ptr<ARDOUR::AutomationList> list);
115 boost::shared_ptr<ARDOUR::AutomationList> the_list() const { return alist; }
117 void show_all_control_points ();
118 void hide_all_but_selected_control_points ();
120 void track_entered();
121 void track_exited();
123 bool is_last_point (ControlPoint &);
124 bool is_first_point (ControlPoint &);
126 XMLNode& get_state (void);
127 int set_state (const XMLNode&, int version);
128 void set_colors();
130 void modify_point_y (ControlPoint&, double);
132 void add_always_in_view (double);
133 void clear_always_in_view ();
135 virtual MementoCommandBinder<ARDOUR::AutomationList>* memento_command_binder ();
137 const Evoral::TimeConverter<double, ARDOUR::framepos_t>& time_converter () const {
138 return _time_converter;
141 std::pair<ARDOUR::framepos_t, ARDOUR::framepos_t> get_point_x_range () const;
143 void set_maximum_time (ARDOUR::framepos_t);
144 ARDOUR::framepos_t maximum_time () const {
145 return _maximum_time;
148 protected:
150 std::string _name;
151 guint32 _height;
152 uint32_t _line_color;
154 boost::shared_ptr<ARDOUR::AutomationList> alist;
156 bool _visible : 1;
157 bool _uses_gain_mapping : 1;
158 bool terminal_points_can_slide : 1;
159 bool update_pending : 1;
160 bool no_draw : 1;
161 bool _is_boolean : 1;
162 bool points_visible : 1;
163 bool did_push;
165 ArdourCanvas::Group& _parent_group;
166 ArdourCanvas::Group* group;
167 ArdourCanvas::Line* line; /* line */
168 ArdourCanvas::Points line_points; /* coordinates for canvas line */
169 std::vector<ControlPoint*> control_points; /* visible control points */
171 struct ALPoint {
172 double x;
173 double y;
174 ALPoint (double xx, double yy) : x(xx), y(yy) {}
177 typedef std::vector<ALPoint> ALPoints;
179 static void invalidate_point (ALPoints&, uint32_t index);
180 static bool invalid_point (ALPoints&, uint32_t index);
182 void determine_visible_control_points (ALPoints&);
183 void sync_model_with_view_point (ControlPoint&, bool, int64_t);
184 void sync_model_with_view_points (std::list<ControlPoint*>, bool, int64_t);
185 void start_drag_common (double, float);
187 virtual void change_model (ARDOUR::AutomationList::iterator, double x, double y);
189 void reset_callback (const Evoral::ControlList&);
190 void list_changed ();
192 virtual bool event_handler (GdkEvent*);
193 virtual void add_model_point (ALPoints& tmp_points, double frame, double yfract);
195 private:
196 std::list<ControlPoint*> _drag_points; ///< points we are dragging
197 std::list<ControlPoint*> _push_points; ///< additional points we are dragging if "push" is enabled
198 bool _drag_had_movement; ///< true if the drag has seen movement, otherwise false
199 double _drag_x; ///< last x position of the drag, in units
200 double _drag_distance; ///< total x movement of the drag, in units
201 double _last_drag_fraction; ///< last y position of the drag, as a fraction
202 std::list<double> _always_in_view;
204 const Evoral::TimeConverter<double, ARDOUR::framepos_t>& _time_converter;
206 void reset_line_coords (ControlPoint&);
207 void add_visible_control_point (uint32_t, uint32_t, double, double, ARDOUR::AutomationList::iterator, uint32_t);
208 double control_point_box_size ();
209 void connect_to_list ();
210 void interpolation_changed (ARDOUR::AutomationList::InterpolationStyle);
212 struct ModelRepresentation {
213 ARDOUR::AutomationList::iterator start;
214 ARDOUR::AutomationList::iterator end;
215 double xpos;
216 double ypos;
217 double xmin;
218 double ymin;
219 double xmax;
220 double ymax;
221 double xval;
222 double yval;
225 void model_representation (ControlPoint&, ModelRepresentation&);
227 PBD::ScopedConnectionList _list_connections;
229 /** maximum time that a point on this line can be at, relative to the start of its region or track */
230 ARDOUR::framecnt_t _maximum_time;
232 friend class AudioRegionGainLine;
235 #endif /* __ardour_automation_line_h__ */