mirror of
https://github.com/eliasstepanik/strudel-docker.git
synced 2026-01-23 19:48:31 +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';
|
import voicings from 'chord-voicings';
|
||||||
const { dictionaryVoicing, minTopNoteDiff, lefthand } = voicings;
|
const { dictionaryVoicing, minTopNoteDiff, lefthand } = voicings;
|
||||||
|
|
||||||
@ -13,16 +13,22 @@ const getVoicing = (chord, lastVoicing, range = ['F3', 'A4']) =>
|
|||||||
|
|
||||||
const Pattern = _Pattern as any;
|
const Pattern = _Pattern as any;
|
||||||
|
|
||||||
Pattern.prototype.voicings = function (range = ['F3', 'A4']) {
|
Pattern.prototype.fmapNested = function (func) {
|
||||||
let lastVoicing;
|
|
||||||
return new Pattern((span) =>
|
return new Pattern((span) =>
|
||||||
this.query(span)
|
this.query(span)
|
||||||
.map((event) => {
|
.map((event) => {
|
||||||
lastVoicing = getVoicing(event.value, lastVoicing, range);
|
return reify(func(event))
|
||||||
return stack(...lastVoicing)
|
|
||||||
.query(span)
|
.query(span)
|
||||||
.map((hap) => new Hap(event.whole, event.part, hap.value));
|
.map((hap) => new Hap(event.whole, event.part, hap.value));
|
||||||
})
|
})
|
||||||
.flat()
|
.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