remove some left over debugging
[ardour.git] / libs / ardour / session_state.cc
index 82ee766b2338eb8b73db530b48b9e301b8f95b68..f1bebae6e3a60f986c253b40e688591d0fddf012 100644 (file)
@@ -130,6 +130,7 @@ using namespace std;
 using namespace ARDOUR;
 using namespace PBD;
 
+
 void
 Session::first_stage_init (string fullpath, string snapshot_name)
 {
@@ -151,12 +152,6 @@ Session::first_stage_init (string fullpath, string snapshot_name)
                _path += G_DIR_SEPARATOR;
        }
 
-       if (Glib::file_test (_path, Glib::FILE_TEST_EXISTS) && ::access (_path.c_str(), W_OK)) {
-               _writable = false;
-       } else {
-               _writable = true;
-       }
-
        /* these two are just provisional settings. set_state()
           will likely override them.
        */
@@ -467,13 +462,6 @@ Session::ensure_subdirs ()
                return -1;
        }
 
-       dir = session_directory().sound_stub_path().to_string();
-
-       if (g_mkdir_with_parents (dir.c_str(), 0755) < 0) {
-               error << string_compose(_("Session: cannot create session stub sounds dir \"%1\" (%2)"), dir, strerror (errno)) << endmsg;
-               return -1;
-       }
-
        dir = session_directory().midi_path().to_string();
 
        if (g_mkdir_with_parents (dir.c_str(), 0755) < 0) {
@@ -481,13 +469,6 @@ Session::ensure_subdirs ()
                return -1;
        }
 
-       dir = session_directory().midi_stub_path().to_string();
-
-       if (g_mkdir_with_parents (dir.c_str(), 0755) < 0) {
-               error << string_compose(_("Session: cannot create session stub midi dir \"%1\" (%2)"), dir, strerror (errno)) << endmsg;
-               return -1;
-       }
-
        dir = session_directory().dead_path().to_string();
 
        if (g_mkdir_with_parents (dir.c_str(), 0755) < 0) {
@@ -532,6 +513,8 @@ Session::create (const string& mix_template, BusProfile* bus_profile)
                return -1;
        }
 
+       _writable = exists_and_writable (sys::path (_path));
+
        if (!mix_template.empty()) {
                std::string in_path = mix_template;
 
@@ -620,7 +603,7 @@ Session::create (const string& mix_template, BusProfile* bus_profile)
                }
 
                if (!rl.empty()) {
-                       add_routes (rl, false);
+                       add_routes (rl, false, false);
                }
 
                 /* this allows the user to override settings with an environment variable.
@@ -912,14 +895,7 @@ 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.to_string().c_str(), W_OK) != 0) {
-               _writable = false;
-       }
+       _writable = exists_and_writable (xmlpath);
 
        if (!state_tree->read (xmlpath.to_string())) {
                error << string_compose(_("Could not understand ardour file %1"), xmlpath.to_string()) << endmsg;
@@ -1236,8 +1212,6 @@ Session::set_state (const XMLNode& node, int version)
 
        setup_raid_path(_session_dir->root_path().to_string());
 
-       cleanup_stubfiles ();
-       
        if ((prop = node.property (X_("id-counter"))) != 0) {
                uint64_t x;
                sscanf (prop->value().c_str(), "%" PRIu64, &x);
@@ -1455,7 +1429,7 @@ Session::load_routes (const XMLNode& node, int version)
                new_routes.push_back (route);
        }
 
-       add_routes (new_routes, false);
+       add_routes (new_routes, false, false);
 
        return 0;
 }
@@ -2324,9 +2298,21 @@ Session::remove_route_group (RouteGroup& rg)
 
                route_group_removed (); /* EMIT SIGNAL */
        }
+}
+
+/** Set a new order for our route groups, without adding or removing any.
+ *  @param groups Route group list in the new order.
+ */
+void
+Session::reorder_route_groups (list<RouteGroup*> groups)
+{
+       _route_groups = groups;
 
+       route_groups_reordered (); /* EMIT SIGNAL */
+       set_dirty ();
 }
 
+
 RouteGroup *
 Session::route_group_by_name (string name)
 {
@@ -2416,16 +2402,12 @@ Session::commit_reversible_command (Command *cmd)
 }
 
 static bool
-accept_all_non_stub_audio_files (const string& path, void */*arg*/)
+accept_all_audio_files (const string& path, void */*arg*/)
 { 
         if (!Glib::file_test (path, Glib::FILE_TEST_IS_REGULAR)) {
                 return false;
         }
 
-        if (FileSource::is_stub_path (path)) {
-                return false;
-        }
-
         if (!AudioFileSource::safe_audio_file_extension (path)) {
                 return false;
         }
@@ -2434,16 +2416,12 @@ accept_all_non_stub_audio_files (const string& path, void */*arg*/)
 }
 
 static bool
-accept_all_non_stub_midi_files (const string& path, void */*arg*/)
+accept_all_midi_files (const string& path, void */*arg*/)
 {
         if (!Glib::file_test (path, Glib::FILE_TEST_IS_REGULAR)) {
                 return false;
         }
 
-        if (FileSource::is_stub_path (path)) {
-                return false;
-        }
-
        return ((path.length() > 4 && path.find (".mid") != (path.length() - 4)) ||
                 (path.length() > 4 && path.find (".smf") != (path.length() - 4)) ||
                 (path.length() > 5 && path.find (".midi") != (path.length() - 5)));
@@ -2686,8 +2664,8 @@ Session::cleanup_sources (CleanupReport& rep)
                i = nexti;
        }
 
-       candidates = scanner (audio_path, accept_all_non_stub_audio_files, (void *) 0, true, true);
-       candidates2 = scanner (midi_path, accept_all_non_stub_midi_files, (void *) 0, true, true);
+       candidates = scanner (audio_path, accept_all_audio_files, (void *) 0, true, true);
+       candidates2 = scanner (midi_path, accept_all_midi_files, (void *) 0, true, true);
 
         /* merge them */
 
@@ -2718,22 +2696,18 @@ Session::cleanup_sources (CleanupReport& rep)
                 ++tmp;
 
                if ((fs = boost::dynamic_pointer_cast<FileSource> (i->second)) != 0) {
-                        if (!fs->is_stub()) {
-                                if (playlists->source_use_count (fs) != 0) {
-                                        all_sources.insert (fs->path());
-                                } else {
-                                        
-                                        /* we might not remove this source from disk, because it may be used
-                                           by other snapshots, but its not being used in this version
-                                           so lets get rid of it now, along with any representative regions
-                                           in the region list.
-                                        */
-
-                                        cerr << "Source " << i->second->name() << "ID " << i->second->id() << " not used, remove from source list and also all regions\n";
-                                        
-                                        RegionFactory::remove_regions_using_source (i->second);
-                                        sources.erase (i);
-                                }
+                        if (playlists->source_use_count (fs) != 0) {
+                                all_sources.insert (fs->path());
+                        } else {
+                                
+                                /* we might not remove this source from disk, because it may be used
+                                   by other snapshots, but its not being used in this version
+                                   so lets get rid of it now, along with any representative regions
+                                   in the region list.
+                                */
+                                
+                                RegionFactory::remove_regions_using_source (i->second);
+                                sources.erase (i);
                         }
                }
 
@@ -2911,8 +2885,7 @@ Session::cleanup_trash_sources (CleanupReport& rep)
 
        for (i = session_dirs.begin(); i != session_dirs.end(); ++i) {
 
-               dead_dir = (*i).path;
-               dead_dir += dead_dir_name;
+               dead_dir = Glib::build_filename ((*i).path, dead_dir_name);
 
                 clear_directory (dead_dir, &rep.space, &rep.paths);
        }
@@ -2920,45 +2893,6 @@ Session::cleanup_trash_sources (CleanupReport& rep)
        return 0;
 }
 
-void
-Session::cleanup_stubfiles ()
-{
-       vector<space_and_path>::iterator i;
-
-       for (i = session_dirs.begin(); i != session_dirs.end(); ++i) {
-
-                string dir;
-                string lname = legalize_for_path (_name);
-
-                vector<string> v;
-
-                /* XXX this is a hack caused by semantic conflicts
-                   between space_and_path and the SessionDirectory concept.
-                */
-
-                v.push_back ((*i).path);
-                v.push_back ("interchange");
-                v.push_back (lname);
-                v.push_back ("audiofiles");
-                v.push_back (stub_dir_name);
-
-                dir = Glib::build_filename (v);
-                
-                clear_directory (dir);
-
-                v.clear ();
-                v.push_back ((*i).path);
-                v.push_back ("interchange");
-                v.push_back (lname);
-                v.push_back ("midifiles");
-                v.push_back (stub_dir_name);
-
-                dir = Glib::build_filename (v);
-
-                clear_directory (dir);
-       }
-}
-
 void
 Session::set_dirty ()
 {
@@ -3367,14 +3301,7 @@ Session::config_changed (std::string p, bool ours)
 
                if (Config->get_monitoring_model() == HardwareMonitoring && transport_rolling()) {
                        /* auto-input only makes a difference if we're rolling */
-
-                       boost::shared_ptr<RouteList> rl = routes.reader ();
-                       for (RouteList::iterator i = rl->begin(); i != rl->end(); ++i) {
-                               boost::shared_ptr<Track> tr = boost::dynamic_pointer_cast<Track> (*i);
-                               if (tr && tr->record_enabled ()) {
-                                       tr->monitor_input (!config.get_auto_input());
-                               }
-                       }
+                        set_track_monitor_input_status (!config.get_auto_input());
                }
 
        } else if (p == "punch-in") {