diff --git a/examples/worker-repl/.gitignore b/examples/worker-repl/.gitignore deleted file mode 100644 index a547bf36..00000000 --- a/examples/worker-repl/.gitignore +++ /dev/null @@ -1,24 +0,0 @@ -# Logs -logs -*.log -npm-debug.log* -yarn-debug.log* -yarn-error.log* -pnpm-debug.log* -lerna-debug.log* - -node_modules -dist -dist-ssr -*.local - -# Editor directories and files -.vscode/* -!.vscode/extensions.json -.idea -.DS_Store -*.suo -*.ntvs* -*.njsproj -*.sln -*.sw? diff --git a/examples/worker-repl/README.md b/examples/worker-repl/README.md deleted file mode 100644 index 41e5fba1..00000000 --- a/examples/worker-repl/README.md +++ /dev/null @@ -1,14 +0,0 @@ -# worker-repl - -This is a poc for a more precise version of cyclist, fixing the clock jitter on chrome. -It is also an experiment to use the `worker-timers` lib to test scheduling in inactive windows, -but not the reason why it works. You can comment out the import from `worker-timers` and it still works precisely.. - -I am not 100% sure why it works + the poc also doesn't implement cps yet.. - -run it with: - -```sh -pnpm i -pnpm dev -``` diff --git a/examples/worker-repl/index.html b/examples/worker-repl/index.html deleted file mode 100644 index 97aeb700..00000000 --- a/examples/worker-repl/index.html +++ /dev/null @@ -1,13 +0,0 @@ - - -
- - -click somewhere...
- - diff --git a/examples/worker-repl/main.js b/examples/worker-repl/main.js deleted file mode 100644 index a4e5e1da..00000000 --- a/examples/worker-repl/main.js +++ /dev/null @@ -1,76 +0,0 @@ -import { createClock, seq } from '@strudel/core'; -import { getAudioContext, initAudioOnFirstClick, samples, superdough } from 'superdough'; -import { setInterval, clearInterval } from 'worker-timers'; // comment out this line to test with window.setInterval - -let loaded = samples('github:tidalcycles/dirt-samples'); -async function run() { - //let pat = seq('hh').s().fast(25.2); - let pat = seq('bd', ['hh', 'hh'], 'jvbass').s().fast(1.92); - await initAudioOnFirstClick(); - await loaded; - const ctx = getAudioContext(); - let last = 0; - let cps = 0.6; - let num_ticks_since_cps_change = 0; - let num_cycles_at_cps_change = 0; - let seconds_at_cps_change; - let latency = 0.1; - - function setCps(_cps) { - if (_cps === cps) { - return; - } - cps = _cps; - num_ticks_since_cps_change = 0; - } - - const clock = createClock( - () => ctx.currentTime, - (phase, duration, tick, t) => { - if (num_ticks_since_cps_change === 0) { - console.log('changed cps..!!', cps); - num_cycles_at_cps_change = last; - seconds_at_cps_change = phase; - } - num_ticks_since_cps_change++; - const seconds_since_cps_change = num_ticks_since_cps_change * duration; - const num_cycles_since_cps_change = seconds_since_cps_change * cps; - - const [begin, end] = [last, (last = num_cycles_at_cps_change + num_cycles_since_cps_change)]; - - console.log( - 'q', - begin.toFixed(2), - end.toFixed(2), - phase.toFixed(2), - '#', - (end - begin).toFixed(2), - duration.toFixed(2), - ); - - pat - .queryArc(begin, end, { _cps: cps }) - .filter((h) => h.hasOnset()) - .forEach((hap) => { - const deadline = (hap.whole.begin - num_cycles_at_cps_change) / cps + seconds_at_cps_change + latency; - superdough(hap.value, '=' + deadline); - }); - }, - 0.025, // duration of each cycle - 0.1, // interval between callbacks - 0.4, // overlap between callbacks - setInterval, - clearInterval, - false, - ); - clock.start(); - setTimeout(() => { - console.log('change cps!!!!!!!!!!!!!!!!!!!!'); - setCps(1.2); - }, 6000); - setTimeout(() => { - clock.stop(); - }, 12000); -} - -run(); diff --git a/examples/worker-repl/package.json b/examples/worker-repl/package.json deleted file mode 100644 index 579dcde7..00000000 --- a/examples/worker-repl/package.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "name": "worker-repl", - "private": true, - "version": "0.0.0", - "type": "module", - "scripts": { - "dev": "vite", - "build": "vite build", - "preview": "vite preview" - }, - "devDependencies": { - "vite": "^5.2.0" - }, - "dependencies": { - "@strudel/core": "workspace:*", - "superdough": "workspace:*", - "worker-timers": "^7.1.4" - } -} diff --git a/examples/worker-repl/worker.mjs b/examples/worker-repl/worker.mjs deleted file mode 100644 index f62e8f97..00000000 --- a/examples/worker-repl/worker.mjs +++ /dev/null @@ -1,116 +0,0 @@ -// used to consistently schedule events -const createClock = ( - getTime, - callback, // called slightly before each cycle - duration = 0.05, // duration of each cycle - interval = 0.1, // interval between callbacks - overlap = 0.1, // overlap between callbacks -) => { - let tick = 0; // counts callbacks - let phase = 0; // next callback time - let precision = 10 ** 4; // used to round phase - let minLatency = 0; - const setDuration = (setter) => (duration = setter(duration)); - overlap = overlap || interval / 2; - const onTick = () => { - const t = getTime(); - const lookahead = t + interval + overlap; // the time window for this tick - if (phase === 0) { - phase = t + minLatency; - } - // callback as long as we're inside the lookahead - while (phase < lookahead) { - // phase = Math.round(phase * precision) / precision; - phase >= t && callback(phase, duration, tick, t); - phase < t && console.log('TOO LATE', phase); // what if latency is added from outside? - phase += duration; // increment phase by duration - tick++; - } - }; - let intervalID; - const start = () => { - clear(); // just in case start was called more than once - onTick(); - intervalID = setInterval(onTick, interval * 1000); - }; - const clear = () => intervalID !== undefined && clearInterval(intervalID); - const pause = () => clear(); - const stop = () => { - tick = 0; - phase = 0; - clear(); - }; - const getPhase = () => phase; - // setCallback - return { setDuration, start, stop, pause, duration, interval, getPhase, minLatency }; -}; - -onmessage = async function (e) { - console.log('Worker: Message received from main script', e); - - /* const { seq } = await import('@strudel/core'); - let pat = seq('bd').fast(4).s(); */ - if (!e.data.origin) { - console.log('no origin'); - return; - } - console.log('start!', e.data.origin); - // e.data.origin = unix ms when main document was created - // performance.timeOrigin = unix ms when worker was created - let originDiff = (performance.timeOrigin - e.data.origin) / 1000; - let firstTick; - console.log('originDiff', originDiff); - - let precision = 10 ** 4; - let cps = 0.5; - let interval = 0.05; - let tickOrigin; - let lastEnd = 0; - let bag = []; - let clock = createClock( - () => performance.now() / 1000, - (phase, duration, tick, t) => { - if (tick === 0) { - firstTick = t; - console.log('firstTick', t); - } - // let durationInCycles = duration * cps; - /* phase = lastEnd; */ - // phase = Math.round(phase * precision) / precision; - - bag.push({ tick, duration, phase, cps, origin: performance.timeOrigin }); - //postMessage({ tick, phase, cps, origin: performance.timeOrigin }); - let pack = 4; - if (bag.length === pack) { - console.log('send', performance.now()); - postMessage(bag); - bag = []; - } - - /* phase += duration; - lastEnd = phase; */ - /*if (tick === 0) { - tickOrigin = performance.now(); - } - let begin = lastEnd || 0; - let end = begin + duration * cps; - lastEnd = end; - //console.log('query', begin, phase); - const haps = pat.queryArc(begin, end).filter((hap) => hap.hasOnset()); - if (haps.length) { - postMessage({ tick, phase, begin, end, haps, cps, tickOrigin, origin: performance.timeOrigin }); - } - */ - /* console.log( - 'tick', - phase, - `${begin.toFixed(2)}-${end.toFixed(2)}: ${haps - .map((h) => `${h.value.s}:${(h.whole.begin + 0).toFixed(2)}`) - .join(' ')}`, - ); */ - }, - interval, - interval, - ); - clock.start(); -}; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 8da30aad..c76263d0 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -137,22 +137,6 @@ importers: specifier: ^5.0.10 version: 5.0.10 - examples/worker-repl: - dependencies: - '@strudel/core': - specifier: workspace:* - version: link:../../packages/core - superdough: - specifier: workspace:* - version: link:../../packages/superdough - worker-timers: - specifier: ^7.1.4 - version: 7.1.4 - devDependencies: - vite: - specifier: ^5.2.0 - version: 5.2.2(@types/node@20.10.6) - packages/codemirror: dependencies: '@codemirror/autocomplete': @@ -2198,6 +2182,7 @@ packages: engines: {node: '>=6.9.0'} dependencies: regenerator-runtime: 0.14.1 + dev: true /@babel/template@7.22.15: resolution: {integrity: sha512-QPErUVm4uyJa60rkI73qneDacvdvzxshT3kksGqlGWYdOTIUOwJ7RDUL8sGqslY1uXWSL6xMFKEXDS3ox2uF0w==} @@ -7592,14 +7577,6 @@ packages: /fast-levenshtein@2.0.6: resolution: {integrity: sha512-DCXu6Ifhqcks7TZKY3Hxp3y6qphY5SJZmrWMDrKcERSOXWQdMhU9Ig/PYrzyw/ul9jOIyh0N4M0tbC5hodg8dw==} - /fast-unique-numbers@8.0.13: - resolution: {integrity: sha512-7OnTFAVPefgw2eBJ1xj2PGGR9FwYzSUso9decayHgCDX4sJkHLdcsYTytTg+tYv+wKF3U8gJuSBz2jJpQV4u/g==} - engines: {node: '>=16.1.0'} - dependencies: - '@babel/runtime': 7.24.1 - tslib: 2.6.2 - dev: false - /fast-xml-parser@4.3.3: resolution: {integrity: sha512-coV/D1MhrShMvU6D0I+VAK3umz6hUaxxhL0yp/9RjfiYUfAv14rDhGQL+PLForhMdr0wq3PiV07WtkkNjJjNHg==} hasBin: true @@ -12021,6 +11998,7 @@ packages: /regenerator-runtime@0.14.1: resolution: {integrity: sha512-dYnhHh0nJoMfnkZs6GmmhFknAGRrLznOu5nc9ML+EJxGvrx6H7teuevqVqCuPcPK//3eDrrjQhehXVx9cnkGdw==} + dev: true /regenerator-transform@0.15.2: resolution: {integrity: sha512-hfMp2BoF0qOk3uc5V20ALGDS2ddjQaLrdl7xrGXvAIow7qeWRM2VA2HuCHkUKk9slq3VwEwLNK3DFBqDfPGYtg==} @@ -13442,6 +13420,7 @@ packages: /tslib@2.6.2: resolution: {integrity: sha512-AEYxH93jGFPn/a2iVAwW87VuUIkR1FVUKB77NwMF7nBTDkDrrT/Hpt/IrCJ0QXhW27jTBDcf5ZY7w6RiqTMw2Q==} requiresBuild: true + optional: true /tsutils@3.21.0(typescript@5.3.3): resolution: {integrity: sha512-mHKK3iUXL+3UF6xL5k0PEhKRUBKPBCv/+RkEOpjRWxxx27KKRBmmA60A9pgOUvMi8GKhRMPEmjBRPzs2W7O1OA==} @@ -14444,31 +14423,6 @@ packages: workbox-core: 7.0.0 dev: true - /worker-timers-broker@6.1.4: - resolution: {integrity: sha512-y3D+Yfj37lrItEMIlcfCm/IRueYtYKgpLlTG2wgTIZ9PSw0n/K4kweilgk3gTC4ahbQNVGT90lU+Rf7W4M5bsw==} - dependencies: - '@babel/runtime': 7.24.1 - fast-unique-numbers: 8.0.13 - tslib: 2.6.2 - worker-timers-worker: 7.0.67 - dev: false - - /worker-timers-worker@7.0.67: - resolution: {integrity: sha512-0ZP2+v2fyiiiGaCEdWxMRUk5YxGFwWdRGB12ZfQy13vw8/27Xd+MW3ua56qlcM30nzjpddXXzLuEpHhGW+Pz7w==} - dependencies: - '@babel/runtime': 7.24.1 - tslib: 2.6.2 - dev: false - - /worker-timers@7.1.4: - resolution: {integrity: sha512-8PRtiPAyeYukrY+iOUL+0tq4Zn5qyCHrTqFTtHxcESfIxGyulxNwyzQkybrYBKhnMWmx0bku3wxRfE1hts5R6Q==} - dependencies: - '@babel/runtime': 7.24.1 - tslib: 2.6.2 - worker-timers-broker: 6.1.4 - worker-timers-worker: 7.0.67 - dev: false - /wrap-ansi@7.0.0: resolution: {integrity: sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==} engines: {node: '>=10'}