3

I'm trying to build an app that will accurately count time between taps, like a tap function on a metronome but finding the results to be inaccurate;

current_time = QDateTime.currentMSecsSinceEpoch ()

tap_old = tap_new
tap_new = current_time
tap_delay = (tap_new - tap_old) 
bpm = 60 / tap_delay

This was the plan but it didn't work out how I expected, giving me a range of values from around 110bpm to 130bpm while tapping along with another metronome set to 120bpm.

I've since tried adding the seconds and the last 3 digits of the microseconds together to see if this increased accuracy, but to no avail. And yes I'm sure this can be done more efficiently, but it was just a test;


 current_sec = QDateTime.currentSecsSinceEpoch ()
 current_msec = QDateTime.currentMSecsSinceEpoch ()
 current_msec = str(current_msec)
 current_msec1 = current_msec[10]
 current_msec2 = current_msec[11]
 current_msec3 = current_msec[12]
 current_msec = (current_msec1 + current_msec2 + current_msec3)
 current_msec = int(current_msec)
 current_msec = current_msec / 1000
 current_time = current_sec + (current_msec)

I've tried just subtracting the times by using current_time = QTime.currentTime() and also trying to compare the two; tap_delay = QTime.mSecsTo(self, tap_old). I definitely don't know how to use these functions so they just gave me errors.

4
  • First of all, summing the last three digits doesn't make any sense: you'd get the same identical sum from "900" and "009". It's also relatively possible that you'd end up with a different second between the two calls of currentSecsSinceEpoch() and currentMSecsSinceEpoch() (if, for instance, the first call happened at the end of the 1000th ms of a second, and the next one happened at the first ms of the next second). Then, "tapping" (you didn't specify the input method, which may matter) doesn't ensure precision, even assuming you're extremely precise: I'm a professional percussionist » Commented Aug 8 at 19:56
  • » and relatively good with timing, yet I still get a range of (at least) +/-5 at 120bpm from time to time, especially when using non "musical" input methods (eg: computer keyboard or mouse buttons). There must also be considered aspects related to the framework and underlying platform (especially when using touch devices), not to mention other aspects caused by the event management, all of which may affect the accuracy of the timing from the moment you physically "trigger" the event and when the event is eventually handled. Even if you're really precise, and you're using an input method that » Commented Aug 8 at 20:04
  • » allows accuracy (including accurate hardware), it's quite possible to still get slightly (if not relevantly) inaccurate results anyway, especially considering that Python is involved and a Python binding is being used as an interface to a C++ API. That said, using QDateTime or QTime doesn't make a lot of sense for such a purpose: "human date/time" data is irrelevant, and it's also prone to other issues such as DST adjustments or automatic system time updates. QElapsedTimer is much more appropriate, it's monotonic, and its implementation is also much lighter than those classes. Commented Aug 8 at 20:11
  • So, first ensure you properly understand time computation (as said at the beginning, doing a sum of digits belonging to different orders of magnitudes is completely wrong), and use a more appropriate type (QElapsedTimer, or even Python's time.monotonic(), so you don't need to go through an external API). Then consider that hardware, input events, OS, and language may increase the inaccuracy: a lot happens between your fingers and what is actually computed. Finally, we're human, it's quite possible that you may just not be as precise ad you believe. Commented Aug 8 at 20:23

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.