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

clock.sync schedules resume events too far in the future #1111

Closed
artfwo opened this issue Apr 30, 2020 · 2 comments
Closed

clock.sync schedules resume events too far in the future #1111

artfwo opened this issue Apr 30, 2020 · 2 comments
Assignees

Comments

@artfwo
Copy link
Member

@artfwo artfwo commented Apr 30, 2020

occasionally clock.sync will schedule resume events too far in the future. this is reproducible by the following example:

local function format_beats()
  return string.format("%.3f", clock.get_beats())
end

local function sync_to_4()
  print('at beat: '..format_beats()..' syncing to 4')
  clock.sync(4)
  print('at beat: '..format_beats())
end

local function late_sync()
  clock.sync(3.75)
  clock.run(sync_to_4)
end

function init()
  clock.run(late_sync)
end

running the example results in the following output:

at beat: 3.744 syncing to 4
at beat: 8.000 <-- should be 4

the issue is caused by the absolute duration check for sync events which prevents unwanted repeats, when resume events happen slightly earlier than expected.

for example as seen above, clock.sync(3.75) can result in a resume event happening at beat 3.744, which would cause a subsequent call to clock.sync(3.75) schedule another wakeup in 0.005 beats.

@artfwo artfwo self-assigned this Apr 30, 2020
@artfwo
Copy link
Member Author

@artfwo artfwo commented May 1, 2020

for reference, here's the result of measuring current beat after running clock.sync(4)[1] a hundred times on hardware with the system under load[2]. clock is set to internal / 120 bpm.

image

[1] the duration check mentioned above is disabled for the purpose of this measurement.
[2] matron object files are being constantly erased and rebuilt in the background.

@artfwo
Copy link
Member Author

@artfwo artfwo commented May 1, 2020

and just a few more measurements for syncing to beat divisions from 0.5 to 16.

image

@artfwo artfwo closed this in 1551498 May 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
1 participant