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