add tranpose method

This commit is contained in:
Felix Roos 2022-02-13 12:10:38 +01:00
parent 016d5c5ef4
commit 3d0d526051
3 changed files with 20 additions and 4 deletions

View File

@ -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';

15
repl/src/tonal.ts Normal file
View File

@ -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);
};

View File

@ -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()
);
};