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