diff data/model/Labeller.h @ 1292:4b0c968a581a subdivide-instants

Add Winnow as well
author Chris Cannam
date Fri, 25 Nov 2016 09:57:36 +0000
parents 22f66068b464
children 114de081a42d
line wrap: on
line diff
--- a/data/model/Labeller.h	Fri Nov 25 09:38:53 2016 +0000
+++ b/data/model/Labeller.h	Fri Nov 25 09:57:36 2016 +0000
@@ -278,6 +278,50 @@
         return command->finish();
     }
 
+    /**
+     * Return a command that has been executed but not yet added to
+     * the history.
+     */
+    template <typename PointType>
+    Command *winnow(SparseModel<PointType> &model, MultiSelection *ms, int n) {
+        
+        typename SparseModel<PointType>::PointList::iterator i;
+        typename SparseModel<PointType>::PointList pl(model.getPoints());
+
+        typename SparseModel<PointType>::EditCommand *command =
+            new typename SparseModel<PointType>::EditCommand
+            (&model, tr("Subdivide"));
+
+        int counter = 0;
+        
+        for (i = pl.begin(); i != pl.end(); ++i) {
+
+            bool inRange = true;
+            if (ms) {
+                Selection s(ms->getContainingSelection(i->frame, false));
+                if (s.isEmpty() || !s.contains(i->frame)) {
+                    inRange = false;
+                }
+            }
+            if (!inRange) {
+                counter = 0;
+                continue;
+            }
+
+            ++counter;
+
+            if (counter == n+1) counter = 1;
+            if (counter == 1) {
+                // this is an Nth instant, don't remove it
+                continue;
+            }
+            
+            command->deletePoint(*i);
+        }
+
+        return command->finish();
+    }
+
     template <typename PointType>
     void setValue(PointType &newPoint, PointType *prevPoint = 0) {
         if (m_type == ValueFromExistingNeighbour) {