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