add chord voicings

This commit is contained in:
Felix Roos 2022-02-12 21:59:45 +01:00
parent f15686ba0f
commit 70dea049ae
4 changed files with 47 additions and 0 deletions

View file

@ -3,6 +3,7 @@ import * as strudel from '../../strudel.mjs';
import { Scale, Note, Interval } from '@tonaljs/tonal';
import './tone';
import './midi';
import './voicings';
import * as toneStuff from './tone';
import shapeshifter from './shapeshifter';

28
repl/src/voicings.ts Normal file
View file

@ -0,0 +1,28 @@
import { Pattern as _Pattern, stack, TimeSpan, Hap } from '../../strudel.mjs';
import voicings from 'chord-voicings';
const { dictionaryVoicing, minTopNoteDiff, lefthand } = voicings;
const getVoicing = (chord, lastVoicing, range = ['F3', 'A4']) =>
dictionaryVoicing({
chord,
dictionary: lefthand,
range,
picker: minTopNoteDiff,
lastVoicing,
});
const Pattern = _Pattern as any;
Pattern.prototype.voicings = function (range = ['F3', 'A4']) {
let lastVoicing;
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));
})
.flat()
);
};