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