changes to help strp silence
[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/stop_signal.h>
37 #include <gtkmm2ext/bindable_button.h>
38 #include <gtkmm2ext/utils.h>
39
40 #include "ardour/amp.h"
41 #include "ardour/audio_diskstream.h"
42 #include "ardour/audioplaylist.h"
43 #include "ardour/event_type_map.h"
44 #include "ardour/location.h"
45 #include "ardour/panner.h"
46 #include "ardour/playlist.h"
47 #include "ardour/processor.h"
48 #include "ardour/profile.h"
49 #include "ardour/session.h"
50 #include "ardour/session_playlist.h"
51 #include "ardour/utils.h"
52
53 #include "ardour_ui.h"
54 #include "audio_time_axis.h"
55 #include "automation_line.h"
56 #include "canvas_impl.h"
57 #include "crossfade_view.h"
58 #include "enums.h"
59 #include "gui_thread.h"
60 #include "automation_time_axis.h"
61 #include "keyboard.h"
62 #include "playlist_selector.h"
63 #include "prompter.h"
64 #include "public_editor.h"
65 #include "audio_region_view.h"
66 #include "simplerect.h"
67 #include "audio_streamview.h"
68 #include "utils.h"
69
70 #include "ardour/audio_track.h"
71
72 #include "i18n.h"
73
74 using namespace std;
75 using namespace ARDOUR;
76 using namespace PBD;
77 using namespace Gtk;
78 using namespace Editing;
79
80 AudioTimeAxisView::AudioTimeAxisView (PublicEditor& ed, Session* sess, boost::shared_ptr<Route> rt, Canvas& canvas)
81         : AxisView(sess)
82         , RouteTimeAxisView(ed, sess, rt, canvas)
83 {
84         // Make sure things are sane...
85         assert(!is_track() || is_audio_track());
86
87         subplugin_menu.set_name ("ArdourContextMenu");
88
89         _view = new AudioStreamView (*this);
90
91         ignore_toggle = false;
92
93         mute_button->set_active (false);
94         solo_button->set_active (false);
95
96         if (is_audio_track()) {
97                 controls_ebox.set_name ("AudioTrackControlsBaseUnselected");
98         } else { // bus
99                 controls_ebox.set_name ("AudioBusControlsBaseUnselected");
100         }
101
102         ensure_xml_node ();
103
104         set_state (*xml_node, Stateful::loading_state_version);
105
106         /* if set_state above didn't create a gain automation child, we need to make one */
107         if (automation_track (GainAutomation) == 0) {
108                 create_automation_child (GainAutomation, false);
109         }
110
111         if (_route->panner()) {
112                 _route->panner()->Changed.connect (*this, boost::bind (&AudioTimeAxisView::ensure_pan_views, this, false), gui_context());
113         }
114
115         /* map current state of the route */
116
117         processors_changed (RouteProcessorChange ());
118         reset_processor_automation_curves ();
119         ensure_pan_views (false);
120         update_control_names ();
121
122         if (is_audio_track()) {
123
124                 /* ask for notifications of any new RegionViews */
125                 _view->RegionViewAdded.connect (sigc::mem_fun(*this, &AudioTimeAxisView::region_view_added));
126
127                 if (!_editor.have_idled()) {
128                         /* first idle will do what we need */
129                 } else {
130                         first_idle ();
131                 }
132
133         } else {
134                 post_construct ();
135         }
136 }
137
138 AudioTimeAxisView::~AudioTimeAxisView ()
139 {
140 }
141
142 void
143 AudioTimeAxisView::first_idle ()
144 {
145         _view->attach ();
146         post_construct ();
147 }
148
149 AudioStreamView*
150 AudioTimeAxisView::audio_view()
151 {
152         return dynamic_cast<AudioStreamView*>(_view);
153 }
154
155 guint32
156 AudioTimeAxisView::show_at (double y, int& nth, Gtk::VBox *parent)
157 {
158         ensure_xml_node ();
159         xml_node->add_property ("shown-editor", "yes");
160
161         return TimeAxisView::show_at (y, nth, parent);
162 }
163
164 void
165 AudioTimeAxisView::hide ()
166 {
167         ensure_xml_node ();
168         xml_node->add_property ("shown-editor", "no");
169
170         TimeAxisView::hide ();
171 }
172
173
174 void
175 AudioTimeAxisView::append_extra_display_menu_items ()
176 {
177         using namespace Menu_Helpers;
178
179         MenuList& items = display_menu->items();
180
181         // crossfade stuff
182         if (!Profile->get_sae()) {
183                 items.push_back (MenuElem (_("Hide all crossfades"), sigc::mem_fun(*this, &AudioTimeAxisView::hide_all_xfades)));
184                 items.push_back (MenuElem (_("Show all crossfades"), sigc::mem_fun(*this, &AudioTimeAxisView::show_all_xfades)));
185         }
186 }
187
188 Gtk::Menu*
189 AudioTimeAxisView::build_mode_menu()
190 {
191         using namespace Menu_Helpers;
192
193         Menu* mode_menu = manage (new Menu);
194         MenuList& items = mode_menu->items();
195         mode_menu->set_name ("ArdourContextMenu");
196
197         RadioMenuItem::Group mode_group;
198
199         items.push_back (RadioMenuElem (mode_group, _("Normal"),
200                                 sigc::bind (sigc::mem_fun (*this, &AudioTimeAxisView::set_track_mode), ARDOUR::Normal)));
201         normal_track_mode_item = dynamic_cast<RadioMenuItem*>(&items.back());
202
203         items.push_back (RadioMenuElem (mode_group, _("Non Overlapping"),
204                                 sigc::bind (sigc::mem_fun (*this, &AudioTimeAxisView::set_track_mode), ARDOUR::NonLayered)));
205         non_layered_track_mode_item = dynamic_cast<RadioMenuItem*>(&items.back());
206
207         items.push_back (RadioMenuElem (mode_group, _("Tape"),
208                                 sigc::bind (sigc::mem_fun (*this, &AudioTimeAxisView::set_track_mode), ARDOUR::Destructive)));
209         destructive_track_mode_item = dynamic_cast<RadioMenuItem*>(&items.back());
210
211         switch (track()->mode()) {
212                 case ARDOUR::Destructive:
213                         destructive_track_mode_item->set_active ();
214                         break;
215                 case ARDOUR::NonLayered:
216                         non_layered_track_mode_item->set_active ();
217                         break;
218                 case ARDOUR::Normal:
219                         normal_track_mode_item->set_active ();
220                         break;
221         }
222
223         return mode_menu;
224 }
225
226 void
227 AudioTimeAxisView::set_show_waveforms_recording (bool yn)
228 {
229         AudioStreamView* asv = audio_view();
230
231         if (asv) {
232                 asv->set_show_waveforms_recording (yn);
233         }
234 }
235
236 void
237 AudioTimeAxisView::create_automation_child (const Evoral::Parameter& param, bool show)
238 {
239         if (param.type() == GainAutomation) {
240
241                 boost::shared_ptr<AutomationControl> c = _route->gain_control();
242                 if (!c) {
243                         error << "Route has no gain automation, unable to add automation track view." << endmsg;
244                         return;
245                 }
246
247                 boost::shared_ptr<AutomationTimeAxisView>
248                         gain_track(new AutomationTimeAxisView (_session,
249                                                                _route, _route->amp(), c,
250                                                                _editor,
251                                                                *this,
252                                                                false,
253                                                                parent_canvas,
254                                                                _route->amp()->describe_parameter(param)));
255
256                 add_automation_child(Evoral::Parameter(GainAutomation), gain_track, show);
257
258         } else if (param.type() == PanAutomation) {
259
260                 ensure_xml_node ();
261                 ensure_pan_views (show);
262
263         } else {
264                 error << "AudioTimeAxisView: unknown automation child " << EventTypeMap::instance().to_symbol(param) << endmsg;
265         }
266 }
267
268 /** Ensure that we have the appropriate AutomationTimeAxisViews for the
269  *  panners that we have.
270  *
271  *  @param show true to show any new views that we create, otherwise false.
272  */
273 void
274 AudioTimeAxisView::ensure_pan_views (bool show)
275 {
276         if (!_route->panner()) {
277                 return;
278         }
279
280         const set<Evoral::Parameter>& params = _route->panner()->what_can_be_automated();
281         set<Evoral::Parameter>::iterator p;
282
283         for (p = params.begin(); p != params.end(); ++p) {
284                 boost::shared_ptr<ARDOUR::AutomationControl> pan_control
285                         = boost::dynamic_pointer_cast<ARDOUR::AutomationControl>(
286                                 _route->panner()->control(*p));
287
288                 if (pan_control->parameter().type() == NullAutomation) {
289                         error << "Pan control has NULL automation type!" << endmsg;
290                         continue;
291                 }
292
293                 if (automation_child (pan_control->parameter ()).get () == 0) {
294
295                         /* we don't already have an AutomationTimeAxisView for this parameter */
296
297                         std::string const name = _route->panner()->describe_parameter (pan_control->parameter ());
298
299                         boost::shared_ptr<AutomationTimeAxisView> pan_track (
300                                 new AutomationTimeAxisView (_session,
301                                                             _route, _route->panner(), pan_control,
302                                                             _editor,
303                                                             *this,
304                                                             false,
305                                                             parent_canvas,
306                                                             name));
307
308                         add_automation_child (*p, pan_track, show);
309                 }
310         }
311 }
312 #if 0
313 void
314 AudioTimeAxisView::toggle_gain_track ()
315 {
316         bool showit = gain_automation_item->get_active();
317
318         if (showit != gain_track->marked_for_display()) {
319                 if (showit) {
320                         gain_track->set_marked_for_display (true);
321                         gain_track->canvas_display->show();
322                         gain_track->canvas_background->show();
323                         gain_track->get_state_node()->add_property ("shown", X_("yes"));
324                 } else {
325                         gain_track->set_marked_for_display (false);
326                         gain_track->hide ();
327                         gain_track->get_state_node()->add_property ("shown", X_("no"));
328                 }
329
330                 /* now trigger a redisplay */
331
332                 if (!no_redraw) {
333                          _route->gui_changed (X_("visible_tracks"), (void *) 0); /* EMIT_SIGNAL */
334                 }
335         }
336 }
337
338 void
339 AudioTimeAxisView::gain_hidden ()
340 {
341         gain_track->get_state_node()->add_property (X_("shown"), X_("no"));
342
343         if (gain_automation_item && !_hidden) {
344                 gain_automation_item->set_active (false);
345         }
346
347          _route->gui_changed ("visible_tracks", (void *) 0); /* EMIT_SIGNAL */
348 }
349
350 void
351 AudioTimeAxisView::toggle_pan_track ()
352 {
353         bool showit = pan_automation_item->get_active();
354
355         if (showit != pan_track->marked_for_display()) {
356                 if (showit) {
357                         pan_track->set_marked_for_display (true);
358                         pan_track->canvas_display->show();
359                         pan_track->canvas_background->show();
360                         pan_track->get_state_node()->add_property ("shown", X_("yes"));
361                 } else {
362                         pan_track->set_marked_for_display (false);
363                         pan_track->hide ();
364                         pan_track->get_state_node()->add_property ("shown", X_("no"));
365                 }
366
367                 /* now trigger a redisplay */
368         }
369 }
370 #endif
371
372 void
373 AudioTimeAxisView::show_all_automation ()
374 {
375         no_redraw = true;
376
377         RouteTimeAxisView::show_all_automation ();
378
379         no_redraw = false;
380
381          _route->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
382 }
383
384 void
385 AudioTimeAxisView::show_existing_automation ()
386 {
387         no_redraw = true;
388
389         RouteTimeAxisView::show_existing_automation ();
390
391         no_redraw = false;
392
393          _route->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
394 }
395
396 void
397 AudioTimeAxisView::hide_all_automation ()
398 {
399         no_redraw = true;
400
401         RouteTimeAxisView::hide_all_automation();
402
403         no_redraw = false;
404          _route->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
405 }
406
407 void
408 AudioTimeAxisView::show_all_xfades ()
409 {
410         AudioStreamView* asv = audio_view();
411
412         if (asv) {
413                 asv->show_all_xfades ();
414         }
415 }
416
417 void
418 AudioTimeAxisView::hide_all_xfades ()
419 {
420         AudioStreamView* asv = audio_view();
421
422         if (asv) {
423                 asv->hide_all_xfades ();
424         }
425 }
426
427 void
428 AudioTimeAxisView::hide_dependent_views (TimeAxisViewItem& tavi)
429 {
430         AudioStreamView* asv = audio_view();
431         AudioRegionView* rv;
432
433         if (asv && (rv = dynamic_cast<AudioRegionView*>(&tavi)) != 0) {
434                 asv->hide_xfades_involving (*rv);
435         }
436 }
437
438 void
439 AudioTimeAxisView::reveal_dependent_views (TimeAxisViewItem& tavi)
440 {
441         AudioStreamView* asv = audio_view();
442         AudioRegionView* rv;
443
444         if (asv && (rv = dynamic_cast<AudioRegionView*>(&tavi)) != 0) {
445                 asv->reveal_xfades_involving (*rv);
446         }
447 }
448
449 void
450 AudioTimeAxisView::route_active_changed ()
451 {
452         RouteTimeAxisView::route_active_changed ();
453         update_control_names ();
454 }
455
456
457 /**
458  *    Set up the names of the controls so that they are coloured
459  *    correctly depending on whether this route is inactive or
460  *    selected.
461  */
462
463 void
464 AudioTimeAxisView::update_control_names ()
465 {
466         if (is_audio_track()) {
467                 if (_route->active()) {
468                         controls_base_selected_name = "AudioTrackControlsBaseSelected";
469                         controls_base_unselected_name = "AudioTrackControlsBaseUnselected";
470                 } else {
471                         controls_base_selected_name = "AudioTrackControlsBaseInactiveSelected";
472                         controls_base_unselected_name = "AudioTrackControlsBaseInactiveUnselected";
473                 }
474         } else {
475                 if (_route->active()) {
476                         controls_base_selected_name = "BusControlsBaseSelected";
477                         controls_base_unselected_name = "BusControlsBaseUnselected";
478                 } else {
479                         controls_base_selected_name = "BusControlsBaseInactiveSelected";
480                         controls_base_unselected_name = "BusControlsBaseInactiveUnselected";
481                 }
482         }
483
484         if (get_selected()) {
485                 controls_ebox.set_name (controls_base_selected_name);
486         } else {
487                 controls_ebox.set_name (controls_base_unselected_name);
488         }
489 }