Changing active-state needs no color lookup
[ardour.git] / gtk2_ardour / automation_time_axis.h
1 /*
2  * Copyright (C) 2005-2017 Paul Davis <paul@linuxaudiosystems.com>
3  * Copyright (C) 2005 Karsten Wiese <fzuuzf@googlemail.com>
4  * Copyright (C) 2005 Taybin Rutkin <taybin@taybin.com>
5  * Copyright (C) 2006-2014 David Robillard <d@drobilla.net>
6  * Copyright (C) 2006 Sampo Savolainen <v2@iki.fi>
7  * Copyright (C) 2009-2012 Carl Hetherington <carl@carlh.net>
8  * Copyright (C) 2014-2015 Ben Loftis <ben@harrisonconsoles.com>
9  * Copyright (C) 2015-2017 Robin Gareus <robin@gareus.org>
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 2 of the License, or
14  * (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License along
22  * with this program; if not, write to the Free Software Foundation, Inc.,
23  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24  */
25
26 #ifndef __ardour_gtk_automation_time_axis_h__
27 #define __ardour_gtk_automation_time_axis_h__
28
29 #include <list>
30 #include <string>
31 #include <utility>
32
33 #include <boost/shared_ptr.hpp>
34
35 #include "ardour/types.h"
36 #include "ardour/automatable.h"
37 #include "ardour/automation_list.h"
38
39 #include "canvas/rectangle.h"
40
41 #include "widgets/ardour_button.h"
42 #include "widgets/ardour_dropdown.h"
43
44 #include "time_axis_view.h"
45 #include "automation_controller.h"
46
47 namespace ARDOUR {
48         class Session;
49         class Stripable;
50         class AutomationControl;
51 }
52
53 class PublicEditor;
54 class TimeSelection;
55 class RegionSelection;
56 class PointSelection;
57 class AutomationLine;
58 class Selection;
59 class Selectable;
60 class AutomationStreamView;
61 class AutomationController;
62 class ItemCounts;
63
64 class AutomationTimeAxisView : public TimeAxisView
65 {
66 public:
67         AutomationTimeAxisView (ARDOUR::Session*,
68                                 boost::shared_ptr<ARDOUR::Stripable>,
69                                 boost::shared_ptr<ARDOUR::Automatable>,
70                                 boost::shared_ptr<ARDOUR::AutomationControl>,
71                                 Evoral::Parameter,
72                                 PublicEditor&,
73                                 TimeAxisView& parent,
74                                 bool show_regions,
75                                 ArdourCanvas::Canvas& canvas,
76                                 const std::string & name, /* translatable */
77                                 const std::string & plug_name = "");
78
79         ~AutomationTimeAxisView();
80
81         virtual void set_height (uint32_t, TrackHeightMode m = OnlySelf);
82         void set_samples_per_pixel (double);
83         std::string name() const { return _name; }
84         Gdk::Color color () const;
85
86         boost::shared_ptr<ARDOUR::Stripable> stripable() const;
87         ARDOUR::PresentationInfo const & presentation_info () const;
88
89         void add_automation_event (GdkEvent *, samplepos_t, double, bool with_guard_points);
90
91         void clear_lines ();
92
93         /** @return Our AutomationLine, if this view has one, or 0 if it uses AutomationRegionViews */
94         boost::shared_ptr<AutomationLine> line() { return _line; }
95
96         /** @return All AutomationLines associated with this view */
97         std::list<boost::shared_ptr<AutomationLine> > lines () const;
98
99         void set_selected_points (PointSelection&);
100         void get_selectables (ARDOUR::samplepos_t start, ARDOUR::samplepos_t end, double top, double bot, std::list<Selectable *>&, bool within = false);
101         void get_inverted_selectables (Selection&, std::list<Selectable*>& results);
102
103         void show_timestretch (samplepos_t /*start*/, samplepos_t /*end*/, int /*layers*/, int /*layer*/) {}
104         void hide_timestretch () {}
105
106         /* editing operations */
107
108         void cut_copy_clear (Selection&, Editing::CutCopyOp);
109         bool paste (ARDOUR::samplepos_t, const Selection&, PasteContext&, const int32_t sub_num);
110
111         int  set_state (const XMLNode&, int version);
112
113         std::string state_id() const;
114         static bool parse_state_id (std::string const &, PBD::ID &, bool &, Evoral::Parameter &);
115
116         boost::shared_ptr<ARDOUR::AutomationControl> control() const   { return _control; }
117         boost::shared_ptr<AutomationController>      controller() const { return _controller; }
118         Evoral::Parameter parameter () const {
119                 return _parameter;
120         }
121
122         ArdourCanvas::Item* base_item () const {
123                 return _base_rect;
124         }
125
126         bool has_automation () const;
127
128         boost::shared_ptr<ARDOUR::Stripable> parent_stripable () {
129                 return _stripable;
130         }
131
132         bool show_regions () const {
133                 return _show_regions;
134         }
135
136         static void what_has_visible_automation (const boost::shared_ptr<ARDOUR::Automatable>& automatable, std::set<Evoral::Parameter>& visible);
137
138 protected:
139         /* Note that for MIDI controller "automation" (in regions), all of these
140          * may be set.  In this case, _automatable is likely _route so the
141          * controller will send immediate events out the route's MIDI port. */
142
143         /** parent strip */
144         boost::shared_ptr<ARDOUR::Stripable> _stripable;
145         /** control */
146         boost::shared_ptr<ARDOUR::AutomationControl> _control;
147         /** control owner; may be _stripable, something else (e.g. a pan control), or NULL */
148         boost::shared_ptr<ARDOUR::Automatable> _automatable;
149         /** controller owner */
150         boost::shared_ptr<AutomationController> _controller;
151         Evoral::Parameter _parameter;
152
153         ArdourCanvas::Rectangle* _base_rect;
154         boost::shared_ptr<AutomationLine> _line;
155
156         std::string _name;
157
158         /** AutomationStreamView if we are editing region-based automation (for MIDI), otherwise 0 */
159         AutomationStreamView* _view;
160
161         bool    ignore_toggle;
162         bool    first_call_to_set_height;
163
164         ArdourWidgets::ArdourButton   hide_button;
165         ArdourWidgets::ArdourDropdown auto_dropdown;
166         Gtk::Label*        plugname;
167         bool               plugname_packed;
168
169         Gtk::CheckMenuItem*     auto_off_item;
170         Gtk::CheckMenuItem*     auto_play_item;
171         Gtk::CheckMenuItem*     auto_touch_item;
172         Gtk::CheckMenuItem*     auto_write_item;
173         Gtk::CheckMenuItem*     auto_latch_item;
174
175         Gtk::CheckMenuItem* mode_discrete_item;
176         Gtk::CheckMenuItem* mode_line_item;
177         Gtk::CheckMenuItem* mode_log_item;
178         Gtk::CheckMenuItem* mode_exp_item;
179
180         bool _show_regions;
181
182         void add_line (boost::shared_ptr<AutomationLine>);
183
184         void clear_clicked ();
185         void hide_clicked ();
186
187         virtual bool can_edit_name() const {return false;}
188
189         void build_display_menu ();
190
191         void cut_copy_clear_one (AutomationLine&, Selection&, Editing::CutCopyOp);
192         bool paste_one (ARDOUR::samplepos_t, unsigned, float times, const Selection&, ItemCounts& counts, bool greedy=false);
193         void route_going_away ();
194
195         void set_automation_state (ARDOUR::AutoState);
196         bool ignore_state_request;
197         bool ignore_mode_request;
198
199         bool propagate_time_selection () const;
200
201         void automation_state_changed ();
202
203         void set_interpolation (ARDOUR::AutomationList::InterpolationStyle);
204         void interpolation_changed (ARDOUR::AutomationList::InterpolationStyle);
205
206         PBD::ScopedConnectionList _list_connections;
207         PBD::ScopedConnectionList _stripable_connections;
208
209         void entered ();
210         void exited ();
211
212         //void set_colors ();
213         void color_handler ();
214
215         static Pango::FontDescription name_font;
216         static bool have_name_font;
217
218         std::string automation_state_off_string () const;
219
220 private:
221         int set_state_2X (const XMLNode &, int);
222 };
223
224 #endif /* __ardour_gtk_automation_time_axis_h__ */