aboutsummaryrefslogtreecommitdiff
path: root/paperreplay.cc
diff options
context:
space:
mode:
authorJavier <dev.git@javispedro.com>2021-09-12 19:41:12 +0200
committerJavier <dev.git@javispedro.com>2021-09-12 19:41:12 +0200
commitac7b085449fb49f54225d22c7c229da6ad120e2b (patch)
tree7910cc8c9a3268dbacbbe434c7f3cea4eedafd3d /paperreplay.cc
parent66dd35254724ec5d4471a8be71f92e06cf0fa8e8 (diff)
downloadscribiu-ac7b085449fb49f54225d22c7c229da6ad120e2b.tar.gz
scribiu-ac7b085449fb49f54225d22c7c229da6ad120e2b.zip
remove PEN_EPOCH mistake and get usertime from the pen
Diffstat (limited to 'paperreplay.cc')
-rw-r--r--paperreplay.cc61
1 files changed, 37 insertions, 24 deletions
diff --git a/paperreplay.cc b/paperreplay.cc
index bec39f1..c7a7f49 100644
--- a/paperreplay.cc
+++ b/paperreplay.cc
@@ -20,6 +20,7 @@
#include <QtCore/QDataStream>
#include <QtCore/QDirIterator>
#include "smartpen.h"
+#include "afdpageaddress.h"
#include "paperreplay.h"
namespace
@@ -57,7 +58,7 @@ PaperReplay::Session::Session() : d()
{
}
-PaperReplay::Session::Session(quint64 id) : d(new SessionData)
+PaperReplay::Session::Session(SessionId id) : d(new SessionData)
{
d->id = id;
}
@@ -71,7 +72,7 @@ bool PaperReplay::Session::isValid() const
return d;
}
-quint64 PaperReplay::Session::id() const
+PaperReplay::SessionId PaperReplay::Session::id() const
{
return d ? d->id : 0;
}
@@ -86,12 +87,12 @@ QString PaperReplay::Session::fileName() const
return d->file;
}
-qint64 PaperReplay::Session::startTime() const
+PaperReplay::PenTime PaperReplay::Session::startTime() const
{
return d->start;
}
-qint64 PaperReplay::Session::endTime() const
+PaperReplay::PenTime PaperReplay::Session::endTime() const
{
return d->end;
}
@@ -105,16 +106,16 @@ PaperReplay::SessionList::SessionList()
{
}
-PaperReplay::SessionList::SessionList(const QMap<qint64, Session> &byTime)
+PaperReplay::SessionList::SessionList(const QMap<PenTime, Session> &byTime)
: _m(byTime)
{
}
-QList<PaperReplay::Session> PaperReplay::SessionList::sessionsDuringTime(qint64 time) const
+QList<PaperReplay::Session> PaperReplay::SessionList::sessionsDuringTime(PenTime time) const
{
QList<Session> sessions;
if (_m.isEmpty()) return sessions;
- QMap<qint64, Session>::const_iterator it = _m.lowerBound(time);
+ QMap<PenTime, Session>::const_iterator it = _m.lowerBound(time);
if (it == _m.end()) --it;
@@ -129,7 +130,7 @@ QList<PaperReplay::Session> PaperReplay::SessionList::sessionsDuringTime(qint64
return sessions;
}
-bool PaperReplay::open(const QString &path, quint64 notebookGuid)
+bool PaperReplay::open(const QString &path, quint64 notebookGuid, PenTime userTime)
{
QString penSerial = findPenSerial(path);
if (penSerial.isEmpty()) {
@@ -145,6 +146,8 @@ bool PaperReplay::open(const QString &path, quint64 notebookGuid)
return false;
}
+ _userTime = userTime;
+
QDirIterator iter(_dir.path(), QStringList("PRS-*"), QDir::Dirs | QDir::NoDotAndDotDot);
while (iter.hasNext()) {
bool ok;
@@ -185,6 +188,7 @@ void PaperReplay::close()
_byPageTime.clear();
_sessions.clear();
_dir.setPath(QString());
+ _userTime = 0;
}
QList<PaperReplay::Session> PaperReplay::sessions() const
@@ -192,12 +196,17 @@ QList<PaperReplay::Session> PaperReplay::sessions() const
return _sessions.values();
}
-PaperReplay::SessionList PaperReplay::sessions(quint64 pageAddress) const
+PaperReplay::SessionList PaperReplay::sessions(PageAddress pageAddress) const
{
return SessionList(_byPageTime[pageAddress]);
}
-bool PaperReplay::parseSessionInfo(SessionData *session, const QString &path)
+PaperReplay::PenTime PaperReplay::userTime() const
+{
+ return _userTime;
+}
+
+bool PaperReplay::parseSessionInfo(SessionData *session, const QString &path) const
{
QFile f(path);
if (f.open(QIODevice::ReadOnly)) {
@@ -207,7 +216,7 @@ bool PaperReplay::parseSessionInfo(SessionData *session, const QString &path)
}
}
-bool PaperReplay::parseSessionInfo(SessionData *session, QIODevice *dev)
+bool PaperReplay::parseSessionInfo(SessionData *session, QIODevice *dev) const
{
unsigned char magic[2];
if (dev->read(reinterpret_cast<char*>(magic), 2) != 2 ||
@@ -231,12 +240,12 @@ bool PaperReplay::parseSessionInfo(SessionData *session, QIODevice *dev)
}
}
-bool PaperReplay::parseSessionInfoV3(SessionData *session, QIODevice *dev)
+bool PaperReplay::parseSessionInfoV3(SessionData *session, QIODevice *dev) const
{
QDataStream s(dev);
if (s.skipRawData(5) != 5) return false;
- qint64 startTime, endTime, creationTime;
+ PenTime startTime, endTime, creationTime;
QString name;
s >> startTime >> endTime >> creationTime;
@@ -248,12 +257,14 @@ bool PaperReplay::parseSessionInfoV3(SessionData *session, QIODevice *dev)
session->start = startTime;
session->end = endTime;
- qDebug() << "Session:" << name << Smartpen::fromPenTime(session->start) << Smartpen::fromPenTime(session->end);
+ qDebug() << " paperreplay" << QString("PRS-%1").arg(session->id, 0, 16) << name
+ << Smartpen::fromPenTime(_userTime, session->start)
+ << Smartpen::fromPenTime(_userTime, session->end);
quint16 num_clips;
s >> num_clips;
- Q_ASSERT(num_clips == 1); // TODO: We do not yet know how to handle this scenario
+ Q_ASSERT(num_clips == 1); // TODO: We do not yet know how to handle this scenario (more than one audio file per session)
for (uint i = 0; i < num_clips; ++i) {
QString file;
@@ -262,14 +273,16 @@ bool PaperReplay::parseSessionInfoV3(SessionData *session, QIODevice *dev)
}
s >> startTime >> endTime;
- qDebug() << " Clip:" << file << Smartpen::fromPenTime(startTime) << Smartpen::fromPenTime(endTime);
+ qDebug() << " clip" << file
+ << Smartpen::fromPenTime(_userTime, startTime) << Smartpen::fromPenTime(_userTime, endTime);
session->file = file;
}
quint16 num_strokes;
s >> num_strokes;
- // TODO:
+ // We are not doing anything with the stroke data stored here,
+ // rather we match the paperreplay when we load the strokes from notebook files
for (uint i = 0; i < num_strokes; ++i) {
quint64 a, b, c;
quint32 d;
@@ -280,13 +293,13 @@ bool PaperReplay::parseSessionInfoV3(SessionData *session, QIODevice *dev)
return false;
}
s >> f >> g;
- qDebug() << " Stroke:" << a << b << c << d << nbGuid << f << g;
+ qDebug() << " stroke" << a << b << c << d << nbGuid << f << g;
}
return true;
}
-bool PaperReplay::parseSessionPages(SessionData *session, const QString &path)
+bool PaperReplay::parseSessionPages(SessionData *session, const QString &path) const
{
QFile f(path);
if (f.open(QIODevice::ReadOnly)) {
@@ -296,7 +309,7 @@ bool PaperReplay::parseSessionPages(SessionData *session, const QString &path)
}
}
-bool PaperReplay::parseSessionPages(SessionData *session, QIODevice *dev)
+bool PaperReplay::parseSessionPages(SessionData *session, QIODevice *dev) const
{
unsigned char magic[2];
if (dev->read(reinterpret_cast<char*>(magic), 2) != 2 ||
@@ -320,7 +333,7 @@ bool PaperReplay::parseSessionPages(SessionData *session, QIODevice *dev)
}
}
-bool PaperReplay::parseSessionPagesV1(SessionData *session, QIODevice *dev)
+bool PaperReplay::parseSessionPagesV1(SessionData *session, QIODevice *dev) const
{
QDataStream s(dev);
if (s.skipRawData(1) != 1) return false;
@@ -330,12 +343,12 @@ bool PaperReplay::parseSessionPagesV1(SessionData *session, QIODevice *dev)
session->pages.reserve(session->pages.size() + num_pages);
for (uint i = 0; i < num_pages; ++i) {
- quint64 address;
- qint64 time;
+ PageAddress address;
+ PenTime time;
s >> address >> time;
session->pages.append(address);
- qDebug() << " Page:" << address << time << Smartpen::fromPenTime(time);
+ qDebug() << " page" << AfdPageAddress(address).toString() << Smartpen::fromPenTime(_userTime, time);
}
return true;