2567306a523f3afb64faa430ba3fb62986308459
[ardour.git] / gtk2_ardour / audio_time_axis.cc
1 /*
2     Copyright (C) 2000-2006 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 #include <cstdlib>
21 #include <cmath>
22 #include <cassert>
23
24 #include <algorithm>
25 #include <string>
26 #include <vector>
27
28 #include <sigc++/bind.h>
29
30 #include "pbd/error.h"
31 #include "pbd/stl_delete.h"
32 #include "pbd/memento_command.h"
33
34 #include "gtkmm2ext/gtk_ui.h"
35 #include "gtkmm2ext/selector.h"
36 #include "gtkmm2ext/bindable_button.h"
37 #include "gtkmm2ext/utils.h"
38
39 #include "widgets/ardour_button.h"
40
41 #include "ardour/event_type_map.h"
42 #include "ardour/pannable.h"
43 #include "ardour/panner.h"
44 #include "ardour/panner_shell.h"
45
46 #include "audio_time_axis.h"
47 #include "automation_line.h"
48 #include "enums.h"
49 #include "gui_thread.h"
50 #include "automation_time_axis.h"
51 #include "keyboard.h"
52 #include "playlist_selector.h"
53 #include "prompter.h"
54 #include "public_editor.h"
55 #include "audio_region_view.h"
56 #include "audio_streamview.h"
57 #include "utils.h"
58
59 #include "pbd/i18n.h"
60
61 using namespace std;
62 using namespace ARDOUR;
63 using namespace ArdourWidgets;
64 using namespace ARDOUR_UI_UTILS;
65 using namespace PBD;
66 using namespace Gtk;
67 using namespace Editing;
68
69 AudioTimeAxisView::AudioTimeAxisView (PublicEditor& ed, Session* sess, ArdourCanvas::Canvas& canvas)
70         : SessionHandlePtr (sess)
71         , RouteTimeAxisView(ed, sess, canvas)
72 {
73 }
74
75 void
76 AudioTimeAxisView::set_route (boost::shared_ptr<Route> rt)
77 {
78         _route = rt;
79
80         /* RouteTimeAxisView::set_route() sets up some things in the View,
81            so it must be created before RouteTimeAxis::set_route() is
82            called.
83         */
84         _view = new AudioStreamView (*this);
85
86         RouteTimeAxisView::set_route (rt);
87
88         _view->apply_color (gdk_color_to_rgba (color()), StreamView::RegionColor);
89
90         // Make sure things are sane...
91         assert(!is_track() || is_audio_track());
92
93         subplugin_menu.set_name ("ArdourContextMenu");
94
95         ignore_toggle = false;
96
97         if (is_audio_track()) {
98                 controls_ebox.set_name ("AudioTrackControlsBaseUnselected");
99                 time_axis_frame.set_name ("AudioTrackControlsBaseUnselected");
100         } else { // bus
101                 controls_ebox.set_name ("AudioBusControlsBaseUnselected");
102                 time_axis_frame.set_name ("AudioBusControlsBaseUnselected");
103         }
104
105         /* if set_state above didn't create a gain automation child, we need to make one */
106         if (automation_child (GainAutomation) == 0) {
107                 create_automation_child (GainAutomation, false);
108         }
109
110         if (automation_child (TrimAutomation) == 0) {
111                 create_automation_child (TrimAutomation, false);
112         }
113
114         /* if set_state above didn't create a mute automation child, we need to make one */
115         if (automation_child (MuteAutomation) == 0) {
116                 create_automation_child (MuteAutomation, false);
117         }
118
119         if (_route->panner_shell()) {
120                 _route->panner_shell()->Changed.connect (*this, invalidator (*this),
121                                                          boost::bind (&AudioTimeAxisView::ensure_pan_views, this, false), gui_context());
122         }
123
124         /* map current state of the route */
125
126         processors_changed (RouteProcessorChange ());
127         reset_processor_automation_curves ();
128         ensure_pan_views (false);
129         update_control_names ();
130
131         if (is_audio_track()) {
132
133                 /* ask for notifications of any new RegionViews */
134                 _view->RegionViewAdded.connect (sigc::mem_fun(*this, &AudioTimeAxisView::region_view_added));
135
136                 if (!_editor.have_idled()) {
137                         /* first idle will do what we need */
138                 } else {
139                         first_idle ();
140                 }
141
142         } else {
143                 post_construct ();
144         }
145 }
146
147 AudioTimeAxisView::~AudioTimeAxisView ()
148 {
149 }
150
151 void
152 AudioTimeAxisView::first_idle ()
153 {
154         _view->attach ();
155         post_construct ();
156 }
157
158 AudioStreamView*
159 AudioTimeAxisView::audio_view()
160 {
161         return dynamic_cast<AudioStreamView*>(_view);
162 }
163
164 guint32
165 AudioTimeAxisView::show_at (double y, int& nth, Gtk::VBox *parent)
166 {
167         set_gui_property ("visible", true);
168         return TimeAxisView::show_at (y, nth, parent);
169 }
170
171 void
172 AudioTimeAxisView::hide ()
173 {
174         set_gui_property ("visible", false);
175         TimeAxisView::hide ();
176 }
177
178 void
179 AudioTimeAxisView::create_automation_child (const Evoral::Parameter& param, bool show)
180 {
181         if (param.type() == NullAutomation) {
182                 return;
183         }
184
185         AutomationTracks::iterator existing = _automation_tracks.find (param);
186
187         if (existing != _automation_tracks.end()) {
188
189                 /* automation track created because we had existing data for
190                  * the processor, but visibility may need to be controlled
191                  * since it will have been set visible by default.
192                  */
193
194                 existing->second->set_marked_for_display (show);
195
196                 if (!no_redraw) {
197                         request_redraw ();
198                 }
199
200                 return;
201         }
202
203         if (param.type() == GainAutomation) {
204
205                 create_gain_automation_child (param, show);
206
207         } else if (param.type() == TrimAutomation) {
208
209                 create_trim_automation_child (param, show);
210
211         } else if (param.type() == PanWidthAutomation ||
212                    param.type() == PanElevationAutomation ||
213                    param.type() == PanAzimuthAutomation) {
214
215                 ensure_pan_views (show);
216
217         } else if (param.type() == PluginAutomation) {
218
219                 /* handled elsewhere */
220
221         } else if (param.type() == MuteAutomation) {
222
223                 create_mute_automation_child (param, show);
224
225
226         } else {
227                 error << "AudioTimeAxisView: unknown automation child " << EventTypeMap::instance().to_symbol(param) << endmsg;
228         }
229 }
230
231 void
232 AudioTimeAxisView::show_all_automation (bool apply_to_selection)
233 {
234         if (apply_to_selection) {
235                 _editor.get_selection().tracks.foreach_audio_time_axis (boost::bind (&AudioTimeAxisView::show_all_automation, _1, false));
236         } else {
237
238                 no_redraw = true;
239
240                 RouteTimeAxisView::show_all_automation ();
241
242                 no_redraw = false;
243                 request_redraw ();
244         }
245 }
246
247 void
248 AudioTimeAxisView::show_existing_automation (bool apply_to_selection)
249 {
250         if (apply_to_selection) {
251                 _editor.get_selection().tracks.foreach_audio_time_axis (boost::bind (&AudioTimeAxisView::show_existing_automation, _1, false));
252         } else {
253                 no_redraw = true;
254
255                 RouteTimeAxisView::show_existing_automation ();
256
257                 no_redraw = false;
258
259                 request_redraw ();
260         }
261 }
262
263 void
264 AudioTimeAxisView::hide_all_automation (bool apply_to_selection)
265 {
266         if (apply_to_selection) {
267                 _editor.get_selection().tracks.foreach_audio_time_axis (boost::bind (&AudioTimeAxisView::hide_all_automation, _1, false));
268         } else {
269                 no_redraw = true;
270
271                 RouteTimeAxisView::hide_all_automation();
272
273                 no_redraw = false;
274                 request_redraw ();
275         }
276 }
277
278 void
279 AudioTimeAxisView::route_active_changed ()
280 {
281         update_control_names ();
282 }
283
284
285 /**
286  *    Set up the names of the controls so that they are coloured
287  *    correctly depending on whether this route is inactive or
288  *    selected.
289  */
290
291 void
292 AudioTimeAxisView::update_control_names ()
293 {
294         if (is_audio_track()) {
295                 if (_route->active()) {
296                         controls_base_selected_name = "AudioTrackControlsBaseSelected";
297                         controls_base_unselected_name = "AudioTrackControlsBaseUnselected";
298                 } else {
299                         controls_base_selected_name = "AudioTrackControlsBaseInactiveSelected";
300                         controls_base_unselected_name = "AudioTrackControlsBaseInactiveUnselected";
301                 }
302         } else {
303                 if (_route->active()) {
304                         controls_base_selected_name = "BusControlsBaseSelected";
305                         controls_base_unselected_name = "BusControlsBaseUnselected";
306                 } else {
307                         controls_base_selected_name = "BusControlsBaseInactiveSelected";
308                         controls_base_unselected_name = "BusControlsBaseInactiveUnselected";
309                 }
310         }
311
312         if (selected()) {
313                 controls_ebox.set_name (controls_base_selected_name);
314                 time_axis_frame.set_name (controls_base_selected_name);
315         } else {
316                 controls_ebox.set_name (controls_base_unselected_name);
317                 time_axis_frame.set_name (controls_base_unselected_name);
318         }
319 }
320
321 void
322 AudioTimeAxisView::build_automation_action_menu (bool for_selection)
323 {
324         RouteTimeAxisView::build_automation_action_menu (for_selection);
325 }