fix lack of canvas.h
[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     $Id$
19 */
20
21 #ifndef __ardour_automation_line_h__
22 #define __ardour_automation_line_h__
23
24 #include <vector>
25 #include <list>
26 #include <string>
27 #include <sys/types.h>
28
29 #include <gtkmm.h>
30 #include <libgnomecanvasmm/libgnomecanvasmm.h>
31 #include <sigc++/signal.h>
32
33 #include <pbd/undo.h>
34
35 #include <ardour/automation_event.h>
36
37
38 using std::vector;
39 using std::string;
40
41 class AutomationLine;
42 class ControlPoint;
43 class PointSelection;
44 class TimeAxisView;
45 class AutomationTimeAxisView;
46 class Selectable;
47 class Selection;
48
49 namespace Gnome {
50         namespace Canvas {
51                 class SimpleRect;
52         }
53 }
54
55 class ControlPoint 
56 {
57   public:
58         ControlPoint (AutomationLine& al, sigc::slot<bool,GdkEvent*,ControlPoint*>);
59         ControlPoint (const ControlPoint&, bool dummy_arg_to_force_special_copy_constructor);
60         ~ControlPoint ();
61
62         enum ShapeType {
63                 Full,
64                 Start,
65                 End
66         };
67         
68         void move_to (double x, double y, ShapeType);
69         void reset (double x, double y, ARDOUR::AutomationList::iterator, uint32_t, ShapeType);
70         double get_x() const { return _x; }
71         double get_y() const { return _y; }
72
73         void hide (); 
74         void show ();
75         void show_color (bool entered, bool hide_too);
76
77         void set_size (double);
78         void set_visible (bool);
79
80         Gnome::Canvas::SimpleRect* item;
81         AutomationLine& line;
82         uint32_t view_index;
83         ARDOUR::AutomationList::iterator model;
84         bool can_slide;
85         bool selected;
86         
87   private:
88         double _x;
89         double _y;
90         double _size;
91         ShapeType _shape;
92 };
93
94 class AutomationLine : public sigc::trackable
95 {
96   public:
97         AutomationLine (string name, TimeAxisView&, Gnome::Canvas::Group&, ARDOUR::AutomationList&,
98                         sigc::slot<bool,GdkEvent*,ControlPoint*>, sigc::slot<bool,GdkEvent*,AutomationLine*>);
99
100         virtual ~AutomationLine ();
101
102         void queue_reset ();
103         void reset ();
104         void clear();
105
106         void set_selected_points (PointSelection&);
107         void get_selectables (jack_nframes_t& start, jack_nframes_t& end,
108                               double botfrac, double topfrac, 
109                               list<Selectable*>& results);
110         void get_inverted_selectables (Selection&, list<Selectable*>& results);
111
112         virtual void remove_point (ControlPoint&);
113         bool control_points_adjacent (double xval, uint32_t& before, uint32_t& after);
114         
115         /* dragging API */
116
117         virtual void start_drag (ControlPoint*, float fraction);
118         virtual void point_drag(ControlPoint&, jack_nframes_t x, float, bool with_push);
119         virtual void end_drag (ControlPoint*);
120         virtual void line_drag(uint32_t i1, uint32_t i2, float, bool with_push);
121
122         ControlPoint* nth (uint32_t);
123         uint32_t npoints() const { return control_points.size(); }
124
125         string  name() const { return _name; }
126         bool    visible() const { return _visible; }
127         guint32 height() const { return _height; }
128
129         void         set_line_color (uint32_t);
130         uint32_t get_line_color() const { return _line_color; }
131
132         void    show ();
133         void    hide ();
134         void    set_height (guint32);
135         void    set_verbose_cursor_uses_gain_mapping (bool yn);
136
137         TimeAxisView& trackview;
138
139         Gnome::Canvas::Group& canvas_group() const { return *group; }
140         Gnome::Canvas::Item&  parent_group() const { return _parent_group; }
141         Gnome::Canvas::Item&  grab_item() const { return *line; }
142
143         void show_selection();
144         void hide_selection ();
145
146         void set_point_size (double size);
147
148         virtual string  get_verbose_cursor_string (float);
149         virtual void view_to_model_y (double&) = 0;
150         virtual void model_to_view_y (double&) = 0;
151
152         ARDOUR::AutomationList& the_list() const { return alist; }
153
154         void show_all_control_points ();
155         void hide_all_but_selected_control_points ();
156
157         bool is_last_point (ControlPoint &);
158         bool is_first_point (ControlPoint &);
159
160   protected:
161         string _name;
162         guint32 _height;
163         uint32_t _line_color;
164         ARDOUR::AutomationList& alist;
165
166         bool    _visible  : 1;
167         bool    _vc_uses_gain_mapping : 1;
168         bool    terminal_points_can_slide : 1;
169         bool    update_pending : 1;
170         bool    no_draw : 1;
171         bool    points_visible : 1;
172         
173         Gnome::Canvas::Group&  _parent_group;
174         Gnome::Canvas::Group*   group;
175         Gnome::Canvas::Line*   line; /* line */
176         Gnome::Canvas::Points  line_points; /* coordinates for canvas line */
177         vector<ControlPoint*>  control_points; /* visible control points */
178
179         sigc::slot<bool,GdkEvent*,ControlPoint*> point_slot;
180
181         struct ALPoint {
182             double x;
183             double y;
184             ALPoint (double xx, double yy) : x(xx), y(yy) {}
185         };
186
187         typedef std::vector<ALPoint> ALPoints;
188
189         static void invalidate_point (ALPoints&, uint32_t index);
190         static bool invalid_point (ALPoints&, uint32_t index);
191         
192         void determine_visible_control_points (ALPoints&);
193         void sync_model_from (ControlPoint&);
194         void sync_model_with_view_point (ControlPoint&);
195         void sync_model_with_view_line (uint32_t, uint32_t);
196         void modify_view (ControlPoint&, double, double, bool with_push);
197         
198         virtual void change_model (ARDOUR::AutomationList::iterator, double x, double y);
199         virtual void change_model_range (ARDOUR::AutomationList::iterator,ARDOUR::AutomationList::iterator, double delta, float ydelta);
200
201         void reset_callback (const ARDOUR::AutomationList&);
202         void list_changed (ARDOUR::Change);
203
204         UndoAction get_memento();
205         
206   private:
207         uint32_t drags;
208         double   first_drag_fraction;
209         double   last_drag_fraction;
210         uint32_t line_drag_cp1;
211         uint32_t line_drag_cp2;
212
213         void modify_view_point(ControlPoint&, double, double, bool with_push);
214         void reset_line_coords (ControlPoint&);
215         void update_line ();
216
217         struct ModelRepresentation {
218             ARDOUR::AutomationList::iterator start;
219             ARDOUR::AutomationList::iterator end;
220             jack_nframes_t xpos;
221             double ypos;
222             jack_nframes_t xmin;
223             double ymin;
224             jack_nframes_t xmax;
225             double ymax;
226             jack_nframes_t xval;
227             double yval;
228         };
229
230         void model_representation (ControlPoint&, ModelRepresentation&);
231
232         friend class AudioRegionGainLine;
233 };
234
235 #endif /* __ardour_automation_line_h__ */
236