From fd2c7fb4bb5d0085363d2102bf54a4646682cd1b Mon Sep 17 00:00:00 2001 From: Felix Roos Date: Tue, 16 Aug 2022 23:12:49 +0200 Subject: [PATCH] allow non notes --- packages/midi/midi.mjs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/packages/midi/midi.mjs b/packages/midi/midi.mjs index 52bfae170..f9a25c46e 100644 --- a/packages/midi/midi.mjs +++ b/packages/midi/midi.mjs @@ -30,7 +30,7 @@ const outputByName = (name) => WebMidi.getOutputByName(name); // Pattern.prototype.midi = function (output: string | number, channel = 1) { Pattern.prototype.midi = function (output, channel = 1) { - if (isPattern(output?.constructor?.name)) { + if (output?.constructor?.name && isPattern(output?.constructor?.name)) { throw new Error( `.midi does not accept Pattern input. Make sure to pass device name with single quotes. Example: .midi('${ WebMidi.outputs?.[0]?.name || 'IAC Driver Bus 1' @@ -38,11 +38,13 @@ Pattern.prototype.midi = function (output, channel = 1) { ); } return this.onTrigger((time, hap, currentTime) => { - let note = getPlayableNoteValue(hap); - const { velocity, nrpnn, nrpv, ccn, ccv, legato, duration: durationValue } = objectify(hap.value); - if (!isNote(note)) { - throw new Error('not a note: ' + note); + let note; + try { + note = getPlayableNoteValue(hap); + } catch (err) { + // dont care if no note is found as we can still send cvs } + const { velocity, nrpnn, nrpv, ccn, ccv, legato, duration: durationValue } = objectify(hap.value); if (!WebMidi.enabled) { throw new Error(`🎹 WebMidi is not enabled. Supported Browsers: https://caniuse.com/?search=webmidi`); }