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"
45 using namespace Gtkmm2ext;
48 using namespace ARDOUR;
49 using namespace ARDOUR_UI_UTILS;
51 std::vector<std::string> AddRouteDialog::channel_combo_strings;
53 AddRouteDialog::AddRouteDialog ()
54 : ArdourDialog (_("Add Track or Bus"))
55 , routes_adjustment (1, 1, 128, 1, 4)
56 , routes_spinner (routes_adjustment)
57 , configuration_label (_("Configuration:"))
58 , mode_label (_("Record Mode:"))
59 , instrument_label (_("Instrument:"))
61 set_name ("AddRouteDialog");
63 set_skip_taskbar_hint (true);
64 set_resizable (false);
66 name_template_entry.set_name (X_("AddRouteDialogNameTemplateEntry"));
67 // routes_spinner.set_name (X_("AddRouteDialogSpinner"));
68 channel_combo.set_name (X_("ChannelCountSelector"));
69 mode_combo.set_name (X_("ChannelCountSelector"));
71 refill_channel_setups ();
72 refill_route_groups ();
73 refill_track_modes ();
75 channel_combo.set_active_text (channel_combo_strings.front());
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 (_("Busses"));
81 track_bus_combo.set_active (0);
83 insert_at_combo.append_text (_("First"));
84 insert_at_combo.append_text (_("Before Selection"));
85 insert_at_combo.append_text (_("After Selection"));
86 insert_at_combo.append_text (_("Last"));
88 insert_at_combo.set_active (1);
90 VBox* vbox = manage (new VBox);
93 get_vbox()->set_spacing (4);
95 vbox->set_spacing (18);
96 vbox->set_border_width (5);
98 HBox *type_hbox = manage (new HBox);
99 type_hbox->set_spacing (6);
101 /* track/bus choice */
103 type_hbox->pack_start (*manage (new Label (_("Add:"))));
104 type_hbox->pack_start (routes_spinner);
105 type_hbox->pack_start (track_bus_combo);
107 vbox->pack_start (*type_hbox, false, true);
109 VBox* options_box = manage (new VBox);
110 Table *table2 = manage (new Table (3, 3, false));
112 options_box->set_spacing (6);
113 table2->set_row_spacings (6);
114 table2->set_col_spacing (1, 6);
116 l = manage (new Label (_("<b>Options</b>"), Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, false));
117 l->set_use_markup ();
118 options_box->pack_start (*l, false, true);
120 l = manage (new Label ("", Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, false));
121 l->set_padding (8, 0);
122 table2->attach (*l, 0, 1, 0, 3, Gtk::FILL, Gtk::FILL, 0, 0);
126 l = manage (new Label (_("Name:"), Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, false));
127 table2->attach (*l, 1, 2, n, n + 1, Gtk::FILL, Gtk::EXPAND, 0, 0);
128 table2->attach (name_template_entry, 2, 3, n, n + 1, Gtk::FILL, Gtk::EXPAND | Gtk::FILL, 0, 0);
131 /* Route configuration */
133 configuration_label.set_alignment (Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER);
134 table2->attach (configuration_label, 1, 2, n, n + 1, Gtk::FILL, Gtk::EXPAND, 0, 0);
135 table2->attach (channel_combo, 2, 3, n, n + 1, Gtk::FILL, Gtk::EXPAND | Gtk::FILL, 0, 0);
138 mode_label.set_alignment (Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER);
139 table2->attach (mode_label, 1, 2, n, n + 1, Gtk::FILL, Gtk::EXPAND, 0, 0);
140 table2->attach (mode_combo, 2, 3, n, n + 1, Gtk::FILL, Gtk::EXPAND | Gtk::FILL, 0, 0);
143 instrument_label.set_alignment (Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER);
144 table2->attach (instrument_label, 1, 2, n, n + 1, Gtk::FILL, Gtk::EXPAND, 0, 0);
145 table2->attach (instrument_combo, 2, 3, n, n + 1, Gtk::FILL, Gtk::EXPAND | Gtk::FILL, 0, 0);
150 l = manage (new Label (_("Group:"), Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, false));
151 table2->attach (*l, 1, 2, n, n + 1, Gtk::FILL, Gtk::EXPAND, 0, 0);
152 table2->attach (route_group_combo, 2, 3, n, n + 1, Gtk::FILL, Gtk::EXPAND | Gtk::FILL, 0, 0);
155 /* New route will be inserted at.. */
156 l = manage (new Label (_("Insert:"), 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 (insert_at_combo, 2, 3, n, n + 1, Gtk::FILL, Gtk::EXPAND | Gtk::FILL, 0, 0);
161 options_box->pack_start (*table2, false, true);
162 vbox->pack_start (*options_box, false, true);
164 get_vbox()->pack_start (*vbox, false, false);
166 track_bus_combo.signal_changed().connect (sigc::mem_fun (*this, &AddRouteDialog::track_type_chosen));
167 channel_combo.signal_changed().connect (sigc::mem_fun (*this, &AddRouteDialog::channel_combo_changed));
168 channel_combo.set_row_separator_func (sigc::mem_fun (*this, &AddRouteDialog::channel_separator));
169 route_group_combo.set_row_separator_func (sigc::mem_fun (*this, &AddRouteDialog::route_separator));
170 route_group_combo.signal_changed ().connect (sigc::mem_fun (*this, &AddRouteDialog::group_changed));
172 show_all_children ();
174 /* track template info will be managed whenever
175 this dialog is shown, via ::on_show()
178 add_button (Stock::CANCEL, RESPONSE_CANCEL);
179 add_button (Stock::ADD, RESPONSE_ACCEPT);
180 set_response_sensitive (RESPONSE_ACCEPT, true);
181 set_default_response (RESPONSE_ACCEPT);
183 track_type_chosen ();
186 AddRouteDialog::~AddRouteDialog ()
191 AddRouteDialog::channel_combo_changed ()
193 maybe_update_name_template_entry ();
194 refill_track_modes ();
197 AddRouteDialog::TypeWanted
198 AddRouteDialog::type_wanted() const
200 std::string str = track_bus_combo.get_active_text();
201 if (str == _("Busses")) {
203 } else if (str == _("MIDI Tracks")){
205 } else if (str == _("Audio+MIDI Tracks")) {
213 AddRouteDialog::maybe_update_name_template_entry ()
216 name_template_entry.get_text() != "" &&
217 name_template_entry.get_text() != _("Audio") &&
218 name_template_entry.get_text() != _("MIDI") &&
219 name_template_entry.get_text() != _("Audio+MIDI") &&
220 name_template_entry.get_text() != _("Bus")) {
224 switch (type_wanted()) {
226 name_template_entry.set_text (_("Audio"));
229 name_template_entry.set_text (_("MIDI"));
232 name_template_entry.set_text (_("Audio+MIDI"));
235 name_template_entry.set_text (_("Bus"));
241 AddRouteDialog::track_type_chosen ()
243 switch (type_wanted()) {
245 mode_combo.set_sensitive (true);
246 channel_combo.set_sensitive (true);
247 instrument_combo.set_sensitive (false);
248 configuration_label.set_sensitive (true);
249 mode_label.set_sensitive (true);
250 instrument_label.set_sensitive (false);
253 channel_combo.set_sensitive (false);
254 mode_combo.set_sensitive (false);
255 instrument_combo.set_sensitive (true);
256 configuration_label.set_sensitive (false);
257 mode_label.set_sensitive (false);
258 instrument_label.set_sensitive (true);
262 MessageDialog msg (_("Audio+MIDI tracks are intended for use <b>ONLY</b> with plugins that use both audio and MIDI input data\n\n"
263 "If you do not plan to use such a plugin, then use a normal audio or MIDI track instead."),
264 true, MESSAGE_INFO, BUTTONS_OK, true);
265 msg.set_position (WIN_POS_MOUSE);
268 channel_combo.set_sensitive (true);
269 mode_combo.set_sensitive (true);
270 instrument_combo.set_sensitive (true);
271 configuration_label.set_sensitive (true);
272 mode_label.set_sensitive (true);
273 instrument_label.set_sensitive (true);
276 mode_combo.set_sensitive (false);
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);
285 maybe_update_name_template_entry ();
290 AddRouteDialog::name_template () const
292 return name_template_entry.get_text ();
296 AddRouteDialog::name_template_is_default() const
298 string n = name_template();
300 if (n == _("Audio") ||
302 n == _("Audio+MIDI") ||
311 AddRouteDialog::count ()
313 return (int) floor (routes_adjustment.get_value ());
317 AddRouteDialog::refill_track_modes ()
321 s.push_back (_("Normal"));
322 s.push_back (_("Non Layered"));
323 s.push_back (_("Tape"));
325 set_popdown_strings (mode_combo, s);
326 mode_combo.set_active_text (s.front());
330 AddRouteDialog::mode ()
332 std::string str = mode_combo.get_active_text();
333 if (str == _("Normal")) {
334 return ARDOUR::Normal;
335 } else if (str == _("Non Layered")){
336 return ARDOUR::NonLayered;
337 } else if (str == _("Tape")) {
338 return ARDOUR::Destructive;
340 fatal << string_compose (X_("programming error: unknown track mode in add route dialog combo = %1"), str)
342 abort(); /*NOTREACHED*/
345 return ARDOUR::Normal;
349 AddRouteDialog::channels ()
353 switch (type_wanted()) {
356 str = channel_combo.get_active_text();
357 for (ChannelSetups::iterator i = channel_setups.begin(); i != channel_setups.end(); ++i) {
358 if (str == (*i).name) {
359 ret.set (DataType::AUDIO, (*i).channels);
363 ret.set (DataType::MIDI, 0);
367 ret.set (DataType::AUDIO, 0);
368 ret.set (DataType::MIDI, 1);
372 str = channel_combo.get_active_text();
373 for (ChannelSetups::iterator i = channel_setups.begin(); i != channel_setups.end(); ++i) {
374 if (str == (*i).name) {
375 ret.set (DataType::AUDIO, (*i).channels);
379 ret.set (DataType::MIDI, 1);
387 AddRouteDialog::track_template ()
389 string str = channel_combo.get_active_text();
391 for (ChannelSetups::iterator i = channel_setups.begin(); i != channel_setups.end(); ++i) {
392 if (str == (*i).name) {
393 return (*i).template_path;
401 AddRouteDialog::on_show ()
403 refill_channel_setups ();
404 refill_route_groups ();
410 AddRouteDialog::refill_channel_setups ()
414 route_templates.clear ();
415 channel_combo_strings.clear ();
416 channel_setups.clear ();
418 chn.name = _("Mono");
420 channel_setups.push_back (chn);
422 chn.name = _("Stereo");
424 channel_setups.push_back (chn);
426 chn.name = "separator";
427 channel_setups.push_back (chn);
429 ARDOUR::find_route_templates (route_templates);
431 if (!route_templates.empty()) {
433 for (vector<TemplateInfo>::iterator x = route_templates.begin(); x != route_templates.end(); ++x) {
436 chn.template_path = x->path;
437 channel_setups.push_back (chn);
441 /* clear template path for the rest */
443 chn.template_path = "";
445 chn.name = _("3 Channel");
447 channel_setups.push_back (chn);
449 chn.name = _("4 Channel");
451 channel_setups.push_back (chn);
453 chn.name = _("5 Channel");
455 channel_setups.push_back (chn);
457 chn.name = _("6 Channel");
459 channel_setups.push_back (chn);
461 chn.name = _("8 Channel");
463 channel_setups.push_back (chn);
465 chn.name = _("12 Channel");
467 channel_setups.push_back (chn);
469 chn.name = _("Custom");
471 channel_setups.push_back (chn);
473 for (ChannelSetups::iterator i = channel_setups.begin(); i != channel_setups.end(); ++i) {
474 channel_combo_strings.push_back ((*i).name);
477 set_popdown_strings (channel_combo, channel_combo_strings);
478 channel_combo.set_active_text (channel_combo_strings.front());
482 AddRouteDialog::add_route_group (RouteGroup* g)
484 route_group_combo.insert_text (3, g->name ());
488 AddRouteDialog::route_group ()
490 if (!_session || route_group_combo.get_active_row_number () == 2) {
494 return _session->route_group_by_name (route_group_combo.get_active_text());
498 AddRouteDialog::refill_route_groups ()
500 route_group_combo.clear ();
501 route_group_combo.append_text (_("New Group..."));
503 route_group_combo.append_text ("separator");
505 route_group_combo.append_text (_("No Group"));
508 _session->foreach_route_group (sigc::mem_fun (*this, &AddRouteDialog::add_route_group));
511 route_group_combo.set_active (2);
515 AddRouteDialog::group_changed ()
517 if (_session && route_group_combo.get_active_text () == _("New Group...")) {
518 RouteGroup* g = new RouteGroup (*_session, "");
519 RouteGroupDialog d (g, true);
523 route_group_combo.set_active (2);
526 _session->add_route_group (g);
529 route_group_combo.set_active (3);
534 AddRouteDialog::InsertAt
535 AddRouteDialog::insert_at ()
537 std::string str = insert_at_combo.get_active_text();
539 if (str == _("First")) {
541 } else if (str == _("After Selection")) {
542 return AfterSelection;
543 } else if (str == _("Before Selection")){
544 return BeforeSelection;
550 AddRouteDialog::channel_separator (const Glib::RefPtr<Gtk::TreeModel> &, const Gtk::TreeModel::iterator &i)
552 channel_combo.set_active (i);
554 return channel_combo.get_active_text () == "separator";
558 AddRouteDialog::route_separator (const Glib::RefPtr<Gtk::TreeModel> &, const Gtk::TreeModel::iterator &i)
560 route_group_combo.set_active (i);
562 return route_group_combo.get_active_text () == "separator";
566 AddRouteDialog::requested_instrument ()
568 return instrument_combo.selected_instrument();