From 965a9740835a77cc2bf9e6cea237e56ae41150d8 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Mon, 7 Mar 2011 13:04:03 +0000 Subject: [PATCH] Make the route group submenu of the RouteTimeAxisView menu apply to the selection. git-svn-id: svn://localhost/ardour2/branches/3.0@9087 d708f5d6-7413-0410-9779-e7cbd77b26cf --- gtk2_ardour/mixer_strip.cc | 18 ++------ gtk2_ardour/mixer_strip.h | 1 - gtk2_ardour/route_group_menu.cc | 74 +++++++++++++++++++++++---------- gtk2_ardour/route_group_menu.h | 8 ++-- gtk2_ardour/route_time_axis.cc | 33 ++++++++------- gtk2_ardour/route_time_axis.h | 2 - libs/ardour/ardour/types.h | 3 +- 7 files changed, 79 insertions(+), 60 deletions(-) diff --git a/gtk2_ardour/mixer_strip.cc b/gtk2_ardour/mixer_strip.cc index ce07737760..919ec86ada 100644 --- a/gtk2_ardour/mixer_strip.cc +++ b/gtk2_ardour/mixer_strip.cc @@ -1255,19 +1255,6 @@ MixerStrip::comment_changed (void *src) } } -/** Set the route group for this strip's route, or remove it from its current group. - * @param rg New RouteGroup, or 0. - */ -void -MixerStrip::set_route_group (RouteGroup *rg) -{ - if (rg) { - rg->add (_route); - } else if (_route->route_group ()) { - _route->route_group()->remove (_route); - } -} - bool MixerStrip::select_route_group (GdkEventButton *ev) { @@ -1284,10 +1271,11 @@ MixerStrip::select_route_group (GdkEventButton *ev) plist->add (Properties::solo, true); group_menu = new RouteGroupMenu (_session, plist); - group_menu->GroupSelected.connect (sigc::mem_fun (*this, &MixerStrip::set_route_group)); } - group_menu->build (route_group ()); + WeakRouteList r; + r.push_back (route ()); + group_menu->build (r); group_menu->menu()->popup (1, ev->time); } diff --git a/gtk2_ardour/mixer_strip.h b/gtk2_ardour/mixer_strip.h index 6ffb1ad907..5debbdb3a1 100644 --- a/gtk2_ardour/mixer_strip.h +++ b/gtk2_ardour/mixer_strip.h @@ -248,7 +248,6 @@ class MixerStrip : public RouteUI, public Gtk::EventBox void comment_edited (); bool ignore_comment_edit; - void set_route_group (ARDOUR::RouteGroup *); bool select_route_group (GdkEventButton *); void route_group_changed (); diff --git a/gtk2_ardour/route_group_menu.cc b/gtk2_ardour/route_group_menu.cc index 5b6c275516..9c1f6f9e38 100644 --- a/gtk2_ardour/route_group_menu.cc +++ b/gtk2_ardour/route_group_menu.cc @@ -22,6 +22,7 @@ #include "gtkmm2ext/utils.h" #include "ardour/session.h" #include "ardour/route_group.h" +#include "ardour/route.h" #include "route_group_menu.h" #include "route_group_dialog.h" #include "i18n.h" @@ -35,7 +36,6 @@ RouteGroupMenu::RouteGroupMenu (Session* s, PropertyList* plist) , _menu (0) , _default_properties (plist) , _inhibit_group_selected (false) - , _selected_route_group (0) { } @@ -46,13 +46,24 @@ RouteGroupMenu::~RouteGroupMenu() delete _default_properties; } -/** @param curr Current route group to mark as selected, or 0 for no group */ +/** @param s Routes to operate on */ void -RouteGroupMenu::build (RouteGroup* curr) +RouteGroupMenu::build (WeakRouteList const & s) { + assert (!s.empty ()); + using namespace Menu_Helpers; - _selected_route_group = curr; + _subject = s; + + /* FInd all the route groups that our subjects are members of */ + std::set groups; + for (WeakRouteList::const_iterator i = _subject.begin (); i != _subject.end(); ++i) { + boost::shared_ptr r = i->lock (); + if (r) { + groups.insert (r->route_group ()); + } + } _inhibit_group_selected = true; @@ -71,30 +82,44 @@ RouteGroupMenu::build (RouteGroup* curr) items.push_back (SeparatorElem ()); RadioMenuItem::Group group; - items.push_back (RadioMenuElem (group, _("No group"), sigc::bind (sigc::mem_fun (*this, &RouteGroupMenu::set_group), (RouteGroup *) 0))); + items.push_back (RadioMenuElem (group, _("No group"))); + RadioMenuItem* i = static_cast (&items.back ()); + i->signal_activate().connect (sigc::bind (sigc::mem_fun (*this, &RouteGroupMenu::set_group), (RouteGroup *) 0)); - if (curr == 0) { - static_cast (&items.back())->set_active (); + if (groups.size() == 1 && *groups.begin() == 0) { + i->set_active (); + } else if (groups.size() > 1) { + i->set_inconsistent (); } if (_session) { - _session->foreach_route_group (sigc::bind (sigc::mem_fun (*this, &RouteGroupMenu::add_item), curr, &group)); + _session->foreach_route_group (sigc::bind (sigc::mem_fun (*this, &RouteGroupMenu::add_item), groups, &group)); } _inhibit_group_selected = false; } +/** @param rg Route group to add. + * @param groups Active route groups (may included 0 for `no group') + * @param group Radio item group to add radio items to. + */ void -RouteGroupMenu::add_item (RouteGroup* rg, RouteGroup* curr, RadioMenuItem::Group* group) +RouteGroupMenu::add_item (RouteGroup* rg, std::set const & groups, RadioMenuItem::Group* group) { using namespace Menu_Helpers; MenuList& items = _menu->items (); - items.push_back (RadioMenuElem (*group, rg->name(), sigc::bind (sigc::mem_fun(*this, &RouteGroupMenu::set_group), rg))); + items.push_back (RadioMenuElem (*group, rg->name())); + RadioMenuItem* i = static_cast (&items.back ()); + i->signal_activate().connect (sigc::bind (sigc::mem_fun (*this, &RouteGroupMenu::set_group), rg)); - if (rg == curr) { - static_cast (&items.back())->set_active (); + if (groups.size() == 1 && *groups.begin() == rg) { + /* there's only one active group, and it's this one */ + i->set_active (); + } else if (groups.size() > 1) { + /* there are >1 active groups */ + i->set_inconsistent (); } } @@ -104,18 +129,25 @@ RouteGroupMenu::add_item (RouteGroup* rg, RouteGroup* curr, RadioMenuItem::Group void RouteGroupMenu::set_group (RouteGroup* g) { - if (g == _selected_route_group) { - /* cut off the signal_toggled that GTK emits for an option that is being un-selected - when a new option is being selected instead - */ + if (_inhibit_group_selected) { return; } - - if (!_inhibit_group_selected) { - GroupSelected (g); - } - _selected_route_group = g; + for (WeakRouteList::const_iterator i = _subject.begin(); i != _subject.end(); ++i) { + boost::shared_ptr r = i->lock (); + if (!r || r->route_group () == g) { + /* lock of weak_ptr failed, or the group for this route is already right */ + continue; + } + + if (g) { + g->add (r); + } else { + if (r->route_group ()) { + r->route_group()->remove (r); + } + } + } } void diff --git a/gtk2_ardour/route_group_menu.h b/gtk2_ardour/route_group_menu.h index e771cf0180..5d711ff66f 100644 --- a/gtk2_ardour/route_group_menu.h +++ b/gtk2_ardour/route_group_menu.h @@ -30,20 +30,18 @@ public: ~RouteGroupMenu(); Gtk::Menu* menu (); - void build (ARDOUR::RouteGroup *); + void build (ARDOUR::WeakRouteList const &); void detach (); - sigc::signal GroupSelected; - private: - void add_item (ARDOUR::RouteGroup *, ARDOUR::RouteGroup *, Gtk::RadioMenuItem::Group*); + void add_item (ARDOUR::RouteGroup *, std::set const &, Gtk::RadioMenuItem::Group*); void new_group (); void set_group (ARDOUR::RouteGroup *); Gtk::Menu* _menu; PBD::PropertyList* _default_properties; bool _inhibit_group_selected; - ARDOUR::RouteGroup* _selected_route_group; + ARDOUR::WeakRouteList _subject; }; #endif /* __ardour_gtk_route_group_menu_h__ */ diff --git a/gtk2_ardour/route_time_axis.cc b/gtk2_ardour/route_time_axis.cc index e723aeee40..6d09fe8792 100644 --- a/gtk2_ardour/route_time_axis.cc +++ b/gtk2_ardour/route_time_axis.cc @@ -231,7 +231,6 @@ RouteTimeAxisView::RouteTimeAxisView (PublicEditor& ed, Session* sess, boost::sh plist->add (ARDOUR::Properties::solo, true); route_group_menu = new RouteGroupMenu (_session, plist); - route_group_menu->GroupSelected.connect (sigc::mem_fun (*this, &RouteTimeAxisView::set_route_group_from_menu)); gm.get_gain_slider().signal_scroll_event().connect(sigc::mem_fun(*this, &RouteTimeAxisView::controls_ebox_scroll), false); gm.get_gain_slider().set_name ("TrackGainFader"); @@ -280,24 +279,15 @@ RouteTimeAxisView::route_group_click (GdkEventButton *ev) return false; } - route_group_menu->build (_route->route_group ()); + WeakRouteList r; + r.push_back (route ()); + + route_group_menu->build (r); route_group_menu->menu()->popup (ev->button, ev->time); return false; } -void -RouteTimeAxisView::set_route_group_from_menu (RouteGroup *eg) -{ - if (eg) { - eg->add (_route); - } else { - if (_route->route_group()) { - _route->route_group()->remove (_route); - } - } -} - void RouteTimeAxisView::playlist_changed () { @@ -609,7 +599,20 @@ RouteTimeAxisView::build_display_menu () items.back().set_sensitive (_editor.get_selection().tracks.size() <= 1); route_group_menu->detach (); - route_group_menu->build (_route->route_group ()); + + WeakRouteList r; + for (TrackSelection::iterator i = _editor.get_selection().tracks.begin(); i != _editor.get_selection().tracks.end(); ++i) { + RouteTimeAxisView* rtv = dynamic_cast (*i); + if (rtv) { + r.push_back (rtv->route ()); + } + } + + if (r.empty ()) { + r.push_back (route ()); + } + + route_group_menu->build (r); items.push_back (MenuElem (_("Route Group"), *route_group_menu->menu ())); build_automation_action_menu (); diff --git a/gtk2_ardour/route_time_axis.h b/gtk2_ardour/route_time_axis.h index d9b957dbab..9a4f321301 100644 --- a/gtk2_ardour/route_time_axis.h +++ b/gtk2_ardour/route_time_axis.h @@ -207,8 +207,6 @@ protected: virtual void label_view (); - void set_route_group_from_menu (ARDOUR::RouteGroup *); - void reset_samples_per_unit (); void horizontal_position_changed (); diff --git a/libs/ardour/ardour/types.h b/libs/ardour/ardour/types.h index 06c600eaee..e0c738270e 100644 --- a/libs/ardour/ardour/types.h +++ b/libs/ardour/ardour/types.h @@ -488,7 +488,8 @@ namespace ARDOUR { typedef std::list AnalysisFeatureList; - typedef std::list > RouteList; + typedef std::list > RouteList; + typedef std::list > WeakRouteList; class Bundle; typedef std::vector > BundleList;