add new static functions to get SR and disk sample format from session XML
authorPaul Davis <paul@linuxaudiosystems.com>
Tue, 24 Sep 2013 01:35:51 +0000 (21:35 -0400)
committerPaul Davis <paul@linuxaudiosystems.com>
Tue, 24 Sep 2013 01:35:51 +0000 (21:35 -0400)
libs/ardour/ardour/session.h
libs/ardour/session_state.cc

index ae5339796c06b4624118c993719938a322396a01..2fcf6d476a137085be828a44ab941d44eb2f9e9c 100644 (file)
@@ -161,6 +161,8 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi
 
        virtual ~Session ();
 
+        static int get_info_from_path (const std::string& xmlpath, float& sample_rate, SampleFormat& data_format);
+
        std::string path() const { return _path; }
        std::string name() const { return _name; }
        std::string snap_name() const { return _current_snapshot_name; }
@@ -1618,6 +1620,8 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi
     void setup_ltc ();
     void setup_click ();
     void setup_bundles ();
+
+    static int get_session_info_from_path (XMLTree& state_tree, const std::string& xmlpath);
 };
 
 } // namespace ARDOUR
index 049cb5b5eedf2725e3b8a32c2009c893cca1cd38..2b2afc0d3d0aae8a4e232b5897c6089128e3d6f9 100644 (file)
@@ -3743,3 +3743,59 @@ Session::rename (const std::string& new_name)
 
 #undef RENAME
 }
+
+int
+Session::get_session_info_from_path (XMLTree& tree, const string& xmlpath)
+{
+       if (!Glib::file_test (xmlpath, Glib::FILE_TEST_EXISTS)) {
+               return -1;
+        }
+
+       if (!tree.read (xmlpath)) {
+               return -1;
+       }
+
+       return 0;
+}
+
+int
+Session::get_info_from_path (const string& xmlpath, float& sample_rate, SampleFormat& data_format)
+{
+       XMLTree tree;
+       bool found_sr = false;
+       bool found_data_format = false;
+
+       if (get_session_info_from_path (tree, xmlpath)) {
+               return -1;
+       }
+
+       /* sample rate */
+
+       const XMLProperty* prop;
+       if ((prop = tree.root()->property (X_("sample-rate"))) != 0) {          
+               sample_rate = atoi (prop->value());
+               found_sr = true;
+       }
+
+       const XMLNodeList& children (tree.root()->children());
+       for (XMLNodeList::const_iterator c = children.begin(); c != children.end(); ++c) {
+               const XMLNode* child = *c;
+               if (child->name() == "Config") {
+                       const XMLNodeList& options (child->children());
+                       for (XMLNodeList::const_iterator oc = options.begin(); oc != options.end(); ++oc) {
+                               const XMLNode* option = *oc;
+                               if (option->property("name")->value() == "native-file-data-format") {
+                                       SampleFormat fmt = (SampleFormat) string_2_enum (option->property ("value")->value(), fmt);
+                                       data_format = fmt;
+                                       found_data_format = true;
+                                       break;
+                               }
+                       }
+               }
+               if (found_data_format) {
+                       break;
+               }
+       }
+
+       return !(found_sr && found_data_format); // zero if they are both found
+}