changeset 355:d02f71281639

* Fix #1841095 tapping time instant gives wrong time in aligned track * Fix #1815654 source tidying: Labeller * Fix (I hope) #1849999 Time value graphs one instant out
author Chris Cannam
date Thu, 13 Dec 2007 17:14:33 +0000
parents 048b21bc9891
children ca3b91119482
files data/fileio/FileSource.cpp data/model/Labeller.h
diffstat 2 files changed, 68 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/data/fileio/FileSource.cpp	Tue Dec 11 14:58:29 2007 +0000
+++ b/data/fileio/FileSource.cpp	Thu Dec 13 17:14:33 2007 +0000
@@ -27,7 +27,7 @@
 
 #include <iostream>
 
-//#define DEBUG_FILE_SOURCE 1
+#define DEBUG_FILE_SOURCE 1
 
 int
 FileSource::m_count = 0;
@@ -200,17 +200,37 @@
 FileSource::init(bool showProgress)
 {
     if (!isRemote()) {
+#ifdef DEBUG_FILE_SOURCE
+        std::cerr << "FileSource::init: Not a remote URL" << std::endl;
+#endif
+        bool literal = false;
         m_localFilename = m_url.toLocalFile();
         if (m_localFilename == "") {
             // QUrl may have mishandled the scheme (e.g. in a DOS path)
             m_localFilename = m_url.toString();
+            literal = true;
         }
+#ifdef DEBUG_FILE_SOURCE
+        std::cerr << "FileSource::init: URL translates to local filename \""
+                  << m_localFilename.toStdString() << "\"" << std::endl;
+#endif
         m_ok = true;
+        m_lastStatus = 200;
+
         if (!QFileInfo(m_localFilename).exists()) {
-            m_lastStatus = 404;
-        } else {
-            m_lastStatus = 200;
+            if (literal) {
+                m_lastStatus = 404;
+            } else {
+                // Again, QUrl may have been mistreating us --
+                // e.g. dropping a part that looks like query data
+                m_localFilename = m_url.toString();
+                literal = true;
+                if (!QFileInfo(m_localFilename).exists()) {
+                    m_lastStatus = 404;
+                }
+            }
         }
+
         m_done = true;
         return;
     }
--- a/data/model/Labeller.h	Tue Dec 11 14:58:29 2007 +0000
+++ b/data/model/Labeller.h	Thu Dec 13 17:14:33 2007 +0000
@@ -36,8 +36,10 @@
         ValueFromTwoLevelCounter,
         ValueFromFrameNumber,
         ValueFromRealTime,
-        ValueFromRealTimeDifference,
-        ValueFromTempo,
+        ValueFromDurationFromPrevious,
+        ValueFromDurationToNext,
+        ValueFromTempoFromPrevious,
+        ValueFromTempoToNext,
         ValueFromExistingNeighbour,
         ValueFromLabel
     };
@@ -59,7 +61,7 @@
     // 4. re-label a set of points that have already been added to a
     // model
 
-    Labeller(ValueType type) :
+    Labeller(ValueType type = ValueNone) :
         m_type(type),
         m_counter(1),
         m_counter2(1),
@@ -81,16 +83,30 @@
     typedef std::map<ValueType, QString> TypeNameMap;
     TypeNameMap getTypeNames() const {
         TypeNameMap m;
-        m[ValueNone] = tr("No numbering");
-        m[ValueFromSimpleCounter] = tr("Simple counter");
-        m[ValueFromCyclicalCounter] = tr("Cyclical counter");
-        m[ValueFromTwoLevelCounter] = tr("Cyclical two-level counter (bar/beat)");
-        m[ValueFromFrameNumber] = tr("Audio sample frame number");
-        m[ValueFromRealTime] = tr("Time in seconds");
-        m[ValueFromRealTimeDifference] = tr("Duration to the following item");
-        m[ValueFromTempo] = tr("Tempo (bpm) based on duration to following item");
-        m[ValueFromExistingNeighbour] = tr("Same as the nearest previous item");
-        m[ValueFromLabel] = tr("Value extracted from the item's label (where possible)");
+        m[ValueNone]
+            = tr("No numbering");
+        m[ValueFromSimpleCounter]
+            = tr("Simple counter");
+        m[ValueFromCyclicalCounter]
+            = tr("Cyclical counter");
+        m[ValueFromTwoLevelCounter]
+            = tr("Cyclical two-level counter (bar/beat)");
+        m[ValueFromFrameNumber]
+            = tr("Audio sample frame number");
+        m[ValueFromRealTime]
+            = tr("Time in seconds");
+        m[ValueFromDurationToNext]
+            = tr("Duration to the following item");
+        m[ValueFromTempoToNext]
+            = tr("Tempo (bpm) based on duration to following item");
+        m[ValueFromDurationFromPrevious]
+            = tr("Duration since the previous item");
+        m[ValueFromTempoFromPrevious]
+            = tr("Tempo (bpm) based on duration since previous item");
+        m[ValueFromExistingNeighbour]
+            = tr("Same as the nearest previous item");
+        m[ValueFromLabel]
+            = tr("Value extracted from the item's label (where possible)");
         return m;
     }
 
@@ -212,9 +228,16 @@
         }
     }
 
+    bool requiresPrevPoint() const {
+        return (m_type == ValueFromDurationFromPrevious ||
+                m_type == ValueFromDurationToNext ||
+                m_type == ValueFromTempoFromPrevious ||
+                m_type == ValueFromDurationToNext);
+    }
+
     bool actingOnPrevPoint() const {
-        return (m_type == ValueFromRealTimeDifference ||
-                m_type == ValueFromTempo);
+        return (m_type == ValueFromDurationToNext ||
+                m_type == ValueFromTempoToNext);
     }
 
 protected:
@@ -252,15 +275,18 @@
             }
             break;
 
-        case ValueFromRealTimeDifference:
-        case ValueFromTempo:
+        case ValueFromDurationToNext:
+        case ValueFromTempoToNext:
+        case ValueFromDurationFromPrevious:
+        case ValueFromTempoFromPrevious:
             if (m_rate == 0.f) {
                 std::cerr << "ERROR: Labeller::getValueFor: Real-time conversion required, but no sample rate set" << std::endl;
             } else if (!prevPoint) {
                 std::cerr << "ERROR: Labeller::getValueFor: Time difference required, but only one point provided" << std::endl;
             } else {
                 size_t f0 = prevPoint->frame, f1 = newPoint.frame;
-                if (m_type == ValueFromRealTimeDifference) {
+                if (m_type == ValueFromDurationToNext ||
+                    m_type == ValueFromDurationFromPrevious) {
                     value = float(f1 - f0) / m_rate;
                 } else {
                     if (f1 > f0) {