2009-06-28 20:57:27 -04:00
|
|
|
/*
|
2019-08-02 17:26:43 -04:00
|
|
|
* Copyright (C) 2009-2011 Carl Hetherington <carl@carlh.net>
|
|
|
|
* Copyright (C) 2009-2011 David Robillard <d@drobilla.net>
|
|
|
|
* Copyright (C) 2009-2016 Paul Davis <paul@linuxaudiosystems.com>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
2009-06-28 20:57:27 -04:00
|
|
|
|
2009-06-28 20:38:58 -04:00
|
|
|
#include <gtkmm/menu.h>
|
|
|
|
#include <gtkmm/stock.h>
|
2016-06-12 14:33:18 -04:00
|
|
|
|
2011-02-22 20:05:15 -05:00
|
|
|
#include "gtkmm2ext/utils.h"
|
2016-06-12 14:33:18 -04:00
|
|
|
#include "gtkmm2ext/doi.h"
|
|
|
|
|
2009-06-28 20:38:58 -04:00
|
|
|
#include "ardour/session.h"
|
|
|
|
#include "ardour/route_group.h"
|
2011-03-07 08:04:03 -05:00
|
|
|
#include "ardour/route.h"
|
2009-06-28 20:38:58 -04:00
|
|
|
#include "route_group_menu.h"
|
|
|
|
#include "route_group_dialog.h"
|
2016-06-12 14:33:18 -04:00
|
|
|
|
2016-07-14 14:44:52 -04:00
|
|
|
#include "pbd/i18n.h"
|
2009-06-28 20:38:58 -04:00
|
|
|
|
|
|
|
using namespace Gtk;
|
|
|
|
using namespace ARDOUR;
|
2010-02-18 08:59:49 -05:00
|
|
|
using namespace PBD;
|
2009-06-28 20:38:58 -04:00
|
|
|
|
2010-02-18 08:59:49 -05:00
|
|
|
RouteGroupMenu::RouteGroupMenu (Session* s, PropertyList* plist)
|
2009-12-17 13:24:23 -05:00
|
|
|
: SessionHandlePtr (s)
|
2011-02-22 20:05:15 -05:00
|
|
|
, _menu (0)
|
2010-02-18 08:59:49 -05:00
|
|
|
, _default_properties (plist)
|
2010-01-12 20:40:07 -05:00
|
|
|
, _inhibit_group_selected (false)
|
2009-06-28 20:38:58 -04:00
|
|
|
{
|
2011-02-22 20:05:15 -05:00
|
|
|
|
2009-06-28 20:38:58 -04:00
|
|
|
}
|
|
|
|
|
2010-02-18 08:59:49 -05:00
|
|
|
RouteGroupMenu::~RouteGroupMenu()
|
|
|
|
{
|
2011-02-22 20:05:15 -05:00
|
|
|
delete _menu;
|
|
|
|
delete _default_properties;
|
2010-02-18 08:59:49 -05:00
|
|
|
}
|
|
|
|
|
2011-03-07 08:04:03 -05:00
|
|
|
/** @param s Routes to operate on */
|
2009-06-28 20:38:58 -04:00
|
|
|
void
|
2011-03-07 08:04:03 -05:00
|
|
|
RouteGroupMenu::build (WeakRouteList const & s)
|
2009-06-28 20:38:58 -04:00
|
|
|
{
|
2011-03-07 08:04:03 -05:00
|
|
|
assert (!s.empty ());
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2009-06-28 20:38:58 -04:00
|
|
|
using namespace Menu_Helpers;
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2011-03-07 08:04:03 -05:00
|
|
|
_subject = s;
|
|
|
|
|
|
|
|
/* FInd all the route groups that our subjects are members of */
|
|
|
|
std::set<RouteGroup*> groups;
|
|
|
|
for (WeakRouteList::const_iterator i = _subject.begin (); i != _subject.end(); ++i) {
|
2023-02-16 18:33:28 -05:00
|
|
|
std::shared_ptr<Route> r = i->lock ();
|
2011-03-07 08:04:03 -05:00
|
|
|
if (r) {
|
|
|
|
groups.insert (r->route_group ());
|
|
|
|
}
|
|
|
|
}
|
2010-01-12 20:40:07 -05:00
|
|
|
|
|
|
|
_inhibit_group_selected = true;
|
|
|
|
|
2011-02-22 20:05:15 -05:00
|
|
|
delete _menu;
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2011-02-22 20:05:15 -05:00
|
|
|
/* Note: don't use manage() here, otherwise if our _menu object is attached as a submenu
|
|
|
|
and its parent is then destroyed, our _menu object will be deleted and we'll have no
|
|
|
|
way of knowing about it. Without manage(), when the above happens our _menu's gobject
|
|
|
|
will be destroyed and its value set to 0, so we know.
|
|
|
|
*/
|
|
|
|
_menu = new Menu;
|
|
|
|
|
|
|
|
MenuList& items = _menu->items ();
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2011-05-16 18:22:57 -04:00
|
|
|
items.push_back (MenuElem (_("New Group..."), sigc::mem_fun (*this, &RouteGroupMenu::new_group)));
|
2021-09-28 01:11:37 -04:00
|
|
|
if (groups.size() == 1 && *groups.begin() != 0) {
|
|
|
|
items.push_back (MenuElem (_("Edit Group..."), sigc::bind (sigc::mem_fun (*this, &RouteGroupMenu::edit_group), *groups.begin ())));
|
|
|
|
}
|
2011-02-22 20:05:15 -05:00
|
|
|
items.push_back (SeparatorElem ());
|
2009-06-28 20:38:58 -04:00
|
|
|
|
|
|
|
RadioMenuItem::Group group;
|
2011-05-16 18:22:57 -04:00
|
|
|
items.push_back (RadioMenuElem (group, _("No Group")));
|
2011-03-07 08:04:03 -05:00
|
|
|
RadioMenuItem* i = static_cast<RadioMenuItem *> (&items.back ());
|
2018-09-16 17:08:41 -04:00
|
|
|
i->signal_activate().connect (sigc::bind (sigc::mem_fun (*this, &RouteGroupMenu::set_group), i, (RouteGroup *) 0));
|
2011-03-07 08:04:03 -05:00
|
|
|
|
|
|
|
if (groups.size() == 1 && *groups.begin() == 0) {
|
|
|
|
i->set_active ();
|
|
|
|
} else if (groups.size() > 1) {
|
|
|
|
i->set_inconsistent ();
|
2009-06-28 20:38:58 -04:00
|
|
|
}
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2009-12-17 13:24:23 -05:00
|
|
|
if (_session) {
|
2011-03-07 08:04:03 -05:00
|
|
|
_session->foreach_route_group (sigc::bind (sigc::mem_fun (*this, &RouteGroupMenu::add_item), groups, &group));
|
2009-12-17 13:24:23 -05:00
|
|
|
}
|
2010-01-12 20:40:07 -05:00
|
|
|
|
|
|
|
_inhibit_group_selected = false;
|
2009-06-28 20:38:58 -04:00
|
|
|
}
|
|
|
|
|
2011-03-07 08:04:03 -05:00
|
|
|
/** @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.
|
|
|
|
*/
|
2009-06-28 20:38:58 -04:00
|
|
|
void
|
2011-03-07 08:04:03 -05:00
|
|
|
RouteGroupMenu::add_item (RouteGroup* rg, std::set<RouteGroup*> const & groups, RadioMenuItem::Group* group)
|
2009-06-28 20:38:58 -04:00
|
|
|
{
|
|
|
|
using namespace Menu_Helpers;
|
|
|
|
|
2011-02-22 20:05:15 -05:00
|
|
|
MenuList& items = _menu->items ();
|
|
|
|
|
2011-03-07 08:04:03 -05:00
|
|
|
items.push_back (RadioMenuElem (*group, rg->name()));
|
|
|
|
RadioMenuItem* i = static_cast<RadioMenuItem*> (&items.back ());
|
2018-09-16 17:08:41 -04:00
|
|
|
i->signal_activate().connect (sigc::bind (sigc::mem_fun (*this, &RouteGroupMenu::set_group), i, rg));
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2011-03-07 08:04:03 -05:00
|
|
|
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 ();
|
2009-10-14 12:10:01 -04:00
|
|
|
}
|
2009-06-28 20:38:58 -04:00
|
|
|
}
|
|
|
|
|
2011-01-05 20:07:10 -05:00
|
|
|
/** Called when a group is selected from the menu.
|
|
|
|
* @param Group, or 0 for none.
|
|
|
|
*/
|
2009-06-28 20:38:58 -04:00
|
|
|
void
|
2018-09-16 17:08:41 -04:00
|
|
|
RouteGroupMenu::set_group (Gtk::RadioMenuItem* e, RouteGroup* g)
|
2009-06-28 20:38:58 -04:00
|
|
|
{
|
2011-03-07 08:04:03 -05:00
|
|
|
if (_inhibit_group_selected) {
|
2010-01-12 20:40:07 -05:00
|
|
|
return;
|
|
|
|
}
|
2018-09-16 17:08:41 -04:00
|
|
|
if (e && !e->get_active()) {
|
|
|
|
return;
|
|
|
|
}
|
2010-01-12 20:40:07 -05:00
|
|
|
|
2011-03-07 08:04:03 -05:00
|
|
|
for (WeakRouteList::const_iterator i = _subject.begin(); i != _subject.end(); ++i) {
|
2023-02-16 18:33:28 -05:00
|
|
|
std::shared_ptr<Route> r = i->lock ();
|
2011-03-07 08:04:03 -05:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-06-28 20:38:58 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
RouteGroupMenu::new_group ()
|
|
|
|
{
|
2009-12-17 13:24:23 -05:00
|
|
|
if (!_session) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-02-18 08:59:49 -05:00
|
|
|
RouteGroup* g = new RouteGroup (*_session, "");
|
2016-06-12 14:33:18 -04:00
|
|
|
RouteGroupDialog* d = new RouteGroupDialog (g, true);
|
|
|
|
|
|
|
|
d->signal_response().connect (sigc::bind (sigc::mem_fun (*this, &RouteGroupMenu::new_group_dialog_finished), d));
|
2016-07-02 11:04:51 -04:00
|
|
|
d->present ();
|
2016-06-12 14:33:18 -04:00
|
|
|
}
|
2009-06-28 20:38:58 -04:00
|
|
|
|
2016-06-12 14:33:18 -04:00
|
|
|
void
|
|
|
|
RouteGroupMenu::new_group_dialog_finished (int r, RouteGroupDialog* d)
|
|
|
|
{
|
|
|
|
if (r == RESPONSE_OK) {
|
|
|
|
_session->add_route_group (d->group());
|
2018-09-16 17:08:41 -04:00
|
|
|
set_group (0, d->group());
|
2011-01-07 21:35:46 -05:00
|
|
|
} else {
|
2016-06-12 14:33:18 -04:00
|
|
|
delete d->group ();
|
2009-06-28 20:38:58 -04:00
|
|
|
}
|
2016-06-12 14:33:18 -04:00
|
|
|
|
|
|
|
delete_when_idle (d);
|
2009-06-28 20:38:58 -04:00
|
|
|
}
|
2011-02-22 20:05:15 -05:00
|
|
|
|
2021-09-28 01:11:37 -04:00
|
|
|
void
|
|
|
|
RouteGroupMenu::edit_group (ARDOUR::RouteGroup* g)
|
|
|
|
{
|
|
|
|
RouteGroupDialog* d = new RouteGroupDialog (g, false);
|
|
|
|
d->signal_response().connect (sigc::hide (sigc::bind (sigc::ptr_fun (&delete_when_idle<RouteGroupDialog>), d)));
|
|
|
|
d->present ();
|
|
|
|
}
|
|
|
|
|
2011-02-22 20:05:15 -05:00
|
|
|
Gtk::Menu *
|
|
|
|
RouteGroupMenu::menu ()
|
|
|
|
{
|
|
|
|
/* Our menu's gobject can be 0 if it was attached as a submenu whose
|
|
|
|
parent was subsequently deleted.
|
|
|
|
*/
|
|
|
|
assert (_menu && _menu->gobj());
|
|
|
|
return _menu;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
RouteGroupMenu::detach ()
|
|
|
|
{
|
|
|
|
if (_menu && _menu->gobj ()) {
|
|
|
|
Gtkmm2ext::detach_menu (*_menu);
|
|
|
|
}
|
|
|
|
}
|