strudel icon indicating copy to clipboard operation
strudel copied to clipboard

REPL sync between windows

Open daslyfe opened this issue 1 year ago • 8 comments

using a shared worker, there are still two problems:

the clock has some jitter on both browsers, Im not sure if its because of a calculation error or delays in the message api for workers

also the animation frames can drop above 1 cps for some reason, Im assuming it is a calculation error somewhere as well

daslyfe avatar Jan 11 '24 15:01 daslyfe

FIxed the animation drops

daslyfe avatar Jan 20 '24 16:01 daslyfe

the clock jitter is probably happening because the worker uses performance.now() (system clock) as a clock source instead of AudioContext.currentTime (audio clock). Sadly, an AudioContext cannot exist in a worker, so some other solution is needed to make sure the deadline / target time is accurate in the context of the audio clock

felixroos avatar Jan 23 '24 22:01 felixroos

@felixroos this should be ready now, the clock is stabilized in firefox, and chrome behaves the same as before. Animations are working correctly. The clock no longer dies when window is unfocused. multiple windows can now sync together. I added a setCycles function as well, which we can integrate later.

daslyfe avatar Feb 04 '24 19:02 daslyfe

not sure what is going on with these test failures though...

daslyfe avatar Feb 04 '24 19:02 daslyfe

not sure what is going on with these test failures though...

self was not defined in node, I've wrapped it in a check

felixroos avatar Feb 04 '24 22:02 felixroos

it's magic btw

felixroos avatar Feb 04 '24 22:02 felixroos

I can review / test this in the coming days ok? on first sight it works great on my machine, I can also test it on my other machine then.

felixroos avatar Feb 04 '24 22:02 felixroos

I can review / test this in the coming days ok? on first sight it works great on my machine, I can also test it on my other machine then.

Sounds good!

daslyfe avatar Feb 04 '24 23:02 daslyfe

I've added a sync flag to opt-in to the NeoCyclist, which is set by the Repl in the website. Flok also uses the repl so maybe set sync to false by default. When the next version is released, we can test if it also works in flok.

felixroos avatar Mar 07 '24 11:03 felixroos

i'll try to fiddle around and see if there is a way to reuse zyklus, as it is identical to neozyklus

felixroos avatar Mar 07 '24 11:03 felixroos

image

ah damnit

felixroos avatar Mar 07 '24 11:03 felixroos

we should test this on mobile before merging i think. mobile browsers often suck at supporting some apis, so might need to disable it on mobile if it doesn't work

felixroos avatar Mar 07 '24 11:03 felixroos

we should test this on mobile before merging i think. mobile browsers often suck at supporting some apis, so might need to disable it on mobile if it doesn't work

It works on IPhone but not on Chrome on Android for some reason...

daslyfe avatar Mar 08 '24 02:03 daslyfe

@felixroos I added a condition to use cyclist if the client does not support shared workers and now android works again.

daslyfe avatar Mar 08 '24 04:03 daslyfe

@felixroos I added a condition to use cyclist if the client does not support shared workers and now android works again.

great! one more thing i've noticed is that with the neo cyclist, the time won't reset when you stop and start again, which might not always be desirable when you want to listen to the same place over and over again when writing. maybe we add a checkbox to allow switching sync off? Or maybe there is also a way to detect if all repls are stopped?

felixroos avatar Mar 08 '24 09:03 felixroos

@felixroos I added a condition to use cyclist if the client does not support shared workers and now android works again.

great! one more thing i've noticed is that with the neo cyclist, the time won't reset when you stop and start again, which might not always be desirable when you want to listen to the same place over and over again when writing. maybe we add a checkbox to allow switching sync off? Or maybe there is also a way to detect if all repls are stopped?

Good idea, I updated the behavior to stop the clock if all instances are stopped :) If a client disconnects while it is started would be the edge case I'm not sure how to solve. I don't think that is that much of a concern though

daslyfe avatar Mar 10 '24 18:03 daslyfe

Good idea, I updated the behavior to stop the clock if all instances are stopped :) If a client disconnects while it is started would be the edge case I'm not sure how to solve. I don't think that is that much of a concern though

cool! so maybe a checkbox to toggle sync on or off is not required then? I guess then this could be merged (finally). I've created https://github.com/tidalcycles/strudel/issues/988 as a follow up to potentially simplify the clock sync

felixroos avatar Mar 14 '24 12:03 felixroos

Good idea, I updated the behavior to stop the clock if all instances are stopped :) If a client disconnects while it is started would be the edge case I'm not sure how to solve. I don't think that is that much of a concern though

cool! so maybe a checkbox to toggle sync on or off is not required then? I guess then this could be merged (finally). I've created #988 as a follow up to potentially simplify the clock sync

sounds good! yes I hope there is a more straightforward way to simplify the this in the future. I will go ahead and merge :)

daslyfe avatar Mar 15 '24 00:03 daslyfe