Tonejs / Tone.js

A Web Audio framework for making interactive music in the browser.
https://tonejs.github.io
MIT License
13.39k stars 976 forks source link

Transport position is resetting to zero when loop region is changed #1078

Open ryanmiyakawa opened 2 years ago

ryanmiyakawa commented 2 years ago

Describe the bug

When Transport looping is enabled and a loop region is redefined (i.e., defined once, transport plays and stops, then loop region is redefined), the transport subsequently starts from zero even if it is set to a non-zero value.

To Reproduce

Here is a fiddle demonstrating the issue: https://jsfiddle.net/3srjLto2/3/

Steps to reproduce:

  1. Set Transport looping to true and define a loop region.
  2. Start and stop Transport
  3. Define a new looping region (different start and end points)
  4. Set Transport position to the start of the new loop region
  5. Start Transport again

Transport position plays from 0 rather than the specified time.

Expected behavior Transport should play from its current position without being reset to zero.

What I've tried I can only get this to happen after playing and stopping the Transport at least once.

Oddly enough, in subsequent attempts (setting position and starting from that position), the Transport will sometimes play from the set position, and sometimes play from 0 (about 60/40, 60% of the time from the correct position). However it always seems to fail in the case described by the fiddle above.

Another note is that you can set the transport position after it starts and it will still reset to 0, as seen here: https://jsfiddle.net/0Ly7gxqa/5/

abswiz commented 2 years ago

Hi. We also observed this and had to build in some guard conditions to stop events at 0:0 triggering when setting transport positions whilst playing. From recollection, I think if you set a position ahead of the current position then it does not rewind, but if you set a position before the current position, it appears to perform a rapid stop (which appears to be a async operation), followed by the repositioning...