diff data/fileio/CSVFileReader.cpp @ 1649:1cc9a0d4b1b6 single-point

Update RegionModel following NoteModel, er, model. They have quite a bit in common that we should now pull out some of
author Chris Cannam
date Fri, 15 Mar 2019 14:23:50 +0000
parents 513192aa9b03
children 7a56bb85030f
line wrap: on
line diff
--- a/data/fileio/CSVFileReader.cpp	Fri Mar 15 10:57:35 2019 +0000
+++ b/data/fileio/CSVFileReader.cpp	Fri Mar 15 14:23:50 2019 +0000
@@ -447,8 +447,8 @@
 
             } else if (modelType == CSVFormat::TwoDimensionalModelWithDuration) {
 
-                RegionModel::Point point(frameNo, value, duration, label);
-                model2a->addPoint(point);
+                Event region(frameNo, value, duration, label);
+                model2a->add(region);
 
             } else if (modelType == CSVFormat::TwoDimensionalModelWithDurationAndPitch) {
 
@@ -581,31 +581,30 @@
                 }
             }
 
-            map<RegionModel::Point, RegionModel::Point,
-                RegionModel::Point::Comparator> pointMap;
-            for (RegionModel::PointList::const_iterator i =
-                     model2a->getPoints().begin();
-                 i != model2a->getPoints().end(); ++i) {
-                RegionModel::Point p(*i);
-                int count = labelCountMap[p.label];
-                v = countLabelValueMap[count][p.label];
-              //  SVCERR << "mapping from label \"" << p.label << "\" (count " << count << ") to value " << v << endl;
-                RegionModel::Point pp(p.frame, v, p.duration, p.label);
-                pointMap[p] = pp;
+            map<Event, Event> eventMap;
+
+            EventVector allEvents = model2a->getAllEvents();
+            for (const Event &e: allEvents) {
+                int count = labelCountMap[e.getLabel()];
+                v = countLabelValueMap[count][e.getLabel()];
+                // SVCERR << "mapping from label \"" << p.label
+                //       << "\" (count " << count
+                //       << ") to value " << v << endl;
+                eventMap[e] = Event(e.getFrame(), v,
+                                    e.getDuration(), e.getLabel());
             }
 
-            for (map<RegionModel::Point, RegionModel::Point>::iterator i = 
-                     pointMap.begin(); i != pointMap.end(); ++i) {
+            for (const auto &i: eventMap) {
                 // There could be duplicate regions; if so replace
                 // them all -- but we need to check we're not
                 // replacing a region by itself (or else this will
                 // never terminate)
-                if (i->first.value == i->second.value) {
+                if (i.first.getValue() == i.second.getValue()) {
                     continue;
                 }
-                while (model2a->containsPoint(i->first)) {
-                    model2a->deletePoint(i->first);
-                    model2a->addPoint(i->second);
+                while (model2a->containsEvent(i.first)) {
+                    model2a->remove(i.first);
+                    model2a->add(i.second);
                 }
             }
         }