canvas items must be able to use fractional positions when rendering.
[ardour.git] / gtk2_ardour / session_dialog.cc
index 710833b8734c47e9a328783e79853463b9cc5f5e..27c5d0e4a0bbba2c0c7850d98832694d0216948a 100644 (file)
@@ -31,6 +31,7 @@
 #include "pbd/replace_all.h"
 #include "pbd/whitespace.h"
 #include "pbd/stacktrace.h"
+#include "pbd/stl_delete.h"
 #include "pbd/openuri.h"
 
 #include "ardour/audioengine.h"
@@ -54,6 +55,7 @@ using namespace Gdk;
 using namespace Glib;
 using namespace PBD;
 using namespace ARDOUR;
+using namespace ARDOUR_UI_UTILS;
 
 static string poor_mans_glob (string path)
 {
@@ -62,8 +64,8 @@ static string poor_mans_glob (string path)
        return copy;
 }
 
-SessionDialog::SessionDialog (bool require_new, const std::string& session_name, const std::string& session_path, const std::string& template_name)
-       : ArdourDialog (_("Session Setup"))
+SessionDialog::SessionDialog (bool require_new, const std::string& session_name, const std::string& session_path, const std::string& template_name, bool cancel_not_quit)
+       : ArdourDialog (_("Session Setup"), true, true)
        , new_only (require_new)
        , _provided_session_name (session_name)
        , _provided_session_path (session_path)
@@ -74,24 +76,21 @@ SessionDialog::SessionDialog (bool require_new, const std::string& session_name,
        , _master_bus_channel_count_adj (2, 0, 100, 1, 10, 0)
        , _existing_session_chooser_used (false)
 {
-       if (!session_name.empty() && !require_new) {
-               response (RESPONSE_OK);
-               return;
-       }
-
+#ifndef PLATFORM_WINDOWS
        set_keep_above (true);
+#endif
        set_position (WIN_POS_CENTER);
        get_vbox()->set_spacing (6);
 
-       string image_path;
+       cancel_button = add_button ((cancel_not_quit ? Stock::CANCEL : Stock::QUIT), RESPONSE_CANCEL);
+       back_button = add_button (Stock::GO_BACK, RESPONSE_NO);
+       open_button = add_button (Stock::OPEN, RESPONSE_ACCEPT);
+
+       back_button->signal_button_press_event().connect (sigc::mem_fun (*this, &SessionDialog::back_button_pressed), false);
+
+       open_button->set_sensitive (false);
+       back_button->set_sensitive (false);
 
-       if (find_file_in_search_path (ardour_data_search_path(), "small-splash.png", image_path)) {
-               Gtk::Image* image;
-               if ((image = manage (new Gtk::Image (image_path))) != 0) {
-                       get_vbox()->pack_start (*image, false, false);
-               }
-       }
-       
        /* this is where announcements will be displayed, but it may be empty
         * and invisible most of the time.
         */
@@ -117,16 +116,7 @@ SessionDialog::SessionDialog (bool require_new, const std::string& session_name,
        
        get_vbox()->show_all ();
 
-       cancel_button = add_button (Stock::QUIT, RESPONSE_CANCEL);
-       back_button = add_button (Stock::GO_BACK, RESPONSE_NO);
-       open_button = add_button (Stock::OPEN, RESPONSE_ACCEPT);
-
-       back_button->signal_button_press_event().connect (sigc::mem_fun (*this, &SessionDialog::back_button_pressed), false);
-
-       open_button->set_sensitive (false);
-       back_button->set_sensitive (false);
-
-       /* fill data models and how/hide accordingly */
+       /* fill data models and show/hide accordingly */
 
        populate_session_templates ();
 
@@ -152,12 +142,32 @@ SessionDialog::SessionDialog (bool require_new, const std::string& session_name,
                        recent_label.hide ();
                }
        }
+
+       /* possibly get out of here immediately if everything is ready to go.
+          We still need to set up the whole dialog because of the way
+          ARDOUR_UI::get_session_parameters() might skip it on a first
+          pass then require it for a second pass (e.g. when there
+          is an error with session loading and we have to ask the user
+          what to do next).
+        */
+
+       if (!session_name.empty() && !require_new) {
+               response (RESPONSE_OK);
+               return;
+       }
 }
 
 SessionDialog::~SessionDialog()
 {
 }
 
+void
+SessionDialog::clear_given ()
+{
+       _provided_session_path = "";
+       _provided_session_name = "";
+}
+
 bool
 SessionDialog::use_session_template ()
 {
@@ -194,6 +204,7 @@ std::string
 SessionDialog::session_name (bool& should_be_new)
 {
        if (!_provided_session_name.empty() && !new_only) {
+               should_be_new = false;
                return _provided_session_name;
        }
 
@@ -230,15 +241,21 @@ SessionDialog::session_folder ()
        TreeIter iter = recent_session_display.get_selection()->get_selected();
        
        if (iter) {
-               return (*iter)[recent_session_columns.fullpath];
+               string s = (*iter)[recent_session_columns.fullpath];
+               if (Glib::file_test (s, Glib::FILE_TEST_IS_REGULAR)) {
+                       return Glib::path_get_dirname (s);
+               }
+               return s;
        }
 
        if (_existing_session_chooser_used) {
                /* existing session chosen from file chooser */
-               return existing_session_chooser.get_current_folder ();
+               return Glib::path_get_dirname (existing_session_chooser.get_current_folder ());
        } else {
-               std::string legal_session_folder_name = legalize_for_path (new_name_entry.get_text());
-               return Glib::build_filename (new_folder_chooser.get_current_folder(), legal_session_folder_name);
+               std::string val = new_name_entry.get_text();
+               strip_whitespace_edges (val);
+               std::string legal_session_folder_name = legalize_for_path (val);
+               return Glib::build_filename (new_folder_chooser.get_filename (), legal_session_folder_name);
        }
 }
 
@@ -253,12 +270,30 @@ SessionDialog::setup_initial_choice_box ()
        centering_vbox->set_spacing (6);
 
        Label* new_label = manage (new Label);
-       new_label->set_markup (string_compose ("<span weight=\"bold\" size=\"large\">%1</span>", _("Create a new session")));
+       new_label->set_markup (string_compose ("<span weight=\"bold\" size=\"large\">%1</span>", _("New Session")));
+       new_label->set_justify (JUSTIFY_CENTER);
 
        ic_new_session_button.add (*new_label);
        ic_new_session_button.signal_clicked().connect (sigc::mem_fun (*this, &SessionDialog::new_session_button_clicked));
 
-       centering_vbox->pack_start (ic_new_session_button, false, false);
+       Gtk::HBox* hbox = manage (new HBox);
+       Gtk::VBox* vbox = manage (new VBox);
+       hbox->set_spacing (12);
+       vbox->set_spacing (12);
+
+       string image_path;
+
+       if (find_file (ardour_data_search_path(), "small-splash.png", image_path)) {
+               Gtk::Image* image;
+               if ((image = manage (new Gtk::Image (image_path))) != 0) {
+                       hbox->pack_start (*image, false, false);
+               }
+       }
+       
+       vbox->pack_start (ic_new_session_button, true, true, 20);
+       hbox->pack_start (*vbox, true, true, 20);
+       
+       centering_vbox->pack_start (*hbox, false, false);
 
        /* Possible update message */
 
@@ -270,8 +305,6 @@ SessionDialog::setup_initial_choice_box ()
 
                info_box->pack_start (info_scroller_label, false, false);
 
-               cerr << "Frame should be visible\n";
-
                info_scroller_count = 0;
                info_scroller_connection = Glib::signal_timeout().connect (mem_fun(*this, &SessionDialog::info_scroller_update), 50);
 
@@ -292,13 +325,14 @@ SessionDialog::setup_initial_choice_box ()
        recent_label.set_no_show_all (true);
        recent_scroller.set_no_show_all (true);
        
-       recent_label.set_markup (string_compose ("<span style=\"italic\" size=\"large\">%1</span>", _("... or load a recent session")));
-       recent_label.set_alignment (0, 0.5);
+       recent_label.set_markup (string_compose ("<span weight=\"bold\" size=\"large\">%1</span>", _("Recent Sessions")));
        
        recent_session_model = TreeStore::create (recent_session_columns);
        
        recent_session_display.set_model (recent_session_model);
        recent_session_display.append_column (_("Recent Sessions"), recent_session_columns.visible_name);
+       recent_session_display.append_column (_("Sample Rate"), recent_session_columns.sample_rate);
+       recent_session_display.append_column (_("Disk Format"), recent_session_columns.disk_format);
        recent_session_display.set_headers_visible (false);
        recent_session_display.get_selection()->set_mode (SELECTION_SINGLE);
        
@@ -312,7 +346,7 @@ SessionDialog::setup_initial_choice_box ()
        recent_session_display.signal_row_activated().connect (sigc::mem_fun (*this, &SessionDialog::recent_row_activated));
        
        centering_vbox->pack_start (recent_label, false, false, 12);
-       centering_vbox->pack_start (recent_scroller, false, true);
+       centering_vbox->pack_start (recent_scroller, true, true);
 
        /* Browse button */
        
@@ -321,7 +355,7 @@ SessionDialog::setup_initial_choice_box ()
        existing_session_chooser.set_current_folder(poor_mans_glob (Config->get_default_session_parent_dir()));
        
        FileFilter session_filter;
-       session_filter.add_pattern ("*.ardour");
+       session_filter.add_pattern (string_compose(X_("*%1"), ARDOUR::statefile_suffix));
        session_filter.set_name (string_compose (_("%1 sessions"), PROGRAM_NAME));
        existing_session_chooser.add_filter (session_filter);
        existing_session_chooser.set_filter (session_filter);
@@ -331,8 +365,7 @@ SessionDialog::setup_initial_choice_box ()
 #endif
        
        Label* browse_label = manage (new Label);
-       browse_label->set_markup (string_compose ("<span style=\"italic\" size=\"large\">%1</span>", _("... or browse for existing sessions")));
-       browse_label->set_alignment (0, 0.5);
+       browse_label->set_markup (string_compose ("<span weight=\"bold\" size=\"large\">%1</span>", _("Other Sessions")));
        
        centering_vbox->pack_start (*browse_label, false, false, 12);
        centering_vbox->pack_start (existing_session_chooser, false, false);
@@ -591,60 +624,114 @@ SessionDialog::redisplay_recent_sessions ()
 
                get_state_files_in_directory (*i, state_file_paths);
 
-               vector<string*>* states;
+               vector<string> states;
                vector<const gchar*> item;
-               string fullpath = *i;
+               string dirname = *i;
 
                /* remove any trailing / */
 
-               if (fullpath[fullpath.length()-1] == '/') {
-                       fullpath = fullpath.substr (0, fullpath.length()-1);
+               if (dirname[dirname.length()-1] == '/') {
+                       dirname = dirname.substr (0, dirname.length()-1);
                }
 
                /* check whether session still exists */
-               if (!Glib::file_test(fullpath.c_str(), Glib::FILE_TEST_EXISTS)) {
+               if (!Glib::file_test(dirname.c_str(), Glib::FILE_TEST_EXISTS)) {
                        /* session doesn't exist */
                        continue;
                }
 
                /* now get available states for this session */
 
-               if ((states = Session::possible_states (fullpath)) == 0) {
+               states = Session::possible_states (dirname);
+
+               if (states.empty()) {
                        /* no state file? */
                        continue;
                }
 
                std::vector<string> state_file_names(get_file_names_no_extension (state_file_paths));
 
+               if (state_file_names.empty()) {
+                       continue;
+               }
+
                Gtk::TreeModel::Row row = *(recent_session_model->append());
 
-               row[recent_session_columns.visible_name] = Glib::path_get_basename (fullpath);
-               row[recent_session_columns.fullpath] = fullpath;
-               row[recent_session_columns.tip] = Glib::Markup::escape_text (fullpath);
-               
+               float sr;
+               SampleFormat sf;
+               std::string state_file_basename = state_file_names.front();
+
+               std::string s = Glib::build_filename (dirname, state_file_basename + statefile_suffix);
+
+               row[recent_session_columns.fullpath] = dirname; /* just the dir, but this works too */
+               row[recent_session_columns.tip] = Glib::Markup::escape_text (dirname);
+
+               if (Session::get_info_from_path (s, sr, sf) == 0) {
+                       row[recent_session_columns.sample_rate] = rate_as_string (sr);
+                       switch (sf) {
+                       case FormatFloat:
+                               row[recent_session_columns.disk_format] = _("32 bit float");
+                               break;
+                       case FormatInt24:
+                               row[recent_session_columns.disk_format] = _("24 bit");
+                               break;
+                       case FormatInt16:
+                               row[recent_session_columns.disk_format] = _("16 bit");
+                               break;
+                       }
+               } else {
+                       row[recent_session_columns.sample_rate] = "??";
+                       row[recent_session_columns.disk_format] = "--";
+               }
+
                ++session_snapshot_count;
 
                if (state_file_names.size() > 1) {
+                       // multiple session files in the session directory - show the directory name.
+                       // if there's not a session file with the same name as the session directory,
+                       // opening the parent item will fail, but expanding it will show the session
+                       // files that actually exist, and the right one can then be opened.
+                       row[recent_session_columns.visible_name] = Glib::path_get_basename (dirname);
 
                        // add the children
-
-                       for (std::vector<std::string>::iterator i2 = state_file_names.begin();
-                                       i2 != state_file_names.end(); ++i2) {
+                       for (std::vector<std::string>::iterator i2 = state_file_names.begin(); i2 != state_file_names.end(); ++i2) {
 
                                Gtk::TreeModel::Row child_row = *(recent_session_model->append (row.children()));
-
+                               
                                child_row[recent_session_columns.visible_name] = *i2;
-                               child_row[recent_session_columns.fullpath] = fullpath;
-                               child_row[recent_session_columns.tip] = Glib::Markup::escape_text (fullpath);
+                               child_row[recent_session_columns.fullpath] = Glib::build_filename (dirname, *i2 + statefile_suffix);
+                               child_row[recent_session_columns.tip] = Glib::Markup::escape_text (dirname);
+                               
+                               if (Session::get_info_from_path (s, sr, sf) == 0) {
+                                       child_row[recent_session_columns.sample_rate] = rate_as_string (sr);
+                                       switch (sf) {
+                                       case FormatFloat:
+                                               child_row[recent_session_columns.disk_format] = _("32 bit float");
+                                               break;
+                                       case FormatInt24:
+                                               child_row[recent_session_columns.disk_format] = _("24 bit");
+                                               break;
+                                       case FormatInt16:
+                                               child_row[recent_session_columns.disk_format] = _("16 bit");
+                                               break;
+                                       }
+                               } else {
+                                       child_row[recent_session_columns.sample_rate] = "??";
+                                       child_row[recent_session_columns.disk_format] = "--";
+                               }
+                               
+
                                ++session_snapshot_count;
                        }
+               } else {
+                       // only a single session file in the directory - show its actual name.
+                       row[recent_session_columns.visible_name] = state_file_basename;
                }
        }
 
        recent_session_display.set_tooltip_column(1); // recent_session_columns.tip 
        recent_session_display.set_model (recent_session_model);
        return session_snapshot_count;
-       // return rs.size();
 }
 
 void
@@ -963,6 +1050,7 @@ void
 SessionDialog::existing_session_selected ()
 {
        _existing_session_chooser_used = true;
+       recent_session_display.get_selection()->unselect_all();
        /* mark this sensitive in case we come back here after a failed open
         * attempt and the user has hacked up the fix. sigh.
         */