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