Merged with trunk R1141
[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 <pbd/convert.h>
28 #include <gtkmm2ext/utils.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
73         if (track_mode_strings.empty()) {
74                 track_mode_strings = I18N (track_mode_names);
75         }
76
77         set_name ("AddRouteDialog");
78         set_wmclass (X_("ardour_add_track_bus"), "Ardour");
79         set_position (Gtk::WIN_POS_MOUSE);
80
81         name_template_entry.set_name ("AddRouteDialogNameTemplateEntry");
82         track_button.set_name ("AddRouteDialogRadioButton");
83         bus_button.set_name ("AddRouteDialogRadioButton");
84         routes_spinner.set_name ("AddRouteDialogSpinner");
85         
86         RadioButton::Group g = track_button.get_group();
87         bus_button.set_group (g);
88         track_button.set_active (true);
89
90         HBox *hbrb = manage (new HBox);
91
92         hbrb->set_spacing (6);
93         hbrb->pack_start (routes_spinner, true, false, 5);
94         hbrb->pack_start (track_button, true, false, 5);
95         hbrb->pack_start (bus_button, true, false, 5);
96
97         aframe.set_label (_("Add"));
98         aframe.set_shadow_type (SHADOW_IN);
99         aframe.add (*hbrb);
100
101         set_popdown_strings (channel_combo, channel_combo_strings);
102         set_popdown_strings (track_mode_combo, track_mode_strings);
103         channel_combo.set_active_text (channel_combo_strings.front());
104         channel_combo.set_name (X_("ChannelCountSelector"));
105
106         track_button.signal_clicked().connect (mem_fun (*this, &AddRouteDialog::track_type_chosen));
107         bus_button.signal_clicked().connect (mem_fun (*this, &AddRouteDialog::track_type_chosen));
108
109         track_mode_combo.set_active_text (track_mode_strings.front());
110         track_mode_combo.set_name (X_("ChannelCountSelector"));
111         
112 #if NOT_USEFUL_YET
113         HBox *hbnt = manage (new HBox);
114
115         hbnt->pack_start (*(manage (new Label (_("Name (template)")))), false, false);
116         hbnt->pack_start (name_template_entry, true, true);
117 #endif
118         VBox *dvbox = manage (new VBox);
119         HBox *dhbox = manage (new HBox);
120
121         ccframe.set_label (_("Channel Configuration"));
122         ccframe.set_shadow_type (SHADOW_IN);
123
124         dvbox->pack_start (channel_combo, true, false, 5);
125         dvbox->pack_start (track_mode_combo, true, false, 5);
126         dhbox->pack_start (*dvbox, true, false, 5);
127
128         ccframe.add (*dhbox);
129
130         get_vbox()->pack_start (aframe, true, false, 10);
131         get_vbox()->pack_start (ccframe, true, false);
132 #if NOT_USEFUL_YET
133         get_vbox()->pack_start (*hbnt, false, false);
134 #endif
135
136         get_vbox()->show_all ();
137
138         add_button (Stock::CANCEL, RESPONSE_CANCEL);
139         add_button (Stock::ADD, RESPONSE_ACCEPT);
140 }
141
142 AddRouteDialog::~AddRouteDialog ()
143 {
144 }
145
146 void
147 AddRouteDialog::track_type_chosen ()
148 {
149         if (track_button.get_active()) {
150                 track_mode_combo.set_sensitive (true);
151         } else {
152                 track_mode_combo.set_sensitive (true);
153         }
154 }
155
156 bool
157 AddRouteDialog::track ()
158 {
159         return track_button.get_active ();
160 }
161
162 ARDOUR::DataType
163 AddRouteDialog::type ()
164 {
165         // FIXME: ew
166         
167         const string str = channel_combo.get_active_text();
168         if (str == _("MIDI"))
169                 return ARDOUR::DataType::MIDI;
170         else
171                 return ARDOUR::DataType::AUDIO;
172 }
173
174 string
175 AddRouteDialog::name_template ()
176 {
177         return name_template_entry.get_text ();
178 }
179
180 int
181 AddRouteDialog::count ()
182 {
183         return (int) floor (routes_adjustment.get_value ());
184 }
185
186 ARDOUR::TrackMode
187 AddRouteDialog::mode ()
188 {
189         Glib::ustring str = track_mode_combo.get_active_text();
190         if (str == _("Normal")) {
191                 return ARDOUR::Normal;
192         } else if (str == _("Tape")) {
193                 return ARDOUR::Destructive;
194         } else {
195                 fatal << string_compose (X_("programming error: unknown track mode in add route dialog combo = %1"), str)
196                       << endmsg;
197                 /*NOTREACHED*/
198         }
199         /* keep gcc happy */
200         return ARDOUR::Normal;
201 }
202
203 int
204 AddRouteDialog::channels ()
205 {
206         string str = channel_combo.get_active_text();
207         int chns;
208
209         if (str == _("Mono") || str == _("MIDI")) {
210                 return 1;
211         } else if (str == _("Stereo")) {
212                 return 2;
213         } else if ((chns = PBD::atoi (str)) != 0) {
214                 return chns;
215         } 
216
217         return 0;
218 }
219