From 3d0d52605139bead9bf3f94a347afcf6282dd5a7 Mon Sep 17 00:00:00 2001 From: Felix Roos Date: Sun, 13 Feb 2022 12:10:38 +0100 Subject: [PATCH] add tranpose method --- repl/src/parse.ts | 1 + repl/src/tonal.ts | 15 +++++++++++++++ repl/src/voicings.ts | 8 ++++---- 3 files changed, 20 insertions(+), 4 deletions(-) create mode 100644 repl/src/tonal.ts diff --git a/repl/src/parse.ts b/repl/src/parse.ts index 1e99d83e..ddc91a67 100644 --- a/repl/src/parse.ts +++ b/repl/src/parse.ts @@ -4,6 +4,7 @@ import { Scale, Note, Interval } from '@tonaljs/tonal'; import './tone'; import './midi'; import './voicings'; +import './tonal'; import * as toneStuff from './tone'; import shapeshifter from './shapeshifter'; diff --git a/repl/src/tonal.ts b/repl/src/tonal.ts new file mode 100644 index 00000000..52443536 --- /dev/null +++ b/repl/src/tonal.ts @@ -0,0 +1,15 @@ +import { Note, Interval } from '@tonaljs/tonal'; +import { Pattern as _Pattern } from '../../strudel.mjs'; + +const Pattern = _Pattern as any; + +Pattern.prototype._transpose = function (intervalOrSemitones: string | number) { + const interval = !isNaN(Number(intervalOrSemitones)) + ? Interval.fromSemitones(intervalOrSemitones as number) + : String(intervalOrSemitones); + return this.fmap((note) => Note.transpose(note, interval)); +}; + +Pattern.prototype.transpose = function (intervalOrSemitones: string | number) { + return this._patternify(Pattern.prototype._transpose)(intervalOrSemitones); +}; diff --git a/repl/src/voicings.ts b/repl/src/voicings.ts index 6a086047..4f7504bc 100644 --- a/repl/src/voicings.ts +++ b/repl/src/voicings.ts @@ -16,11 +16,11 @@ const Pattern = _Pattern as any; Pattern.prototype.fmapNested = function (func) { return new Pattern((span) => this.query(span) - .map((event) => { - return reify(func(event)) + .map((event) => + reify(func(event)) .query(span) - .map((hap) => new Hap(event.whole, event.part, hap.value)); - }) + .map((hap) => new Hap(event.whole, event.part, hap.value)) + ) .flat() ); };