2 Copyright (C) 2003 Paul Davis
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.
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.
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.
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>
29 #include "pbd/error.h"
30 #include "pbd/convert.h"
32 #include "gtkmm2ext/utils.h"
33 #include "gtkmm2ext/doi.h"
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"
43 #include "add_route_dialog.h"
44 #include "route_group_dialog.h"
49 using namespace Gtkmm2ext;
52 using namespace ARDOUR;
53 using namespace ARDOUR_UI_UTILS;
55 std::vector<std::string> AddRouteDialog::channel_combo_strings;
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:"))
65 set_name ("AddRouteDialog");
66 set_skip_taskbar_hint (true);
67 set_resizable (false);
68 set_position (WIN_POS_MOUSE);
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"));
75 refill_track_modes ();
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);
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);
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);
95 VBox* vbox = manage (new VBox);
98 get_vbox()->set_spacing (4);
100 vbox->set_spacing (18);
101 vbox->set_border_width (5);
103 HBox *type_hbox = manage (new HBox);
104 type_hbox->set_spacing (6);
106 /* track/bus choice */
108 type_hbox->pack_start (*manage (new Label (_("Add:"))));
109 type_hbox->pack_start (routes_spinner);
110 type_hbox->pack_start (track_bus_combo);
112 vbox->pack_start (*type_hbox, false, true);
114 VBox* options_box = manage (new VBox);
115 Table *table2 = manage (new Table (3, 3, false));
117 options_box->set_spacing (6);
118 table2->set_row_spacings (6);
119 table2->set_col_spacing (1, 6);
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);
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);
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);
136 /* Route configuration */
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);
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);
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);
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);
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);
166 /* New Route's Routing is.. */
168 if (Profile->get_mixbus ()) {
169 strict_io_combo.set_active (1);
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);
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."));
180 options_box->pack_start (*table2, false, true);
181 vbox->pack_start (*options_box, false, true);
183 get_vbox()->pack_start (*vbox, false, false);
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));
191 show_all_children ();
193 /* track template info will be managed whenever
194 this dialog is shown, via ::on_show()
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);
202 track_type_chosen ();
205 AddRouteDialog::~AddRouteDialog ()
210 AddRouteDialog::channel_combo_changed ()
212 maybe_update_name_template_entry ();
213 refill_track_modes ();
216 AddRouteDialog::TypeWanted
217 AddRouteDialog::type_wanted() const
219 std::string str = track_bus_combo.get_active_text();
220 if (str == _("Audio Busses")) {
222 } else if (str == _("MIDI Busses")){
224 } else if (str == _("MIDI Tracks")){
226 } else if (str == _("Audio+MIDI Tracks")) {
228 } else if (str == _("Audio Tracks")) {
236 AddRouteDialog::maybe_update_name_template_entry ()
239 name_template_entry.get_text() != "" &&
240 name_template_entry.get_text() != VCA::default_name_template() &&
241 name_template_entry.get_text() != _("Audio") &&
242 name_template_entry.get_text() != _("MIDI") &&
243 name_template_entry.get_text() != _("Audio+MIDI") &&
244 name_template_entry.get_text() != _("Bus")) {
245 strict_io_combo.set_sensitive (false);
249 strict_io_combo.set_sensitive (true);
251 switch (type_wanted()) {
253 name_template_entry.set_text (_("Audio"));
256 name_template_entry.set_text (_("MIDI"));
259 name_template_entry.set_text (_("Audio+MIDI"));
263 name_template_entry.set_text (_("Bus"));
266 name_template_entry.set_text (VCA::default_name_template());
272 AddRouteDialog::track_type_chosen ()
274 switch (type_wanted()) {
276 mode_combo.set_sensitive (true);
277 channel_combo.set_sensitive (true);
278 instrument_combo.set_sensitive (false);
279 configuration_label.set_sensitive (true);
280 mode_label.set_sensitive (true);
281 instrument_label.set_sensitive (false);
282 route_group_combo.set_sensitive (true);
285 channel_combo.set_sensitive (false);
286 mode_combo.set_sensitive (false);
287 instrument_combo.set_sensitive (true);
288 configuration_label.set_sensitive (false);
289 mode_label.set_sensitive (false);
290 instrument_label.set_sensitive (true);
291 route_group_combo.set_sensitive (true);
295 MessageDialog msg (_("Audio+MIDI tracks are intended for use <b>ONLY</b> with plugins that use both audio and MIDI input data\n\n"
296 "If you do not plan to use such a plugin, then use a normal audio or MIDI track instead."),
297 true, MESSAGE_INFO, BUTTONS_OK, true);
298 msg.set_position (WIN_POS_MOUSE);
301 channel_combo.set_sensitive (true);
302 mode_combo.set_sensitive (true);
303 instrument_combo.set_sensitive (true);
304 configuration_label.set_sensitive (true);
305 mode_label.set_sensitive (true);
306 instrument_label.set_sensitive (true);
307 route_group_combo.set_sensitive (true);
310 mode_combo.set_sensitive (false);
311 channel_combo.set_sensitive (true);
312 instrument_combo.set_sensitive (false);
313 configuration_label.set_sensitive (true);
314 mode_label.set_sensitive (true);
315 instrument_label.set_sensitive (false);
316 route_group_combo.set_sensitive (true);
319 mode_combo.set_sensitive (false);
320 channel_combo.set_sensitive (false);
321 instrument_combo.set_sensitive (false);
322 configuration_label.set_sensitive (false);
323 mode_label.set_sensitive (false);
324 instrument_label.set_sensitive (false);
325 route_group_combo.set_sensitive (false);
328 mode_combo.set_sensitive (false);
329 channel_combo.set_sensitive (false);
330 instrument_combo.set_sensitive (true);
331 configuration_label.set_sensitive (false);
332 mode_label.set_sensitive (true);
333 instrument_label.set_sensitive (true);
337 maybe_update_name_template_entry ();
342 AddRouteDialog::name_template () const
344 return name_template_entry.get_text ();
348 AddRouteDialog::name_template_is_default() const
350 string n = name_template();
352 if (n == _("Audio") ||
354 n == _("Audio+MIDI") ||
356 n == VCA::default_name_template()) {
364 AddRouteDialog::count ()
366 return (int) floor (routes_adjustment.get_value ());
370 AddRouteDialog::refill_track_modes ()
374 s.push_back (_("Normal"));
375 s.push_back (_("Non Layered"));
376 s.push_back (_("Tape"));
378 set_popdown_strings (mode_combo, s);
379 mode_combo.set_active_text (s.front());
383 AddRouteDialog::mode ()
385 std::string str = mode_combo.get_active_text();
386 if (str == _("Normal")) {
387 return ARDOUR::Normal;
388 } else if (str == _("Non Layered")){
389 return ARDOUR::NonLayered;
390 } else if (str == _("Tape")) {
391 return ARDOUR::Destructive;
393 fatal << string_compose (X_("programming error: unknown track mode in add route dialog combo = %1"), str)
395 abort(); /*NOTREACHED*/
398 return ARDOUR::Normal;
402 AddRouteDialog::channels ()
406 switch (type_wanted()) {
409 str = channel_combo.get_active_text();
410 for (ChannelSetups::iterator i = channel_setups.begin(); i != channel_setups.end(); ++i) {
411 if (str == (*i).name) {
412 ret.set (DataType::AUDIO, (*i).channels);
416 ret.set (DataType::MIDI, 0);
421 ret.set (DataType::AUDIO, 0);
422 ret.set (DataType::MIDI, 1);
426 str = channel_combo.get_active_text();
427 for (ChannelSetups::iterator i = channel_setups.begin(); i != channel_setups.end(); ++i) {
428 if (str == (*i).name) {
429 ret.set (DataType::AUDIO, (*i).channels);
433 ret.set (DataType::MIDI, 1);
443 AddRouteDialog::track_template ()
445 string str = channel_combo.get_active_text();
447 for (ChannelSetups::iterator i = channel_setups.begin(); i != channel_setups.end(); ++i) {
448 if (str == (*i).name) {
449 return (*i).template_path;
457 AddRouteDialog::on_show ()
459 refill_channel_setups ();
460 refill_route_groups ();
466 AddRouteDialog::refill_channel_setups ()
470 route_templates.clear ();
472 string channel_current_choice = channel_combo.get_active_text();
474 channel_combo_strings.clear ();
475 channel_setups.clear ();
477 chn.name = _("Mono");
479 channel_setups.push_back (chn);
481 chn.name = _("Stereo");
483 channel_setups.push_back (chn);
485 chn.name = "separator";
486 channel_setups.push_back (chn);
488 ARDOUR::find_route_templates (route_templates);
490 if (!route_templates.empty()) {
492 for (vector<TemplateInfo>::iterator x = route_templates.begin(); x != route_templates.end(); ++x) {
495 chn.template_path = x->path;
496 channel_setups.push_back (chn);
500 /* clear template path for the rest */
502 chn.template_path = "";
504 chn.name = _("3 Channel");
506 channel_setups.push_back (chn);
508 chn.name = _("4 Channel");
510 channel_setups.push_back (chn);
512 chn.name = _("5 Channel");
514 channel_setups.push_back (chn);
516 chn.name = _("6 Channel");
518 channel_setups.push_back (chn);
520 chn.name = _("8 Channel");
522 channel_setups.push_back (chn);
524 chn.name = _("12 Channel");
526 channel_setups.push_back (chn);
528 chn.name = _("Custom");
530 channel_setups.push_back (chn);
532 for (ChannelSetups::iterator i = channel_setups.begin(); i != channel_setups.end(); ++i) {
533 channel_combo_strings.push_back ((*i).name);
536 set_popdown_strings (channel_combo, channel_combo_strings);
538 if (!channel_current_choice.empty()) {
539 channel_combo.set_active_text (channel_current_choice);
541 channel_combo.set_active_text (channel_combo_strings.front());
546 AddRouteDialog::add_route_group (RouteGroup* g)
548 route_group_combo.insert_text (3, g->name ());
552 AddRouteDialog::route_group ()
554 if (!_session || route_group_combo.get_active_row_number () == 2) {
558 return _session->route_group_by_name (route_group_combo.get_active_text());
562 AddRouteDialog::use_strict_io() {
563 return strict_io_combo.get_active_row_number () == 1;
567 AddRouteDialog::refill_route_groups ()
569 route_group_combo.clear ();
570 route_group_combo.append_text (_("New Group..."));
572 route_group_combo.append_text ("separator");
574 route_group_combo.append_text (_("No Group"));
577 _session->foreach_route_group (sigc::mem_fun (*this, &AddRouteDialog::add_route_group));
580 route_group_combo.set_active (2);
584 AddRouteDialog::group_changed ()
586 if (_session && route_group_combo.get_active_text () == _("New Group...")) {
587 RouteGroup* g = new RouteGroup (*_session, "");
588 RouteGroupDialog* d = new RouteGroupDialog (g, true);
590 d->signal_response().connect (sigc::bind (sigc::mem_fun (*this, &AddRouteDialog::new_group_dialog_finished), d));
596 AddRouteDialog::new_group_dialog_finished (int r, RouteGroupDialog* d)
598 if (r == RESPONSE_OK) {
600 if (!d->name_check()) {
605 _session->add_route_group (d->group());
608 add_route_group (d->group());
609 route_group_combo.set_active (3);
612 route_group_combo.set_active (2);
615 delete_when_idle (d);
618 AddRouteDialog::InsertAt
619 AddRouteDialog::insert_at ()
621 std::string str = insert_at_combo.get_active_text();
623 if (str == _("First")) {
625 } else if (str == _("After Selection")) {
626 return AfterSelection;
627 } else if (str == _("Before Selection")){
628 return BeforeSelection;
634 AddRouteDialog::channel_separator (const Glib::RefPtr<Gtk::TreeModel> &, const Gtk::TreeModel::iterator &i)
636 channel_combo.set_active (i);
638 return channel_combo.get_active_text () == "separator";
642 AddRouteDialog::route_separator (const Glib::RefPtr<Gtk::TreeModel> &, const Gtk::TreeModel::iterator &i)
644 route_group_combo.set_active (i);
646 return route_group_combo.get_active_text () == "separator";
650 AddRouteDialog::requested_instrument ()
652 return instrument_combo.selected_instrument();