Make Dropdown menus at least as wide as the button
[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 #include "ardour_button.h"
38
39 namespace ARDOUR {
40         class Session;
41         class Route;
42         class AutomationControl;
43 }
44
45 class PublicEditor;
46 class TimeSelection;
47 class RegionSelection;
48 class PointSelection;
49 class AutomationLine;
50 class Selection;
51 class Selectable;
52 class AutomationStreamView;
53 class AutomationController;
54 class ItemCounts;
55
56 class AutomationTimeAxisView : public TimeAxisView {
57   public:
58         AutomationTimeAxisView (ARDOUR::Session*,
59                                 boost::shared_ptr<ARDOUR::Route>,
60                                 boost::shared_ptr<ARDOUR::Automatable>,
61                                 boost::shared_ptr<ARDOUR::AutomationControl>,
62                                 Evoral::Parameter,
63                                 PublicEditor&,
64                                 TimeAxisView& parent,
65                                 bool show_regions,
66                                 ArdourCanvas::Canvas& canvas,
67                                 const std::string & name, /* translatable */
68                                 const std::string & plug_name = "");
69
70         ~AutomationTimeAxisView();
71
72         virtual void set_height (uint32_t, TrackHeightMode m = OnlySelf);
73         void set_samples_per_pixel (double);
74         std::string name() const { return _name; }
75         Gdk::Color color () const;
76
77         boost::shared_ptr<ARDOUR::Stripable> stripable() const;
78         ARDOUR::PresentationInfo const & presentation_info () const;
79
80         void add_automation_event (GdkEvent *, framepos_t, double, bool with_guard_points);
81
82         void clear_lines ();
83
84         /** @return Our AutomationLine, if this view has one, or 0 if it uses AutomationRegionViews */
85         boost::shared_ptr<AutomationLine> line() { return _line; }
86
87         /** @return All AutomationLines associated with this view */
88         std::list<boost::shared_ptr<AutomationLine> > lines () const;
89
90         void set_selected_points (PointSelection&);
91         void get_selectables (ARDOUR::framepos_t start, ARDOUR::framepos_t end, double top, double bot, std::list<Selectable *>&, bool within = false);
92         void get_inverted_selectables (Selection&, std::list<Selectable*>& results);
93
94         void show_timestretch (framepos_t /*start*/, framepos_t /*end*/, int /*layers*/, int /*layer*/) {}
95         void hide_timestretch () {}
96
97         /* editing operations */
98
99         void cut_copy_clear (Selection&, Editing::CutCopyOp);
100         bool paste (ARDOUR::framepos_t, const Selection&, PasteContext&, const int32_t sub_num);
101
102         int  set_state (const XMLNode&, int version);
103
104         std::string state_id() const;
105         static bool parse_state_id (std::string const &, PBD::ID &, bool &, Evoral::Parameter &);
106
107         boost::shared_ptr<ARDOUR::AutomationControl> control()    { return _control; }
108         boost::shared_ptr<AutomationController>      controller() { return _controller; }
109         Evoral::Parameter parameter () const {
110                 return _parameter;
111         }
112
113         ArdourCanvas::Item* base_item () const {
114                 return _base_rect;
115         }
116
117         bool has_automation () const;
118
119         boost::shared_ptr<ARDOUR::Route> parent_route () {
120                 return _route;
121         }
122
123         bool show_regions () const {
124                 return _show_regions;
125         }
126
127         static void what_has_visible_automation (const boost::shared_ptr<ARDOUR::Automatable>& automatable, std::set<Evoral::Parameter>& visible);
128
129   protected:
130         /* Note that for MIDI controller "automation" (in regions), all of these
131            may be set.  In this case, _automatable is likely _route so the
132            controller will send immediate events out the route's MIDI port. */
133
134         /** parent route */
135         boost::shared_ptr<ARDOUR::Route> _route;
136         /** control */
137         boost::shared_ptr<ARDOUR::AutomationControl> _control;
138         /** control owner; may be _route, something else (e.g. a pan control), or NULL */
139         boost::shared_ptr<ARDOUR::Automatable> _automatable;
140         /** controller owner */
141         boost::shared_ptr<AutomationController> _controller;
142         Evoral::Parameter _parameter;
143
144         ArdourCanvas::Rectangle* _base_rect;
145         boost::shared_ptr<AutomationLine> _line;
146
147         std::string _name;
148
149         /** AutomationStreamView if we are editing region-based automation (for MIDI), otherwise 0 */
150         AutomationStreamView* _view;
151
152         bool    ignore_toggle;
153         bool    first_call_to_set_height;
154
155         ArdourButton       hide_button;
156         ArdourButton       auto_button;
157         Gtk::Menu*         automation_menu;
158         Gtk::Label*        plugname;
159         bool               plugname_packed;
160
161         Gtk::CheckMenuItem*     auto_off_item;
162         Gtk::CheckMenuItem*     auto_play_item;
163         Gtk::CheckMenuItem*     auto_touch_item;
164         Gtk::CheckMenuItem*     auto_write_item;
165
166         Gtk::CheckMenuItem* mode_discrete_item;
167         Gtk::CheckMenuItem* mode_line_item;
168
169         bool _show_regions;
170
171         void add_line (boost::shared_ptr<AutomationLine>);
172
173         void clear_clicked ();
174         void hide_clicked ();
175         void auto_clicked ();
176
177         virtual bool can_edit_name() const {return false;}
178
179         void build_display_menu ();
180
181         void cut_copy_clear_one (AutomationLine&, Selection&, Editing::CutCopyOp);
182         bool paste_one (ARDOUR::framepos_t, unsigned, float times, const Selection&, ItemCounts& counts, bool greedy=false);
183         void route_going_away ();
184
185         void set_automation_state (ARDOUR::AutoState);
186         bool ignore_state_request;
187
188         void automation_state_changed ();
189
190         void set_interpolation (ARDOUR::AutomationList::InterpolationStyle);
191         void interpolation_changed (ARDOUR::AutomationList::InterpolationStyle);
192
193         PBD::ScopedConnectionList _list_connections;
194         PBD::ScopedConnectionList _route_connections;
195
196         void entered ();
197         void exited ();
198
199         //void set_colors ();
200         void color_handler ();
201
202         static Pango::FontDescription name_font;
203         static bool have_name_font;
204
205 private:
206         int set_state_2X (const XMLNode &, int);
207 };
208
209 #endif /* __ardour_gtk_automation_time_axis_h__ */