Merge branch 'master' into cairocanvas
[ardour.git] / gtk2_ardour / automation_time_axis.h
1 /*
2     Copyright (C) 2000-2007 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_gtk_automation_time_axis_h__
21 #define __ardour_gtk_automation_time_axis_h__
22
23 #include <list>
24 #include <string>
25 #include <utility>
26
27 #include <boost/shared_ptr.hpp>
28
29 #include "ardour/types.h"
30 #include "ardour/automatable.h"
31 #include "ardour/automation_list.h"
32
33 #include "canvas/rectangle.h"
34
35 #include "time_axis_view.h"
36 #include "automation_controller.h"
37
38 namespace ARDOUR {
39         class Session;
40         class Route;
41         class AutomationControl;
42 }
43
44 class PublicEditor;
45 class TimeSelection;
46 class RegionSelection;
47 class PointSelection;
48 class AutomationLine;
49 class Selection;
50 class Selectable;
51 class AutomationStreamView;
52 class AutomationController;
53
54
55 class AutomationTimeAxisView : public TimeAxisView {
56   public:
57         AutomationTimeAxisView (ARDOUR::Session*,
58                                 boost::shared_ptr<ARDOUR::Route>,
59                                 boost::shared_ptr<ARDOUR::Automatable>,
60                                 boost::shared_ptr<ARDOUR::AutomationControl>,
61                                 Evoral::Parameter,
62                                 PublicEditor&,
63                                 TimeAxisView& parent,
64                                 bool show_regions,
65                                 ArdourCanvas::Canvas& canvas,
66                                 const std::string & name, /* translatable */
67                                 const std::string & plug_name = "");
68
69         ~AutomationTimeAxisView();
70
71         virtual void set_height (uint32_t);
72         void set_samples_per_pixel (double);
73         std::string name() const { return _name; }
74
75         void add_automation_event (GdkEvent *, framepos_t, double);
76
77         void clear_lines ();
78
79         /** @return Our AutomationLine, if this view has one, or 0 if it uses AutomationRegionViews */
80         boost::shared_ptr<AutomationLine> line() { return _line; }
81
82         /** @return All AutomationLines associated with this view */
83         std::list<boost::shared_ptr<AutomationLine> > lines () const;
84
85         void set_selected_points (PointSelection&);
86         void get_selectables (ARDOUR::framepos_t start, ARDOUR::framepos_t end, double top, double bot, std::list<Selectable *>&);
87         void get_inverted_selectables (Selection&, std::list<Selectable*>& results);
88
89         void show_timestretch (framepos_t /*start*/, framepos_t /*end*/, int /*layers*/, int /*layer*/) {}
90         void hide_timestretch () {}
91
92         /* editing operations */
93
94         void cut_copy_clear (Selection&, Editing::CutCopyOp);
95         bool paste (ARDOUR::framepos_t, float times, Selection&, size_t nth);
96
97         int  set_state (const XMLNode&, int version);
98
99         std::string state_id() const;
100         static bool parse_state_id (std::string const &, PBD::ID &, bool &, Evoral::Parameter &);
101
102         boost::shared_ptr<ARDOUR::AutomationControl> control()    { return _control; }
103         boost::shared_ptr<AutomationController>      controller() { return _controller; }
104         Evoral::Parameter parameter () const {
105                 return _parameter;
106         }
107
108         ArdourCanvas::Item* base_item () const {
109                 return _base_rect;
110         }
111
112         bool has_automation () const;
113
114         boost::shared_ptr<ARDOUR::Route> parent_route () {
115                 return _route;
116         }
117
118         bool show_regions () const {
119                 return _show_regions;
120         }
121
122         static void what_has_visible_automation (const boost::shared_ptr<ARDOUR::Automatable>& automatable, std::set<Evoral::Parameter>& visible);
123
124   protected:
125         /** parent route */
126         boost::shared_ptr<ARDOUR::Route> _route;
127         /** control; 0 if we are editing region-based automation */
128         boost::shared_ptr<ARDOUR::AutomationControl> _control;
129         /** control owner; may be _route, or 0 if we are editing region-based automation */
130         boost::shared_ptr<ARDOUR::Automatable> _automatable;
131         /** controller owner; 0 if we are editing region-based automation */
132         boost::shared_ptr<AutomationController> _controller;
133         Evoral::Parameter _parameter;
134
135         ArdourCanvas::Rectangle* _base_rect;
136         boost::shared_ptr<AutomationLine> _line;
137
138         /** AutomationStreamView if we are editing region-based automation (for MIDI), otherwise 0 */
139         AutomationStreamView* _view;
140
141         std::string _name;
142         bool    ignore_toggle;
143
144         bool    first_call_to_set_height;
145
146         Gtk::Button        hide_button;
147         Gtk::Button        auto_button;
148         Gtk::Menu*         automation_menu;
149         Gtk::Label*        plugname;
150         bool               plugname_packed;
151
152         Gtk::CheckMenuItem*     auto_off_item;
153         Gtk::CheckMenuItem*     auto_play_item;
154         Gtk::CheckMenuItem*     auto_touch_item;
155         Gtk::CheckMenuItem*     auto_write_item;
156
157         Gtk::CheckMenuItem* mode_discrete_item;
158         Gtk::CheckMenuItem* mode_line_item;
159
160         bool _show_regions;
161
162         void add_line (boost::shared_ptr<AutomationLine>);
163
164         void clear_clicked ();
165         void hide_clicked ();
166         void auto_clicked ();
167
168         void build_display_menu ();
169
170         void cut_copy_clear_one (AutomationLine&, Selection&, Editing::CutCopyOp);
171         bool paste_one (AutomationLine&, ARDOUR::framepos_t, float times, Selection&, size_t nth);
172         void route_going_away ();
173
174         void set_automation_state (ARDOUR::AutoState);
175         bool ignore_state_request;
176
177         void automation_state_changed ();
178
179         void set_interpolation (ARDOUR::AutomationList::InterpolationStyle);
180         void interpolation_changed (ARDOUR::AutomationList::InterpolationStyle);
181
182         PBD::ScopedConnectionList _list_connections;
183         PBD::ScopedConnectionList _route_connections;
184
185         void entered ();
186         void exited ();
187
188         //void set_colors ();
189         void color_handler ();
190
191         static Pango::FontDescription name_font;
192         static bool have_name_font;
193
194 private:
195         int set_state_2X (const XMLNode &, int);
196 };
197
198 #endif /* __ardour_gtk_automation_time_axis_h__ */