formatting uzu/strudel#1944
This commit is contained in:
parent
3bbaf77b20
commit
05ae80b0ca
4 changed files with 180 additions and 29 deletions
|
|
@ -7,7 +7,6 @@ This program is free software: you can redistribute it and/or modify it under th
|
||||||
import Tune from './tunejs.js';
|
import Tune from './tunejs.js';
|
||||||
import { register } from '@strudel/core';
|
import { register } from '@strudel/core';
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Assumes a numerical pattern of EDO steps. Accepts a scale name or list of frequencies (see all available names at the link on the reference). Returns a new pattern with all values mapped to a frequency ratio. Similar to `xen`.
|
* Assumes a numerical pattern of EDO steps. Accepts a scale name or list of frequencies (see all available names at the link on the reference). Returns a new pattern with all values mapped to a frequency ratio. Similar to `xen`.
|
||||||
* @name tune
|
* @name tune
|
||||||
|
|
@ -17,24 +16,24 @@ import { register } from '@strudel/core';
|
||||||
* @example
|
* @example
|
||||||
* "0 1 2 3 4 5".tune("hexany15").mul("220").freq()
|
* "0 1 2 3 4 5".tune("hexany15").mul("220").freq()
|
||||||
* @example
|
* @example
|
||||||
* // You can set your root to be a
|
* // You can set your root to be a
|
||||||
* // particular note with getFreq:
|
* // particular note with getFreq:
|
||||||
* `"4 8 9 10 - - 5 7 9 11 - -".tune("tranh3")
|
* "4 8 9 10 - - 5 7 9 11 - -".tune("tranh3")
|
||||||
* .mul(getFreq('c3'))
|
* .mul(getFreq('c3'))
|
||||||
* .freq().clip(.5).room(1)`
|
* .freq().clip(.5).room(1)
|
||||||
* @example
|
* @example
|
||||||
* // You can also give tune a list of
|
* // You can also give tune a list of
|
||||||
* // frequencies to use as the scale:
|
* // frequencies to use as the scale:
|
||||||
* "0 1 2 3 4".tune([
|
* "0 1 2 3 4".tune([
|
||||||
* 261.6255653006,
|
* 261.6255653006,
|
||||||
* 302.72962012827,
|
* 302.72962012827,
|
||||||
* 350.29154279212,
|
* 350.29154279212,
|
||||||
* 405.32593044476,
|
* 405.32593044476,
|
||||||
* 469.00678383895,
|
* 469.00678383895,
|
||||||
* 523.2511306012
|
* 523.2511306012
|
||||||
* ]).mul(220).freq();
|
* ]).mul(220).freq();
|
||||||
* @tags tonal
|
* @tags tonal
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// Tune.scale seems to be in ratio format
|
// Tune.scale seems to be in ratio format
|
||||||
export const tune = register('tune', (scale, pat) => {
|
export const tune = register('tune', (scale, pat) => {
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ This program is free software: you can redistribute it and/or modify it under th
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { register, _mod, parseNumeral } from '@strudel/core';
|
import { register, _mod, parseNumeral } from '@strudel/core';
|
||||||
import Tune from './tunejs.js'
|
import Tune from './tunejs.js';
|
||||||
|
|
||||||
// returns a list of frequency ratios for given edo scale
|
// returns a list of frequency ratios for given edo scale
|
||||||
export function edo(name) {
|
export function edo(name) {
|
||||||
|
|
@ -31,18 +31,16 @@ const defaultBase = 220;
|
||||||
// Assumes a base of 220. Returns a filtered scale based on 'indices'
|
// Assumes a base of 220. Returns a filtered scale based on 'indices'
|
||||||
// NOTE: indices functionality is unused
|
// NOTE: indices functionality is unused
|
||||||
function getXenScale(scale, indices) {
|
function getXenScale(scale, indices) {
|
||||||
let tune = new Tune()
|
let tune = new Tune();
|
||||||
if (typeof scale === 'string') {
|
if (typeof scale === 'string') {
|
||||||
if (/^[1-9]+[0-9]*edo$/.test(scale)) {
|
if (/^[1-9]+[0-9]*edo$/.test(scale)) {
|
||||||
scale = edo(scale);
|
scale = edo(scale);
|
||||||
} else if (presets[scale]) {
|
} else if (presets[scale]) {
|
||||||
scale = presets[scale];
|
scale = presets[scale];
|
||||||
}
|
} else if (tune.isValidScale(scale)) {
|
||||||
else if (tune.isValidScale(scale)) {
|
tune.loadScale(scale);
|
||||||
tune.loadScale(scale)
|
scale = tune.scale;
|
||||||
scale = tune.scale
|
} else {
|
||||||
}
|
|
||||||
else {
|
|
||||||
throw new Error('unknown scale name: "' + scale + '"');
|
throw new Error('unknown scale name: "' + scale + '"');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -53,7 +51,6 @@ function getXenScale(scale, indices) {
|
||||||
return scale.filter((_, i) => indices.includes(i));
|
return scale.filter((_, i) => indices.includes(i));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function xenOffset(xenScale, offset, index = 0) {
|
function xenOffset(xenScale, offset, index = 0) {
|
||||||
const i = _mod(index + offset, xenScale.length);
|
const i = _mod(index + offset, xenScale.length);
|
||||||
const oct = Math.floor(offset / xenScale.length);
|
const oct = Math.floor(offset / xenScale.length);
|
||||||
|
|
@ -68,7 +65,7 @@ function xenOffset(xenScale, offset, index = 0) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Assumes a numerical pattern of EDO steps. Accepts all scale names of `tune` as well as any arbitrary edo scale. Returns a new pattern with all values mapped to their associated frequency, assuming a base frequency of 220hz.
|
* Assumes a numerical pattern of EDO steps. Accepts all scale names of `tune` as well as any arbitrary edo scale. Returns a new pattern with all values mapped to their associated frequency, assuming a base frequency of 220hz.
|
||||||
*
|
*
|
||||||
* @name xen
|
* @name xen
|
||||||
* @returns Pattern
|
* @returns Pattern
|
||||||
* @memberof Pattern
|
* @memberof Pattern
|
||||||
|
|
@ -78,18 +75,18 @@ function xenOffset(xenScale, offset, index = 0) {
|
||||||
* // A major tried in 31edo:
|
* // A major tried in 31edo:
|
||||||
* "0 8 18".xen("31edo").freq().piano()
|
* "0 8 18".xen("31edo").freq().piano()
|
||||||
* @example
|
* @example
|
||||||
* // You can also use xen with frequency ratios.
|
* // You can also use xen with frequency ratios.
|
||||||
* // This is equivalent to the above:
|
* // This is equivalent to the above:
|
||||||
* "0 1 2".xen([
|
* "0 1 2".xen([
|
||||||
* Math.pow(2, 0/31),
|
* Math.pow(2, 0/31),
|
||||||
* Math.pow(2, 8/31),
|
* Math.pow(2, 8/31),
|
||||||
* Math.pow(2, 18/31),
|
* Math.pow(2, 18/31),
|
||||||
* ]).freq().piano()
|
* ]).freq().piano()
|
||||||
* @example
|
* @example
|
||||||
* // xen also supports all scale names that
|
* // xen also supports all scale names that
|
||||||
* // tune does:
|
* // tune does:
|
||||||
* "0 1 2 3 4 5".xen("hexany15").freq()
|
* "0 1 2 3 4 5".xen("hexany15").freq()
|
||||||
* // equiv to:
|
* // equiv to:
|
||||||
* // "0 1 2 3 4 5".tune("hexany15").mul("220").freq()
|
* // "0 1 2 3 4 5".tune("hexany15").mul("220").freq()
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -13088,6 +13088,97 @@ exports[`runs examples > example "tri" example index 0 1`] = `
|
||||||
]
|
]
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
exports[`runs examples > example "tune" example index 0 1`] = `
|
||||||
|
[
|
||||||
|
"[ 0/1 → 1/6 | freq:0 ]",
|
||||||
|
"[ 1/6 → 1/3 | freq:220 ]",
|
||||||
|
"[ 1/3 → 1/2 | freq:440 ]",
|
||||||
|
"[ 1/2 → 2/3 | freq:660 ]",
|
||||||
|
"[ 2/3 → 5/6 | freq:880 ]",
|
||||||
|
"[ 5/6 → 1/1 | freq:1100 ]",
|
||||||
|
"[ 1/1 → 7/6 | freq:0 ]",
|
||||||
|
"[ 7/6 → 4/3 | freq:220 ]",
|
||||||
|
"[ 4/3 → 3/2 | freq:440 ]",
|
||||||
|
"[ 3/2 → 5/3 | freq:660 ]",
|
||||||
|
"[ 5/3 → 11/6 | freq:880 ]",
|
||||||
|
"[ 11/6 → 2/1 | freq:1100 ]",
|
||||||
|
"[ 2/1 → 13/6 | freq:0 ]",
|
||||||
|
"[ 13/6 → 7/3 | freq:220 ]",
|
||||||
|
"[ 7/3 → 5/2 | freq:440 ]",
|
||||||
|
"[ 5/2 → 8/3 | freq:660 ]",
|
||||||
|
"[ 8/3 → 17/6 | freq:880 ]",
|
||||||
|
"[ 17/6 → 3/1 | freq:1100 ]",
|
||||||
|
"[ 3/1 → 19/6 | freq:0 ]",
|
||||||
|
"[ 19/6 → 10/3 | freq:220 ]",
|
||||||
|
"[ 10/3 → 7/2 | freq:440 ]",
|
||||||
|
"[ 7/2 → 11/3 | freq:660 ]",
|
||||||
|
"[ 11/3 → 23/6 | freq:880 ]",
|
||||||
|
"[ 23/6 → 4/1 | freq:1100 ]",
|
||||||
|
]
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`runs examples > example "tune" example index 1 1`] = `
|
||||||
|
[
|
||||||
|
"[ 0/1 → 1/12 | freq:523.2511306011972 clip:0.5 room:1 ]",
|
||||||
|
"[ 1/12 → 1/6 | freq:1046.5022612023945 clip:0.5 room:1 ]",
|
||||||
|
"[ 1/6 → 1/4 | freq:1177.3150438526939 clip:0.5 room:1 ]",
|
||||||
|
"[ 1/4 → 1/3 | freq:1308.1278265029932 clip:0.5 room:1 ]",
|
||||||
|
"[ 1/2 → 7/12 | freq:654.0639132514966 clip:0.5 room:1 ]",
|
||||||
|
"[ 7/12 → 2/3 | freq:915.6894785520951 clip:0.5 room:1 ]",
|
||||||
|
"[ 2/3 → 3/4 | freq:1177.3150438526939 clip:0.5 room:1 ]",
|
||||||
|
"[ 3/4 → 5/6 | freq:1438.9406091532924 clip:0.5 room:1 ]",
|
||||||
|
"[ 1/1 → 13/12 | freq:523.2511306011972 clip:0.5 room:1 ]",
|
||||||
|
"[ 13/12 → 7/6 | freq:1046.5022612023945 clip:0.5 room:1 ]",
|
||||||
|
"[ 7/6 → 5/4 | freq:1177.3150438526939 clip:0.5 room:1 ]",
|
||||||
|
"[ 5/4 → 4/3 | freq:1308.1278265029932 clip:0.5 room:1 ]",
|
||||||
|
"[ 3/2 → 19/12 | freq:654.0639132514966 clip:0.5 room:1 ]",
|
||||||
|
"[ 19/12 → 5/3 | freq:915.6894785520951 clip:0.5 room:1 ]",
|
||||||
|
"[ 5/3 → 7/4 | freq:1177.3150438526939 clip:0.5 room:1 ]",
|
||||||
|
"[ 7/4 → 11/6 | freq:1438.9406091532924 clip:0.5 room:1 ]",
|
||||||
|
"[ 2/1 → 25/12 | freq:523.2511306011972 clip:0.5 room:1 ]",
|
||||||
|
"[ 25/12 → 13/6 | freq:1046.5022612023945 clip:0.5 room:1 ]",
|
||||||
|
"[ 13/6 → 9/4 | freq:1177.3150438526939 clip:0.5 room:1 ]",
|
||||||
|
"[ 9/4 → 7/3 | freq:1308.1278265029932 clip:0.5 room:1 ]",
|
||||||
|
"[ 5/2 → 31/12 | freq:654.0639132514966 clip:0.5 room:1 ]",
|
||||||
|
"[ 31/12 → 8/3 | freq:915.6894785520951 clip:0.5 room:1 ]",
|
||||||
|
"[ 8/3 → 11/4 | freq:1177.3150438526939 clip:0.5 room:1 ]",
|
||||||
|
"[ 11/4 → 17/6 | freq:1438.9406091532924 clip:0.5 room:1 ]",
|
||||||
|
"[ 3/1 → 37/12 | freq:523.2511306011972 clip:0.5 room:1 ]",
|
||||||
|
"[ 37/12 → 19/6 | freq:1046.5022612023945 clip:0.5 room:1 ]",
|
||||||
|
"[ 19/6 → 13/4 | freq:1177.3150438526939 clip:0.5 room:1 ]",
|
||||||
|
"[ 13/4 → 10/3 | freq:1308.1278265029932 clip:0.5 room:1 ]",
|
||||||
|
"[ 7/2 → 43/12 | freq:654.0639132514966 clip:0.5 room:1 ]",
|
||||||
|
"[ 43/12 → 11/3 | freq:915.6894785520951 clip:0.5 room:1 ]",
|
||||||
|
"[ 11/3 → 15/4 | freq:1177.3150438526939 clip:0.5 room:1 ]",
|
||||||
|
"[ 15/4 → 23/6 | freq:1438.9406091532924 clip:0.5 room:1 ]",
|
||||||
|
]
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`runs examples > example "tune" example index 2 1`] = `
|
||||||
|
[
|
||||||
|
"[ 0/1 → 1/5 | freq:0 ]",
|
||||||
|
"[ 1/5 → 2/5 | freq:220 ]",
|
||||||
|
"[ 2/5 → 3/5 | freq:440 ]",
|
||||||
|
"[ 3/5 → 4/5 | freq:660 ]",
|
||||||
|
"[ 4/5 → 1/1 | freq:880 ]",
|
||||||
|
"[ 1/1 → 6/5 | freq:0 ]",
|
||||||
|
"[ 6/5 → 7/5 | freq:220 ]",
|
||||||
|
"[ 7/5 → 8/5 | freq:440 ]",
|
||||||
|
"[ 8/5 → 9/5 | freq:660 ]",
|
||||||
|
"[ 9/5 → 2/1 | freq:880 ]",
|
||||||
|
"[ 2/1 → 11/5 | freq:0 ]",
|
||||||
|
"[ 11/5 → 12/5 | freq:220 ]",
|
||||||
|
"[ 12/5 → 13/5 | freq:440 ]",
|
||||||
|
"[ 13/5 → 14/5 | freq:660 ]",
|
||||||
|
"[ 14/5 → 3/1 | freq:880 ]",
|
||||||
|
"[ 3/1 → 16/5 | freq:0 ]",
|
||||||
|
"[ 16/5 → 17/5 | freq:220 ]",
|
||||||
|
"[ 17/5 → 18/5 | freq:440 ]",
|
||||||
|
"[ 18/5 → 19/5 | freq:660 ]",
|
||||||
|
"[ 19/5 → 4/1 | freq:880 ]",
|
||||||
|
]
|
||||||
|
`;
|
||||||
|
|
||||||
exports[`runs examples > example "undegrade" example index 0 1`] = `
|
exports[`runs examples > example "undegrade" example index 0 1`] = `
|
||||||
[
|
[
|
||||||
"[ 0/1 → 1/8 | s:hh ]",
|
"[ 0/1 → 1/8 | s:hh ]",
|
||||||
|
|
@ -14000,6 +14091,69 @@ exports[`runs examples > example "wtphaserand" example index 0 1`] = `
|
||||||
]
|
]
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
exports[`runs examples > example "xen" example index 0 1`] = `
|
||||||
|
[
|
||||||
|
"[ 0/1 → 1/3 | freq:220 clip:1 s:piano release:0.1 pan:0.5138888888888888 ]",
|
||||||
|
"[ 1/3 → 2/3 | freq:263.09212028971103 clip:1 s:piano release:0.1 pan:0.5277777777777778 ]",
|
||||||
|
"[ 2/3 → 1/1 | freq:329.01393411660587 clip:1 s:piano release:0.1 pan:0.5462962962962963 ]",
|
||||||
|
"[ 1/1 → 4/3 | freq:220 clip:1 s:piano release:0.1 pan:0.5138888888888888 ]",
|
||||||
|
"[ 4/3 → 5/3 | freq:263.09212028971103 clip:1 s:piano release:0.1 pan:0.5277777777777778 ]",
|
||||||
|
"[ 5/3 → 2/1 | freq:329.01393411660587 clip:1 s:piano release:0.1 pan:0.5462962962962963 ]",
|
||||||
|
"[ 2/1 → 7/3 | freq:220 clip:1 s:piano release:0.1 pan:0.5138888888888888 ]",
|
||||||
|
"[ 7/3 → 8/3 | freq:263.09212028971103 clip:1 s:piano release:0.1 pan:0.5277777777777778 ]",
|
||||||
|
"[ 8/3 → 3/1 | freq:329.01393411660587 clip:1 s:piano release:0.1 pan:0.5462962962962963 ]",
|
||||||
|
"[ 3/1 → 10/3 | freq:220 clip:1 s:piano release:0.1 pan:0.5138888888888888 ]",
|
||||||
|
"[ 10/3 → 11/3 | freq:263.09212028971103 clip:1 s:piano release:0.1 pan:0.5277777777777778 ]",
|
||||||
|
"[ 11/3 → 4/1 | freq:329.01393411660587 clip:1 s:piano release:0.1 pan:0.5462962962962963 ]",
|
||||||
|
]
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`runs examples > example "xen" example index 1 1`] = `
|
||||||
|
[
|
||||||
|
"[ 0/1 → 1/3 | freq:220 clip:1 s:piano release:0.1 pan:0.5138888888888888 ]",
|
||||||
|
"[ 1/3 → 2/3 | freq:263.09212028971103 clip:1 s:piano release:0.1 pan:0.5277777777777778 ]",
|
||||||
|
"[ 2/3 → 1/1 | freq:329.01393411660587 clip:1 s:piano release:0.1 pan:0.5462962962962963 ]",
|
||||||
|
"[ 1/1 → 4/3 | freq:220 clip:1 s:piano release:0.1 pan:0.5138888888888888 ]",
|
||||||
|
"[ 4/3 → 5/3 | freq:263.09212028971103 clip:1 s:piano release:0.1 pan:0.5277777777777778 ]",
|
||||||
|
"[ 5/3 → 2/1 | freq:329.01393411660587 clip:1 s:piano release:0.1 pan:0.5462962962962963 ]",
|
||||||
|
"[ 2/1 → 7/3 | freq:220 clip:1 s:piano release:0.1 pan:0.5138888888888888 ]",
|
||||||
|
"[ 7/3 → 8/3 | freq:263.09212028971103 clip:1 s:piano release:0.1 pan:0.5277777777777778 ]",
|
||||||
|
"[ 8/3 → 3/1 | freq:329.01393411660587 clip:1 s:piano release:0.1 pan:0.5462962962962963 ]",
|
||||||
|
"[ 3/1 → 10/3 | freq:220 clip:1 s:piano release:0.1 pan:0.5138888888888888 ]",
|
||||||
|
"[ 10/3 → 11/3 | freq:263.09212028971103 clip:1 s:piano release:0.1 pan:0.5277777777777778 ]",
|
||||||
|
"[ 11/3 → 4/1 | freq:329.01393411660587 clip:1 s:piano release:0.1 pan:0.5462962962962963 ]",
|
||||||
|
]
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`runs examples > example "xen" example index 2 1`] = `
|
||||||
|
[
|
||||||
|
"[ 0/1 → 1/6 | freq:220 ]",
|
||||||
|
"[ 1/6 → 1/3 | freq:275 ]",
|
||||||
|
"[ 1/3 → 1/2 | freq:293.33333333333616 ]",
|
||||||
|
"[ 1/2 → 2/3 | freq:330 ]",
|
||||||
|
"[ 2/3 → 5/6 | freq:352 ]",
|
||||||
|
"[ 5/6 → 1/1 | freq:440 ]",
|
||||||
|
"[ 1/1 → 7/6 | freq:220 ]",
|
||||||
|
"[ 7/6 → 4/3 | freq:275 ]",
|
||||||
|
"[ 4/3 → 3/2 | freq:293.33333333333616 ]",
|
||||||
|
"[ 3/2 → 5/3 | freq:330 ]",
|
||||||
|
"[ 5/3 → 11/6 | freq:352 ]",
|
||||||
|
"[ 11/6 → 2/1 | freq:440 ]",
|
||||||
|
"[ 2/1 → 13/6 | freq:220 ]",
|
||||||
|
"[ 13/6 → 7/3 | freq:275 ]",
|
||||||
|
"[ 7/3 → 5/2 | freq:293.33333333333616 ]",
|
||||||
|
"[ 5/2 → 8/3 | freq:330 ]",
|
||||||
|
"[ 8/3 → 17/6 | freq:352 ]",
|
||||||
|
"[ 17/6 → 3/1 | freq:440 ]",
|
||||||
|
"[ 3/1 → 19/6 | freq:220 ]",
|
||||||
|
"[ 19/6 → 10/3 | freq:275 ]",
|
||||||
|
"[ 10/3 → 7/2 | freq:293.33333333333616 ]",
|
||||||
|
"[ 7/2 → 11/3 | freq:330 ]",
|
||||||
|
"[ 11/3 → 23/6 | freq:352 ]",
|
||||||
|
"[ 23/6 → 4/1 | freq:440 ]",
|
||||||
|
]
|
||||||
|
`;
|
||||||
|
|
||||||
exports[`runs examples > example "xfade" example index 0 1`] = `
|
exports[`runs examples > example "xfade" example index 0 1`] = `
|
||||||
[
|
[
|
||||||
"[ 0/1 → 1/8 | s:hh gain:0 ]",
|
"[ 0/1 → 1/8 | s:hh gain:0 ]",
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@ import { JsDoc } from '../../docs/JsDoc';
|
||||||
These functions allow the use of scales other than your typical chromatic 12 based ones.
|
These functions allow the use of scales other than your typical chromatic 12 based ones.
|
||||||
|
|
||||||
### tune(scale)
|
### tune(scale)
|
||||||
|
|
||||||
{/* TODO (maybe): combine jsdoc things in tune.mjs with here */}
|
{/* TODO (maybe): combine jsdoc things in tune.mjs with here */}
|
||||||
|
|
||||||
<JsDoc client:idle name="tune" h={0} />
|
<JsDoc client:idle name="tune" h={0} />
|
||||||
|
|
@ -115,4 +116,4 @@ You can also give tune a list of frequencies to use as the scale:
|
||||||
|
|
||||||
{/* TODO add explanation of EDO to documentation */}
|
{/* TODO add explanation of EDO to documentation */}
|
||||||
|
|
||||||
<JsDoc client:idle name="Pattern.xen" h={0} />
|
<JsDoc client:idle name="Pattern.xen" h={0} />
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue