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