diff --git a/packages/core/examples/metro.html b/packages/core/examples/metro.html index f3bba5098..17f456ec1 100644 --- a/packages/core/examples/metro.html +++ b/packages/core/examples/metro.html @@ -13,7 +13,7 @@ Loading... { // we cannot use closures here! let interval; @@ -90,13 +88,17 @@ Loading... Math.round(n * d) / d; + const precision = 100; this.worker.onmessage = (e) => { if (e.data === 'tick') { - const begin = this.lastEnd || this.startedAt + this.lookahead; - const end = begin + this.interval; + const sinceStart = this.audioContext.currentTime - this.startedAt; // seconds since pressing start + const tick = Math.floor(sinceStart / this.interval); // tick number + const begin = round(tick * this.interval + this.startedAt, precision); // begin of tick + const end = round(begin + this.interval, precision); // end of tick this.lastEnd = end; // callback with query span, using clock #2 (the audio clock) - callback(begin, end, this.lookahead); + callback(begin, end); } }; } @@ -112,12 +114,12 @@ Loading... { - pattern.query(new State(new TimeSpan(begin - lookahead, end - lookahead))).forEach((e) => { + (begin, end) => { + pattern.query(new State(new TimeSpan(begin, end))).forEach((e) => { if (!e.part.begin.equals(e.whole.begin)) { return; }