From 1b35dd0c5553220479c64e3dae46f4a5fb046962 Mon Sep 17 00:00:00 2001 From: Felix Roos Date: Sat, 16 Apr 2022 21:34:05 +0200 Subject: [PATCH] add preliminary getFrequency --- packages/core/util.mjs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/packages/core/util.mjs b/packages/core/util.mjs index 5ec88125..ba0d00a4 100644 --- a/packages/core/util.mjs +++ b/packages/core/util.mjs @@ -40,6 +40,23 @@ export const getPlayableNoteValue = (event) => { return note; }; +// TODO: make this compatible with midi numbers object values +export const getFrequency = (event) => { + let { value, context } = event; + // if value is number => interpret as midi number as long as its not marked as frequency + if (typeof value === 'object' && value.freq) { + return value.freq; + } + /* if (typeof value === 'number' && context.type !== 'frequency') { + value = fromMidi(event.value); + } else */ if (typeof value === 'string' && isNote(value)) { + value = fromMidi(toMidi(event.value)); + } else if (typeof value !== 'number') { + throw new Error('not a note or frequency:' + value); + } + return value; +}; + // rotate array by n steps (to the left) export const rotate = (arr, n) => arr.slice(n).concat(arr.slice(0, n));