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