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