Give route groups their own colour, settable from the route
[ardour.git] / gtk2_ardour / route_group_dialog.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/table.h>
21 #include <gtkmm/stock.h>
22 #include <gtkmm/messagedialog.h>
23 #include "ardour/route_group.h"
24 #include "ardour/session.h"
25 #include "route_group_dialog.h"
26 #include "group_tabs.h"
27 #include "i18n.h"
28 #include <iostream>
29
30 using namespace Gtk;
31 using namespace ARDOUR;
32 using namespace std;
33 using namespace PBD;
34
35 RouteGroupDialog::RouteGroupDialog (RouteGroup* g, bool creating_new)
36         : ArdourDialog (_("Route Group"))
37         , _group (g)
38         , _initial_name (g->name ())
39         , _active (_("Active"))
40         , _gain (_("Gain"))
41         , _relative (_("Relative"))
42         , _mute (_("Muting"))
43         , _solo (_("Soloing"))
44         , _rec_enable (_("Record enable"))
45         , _select (_("Selection"))
46         , _edit (_("Editing"))
47         , _route_active (_("Route active state"))
48 {
49         set_modal (true);
50         set_skip_taskbar_hint (true);
51         set_resizable (false);
52         set_position (Gtk::WIN_POS_MOUSE);
53         set_name (N_("RouteGroupDialog"));
54
55         VBox* main_vbox = manage (new VBox);
56         Gtk::Label* l;
57
58         get_vbox()->set_spacing (4);
59
60         main_vbox->set_spacing (18);
61         main_vbox->set_border_width (5);
62
63         HBox* hbox = manage (new HBox);
64         hbox->set_spacing (6);
65         l = manage (new Label (_("Name:"), Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, false ));
66
67         hbox->pack_start (*l, false, true);
68         hbox->pack_start (_name, true, true);
69
70         VBox* top_vbox = manage (new VBox);
71         top_vbox->set_spacing (4);
72
73         top_vbox->pack_start (*hbox, false, true);
74         top_vbox->pack_start (_active);
75
76         main_vbox->pack_start (*top_vbox, false, false);
77
78         _name.set_text (_group->name ());
79         _active.set_active (_group->is_active ());
80
81         VBox* options_box = manage (new VBox);
82         options_box->set_spacing (6);
83         
84         l = manage (new Label (_("<b>Sharing</b>"), Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, false ));
85         l->set_use_markup ();
86         options_box->pack_start (*l, false, true);
87
88         _name.signal_activate ().connect (sigc::bind (sigc::mem_fun (*this, &Dialog::response), RESPONSE_OK));
89
90         _gain.set_active (_group->is_gain());
91         _relative.set_active (_group->is_relative());
92         _mute.set_active (_group->is_mute());
93         _solo.set_active (_group->is_solo());
94         _rec_enable.set_active (_group->is_recenable());
95         _select.set_active (_group->is_select());
96         _edit.set_active (_group->is_edit());
97         _route_active.set_active (_group->is_route_active());
98         _color.set_color (GroupTabs::group_color (_group));
99
100         _name.signal_changed().connect (sigc::mem_fun (*this, &RouteGroupDialog::update));
101         _active.signal_toggled().connect (sigc::mem_fun (*this, &RouteGroupDialog::update));
102         _gain.signal_toggled().connect (sigc::mem_fun (*this, &RouteGroupDialog::update));
103         _relative.signal_toggled().connect (sigc::mem_fun (*this, &RouteGroupDialog::update));
104         _mute.signal_toggled().connect (sigc::mem_fun (*this, &RouteGroupDialog::update));
105         _solo.signal_toggled().connect (sigc::mem_fun (*this, &RouteGroupDialog::update));
106         _rec_enable.signal_toggled().connect (sigc::mem_fun (*this, &RouteGroupDialog::update));
107         _select.signal_toggled().connect (sigc::mem_fun (*this, &RouteGroupDialog::update));
108         _edit.signal_toggled().connect (sigc::mem_fun (*this, &RouteGroupDialog::update));
109         _route_active.signal_toggled().connect (sigc::mem_fun (*this, &RouteGroupDialog::update));
110         _color.signal_color_set().connect (sigc::mem_fun (*this, &RouteGroupDialog::update));
111
112         gain_toggled ();
113
114         Table* table = manage (new Table (11, 4, false));
115         table->set_row_spacings (6);
116
117         l = manage (new Label ("", Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, false));
118         l->set_padding (8, 0);
119         table->attach (*l, 0, 1, 0, 8, Gtk::FILL, Gtk::FILL, 0, 0);
120
121         table->attach (_gain, 1, 3, 1, 2, Gtk::FILL, Gtk::FILL, 0, 0);
122
123         l = manage (new Label ("", Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, false));
124         l->set_padding (0, 0);
125         table->attach (*l, 1, 2, 2, 3, Gtk::FILL, Gtk::FILL, 0, 0);
126         table->attach (_relative, 2, 3, 2, 3, Gtk::FILL, Gtk::FILL, 0, 0);
127
128         table->attach (_mute, 1, 3, 3, 4, Gtk::FILL, Gtk::FILL, 0, 0);
129         table->attach (_solo, 1, 3, 4, 5, Gtk::FILL, Gtk::FILL, 0, 0);
130         table->attach (_rec_enable, 1, 3, 5, 6, Gtk::FILL, Gtk::FILL, 0, 0);
131         table->attach (_select, 1, 3, 6, 7, Gtk::FILL, Gtk::FILL, 0, 0);
132         table->attach (_edit, 1, 3, 7, 8, Gtk::FILL, Gtk::FILL, 0, 0);
133         table->attach (_route_active, 1, 3, 8, 9, Gtk::FILL, Gtk::FILL, 0, 0);
134
135         HBox* b = manage (new HBox);
136         l = manage (new Label (_("Color"), Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, false));
137         b->pack_start (*l, Gtk::SHRINK, Gtk::SHRINK);
138         b->pack_start (_color, Gtk::FILL, Gtk::FILL);
139         table->attach (*b, 1, 3, 10, 11, Gtk::FILL, Gtk::FILL, 0, 0);
140
141         options_box->pack_start (*table, false, true);
142         main_vbox->pack_start (*options_box, false, true);
143
144         get_vbox()->pack_start (*main_vbox, false, false);
145
146         _gain.signal_toggled().connect(sigc::mem_fun (*this, &RouteGroupDialog::gain_toggled));
147
148         if (creating_new) {
149                 add_button (Stock::CANCEL, RESPONSE_CANCEL);
150                 add_button (Stock::NEW, RESPONSE_OK);
151                 set_default_response (RESPONSE_OK);
152         } else {
153                 add_button (Stock::CLOSE, RESPONSE_CLOSE);
154                 set_default_response (RESPONSE_CLOSE);
155         }
156
157         show_all_children ();
158 }
159
160 /** @return true if the route group edit was cancelled, otherwise false */
161 bool
162 RouteGroupDialog::do_run ()
163 {
164         while (1) {
165                 int const r = run ();
166                 if (r == Gtk::RESPONSE_CANCEL) {
167                         /* cancel, so just bail now */
168                         return Gtk::RESPONSE_CANCEL;
169                 }
170
171                 if (unique_name ()) {
172                         /* not cancelled and the name is ok, so all is well */
173                         return false;
174                 }
175
176                 _group->set_name (_initial_name);
177                 MessageDialog msg (
178                         _("A route group of this name already exists.  Please use a different name."),
179                         false,
180                         Gtk::MESSAGE_ERROR,
181                         Gtk::BUTTONS_OK,
182                         true
183                         );
184
185                 msg.run ();
186         }
187
188         /* NOTREACHED */
189         return false;
190 }
191
192 void
193 RouteGroupDialog::update ()
194 {
195         PropertyList plist;
196
197         plist.add (Properties::gain, _gain.get_active());
198         plist.add (Properties::recenable, _rec_enable.get_active());
199         plist.add (Properties::mute, _mute.get_active());
200         plist.add (Properties::solo, _solo.get_active ());
201         plist.add (Properties::select, _select.get_active());
202         plist.add (Properties::edit, _edit.get_active());
203         plist.add (Properties::route_active, _route_active.get_active());
204         plist.add (Properties::relative, _relative.get_active());
205         plist.add (Properties::active, _active.get_active());
206         plist.add (Properties::name, string (_name.get_text()));
207
208         GroupTabs::set_group_color (_group, _color.get_color ());
209         
210         _group->apply_changes (plist);
211 }
212
213 void
214 RouteGroupDialog::gain_toggled ()
215 {
216         _relative.set_sensitive (_gain.get_active ());
217 }
218
219 /** @return true if the current group's name is unique accross the session */
220 bool
221 RouteGroupDialog::unique_name () const
222 {
223         list<RouteGroup*> route_groups = _group->session().route_groups ();
224         list<RouteGroup*>::iterator i = route_groups.begin ();
225         while (i != route_groups.end() && ((*i)->name() != _name.get_text() || *i == _group)) {
226                 ++i;
227         }
228
229         return (i == route_groups.end ());
230 }