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/separator.h>
26 #include <gtkmm/table.h>
28 #include "pbd/error.h"
29 #include "pbd/convert.h"
30 #include "gtkmm2ext/utils.h"
31 #include "ardour/profile.h"
32 #include "ardour/template_utils.h"
33 #include "ardour/route_group.h"
34 #include "ardour/session.h"
37 #include "add_route_dialog.h"
38 #include "route_group_dialog.h"
42 using namespace Gtkmm2ext
;
45 using namespace ARDOUR
;
47 static const char* track_mode_names
[] = {
54 std::vector
<std::string
> AddRouteDialog::channel_combo_strings
;
55 std::vector
<std::string
> AddRouteDialog::track_mode_strings
;
57 AddRouteDialog::AddRouteDialog (Session
* s
)
58 : ArdourDialog (_("Add Track or Bus"))
59 , routes_adjustment (1, 1, 128, 1, 4)
60 , routes_spinner (routes_adjustment
)
61 , mode_label (_("Track mode:"))
65 if (track_mode_strings
.empty()) {
66 track_mode_strings
= I18N (track_mode_names
);
68 if (ARDOUR::Profile
->get_sae()) {
69 /* remove all but the first track mode (Normal) */
71 while (track_mode_strings
.size() > 1) {
72 track_mode_strings
.pop_back();
77 set_name ("AddRouteDialog");
78 set_position (Gtk::WIN_POS_MOUSE
);
80 set_skip_taskbar_hint (true);
81 set_resizable (false);
83 name_template_entry
.set_name (X_("AddRouteDialogNameTemplateEntry"));
84 routes_spinner
.set_name (X_("AddRouteDialogSpinner"));
85 channel_combo
.set_name (X_("ChannelCountSelector"));
86 mode_combo
.set_name (X_("ChannelCountSelector"));
88 refill_channel_setups ();
89 refill_route_groups ();
90 set_popdown_strings (mode_combo
, track_mode_strings
, true);
92 channel_combo
.set_active_text (channel_combo_strings
.front());
93 mode_combo
.set_active_text (track_mode_strings
.front());
95 track_bus_combo
.append_text (_("tracks"));
96 track_bus_combo
.append_text (_("busses"));
97 track_bus_combo
.set_active (0);
99 VBox
* vbox
= manage (new VBox
);
102 get_vbox()->set_spacing (4);
104 vbox
->set_spacing (18);
105 vbox
->set_border_width (5);
107 HBox
*type_hbox
= manage (new HBox
);
108 type_hbox
->set_spacing (6);
110 /* track/bus choice */
112 type_hbox
->pack_start (*manage (new Label (_("Add:"))));
113 type_hbox
->pack_start (routes_spinner
);
114 type_hbox
->pack_start (track_bus_combo
);
116 vbox
->pack_start (*type_hbox
, false, true);
118 VBox
* options_box
= manage (new VBox
);
119 Table
*table2
= manage (new Table (3, 3, false));
121 options_box
->set_spacing (6);
122 table2
->set_row_spacings (6);
123 table2
->set_col_spacing (1, 6);
125 l
= manage (new Label (_("<b>Options</b>"), Gtk::ALIGN_LEFT
, Gtk::ALIGN_CENTER
, false));
126 l
->set_use_markup ();
127 options_box
->pack_start (*l
, false, true);
129 l
= manage (new Label ("", Gtk::ALIGN_LEFT
, Gtk::ALIGN_CENTER
, false));
130 l
->set_padding (8, 0);
131 table2
->attach (*l
, 0, 1, 0, 3, Gtk::FILL
, Gtk::FILL
, 0, 0);
135 l
= manage (new Label (_("Name:"), Gtk::ALIGN_LEFT
, Gtk::ALIGN_CENTER
, false));
136 table2
->attach (*l
, 1, 2, n
, n
+ 1, Gtk::FILL
, Gtk::EXPAND
, 0, 0);
137 table2
->attach (name_template_entry
, 2, 3, n
, n
+ 1, Gtk::FILL
, Gtk::EXPAND
| Gtk::FILL
, 0, 0);
140 /* Route configuration */
142 l
= manage (new Label (_("Configuration:"), Gtk::ALIGN_LEFT
, Gtk::ALIGN_CENTER
, false));
143 table2
->attach (*l
, 1, 2, n
, n
+ 1, Gtk::FILL
, Gtk::EXPAND
, 0, 0);
144 table2
->attach (channel_combo
, 2, 3, n
, n
+ 1, Gtk::FILL
, Gtk::EXPAND
| Gtk::FILL
, 0, 0);
147 if (!ARDOUR::Profile
->get_sae ()) {
151 mode_label
.set_alignment (Gtk::ALIGN_LEFT
, Gtk::ALIGN_CENTER
);
152 table2
->attach (mode_label
, 1, 2, n
, n
+ 1, Gtk::FILL
, Gtk::EXPAND
, 0, 0);
153 table2
->attach (mode_combo
, 2, 3, n
, n
+ 1, Gtk::FILL
, Gtk::EXPAND
| Gtk::FILL
, 0, 0);
160 l
= manage (new Label (_("Group:"), Gtk::ALIGN_LEFT
, Gtk::ALIGN_CENTER
, false));
161 table2
->attach (*l
, 1, 2, n
, n
+ 1, Gtk::FILL
, Gtk::EXPAND
, 0, 0);
162 table2
->attach (route_group_combo
, 2, 3, n
, n
+ 1, Gtk::FILL
, Gtk::EXPAND
| Gtk::FILL
, 0, 0);
165 options_box
->pack_start (*table2
, false, true);
166 vbox
->pack_start (*options_box
, false, true);
168 get_vbox()->pack_start (*vbox
, false, false);
170 track_bus_combo
.signal_changed().connect (sigc::mem_fun (*this, &AddRouteDialog::track_type_chosen
));
171 channel_combo
.signal_changed().connect (sigc::mem_fun (*this, &AddRouteDialog::maybe_update_name_template_entry
));
172 channel_combo
.set_row_separator_func (sigc::mem_fun (*this, &AddRouteDialog::channel_separator
));
173 route_group_combo
.set_row_separator_func (sigc::mem_fun (*this, &AddRouteDialog::route_separator
));
174 route_group_combo
.signal_changed ().connect (sigc::mem_fun (*this, &AddRouteDialog::group_changed
));
176 show_all_children ();
178 /* track template info will be managed whenever
179 this dialog is shown, via ::on_show()
182 add_button (Stock::CANCEL
, RESPONSE_CANCEL
);
183 add_button (Stock::ADD
, RESPONSE_ACCEPT
);
185 track_type_chosen ();
188 AddRouteDialog::~AddRouteDialog ()
193 AddRouteDialog::maybe_update_name_template_entry ()
196 name_template_entry
.get_text() != "" &&
197 name_template_entry
.get_text() != _("Audio") &&
198 name_template_entry
.get_text() != _("MIDI") &&
199 name_template_entry
.get_text() != _("Bus")) {
204 if (type () == DataType::MIDI
) {
205 name_template_entry
.set_text (_("MIDI"));
207 name_template_entry
.set_text (_("Audio"));
210 name_template_entry
.set_text (_("Bus"));
215 AddRouteDialog::track_type_chosen ()
217 mode_combo
.set_sensitive (track ());
218 maybe_update_name_template_entry ();
222 AddRouteDialog::track ()
224 return track_bus_combo
.get_active_row_number () == 0;
228 AddRouteDialog::type ()
230 return (channel_combo
.get_active_text() == _("MIDI"))
231 ? ARDOUR::DataType::MIDI
232 : ARDOUR::DataType::AUDIO
;
236 AddRouteDialog::name_template ()
238 return name_template_entry
.get_text ();
242 AddRouteDialog::count ()
244 return (int) floor (routes_adjustment
.get_value ());
248 AddRouteDialog::mode ()
250 if (ARDOUR::Profile
->get_sae()) {
251 return ARDOUR::Normal
;
254 std::string str
= mode_combo
.get_active_text();
255 if (str
== _("Normal")) {
256 return ARDOUR::Normal
;
257 } else if (str
== _("Non Layered")){
258 return ARDOUR::NonLayered
;
259 } else if (str
== _("Tape")) {
260 return ARDOUR::Destructive
;
262 fatal
<< string_compose (X_("programming error: unknown track mode in add route dialog combo = %1"), str
)
267 return ARDOUR::Normal
;
271 AddRouteDialog::channels ()
273 string str
= channel_combo
.get_active_text();
275 for (ChannelSetups::iterator i
= channel_setups
.begin(); i
!= channel_setups
.end(); ++i
) {
276 if (str
== (*i
).name
) {
277 return (*i
).channels
;
285 AddRouteDialog::track_template ()
287 string str
= channel_combo
.get_active_text();
289 for (ChannelSetups::iterator i
= channel_setups
.begin(); i
!= channel_setups
.end(); ++i
) {
290 if (str
== (*i
).name
) {
291 return (*i
).template_path
;
299 AddRouteDialog::on_show ()
301 refill_channel_setups ();
302 refill_route_groups ();
308 AddRouteDialog::refill_channel_setups ()
312 route_templates
.clear ();
313 channel_combo_strings
.clear ();
314 channel_setups
.clear ();
316 chn
.name
= _("Mono");
318 channel_setups
.push_back (chn
);
320 chn
.name
= _("Stereo");
322 channel_setups
.push_back (chn
);
324 chn
.name
= "separator";
325 channel_setups
.push_back (chn
);
327 chn
.name
= _("MIDI");
329 channel_setups
.push_back (chn
);
331 chn
.name
= "separator";
332 channel_setups
.push_back (chn
);
334 ARDOUR::find_route_templates (route_templates
);
336 if (!ARDOUR::Profile
->get_sae()) {
337 if (!route_templates
.empty()) {
339 for (vector
<TemplateInfo
>::iterator x
= route_templates
.begin(); x
!= route_templates
.end(); ++x
) {
342 chn
.template_path
= x
->path
;
343 channel_setups
.push_back (chn
);
347 /* clear template path for the rest */
349 chn
.template_path
= "";
351 chn
.name
= _("3 Channel");
353 channel_setups
.push_back (chn
);
355 chn
.name
= _("4 Channel");
357 channel_setups
.push_back (chn
);
359 chn
.name
= _("5 Channel");
361 channel_setups
.push_back (chn
);
363 chn
.name
= _("6 Channel");
365 channel_setups
.push_back (chn
);
367 chn
.name
= _("8 Channel");
369 channel_setups
.push_back (chn
);
371 chn
.name
= _("12 Channel");
373 channel_setups
.push_back (chn
);
375 chn
.name
= _("Custom");
377 channel_setups
.push_back (chn
);
380 for (ChannelSetups::iterator i
= channel_setups
.begin(); i
!= channel_setups
.end(); ++i
) {
381 channel_combo_strings
.push_back ((*i
).name
);
384 set_popdown_strings (channel_combo
, channel_combo_strings
, true);
385 channel_combo
.set_active_text (channel_combo_strings
.front());
389 AddRouteDialog::add_route_group (RouteGroup
* g
)
391 route_group_combo
.insert_text (3, g
->name ());
395 AddRouteDialog::route_group ()
397 if (route_group_combo
.get_active_row_number () == 2) {
401 return _session
->route_group_by_name (route_group_combo
.get_active_text());
405 AddRouteDialog::refill_route_groups ()
407 route_group_combo
.clear ();
408 route_group_combo
.append_text (_("New group..."));
410 route_group_combo
.append_text ("separator");
412 route_group_combo
.append_text (_("No group"));
414 _session
->foreach_route_group (sigc::mem_fun (*this, &AddRouteDialog::add_route_group
));
416 route_group_combo
.set_active (2);
420 AddRouteDialog::group_changed ()
422 if (_session
&& route_group_combo
.get_active_text () == _("New group...")) {
423 RouteGroup
* g
= new RouteGroup (*_session
, "");
426 plist
.add (Properties::active
, true);
427 g
->apply_changes (plist
);
429 RouteGroupDialog
d (g
, true);
433 route_group_combo
.set_active (2);
435 _session
->add_route_group (g
);
437 route_group_combo
.set_active (3);
443 AddRouteDialog::channel_separator (const Glib::RefPtr
<Gtk::TreeModel
> &, const Gtk::TreeModel::iterator
&i
)
445 channel_combo
.set_active (i
);
447 return channel_combo
.get_active_text () == "separator";
451 AddRouteDialog::route_separator (const Glib::RefPtr
<Gtk::TreeModel
> &, const Gtk::TreeModel::iterator
&i
)
453 route_group_combo
.set_active (i
);
455 return route_group_combo
.get_active_text () == "separator";