# HG changeset patch # User Chris Cannam # Date 1480067856 0 # Node ID 4b0c968a581a44a9447b9c7120de262fe50069f8 # Parent 22f66068b464abca422ba876d42ef08c9477de86 Add Winnow as well diff -r 22f66068b464 -r 4b0c968a581a data/model/Labeller.h --- 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 + Command *winnow(SparseModel &model, MultiSelection *ms, int n) { + + typename SparseModel::PointList::iterator i; + typename SparseModel::PointList pl(model.getPoints()); + + typename SparseModel::EditCommand *command = + new typename SparseModel::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 void setValue(PointType &newPoint, PointType *prevPoint = 0) { if (m_type == ValueFromExistingNeighbour) {