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