extend add route dialog to include VCA masters
[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 #include "gtkmm2ext/utils.h"
32
33 #include "ardour/plugin_manager.h"
34 #include "ardour/profile.h"
35 #include "ardour/template_utils.h"
36 #include "ardour/route_group.h"
37 #include "ardour/session.h"
38
39 #include "utils.h"
40 #include "add_route_dialog.h"
41 #include "route_group_dialog.h"
42 #include "tooltips.h"
43 #include "i18n.h"
44
45 using namespace Gtk;
46 using namespace Gtkmm2ext;
47 using namespace std;
48 using namespace PBD;
49 using namespace ARDOUR;
50 using namespace ARDOUR_UI_UTILS;
51
52 std::vector<std::string> AddRouteDialog::channel_combo_strings;
53
54 AddRouteDialog::AddRouteDialog ()
55         : ArdourDialog (_("Add Track/Bus/VCA"))
56         , routes_adjustment (1, 1, 128, 1, 4)
57         , routes_spinner (routes_adjustment)
58         , configuration_label (_("Configuration:"))
59         , mode_label (_("Record Mode:"))
60         , instrument_label (_("Instrument:"))
61 {
62         set_name ("AddRouteDialog");
63         set_modal (true);
64         set_skip_taskbar_hint (true);
65         set_resizable (false);
66
67         name_template_entry.set_name (X_("AddRouteDialogNameTemplateEntry"));
68         // routes_spinner.set_name (X_("AddRouteDialogSpinner"));
69         channel_combo.set_name (X_("ChannelCountSelector"));
70         mode_combo.set_name (X_("ChannelCountSelector"));
71
72         refill_channel_setups ();
73         refill_route_groups ();
74         refill_track_modes ();
75
76         channel_combo.set_active_text (channel_combo_strings.front());
77
78         track_bus_combo.append_text (_("Audio Tracks"));
79         track_bus_combo.append_text (_("MIDI Tracks"));
80         track_bus_combo.append_text (_("Audio+MIDI Tracks"));
81         track_bus_combo.append_text (_("Audio Busses"));
82         track_bus_combo.append_text (_("MIDI Busses"));
83         track_bus_combo.append_text (_("VCA Masters"));
84         track_bus_combo.set_active (0);
85
86         insert_at_combo.append_text (_("First"));
87         insert_at_combo.append_text (_("Before Selection"));
88         insert_at_combo.append_text (_("After Selection"));
89         insert_at_combo.append_text (_("Last"));
90         insert_at_combo.set_active (3);
91
92         strict_io_combo.append_text (_("Flexible-I/O"));
93         strict_io_combo.append_text (_("Strict-I/O"));
94         strict_io_combo.set_active (Config->get_strict_io () ? 1 : 0);
95
96         VBox* vbox = manage (new VBox);
97         Gtk::Label* l;
98
99         get_vbox()->set_spacing (4);
100
101         vbox->set_spacing (18);
102         vbox->set_border_width (5);
103
104         HBox *type_hbox = manage (new HBox);
105         type_hbox->set_spacing (6);
106
107         /* track/bus choice */
108
109         type_hbox->pack_start (*manage (new Label (_("Add:"))));
110         type_hbox->pack_start (routes_spinner);
111         type_hbox->pack_start (track_bus_combo);
112
113         vbox->pack_start (*type_hbox, false, true);
114
115         VBox* options_box = manage (new VBox);
116         Table *table2 = manage (new Table (3, 3, false));
117
118         options_box->set_spacing (6);
119         table2->set_row_spacings (6);
120         table2->set_col_spacing (1, 6);
121
122         l = manage (new Label (_("<b>Options</b>"), Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, false));
123         l->set_use_markup ();
124         options_box->pack_start (*l, false, true);
125
126         l = manage (new Label ("", Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, false));
127         l->set_padding (8, 0);
128         table2->attach (*l, 0, 1, 0, 3, Gtk::FILL, Gtk::FILL, 0, 0);
129
130         int n = 0;
131
132         l = manage (new Label (_("Name:"), Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, false));
133         table2->attach (*l, 1, 2, n, n + 1, Gtk::FILL, Gtk::EXPAND, 0, 0);
134         table2->attach (name_template_entry, 2, 3, n, n + 1, Gtk::FILL, Gtk::EXPAND | Gtk::FILL, 0, 0);
135         ++n;
136
137         /* Route configuration */
138
139         configuration_label.set_alignment (Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER);
140         table2->attach (configuration_label, 1, 2, n, n + 1, Gtk::FILL, Gtk::EXPAND, 0, 0);
141         table2->attach (channel_combo, 2, 3, n, n + 1, Gtk::FILL, Gtk::EXPAND | Gtk::FILL, 0, 0);
142         ++n;
143
144         mode_label.set_alignment (Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER);
145         table2->attach (mode_label, 1, 2, n, n + 1, Gtk::FILL, Gtk::EXPAND, 0, 0);
146         table2->attach (mode_combo, 2, 3, n, n + 1, Gtk::FILL, Gtk::EXPAND | Gtk::FILL, 0, 0);
147         ++n;
148
149         instrument_label.set_alignment (Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER);
150         table2->attach (instrument_label, 1, 2, n, n + 1, Gtk::FILL, Gtk::EXPAND, 0, 0);
151         table2->attach (instrument_combo, 2, 3, n, n + 1, Gtk::FILL, Gtk::EXPAND | Gtk::FILL, 0, 0);
152         ++n;
153
154         /* Group choice */
155
156         l = manage (new Label (_("Group:"), Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, false));
157         table2->attach (*l, 1, 2, n, n + 1, Gtk::FILL, Gtk::EXPAND, 0, 0);
158         table2->attach (route_group_combo, 2, 3, n, n + 1, Gtk::FILL, Gtk::EXPAND | Gtk::FILL, 0, 0);
159         ++n;
160
161         /* New route will be inserted at.. */
162         l = manage (new Label (_("Insert:"), Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, false));
163         table2->attach (*l, 1, 2, n, n + 1, Gtk::FILL, Gtk::EXPAND, 0, 0);
164         table2->attach (insert_at_combo, 2, 3, n, n + 1, Gtk::FILL, Gtk::EXPAND | Gtk::FILL, 0, 0);
165         ++n;
166
167         /* New Route's Routing is.. */
168
169         if (Profile->get_mixbus ()) {
170                 strict_io_combo.set_active (1);
171         } else {
172                 l = manage (new Label (_("Output Ports:"), Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, false));
173                 table2->attach (*l, 1, 2, n, n + 1, Gtk::FILL, Gtk::EXPAND, 0, 0);
174                 table2->attach (strict_io_combo, 2, 3, n, n + 1, Gtk::FILL, Gtk::EXPAND | Gtk::FILL, 0, 0);
175
176                 ARDOUR_UI_UTILS::set_tooltip (strict_io_combo,
177                                 _("With strict-i/o enabled, Effect Processors will not modify the number of channels on a track. The number of output channels will always match the number of input channels."));
178                 ++n;
179         }
180
181         options_box->pack_start (*table2, false, true);
182         vbox->pack_start (*options_box, false, true);
183
184         get_vbox()->pack_start (*vbox, false, false);
185
186         track_bus_combo.signal_changed().connect (sigc::mem_fun (*this, &AddRouteDialog::track_type_chosen));
187         channel_combo.signal_changed().connect (sigc::mem_fun (*this, &AddRouteDialog::channel_combo_changed));
188         channel_combo.set_row_separator_func (sigc::mem_fun (*this, &AddRouteDialog::channel_separator));
189         route_group_combo.set_row_separator_func (sigc::mem_fun (*this, &AddRouteDialog::route_separator));
190         route_group_combo.signal_changed ().connect (sigc::mem_fun (*this, &AddRouteDialog::group_changed));
191
192         show_all_children ();
193
194         /* track template info will be managed whenever
195            this dialog is shown, via ::on_show()
196         */
197
198         add_button (Stock::CANCEL, RESPONSE_CANCEL);
199         add_button (Stock::ADD, RESPONSE_ACCEPT);
200         set_response_sensitive (RESPONSE_ACCEPT, true);
201         set_default_response (RESPONSE_ACCEPT);
202
203         track_type_chosen ();
204 }
205
206 AddRouteDialog::~AddRouteDialog ()
207 {
208 }
209
210 void
211 AddRouteDialog::channel_combo_changed ()
212 {
213         maybe_update_name_template_entry ();
214         refill_track_modes ();
215 }
216
217 AddRouteDialog::TypeWanted
218 AddRouteDialog::type_wanted() const
219 {
220         std::string str = track_bus_combo.get_active_text();
221         if (str == _("Audio Busses")) {
222                 return AudioBus;
223         } else if (str == _("MIDI Busses")){
224                 return MidiBus;
225         } else if (str == _("MIDI Tracks")){
226                 return MidiTrack;
227         } else if (str == _("Audio+MIDI Tracks")) {
228                 return MixedTrack;
229         } else if (str == _("Audio Tracks")) {
230                 return AudioTrack;
231         } else {
232                 return VCAMaster;
233         }
234 }
235
236 void
237 AddRouteDialog::maybe_update_name_template_entry ()
238 {
239         if (
240                 name_template_entry.get_text() != "" &&
241                 name_template_entry.get_text() != _("VCA") &&
242                 name_template_entry.get_text() != _("Audio") &&
243                 name_template_entry.get_text() != _("MIDI")  &&
244                 name_template_entry.get_text() != _("Audio+MIDI")  &&
245                 name_template_entry.get_text() != _("Bus")) {
246                 strict_io_combo.set_sensitive (false);
247                 return;
248         }
249
250         strict_io_combo.set_sensitive (true);
251
252         switch (type_wanted()) {
253         case AudioTrack:
254                 name_template_entry.set_text (_("Audio"));
255                 break;
256         case MidiTrack:
257                 name_template_entry.set_text (_("MIDI"));
258                 break;
259         case MixedTrack:
260                 name_template_entry.set_text (_("Audio+MIDI"));
261                 break;
262         case AudioBus:
263         case MidiBus:
264                 name_template_entry.set_text (_("Bus"));
265                 break;
266         case VCAMaster:
267                 name_template_entry.set_text (_("VCA"));
268                 break;
269         }
270 }
271
272 void
273 AddRouteDialog::track_type_chosen ()
274 {
275         switch (type_wanted()) {
276         case AudioTrack:
277                 mode_combo.set_sensitive (true);
278                 channel_combo.set_sensitive (true);
279                 instrument_combo.set_sensitive (false);
280                 configuration_label.set_sensitive (true);
281                 mode_label.set_sensitive (true);
282                 instrument_label.set_sensitive (false);
283                 route_group_combo.set_sensitive (true);
284                 break;
285         case MidiTrack:
286                 channel_combo.set_sensitive (false);
287                 mode_combo.set_sensitive (false);
288                 instrument_combo.set_sensitive (true);
289                 configuration_label.set_sensitive (false);
290                 mode_label.set_sensitive (false);
291                 instrument_label.set_sensitive (true);
292                 route_group_combo.set_sensitive (true);
293                 break;
294         case MixedTrack:
295                 {
296                         MessageDialog msg (_("Audio+MIDI tracks are intended for use <b>ONLY</b> with plugins that use both audio and MIDI input data\n\n"
297                                              "If you do not plan to use such a plugin, then use a normal audio or MIDI track instead."),
298                                            true, MESSAGE_INFO, BUTTONS_OK, true);
299                         msg.set_position (WIN_POS_MOUSE);
300                         msg.run ();
301                 }
302                 channel_combo.set_sensitive (true);
303                 mode_combo.set_sensitive (true);
304                 instrument_combo.set_sensitive (true);
305                 configuration_label.set_sensitive (true);
306                 mode_label.set_sensitive (true);
307                 instrument_label.set_sensitive (true);
308                 route_group_combo.set_sensitive (true);
309                 break;
310         case AudioBus:
311                 mode_combo.set_sensitive (false);
312                 channel_combo.set_sensitive (true);
313                 instrument_combo.set_sensitive (false);
314                 configuration_label.set_sensitive (true);
315                 mode_label.set_sensitive (true);
316                 instrument_label.set_sensitive (false);
317                 route_group_combo.set_sensitive (true);
318                 break;
319         case VCAMaster:
320                 mode_combo.set_sensitive (false);
321                 channel_combo.set_sensitive (false);
322                 instrument_combo.set_sensitive (false);
323                 configuration_label.set_sensitive (false);
324                 mode_label.set_sensitive (false);
325                 instrument_label.set_sensitive (false);
326                 route_group_combo.set_sensitive (false);
327                 break;
328         case MidiBus:
329                 mode_combo.set_sensitive (false);
330                 channel_combo.set_sensitive (false);
331                 instrument_combo.set_sensitive (true);
332                 configuration_label.set_sensitive (false);
333                 mode_label.set_sensitive (true);
334                 instrument_label.set_sensitive (true);
335                 break;
336         }
337
338         maybe_update_name_template_entry ();
339 }
340
341
342 string
343 AddRouteDialog::name_template () const
344 {
345         return name_template_entry.get_text ();
346 }
347
348 bool
349 AddRouteDialog::name_template_is_default() const
350 {
351         string n = name_template();
352
353         if (n == _("Audio") ||
354             n == _("MIDI") ||
355             n == _("Audio+MIDI") ||
356             n == _("Bus") ||
357             n == _("VCA")) {
358                 return true;
359         }
360
361         return false;
362 }
363
364 int
365 AddRouteDialog::count ()
366 {
367         return (int) floor (routes_adjustment.get_value ());
368 }
369
370 void
371 AddRouteDialog::refill_track_modes ()
372 {
373         vector<string> s;
374
375         s.push_back (_("Normal"));
376         s.push_back (_("Non Layered"));
377         s.push_back (_("Tape"));
378
379         set_popdown_strings (mode_combo, s);
380         mode_combo.set_active_text (s.front());
381 }
382
383 ARDOUR::TrackMode
384 AddRouteDialog::mode ()
385 {
386         std::string str = mode_combo.get_active_text();
387         if (str == _("Normal")) {
388                 return ARDOUR::Normal;
389         } else if (str == _("Non Layered")){
390                 return ARDOUR::NonLayered;
391         } else if (str == _("Tape")) {
392                 return ARDOUR::Destructive;
393         } else {
394                 fatal << string_compose (X_("programming error: unknown track mode in add route dialog combo = %1"), str)
395                       << endmsg;
396                 abort(); /*NOTREACHED*/
397         }
398         /* keep gcc happy */
399         return ARDOUR::Normal;
400 }
401
402 ChanCount
403 AddRouteDialog::channels ()
404 {
405         ChanCount ret;
406         string str;
407         switch (type_wanted()) {
408         case AudioTrack:
409         case AudioBus:
410                 str = channel_combo.get_active_text();
411                 for (ChannelSetups::iterator i = channel_setups.begin(); i != channel_setups.end(); ++i) {
412                         if (str == (*i).name) {
413                                 ret.set (DataType::AUDIO, (*i).channels);
414                                 break;
415                         }
416                 }
417                 ret.set (DataType::MIDI, 0);
418                 break;
419
420         case MidiBus:
421         case MidiTrack:
422                 ret.set (DataType::AUDIO, 0);
423                 ret.set (DataType::MIDI, 1);
424                 break;
425
426         case MixedTrack:
427                 str = channel_combo.get_active_text();
428                 for (ChannelSetups::iterator i = channel_setups.begin(); i != channel_setups.end(); ++i) {
429                         if (str == (*i).name) {
430                                 ret.set (DataType::AUDIO, (*i).channels);
431                                 break;
432                         }
433                 }
434                 ret.set (DataType::MIDI, 1);
435                 break;
436         default:
437                 break;
438         }
439
440         return ret;
441 }
442
443 string
444 AddRouteDialog::track_template ()
445 {
446         string str = channel_combo.get_active_text();
447
448         for (ChannelSetups::iterator i = channel_setups.begin(); i != channel_setups.end(); ++i) {
449                 if (str == (*i).name) {
450                         return (*i).template_path;
451                 }
452         }
453
454         return string();
455 }
456
457 void
458 AddRouteDialog::on_show ()
459 {
460         refill_channel_setups ();
461         refill_route_groups ();
462
463         Dialog::on_show ();
464 }
465
466 void
467 AddRouteDialog::refill_channel_setups ()
468 {
469         ChannelSetup chn;
470
471         route_templates.clear ();
472         channel_combo_strings.clear ();
473         channel_setups.clear ();
474
475         chn.name = _("Mono");
476         chn.channels = 1;
477         channel_setups.push_back (chn);
478
479         chn.name = _("Stereo");
480         chn.channels = 2;
481         channel_setups.push_back (chn);
482
483         chn.name = "separator";
484         channel_setups.push_back (chn);
485
486         ARDOUR::find_route_templates (route_templates);
487
488         if (!route_templates.empty()) {
489                 vector<string> v;
490                 for (vector<TemplateInfo>::iterator x = route_templates.begin(); x != route_templates.end(); ++x) {
491                         chn.name = x->name;
492                         chn.channels = 0;
493                         chn.template_path = x->path;
494                         channel_setups.push_back (chn);
495                 }
496         }
497
498         /* clear template path for the rest */
499
500         chn.template_path = "";
501
502         chn.name = _("3 Channel");
503         chn.channels = 3;
504         channel_setups.push_back (chn);
505
506         chn.name = _("4 Channel");
507         chn.channels = 4;
508         channel_setups.push_back (chn);
509
510         chn.name = _("5 Channel");
511         chn.channels = 5;
512         channel_setups.push_back (chn);
513
514         chn.name = _("6 Channel");
515         chn.channels = 6;
516         channel_setups.push_back (chn);
517
518         chn.name = _("8 Channel");
519         chn.channels = 8;
520         channel_setups.push_back (chn);
521
522         chn.name = _("12 Channel");
523         chn.channels = 12;
524         channel_setups.push_back (chn);
525
526         chn.name = _("Custom");
527         chn.channels = 0;
528         channel_setups.push_back (chn);
529
530         for (ChannelSetups::iterator i = channel_setups.begin(); i != channel_setups.end(); ++i) {
531                 channel_combo_strings.push_back ((*i).name);
532         }
533
534         set_popdown_strings (channel_combo, channel_combo_strings);
535         channel_combo.set_active_text (channel_combo_strings.front());
536 }
537
538 void
539 AddRouteDialog::add_route_group (RouteGroup* g)
540 {
541         route_group_combo.insert_text (3, g->name ());
542 }
543
544 RouteGroup*
545 AddRouteDialog::route_group ()
546 {
547         if (!_session || route_group_combo.get_active_row_number () == 2) {
548                 return 0;
549         }
550
551         return _session->route_group_by_name (route_group_combo.get_active_text());
552 }
553
554 bool
555 AddRouteDialog::use_strict_io() {
556         return strict_io_combo.get_active_row_number () == 1;
557 }
558
559 void
560 AddRouteDialog::refill_route_groups ()
561 {
562         route_group_combo.clear ();
563         route_group_combo.append_text (_("New Group..."));
564
565         route_group_combo.append_text ("separator");
566
567         route_group_combo.append_text (_("No Group"));
568
569         if (_session) {
570                 _session->foreach_route_group (sigc::mem_fun (*this, &AddRouteDialog::add_route_group));
571         }
572
573         route_group_combo.set_active (2);
574 }
575
576 void
577 AddRouteDialog::group_changed ()
578 {
579         if (_session && route_group_combo.get_active_text () == _("New Group...")) {
580                 RouteGroup* g = new RouteGroup (*_session, "");
581                 RouteGroupDialog d (g, true);
582
583                 if (d.do_run ()) {
584                         delete g;
585                         route_group_combo.set_active (2);
586                 } else {
587                         if (_session) {
588                                 _session->add_route_group (g);
589                         }
590                         add_route_group (g);
591                         route_group_combo.set_active (3);
592                 }
593         }
594 }
595
596 AddRouteDialog::InsertAt
597 AddRouteDialog::insert_at ()
598 {
599         std::string str = insert_at_combo.get_active_text();
600
601         if (str == _("First")) {
602                 return First;
603         } else if (str == _("After Selection")) {
604                 return AfterSelection;
605         } else if (str == _("Before Selection")){
606                 return BeforeSelection;
607         }
608         return Last;
609 }
610
611 bool
612 AddRouteDialog::channel_separator (const Glib::RefPtr<Gtk::TreeModel> &, const Gtk::TreeModel::iterator &i)
613 {
614         channel_combo.set_active (i);
615
616         return channel_combo.get_active_text () == "separator";
617 }
618
619 bool
620 AddRouteDialog::route_separator (const Glib::RefPtr<Gtk::TreeModel> &, const Gtk::TreeModel::iterator &i)
621 {
622         route_group_combo.set_active (i);
623
624         return route_group_combo.get_active_text () == "separator";
625 }
626
627 PluginInfoPtr
628 AddRouteDialog::requested_instrument ()
629 {
630         return instrument_combo.selected_instrument();
631 }