From 4743334a17388c58993b84fbb6bf57d604d7829e Mon Sep 17 00:00:00 2001 From: Aria Date: Fri, 9 Jan 2026 22:50:16 -0600 Subject: [PATCH] Reduce latency; change name to midikeys; include in i/o learn page --- packages/midi/midi.mjs | 10 +++++----- test/__snapshots__/examples.test.mjs.snap | 8 ++++---- test/runtime.mjs | 4 ++-- website/src/pages/learn/input-output.mdx | 6 +++++- 4 files changed, 16 insertions(+), 12 deletions(-) diff --git a/packages/midi/midi.mjs b/packages/midi/midi.mjs index bfc42207..d4f6093a 100644 --- a/packages/midi/midi.mjs +++ b/packages/midi/midi.mjs @@ -558,16 +558,16 @@ export async function midin(input) { * The note length is fixed as Superdough is not currently set up for undetermined * note durations * - * @name keyboard + * @name midikeys * @param {string | number} input MIDI device name or index defaulting to 0 * @returns {function((number | Pattern)=): Pattern} A function that produces a pattern. * When queried, the pattern will produces the most recently played midi notes and velocities, * lasting for the specified duration * @example - * const kb = await keyboard('Arturia KeyStep 32') + * const kb = await midikeys('Arturia KeyStep 32') * kb().s("tri").lpf(80).lpe(6).lpd(0.1).room(2).delay(0.35) * @example - * const kb = await keyboard('Arturia KeyStep 32') + * const kb = await midikeys('Arturia KeyStep 32') * kb("0.5 1") * .s("saw") * .add(note(rand.mul(0.3))) @@ -575,7 +575,7 @@ export async function midin(input) { */ const kHaps = {}; const kListeners = {}; -export async function keyboard(input) { +export async function midikeys(input) { const device = await _initialize(input); if (!kHaps[input]) { kHaps[input] = []; @@ -586,7 +586,7 @@ export async function keyboard(input) { const [note, velocity] = dataBytes; const noteoff = message.command === 8; const key = `${input}_${note}`; - const t = getTime() + 0.1; // slight delay so it's not too late for cyclist to catch + const t = getTime() + 0.03; // slight delay so it's not too late for cyclist to catch const span = new TimeSpan(t, t); let value = { midikey: key }; if (noteoff) { diff --git a/test/__snapshots__/examples.test.mjs.snap b/test/__snapshots__/examples.test.mjs.snap index 62e2de91..2aa20a0e 100644 --- a/test/__snapshots__/examples.test.mjs.snap +++ b/test/__snapshots__/examples.test.mjs.snap @@ -5943,10 +5943,6 @@ exports[`runs examples > example "juxBy" example index 0 1`] = ` exports[`runs examples > example "keyDown" example index 0 1`] = `[]`; -exports[`runs examples > example "keyboard" example index 0 1`] = `[]`; - -exports[`runs examples > example "keyboard" example index 1 1`] = `[]`; - exports[`runs examples > example "lastOf" example index 0 1`] = ` [ "[ 0/1 → 1/4 | note:c3 ]", @@ -7031,6 +7027,10 @@ exports[`runs examples > example "midicmd" example index 0 1`] = ` ] `; +exports[`runs examples > example "midikeys" example index 0 1`] = `[]`; + +exports[`runs examples > example "midikeys" example index 1 1`] = `[]`; + exports[`runs examples > example "midin" example index 0 1`] = ` [ "[ 0/1 → 1/4 | note:c cutoff:0 resonance:0 s:sawtooth ]", diff --git a/test/runtime.mjs b/test/runtime.mjs index 51a713a6..5a64913c 100644 --- a/test/runtime.mjs +++ b/test/runtime.mjs @@ -131,7 +131,7 @@ const midin = () => { return (ccNum) => strudel.ref(() => 0); // returns ref with default value 0 }; -const keyboard = async () => { +const midikeys = async () => { return () => strudel.silence; }; @@ -154,7 +154,7 @@ evalScope( */ { midin, - keyboard, + midikeys, sysex, // gist, // euclid, diff --git a/website/src/pages/learn/input-output.mdx b/website/src/pages/learn/input-output.mdx index 0dd48b7d..1d4bf4c3 100644 --- a/website/src/pages/learn/input-output.mdx +++ b/website/src/pages/learn/input-output.mdx @@ -16,10 +16,14 @@ It is also possible to pattern other things with Strudel, such as software and h Strudel supports MIDI without any additional software (thanks to [webmidi](https://npmjs.com/package/webmidi)), just by adding methods to your pattern: -## midiin(inputName?) +## midin(inputName?) +## midikeys(inputName?) + + + ## midi(outputName?,options?) Either connect a midi device or use the IAC Driver (Mac) or Midi Through Port (Linux) for internal midi messages.