From 125d190ff121aa92a5d9ac3cb078c07a4826a3be Mon Sep 17 00:00:00 2001 From: Felix Roos Date: Mon, 28 Feb 2022 21:39:53 +0100 Subject: [PATCH] fix: scaleTranspose for scales without C in it --- repl/src/tonal.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/repl/src/tonal.ts b/repl/src/tonal.ts index 0273e30f..5953e8f7 100644 --- a/repl/src/tonal.ts +++ b/repl/src/tonal.ts @@ -34,11 +34,11 @@ function scaleTranspose(scale: string, offset: number, note: string) { while (Math.abs(i - noteIndex) < Math.abs(offset)) { i += direction; const index = mod(i, notes.length); - if (direction < 0 && n === 'C') { + if (direction < 0 && n[0] === 'C') { o += direction; } n = notes[index]; - if (direction > 0 && n === 'C') { + if (direction > 0 && n[0] === 'C') { o += direction; } } @@ -54,7 +54,9 @@ Pattern.prototype._transpose = function (intervalOrSemitones: string | number) { const semitones = typeof interval === 'string' ? Interval.semitones(interval) || 0 : interval; return event.withValue(() => event.value + semitones); } - return event.withValue(() => Note.transpose(event.value, interval)); + // TODO: move simplify to player to preserve enharmonics + // tone.js doesn't understand multiple sharps flats e.g. F##3 has to be turned into G3 + return event.withValue(() => Note.simplify(Note.transpose(event.value, interval))); }); };