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 "widgets/tooltips.h"
37 #include "ardour/plugin_manager.h"
38 #include "ardour/profile.h"
39 #include "ardour/template_utils.h"
40 #include "ardour/route_group.h"
41 #include "ardour/session.h"
42 #include "ardour/vca.h"
45 #include "add_route_dialog.h"
46 #include "route_group_dialog.h"
50 using namespace Gtkmm2ext;
53 using namespace ARDOUR;
54 using namespace ARDOUR_UI_UTILS;
56 std::vector<std::string> AddRouteDialog::channel_combo_strings;
58 AddRouteDialog::AddRouteDialog ()
59 : ArdourDialog (_("Add Track/Bus/VCA"))
60 , routes_adjustment (1, 1, 128, 1, 4)
61 , routes_spinner (routes_adjustment)
62 , configuration_label (_("Configuration:"))
63 , mode_label (_("Record Mode:"))
64 , instrument_label (_("Instrument:"))
65 , name_edited_by_user (false)
67 set_name ("AddRouteDialog");
68 set_skip_taskbar_hint (true);
69 set_resizable (false);
70 set_position (WIN_POS_MOUSE);
72 name_template_entry.set_name (X_("AddRouteDialogNameTemplateEntry"));
73 // routes_spinner.set_name (X_("AddRouteDialogSpinner"));
74 channel_combo.set_name (X_("ChannelCountSelector"));
75 mode_combo.set_name (X_("ChannelCountSelector"));
77 refill_track_modes ();
79 track_bus_combo.append_text (_("Audio Tracks"));
80 track_bus_combo.append_text (_("MIDI Tracks"));
81 track_bus_combo.append_text (_("Audio+MIDI Tracks"));
82 track_bus_combo.append_text (_("Audio Busses"));
83 track_bus_combo.append_text (_("MIDI Busses"));
84 track_bus_combo.append_text (_("VCA Masters"));
85 track_bus_combo.set_active (0);
87 insert_at_combo.append_text (_("First"));
88 insert_at_combo.append_text (_("Before Selection"));
89 insert_at_combo.append_text (_("After Selection"));
90 insert_at_combo.append_text (_("Last"));
91 insert_at_combo.set_active (3);
93 strict_io_combo.append_text (_("Flexible-I/O"));
94 strict_io_combo.append_text (_("Strict-I/O"));
95 strict_io_combo.set_active (Config->get_strict_io () ? 1 : 0);
97 VBox* vbox = manage (new VBox);
100 get_vbox()->set_spacing (4);
102 vbox->set_spacing (18);
103 vbox->set_border_width (5);
105 HBox *type_hbox = manage (new HBox);
106 type_hbox->set_spacing (6);
108 /* track/bus choice */
110 type_hbox->pack_start (*manage (new Label (_("Add:"))));
111 type_hbox->pack_start (routes_spinner);
112 type_hbox->pack_start (track_bus_combo);
114 vbox->pack_start (*type_hbox, false, true);
116 VBox* options_box = manage (new VBox);
117 Table *table2 = manage (new Table (3, 3, false));
119 options_box->set_spacing (6);
120 table2->set_row_spacings (6);
121 table2->set_col_spacing (1, 6);
123 l = manage (new Label (_("<b>Options</b>"), Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, false));
124 l->set_use_markup ();
125 options_box->pack_start (*l, false, true);
127 l = manage (new Label ("", Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, false));
128 l->set_padding (8, 0);
129 table2->attach (*l, 0, 1, 0, 3, Gtk::FILL, Gtk::FILL, 0, 0);
133 l = manage (new Label (_("Name:"), Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, false));
134 table2->attach (*l, 1, 2, n, n + 1, Gtk::FILL, Gtk::EXPAND, 0, 0);
135 table2->attach (name_template_entry, 2, 3, n, n + 1, Gtk::FILL, Gtk::EXPAND | Gtk::FILL, 0, 0);
138 /* Route configuration */
140 configuration_label.set_alignment (Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER);
141 table2->attach (configuration_label, 1, 2, n, n + 1, Gtk::FILL, Gtk::EXPAND, 0, 0);
142 table2->attach (channel_combo, 2, 3, n, n + 1, Gtk::FILL, Gtk::EXPAND | Gtk::FILL, 0, 0);
145 mode_label.set_alignment (Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER);
146 table2->attach (mode_label, 1, 2, n, n + 1, Gtk::FILL, Gtk::EXPAND, 0, 0);
147 table2->attach (mode_combo, 2, 3, n, n + 1, Gtk::FILL, Gtk::EXPAND | Gtk::FILL, 0, 0);
150 instrument_label.set_alignment (Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER);
151 table2->attach (instrument_label, 1, 2, n, n + 1, Gtk::FILL, Gtk::EXPAND, 0, 0);
152 table2->attach (instrument_combo, 2, 3, n, n + 1, Gtk::FILL, Gtk::EXPAND | Gtk::FILL, 0, 0);
157 l = manage (new Label (_("Group:"), Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, false));
158 table2->attach (*l, 1, 2, n, n + 1, Gtk::FILL, Gtk::EXPAND, 0, 0);
159 table2->attach (route_group_combo, 2, 3, n, n + 1, Gtk::FILL, Gtk::EXPAND | Gtk::FILL, 0, 0);
162 /* New route will be inserted at.. */
163 l = manage (new Label (_("Insert:"), Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, false));
164 table2->attach (*l, 1, 2, n, n + 1, Gtk::FILL, Gtk::EXPAND, 0, 0);
165 table2->attach (insert_at_combo, 2, 3, n, n + 1, Gtk::FILL, Gtk::EXPAND | Gtk::FILL, 0, 0);
168 /* New Route's Routing is.. */
170 if (Profile->get_mixbus ()) {
171 strict_io_combo.set_active (1);
173 l = manage (new Label (_("Output Ports:"), Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, false));
174 table2->attach (*l, 1, 2, n, n + 1, Gtk::FILL, Gtk::EXPAND, 0, 0);
175 table2->attach (strict_io_combo, 2, 3, n, n + 1, Gtk::FILL, Gtk::EXPAND | Gtk::FILL, 0, 0);
177 ArdourWidgets::set_tooltip (strict_io_combo,
178 _("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."));
182 options_box->pack_start (*table2, false, true);
183 vbox->pack_start (*options_box, false, true);
185 get_vbox()->pack_start (*vbox, false, false);
187 name_template_entry.signal_insert_text ().connect (sigc::mem_fun (*this, &AddRouteDialog::name_template_entry_insertion));
188 name_template_entry.signal_delete_text ().connect (sigc::mem_fun (*this, &AddRouteDialog::name_template_entry_deletion));
189 track_bus_combo.signal_changed().connect (sigc::mem_fun (*this, &AddRouteDialog::track_type_chosen));
190 channel_combo.signal_changed().connect (sigc::mem_fun (*this, &AddRouteDialog::channel_combo_changed));
191 channel_combo.set_row_separator_func (sigc::mem_fun (*this, &AddRouteDialog::channel_separator));
192 route_group_combo.set_row_separator_func (sigc::mem_fun (*this, &AddRouteDialog::route_separator));
193 route_group_combo.signal_changed ().connect (sigc::mem_fun (*this, &AddRouteDialog::group_changed));
195 show_all_children ();
197 /* track template info will be managed whenever
198 this dialog is shown, via ::on_show()
201 add_button (_("Add and Close"), AddAndClose);
202 add_button (_("Add"), Add);
203 set_response_sensitive (AddAndClose, true);
204 set_default_response (AddAndClose);
206 track_type_chosen ();
209 AddRouteDialog::~AddRouteDialog ()
214 AddRouteDialog::on_response (int r)
216 name_edited_by_user = false;
217 /* Don't call ArdourDialog::on_response() because that will
218 automatically hide the dialog.
220 Gtk::Dialog::on_response (r);
224 AddRouteDialog::name_template_entry_insertion (Glib::ustring const &,int*)
226 name_edited_by_user = true;
230 AddRouteDialog::name_template_entry_deletion (int, int)
232 name_edited_by_user = true;
236 AddRouteDialog::channel_combo_changed ()
238 refill_track_modes ();
241 AddRouteDialog::TypeWanted
242 AddRouteDialog::type_wanted() const
244 std::string str = track_bus_combo.get_active_text();
245 if (str == _("Audio Busses")) {
247 } else if (str == _("MIDI Busses")){
249 } else if (str == _("MIDI Tracks")){
251 } else if (str == _("Audio+MIDI Tracks")) {
253 } else if (str == _("Audio Tracks")) {
261 AddRouteDialog::maybe_update_name_template_entry ()
263 if (name_edited_by_user) {
267 switch (type_wanted()) {
269 name_template_entry.set_text (_("Audio"));
272 name_template_entry.set_text (_("MIDI"));
275 name_template_entry.set_text (_("Audio+MIDI"));
279 name_template_entry.set_text (_("Bus"));
282 name_template_entry.set_text (VCA::default_name_template());
285 name_edited_by_user = false;
289 AddRouteDialog::track_type_chosen ()
291 switch (type_wanted()) {
293 mode_combo.set_sensitive (true);
294 channel_combo.set_sensitive (true);
295 instrument_combo.set_sensitive (false);
296 configuration_label.set_sensitive (true);
297 mode_label.set_sensitive (true);
298 instrument_label.set_sensitive (false);
299 route_group_combo.set_sensitive (true);
300 strict_io_combo.set_sensitive (true);
301 insert_at_combo.set_sensitive (true);
304 channel_combo.set_sensitive (false);
305 mode_combo.set_sensitive (false);
306 instrument_combo.set_sensitive (true);
307 configuration_label.set_sensitive (false);
308 mode_label.set_sensitive (false);
309 instrument_label.set_sensitive (true);
310 route_group_combo.set_sensitive (true);
311 strict_io_combo.set_sensitive (true);
312 insert_at_combo.set_sensitive (true);
316 MessageDialog msg (_("Audio+MIDI tracks are intended for use <b>ONLY</b> with plugins that use both audio and MIDI input data\n\n"
317 "If you do not plan to use such a plugin, then use a normal audio or MIDI track instead."),
318 true, MESSAGE_INFO, BUTTONS_OK, true);
319 msg.set_position (WIN_POS_MOUSE);
322 channel_combo.set_sensitive (true);
323 mode_combo.set_sensitive (true);
324 instrument_combo.set_sensitive (true);
325 configuration_label.set_sensitive (true);
326 mode_label.set_sensitive (true);
327 instrument_label.set_sensitive (true);
328 route_group_combo.set_sensitive (true);
329 strict_io_combo.set_sensitive (true);
330 insert_at_combo.set_sensitive (true);
333 mode_combo.set_sensitive (false);
334 channel_combo.set_sensitive (true);
335 instrument_combo.set_sensitive (false);
336 configuration_label.set_sensitive (true);
337 mode_label.set_sensitive (true);
338 instrument_label.set_sensitive (false);
339 route_group_combo.set_sensitive (true);
340 strict_io_combo.set_sensitive (true);
341 insert_at_combo.set_sensitive (true);
344 mode_combo.set_sensitive (false);
345 channel_combo.set_sensitive (false);
346 instrument_combo.set_sensitive (false);
347 configuration_label.set_sensitive (false);
348 mode_label.set_sensitive (false);
349 instrument_label.set_sensitive (false);
350 route_group_combo.set_sensitive (false);
351 strict_io_combo.set_sensitive (false);
352 insert_at_combo.set_sensitive (false);
355 mode_combo.set_sensitive (false);
356 channel_combo.set_sensitive (false);
357 instrument_combo.set_sensitive (true);
358 configuration_label.set_sensitive (false);
359 mode_label.set_sensitive (true);
360 instrument_label.set_sensitive (true);
361 strict_io_combo.set_sensitive (true);
362 insert_at_combo.set_sensitive (true);
366 maybe_update_name_template_entry ();
371 AddRouteDialog::name_template () const
373 return name_template_entry.get_text ();
377 AddRouteDialog::name_template_is_default() const
379 string n = name_template();
381 if (n == _("Audio") ||
383 n == _("Audio+MIDI") ||
385 n == VCA::default_name_template()) {
393 AddRouteDialog::count ()
395 return (int) floor (routes_adjustment.get_value ());
399 AddRouteDialog::refill_track_modes ()
403 s.push_back (_("Normal"));
404 #ifdef XXX_OLD_DESTRUCTIVE_API_XXX
405 s.push_back (_("Non Layered"));
407 if (!ARDOUR::Profile->get_mixbus ()) {
408 s.push_back (_("Tape"));
411 set_popdown_strings (mode_combo, s);
412 mode_combo.set_active_text (s.front());
416 AddRouteDialog::mode ()
418 std::string str = mode_combo.get_active_text();
419 if (str == _("Normal")) {
420 return ARDOUR::Normal;
421 } else if (str == _("Non Layered")){
422 return ARDOUR::NonLayered;
423 } else if (str == _("Tape")) {
424 return ARDOUR::Destructive;
426 fatal << string_compose (X_("programming error: unknown track mode in add route dialog combo = %1"), str)
428 abort(); /*NOTREACHED*/
431 return ARDOUR::Normal;
435 AddRouteDialog::channels ()
439 switch (type_wanted()) {
442 str = channel_combo.get_active_text();
443 for (ChannelSetups::iterator i = channel_setups.begin(); i != channel_setups.end(); ++i) {
444 if (str == (*i).name) {
445 ret.set (DataType::AUDIO, (*i).channels);
449 ret.set (DataType::MIDI, 0);
454 ret.set (DataType::AUDIO, 0);
455 ret.set (DataType::MIDI, 1);
459 str = channel_combo.get_active_text();
460 for (ChannelSetups::iterator i = channel_setups.begin(); i != channel_setups.end(); ++i) {
461 if (str == (*i).name) {
462 ret.set (DataType::AUDIO, (*i).channels);
466 ret.set (DataType::MIDI, 1);
476 AddRouteDialog::track_template ()
478 string str = channel_combo.get_active_text();
480 for (ChannelSetups::iterator i = channel_setups.begin(); i != channel_setups.end(); ++i) {
481 if (str == (*i).name) {
482 return (*i).template_path;
490 AddRouteDialog::on_show ()
492 routes_spinner.grab_focus ();
493 name_edited_by_user = false;
495 refill_channel_setups ();
496 refill_route_groups ();
502 AddRouteDialog::refill_channel_setups ()
506 route_templates.clear ();
508 string channel_current_choice = channel_combo.get_active_text();
510 channel_combo_strings.clear ();
511 channel_setups.clear ();
513 chn.name = _("Mono");
515 channel_setups.push_back (chn);
517 chn.name = _("Stereo");
519 channel_setups.push_back (chn);
521 chn.name = "separator";
522 channel_setups.push_back (chn);
524 ARDOUR::find_route_templates (route_templates);
526 if (!route_templates.empty()) {
528 for (vector<TemplateInfo>::iterator x = route_templates.begin(); x != route_templates.end(); ++x) {
531 chn.template_path = x->path;
532 channel_setups.push_back (chn);
536 /* clear template path for the rest */
538 chn.template_path = "";
540 chn.name = _("3 Channel");
542 channel_setups.push_back (chn);
544 chn.name = _("4 Channel");
546 channel_setups.push_back (chn);
548 chn.name = _("5 Channel");
550 channel_setups.push_back (chn);
552 chn.name = _("6 Channel");
554 channel_setups.push_back (chn);
556 chn.name = _("8 Channel");
558 channel_setups.push_back (chn);
560 chn.name = _("12 Channel");
562 channel_setups.push_back (chn);
564 chn.name = _("Custom");
566 channel_setups.push_back (chn);
568 for (ChannelSetups::iterator i = channel_setups.begin(); i != channel_setups.end(); ++i) {
569 channel_combo_strings.push_back ((*i).name);
572 set_popdown_strings (channel_combo, channel_combo_strings);
574 if (!channel_current_choice.empty()) {
575 channel_combo.set_active_text (channel_current_choice);
577 channel_combo.set_active_text (channel_combo_strings.front());
582 AddRouteDialog::add_route_group (RouteGroup* g)
584 route_group_combo.insert_text (3, g->name ());
588 AddRouteDialog::route_group ()
590 if (!_session || route_group_combo.get_active_row_number () == 2) {
594 return _session->route_group_by_name (route_group_combo.get_active_text());
598 AddRouteDialog::use_strict_io() {
599 return strict_io_combo.get_active_row_number () == 1;
603 AddRouteDialog::refill_route_groups ()
605 route_group_combo.clear ();
606 route_group_combo.append_text (_("New Group..."));
608 route_group_combo.append_text ("separator");
610 route_group_combo.append_text (_("No Group"));
613 _session->foreach_route_group (sigc::mem_fun (*this, &AddRouteDialog::add_route_group));
616 route_group_combo.set_active (2);
620 AddRouteDialog::group_changed ()
622 if (_session && route_group_combo.get_active_text () == _("New Group...")) {
623 RouteGroup* g = new RouteGroup (*_session, "");
624 RouteGroupDialog* d = new RouteGroupDialog (g, true);
626 d->signal_response().connect (sigc::bind (sigc::mem_fun (*this, &AddRouteDialog::new_group_dialog_finished), d));
632 AddRouteDialog::new_group_dialog_finished (int r, RouteGroupDialog* d)
634 if (r == RESPONSE_OK) {
636 if (!d->name_check()) {
641 _session->add_route_group (d->group());
644 add_route_group (d->group());
645 route_group_combo.set_active (3);
648 route_group_combo.set_active (2);
651 delete_when_idle (d);
654 RouteDialogs::InsertAt
655 AddRouteDialog::insert_at ()
657 using namespace RouteDialogs;
659 std::string str = insert_at_combo.get_active_text();
661 if (str == _("First")) {
663 } else if (str == _("After Selection")) {
664 return AfterSelection;
665 } else if (str == _("Before Selection")){
666 return BeforeSelection;
672 AddRouteDialog::channel_separator (const Glib::RefPtr<Gtk::TreeModel> &, const Gtk::TreeModel::iterator &i)
674 channel_combo.set_active (i);
676 return channel_combo.get_active_text () == "separator";
680 AddRouteDialog::route_separator (const Glib::RefPtr<Gtk::TreeModel> &, const Gtk::TreeModel::iterator &i)
682 route_group_combo.set_active (i);
684 return route_group_combo.get_active_text () == "separator";
688 AddRouteDialog::requested_instrument ()
690 return instrument_combo.selected_instrument();