Pattern .define + .bootstrap
+ seperate parse / evaluate + add Pattern.edit + move string hacks to evaluate + automate eval scoping with globalThis + add random tune button + mini: handle angle brackets + add chordBass + fix old tunes
This commit is contained in:
parent
c225c058bc
commit
c11c217baf
9 changed files with 259 additions and 221 deletions
|
|
@ -1,6 +1,6 @@
|
|||
import { Pattern as _Pattern, stack, TimeSpan, Hap, reify } from '../../strudel.mjs';
|
||||
import voicings from 'chord-voicings';
|
||||
const { dictionaryVoicing, minTopNoteDiff, lefthand } = voicings;
|
||||
import { Pattern as _Pattern, stack, Hap, reify } from '../../strudel.mjs';
|
||||
import _voicings from 'chord-voicings';
|
||||
const { dictionaryVoicing, minTopNoteDiff, lefthand } = _voicings;
|
||||
|
||||
const getVoicing = (chord, lastVoicing, range = ['F3', 'A4']) =>
|
||||
dictionaryVoicing({
|
||||
|
|
@ -25,10 +25,29 @@ Pattern.prototype.fmapNested = function (func) {
|
|||
);
|
||||
};
|
||||
|
||||
Pattern.prototype.voicings = function (range = ['F3', 'A4']) {
|
||||
Pattern.prototype.voicings = function (range) {
|
||||
let lastVoicing;
|
||||
if (!range?.length) {
|
||||
// allows to pass empty array, if too lazy to specify range
|
||||
range = ['F3', 'A4'];
|
||||
}
|
||||
return this.fmapNested((event) => {
|
||||
lastVoicing = getVoicing(event.value, lastVoicing, range);
|
||||
return stack(...lastVoicing);
|
||||
});
|
||||
};
|
||||
|
||||
Pattern.prototype.chordBass = function () { // range = ['G1', 'C3']
|
||||
return this._mapNotes((value) => {
|
||||
console.log('value',value);
|
||||
const [_, root] = value.value.match(/^([a-gC-G])[b#]?.*$/);
|
||||
const bassNote = root + '2';
|
||||
return { ...value, value: bassNote };
|
||||
});
|
||||
};
|
||||
|
||||
Pattern.prototype.define('voicings', (range, pat) => pat.voicings(range), { composable: true });
|
||||
Pattern.prototype.define('chordBass', (pat) => {
|
||||
console.log('call chordBass ...', pat);
|
||||
return pat.chordBass()
|
||||
}, { composable: true });
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue