Fly my pretties!
[ardour.git] / gtk2_ardour / new_session_dialog.cc
1 /*
2     Copyright (C) 1999-2002 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 <list>
22 #include <string>
23 #include <ardour/session.h>
24 #include <ardour/audioengine.h>
25
26 #include "prompter.h"
27 #include "new_session_dialog.h"
28
29 using namespace Gtkmm2ext;
30 using namespace Gtk;
31 using namespace ARDOUR;
32
33 #include "i18n.h"
34
35 extern std::vector<string> channel_combo_strings;
36
37 NewSessionDialog::NewSessionDialog (ARDOUR::AudioEngine& engine, bool startup, string given_path)
38         : ArdourDialog ("new session dialog"),
39           file_selector (_("Session name:"), _("Create")),
40           use_control_button (_("use control outs")),
41           use_master_button (_("use master outs")),
42           connect_to_physical_inputs_button (_("automatically connect track inputs to physical ports")),
43           connect_to_master_button (_("automatically connect track outputs to master outs")),
44           connect_to_physical_outputs_button (_("automatically connect track outputs to physical ports")),
45           manual_connect_outputs_button (_("manually connect track outputs")),
46           in_count_adjustment (2, 1, 1000, 1, 2),
47           out_count_adjustment (2, 1, 1000, 1, 2),
48           output_label (_("Output Connections")),
49           input_label (_("Input Connections")),
50           expansion_button (_("Advanced...")),
51           out_table (2, 2),
52           show_again (_("show again")),
53           in_count_spinner (in_count_adjustment),
54           out_count_spinner (out_count_adjustment),
55           in_count_label (_("Hardware Inputs: use")),
56           out_count_label (_("Hardware Outputs: use"))
57         
58 {
59         using namespace Notebook_Helpers;
60
61         set_name ("NewSessionDialog");
62         set_title (_("new session setup"));
63         set_wmclass (_("ardour_new_session"), "Ardour");
64         set_position (Gtk::WIN_POS_MOUSE);
65         set_keyboard_input (true);
66         set_policy (false, true, false);
67         set_modal (true);
68
69         /* sample rate */
70
71         sr_label1.set_text (compose 
72                            (_("This session will playback and record at %1 Hz"),
73                             engine.frame_rate()));
74         sr_label2.set_text (_("This rate is set by JACK and cannot be changed.\n"
75                               "If you want to use a different sample rate\n"
76                               "please exit and restart JACK"));
77         sr_box.set_spacing (12);
78         sr_box.set_border_width (12);
79         sr_box.pack_start (sr_label1, false, false);
80         sr_box.pack_start (sr_label2, false, false);
81         sr_frame.add (sr_box);
82
83         /* input */
84
85         connect_to_physical_inputs_button.set_active (true);
86         connect_to_physical_inputs_button.set_name ("NewSessionDialogButton");
87         
88         HBox* input_limit_box = manage (new HBox);
89         input_limit_box->set_spacing (7);
90         input_limit_box->pack_start (in_count_label, false, false);
91         input_limit_box->pack_start (in_count_spinner, false, false);
92
93         input_label.set_alignment (0.1, 0.5);
94         input_vbox.pack_start (input_label, false, false, 7);
95         input_vbox.pack_start (connect_to_physical_inputs_button, false, false);
96
97         if (engine.n_physical_inputs() > 2) {
98                 input_vbox.pack_start (*input_limit_box, false, false);
99         }
100
101         /* output */
102
103         use_master_button.set_active (true);
104         use_master_button.set_name ("NewSessionDialogButton");
105         
106         connect_to_physical_outputs_button.set_group (connect_to_master_button.group());
107         manual_connect_outputs_button.set_group (connect_to_master_button.group());
108         connect_to_master_button.set_active (true);
109         
110         connect_to_physical_outputs_button.set_name ("NewSessionDialogButton");
111         manual_connect_outputs_button.set_name ("NewSessionDialogButton");
112         connect_to_master_button.set_name ("NewSessionDialogButton");
113         use_control_button.set_name ("NewSessionDialogButton");
114         
115         out_count_adjustment.set_value (engine.n_physical_outputs());
116         in_count_adjustment.set_value (engine.n_physical_inputs());
117
118         control_out_channel_combo.set_popdown_strings (channel_combo_strings);
119         control_out_channel_combo.set_name (X_("NewSessionChannelCombo"));
120         control_out_channel_combo.get_entry()->set_name (X_("NewSessionChannelCombo"));
121         control_out_channel_combo.get_popwin()->set_name (X_("NewSessionChannelCombo"));
122         // use stereo as default
123         control_out_channel_combo.get_list()->select_item (1);
124
125         master_out_channel_combo.set_popdown_strings (channel_combo_strings);
126         master_out_channel_combo.set_name (X_("NewSessionChannelCombo"));
127         master_out_channel_combo.get_entry()->set_name (X_("NewSessionChannelCombo"));
128         master_out_channel_combo.get_popwin()->set_name (X_("NewSessionChannelCombo"));
129         // use stereo as default
130         master_out_channel_combo.get_list()->select_item (1);
131
132         
133         out_table.set_col_spacings (7);
134         out_table.set_row_spacings (7);
135         if (engine.n_physical_outputs() > 2) {
136                 out_table.attach (out_count_label, 0, 1, 0, 1, 0, 0);   
137                 out_table.attach (out_count_spinner, 1, 2, 0, 1, 0, 0);
138         }
139         out_table.attach (use_control_button, 0, 1, 1, 2, 0, 0);
140         out_table.attach (control_out_channel_combo, 1, 2, 1, 2, 0, 0);
141         out_table.attach (use_master_button, 0, 1, 2, 3, 0, 0);
142         out_table.attach (master_out_channel_combo, 1, 2, 2, 3, 0, 0);
143         
144         output_label.set_alignment (0.1, 0.5);
145         output_vbox.pack_start (output_label, true, true, 7);
146         output_vbox.pack_start (out_table, false, false, 5);
147         output_vbox.pack_start (connect_to_master_button, false);
148         output_vbox.pack_start (connect_to_physical_outputs_button, false);
149         output_vbox.pack_start (manual_connect_outputs_button, false);
150         
151         input_hbox.pack_start (input_vbox, false, false);
152         output_hbox.pack_start (output_vbox, false, false);
153
154         VBox* template_vbox = manage (new VBox);
155         Label* template_label = manage (new Label (_("Session template")));
156         
157         template_label->set_alignment (0.1, 0.5);
158         template_vbox->pack_start (*template_label, true, true, 7);
159         template_vbox->pack_start (template_combo, false, false);
160
161         io_box.set_border_width (12);
162         io_box.set_spacing (7);
163         io_box.pack_start (*template_vbox);
164
165         io_box.pack_start (input_hbox);
166         io_box.pack_start (output_hbox);
167
168         reset_templates();
169
170         option_hbox.set_spacing (7);
171         option_hbox.pack_start (io_box);
172
173         fsbox.set_border_width (12);
174         fsbox.set_spacing (7);
175         fsbox.pack_start (file_selector.table, false, false);
176
177         notebook.pages().push_back (TabElem (fsbox, _("Location")));
178         notebook.pages().push_back (TabElem (option_hbox, _("Configuration")));
179
180         if (startup) {
181                 show_again.set_active(true);
182                 show_again.toggled.connect (slot (*this, &NewSessionDialog::show_again_toggled));
183                 file_selector.button_box.pack_end(show_again, false, false);
184         }
185
186         main_vbox.set_border_width (12);
187         main_vbox.set_border_width (12);
188         main_vbox.set_spacing (7);
189         main_vbox.pack_start (sr_frame, false, false);
190         main_vbox.pack_start (notebook, false, false);
191         main_vbox.pack_start (file_selector.button_box, false, false);
192         
193         add (main_vbox);
194
195 //      template_selector.shift_made.connect (
196 //              slot (*this, &NewSessionDialog::mix_template_shift));
197 //      template_selector.control_made.connect (
198 //              slot (*this, &NewSessionDialog::mix_template_control));
199
200         file_selector.cancel_button.signal_clicked().connect (bind (slot (*this, &ArdourDialog::stop), -1));
201         file_selector.op_button.signal_clicked().connect (bind (slot (*this, &ArdourDialog::stop), 0));
202         file_selector.Expanded.connect (slot (*this, &NewSessionDialog::file_selector_expansion));
203
204         delete_event.connect (slot (*this, &ArdourDialog::wm_close_event));
205         show.connect (slot (*this, &NewSessionDialog::fixup_at_show));
206
207         file_selector.entry_label.set_name ("NewSessionMainLabel");
208         file_selector.where_label.set_name ("NewSessionMainLabel");
209         template_label->set_name ("NewSessionIOLabel");
210         input_label.set_name ("NewSessionIOLabel");
211         output_label.set_name ("NewSessionIOLabel");
212         sr_label1.set_name ("NewSessionSR1Label");
213         sr_label2.set_name ("NewSessionSR2Label");
214
215         if (given_path.empty()) {
216                 Session::FavoriteDirs favs;
217                 Session::read_favorite_dirs (favs);
218                 file_selector.set_favorites (favs);
219         } else {
220                 file_selector.set_path (given_path, true);
221                 notebook.set_page (-1);
222                 notebook.show.connect (bind (slot (notebook, &Notebook::set_page), -1));
223         }
224  
225         set_default_size(531, 358);
226 }
227
228 void
229 NewSessionDialog::file_selector_expansion (bool expanded)
230 {
231         if (expanded) {
232                 fsbox.pack_start (file_selector.expansion_vbox);
233                 fsbox.reorder_child (file_selector.expansion_vbox, 2);
234         } else {
235                 fsbox.remove (file_selector.expansion_vbox);
236         }
237 }
238
239 void
240 NewSessionDialog::fixup_at_show ()
241 {
242 //      if (template_selector.clist().rows().size() == 0) {
243 //              use_template_button.set_sensitive (false);
244 //      }
245
246         Session::FavoriteDirs favs;
247         Session::read_favorite_dirs (favs);
248         file_selector.set_favorites (favs);
249
250         file_selector.entry.grab_focus ();
251 }
252
253 void
254 NewSessionDialog::_mix_template_refiller (CList &clist, void *arg)
255
256 {
257         ((NewSessionDialog*) arg)->mix_template_refiller (clist);
258 }
259
260 void
261 NewSessionDialog::mix_template_refiller (CList &clist)
262 {
263         const gchar *rowdata[2];
264         list<string> templates;
265         list<string>::iterator i;
266         
267         Session::get_template_list(templates);
268         
269         rowdata[0] = _("blank");
270         clist.insert_row (0, rowdata);
271
272         guint row;
273         for (row=1, i=templates.begin(); i != templates.end(); ++row, ++i) {
274                 rowdata[0] = (*i).c_str();
275                 clist.insert_row (row, rowdata);
276         }
277 }
278
279 void
280 NewSessionDialog::mix_template_shift (Gtkmm2ext::Selector* selector, Gtkmm2ext::SelectionResult* res)
281 {
282         if (res && res->text){
283                 Session::delete_template(*res->text);
284                 // template_selector.rescan();
285         }
286 }
287
288 void
289 NewSessionDialog::mix_template_control (Gtkmm2ext::Selector* selector, Gtkmm2ext::SelectionResult* res)
290 {
291 #if 0
292         if (res && res->text) {
293                 ArdourPrompter prompter (true);
294                 prompter.set_prompt(_("Name for mix template:"));
295
296                 string old_name = *(res->text);
297                 prompter.set_initial_text (old_name);
298                 prompter.done.connect (Gtk::Main::quit.slot());
299                 prompter.show_all();
300                 
301                 Gtk::Main::run();
302                 
303                 if (prompter.status == Gtkmm2ext::Prompter::entered) {
304                         string name;
305
306                         prompter.get_result (name);
307
308                         if (name.length() && name != old_name) {
309                                 Session::rename_template(old_name, name);
310                                 template_selector.rescan();
311                         }
312                 }
313         }
314 #endif
315 }
316
317 void
318 NewSessionDialog::show_again_toggled ()
319 {
320         Config->set_no_new_session_dialog(!show_again.get_active());
321         Config->save_state();
322 }
323
324 void
325 NewSessionDialog::reset_templates ()
326 {
327         templates.clear ();
328         templates.push_back (_("No template - create tracks/busses manually"));
329         Session::get_template_list (templates);
330         template_combo.set_popdown_strings (templates);
331 }
332
333 string
334 NewSessionDialog::get_template_name()
335 {
336         string str = template_combo.get_entry()->get_text();
337         if (str.substr (0, 11) == _("No template")) {
338                 return "";
339         } else {
340                 return str;
341         }
342 }