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