diff --git a/repl/src/voicings.ts b/repl/src/voicings.ts index 9aca4cfa..6a086047 100644 --- a/repl/src/voicings.ts +++ b/repl/src/voicings.ts @@ -1,4 +1,4 @@ -import { Pattern as _Pattern, stack, TimeSpan, Hap } from '../../strudel.mjs'; +import { Pattern as _Pattern, stack, TimeSpan, Hap, reify } from '../../strudel.mjs'; import voicings from 'chord-voicings'; const { dictionaryVoicing, minTopNoteDiff, lefthand } = voicings; @@ -13,16 +13,22 @@ const getVoicing = (chord, lastVoicing, range = ['F3', 'A4']) => const Pattern = _Pattern as any; -Pattern.prototype.voicings = function (range = ['F3', 'A4']) { - let lastVoicing; +Pattern.prototype.fmapNested = function (func) { return new Pattern((span) => this.query(span) .map((event) => { - lastVoicing = getVoicing(event.value, lastVoicing, range); - return stack(...lastVoicing) + return reify(func(event)) .query(span) .map((hap) => new Hap(event.whole, event.part, hap.value)); }) .flat() ); }; + +Pattern.prototype.voicings = function (range = ['F3', 'A4']) { + let lastVoicing; + return this.fmapNested((event) => { + lastVoicing = getVoicing(event.value, lastVoicing, range); + return stack(...lastVoicing); + }); +};