fix merge conflicts from master
[ardour.git] / gtk2_ardour / automation_line.h
1 /*
2     Copyright (C) 2002 Paul Davis
3
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.
8
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.
13
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.
17
18 */
19
20 #ifndef __ardour_automation_line_h__
21 #define __ardour_automation_line_h__
22
23 #include <vector>
24 #include <list>
25 #include <string>
26 #include <sys/types.h>
27
28 #include <sigc++/signal.h>
29
30 #include "evoral/TimeConverter.hpp"
31
32 #include "pbd/undo.h"
33 #include "pbd/statefuldestructible.h"
34 #include "pbd/memento_command.h"
35
36 #include "ardour/automation_list.h"
37 #include "ardour/types.h"
38
39 #include "canvas/types.h"
40 #include "canvas/group.h"
41 #include "canvas/curve.h"
42
43 class AutomationLine;
44 class ControlPoint;
45 class PointSelection;
46 class TimeAxisView;
47 class AutomationTimeAxisView;
48 class Selectable;
49 class Selection;
50
51
52 /** A GUI representation of an ARDOUR::AutomationList */
53 class AutomationLine : public sigc::trackable, public PBD::StatefulDestructible
54 {
55   public:
56         enum VisibleAspects {
57                 Line = 0x1,
58                 ControlPoints = 0x2,
59                 SelectedControlPoints = 0x4
60         };
61         
62         AutomationLine (const std::string& name, TimeAxisView&, ArdourCanvas::Group&,
63                         boost::shared_ptr<ARDOUR::AutomationList>,
64                         Evoral::TimeConverter<double, ARDOUR::framepos_t>* converter = 0);
65         virtual ~AutomationLine ();
66
67         void queue_reset ();
68         void reset ();
69         void clear ();
70
71         void set_selected_points (PointSelection const &);
72         void get_selectables (ARDOUR::framepos_t, ARDOUR::framepos_t, double, double, std::list<Selectable*>&);
73         void get_inverted_selectables (Selection&, std::list<Selectable*>& results);
74
75         virtual void remove_point (ControlPoint&);
76         bool control_points_adjacent (double xval, uint32_t& before, uint32_t& after);
77
78         /* dragging API */
79         virtual void start_drag_single (ControlPoint*, double, float);
80         virtual void start_drag_line (uint32_t, uint32_t, float);
81         virtual void start_drag_multiple (std::list<ControlPoint*>, float, XMLNode *);
82         virtual std::pair<double, float> drag_motion (double, float, bool, bool with_push, uint32_t& final_index);
83         virtual void end_drag (bool with_push, uint32_t final_index);
84
85         ControlPoint* nth (uint32_t);
86         ControlPoint const * nth (uint32_t) const;
87         uint32_t npoints() const { return control_points.size(); }
88
89         std::string  name()    const { return _name; }
90         bool    visible() const { return _visible != VisibleAspects(0); }
91         guint32 height()  const { return _height; }
92
93         void     set_line_color (uint32_t);
94         uint32_t get_line_color() const { return _line_color; }
95
96         void set_visibility (VisibleAspects);
97         void add_visibility (VisibleAspects);
98         void remove_visibility (VisibleAspects);
99
100         void hide ();
101         void set_height (guint32);
102         void set_uses_gain_mapping (bool yn);
103         bool get_uses_gain_mapping () const { return _uses_gain_mapping; }
104
105         TimeAxisView& trackview;
106
107         ArdourCanvas::Group& canvas_group() const { return *group; }
108         ArdourCanvas::Item&  parent_group() const { return _parent_group; }
109         ArdourCanvas::Item&  grab_item() const { return *line; }
110
111         std::string get_verbose_cursor_string (double) const;
112         std::string get_verbose_cursor_relative_string (double, double) const;
113         std::string fraction_to_string (double) const;
114         std::string fraction_to_relative_string (double, double) const;
115         double string_to_fraction (std::string const &) const;
116         void   view_to_model_coord (double& x, double& y) const;
117         void   view_to_model_coord_y (double &) const;
118         void   model_to_view_coord (double& x, double& y) const;
119
120         void set_list(boost::shared_ptr<ARDOUR::AutomationList> list);
121         boost::shared_ptr<ARDOUR::AutomationList> the_list() const { return alist; }
122
123         void track_entered();
124         void track_exited();
125
126         bool is_last_point (ControlPoint &);
127         bool is_first_point (ControlPoint &);
128
129         XMLNode& get_state (void);
130         int set_state (const XMLNode&, int version);
131         void set_colors();
132
133         void modify_point_y (ControlPoint&, double);
134
135         virtual MementoCommandBinder<ARDOUR::AutomationList>* memento_command_binder ();
136
137         const Evoral::TimeConverter<double, ARDOUR::framepos_t>& time_converter () const {
138                 return *_time_converter;
139         }
140
141         std::pair<ARDOUR::framepos_t, ARDOUR::framepos_t> get_point_x_range () const;
142
143         void set_maximum_time (ARDOUR::framecnt_t);
144         ARDOUR::framecnt_t maximum_time () const {
145                 return _maximum_time;
146         }
147
148         void set_offset (ARDOUR::framecnt_t);
149         void set_width (ARDOUR::framecnt_t);
150
151         framepos_t session_position (ARDOUR::AutomationList::const_iterator) const;
152
153   protected:
154
155         std::string    _name;
156         guint32   _height;
157         uint32_t  _line_color;
158
159         boost::shared_ptr<ARDOUR::AutomationList> alist;
160         Evoral::TimeConverter<double, ARDOUR::framepos_t>* _time_converter;
161         /** true if _time_converter belongs to us (ie we should delete it on destruction) */
162         bool _our_time_converter;
163
164         VisibleAspects _visible;
165  
166         bool    _uses_gain_mapping;
167         bool    terminal_points_can_slide;
168         bool    update_pending;
169         bool    have_timeout;
170         bool    no_draw;
171         bool    _is_boolean;
172         /** true if we did a push at any point during the current drag */
173         bool    did_push;
174
175         ArdourCanvas::Group&        _parent_group;
176         ArdourCanvas::Group*        group;
177         ArdourCanvas::Curve*        line; /* line */
178         ArdourCanvas::Points        line_points; /* coordinates for canvas line */
179         std::vector<ControlPoint*>  control_points; /* visible control points */
180
181         class ContiguousControlPoints : public std::list<ControlPoint*> {
182           public:
183             ContiguousControlPoints (AutomationLine& al);
184             double clamp_dx (double dx);
185             void move (double dx, double dy);
186             void compute_x_bounds ();
187           private:
188             AutomationLine& line;
189             double before_x;
190             double after_x;
191         };
192
193         friend class ContiguousControlPoints;
194
195         typedef boost::shared_ptr<ContiguousControlPoints> CCP;
196         std::vector<CCP> contiguous_points;
197
198         void sync_model_with_view_point (ControlPoint&);
199         void sync_model_with_view_points (std::list<ControlPoint*>);
200         void start_drag_common (double, float);
201
202         virtual void change_model (ARDOUR::AutomationList::iterator, double x, double y);
203
204         void reset_callback (const Evoral::ControlList&);
205         void list_changed ();
206
207         virtual bool event_handler (GdkEvent*);
208
209   private:
210         std::list<ControlPoint*> _drag_points; ///< points we are dragging
211         std::list<ControlPoint*> _push_points; ///< additional points we are dragging if "push" is enabled
212         bool _drag_had_movement; ///< true if the drag has seen movement, otherwise false
213         double _drag_x; ///< last x position of the drag, in units
214         double _drag_distance; ///< total x movement of the drag, in canvas units
215         double _last_drag_fraction; ///< last y position of the drag, as a fraction
216         /** offset from the start of the automation list to the start of the line, so that
217          *  a +ve offset means that the 0 on the line is at _offset in the list
218          */
219         ARDOUR::framecnt_t _offset;
220
221         void show ();
222         void reset_line_coords (ControlPoint&);
223         void add_visible_control_point (uint32_t, uint32_t, double, double, ARDOUR::AutomationList::iterator, uint32_t);
224         double control_point_box_size ();
225         void connect_to_list ();
226         void interpolation_changed (ARDOUR::AutomationList::InterpolationStyle);
227
228         PBD::ScopedConnectionList _list_connections;
229
230         /** maximum time that a point on this line can be at, relative to the position of its region or start of its track */
231         ARDOUR::framecnt_t _maximum_time;
232
233         friend class AudioRegionGainLine;
234 };
235
236 #endif /* __ardour_automation_line_h__ */
237