Mercurial > hg > svcore
comparison data/model/SparseModel.h @ 1064:c9fdd9921146 tonioni
Implement FillGaps option in SparseModel export
| author | Chris Cannam |
|---|---|
| date | Tue, 31 Mar 2015 11:54:57 +0100 |
| parents | 57633d605547 |
| children | 0fd3661bcfff |
comparison
equal
deleted
inserted
replaced
| 1063:074d7c51e973 | 1064:c9fdd9921146 |
|---|---|
| 151 virtual QString toDelimitedDataString(QString delimiter) const { | 151 virtual QString toDelimitedDataString(QString delimiter) const { |
| 152 return toDelimitedDataStringWithOptions(delimiter, DataExportDefaults); | 152 return toDelimitedDataStringWithOptions(delimiter, DataExportDefaults); |
| 153 } | 153 } |
| 154 | 154 |
| 155 virtual QString toDelimitedDataStringWithOptions(QString delimiter, | 155 virtual QString toDelimitedDataStringWithOptions(QString delimiter, |
| 156 DataExportOptions opts) const { | 156 DataExportOptions opts) const { |
| 157 QString s; | 157 return toDelimitedDataStringSubsetWithOptions |
| 158 for (PointListConstIterator i = m_points.begin(); i != m_points.end(); ++i) { | 158 (delimiter, opts, |
| 159 s += i->toDelimitedDataString(delimiter, opts, m_sampleRate) + "\n"; | 159 std::min(getStartFrame(), sv_frame_t(0)), getEndFrame()); |
| 160 } | |
| 161 return s; | |
| 162 } | 160 } |
| 163 | 161 |
| 164 virtual QString toDelimitedDataStringSubset(QString delimiter, sv_frame_t f0, sv_frame_t f1) const { | 162 virtual QString toDelimitedDataStringSubset(QString delimiter, sv_frame_t f0, sv_frame_t f1) const { |
| 165 return toDelimitedDataStringSubsetWithOptions(delimiter, DataExportDefaults, f0, f1); | 163 return toDelimitedDataStringSubsetWithOptions(delimiter, DataExportDefaults, f0, f1); |
| 166 } | 164 } |
| 167 | 165 |
| 168 virtual QString toDelimitedDataStringSubsetWithOptions(QString delimiter, DataExportOptions opts, sv_frame_t f0, sv_frame_t f1) const { | 166 virtual QString toDelimitedDataStringSubsetWithOptions(QString delimiter, DataExportOptions opts, sv_frame_t f0, sv_frame_t f1) const { |
| 169 QString s; | 167 if (opts & DataExportFillGaps) { |
| 170 for (PointListConstIterator i = m_points.begin(); i != m_points.end(); ++i) { | 168 return toDelimitedDataStringSubsetFilled(delimiter, opts, f0, f1); |
| 171 if (i->frame >= f0 && i->frame < f1) { | 169 } else { |
| 172 s += i->toDelimitedDataString(delimiter, opts, m_sampleRate) + "\n"; | 170 QString s; |
| 171 for (PointListConstIterator i = m_points.begin(); i != m_points.end(); ++i) { | |
| 172 if (i->frame >= f0 && i->frame < f1) { | |
| 173 s += i->toDelimitedDataString(delimiter, opts, m_sampleRate) + "\n"; | |
| 174 } | |
| 173 } | 175 } |
| 174 } | 176 return s; |
| 175 return s; | 177 } |
| 176 } | 178 } |
| 177 | 179 |
| 178 /** | 180 /** |
| 179 * Command to add a point, with undo. | 181 * Command to add a point, with undo. |
| 180 */ | 182 */ |
| 460 | 462 |
| 461 if (indexAtFrame > 0) { | 463 if (indexAtFrame > 0) { |
| 462 std::cerr << "WARNING: SparseModel::getPointListIteratorForRow: No iterator available for row " << row << " (frame = " << frame << ", index at frame = " << initialIndexAtFrame << ", leftover index " << indexAtFrame << ")" << std::endl; | 464 std::cerr << "WARNING: SparseModel::getPointListIteratorForRow: No iterator available for row " << row << " (frame = " << frame << ", index at frame = " << initialIndexAtFrame << ", leftover index " << indexAtFrame << ")" << std::endl; |
| 463 } | 465 } |
| 464 return i; | 466 return i; |
| 467 } | |
| 468 | |
| 469 QString toDelimitedDataStringSubsetFilled(QString delimiter, | |
| 470 DataExportOptions opts, | |
| 471 sv_frame_t f0, | |
| 472 sv_frame_t f1) const { | |
| 473 | |
| 474 QString s; | |
| 475 opts &= ~DataExportFillGaps; | |
| 476 | |
| 477 // find frame time of first point in range (if any) | |
| 478 sv_frame_t first = f0; | |
| 479 for (auto &p: m_points) { | |
| 480 if (p.frame >= f0) { | |
| 481 first = p.frame; | |
| 482 break; | |
| 483 } | |
| 484 } | |
| 485 | |
| 486 // project back to first frame time in range according to | |
| 487 // resolution. e.g. if f0 = 2, first = 9, resolution = 4 then | |
| 488 // we start at 5 (because 1 is too early and we need to arrive | |
| 489 // at 9 to match the first actual point). This method is | |
| 490 // stupid but easy to understand: | |
| 491 sv_frame_t f = first; | |
| 492 while (f >= f0 + m_resolution) f -= m_resolution; | |
| 493 | |
| 494 // now progress, either writing the next point (if within | |
| 495 // distance) or a default point | |
| 496 PointListConstIterator itr = m_points.begin(); | |
| 497 | |
| 498 while (f < f1) { | |
| 499 if (itr != m_points.end() && itr->frame <= f) { | |
| 500 s += itr->toDelimitedDataString(delimiter, opts, m_sampleRate); | |
| 501 ++itr; | |
| 502 } else { | |
| 503 s += Point(f).toDelimitedDataString(delimiter, opts, m_sampleRate); | |
| 504 } | |
| 505 s += "\n"; | |
| 506 f += m_resolution; | |
| 507 } | |
| 508 | |
| 509 return s; | |
| 465 } | 510 } |
| 466 }; | 511 }; |
| 467 | 512 |
| 468 | 513 |
| 469 template <typename PointType> | 514 template <typename PointType> |
