Use Session::session_directory to access the sound path of the session in Editor...
[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 ControlPoint 
57 {
58   public:
59         ControlPoint (AutomationLine& al);
60         ControlPoint (const ControlPoint&, bool dummy_arg_to_force_special_copy_constructor);
61         virtual ~ControlPoint ();
62
63         enum ShapeType {
64                 Full,
65                 Start,
66                 End
67         };
68         
69         void move_to (double x, double y, ShapeType);
70         void reset (double x, double y, ARDOUR::AutomationList::iterator, uint32_t, ShapeType);
71         double get_x() const { return _x; }
72         double get_y() const { return _y; }
73
74         void hide (); 
75         void show ();
76         void show_color (bool entered, bool hide_too);
77
78         void set_size (double);
79         void set_visible (bool);
80
81         ArdourCanvas::SimpleRect* item;
82         AutomationLine& line;
83         uint32_t view_index;
84         ARDOUR::AutomationList::iterator model;
85         bool can_slide;
86         bool selected;
87         
88   protected:
89         virtual bool event_handler (GdkEvent*);
90
91   private:
92         double _x;
93         double _y;
94         double _size;
95         ShapeType _shape;
96 };
97
98 class AutomationLine : public sigc::trackable, public PBD::StatefulThingWithGoingAway
99 {
100   public:
101         AutomationLine (const string & name, TimeAxisView&, ArdourCanvas::Group&, ARDOUR::AutomationList&);
102         virtual ~AutomationLine ();
103
104         void queue_reset ();
105         void reset ();
106         void clear();
107
108         void set_selected_points (PointSelection&);
109         void get_selectables (nframes_t& start, nframes_t& end,
110                               double botfrac, double topfrac, 
111                               list<Selectable*>& results);
112         void get_inverted_selectables (Selection&, list<Selectable*>& results);
113
114         virtual void remove_point (ControlPoint&);
115         bool control_points_adjacent (double xval, uint32_t& before, uint32_t& after);
116         
117         /* dragging API */
118
119         virtual void start_drag (ControlPoint*, nframes_t x, float fraction);
120         virtual void point_drag(ControlPoint&, nframes_t x, float, bool with_push);
121         virtual void end_drag (ControlPoint*);
122         virtual void line_drag(uint32_t i1, uint32_t i2, float, bool with_push);
123
124         ControlPoint* nth (uint32_t);
125         uint32_t npoints() const { return control_points.size(); }
126
127         string  name() const { return _name; }
128         bool    visible() const { return _visible; }
129         guint32 height() const { return _height; }
130         guint32 y_position() const { return _y_position; }
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_y_position_and_height (uint32_t, uint32_t);
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         virtual string  get_verbose_cursor_string (float);
150         virtual void view_to_model_y (double&) = 0;
151         virtual void model_to_view_y (double&) = 0;
152
153         ARDOUR::AutomationList& the_list() const { return alist; }
154
155         void show_all_control_points ();
156         void hide_all_but_selected_control_points ();
157
158         bool is_last_point (ControlPoint &);
159         bool is_first_point (ControlPoint &);
160
161         XMLNode& get_state (void);
162         int set_state (const XMLNode&);
163         void set_colors();
164
165   protected:
166
167         string _name;
168         guint32 _y_position;
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         bool    did_push;
180
181         ArdourCanvas::Group&  _parent_group;
182         ArdourCanvas::Group*   group;
183         ArdourCanvas::Line*   line; /* line */
184         ArdourCanvas::Points  line_points; /* coordinates for canvas line */
185         vector<ControlPoint*>  control_points; /* visible control points */
186
187         struct ALPoint {
188             double x;
189             double y;
190             ALPoint (double xx, double yy) : x(xx), y(yy) {}
191         };
192
193         typedef std::vector<ALPoint> ALPoints;
194
195         static void invalidate_point (ALPoints&, uint32_t index);
196         static bool invalid_point (ALPoints&, uint32_t index);
197         
198         void determine_visible_control_points (ALPoints&);
199         void sync_model_with_view_point (ControlPoint&, bool did_push, int64_t distance);
200         void sync_model_with_view_line (uint32_t, uint32_t);
201         
202         virtual void change_model (ARDOUR::AutomationList::iterator, double x, double y);
203         virtual void change_model_range (ARDOUR::AutomationList::iterator,ARDOUR::AutomationList::iterator, double delta, float ydelta);
204
205         void reset_callback (const ARDOUR::AutomationList&);
206         void list_changed ();
207
208         virtual bool event_handler (GdkEvent*);
209         
210   private:
211         uint32_t drags;
212         double   first_drag_fraction;
213         double   last_drag_fraction;
214         uint32_t line_drag_cp1;
215         uint32_t line_drag_cp2;
216         int64_t  drag_x;
217         int64_t  drag_distance;
218
219         void modify_view_point(ControlPoint&, double, double, bool with_push);
220         void reset_line_coords (ControlPoint&);
221
222         double control_point_box_size ();
223
224         struct ModelRepresentation {
225             ARDOUR::AutomationList::iterator start;
226             ARDOUR::AutomationList::iterator end;
227             nframes_t xpos;
228             double ypos;
229             nframes_t xmin;
230             double ymin;
231             nframes_t xmax;
232             double ymax;
233             nframes_t xval;
234             double yval;
235         };
236
237         void model_representation (ControlPoint&, ModelRepresentation&);
238
239         friend class AudioRegionGainLine;
240 };
241
242 #endif /* __ardour_automation_line_h__ */
243