add track-record-enable-toggle action to menu, to make it actually bindable ; fixup...
[ardour.git] / gtk2_ardour / add_route_dialog.cc
1 /*
2   Copyright (C) 2003 Paul Davis 
3
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.
8
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.
13
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.
17
18 */
19
20 #include <cstdio>
21 #include <cmath>
22
23 #include <sigc++/bind.h>
24 #include <gtkmm/stock.h>
25 #include <gtkmm/separator.h>
26 #include <pbd/error.h>
27 #include <pbd/convert.h>
28 #include <gtkmm2ext/utils.h>
29 #include <ardour/profile.h>
30 #include <ardour/session.h>
31
32 #include "utils.h"
33 #include "add_route_dialog.h"
34 #include "i18n.h"
35
36 using namespace Gtk;
37 using namespace Gtkmm2ext;
38 using namespace sigc;
39 using namespace std;
40 using namespace PBD;
41 using namespace ARDOUR;
42
43 static const char* track_mode_names[] = {
44         N_("Normal"),
45         N_("Tape"),
46         0
47 };
48
49
50 AddRouteDialog::AddRouteDialog ()
51         : Dialog (_("ardour: add track/bus")),
52           track_button (_("Tracks")),
53           bus_button (_("Busses")),
54           routes_adjustment (1, 1, 128, 1, 4),
55           routes_spinner (routes_adjustment)
56 {
57         if (track_mode_strings.empty()) {
58                 track_mode_strings = I18N (track_mode_names);
59
60                 if (ARDOUR::Profile->get_sae()) {
61                         /* remove all but the first track mode (Normal) */
62
63                         while (track_mode_strings.size() > 1) {
64                                 track_mode_strings.pop_back();
65                         }
66                 }
67         }
68         
69         set_name ("AddRouteDialog");
70         set_wmclass (X_("ardour_add_track_bus"), "Ardour");
71         set_position (Gtk::WIN_POS_MOUSE);
72         set_resizable (false);
73
74         name_template_entry.set_name ("AddRouteDialogNameTemplateEntry");
75         track_button.set_name ("AddRouteDialogRadioButton");
76         bus_button.set_name ("AddRouteDialogRadioButton");
77         routes_spinner.set_name ("AddRouteDialogSpinner");
78         
79         RadioButton::Group g = track_button.get_group();
80         bus_button.set_group (g);
81         track_button.set_active (true);
82
83         /* add */
84
85         HBox* hbox1 = manage (new HBox);
86         hbox1->set_spacing (6);
87         Label* label1 = manage (new Label (_("Add this many:")));
88         hbox1->pack_start (*label1, PACK_SHRINK);
89         hbox1->pack_start (routes_spinner, PACK_SHRINK);
90
91         HBox* hbox2 = manage (new HBox);
92         hbox2->set_spacing (6);
93         hbox2->set_border_width (6);
94         hbox2->pack_start (*hbox1, PACK_EXPAND_WIDGET);
95
96         /* track/bus choice & modes */
97
98         HBox* hbox5 = manage (new HBox);
99         hbox5->set_spacing (6);
100         hbox5->pack_start (track_button, PACK_EXPAND_PADDING);
101         hbox5->pack_start (bus_button, PACK_EXPAND_PADDING);
102
103         channel_combo.set_name (X_("ChannelCountSelector"));
104         track_mode_combo.set_name (X_("ChannelCountSelector"));
105
106         refill_channel_setups ();
107         set_popdown_strings (track_mode_combo, track_mode_strings, true);
108
109         channel_combo.set_active_text (channel_combo_strings.front());
110         track_mode_combo.set_active_text (track_mode_strings.front());
111
112         track_button.signal_clicked().connect (mem_fun (*this, &AddRouteDialog::track_type_chosen));
113         bus_button.signal_clicked().connect (mem_fun (*this, &AddRouteDialog::track_type_chosen));
114         
115         VBox* vbox1 = manage (new VBox);
116         vbox1->set_spacing (6);
117         vbox1->set_border_width (6);
118
119         Frame* frame1 = manage (new Frame (_("Channel Configuration")));
120         frame1->add (channel_combo);
121         Frame* frame2 = manage (new Frame (_("Track Mode")));
122         frame2->add (track_mode_combo);
123
124         vbox1->pack_start (*hbox5, PACK_SHRINK);
125         vbox1->pack_start (*frame1, PACK_SHRINK);
126
127         if (!ARDOUR::Profile->get_sae()) {
128                 vbox1->pack_start (*frame2, PACK_SHRINK);
129         }
130
131         get_vbox()->set_spacing (6);
132         get_vbox()->set_border_width (6);
133
134         get_vbox()->pack_start (*hbox2, PACK_SHRINK);
135         get_vbox()->pack_start (*vbox1, PACK_SHRINK);
136
137         get_vbox()->show_all ();
138
139         /* track template info will be managed whenever
140            this dialog is shown, via ::on_show()
141         */
142
143         add_button (Stock::CANCEL, RESPONSE_CANCEL);
144         add_button (Stock::ADD, RESPONSE_ACCEPT);
145
146         track_type_chosen ();
147 }
148
149 AddRouteDialog::~AddRouteDialog ()
150 {
151 }
152
153 void
154 AddRouteDialog::track_type_chosen ()
155 {
156         if (track_button.get_active()) {
157                 track_mode_combo.set_sensitive (true);
158         } else {
159                 track_mode_combo.set_sensitive (false);
160         }
161 }
162
163 bool
164 AddRouteDialog::track ()
165 {
166         return track_button.get_active ();
167 }
168
169 string
170 AddRouteDialog::name_template ()
171 {
172         return name_template_entry.get_text ();
173 }
174
175 int
176 AddRouteDialog::count ()
177 {
178         return (int) floor (routes_adjustment.get_value ());
179 }
180
181 ARDOUR::TrackMode
182 AddRouteDialog::mode ()
183 {
184         if (ARDOUR::Profile->get_sae()) {
185                 return ARDOUR::Normal;
186         }
187
188         Glib::ustring str = track_mode_combo.get_active_text();
189         if (str == _("Normal")) {
190                 return ARDOUR::Normal;
191         } else if (str == _("Tape")) {
192                 return ARDOUR::Destructive;
193         } else {
194                 fatal << string_compose (X_("programming error: unknown track mode in add route dialog combo = %1"), str)
195                       << endmsg;
196                 /*NOTREACHED*/
197         }
198         /* keep gcc happy */
199         return ARDOUR::Normal;
200 }
201
202 int
203 AddRouteDialog::channels ()
204 {
205         string str = channel_combo.get_active_text();
206       
207         for (ChannelSetups::iterator i = channel_setups.begin(); i != channel_setups.end(); ++i) {
208                 if (str == (*i).name) {
209                         return (*i).channels;
210                 }
211         }
212
213         return 0;
214 }
215
216 string
217 AddRouteDialog::track_template ()
218 {
219         string str = channel_combo.get_active_text();
220         
221         for (ChannelSetups::iterator i = channel_setups.begin(); i != channel_setups.end(); ++i) {
222                 if (str == (*i).name) {
223                         return (*i).template_path;
224                 }
225         }
226         
227         return string();
228 }
229
230 void
231 AddRouteDialog::on_show ()
232 {
233         refill_channel_setups ();
234         Dialog::on_show ();
235 }
236 void
237 AddRouteDialog::refill_channel_setups ()
238 {
239         ChannelSetup chn;
240         
241         route_templates.clear ();
242         channel_combo_strings.clear ();
243         channel_setups.clear ();
244
245         chn.name = _("Mono");
246         chn.channels = 1;
247         channel_setups.push_back (chn);
248
249         chn.name = _("Stereo");
250         chn.channels = 2;
251         channel_setups.push_back (chn);
252
253         Session::get_route_templates (route_templates);
254
255         if (!ARDOUR::Profile->get_sae()) {
256                 if (!route_templates.empty()) {
257                         vector<string> v;
258                         for (vector<Session::RouteTemplateInfo>::iterator x = route_templates.begin(); x != route_templates.end(); ++x) {
259                                 chn.name = x->name;
260                                 chn.channels = 0;
261                                 chn.template_path = x->path;
262                                 channel_setups.push_back (chn);
263                         }
264                 } 
265
266                 /* no more templates for the rest */
267                 chn.template_path = "";
268
269                 chn.name = _("3 Channel");
270                 chn.channels = 3;
271                 channel_setups.push_back (chn);
272
273                 chn.name = _("4 Channel");
274                 chn.channels = 4;
275                 channel_setups.push_back (chn);
276
277                 chn.name = _("5 Channel");
278                 chn.channels = 5;
279                 channel_setups.push_back (chn);
280
281                 chn.name = _("6 Channel");
282                 chn.channels = 6;
283                 channel_setups.push_back (chn);
284
285                 chn.name = _("8 Channel");
286                 chn.channels = 8;
287                 channel_setups.push_back (chn);
288
289                 chn.name = _("12 Channel");
290                 chn.channels = 12;
291                 channel_setups.push_back (chn);
292
293                 chn.name = X_("Custom");
294                 chn.channels = 0;
295                 channel_setups.push_back (chn);
296         }
297
298         for (ChannelSetups::iterator i = channel_setups.begin(); i != channel_setups.end(); ++i) {
299                 channel_combo_strings.push_back ((*i).name);
300         }
301
302         set_popdown_strings (channel_combo, channel_combo_strings, true);
303         channel_combo.set_active_text (channel_combo_strings.front());
304 }
305