* make MIDI-specific menu show up on all MIDI lanes
[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 <libgnomecanvasmm/line.h>
29 #include <sigc++/signal.h>
30 #include "canvas.h"
31 #include "simplerect.h"
32
33 #include <pbd/undo.h>
34 #include <pbd/statefuldestructible.h> 
35
36 #include <ardour/automation_list.h>
37
38
39 class AutomationLine;
40 class ControlPoint;
41 class PointSelection;
42 class TimeAxisView;
43 class AutomationTimeAxisView;
44 class Selectable;
45 class Selection;
46
47 namespace Gnome {
48         namespace Canvas {
49                 class SimpleRect;
50         }
51 }
52
53 class AutomationLine : public sigc::trackable, public PBD::StatefulThingWithGoingAway
54 {
55   public:
56         AutomationLine (const string & name, TimeAxisView&, ArdourCanvas::Group&, boost::shared_ptr<ARDOUR::AutomationList>);
57         virtual ~AutomationLine ();
58
59         void queue_reset ();
60         void reset ();
61         void clear();
62
63         void set_selected_points (PointSelection&);
64         void get_selectables (nframes_t& start, nframes_t& end,
65                               double botfrac, double topfrac, 
66                               std::list<Selectable*>& results);
67         void get_inverted_selectables (Selection&, std::list<Selectable*>& results);
68
69         virtual void remove_point (ControlPoint&);
70         bool control_points_adjacent (double xval, uint32_t& before, uint32_t& after);
71         
72         /* dragging API */
73
74         virtual void start_drag (ControlPoint*, nframes_t x, float fraction);
75         virtual void point_drag(ControlPoint&, nframes_t x, float, bool with_push);
76         virtual void end_drag (ControlPoint*);
77         virtual void line_drag(uint32_t i1, uint32_t i2, float, bool with_push);
78
79         ControlPoint* nth (uint32_t);
80         uint32_t npoints() const { return control_points.size(); }
81
82         string  name() const { return _name; }
83         bool    visible() const { return _visible; }
84         guint32 height() const { return _height; }
85
86         void     set_line_color (uint32_t);
87         uint32_t get_line_color() const { return _line_color; }
88
89         void set_interpolation(ARDOUR::AutomationList::InterpolationStyle style);
90
91         void    show ();
92         void    hide ();
93         void    set_height (guint32);
94         void    set_uses_gain_mapping (bool yn);
95         bool    get_uses_gain_mapping () const { return _uses_gain_mapping; }
96
97         TimeAxisView& trackview;
98
99         ArdourCanvas::Group& canvas_group() const { return *group; }
100         ArdourCanvas::Item&  parent_group() const { return _parent_group; }
101         ArdourCanvas::Item&  grab_item() const { return *line; }
102
103         void show_selection();
104         void hide_selection ();
105
106         string get_verbose_cursor_string (double) const;
107         string fraction_to_string (double) const;
108         double string_to_fraction (string const &) const;
109         void   view_to_model_y (double&) const;
110         void   model_to_view_y (double&) const;
111
112         void set_list(boost::shared_ptr<ARDOUR::AutomationList> list);
113         boost::shared_ptr<ARDOUR::AutomationList> the_list() const { return alist; }
114
115         void show_all_control_points ();
116         void hide_all_but_selected_control_points ();
117
118         void track_entered();
119         void track_exited();
120
121         bool is_last_point (ControlPoint &);
122         bool is_first_point (ControlPoint &);
123
124         XMLNode& get_state (void);
125         int set_state (const XMLNode&);
126         void set_colors();
127
128         void modify_point_y (ControlPoint&, double);
129
130   protected:
131
132         string    _name;
133         guint32   _height;
134         uint32_t  _line_color;
135         
136         boost::shared_ptr<ARDOUR::AutomationList> alist;
137
138         bool    _visible                  : 1;
139         bool    _uses_gain_mapping        : 1;
140         bool    terminal_points_can_slide : 1;
141         bool    update_pending            : 1;
142         bool    no_draw                   : 1;
143         bool    points_visible            : 1;
144         bool    did_push;
145
146         ArdourCanvas::Group&        _parent_group;
147         ArdourCanvas::Group*        group;
148         ArdourCanvas::Line*         line; /* line */
149         ArdourCanvas::Points        line_points; /* coordinates for canvas line */
150         std::vector<ControlPoint*>  control_points; /* visible control points */
151
152         struct ALPoint {
153             double x;
154             double y;
155             ALPoint (double xx, double yy) : x(xx), y(yy) {}
156         };
157
158         typedef std::vector<ALPoint> ALPoints;
159
160         static void invalidate_point (ALPoints&, uint32_t index);
161         static bool invalid_point (ALPoints&, uint32_t index);
162         
163         void determine_visible_control_points (ALPoints&);
164         void sync_model_with_view_point (ControlPoint&, bool did_push, int64_t distance);
165         void sync_model_with_view_line (uint32_t, uint32_t);
166         
167         virtual void change_model (ARDOUR::AutomationList::iterator, double x, double y);
168
169         void reset_callback (const Evoral::ControlList&);
170         void list_changed ();
171
172         virtual bool event_handler (GdkEvent*);
173         virtual void add_model_point (ALPoints& tmp_points, double frame, double yfract);
174         
175   private:
176         uint32_t drags;
177         double   first_drag_fraction;
178         double   last_drag_fraction;
179         uint32_t line_drag_cp1;
180         uint32_t line_drag_cp2;
181         int64_t  drag_x;
182         int64_t  drag_distance;
183         
184         ARDOUR::AutomationList::InterpolationStyle _interpolation;
185
186         void modify_view_point (ControlPoint&, double, double, bool with_push);
187         void reset_line_coords (ControlPoint&);
188
189         double control_point_box_size ();
190
191         struct ModelRepresentation {
192             ARDOUR::AutomationList::iterator start;
193             ARDOUR::AutomationList::iterator end;
194             nframes_t xpos;
195             double ypos;
196             nframes_t xmin;
197             double ymin;
198             nframes_t xmax;
199             double ymax;
200             nframes_t xval;
201             double yval;
202         };
203
204         void model_representation (ControlPoint&, ModelRepresentation&);
205
206         friend class AudioRegionGainLine;
207 };
208
209 #endif /* __ardour_automation_line_h__ */
210