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__
26 #include <sys/types.h>
28 #include <sigc++/signal.h>
30 #include "evoral/TimeConverter.hpp"
33 #include "pbd/statefuldestructible.h"
34 #include "pbd/memento_command.h"
36 #include "ardour/automation_list.h"
37 #include "ardour/types.h"
39 #include "canvas/types.h"
40 #include "canvas/group.h"
41 #include "canvas/line.h"
47 class AutomationTimeAxisView;
51 namespace ArdourCanvas {
55 /** A GUI representation of an ARDOUR::AutomationList */
56 class AutomationLine : public sigc::trackable, public PBD::StatefulDestructible
62 SelectedControlPoints = 0x4
65 AutomationLine (const std::string& name, TimeAxisView&, ArdourCanvas::Group&,
66 boost::shared_ptr<ARDOUR::AutomationList>,
67 Evoral::TimeConverter<double, ARDOUR::framepos_t>* converter = 0);
68 virtual ~AutomationLine ();
74 void set_selected_points (PointSelection const &);
75 void get_selectables (ARDOUR::framepos_t, ARDOUR::framepos_t, double, double, std::list<Selectable*>&);
76 void get_inverted_selectables (Selection&, std::list<Selectable*>& results);
78 virtual void remove_point (ControlPoint&);
79 bool control_points_adjacent (double xval, uint32_t& before, uint32_t& after);
82 virtual void start_drag_single (ControlPoint*, double, float);
83 virtual void start_drag_line (uint32_t, uint32_t, float);
84 virtual void start_drag_multiple (std::list<ControlPoint*>, float, XMLNode *);
85 virtual std::pair<double, float> drag_motion (double, float, bool, bool with_push, uint32_t& final_index);
86 virtual void end_drag (bool with_push, uint32_t final_index);
88 ControlPoint* nth (uint32_t);
89 ControlPoint const * nth (uint32_t) const;
90 uint32_t npoints() const { return control_points.size(); }
92 std::string name() const { return _name; }
93 bool visible() const { return _visible != VisibleAspects(0); }
94 guint32 height() const { return _height; }
96 void set_line_color (uint32_t);
97 uint32_t get_line_color() const { return _line_color; }
99 void set_visibility (VisibleAspects);
100 void add_visibility (VisibleAspects);
101 void remove_visibility (VisibleAspects);
104 void set_height (guint32);
105 void set_uses_gain_mapping (bool yn);
106 bool get_uses_gain_mapping () const { return _uses_gain_mapping; }
108 TimeAxisView& trackview;
110 ArdourCanvas::Group& canvas_group() const { return *group; }
111 ArdourCanvas::Item& parent_group() const { return _parent_group; }
112 ArdourCanvas::Item& grab_item() const { return *line; }
114 std::string get_verbose_cursor_string (double) const;
115 std::string get_verbose_cursor_relative_string (double, double) const;
116 std::string fraction_to_string (double) const;
117 std::string fraction_to_relative_string (double, double) const;
118 double string_to_fraction (std::string const &) const;
119 void view_to_model_coord (double& x, double& y) const;
120 void view_to_model_coord_y (double &) const;
121 void model_to_view_coord (double& x, double& y) const;
123 void set_list(boost::shared_ptr<ARDOUR::AutomationList> list);
124 boost::shared_ptr<ARDOUR::AutomationList> the_list() const { return alist; }
126 void track_entered();
129 bool is_last_point (ControlPoint &);
130 bool is_first_point (ControlPoint &);
132 XMLNode& get_state (void);
133 int set_state (const XMLNode&, int version);
136 void modify_point_y (ControlPoint&, double);
138 virtual MementoCommandBinder<ARDOUR::AutomationList>* memento_command_binder ();
140 const Evoral::TimeConverter<double, ARDOUR::framepos_t>& time_converter () const {
141 return *_time_converter;
144 std::pair<ARDOUR::framepos_t, ARDOUR::framepos_t> get_point_x_range () const;
146 void set_maximum_time (ARDOUR::framecnt_t);
147 ARDOUR::framecnt_t maximum_time () const {
148 return _maximum_time;
151 void set_offset (ARDOUR::framecnt_t);
152 void set_width (ARDOUR::framecnt_t);
154 framepos_t session_position (ARDOUR::AutomationList::const_iterator) const;
160 uint32_t _line_color;
162 boost::shared_ptr<ARDOUR::AutomationList> alist;
163 Evoral::TimeConverter<double, ARDOUR::framepos_t>* _time_converter;
164 /** true if _time_converter belongs to us (ie we should delete it on destruction) */
165 bool _our_time_converter;
167 VisibleAspects _visible;
169 bool _uses_gain_mapping;
170 bool terminal_points_can_slide;
175 /** true if we did a push at any point during the current drag */
178 ArdourCanvas::Group& _parent_group;
179 ArdourCanvas::Group* group;
180 ArdourCanvas::PolyLine* line; /* line */
181 ArdourCanvas::Points line_points; /* coordinates for canvas line */
182 std::vector<ControlPoint*> control_points; /* visible control points */
184 class ContiguousControlPoints : public std::list<ControlPoint*> {
186 ContiguousControlPoints (AutomationLine& al);
187 double clamp_dx (double dx);
188 void move (double dx, double dy);
189 void compute_x_bounds ();
191 AutomationLine& line;
196 friend class ContiguousControlPoints;
198 typedef boost::shared_ptr<ContiguousControlPoints> CCP;
199 std::vector<CCP> contiguous_points;
201 void sync_model_with_view_point (ControlPoint&);
202 void sync_model_with_view_points (std::list<ControlPoint*>);
203 void start_drag_common (double, float);
205 virtual void change_model (ARDOUR::AutomationList::iterator, double x, double y);
207 void reset_callback (const Evoral::ControlList&);
208 void list_changed ();
210 virtual bool event_handler (GdkEvent*);
213 std::list<ControlPoint*> _drag_points; ///< points we are dragging
214 std::list<ControlPoint*> _push_points; ///< additional points we are dragging if "push" is enabled
215 bool _drag_had_movement; ///< true if the drag has seen movement, otherwise false
216 double _drag_x; ///< last x position of the drag, in units
217 double _drag_distance; ///< total x movement of the drag, in canvas units
218 double _last_drag_fraction; ///< last y position of the drag, as a fraction
219 /** offset from the start of the automation list to the start of the line, so that
220 * a +ve offset means that the 0 on the line is at _offset in the list
222 ARDOUR::framecnt_t _offset;
225 void reset_line_coords (ControlPoint&);
226 void add_visible_control_point (uint32_t, uint32_t, double, double, ARDOUR::AutomationList::iterator, uint32_t);
227 double control_point_box_size ();
228 void connect_to_list ();
229 void interpolation_changed (ARDOUR::AutomationList::InterpolationStyle);
231 PBD::ScopedConnectionList _list_connections;
233 /** maximum time that a point on this line can be at, relative to the position of its region or start of its track */
234 ARDOUR::framecnt_t _maximum_time;
236 friend class AudioRegionGainLine;
239 #endif /* __ardour_automation_line_h__ */