Note modes: note, percussion.
[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_event.h>
37
38
39 using std::vector;
40 using std::string;
41
42 class AutomationLine;
43 class ControlPoint;
44 class PointSelection;
45 class TimeAxisView;
46 class AutomationTimeAxisView;
47 class Selectable;
48 class Selection;
49
50 namespace Gnome {
51         namespace Canvas {
52                 class SimpleRect;
53         }
54 }
55
56 class AutomationLine : public sigc::trackable, public PBD::StatefulThingWithGoingAway
57 {
58   public:
59         AutomationLine (const string & name, TimeAxisView&, ArdourCanvas::Group&, boost::shared_ptr<ARDOUR::AutomationList>);
60         virtual ~AutomationLine ();
61
62         void queue_reset ();
63         void reset ();
64         void clear();
65
66         void set_selected_points (PointSelection&);
67         void get_selectables (nframes_t& start, nframes_t& end,
68                               double botfrac, double topfrac, 
69                               list<Selectable*>& results);
70         void get_inverted_selectables (Selection&, list<Selectable*>& results);
71
72         virtual void remove_point (ControlPoint&);
73         bool control_points_adjacent (double xval, uint32_t& before, uint32_t& after);
74         
75         /* dragging API */
76
77         virtual void start_drag (ControlPoint*, nframes_t x, float fraction);
78         virtual void point_drag(ControlPoint&, nframes_t x, float, bool with_push);
79         virtual void end_drag (ControlPoint*);
80         virtual void line_drag(uint32_t i1, uint32_t i2, float, bool with_push);
81
82         ControlPoint* nth (uint32_t);
83         uint32_t npoints() const { return control_points.size(); }
84
85         string  name() const { return _name; }
86         bool    visible() const { return _visible; }
87         guint32 height() const { return _height; }
88         guint32 y_position() const { return _y_position; }
89
90         void     set_line_color (uint32_t);
91         uint32_t get_line_color() const { return _line_color; }
92
93         void set_interpolation(ARDOUR::AutomationList::InterpolationStyle style);
94
95         void    show ();
96         void    hide ();
97         void    set_y_position_and_height (uint32_t, uint32_t);
98         void    set_verbose_cursor_uses_gain_mapping (bool yn);
99
100         TimeAxisView& trackview;
101
102         ArdourCanvas::Group& canvas_group() const { return *group; }
103         ArdourCanvas::Item&  parent_group() const { return _parent_group; }
104         ArdourCanvas::Item&  grab_item() const { return *line; }
105
106         void show_selection();
107         void hide_selection ();
108
109         virtual string get_verbose_cursor_string (double);
110         virtual void view_to_model_y (double&);
111         virtual void model_to_view_y (double&);
112
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   protected:
129
130         string _name;
131         guint32 _y_position;
132         guint32 _height;
133         uint32_t _line_color;
134         boost::shared_ptr<ARDOUR::AutomationList> alist;
135
136         bool    _visible  : 1;
137         bool    _vc_uses_gain_mapping : 1;
138         bool    terminal_points_can_slide : 1;
139         bool    update_pending : 1;
140         bool    no_draw : 1;
141         bool    points_visible : 1;
142         bool    did_push;
143
144         ArdourCanvas::Group&  _parent_group;
145         ArdourCanvas::Group*   group;
146         ArdourCanvas::Line*   line; /* line */
147         ArdourCanvas::Points  line_points; /* coordinates for canvas line */
148         vector<ControlPoint*>  control_points; /* visible control points */
149
150         struct ALPoint {
151             double x;
152             double y;
153             ALPoint (double xx, double yy) : x(xx), y(yy) {}
154         };
155
156         typedef std::vector<ALPoint> ALPoints;
157
158         static void invalidate_point (ALPoints&, uint32_t index);
159         static bool invalid_point (ALPoints&, uint32_t index);
160         
161         void determine_visible_control_points (ALPoints&);
162         void sync_model_with_view_point (ControlPoint&, bool did_push, int64_t distance);
163         void sync_model_with_view_line (uint32_t, uint32_t);
164         
165         virtual void change_model (ARDOUR::AutomationList::iterator, double x, double y);
166         virtual void change_model_range (ARDOUR::AutomationList::iterator,ARDOUR::AutomationList::iterator, double delta, float ydelta);
167
168         void reset_callback (const ARDOUR::AutomationList&);
169         void list_changed ();
170
171         virtual bool event_handler (GdkEvent*);
172         
173   private:
174         uint32_t drags;
175         double   first_drag_fraction;
176         double   last_drag_fraction;
177         uint32_t line_drag_cp1;
178         uint32_t line_drag_cp2;
179         int64_t  drag_x;
180         int64_t  drag_distance;
181         
182         ARDOUR::AutomationList::InterpolationStyle _interpolation;
183
184         void modify_view_point(ControlPoint&, double, double, bool with_push);
185         void reset_line_coords (ControlPoint&);
186
187         double control_point_box_size ();
188
189         struct ModelRepresentation {
190             ARDOUR::AutomationList::iterator start;
191             ARDOUR::AutomationList::iterator end;
192             nframes_t xpos;
193             double ypos;
194             nframes_t xmin;
195             double ymin;
196             nframes_t xmax;
197             double ymax;
198             nframes_t xval;
199             double yval;
200         };
201
202         void model_representation (ControlPoint&, ModelRepresentation&);
203
204         friend class AudioRegionGainLine;
205 };
206
207 #endif /* __ardour_automation_line_h__ */
208