fix compose mess, and a number of 64 bit printf specs
[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 (string_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.get_group());
107         manual_connect_outputs_button.set_group (connect_to_master_button.get_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         set_popdown_strings (control_out_channel_combo, channel_combo_strings);
119         control_out_channel_combo.set_name (X_("NewSessionChannelCombo"));
120         // use stereo as default
121         control_out_channel_combo.set_active_text (channel_combo_strings.front());
122
123         set_popdown_strings (master_out_channel_combo, channel_combo_strings);
124         master_out_channel_combo.set_name (X_("NewSessionChannelCombo"));
125         // use stereo as default
126         master_out_channel_combo.set_active_text (channel_combo_strings.front());
127
128         
129         out_table.set_col_spacings (7);
130         out_table.set_row_spacings (7);
131         if (engine.n_physical_outputs() > 2) {
132                 out_table.attach (out_count_label, 0, 1, 0, 1, 0, 0);   
133                 out_table.attach (out_count_spinner, 1, 2, 0, 1, 0, 0);
134         }
135         out_table.attach (use_control_button, 0, 1, 1, 2, 0, 0);
136         out_table.attach (control_out_channel_combo, 1, 2, 1, 2, 0, 0);
137         out_table.attach (use_master_button, 0, 1, 2, 3, 0, 0);
138         out_table.attach (master_out_channel_combo, 1, 2, 2, 3, 0, 0);
139         
140         output_label.set_alignment (0.1, 0.5);
141         output_vbox.pack_start (output_label, true, true, 7);
142         output_vbox.pack_start (out_table, false, false, 5);
143         output_vbox.pack_start (connect_to_master_button, false);
144         output_vbox.pack_start (connect_to_physical_outputs_button, false);
145         output_vbox.pack_start (manual_connect_outputs_button, false);
146         
147         input_hbox.pack_start (input_vbox, false, false);
148         output_hbox.pack_start (output_vbox, false, false);
149
150         VBox* template_vbox = manage (new VBox);
151         Label* template_label = manage (new Label (_("Session template")));
152         
153         template_label->set_alignment (0.1, 0.5);
154         template_vbox->pack_start (*template_label, true, true, 7);
155         template_vbox->pack_start (template_combo, false, false);
156
157         io_box.set_border_width (12);
158         io_box.set_spacing (7);
159         io_box.pack_start (*template_vbox);
160
161         io_box.pack_start (input_hbox);
162         io_box.pack_start (output_hbox);
163
164         reset_templates();
165
166         option_hbox.set_spacing (7);
167         option_hbox.pack_start (io_box);
168
169         fsbox.set_border_width (12);
170         fsbox.set_spacing (7);
171         fsbox.pack_start (file_selector.table, false, false);
172
173         notebook.pages().push_back (TabElem (fsbox, _("Location")));
174         notebook.pages().push_back (TabElem (option_hbox, _("Configuration")));
175
176         if (startup) {
177                 show_again.set_active(true);
178                 show_again.toggled.connect (mem_fun(*this, &NewSessionDialog::show_again_toggled));
179                 file_selector.button_box.pack_end(show_again, false, false);
180         }
181
182         main_vbox.set_border_width (12);
183         main_vbox.set_border_width (12);
184         main_vbox.set_spacing (7);
185         main_vbox.pack_start (sr_frame, false, false);
186         main_vbox.pack_start (notebook, false, false);
187         main_vbox.pack_start (file_selector.button_box, false, false);
188         
189         add (main_vbox);
190
191 //      template_selector.shift_made.connect (
192 //              mem_fun(*this, &NewSessionDialog::mix_template_shift));
193 //      template_selector.control_made.connect (
194 //              mem_fun(*this, &NewSessionDialog::mix_template_control));
195
196         file_selector.cancel_button.signal_clicked().connect (bind (mem_fun(*this, &ArdourDialog::stop), -1));
197         file_selector.op_button.signal_clicked().connect (bind (mem_fun(*this, &ArdourDialog::stop), 0));
198         file_selector.Expanded.connect (mem_fun(*this, &NewSessionDialog::file_selector_expansion));
199
200         delete_event.connect (mem_fun(*this, &ArdourDialog::wm_close_event));
201         show.connect (mem_fun(*this, &NewSessionDialog::fixup_at_show));
202
203         file_selector.entry_label.set_name ("NewSessionMainLabel");
204         file_selector.where_label.set_name ("NewSessionMainLabel");
205         template_label->set_name ("NewSessionIOLabel");
206         input_label.set_name ("NewSessionIOLabel");
207         output_label.set_name ("NewSessionIOLabel");
208         sr_label1.set_name ("NewSessionSR1Label");
209         sr_label2.set_name ("NewSessionSR2Label");
210
211         if (given_path.empty()) {
212                 Session::FavoriteDirs favs;
213                 Session::read_favorite_dirs (favs);
214                 file_selector.set_favorites (favs);
215         } else {
216                 file_selector.set_path (given_path, true);
217                 notebook.set_page (-1);
218                 notebook.show.connect (bind (mem_fun (notebook, &Notebook::set_page), -1));
219         }
220  
221         set_default_size(531, 358);
222 }
223
224 void
225 NewSessionDialog::file_selector_expansion (bool expanded)
226 {
227         if (expanded) {
228                 fsbox.pack_start (file_selector.expansion_vbox);
229                 fsbox.reorder_child (file_selector.expansion_vbox, 2);
230         } else {
231                 fsbox.remove (file_selector.expansion_vbox);
232         }
233 }
234
235 void
236 NewSessionDialog::fixup_at_show ()
237 {
238 //      if (template_selector.clist().rows().size() == 0) {
239 //              use_template_button.set_sensitive (false);
240 //      }
241
242         Session::FavoriteDirs favs;
243         Session::read_favorite_dirs (favs);
244         file_selector.set_favorites (favs);
245
246         file_selector.entry.grab_focus ();
247 }
248
249 void
250 NewSessionDialog::_mix_template_refiller (CList &clist, void *arg)
251
252 {
253         ((NewSessionDialog*) arg)->mix_template_refiller (clist);
254 }
255
256 void
257 NewSessionDialog::mix_template_refiller (CList &clist)
258 {
259         const gchar *rowdata[2];
260         list<string> templates;
261         list<string>::iterator i;
262         
263         Session::get_template_list(templates);
264         
265         rowdata[0] = _("blank");
266         clist.insert_row (0, rowdata);
267
268         guint row;
269         for (row=1, i=templates.begin(); i != templates.end(); ++row, ++i) {
270                 rowdata[0] = (*i).c_str();
271                 clist.insert_row (row, rowdata);
272         }
273 }
274
275 void
276 NewSessionDialog::mix_template_shift (Gtkmm2ext::Selector* selector, Gtkmm2ext::SelectionResult* res)
277 {
278         if (res && res->text){
279                 Session::delete_template(*res->text);
280                 // template_selector.rescan();
281         }
282 }
283
284 void
285 NewSessionDialog::mix_template_control (Gtkmm2ext::Selector* selector, Gtkmm2ext::SelectionResult* res)
286 {
287 #if 0
288         if (res && res->text) {
289                 ArdourPrompter prompter (true);
290                 prompter.set_prompt(_("Name for mix template:"));
291
292                 string old_name = *(res->text);
293                 prompter.set_initial_text (old_name);
294                 prompter.done.connect (Gtk::Main::quit.slot());
295                 prompter.show_all();
296                 
297                 Gtk::Main::run();
298                 
299                 if (prompter.status == Gtkmm2ext::Prompter::entered) {
300                         string name;
301
302                         prompter.get_result (name);
303
304                         if (name.length() && name != old_name) {
305                                 Session::rename_template(old_name, name);
306                                 template_selector.rescan();
307                         }
308                 }
309         }
310 #endif
311 }
312
313 void
314 NewSessionDialog::show_again_toggled ()
315 {
316         Config->set_no_new_session_dialog(!show_again.get_active());
317         Config->save_state();
318 }
319
320 void
321 NewSessionDialog::reset_templates ()
322 {
323         templates.clear ();
324         templates.push_back (_("No template - create tracks/busses manually"));
325         Session::get_template_list (templates);
326         set_popdown_strings (template_combo, templates);
327 }
328
329 string
330 NewSessionDialog::get_template_name()
331 {
332         string str = template_combo.get_entry()->get_text();
333         if (str.substr (0, 11) == _("No template")) {
334                 return "";
335         } else {
336                 return str;
337         }
338 }