Mercurial > hg > svcore
comparison base/EventSeries.cpp @ 1679:0d89abd631ac single-point
Re-add the toDelimitedDataString stuff
author | Chris Cannam |
---|---|
date | Thu, 28 Mar 2019 16:03:36 +0000 |
parents | f97d64b8674f |
children | ff8c57c364a0 |
comparison
equal
deleted
inserted
replaced
1678:1078f0ef3012 | 1679:0d89abd631ac |
---|---|
11 License, or (at your option) any later version. See the file | 11 License, or (at your option) any later version. See the file |
12 COPYING included with this distribution for more information. | 12 COPYING included with this distribution for more information. |
13 */ | 13 */ |
14 | 14 |
15 #include "EventSeries.h" | 15 #include "EventSeries.h" |
16 | |
17 EventSeries | |
18 EventSeries::fromEvents(const EventVector &v) | |
19 { | |
20 EventSeries s; | |
21 for (const auto &e: v) { | |
22 s.add(e); | |
23 } | |
24 return s; | |
25 } | |
16 | 26 |
17 bool | 27 bool |
18 EventSeries::isEmpty() const | 28 EventSeries::isEmpty() const |
19 { | 29 { |
20 return m_events.empty(); | 30 return m_events.empty(); |
503 } | 513 } |
504 | 514 |
505 out << indent << "</dataset>\n"; | 515 out << indent << "</dataset>\n"; |
506 } | 516 } |
507 | 517 |
508 | 518 QString |
519 EventSeries::toDelimitedDataString(QString delimiter, | |
520 DataExportOptions options, | |
521 sv_frame_t startFrame, | |
522 sv_frame_t duration, | |
523 sv_samplerate_t sampleRate, | |
524 sv_frame_t resolution, | |
525 Event fillEvent) const | |
526 { | |
527 QString s; | |
528 | |
529 const sv_frame_t end = startFrame + duration; | |
530 | |
531 auto pitr = lower_bound(m_events.begin(), m_events.end(), | |
532 Event(startFrame)); | |
533 | |
534 if (!(options & DataExportFillGaps)) { | |
535 | |
536 while (pitr != m_events.end() && pitr->getFrame() < end) { | |
537 s += pitr->toDelimitedDataString(delimiter, | |
538 options, | |
539 sampleRate); | |
540 s += "\n"; | |
541 ++pitr; | |
542 } | |
543 | |
544 } else { | |
545 | |
546 // find frame time of first point in range (if any) | |
547 sv_frame_t first = startFrame; | |
548 if (pitr != m_events.end()) { | |
549 first = pitr->getFrame(); | |
550 } | |
551 | |
552 // project back to first frame time in range according to | |
553 // resolution. e.g. if f0 = 2, first = 9, resolution = 4 then | |
554 // we start at 5 (because 1 is too early and we need to arrive | |
555 // at 9 to match the first actual point). This method is | |
556 // stupid but easy to understand: | |
557 sv_frame_t f = first; | |
558 while (f >= startFrame + resolution) f -= resolution; | |
559 | |
560 // now progress, either writing the next point (if within | |
561 // distance) or a default fill point | |
562 while (f < end) { | |
563 if (pitr != m_events.end() && pitr->getFrame() <= f) { | |
564 s += pitr->toDelimitedDataString | |
565 (delimiter, | |
566 options & ~DataExportFillGaps, | |
567 sampleRate); | |
568 ++pitr; | |
569 } else { | |
570 s += fillEvent.withFrame(f).toDelimitedDataString | |
571 (delimiter, | |
572 options & ~DataExportFillGaps, | |
573 sampleRate); | |
574 } | |
575 s += "\n"; | |
576 f += resolution; | |
577 } | |
578 } | |
579 | |
580 return s; | |
581 } | |
582 |