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