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