85408ca692f38eeb0253571bdc9cf672e0c74b7b
[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     $Id$
19 */
20
21 #include <cstdio>
22 #include <cmath>
23
24 #include <sigc++/bind.h>
25 #include <gtkmm/stock.h>
26 #include <pbd/error.h>
27 #include <gtkmm2ext/utils.h>
28
29 #include "utils.h"
30 #include "add_route_dialog.h"
31 #include "i18n.h"
32
33 using namespace Gtk;
34 using namespace Gtkmm2ext;
35 using namespace sigc;
36 using namespace std;
37
38 static const char* channel_setup_names[] = {
39         "mono",
40         "stereo",
41         "3 channels",
42         "4 channels",
43         "5 channels",
44         "8 channels",
45         "manual setup",
46         0
47 };
48
49 static const char* track_mode_names[] = {
50         "normal",
51         "tape",
52         0
53 };
54
55 static vector<string> channel_combo_strings;
56 static vector<string> track_mode_strings;
57
58
59 AddRouteDialog::AddRouteDialog ()
60         : Dialog (_("ardour: add track/bus")),
61           track_button (_("Tracks")),
62           bus_button (_("Busses")),
63           routes_adjustment (1, 1, 32, 1, 4),
64           routes_spinner (routes_adjustment)
65 {
66         if (channel_combo_strings.empty()) {
67                 channel_combo_strings = internationalize (channel_setup_names);
68         }
69
70         if (track_mode_strings.empty()) {
71                 track_mode_strings = internationalize (track_mode_names);
72         }
73
74
75         set_name ("AddRouteDialog");
76         set_wmclass (X_("ardour_add_track_bus"), "Ardour");
77         set_position (Gtk::WIN_POS_MOUSE);
78
79         name_template_entry.set_name ("AddRouteDialogNameTemplateEntry");
80         track_button.set_name ("AddRouteDialogRadioButton");
81         bus_button.set_name ("AddRouteDialogRadioButton");
82         routes_spinner.set_name ("AddRouteDialogSpinner");
83         
84         RadioButton::Group g = track_button.get_group();
85         bus_button.set_group (g);
86         track_button.set_active (true);
87
88         HBox *hbrb = manage (new HBox);
89
90         hbrb->set_spacing (6);
91         hbrb->pack_start (*(manage (new Label (_("Add")))), false, false);
92         hbrb->pack_start (routes_spinner, false, false);
93         hbrb->pack_start (track_button, false, false);
94         hbrb->pack_start (bus_button, false, false);
95
96         set_popdown_strings (channel_combo, channel_combo_strings);
97         set_popdown_strings (track_mode_combo, track_mode_strings);
98         channel_combo.set_active_text (channel_combo_strings.front());
99         channel_combo.set_name (X_("ChannelCountSelector"));
100
101         track_button.signal_clicked().connect (mem_fun (*this, &AddRouteDialog::track_type_chosen));
102         bus_button.signal_clicked().connect (mem_fun (*this, &AddRouteDialog::track_type_chosen));
103
104         track_mode_combo.set_active_text (track_mode_strings.front());
105         track_mode_combo.set_name (X_("ChannelCountSelector"));
106         
107 #if NOT_USEFUL_YET
108         HBox *hbnt = manage (new HBox);
109
110         hbnt->pack_start (*(manage (new Label (_("Name (template)")))), false, false);
111         hbnt->pack_start (name_template_entry, true, true);
112 #endif
113
114         get_vbox()->pack_start (*hbrb, false, false);
115         get_vbox()->pack_start (*(manage (new Label ("Channel configuration"))), false, false);
116         get_vbox()->pack_start (channel_combo, false, false);
117         get_vbox()->pack_start (track_mode_combo, false, false, 10);
118 #if NOT_USEFUL_YET
119         get_vbox()->pack_start (*hbnt, false, false);
120 #endif
121
122         get_vbox()->show_all ();
123
124         add_button (Stock::OK, RESPONSE_ACCEPT);
125         add_button (Stock::CANCEL, RESPONSE_CANCEL);
126 }
127
128 AddRouteDialog::~AddRouteDialog ()
129 {
130 }
131
132 void
133 AddRouteDialog::track_type_chosen ()
134 {
135         if (track_button.get_active()) {
136                 track_mode_combo.set_sensitive (true);
137         } else {
138                 track_mode_combo.set_sensitive (true);
139         }
140 }
141
142 bool
143 AddRouteDialog::track ()
144 {
145         return track_button.get_active ();
146 }
147
148 string
149 AddRouteDialog::name_template ()
150 {
151         return name_template_entry.get_text ();
152 }
153
154 int
155 AddRouteDialog::count ()
156 {
157         return (int) floor (routes_adjustment.get_value ());
158 }
159
160 ARDOUR::TrackMode
161 AddRouteDialog::mode ()
162 {
163         Glib::ustring str = track_mode_combo.get_active_text();
164         if (str == _("normal")) {
165                 return ARDOUR::Normal;
166         } else if (str == _("tape")) {
167                 return ARDOUR::Destructive;
168         } else {
169                 fatal << string_compose (X_("programming error: unknown track mode in add route dialog combo = %1"), str)
170                       << endmsg;
171                 /*NOTREACHED*/
172         }
173         /* keep gcc happy */
174         return ARDOUR::Normal;
175 }
176
177 int
178 AddRouteDialog::channels ()
179 {
180         string str = channel_combo.get_active_text();
181         int chns;
182
183         if (str == _("mono")) {
184                 return 1;
185         } else if (str == _("stereo")) {
186                 return 2;
187         } else if ((chns = atoi (str)) != 0) {
188                 return chns;
189         } else {
190                 return 0;
191         }
192 }
193