Unconditionally save instant.xml on session-close
[ardour.git] / gtk2_ardour / route_group_dialog.cc
1 /*
2  * Copyright (C) 2009-2011 David Robillard <d@drobilla.net>
3  * Copyright (C) 2009-2012 Carl Hetherington <carl@carlh.net>
4  * Copyright (C) 2009-2016 Paul Davis <paul@linuxaudiosystems.com>
5  * Copyright (C) 2014-2017 Robin Gareus <robin@gareus.org>
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License along
18  * with this program; if not, write to the Free Software Foundation, Inc.,
19  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20  */
21
22 #include <iostream>
23
24 #include "ardour/route_group.h"
25 #include "ardour/session.h"
26
27 #include <gtkmm/table.h>
28 #include <gtkmm/stock.h>
29 #include <gtkmm/messagedialog.h>
30
31 #include "route_group_dialog.h"
32 #include "group_tabs.h"
33 #include "utils.h"
34
35 #include "pbd/i18n.h"
36
37 using namespace Gtk;
38 using namespace ARDOUR;
39 using namespace ARDOUR_UI_UTILS;
40 using namespace std;
41 using namespace PBD;
42
43 RouteGroupDialog::RouteGroupDialog (RouteGroup* g, bool creating_new)
44         : ArdourDialog (_("Track/bus Group"))
45         , _group (g)
46         , _initial_name (g->name ())
47         , _active (_("Active"))
48         , _gain (_("Gain"))
49         , _relative (_("Relative"))
50         , _mute (_("Muting"))
51         , _solo (_("Soloing"))
52         , _rec_enable (_("Record enable"))
53         , _select (_("Selection"))
54         , _route_active (_("Active state"))
55         , _share_color (_("Color"))
56         , _share_monitoring (_("Monitoring"))
57 {
58         set_skip_taskbar_hint (true);
59         set_resizable (true);
60         set_name (N_("RouteGroupDialog"));
61
62         VBox* main_vbox = manage (new VBox);
63         Gtk::Label* l;
64
65         get_vbox()->set_spacing (4);
66
67         main_vbox->set_spacing (18);
68         main_vbox->set_border_width (5);
69
70         HBox* hbox = manage (new HBox);
71         hbox->set_spacing (6);
72         l = manage (new Label (_("Name:"), Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, false ));
73
74         hbox->pack_start (*l, false, true);
75         hbox->pack_start (_name, true, true);
76
77         VBox* top_vbox = manage (new VBox);
78         top_vbox->set_spacing (4);
79
80         top_vbox->pack_start (*hbox, false, true);
81         top_vbox->pack_start (_active);
82
83         l = manage (new Label (_("Color"), Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, false));
84         hbox = manage (new HBox);
85         hbox->set_spacing (12);
86         hbox->pack_start (*l, false, false);
87         hbox->pack_start (_color, false, false);
88         top_vbox->pack_start (*hbox, false, false);
89
90         main_vbox->pack_start (*top_vbox, false, false);
91
92         _active.set_active (_group->is_active ());
93
94         Gdk::Color c;
95         set_color_from_rgba (c, GroupTabs::group_color (_group));
96         _color.set_color (c);
97
98         VBox* options_box = manage (new VBox);
99         options_box->set_spacing (6);
100
101         l = manage (new Label (_("<b>Sharing</b>"), Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, false ));
102         l->set_use_markup ();
103         options_box->pack_start (*l, false, true);
104
105         _gain.set_active (_group->is_gain());
106         _relative.set_active (_group->is_relative());
107         _mute.set_active (_group->is_mute());
108         _solo.set_active (_group->is_solo());
109         _rec_enable.set_active (_group->is_recenable());
110         _select.set_active (_group->is_select());
111         _route_active.set_active (_group->is_route_active());
112         _share_color.set_active (_group->is_color());
113         _share_monitoring.set_active (_group->is_monitoring());
114
115         if (_group->name ().empty()) {
116                 _initial_name = "1";
117                 while (!unique_name (_initial_name)) {
118                         _initial_name = bump_name_number (_initial_name);
119                 }
120                 _name.set_text (_initial_name);
121                 update();
122         } else {
123                 _name.set_text (_initial_name);
124         }
125
126         _name.signal_activate ().connect (sigc::bind (sigc::mem_fun (*this, &Dialog::response), RESPONSE_OK));
127         _name.signal_changed().connect (sigc::mem_fun (*this, &RouteGroupDialog::update));
128         _active.signal_toggled().connect (sigc::mem_fun (*this, &RouteGroupDialog::update));
129         _color.signal_color_set().connect (sigc::mem_fun (*this, &RouteGroupDialog::update));
130         _gain.signal_toggled().connect (sigc::mem_fun (*this, &RouteGroupDialog::update));
131         _relative.signal_toggled().connect (sigc::mem_fun (*this, &RouteGroupDialog::update));
132         _mute.signal_toggled().connect (sigc::mem_fun (*this, &RouteGroupDialog::update));
133         _solo.signal_toggled().connect (sigc::mem_fun (*this, &RouteGroupDialog::update));
134         _rec_enable.signal_toggled().connect (sigc::mem_fun (*this, &RouteGroupDialog::update));
135         _select.signal_toggled().connect (sigc::mem_fun (*this, &RouteGroupDialog::update));
136         _route_active.signal_toggled().connect (sigc::mem_fun (*this, &RouteGroupDialog::update));
137         _share_color.signal_toggled().connect (sigc::mem_fun (*this, &RouteGroupDialog::update));
138         _share_monitoring.signal_toggled().connect (sigc::mem_fun (*this, &RouteGroupDialog::update));
139
140         gain_toggled ();
141
142         Table* table = manage (new Table (11, 4, false));
143         table->set_row_spacings (6);
144
145         l = manage (new Label ("", Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, false));
146         l->set_padding (8, 0);
147         table->attach (*l, 0, 1, 0, 8, Gtk::FILL, Gtk::FILL, 0, 0);
148
149         table->attach (_gain, 1, 3, 1, 2, Gtk::FILL, Gtk::FILL, 0, 0);
150
151         l = manage (new Label ("", Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, false));
152         l->set_padding (0, 0);
153         table->attach (*l, 1, 2, 2, 3, Gtk::FILL, Gtk::FILL, 0, 0);
154         table->attach (_relative, 2, 3, 2, 3, Gtk::FILL, Gtk::FILL, 0, 0);
155
156         table->attach (_mute, 1, 3, 3, 4, Gtk::FILL, Gtk::FILL, 0, 0);
157         table->attach (_solo, 1, 3, 4, 5, Gtk::FILL, Gtk::FILL, 0, 0);
158         table->attach (_rec_enable, 1, 3, 5, 6, Gtk::FILL, Gtk::FILL, 0, 0);
159         table->attach (_select, 1, 3, 6, 7, Gtk::FILL, Gtk::FILL, 0, 0);
160         table->attach (_route_active, 1, 3, 7, 8, Gtk::FILL, Gtk::FILL, 0, 0);
161         table->attach (_share_color, 1, 3, 8, 9, Gtk::FILL, Gtk::FILL, 0, 0);
162         table->attach (_share_monitoring, 1, 3, 9, 10, Gtk::FILL, Gtk::FILL, 0, 0);
163
164         options_box->pack_start (*table, false, true);
165         main_vbox->pack_start (*options_box, false, true);
166
167         get_vbox()->pack_start (*main_vbox, false, false);
168
169         _gain.signal_toggled().connect(sigc::mem_fun (*this, &RouteGroupDialog::gain_toggled));
170
171         if (creating_new) {
172                 add_button (Stock::CANCEL, RESPONSE_CANCEL);
173                 add_button (Stock::NEW, RESPONSE_OK);
174                 set_default_response (RESPONSE_OK);
175         }
176
177         show_all_children ();
178 }
179
180 bool
181 RouteGroupDialog::name_check () const
182 {
183         if (unique_name (_name.get_text())) {
184                 /* not cancelled and the name is ok, so all is well */
185                 return true;
186         }
187
188         _group->set_name (_initial_name);
189
190         MessageDialog msg (
191                 _("The group name is not unique. Please use a different name."),
192                 false,
193                 Gtk::MESSAGE_ERROR,
194                 Gtk::BUTTONS_OK,
195                 true
196                 );
197
198         msg.set_position (WIN_POS_MOUSE);
199         msg.run ();
200
201         return false;
202 }
203
204 void
205 RouteGroupDialog::update ()
206 {
207         PropertyList plist;
208
209         plist.add (Properties::group_gain, _gain.get_active());
210         plist.add (Properties::group_recenable, _rec_enable.get_active());
211         plist.add (Properties::group_mute, _mute.get_active());
212         plist.add (Properties::group_solo, _solo.get_active ());
213         plist.add (Properties::group_select, _select.get_active());
214         plist.add (Properties::group_route_active, _route_active.get_active());
215         plist.add (Properties::group_relative, _relative.get_active());
216         plist.add (Properties::group_color, _share_color.get_active());
217         plist.add (Properties::group_monitoring, _share_monitoring.get_active());
218         plist.add (Properties::active, _active.get_active());
219         plist.add (Properties::name, string (_name.get_text()));
220
221         _group->apply_changes (plist);
222
223         GroupTabs::set_group_color (_group, gdk_color_to_rgba (_color.get_color ()));
224 }
225
226 void
227 RouteGroupDialog::gain_toggled ()
228 {
229         _relative.set_sensitive (_gain.get_active ());
230 }
231
232 /** @return true if the current group's name is unique accross the session */
233 bool
234 RouteGroupDialog::unique_name (std::string const name) const
235 {
236         if (name.empty()) return false; // do not allow empty name, empty means unset.
237         list<RouteGroup*> route_groups = _group->session().route_groups ();
238         list<RouteGroup*>::iterator i = route_groups.begin ();
239         while (i != route_groups.end() && ((*i)->name() != name || *i == _group)) {
240                 ++i;
241         }
242
243         return (i == route_groups.end ());
244 }