Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Event coordination code seems incorrect #19

Open
Astronought opened this issue Jun 25, 2020 · 0 comments
Open

Event coordination code seems incorrect #19

Astronought opened this issue Jun 25, 2020 · 0 comments

Comments

@Astronought
Copy link

Astronought commented Jun 25, 2020

Hi,

Not sure if this library is still maintained, but I've found a potential problem around how event timings are coordinated.

Specifically the code that starts here.

For example lets imagine I have a lastTimestamp of 8000 and a timestamp of 5000, i.e. there was 5192 ms between the last midi event and the current midi event. Now the condition of the if statement is false because 5000 + (8192 / 2) = 9096 which obviously isn't < 8000 (lastTimestamp) and so no adjustment is made to the current timestamp.

This is now an issue, because when the final result is calculated, part of the calculation is adjustedTimestamp - lastTimestamp or 5000 - 8000, which when we take the system time into account means we end up with an event timing that is less than the previous event, despite the current event taking place 5192ms after the previous.

I suggest all that needs to happen instead is we need to take the MAX_TIMESTAMP, subtract the lastTimestamp from it and add the difference onto the current timestamp to get the proper adjustment. E.g. 8192 - 8000 + 5000 = 5192ms, this can then be added onto the last system time recorded and we get correct event ordering.

Please let me know if I've missed something completely obvious, otherwise I am happy to put up a PR.

EDIT: BlueZ has a fantastic implementation of this here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant