From ff80bae275a89a8f2bd7385ac32db41d0dd80cd4 Mon Sep 17 00:00:00 2001 From: Felix Roos Date: Tue, 13 Oct 2026 20:52:05 +0200 Subject: [PATCH] move common dough things to lib.mjs --- packages/dough/dough.mjs | 29 +++++------------------------ packages/dough/lib.mjs | 28 ++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 24 deletions(-) create mode 100644 packages/dough/lib.mjs diff --git a/packages/dough/dough.mjs b/packages/dough/dough.mjs index 78ac4dc1b..4701ce205 100644 --- a/packages/dough/dough.mjs +++ b/packages/dough/dough.mjs @@ -4,15 +4,13 @@ Copyright (C) 2022 Strudel contributors - see . */ -import { register, noteToMidi, registerControl, stack, Pattern } from '@strudel/core'; +import { register } from '@strudel/core'; import { Dough, doughsamples } from 'dough-synth'; import { getAudioContext, ensureMinimalOutput } from '@strudel/webaudio'; import wasm from 'dough-synth/dough.wasm?url'; import workletCode from 'dough-synth/dough.js?raw'; - -export const { group } = registerControl('group'); -export const { voices } = registerControl('voices'); -export const { glide } = registerControl('glide'); +import { hap2dough } from './lib.mjs'; +export * from './lib.mjs'; Object.assign(globalThis, { doughsamples }); @@ -46,16 +44,8 @@ export async function doughOutput(hap, targetTime, cps = 1) { if (!offset) { return; // not ready } - hap.ensureObjectValue(); - const event = { - dough: 'play', - ...hap.value, - time: targetTime - offset, - duration: hap.duration / cps, - }; - if (typeof event.note === 'string') { - event.note = noteToMidi(event.note); - } + const t = targetTime - offset; + const event = hap2dough(hap, t, cps); D.evaluate(event); } @@ -77,12 +67,3 @@ export const dough = register('dough', (pat) => { ensureMinimalOutput(); return pat.onSchedule(doughOutput); }); - -export const groupmod = register('groupmod', function (modulator, pat) { - const modpat = modulator - .withValue((vm) => pat.withValue(({ group }) => ({ ...vm, group }))) - .outerJoin() - .set({ dough: 'update_group' }); - return stack(pat.set(modulator), modpat); -}); -Pattern.prototype.gmod = Pattern.prototype.groupmod; diff --git a/packages/dough/lib.mjs b/packages/dough/lib.mjs new file mode 100644 index 000000000..4ceb05441 --- /dev/null +++ b/packages/dough/lib.mjs @@ -0,0 +1,28 @@ +import { register, registerControl, stack, Pattern, noteToMidi } from '@strudel/core'; + +export const { group } = registerControl('group'); +export const { voices } = registerControl('voices'); +export const { glide } = registerControl('glide'); + +export const groupmod = register('groupmod', function (modulator, pat) { + const modpat = modulator + .withValue((vm) => pat.withValue(({ group }) => ({ ...vm, group }))) + .outerJoin() + .set({ dough: 'update_group' }); + return stack(pat.set(modulator), modpat); +}); +Pattern.prototype.gmod = Pattern.prototype.groupmod; + +export function hap2dough(hap, time, cps) { + hap.ensureObjectValue(); + const event = { + dough: 'play', + ...hap.value, + time, + duration: hap.duration / cps, + }; + if (typeof event.note === 'string') { + event.note = noteToMidi(event.note); + } + return event; +}