From 6cd3cc96a34552b7a55ee58470caa22d816b16e8 Mon Sep 17 00:00:00 2001 From: Felix Roos Date: Thu, 6 Apr 2023 00:08:23 +0200 Subject: [PATCH] fix: do not prebake in tests + pull piano function to separate file for tests --- test/runtime.mjs | 2 +- website/src/repl/piano.mjs | 16 ++++++++++++++++ website/src/repl/prebake.mjs | 1 + 3 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 website/src/repl/piano.mjs diff --git a/test/runtime.mjs b/test/runtime.mjs index 17e92954..47ebfe59 100644 --- a/test/runtime.mjs +++ b/test/runtime.mjs @@ -29,7 +29,7 @@ import '@strudel.cycles/xen/xen.mjs'; // import '@strudel.cycles/webaudio/webaudio.mjs'; // import '@strudel.cycles/serial/serial.mjs'; // import controls from '@strudel.cycles/core/controls.mjs'; -import '../website/src/repl/prebake'; +import '../website/src/repl/piano'; class MockedNode { chain() { diff --git a/website/src/repl/piano.mjs b/website/src/repl/piano.mjs new file mode 100644 index 00000000..bb849b20 --- /dev/null +++ b/website/src/repl/piano.mjs @@ -0,0 +1,16 @@ +import { Pattern, noteToMidi, valueToMidi } from '@strudel.cycles/core'; + +const maxPan = noteToMidi('C8'); +const panwidth = (pan, width) => pan * width + (1 - width) / 2; + +Pattern.prototype.piano = function () { + return this.clip(1) + .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 }; + }); +}; diff --git a/website/src/repl/prebake.mjs b/website/src/repl/prebake.mjs index 5cd57303..a9ad87c9 100644 --- a/website/src/repl/prebake.mjs +++ b/website/src/repl/prebake.mjs @@ -1,6 +1,7 @@ import { Pattern, noteToMidi, valueToMidi } from '@strudel.cycles/core'; import { registerSoundfonts } from '@strudel.cycles/soundfonts'; import { registerSynthSounds, samples } from '@strudel.cycles/webaudio'; +import './piano.mjs'; export async function prebake() { // https://archive.org/details/SalamanderGrandPianoV3