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());
288 AddRouteDialog::track_type_chosen ()
290 switch (type_wanted()) {
292 mode_combo.set_sensitive (true);
293 channel_combo.set_sensitive (true);
294 instrument_combo.set_sensitive (false);
295 configuration_label.set_sensitive (true);
296 mode_label.set_sensitive (true);
297 instrument_label.set_sensitive (false);
298 route_group_combo.set_sensitive (true);
299 strict_io_combo.set_sensitive (true);
300 insert_at_combo.set_sensitive (true);
303 channel_combo.set_sensitive (false);
304 mode_combo.set_sensitive (false);
305 instrument_combo.set_sensitive (true);
306 configuration_label.set_sensitive (false);
307 mode_label.set_sensitive (false);
308 instrument_label.set_sensitive (true);
309 route_group_combo.set_sensitive (true);
310 strict_io_combo.set_sensitive (true);
311 insert_at_combo.set_sensitive (true);
315 MessageDialog msg (_("Audio+MIDI tracks are intended for use <b>ONLY</b> with plugins that use both audio and MIDI input data\n\n"
316 "If you do not plan to use such a plugin, then use a normal audio or MIDI track instead."),
317 true, MESSAGE_INFO, BUTTONS_OK, true);
318 msg.set_position (WIN_POS_MOUSE);
321 channel_combo.set_sensitive (true);
322 mode_combo.set_sensitive (true);
323 instrument_combo.set_sensitive (true);
324 configuration_label.set_sensitive (true);
325 mode_label.set_sensitive (true);
326 instrument_label.set_sensitive (true);
327 route_group_combo.set_sensitive (true);
328 strict_io_combo.set_sensitive (true);
329 insert_at_combo.set_sensitive (true);
332 mode_combo.set_sensitive (false);
333 channel_combo.set_sensitive (true);
334 instrument_combo.set_sensitive (false);
335 configuration_label.set_sensitive (true);
336 mode_label.set_sensitive (true);
337 instrument_label.set_sensitive (false);
338 route_group_combo.set_sensitive (true);
339 strict_io_combo.set_sensitive (true);
340 insert_at_combo.set_sensitive (true);
343 mode_combo.set_sensitive (false);
344 channel_combo.set_sensitive (false);
345 instrument_combo.set_sensitive (false);
346 configuration_label.set_sensitive (false);
347 mode_label.set_sensitive (false);
348 instrument_label.set_sensitive (false);
349 route_group_combo.set_sensitive (false);
350 strict_io_combo.set_sensitive (false);
351 insert_at_combo.set_sensitive (false);
354 mode_combo.set_sensitive (false);
355 channel_combo.set_sensitive (false);
356 instrument_combo.set_sensitive (true);
357 configuration_label.set_sensitive (false);
358 mode_label.set_sensitive (true);
359 instrument_label.set_sensitive (true);
360 strict_io_combo.set_sensitive (true);
361 insert_at_combo.set_sensitive (true);
365 maybe_update_name_template_entry ();
370 AddRouteDialog::name_template () const
372 return name_template_entry.get_text ();
376 AddRouteDialog::name_template_is_default() const
378 string n = name_template();
380 if (n == _("Audio") ||
382 n == _("Audio+MIDI") ||
384 n == VCA::default_name_template()) {
392 AddRouteDialog::count ()
394 return (int) floor (routes_adjustment.get_value ());
398 AddRouteDialog::refill_track_modes ()
402 s.push_back (_("Normal"));
403 #ifdef XXX_OLD_DESTRUCTIVE_API_XXX
404 s.push_back (_("Non Layered"));
406 if (!ARDOUR::Profile->get_mixbus ()) {
407 s.push_back (_("Tape"));
410 set_popdown_strings (mode_combo, s);
411 mode_combo.set_active_text (s.front());
415 AddRouteDialog::mode ()
417 std::string str = mode_combo.get_active_text();
418 if (str == _("Normal")) {
419 return ARDOUR::Normal;
420 } else if (str == _("Non Layered")){
421 return ARDOUR::NonLayered;
422 } else if (str == _("Tape")) {
423 return ARDOUR::Destructive;
425 fatal << string_compose (X_("programming error: unknown track mode in add route dialog combo = %1"), str)
427 abort(); /*NOTREACHED*/
430 return ARDOUR::Normal;
434 AddRouteDialog::channels ()
438 switch (type_wanted()) {
441 str = channel_combo.get_active_text();
442 for (ChannelSetups::iterator i = channel_setups.begin(); i != channel_setups.end(); ++i) {
443 if (str == (*i).name) {
444 ret.set (DataType::AUDIO, (*i).channels);
448 ret.set (DataType::MIDI, 0);
453 ret.set (DataType::AUDIO, 0);
454 ret.set (DataType::MIDI, 1);
458 str = channel_combo.get_active_text();
459 for (ChannelSetups::iterator i = channel_setups.begin(); i != channel_setups.end(); ++i) {
460 if (str == (*i).name) {
461 ret.set (DataType::AUDIO, (*i).channels);
465 ret.set (DataType::MIDI, 1);
475 AddRouteDialog::track_template ()
477 string str = channel_combo.get_active_text();
479 for (ChannelSetups::iterator i = channel_setups.begin(); i != channel_setups.end(); ++i) {
480 if (str == (*i).name) {
481 return (*i).template_path;
489 AddRouteDialog::on_show ()
491 routes_spinner.grab_focus ();
492 name_edited_by_user = false;
494 refill_channel_setups ();
495 refill_route_groups ();
501 AddRouteDialog::refill_channel_setups ()
505 route_templates.clear ();
507 string channel_current_choice = channel_combo.get_active_text();
509 channel_combo_strings.clear ();
510 channel_setups.clear ();
512 chn.name = _("Mono");
514 channel_setups.push_back (chn);
516 chn.name = _("Stereo");
518 channel_setups.push_back (chn);
520 chn.name = "separator";
521 channel_setups.push_back (chn);
523 ARDOUR::find_route_templates (route_templates);
525 if (!route_templates.empty()) {
527 for (vector<TemplateInfo>::iterator x = route_templates.begin(); x != route_templates.end(); ++x) {
530 chn.template_path = x->path;
531 channel_setups.push_back (chn);
535 /* clear template path for the rest */
537 chn.template_path = "";
539 chn.name = _("3 Channel");
541 channel_setups.push_back (chn);
543 chn.name = _("4 Channel");
545 channel_setups.push_back (chn);
547 chn.name = _("5 Channel");
549 channel_setups.push_back (chn);
551 chn.name = _("6 Channel");
553 channel_setups.push_back (chn);
555 chn.name = _("8 Channel");
557 channel_setups.push_back (chn);
559 chn.name = _("12 Channel");
561 channel_setups.push_back (chn);
563 chn.name = _("Custom");
565 channel_setups.push_back (chn);
567 for (ChannelSetups::iterator i = channel_setups.begin(); i != channel_setups.end(); ++i) {
568 channel_combo_strings.push_back ((*i).name);
571 set_popdown_strings (channel_combo, channel_combo_strings);
573 if (!channel_current_choice.empty()) {
574 channel_combo.set_active_text (channel_current_choice);
576 channel_combo.set_active_text (channel_combo_strings.front());
581 AddRouteDialog::add_route_group (RouteGroup* g)
583 route_group_combo.insert_text (3, g->name ());
587 AddRouteDialog::route_group ()
589 if (!_session || route_group_combo.get_active_row_number () == 2) {
593 return _session->route_group_by_name (route_group_combo.get_active_text());
597 AddRouteDialog::use_strict_io() {
598 return strict_io_combo.get_active_row_number () == 1;
602 AddRouteDialog::refill_route_groups ()
604 route_group_combo.clear ();
605 route_group_combo.append_text (_("New Group..."));
607 route_group_combo.append_text ("separator");
609 route_group_combo.append_text (_("No Group"));
612 _session->foreach_route_group (sigc::mem_fun (*this, &AddRouteDialog::add_route_group));
615 route_group_combo.set_active (2);
619 AddRouteDialog::group_changed ()
621 if (_session && route_group_combo.get_active_text () == _("New Group...")) {
622 RouteGroup* g = new RouteGroup (*_session, "");
623 RouteGroupDialog* d = new RouteGroupDialog (g, true);
625 d->signal_response().connect (sigc::bind (sigc::mem_fun (*this, &AddRouteDialog::new_group_dialog_finished), d));
631 AddRouteDialog::new_group_dialog_finished (int r, RouteGroupDialog* d)
633 if (r == RESPONSE_OK) {
635 if (!d->name_check()) {
640 _session->add_route_group (d->group());
643 add_route_group (d->group());
644 route_group_combo.set_active (3);
647 route_group_combo.set_active (2);
650 delete_when_idle (d);
653 RouteDialogs::InsertAt
654 AddRouteDialog::insert_at ()
656 using namespace RouteDialogs;
658 std::string str = insert_at_combo.get_active_text();
660 if (str == _("First")) {
662 } else if (str == _("After Selection")) {
663 return AfterSelection;
664 } else if (str == _("Before Selection")){
665 return BeforeSelection;
671 AddRouteDialog::channel_separator (const Glib::RefPtr<Gtk::TreeModel> &, const Gtk::TreeModel::iterator &i)
673 channel_combo.set_active (i);
675 return channel_combo.get_active_text () == "separator";
679 AddRouteDialog::route_separator (const Glib::RefPtr<Gtk::TreeModel> &, const Gtk::TreeModel::iterator &i)
681 route_group_combo.set_active (i);
683 return route_group_combo.get_active_text () == "separator";
687 AddRouteDialog::requested_instrument ()
689 return instrument_combo.selected_instrument();