From d0e882e6b759ffe18a545cb8cce18ca402eac763 Mon Sep 17 00:00:00 2001 From: Javier Date: Mon, 20 Sep 2021 00:45:38 +0200 Subject: use stf speed to compute time between stroke points in txyf export --- paperreplay.cc | 7 ++++++- paperreplay.h | 3 ++- paperreplaymodel.cc | 4 ++-- stfexporter.cc | 15 +++------------ stfreader.cc | 16 ++++++++-------- stfstrokeitem.cc | 2 +- 6 files changed, 22 insertions(+), 25 deletions(-) diff --git a/paperreplay.cc b/paperreplay.cc index c7a7f49..9f0a7f6 100644 --- a/paperreplay.cc +++ b/paperreplay.cc @@ -97,7 +97,12 @@ PaperReplay::PenTime PaperReplay::Session::endTime() const return d->end; } -bool PaperReplay::Session::startTimeLess(const Session &a, const Session &b) +PaperReplay::PenTime PaperReplay::Session::duration() const +{ + return d->end - d->start; +} + +bool PaperReplay::Session::compareByStartTime(const Session &a, const Session &b) { return a.d->start < b.d->start; } diff --git a/paperreplay.h b/paperreplay.h index 62a75a6..5427dee 100644 --- a/paperreplay.h +++ b/paperreplay.h @@ -63,12 +63,13 @@ public: PenTime startTime() const; PenTime endTime() const; + PenTime duration() const; QVector pages() const; QString fileName() const; - static bool startTimeLess(const Session &a, const Session &b); + static bool compareByStartTime(const Session &a, const Session &b); private: Session(SessionId id); diff --git a/paperreplaymodel.cc b/paperreplaymodel.cc index 4c40f76..dcab5cf 100644 --- a/paperreplaymodel.cc +++ b/paperreplaymodel.cc @@ -98,7 +98,7 @@ void PaperReplayModel::refresh() { beginResetModel(); _sessions = _replay->sessions(); - std::sort(_sessions.begin(), _sessions.end(), PaperReplay::Session::startTimeLess); + std::sort(_sessions.begin(), _sessions.end(), PaperReplay::Session::compareByStartTime); endResetModel(); } @@ -116,7 +116,7 @@ QString PaperReplayModel::getSessionName(const PaperReplay::Session &session) co QString PaperReplayModel::getSessionLength(const PaperReplay::Session &session) const { - qint64 msecs = session.endTime() - session.startTime(); + quint64 msecs = session.duration(); uint secs = msecs / 1000; uint mins = secs / 60; secs %= 60; diff --git a/stfexporter.cc b/stfexporter.cc index fcd7194..1503ae4 100644 --- a/stfexporter.cc +++ b/stfexporter.cc @@ -26,14 +26,12 @@ class StfToTXYP : public StfReader::StrokeHandler { QTextStream _out; - QPoint _lastP; - int _lastForce; qint64 _startTime; bool _relativeTime; public: StfToTXYP(QIODevice *out, bool relativeTime) - : _out(out), _lastP(), _lastForce(0), _startTime(0), _relativeTime(relativeTime) { + : _out(out), _startTime(0), _relativeTime(relativeTime) { _out << "T\tX\tY\tP\n"; } @@ -42,24 +40,17 @@ public: _startTime = time; } _out << (time - _startTime) << '\t' << p.x() << '\t' << p.y() << '\t' << force << '\n'; - _lastP = p; - _lastForce = force; return true; } bool strokePoint(const QPoint& p, int force, qint64 time) { _out << (time - _startTime) << '\t' << p.x() << '\t' << p.y() << '\t' << force << '\n'; - _lastP = p; - _lastForce = force; return true; } bool endStroke(qint64 time) { - // Ensure there is a entry with force=0, in case the pen didn't provide it - if (_lastForce != 0) { - _out << (time - _startTime) << '\t' << _lastP.x() << '\t' << _lastP.y() << '\t' << 0 << '\n'; - _lastForce = 0; - } + // Force == 0 is used to detect strokes + Q_UNUSED(time); return true; } }; diff --git a/stfreader.cc b/stfreader.cc index 270a39c..efe7412 100644 --- a/stfreader.cc +++ b/stfreader.cc @@ -45,7 +45,7 @@ StfReader::StrokeHandler::~StrokeHandler() bool StfReader::parseV1(BitReader& br) { - quint64 cur_time = 0; + quint64 stroke_time = 0; while (!br.atEnd()) { syncV1(br); @@ -76,18 +76,18 @@ bool StfReader::parseV1(BitReader& br) } /* Start of a stroke. */ - cur_time += time; + stroke_time += time; p0.setX(br.readBits(16)); p0.setY(br.readBits(16)); f0 = readForce(br); - quint64 stroke_time = cur_time; - if (handler) { - bool res = handler->startStroke(p0, f0, cur_time); + bool res = handler->startStroke(p0, f0, stroke_time); if (!res) return false; } + quint64 point_time = 0; + while (!br.atEnd()) { header = readHeader(br); if (header == 0 || header == 1) { @@ -112,7 +112,7 @@ bool StfReader::parseV1(BitReader& br) if (time == 0) { if (handler) { - bool res = handler->endStroke(stroke_time); + bool res = handler->endStroke(stroke_time + ((point_time * 1000ULL) / speed)); if (!res) return false; } break; @@ -151,10 +151,10 @@ bool StfReader::parseV1(BitReader& br) pa *= 256 / static_cast(time); f0 += deltaf; - stroke_time += time; + point_time += time; if (handler) { - bool res = handler->strokePoint(p0, f0, stroke_time); + bool res = handler->strokePoint(p0, f0, stroke_time + ((point_time * 1000ULL) / speed)); if (!res) return false; } } diff --git a/stfstrokeitem.cc b/stfstrokeitem.cc index 8fce6b7..a9ca693 100644 --- a/stfstrokeitem.cc +++ b/stfstrokeitem.cc @@ -54,7 +54,7 @@ void StfStrokeItem::mousePressEvent(QGraphicsSceneMouseEvent *event) PaperReplay::PenTime time = _startTime - _session.startTime(); if (time < 10) time = 0; - qDebug() << "requesting paper replay at time" << time << "/" << (_session.endTime() - _session.startTime()); + qDebug() << "requesting paper replay at time" << time << "/" << _session.duration(); nbview->requestPaperReplay(_session.fileName(), time); event->accept(); -- cgit v1.2.3