changeset 256:9c85517ff0f5

* Fix #1706927 NaNs from plugin outputs should not be used
author Chris Cannam
date Fri, 27 Apr 2007 15:39:48 +0000
parents 7033e188b2b2
children 46398ab6ff58
files data/fileio/CSVFileReader.cpp data/model/EditableDenseThreeDimensionalModel.cpp data/model/EditableDenseThreeDimensionalModel.h data/model/NoteModel.h data/model/SparseTimeValueModel.h data/model/SparseValueModel.h plugin/plugin.pro
diffstat 7 files changed, 58 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/data/fileio/CSVFileReader.cpp	Thu Apr 19 15:19:51 2007 +0000
+++ b/data/fileio/CSVFileReader.cpp	Fri Apr 27 15:39:48 2007 +0000
@@ -142,9 +142,7 @@
 		break;
 		
 	    case CSVFormatDialog::TwoDimensionalModel:
-		model2 = new SparseTimeValueModel(sampleRate, windowSize,
-						  0.0, 0.0,
-						  false);
+		model2 = new SparseTimeValueModel(sampleRate, windowSize, false);
 		model = model2;
 		break;
 		
--- a/data/model/EditableDenseThreeDimensionalModel.cpp	Thu Apr 19 15:19:51 2007 +0000
+++ b/data/model/EditableDenseThreeDimensionalModel.cpp	Fri Apr 27 15:39:48 2007 +0000
@@ -19,6 +19,8 @@
 
 #include <iostream>
 
+#include <cmath>
+
 EditableDenseThreeDimensionalModel::EditableDenseThreeDimensionalModel(size_t sampleRate,
                                                                        size_t resolution,
                                                                        size_t yBinCount,
@@ -28,6 +30,7 @@
     m_yBinCount(yBinCount),
     m_minimum(0.0),
     m_maximum(0.0),
+    m_haveExtents(false),
     m_notifyOnAdd(notifyOnAdd),
     m_sinceLastNotifyMin(-1),
     m_sinceLastNotifyMax(-1),
@@ -68,6 +71,7 @@
 
     model->m_minimum = m_minimum;
     model->m_maximum = m_maximum;
+    model->m_haveExtents = m_haveExtents;
 
     for (size_t i = 0; i < m_data.size(); ++i) {
 	model->setColumn(i, m_data[i]);
@@ -152,8 +156,8 @@
 
     if (index < m_data.size()) {
 	const Column &s = m_data[index];
-        std::cerr << "index " << index << ", n " << n << ", res " << m_resolution << ", size " << s.size()
-                  << std::endl;
+//        std::cerr << "index " << index << ", n " << n << ", res " << m_resolution << ", size " << s.size()
+//                  << std::endl;
 	if (n < s.size()) return s[n];
     }
 
@@ -170,18 +174,22 @@
 	m_data.push_back(Column());
     }
 
-    bool newExtents = (m_data.empty() && (m_minimum == m_maximum));
     bool allChange = false;
 
     for (size_t i = 0; i < values.size(); ++i) {
-	if (newExtents || values[i] < m_minimum) {
-	    m_minimum = values[i];
+        float value = values[i];
+        if (isnan(value) || isinf(value)) {
+            continue;
+        }
+	if (!m_haveExtents || value < m_minimum) {
+	    m_minimum = value;
 	    allChange = true;
 	}
-	if (newExtents || values[i] > m_maximum) {
-	    m_maximum = values[i];
+	if (!m_haveExtents || value > m_maximum) {
+	    m_maximum = value;
 	    allChange = true;
 	}
+        m_haveExtents = true;
     }
 
     m_data[index] = values;
--- a/data/model/EditableDenseThreeDimensionalModel.h	Thu Apr 19 15:19:51 2007 +0000
+++ b/data/model/EditableDenseThreeDimensionalModel.h	Fri Apr 27 15:39:48 2007 +0000
@@ -127,6 +127,7 @@
     size_t m_yBinCount;
     float m_minimum;
     float m_maximum;
+    bool m_haveExtents;
     bool m_notifyOnAdd;
     long m_sinceLastNotifyMin;
     long m_sinceLastNotifyMax;
--- a/data/model/NoteModel.h	Thu Apr 19 15:19:51 2007 +0000
+++ b/data/model/NoteModel.h	Fri Apr 27 15:39:48 2007 +0000
@@ -83,6 +83,15 @@
 {
 public:
     NoteModel(size_t sampleRate, size_t resolution,
+	      bool notifyOnAdd = true) :
+	SparseValueModel<Note>(sampleRate, resolution,
+			       notifyOnAdd),
+	m_valueQuantization(0)
+    {
+	PlayParameterRepository::getInstance()->addModel(this);
+    }
+
+    NoteModel(size_t sampleRate, size_t resolution,
 	      float valueMinimum, float valueMaximum,
 	      bool notifyOnAdd = true) :
 	SparseValueModel<Note>(sampleRate, resolution,
--- a/data/model/SparseTimeValueModel.h	Thu Apr 19 15:19:51 2007 +0000
+++ b/data/model/SparseTimeValueModel.h	Fri Apr 27 15:39:48 2007 +0000
@@ -77,6 +77,14 @@
 {
 public:
     SparseTimeValueModel(size_t sampleRate, size_t resolution,
+			 bool notifyOnAdd = true) :
+	SparseValueModel<TimeValuePoint>(sampleRate, resolution,
+					 notifyOnAdd)
+    {
+	PlayParameterRepository::getInstance()->addModel(this);
+    }
+
+    SparseTimeValueModel(size_t sampleRate, size_t resolution,
 			 float valueMinimum, float valueMaximum,
 			 bool notifyOnAdd = true) :
 	SparseValueModel<TimeValuePoint>(sampleRate, resolution,
--- a/data/model/SparseValueModel.h	Thu Apr 19 15:19:51 2007 +0000
+++ b/data/model/SparseValueModel.h	Fri Apr 27 15:39:48 2007 +0000
@@ -30,11 +30,20 @@
 {
 public:
     SparseValueModel(size_t sampleRate, size_t resolution,
+		     bool notifyOnAdd = true) :
+	SparseModel<PointType>(sampleRate, resolution, notifyOnAdd),
+	m_valueMinimum(0.f),
+	m_valueMaximum(0.f),
+        m_haveExtents(false)
+    { }
+
+    SparseValueModel(size_t sampleRate, size_t resolution,
 		     float valueMinimum, float valueMaximum,
 		     bool notifyOnAdd = true) :
 	SparseModel<PointType>(sampleRate, resolution, notifyOnAdd),
 	m_valueMinimum(valueMinimum),
-	m_valueMaximum(valueMaximum)
+	m_valueMaximum(valueMaximum),
+        m_haveExtents(true)
     { }
 
     using SparseModel<PointType>::m_points;
@@ -52,12 +61,16 @@
     virtual void addPoint(const PointType &point)
     {
 	bool allChange = false;
-	if (m_points.empty() || point.value < m_valueMinimum) {
-	    m_valueMinimum = point.value; allChange = true;
-	}
-	if (m_points.empty() || point.value > m_valueMaximum) {
-	    m_valueMaximum = point.value; allChange = true;
-	}
+
+        if (!isnan(point.value) && !isinf(point.value)) {
+            if (!m_haveExtents || point.value < m_valueMinimum) {
+                m_valueMinimum = point.value; allChange = true;
+            }
+            if (!m_haveExtents || point.value > m_valueMaximum) {
+                m_valueMaximum = point.value; allChange = true;
+            }
+            m_haveExtents = true;
+        }
 
 	SparseModel<PointType>::addPoint(point);
 	if (allChange) emit modelChanged();
@@ -103,6 +116,7 @@
 protected:
     float m_valueMinimum;
     float m_valueMaximum;
+    bool m_haveExtents;
     QString m_units;
 };
 
--- a/plugin/plugin.pro	Thu Apr 19 15:19:51 2007 +0000
+++ b/plugin/plugin.pro	Fri Apr 27 15:39:48 2007 +0000
@@ -8,6 +8,9 @@
 
 TARGET = svplugin
 
+# Doesn't work with this library, which contains C99 as well as C++
+PRECOMPILED_HEADER =
+
 DEPENDPATH += . .. api plugins api/alsa api/alsa/sound
 INCLUDEPATH += . .. api api/alsa plugins api/alsa/sound
 OBJECTS_DIR = tmp_obj