changeset 1659:8bf3a52a1604 single-point

Work on start/end frame stuff to match API description
author Chris Cannam
date Thu, 21 Mar 2019 11:35:30 +0000
parents 5b7b01da430a
children b234d4d011df
files data/model/Model.h data/model/NoteModel.h data/model/RegionModel.h data/model/SparseOneDimensionalModel.h data/model/SparseTimeValueModel.h data/model/test/TestSparseModels.h
diffstat 6 files changed, 60 insertions(+), 32 deletions(-) [+]
line wrap: on
line diff
--- a/data/model/Model.h	Wed Mar 20 16:22:13 2019 +0000
+++ b/data/model/Model.h	Thu Mar 21 11:35:30 2019 +0000
@@ -56,11 +56,12 @@
 
     /**
      * Return the audio frame at the end of the model, i.e. the final
-     * frame contained within the model plus 1 (or plus the model's
-     * "resolution" granularity, if more than 1). The end frame minus
-     * the start frame should yield the total duration in frames
-     * spanned by the model. This is consistent with the definition of
-     * the end frame of a Selection object.
+     * frame contained within the model plus 1 (rounded up to the
+     * model's "resolution" granularity, if more than 1). The end
+     * frame minus the start frame should yield the total duration in
+     * frames (as a multiple of the resolution) spanned by the
+     * model. This is broadly consistent with the definition of the
+     * end frame of a Selection object.
      */
     virtual sv_frame_t getEndFrame() const = 0;
 
--- a/data/model/NoteModel.h	Wed Mar 20 16:22:13 2019 +0000
+++ b/data/model/NoteModel.h	Thu Mar 21 11:35:30 2019 +0000
@@ -96,10 +96,19 @@
 
     QString getTypeName() const override { return tr("Note"); }
     Subtype getSubtype() const { return m_subtype; }
+    bool isSparse() const { return true; }
+    bool isOK() const override { return true; }
+    
+    sv_frame_t getStartFrame() const override {
+        return m_events.getStartFrame();
+    }
+    sv_frame_t getEndFrame() const override {
+        if (m_events.isEmpty()) return 0;
+        sv_frame_t e = m_events.getEndFrame();
+        if (e % m_resolution == 0) return e;
+        else return (e / m_resolution + 1) * m_resolution;
+    }
 
-    bool isOK() const override { return true; }
-    sv_frame_t getStartFrame() const override { return m_events.getStartFrame(); }
-    sv_frame_t getEndFrame() const override { return m_events.getEndFrame(); }
     sv_samplerate_t getSampleRate() const override { return m_sampleRate; }
     int getResolution() const { return m_resolution; }
 
--- a/data/model/RegionModel.h	Wed Mar 20 16:22:13 2019 +0000
+++ b/data/model/RegionModel.h	Thu Mar 21 11:35:30 2019 +0000
@@ -77,10 +77,19 @@
     }
 
     QString getTypeName() const override { return tr("Region"); }
+    bool isSparse() const { return true; }
+    bool isOK() const override { return true; }
 
-    bool isOK() const override { return true; }
-    sv_frame_t getStartFrame() const override { return m_events.getStartFrame(); }
-    sv_frame_t getEndFrame() const override { return m_events.getEndFrame(); }
+    sv_frame_t getStartFrame() const override {
+        return m_events.getStartFrame();
+    }
+    sv_frame_t getEndFrame() const override {
+        if (m_events.isEmpty()) return 0;
+        sv_frame_t e = m_events.getEndFrame();
+        if (e % m_resolution == 0) return e;
+        else return (e / m_resolution + 1) * m_resolution;
+    }
+
     sv_samplerate_t getSampleRate() const override { return m_sampleRate; }
     int getResolution() const { return m_resolution; }
 
--- a/data/model/SparseOneDimensionalModel.h	Wed Mar 20 16:22:13 2019 +0000
+++ b/data/model/SparseOneDimensionalModel.h	Thu Mar 21 11:35:30 2019 +0000
@@ -60,10 +60,19 @@
     }
 
     QString getTypeName() const override { return tr("Sparse 1-D"); }
+    bool isSparse() const { return true; }
+    bool isOK() const override { return true; }
 
-    bool isOK() const override { return true; }
-    sv_frame_t getStartFrame() const override { return m_events.getStartFrame(); }
-    sv_frame_t getEndFrame() const override { return m_events.getEndFrame(); }
+    sv_frame_t getStartFrame() const override {
+        return m_events.getStartFrame();
+    }
+    sv_frame_t getEndFrame() const override {
+        if (m_events.isEmpty()) return 0;
+        sv_frame_t e = m_events.getEndFrame() + 1;
+        if (e % m_resolution == 0) return e;
+        else return (e / m_resolution + 1) * m_resolution;
+    }
+    
     sv_samplerate_t getSampleRate() const override { return m_sampleRate; }
     int getResolution() const { return m_resolution; }
 
--- a/data/model/SparseTimeValueModel.h	Wed Mar 20 16:22:13 2019 +0000
+++ b/data/model/SparseTimeValueModel.h	Thu Mar 21 11:35:30 2019 +0000
@@ -81,10 +81,19 @@
     }
 
     QString getTypeName() const override { return tr("Sparse Time-Value"); }
+    bool isSparse() const { return true; }
+    bool isOK() const override { return true; }
 
-    bool isOK() const override { return true; }
-    sv_frame_t getStartFrame() const override { return m_events.getStartFrame(); }
-    sv_frame_t getEndFrame() const override { return m_events.getEndFrame(); }
+    sv_frame_t getStartFrame() const override {
+        return m_events.getStartFrame();
+    }
+    sv_frame_t getEndFrame() const override {
+        if (m_events.isEmpty()) return 0;
+        sv_frame_t e = m_events.getEndFrame() + 1;
+        if (e % m_resolution == 0) return e;
+        else return (e / m_resolution + 1) * m_resolution;
+    }
+    
     sv_samplerate_t getSampleRate() const override { return m_sampleRate; }
     int getResolution() const { return m_resolution; }
 
--- a/data/model/test/TestSparseModels.h	Wed Mar 20 16:22:13 2019 +0000
+++ b/data/model/test/TestSparseModels.h	Thu Mar 21 11:35:30 2019 +0000
@@ -43,16 +43,6 @@
 
         Event p(10);
         m.add(p);
-/*!!!
-        m.clear();
-        QCOMPARE(m.isEmpty(), true);
-        QCOMPARE(m.getEventCount(), 0);
-        QCOMPARE(m.getAllEvents().size(), 0);
-        QCOMPARE(m.getStartFrame(), 0);
-        QCOMPARE(m.getEndFrame(), 0);
-
-        m.add(p);
-*/
         m.remove(p);
         QCOMPARE(m.isEmpty(), true);
         QCOMPARE(m.getEventCount(), 0);
@@ -95,19 +85,20 @@
         QCOMPARE(m.getAllEvents().size(), 3);
         QCOMPARE(*m.getAllEvents().begin(), p1);
         QCOMPARE(*m.getAllEvents().rbegin(), p3);
-/*!!!
-        auto pp = m.getAllEvents(20, 30);
+
+        // The EventSeries that is used internally is tested more
+        // thoroughly in its own test suite. This is just a check
+        auto pp = m.getEventsWithin(20, 10);
         QCOMPARE(pp.size(), 2);
         QCOMPARE(*pp.begin(), p1);
         QCOMPARE(*pp.rbegin(), p2);
         
-        pp = m.getAllEvents(40, 50);
+        pp = m.getEventsWithin(40, 10);
         QCOMPARE(pp.size(), 0);
 
-        pp = m.getAllEvents(50, 50);
+        pp = m.getEventsStartingAt(50);
         QCOMPARE(pp.size(), 1);
         QCOMPARE(*pp.begin(), p3);
-*/
     }
 
     void s1d_xml() {