fix: add .piano function
This commit is contained in:
parent
e8e8f888dd
commit
0ed615a312
1 changed files with 16 additions and 1 deletions
|
|
@ -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 { registerSynthSounds, registerZZFXSounds, samples } from '@strudel.cycles/webaudio';
|
||||||
import * as core from '@strudel.cycles/core';
|
import * as core from '@strudel.cycles/core';
|
||||||
|
|
||||||
|
|
@ -37,3 +37,18 @@ export async function prebake() {
|
||||||
samples(`${ds}/vcsl.json`),
|
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 };
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue