Fix typo in 952b8e1d74
[ardour.git] / gtk2_ardour / add_route_dialog.cc
1 /*
2   Copyright (C) 2003 Paul Davis
3
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.
8
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.
13
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.
17
18 */
19
20 #include <cstdio>
21 #include <cmath>
22
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>
28
29 #include "pbd/error.h"
30 #include "pbd/convert.h"
31
32 #include "gtkmm2ext/utils.h"
33 #include "gtkmm2ext/doi.h"
34
35 #include "widgets/tooltips.h"
36
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"
43
44 #include "utils.h"
45 #include "add_route_dialog.h"
46 #include "route_group_dialog.h"
47 #include "pbd/i18n.h"
48
49 using namespace Gtk;
50 using namespace Gtkmm2ext;
51 using namespace std;
52 using namespace PBD;
53 using namespace ARDOUR;
54 using namespace ARDOUR_UI_UTILS;
55
56 std::vector<std::string> AddRouteDialog::channel_combo_strings;
57
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         , manual_label (_("Manual Configuration:"))
64         , add_label (_("Add:"))
65         , type_label (_("Type:"))
66         , name_label (_("Name:"))
67         , group_label (_("Group:"))
68         , insert_label (_("Insert At:"))
69         , strict_io_label (_("Pin Mode:"))
70         , mode_label (_("Record Mode:"))
71         , instrument_label (_("Instrument:"))
72         , name_edited_by_user (false)
73 {
74         set_name ("AddRouteDialog");
75         set_skip_taskbar_hint (true);
76         set_resizable (false);
77         set_position (WIN_POS_MOUSE);
78
79         name_template_entry.set_name (X_("AddRouteDialogNameTemplateEntry"));
80         // routes_spinner.set_name (X_("AddRouteDialogSpinner"));
81         channel_combo.set_name (X_("ChannelCountSelector"));
82         mode_combo.set_name (X_("ChannelCountSelector"));
83
84         refill_track_modes ();
85
86         track_bus_combo.append_text (_("Audio Tracks"));
87         track_bus_combo.append_text (_("MIDI Tracks"));
88         track_bus_combo.append_text (_("Audio+MIDI Tracks"));
89         track_bus_combo.append_text (_("Audio Busses"));
90         track_bus_combo.append_text (_("MIDI Busses"));
91         track_bus_combo.append_text (_("VCA Masters"));
92         track_bus_combo.set_active (0);
93
94         insert_at_combo.append_text (_("First"));
95         insert_at_combo.append_text (_("Before Selection"));
96         insert_at_combo.append_text (_("After Selection"));
97         insert_at_combo.append_text (_("Last"));
98         insert_at_combo.set_active (3);
99
100         strict_io_combo.append_text (_("Flexible-I/O"));
101         strict_io_combo.append_text (_("Strict-I/O"));
102         strict_io_combo.set_active (Config->get_strict_io () ? 1 : 0);
103
104         VBox* vbox = manage (new VBox);
105
106         get_vbox()->set_spacing (4);
107
108         vbox->set_spacing (18);
109         vbox->set_border_width (5);
110
111         HBox* template_hbox = manage (new HBox);
112         template_hbox->set_spacing (8);
113
114         Gtk::ScrolledWindow *template_scroller = manage (new Gtk::ScrolledWindow());
115         template_scroller->set_policy (Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC);
116         template_scroller->add (trk_template_chooser);
117
118         Gtk::ScrolledWindow *desc_scroller = manage (new Gtk::ScrolledWindow());
119         desc_scroller->set_policy (Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC);
120         desc_scroller->add (trk_template_desc);
121
122         template_hbox->pack_start (*template_scroller, true, true);
123
124         trk_template_desc_frame.set_name (X_("TextHighlightFrame"));
125         trk_template_desc_frame.add (*desc_scroller);
126         template_hbox->pack_start (trk_template_desc_frame, true, true);
127
128         /* template_chooser is the treeview showing available templates */
129         trk_template_model = TreeStore::create (track_template_columns);
130         trk_template_chooser.set_model (trk_template_model);
131         trk_template_chooser.append_column (_("Template"), track_template_columns.name);
132 #ifdef MIXBUS
133         trk_template_chooser.append_column (_("Created With"), track_template_columns.created_with);
134 #endif
135         trk_template_chooser.set_headers_visible (true);
136         trk_template_chooser.get_selection()->set_mode (SELECTION_SINGLE);
137         trk_template_chooser.get_selection()->signal_changed().connect (sigc::mem_fun (*this, &AddRouteDialog::trk_template_row_selected));
138         trk_template_chooser.set_sensitive (true);
139
140         /* template_desc is the textview that displays the currently selected template's description */
141         trk_template_desc.set_editable (false);
142         trk_template_desc.set_wrap_mode (Gtk::WRAP_WORD);
143         trk_template_desc.set_size_request(400,200);
144         trk_template_desc.set_name (X_("TextOnBackground"));
145         trk_template_desc.set_border_width (6);
146
147         vbox->pack_start (*template_hbox, true, true);
148
149         HBox *separator_hbox = manage (new HBox);
150         separator_hbox->pack_start (manual_label, false, false);
151         separator_hbox->pack_start (*(manage (new Gtk::HSeparator)), true, true);
152         separator_hbox->set_spacing (6);
153         vbox->pack_start (*separator_hbox, true, true);
154
155         /* track/bus choice */
156
157         Table *add_table = manage (new Table (8, 8, false));
158         add_table->set_row_spacings (8);
159         add_table->set_col_spacings     (3);
160         add_table->set_col_spacing      (1, 12);
161         add_table->set_col_spacing      (3, 12);
162         add_table->set_col_spacing      (5, 12);
163         add_table->set_border_width     (0);
164
165         int n = 0;
166
167         // Number
168         add_label.set_alignment (Gtk::ALIGN_RIGHT, Gtk::ALIGN_CENTER);
169         add_table->attach (add_label, 0, 1, n, n + 1, Gtk::FILL, Gtk::EXPAND, 0, 0);
170         add_table->attach (routes_spinner, 1, 2, n, n + 1, Gtk::FILL, Gtk::EXPAND, 0, 0);
171
172         // Type
173         type_label.set_alignment (Gtk::ALIGN_RIGHT, Gtk::ALIGN_CENTER);
174         add_table->attach (type_label, 2,3, n, n + 1, Gtk::FILL, Gtk::EXPAND, 0, 0);
175         add_table->attach (track_bus_combo, 3, 4, n, n + 1, Gtk::FILL, Gtk::EXPAND, 0, 0);
176
177         // Name
178         name_label.set_alignment (Gtk::ALIGN_RIGHT, Gtk::ALIGN_CENTER);
179         add_table->attach (name_label, 4, 5, n, n + 1, Gtk::FILL, Gtk::EXPAND, 0, 0);
180         add_table->attach (name_template_entry, 5, 8, n, n + 1, Gtk::FILL, Gtk::EXPAND | Gtk::FILL, 0, 0);
181
182         ++n;
183
184         // Route configuration
185         configuration_label.set_alignment (Gtk::ALIGN_RIGHT, Gtk::ALIGN_CENTER);
186         add_table->attach (configuration_label, 2, 3, n, n + 1, Gtk::FILL, Gtk::EXPAND, 0, 0);
187         add_table->attach (channel_combo, 3, 4, n, n + 1, Gtk::FILL, Gtk::EXPAND | Gtk::FILL, 0, 0);
188
189         // Group choice
190         group_label.set_alignment (Gtk::ALIGN_RIGHT, Gtk::ALIGN_CENTER);
191         add_table->attach (group_label, 4, 5, n, n + 1, Gtk::FILL, Gtk::EXPAND, 0, 0);
192         add_table->attach (route_group_combo, 5, 8, n, n + 1, Gtk::FILL, Gtk::EXPAND | Gtk::FILL, 0, 0);
193
194         ++n;
195
196         // instrument choice (for MIDI)
197         instrument_label.set_alignment (Gtk::ALIGN_RIGHT, Gtk::ALIGN_CENTER);
198         add_table->attach (instrument_label, 2, 3, n, n + 1, Gtk::FILL, Gtk::EXPAND, 0, 0);
199         add_table->attach (instrument_combo, 3, 4, n, n + 1, Gtk::FILL, Gtk::EXPAND | Gtk::FILL, 0, 0);
200
201         ++n;
202
203         // New Route's I/O is.. {strict/flexible}
204         if (Profile->get_mixbus ()) {
205                 strict_io_combo.set_active (1);
206         } else {
207                 strict_io_label.set_alignment (Gtk::ALIGN_RIGHT, Gtk::ALIGN_CENTER);
208                 add_table->attach (strict_io_label, 2, 3, n, n + 1, Gtk::FILL, Gtk::EXPAND, 0, 0);
209                 add_table->attach (strict_io_combo, 3, 4, n, n + 1, Gtk::FILL, Gtk::EXPAND | Gtk::FILL, 0, 0);
210
211                 ArdourWidgets::set_tooltip (strict_io_combo,
212                                 _("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."));
213
214                 // recording mode
215                 mode_label.set_alignment (Gtk::ALIGN_RIGHT, Gtk::ALIGN_CENTER);
216                 add_table->attach (mode_label, 4, 5, n, n + 1, Gtk::FILL, Gtk::EXPAND, 0, 0);
217                 add_table->attach (mode_combo, 5, 8, n, n + 1, Gtk::FILL, Gtk::EXPAND | Gtk::FILL, 0, 0);
218
219                 ++n;
220         }
221
222         // Separator
223         ++n;
224         add_table->attach (*(manage (new Gtk::HSeparator)), 0, 8, n, n + 1, Gtk::FILL, Gtk::EXPAND, 0, 0);
225
226         ++n;
227         ++n;
228         // New route will be inserted at..
229         insert_label.set_alignment (Gtk::ALIGN_RIGHT, Gtk::ALIGN_CENTER);
230         add_table->attach (insert_label, 2, 3, n, n + 1, Gtk::FILL, Gtk::EXPAND, 0, 0);
231         add_table->attach (insert_at_combo, 3, 4, n, n + 1, Gtk::FILL, Gtk::EXPAND | Gtk::FILL, 0, 0);
232
233         add_table->attach (*(manage (new Gtk::Button(_("Add selected items (and leave dialog open)"), Add))), 5, 8, n, n + 1, Gtk::FILL, Gtk::EXPAND | Gtk::FILL, 0, 0);
234
235
236         vbox->pack_start (*add_table, false, true);
237
238         get_vbox()->pack_start (*vbox, false, false);
239
240         name_template_entry.signal_insert_text ().connect (sigc::mem_fun (*this, &AddRouteDialog::name_template_entry_insertion));
241         name_template_entry.signal_delete_text ().connect (sigc::mem_fun (*this, &AddRouteDialog::name_template_entry_deletion));
242         track_bus_combo.signal_changed().connect (sigc::mem_fun (*this, &AddRouteDialog::track_type_chosen));
243         channel_combo.signal_changed().connect (sigc::mem_fun (*this, &AddRouteDialog::channel_combo_changed));
244         channel_combo.set_row_separator_func (sigc::mem_fun (*this, &AddRouteDialog::channel_separator));
245         route_group_combo.set_row_separator_func (sigc::mem_fun (*this, &AddRouteDialog::route_separator));
246         route_group_combo.signal_changed ().connect (sigc::mem_fun (*this, &AddRouteDialog::group_changed));
247
248         show_all_children ();
249
250         /* track template info will be managed whenever
251          * this dialog is shown, via ::on_show()
252          */
253
254         add_button (_("Add and Close"), AddAndClose);
255         //add_button (_("Add"), Add);
256         set_response_sensitive (AddAndClose, true);
257         set_default_response (AddAndClose);
258
259         track_type_chosen ();
260 }
261
262 AddRouteDialog::~AddRouteDialog ()
263 {
264 }
265
266 void
267 AddRouteDialog::on_response (int r)
268 {
269         name_edited_by_user = false;
270         /* Don't call ArdourDialog::on_response() because that will
271            automatically hide the dialog.
272         */
273         Gtk::Dialog::on_response (r);
274 }
275
276 void
277 AddRouteDialog::trk_template_row_selected ()
278 {
279         if (trk_template_chooser.get_selection()->count_selected_rows() > 0) {
280                 TreeIter iter = trk_template_chooser.get_selection()->get_selected();
281
282                 if (!iter) {
283                         return;
284                 }
285
286                 string d = (*iter)[track_template_columns.description];
287                 trk_template_desc.get_buffer()->set_text (d);
288
289                 string n = (*iter)[track_template_columns.name];
290                 if ( n != _("Manual Configuration") ) {
291
292                         trk_template_desc.set_sensitive(true);
293
294                         manual_label.set_sensitive(false);
295                         add_label.set_sensitive(false);
296                         type_label.set_sensitive(false);
297                         name_label.set_sensitive(false);
298                         group_label.set_sensitive(false);
299                         strict_io_label.set_sensitive(false);
300                         configuration_label.set_sensitive(false);
301                         mode_label.set_sensitive(false);
302
303                         routes_spinner.set_sensitive(false);
304                         track_bus_combo.set_sensitive(false);
305                         name_template_entry.set_sensitive(false);
306                         channel_combo.set_sensitive(false);
307                         mode_combo.set_sensitive(false);
308                         instrument_combo.set_sensitive(false);
309                         strict_io_combo.set_sensitive(false);
310                         route_group_combo.set_sensitive(false);
311
312                 } else {
313
314                         trk_template_desc.set_sensitive(false);
315
316                         manual_label.set_sensitive(true);
317                         add_label.set_sensitive(true);
318                         type_label.set_sensitive(true);
319                         name_label.set_sensitive(true);
320                         group_label.set_sensitive(true);
321                         strict_io_label.set_sensitive(true);
322
323                         track_bus_combo.set_sensitive(true);
324                         routes_spinner.set_sensitive(true);
325                         name_template_entry.set_sensitive(true);
326                         track_type_chosen();
327                 }
328         }
329 }
330
331
332 void
333 AddRouteDialog::name_template_entry_insertion (Glib::ustring const &,int*)
334 {
335         name_edited_by_user = true;
336 }
337
338 void
339 AddRouteDialog::name_template_entry_deletion (int, int)
340 {
341         name_edited_by_user = true;
342 }
343
344 void
345 AddRouteDialog::channel_combo_changed ()
346 {
347         refill_track_modes ();
348 }
349
350 std::string
351 AddRouteDialog::get_template_path ()
352 {
353         string p;
354         
355         if (trk_template_chooser.get_selection()->count_selected_rows() > 0) {
356                 TreeIter iter = trk_template_chooser.get_selection()->get_selected();
357
358                 if (iter) {
359                         string n = (*iter)[track_template_columns.name];
360                         if ( n != _("Manual Configuration") ) {
361                                 p = (*iter)[track_template_columns.path];
362                         }
363                 }
364         }
365
366         return p;
367 }
368
369
370 AddRouteDialog::TypeWanted
371 AddRouteDialog::type_wanted() const
372 {
373         std::string str = track_bus_combo.get_active_text();
374         if (str == _("Audio Busses")) {
375                 return AudioBus;
376         } else if (str == _("MIDI Busses")){
377                 return MidiBus;
378         } else if (str == _("MIDI Tracks")){
379                 return MidiTrack;
380         } else if (str == _("Audio+MIDI Tracks")) {
381                 return MixedTrack;
382         } else if (str == _("Audio Tracks")) {
383                 return AudioTrack;
384         } else {
385                 return VCAMaster;
386         }
387 }
388
389 void
390 AddRouteDialog::maybe_update_name_template_entry ()
391 {
392         if (name_edited_by_user) {
393                 return;
394         }
395
396         switch (type_wanted()) {
397         case AudioTrack:
398                 name_template_entry.set_text (_("Audio"));
399                 break;
400         case MidiTrack:
401                 name_template_entry.set_text (_("MIDI"));
402                 break;
403         case MixedTrack:
404                 name_template_entry.set_text (_("Audio+MIDI"));
405                 break;
406         case AudioBus:
407         case MidiBus:
408                 name_template_entry.set_text (_("Bus"));
409                 break;
410         case VCAMaster:
411                 name_template_entry.set_text (VCA::default_name_template());
412                 break;
413         }
414         name_edited_by_user = false;
415 }
416
417 void
418 AddRouteDialog::track_type_chosen ()
419 {
420         switch (type_wanted()) {
421         case AudioTrack:
422                 mode_combo.set_sensitive (true);
423                 channel_combo.set_sensitive (true);
424                 instrument_combo.set_sensitive (false);
425                 configuration_label.set_sensitive (true);
426                 mode_label.set_sensitive (true);
427                 instrument_label.set_sensitive (false);
428                 route_group_combo.set_sensitive (true);
429                 strict_io_combo.set_sensitive (true);
430                 insert_at_combo.set_sensitive (true);
431                 break;
432         case MidiTrack:
433                 channel_combo.set_sensitive (false);
434                 mode_combo.set_sensitive (false);
435                 instrument_combo.set_sensitive (true);
436                 configuration_label.set_sensitive (false);
437                 mode_label.set_sensitive (false);
438                 instrument_label.set_sensitive (true);
439                 route_group_combo.set_sensitive (true);
440                 strict_io_combo.set_sensitive (true);
441                 insert_at_combo.set_sensitive (true);
442                 break;
443         case MixedTrack:
444                 {
445                         MessageDialog msg (_("Audio+MIDI tracks are intended for use <b>ONLY</b> with plugins that use both audio and MIDI input data\n\n"
446                                              "If you do not plan to use such a plugin, then use a normal audio or MIDI track instead."),
447                                            true, MESSAGE_INFO, BUTTONS_OK, true);
448                         msg.set_position (WIN_POS_MOUSE);
449                         msg.run ();
450                 }
451                 channel_combo.set_sensitive (true);
452                 mode_combo.set_sensitive (true);
453                 instrument_combo.set_sensitive (true);
454                 configuration_label.set_sensitive (true);
455                 mode_label.set_sensitive (true);
456                 instrument_label.set_sensitive (true);
457                 route_group_combo.set_sensitive (true);
458                 strict_io_combo.set_sensitive (true);
459                 insert_at_combo.set_sensitive (true);
460                 break;
461         case AudioBus:
462                 mode_combo.set_sensitive (false);
463                 channel_combo.set_sensitive (true);
464                 instrument_combo.set_sensitive (false);
465                 configuration_label.set_sensitive (true);
466                 mode_label.set_sensitive (true);
467                 instrument_label.set_sensitive (false);
468                 route_group_combo.set_sensitive (true);
469                 strict_io_combo.set_sensitive (true);
470                 insert_at_combo.set_sensitive (true);
471                 break;
472         case VCAMaster:
473                 mode_combo.set_sensitive (false);
474                 channel_combo.set_sensitive (false);
475                 instrument_combo.set_sensitive (false);
476                 configuration_label.set_sensitive (false);
477                 mode_label.set_sensitive (false);
478                 instrument_label.set_sensitive (false);
479                 route_group_combo.set_sensitive (false);
480                 strict_io_combo.set_sensitive (false);
481                 insert_at_combo.set_sensitive (false);
482                 break;
483         case MidiBus:
484                 mode_combo.set_sensitive (false);
485                 channel_combo.set_sensitive (false);
486                 instrument_combo.set_sensitive (true);
487                 configuration_label.set_sensitive (false);
488                 mode_label.set_sensitive (true);
489                 instrument_label.set_sensitive (true);
490                 strict_io_combo.set_sensitive (true);
491                 insert_at_combo.set_sensitive (true);
492                 break;
493         }
494
495         maybe_update_name_template_entry ();
496
497 }
498
499
500 string
501 AddRouteDialog::name_template () const
502 {
503         return name_template_entry.get_text ();
504 }
505
506 bool
507 AddRouteDialog::name_template_is_default() const
508 {
509         string n = name_template();
510
511         if (n == _("Audio") ||
512             n == _("MIDI") ||
513             n == _("Audio+MIDI") ||
514             n == _("Bus") ||
515             n == VCA::default_name_template()) {
516                 return true;
517         }
518
519         return false;
520 }
521
522 int
523 AddRouteDialog::count ()
524 {
525         return (int) floor (routes_adjustment.get_value ());
526 }
527
528 void
529 AddRouteDialog::refill_track_modes ()
530 {
531         vector<string> s;
532
533         s.push_back (_("Normal"));
534 #ifdef XXX_OLD_DESTRUCTIVE_API_XXX
535         s.push_back (_("Non Layered"));
536 #endif
537         if (!ARDOUR::Profile->get_mixbus ()) {
538                 s.push_back (_("Tape"));
539         }
540
541         set_popdown_strings (mode_combo, s);
542         mode_combo.set_active_text (s.front());
543 }
544
545 ARDOUR::TrackMode
546 AddRouteDialog::mode ()
547 {
548         std::string str = mode_combo.get_active_text();
549         if (str == _("Normal")) {
550                 return ARDOUR::Normal;
551         } else if (str == _("Non Layered")){
552                 return ARDOUR::NonLayered;
553         } else if (str == _("Tape")) {
554                 return ARDOUR::Destructive;
555         } else {
556                 fatal << string_compose (X_("programming error: unknown track mode in add route dialog combo = %1"), str)
557                       << endmsg;
558                 abort(); /*NOTREACHED*/
559         }
560         /* keep gcc happy */
561         return ARDOUR::Normal;
562 }
563
564 ChanCount
565 AddRouteDialog::channels ()
566 {
567         ChanCount ret;
568         string str;
569         switch (type_wanted()) {
570         case AudioTrack:
571         case AudioBus:
572                 str = channel_combo.get_active_text();
573                 for (ChannelSetups::iterator i = channel_setups.begin(); i != channel_setups.end(); ++i) {
574                         if (str == (*i).name) {
575                                 ret.set (DataType::AUDIO, (*i).channels);
576                                 break;
577                         }
578                 }
579                 ret.set (DataType::MIDI, 0);
580                 break;
581
582         case MidiBus:
583         case MidiTrack:
584                 ret.set (DataType::AUDIO, 0);
585                 ret.set (DataType::MIDI, 1);
586                 break;
587
588         case MixedTrack:
589                 str = channel_combo.get_active_text();
590                 for (ChannelSetups::iterator i = channel_setups.begin(); i != channel_setups.end(); ++i) {
591                         if (str == (*i).name) {
592                                 ret.set (DataType::AUDIO, (*i).channels);
593                                 break;
594                         }
595                 }
596                 ret.set (DataType::MIDI, 1);
597                 break;
598         default:
599                 break;
600         }
601
602         return ret;
603 }
604
605 string
606 AddRouteDialog::track_template ()
607 {
608         string str = channel_combo.get_active_text();
609
610         for (ChannelSetups::iterator i = channel_setups.begin(); i != channel_setups.end(); ++i) {
611                 if (str == (*i).name) {
612                         return (*i).template_path;
613                 }
614         }
615
616         return string();
617 }
618
619 void
620 AddRouteDialog::on_show ()
621 {
622         routes_spinner.grab_focus ();
623         name_edited_by_user = false;
624
625         refill_channel_setups ();
626         refill_route_groups ();
627
628         Dialog::on_show ();
629 }
630
631 void
632 AddRouteDialog::refill_channel_setups ()
633 {
634         ChannelSetup chn;
635
636         route_templates.clear ();
637
638         string channel_current_choice = channel_combo.get_active_text();
639
640         channel_combo_strings.clear ();
641         channel_setups.clear ();
642
643         chn.name = _("Mono");
644         chn.channels = 1;
645         channel_setups.push_back (chn);
646
647         chn.name = _("Stereo");
648         chn.channels = 2;
649         channel_setups.push_back (chn);
650
651         chn.name = "separator";
652         channel_setups.push_back (chn);
653
654         ARDOUR::find_route_templates (route_templates);
655
656         if (!route_templates.empty()) {
657                 vector<string> v;
658                 for (vector<TemplateInfo>::iterator x = route_templates.begin(); x != route_templates.end(); ++x) {
659                         chn.name = x->name;
660                         chn.channels = 0;
661                         chn.template_path = x->path;
662                         channel_setups.push_back (chn);
663                 }
664         }
665
666         trk_template_model->clear();
667
668         //Add any Lua scripts (factory templates) found in the scripts folder
669     LuaScriptList& ms (LuaScripting::instance ().scripts (LuaScriptInfo::TrackSetup));
670         for (LuaScriptList::const_iterator s = ms.begin(); s != ms.end(); ++s) {
671                 TreeModel::Row row;
672                 if ( (*s)->name == "Add tracks") {  //somewhat-special, most-used template
673                         row = *(trk_template_model->prepend ());
674                 } else {
675                         row = *(trk_template_model->append ());
676                 }
677                 row[track_template_columns.name] = (*s)->name;
678                 row[track_template_columns.path] = "urn:ardour:" + (*s)->path;
679                 row[track_template_columns.description] = (*s)->description;
680                 row[track_template_columns.created_with] = _("{Factory Template}");
681
682                 if ( (*s)->name == "Add tracks") {  //somewhat-special, most-used template
683                         trk_template_chooser.get_selection()->select(row);
684                 }
685         }
686
687         //Add a special item for "Manual Configuration)
688         TreeModel::Row row = *(trk_template_model->prepend ());
689         row[track_template_columns.name] = _("Manual Configuration");
690         row[track_template_columns.path] = "urn:ardour:manual";
691         row[track_template_columns.description] = _("Use the controls, below, to add tracks.");
692         row[track_template_columns.created_with] = "";
693
694         /* clear template path for the rest */
695
696         chn.template_path = "";
697
698         chn.name = _("3 Channel");
699         chn.channels = 3;
700         channel_setups.push_back (chn);
701
702         chn.name = _("4 Channel");
703         chn.channels = 4;
704         channel_setups.push_back (chn);
705
706         chn.name = _("5 Channel");
707         chn.channels = 5;
708         channel_setups.push_back (chn);
709
710         chn.name = _("6 Channel");
711         chn.channels = 6;
712         channel_setups.push_back (chn);
713
714         chn.name = _("8 Channel");
715         chn.channels = 8;
716         channel_setups.push_back (chn);
717
718         chn.name = _("12 Channel");
719         chn.channels = 12;
720         channel_setups.push_back (chn);
721
722         chn.name = _("Custom");
723         chn.channels = 0;
724         channel_setups.push_back (chn);
725
726         for (ChannelSetups::iterator i = channel_setups.begin(); i != channel_setups.end(); ++i) {
727                 channel_combo_strings.push_back ((*i).name);
728         }
729
730         set_popdown_strings (channel_combo, channel_combo_strings);
731
732         if (!channel_current_choice.empty()) {
733                 channel_combo.set_active_text (channel_current_choice);
734         } else {
735                 channel_combo.set_active_text (channel_combo_strings.front());
736         }
737 }
738
739 void
740 AddRouteDialog::add_route_group (RouteGroup* g)
741 {
742         route_group_combo.insert_text (3, g->name ());
743 }
744
745 RouteGroup*
746 AddRouteDialog::route_group ()
747 {
748         if (!_session || route_group_combo.get_active_row_number () == 2) {
749                 return 0;
750         }
751
752         return _session->route_group_by_name (route_group_combo.get_active_text());
753 }
754
755 bool
756 AddRouteDialog::use_strict_io() {
757         return strict_io_combo.get_active_row_number () == 1;
758 }
759
760 void
761 AddRouteDialog::refill_route_groups ()
762 {
763         route_group_combo.clear ();
764         route_group_combo.append_text (_("New Group..."));
765
766         route_group_combo.append_text ("separator");
767
768         route_group_combo.append_text (_("No Group"));
769
770         if (_session) {
771                 _session->foreach_route_group (sigc::mem_fun (*this, &AddRouteDialog::add_route_group));
772         }
773
774         route_group_combo.set_active (2);
775 }
776
777 void
778 AddRouteDialog::group_changed ()
779 {
780         if (_session && route_group_combo.get_active_text () == _("New Group...")) {
781                 RouteGroup* g = new RouteGroup (*_session, "");
782                 RouteGroupDialog* d = new RouteGroupDialog (g, true);
783
784                 d->signal_response().connect (sigc::bind (sigc::mem_fun (*this, &AddRouteDialog::new_group_dialog_finished), d));
785                 d->present();
786         }
787 }
788
789 void
790 AddRouteDialog::new_group_dialog_finished (int r, RouteGroupDialog* d)
791 {
792         if (r == RESPONSE_OK) {
793
794                 if (!d->name_check()) {
795                         return;
796                 }
797
798                 if (_session) {
799                         _session->add_route_group (d->group());
800                 }
801
802                 add_route_group (d->group());
803                 route_group_combo.set_active (3);
804         } else {
805                 delete d->group ();
806                 route_group_combo.set_active (2);
807         }
808
809         delete_when_idle (d);
810 }
811
812 RouteDialogs::InsertAt
813 AddRouteDialog::insert_at ()
814 {
815         using namespace RouteDialogs;
816
817         std::string str = insert_at_combo.get_active_text();
818
819         if (str == _("First")) {
820                 return First;
821         } else if (str == _("After Selection")) {
822                 return AfterSelection;
823         } else if (str == _("Before Selection")){
824                 return BeforeSelection;
825         }
826         return Last;
827 }
828
829 bool
830 AddRouteDialog::channel_separator (const Glib::RefPtr<Gtk::TreeModel> &, const Gtk::TreeModel::iterator &i)
831 {
832         channel_combo.set_active (i);
833
834         return channel_combo.get_active_text () == "separator";
835 }
836
837 bool
838 AddRouteDialog::route_separator (const Glib::RefPtr<Gtk::TreeModel> &, const Gtk::TreeModel::iterator &i)
839 {
840         route_group_combo.set_active (i);
841
842         return route_group_combo.get_active_text () == "separator";
843 }
844
845 PluginInfoPtr
846 AddRouteDialog::requested_instrument ()
847 {
848         return instrument_combo.selected_instrument();
849 }