fix: add .piano function

This commit is contained in:
Felix Roos 2023-12-25 15:32:12 +01:00
parent e8e8f888dd
commit 0ed615a312

View File

@ -1,4 +1,4 @@
import { controls, evalScope } from '@strudel.cycles/core';
import { controls, noteToMidi, valueToMidi, Pattern, evalScope } from '@strudel.cycles/core';
import { registerSynthSounds, registerZZFXSounds, samples } from '@strudel.cycles/webaudio';
import * as core from '@strudel.cycles/core';
@ -37,3 +37,18 @@ export async function prebake() {
samples(`${ds}/vcsl.json`),
]);
}
const maxPan = noteToMidi('C8');
const panwidth = (pan, width) => pan * width + (1 - width) / 2;
Pattern.prototype.piano = function () {
return this.fmap((v) => ({ ...v, clip: v.clip ?? 1 })) // set clip if not already set..
.s('piano')
.release(0.1)
.fmap((value) => {
const midi = valueToMidi(value);
// pan by pitch
const pan = panwidth(Math.min(Math.round(midi) / maxPan, 1), 0.5);
return { ...value, pan: (value.pan || 1) * pan };
});
};