changeset 1254:cbdd534f517a piper

Avoid assigning model resolution of 0 to models coming from plugins that report weirdly high output rates (symptom: data did not show up in edit layer data dialog, as the row/frame conversion failed)
author Chris Cannam
date Sat, 05 Nov 2016 10:40:22 +0000
parents c2d66e3c83d0
children ca9032dd2811
files data/model/ModelDataTableModel.cpp data/model/SparseModel.h transform/FeatureExtractionModelTransformer.cpp
diffstat 3 files changed, 36 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/data/model/ModelDataTableModel.cpp	Fri Nov 04 14:39:15 2016 +0000
+++ b/data/model/ModelDataTableModel.cpp	Sat Nov 05 10:40:22 2016 +0000
@@ -47,7 +47,8 @@
     if (!m_model) return QVariant();
     if (role != Qt::EditRole && role != Qt::DisplayRole) return QVariant();
     if (!index.isValid()) return QVariant();
-    return m_model->getData(getUnsorted(index.row()), index.column(), role);
+    QVariant d = m_model->getData(getUnsorted(index.row()), index.column(), role);
+    return d;
 }
 
 bool
--- a/data/model/SparseModel.h	Fri Nov 04 14:39:15 2016 +0000
+++ b/data/model/SparseModel.h	Sat Nov 05 10:40:22 2016 +0000
@@ -332,8 +332,13 @@
     virtual QVariant getData(int row, int column, int role) const
     {
         PointListConstIterator i = getPointListIteratorForRow(row);
-        if (i == m_points.end()) return QVariant();
+        if (i == m_points.end()) {
+//            cerr << "no iterator for row " << row << " (have " << getRowCount() << " rows)" << endl;
+            return QVariant();
+        }
 
+//        cerr << "returning data for row " << row << " col " << column << endl;
+        
         switch (column) {
         case 0: {
             if (role == SortRole) return int(i->frame);
@@ -411,6 +416,7 @@
     // This is only used if the model is called on to act in
     // TabularModel mode
     mutable std::vector<sv_frame_t> m_rows; // map from row number to frame
+
     void rebuildRowVector() const
     {
         m_rows.clear();
@@ -458,7 +464,7 @@
         while (ri > 0 && m_rows[ri-1] == m_rows[row]) { --ri; ++indexAtFrame; }
         int initialIndexAtFrame = indexAtFrame;
 
-//        std::cerr << "getPointListIteratorForRow " << row << ": initialIndexAtFrame = " << initialIndexAtFrame << std::endl;
+//        std::cerr << "getPointListIteratorForRow " << row << ": initialIndexAtFrame = " << initialIndexAtFrame << " for frame " << frame << std::endl;
 
         PointListConstIterator i0, i1;
         getPointIterators(frame, i0, i1);
@@ -471,9 +477,13 @@
             if (indexAtFrame > 0) { --indexAtFrame; continue; }
             return i;
         }
-
-//        std::cerr << "returning i with i->frame = " << i->frame << std::endl;
-
+/*
+        if (i == m_points.end()) {
+            std::cerr << "returning i at end" << std::endl;
+        } else {
+            std::cerr << "returning i with i->frame = " << i->frame << std::endl;
+        }
+*/
         if (indexAtFrame > 0) {
             std::cerr << "WARNING: SparseModel::getPointListIteratorForRow: No iterator available for row " << row << " (frame = " << frame << ", index at frame = " << initialIndexAtFrame << ", leftover index " << indexAtFrame << ")" << std::endl;
         }
--- a/transform/FeatureExtractionModelTransformer.cpp	Fri Nov 04 14:39:15 2016 +0000
+++ b/transform/FeatureExtractionModelTransformer.cpp	Sat Nov 05 10:40:22 2016 +0000
@@ -277,21 +277,33 @@
     }
 
     sv_samplerate_t modelRate = input->getSampleRate();
+    sv_samplerate_t outputRate = modelRate;
     int modelResolution = 1;
 
     if (m_descriptors[n]->sampleType != 
         Vamp::Plugin::OutputDescriptor::OneSamplePerStep) {
-        if (m_descriptors[n]->sampleRate > input->getSampleRate()) {
+
+        outputRate = m_descriptors[n]->sampleRate;
+
+        //!!! SV doesn't actually support display of models that have
+        //!!! different underlying rates together -- so we always set
+        //!!! the model rate to be the input model's rate, and adjust
+        //!!! the resolution appropriately.  We can't properly display
+        //!!! data with a higher resolution than the base model at all
+        if (outputRate > input->getSampleRate()) {
             cerr << "WARNING: plugin reports output sample rate as "
-                      << m_descriptors[n]->sampleRate << " (can't display features with finer resolution than the input rate of " << input->getSampleRate() << ")" << endl;
+                 << outputRate
+                 << " (can't display features with finer resolution than the input rate of "
+                 << modelRate << ")" << endl;
+            outputRate = modelRate;
         }
     }
 
     switch (m_descriptors[n]->sampleType) {
 
     case Vamp::Plugin::OutputDescriptor::VariableSampleRate:
-	if (m_descriptors[n]->sampleRate != 0.0) {
-	    modelResolution = int(round(modelRate / m_descriptors[n]->sampleRate));
+	if (outputRate != 0.0) {
+	    modelResolution = int(round(modelRate / outputRate));
 	}
 	break;
 
@@ -300,18 +312,12 @@
 	break;
 
     case Vamp::Plugin::OutputDescriptor::FixedSampleRate:
-        //!!! SV doesn't actually support display of models that have
-        //!!! different underlying rates together -- so we always set
-        //!!! the model rate to be the input model's rate, and adjust
-        //!!! the resolution appropriately.  We can't properly display
-        //!!! data with a higher resolution than the base model at all
-        if (m_descriptors[n]->sampleRate > input->getSampleRate()) {
-            modelResolution = 1;
-        } else if (m_descriptors[n]->sampleRate <= 0.0) {
+        if (outputRate <= 0.0) {
             cerr << "WARNING: Fixed sample-rate plugin reports invalid sample rate " << m_descriptors[n]->sampleRate << "; defaulting to input rate of " << input->getSampleRate() << endl;
             modelResolution = 1;
         } else {
-            modelResolution = int(round(modelRate / m_descriptors[n]->sampleRate));
+            modelResolution = int(round(modelRate / outputRate));
+//            cerr << "modelRate = " << modelRate << ", descriptor rate = " << outputRate << ", modelResolution = " << modelResolution << endl;
         }
 	break;
     }