Copy local state in AudioRegionView copy constructor. Fixes #4047.
[ardour2.git] / gtk2_ardour / add_route_dialog.cc
blob29ae5cb3f399d85c60d8080117428f7776a2ea18
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 std::vector<std::string> AddRouteDialog::channel_combo_strings;
55 std::vector<std::string> AddRouteDialog::track_mode_strings;
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:"))
63 set_session (s);
65 if (track_mode_strings.empty()) {
66 track_mode_strings = I18N (track_mode_names);
68 if (ARDOUR::Profile->get_sae()) {
69 /* remove all but the first track mode (Normal) */
71 while (track_mode_strings.size() > 1) {
72 track_mode_strings.pop_back();
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);
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"));
88 refill_channel_setups ();
89 refill_route_groups ();
90 set_popdown_strings (mode_combo, track_mode_strings, true);
92 channel_combo.set_active_text (channel_combo_strings.front());
93 mode_combo.set_active_text (track_mode_strings.front());
95 track_bus_combo.append_text (_("tracks"));
96 track_bus_combo.append_text (_("busses"));
97 track_bus_combo.set_active (0);
99 VBox* vbox = manage (new VBox);
100 Gtk::Label* l;
102 get_vbox()->set_spacing (4);
104 vbox->set_spacing (18);
105 vbox->set_border_width (5);
107 HBox *type_hbox = manage (new HBox);
108 type_hbox->set_spacing (6);
110 /* track/bus choice */
112 type_hbox->pack_start (*manage (new Label (_("Add:"))));
113 type_hbox->pack_start (routes_spinner);
114 type_hbox->pack_start (track_bus_combo);
116 vbox->pack_start (*type_hbox, false, true);
118 VBox* options_box = manage (new VBox);
119 Table *table2 = manage (new Table (3, 3, false));
121 options_box->set_spacing (6);
122 table2->set_row_spacings (6);
123 table2->set_col_spacing (1, 6);
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);
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);
133 int n = 0;
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;
140 /* Route configuration */
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;
147 if (!ARDOUR::Profile->get_sae ()) {
149 /* Track mode */
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;
158 /* Group choice */
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;
165 options_box->pack_start (*table2, false, true);
166 vbox->pack_start (*options_box, false, true);
168 get_vbox()->pack_start (*vbox, false, false);
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));
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::maybe_update_name_template_entry ()
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;
203 if (track ()) {
204 if (type () == DataType::MIDI) {
205 name_template_entry.set_text (_("MIDI"));
206 } else {
207 name_template_entry.set_text (_("Audio"));
209 } else {
210 name_template_entry.set_text (_("Bus"));
214 void
215 AddRouteDialog::track_type_chosen ()
217 mode_combo.set_sensitive (track ());
218 maybe_update_name_template_entry ();
221 bool
222 AddRouteDialog::track ()
224 return track_bus_combo.get_active_row_number () == 0;
227 ARDOUR::DataType
228 AddRouteDialog::type ()
230 return (channel_combo.get_active_text() == _("MIDI"))
231 ? ARDOUR::DataType::MIDI
232 : ARDOUR::DataType::AUDIO;
235 string
236 AddRouteDialog::name_template ()
238 return name_template_entry.get_text ();
242 AddRouteDialog::count ()
244 return (int) floor (routes_adjustment.get_value ());
247 ARDOUR::TrackMode
248 AddRouteDialog::mode ()
250 if (ARDOUR::Profile->get_sae()) {
251 return ARDOUR::Normal;
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*/
266 /* keep gcc happy */
267 return ARDOUR::Normal;
271 AddRouteDialog::channels ()
273 string str = channel_combo.get_active_text();
275 for (ChannelSetups::iterator i = channel_setups.begin(); i != channel_setups.end(); ++i) {
276 if (str == (*i).name) {
277 return (*i).channels;
281 return 0;
284 string
285 AddRouteDialog::track_template ()
287 string str = channel_combo.get_active_text();
289 for (ChannelSetups::iterator i = channel_setups.begin(); i != channel_setups.end(); ++i) {
290 if (str == (*i).name) {
291 return (*i).template_path;
295 return string();
298 void
299 AddRouteDialog::on_show ()
301 refill_channel_setups ();
302 refill_route_groups ();
304 Dialog::on_show ();
307 void
308 AddRouteDialog::refill_channel_setups ()
310 ChannelSetup chn;
312 route_templates.clear ();
313 channel_combo_strings.clear ();
314 channel_setups.clear ();
316 chn.name = _("Mono");
317 chn.channels = 1;
318 channel_setups.push_back (chn);
320 chn.name = _("Stereo");
321 chn.channels = 2;
322 channel_setups.push_back (chn);
324 chn.name = "separator";
325 channel_setups.push_back (chn);
327 chn.name = _("MIDI");
328 chn.channels = 0;
329 channel_setups.push_back (chn);
331 chn.name = "separator";
332 channel_setups.push_back (chn);
334 ARDOUR::find_route_templates (route_templates);
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);
347 /* clear template path for the rest */
349 chn.template_path = "";
351 chn.name = _("3 Channel");
352 chn.channels = 3;
353 channel_setups.push_back (chn);
355 chn.name = _("4 Channel");
356 chn.channels = 4;
357 channel_setups.push_back (chn);
359 chn.name = _("5 Channel");
360 chn.channels = 5;
361 channel_setups.push_back (chn);
363 chn.name = _("6 Channel");
364 chn.channels = 6;
365 channel_setups.push_back (chn);
367 chn.name = _("8 Channel");
368 chn.channels = 8;
369 channel_setups.push_back (chn);
371 chn.name = _("12 Channel");
372 chn.channels = 12;
373 channel_setups.push_back (chn);
375 chn.name = _("Custom");
376 chn.channels = 0;
377 channel_setups.push_back (chn);
380 for (ChannelSetups::iterator i = channel_setups.begin(); i != channel_setups.end(); ++i) {
381 channel_combo_strings.push_back ((*i).name);
384 set_popdown_strings (channel_combo, channel_combo_strings, true);
385 channel_combo.set_active_text (channel_combo_strings.front());
388 void
389 AddRouteDialog::add_route_group (RouteGroup* g)
391 route_group_combo.insert_text (3, g->name ());
394 RouteGroup*
395 AddRouteDialog::route_group ()
397 if (route_group_combo.get_active_row_number () == 2) {
398 return 0;
401 return _session->route_group_by_name (route_group_combo.get_active_text());
404 void
405 AddRouteDialog::refill_route_groups ()
407 route_group_combo.clear ();
408 route_group_combo.append_text (_("New Group..."));
410 route_group_combo.append_text ("separator");
412 route_group_combo.append_text (_("No Group"));
414 _session->foreach_route_group (sigc::mem_fun (*this, &AddRouteDialog::add_route_group));
416 route_group_combo.set_active (2);
419 void
420 AddRouteDialog::group_changed ()
422 if (_session && route_group_combo.get_active_text () == _("New Group...")) {
423 RouteGroup* g = new RouteGroup (*_session, "");
425 PropertyList plist;
426 plist.add (Properties::active, true);
427 g->apply_changes (plist);
429 RouteGroupDialog d (g, true);
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);
442 bool
443 AddRouteDialog::channel_separator (const Glib::RefPtr<Gtk::TreeModel> &, const Gtk::TreeModel::iterator &i)
445 channel_combo.set_active (i);
447 return channel_combo.get_active_text () == "separator";
450 bool
451 AddRouteDialog::route_separator (const Glib::RefPtr<Gtk::TreeModel> &, const Gtk::TreeModel::iterator &i)
453 route_group_combo.set_active (i);
455 return route_group_combo.get_active_text () == "separator";