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