From 65e17100872e515e8a6a50b8213fa7ed99a1455f Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Wed, 23 Feb 2011 02:08:57 +0000 Subject: Make layer menu items apply to the selection. git-svn-id: svn://localhost/ardour2/branches/3.0@8940 d708f5d6-7413-0410-9779-e7cbd77b26cf --- gtk2_ardour/route_time_axis.cc | 61 +++++++++++++++++++++++++++++++++--------- gtk2_ardour/route_time_axis.h | 2 +- gtk2_ardour/track_selection.h | 8 ++++++ 3 files changed, 57 insertions(+), 14 deletions(-) diff --git a/gtk2_ardour/route_time_axis.cc b/gtk2_ardour/route_time_axis.cc index da1ab50360..ad789d4285 100644 --- a/gtk2_ardour/route_time_axis.cc +++ b/gtk2_ardour/route_time_axis.cc @@ -464,15 +464,45 @@ RouteTimeAxisView::build_display_menu () RadioMenuItem::Group layers_group; - layers_items.push_back(RadioMenuElem (layers_group, _("Overlaid"), - sigc::bind (sigc::mem_fun (*this, &RouteTimeAxisView::set_layer_display), Overlaid))); + /* Find out how many overlaid/stacked tracks we have in the selection */ + + int overlaid = 0; + int stacked = 0; + TrackSelection const & s = _editor.get_selection().tracks; + for (TrackSelection::const_iterator i = s.begin(); i != s.end(); ++i) { + StreamView* v = (*i)->view (); + if (!v) { + continue; + } + + if (v->layer_display() == Overlaid) { + ++overlaid; + } else if (v->layer_display() == Stacked) { + ++stacked; + } + } - dynamic_cast (&layers_items.back())->set_active (_view && _view->layer_display() == Overlaid); + /* We're not connecting to signal_toggled() here; in the case where these two items are + set to be in the `inconsistent' state, it seems that one or other will end up active + as well as inconsistent (presumably due to the RadioMenuItem::Group). Then when you + select the active one, no toggled signal is emitted so nothing happens. + */ - layers_items.push_back(RadioMenuElem (layers_group, _("Stacked"), - sigc::bind (sigc::mem_fun (*this, &RouteTimeAxisView::set_layer_display), Stacked))); - - dynamic_cast (&layers_items.back())->set_active (_view && _view->layer_display() == Stacked); + layers_items.push_back (RadioMenuElem (layers_group, _("Overlaid"))); + RadioMenuItem* i = dynamic_cast (&layers_items.back ()); + i->set_active (overlaid != 0 && stacked == 0); + i->set_inconsistent (overlaid != 0 && stacked != 0); + i->signal_activate().connect (sigc::bind (sigc::mem_fun (*this, &RouteTimeAxisView::set_layer_display), Overlaid, true)); + + layers_items.push_back ( + RadioMenuElem (layers_group, _("Stacked"), + sigc::bind (sigc::mem_fun (*this, &RouteTimeAxisView::set_layer_display), Stacked, true)) + ); + + i = dynamic_cast (&layers_items.back ()); + i->signal_activate().connect (sigc::bind (sigc::mem_fun (*this, &RouteTimeAxisView::set_layer_display), Stacked, true)); + i->set_active (overlaid == 0 && stacked != 0); + i->set_inconsistent (overlaid != 0 && stacked != 0); items.push_back (MenuElem (_("Layers"), *layers_menu)); @@ -2162,14 +2192,19 @@ RouteTimeAxisView::update_rec_display () } void -RouteTimeAxisView::set_layer_display (LayerDisplay d) +RouteTimeAxisView::set_layer_display (LayerDisplay d, bool apply_to_selection) { - if (_view) { - _view->set_layer_display (d); + if (apply_to_selection) { + _editor.get_selection().tracks.foreach_route_time_axis (boost::bind (&RouteTimeAxisView::set_layer_display, _1, d, false)); + } else { + + if (_view) { + _view->set_layer_display (d); + } + + ensure_xml_node (); + xml_node->add_property (N_("layer-display"), enum_2_string (d)); } - - ensure_xml_node (); - xml_node->add_property (N_("layer-display"), enum_2_string (d)); } LayerDisplay diff --git a/gtk2_ardour/route_time_axis.h b/gtk2_ardour/route_time_axis.h index 940964df53..bffa126a14 100644 --- a/gtk2_ardour/route_time_axis.h +++ b/gtk2_ardour/route_time_axis.h @@ -85,7 +85,7 @@ public: void set_selected_regionviews (RegionSelection&); void get_selectables (ARDOUR::framepos_t start, ARDOUR::framepos_t end, double top, double bot, std::list&); void get_inverted_selectables (Selection&, std::list&); - void set_layer_display (LayerDisplay d); + void set_layer_display (LayerDisplay d, bool apply_to_selection = false); LayerDisplay layer_display () const; boost::shared_ptr find_next_region (framepos_t pos, ARDOUR::RegionPoint, int32_t dir); diff --git a/gtk2_ardour/track_selection.h b/gtk2_ardour/track_selection.h index 0c4f364c4e..e61e62958f 100644 --- a/gtk2_ardour/track_selection.h +++ b/gtk2_ardour/track_selection.h @@ -51,6 +51,14 @@ public: } } + template + void foreach_route_time_axis (Function f) { + for (iterator i = begin(); i != end(); ++i) { + RouteTimeAxisView* t = dynamic_cast (*i); + f (t); + } + } + template void foreach_audio_time_axis (Function f) { for (iterator i = begin(); i != end(); ++i) { -- cgit v1.2.3