diff options
author | Robin Gareus <robin@gareus.org> | 2016-12-08 10:36:12 +0100 |
---|---|---|
committer | Robin Gareus <robin@gareus.org> | 2016-12-08 10:36:12 +0100 |
commit | e1ca4b28873a195c802d7d02b5bf420d778e3f35 (patch) | |
tree | d86b5001908abf8fa5932e897bf5c654cf155376 /libs/ardour/session_state.cc | |
parent | 9a46d593cbbc9d40c119bc0c5da40d124e476df7 (diff) |
Speed up recent session display (for many large sessions)
- don't parse XML into XMLTree
- only read the file, extract relevant elements
- don't read session-template contents, only test file
Diffstat (limited to 'libs/ardour/session_state.cc')
-rw-r--r-- | libs/ardour/session_state.cc | 96 |
1 files changed, 48 insertions, 48 deletions
diff --git a/libs/ardour/session_state.cc b/libs/ardour/session_state.cc index f82212345d..c9c687fcdd 100644 --- a/libs/ardour/session_state.cc +++ b/libs/ardour/session_state.cc @@ -4354,68 +4354,68 @@ Session::rename (const std::string& new_name) } int -Session::get_session_info_from_path (XMLTree& tree, const string& xmlpath) +Session::get_info_from_path (const string& xmlpath, float& sample_rate, SampleFormat& data_format) { + bool found_sr = false; + bool found_data_format = false; + if (!Glib::file_test (xmlpath, Glib::FILE_TEST_EXISTS)) { return -1; - } + } - if (!tree.read (xmlpath)) { + xmlParserCtxtPtr ctxt = xmlNewParserCtxt(); + if (ctxt == NULL) { return -1; } + xmlDocPtr doc = xmlCtxtReadFile (ctxt, xmlpath.c_str(), NULL, XML_PARSE_HUGE); - 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)) { + if (doc == NULL) { + xmlFreeParserCtxt(ctxt); return -1; } - /* sample rate */ - - XMLProperty const * prop; - XMLNode const * root (tree.root()); + xmlNodePtr node = xmlDocGetRootElement(doc); - if ((prop = root->property (X_("sample-rate"))) != 0) { - sample_rate = atoi (prop->value()); - found_sr = true; + if (node == NULL) { + xmlFreeParserCtxt(ctxt); + return -1; } - const XMLNodeList& children (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) { - XMLNode const * option = *oc; - XMLProperty const * name = option->property("name"); - - if (!name) { - continue; - } + /* sample rate */ - if (name->value() == "native-file-data-format") { - XMLProperty const * value = option->property ("value"); - if (value) { - SampleFormat fmt = (SampleFormat) string_2_enum (option->property ("value")->value(), fmt); - data_format = fmt; - found_data_format = true; - break; - } - } - } - } - if (found_data_format) { - break; - } - } + xmlAttrPtr attr; + for (attr = node->properties; attr; attr = attr->next) { + if (!strcmp ((const char*)attr->name, "sample-rate") && attr->children) { + sample_rate = atoi ((char*)attr->children->content); + found_sr = true; + } + } + + node = node->children; + while (node != NULL) { + if (strcmp((const char*) node->name, "Config")) { + node = node->next; + continue; + } + for (node = node->children; node; node = node->next) { + xmlChar* pv = xmlGetProp (node, (const xmlChar*)"name"); + if (pv && !strcmp ((const char*)pv, "native-file-data-format")) { + xmlFree (pv); + xmlChar* val = xmlGetProp (node, (const xmlChar*)"value"); + if (val) { + SampleFormat fmt = (SampleFormat) string_2_enum (string ((const char*)val), fmt); + data_format = fmt; + found_data_format = true; + } + xmlFree (val); + break; + } + xmlFree (pv); + } + break; + } + + xmlFreeParserCtxt(ctxt); return !(found_sr && found_data_format); // zero if they are both found } |