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