Part 1 of loading 2.X sessions; some things work, some things don't, hacks a-plenty.
[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 "evoral/TimeConverter.hpp"
34
35 #include "pbd/undo.h"
36 #include "pbd/statefuldestructible.h"
37
38 #include "ardour/automation_list.h"
39 #include "ardour/types.h"
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 AutomationLine : public sigc::trackable, public PBD::StatefulThingWithGoingAway
56 {
57   public:
58         AutomationLine (const std::string& name, TimeAxisView&, ArdourCanvas::Group&,
59                         boost::shared_ptr<ARDOUR::AutomationList>,
60                         const Evoral::TimeConverter<double, ARDOUR::sframes_t>* converter = 0);
61         virtual ~AutomationLine ();
62
63         void queue_reset ();
64         void reset ();
65         void clear();
66
67         void set_selected_points (PointSelection&);
68         void get_selectables (nframes_t& start, nframes_t& end,
69                               double botfrac, double topfrac,
70                               std::list<Selectable*>& results);
71         void get_inverted_selectables (Selection&, std::list<Selectable*>& results);
72
73         virtual void remove_point (ControlPoint&);
74         bool control_points_adjacent (double xval, uint32_t& before, uint32_t& after);
75
76         /* dragging API */
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         std::string  name()    const { return _name; }
86         bool    visible() const { return _visible; }
87         guint32 height()  const { return _height; }
88
89         void     set_line_color (uint32_t);
90         uint32_t get_line_color() const { return _line_color; }
91
92         void set_interpolation(ARDOUR::AutomationList::InterpolationStyle style);
93
94         void    show ();
95         void    hide ();
96         void    set_height (guint32);
97         void    set_uses_gain_mapping (bool yn);
98         bool    get_uses_gain_mapping () const { return _uses_gain_mapping; }
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         std::string get_verbose_cursor_string (double) const;
110         std::string fraction_to_string (double) const;
111         double string_to_fraction (std::string const &) const;
112         void   view_to_model_coord (double& x, double& y) const;
113         void   model_to_view_coord (double& x, double& y) const;
114
115         void set_list(boost::shared_ptr<ARDOUR::AutomationList> list);
116         boost::shared_ptr<ARDOUR::AutomationList> the_list() const { return alist; }
117
118         void show_all_control_points ();
119         void hide_all_but_selected_control_points ();
120
121         void track_entered();
122         void track_exited();
123
124         bool is_last_point (ControlPoint &);
125         bool is_first_point (ControlPoint &);
126
127         XMLNode& get_state (void);
128         int set_state (const XMLNode&, int version = 3000);
129         void set_colors();
130
131         void modify_point_y (ControlPoint&, double);
132
133   protected:
134
135         std::string    _name;
136         guint32   _height;
137         uint32_t  _line_color;
138
139         boost::shared_ptr<ARDOUR::AutomationList> alist;
140
141         bool    _visible                  : 1;
142         bool    _uses_gain_mapping        : 1;
143         bool    terminal_points_can_slide : 1;
144         bool    update_pending            : 1;
145         bool    no_draw                   : 1;
146         bool    points_visible            : 1;
147         bool    did_push;
148
149         ArdourCanvas::Group&        _parent_group;
150         ArdourCanvas::Group*        group;
151         ArdourCanvas::Line*         line; /* line */
152         ArdourCanvas::Points        line_points; /* coordinates for canvas line */
153         std::vector<ControlPoint*>  control_points; /* visible control points */
154
155         struct ALPoint {
156             double x;
157             double y;
158             ALPoint (double xx, double yy) : x(xx), y(yy) {}
159         };
160
161         typedef std::vector<ALPoint> ALPoints;
162
163         static void invalidate_point (ALPoints&, uint32_t index);
164         static bool invalid_point (ALPoints&, uint32_t index);
165
166         void determine_visible_control_points (ALPoints&);
167         void sync_model_with_view_point (ControlPoint&, bool did_push, int64_t distance);
168         void sync_model_with_view_line (uint32_t, uint32_t);
169
170         virtual void change_model (ARDOUR::AutomationList::iterator, double x, double y);
171
172         void reset_callback (const Evoral::ControlList&);
173         void list_changed ();
174
175         virtual bool event_handler (GdkEvent*);
176         virtual void add_model_point (ALPoints& tmp_points, double frame, double yfract);
177
178   private:
179         uint32_t drags;
180         double   first_drag_fraction;
181         double   last_drag_fraction;
182         uint32_t line_drag_cp1;
183         uint32_t line_drag_cp2;
184         int64_t  drag_x;
185         int64_t  drag_distance;
186
187         const Evoral::TimeConverter<double, ARDOUR::sframes_t>& _time_converter;
188         ARDOUR::AutomationList::InterpolationStyle              _interpolation;
189
190         void modify_view_point (ControlPoint&, double, double, bool with_push);
191         void reset_line_coords (ControlPoint&);
192
193         double control_point_box_size ();
194
195         struct ModelRepresentation {
196             ARDOUR::AutomationList::iterator start;
197             ARDOUR::AutomationList::iterator end;
198             double xpos;
199             double ypos;
200             double xmin;
201             double ymin;
202             double xmax;
203             double ymax;
204             double xval;
205             double yval;
206         };
207
208         void model_representation (ControlPoint&, ModelRepresentation&);
209
210         friend class AudioRegionGainLine;
211 };
212
213 #endif /* __ardour_automation_line_h__ */
214