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