Fix mantis bug #1619; de-selecting Options->Crossfades->Show now hides all crossfades...
[ardour.git] / gtk2_ardour / new_session_dialog.cc
1 /*
2     Copyright (C) 2005 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 "i18n.h"
21 #include "new_session_dialog.h"
22
23 #include <ardour/recent_sessions.h>
24 #include <ardour/session.h>
25
26 #include <gtkmm/entry.h>
27 #include <gtkmm/filechooserbutton.h>
28 #include <gtkmm/spinbutton.h>
29 #include <gtkmm/checkbutton.h>
30 #include <gtkmm/radiobutton.h>
31 #include <gtkmm/filefilter.h>
32 #include <gtkmm/stock.h>
33 #include <gdkmm/cursor.h>
34
35 #include <gtkmm2ext/window_title.h>
36
37 using namespace Gtkmm2ext;
38
39 #include "opts.h"
40
41 NewSessionDialog::NewSessionDialog()
42         : ArdourDialog ("session control")
43 {
44         session_name_label = Gtk::manage(new class Gtk::Label(_("Name :")));
45         m_name = Gtk::manage(new class Gtk::Entry());
46         m_name->set_text(GTK_ARDOUR::session_name);
47
48         chan_count_label_1 = Gtk::manage(new class Gtk::Label(_("channels")));
49         chan_count_label_2 = Gtk::manage(new class Gtk::Label(_("channels")));
50         chan_count_label_3 = Gtk::manage(new class Gtk::Label(_("channels")));
51         chan_count_label_4 = Gtk::manage(new class Gtk::Label(_("channels")));
52
53         chan_count_label_1->set_alignment(0,0.5);
54         chan_count_label_1->set_padding(0,0);
55         chan_count_label_1->set_line_wrap(false);
56
57         chan_count_label_2->set_alignment(0,0.5);
58         chan_count_label_2->set_padding(0,0);
59         chan_count_label_2->set_line_wrap(false);
60
61         chan_count_label_3->set_alignment(0,0.5);
62         chan_count_label_3->set_padding(0,0);
63         chan_count_label_3->set_line_wrap(false);
64
65         chan_count_label_4->set_alignment(0,0.5);
66         chan_count_label_4->set_padding(0,0);
67         chan_count_label_4->set_line_wrap(false);
68
69         bus_label = Gtk::manage(new class Gtk::Label(_("<b>Busses</b>")));
70         input_label = Gtk::manage(new class Gtk::Label(_("<b>Inputs</b>")));
71         output_label = Gtk::manage(new class Gtk::Label(_("<b>Outputs</b>")));
72
73         session_location_label = Gtk::manage(new class Gtk::Label(_("Create Folder In :")));
74         m_folder = Gtk::manage(new class Gtk::FileChooserButton(Gtk::FILE_CHOOSER_ACTION_SELECT_FOLDER));
75         session_template_label = Gtk::manage(new class Gtk::Label(_("Template :")));
76         m_template = Gtk::manage(new class Gtk::FileChooserButton());
77         m_create_control_bus = Gtk::manage(new class Gtk::CheckButton(_("Create Monitor Bus")));
78         
79         Gtk::Adjustment *m_control_bus_channel_count_adj = Gtk::manage(new class Gtk::Adjustment(2, 0, 100, 1, 10, 10));
80         m_control_bus_channel_count = Gtk::manage(new class Gtk::SpinButton(*m_control_bus_channel_count_adj, 1, 0));
81         
82         Gtk::Adjustment *m_master_bus_channel_count_adj = Gtk::manage(new class Gtk::Adjustment(2, 0, 100, 1, 10, 10));
83         m_master_bus_channel_count = Gtk::manage(new class Gtk::SpinButton(*m_master_bus_channel_count_adj, 1, 0));
84         m_create_master_bus = Gtk::manage(new class Gtk::CheckButton(_("Create Master Bus")));
85         advanced_table = Gtk::manage(new class Gtk::Table(2, 2, true));
86         m_connect_inputs = Gtk::manage(new class Gtk::CheckButton(_("Automatically Connect to Physical Inputs")));
87         m_limit_input_ports = Gtk::manage(new class Gtk::CheckButton(_("Use only")));
88         
89         Gtk::Adjustment *m_input_limit_count_adj = Gtk::manage(new class Gtk::Adjustment(1, 0, 100, 1, 10, 10));
90         m_input_limit_count = Gtk::manage(new class Gtk::SpinButton(*m_input_limit_count_adj, 1, 0));
91         input_port_limit_hbox = Gtk::manage(new class Gtk::HBox(false, 0));
92         input_port_vbox = Gtk::manage(new class Gtk::VBox(false, 0));
93         input_table = Gtk::manage(new class Gtk::Table(2, 2, false));
94
95         bus_frame = Gtk::manage(new class Gtk::Frame());
96         bus_table = Gtk::manage (new Gtk::Table (2, 3, false));
97
98         input_frame = Gtk::manage(new class Gtk::Frame());
99         m_connect_outputs = Gtk::manage(new class Gtk::CheckButton(_("Automatically Connect Outputs")));
100         m_limit_output_ports = Gtk::manage(new class Gtk::CheckButton(_("Use only")));
101         
102         Gtk::Adjustment *m_output_limit_count_adj = Gtk::manage(new class Gtk::Adjustment(1, 0, 100, 1, 10, 10));
103         m_output_limit_count = Gtk::manage(new class Gtk::SpinButton(*m_output_limit_count_adj, 1, 0));
104         output_port_limit_hbox = Gtk::manage(new class Gtk::HBox(false, 0));
105         output_port_vbox = Gtk::manage(new class Gtk::VBox(false, 0));
106         
107         Gtk::RadioButton::Group _RadioBGroup_m_connect_outputs_to_master;
108         m_connect_outputs_to_master = Gtk::manage(new class Gtk::RadioButton(_RadioBGroup_m_connect_outputs_to_master, _("... to Master Bus")));
109         m_connect_outputs_to_physical = Gtk::manage(new class Gtk::RadioButton(_RadioBGroup_m_connect_outputs_to_master, _("... to Physical Outputs")));
110         output_conn_vbox = Gtk::manage(new class Gtk::VBox(false, 0));
111         output_vbox = Gtk::manage(new class Gtk::VBox(false, 0));
112
113         output_frame = Gtk::manage(new class Gtk::Frame());
114         advanced_vbox = Gtk::manage(new class Gtk::VBox(false, 0));
115         advanced_label = Gtk::manage(new class Gtk::Label(_("Advanced Options")));
116         advanced_expander = Gtk::manage(new class Gtk::Expander());
117         new_session_table = Gtk::manage(new class Gtk::Table(2, 2, false));
118         m_open_filechooser = Gtk::manage(new class Gtk::FileChooserButton());
119         open_session_hbox = Gtk::manage(new class Gtk::HBox(false, 0));
120         m_treeview = Gtk::manage(new class Gtk::TreeView());
121         recent_scrolledwindow = Gtk::manage(new class Gtk::ScrolledWindow());
122
123         recent_sesion_label = Gtk::manage(new class Gtk::Label(_("Recent:")));
124         recent_frame = Gtk::manage(new class Gtk::Frame());
125         open_session_vbox = Gtk::manage(new class Gtk::VBox(false, 0));
126         m_notebook = Gtk::manage(new class Gtk::Notebook());
127         session_name_label->set_alignment(0, 0.5);
128         session_name_label->set_padding(6,0);
129         session_name_label->set_line_wrap(false);
130         session_name_label->set_selectable(false);
131         m_name->set_editable(true);
132         m_name->set_max_length(0);
133         m_name->set_has_frame(true);
134         m_name->set_activates_default(true);
135         m_name->set_width_chars (40);
136         session_location_label->set_alignment(0,0.5);
137         session_location_label->set_padding(6,0);
138         session_location_label->set_line_wrap(false);
139         session_location_label->set_selectable(false);
140         session_template_label->set_alignment(0,0.5);
141         session_template_label->set_padding(6,0);
142         session_template_label->set_line_wrap(false);
143         session_template_label->set_selectable(false);
144         m_create_control_bus->set_flags(Gtk::CAN_FOCUS);
145         m_create_control_bus->set_relief(Gtk::RELIEF_NORMAL);
146         m_create_control_bus->set_mode(true);
147         m_create_control_bus->set_active(false);
148         m_create_control_bus->set_border_width(0);
149         m_control_bus_channel_count->set_flags(Gtk::CAN_FOCUS);
150         m_control_bus_channel_count->set_update_policy(Gtk::UPDATE_ALWAYS);
151         m_control_bus_channel_count->set_numeric(true);
152         m_control_bus_channel_count->set_digits(0);
153         m_control_bus_channel_count->set_wrap(false);
154         m_control_bus_channel_count->set_sensitive(false);
155         m_master_bus_channel_count->set_flags(Gtk::CAN_FOCUS);
156         m_master_bus_channel_count->set_update_policy(Gtk::UPDATE_ALWAYS);
157         m_master_bus_channel_count->set_numeric(true);
158         m_master_bus_channel_count->set_digits(0);
159         m_master_bus_channel_count->set_wrap(false);
160         open_session_file_label = Gtk::manage(new class Gtk::Label(_("Browse:")));
161         open_session_file_label->set_alignment(0, 0.5);
162         m_create_master_bus->set_flags(Gtk::CAN_FOCUS);
163         m_create_master_bus->set_relief(Gtk::RELIEF_NORMAL);
164         m_create_master_bus->set_mode(true);
165         m_create_master_bus->set_active(true);
166         m_create_master_bus->set_border_width(0);
167         advanced_table->set_row_spacings(0);
168         advanced_table->set_col_spacings(0);
169
170         m_connect_inputs->set_flags(Gtk::CAN_FOCUS);
171         m_connect_inputs->set_relief(Gtk::RELIEF_NORMAL);
172         m_connect_inputs->set_mode(true);
173         m_connect_inputs->set_active(true);
174         m_connect_inputs->set_border_width(0);
175
176         m_limit_input_ports->set_flags(Gtk::CAN_FOCUS);
177         m_limit_input_ports->set_relief(Gtk::RELIEF_NORMAL);
178         m_limit_input_ports->set_mode(true);
179         m_limit_input_ports->set_sensitive(true);
180         m_limit_input_ports->set_border_width(0);
181         m_input_limit_count->set_flags(Gtk::CAN_FOCUS);
182         m_input_limit_count->set_update_policy(Gtk::UPDATE_ALWAYS);
183         m_input_limit_count->set_numeric(true);
184         m_input_limit_count->set_digits(0);
185         m_input_limit_count->set_wrap(false);
186         m_input_limit_count->set_sensitive(false);
187
188         bus_hbox = Gtk::manage (new Gtk::HBox (false, 0));
189         bus_hbox->pack_start (*bus_table, Gtk::PACK_SHRINK, 18);
190
191         bus_label->set_alignment(0, 0.5);
192         bus_label->set_padding(0,0);
193         bus_label->set_line_wrap(false);
194         bus_label->set_selectable(false);
195         bus_label->set_use_markup(true);
196         bus_frame->set_shadow_type(Gtk::SHADOW_NONE);
197         bus_frame->set_label_align(0,0.5);
198         bus_frame->add(*bus_hbox);
199         bus_frame->set_label_widget(*bus_label);
200         
201         bus_table->set_row_spacings (0);
202         bus_table->set_col_spacings (0);
203         bus_table->attach (*m_create_master_bus, 0, 1, 0, 1, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
204         bus_table->attach (*m_master_bus_channel_count, 1, 2, 0, 1, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
205         bus_table->attach (*chan_count_label_1, 2, 3, 0, 1, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 6, 0);
206         bus_table->attach (*m_create_control_bus, 0, 1, 1, 2, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
207         bus_table->attach (*m_control_bus_channel_count, 1, 2, 1, 2, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
208         bus_table->attach (*chan_count_label_2, 2, 3, 1, 2, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 6, 0);
209
210         input_port_limit_hbox->pack_start(*m_limit_input_ports, Gtk::PACK_SHRINK, 6);
211         input_port_limit_hbox->pack_start(*m_input_limit_count, Gtk::PACK_SHRINK, 0);
212         input_port_limit_hbox->pack_start(*chan_count_label_3, Gtk::PACK_SHRINK, 6);
213         input_port_vbox->pack_start(*m_connect_inputs, Gtk::PACK_SHRINK, 0);
214         input_port_vbox->pack_start(*input_port_limit_hbox, Gtk::PACK_EXPAND_PADDING, 0);
215         input_table->set_row_spacings(0);
216         input_table->set_col_spacings(0);
217         input_table->attach(*input_port_vbox, 0, 1, 0, 1, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 6, 6);
218
219         input_hbox = Gtk::manage (new Gtk::HBox (false, 0));
220         input_hbox->pack_start (*input_table, Gtk::PACK_SHRINK, 18);
221
222         input_label->set_alignment(0, 0.5);
223         input_label->set_padding(0,0);
224         input_label->set_line_wrap(false);
225         input_label->set_selectable(false);
226         input_label->set_use_markup(true);
227         input_frame->set_shadow_type(Gtk::SHADOW_NONE);
228         input_frame->set_label_align(0,0.5);
229         input_frame->add(*input_hbox);
230         input_frame->set_label_widget(*input_label);
231
232         m_connect_outputs->set_flags(Gtk::CAN_FOCUS);
233         m_connect_outputs->set_relief(Gtk::RELIEF_NORMAL);
234         m_connect_outputs->set_mode(true);
235         m_connect_outputs->set_active(true);
236         m_connect_outputs->set_border_width(0);
237         m_limit_output_ports->set_flags(Gtk::CAN_FOCUS);
238         m_limit_output_ports->set_relief(Gtk::RELIEF_NORMAL);
239         m_limit_output_ports->set_mode(true);
240         m_limit_output_ports->set_sensitive(true);
241         m_limit_output_ports->set_border_width(0);
242         m_output_limit_count->set_flags(Gtk::CAN_FOCUS);
243         m_output_limit_count->set_update_policy(Gtk::UPDATE_ALWAYS);
244         m_output_limit_count->set_numeric(false);
245         m_output_limit_count->set_digits(0);
246         m_output_limit_count->set_wrap(false);
247         m_output_limit_count->set_sensitive(false);
248         output_port_limit_hbox->pack_start(*m_limit_output_ports, Gtk::PACK_SHRINK, 6);
249         output_port_limit_hbox->pack_start(*m_output_limit_count, Gtk::PACK_SHRINK, 0);
250         output_port_limit_hbox->pack_start(*chan_count_label_4, Gtk::PACK_SHRINK, 6);
251         m_connect_outputs_to_master->set_flags(Gtk::CAN_FOCUS);
252         m_connect_outputs_to_master->set_relief(Gtk::RELIEF_NORMAL);
253         m_connect_outputs_to_master->set_mode(true);
254         m_connect_outputs_to_master->set_active(false);
255         m_connect_outputs_to_master->set_border_width(0);
256         m_connect_outputs_to_physical->set_flags(Gtk::CAN_FOCUS);
257         m_connect_outputs_to_physical->set_relief(Gtk::RELIEF_NORMAL);
258         m_connect_outputs_to_physical->set_mode(true);
259         m_connect_outputs_to_physical->set_active(false);
260         m_connect_outputs_to_physical->set_border_width(0);
261         output_conn_vbox->pack_start(*m_connect_outputs, Gtk::PACK_SHRINK, 0);
262         output_conn_vbox->pack_start(*m_connect_outputs_to_master, Gtk::PACK_SHRINK, 0);
263         output_conn_vbox->pack_start(*m_connect_outputs_to_physical, Gtk::PACK_SHRINK, 0);
264         output_vbox->set_border_width(6);
265
266         output_port_vbox->pack_start(*output_port_limit_hbox, Gtk::PACK_SHRINK, 0);
267
268         output_vbox->pack_start(*output_conn_vbox);
269         output_vbox->pack_start(*output_port_vbox);
270
271         output_label->set_alignment(0, 0.5);
272         output_label->set_padding(0,0);
273         output_label->set_line_wrap(false);
274         output_label->set_selectable(false);
275         output_label->set_use_markup(true);
276         output_frame->set_shadow_type(Gtk::SHADOW_NONE);
277         output_frame->set_label_align(0,0.5);
278
279         output_hbox = Gtk::manage (new Gtk::HBox (false, 0));
280         output_hbox->pack_start (*output_vbox, Gtk::PACK_SHRINK, 18);
281
282         output_frame->add(*output_hbox);
283         output_frame->set_label_widget(*output_label);
284
285         advanced_vbox->pack_start(*advanced_table, Gtk::PACK_SHRINK, 0);
286         advanced_vbox->pack_start(*bus_frame, Gtk::PACK_SHRINK, 6);
287         advanced_vbox->pack_start(*input_frame, Gtk::PACK_SHRINK, 6);
288         advanced_vbox->pack_start(*output_frame, Gtk::PACK_SHRINK, 0);
289         advanced_label->set_padding(0,0);
290         advanced_label->set_line_wrap(false);
291         advanced_label->set_selectable(false);
292         advanced_label->set_alignment(0, 0.5);
293         advanced_expander->set_flags(Gtk::CAN_FOCUS);
294         advanced_expander->set_border_width(0);
295         advanced_expander->set_expanded(false);
296         advanced_expander->set_spacing(0);
297         advanced_expander->add(*advanced_vbox);
298         advanced_expander->set_label_widget(*advanced_label);
299         new_session_table->set_border_width(12);
300         new_session_table->set_row_spacings(6);
301         new_session_table->set_col_spacings(0);
302         new_session_table->attach(*session_name_label, 0, 1, 0, 1, Gtk::FILL, Gtk::FILL, 0, 0);
303         new_session_table->attach(*m_name, 1, 2, 0, 1, Gtk::EXPAND|Gtk::FILL, Gtk::FILL, 0, 0);
304         new_session_table->attach(*session_location_label, 0, 1, 1, 2, Gtk::FILL, Gtk::FILL, 0, 0);
305         new_session_table->attach(*m_folder, 1, 2, 1, 2, Gtk::EXPAND|Gtk::FILL, Gtk::FILL, 0, 0);
306         new_session_table->attach(*session_template_label, 0, 1, 2, 3, Gtk::FILL, Gtk::FILL, 0, 0);
307         new_session_table->attach(*m_template, 1, 2, 2, 3, Gtk::EXPAND|Gtk::FILL, Gtk::FILL, 0, 0);
308         new_session_table->attach(*advanced_expander, 0, 2, 3, 4, Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 6);
309
310         open_session_hbox->pack_start(*open_session_file_label, false, false, 12);
311         open_session_hbox->pack_start(*m_open_filechooser, true, true, 12);
312         m_treeview->set_flags(Gtk::CAN_FOCUS);
313         m_treeview->set_headers_visible(true);
314         m_treeview->set_rules_hint(false);
315         m_treeview->set_reorderable(false);
316         m_treeview->set_enable_search(true);
317         m_treeview->set_fixed_height_mode(false);
318         m_treeview->set_hover_selection(false);
319         m_treeview->set_size_request(-1, 150);
320         recent_scrolledwindow->set_flags(Gtk::CAN_FOCUS);
321         recent_scrolledwindow->set_border_width(6);
322         recent_scrolledwindow->set_shadow_type(Gtk::SHADOW_IN);
323         recent_scrolledwindow->set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
324         recent_scrolledwindow->property_window_placement().set_value(Gtk::CORNER_TOP_LEFT);
325         recent_scrolledwindow->add(*m_treeview);
326
327         recent_sesion_label->set_padding(0,0);
328         recent_sesion_label->set_line_wrap(false);
329         recent_sesion_label->set_selectable(false);
330         recent_frame->set_border_width(12);
331         recent_frame->set_shadow_type(Gtk::SHADOW_NONE);
332         recent_frame->add(*recent_scrolledwindow);
333         recent_frame->set_label_widget(*recent_sesion_label);
334         open_session_vbox->pack_start(*recent_frame, Gtk::PACK_EXPAND_WIDGET, 0);
335         open_session_vbox->pack_start(*open_session_hbox, Gtk::PACK_SHRINK, 12);
336         m_notebook->set_flags(Gtk::CAN_FOCUS);
337         m_notebook->set_scrollable(true);
338         m_notebook->append_page(*new_session_table, _("New Session"));
339         m_notebook->pages().back().set_tab_label_packing(false, true, Gtk::PACK_START);
340         m_notebook->append_page(*open_session_vbox, _("Open Session"));
341         m_notebook->pages().back().set_tab_label_packing(false, true, Gtk::PACK_START);
342         get_vbox()->set_homogeneous(false);
343         get_vbox()->set_spacing(0);
344         get_vbox()->pack_start(*m_notebook, Gtk::PACK_SHRINK, 0);
345
346         WindowTitle title(Glib::get_application_name());
347         title += _("Session Control");
348         set_title(title.get_string());
349
350         //set_modal(false);
351         //property_window_position().set_value(Gtk::WIN_POS_NONE);
352         set_resizable(false);
353         //property_destroy_with_parent().set_value(false);
354         set_has_separator(false);
355         // add_button(Gtk::Stock::HELP, Gtk::RESPONSE_HELP);
356         add_button(Gtk::Stock::QUIT, Gtk::RESPONSE_CANCEL);
357         add_button(Gtk::Stock::CLEAR, Gtk::RESPONSE_NONE);
358         m_okbutton = add_button(Gtk::Stock::NEW, Gtk::RESPONSE_OK);
359
360         recent_model = Gtk::TreeStore::create (recent_columns);
361         m_treeview->set_model (recent_model);
362         m_treeview->append_column (_("Recent Sessions"), recent_columns.visible_name);
363         m_treeview->set_headers_visible (false);
364         m_treeview->get_selection()->set_mode (Gtk::SELECTION_SINGLE);
365
366         std::string path = ARDOUR::get_user_ardour_path();
367         
368         if (path.empty()) {
369                 path = ARDOUR::get_system_data_path();
370         }
371
372         const char * const template_dir_name = X_("templates");
373
374         if (!path.empty()) {
375                 string user_template_path = path + template_dir_name;
376
377                 if (Glib::file_test(user_template_path, Glib::FILE_TEST_IS_DIR))
378                 {
379                         m_template->set_current_folder (user_template_path);
380                 }
381         }
382
383         const std::string sys_templates_dir = ARDOUR::get_system_data_path() + template_dir_name;
384         
385         if (Glib::file_test(sys_templates_dir, Glib::FILE_TEST_IS_DIR))
386         {
387                 m_template->add_shortcut_folder(sys_templates_dir);
388         }
389
390         m_template->set_title(_("select template"));
391         Gtk::FileFilter* session_filter = manage (new (Gtk::FileFilter));
392         session_filter->add_pattern(X_("*.ardour"));
393         session_filter->add_pattern(X_("*.ardour.bak"));
394         m_open_filechooser->set_filter (*session_filter);
395         m_open_filechooser->set_current_folder(getenv ("HOME"));
396         m_open_filechooser->set_title(_("select session file"));
397
398         Gtk::FileFilter* template_filter = manage (new (Gtk::FileFilter));
399         template_filter->add_pattern(X_("*.ardour"));
400         template_filter->add_pattern(X_("*.ardour.bak"));
401         template_filter->add_pattern(X_("*.template"));
402         m_template->set_filter (*template_filter);
403
404         m_folder->set_current_folder(getenv ("HOME"));
405         m_folder->set_title(_("select directory"));
406
407         on_new_session_page = true;
408         m_notebook->set_current_page(0);
409         m_notebook->show();
410         m_notebook->show_all_children();
411
412
413         set_default_response (Gtk::RESPONSE_OK);
414         if (!GTK_ARDOUR::session_name.length()) {
415                 set_response_sensitive (Gtk::RESPONSE_OK, false);
416                 set_response_sensitive (Gtk::RESPONSE_NONE, false);
417         } else {
418                 set_response_sensitive (Gtk::RESPONSE_OK, true);
419                 set_response_sensitive (Gtk::RESPONSE_NONE, true);
420         }
421
422         ///@ connect some signals
423
424         m_connect_inputs->signal_clicked().connect (mem_fun (*this, &NewSessionDialog::connect_inputs_clicked));
425         m_connect_outputs->signal_clicked().connect (mem_fun (*this, &NewSessionDialog::connect_outputs_clicked));
426         m_limit_input_ports->signal_clicked().connect (mem_fun (*this, &NewSessionDialog::limit_inputs_clicked));
427         m_limit_output_ports->signal_clicked().connect (mem_fun (*this, &NewSessionDialog::limit_outputs_clicked));
428         m_create_master_bus->signal_clicked().connect (mem_fun (*this, &NewSessionDialog::master_bus_button_clicked));
429         m_create_control_bus->signal_clicked().connect (mem_fun (*this, &NewSessionDialog::monitor_bus_button_clicked));
430         m_name->signal_key_release_event().connect(mem_fun (*this, &NewSessionDialog::entry_key_release));
431         m_notebook->signal_switch_page().connect (mem_fun (*this, &NewSessionDialog::notebook_page_changed));
432         m_treeview->get_selection()->signal_changed().connect (mem_fun (*this, &NewSessionDialog::treeview_selection_changed));
433         m_treeview->signal_row_activated().connect (mem_fun (*this, &NewSessionDialog::recent_row_activated));
434         m_open_filechooser->signal_selection_changed ().connect (mem_fun (*this, &NewSessionDialog::file_chosen));
435         m_template->signal_selection_changed ().connect (mem_fun (*this, &NewSessionDialog::template_chosen));
436         m_name->grab_focus();
437 }
438
439 void
440 NewSessionDialog::set_session_name(const Glib::ustring& name)
441 {
442         m_name->set_text(name);
443 }
444
445 std::string
446 NewSessionDialog::session_name() const
447 {
448         std::string str = Glib::filename_from_utf8(m_open_filechooser->get_filename());
449         std::string::size_type position = str.find_last_of ('/');
450         str = str.substr (position+1);
451         position = str.find_last_of ('.');
452         str = str.substr (0, position);
453
454         /*
455           XXX what to do if it's a .bak file?
456           load_session doesn't allow it!
457
458         if ((position = str.rfind(".bak")) != string::npos) {
459                 str = str.substr (0, position);
460         }         
461         */
462
463         if (m_notebook->get_current_page() == 0) {
464                 return Glib::filename_from_utf8(m_name->get_text());
465         } else {
466                 if (m_treeview->get_selection()->count_selected_rows() == 0) {
467                         return Glib::filename_from_utf8(str);
468                 }
469                 Gtk::TreeModel::iterator i = m_treeview->get_selection()->get_selected();
470                 return (*i)[recent_columns.visible_name];
471         }
472 }
473
474 std::string
475 NewSessionDialog::session_folder() const
476 {
477         if (m_notebook->get_current_page() == 0) {
478                 return Glib::filename_from_utf8(m_folder->get_current_folder());
479         } else {
480                
481                 if (m_treeview->get_selection()->count_selected_rows() == 0) {
482                         return Glib::filename_from_utf8(m_open_filechooser->get_current_folder());
483                 }
484                 Gtk::TreeModel::iterator i = m_treeview->get_selection()->get_selected();
485                 return (*i)[recent_columns.fullpath];
486         }
487 }
488
489 bool
490 NewSessionDialog::use_session_template() const
491 {
492         if(m_template->get_filename().empty() && (m_notebook->get_current_page() == 0)) return false;
493         return true;
494 }
495
496 std::string
497 NewSessionDialog::session_template_name() const
498 {
499         return Glib::filename_from_utf8(m_template->get_filename());
500 }
501
502 bool
503 NewSessionDialog::create_master_bus() const
504 {
505         return m_create_master_bus->get_active();
506 }
507
508 int
509 NewSessionDialog::master_channel_count() const
510 {
511         return m_master_bus_channel_count->get_value_as_int();
512 }
513
514 bool
515 NewSessionDialog::create_control_bus() const
516 {
517         return m_create_control_bus->get_active();
518 }
519
520 int
521 NewSessionDialog::control_channel_count() const
522 {
523         return m_control_bus_channel_count->get_value_as_int();
524 }
525
526 bool
527 NewSessionDialog::connect_inputs() const
528 {
529         return m_connect_inputs->get_active();
530 }
531
532 bool
533 NewSessionDialog::limit_inputs_used_for_connection() const
534 {
535         return m_limit_input_ports->get_active();
536 }
537
538 int
539 NewSessionDialog::input_limit_count() const
540 {
541         return m_input_limit_count->get_value_as_int();
542 }
543
544 bool
545 NewSessionDialog::connect_outputs() const
546 {
547         return m_connect_outputs->get_active();
548 }
549
550 bool
551 NewSessionDialog::limit_outputs_used_for_connection() const
552 {
553         return m_limit_output_ports->get_active();
554 }
555
556 int
557 NewSessionDialog::output_limit_count() const
558 {
559         return m_output_limit_count->get_value_as_int();
560 }
561
562 bool
563 NewSessionDialog::connect_outs_to_master() const
564 {
565         return m_connect_outputs_to_master->get_active();
566 }
567
568 bool
569 NewSessionDialog::connect_outs_to_physical() const
570 {
571         return m_connect_outputs_to_physical->get_active();
572 }
573
574 int
575 NewSessionDialog::get_current_page()
576 {
577         return m_notebook->get_current_page();
578         
579 }
580
581 void
582 NewSessionDialog::reset_name()
583 {
584         m_name->set_text("");
585         set_response_sensitive (Gtk::RESPONSE_OK, false);
586         
587 }
588
589 bool
590 NewSessionDialog::entry_key_release (GdkEventKey* ev)
591 {
592         if (m_name->get_text() != "") {
593                 set_response_sensitive (Gtk::RESPONSE_OK, true);
594                 set_response_sensitive (Gtk::RESPONSE_NONE, true);
595         } else {
596                 set_response_sensitive (Gtk::RESPONSE_OK, false);
597         }
598         return true;
599 }
600
601 void
602 NewSessionDialog::notebook_page_changed (GtkNotebookPage* np, uint pagenum)
603 {
604         if (pagenum == 1) {
605                 on_new_session_page = false;
606                 m_okbutton->set_label(_("Open"));
607                 set_response_sensitive (Gtk::RESPONSE_NONE, false);
608                 m_okbutton->set_image (*(new Gtk::Image (Gtk::Stock::OPEN, Gtk::ICON_SIZE_BUTTON)));
609                 if (m_treeview->get_selection()->count_selected_rows() == 0) {
610                         set_response_sensitive (Gtk::RESPONSE_OK, false);
611                 } else {
612                         set_response_sensitive (Gtk::RESPONSE_OK, true);
613                 }
614         } else {
615                 on_new_session_page = true;
616                 if (m_name->get_text() != "") {
617                         set_response_sensitive (Gtk::RESPONSE_NONE, true);
618                 }
619                 m_okbutton->set_label(_("New"));
620                 m_okbutton->set_image (*(new Gtk::Image (Gtk::Stock::NEW, Gtk::ICON_SIZE_BUTTON)));
621                 if (m_name->get_text() == "") {
622                         set_response_sensitive (Gtk::RESPONSE_OK, false);
623                 } else {
624                         set_response_sensitive (Gtk::RESPONSE_OK, true);
625                 }
626         }
627 }
628
629 void
630 NewSessionDialog::treeview_selection_changed ()
631 {
632         if (m_treeview->get_selection()->count_selected_rows() == 0) {
633                 if (!m_open_filechooser->get_filename().empty()) {
634                         set_response_sensitive (Gtk::RESPONSE_OK, true);
635                 } else {
636                         set_response_sensitive (Gtk::RESPONSE_OK, false);
637                 }
638         } else {
639                 set_response_sensitive (Gtk::RESPONSE_OK, true);
640         }
641 }
642
643 void
644 NewSessionDialog::file_chosen ()
645 {
646         if (on_new_session_page) return;
647
648         m_treeview->get_selection()->unselect_all();
649
650         get_window()->set_cursor(Gdk::Cursor(Gdk::WATCH));
651
652         if (!m_open_filechooser->get_filename().empty()) {
653                 set_response_sensitive (Gtk::RESPONSE_OK, true);
654                 response (Gtk::RESPONSE_OK);
655         } else {
656                 set_response_sensitive (Gtk::RESPONSE_OK, false);
657         }
658 }
659
660 void
661 NewSessionDialog::template_chosen ()
662 {
663         if (m_template->get_filename() != "" ) {;
664                 set_response_sensitive (Gtk::RESPONSE_NONE, true);
665         } else {
666                 set_response_sensitive (Gtk::RESPONSE_NONE, false);
667         }
668 }
669
670 void
671 NewSessionDialog::recent_row_activated (const Gtk::TreePath& path, Gtk::TreeViewColumn* col)
672 {
673         response (Gtk::RESPONSE_YES);
674 }
675
676 void
677 NewSessionDialog::connect_inputs_clicked ()
678 {
679         m_limit_input_ports->set_sensitive(m_connect_inputs->get_active());
680
681                 if (m_connect_inputs->get_active() && m_limit_input_ports->get_active()) {
682                 m_input_limit_count->set_sensitive(true);
683                 } else {
684                 m_input_limit_count->set_sensitive(false);
685                 }
686 }
687
688 void
689 NewSessionDialog::connect_outputs_clicked ()
690 {
691         m_limit_output_ports->set_sensitive(m_connect_outputs->get_active());
692
693                 if (m_connect_outputs->get_active() && m_limit_output_ports->get_active()) {
694                 m_output_limit_count->set_sensitive(true);
695                 } else {
696                 m_output_limit_count->set_sensitive(false);
697                 }
698 }
699
700 void
701 NewSessionDialog::limit_inputs_clicked ()
702 {
703         m_input_limit_count->set_sensitive(m_limit_input_ports->get_active());
704 }
705
706 void
707 NewSessionDialog::limit_outputs_clicked ()
708 {
709         m_output_limit_count->set_sensitive(m_limit_output_ports->get_active());
710 }
711
712 void
713 NewSessionDialog::master_bus_button_clicked ()
714 {
715         m_master_bus_channel_count->set_sensitive(m_create_master_bus->get_active());
716 }
717
718 void
719 NewSessionDialog::monitor_bus_button_clicked ()
720 {
721         m_control_bus_channel_count->set_sensitive(m_create_control_bus->get_active());
722 }
723
724 void
725 NewSessionDialog::reset_template()
726 {
727         m_template->set_filename("");
728 }
729
730 void
731 NewSessionDialog::reset_recent()
732 {
733         /* Shamelessly ripped from ardour_ui.cc */
734         std::vector<string *> *sessions;
735         std::vector<string *>::iterator i;
736         RecentSessionsSorter cmp;
737         
738         recent_model->clear ();
739
740         ARDOUR::RecentSessions rs;
741         ARDOUR::read_recent_sessions (rs);
742         
743         /* sort them alphabetically */
744         sort (rs.begin(), rs.end(), cmp);
745         sessions = new std::vector<std::string*>;
746         
747         for (ARDOUR::RecentSessions::iterator i = rs.begin(); i != rs.end(); ++i) {
748                 sessions->push_back (new string ((*i).second));
749         }
750         
751         for (i = sessions->begin(); i != sessions->end(); ++i) {
752
753                 std::vector<std::string*>* states;
754                 std::vector<const gchar*> item;
755                 std::string fullpath = *(*i);
756                 
757                 /* remove any trailing / */
758                 
759                 if (fullpath[fullpath.length()-1] == '/') {
760                         fullpath = fullpath.substr (0, fullpath.length()-1);
761                 }
762             
763                 /* now get available states for this session */
764                   
765                 if ((states = ARDOUR::Session::possible_states (fullpath)) == 0) {
766                         /* no state file? */
767                         continue;
768                 }
769             
770                 Gtk::TreeModel::Row row = *(recent_model->append());
771                 
772                 row[recent_columns.visible_name] = Glib::path_get_basename (fullpath);
773                 row[recent_columns.fullpath] = fullpath;
774                 
775                 if (states->size()) {
776                     
777                         /* add the children */
778                     
779                         for (std::vector<std::string*>::iterator i2 = states->begin(); i2 != states->end(); ++i2) {
780
781                                 Gtk::TreeModel::Row child_row = *(recent_model->append (row.children()));
782                                 
783                                 child_row[recent_columns.visible_name] = **i2;
784                                 child_row[recent_columns.fullpath] = fullpath;
785                                 
786                                 delete *i2;
787                         }
788                 }
789
790                 delete states;
791         }
792         delete sessions;
793 }
794
795 void
796 NewSessionDialog::reset()
797 {
798         reset_name();
799         reset_template();
800         set_response_sensitive (Gtk::RESPONSE_NONE, false);
801 }