summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Davis <paul@linuxaudiosystems.com>2013-09-23 21:35:51 -0400
committerPaul Davis <paul@linuxaudiosystems.com>2013-09-23 21:35:51 -0400
commit4209e8a8347940a5d17b129fa1f52d4f57efd02c (patch)
tree5fb6084031abcdce42665a48a5d75e4968e9120d
parentcff174b5417d9b242673588792d390db9f61ca93 (diff)
add new static functions to get SR and disk sample format from session XML
-rw-r--r--libs/ardour/ardour/session.h4
-rw-r--r--libs/ardour/session_state.cc56
2 files changed, 60 insertions, 0 deletions
diff --git a/libs/ardour/ardour/session.h b/libs/ardour/ardour/session.h
index ae5339796c..2fcf6d476a 100644
--- a/libs/ardour/ardour/session.h
+++ b/libs/ardour/ardour/session.h
@@ -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
diff --git a/libs/ardour/session_state.cc b/libs/ardour/session_state.cc
index 049cb5b5ee..2b2afc0d3d 100644
--- a/libs/ardour/session_state.cc
+++ b/libs/ardour/session_state.cc
@@ -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
+}