use new action map API instead of ActionManager::get_action
[ardour.git] / gtk2_ardour / stripable_time_axis.cc
1 /*
2  * Copyright (C) 2017 Robin Gareus <robin@gareus.org>
3  * Copyright (C) 2016 Paul Davis
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation; either version 2
8  * of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
18  */
19
20 #include <gtkmm/menu.h>
21 #include <gtkmm/menuitem.h>
22
23 #include "ardour/parameter_descriptor.h"
24 #include "ardour/parameter_types.h"
25 #include "ardour/stripable.h"
26
27 #include "public_editor.h"
28 #include "stripable_time_axis.h"
29
30 #include "pbd/i18n.h"
31
32 using namespace PBD;
33 using namespace ARDOUR;
34 using namespace Gtk;
35
36 StripableTimeAxisView::StripableTimeAxisView (PublicEditor& ed, ARDOUR::Session* s, ArdourCanvas::Canvas& canvas)
37         : TimeAxisView(s, ed, (TimeAxisView*) 0, canvas)
38         , gain_automation_item(NULL)
39         , trim_automation_item(NULL)
40         , mute_automation_item(NULL)
41         , parent_canvas (canvas)
42         , no_redraw (false)
43 {
44 }
45
46 StripableTimeAxisView::~StripableTimeAxisView ()
47 {
48 }
49
50 void
51 StripableTimeAxisView::set_stripable (boost::shared_ptr<ARDOUR::Stripable> s)
52 {
53         _stripable = s;
54         _editor.ZoomChanged.connect (sigc::mem_fun(*this, &StripableTimeAxisView::reset_samples_per_pixel));
55 }
56
57 void
58 StripableTimeAxisView::reset_samples_per_pixel ()
59 {
60         set_samples_per_pixel (_editor.get_current_zoom());
61 }
62
63 void
64 StripableTimeAxisView::set_samples_per_pixel (double fpp)
65 {
66         TimeAxisView::set_samples_per_pixel (fpp);
67 }
68
69
70 void
71 StripableTimeAxisView::add_automation_child (Evoral::Parameter param, boost::shared_ptr<AutomationTimeAxisView> track, bool show)
72 {
73         using namespace Menu_Helpers;
74
75         add_child (track);
76
77         track->Hiding.connect (sigc::bind (sigc::mem_fun (*this, &StripableTimeAxisView::automation_track_hidden), param));
78
79         _automation_tracks[param] = track;
80
81         /* existing state overrides "show" argument */
82         bool visible;
83         if (track->get_gui_property ("visible", visible)) {
84                 show = visible;
85         }
86
87         /* this might or might not change the visibility status, so don't rely on it */
88         track->set_marked_for_display (show);
89
90         if (show && !no_redraw) {
91                 request_redraw ();
92         }
93
94         if (!ARDOUR::parameter_is_midi((AutomationType)param.type())) {
95                 /* MIDI-related parameters are always in the menu, there's no
96                    reason to rebuild the menu just because we added a automation
97                    lane for one of them. But if we add a non-MIDI automation
98                    lane, then we need to invalidate the display menu.
99                 */
100                 delete display_menu;
101                 display_menu = 0;
102         }
103 }
104
105 void
106 StripableTimeAxisView::update_gain_track_visibility ()
107 {
108         bool const showit = gain_automation_item->get_active();
109
110         bool visible;
111         if (gain_track->get_gui_property ("visible", visible) && visible != showit) {
112                 gain_track->set_marked_for_display (showit);
113
114                 /* now trigger a redisplay */
115
116                 if (!no_redraw) {
117                          _stripable->gui_changed (X_("visible_tracks"), (void *) 0); /* EMIT_SIGNAL */
118                 }
119         }
120 }
121
122 void
123 StripableTimeAxisView::update_trim_track_visibility ()
124 {
125         bool const showit = trim_automation_item->get_active();
126
127         bool visible;
128         if (trim_track->get_gui_property ("visible", visible) && visible != showit) {
129                 trim_track->set_marked_for_display (showit);
130
131                 /* now trigger a redisplay */
132
133                 if (!no_redraw) {
134                          _stripable->gui_changed (X_("visible_tracks"), (void *) 0); /* EMIT_SIGNAL */
135                 }
136         }
137 }
138
139 void
140 StripableTimeAxisView::update_mute_track_visibility ()
141 {
142         bool const showit = mute_automation_item->get_active();
143
144         bool visible;
145         if (mute_track->get_gui_property ("visible", visible) && visible != showit) {
146                 mute_track->set_marked_for_display (showit);
147
148                 /* now trigger a redisplay */
149
150                 if (!no_redraw) {
151                          _stripable->gui_changed (X_("visible_tracks"), (void *) 0); /* EMIT_SIGNAL */
152                 }
153         }
154 }
155
156 Gtk::CheckMenuItem*
157 StripableTimeAxisView::automation_child_menu_item (Evoral::Parameter param)
158 {
159         ParameterMenuMap::iterator i = _main_automation_menu_map.find (param);
160         if (i != _main_automation_menu_map.end()) {
161                 return i->second;
162         }
163
164         return 0;
165 }
166
167 void
168 StripableTimeAxisView::automation_track_hidden (Evoral::Parameter param)
169 {
170         boost::shared_ptr<AutomationTimeAxisView> track = automation_child (param);
171
172         if (!track) {
173                 return;
174         }
175
176         Gtk::CheckMenuItem* menu = automation_child_menu_item (param);
177
178         if (menu && !_hidden && menu->get_active()) {
179                 menu->set_active (false);
180         }
181
182         if (_stripable && !no_redraw) {
183                 request_redraw ();
184         }
185 }
186
187 boost::shared_ptr<AutomationTimeAxisView>
188 StripableTimeAxisView::automation_child(Evoral::Parameter param)
189 {
190         AutomationTracks::iterator i = _automation_tracks.find(param);
191         if (i != _automation_tracks.end()) {
192                 return i->second;
193         } else {
194                 return boost::shared_ptr<AutomationTimeAxisView>();
195         }
196 }
197
198 void
199 StripableTimeAxisView::request_redraw ()
200 {
201         if (_stripable) {
202                 _stripable->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
203         }
204 }
205
206 void
207 StripableTimeAxisView::show_all_automation (bool apply_to_selection)
208 {
209         /* this protected member should not be called directly */
210         assert (!apply_to_selection);
211         assert (no_redraw);
212
213         for (AutomationTracks::iterator i = _automation_tracks.begin(); i != _automation_tracks.end(); ++i) {
214                 i->second->set_marked_for_display (true);
215
216                 Gtk::CheckMenuItem* menu = automation_child_menu_item (i->first);
217
218                 if (menu) {
219                         menu->set_active(true);
220                 }
221         }
222 }
223
224 void
225 StripableTimeAxisView::show_existing_automation (bool apply_to_selection)
226 {
227         /* this protected member should not be called directly */
228         assert (!apply_to_selection);
229         assert (no_redraw);
230
231         for (AutomationTracks::iterator i = _automation_tracks.begin(); i != _automation_tracks.end(); ++i) {
232                 if (i->second->has_automation()) {
233                         i->second->set_marked_for_display (true);
234
235                         Gtk::CheckMenuItem* menu = automation_child_menu_item (i->first);
236                         if (menu) {
237                                 menu->set_active(true);
238                         }
239                 }
240         }
241 }
242
243 void
244 StripableTimeAxisView::hide_all_automation (bool apply_to_selection)
245 {
246         /* this protected member should not be called directly */
247         assert (!apply_to_selection);
248         assert (no_redraw);
249
250         for (AutomationTracks::iterator i = _automation_tracks.begin(); i != _automation_tracks.end(); ++i) {
251                 i->second->set_marked_for_display (false);
252
253                 Gtk::CheckMenuItem* menu = automation_child_menu_item (i->first);
254
255                 if (menu) {
256                         menu->set_active (false);
257                 }
258         }
259 }