+ const string legalized_root (legalize_for_path (Glib::path_get_basename(p)));
+
+ std::string sources_root_path = Glib::build_filename (m_root_path, interchange_dir_name);
+
+ /* check the interchange folder:
+ *
+ * 1) if a single subdir exists, use it, regardless of the name
+ * 2) if more than one dir is in interchange: abort, blame the user
+ * 3) if interchange does not exist or no subdir is present,
+ * use the session-name to create one.
+ *
+ * We use the name of the containing folder, not the actual
+ * session name. The latter would require some API changes and
+ * careful libardour updates:
+ *
+ * The session object is created with the "snapshot-name", only
+ * when loading the .ardour session file, the actual name is set.
+ *
+ * SessionDirectory is created with the session itself
+ * and picks up the wrong inital name.
+ *
+ * SessionDirectory is also used directly by the AudioRegionImporter,
+ * and the peak-file background thread (session.cc).
+ *
+ * There is no actual benefit to use the session-name instead of
+ * the folder-name. Under normal circumstances they are always
+ * identical. But it would be consistent to prefer the name.
+ */
+ try {
+ Glib::Dir dir(sources_root_path);
+
+ std::list<std::string> entries;
+
+ for (Glib::DirIterator di = dir.begin(); di != dir.end(); di++) {
+ // ignore hidden files (eg. OS X ".DS_Store")
+ if ((*di).at(0) == '.') {
+ continue;
+ }
+ // and skip regular files (eg. Win Thumbs.db)
+ string fullpath = Glib::build_filename (sources_root_path, *di);
+ if (!Glib::file_test (fullpath, Glib::FILE_TEST_IS_DIR)) {
+ continue;
+ }
+ entries.push_back(*di);
+ }