X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=libs%2Fardour%2Fsource.cc;h=6ae1aca1ca1defcd9afaafd7373daf1b997cfd32;hb=9cdbeaa07d916da8ee84e2172895b38965740604;hp=03039fea5baf5f9abc8205132e821f51fb4645ec;hpb=ad017365f7a73f8ba57f667cc1aa36478b48c50e;p=ardour.git diff --git a/libs/ardour/source.cc b/libs/ardour/source.cc index 03039fea5b..6ae1aca1ca 100644 --- a/libs/ardour/source.cc +++ b/libs/ardour/source.cc @@ -25,21 +25,28 @@ #include #include #include -#include +#include "pbd/gstdio_compat.h" #include #include #include #include "pbd/xml++.h" #include "pbd/pthread_utils.h" #include "pbd/enumwriter.h" +#include "pbd/types_convert.h" #include "ardour/debug.h" +#include "ardour/profile.h" #include "ardour/session.h" #include "ardour/source.h" #include "ardour/transient_detector.h" +#include "ardour/types_convert.h" -#include "i18n.h" +#include "pbd/i18n.h" + +namespace PBD { + DEFINE_ENUM_CONVERT(ARDOUR::Source::Flag); +} using namespace std; using namespace ARDOUR; @@ -93,17 +100,14 @@ XMLNode& Source::get_state () { XMLNode *node = new XMLNode ("Source"); - char buf[64]; - node->add_property ("name", name()); - node->add_property ("type", _type.to_string()); - node->add_property (X_("flags"), enum_2_string (_flags)); - id().print (buf, sizeof (buf)); - node->add_property ("id", buf); + node->set_property ("name", name()); + node->set_property ("type", _type); + node->set_property (X_("flags"), _flags); + node->set_property ("id", id()); if (_timestamp != 0) { - snprintf (buf, sizeof (buf), "%ld", _timestamp); - node->add_property ("timestamp", buf); + node->set_property ("timestamp", (int64_t)_timestamp); } return *node; @@ -112,10 +116,9 @@ Source::get_state () int Source::set_state (const XMLNode& node, int version) { - const XMLProperty* prop; - - if ((prop = node.property ("name")) != 0) { - _name = prop->value(); + std::string str; + if (node.get_property ("name", str)) { + _name = str; } else { return -1; } @@ -124,26 +127,27 @@ Source::set_state (const XMLNode& node, int version) return -1; } - if ((prop = node.property ("type")) != 0) { - _type = DataType(prop->value()); - } + node.get_property ("type", _type); - if ((prop = node.property ("timestamp")) != 0) { - sscanf (prop->value().c_str(), "%ld", &_timestamp); + int64_t t; + if (node.get_property ("timestamp", t)) { + _timestamp = t; } - if ((prop = node.property (X_("flags"))) != 0) { - _flags = Flag (string_2_enum (prop->value(), _flags)); - } else { + if (!node.get_property (X_("flags"), _flags)) { _flags = Flag (0); - } /* old style, from the period when we had DestructiveFileSource */ - if ((prop = node.property (X_("destructive"))) != 0) { + if (node.get_property (X_("destructive"), str)) { _flags = Flag (_flags | Destructive); } + if (Profile->get_trx() && (_flags & Destructive)) { + error << string_compose (_("%1: this session uses destructive tracks, which are not supported"), PROGRAM_NAME) << endmsg; + return -1; + } + if (version < 3000) { /* a source with an XML node must necessarily already exist, and therefore cannot be removable/writable etc. etc.; 2.X @@ -167,41 +171,41 @@ Source::has_been_analysed() const void Source::set_been_analysed (bool yn) { - { + if (yn) { + if (0 == load_transients (get_transients_path())) { + yn = false; + } + } + if (yn != _analysed) { Glib::Threads::Mutex::Lock lm (_analysis_lock); _analysed = yn; } - - if (yn) { - load_transients (get_transients_path()); - AnalysisChanged(); // EMIT SIGNAL - } + AnalysisChanged(); // EMIT SIGNAL } int Source::load_transients (const string& path) { - ifstream file (path.c_str()); - - if (!file) { + int rv = 0; + FILE *tf; + if (! (tf = g_fopen (path.c_str (), "rb"))) { return -1; } transients.clear (); - - stringstream strstr; - double val; - - while (file.good()) { - file >> val; - - if (!file.fail()) { - framepos_t frame = (framepos_t) floor (val * _session.frame_rate()); - transients.push_back (frame); + while (!feof (tf) && !ferror(tf)) { + double val; + if (1 != fscanf (tf, "%lf", &val)) { + rv = -1; + break; } + + samplepos_t sample = (samplepos_t) floor (val * _session.sample_rate()); + transients.push_back (sample); } - return 0; + ::fclose (tf); + return rv; } string @@ -261,7 +265,7 @@ Source::mark_for_remove () } void -Source::set_timeline_position (framepos_t pos) +Source::set_timeline_position (samplepos_t pos) { _timeline_position = pos; }