strudel/docs/dist/tune.js
Felix Roos a2ab2b9da5 build
2022-03-06 21:39:10 +01:00

15 lines
652 B
JavaScript

import Tune from "./tunejs.js";
import {Pattern} from "../_snowpack/link/strudel.js";
Pattern.prototype._tune = function(scale, tonic = 220) {
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);
tune.tonicize(tonic);
return this._asNumber()._withEvent((event) => {
return event.withValue(() => tune.note(event.value)).setContext({...event.context, type: "frequency"});
});
};
Pattern.prototype.define("tune", (scale, pat) => pat.tune(scale), {composable: true, patternified: true});