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;
45 using namespace ARDOUR;
47 std::vector<std::string> AddRouteDialog::channel_combo_strings;
49 AddRouteDialog::AddRouteDialog (Session* s)
50 : ArdourDialog (_("Add Track or Bus"))
51 , routes_adjustment (1, 1, 128, 1, 4)
52 , routes_spinner (routes_adjustment)
53 , mode_label (_("Track mode:"))
57 set_name ("AddRouteDialog");
58 set_position (Gtk::WIN_POS_MOUSE);
60 set_skip_taskbar_hint (true);
61 set_resizable (false);
63 name_template_entry.set_name (X_("AddRouteDialogNameTemplateEntry"));
64 routes_spinner.set_name (X_("AddRouteDialogSpinner"));
65 channel_combo.set_name (X_("ChannelCountSelector"));
66 mode_combo.set_name (X_("ChannelCountSelector"));
68 refill_channel_setups ();
69 refill_route_groups ();
70 refill_track_modes ();
72 channel_combo.set_active_text (channel_combo_strings.front());
74 track_bus_combo.append_text (_("tracks"));
75 track_bus_combo.append_text (_("busses"));
76 track_bus_combo.set_active (0);
78 VBox* vbox = manage (new VBox);
81 get_vbox()->set_spacing (4);
83 vbox->set_spacing (18);
84 vbox->set_border_width (5);
86 HBox *type_hbox = manage (new HBox);
87 type_hbox->set_spacing (6);
89 /* track/bus choice */
91 type_hbox->pack_start (*manage (new Label (_("Add:"))));
92 type_hbox->pack_start (routes_spinner);
93 type_hbox->pack_start (track_bus_combo);
95 vbox->pack_start (*type_hbox, false, true);
97 VBox* options_box = manage (new VBox);
98 Table *table2 = manage (new Table (3, 3, false));
100 options_box->set_spacing (6);
101 table2->set_row_spacings (6);
102 table2->set_col_spacing (1, 6);
104 l = manage (new Label (_("<b>Options</b>"), Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, false));
105 l->set_use_markup ();
106 options_box->pack_start (*l, false, true);
108 l = manage (new Label ("", Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, false));
109 l->set_padding (8, 0);
110 table2->attach (*l, 0, 1, 0, 3, Gtk::FILL, Gtk::FILL, 0, 0);
114 l = manage (new Label (_("Name:"), Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, false));
115 table2->attach (*l, 1, 2, n, n + 1, Gtk::FILL, Gtk::EXPAND, 0, 0);
116 table2->attach (name_template_entry, 2, 3, n, n + 1, Gtk::FILL, Gtk::EXPAND | Gtk::FILL, 0, 0);
119 /* Route configuration */
121 l = manage (new Label (_("Configuration:"), Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, false));
122 table2->attach (*l, 1, 2, n, n + 1, Gtk::FILL, Gtk::EXPAND, 0, 0);
123 table2->attach (channel_combo, 2, 3, n, n + 1, Gtk::FILL, Gtk::EXPAND | Gtk::FILL, 0, 0);
126 if (!ARDOUR::Profile->get_sae ()) {
130 mode_label.set_alignment (Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER);
131 table2->attach (mode_label, 1, 2, n, n + 1, Gtk::FILL, Gtk::EXPAND, 0, 0);
132 table2->attach (mode_combo, 2, 3, n, n + 1, Gtk::FILL, Gtk::EXPAND | Gtk::FILL, 0, 0);
139 l = manage (new Label (_("Group:"), Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, false));
140 table2->attach (*l, 1, 2, n, n + 1, Gtk::FILL, Gtk::EXPAND, 0, 0);
141 table2->attach (route_group_combo, 2, 3, n, n + 1, Gtk::FILL, Gtk::EXPAND | Gtk::FILL, 0, 0);
144 options_box->pack_start (*table2, false, true);
145 vbox->pack_start (*options_box, false, true);
147 get_vbox()->pack_start (*vbox, false, false);
149 track_bus_combo.signal_changed().connect (sigc::mem_fun (*this, &AddRouteDialog::track_type_chosen));
150 channel_combo.signal_changed().connect (sigc::mem_fun (*this, &AddRouteDialog::channel_combo_changed));
151 channel_combo.set_row_separator_func (sigc::mem_fun (*this, &AddRouteDialog::channel_separator));
152 route_group_combo.set_row_separator_func (sigc::mem_fun (*this, &AddRouteDialog::route_separator));
153 route_group_combo.signal_changed ().connect (sigc::mem_fun (*this, &AddRouteDialog::group_changed));
155 show_all_children ();
157 /* track template info will be managed whenever
158 this dialog is shown, via ::on_show()
161 add_button (Stock::CANCEL, RESPONSE_CANCEL);
162 add_button (Stock::ADD, RESPONSE_ACCEPT);
164 track_type_chosen ();
167 AddRouteDialog::~AddRouteDialog ()
172 AddRouteDialog::channel_combo_changed ()
174 maybe_update_name_template_entry ();
175 refill_track_modes ();
179 AddRouteDialog::maybe_update_name_template_entry ()
182 name_template_entry.get_text() != "" &&
183 name_template_entry.get_text() != _("Audio") &&
184 name_template_entry.get_text() != _("MIDI") &&
185 name_template_entry.get_text() != _("Bus")) {
190 if (type () == DataType::MIDI) {
191 name_template_entry.set_text (_("MIDI"));
193 name_template_entry.set_text (_("Audio"));
196 name_template_entry.set_text (_("Bus"));
201 AddRouteDialog::track_type_chosen ()
203 mode_combo.set_sensitive (track ());
204 maybe_update_name_template_entry ();
208 AddRouteDialog::track ()
210 return track_bus_combo.get_active_row_number () == 0;
214 AddRouteDialog::type ()
216 return (channel_combo.get_active_text() == _("MIDI"))
217 ? ARDOUR::DataType::MIDI
218 : ARDOUR::DataType::AUDIO;
222 AddRouteDialog::name_template ()
224 return name_template_entry.get_text ();
228 AddRouteDialog::count ()
230 return (int) floor (routes_adjustment.get_value ());
234 AddRouteDialog::refill_track_modes ()
238 s.push_back (_("Normal"));
240 if (!ARDOUR::Profile->get_sae ()) {
241 s.push_back (_("Non Layered"));
243 if (type() != DataType::MIDI) {
244 s.push_back (_("Tape"));
248 set_popdown_strings (mode_combo, s);
249 mode_combo.set_active_text (s.front());
253 AddRouteDialog::mode ()
255 if (ARDOUR::Profile->get_sae()) {
256 return ARDOUR::Normal;
259 std::string str = mode_combo.get_active_text();
260 if (str == _("Normal")) {
261 return ARDOUR::Normal;
262 } else if (str == _("Non Layered")){
263 return ARDOUR::NonLayered;
264 } else if (str == _("Tape")) {
265 return ARDOUR::Destructive;
267 fatal << string_compose (X_("programming error: unknown track mode in add route dialog combo = %1"), str)
272 return ARDOUR::Normal;
276 AddRouteDialog::channels ()
278 string str = channel_combo.get_active_text();
280 for (ChannelSetups::iterator i = channel_setups.begin(); i != channel_setups.end(); ++i) {
281 if (str == (*i).name) {
282 return (*i).channels;
290 AddRouteDialog::track_template ()
292 string str = channel_combo.get_active_text();
294 for (ChannelSetups::iterator i = channel_setups.begin(); i != channel_setups.end(); ++i) {
295 if (str == (*i).name) {
296 return (*i).template_path;
304 AddRouteDialog::on_show ()
306 refill_channel_setups ();
307 refill_route_groups ();
313 AddRouteDialog::refill_channel_setups ()
317 route_templates.clear ();
318 channel_combo_strings.clear ();
319 channel_setups.clear ();
321 chn.name = _("Mono");
323 channel_setups.push_back (chn);
325 chn.name = _("Stereo");
327 channel_setups.push_back (chn);
329 chn.name = "separator";
330 channel_setups.push_back (chn);
332 chn.name = _("MIDI");
334 channel_setups.push_back (chn);
336 chn.name = "separator";
337 channel_setups.push_back (chn);
339 ARDOUR::find_route_templates (route_templates);
341 if (!ARDOUR::Profile->get_sae()) {
342 if (!route_templates.empty()) {
344 for (vector<TemplateInfo>::iterator x = route_templates.begin(); x != route_templates.end(); ++x) {
347 chn.template_path = x->path;
348 channel_setups.push_back (chn);
352 /* clear template path for the rest */
354 chn.template_path = "";
356 chn.name = _("3 Channel");
358 channel_setups.push_back (chn);
360 chn.name = _("4 Channel");
362 channel_setups.push_back (chn);
364 chn.name = _("5 Channel");
366 channel_setups.push_back (chn);
368 chn.name = _("6 Channel");
370 channel_setups.push_back (chn);
372 chn.name = _("8 Channel");
374 channel_setups.push_back (chn);
376 chn.name = _("12 Channel");
378 channel_setups.push_back (chn);
380 chn.name = _("Custom");
382 channel_setups.push_back (chn);
385 for (ChannelSetups::iterator i = channel_setups.begin(); i != channel_setups.end(); ++i) {
386 channel_combo_strings.push_back ((*i).name);
389 set_popdown_strings (channel_combo, channel_combo_strings);
390 channel_combo.set_active_text (channel_combo_strings.front());
394 AddRouteDialog::add_route_group (RouteGroup* g)
396 route_group_combo.insert_text (3, g->name ());
400 AddRouteDialog::route_group ()
402 if (route_group_combo.get_active_row_number () == 2) {
406 return _session->route_group_by_name (route_group_combo.get_active_text());
410 AddRouteDialog::refill_route_groups ()
412 route_group_combo.clear ();
413 route_group_combo.append_text (_("New Group..."));
415 route_group_combo.append_text ("separator");
417 route_group_combo.append_text (_("No Group"));
419 _session->foreach_route_group (sigc::mem_fun (*this, &AddRouteDialog::add_route_group));
421 route_group_combo.set_active (2);
425 AddRouteDialog::group_changed ()
427 if (_session && route_group_combo.get_active_text () == _("New Group...")) {
428 RouteGroup* g = new RouteGroup (*_session, "");
431 plist.add (Properties::active, true);
432 g->apply_changes (plist);
434 RouteGroupDialog d (g, true);
438 route_group_combo.set_active (2);
440 _session->add_route_group (g);
442 route_group_combo.set_active (3);
448 AddRouteDialog::channel_separator (const Glib::RefPtr<Gtk::TreeModel> &, const Gtk::TreeModel::iterator &i)
450 channel_combo.set_active (i);
452 return channel_combo.get_active_text () == "separator";
456 AddRouteDialog::route_separator (const Glib::RefPtr<Gtk::TreeModel> &, const Gtk::TreeModel::iterator &i)
458 route_group_combo.set_active (i);
460 return route_group_combo.get_active_text () == "separator";