remove using namespace sigc everywhere to ensure clarity over which bind/mem_fun...
[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 "route_group_dialog.h"
39 #include "i18n.h"
40
41 using namespace Gtk;
42 using namespace Gtkmm2ext;
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 static const char* bus_mode_names[] = {
55         N_("Aux"),
56         N_("Direct"),
57         0
58 };
59
60 std::vector<std::string> AddRouteDialog::channel_combo_strings;
61 std::vector<std::string> AddRouteDialog::track_mode_strings;
62 std::vector<std::string> AddRouteDialog::bus_mode_strings;
63
64 AddRouteDialog::AddRouteDialog (Session & s)
65         : ArdourDialog (X_("add route dialog"))
66         , _session (s)
67         , routes_adjustment (1, 1, 128, 1, 4)
68         , routes_spinner (routes_adjustment)
69         , mode_label (_("Track mode:"))
70 {
71         if (track_mode_strings.empty()) {
72                 track_mode_strings = I18N (track_mode_names);
73
74                 if (ARDOUR::Profile->get_sae()) {
75                         /* remove all but the first track mode (Normal) */
76
77                         while (track_mode_strings.size() > 1) {
78                                 track_mode_strings.pop_back();
79                         }
80                 }
81         }
82
83         if (bus_mode_strings.empty()) {
84                 bus_mode_strings = I18N (bus_mode_names);
85         }
86
87         set_name ("AddRouteDialog");
88         set_position (Gtk::WIN_POS_MOUSE);
89         set_modal (true);
90         set_skip_taskbar_hint (true);
91         set_resizable (false);
92
93         set_title (_("Add Track/Bus"));
94
95         name_template_entry.set_name (X_("AddRouteDialogNameTemplateEntry"));
96         routes_spinner.set_name (X_("AddRouteDialogSpinner"));
97         channel_combo.set_name (X_("ChannelCountSelector"));
98         mode_combo.set_name (X_("ChannelCountSelector"));
99
100         refill_channel_setups ();
101         refill_route_groups ();
102         set_popdown_strings (mode_combo, track_mode_strings, true);
103
104         channel_combo.set_active_text (channel_combo_strings.front());
105         mode_combo.set_active_text (track_mode_strings.front());
106
107         track_bus_combo.append_text (_("tracks"));
108         track_bus_combo.append_text (_("busses"));
109         track_bus_combo.set_active (0);
110
111         VBox* vbox = manage (new VBox);
112         Gtk::Label* l;
113
114         get_vbox()->set_spacing (4);
115
116         vbox->set_spacing (18);
117         vbox->set_border_width (5);
118
119         HBox *type_hbox = manage (new HBox);
120         type_hbox->set_spacing (6);
121
122         /* track/bus choice */
123
124         type_hbox->pack_start (*manage (new Label (_("Add:"))));
125         type_hbox->pack_start (routes_spinner);
126         type_hbox->pack_start (track_bus_combo);
127
128         vbox->pack_start (*type_hbox, false, true);
129
130         VBox* options_box = manage (new VBox);
131         Table *table2 = manage (new Table (3, 3, false));
132
133         options_box->set_spacing (6);
134         table2->set_row_spacings (6);
135         table2->set_col_spacing (1, 6);
136
137         l = manage (new Label (_("<b>Options</b>"), Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, false));
138         l->set_use_markup ();
139         options_box->pack_start (*l, false, true);
140
141         l = manage (new Label ("", Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, false));
142         l->set_padding (8, 0);
143         table2->attach (*l, 0, 1, 0, 3, Gtk::FILL, Gtk::FILL, 0, 0);
144
145         /* Route configuration */
146
147         l = manage (new Label (_("Configuration:"), Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, false));
148         table2->attach (*l, 1, 2, 0, 1, Gtk::FILL, Gtk::EXPAND, 0, 0);
149         table2->attach (channel_combo, 2, 3, 0, 1, Gtk::FILL, Gtk::EXPAND & Gtk::FILL, 0, 0);
150
151         if (!ARDOUR::Profile->get_sae ()) {
152
153                 /* Track mode */
154
155                 mode_label.set_alignment (Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER);
156                 table2->attach (mode_label, 1, 2, 1, 2, Gtk::FILL, Gtk::EXPAND, 0, 0);
157                 table2->attach (mode_combo, 2, 3, 1, 2, Gtk::FILL, Gtk::EXPAND & Gtk::FILL, 0, 0);
158
159         }
160
161         /* Group choise */
162
163         l = manage (new Label (_("Group:"), Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, false));
164         table2->attach (*l, 1, 2, 2, 3, Gtk::FILL, Gtk::EXPAND, 0, 0);
165         table2->attach (route_group_combo, 2, 3, 2, 3, Gtk::FILL, Gtk::EXPAND & Gtk::FILL, 0, 0);
166
167         options_box->pack_start (*table2, false, true);
168         vbox->pack_start (*options_box, false, true);
169
170         get_vbox()->pack_start (*vbox, false, false);
171
172         track_bus_combo.signal_changed().connect (sigc::mem_fun (*this, &AddRouteDialog::track_type_chosen));
173         channel_combo.set_row_separator_func (sigc::mem_fun (*this, &AddRouteDialog::channel_separator));
174         route_group_combo.set_row_separator_func (sigc::mem_fun (*this, &AddRouteDialog::route_separator));
175         route_group_combo.signal_changed ().connect (sigc::mem_fun (*this, &AddRouteDialog::group_changed));
176
177         show_all_children ();
178
179         /* track template info will be managed whenever
180            this dialog is shown, via ::on_show()
181         */
182
183         add_button (Stock::CANCEL, RESPONSE_CANCEL);
184         add_button (Stock::ADD, RESPONSE_ACCEPT);
185
186         track_type_chosen ();
187 }
188
189 AddRouteDialog::~AddRouteDialog ()
190 {
191 }
192
193 void
194 AddRouteDialog::track_type_chosen ()
195 {
196         if (track()) {
197                 mode_label.set_text (_("Track mode:"));
198                 set_popdown_strings (mode_combo, track_mode_strings);
199                 mode_combo.set_active_text (track_mode_strings.front());
200         } else {
201                 mode_label.set_text (_("Bus type:"));
202                 set_popdown_strings (mode_combo, bus_mode_strings);
203                 mode_combo.set_active_text (bus_mode_strings.front());
204         }
205
206 }
207
208 bool
209 AddRouteDialog::track ()
210 {
211         return track_bus_combo.get_active_row_number () == 0;
212 }
213
214 bool
215 AddRouteDialog::aux ()
216 {
217         return !track() && mode_combo.get_active_row_number () == 0;
218 }
219
220 ARDOUR::DataType
221 AddRouteDialog::type ()
222 {
223         return (channel_combo.get_active_text() == _("MIDI"))
224                         ? ARDOUR::DataType::MIDI
225                         : ARDOUR::DataType::AUDIO;
226 }
227
228 string
229 AddRouteDialog::name_template ()
230 {
231         return name_template_entry.get_text ();
232 }
233
234 int
235 AddRouteDialog::count ()
236 {
237         return (int) floor (routes_adjustment.get_value ());
238 }
239
240 ARDOUR::TrackMode
241 AddRouteDialog::mode ()
242 {
243         if (ARDOUR::Profile->get_sae()) {
244                 return ARDOUR::Normal;
245         }
246
247         Glib::ustring str = mode_combo.get_active_text();
248         if (str == _("Normal")) {
249                 return ARDOUR::Normal;
250         } else if (str == _("Non Layered")){
251                 return ARDOUR::NonLayered;
252         } else if (str == _("Tape")) {
253                 return ARDOUR::Destructive;
254         } else {
255                 fatal << string_compose (X_("programming error: unknown track mode in add route dialog combo = %1"), str)
256                       << endmsg;
257                 /*NOTREACHED*/
258         }
259         /* keep gcc happy */
260         return ARDOUR::Normal;
261 }
262
263 int
264 AddRouteDialog::channels ()
265 {
266         string str = channel_combo.get_active_text();
267
268         for (ChannelSetups::iterator i = channel_setups.begin(); i != channel_setups.end(); ++i) {
269                 if (str == (*i).name) {
270                         return (*i).channels;
271                 }
272         }
273
274         return 0;
275 }
276
277 string
278 AddRouteDialog::track_template ()
279 {
280         string str = channel_combo.get_active_text();
281
282         for (ChannelSetups::iterator i = channel_setups.begin(); i != channel_setups.end(); ++i) {
283                 if (str == (*i).name) {
284                         return (*i).template_path;
285                 }
286         }
287
288         return string();
289 }
290
291 void
292 AddRouteDialog::on_show ()
293 {
294         refill_channel_setups ();
295         refill_route_groups ();
296
297         Dialog::on_show ();
298 }
299
300 void
301 AddRouteDialog::refill_channel_setups ()
302 {
303         ChannelSetup chn;
304
305         route_templates.clear ();
306         channel_combo_strings.clear ();
307         channel_setups.clear ();
308
309         chn.name = _("Mono");
310         chn.channels = 1;
311         channel_setups.push_back (chn);
312
313         chn.name = _("Stereo");
314         chn.channels = 2;
315         channel_setups.push_back (chn);
316
317         chn.name = "separator";
318         channel_setups.push_back (chn);
319
320         chn.name = X_("MIDI");
321         chn.channels = 0;
322         channel_setups.push_back (chn);
323
324         chn.name = "separator";
325         channel_setups.push_back (chn);
326
327         ARDOUR::find_route_templates (route_templates);
328
329         if (!ARDOUR::Profile->get_sae()) {
330                 if (!route_templates.empty()) {
331                         vector<string> v;
332                         for (vector<TemplateInfo>::iterator x = route_templates.begin(); x != route_templates.end(); ++x) {
333                                 chn.name = x->name;
334                                 chn.channels = 0;
335                                 chn.template_path = x->path;
336                                 channel_setups.push_back (chn);
337                         }
338                 }
339
340                 /* clear template path for the rest */
341
342                 chn.template_path = "";
343
344                 chn.name = _("3 Channel");
345                 chn.channels = 3;
346                 channel_setups.push_back (chn);
347
348                 chn.name = _("4 Channel");
349                 chn.channels = 4;
350                 channel_setups.push_back (chn);
351
352                 chn.name = _("5 Channel");
353                 chn.channels = 5;
354                 channel_setups.push_back (chn);
355
356                 chn.name = _("6 Channel");
357                 chn.channels = 6;
358                 channel_setups.push_back (chn);
359
360                 chn.name = _("8 Channel");
361                 chn.channels = 8;
362                 channel_setups.push_back (chn);
363
364                 chn.name = _("12 Channel");
365                 chn.channels = 12;
366                 channel_setups.push_back (chn);
367
368                 chn.name = X_("Custom");
369                 chn.channels = 0;
370                 channel_setups.push_back (chn);
371         }
372
373         for (ChannelSetups::iterator i = channel_setups.begin(); i != channel_setups.end(); ++i) {
374                 channel_combo_strings.push_back ((*i).name);
375         }
376
377         set_popdown_strings (channel_combo, channel_combo_strings, true);
378         channel_combo.set_active_text (channel_combo_strings.front());
379 }
380
381 void
382 AddRouteDialog::add_route_group (RouteGroup* g)
383 {
384         route_group_combo.insert_text (3, g->name ());
385 }
386
387 RouteGroup*
388 AddRouteDialog::route_group ()
389 {
390         if (route_group_combo.get_active_row_number () == 2) {
391                 return 0;
392         }
393
394         return _session.route_group_by_name (route_group_combo.get_active_text());
395 }
396
397 void
398 AddRouteDialog::refill_route_groups ()
399 {
400         route_group_combo.clear ();
401         route_group_combo.append_text (_("New group..."));
402
403         route_group_combo.append_text ("separator");
404
405         route_group_combo.append_text (_("No group"));
406
407         _session.foreach_route_group (sigc::mem_fun (*this, &AddRouteDialog::add_route_group));
408
409         route_group_combo.set_active (2);
410 }
411
412 void
413 AddRouteDialog::group_changed ()
414 {
415         if (route_group_combo.get_active_text () == _("New group...")) {
416                 RouteGroup* g = new RouteGroup (_session, "", RouteGroup::Active);
417
418                 RouteGroupDialog d (g, Gtk::Stock::NEW);
419                 int const r = d.do_run ();
420
421                 if (r == Gtk::RESPONSE_OK) {
422                         _session.add_route_group (g);
423                         add_route_group (g);
424                         route_group_combo.set_active (3);
425                 } else {
426                         delete g;
427
428                         route_group_combo.set_active (2);
429                 }
430         }
431 }
432
433 bool
434 AddRouteDialog::channel_separator (const Glib::RefPtr<Gtk::TreeModel> &, const Gtk::TreeModel::iterator &i)
435 {
436         channel_combo.set_active (i);
437
438         return channel_combo.get_active_text () == "separator";
439 }
440
441 bool
442 AddRouteDialog::route_separator (const Glib::RefPtr<Gtk::TreeModel> &, const Gtk::TreeModel::iterator &i)
443 {
444         route_group_combo.set_active (i);
445
446         return route_group_combo.get_active_text () == "separator";
447 }
448