try to make NewSessionDialog only show up when really needed, and only have necessary...
[ardour.git] / libs / ardour / session_state.cc
index efd2d180f284232d59dced08d0225ff5e802dd5f..fd2c9fa98285b747f537e5174537f3c0f75f8b5f 100644 (file)
@@ -117,6 +117,9 @@ Session::first_stage_init (string fullpath, string snapshot_name)
                _path += '/';
        }
 
+       set_history_depth (Config->get_history_depth());
+       
+
        /* these two are just provisional settings. set_state()
           will likely override them.
        */
@@ -135,6 +138,7 @@ Session::first_stage_init (string fullpath, string snapshot_name)
        transport_sub_state = 0;
        _transport_frame = 0;
        last_stop_frame = 0;
+       requested_return_frame = -1;
        end_location = new Location (0, 0, _("end"), Location::Flags ((Location::IsMark|Location::IsEnd)));
        start_location = new Location (0, 0, _("start"), Location::Flags ((Location::IsMark|Location::IsStart)));
        _end_location_is_free = true;
@@ -161,6 +165,7 @@ Session::first_stage_init (string fullpath, string snapshot_name)
        _worst_track_latency = 0;
        _state_of_the_state = StateOfTheState(CannotSave|InitialConnecting|Loading|Deletion);
        _slave = 0;
+       _silent = false;
        butler_mixdown_buffer = 0;
        butler_gain_buffer = 0;
        mmc = 0;
@@ -452,7 +457,7 @@ Session::setup_raid_path (string path)
 }
 
 int
-Session::create (bool& new_session, string* mix_template, nframes_t initial_length)
+Session::create (bool& new_session, const string& mix_template, nframes_t initial_length)
 {
        string dir;
 
@@ -497,8 +502,8 @@ Session::create (bool& new_session, string* mix_template, nframes_t initial_leng
 
        /* check new_session so we don't overwrite an existing one */
 
-       if (mix_template) {
-               std::string in_path = *mix_template;
+       if (!mix_template.empty()) {
+               std::string in_path = mix_template;
 
                ifstream in(in_path.c_str());
 
@@ -689,7 +694,7 @@ Session::save_state (string snapshot_name, bool pending)
        tmp_path += snapshot_name;
        tmp_path += ".tmp";
 
-       cerr << "actually writing state to " << xml_path << endl;
+       // cerr << "actually writing state to " << xml_path << endl;
 
        if (!tree.write (tmp_path)) {
                error << string_compose (_("state could not be saved to %1"), tmp_path) << endmsg;
@@ -814,13 +819,17 @@ Session::load_state (string snapshot_name)
                backup_path += "-1";
                backup_path += _statefile_suffix;
 
-               info << string_compose (_("Copying old session file %1 to %2\nUse %2 with Ardour versions before 2.0 from now on"),
-                                       xmlpath, backup_path) 
-                    << endmsg;
-
-               copy_file (xmlpath, backup_path);
+               /* don't make another copy if it already exists */
 
-               /* if it fails, don't worry. right? */
+               if (!Glib::file_test (backup_path, Glib::FILE_TEST_EXISTS)) {
+                       info << string_compose (_("Copying old session file %1 to %2\nUse %2 with Ardour versions before 2.0 from now on"),
+                                               xmlpath, backup_path) 
+                            << endmsg;
+                       
+                       copy_file (xmlpath, backup_path);
+                       
+                       /* if it fails, don't worry. right? */
+               }
        }
 
        return 0;
@@ -895,7 +904,7 @@ Session::state(bool full_state)
        // store libardour version, just in case
        char buf[16];
        snprintf(buf, sizeof(buf)-1, "%d.%d.%d", 
-                libardour_major_version, libardour_minor_version, libardour_micro_version);
+                libardour2_major_version, libardour2_minor_version, libardour2_micro_version);
        node->add_property("version", string(buf));
                
        /* store configuration settings */
@@ -1391,6 +1400,7 @@ Session::XMLRegionFactory (const XMLNode& node, bool full)
        boost::shared_ptr<Source> source;
        boost::shared_ptr<AudioSource> as;
        SourceList sources;
+       SourceList master_sources;
        uint32_t nchans = 1;
        char buf[128];
        
@@ -1451,7 +1461,27 @@ Session::XMLRegionFactory (const XMLNode& node, bool full)
                        sources.push_back (as);
                }
        }
-       
+
+       for (uint32_t n=0; n < nchans; ++n) {
+               snprintf (buf, sizeof(buf), X_("master-source-%d"), n);
+               if ((prop = node.property (buf)) != 0) {
+               
+                       PBD::ID id2 (prop->value());
+                       
+                       if ((source = source_by_id (id2)) == 0) {
+                               error << string_compose(_("Session: XMLNode describing a AudioRegion references an unknown source id =%1"), id2) << endmsg;
+                               return boost::shared_ptr<AudioRegion>();
+                       }
+                       
+                       as = boost::dynamic_pointer_cast<AudioSource>(source);
+                       if (!as) {
+                               error << string_compose(_("Session: XMLNode describing a AudioRegion references a non-audio source id =%1"), id2) << endmsg;
+                               return boost::shared_ptr<AudioRegion>();
+                       }
+                       master_sources.push_back (as);
+               } 
+       }
+
        try {
                boost::shared_ptr<AudioRegion> region (boost::dynamic_pointer_cast<AudioRegion> (RegionFactory::create (sources, node)));
 
@@ -1466,6 +1496,13 @@ Session::XMLRegionFactory (const XMLNode& node, bool full)
                        }
                }
 
+               if (!master_sources.empty()) {
+                       if (master_sources.size() != nchans) {
+                               error << _("Session: XMLNode describing an AudioRegion is missing some master sources; ignored") << endmsg;
+                       } else {
+                               region->set_master_sources (master_sources);
+                       }
+               }
 
                return region;
                                                       
@@ -2975,7 +3012,6 @@ Session::add_instant_xml (XMLNode& node, const std::string& dir)
        Config->add_instant_xml (node, get_user_ardour_path());
 }
 
-
 int 
 Session::save_history (string snapshot_name)
 {
@@ -2983,8 +3019,6 @@ Session::save_history (string snapshot_name)
     string xml_path;
     string bak_path;
 
-    tree.set_root (&_history.get_state (Config->get_saved_history_depth()));
-
     if (snapshot_name.empty()) {
        snapshot_name = _current_snapshot_name;
     }
@@ -2993,13 +3027,17 @@ Session::save_history (string snapshot_name)
 
     bak_path = xml_path + ".bak";
 
-    if ((access (xml_path.c_str(), F_OK) == 0) &&
-        (rename (xml_path.c_str(), bak_path.c_str())))
-    {
+    if (Glib::file_test (xml_path, Glib::FILE_TEST_EXISTS) && ::rename (xml_path.c_str(), bak_path.c_str())) {
         error << _("could not backup old history file, current history not saved.") << endmsg;
         return -1;
     }
 
+    if (!Config->get_save_history() || Config->get_saved_history_depth() < 0) {
+           return 0;
+    }
+
+    tree.set_root (&_history.get_state (Config->get_saved_history_depth()));
+
     if (!tree.write (xml_path))
     {
         error << string_compose (_("history could not be saved to %1"), xml_path) << endmsg;
@@ -3037,8 +3075,7 @@ Session::restore_history (string snapshot_name)
     xmlpath = _path + snapshot_name + ".history";
     cerr << string_compose(_("Loading history from '%1'."), xmlpath) << endmsg;
 
-    if (access (xmlpath.c_str(), F_OK)) {
-           info << string_compose (_("%1: no history file \"%2\" for this session."), _name, xmlpath) << endmsg;
+    if (!Glib::file_test (xmlpath, Glib::FILE_TEST_EXISTS)) {
            return 1;
     }
 
@@ -3157,21 +3194,19 @@ Session::config_changed (const char* parameter_name)
 
        } else if (PARAM_IS ("use-video-sync")) {
 
-               if (transport_stopped()) {
-                       if (Config->get_use_video_sync()) {
-                               waiting_for_sync_offset = true;
-                       }
-               }
+               waiting_for_sync_offset = Config->get_use_video_sync();
 
        } else if (PARAM_IS ("mmc-control")) {
 
                poke_midi_thread ();
 
-       } else if (PARAM_IS ("mmc-device-id")) {
+       } else if (PARAM_IS ("mmc-device-id") || PARAM_IS ("mmc-receive-device-id")) {
 
-               if (mmc) {
-                       mmc->set_device_id (Config->get_mmc_device_id());
-               }
+               set_mmc_receive_device_id (Config->get_mmc_receive_device_id());
+
+       } else if (PARAM_IS ("mmc-send-device-id")) {
+
+               set_mmc_send_device_id (Config->get_mmc_send_device_id());
 
        } else if (PARAM_IS ("midi-control")) {
                
@@ -3282,6 +3317,12 @@ Session::config_changed (const char* parameter_name)
                set_slave_source (Config->get_slave_source());
        } else if (PARAM_IS ("remote-model")) {
                set_remote_control_ids ();
+       } else if (PARAM_IS ("denormal-model")) {
+               setup_fpu ();
+       } else if (PARAM_IS ("history-depth")) {
+               set_history_depth (Config->get_history_depth());
+       } else if (PARAM_IS ("sync-all-route-ordering")) {
+               sync_order_keys ();
        }
 
        set_dirty ();
@@ -3289,3 +3330,9 @@ Session::config_changed (const char* parameter_name)
 #undef PARAM_IS
 
 }
+
+void
+Session::set_history_depth (uint32_t d)
+{
+       _history.set_depth (d);
+}