add QMDSP library to ardev file so that its discoverable as we try to load VAMP stuff
[ardour.git] / gtk2_ardour / route_group_menu.cc
1 /*
2     Copyright (C) 2009 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 <gtkmm/menu.h>
21 #include <gtkmm/stock.h>
22 #include "gtkmm2ext/utils.h"
23 #include "ardour/session.h"
24 #include "ardour/route_group.h"
25 #include "route_group_menu.h"
26 #include "route_group_dialog.h"
27 #include "i18n.h"
28
29 using namespace Gtk;
30 using namespace ARDOUR;
31 using namespace PBD;
32
33 RouteGroupMenu::RouteGroupMenu (Session* s, PropertyList* plist)
34         : SessionHandlePtr (s)
35         , _menu (0)
36         , _default_properties (plist)
37         , _inhibit_group_selected (false)
38         , _selected_route_group (0)
39 {
40
41 }
42
43 RouteGroupMenu::~RouteGroupMenu()
44 {
45         delete _menu;
46         delete _default_properties;
47 }
48
49 /** @param curr Current route group to mark as selected, or 0 for no group */
50 void
51 RouteGroupMenu::build (RouteGroup* curr)
52 {
53         using namespace Menu_Helpers;
54
55         _selected_route_group = curr;
56
57         _inhibit_group_selected = true;
58
59         delete _menu;
60         
61         /* Note: don't use manage() here, otherwise if our _menu object is attached as a submenu
62            and its parent is then destroyed, our _menu object will be deleted and we'll have no
63            way of knowing about it.  Without manage(), when the above happens our _menu's gobject
64            will be destroyed and its value set to 0, so we know.
65         */
66         _menu = new Menu;
67
68         MenuList& items = _menu->items ();
69         
70         items.push_back (MenuElem (_("New group..."), sigc::mem_fun (*this, &RouteGroupMenu::new_group)));
71         items.push_back (SeparatorElem ());
72
73         RadioMenuItem::Group group;
74         items.push_back (RadioMenuElem (group, _("No group"), sigc::bind (sigc::mem_fun (*this, &RouteGroupMenu::set_group), (RouteGroup *) 0)));
75
76         if (curr == 0) {
77                 static_cast<RadioMenuItem*> (&items.back())->set_active ();
78         }
79
80         if (_session) {
81                 _session->foreach_route_group (sigc::bind (sigc::mem_fun (*this, &RouteGroupMenu::add_item), curr, &group));
82         }
83
84         _inhibit_group_selected = false;
85 }
86
87 void
88 RouteGroupMenu::add_item (RouteGroup* rg, RouteGroup* curr, RadioMenuItem::Group* group)
89 {
90         using namespace Menu_Helpers;
91
92         MenuList& items = _menu->items ();
93
94         items.push_back (RadioMenuElem (*group, rg->name(), sigc::bind (sigc::mem_fun(*this, &RouteGroupMenu::set_group), rg)));
95
96         if (rg == curr) {
97                 static_cast<RadioMenuItem*> (&items.back())->set_active ();
98         }
99 }
100
101 /** Called when a group is selected from the menu.
102  *  @param Group, or 0 for none.
103  */
104 void
105 RouteGroupMenu::set_group (RouteGroup* g)
106 {
107         if (g == _selected_route_group) {
108                 /* cut off the signal_toggled that GTK emits for an option that is being un-selected
109                    when a new option is being selected instead
110                 */
111                 return;
112         }
113         
114         if (!_inhibit_group_selected) {
115                 GroupSelected (g);
116         }
117
118         _selected_route_group = g;
119 }
120
121 void
122 RouteGroupMenu::new_group ()
123 {
124         if (!_session) {
125                 return;
126         }
127
128         RouteGroup* g = new RouteGroup (*_session, "");
129         g->apply_changes (*_default_properties);
130
131         RouteGroupDialog d (g, true);
132
133         if (d.do_run ()) {
134                 delete g;
135         } else {
136                 _session->add_route_group (g);
137                 set_group (g);
138         }
139 }
140
141 Gtk::Menu *
142 RouteGroupMenu::menu ()
143 {
144         /* Our menu's gobject can be 0 if it was attached as a submenu whose
145            parent was subsequently deleted.
146         */
147         assert (_menu && _menu->gobj());
148         return _menu;
149 }
150
151 void
152 RouteGroupMenu::detach ()
153 {
154         if (_menu && _menu->gobj ()) {
155                 Gtkmm2ext::detach_menu (*_menu);
156         }
157 }