changeset 951:4b9fc70a37d5

Debug output stuff
author Chris Cannam
date Fri, 25 Jul 2014 17:02:44 +0100
parents 387fa69f4eaa
children ad14e7ed096d
files base/Debug.cpp data/model/Model.cpp
diffstat 2 files changed, 15 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/base/Debug.cpp	Fri Jul 25 15:21:41 2014 +0100
+++ b/base/Debug.cpp	Fri Jul 25 17:02:44 2014 +0100
@@ -30,7 +30,6 @@
 
 static QThreadStorage<QDebug *> debugs;
 static QMutex mutex;
-static QFile *logFile = 0;
 static char *prefix = 0;
 
 QDebug &
@@ -40,17 +39,22 @@
 
     QDebug *debug = 0;
 
+    QString pfx = ResourceFinder().getUserResourcePrefix();
+    QDir logdir(QString("%1/%2").arg(pfx).arg("log"));
+
     if (!prefix) {
         prefix = new char[20];
         sprintf(prefix, "[%lu]", (unsigned long)QCoreApplication::applicationPid());
-	QString pfx = ResourceFinder().getUserResourcePrefix();
-	QDir logdir(QString("%1/%2").arg(pfx).arg("log"));
 	if (!logdir.exists()) logdir.mkpath(logdir.path());
-        logFile = new QFile(logdir.path() + "/sv-debug.log");
-        if (logFile->open(QIODevice::WriteOnly | QIODevice::Truncate)) {
+    }
+
+    if (!debugs.hasLocalData()) {
+        QFile *logFile = new QFile(logdir.path() + "/sv-debug.log");
+        if (logFile->open(QIODevice::WriteOnly | QIODevice::Append)) {
             QDebug(QtDebugMsg) << (const char *)prefix
                                << "Opened debug log file "
                                << logFile->fileName();
+            debug = new QDebug(logFile);
         } else {
             QDebug(QtWarningMsg) << (const char *)prefix
                                  << "Failed to open debug log file "
@@ -58,20 +62,13 @@
                                  << " for writing, using console debug instead";
             delete logFile;
             logFile = 0;
-        }
-    }
-
-    if (debugs.hasLocalData()) {
-        debug = debugs.localData();
-    } else {
-        if (logFile) {
-            debug = new QDebug(logFile);
-        } else {
             debug = new QDebug(QtDebugMsg);
         }
         debugs.setLocalData(debug);
         *debug << endl << (const char *)prefix << "Log started at "
                << QDateTime::currentDateTime().toString();
+    } else {
+        debug = debugs.localData();
     }
 
     mutex.unlock();
--- a/data/model/Model.cpp	Fri Jul 25 15:21:41 2014 +0100
+++ b/data/model/Model.cpp	Fri Jul 25 17:02:44 2014 +0100
@@ -109,6 +109,7 @@
 int
 Model::alignToReference(int frame) const
 {
+//    cerr << "Model(" << this << ")::alignToReference(" << frame << ")" << endl;
     if (!m_alignment) {
         if (m_sourceModel) return m_sourceModel->alignToReference(frame);
         else return frame;
@@ -116,18 +117,21 @@
     int refFrame = m_alignment->toReference(frame);
     const Model *m = m_alignment->getReferenceModel();
     if (m && refFrame > m->getEndFrame()) refFrame = m->getEndFrame();
+//    cerr << "have alignment, aligned is " << refFrame << endl;
     return refFrame;
 }
 
 int
 Model::alignFromReference(int refFrame) const
 {
+//    cerr << "Model(" << this << ")::alignFromReference(" << refFrame << ")" << endl;
     if (!m_alignment) {
         if (m_sourceModel) return m_sourceModel->alignFromReference(refFrame);
         else return refFrame;
     }
     int frame = m_alignment->fromReference(refFrame);
     if (frame > getEndFrame()) frame = getEndFrame();
+//    cerr << "have alignment, aligned is " << frame << endl;
     return frame;
 }