20da63689fb6058f98ca5e24272c237d9c173df5
[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* channel_setup_names[] = {
44         N_("Mono"),
45         N_("Stereo"),
46         N_("3 Channels"),
47         N_("4 Channels"),
48         N_("6 Channels"),
49         N_("8 Channels"),
50         N_("Manual Setup"),
51         0
52 };
53
54 static const char* track_mode_names[] = {
55         N_("Normal"),
56         N_("Tape"),
57         0
58 };
59
60 static vector<string> channel_combo_strings;
61 static vector<string> track_mode_strings;
62
63
64 AddRouteDialog::AddRouteDialog ()
65         : Dialog (_("ardour: add track/bus")),
66           track_button (_("Tracks")),
67           bus_button (_("Busses")),
68           template_button (_("Using this template:")),
69           routes_adjustment (1, 1, 128, 1, 4),
70           routes_spinner (routes_adjustment)
71 {
72         if (channel_combo_strings.empty()) {
73                 channel_combo_strings = I18N (channel_setup_names);
74
75                 if (ARDOUR::Profile->get_sae()) {
76                         /* remove all but the first two (Mono & Stereo) */
77
78                         while (track_mode_strings.size() > 2) {
79                                 track_mode_strings.pop_back();
80                         }
81                 }
82
83         }
84
85         if (track_mode_strings.empty()) {
86                 track_mode_strings = I18N (track_mode_names);
87
88                 if (ARDOUR::Profile->get_sae()) {
89                         /* remove all but the first track mode (Normal) */
90
91                         while (track_mode_strings.size() > 1) {
92                                 track_mode_strings.pop_back();
93                         }
94                 }
95         }
96         
97         set_name ("AddRouteDialog");
98         set_wmclass (X_("ardour_add_track_bus"), "Ardour");
99         set_position (Gtk::WIN_POS_MOUSE);
100         set_resizable (false);
101
102         name_template_entry.set_name ("AddRouteDialogNameTemplateEntry");
103         track_button.set_name ("AddRouteDialogRadioButton");
104         bus_button.set_name ("AddRouteDialogRadioButton");
105         template_button.set_name ("AddRouteDialogRadioButton");
106         routes_spinner.set_name ("AddRouteDialogSpinner");
107         
108         RadioButton::Group g = track_button.get_group();
109         bus_button.set_group (g);
110         template_button.set_group (g);
111         track_button.set_active (true);
112
113         /* add */
114
115         HBox* hbox1 = manage (new HBox);
116         hbox1->set_spacing (6);
117         Label* label1 = manage (new Label (_("Add this many:")));
118         hbox1->pack_start (*label1, PACK_SHRINK);
119         hbox1->pack_start (routes_spinner, PACK_SHRINK);
120
121         HBox* hbox2 = manage (new HBox);
122         hbox2->set_spacing (6);
123         hbox2->set_border_width (6);
124         hbox2->pack_start (*hbox1, PACK_EXPAND_WIDGET);
125
126         /* templates */
127
128         hbox3 = new HBox;
129         hbox3->set_spacing (6);
130         hbox3->set_border_width (6);
131         hbox3->pack_start (template_button, PACK_SHRINK);
132
133         hbox9 = new HBox;
134         hbox9->set_spacing (6);
135         hbox9->set_border_width (6);
136         hbox9->pack_start (track_template_combo, PACK_EXPAND_WIDGET);
137         
138         /* separator */
139
140         hbox4 = new HBox;
141         hbox4->set_spacing (6);
142         Label* label2 = manage (new Label (_("OR")));
143         hbox4->pack_start (*(manage (new HSeparator)), PACK_EXPAND_WIDGET);
144         hbox4->pack_start (*label2, false, false);
145         hbox4->pack_start (*(manage (new HSeparator)), PACK_EXPAND_WIDGET);
146
147         /* we need more control over the visibility of these boxes */
148         /*
149         hbox3->set_no_show_all (true);
150         hbox9->set_no_show_all (true);
151         hbox4->set_no_show_all (true);
152         */
153         /* track/bus choice & modes */
154
155         HBox* hbox5 = manage (new HBox);
156         hbox5->set_spacing (6);
157         hbox5->pack_start (track_button, PACK_EXPAND_PADDING);
158         hbox5->pack_start (bus_button, PACK_EXPAND_PADDING);
159
160         set_popdown_strings (channel_combo, channel_combo_strings);
161         set_popdown_strings (track_mode_combo, track_mode_strings);
162         channel_combo.set_active_text (channel_combo_strings.front());
163         channel_combo.set_name (X_("ChannelCountSelector"));
164
165         track_button.signal_clicked().connect (mem_fun (*this, &AddRouteDialog::track_type_chosen));
166         bus_button.signal_clicked().connect (mem_fun (*this, &AddRouteDialog::track_type_chosen));
167         template_button.signal_clicked().connect (mem_fun (*this, &AddRouteDialog::track_type_chosen));
168
169         track_mode_combo.set_active_text (track_mode_strings.front());
170         track_mode_combo.set_name (X_("ChannelCountSelector"));
171         
172         VBox* vbox1 = manage (new VBox);
173         vbox1->set_spacing (6);
174         vbox1->set_border_width (6);
175
176         Frame* frame1 = manage (new Frame (_("Channel Configuration")));
177         frame1->add (channel_combo);
178         Frame* frame2 = manage (new Frame (_("Track Mode")));
179         frame2->add (track_mode_combo);
180
181         vbox1->pack_start (*hbox5, PACK_SHRINK);
182         vbox1->pack_start (*frame1, PACK_SHRINK);
183
184         if (!ARDOUR::Profile->get_sae()) {
185           vbox1->pack_start (*frame2, PACK_SHRINK);
186         }
187
188         get_vbox()->set_spacing (6);
189         get_vbox()->set_border_width (6);
190
191         get_vbox()->pack_start (*hbox2, PACK_SHRINK);
192         get_vbox()->pack_start (*hbox3, PACK_SHRINK);
193         get_vbox()->pack_start (*hbox9, PACK_SHRINK);
194         get_vbox()->pack_start (*hbox4, PACK_SHRINK);
195         get_vbox()->pack_start (*vbox1, PACK_SHRINK);
196
197         get_vbox()->show_all ();
198
199         /* track template info will be managed whenever
200            this dialog is shown, via ::on_show()
201         */
202
203         add_button (Stock::CANCEL, RESPONSE_CANCEL);
204         add_button (Stock::ADD, RESPONSE_ACCEPT);
205
206         track_type_chosen ();
207 }
208
209 AddRouteDialog::~AddRouteDialog ()
210 {
211 }
212
213 void
214 AddRouteDialog::track_type_chosen ()
215 {
216   if (template_button.get_active()) {
217     track_mode_combo.set_sensitive (false);
218     channel_combo.set_sensitive (false);
219     track_template_combo.set_sensitive (true);
220   } else {
221     track_template_combo.set_sensitive (false);
222     channel_combo.set_sensitive (true);
223     if (track_button.get_active()) {
224       track_mode_combo.set_sensitive (true);
225     } else {
226       track_mode_combo.set_sensitive (false);
227     }
228   }
229 }
230
231 bool
232 AddRouteDialog::track ()
233 {
234         return track_button.get_active ();
235 }
236
237 string
238 AddRouteDialog::name_template ()
239 {
240         return name_template_entry.get_text ();
241 }
242
243 int
244 AddRouteDialog::count ()
245 {
246         return (int) floor (routes_adjustment.get_value ());
247 }
248
249 ARDOUR::TrackMode
250 AddRouteDialog::mode ()
251 {
252         if (ARDOUR::Profile->get_sae()) {
253                 return ARDOUR::Normal;
254         }
255
256         Glib::ustring str = track_mode_combo.get_active_text();
257         if (str == _("Normal")) {
258                 return ARDOUR::Normal;
259         } else if (str == _("Tape")) {
260                 return ARDOUR::Destructive;
261         } else {
262                 fatal << string_compose (X_("programming error: unknown track mode in add route dialog combo = %1"), str)
263                       << endmsg;
264                 /*NOTREACHED*/
265         }
266         /* keep gcc happy */
267         return ARDOUR::Normal;
268 }
269
270 int
271 AddRouteDialog::channels ()
272 {
273         string str = channel_combo.get_active_text();
274         int chns;
275
276         if (str == _("Mono")) {
277                 return 1;
278         } else if (str == _("Stereo")) {
279                 return 2;
280         } else if ((chns = PBD::atoi (str)) != 0) {
281                 return chns;
282         } 
283
284         return 0;
285 }
286
287 string
288 AddRouteDialog::track_template ()
289 {
290   if (!template_button.get_active()) {
291     return string ();
292   }
293
294   string str = track_template_combo.get_active_text();
295
296   for (vector<Session::RouteTemplateInfo>::iterator x = route_templates.begin(); x != route_templates.end(); ++x) {
297     if ((*x).name == str) {
298       return (*x).path;
299     }
300   }
301
302   return string();
303 }
304
305 void
306 AddRouteDialog::on_show ()
307 {
308   refill_track_templates ();
309   Dialog::on_show ();
310 }
311
312 void
313 AddRouteDialog::refill_track_templates ()
314 {
315   route_templates.clear ();
316   Session::get_route_templates (route_templates);
317   
318   if (!route_templates.empty()) {
319     vector<string> v;
320     for (vector<Session::RouteTemplateInfo>::iterator x = route_templates.begin(); x != route_templates.end(); ++x) {
321       v.push_back ((*x).name);
322     }
323     set_popdown_strings (track_template_combo, v);
324     track_template_combo.set_active_text (v.front());
325   } 
326
327   reset_template_option_visibility ();
328 }
329
330 void
331 AddRouteDialog::reset_template_option_visibility ()
332 {
333   if (route_templates.empty()) {
334     hbox3->hide ();
335     hbox9->hide ();
336     hbox4->hide ();
337   } else {
338     hbox3->show_all ();
339     hbox9->show_all ();
340     hbox4->show_all ();
341   }
342 }