All included libraries now link dynamically instead of statically.
[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
39 static const char* channel_setup_names[] = {
40         "Mono",
41         "Stereo",
42         "3 Channels",
43         "4 Channels",
44         "6 Channels",
45         "8 Channels",
46         "Manual Setup",
47         0
48 };
49
50 static const char* track_mode_names[] = {
51         "Normal",
52         "Tape",
53         0
54 };
55
56 static vector<string> channel_combo_strings;
57 static vector<string> track_mode_strings;
58
59
60 AddRouteDialog::AddRouteDialog ()
61         : Dialog (_("ardour: add track/bus")),
62           track_button (_("Tracks")),
63           bus_button (_("Busses")),
64           routes_adjustment (1, 1, 32, 1, 4),
65           routes_spinner (routes_adjustment)
66 {
67         if (channel_combo_strings.empty()) {
68                 channel_combo_strings = PBD::internationalize (channel_setup_names);
69         }
70
71         if (track_mode_strings.empty()) {
72                 track_mode_strings = PBD::internationalize (track_mode_names);
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 (routes_spinner, true, false, 5);
92         hbrb->pack_start (track_button, true, false, 5);
93         hbrb->pack_start (bus_button, true, false, 5);
94
95         aframe.set_label (_("Add"));
96         aframe.set_shadow_type (SHADOW_IN);
97         aframe.add (*hbrb);
98
99         set_popdown_strings (channel_combo, channel_combo_strings);
100         set_popdown_strings (track_mode_combo, track_mode_strings);
101         channel_combo.set_active_text (channel_combo_strings.front());
102         channel_combo.set_name (X_("ChannelCountSelector"));
103
104         track_button.signal_clicked().connect (mem_fun (*this, &AddRouteDialog::track_type_chosen));
105         bus_button.signal_clicked().connect (mem_fun (*this, &AddRouteDialog::track_type_chosen));
106
107         track_mode_combo.set_active_text (track_mode_strings.front());
108         track_mode_combo.set_name (X_("ChannelCountSelector"));
109         
110 #if NOT_USEFUL_YET
111         HBox *hbnt = manage (new HBox);
112
113         hbnt->pack_start (*(manage (new Label (_("Name (template)")))), false, false);
114         hbnt->pack_start (name_template_entry, true, true);
115 #endif
116         VBox *dvbox = manage (new VBox);
117         HBox *dhbox = manage (new HBox);
118
119         ccframe.set_label (_("Channel Configuration"));
120         ccframe.set_shadow_type (SHADOW_IN);
121
122         dvbox->pack_start (channel_combo, true, false, 5);
123         dvbox->pack_start (track_mode_combo, true, false, 5);
124         dhbox->pack_start (*dvbox, true, false, 5);
125
126         ccframe.add (*dhbox);
127
128         get_vbox()->pack_start (aframe, true, false, 10);
129         get_vbox()->pack_start (ccframe, true, false);
130 #if NOT_USEFUL_YET
131         get_vbox()->pack_start (*hbnt, false, false);
132 #endif
133
134         get_vbox()->show_all ();
135
136         add_button (Stock::CANCEL, RESPONSE_CANCEL);
137         add_button (Stock::ADD, RESPONSE_ACCEPT);
138 }
139
140 AddRouteDialog::~AddRouteDialog ()
141 {
142 }
143
144 void
145 AddRouteDialog::track_type_chosen ()
146 {
147         if (track_button.get_active()) {
148                 track_mode_combo.set_sensitive (true);
149         } else {
150                 track_mode_combo.set_sensitive (true);
151         }
152 }
153
154 bool
155 AddRouteDialog::track ()
156 {
157         return track_button.get_active ();
158 }
159
160 string
161 AddRouteDialog::name_template ()
162 {
163         return name_template_entry.get_text ();
164 }
165
166 int
167 AddRouteDialog::count ()
168 {
169         return (int) floor (routes_adjustment.get_value ());
170 }
171
172 ARDOUR::TrackMode
173 AddRouteDialog::mode ()
174 {
175         Glib::ustring str = track_mode_combo.get_active_text();
176         if (str == _("Normal")) {
177                 return ARDOUR::Normal;
178         } else if (str == _("Tape")) {
179                 return ARDOUR::Destructive;
180         } else {
181                 fatal << string_compose (X_("programming error: unknown track mode in add route dialog combo = %1"), str)
182                       << endmsg;
183                 /*NOTREACHED*/
184         }
185         /* keep gcc happy */
186         return ARDOUR::Normal;
187 }
188
189 int
190 AddRouteDialog::channels ()
191 {
192         string str = channel_combo.get_active_text();
193         int chns;
194
195         if (str == _("Mono")) {
196                 return 1;
197         } else if (str == _("Stereo")) {
198                 return 2;
199         } else if ((chns = PBD::atoi (str)) != 0) {
200                 return chns;
201         } 
202
203         return 0;
204 }
205