From dd736130a0fb1755fbd45e3497edc83540b2a068 Mon Sep 17 00:00:00 2001 From: Felix Roos Date: Thu, 29 Dec 2022 13:03:28 +0100 Subject: [PATCH] improve pianoroll value mapping --- packages/core/pianoroll.mjs | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/packages/core/pianoroll.mjs b/packages/core/pianoroll.mjs index 122bb449..34ce1d4b 100644 --- a/packages/core/pianoroll.mjs +++ b/packages/core/pianoroll.mjs @@ -4,7 +4,7 @@ Copyright (C) 2022 Strudel contributors - see . */ -import { Pattern, toMidi, getDrawContext, freqToMidi } from './index.mjs'; +import { Pattern, toMidi, getDrawContext, freqToMidi, isNote } from './index.mjs'; const scale = (normalized, min, max) => normalized * (max - min) + min; const getValue = (e) => { @@ -12,13 +12,19 @@ const getValue = (e) => { if (typeof e.value !== 'object') { value = { value }; } - let { note, n, freq } = value; + let { note, n, freq, s } = value; if (freq) { - note = freqToMidi(freq); + return freqToMidi(freq); } - value = note ?? n ?? e.value; - if (typeof value === 'string') { - value = toMidi(value); + note = note ?? n; + if (typeof note === 'string') { + return toMidi(note); + } + if (typeof note === 'number') { + return note; + } + if (s) { + return '_' + s; } return value; }; @@ -143,7 +149,7 @@ Pattern.prototype.pianoroll = function ({ maxMidi = max; valueExtent = maxMidi - minMidi + 1; } - foldValues = values.sort((a, b) => a - b); + foldValues = values.sort((a, b) => String(a).localeCompare(String(b))); barThickness = fold ? valueAxis / foldValues.length : valueAxis / valueExtent; }, }, @@ -215,7 +221,8 @@ export function pianoroll({ maxMidi = max; valueExtent = maxMidi - minMidi + 1; } - foldValues = values.sort((a, b) => a - b); + // foldValues = values.sort((a, b) => a - b); + foldValues = values.sort((a, b) => String(a).localeCompare(String(b))); barThickness = fold ? valueAxis / foldValues.length : valueAxis / valueExtent; ctx.fillStyle = background;