2 Copyright (C) 2005 Paul Davis
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.
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.
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.
21 #include "new_session_dialog.h"
23 #include <pbd/error.h>
25 #include <ardour/recent_sessions.h>
26 #include <ardour/session_state_utils.h>
27 #include <ardour/template_utils.h>
28 #include <ardour/session.h>
29 #include <ardour/profile.h>
31 #include <gtkmm/entry.h>
32 #include <gtkmm/filechooserbutton.h>
33 #include <gtkmm/spinbutton.h>
34 #include <gtkmm/checkbutton.h>
35 #include <gtkmm/radiobutton.h>
36 #include <gtkmm/filefilter.h>
37 #include <gtkmm/stock.h>
38 #include <gdkmm/cursor.h>
40 #include <gtkmm2ext/window_title.h>
42 using namespace Gtkmm2ext;
44 using namespace ARDOUR;
49 NewSessionDialog::NewSessionDialog()
50 : ArdourDialog ("session control")
52 in_destructor = false;
53 session_name_label = Gtk::manage(new class Gtk::Label(_("Name :")));
54 m_name = Gtk::manage(new class Gtk::Entry());
55 m_name->set_text(ARDOUR_COMMAND_LINE::session_name);
57 chan_count_label_1 = Gtk::manage(new class Gtk::Label(_("channels")));
58 chan_count_label_2 = Gtk::manage(new class Gtk::Label(_("channels")));
59 chan_count_label_3 = Gtk::manage(new class Gtk::Label(_("channels")));
60 chan_count_label_4 = Gtk::manage(new class Gtk::Label(_("channels")));
62 chan_count_label_1->set_alignment(0,0.5);
63 chan_count_label_1->set_padding(0,0);
64 chan_count_label_1->set_line_wrap(false);
66 chan_count_label_2->set_alignment(0,0.5);
67 chan_count_label_2->set_padding(0,0);
68 chan_count_label_2->set_line_wrap(false);
70 chan_count_label_3->set_alignment(0,0.5);
71 chan_count_label_3->set_padding(0,0);
72 chan_count_label_3->set_line_wrap(false);
74 chan_count_label_4->set_alignment(0,0.5);
75 chan_count_label_4->set_padding(0,0);
76 chan_count_label_4->set_line_wrap(false);
78 bus_label = Gtk::manage(new class Gtk::Label(_("<b>Busses</b>")));
79 input_label = Gtk::manage(new class Gtk::Label(_("<b>Inputs</b>")));
80 output_label = Gtk::manage(new class Gtk::Label(_("<b>Outputs</b>")));
82 session_location_label = Gtk::manage(new class Gtk::Label(_("Create Folder In :")));
83 m_folder = Gtk::manage(new class Gtk::FileChooserButton(Gtk::FILE_CHOOSER_ACTION_SELECT_FOLDER));
84 session_template_label = Gtk::manage(new class Gtk::Label(_("Template :")));
85 m_template = Gtk::manage(new class Gtk::FileChooserButton());
86 m_create_control_bus = Gtk::manage(new class Gtk::CheckButton(_("Create Monitor Bus")));
88 Gtk::Adjustment *m_control_bus_channel_count_adj = Gtk::manage(new class Gtk::Adjustment(2, 0, 100, 1, 10, 10));
89 m_control_bus_channel_count = Gtk::manage(new class Gtk::SpinButton(*m_control_bus_channel_count_adj, 1, 0));
91 Gtk::Adjustment *m_master_bus_channel_count_adj = Gtk::manage(new class Gtk::Adjustment(2, 0, 100, 1, 10, 10));
92 m_master_bus_channel_count = Gtk::manage(new class Gtk::SpinButton(*m_master_bus_channel_count_adj, 1, 0));
93 m_create_master_bus = Gtk::manage(new class Gtk::CheckButton(_("Create Master Bus")));
94 advanced_table = Gtk::manage(new class Gtk::Table(2, 2, true));
95 m_connect_inputs = Gtk::manage(new class Gtk::CheckButton(_("Automatically Connect to Physical Inputs")));
96 m_limit_input_ports = Gtk::manage(new class Gtk::CheckButton(_("Use only")));
98 Gtk::Adjustment *m_input_limit_count_adj = Gtk::manage(new class Gtk::Adjustment(1, 0, 100, 1, 10, 10));
99 m_input_limit_count = Gtk::manage(new class Gtk::SpinButton(*m_input_limit_count_adj, 1, 0));
100 input_port_limit_hbox = Gtk::manage(new class Gtk::HBox(false, 0));
101 input_port_vbox = Gtk::manage(new class Gtk::VBox(false, 0));
102 input_table = Gtk::manage(new class Gtk::Table(2, 2, false));
104 bus_frame = Gtk::manage(new class Gtk::Frame());
105 bus_table = Gtk::manage (new Gtk::Table (2, 3, false));
107 input_frame = Gtk::manage(new class Gtk::Frame());
108 m_connect_outputs = Gtk::manage(new class Gtk::CheckButton(_("Automatically Connect Outputs")));
109 m_limit_output_ports = Gtk::manage(new class Gtk::CheckButton(_("Use only")));
111 Gtk::Adjustment *m_output_limit_count_adj = Gtk::manage(new class Gtk::Adjustment(1, 0, 100, 1, 10, 10));
112 m_output_limit_count = Gtk::manage(new class Gtk::SpinButton(*m_output_limit_count_adj, 1, 0));
113 output_port_limit_hbox = Gtk::manage(new class Gtk::HBox(false, 0));
114 output_port_vbox = Gtk::manage(new class Gtk::VBox(false, 0));
116 Gtk::RadioButton::Group _RadioBGroup_m_connect_outputs_to_master;
117 m_connect_outputs_to_master = Gtk::manage(new class Gtk::RadioButton(_RadioBGroup_m_connect_outputs_to_master, _("... to Master Bus")));
118 m_connect_outputs_to_physical = Gtk::manage(new class Gtk::RadioButton(_RadioBGroup_m_connect_outputs_to_master, _("... to Physical Outputs")));
119 output_conn_vbox = Gtk::manage(new class Gtk::VBox(false, 0));
120 output_vbox = Gtk::manage(new class Gtk::VBox(false, 0));
122 output_frame = Gtk::manage(new class Gtk::Frame());
123 advanced_vbox = Gtk::manage(new class Gtk::VBox(false, 0));
124 advanced_label = Gtk::manage(new class Gtk::Label(_("Advanced Options")));
125 advanced_expander = Gtk::manage(new class Gtk::Expander());
126 new_session_table = Gtk::manage(new class Gtk::Table(2, 2, false));
127 m_open_filechooser = Gtk::manage(new class Gtk::FileChooserButton());
128 open_session_hbox = Gtk::manage(new class Gtk::HBox(false, 0));
129 m_treeview = Gtk::manage(new class Gtk::TreeView());
130 recent_scrolledwindow = Gtk::manage(new class Gtk::ScrolledWindow());
132 recent_sesion_label = Gtk::manage(new class Gtk::Label(_("Recent:")));
133 recent_frame = Gtk::manage(new class Gtk::Frame());
134 open_session_vbox = Gtk::manage(new class Gtk::VBox(false, 0));
135 m_notebook = Gtk::manage(new class Gtk::Notebook());
136 session_name_label->set_alignment(0, 0.5);
137 session_name_label->set_padding(6,0);
138 session_name_label->set_line_wrap(false);
139 session_name_label->set_selectable(false);
140 m_name->set_editable(true);
141 m_name->set_max_length(0);
142 m_name->set_has_frame(true);
143 m_name->set_activates_default(true);
144 m_name->set_width_chars (40);
145 session_location_label->set_alignment(0,0.5);
146 session_location_label->set_padding(6,0);
147 session_location_label->set_line_wrap(false);
148 session_location_label->set_selectable(false);
149 session_template_label->set_alignment(0,0.5);
150 session_template_label->set_padding(6,0);
151 session_template_label->set_line_wrap(false);
152 session_template_label->set_selectable(false);
153 m_create_control_bus->set_flags(Gtk::CAN_FOCUS);
154 m_create_control_bus->set_relief(Gtk::RELIEF_NORMAL);
155 m_create_control_bus->set_mode(true);
156 m_create_control_bus->set_active(false);
157 m_create_control_bus->set_border_width(0);
158 m_control_bus_channel_count->set_flags(Gtk::CAN_FOCUS);
159 m_control_bus_channel_count->set_update_policy(Gtk::UPDATE_ALWAYS);
160 m_control_bus_channel_count->set_numeric(true);
161 m_control_bus_channel_count->set_digits(0);
162 m_control_bus_channel_count->set_wrap(false);
163 m_control_bus_channel_count->set_sensitive(false);
164 m_master_bus_channel_count->set_flags(Gtk::CAN_FOCUS);
165 m_master_bus_channel_count->set_update_policy(Gtk::UPDATE_ALWAYS);
166 m_master_bus_channel_count->set_numeric(true);
167 m_master_bus_channel_count->set_digits(0);
168 m_master_bus_channel_count->set_wrap(false);
169 open_session_file_label = Gtk::manage(new class Gtk::Label(_("Browse:")));
170 open_session_file_label->set_alignment(0, 0.5);
171 m_create_master_bus->set_flags(Gtk::CAN_FOCUS);
172 m_create_master_bus->set_relief(Gtk::RELIEF_NORMAL);
173 m_create_master_bus->set_mode(true);
174 m_create_master_bus->set_active(true);
175 m_create_master_bus->set_border_width(0);
176 advanced_table->set_row_spacings(0);
177 advanced_table->set_col_spacings(0);
179 m_connect_inputs->set_flags(Gtk::CAN_FOCUS);
180 m_connect_inputs->set_relief(Gtk::RELIEF_NORMAL);
181 m_connect_inputs->set_mode(true);
182 m_connect_inputs->set_active(true);
183 m_connect_inputs->set_border_width(0);
185 m_limit_input_ports->set_flags(Gtk::CAN_FOCUS);
186 m_limit_input_ports->set_relief(Gtk::RELIEF_NORMAL);
187 m_limit_input_ports->set_mode(true);
188 m_limit_input_ports->set_sensitive(true);
189 m_limit_input_ports->set_border_width(0);
190 m_input_limit_count->set_flags(Gtk::CAN_FOCUS);
191 m_input_limit_count->set_update_policy(Gtk::UPDATE_ALWAYS);
192 m_input_limit_count->set_numeric(true);
193 m_input_limit_count->set_digits(0);
194 m_input_limit_count->set_wrap(false);
195 m_input_limit_count->set_sensitive(false);
197 bus_hbox = Gtk::manage (new Gtk::HBox (false, 0));
198 bus_hbox->pack_start (*bus_table, Gtk::PACK_SHRINK, 18);
200 bus_label->set_alignment(0, 0.5);
201 bus_label->set_padding(0,0);
202 bus_label->set_line_wrap(false);
203 bus_label->set_selectable(false);
204 bus_label->set_use_markup(true);
205 bus_frame->set_shadow_type(Gtk::SHADOW_NONE);
206 bus_frame->set_label_align(0,0.5);
207 bus_frame->add(*bus_hbox);
208 bus_frame->set_label_widget(*bus_label);
210 bus_table->set_row_spacings (0);
211 bus_table->set_col_spacings (0);
212 bus_table->attach (*m_create_master_bus, 0, 1, 0, 1, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
213 bus_table->attach (*m_master_bus_channel_count, 1, 2, 0, 1, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
214 bus_table->attach (*chan_count_label_1, 2, 3, 0, 1, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 6, 0);
215 bus_table->attach (*m_create_control_bus, 0, 1, 1, 2, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
216 bus_table->attach (*m_control_bus_channel_count, 1, 2, 1, 2, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
217 bus_table->attach (*chan_count_label_2, 2, 3, 1, 2, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 6, 0);
219 input_port_limit_hbox->pack_start(*m_limit_input_ports, Gtk::PACK_SHRINK, 6);
220 input_port_limit_hbox->pack_start(*m_input_limit_count, Gtk::PACK_SHRINK, 0);
221 input_port_limit_hbox->pack_start(*chan_count_label_3, Gtk::PACK_SHRINK, 6);
222 input_port_vbox->pack_start(*m_connect_inputs, Gtk::PACK_SHRINK, 0);
223 input_port_vbox->pack_start(*input_port_limit_hbox, Gtk::PACK_EXPAND_PADDING, 0);
224 input_table->set_row_spacings(0);
225 input_table->set_col_spacings(0);
226 input_table->attach(*input_port_vbox, 0, 1, 0, 1, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 6, 6);
228 input_hbox = Gtk::manage (new Gtk::HBox (false, 0));
229 input_hbox->pack_start (*input_table, Gtk::PACK_SHRINK, 18);
231 input_label->set_alignment(0, 0.5);
232 input_label->set_padding(0,0);
233 input_label->set_line_wrap(false);
234 input_label->set_selectable(false);
235 input_label->set_use_markup(true);
236 input_frame->set_shadow_type(Gtk::SHADOW_NONE);
237 input_frame->set_label_align(0,0.5);
238 input_frame->add(*input_hbox);
239 input_frame->set_label_widget(*input_label);
241 m_connect_outputs->set_flags(Gtk::CAN_FOCUS);
242 m_connect_outputs->set_relief(Gtk::RELIEF_NORMAL);
243 m_connect_outputs->set_mode(true);
244 m_connect_outputs->set_active(true);
245 m_connect_outputs->set_border_width(0);
246 m_limit_output_ports->set_flags(Gtk::CAN_FOCUS);
247 m_limit_output_ports->set_relief(Gtk::RELIEF_NORMAL);
248 m_limit_output_ports->set_mode(true);
249 m_limit_output_ports->set_sensitive(true);
250 m_limit_output_ports->set_border_width(0);
251 m_output_limit_count->set_flags(Gtk::CAN_FOCUS);
252 m_output_limit_count->set_update_policy(Gtk::UPDATE_ALWAYS);
253 m_output_limit_count->set_numeric(false);
254 m_output_limit_count->set_digits(0);
255 m_output_limit_count->set_wrap(false);
256 m_output_limit_count->set_sensitive(false);
257 output_port_limit_hbox->pack_start(*m_limit_output_ports, Gtk::PACK_SHRINK, 6);
258 output_port_limit_hbox->pack_start(*m_output_limit_count, Gtk::PACK_SHRINK, 0);
259 output_port_limit_hbox->pack_start(*chan_count_label_4, Gtk::PACK_SHRINK, 6);
260 m_connect_outputs_to_master->set_flags(Gtk::CAN_FOCUS);
261 m_connect_outputs_to_master->set_relief(Gtk::RELIEF_NORMAL);
262 m_connect_outputs_to_master->set_mode(true);
263 m_connect_outputs_to_master->set_active(false);
264 m_connect_outputs_to_master->set_border_width(0);
265 m_connect_outputs_to_physical->set_flags(Gtk::CAN_FOCUS);
266 m_connect_outputs_to_physical->set_relief(Gtk::RELIEF_NORMAL);
267 m_connect_outputs_to_physical->set_mode(true);
268 m_connect_outputs_to_physical->set_active(false);
269 m_connect_outputs_to_physical->set_border_width(0);
270 output_conn_vbox->pack_start(*m_connect_outputs, Gtk::PACK_SHRINK, 0);
271 output_conn_vbox->pack_start(*m_connect_outputs_to_master, Gtk::PACK_SHRINK, 0);
272 output_conn_vbox->pack_start(*m_connect_outputs_to_physical, Gtk::PACK_SHRINK, 0);
273 output_vbox->set_border_width(6);
275 output_port_vbox->pack_start(*output_port_limit_hbox, Gtk::PACK_SHRINK, 0);
277 output_vbox->pack_start(*output_conn_vbox);
278 output_vbox->pack_start(*output_port_vbox);
280 output_label->set_alignment(0, 0.5);
281 output_label->set_padding(0,0);
282 output_label->set_line_wrap(false);
283 output_label->set_selectable(false);
284 output_label->set_use_markup(true);
285 output_frame->set_shadow_type(Gtk::SHADOW_NONE);
286 output_frame->set_label_align(0,0.5);
288 output_hbox = Gtk::manage (new Gtk::HBox (false, 0));
289 output_hbox->pack_start (*output_vbox, Gtk::PACK_SHRINK, 18);
291 output_frame->add(*output_hbox);
292 output_frame->set_label_widget(*output_label);
294 advanced_vbox->pack_start(*advanced_table, Gtk::PACK_SHRINK, 0);
295 advanced_vbox->pack_start(*bus_frame, Gtk::PACK_SHRINK, 6);
296 advanced_vbox->pack_start(*input_frame, Gtk::PACK_SHRINK, 6);
297 advanced_vbox->pack_start(*output_frame, Gtk::PACK_SHRINK, 0);
298 advanced_label->set_padding(0,0);
299 advanced_label->set_line_wrap(false);
300 advanced_label->set_selectable(false);
301 advanced_label->set_alignment(0, 0.5);
302 advanced_expander->set_flags(Gtk::CAN_FOCUS);
303 advanced_expander->set_border_width(0);
304 advanced_expander->set_expanded(false);
305 advanced_expander->set_spacing(0);
306 advanced_expander->add(*advanced_vbox);
307 advanced_expander->set_label_widget(*advanced_label);
308 new_session_table->set_border_width(12);
309 new_session_table->set_row_spacings(6);
310 new_session_table->set_col_spacings(0);
311 new_session_table->attach(*session_name_label, 0, 1, 0, 1, Gtk::FILL, Gtk::FILL, 0, 0);
312 new_session_table->attach(*m_name, 1, 2, 0, 1, Gtk::EXPAND|Gtk::FILL, Gtk::FILL, 0, 0);
313 new_session_table->attach(*session_location_label, 0, 1, 1, 2, Gtk::FILL, Gtk::FILL, 0, 0);
314 new_session_table->attach(*m_folder, 1, 2, 1, 2, Gtk::EXPAND|Gtk::FILL, Gtk::FILL, 0, 0);
315 new_session_table->attach(*session_template_label, 0, 1, 2, 3, Gtk::FILL, Gtk::FILL, 0, 0);
316 new_session_table->attach(*m_template, 1, 2, 2, 3, Gtk::EXPAND|Gtk::FILL, Gtk::FILL, 0, 0);
318 if (!ARDOUR::Profile->get_sae()) {
319 new_session_table->attach(*advanced_expander, 0, 2, 3, 4, Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 6);
322 open_session_hbox->pack_start(*open_session_file_label, false, false, 12);
323 open_session_hbox->pack_start(*m_open_filechooser, true, true, 12);
324 m_treeview->set_flags(Gtk::CAN_FOCUS);
325 m_treeview->set_headers_visible(true);
326 m_treeview->set_rules_hint(false);
327 m_treeview->set_reorderable(false);
328 m_treeview->set_enable_search(true);
329 m_treeview->set_fixed_height_mode(false);
330 m_treeview->set_hover_selection(false);
331 m_treeview->set_size_request(-1, 150);
332 recent_scrolledwindow->set_flags(Gtk::CAN_FOCUS);
333 recent_scrolledwindow->set_border_width(6);
334 recent_scrolledwindow->set_shadow_type(Gtk::SHADOW_IN);
335 recent_scrolledwindow->set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
336 recent_scrolledwindow->property_window_placement().set_value(Gtk::CORNER_TOP_LEFT);
337 recent_scrolledwindow->add(*m_treeview);
339 recent_sesion_label->set_padding(0,0);
340 recent_sesion_label->set_line_wrap(false);
341 recent_sesion_label->set_selectable(false);
342 recent_frame->set_border_width(12);
343 recent_frame->set_shadow_type(Gtk::SHADOW_NONE);
344 recent_frame->add(*recent_scrolledwindow);
345 recent_frame->set_label_widget(*recent_sesion_label);
346 open_session_vbox->pack_start(*recent_frame, Gtk::PACK_EXPAND_WIDGET, 0);
347 open_session_vbox->pack_start(*open_session_hbox, Gtk::PACK_SHRINK, 12);
348 m_notebook->set_flags(Gtk::CAN_FOCUS);
349 m_notebook->set_scrollable(true);
350 get_vbox()->set_homogeneous(false);
351 get_vbox()->set_spacing(0);
352 get_vbox()->pack_start(*m_notebook, Gtk::PACK_SHRINK, 0);
355 icon setting is done again in the editor (for the whole app),
356 but its all chickens and eggs at this point.
359 list<Glib::RefPtr<Gdk::Pixbuf> > window_icons;
360 Glib::RefPtr<Gdk::Pixbuf> icon;
362 if ((icon = ::get_icon ("ardour_icon_16px")) != 0) {
363 window_icons.push_back (icon);
365 if ((icon = ::get_icon ("ardour_icon_22px")) != 0) {
366 window_icons.push_back (icon);
368 if ((icon = ::get_icon ("ardour_icon_32px")) != 0) {
369 window_icons.push_back (icon);
371 if ((icon = ::get_icon ("ardour_icon_48px")) != 0) {
372 window_icons.push_back (icon);
374 if (!window_icons.empty()) {
375 set_icon_list (window_icons);
378 WindowTitle title(Glib::get_application_name());
379 title += _("Session Control");
380 set_title(title.get_string());
383 //property_window_position().set_value(Gtk::WIN_POS_NONE);
384 set_resizable(false);
385 //property_destroy_with_parent().set_value(false);
386 set_has_separator(false);
387 // add_button(Gtk::Stock::HELP, Gtk::RESPONSE_HELP);
388 add_button(Gtk::Stock::QUIT, Gtk::RESPONSE_CANCEL);
389 add_button(Gtk::Stock::CLEAR, Gtk::RESPONSE_NONE);
390 m_okbutton = add_button(Gtk::Stock::NEW, Gtk::RESPONSE_OK);
392 recent_model = Gtk::TreeStore::create (recent_columns);
393 m_treeview->set_model (recent_model);
394 m_treeview->append_column (_("Recent Sessions"), recent_columns.visible_name);
395 m_treeview->set_headers_visible (false);
396 m_treeview->get_selection()->set_mode (Gtk::SELECTION_SINGLE);
398 if (is_directory (user_template_directory ()))
400 m_template->set_current_folder (user_template_directory().to_string());
402 else if (is_directory (system_template_directory ()))
404 m_template->set_current_folder (system_template_directory().to_string());
407 if (is_directory (system_template_directory ()))
409 m_template->add_shortcut_folder (system_template_directory().to_string());
412 m_template->set_title(_("select template"));
413 Gtk::FileFilter* session_filter = manage (new (Gtk::FileFilter));
414 session_filter->add_pattern(X_("*.ardour"));
415 session_filter->add_pattern(X_("*.ardour.bak"));
416 m_open_filechooser->set_filter (*session_filter);
417 m_open_filechooser->set_current_folder(getenv ("HOME"));
418 m_open_filechooser->set_title(_("select session file"));
420 Gtk::FileFilter* template_filter = manage (new (Gtk::FileFilter));
421 template_filter->add_pattern(X_("*.template"));
422 m_template->set_filter (*template_filter);
424 m_folder->set_current_folder(getenv ("HOME"));
425 m_folder->set_title(_("select directory"));
427 m_notebook->set_current_page(0);
429 m_notebook->show_all_children();
432 set_default_response (Gtk::RESPONSE_OK);
433 if (!ARDOUR_COMMAND_LINE::session_name.length()) {
434 set_response_sensitive (Gtk::RESPONSE_OK, false);
435 set_response_sensitive (Gtk::RESPONSE_NONE, false);
437 set_response_sensitive (Gtk::RESPONSE_OK, true);
438 set_response_sensitive (Gtk::RESPONSE_NONE, true);
441 ///@ connect some signals
443 m_connect_inputs->signal_clicked().connect (mem_fun (*this, &NewSessionDialog::connect_inputs_clicked));
444 m_connect_outputs->signal_clicked().connect (mem_fun (*this, &NewSessionDialog::connect_outputs_clicked));
445 m_limit_input_ports->signal_clicked().connect (mem_fun (*this, &NewSessionDialog::limit_inputs_clicked));
446 m_limit_output_ports->signal_clicked().connect (mem_fun (*this, &NewSessionDialog::limit_outputs_clicked));
447 m_create_master_bus->signal_clicked().connect (mem_fun (*this, &NewSessionDialog::master_bus_button_clicked));
448 m_create_control_bus->signal_clicked().connect (mem_fun (*this, &NewSessionDialog::monitor_bus_button_clicked));
449 m_name->signal_changed().connect(mem_fun (*this, &NewSessionDialog::on_new_session_name_entry_changed));
450 m_notebook->signal_switch_page().connect (mem_fun (*this, &NewSessionDialog::notebook_page_changed));
451 m_treeview->get_selection()->signal_changed().connect (mem_fun (*this, &NewSessionDialog::treeview_selection_changed));
452 m_treeview->signal_row_activated().connect (mem_fun (*this, &NewSessionDialog::recent_row_activated));
453 m_open_filechooser->signal_selection_changed ().connect (mem_fun (*this, &NewSessionDialog::file_chosen));
454 m_template->signal_selection_changed ().connect (mem_fun (*this, &NewSessionDialog::template_chosen));
456 page_set = Pages (0);
459 NewSessionDialog::~NewSessionDialog()
461 in_destructor = true;
465 NewSessionDialog::run ()
468 /* nothing to display */
469 return Gtk::RESPONSE_OK;
472 return ArdourDialog::run ();
476 NewSessionDialog::set_have_engine (bool yn)
479 m_notebook->remove_page (engine_control);
480 page_set = Pages (page_set & ~EnginePage);
482 if (!(page_set & EnginePage)) {
483 m_notebook->append_page (engine_control, _("Audio Setup"));
484 m_notebook->show_all_children();
485 page_set = Pages (page_set | EnginePage);
492 NewSessionDialog::set_existing_session (bool yn)
496 if (page_set & NewPage) {
497 m_notebook->remove_page (*new_session_table);
498 page_set = Pages (page_set & ~NewPage);
501 if (page_set & OpenPage) {
502 m_notebook->remove_page (*open_session_vbox);
503 page_set = Pages (page_set & ~OpenPage);
507 if (!(page_set & NewPage)) {
508 m_notebook->append_page(*new_session_table, _("New Session"));
509 m_notebook->pages().back().set_tab_label_packing(false, true, Gtk::PACK_START);
510 page_set = Pages (page_set | NewPage);
512 if (!(page_set & OpenPage)) {
513 m_notebook->append_page(*open_session_vbox, _("Open Session"));
514 m_notebook->pages().back().set_tab_label_packing(false, true, Gtk::PACK_START);
515 page_set = Pages (page_set | OpenPage);
518 m_notebook->show_all_children();
523 NewSessionDialog::set_session_name (const Glib::ustring& name)
525 m_name->set_text (name);
529 NewSessionDialog::set_session_folder(const Glib::ustring& dir)
531 Glib::ustring realdir = dir;
534 /* this little tangled mess is a result of 4 things:
536 1) GtkFileChooser vomits when given a non-absolute directory
537 argument to set_current_folder()
538 2) canonicalize_file_name() doesn't exist on OS X
539 3) linux man page for realpath() says "do not use this function"
540 4) canonicalize_file_name() & realpath() have entirely
541 different semantics on OS X and Linux when given
544 as result of all this, we take two distinct pathways through the code.
552 if((res = realpath (dir.c_str(), buf)) != 0) {
553 if (!Glib::file_test (dir, Glib::FILE_TEST_IS_DIR)) {
554 realdir = Glib::path_get_dirname (realdir);
556 m_folder->set_current_folder (realdir);
561 if (!Glib::file_test (dir, Glib::FILE_TEST_IS_DIR)) {
562 realdir = Glib::path_get_dirname (realdir);
563 cerr << "didn't exist, use " << realdir << endl;
566 if ((res = canonicalize_file_name (realdir.c_str())) != 0) {
567 cerr << "canonical, use " << res << endl;
568 m_folder->set_current_folder (res);
577 NewSessionDialog::session_name() const
579 std::string str = Glib::filename_from_utf8(m_open_filechooser->get_filename());
580 std::string::size_type position = str.find_last_of ('/');
581 str = str.substr (position+1);
582 position = str.find_last_of ('.');
583 str = str.substr (0, position);
586 XXX what to do if it's a .bak file?
587 load_session doesn't allow it!
589 if ((position = str.rfind(".bak")) != string::npos) {
590 str = str.substr (0, position);
594 switch (which_page()) {
597 /* new or audio setup pages */
598 return Glib::filename_from_utf8(m_name->get_text());
603 if (m_treeview->get_selection()->count_selected_rows() == 0) {
604 return Glib::filename_from_utf8(str);
606 Gtk::TreeModel::iterator i = m_treeview->get_selection()->get_selected();
607 return (*i)[recent_columns.visible_name];
611 NewSessionDialog::session_folder() const
613 switch (which_page()) {
615 return Glib::filename_from_utf8(m_folder->get_filename());
618 if (page_set == EnginePage) {
619 /* just engine page, nothing else : use m_folder since it should be set */
620 return Glib::filename_from_utf8(m_folder->get_filename());
628 if (m_treeview->get_selection()->count_selected_rows() == 0) {
629 const string filename(Glib::filename_from_utf8(m_open_filechooser->get_filename()));
630 return Glib::path_get_dirname(filename);
633 Gtk::TreeModel::iterator i = m_treeview->get_selection()->get_selected();
634 return (*i)[recent_columns.fullpath];
638 NewSessionDialog::use_session_template() const
640 if (m_template->get_filename().empty() && (which_page() == NewPage))
646 NewSessionDialog::session_template_name() const
648 return Glib::filename_from_utf8(m_template->get_filename());
652 NewSessionDialog::create_master_bus() const
654 return m_create_master_bus->get_active();
658 NewSessionDialog::master_channel_count() const
660 return m_master_bus_channel_count->get_value_as_int();
664 NewSessionDialog::create_control_bus() const
666 return m_create_control_bus->get_active();
670 NewSessionDialog::control_channel_count() const
672 return m_control_bus_channel_count->get_value_as_int();
676 NewSessionDialog::connect_inputs() const
678 return m_connect_inputs->get_active();
682 NewSessionDialog::limit_inputs_used_for_connection() const
684 return m_limit_input_ports->get_active();
688 NewSessionDialog::input_limit_count() const
690 return m_input_limit_count->get_value_as_int();
694 NewSessionDialog::connect_outputs() const
696 return m_connect_outputs->get_active();
700 NewSessionDialog::limit_outputs_used_for_connection() const
702 return m_limit_output_ports->get_active();
706 NewSessionDialog::output_limit_count() const
708 return m_output_limit_count->get_value_as_int();
712 NewSessionDialog::connect_outs_to_master() const
714 return m_connect_outputs_to_master->get_active();
718 NewSessionDialog::connect_outs_to_physical() const
720 return m_connect_outputs_to_physical->get_active();
724 NewSessionDialog::get_current_page()
726 return m_notebook->get_current_page();
729 NewSessionDialog::Pages
730 NewSessionDialog::which_page () const
732 int num = m_notebook->get_current_page();
734 if (page_set == NewPage) {
737 } else if (page_set == OpenPage) {
740 } else if (page_set == EnginePage) {
743 } else if (page_set == NewPage|OpenPage) {
751 } else if (page_set == NewPage|EnginePage) {
759 } else if (page_set == NewPage|EnginePage|OpenPage) {
769 } else if (page_set == OpenPage|EnginePage) {
780 NewSessionDialog::set_current_page(int page)
782 return m_notebook->set_current_page (page);
786 NewSessionDialog::reset_name()
788 m_name->set_text("");
789 set_response_sensitive (Gtk::RESPONSE_OK, false);
793 NewSessionDialog::on_new_session_name_entry_changed ()
795 if (m_name->get_text() != "") {
796 set_response_sensitive (Gtk::RESPONSE_OK, true);
797 set_response_sensitive (Gtk::RESPONSE_NONE, true);
799 set_response_sensitive (Gtk::RESPONSE_OK, false);
804 NewSessionDialog::notebook_page_changed (GtkNotebookPage* np, uint pagenum)
810 switch (which_page()) {
812 on_new_session_page = false;
813 m_okbutton->set_label(_("Open"));
814 m_okbutton->set_image (*(manage (new Gtk::Image (Gtk::Stock::OPEN, Gtk::ICON_SIZE_BUTTON))));
815 set_response_sensitive (Gtk::RESPONSE_NONE, false);
816 if (m_treeview->get_selection()->count_selected_rows() == 0) {
817 set_response_sensitive (Gtk::RESPONSE_OK, false);
819 set_response_sensitive (Gtk::RESPONSE_OK, true);
824 on_new_session_page = false;
825 m_okbutton->set_label(_("Open"));
826 m_okbutton->set_image (*(manage (new Gtk::Image (Gtk::Stock::OPEN, Gtk::ICON_SIZE_BUTTON))));
827 set_response_sensitive (Gtk::RESPONSE_NONE, false);
828 set_response_sensitive (Gtk::RESPONSE_OK, true);
832 on_new_session_page = true;
833 m_okbutton->set_label(_("New"));
834 m_okbutton->set_image (*(new Gtk::Image (Gtk::Stock::NEW, Gtk::ICON_SIZE_BUTTON)));
835 if (m_name->get_text() == "") {
836 set_response_sensitive (Gtk::RESPONSE_OK, false);
837 m_name->grab_focus();
839 set_response_sensitive (Gtk::RESPONSE_OK, true);
845 NewSessionDialog::treeview_selection_changed ()
847 if (m_treeview->get_selection()->count_selected_rows() == 0) {
848 if (!m_open_filechooser->get_filename().empty()) {
849 set_response_sensitive (Gtk::RESPONSE_OK, true);
851 set_response_sensitive (Gtk::RESPONSE_OK, false);
854 set_response_sensitive (Gtk::RESPONSE_OK, true);
859 NewSessionDialog::file_chosen ()
861 switch (which_page()) {
869 m_treeview->get_selection()->unselect_all();
871 Glib::RefPtr<Gdk::Window> win (get_window());
874 win->set_cursor(Gdk::Cursor(Gdk::WATCH));
877 if (!m_open_filechooser->get_filename().empty()) {
878 set_response_sensitive (Gtk::RESPONSE_OK, true);
879 response (Gtk::RESPONSE_OK);
881 set_response_sensitive (Gtk::RESPONSE_OK, false);
886 NewSessionDialog::template_chosen ()
888 if (m_template->get_filename() != "" ) {;
889 set_response_sensitive (Gtk::RESPONSE_NONE, true);
891 set_response_sensitive (Gtk::RESPONSE_NONE, false);
896 NewSessionDialog::recent_row_activated (const Gtk::TreePath& path, Gtk::TreeViewColumn* col)
898 response (Gtk::RESPONSE_YES);
902 NewSessionDialog::connect_inputs_clicked ()
904 m_limit_input_ports->set_sensitive(m_connect_inputs->get_active());
906 if (m_connect_inputs->get_active() && m_limit_input_ports->get_active()) {
907 m_input_limit_count->set_sensitive(true);
909 m_input_limit_count->set_sensitive(false);
914 NewSessionDialog::connect_outputs_clicked ()
916 m_limit_output_ports->set_sensitive(m_connect_outputs->get_active());
918 if (m_connect_outputs->get_active() && m_limit_output_ports->get_active()) {
919 m_output_limit_count->set_sensitive(true);
921 m_output_limit_count->set_sensitive(false);
926 NewSessionDialog::limit_inputs_clicked ()
928 m_input_limit_count->set_sensitive(m_limit_input_ports->get_active());
932 NewSessionDialog::limit_outputs_clicked ()
934 m_output_limit_count->set_sensitive(m_limit_output_ports->get_active());
938 NewSessionDialog::master_bus_button_clicked ()
940 m_master_bus_channel_count->set_sensitive(m_create_master_bus->get_active());
944 NewSessionDialog::monitor_bus_button_clicked ()
946 m_control_bus_channel_count->set_sensitive(m_create_control_bus->get_active());
950 NewSessionDialog::reset_template()
952 m_template->unselect_all ();
956 NewSessionDialog::reset_recent()
958 std::vector<sys::path> session_directories;
959 RecentSessionsSorter cmp;
961 recent_model->clear ();
963 ARDOUR::RecentSessions rs;
964 ARDOUR::read_recent_sessions (rs);
966 // sort them alphabetically
967 sort (rs.begin(), rs.end(), cmp);
969 for (ARDOUR::RecentSessions::iterator i = rs.begin(); i != rs.end(); ++i) {
970 session_directories.push_back ((*i).second);
973 for (vector<sys::path>::const_iterator i = session_directories.begin();
974 i != session_directories.end(); ++i)
976 std::vector<sys::path> state_file_paths;
978 // now get available states for this session
980 get_state_files_in_directory (*i, state_file_paths);
982 if (state_file_paths.empty()) {
987 std::vector<string> state_file_names(get_file_names_no_extension (state_file_paths));
989 Gtk::TreeModel::Row row = *(recent_model->append());
991 const string fullpath = (*i).to_string();
993 row[recent_columns.visible_name] = Glib::path_get_basename (fullpath);
994 row[recent_columns.fullpath] = fullpath;
996 if (state_file_names.size() > 1) {
1000 for (std::vector<std::string>::iterator i2 = state_file_names.begin();
1001 i2 != state_file_names.end(); ++i2)
1004 Gtk::TreeModel::Row child_row = *(recent_model->append (row.children()));
1006 child_row[recent_columns.visible_name] = *i2;
1007 child_row[recent_columns.fullpath] = fullpath;
1014 NewSessionDialog::reset()
1018 set_response_sensitive (Gtk::RESPONSE_NONE, false);