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