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