Make level meter colors user definable. Base, Mid, Top, and Clip colors are defined...
[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                 m_notebook->remove_page (engine_control);
456         } else {
457                 // XXX this is a bit of crude hack. if we ever add or remove
458                 // pages from the notebook, this is going to break.
459                 if (m_notebook->get_n_pages () != 3) {
460                         m_notebook->append_page (engine_control, _("Audio Setup"));
461                         m_notebook->show_all_children();
462                 }
463         }
464 }
465
466 void
467 NewSessionDialog::set_session_name(const Glib::ustring& name)
468 {
469         m_name->set_text(name);
470 }
471
472 void
473 NewSessionDialog::set_session_folder(const Glib::ustring& dir)
474 {
475         // XXX DO SOMETHING
476 }
477
478 std::string
479 NewSessionDialog::session_name() const
480 {
481         std::string str = Glib::filename_from_utf8(m_open_filechooser->get_filename());
482         std::string::size_type position = str.find_last_of ('/');
483         str = str.substr (position+1);
484         position = str.find_last_of ('.');
485         str = str.substr (0, position);
486
487         /*
488           XXX what to do if it's a .bak file?
489           load_session doesn't allow it!
490
491         if ((position = str.rfind(".bak")) != string::npos) {
492                 str = str.substr (0, position);
493         }         
494         */
495
496         int page = m_notebook->get_current_page();
497
498         if (page == 0 || page == 2) {
499                 /* new or audio setup pages */
500                 return Glib::filename_from_utf8(m_name->get_text());
501         } else {
502                 if (m_treeview->get_selection()->count_selected_rows() == 0) {
503                         return Glib::filename_from_utf8(str);
504                 }
505                 Gtk::TreeModel::iterator i = m_treeview->get_selection()->get_selected();
506                 return (*i)[recent_columns.visible_name];
507         }
508 }
509
510 std::string
511 NewSessionDialog::session_folder() const
512 {
513         if (m_notebook->get_current_page() == 0) {
514                 return Glib::filename_from_utf8(m_folder->get_filename());
515         } else {
516                
517                 if (m_treeview->get_selection()->count_selected_rows() == 0) {
518                         const string filename(Glib::filename_from_utf8(m_open_filechooser->get_filename()));
519                         return Glib::path_get_dirname(filename);
520                 }
521                 Gtk::TreeModel::iterator i = m_treeview->get_selection()->get_selected();
522                 return (*i)[recent_columns.fullpath];
523         }
524 }
525
526 bool
527 NewSessionDialog::use_session_template() const
528 {
529         if(m_template->get_filename().empty() && (m_notebook->get_current_page() == 0)) return false;
530         return true;
531 }
532
533 std::string
534 NewSessionDialog::session_template_name() const
535 {
536         return Glib::filename_from_utf8(m_template->get_filename());
537 }
538
539 bool
540 NewSessionDialog::create_master_bus() const
541 {
542         return m_create_master_bus->get_active();
543 }
544
545 int
546 NewSessionDialog::master_channel_count() const
547 {
548         return m_master_bus_channel_count->get_value_as_int();
549 }
550
551 bool
552 NewSessionDialog::create_control_bus() const
553 {
554         return m_create_control_bus->get_active();
555 }
556
557 int
558 NewSessionDialog::control_channel_count() const
559 {
560         return m_control_bus_channel_count->get_value_as_int();
561 }
562
563 bool
564 NewSessionDialog::connect_inputs() const
565 {
566         return m_connect_inputs->get_active();
567 }
568
569 bool
570 NewSessionDialog::limit_inputs_used_for_connection() const
571 {
572         return m_limit_input_ports->get_active();
573 }
574
575 int
576 NewSessionDialog::input_limit_count() const
577 {
578         return m_input_limit_count->get_value_as_int();
579 }
580
581 bool
582 NewSessionDialog::connect_outputs() const
583 {
584         return m_connect_outputs->get_active();
585 }
586
587 bool
588 NewSessionDialog::limit_outputs_used_for_connection() const
589 {
590         return m_limit_output_ports->get_active();
591 }
592
593 int
594 NewSessionDialog::output_limit_count() const
595 {
596         return m_output_limit_count->get_value_as_int();
597 }
598
599 bool
600 NewSessionDialog::connect_outs_to_master() const
601 {
602         return m_connect_outputs_to_master->get_active();
603 }
604
605 bool
606 NewSessionDialog::connect_outs_to_physical() const
607 {
608         return m_connect_outputs_to_physical->get_active();
609 }
610
611 int
612 NewSessionDialog::get_current_page()
613 {
614         return m_notebook->get_current_page();
615 }
616
617 void
618 NewSessionDialog::set_current_page(int page)
619 {
620         return m_notebook->set_current_page (page);
621 }
622
623 void
624 NewSessionDialog::reset_name()
625 {
626         m_name->set_text("");
627         set_response_sensitive (Gtk::RESPONSE_OK, false);
628         
629 }
630
631 void
632 NewSessionDialog::on_new_session_name_entry_changed ()
633 {
634         if (m_name->get_text() != "") {
635                 set_response_sensitive (Gtk::RESPONSE_OK, true);
636                 set_response_sensitive (Gtk::RESPONSE_NONE, true);
637         } else {
638                 set_response_sensitive (Gtk::RESPONSE_OK, false);
639         }
640 }
641
642 void
643 NewSessionDialog::notebook_page_changed (GtkNotebookPage* np, uint pagenum)
644 {
645         if (in_destructor) {
646                 return;
647         }
648
649         if (pagenum == 1) {
650                 on_new_session_page = false;
651                 set_response_sensitive (Gtk::RESPONSE_NONE, false);
652                 if (m_treeview->get_selection()->count_selected_rows() == 0) {
653                         set_response_sensitive (Gtk::RESPONSE_OK, false);
654                 } else {
655                         set_response_sensitive (Gtk::RESPONSE_OK, true);
656                 }
657         } else {
658                 on_new_session_page = true;
659                 if (m_name->get_text() != "") {
660                         set_response_sensitive (Gtk::RESPONSE_NONE, true);
661                 }
662                 if (m_name->get_text() == "") {
663                         set_response_sensitive (Gtk::RESPONSE_OK, false);
664                 } else {
665                         set_response_sensitive (Gtk::RESPONSE_OK, true);
666                 }
667         }
668 }
669
670 void
671 NewSessionDialog::treeview_selection_changed ()
672 {
673         if (m_treeview->get_selection()->count_selected_rows() == 0) {
674                 if (!m_open_filechooser->get_filename().empty()) {
675                         set_response_sensitive (Gtk::RESPONSE_OK, true);
676                 } else {
677                         set_response_sensitive (Gtk::RESPONSE_OK, false);
678                 }
679         } else {
680                 set_response_sensitive (Gtk::RESPONSE_OK, true);
681         }
682 }
683
684 void
685 NewSessionDialog::file_chosen ()
686 {
687         if (on_new_session_page) return;
688
689         m_treeview->get_selection()->unselect_all();
690
691         get_window()->set_cursor(Gdk::Cursor(Gdk::WATCH));
692
693         if (!m_open_filechooser->get_filename().empty()) {
694                 set_response_sensitive (Gtk::RESPONSE_OK, true);
695                 response (Gtk::RESPONSE_OK);
696         } else {
697                 set_response_sensitive (Gtk::RESPONSE_OK, false);
698         }
699 }
700
701 void
702 NewSessionDialog::template_chosen ()
703 {
704         if (m_template->get_filename() != "" ) {;
705                 set_response_sensitive (Gtk::RESPONSE_NONE, true);
706         } else {
707                 set_response_sensitive (Gtk::RESPONSE_NONE, false);
708         }
709 }
710
711 void
712 NewSessionDialog::recent_row_activated (const Gtk::TreePath& path, Gtk::TreeViewColumn* col)
713 {
714         response (Gtk::RESPONSE_YES);
715 }
716
717 void
718 NewSessionDialog::connect_inputs_clicked ()
719 {
720         m_limit_input_ports->set_sensitive(m_connect_inputs->get_active());
721
722                 if (m_connect_inputs->get_active() && m_limit_input_ports->get_active()) {
723                 m_input_limit_count->set_sensitive(true);
724                 } else {
725                 m_input_limit_count->set_sensitive(false);
726                 }
727 }
728
729 void
730 NewSessionDialog::connect_outputs_clicked ()
731 {
732         m_limit_output_ports->set_sensitive(m_connect_outputs->get_active());
733
734                 if (m_connect_outputs->get_active() && m_limit_output_ports->get_active()) {
735                 m_output_limit_count->set_sensitive(true);
736                 } else {
737                 m_output_limit_count->set_sensitive(false);
738                 }
739 }
740
741 void
742 NewSessionDialog::limit_inputs_clicked ()
743 {
744         m_input_limit_count->set_sensitive(m_limit_input_ports->get_active());
745 }
746
747 void
748 NewSessionDialog::limit_outputs_clicked ()
749 {
750         m_output_limit_count->set_sensitive(m_limit_output_ports->get_active());
751 }
752
753 void
754 NewSessionDialog::master_bus_button_clicked ()
755 {
756         m_master_bus_channel_count->set_sensitive(m_create_master_bus->get_active());
757 }
758
759 void
760 NewSessionDialog::monitor_bus_button_clicked ()
761 {
762         m_control_bus_channel_count->set_sensitive(m_create_control_bus->get_active());
763 }
764
765 void
766 NewSessionDialog::reset_template()
767 {
768         m_template->set_filename("");
769 }
770
771 void
772 NewSessionDialog::reset_recent()
773 {
774         /* Shamelessly ripped from ardour_ui.cc */
775         std::vector<string *> *sessions;
776         std::vector<string *>::iterator i;
777         RecentSessionsSorter cmp;
778         
779         recent_model->clear ();
780
781         ARDOUR::RecentSessions rs;
782         ARDOUR::read_recent_sessions (rs);
783         
784         /* sort them alphabetically */
785         sort (rs.begin(), rs.end(), cmp);
786         sessions = new std::vector<std::string*>;
787         
788         for (ARDOUR::RecentSessions::iterator i = rs.begin(); i != rs.end(); ++i) {
789                 sessions->push_back (new string ((*i).second));
790         }
791         
792         for (i = sessions->begin(); i != sessions->end(); ++i) {
793
794                 std::vector<std::string*>* states;
795                 std::vector<const gchar*> item;
796                 std::string fullpath = *(*i);
797                 
798                 /* remove any trailing / */
799                 
800                 if (fullpath[fullpath.length()-1] == '/') {
801                         fullpath = fullpath.substr (0, fullpath.length()-1);
802                 }
803             
804                 /* now get available states for this session */
805                   
806                 if ((states = ARDOUR::Session::possible_states (fullpath)) == 0) {
807                         /* no state file? */
808                         continue;
809                 }
810             
811                 Gtk::TreeModel::Row row = *(recent_model->append());
812                 
813                 row[recent_columns.visible_name] = Glib::path_get_basename (fullpath);
814                 row[recent_columns.fullpath] = fullpath;
815                 
816                 if (states->size()) {
817                     
818                         /* add the children */
819                     
820                         for (std::vector<std::string*>::iterator i2 = states->begin(); i2 != states->end(); ++i2) {
821
822                                 Gtk::TreeModel::Row child_row = *(recent_model->append (row.children()));
823                                 
824                                 child_row[recent_columns.visible_name] = **i2;
825                                 child_row[recent_columns.fullpath] = fullpath;
826                                 
827                                 delete *i2;
828                         }
829                 }
830
831                 delete states;
832         }
833         delete sessions;
834 }
835
836 void
837 NewSessionDialog::reset()
838 {
839         reset_name();
840         reset_template();
841         set_response_sensitive (Gtk::RESPONSE_NONE, false);
842 }