do not mark session dirty during loading process; sync with loaded locations state...
[ardour.git] / libs / ardour / session_state.cc
index 4e99c663f0521cb931f25826fb6888f792e3a345..cfd6b9c1e01348671f86f285b0c1713fda0ea187 100644 (file)
@@ -318,6 +318,8 @@ Session::post_engine_init ()
                _locations->changed.connect_same_thread (*this, boost::bind (&Session::locations_changed, this));
                _locations->added.connect_same_thread (*this, boost::bind (&Session::locations_added, this, _1));
                
+               
+               
        } catch (AudioEngine::PortRegistrationFailure& err) {
                /* handle this one in a different way than all others, so that its clear what happened */
                error << err.what() << endmsg;
@@ -540,7 +542,7 @@ Session::create (const string& session_template, BusProfile* bus_profile)
                 ChanCount count(DataType::AUDIO, bus_profile->master_out_channels);
 
                if (bus_profile->master_out_channels) {
-                       boost::shared_ptr<Route> r (new Route (*this, _("master"), Route::MasterOut, DataType::AUDIO));
+                       boost::shared_ptr<Route> r (new Route (*this, _("Master"), Route::MasterOut, DataType::AUDIO));
                         if (r->init ()) {
                                 return -1;
                         }
@@ -665,6 +667,10 @@ Session::save_state (string snapshot_name, bool pending, bool switch_to_snapshot
        XMLTree tree;
        std::string xml_path(_session_dir->root_path());
 
+       /* prevent concurrent saves from different threads */
+
+       Glib::Threads::Mutex::Lock lm (save_state_lock);
+
        if (!_writable || (_state_of_the_state & CannotSave)) {
                return 1;
        }
@@ -1139,7 +1145,7 @@ Session::set_state (const XMLNode& node, int version)
 
        if (node.name() != X_("Session")) {
                fatal << _("programming error: Session: incorrect XML node sent to set_state()") << endmsg;
-               return -1;
+               goto out;
        }
 
        if ((prop = node.property ("name")) != 0) {
@@ -1153,7 +1159,7 @@ Session::set_state (const XMLNode& node, int version)
                if (_nominal_frame_rate != _current_frame_rate) {
                         boost::optional<int> r = AskAboutSampleRateMismatch (_nominal_frame_rate, _current_frame_rate);
                        if (r.get_value_or (0)) {
-                               return -1;
+                               goto out;
                        }
                }
        }
@@ -1228,20 +1234,7 @@ Session::set_state (const XMLNode& node, int version)
                goto out;
        }
 
-       Location* location;
-
-       if ((location = _locations->auto_loop_location()) != 0) {
-               set_auto_loop_location (location);
-       }
-
-       if ((location = _locations->auto_punch_location()) != 0) {
-               set_auto_punch_location (location);
-       }
-
-       if ((location = _locations->session_range_location()) != 0) {
-               delete _session_range_location;
-               _session_range_location = location;
-       }
+       locations_changed ();
 
        if (_session_range_location) {
                AudioFileSource::set_header_position_offset (_session_range_location->start());
@@ -1346,9 +1339,13 @@ Session::set_state (const XMLNode& node, int version)
 
        StateReady (); /* EMIT SIGNAL */
 
+       delete state_tree;
+       state_tree = 0;
        return 0;
 
   out:
+       delete state_tree;
+       state_tree = 0;
        return ret;
 }
 
@@ -1899,8 +1896,19 @@ Session::load_sources (const XMLNode& node)
 
                         case -1:
                         default:
-                                warning << _("A sound file is missing. It will be replaced by silence.") << endmsg;
-                                source = SourceFactory::createSilent (*this, **niter, max_framecnt, _current_frame_rate);
+                               switch (err.type) {
+
+                               case DataType::AUDIO:
+                                       warning << _("A sound file is missing. It will be replaced by silence.") << endmsg;
+                                       source = SourceFactory::createSilent (*this, **niter, max_framecnt, _current_frame_rate);
+                                       break;
+
+                               case DataType::MIDI:
+                                       warning << string_compose (_("A MIDI file is missing. %1 cannot currently recover from missing MIDI files"),
+                                                                    PROGRAM_NAME) << endmsg;
+                                       return -1;
+                                       break;
+                               }
                                 break;
                         }
                }
@@ -2874,6 +2882,12 @@ Session::cleanup_trash_sources (CleanupReport& rep)
 void
 Session::set_dirty ()
 {
+       /* never mark session dirty during loading */
+
+       if (_state_of_the_state & Loading) {
+               return;
+       }
+
        bool was_dirty = dirty();
 
        _state_of_the_state = StateOfTheState (_state_of_the_state | Dirty);
@@ -2965,7 +2979,7 @@ Session::controllable_by_descriptor (const ControllableDescriptor& desc)
        case ControllableDescriptor::NamedRoute:
        {
                std::string str = desc.top_level_name();
-               if (str == "master") {
+               if (str == "Master" || str == "master") {
                        r = _master_out;
                } else if (str == "control" || str == "listen") {
                        r = _monitor_out;