fix up file renaming code a little bit
[ArdourMidi.git] / gtk2_ardour / add_route_dialog.cc
blobe7ae4454aa2bfae89ff31c406e7e320bb831c011
1 /*
2 Copyright (C) 2003 Paul Davis
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.
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.
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.
20 #include <cstdio>
21 #include <cmath>
23 #include <sigc++/bind.h>
24 #include <gtkmm/stock.h>
25 #include <gtkmm/separator.h>
26 #include <gtkmm/table.h>
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"
36 #include "utils.h"
37 #include "add_route_dialog.h"
38 #include "route_group_dialog.h"
39 #include "i18n.h"
41 using namespace Gtk;
42 using namespace Gtkmm2ext;
43 using namespace std;
44 using namespace PBD;
45 using namespace ARDOUR;
47 static const char* track_mode_names[] = {
48 N_("Normal"),
49 N_("Non Layered"),
50 N_("Tape"),
54 static const char* bus_mode_names[] = {
55 N_("Aux"),
56 N_("Direct"),
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;
64 AddRouteDialog::AddRouteDialog (Session* s)
65 : ArdourDialog (_("Add Track or Bus"))
66 , routes_adjustment (1, 1, 128, 1, 4)
67 , routes_spinner (routes_adjustment)
68 , mode_label (_("Track mode:"))
70 set_session (s);
72 if (track_mode_strings.empty()) {
73 track_mode_strings = I18N (track_mode_names);
75 if (ARDOUR::Profile->get_sae()) {
76 /* remove all but the first track mode (Normal) */
78 while (track_mode_strings.size() > 1) {
79 track_mode_strings.pop_back();
84 if (bus_mode_strings.empty()) {
85 bus_mode_strings = I18N (bus_mode_names);
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);
94 name_template_entry.set_name (X_("AddRouteDialogNameTemplateEntry"));
95 routes_spinner.set_name (X_("AddRouteDialogSpinner"));
96 channel_combo.set_name (X_("ChannelCountSelector"));
97 mode_combo.set_name (X_("ChannelCountSelector"));
99 refill_channel_setups ();
100 refill_route_groups ();
101 set_popdown_strings (mode_combo, track_mode_strings, true);
103 channel_combo.set_active_text (channel_combo_strings.front());
104 mode_combo.set_active_text (track_mode_strings.front());
106 track_bus_combo.append_text (_("tracks"));
107 track_bus_combo.append_text (_("busses"));
108 track_bus_combo.set_active (0);
110 VBox* vbox = manage (new VBox);
111 Gtk::Label* l;
113 get_vbox()->set_spacing (4);
115 vbox->set_spacing (18);
116 vbox->set_border_width (5);
118 HBox *type_hbox = manage (new HBox);
119 type_hbox->set_spacing (6);
121 /* track/bus choice */
123 type_hbox->pack_start (*manage (new Label (_("Add:"))));
124 type_hbox->pack_start (routes_spinner);
125 type_hbox->pack_start (track_bus_combo);
127 vbox->pack_start (*type_hbox, false, true);
129 VBox* options_box = manage (new VBox);
130 Table *table2 = manage (new Table (3, 3, false));
132 options_box->set_spacing (6);
133 table2->set_row_spacings (6);
134 table2->set_col_spacing (1, 6);
136 l = manage (new Label (_("<b>Options</b>"), Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, false));
137 l->set_use_markup ();
138 options_box->pack_start (*l, false, true);
140 l = manage (new Label ("", Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, false));
141 l->set_padding (8, 0);
142 table2->attach (*l, 0, 1, 0, 3, Gtk::FILL, Gtk::FILL, 0, 0);
144 /* Route configuration */
146 l = manage (new Label (_("Configuration:"), Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, false));
147 table2->attach (*l, 1, 2, 0, 1, Gtk::FILL, Gtk::EXPAND, 0, 0);
148 table2->attach (channel_combo, 2, 3, 0, 1, Gtk::FILL, Gtk::EXPAND & Gtk::FILL, 0, 0);
150 if (!ARDOUR::Profile->get_sae ()) {
152 /* Track mode */
154 mode_label.set_alignment (Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER);
155 table2->attach (mode_label, 1, 2, 1, 2, Gtk::FILL, Gtk::EXPAND, 0, 0);
156 table2->attach (mode_combo, 2, 3, 1, 2, Gtk::FILL, Gtk::EXPAND & Gtk::FILL, 0, 0);
160 /* Group choise */
162 l = manage (new Label (_("Group:"), Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, false));
163 table2->attach (*l, 1, 2, 2, 3, Gtk::FILL, Gtk::EXPAND, 0, 0);
164 table2->attach (route_group_combo, 2, 3, 2, 3, Gtk::FILL, Gtk::EXPAND & Gtk::FILL, 0, 0);
166 options_box->pack_start (*table2, false, true);
167 vbox->pack_start (*options_box, false, true);
169 get_vbox()->pack_start (*vbox, false, false);
171 track_bus_combo.signal_changed().connect (sigc::mem_fun (*this, &AddRouteDialog::track_type_chosen));
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));
176 show_all_children ();
178 /* track template info will be managed whenever
179 this dialog is shown, via ::on_show()
182 add_button (Stock::CANCEL, RESPONSE_CANCEL);
183 add_button (Stock::ADD, RESPONSE_ACCEPT);
185 track_type_chosen ();
188 AddRouteDialog::~AddRouteDialog ()
192 void
193 AddRouteDialog::track_type_chosen ()
195 if (track()) {
196 mode_label.set_text (_("Track mode:"));
197 set_popdown_strings (mode_combo, track_mode_strings);
198 mode_combo.set_active_text (track_mode_strings.front());
199 } else {
200 mode_label.set_text (_("Bus type:"));
201 set_popdown_strings (mode_combo, bus_mode_strings);
202 mode_combo.set_active_text (bus_mode_strings.front());
207 bool
208 AddRouteDialog::track ()
210 return track_bus_combo.get_active_row_number () == 0;
213 bool
214 AddRouteDialog::aux ()
216 return !track() && mode_combo.get_active_row_number () == 0;
219 ARDOUR::DataType
220 AddRouteDialog::type ()
222 return (channel_combo.get_active_text() == _("MIDI"))
223 ? ARDOUR::DataType::MIDI
224 : ARDOUR::DataType::AUDIO;
227 string
228 AddRouteDialog::name_template ()
230 return name_template_entry.get_text ();
234 AddRouteDialog::count ()
236 return (int) floor (routes_adjustment.get_value ());
239 ARDOUR::TrackMode
240 AddRouteDialog::mode ()
242 if (ARDOUR::Profile->get_sae()) {
243 return ARDOUR::Normal;
246 Glib::ustring str = mode_combo.get_active_text();
247 if (str == _("Normal")) {
248 return ARDOUR::Normal;
249 } else if (str == _("Non Layered")){
250 return ARDOUR::NonLayered;
251 } else if (str == _("Tape")) {
252 return ARDOUR::Destructive;
253 } else {
254 fatal << string_compose (X_("programming error: unknown track mode in add route dialog combo = %1"), str)
255 << endmsg;
256 /*NOTREACHED*/
258 /* keep gcc happy */
259 return ARDOUR::Normal;
263 AddRouteDialog::channels ()
265 string str = channel_combo.get_active_text();
267 for (ChannelSetups::iterator i = channel_setups.begin(); i != channel_setups.end(); ++i) {
268 if (str == (*i).name) {
269 return (*i).channels;
273 return 0;
276 string
277 AddRouteDialog::track_template ()
279 string str = channel_combo.get_active_text();
281 for (ChannelSetups::iterator i = channel_setups.begin(); i != channel_setups.end(); ++i) {
282 if (str == (*i).name) {
283 return (*i).template_path;
287 return string();
290 void
291 AddRouteDialog::on_show ()
293 refill_channel_setups ();
294 refill_route_groups ();
296 Dialog::on_show ();
299 void
300 AddRouteDialog::refill_channel_setups ()
302 ChannelSetup chn;
304 route_templates.clear ();
305 channel_combo_strings.clear ();
306 channel_setups.clear ();
308 chn.name = _("Mono");
309 chn.channels = 1;
310 channel_setups.push_back (chn);
312 chn.name = _("Stereo");
313 chn.channels = 2;
314 channel_setups.push_back (chn);
316 chn.name = "separator";
317 channel_setups.push_back (chn);
319 chn.name = X_("MIDI");
320 chn.channels = 0;
321 channel_setups.push_back (chn);
323 chn.name = "separator";
324 channel_setups.push_back (chn);
326 ARDOUR::find_route_templates (route_templates);
328 if (!ARDOUR::Profile->get_sae()) {
329 if (!route_templates.empty()) {
330 vector<string> v;
331 for (vector<TemplateInfo>::iterator x = route_templates.begin(); x != route_templates.end(); ++x) {
332 chn.name = x->name;
333 chn.channels = 0;
334 chn.template_path = x->path;
335 channel_setups.push_back (chn);
339 /* clear template path for the rest */
341 chn.template_path = "";
343 chn.name = _("3 Channel");
344 chn.channels = 3;
345 channel_setups.push_back (chn);
347 chn.name = _("4 Channel");
348 chn.channels = 4;
349 channel_setups.push_back (chn);
351 chn.name = _("5 Channel");
352 chn.channels = 5;
353 channel_setups.push_back (chn);
355 chn.name = _("6 Channel");
356 chn.channels = 6;
357 channel_setups.push_back (chn);
359 chn.name = _("8 Channel");
360 chn.channels = 8;
361 channel_setups.push_back (chn);
363 chn.name = _("12 Channel");
364 chn.channels = 12;
365 channel_setups.push_back (chn);
367 chn.name = _("Custom");
368 chn.channels = 0;
369 channel_setups.push_back (chn);
372 for (ChannelSetups::iterator i = channel_setups.begin(); i != channel_setups.end(); ++i) {
373 channel_combo_strings.push_back ((*i).name);
376 set_popdown_strings (channel_combo, channel_combo_strings, true);
377 channel_combo.set_active_text (channel_combo_strings.front());
380 void
381 AddRouteDialog::add_route_group (RouteGroup* g)
383 route_group_combo.insert_text (3, g->name ());
386 RouteGroup*
387 AddRouteDialog::route_group ()
389 if (route_group_combo.get_active_row_number () == 2) {
390 return 0;
393 return _session->route_group_by_name (route_group_combo.get_active_text());
396 void
397 AddRouteDialog::refill_route_groups ()
399 route_group_combo.clear ();
400 route_group_combo.append_text (_("New group..."));
402 route_group_combo.append_text ("separator");
404 route_group_combo.append_text (_("No group"));
406 _session->foreach_route_group (sigc::mem_fun (*this, &AddRouteDialog::add_route_group));
408 route_group_combo.set_active (2);
411 void
412 AddRouteDialog::group_changed ()
414 if (_session && route_group_combo.get_active_text () == _("New group...")) {
415 RouteGroup* g = new RouteGroup (*_session, "");
417 PropertyList plist;
418 plist.add (Properties::active, true);
419 g->set_properties (plist);
421 RouteGroupDialog d (g, Gtk::Stock::NEW);
422 int const r = d.do_run ();
424 if (r == Gtk::RESPONSE_OK) {
425 _session->add_route_group (g);
426 add_route_group (g);
427 route_group_combo.set_active (3);
428 } else {
429 delete g;
431 route_group_combo.set_active (2);
436 bool
437 AddRouteDialog::channel_separator (const Glib::RefPtr<Gtk::TreeModel> &, const Gtk::TreeModel::iterator &i)
439 channel_combo.set_active (i);
441 return channel_combo.get_active_text () == "separator";
444 bool
445 AddRouteDialog::route_separator (const Glib::RefPtr<Gtk::TreeModel> &, const Gtk::TreeModel::iterator &i)
447 route_group_combo.set_active (i);
449 return route_group_combo.get_active_text () == "separator";