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