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 (_("Audio Tracks"));
75 track_bus_combo.append_text (_("MIDI Tracks"));
76 track_bus_combo.append_text (_("Busses"));
77 track_bus_combo.set_active (0);
79 VBox* vbox = manage (new VBox);
82 get_vbox()->set_spacing (4);
84 vbox->set_spacing (18);
85 vbox->set_border_width (5);
87 HBox *type_hbox = manage (new HBox);
88 type_hbox->set_spacing (6);
90 /* track/bus choice */
92 type_hbox->pack_start (*manage (new Label (_("Add:"))));
93 type_hbox->pack_start (routes_spinner);
94 type_hbox->pack_start (track_bus_combo);
96 vbox->pack_start (*type_hbox, false, true);
98 VBox* options_box = manage (new VBox);
99 Table *table2 = manage (new Table (3, 3, false));
101 options_box->set_spacing (6);
102 table2->set_row_spacings (6);
103 table2->set_col_spacing (1, 6);
105 l = manage (new Label (_("<b>Options</b>"), Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, false));
106 l->set_use_markup ();
107 options_box->pack_start (*l, false, true);
109 l = manage (new Label ("", Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, false));
110 l->set_padding (8, 0);
111 table2->attach (*l, 0, 1, 0, 3, Gtk::FILL, Gtk::FILL, 0, 0);
115 l = manage (new Label (_("Name:"), Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, false));
116 table2->attach (*l, 1, 2, n, n + 1, Gtk::FILL, Gtk::EXPAND, 0, 0);
117 table2->attach (name_template_entry, 2, 3, n, n + 1, Gtk::FILL, Gtk::EXPAND | Gtk::FILL, 0, 0);
120 /* Route configuration */
122 l = manage (new Label (_("Configuration:"), Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, false));
123 table2->attach (*l, 1, 2, n, n + 1, Gtk::FILL, Gtk::EXPAND, 0, 0);
124 table2->attach (channel_combo, 2, 3, n, n + 1, Gtk::FILL, Gtk::EXPAND | Gtk::FILL, 0, 0);
127 if (!ARDOUR::Profile->get_sae ()) {
131 mode_label.set_alignment (Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER);
132 table2->attach (mode_label, 1, 2, n, n + 1, Gtk::FILL, Gtk::EXPAND, 0, 0);
133 table2->attach (mode_combo, 2, 3, n, n + 1, Gtk::FILL, Gtk::EXPAND | Gtk::FILL, 0, 0);
140 l = manage (new Label (_("Group:"), Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, false));
141 table2->attach (*l, 1, 2, n, n + 1, Gtk::FILL, Gtk::EXPAND, 0, 0);
142 table2->attach (route_group_combo, 2, 3, n, n + 1, Gtk::FILL, Gtk::EXPAND | Gtk::FILL, 0, 0);
145 options_box->pack_start (*table2, false, true);
146 vbox->pack_start (*options_box, false, true);
148 get_vbox()->pack_start (*vbox, false, false);
150 track_bus_combo.signal_changed().connect (sigc::mem_fun (*this, &AddRouteDialog::track_type_chosen));
151 channel_combo.signal_changed().connect (sigc::mem_fun (*this, &AddRouteDialog::channel_combo_changed));
152 channel_combo.set_row_separator_func (sigc::mem_fun (*this, &AddRouteDialog::channel_separator));
153 route_group_combo.set_row_separator_func (sigc::mem_fun (*this, &AddRouteDialog::route_separator));
154 route_group_combo.signal_changed ().connect (sigc::mem_fun (*this, &AddRouteDialog::group_changed));
156 show_all_children ();
158 /* track template info will be managed whenever
159 this dialog is shown, via ::on_show()
162 add_button (Stock::CANCEL, RESPONSE_CANCEL);
163 add_button (Stock::ADD, RESPONSE_ACCEPT);
165 track_type_chosen ();
168 AddRouteDialog::~AddRouteDialog ()
173 AddRouteDialog::channel_combo_changed ()
175 maybe_update_name_template_entry ();
176 refill_track_modes ();
180 AddRouteDialog::maybe_update_name_template_entry ()
183 name_template_entry.get_text() != "" &&
184 name_template_entry.get_text() != _("Audio") &&
185 name_template_entry.get_text() != _("MIDI") &&
186 name_template_entry.get_text() != _("Bus")) {
190 if (audio_tracks_wanted ()) {
191 name_template_entry.set_text (_("Audio"));
192 } else if (midi_tracks_wanted()) {
193 name_template_entry.set_text (_("MIDI"));
195 name_template_entry.set_text (_("Bus"));
200 AddRouteDialog::track_type_chosen ()
202 if (midi_tracks_wanted()) {
203 channel_combo.set_sensitive (false);
204 mode_combo.set_sensitive (false);
205 } else if (audio_tracks_wanted()) {
206 mode_combo.set_sensitive (true);
207 channel_combo.set_sensitive (true);
209 mode_combo.set_sensitive (false);
210 channel_combo.set_sensitive (true);
213 maybe_update_name_template_entry ();
217 AddRouteDialog::audio_tracks_wanted ()
219 return track_bus_combo.get_active_row_number () == 0;
223 AddRouteDialog::midi_tracks_wanted ()
225 return track_bus_combo.get_active_row_number () == 1;
229 AddRouteDialog::name_template ()
231 return name_template_entry.get_text ();
235 AddRouteDialog::count ()
237 return (int) floor (routes_adjustment.get_value ());
241 AddRouteDialog::refill_track_modes ()
245 s.push_back (_("Normal"));
247 if (!ARDOUR::Profile->get_sae ()) {
248 s.push_back (_("Non Layered"));
249 s.push_back (_("Tape"));
252 set_popdown_strings (mode_combo, s);
253 mode_combo.set_active_text (s.front());
257 AddRouteDialog::mode ()
259 if (ARDOUR::Profile->get_sae()) {
260 return ARDOUR::Normal;
263 std::string str = mode_combo.get_active_text();
264 if (str == _("Normal")) {
265 return ARDOUR::Normal;
266 } else if (str == _("Non Layered")){
267 return ARDOUR::NonLayered;
268 } else if (str == _("Tape")) {
269 return ARDOUR::Destructive;
271 fatal << string_compose (X_("programming error: unknown track mode in add route dialog combo = %1"), str)
276 return ARDOUR::Normal;
280 AddRouteDialog::channels ()
282 string str = channel_combo.get_active_text();
284 for (ChannelSetups::iterator i = channel_setups.begin(); i != channel_setups.end(); ++i) {
285 if (str == (*i).name) {
286 return (*i).channels;
294 AddRouteDialog::track_template ()
296 string str = channel_combo.get_active_text();
298 for (ChannelSetups::iterator i = channel_setups.begin(); i != channel_setups.end(); ++i) {
299 if (str == (*i).name) {
300 return (*i).template_path;
308 AddRouteDialog::on_show ()
310 refill_channel_setups ();
311 refill_route_groups ();
317 AddRouteDialog::refill_channel_setups ()
321 route_templates.clear ();
322 channel_combo_strings.clear ();
323 channel_setups.clear ();
325 chn.name = _("Mono");
327 channel_setups.push_back (chn);
329 chn.name = _("Stereo");
331 channel_setups.push_back (chn);
333 chn.name = "separator";
334 channel_setups.push_back (chn);
336 ARDOUR::find_route_templates (route_templates);
338 if (!ARDOUR::Profile->get_sae()) {
339 if (!route_templates.empty()) {
341 for (vector<TemplateInfo>::iterator x = route_templates.begin(); x != route_templates.end(); ++x) {
344 chn.template_path = x->path;
345 channel_setups.push_back (chn);
349 /* clear template path for the rest */
351 chn.template_path = "";
353 chn.name = _("3 Channel");
355 channel_setups.push_back (chn);
357 chn.name = _("4 Channel");
359 channel_setups.push_back (chn);
361 chn.name = _("5 Channel");
363 channel_setups.push_back (chn);
365 chn.name = _("6 Channel");
367 channel_setups.push_back (chn);
369 chn.name = _("8 Channel");
371 channel_setups.push_back (chn);
373 chn.name = _("12 Channel");
375 channel_setups.push_back (chn);
377 chn.name = _("Custom");
379 channel_setups.push_back (chn);
382 for (ChannelSetups::iterator i = channel_setups.begin(); i != channel_setups.end(); ++i) {
383 channel_combo_strings.push_back ((*i).name);
386 set_popdown_strings (channel_combo, channel_combo_strings);
387 channel_combo.set_active_text (channel_combo_strings.front());
391 AddRouteDialog::add_route_group (RouteGroup* g)
393 route_group_combo.insert_text (3, g->name ());
397 AddRouteDialog::route_group ()
399 if (route_group_combo.get_active_row_number () == 2) {
403 return _session->route_group_by_name (route_group_combo.get_active_text());
407 AddRouteDialog::refill_route_groups ()
409 route_group_combo.clear ();
410 route_group_combo.append_text (_("New Group..."));
412 route_group_combo.append_text ("separator");
414 route_group_combo.append_text (_("No Group"));
416 _session->foreach_route_group (sigc::mem_fun (*this, &AddRouteDialog::add_route_group));
418 route_group_combo.set_active (2);
422 AddRouteDialog::group_changed ()
424 if (_session && route_group_combo.get_active_text () == _("New Group...")) {
425 RouteGroup* g = new RouteGroup (*_session, "");
428 plist.add (Properties::active, true);
429 g->apply_changes (plist);
431 RouteGroupDialog d (g, true);
435 route_group_combo.set_active (2);
437 _session->add_route_group (g);
439 route_group_combo.set_active (3);
445 AddRouteDialog::channel_separator (const Glib::RefPtr<Gtk::TreeModel> &, const Gtk::TreeModel::iterator &i)
447 channel_combo.set_active (i);
449 return channel_combo.get_active_text () == "separator";
453 AddRouteDialog::route_separator (const Glib::RefPtr<Gtk::TreeModel> &, const Gtk::TreeModel::iterator &i)
455 route_group_combo.set_active (i);
457 return route_group_combo.get_active_text () == "separator";