when renaming redirects, scan all routes AND sends AND port inserts for the name...
[ardour.git] / libs / ardour / session_state.cc
index c769e570257b8aec7333ab8f5399028b7c867d6a..0abe1b652ef22278e3d7b23300ca5536ac748298 100644 (file)
@@ -117,6 +117,14 @@ Session::first_stage_init (string fullpath, string snapshot_name)
                _path += '/';
        }
 
+       if (Glib::file_test (_path, Glib::FILE_TEST_EXISTS) && ::access (_path.c_str(), W_OK)) {
+               cerr << "Session non-writable based on " << _path << endl;
+               _writable = false;
+       } else {
+               cerr << "Session writable based on " << _path << endl;
+               _writable = true;       
+       }
+
        set_history_depth (Config->get_history_depth());
        
 
@@ -134,6 +142,7 @@ Session::first_stage_init (string fullpath, string snapshot_name)
        _tempo_map->StateChanged.connect (mem_fun (*this, &Session::tempo_map_changed));
 
        g_atomic_int_set (&processing_prohibited, 0);
+       post_transport_work = PostTransportWork (0);
        insert_cnt = 0;
        _transport_speed = 0;
        _last_transport_speed = 0;
@@ -162,12 +171,13 @@ Session::first_stage_init (string fullpath, string snapshot_name)
        current_block_size = 0;
        solo_update_disabled = false;
        currently_soloing = false;
+       _was_seamless = Config->get_seamless_loop ();
        _have_captured = false;
        _worst_output_latency = 0;
        _worst_input_latency = 0;
        _worst_track_latency = 0;
        _state_of_the_state = StateOfTheState(CannotSave|InitialConnecting|Loading);
-
+       
        _slave = 0;
        _silent = false;
        session_send_mmc = false;
@@ -185,6 +195,7 @@ Session::first_stage_init (string fullpath, string snapshot_name)
        _pan_automation_buffer = 0;
        _npan_buffers = 0;
        pending_abort = false;
+       pending_clear_substate = false;
        destructive_index = 0;
        current_trans = 0;
        first_file_data_format_reset = true;
@@ -656,7 +667,7 @@ Session::save_state (string snapshot_name, bool pending)
        string xml_path;
        string bak_path;
 
-       if (_state_of_the_state & CannotSave) {
+       if (!_writable || (_state_of_the_state & CannotSave)) {
                return 1;
        }
 
@@ -790,6 +801,15 @@ Session::load_state (string snapshot_name)
 
        set_dirty();
 
+       /* writable() really reflects the whole folder, but if for any
+          reason the session state file can't be written to, still
+          make us unwritable.
+       */
+
+       if (::access (xmlpath.c_str(), W_OK) != 0) {
+               _writable = false;
+       }
+
        if (!state_tree->read (xmlpath)) {
                error << string_compose(_("Could not understand ardour file %1"), xmlpath) << endmsg;
                delete state_tree;
@@ -861,7 +881,7 @@ Session::load_options (const XMLNode& node)
 
        if ((child = find_named_node (node, "end-marker-is-free")) != 0) {
                if ((prop = child->property ("val")) != 0) {
-                       _end_location_is_free = (prop->value() == "yes");
+                       _end_location_is_free = string_is_affirmative (prop->value());
                }
        }
 
@@ -1158,10 +1178,10 @@ Session::set_state (const XMLNode& node)
        if ((prop = node.property (X_("sample-rate"))) != 0) {
 
                _nominal_frame_rate = atoi (prop->value());
-
+               
                if (_nominal_frame_rate != _current_frame_rate) {
                        if (AskAboutSampleRateMismatch (_nominal_frame_rate, _current_frame_rate)) {
-                               return -1;
+                               throw SRMismatchRejected();
                        }
                }
        }
@@ -1359,6 +1379,13 @@ Session::load_routes (const XMLNode& node)
        set_dirty();
 
        for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
+               XMLProperty* prop = (*niter)->property ("default-type");
+               
+               if (prop && prop->value() == "unknown" ) {
+                       std::cout << "ignoring route with type unknown. (video-track)" << std::endl;
+                       // Note: this may mess up remote_control IDs or more..
+                       continue;
+               }
 
                boost::shared_ptr<Route> route (XMLRouteFactory (**niter));
 
@@ -2057,6 +2084,12 @@ Session::template_dir ()
        return Glib::build_filename (get_user_ardour_path(), "templates");
 }
 
+string
+Session::route_template_dir ()
+{
+       return Glib::build_filename (get_user_ardour_path(), "route_templates");
+}
+
 string
 Session::export_dir () const
 {
@@ -2103,6 +2136,13 @@ Session::template_path ()
        return suffixed_search_path (X_("templates"), true);
 }
 
+
+string
+Session::route_template_path ()
+{
+       return suffixed_search_path (X_("route_templates"), true);
+}
+
 string
 Session::control_protocol_path ()
 {
@@ -2471,6 +2511,43 @@ Session::get_template_list (list<string> &template_names)
        }
 }
 
+void
+Session::get_route_templates (vector<RouteTemplateInfo>& template_names)
+{
+       vector<string *> *templates;
+       PathScanner scanner;
+       string path;
+
+       path = route_template_path ();
+       
+       templates = scanner (path, template_filter, 0, false, true);
+       
+       if (!templates) {
+         return;
+       }
+
+       for (vector<string*>::iterator i = templates->begin(); i != templates->end(); ++i) {
+               string fullpath = *(*i);
+
+               XMLTree tree;
+
+               if (!tree.read (fullpath.c_str())) {
+                 continue;
+               }
+
+               XMLNode* root = tree.root();
+               
+               RouteTemplateInfo rti;
+
+               rti.name = IO::name_from_state (*root->children().front());
+               rti.path = fullpath;
+
+               template_names.push_back (rti);
+       }
+
+       delete templates;
+}
+
 int
 Session::read_favorite_dirs (FavoriteDirs & favs)
 {
@@ -2569,12 +2646,17 @@ Session::find_all_sources (string path, set<string>& result)
                        continue;
                }
 
-               string path = _path; /* /-terminated */
-               path += sound_dir_name;
-               path += '/';
-               path += prop->value();
+               /* now we have to actually find the file */
 
-               result.insert (path);
+               bool is_new;
+               uint16_t chan;
+               Glib::ustring path;
+               std::string name;
+               
+               if (AudioFileSource::find (prop->value(), true, false, is_new, chan, path, name)) {
+                       cerr << "Got " << path << " from XML source with prop = " << prop->value() << endl;
+                       result.insert (path);
+               }
        }
 
        return 0;
@@ -2762,6 +2844,8 @@ Session::cleanup_sources (Session::cleanup_report& rep)
                        realpath(spath.c_str(), tmppath1);
                        realpath((*i).c_str(),  tmppath2);
 
+                       cerr << "comparing " << tmppath1 << " and " << tmppath2 << endl;
+
                        if (strcmp(tmppath1, tmppath2) == 0) {
                                used = true;
                                break;
@@ -3032,7 +3116,9 @@ Session::controllable_by_id (const PBD::ID& id)
 void 
 Session::add_instant_xml (XMLNode& node, const std::string& dir)
 {
-       Stateful::add_instant_xml (node, dir);
+       if (_writable) {
+               Stateful::add_instant_xml (node, dir);
+       }
        Config->add_instant_xml (node, get_user_ardour_path());
 }
 
@@ -3043,6 +3129,10 @@ Session::save_history (string snapshot_name)
     string xml_path;
     string bak_path;
 
+    if (!_writable) {
+           return 0;
+    }
+
     if (snapshot_name.empty()) {
        snapshot_name = _current_snapshot_name;
     }
@@ -3097,7 +3187,7 @@ Session::restore_history (string snapshot_name)
 
     /* read xml */
     xmlpath = _path + snapshot_name + ".history";
-    cerr << string_compose(_("Loading history from '%1'."), xmlpath) << endmsg;
+    info << string_compose(_("Loading history from '%1'."), xmlpath) << endmsg;
 
     if (!Glib::file_test (xmlpath, Glib::FILE_TEST_EXISTS)) {
            return 1;