From b87b2aff9a06aa3f54e0c1c7ce65ae27f18f21ce Mon Sep 17 00:00:00 2001 From: Felix Roos Date: Sun, 2 Feb 2025 22:18:56 +0100 Subject: [PATCH] simplify more --- packages/midi/midi.mjs | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/packages/midi/midi.mjs b/packages/midi/midi.mjs index 9425beac..240e3844 100644 --- a/packages/midi/midi.mjs +++ b/packages/midi/midi.mjs @@ -117,15 +117,13 @@ function normalize(value = 0, min = 0, max = 1, exp = 1) { return Math.pow(normalized, exp); } function mapCC(mapping, value) { - const ccs = []; - const matches = Object.entries(value).filter(([key]) => !!mapping[getControlName(key)]); - matches.forEach((match) => { - const control = match[0]; - const { ccn, min = 0, max = 1, exp = 1 } = mapping[control]; - const ccv = normalize(value[control], min, max, exp); - ccs.push({ ccn, ccv }); - }); - return ccs; + return Object.keys(value) + .filter((key) => !!mapping[getControlName(key)]) + .map((key) => { + const { ccn, min = 0, max = 1, exp = 1 } = mapping[key]; + const ccv = normalize(value[key], min, max, exp); + return { ccn, ccv }; + }); } // sends a cc message to the given device on the given channel