[midisnoop] push by surfacep...@gmail.com - Add implementation to get millisecond timestamps when Qt is before 4.7... on 2013-02-28 06:04 GMT

0 views
Skip to first unread message

midi...@googlecode.com

unread,
Feb 28, 2013, 1:05:01 AM2/28/13
to midisnoop-...@googlegroups.com
Revision: 3dc8c19e224d
Author: Devin Anderson <surface...@gmail.com>
Date: Wed Feb 27 22:04:38 2013
Log: Add implementation to get millisecond timestamps when Qt is
before 4.7.

http://code.google.com/p/midisnoop/source/detail?r=3dc8c19e224d

Modified:
/install/util.py
/src/engine.cpp
/src/engine.h
/src/src.pro

=======================================
--- /install/util.py Sun Dec 30 16:43:13 2012
+++ /install/util.py Wed Feb 27 22:04:38 2013
@@ -17,7 +17,7 @@

MAJOR_VERSION = 0
MINOR_VERSION = 1
-REVISION = 0
+REVISION = 2
VERSION = "%d.%d.%d" % (MAJOR_VERSION, MINOR_VERSION, REVISION)

PLATFORM_MACX = 1
=======================================
--- /src/engine.cpp Sun Dec 30 19:40:00 2012
+++ /src/engine.cpp Wed Feb 27 22:04:38 2013
@@ -19,12 +19,19 @@

#include <cassert>

-#include <QtCore/QDateTime>
#include <QtCore/QDebug>

#include "engine.h"
#include "error.h"

+#if QT_VERSION >= 0x040700
+#include <QtCore/QDateTime>
+#else
+#include <cerrno>
+#include <cstring>
+#include <sys/time.h>
+#endif
+
// Static functions

void
@@ -160,12 +167,29 @@
assert((index >= 0) && (index < outputPortNames.count()));
return outputPortNames[index];
}
+
+quint64
+Engine::getCurrentTimestamp() const
+{
+
+#if QT_VERSION >= 0x040700
+ return QDateTime::currentDateTime().toMSecsSinceEpoch();
+#else
+ struct timeval time;
+ if (gettimeofday(&time, 0) == -1) {
+ throw Error(tr("failed to get time of
day: %1").arg(strerror(errno)));
+ }
+ return (static_cast<quint64>(time.tv_sec) * 1000) +
+ (static_cast<quint64>(time.tv_usec) / 1000);
+#endif
+
+}

void
Engine::handleMidiInput(double /*timeStamp*/,
std::vector<unsigned char> *message)
{
- quint64 timeStamp = QDateTime::currentDateTime().toMSecsSinceEpoch();
+ quint64 timeStamp = getCurrentTimestamp();
QByteArray msg;
int size = static_cast<int>(message->size());
for (int i = 0; i < size; i++) {
@@ -202,7 +226,7 @@
} catch (RtError &e) {
throw Error(e.what());
}
- return QDateTime::currentDateTime().toMSecsSinceEpoch();
+ return getCurrentTimestamp();
}

void
=======================================
--- /src/engine.h Sun Dec 30 01:18:51 2012
+++ /src/engine.h Wed Feb 27 22:04:38 2013
@@ -137,6 +137,9 @@
handleMidiInput(double timeStamp, std::vector<unsigned char> *message,
void *engine);

+ quint64
+ getCurrentTimestamp() const;
+
void
handleMidiInput(double timeStamp, std::vector<unsigned char> *message);

=======================================
--- /src/src.pro Mon Dec 31 13:11:12 2012
+++ /src/src.pro Wed Feb 27 22:04:38 2013
@@ -24,7 +24,7 @@
MINOR_VERSION = 1
}
isEmpty(REVISION) {
- REVISION = 0
+ REVISION = 2
}
MIDISNOOP_VERSION = $${MAJOR_VERSION}.$${MINOR_VERSION}.$${REVISION}

Reply all
Reply to author
Forward
0 new messages