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