Audio-synchronized widget linking
benbovy opened this issue · comments
Similarly to Ipywidgets's jsdlink
, it would be nice if we could easily link an ipytone widget to any other widget, e.g.,
l = ipytone.sync_jsdlink((audio_widget, 'value'), (graphic_widget, 'value'), "8n")
that would do something like this on the JS side:
Tone.Transport.scheduleRepeat((time) => {
Tone.Draw.schedule(() => {
graphic_widget.set('value', audio_widget.get('value'));
graphic_widget.save_changes();
}, time);
}, '8n');
And l.unlink()
would basically call Tone.Transport.clear()
with the corresponding event id.
That would provide a high-level, convenient way of synchronizing any widget state (e.g., some ipycanvas drawing) with an audio signal on the JS side.
I'd be happy to hear your thoughts @davidbrochart! I guess that we could reuse the same approach that you used in #14?
So that would all happen in the front-end, or would there be a round-trip with the back-end?
I don't quite understand why time has anything to play with it, wouldn't the synchronization be instantaneous, whenever a change happens?
So that would all happen in the front-end, or would there be a round-trip with the back-end?
All in the front-end, as I don't think any round-trip would be fast enough to result in an apparent synchronized state between a (DOM) widget and an audio signal.
I don't quite understand why time has anything to play with it, wouldn't the synchronization be instantaneous, whenever a change happens?
I'm not sure we'd be able to synchronize a widget trait value with an audio signal value that changes at the audio sample rate, so the idea is to force the synchronization to happen at some specific scheduled times (<< 44.1kHz), using Tone.Draw
to improve the time accuracy.
Oh I didn't know Tone.Draw
was something from tonejs 😄
Yes it makes total sense then.
Closed in #70.