From 868f4d8ae564d5137dd01d96d489f04f35bf698e Mon Sep 17 00:00:00 2001 From: Felix Roos Date: Tue, 4 Feb 2025 08:36:51 +0100 Subject: [PATCH] use worker-timers for strudel clock - maybe solves callback clogging --- package.json | 1 + pnpm-lock.yaml | 45 +++++++++++++++++++++++++++++++++++++++++++++ src/strudel.js | 5 ++++- 3 files changed, 50 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 4f23be5..6c6f7c9 100644 --- a/package.json +++ b/package.json @@ -36,6 +36,7 @@ "@strudel/webaudio": "^1.1.0", "codemirror": "^6.0.1", "hydra-synth": "^1.3.29", + "worker-timers": "^8.0.13", "y-codemirror.next": "github:felixroos/y-codemirror.next#a75a1cbfddf6968d4ced07f6e47c314e4fd7c72f", "y-indexeddb": "^9.0.9", "y-protocols": "^1.0.5", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index a79345f..209cd72 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -74,6 +74,9 @@ importers: hydra-synth: specifier: ^1.3.29 version: 1.3.29(rollup@4.29.1) + worker-timers: + specifier: ^8.0.13 + version: 8.0.13 y-codemirror.next: specifier: github:felixroos/y-codemirror.next#a75a1cbfddf6968d4ced07f6e47c314e4fd7c72f version: https://codeload.github.com/felixroos/y-codemirror.next/tar.gz/a75a1cbfddf6968d4ced07f6e47c314e4fd7c72f(@codemirror/state@6.5.0)(@codemirror/view@6.36.1)(yjs@13.6.21) @@ -848,6 +851,10 @@ packages: resolution: {integrity: sha512-mQw+2fkQbALzQ7V0MY0IqdnXNOeTtP4r0lN9z7AAawCXgqea7bDii20AYrIBrFd/Hx0M2Ocz6S111CaFkUcb0Q==} engines: {node: '>=0.8.x'} + fast-unique-numbers@9.0.15: + resolution: {integrity: sha512-vHj0sfq6yB37b/RAAsAJ2DzIp0LR5NlUit7nYFp2YfTUcKL9m/Yk0f0kvYPV4oiuFYXdtO5scs3LQX7qiPAVYQ==} + engines: {node: '>=18.2.0'} + fftjs@0.0.4: resolution: {integrity: sha512-nIWxQyth1LVD6NH8a+YZUv+McjzbOY6dMe4wv6Pq5cGfP+c8Rd1T8Dsd50DCWlNgzSqA3y9lOkpD6dZD3qHa1A==} @@ -1099,6 +1106,9 @@ packages: resolution: {integrity: sha512-ot0WnXS9fgdkgIcePe6RHNk1WA8+muPa6cSjeR3V8K27q9BB1rTE3R1p7Hv0z1ZyAc8s6Vvv8DIyWf681MAt0w==} engines: {node: '>= 0.4'} + tslib@2.8.1: + resolution: {integrity: sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w==} + utf-8-validate@6.0.5: resolution: {integrity: sha512-EYZR+OpIXp9Y1eG1iueg8KRsY8TuT8VNgnanZ0uA3STqhHQTLwbl+WX76/9X5OY12yQubymBpaBSmMPkSTQcKA==} engines: {node: '>=6.14.2'} @@ -1151,6 +1161,15 @@ packages: resolution: {integrity: sha512-X1lACggXm2BxuAPdx5wleh8S2kygduHbtR2ti5sGhivLkX6Muv/sLAYmPuIaNLOUddyxr71+3tsq8m5dKXoT4A==} engines: {node: '>=8.5'} + worker-timers-broker@7.1.9: + resolution: {integrity: sha512-YPql2CMZwAqPlCHoxXWsERLJChb8r9YvjRiAR0KSQ8iyNbckmSXdw4UCttrMbntwQLWxz5msO0oiUX2VA3WyTQ==} + + worker-timers-worker@8.0.10: + resolution: {integrity: sha512-wmdEMhn70li//pFNDT3pcjQ8kcuZOIuD6vrt9RBCwdTcnwvnsAmdSKSHiZSGwhNYwTJd+dvuhb81G05TGpTHcg==} + + worker-timers@8.0.13: + resolution: {integrity: sha512-ggT5TBkuZC+EySptNS61Z5nuwa/8klCyKBv0+Wa0HPLjp13nluIrdUXX9zdYGwJKwNuVPp1wPMUnFuSKw5Hxsg==} + ws@6.2.3: resolution: {integrity: sha512-jmTjYU0j60B+vHey6TfR3Z7RD61z/hmxBS3VMSGIrroOWXQEneK1zNuotOUrGyBHQj0yrpsLHPWtigEFd13ndA==} peerDependencies: @@ -2271,6 +2290,11 @@ snapshots: events@3.3.0: {} + fast-unique-numbers@9.0.15: + dependencies: + '@babel/runtime': 7.26.0 + tslib: 2.8.1 + fftjs@0.0.4: dependencies: babel-plugin-add-module-exports: 0.2.1 @@ -2558,6 +2582,8 @@ snapshots: supports-preserve-symlinks-flag@1.0.0: {} + tslib@2.8.1: {} + utf-8-validate@6.0.5: dependencies: node-gyp-build: 4.8.4 @@ -2592,6 +2618,25 @@ snapshots: optionalDependencies: jzz: 1.8.7 + worker-timers-broker@7.1.9: + dependencies: + '@babel/runtime': 7.26.0 + fast-unique-numbers: 9.0.15 + tslib: 2.8.1 + worker-timers-worker: 8.0.10 + + worker-timers-worker@8.0.10: + dependencies: + '@babel/runtime': 7.26.0 + tslib: 2.8.1 + + worker-timers@8.0.13: + dependencies: + '@babel/runtime': 7.26.0 + tslib: 2.8.1 + worker-timers-broker: 7.1.9 + worker-timers-worker: 8.0.10 + ws@6.2.3(bufferutil@4.0.9)(utf-8-validate@6.0.5): dependencies: async-limiter: 1.0.1 diff --git a/src/strudel.js b/src/strudel.js index 89177a8..a1a80a6 100644 --- a/src/strudel.js +++ b/src/strudel.js @@ -1,8 +1,9 @@ -import { controls, evalScope, stack, evaluate, silence, getTrigger, setTime, register } from '@strudel/core'; +import { controls, evalScope, stack, evaluate, silence, getTrigger, setTime, register, Cyclist } from '@strudel/core'; import { Framer } from '@strudel/draw'; import { registerSoundfonts } from '@strudel/soundfonts'; import { transpiler } from '@strudel/transpiler'; import { getAudioContext, initAudio, registerSynthSounds, samples, webaudioOutput } from '@strudel/webaudio'; +import { setInterval, clearInterval } from 'worker-timers'; controls.createParam('docId'); @@ -67,6 +68,8 @@ export class StrudelSession { this.scheduler = new Cyclist({ onTrigger: getTrigger({ defaultOutput: webaudioOutput, getTime }), getTime, + setInterval, + clearInterval, }); setTime(() => this.scheduler.now()); // this is cursed