summaryrefslogtreecommitdiff
path: root/gtk2_ardour/route_group_dialog.cc
blob: 94a36d1605f1397c4a25f8a7d576b74214066a01 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
/*
    Copyright (C) 2009 Paul Davis

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

*/

#include <gtkmm/table.h>
#include <gtkmm/stock.h>
#include <gtkmm/messagedialog.h>
#include "ardour/route_group.h"
#include "ardour/session.h"
#include "route_group_dialog.h"
#include "i18n.h"
#include <iostream>

using namespace Gtk;
using namespace ARDOUR;
using namespace std;
using namespace PBD;

RouteGroupDialog::RouteGroupDialog (RouteGroup* g, bool creating_new)
	: ArdourDialog (_("Route Group"))
	, _group (g)
	, _initial_name (g->name ())
	, _active (_("Active"))
	, _gain (_("Gain"))
	, _relative (_("Relative"))
	, _mute (_("Muting"))
	, _solo (_("Soloing"))
	, _rec_enable (_("Record enable"))
	, _select (_("Selection"))
	, _edit (_("Editing"))
	, _route_active (_("Route active state"))
{
	set_modal (true);
	set_skip_taskbar_hint (true);
	set_resizable (false);
	set_position (Gtk::WIN_POS_MOUSE);
	set_name (N_("RouteGroupDialog"));

	VBox* vbox = manage (new VBox);
	Gtk::Label* l;

	get_vbox()->set_spacing (4);

	vbox->set_spacing (18);
	vbox->set_border_width (5);

	HBox* hbox = manage (new HBox);
	hbox->set_spacing (6);
	l = manage (new Label (_("Name:"), Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, false ));

	hbox->pack_start (*l, false, true);
	hbox->pack_start (_name, true, true);

	vbox->pack_start (*hbox, false, true);

	VBox* options_box = manage (new VBox);
	options_box->set_spacing (6);

	l = manage (new Label (_("<b>Sharing</b>"), Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, false ));
	l->set_use_markup ();
	options_box->pack_start (*l, false, true);

	_name.set_text (_group->name ());
	_active.set_active (_group->is_active ());

	_name.signal_activate ().connect (sigc::bind (sigc::mem_fun (*this, &Dialog::response), RESPONSE_OK));

	_gain.set_active (_group->is_gain());
	_relative.set_active (_group->is_relative());
	_mute.set_active (_group->is_mute());
	_solo.set_active (_group->is_solo());
	_rec_enable.set_active (_group->is_recenable());
	_select.set_active (_group->is_select());
	_edit.set_active (_group->is_edit());
	_route_active.set_active (_group->is_route_active());

	_name.signal_changed().connect (sigc::mem_fun (*this, &RouteGroupDialog::update));
	_active.signal_toggled().connect (sigc::mem_fun (*this, &RouteGroupDialog::update));
	_gain.signal_toggled().connect (sigc::mem_fun (*this, &RouteGroupDialog::update));
 	_relative.signal_toggled().connect (sigc::mem_fun (*this, &RouteGroupDialog::update));
 	_mute.signal_toggled().connect (sigc::mem_fun (*this, &RouteGroupDialog::update));
 	_solo.signal_toggled().connect (sigc::mem_fun (*this, &RouteGroupDialog::update));
 	_rec_enable.signal_toggled().connect (sigc::mem_fun (*this, &RouteGroupDialog::update));
 	_select.signal_toggled().connect (sigc::mem_fun (*this, &RouteGroupDialog::update));
 	_edit.signal_toggled().connect (sigc::mem_fun (*this, &RouteGroupDialog::update));
 	_route_active.signal_toggled().connect (sigc::mem_fun (*this, &RouteGroupDialog::update));

	gain_toggled ();

	Table* table = manage (new Table (8, 3, false));
	table->set_row_spacings	(6);

	l = manage (new Label ("", Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, false));
	l->set_padding (8, 0);
	table->attach (*l, 0, 1, 0, 8, Gtk::FILL, Gtk::FILL, 0, 0);

	table->attach (_active, 1, 3, 0, 1, Gtk::FILL, Gtk::FILL, 0, 0);
	table->attach (_gain, 1, 3, 1, 2, Gtk::FILL, Gtk::FILL, 0, 0);

	l = manage (new Label ("", Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, false));
	l->set_padding (0, 0);
	table->attach (*l, 1, 2, 2, 3, Gtk::FILL, Gtk::FILL, 0, 0);
	table->attach (_relative, 2, 3, 2, 3, Gtk::FILL, Gtk::FILL, 0, 0);

	table->attach (_mute, 1, 3, 3, 4, Gtk::FILL, Gtk::FILL, 0, 0);
	table->attach (_solo, 1, 3, 4, 5, Gtk::FILL, Gtk::FILL, 0, 0);
	table->attach (_rec_enable, 1, 3, 5, 6, Gtk::FILL, Gtk::FILL, 0, 0);
	table->attach (_select, 1, 3, 6, 7, Gtk::FILL, Gtk::FILL, 0, 0);
	table->attach (_edit, 1, 3, 7, 8, Gtk::FILL, Gtk::FILL, 0, 0);
	table->attach (_route_active, 1, 3, 8, 9, Gtk::FILL, Gtk::FILL, 0, 0);

	options_box->pack_start (*table, false, true);
	vbox->pack_start (*options_box, false, true);

	get_vbox()->pack_start (*vbox, false, false);

	_gain.signal_toggled().connect(sigc::mem_fun (*this, &RouteGroupDialog::gain_toggled));

	if (creating_new) {
		add_button (Stock::CANCEL, RESPONSE_CANCEL);
		add_button (Stock::NEW, RESPONSE_OK);
		set_default_response (RESPONSE_OK);
	} else {
		add_button (Stock::CLOSE, RESPONSE_CLOSE);
		set_default_response (RESPONSE_CLOSE);
	}

	show_all_children ();
}

/** @return true if the route group edit was cancelled, otherwise false */
bool
RouteGroupDialog::do_run ()
{
	while (1) {
		int const r = run ();
		if (r == Gtk::RESPONSE_CANCEL) {
			/* cancel, so just bail now */
			return Gtk::RESPONSE_CANCEL;
		}

		if (unique_name ()) {
			/* not cancelled and the name is ok, so all is well */
			return false;
		}

		_group->set_name (_initial_name);
		MessageDialog msg (
			_("A route group of this name already exists.  Please use a different name."),
			false,
			Gtk::MESSAGE_ERROR,
			Gtk::BUTTONS_OK,
			true
			);

		msg.run ();
	}

	/* NOTREACHED */
	return false;
}

void
RouteGroupDialog::update ()
{
	PropertyList plist;

	plist.add (Properties::gain, _gain.get_active());
	plist.add (Properties::recenable, _rec_enable.get_active());
	plist.add (Properties::mute, _mute.get_active());
	plist.add (Properties::solo, _solo.get_active ());
	plist.add (Properties::select, _select.get_active());
	plist.add (Properties::edit, _edit.get_active());
	plist.add (Properties::route_active, _route_active.get_active());
	plist.add (Properties::relative, _relative.get_active());
	plist.add (Properties::active, _active.get_active());
	plist.add (Properties::name, string (_name.get_text()));

	_group->apply_changes (plist);
}

void
RouteGroupDialog::gain_toggled ()
{
	_relative.set_sensitive (_gain.get_active ());
}

/** @return true if the current group's name is unique accross the session */
bool
RouteGroupDialog::unique_name () const
{
	list<RouteGroup*> route_groups = _group->session().route_groups ();
	list<RouteGroup*>::iterator i = route_groups.begin ();
	while (i != route_groups.end() && ((*i)->name() != _name.get_text() || *i == _group)) {
		++i;
	}

	return (i == route_groups.end ());
}