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 static const char* track_mode_names[] = {
54 std::vector<std::string> AddRouteDialog::channel_combo_strings;
55 std::vector<std::string> AddRouteDialog::track_mode_strings;
57 AddRouteDialog::AddRouteDialog (Session* s)
58 : ArdourDialog (_("Add Track or Bus"))
59 , routes_adjustment (1, 1, 128, 1, 4)
60 , routes_spinner (routes_adjustment)
61 , mode_label (_("Track mode:"))
65 if (track_mode_strings.empty()) {
66 track_mode_strings = I18N (track_mode_names);
68 if (ARDOUR::Profile->get_sae()) {
69 /* remove all but the first track mode (Normal) */
71 while (track_mode_strings.size() > 1) {
72 track_mode_strings.pop_back();
77 set_name ("AddRouteDialog");
78 set_position (Gtk::WIN_POS_MOUSE);
80 set_skip_taskbar_hint (true);
81 set_resizable (false);
83 name_template_entry.set_name (X_("AddRouteDialogNameTemplateEntry"));
84 routes_spinner.set_name (X_("AddRouteDialogSpinner"));
85 channel_combo.set_name (X_("ChannelCountSelector"));
86 mode_combo.set_name (X_("ChannelCountSelector"));
88 refill_channel_setups ();
89 refill_route_groups ();
90 set_popdown_strings (mode_combo, track_mode_strings, true);
92 channel_combo.set_active_text (channel_combo_strings.front());
93 mode_combo.set_active_text (track_mode_strings.front());
95 track_bus_combo.append_text (_("tracks"));
96 track_bus_combo.append_text (_("busses"));
97 track_bus_combo.set_active (0);
99 VBox* vbox = manage (new VBox);
102 get_vbox()->set_spacing (4);
104 vbox->set_spacing (18);
105 vbox->set_border_width (5);
107 HBox *type_hbox = manage (new HBox);
108 type_hbox->set_spacing (6);
110 /* track/bus choice */
112 type_hbox->pack_start (*manage (new Label (_("Add:"))));
113 type_hbox->pack_start (routes_spinner);
114 type_hbox->pack_start (track_bus_combo);
116 vbox->pack_start (*type_hbox, false, true);
118 VBox* options_box = manage (new VBox);
119 Table *table2 = manage (new Table (3, 3, false));
121 options_box->set_spacing (6);
122 table2->set_row_spacings (6);
123 table2->set_col_spacing (1, 6);
125 l = manage (new Label (_("<b>Options</b>"), Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, false));
126 l->set_use_markup ();
127 options_box->pack_start (*l, false, true);
129 l = manage (new Label ("", Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, false));
130 l->set_padding (8, 0);
131 table2->attach (*l, 0, 1, 0, 3, Gtk::FILL, Gtk::FILL, 0, 0);
133 /* Route configuration */
135 l = manage (new Label (_("Configuration:"), Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, false));
136 table2->attach (*l, 1, 2, 0, 1, Gtk::FILL, Gtk::EXPAND, 0, 0);
137 table2->attach (channel_combo, 2, 3, 0, 1, Gtk::FILL, Gtk::EXPAND & Gtk::FILL, 0, 0);
139 if (!ARDOUR::Profile->get_sae ()) {
143 mode_label.set_alignment (Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER);
144 table2->attach (mode_label, 1, 2, 1, 2, Gtk::FILL, Gtk::EXPAND, 0, 0);
145 table2->attach (mode_combo, 2, 3, 1, 2, Gtk::FILL, Gtk::EXPAND & Gtk::FILL, 0, 0);
151 l = manage (new Label (_("Group:"), Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, false));
152 table2->attach (*l, 1, 2, 2, 3, Gtk::FILL, Gtk::EXPAND, 0, 0);
153 table2->attach (route_group_combo, 2, 3, 2, 3, Gtk::FILL, Gtk::EXPAND & Gtk::FILL, 0, 0);
155 options_box->pack_start (*table2, false, true);
156 vbox->pack_start (*options_box, false, true);
158 get_vbox()->pack_start (*vbox, false, false);
160 track_bus_combo.signal_changed().connect (sigc::mem_fun (*this, &AddRouteDialog::track_type_chosen));
161 channel_combo.set_row_separator_func (sigc::mem_fun (*this, &AddRouteDialog::channel_separator));
162 route_group_combo.set_row_separator_func (sigc::mem_fun (*this, &AddRouteDialog::route_separator));
163 route_group_combo.signal_changed ().connect (sigc::mem_fun (*this, &AddRouteDialog::group_changed));
165 show_all_children ();
167 /* track template info will be managed whenever
168 this dialog is shown, via ::on_show()
171 add_button (Stock::CANCEL, RESPONSE_CANCEL);
172 add_button (Stock::ADD, RESPONSE_ACCEPT);
174 track_type_chosen ();
177 AddRouteDialog::~AddRouteDialog ()
182 AddRouteDialog::track_type_chosen ()
185 mode_label.set_text (_("Track mode:"));
186 set_popdown_strings (mode_combo, track_mode_strings);
187 mode_combo.set_sensitive (true);
188 mode_combo.set_active_text (track_mode_strings.front());
190 mode_combo.set_sensitive (false);
195 AddRouteDialog::track ()
197 return track_bus_combo.get_active_row_number () == 0;
201 AddRouteDialog::type ()
203 return (channel_combo.get_active_text() == _("MIDI"))
204 ? ARDOUR::DataType::MIDI
205 : ARDOUR::DataType::AUDIO;
209 AddRouteDialog::name_template ()
211 return name_template_entry.get_text ();
215 AddRouteDialog::count ()
217 return (int) floor (routes_adjustment.get_value ());
221 AddRouteDialog::mode ()
223 if (ARDOUR::Profile->get_sae()) {
224 return ARDOUR::Normal;
227 std::string str = mode_combo.get_active_text();
228 if (str == _("Normal")) {
229 return ARDOUR::Normal;
230 } else if (str == _("Non Layered")){
231 return ARDOUR::NonLayered;
232 } else if (str == _("Tape")) {
233 return ARDOUR::Destructive;
235 fatal << string_compose (X_("programming error: unknown track mode in add route dialog combo = %1"), str)
240 return ARDOUR::Normal;
244 AddRouteDialog::channels ()
246 string str = channel_combo.get_active_text();
248 for (ChannelSetups::iterator i = channel_setups.begin(); i != channel_setups.end(); ++i) {
249 if (str == (*i).name) {
250 return (*i).channels;
258 AddRouteDialog::track_template ()
260 string str = channel_combo.get_active_text();
262 for (ChannelSetups::iterator i = channel_setups.begin(); i != channel_setups.end(); ++i) {
263 if (str == (*i).name) {
264 return (*i).template_path;
272 AddRouteDialog::on_show ()
274 refill_channel_setups ();
275 refill_route_groups ();
281 AddRouteDialog::refill_channel_setups ()
285 route_templates.clear ();
286 channel_combo_strings.clear ();
287 channel_setups.clear ();
289 chn.name = _("Mono");
291 channel_setups.push_back (chn);
293 chn.name = _("Stereo");
295 channel_setups.push_back (chn);
297 chn.name = "separator";
298 channel_setups.push_back (chn);
300 chn.name = _("MIDI");
302 channel_setups.push_back (chn);
304 chn.name = "separator";
305 channel_setups.push_back (chn);
307 ARDOUR::find_route_templates (route_templates);
309 if (!ARDOUR::Profile->get_sae()) {
310 if (!route_templates.empty()) {
312 for (vector<TemplateInfo>::iterator x = route_templates.begin(); x != route_templates.end(); ++x) {
315 chn.template_path = x->path;
316 channel_setups.push_back (chn);
320 /* clear template path for the rest */
322 chn.template_path = "";
324 chn.name = _("3 Channel");
326 channel_setups.push_back (chn);
328 chn.name = _("4 Channel");
330 channel_setups.push_back (chn);
332 chn.name = _("5 Channel");
334 channel_setups.push_back (chn);
336 chn.name = _("6 Channel");
338 channel_setups.push_back (chn);
340 chn.name = _("8 Channel");
342 channel_setups.push_back (chn);
344 chn.name = _("12 Channel");
346 channel_setups.push_back (chn);
348 chn.name = _("Custom");
350 channel_setups.push_back (chn);
353 for (ChannelSetups::iterator i = channel_setups.begin(); i != channel_setups.end(); ++i) {
354 channel_combo_strings.push_back ((*i).name);
357 set_popdown_strings (channel_combo, channel_combo_strings, true);
358 channel_combo.set_active_text (channel_combo_strings.front());
362 AddRouteDialog::add_route_group (RouteGroup* g)
364 route_group_combo.insert_text (3, g->name ());
368 AddRouteDialog::route_group ()
370 if (route_group_combo.get_active_row_number () == 2) {
374 return _session->route_group_by_name (route_group_combo.get_active_text());
378 AddRouteDialog::refill_route_groups ()
380 route_group_combo.clear ();
381 route_group_combo.append_text (_("New group..."));
383 route_group_combo.append_text ("separator");
385 route_group_combo.append_text (_("No group"));
387 _session->foreach_route_group (sigc::mem_fun (*this, &AddRouteDialog::add_route_group));
389 route_group_combo.set_active (2);
393 AddRouteDialog::group_changed ()
395 if (_session && route_group_combo.get_active_text () == _("New group...")) {
396 RouteGroup* g = new RouteGroup (*_session, "");
399 plist.add (Properties::active, true);
400 g->apply_changes (plist);
402 RouteGroupDialog d (g, true);
406 route_group_combo.set_active (2);
408 _session->add_route_group (g);
410 route_group_combo.set_active (3);
416 AddRouteDialog::channel_separator (const Glib::RefPtr<Gtk::TreeModel> &, const Gtk::TreeModel::iterator &i)
418 channel_combo.set_active (i);
420 return channel_combo.get_active_text () == "separator";
424 AddRouteDialog::route_separator (const Glib::RefPtr<Gtk::TreeModel> &, const Gtk::TreeModel::iterator &i)
426 route_group_combo.set_active (i);
428 return route_group_combo.get_active_text () == "separator";