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