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"
31 #include "gtkmm2ext/utils.h"
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"
40 #include "add_route_dialog.h"
41 #include "route_group_dialog.h"
46 using namespace Gtkmm2ext;
49 using namespace ARDOUR;
50 using namespace ARDOUR_UI_UTILS;
52 std::vector<std::string> AddRouteDialog::channel_combo_strings;
54 AddRouteDialog::AddRouteDialog ()
55 : ArdourDialog (_("Add Track or Bus"))
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 , strict_io (_("Strict I/O"))
63 set_name ("AddRouteDialog");
65 set_skip_taskbar_hint (true);
66 set_resizable (false);
68 name_template_entry.set_name (X_("AddRouteDialogNameTemplateEntry"));
69 // routes_spinner.set_name (X_("AddRouteDialogSpinner"));
70 channel_combo.set_name (X_("ChannelCountSelector"));
71 mode_combo.set_name (X_("ChannelCountSelector"));
73 refill_channel_setups ();
74 refill_route_groups ();
75 refill_track_modes ();
77 channel_combo.set_active_text (channel_combo_strings.front());
79 track_bus_combo.append_text (_("Audio Tracks"));
80 track_bus_combo.append_text (_("MIDI Tracks"));
81 track_bus_combo.append_text (_("Audio+MIDI Tracks"));
82 track_bus_combo.append_text (_("Audio Busses"));
83 track_bus_combo.append_text (_("MIDI Busses"));
84 track_bus_combo.set_active (0);
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"));
91 insert_at_combo.set_active (1);
93 VBox* vbox = manage (new VBox);
96 get_vbox()->set_spacing (4);
98 vbox->set_spacing (18);
99 vbox->set_border_width (5);
101 HBox *type_hbox = manage (new HBox);
102 type_hbox->set_spacing (6);
104 /* track/bus choice */
106 type_hbox->pack_start (*manage (new Label (_("Add:"))));
107 type_hbox->pack_start (routes_spinner);
108 type_hbox->pack_start (track_bus_combo);
110 vbox->pack_start (*type_hbox, false, true);
112 VBox* options_box = manage (new VBox);
113 Table *table2 = manage (new Table (3, 3, false));
115 options_box->set_spacing (6);
116 table2->set_row_spacings (6);
117 table2->set_col_spacing (1, 6);
119 l = manage (new Label (_("<b>Options</b>"), Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, false));
120 l->set_use_markup ();
121 options_box->pack_start (*l, false, true);
123 l = manage (new Label ("", Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, false));
124 l->set_padding (8, 0);
125 table2->attach (*l, 0, 1, 0, 3, Gtk::FILL, Gtk::FILL, 0, 0);
129 l = manage (new Label (_("Name:"), Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, false));
130 table2->attach (*l, 1, 2, n, n + 1, Gtk::FILL, Gtk::EXPAND, 0, 0);
131 table2->attach (name_template_entry, 2, 3, n, n + 1, Gtk::FILL, Gtk::EXPAND | Gtk::FILL, 0, 0);
134 /* Route configuration */
136 configuration_label.set_alignment (Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER);
137 table2->attach (configuration_label, 1, 2, n, n + 1, Gtk::FILL, Gtk::EXPAND, 0, 0);
138 table2->attach (channel_combo, 2, 3, n, n + 1, Gtk::FILL, Gtk::EXPAND | Gtk::FILL, 0, 0);
141 mode_label.set_alignment (Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER);
142 table2->attach (mode_label, 1, 2, n, n + 1, Gtk::FILL, Gtk::EXPAND, 0, 0);
143 table2->attach (mode_combo, 2, 3, n, n + 1, Gtk::FILL, Gtk::EXPAND | Gtk::FILL, 0, 0);
146 instrument_label.set_alignment (Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER);
147 table2->attach (instrument_label, 1, 2, n, n + 1, Gtk::FILL, Gtk::EXPAND, 0, 0);
148 table2->attach (instrument_combo, 2, 3, n, n + 1, Gtk::FILL, Gtk::EXPAND | Gtk::FILL, 0, 0);
153 l = manage (new Label (_("Group:"), Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, false));
154 table2->attach (*l, 1, 2, n, n + 1, Gtk::FILL, Gtk::EXPAND, 0, 0);
155 table2->attach (route_group_combo, 2, 3, n, n + 1, Gtk::FILL, Gtk::EXPAND | Gtk::FILL, 0, 0);
158 /* New route will be inserted at.. */
159 l = manage (new Label (_("Insert:"), Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, false));
160 table2->attach (*l, 1, 2, n, n + 1, Gtk::FILL, Gtk::EXPAND, 0, 0);
161 table2->attach (insert_at_combo, 2, 3, n, n + 1, Gtk::FILL, Gtk::EXPAND | Gtk::FILL, 0, 0);
164 /* New Route's Routing is.. */
165 strict_io.set_active (Config->get_strict_io ());
166 ARDOUR_UI_UTILS::set_tooltip (strict_io,
167 _("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."));
168 table2->attach (strict_io, 2, 3, n, n + 1, Gtk::FILL, Gtk::EXPAND | Gtk::FILL, 0, 0);
171 options_box->pack_start (*table2, false, true);
172 vbox->pack_start (*options_box, false, true);
174 get_vbox()->pack_start (*vbox, false, false);
176 track_bus_combo.signal_changed().connect (sigc::mem_fun (*this, &AddRouteDialog::track_type_chosen));
177 channel_combo.signal_changed().connect (sigc::mem_fun (*this, &AddRouteDialog::channel_combo_changed));
178 channel_combo.set_row_separator_func (sigc::mem_fun (*this, &AddRouteDialog::channel_separator));
179 route_group_combo.set_row_separator_func (sigc::mem_fun (*this, &AddRouteDialog::route_separator));
180 route_group_combo.signal_changed ().connect (sigc::mem_fun (*this, &AddRouteDialog::group_changed));
182 show_all_children ();
184 /* track template info will be managed whenever
185 this dialog is shown, via ::on_show()
188 add_button (Stock::CANCEL, RESPONSE_CANCEL);
189 add_button (Stock::ADD, RESPONSE_ACCEPT);
190 set_response_sensitive (RESPONSE_ACCEPT, true);
191 set_default_response (RESPONSE_ACCEPT);
193 track_type_chosen ();
196 AddRouteDialog::~AddRouteDialog ()
201 AddRouteDialog::channel_combo_changed ()
203 maybe_update_name_template_entry ();
204 refill_track_modes ();
207 AddRouteDialog::TypeWanted
208 AddRouteDialog::type_wanted() const
210 std::string str = track_bus_combo.get_active_text();
211 if (str == _("Audio Busses")) {
213 } else if (str == _("MIDI Busses")){
215 } else if (str == _("MIDI Tracks")){
217 } else if (str == _("Audio+MIDI Tracks")) {
225 AddRouteDialog::maybe_update_name_template_entry ()
228 name_template_entry.get_text() != "" &&
229 name_template_entry.get_text() != _("Audio") &&
230 name_template_entry.get_text() != _("MIDI") &&
231 name_template_entry.get_text() != _("Audio+MIDI") &&
232 name_template_entry.get_text() != _("Bus")) {
233 strict_io.set_sensitive (false);
237 strict_io.set_sensitive (true);
239 switch (type_wanted()) {
241 name_template_entry.set_text (_("Audio"));
244 name_template_entry.set_text (_("MIDI"));
247 name_template_entry.set_text (_("Audio+MIDI"));
251 name_template_entry.set_text (_("Bus"));
257 AddRouteDialog::track_type_chosen ()
259 switch (type_wanted()) {
261 mode_combo.set_sensitive (true);
262 channel_combo.set_sensitive (true);
263 instrument_combo.set_sensitive (false);
264 configuration_label.set_sensitive (true);
265 mode_label.set_sensitive (true);
266 instrument_label.set_sensitive (false);
269 channel_combo.set_sensitive (false);
270 mode_combo.set_sensitive (false);
271 instrument_combo.set_sensitive (true);
272 configuration_label.set_sensitive (false);
273 mode_label.set_sensitive (false);
274 instrument_label.set_sensitive (true);
278 MessageDialog msg (_("Audio+MIDI tracks are intended for use <b>ONLY</b> with plugins that use both audio and MIDI input data\n\n"
279 "If you do not plan to use such a plugin, then use a normal audio or MIDI track instead."),
280 true, MESSAGE_INFO, BUTTONS_OK, true);
281 msg.set_position (WIN_POS_MOUSE);
284 channel_combo.set_sensitive (true);
285 mode_combo.set_sensitive (true);
286 instrument_combo.set_sensitive (true);
287 configuration_label.set_sensitive (true);
288 mode_label.set_sensitive (true);
289 instrument_label.set_sensitive (true);
292 mode_combo.set_sensitive (false);
293 channel_combo.set_sensitive (true);
294 instrument_combo.set_sensitive (false);
295 configuration_label.set_sensitive (true);
296 mode_label.set_sensitive (true);
297 instrument_label.set_sensitive (false);
300 mode_combo.set_sensitive (false);
301 channel_combo.set_sensitive (false);
302 instrument_combo.set_sensitive (true);
303 configuration_label.set_sensitive (false);
304 mode_label.set_sensitive (true);
305 instrument_label.set_sensitive (true);
309 maybe_update_name_template_entry ();
314 AddRouteDialog::name_template () const
316 return name_template_entry.get_text ();
320 AddRouteDialog::name_template_is_default() const
322 string n = name_template();
324 if (n == _("Audio") ||
326 n == _("Audio+MIDI") ||
335 AddRouteDialog::count ()
337 return (int) floor (routes_adjustment.get_value ());
341 AddRouteDialog::refill_track_modes ()
345 s.push_back (_("Normal"));
346 s.push_back (_("Non Layered"));
347 s.push_back (_("Tape"));
349 set_popdown_strings (mode_combo, s);
350 mode_combo.set_active_text (s.front());
354 AddRouteDialog::mode ()
356 std::string str = mode_combo.get_active_text();
357 if (str == _("Normal")) {
358 return ARDOUR::Normal;
359 } else if (str == _("Non Layered")){
360 return ARDOUR::NonLayered;
361 } else if (str == _("Tape")) {
362 return ARDOUR::Destructive;
364 fatal << string_compose (X_("programming error: unknown track mode in add route dialog combo = %1"), str)
366 abort(); /*NOTREACHED*/
369 return ARDOUR::Normal;
373 AddRouteDialog::channels ()
377 switch (type_wanted()) {
380 str = channel_combo.get_active_text();
381 for (ChannelSetups::iterator i = channel_setups.begin(); i != channel_setups.end(); ++i) {
382 if (str == (*i).name) {
383 ret.set (DataType::AUDIO, (*i).channels);
387 ret.set (DataType::MIDI, 0);
392 ret.set (DataType::AUDIO, 0);
393 ret.set (DataType::MIDI, 1);
397 str = channel_combo.get_active_text();
398 for (ChannelSetups::iterator i = channel_setups.begin(); i != channel_setups.end(); ++i) {
399 if (str == (*i).name) {
400 ret.set (DataType::AUDIO, (*i).channels);
404 ret.set (DataType::MIDI, 1);
412 AddRouteDialog::track_template ()
414 string str = channel_combo.get_active_text();
416 for (ChannelSetups::iterator i = channel_setups.begin(); i != channel_setups.end(); ++i) {
417 if (str == (*i).name) {
418 return (*i).template_path;
426 AddRouteDialog::on_show ()
428 refill_channel_setups ();
429 refill_route_groups ();
435 AddRouteDialog::refill_channel_setups ()
439 route_templates.clear ();
440 channel_combo_strings.clear ();
441 channel_setups.clear ();
443 chn.name = _("Mono");
445 channel_setups.push_back (chn);
447 chn.name = _("Stereo");
449 channel_setups.push_back (chn);
451 chn.name = "separator";
452 channel_setups.push_back (chn);
454 ARDOUR::find_route_templates (route_templates);
456 if (!route_templates.empty()) {
458 for (vector<TemplateInfo>::iterator x = route_templates.begin(); x != route_templates.end(); ++x) {
461 chn.template_path = x->path;
462 channel_setups.push_back (chn);
466 /* clear template path for the rest */
468 chn.template_path = "";
470 chn.name = _("3 Channel");
472 channel_setups.push_back (chn);
474 chn.name = _("4 Channel");
476 channel_setups.push_back (chn);
478 chn.name = _("5 Channel");
480 channel_setups.push_back (chn);
482 chn.name = _("6 Channel");
484 channel_setups.push_back (chn);
486 chn.name = _("8 Channel");
488 channel_setups.push_back (chn);
490 chn.name = _("12 Channel");
492 channel_setups.push_back (chn);
494 chn.name = _("Custom");
496 channel_setups.push_back (chn);
498 for (ChannelSetups::iterator i = channel_setups.begin(); i != channel_setups.end(); ++i) {
499 channel_combo_strings.push_back ((*i).name);
502 set_popdown_strings (channel_combo, channel_combo_strings);
503 channel_combo.set_active_text (channel_combo_strings.front());
507 AddRouteDialog::add_route_group (RouteGroup* g)
509 route_group_combo.insert_text (3, g->name ());
513 AddRouteDialog::route_group ()
515 if (!_session || route_group_combo.get_active_row_number () == 2) {
519 return _session->route_group_by_name (route_group_combo.get_active_text());
523 AddRouteDialog::refill_route_groups ()
525 route_group_combo.clear ();
526 route_group_combo.append_text (_("New Group..."));
528 route_group_combo.append_text ("separator");
530 route_group_combo.append_text (_("No Group"));
533 _session->foreach_route_group (sigc::mem_fun (*this, &AddRouteDialog::add_route_group));
536 route_group_combo.set_active (2);
540 AddRouteDialog::group_changed ()
542 if (_session && route_group_combo.get_active_text () == _("New Group...")) {
543 RouteGroup* g = new RouteGroup (*_session, "");
544 RouteGroupDialog d (g, true);
548 route_group_combo.set_active (2);
551 _session->add_route_group (g);
554 route_group_combo.set_active (3);
559 AddRouteDialog::InsertAt
560 AddRouteDialog::insert_at ()
562 std::string str = insert_at_combo.get_active_text();
564 if (str == _("First")) {
566 } else if (str == _("After Selection")) {
567 return AfterSelection;
568 } else if (str == _("Before Selection")){
569 return BeforeSelection;
575 AddRouteDialog::channel_separator (const Glib::RefPtr<Gtk::TreeModel> &, const Gtk::TreeModel::iterator &i)
577 channel_combo.set_active (i);
579 return channel_combo.get_active_text () == "separator";
583 AddRouteDialog::route_separator (const Glib::RefPtr<Gtk::TreeModel> &, const Gtk::TreeModel::iterator &i)
585 route_group_combo.set_active (i);
587 return route_group_combo.get_active_text () == "separator";
591 AddRouteDialog::requested_instrument ()
593 return instrument_combo.selected_instrument();