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.
currentSecsSinceEpoch()andcurrentMSecsSinceEpoch()(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 »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.