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