mirror of
https://github.com/eliasstepanik/strudel.git
synced 2026-01-11 21:58:37 +00:00
fmapNested prototype
This commit is contained in:
parent
64e24e5fc1
commit
c20d5e5be9
@ -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);
|
||||
});
|
||||
};
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user