move common dough things to lib.mjs

This commit is contained in:
Felix Roos
2026-10-13 20:52:05 +02:00
parent c398620439
commit ff80bae275
2 changed files with 33 additions and 24 deletions
+5 -24
View File
@@ -4,15 +4,13 @@ Copyright (C) 2022 Strudel contributors - see <https://codeberg.org/uzu/strudel/
This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
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;
+28
View File
@@ -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;
}