This commit is contained in:
Felix Roos 2022-02-12 22:56:41 +01:00
parent ffffca8cdc
commit a0c09f7575
4 changed files with 175 additions and 136 deletions

15
docs/dist/voicings.js vendored
View file

@ -1,4 +1,4 @@
import {Pattern as _Pattern, stack, Hap} from "../_snowpack/link/strudel.js";
import {Pattern as _Pattern, stack, Hap, reify} from "../_snowpack/link/strudel.js";
import voicings from "../_snowpack/pkg/chord-voicings.js";
const {dictionaryVoicing, minTopNoteDiff, lefthand} = voicings;
const getVoicing = (chord, lastVoicing, range = ["F3", "A4"]) => dictionaryVoicing({
@ -9,10 +9,15 @@ const getVoicing = (chord, lastVoicing, range = ["F3", "A4"]) => dictionaryVoici
lastVoicing
});
const Pattern = _Pattern;
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).query(span).map((hap) => new Hap(event.whole, event.part, hap.value));
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);
});
};