Merge libs/ardour and gtk2_ardour with 2.0-ongoing R2837.
[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 <pbd/error.h>
26 #include <pbd/convert.h>
27 #include <gtkmm2ext/utils.h>
28 #include <ardour/profile.h>
29
30 #include "utils.h"
31 #include "add_route_dialog.h"
32 #include "i18n.h"
33
34 using namespace Gtk;
35 using namespace Gtkmm2ext;
36 using namespace sigc;
37 using namespace std;
38 using namespace PBD;
39
40 static const char* channel_setup_names[] = {
41         N_("Mono"),
42         N_("Stereo"),
43         N_("3 Channels"),
44         N_("4 Channels"),
45         N_("6 Channels"),
46         N_("8 Channels"),
47         N_("Manual Setup"),
48         "MIDI",
49         0
50 };
51
52 static const char* track_mode_names[] = {
53         N_("Normal"),
54         N_("Tape"),
55         0
56 };
57
58 static vector<string> channel_combo_strings;
59 static vector<string> track_mode_strings;
60
61
62 AddRouteDialog::AddRouteDialog ()
63         : Dialog (_("ardour: add track/bus")),
64           track_button (_("Tracks")),
65           bus_button (_("Busses")),
66           routes_adjustment (1, 1, 128, 1, 4),
67           routes_spinner (routes_adjustment)
68 {
69         if (channel_combo_strings.empty()) {
70                 channel_combo_strings = I18N (channel_setup_names);
71
72                 if (ARDOUR::Profile->get_sae()) {
73                         /* remove all but the first two (Mono & Stereo) */
74
75                         while (track_mode_strings.size() > 2) {
76                                 track_mode_strings.pop_back();
77                         }
78                 }
79
80         }
81
82         if (track_mode_strings.empty()) {
83                 track_mode_strings = I18N (track_mode_names);
84
85                 if (ARDOUR::Profile->get_sae()) {
86                         /* remove all but the first track mode (Normal) */
87
88                         while (track_mode_strings.size() > 1) {
89                                 track_mode_strings.pop_back();
90                         }
91                 }
92         }
93
94         set_name ("AddRouteDialog");
95         set_wmclass (X_("ardour_add_track_bus"), "Ardour");
96         set_position (Gtk::WIN_POS_MOUSE);
97
98         name_template_entry.set_name ("AddRouteDialogNameTemplateEntry");
99         track_button.set_name ("AddRouteDialogRadioButton");
100         bus_button.set_name ("AddRouteDialogRadioButton");
101         routes_spinner.set_name ("AddRouteDialogSpinner");
102         
103         RadioButton::Group g = track_button.get_group();
104         bus_button.set_group (g);
105         track_button.set_active (true);
106
107         HBox *hbrb = manage (new HBox);
108
109         hbrb->set_spacing (6);
110         hbrb->pack_start (routes_spinner, true, false, 5);
111         hbrb->pack_start (track_button, true, false, 5);
112         hbrb->pack_start (bus_button, true, false, 5);
113
114         aframe.set_label (_("Add"));
115         aframe.set_shadow_type (SHADOW_IN);
116         aframe.add (*hbrb);
117
118         set_popdown_strings (channel_combo, channel_combo_strings);
119         set_popdown_strings (track_mode_combo, track_mode_strings);
120         channel_combo.set_active_text (channel_combo_strings.front());
121         channel_combo.set_name (X_("ChannelCountSelector"));
122
123         track_button.signal_clicked().connect (mem_fun (*this, &AddRouteDialog::track_type_chosen));
124         bus_button.signal_clicked().connect (mem_fun (*this, &AddRouteDialog::track_type_chosen));
125
126         track_mode_combo.set_active_text (track_mode_strings.front());
127         track_mode_combo.set_name (X_("ChannelCountSelector"));
128         
129 #if NOT_USEFUL_YET
130         HBox *hbnt = manage (new HBox);
131
132         hbnt->pack_start (*(manage (new Label (_("Name (template)")))), false, false);
133         hbnt->pack_start (name_template_entry, true, true);
134 #endif
135         VBox *dvbox = manage (new VBox);
136         HBox *dhbox = manage (new HBox);
137
138         ccframe.set_label (_("Channel Configuration"));
139         ccframe.set_shadow_type (SHADOW_IN);
140
141         dvbox->pack_start (channel_combo, true, false, 5);
142         if (!ARDOUR::Profile->get_sae()) {
143                 dvbox->pack_start (track_mode_combo, true, false, 5);
144         }
145         dhbox->pack_start (*dvbox, true, false, 5);
146
147         ccframe.add (*dhbox);
148
149         get_vbox()->pack_start (aframe, true, false, 10);
150         get_vbox()->pack_start (ccframe, true, false);
151 #if NOT_USEFUL_YET
152         get_vbox()->pack_start (*hbnt, false, false);
153 #endif
154
155         add_button (Stock::CANCEL, RESPONSE_CANCEL);
156         add_button (Stock::ADD, RESPONSE_ACCEPT);
157
158         name_template_entry.show();
159         track_button.show();
160         bus_button.show();
161         routes_spinner.show();
162         channel_combo.show();
163         track_mode_combo.show();
164         aframe.show();
165         ccframe.show();
166
167         hbrb->show();
168         dvbox->show();
169         dhbox->show();
170
171         //get_vbox()->show();  why isnt this needed?
172 }
173
174 AddRouteDialog::~AddRouteDialog ()
175 {
176 }
177
178 void
179 AddRouteDialog::track_type_chosen ()
180 {
181         if (track_button.get_active()) {
182                 track_mode_combo.set_sensitive (true);
183         } else {
184                 track_mode_combo.set_sensitive (false);
185         }
186 }
187
188 bool
189 AddRouteDialog::track ()
190 {
191         return track_button.get_active ();
192 }
193
194 ARDOUR::DataType
195 AddRouteDialog::type ()
196 {
197         // FIXME: ew
198         
199         const string str = channel_combo.get_active_text();
200         if (str == _("MIDI"))
201                 return ARDOUR::DataType::MIDI;
202         else
203                 return ARDOUR::DataType::AUDIO;
204 }
205
206 string
207 AddRouteDialog::name_template ()
208 {
209         return name_template_entry.get_text ();
210 }
211
212 int
213 AddRouteDialog::count ()
214 {
215         return (int) floor (routes_adjustment.get_value ());
216 }
217
218 ARDOUR::TrackMode
219 AddRouteDialog::mode ()
220 {
221         if (ARDOUR::Profile->get_sae()) {
222                 return ARDOUR::Normal;
223         }
224
225         Glib::ustring str = track_mode_combo.get_active_text();
226         if (str == _("Normal")) {
227                 return ARDOUR::Normal;
228         } else if (str == _("Tape")) {
229                 return ARDOUR::Destructive;
230         } else {
231                 fatal << string_compose (X_("programming error: unknown track mode in add route dialog combo = %1"), str)
232                       << endmsg;
233                 /*NOTREACHED*/
234         }
235         /* keep gcc happy */
236         return ARDOUR::Normal;
237 }
238
239 int
240 AddRouteDialog::channels ()
241 {
242         string str = channel_combo.get_active_text();
243         int chns;
244
245         if (str == _("Mono") || str == _("MIDI")) {
246                 return 1;
247         } else if (str == _("Stereo")) {
248                 return 2;
249         } else if ((chns = PBD::atoi (str)) != 0) {
250                 return chns;
251         } 
252
253         return 0;
254 }
255