diff --git a/packages/dough/dough.mjs b/packages/dough/dough.mjs index 14f4ffa2b..4701ce205 100644 --- a/packages/dough/dough.mjs +++ b/packages/dough/dough.mjs @@ -4,11 +4,13 @@ Copyright (C) 2022 Strudel contributors - see . */ -import { register, noteToMidi } 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'; +import { hap2dough } from './lib.mjs'; +export * from './lib.mjs'; Object.assign(globalThis, { doughsamples }); @@ -42,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); } 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; +} diff --git a/packages/dough/package.json b/packages/dough/package.json index abbb543be..7dc73a962 100644 --- a/packages/dough/package.json +++ b/packages/dough/package.json @@ -31,7 +31,7 @@ "dependencies": { "@strudel/core": "workspace:*", "@strudel/webaudio": "workspace:*", - "dough-synth": "0.2.4" + "dough-synth": "0.4.1" }, "devDependencies": { "vite": "^6.0.11" diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 9930ef857..c4c045c9f 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -318,8 +318,8 @@ importers: specifier: workspace:* version: link:../webaudio dough-synth: - specifier: 0.2.4 - version: 0.2.4 + specifier: 0.4.1 + version: 0.4.1 devDependencies: vite: specifier: ^6.0.11 @@ -4078,8 +4078,8 @@ packages: resolution: {integrity: sha512-47qPchRCykZC03FhkYAhrvwU4xDBFIj1QPqaarj6mdM/hgUzfPHcpkHJOn3mJAufFeeAxAzeGsr5X0M4k6fLZQ==} engines: {node: '>=12'} - dough-synth@0.2.4: - resolution: {integrity: sha512-qMnMKVj1B2ivUgobNCwqJqNzZHOMN+5339OmCOk07zIDEK7iCYdufa+ZDE2BEgmKrWDyhGS7oTNFjHtTwzEv9w==} + dough-synth@0.4.1: + resolution: {integrity: sha512-hxBsfOBwTIlJMhSB/Pk2xNNc7YTAVTgexn5Y7GRv/Kn2qBkMxwLxHJNvhsUhklQhVvzny/aCihxb0EOq4tv5Bw==} hasBin: true dset@3.1.4: @@ -8030,6 +8030,18 @@ packages: utf-8-validate: optional: true + ws@8.22.0: + resolution: {integrity: sha512-Ydggc987+RO0AnWtZ/7Wq9FtNvcrL1b/RO0ud9mWjUPgDrsAAwQSF51sm2hm1XofbU/4jkpGEsLFsZZxU+1DOg==} + engines: {node: '>=10.0.0'} + peerDependencies: + bufferutil: ^4.0.1 + utf-8-validate: '>=5.0.2' + peerDependenciesMeta: + bufferutil: + optional: true + utf-8-validate: + optional: true + xmlcreate@2.0.4: resolution: {integrity: sha512-nquOebG4sngPmGPICTS5EnxqhKbCmz5Ox5hsszI2T6U5qdrJizBc+0ilYSEjTSzU0yZcmvppztXe/5Al5fUwdg==} @@ -11800,7 +11812,12 @@ snapshots: dotenv@16.4.7: {} - dough-synth@0.2.4: {} + dough-synth@0.4.1: + dependencies: + ws: 8.22.0 + transitivePeerDependencies: + - bufferutil + - utf-8-validate dset@3.1.4: {} @@ -16698,6 +16715,8 @@ snapshots: ws@8.18.3: {} + ws@8.22.0: {} + xmlcreate@2.0.4: {} xtend@4.0.2: {}