diff --git a/packages/xen/tune.mjs b/packages/xen/tune.mjs index 01303bf52..22b345695 100644 --- a/packages/xen/tune.mjs +++ b/packages/xen/tune.mjs @@ -7,12 +7,16 @@ This program is free software: you can redistribute it and/or modify it under th import Tune from './tunejs.js'; import { register } from '@strudel/core'; +// Tune.scale seems to be in ratio format +// + export const tune = register('tune', (scale, pat) => { const tune = new Tune(); if (!tune.isValidScale(scale)) { throw new Error('not a valid tune.js scale name: "' + scale + '". See http://abbernie.github.io/tune/scales.html'); } tune.loadScale(scale); + // if the tonic is a frequency, why are we putting in "1" tune.tonicize(1); return pat.withHap((hap) => { return hap.withValue(() => tune.note(hap.value)); diff --git a/packages/xen/tunejs.js b/packages/xen/tunejs.js index 9f4253709..e4e272518 100644 --- a/packages/xen/tunejs.js +++ b/packages/xen/tunejs.js @@ -78,14 +78,21 @@ Tune.prototype.frequency = function(stepIn, octaveIn) { } // which scale degree (0 - scale length) is our input + // 60 % 12 = 0 var scaleDegree = stepIn % this.scale.length + // what's this doing + // 0 scaleDegree = 12 + // seems to simply be for a negative result from above, maybe another way to do it, but ok for now while (scaleDegree < 0) { scaleDegree += this.scale.length } + // tonic is currently always 1 + // so this is 1*scale[scaledegree] var freq = this.tonic*this.scale[scaleDegree] + // map it to octave freq = freq*(Math.pow(2,octave)) // truncate irrational numbers @@ -137,10 +144,13 @@ Tune.prototype.MIDI = function(stepIn,octaveIn) { } /* Load a new scale */ +// sets .scale to ratios Tune.prototype.loadScale = function(scale){ /* load the scale */ + let name + if (typeof scale === 'string') name = scale; var freqs = isArrayOfNumbers(scale) ? scale : TuningList[scale].frequencies this.scale = [] for (var i=0;i { diff --git a/website/src/pages/learn/xen.mdx b/website/src/pages/learn/xen.mdx index 0dd0ea5fe..584d91b13 100644 --- a/website/src/pages/learn/xen.mdx +++ b/website/src/pages/learn/xen.mdx @@ -8,6 +8,8 @@ import { JsDoc } from '../../docs/JsDoc'; # Xenharmonic Functions (experimental) +{/* TODO expand explanation of xenharmony */} + These functions allow the use of scales other than your typical chromatic 12 based ones. ### tune(scale) @@ -96,11 +98,4 @@ The `tranh3` tuning has a similar set of notes, with two clashing. You might try ### xen(scaleOrRatios) - - -{/* */} + \ No newline at end of file