2 Copyright (C) 2003 Paul Davis
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.
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.
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.
23 #include <sigc++/bind.h>
24 #include <gtkmm/stock.h>
25 #include <gtkmm/separator.h>
26 #include <gtkmm/table.h>
28 #include "pbd/error.h"
29 #include "pbd/convert.h"
30 #include "gtkmm2ext/utils.h"
31 #include "ardour/profile.h"
32 #include "ardour/template_utils.h"
33 #include "ardour/route_group.h"
34 #include "ardour/session.h"
37 #include "add_route_dialog.h"
38 #include "route_group_dialog.h"
42 using namespace Gtkmm2ext;
46 using namespace ARDOUR;
48 static const char* track_mode_names[] = {
55 static const char* bus_mode_names[] = {
61 std::vector<std::string> AddRouteDialog::channel_combo_strings;
62 std::vector<std::string> AddRouteDialog::track_mode_strings;
63 std::vector<std::string> AddRouteDialog::bus_mode_strings;
65 AddRouteDialog::AddRouteDialog (Session & s)
66 : ArdourDialog (X_("add route dialog"))
68 , routes_adjustment (1, 1, 128, 1, 4)
69 , routes_spinner (routes_adjustment)
70 , mode_label (_("Track mode:"))
72 if (track_mode_strings.empty()) {
73 track_mode_strings = I18N (track_mode_names);
75 if (ARDOUR::Profile->get_sae()) {
76 /* remove all but the first track mode (Normal) */
78 while (track_mode_strings.size() > 1) {
79 track_mode_strings.pop_back();
84 if (bus_mode_strings.empty()) {
85 bus_mode_strings = I18N (bus_mode_names);
88 set_name ("AddRouteDialog");
89 set_position (Gtk::WIN_POS_MOUSE);
91 set_skip_taskbar_hint (true);
92 set_resizable (false);
94 set_title (_("Add Track/Bus"));
96 name_template_entry.set_name (X_("AddRouteDialogNameTemplateEntry"));
97 routes_spinner.set_name (X_("AddRouteDialogSpinner"));
98 channel_combo.set_name (X_("ChannelCountSelector"));
99 mode_combo.set_name (X_("ChannelCountSelector"));
101 refill_channel_setups ();
102 refill_route_groups ();
103 set_popdown_strings (mode_combo, track_mode_strings, true);
105 channel_combo.set_active_text (channel_combo_strings.front());
106 mode_combo.set_active_text (track_mode_strings.front());
108 track_bus_combo.append_text (_("tracks"));
109 track_bus_combo.append_text (_("busses"));
110 track_bus_combo.set_active (0);
112 VBox* vbox = manage (new VBox);
115 get_vbox()->set_spacing (4);
117 vbox->set_spacing (18);
118 vbox->set_border_width (5);
120 HBox *type_hbox = manage (new HBox);
121 type_hbox->set_spacing (6);
123 /* track/bus choice */
125 type_hbox->pack_start (*manage (new Label (_("Add:"))));
126 type_hbox->pack_start (routes_spinner);
127 type_hbox->pack_start (track_bus_combo);
129 vbox->pack_start (*type_hbox, false, true);
131 VBox* options_box = manage (new VBox);
132 Table *table2 = manage (new Table (3, 3, false));
134 options_box->set_spacing (6);
135 table2->set_row_spacings (6);
136 table2->set_col_spacing (1, 6);
138 l = manage (new Label (_("<b>Options</b>"), Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, false));
139 l->set_use_markup ();
140 options_box->pack_start (*l, false, true);
142 l = manage (new Label ("", Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, false));
143 l->set_padding (8, 0);
144 table2->attach (*l, 0, 1, 0, 3, Gtk::FILL, Gtk::FILL, 0, 0);
146 /* Route configuration */
148 l = manage (new Label (_("Configuration:"), Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, false));
149 table2->attach (*l, 1, 2, 0, 1, Gtk::FILL, Gtk::EXPAND, 0, 0);
150 table2->attach (channel_combo, 2, 3, 0, 1, Gtk::FILL, Gtk::EXPAND & Gtk::FILL, 0, 0);
152 if (!ARDOUR::Profile->get_sae ()) {
156 mode_label.set_alignment (Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER);
157 table2->attach (mode_label, 1, 2, 1, 2, Gtk::FILL, Gtk::EXPAND, 0, 0);
158 table2->attach (mode_combo, 2, 3, 1, 2, Gtk::FILL, Gtk::EXPAND & Gtk::FILL, 0, 0);
164 l = manage (new Label (_("Group:"), Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, false));
165 table2->attach (*l, 1, 2, 2, 3, Gtk::FILL, Gtk::EXPAND, 0, 0);
166 table2->attach (route_group_combo, 2, 3, 2, 3, Gtk::FILL, Gtk::EXPAND & Gtk::FILL, 0, 0);
168 options_box->pack_start (*table2, false, true);
169 vbox->pack_start (*options_box, false, true);
171 get_vbox()->pack_start (*vbox, false, false);
173 track_bus_combo.signal_changed().connect (sigc::mem_fun (*this, &AddRouteDialog::track_type_chosen));
174 channel_combo.set_row_separator_func (sigc::mem_fun (*this, &AddRouteDialog::channel_separator));
175 route_group_combo.set_row_separator_func (sigc::mem_fun (*this, &AddRouteDialog::route_separator));
176 route_group_combo.signal_changed ().connect (sigc::mem_fun (*this, &AddRouteDialog::group_changed));
178 show_all_children ();
180 /* track template info will be managed whenever
181 this dialog is shown, via ::on_show()
184 add_button (Stock::CANCEL, RESPONSE_CANCEL);
185 add_button (Stock::ADD, RESPONSE_ACCEPT);
187 track_type_chosen ();
190 AddRouteDialog::~AddRouteDialog ()
195 AddRouteDialog::track_type_chosen ()
198 mode_label.set_text (_("Track mode:"));
199 set_popdown_strings (mode_combo, track_mode_strings);
200 mode_combo.set_active_text (track_mode_strings.front());
202 mode_label.set_text (_("Bus type:"));
203 set_popdown_strings (mode_combo, bus_mode_strings);
204 mode_combo.set_active_text (bus_mode_strings.front());
210 AddRouteDialog::track ()
212 return track_bus_combo.get_active_row_number () == 0;
216 AddRouteDialog::aux ()
218 return !track() && mode_combo.get_active_row_number () == 0;
222 AddRouteDialog::type ()
224 return (channel_combo.get_active_text() == _("MIDI"))
225 ? ARDOUR::DataType::MIDI
226 : ARDOUR::DataType::AUDIO;
230 AddRouteDialog::name_template ()
232 return name_template_entry.get_text ();
236 AddRouteDialog::count ()
238 return (int) floor (routes_adjustment.get_value ());
242 AddRouteDialog::mode ()
244 if (ARDOUR::Profile->get_sae()) {
245 return ARDOUR::Normal;
248 Glib::ustring str = mode_combo.get_active_text();
249 if (str == _("Normal")) {
250 return ARDOUR::Normal;
251 } else if (str == _("Non Layered")){
252 return ARDOUR::NonLayered;
253 } else if (str == _("Tape")) {
254 return ARDOUR::Destructive;
256 fatal << string_compose (X_("programming error: unknown track mode in add route dialog combo = %1"), str)
261 return ARDOUR::Normal;
265 AddRouteDialog::channels ()
267 string str = channel_combo.get_active_text();
269 for (ChannelSetups::iterator i = channel_setups.begin(); i != channel_setups.end(); ++i) {
270 if (str == (*i).name) {
271 return (*i).channels;
279 AddRouteDialog::track_template ()
281 string str = channel_combo.get_active_text();
283 for (ChannelSetups::iterator i = channel_setups.begin(); i != channel_setups.end(); ++i) {
284 if (str == (*i).name) {
285 return (*i).template_path;
293 AddRouteDialog::on_show ()
295 refill_channel_setups ();
296 refill_route_groups ();
302 AddRouteDialog::refill_channel_setups ()
306 route_templates.clear ();
307 channel_combo_strings.clear ();
308 channel_setups.clear ();
310 chn.name = _("Mono");
312 channel_setups.push_back (chn);
314 chn.name = _("Stereo");
316 channel_setups.push_back (chn);
318 chn.name = "separator";
319 channel_setups.push_back (chn);
321 chn.name = X_("MIDI");
323 channel_setups.push_back (chn);
325 chn.name = "separator";
326 channel_setups.push_back (chn);
328 ARDOUR::find_route_templates (route_templates);
330 if (!ARDOUR::Profile->get_sae()) {
331 if (!route_templates.empty()) {
333 for (vector<TemplateInfo>::iterator x = route_templates.begin(); x != route_templates.end(); ++x) {
336 chn.template_path = x->path;
337 channel_setups.push_back (chn);
341 /* clear template path for the rest */
343 chn.template_path = "";
345 chn.name = _("3 Channel");
347 channel_setups.push_back (chn);
349 chn.name = _("4 Channel");
351 channel_setups.push_back (chn);
353 chn.name = _("5 Channel");
355 channel_setups.push_back (chn);
357 chn.name = _("6 Channel");
359 channel_setups.push_back (chn);
361 chn.name = _("8 Channel");
363 channel_setups.push_back (chn);
365 chn.name = _("12 Channel");
367 channel_setups.push_back (chn);
369 chn.name = X_("Custom");
371 channel_setups.push_back (chn);
374 for (ChannelSetups::iterator i = channel_setups.begin(); i != channel_setups.end(); ++i) {
375 channel_combo_strings.push_back ((*i).name);
378 set_popdown_strings (channel_combo, channel_combo_strings, true);
379 channel_combo.set_active_text (channel_combo_strings.front());
383 AddRouteDialog::add_route_group (RouteGroup* g)
385 route_group_combo.insert_text (3, g->name ());
389 AddRouteDialog::route_group ()
391 if (route_group_combo.get_active_row_number () == 2) {
395 return _session.route_group_by_name (route_group_combo.get_active_text());
399 AddRouteDialog::refill_route_groups ()
401 route_group_combo.clear ();
402 route_group_combo.append_text (_("New group..."));
404 route_group_combo.append_text ("separator");
406 route_group_combo.append_text (_("No group"));
408 _session.foreach_route_group (sigc::mem_fun (*this, &AddRouteDialog::add_route_group));
410 route_group_combo.set_active (2);
414 AddRouteDialog::group_changed ()
416 if (route_group_combo.get_active_text () == _("New group...")) {
417 RouteGroup* g = new RouteGroup (_session, "", RouteGroup::Active);
419 RouteGroupDialog d (g, Gtk::Stock::NEW);
420 int const r = d.do_run ();
422 if (r == Gtk::RESPONSE_OK) {
423 _session.add_route_group (g);
425 route_group_combo.set_active (3);
429 route_group_combo.set_active (2);
435 AddRouteDialog::channel_separator (const Glib::RefPtr<Gtk::TreeModel> &, const Gtk::TreeModel::iterator &i)
437 channel_combo.set_active (i);
439 return channel_combo.get_active_text () == "separator";
443 AddRouteDialog::route_separator (const Glib::RefPtr<Gtk::TreeModel> &, const Gtk::TreeModel::iterator &i)
445 route_group_combo.set_active (i);
447 return route_group_combo.get_active_text () == "separator";