Describe the bug
When:
- an Oscillator is sync'd with the transport,
- the Oscillator is started at time X
- the transport is started and passes time X
- the transport position is set before time X (without stopping)
Sometimes when the transport position is set before time X, the oscillator sound does not stop. When the transport time reaches X again, a second ToneOscillatorNode is created. The first ToneOscillatorNode will continue sounding and will now be orphaned. So stopping the transport will stop the second ToneOscillatorNode but it will not stop the orphaned ToneOscillatorNode.
This bug could not be reliably reproduced by simply following the steps above. The demo uses a slider so the transport position can be quickly set to before and after the Oscillator start time.
To Reproduce
https://codesandbox.io/p/sandbox/mystifying-wu-kdxkdr
Expected behavior
- When an Oscillator is sync'd with the Transport, it should always stop when the Transport stops.
- When an Oscillator is sync'd with the Transport, and configured to start after Transport time X, when the Transport position is set before X, the Oscillator shouldn't be sounding anymore.
What I've tried
I've looked at the code and seen how the Oscillator#_start is not checking for an existing _oscillator before creating a new one.
I haven't tried to figure out why Oscillator#_stop is not being called sometimes. I suspect there is some case where the _stop is getting skipped because of the rapid changes to the Transport position which are causing lots of start and stopping.
Additional context
There are notes in the codesandbox html which provide a little more info.
Describe the bug
When:
Sometimes when the transport position is set before time X, the oscillator sound does not stop. When the transport time reaches X again, a second ToneOscillatorNode is created. The first ToneOscillatorNode will continue sounding and will now be orphaned. So stopping the transport will stop the second ToneOscillatorNode but it will not stop the orphaned ToneOscillatorNode.
This bug could not be reliably reproduced by simply following the steps above. The demo uses a slider so the transport position can be quickly set to before and after the Oscillator start time.
To Reproduce
https://codesandbox.io/p/sandbox/mystifying-wu-kdxkdr
Expected behavior
What I've tried
I've looked at the code and seen how the
Oscillator#_startis not checking for an existing_oscillatorbefore creating a new one.I haven't tried to figure out why
Oscillator#_stopis not being called sometimes. I suspect there is some case where the _stop is getting skipped because of the rapid changes to the Transport position which are causing lots of start and stopping.Additional context
There are notes in the codesandbox html which provide a little more info.