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

17
repl/package-lock.json generated
View File

@ -6,6 +6,7 @@
"": {
"dependencies": {
"@tonaljs/tonal": "^4.6.5",
"chord-voicings": "^0.0.1",
"codemirror": "^5.65.1",
"estraverse": "^5.3.0",
"multimap": "^1.1.0",
@ -2759,6 +2760,14 @@
"fsevents": "~2.3.2"
}
},
"node_modules/chord-voicings": {
"version": "0.0.1",
"resolved": "https://registry.npmjs.org/chord-voicings/-/chord-voicings-0.0.1.tgz",
"integrity": "sha512-SutgB/4ynkkuiK6qdQ/k3QvCFcH0Vj8Ch4t6LbRyRQbVzP/TOztiCk3kvXd516UZ6fqk7ijDRELEFcKN+6V8sA==",
"dependencies": {
"@tonaljs/tonal": "^4.6.5"
}
},
"node_modules/chownr": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/chownr/-/chownr-2.0.0.tgz",
@ -10966,6 +10975,14 @@
"readdirp": "~3.6.0"
}
},
"chord-voicings": {
"version": "0.0.1",
"resolved": "https://registry.npmjs.org/chord-voicings/-/chord-voicings-0.0.1.tgz",
"integrity": "sha512-SutgB/4ynkkuiK6qdQ/k3QvCFcH0Vj8Ch4t6LbRyRQbVzP/TOztiCk3kvXd516UZ6fqk7ijDRELEFcKN+6V8sA==",
"requires": {
"@tonaljs/tonal": "^4.6.5"
}
},
"chownr": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/chownr/-/chownr-2.0.0.tgz",

View File

@ -10,6 +10,7 @@
},
"dependencies": {
"@tonaljs/tonal": "^4.6.5",
"chord-voicings": "^0.0.1",
"codemirror": "^5.65.1",
"estraverse": "^5.3.0",
"multimap": "^1.1.0",

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()
);
};