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>
27 #include "pbd/error.h"
28 #include "pbd/convert.h"
29 #include "gtkmm2ext/utils.h"
30 #include "ardour/profile.h"
31 #include "ardour/template_utils.h"
32 #include "ardour/session.h"
35 #include "add_route_dialog.h"
39 using namespace Gtkmm2ext;
43 using namespace ARDOUR;
45 static const char* channel_setup_names[] = {
57 static const char* track_mode_names[] = {
63 static vector<string> channel_combo_strings;
64 static vector<string> track_mode_strings;
67 AddRouteDialog::AddRouteDialog ()
68 : Dialog (_("ardour: add track/bus")),
69 track_button (_("Tracks")),
70 bus_button (_("Busses")),
71 template_button (_("Using this template:")),
72 routes_adjustment (1, 1, 128, 1, 4),
73 routes_spinner (routes_adjustment)
75 if (channel_combo_strings.empty()) {
76 channel_combo_strings = I18N (channel_setup_names);
78 if (ARDOUR::Profile->get_sae()) {
79 /* remove all but the first two (Mono & Stereo) */
81 while (track_mode_strings.size() > 2) {
82 track_mode_strings.pop_back();
88 if (track_mode_strings.empty()) {
89 track_mode_strings = I18N (track_mode_names);
91 if (ARDOUR::Profile->get_sae()) {
92 /* remove all but the first track mode (Normal) */
94 while (track_mode_strings.size() > 1) {
95 track_mode_strings.pop_back();
100 set_name ("AddRouteDialog");
101 set_wmclass (X_("ardour_add_track_bus"), "Ardour");
102 set_position (Gtk::WIN_POS_MOUSE);
103 set_resizable (false);
105 name_template_entry.set_name ("AddRouteDialogNameTemplateEntry");
106 track_button.set_name ("AddRouteDialogRadioButton");
107 bus_button.set_name ("AddRouteDialogRadioButton");
108 template_button.set_name ("AddRouteDialogRadioButton");
109 routes_spinner.set_name ("AddRouteDialogSpinner");
111 RadioButton::Group g = track_button.get_group();
112 bus_button.set_group (g);
113 template_button.set_group (g);
114 track_button.set_active (true);
118 HBox* hbox1 = manage (new HBox);
119 hbox1->set_spacing (6);
120 Label* label1 = manage (new Label (_("Add this many:")));
121 hbox1->pack_start (*label1, PACK_SHRINK);
122 hbox1->pack_start (routes_spinner, PACK_SHRINK);
124 HBox* hbox2 = manage (new HBox);
125 hbox2->set_spacing (6);
126 hbox2->set_border_width (6);
127 hbox2->pack_start (*hbox1, PACK_EXPAND_WIDGET);
132 hbox3->set_spacing (6);
133 hbox3->set_border_width (6);
134 hbox3->pack_start (template_button, PACK_SHRINK);
137 hbox9->set_spacing (6);
138 hbox9->set_border_width (6);
139 hbox9->pack_start (track_template_combo, PACK_EXPAND_WIDGET);
144 hbox4->set_spacing (6);
145 Label* label2 = manage (new Label (_("OR")));
146 hbox4->pack_start (*(manage (new HSeparator)), PACK_EXPAND_WIDGET);
147 hbox4->pack_start (*label2, false, false);
148 hbox4->pack_start (*(manage (new HSeparator)), PACK_EXPAND_WIDGET);
150 /* we need more control over the visibility of these boxes */
152 hbox3->set_no_show_all (true);
153 hbox9->set_no_show_all (true);
154 hbox4->set_no_show_all (true);
156 /* track/bus choice & modes */
158 HBox* hbox5 = manage (new HBox);
159 hbox5->set_spacing (6);
160 hbox5->pack_start (track_button, PACK_EXPAND_PADDING);
161 hbox5->pack_start (bus_button, PACK_EXPAND_PADDING);
163 set_popdown_strings (channel_combo, channel_combo_strings);
164 set_popdown_strings (track_mode_combo, track_mode_strings);
165 channel_combo.set_active_text (channel_combo_strings.front());
166 channel_combo.set_name (X_("ChannelCountSelector"));
168 track_button.signal_clicked().connect (mem_fun (*this, &AddRouteDialog::track_type_chosen));
169 bus_button.signal_clicked().connect (mem_fun (*this, &AddRouteDialog::track_type_chosen));
170 template_button.signal_clicked().connect (mem_fun (*this, &AddRouteDialog::track_type_chosen));
172 track_mode_combo.set_active_text (track_mode_strings.front());
173 track_mode_combo.set_name (X_("ChannelCountSelector"));
175 VBox* vbox1 = manage (new VBox);
176 vbox1->set_spacing (6);
177 vbox1->set_border_width (6);
179 Frame* frame1 = manage (new Frame (_("Channel Configuration")));
180 frame1->add (channel_combo);
181 Frame* frame2 = manage (new Frame (_("Track Mode")));
182 frame2->add (track_mode_combo);
184 vbox1->pack_start (*hbox5, PACK_SHRINK);
185 vbox1->pack_start (*frame1, PACK_SHRINK);
187 if (!ARDOUR::Profile->get_sae()) {
188 vbox1->pack_start (*frame2, PACK_SHRINK);
191 get_vbox()->set_spacing (6);
192 get_vbox()->set_border_width (6);
194 get_vbox()->pack_start (*hbox2, PACK_SHRINK);
195 get_vbox()->pack_start (*hbox3, PACK_SHRINK);
196 get_vbox()->pack_start (*hbox9, PACK_SHRINK);
197 get_vbox()->pack_start (*hbox4, PACK_SHRINK);
198 get_vbox()->pack_start (*vbox1, PACK_SHRINK);
200 get_vbox()->show_all ();
202 /* track template info will be managed whenever
203 this dialog is shown, via ::on_show()
206 add_button (Stock::CANCEL, RESPONSE_CANCEL);
207 add_button (Stock::ADD, RESPONSE_ACCEPT);
209 track_type_chosen ();
212 AddRouteDialog::~AddRouteDialog ()
217 AddRouteDialog::track_type_chosen ()
219 if (template_button.get_active()) {
220 track_mode_combo.set_sensitive (false);
221 channel_combo.set_sensitive (false);
222 track_template_combo.set_sensitive (true);
224 track_template_combo.set_sensitive (false);
225 channel_combo.set_sensitive (true);
226 if (track_button.get_active()) {
227 track_mode_combo.set_sensitive (true);
229 track_mode_combo.set_sensitive (false);
235 AddRouteDialog::track ()
237 return track_button.get_active ();
241 AddRouteDialog::type ()
245 const string str = channel_combo.get_active_text();
246 if (str == _("MIDI"))
247 return ARDOUR::DataType::MIDI;
249 return ARDOUR::DataType::AUDIO;
253 AddRouteDialog::name_template ()
255 return name_template_entry.get_text ();
259 AddRouteDialog::count ()
261 return (int) floor (routes_adjustment.get_value ());
265 AddRouteDialog::mode ()
267 if (ARDOUR::Profile->get_sae()) {
268 return ARDOUR::Normal;
271 Glib::ustring str = track_mode_combo.get_active_text();
272 if (str == _("Normal")) {
273 return ARDOUR::Normal;
274 } else if (str == _("Tape")) {
275 return ARDOUR::Destructive;
277 fatal << string_compose (X_("programming error: unknown track mode in add route dialog combo = %1"), str)
282 return ARDOUR::Normal;
286 AddRouteDialog::channels ()
288 string str = channel_combo.get_active_text();
291 if (str == _("Mono")) {
293 } else if (str == _("Stereo")) {
295 } else if ((chns = PBD::atoi (str)) != 0) {
303 AddRouteDialog::track_template ()
305 if (!template_button.get_active()) {
309 string str = track_template_combo.get_active_text();
311 for (vector<RouteTemplateInfo>::iterator x = route_templates.begin(); x != route_templates.end(); ++x) {
312 if ((*x).name == str) {
321 AddRouteDialog::on_show ()
323 refill_track_templates ();
328 AddRouteDialog::refill_track_templates ()
330 route_templates.clear ();
331 ARDOUR::find_route_templates (route_templates);
333 if (!route_templates.empty()) {
335 for (vector<RouteTemplateInfo>::iterator x = route_templates.begin(); x != route_templates.end(); ++x) {
336 v.push_back ((*x).name);
338 set_popdown_strings (track_template_combo, v);
339 track_template_combo.set_active_text (v.front());
342 reset_template_option_visibility ();
346 AddRouteDialog::reset_template_option_visibility ()
348 if (route_templates.empty()) {