feat: added Tune scales to Xen, improved documentation re uzu/strudel#1944
This commit is contained in:
parent
47ad4bb171
commit
14cc5d989b
4 changed files with 37 additions and 14 deletions
|
|
@ -5,7 +5,7 @@ This program is free software: you can redistribute it and/or modify it under th
|
|||
*/
|
||||
|
||||
import { register, _mod, parseNumeral, removeUndefineds } from '@strudel/core';
|
||||
|
||||
import Tune from './tunejs.js'
|
||||
|
||||
// returns a list of frequency ratios for given edo scale
|
||||
export function edo(name) {
|
||||
|
|
@ -30,12 +30,18 @@ const defaultBase = 220;
|
|||
|
||||
// Assumes a base of 220. Returns a filtered scale based on 'indices'
|
||||
function getXenScale(scale, indices) {
|
||||
let tune = new Tune()
|
||||
if (typeof scale === 'string') {
|
||||
if (/^[1-9]+[0-9]*edo$/.test(scale)) {
|
||||
scale = edo(scale);
|
||||
} else if (presets[scale]) {
|
||||
scale = presets[scale];
|
||||
} else {
|
||||
}
|
||||
else if (tune.isValidScale(scale)) {
|
||||
tune.loadScale(scale)
|
||||
scale = tune.scale
|
||||
}
|
||||
else {
|
||||
throw new Error('unknown scale name: "' + scale + '"');
|
||||
}
|
||||
}
|
||||
|
|
@ -69,6 +75,7 @@ function xenOffset(xenScale, offset, index = 0) {
|
|||
* @param {(string | number[] )} scaleNameOrRatios
|
||||
* @tags music_theory
|
||||
* @example
|
||||
* // A major tried in 31edo:
|
||||
* "0 8 18".xen("31edo").freq().piano()
|
||||
* @example
|
||||
* // You can also use xen with frequency ratios.
|
||||
|
|
@ -78,8 +85,15 @@ function xenOffset(xenScale, offset, index = 0) {
|
|||
* Math.pow(2, 8/31),
|
||||
* Math.pow(2, 18/31),
|
||||
* ]).freq().piano()
|
||||
* @example
|
||||
* // xen also supports all scale names that
|
||||
* // tune does:
|
||||
* "0 1 2 3 4 5".xen("hexany15").freq()
|
||||
* // equiv to:
|
||||
* // "0 1 2 3 4 5".tune("hexany15").mul("220").freq()
|
||||
*/
|
||||
|
||||
// TODO how do you reference another function in jsdoc (tune, above)
|
||||
// TODO support tunings defined in './tunejs.js'
|
||||
export const xen = register('xen', function (scaleNameOrRatios, pat) {
|
||||
return pat.withHaps((haps) => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue