From bc3481822caa557831eaa7c87a30969f4c224390 Mon Sep 17 00:00:00 2001 From: nkymut Date: Sun, 9 Feb 2025 16:38:15 +0800 Subject: [PATCH] allow midimaps to register arbitary controlnames --- packages/midi/midi.mjs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/packages/midi/midi.mjs b/packages/midi/midi.mjs index 8de6c447f..c46ff0a30 100644 --- a/packages/midi/midi.mjs +++ b/packages/midi/midi.mjs @@ -6,7 +6,7 @@ This program is free software: you can redistribute it and/or modify it under th import * as _WebMidi from 'webmidi'; import { Pattern, getEventOffsetMs, isPattern, logger, ref } from '@strudel/core'; -import { noteToMidi, getControlName } from '@strudel/core'; +import { noteToMidi, getControlName, registerControl } from '@strudel/core'; import { Note } from 'webmidi'; // if you use WebMidi from outside of this package, make sure to import that instance: @@ -100,10 +100,23 @@ export const midicontrolMap = new Map(); function unifyMapping(mapping) { return Object.fromEntries( Object.entries(mapping).map(([key, mapping]) => { + // Convert number to object with ccn property if (typeof mapping === 'number') { mapping = { ccn: mapping }; } - return [getControlName(key), mapping]; + + const controlName = getControlName(key); + + // Register the control in the midicontrolMap if it doesn't exist in + if (!midicontrolMap.has(controlName)) { + try { + registerControl(controlName); + } catch (err) { + logger.error(`Failed to register control '${controlName}': ${err.message}`); + throw err; + } + } + return [controlName, mapping]; }), ); }