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/messagedialog.h>
26 #include <gtkmm/separator.h>
27 #include <gtkmm/table.h>
29 #include "pbd/error.h"
30 #include "pbd/convert.h"
32 #include "gtkmm2ext/utils.h"
33 #include "gtkmm2ext/doi.h"
35 #include "ardour/plugin_manager.h"
36 #include "ardour/profile.h"
37 #include "ardour/template_utils.h"
38 #include "ardour/route_group.h"
39 #include "ardour/session.h"
40 #include "ardour/vca.h"
43 #include "add_route_dialog.h"
44 #include "route_group_dialog.h"
49 using namespace Gtkmm2ext;
52 using namespace ARDOUR;
53 using namespace ARDOUR_UI_UTILS;
55 std::vector<std::string> AddRouteDialog::channel_combo_strings;
57 AddRouteDialog::AddRouteDialog ()
58 : ArdourDialog (_("Add Track/Bus/VCA"))
59 , routes_adjustment (1, 1, 128, 1, 4)
60 , routes_spinner (routes_adjustment)
61 , configuration_label (_("Configuration:"))
62 , mode_label (_("Record Mode:"))
63 , instrument_label (_("Instrument:"))
64 , name_edited_by_user (false)
66 set_name ("AddRouteDialog");
67 set_skip_taskbar_hint (true);
68 set_resizable (false);
69 set_position (WIN_POS_MOUSE);
71 name_template_entry.set_name (X_("AddRouteDialogNameTemplateEntry"));
72 // routes_spinner.set_name (X_("AddRouteDialogSpinner"));
73 channel_combo.set_name (X_("ChannelCountSelector"));
74 mode_combo.set_name (X_("ChannelCountSelector"));
76 refill_track_modes ();
78 track_bus_combo.append_text (_("Audio Tracks"));
79 track_bus_combo.append_text (_("MIDI Tracks"));
80 track_bus_combo.append_text (_("Audio+MIDI Tracks"));
81 track_bus_combo.append_text (_("Audio Busses"));
82 track_bus_combo.append_text (_("MIDI Busses"));
83 track_bus_combo.append_text (_("VCA Masters"));
84 track_bus_combo.set_active (0);
86 insert_at_combo.append_text (_("First"));
87 insert_at_combo.append_text (_("Before Selection"));
88 insert_at_combo.append_text (_("After Selection"));
89 insert_at_combo.append_text (_("Last"));
90 insert_at_combo.set_active (3);
92 strict_io_combo.append_text (_("Flexible-I/O"));
93 strict_io_combo.append_text (_("Strict-I/O"));
94 strict_io_combo.set_active (Config->get_strict_io () ? 1 : 0);
96 VBox* vbox = manage (new VBox);
99 get_vbox()->set_spacing (4);
101 vbox->set_spacing (18);
102 vbox->set_border_width (5);
104 HBox *type_hbox = manage (new HBox);
105 type_hbox->set_spacing (6);
107 /* track/bus choice */
109 type_hbox->pack_start (*manage (new Label (_("Add:"))));
110 type_hbox->pack_start (routes_spinner);
111 type_hbox->pack_start (track_bus_combo);
113 vbox->pack_start (*type_hbox, false, true);
115 VBox* options_box = manage (new VBox);
116 Table *table2 = manage (new Table (3, 3, false));
118 options_box->set_spacing (6);
119 table2->set_row_spacings (6);
120 table2->set_col_spacing (1, 6);
122 l = manage (new Label (_("<b>Options</b>"), Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, false));
123 l->set_use_markup ();
124 options_box->pack_start (*l, false, true);
126 l = manage (new Label ("", Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, false));
127 l->set_padding (8, 0);
128 table2->attach (*l, 0, 1, 0, 3, Gtk::FILL, Gtk::FILL, 0, 0);
132 l = manage (new Label (_("Name:"), Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, false));
133 table2->attach (*l, 1, 2, n, n + 1, Gtk::FILL, Gtk::EXPAND, 0, 0);
134 table2->attach (name_template_entry, 2, 3, n, n + 1, Gtk::FILL, Gtk::EXPAND | Gtk::FILL, 0, 0);
137 /* Route configuration */
139 configuration_label.set_alignment (Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER);
140 table2->attach (configuration_label, 1, 2, n, n + 1, Gtk::FILL, Gtk::EXPAND, 0, 0);
141 table2->attach (channel_combo, 2, 3, n, n + 1, Gtk::FILL, Gtk::EXPAND | Gtk::FILL, 0, 0);
144 mode_label.set_alignment (Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER);
145 table2->attach (mode_label, 1, 2, n, n + 1, Gtk::FILL, Gtk::EXPAND, 0, 0);
146 table2->attach (mode_combo, 2, 3, n, n + 1, Gtk::FILL, Gtk::EXPAND | Gtk::FILL, 0, 0);
149 instrument_label.set_alignment (Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER);
150 table2->attach (instrument_label, 1, 2, n, n + 1, Gtk::FILL, Gtk::EXPAND, 0, 0);
151 table2->attach (instrument_combo, 2, 3, n, n + 1, Gtk::FILL, Gtk::EXPAND | Gtk::FILL, 0, 0);
156 l = manage (new Label (_("Group:"), Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, false));
157 table2->attach (*l, 1, 2, n, n + 1, Gtk::FILL, Gtk::EXPAND, 0, 0);
158 table2->attach (route_group_combo, 2, 3, n, n + 1, Gtk::FILL, Gtk::EXPAND | Gtk::FILL, 0, 0);
161 /* New route will be inserted at.. */
162 l = manage (new Label (_("Insert:"), Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, false));
163 table2->attach (*l, 1, 2, n, n + 1, Gtk::FILL, Gtk::EXPAND, 0, 0);
164 table2->attach (insert_at_combo, 2, 3, n, n + 1, Gtk::FILL, Gtk::EXPAND | Gtk::FILL, 0, 0);
167 /* New Route's Routing is.. */
169 if (Profile->get_mixbus ()) {
170 strict_io_combo.set_active (1);
172 l = manage (new Label (_("Output Ports:"), Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, false));
173 table2->attach (*l, 1, 2, n, n + 1, Gtk::FILL, Gtk::EXPAND, 0, 0);
174 table2->attach (strict_io_combo, 2, 3, n, n + 1, Gtk::FILL, Gtk::EXPAND | Gtk::FILL, 0, 0);
176 ARDOUR_UI_UTILS::set_tooltip (strict_io_combo,
177 _("With strict-i/o enabled, Effect Processors will not modify the number of channels on a track. The number of output channels will always match the number of input channels."));
181 options_box->pack_start (*table2, false, true);
182 vbox->pack_start (*options_box, false, true);
184 get_vbox()->pack_start (*vbox, false, false);
186 name_template_entry.signal_insert_text ().connect (sigc::mem_fun (*this, &AddRouteDialog::name_template_entry_insertion));
187 name_template_entry.signal_delete_text ().connect (sigc::mem_fun (*this, &AddRouteDialog::name_template_entry_deletion));
188 track_bus_combo.signal_changed().connect (sigc::mem_fun (*this, &AddRouteDialog::track_type_chosen));
189 channel_combo.signal_changed().connect (sigc::mem_fun (*this, &AddRouteDialog::channel_combo_changed));
190 channel_combo.set_row_separator_func (sigc::mem_fun (*this, &AddRouteDialog::channel_separator));
191 route_group_combo.set_row_separator_func (sigc::mem_fun (*this, &AddRouteDialog::route_separator));
192 route_group_combo.signal_changed ().connect (sigc::mem_fun (*this, &AddRouteDialog::group_changed));
194 show_all_children ();
196 /* track template info will be managed whenever
197 this dialog is shown, via ::on_show()
200 add_button (_("Add and Close"), AddAndClose);
201 add_button (_("Add"), Add);
202 set_response_sensitive (AddAndClose, true);
203 set_default_response (AddAndClose);
205 track_type_chosen ();
208 AddRouteDialog::~AddRouteDialog ()
213 AddRouteDialog::on_response (int r)
215 name_edited_by_user = false;
216 ArdourDialog::on_response (r);
220 AddRouteDialog::name_template_entry_insertion (Glib::ustring const &,int*)
222 name_edited_by_user = true;
226 AddRouteDialog::name_template_entry_deletion (int, int)
228 name_edited_by_user = true;
232 AddRouteDialog::channel_combo_changed ()
234 refill_track_modes ();
237 AddRouteDialog::TypeWanted
238 AddRouteDialog::type_wanted() const
240 std::string str = track_bus_combo.get_active_text();
241 if (str == _("Audio Busses")) {
243 } else if (str == _("MIDI Busses")){
245 } else if (str == _("MIDI Tracks")){
247 } else if (str == _("Audio+MIDI Tracks")) {
249 } else if (str == _("Audio Tracks")) {
257 AddRouteDialog::maybe_update_name_template_entry ()
259 if (name_edited_by_user) {
263 switch (type_wanted()) {
265 name_template_entry.set_text (_("Audio"));
268 name_template_entry.set_text (_("MIDI"));
271 name_template_entry.set_text (_("Audio+MIDI"));
275 name_template_entry.set_text (_("Bus"));
278 name_template_entry.set_text (VCA::default_name_template());
284 AddRouteDialog::track_type_chosen ()
286 switch (type_wanted()) {
288 mode_combo.set_sensitive (true);
289 channel_combo.set_sensitive (true);
290 instrument_combo.set_sensitive (false);
291 configuration_label.set_sensitive (true);
292 mode_label.set_sensitive (true);
293 instrument_label.set_sensitive (false);
294 route_group_combo.set_sensitive (true);
295 strict_io_combo.set_sensitive (true);
296 insert_at_combo.set_sensitive (true);
299 channel_combo.set_sensitive (false);
300 mode_combo.set_sensitive (false);
301 instrument_combo.set_sensitive (true);
302 configuration_label.set_sensitive (false);
303 mode_label.set_sensitive (false);
304 instrument_label.set_sensitive (true);
305 route_group_combo.set_sensitive (true);
306 strict_io_combo.set_sensitive (true);
307 insert_at_combo.set_sensitive (true);
311 MessageDialog msg (_("Audio+MIDI tracks are intended for use <b>ONLY</b> with plugins that use both audio and MIDI input data\n\n"
312 "If you do not plan to use such a plugin, then use a normal audio or MIDI track instead."),
313 true, MESSAGE_INFO, BUTTONS_OK, true);
314 msg.set_position (WIN_POS_MOUSE);
317 channel_combo.set_sensitive (true);
318 mode_combo.set_sensitive (true);
319 instrument_combo.set_sensitive (true);
320 configuration_label.set_sensitive (true);
321 mode_label.set_sensitive (true);
322 instrument_label.set_sensitive (true);
323 route_group_combo.set_sensitive (true);
324 strict_io_combo.set_sensitive (true);
325 insert_at_combo.set_sensitive (true);
328 mode_combo.set_sensitive (false);
329 channel_combo.set_sensitive (true);
330 instrument_combo.set_sensitive (false);
331 configuration_label.set_sensitive (true);
332 mode_label.set_sensitive (true);
333 instrument_label.set_sensitive (false);
334 route_group_combo.set_sensitive (true);
335 strict_io_combo.set_sensitive (true);
336 insert_at_combo.set_sensitive (true);
339 mode_combo.set_sensitive (false);
340 channel_combo.set_sensitive (false);
341 instrument_combo.set_sensitive (false);
342 configuration_label.set_sensitive (false);
343 mode_label.set_sensitive (false);
344 instrument_label.set_sensitive (false);
345 route_group_combo.set_sensitive (false);
346 strict_io_combo.set_sensitive (false);
347 insert_at_combo.set_sensitive (false);
350 mode_combo.set_sensitive (false);
351 channel_combo.set_sensitive (false);
352 instrument_combo.set_sensitive (true);
353 configuration_label.set_sensitive (false);
354 mode_label.set_sensitive (true);
355 instrument_label.set_sensitive (true);
356 strict_io_combo.set_sensitive (true);
357 insert_at_combo.set_sensitive (true);
361 maybe_update_name_template_entry ();
366 AddRouteDialog::name_template () const
368 return name_template_entry.get_text ();
372 AddRouteDialog::name_template_is_default() const
374 string n = name_template();
376 if (n == _("Audio") ||
378 n == _("Audio+MIDI") ||
380 n == VCA::default_name_template()) {
388 AddRouteDialog::count ()
390 return (int) floor (routes_adjustment.get_value ());
394 AddRouteDialog::refill_track_modes ()
398 s.push_back (_("Normal"));
399 #ifdef XXX_OLD_DESTRUCTIVE_API_XXX
400 s.push_back (_("Non Layered"));
402 if (!ARDOUR::Profile->get_mixbus ()) {
403 s.push_back (_("Tape"));
406 set_popdown_strings (mode_combo, s);
407 mode_combo.set_active_text (s.front());
411 AddRouteDialog::mode ()
413 std::string str = mode_combo.get_active_text();
414 if (str == _("Normal")) {
415 return ARDOUR::Normal;
416 } else if (str == _("Non Layered")){
417 return ARDOUR::NonLayered;
418 } else if (str == _("Tape")) {
419 return ARDOUR::Destructive;
421 fatal << string_compose (X_("programming error: unknown track mode in add route dialog combo = %1"), str)
423 abort(); /*NOTREACHED*/
426 return ARDOUR::Normal;
430 AddRouteDialog::channels ()
434 switch (type_wanted()) {
437 str = channel_combo.get_active_text();
438 for (ChannelSetups::iterator i = channel_setups.begin(); i != channel_setups.end(); ++i) {
439 if (str == (*i).name) {
440 ret.set (DataType::AUDIO, (*i).channels);
444 ret.set (DataType::MIDI, 0);
449 ret.set (DataType::AUDIO, 0);
450 ret.set (DataType::MIDI, 1);
454 str = channel_combo.get_active_text();
455 for (ChannelSetups::iterator i = channel_setups.begin(); i != channel_setups.end(); ++i) {
456 if (str == (*i).name) {
457 ret.set (DataType::AUDIO, (*i).channels);
461 ret.set (DataType::MIDI, 1);
471 AddRouteDialog::track_template ()
473 string str = channel_combo.get_active_text();
475 for (ChannelSetups::iterator i = channel_setups.begin(); i != channel_setups.end(); ++i) {
476 if (str == (*i).name) {
477 return (*i).template_path;
485 AddRouteDialog::on_show ()
487 routes_spinner.grab_focus ();
488 name_edited_by_user = false;
490 refill_channel_setups ();
491 refill_route_groups ();
497 AddRouteDialog::refill_channel_setups ()
501 route_templates.clear ();
503 string channel_current_choice = channel_combo.get_active_text();
505 channel_combo_strings.clear ();
506 channel_setups.clear ();
508 chn.name = _("Mono");
510 channel_setups.push_back (chn);
512 chn.name = _("Stereo");
514 channel_setups.push_back (chn);
516 chn.name = "separator";
517 channel_setups.push_back (chn);
519 ARDOUR::find_route_templates (route_templates);
521 if (!route_templates.empty()) {
523 for (vector<TemplateInfo>::iterator x = route_templates.begin(); x != route_templates.end(); ++x) {
526 chn.template_path = x->path;
527 channel_setups.push_back (chn);
531 /* clear template path for the rest */
533 chn.template_path = "";
535 chn.name = _("3 Channel");
537 channel_setups.push_back (chn);
539 chn.name = _("4 Channel");
541 channel_setups.push_back (chn);
543 chn.name = _("5 Channel");
545 channel_setups.push_back (chn);
547 chn.name = _("6 Channel");
549 channel_setups.push_back (chn);
551 chn.name = _("8 Channel");
553 channel_setups.push_back (chn);
555 chn.name = _("12 Channel");
557 channel_setups.push_back (chn);
559 chn.name = _("Custom");
561 channel_setups.push_back (chn);
563 for (ChannelSetups::iterator i = channel_setups.begin(); i != channel_setups.end(); ++i) {
564 channel_combo_strings.push_back ((*i).name);
567 set_popdown_strings (channel_combo, channel_combo_strings);
569 if (!channel_current_choice.empty()) {
570 channel_combo.set_active_text (channel_current_choice);
572 channel_combo.set_active_text (channel_combo_strings.front());
577 AddRouteDialog::add_route_group (RouteGroup* g)
579 route_group_combo.insert_text (3, g->name ());
583 AddRouteDialog::route_group ()
585 if (!_session || route_group_combo.get_active_row_number () == 2) {
589 return _session->route_group_by_name (route_group_combo.get_active_text());
593 AddRouteDialog::use_strict_io() {
594 return strict_io_combo.get_active_row_number () == 1;
598 AddRouteDialog::refill_route_groups ()
600 route_group_combo.clear ();
601 route_group_combo.append_text (_("New Group..."));
603 route_group_combo.append_text ("separator");
605 route_group_combo.append_text (_("No Group"));
608 _session->foreach_route_group (sigc::mem_fun (*this, &AddRouteDialog::add_route_group));
611 route_group_combo.set_active (2);
615 AddRouteDialog::group_changed ()
617 if (_session && route_group_combo.get_active_text () == _("New Group...")) {
618 RouteGroup* g = new RouteGroup (*_session, "");
619 RouteGroupDialog* d = new RouteGroupDialog (g, true);
621 d->signal_response().connect (sigc::bind (sigc::mem_fun (*this, &AddRouteDialog::new_group_dialog_finished), d));
627 AddRouteDialog::new_group_dialog_finished (int r, RouteGroupDialog* d)
629 if (r == RESPONSE_OK) {
631 if (!d->name_check()) {
636 _session->add_route_group (d->group());
639 add_route_group (d->group());
640 route_group_combo.set_active (3);
643 route_group_combo.set_active (2);
646 delete_when_idle (d);
649 RouteDialogs::InsertAt
650 AddRouteDialog::insert_at ()
652 using namespace RouteDialogs;
654 std::string str = insert_at_combo.get_active_text();
656 if (str == _("First")) {
658 } else if (str == _("After Selection")) {
659 return AfterSelection;
660 } else if (str == _("Before Selection")){
661 return BeforeSelection;
667 AddRouteDialog::channel_separator (const Glib::RefPtr<Gtk::TreeModel> &, const Gtk::TreeModel::iterator &i)
669 channel_combo.set_active (i);
671 return channel_combo.get_active_text () == "separator";
675 AddRouteDialog::route_separator (const Glib::RefPtr<Gtk::TreeModel> &, const Gtk::TreeModel::iterator &i)
677 route_group_combo.set_active (i);
679 return route_group_combo.get_active_text () == "separator";
683 AddRouteDialog::requested_instrument ()
685 return instrument_combo.selected_instrument();