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