rename inline functions to match global ones, prefixed with _

This commit is contained in:
Felix Roos 2024-03-17 04:15:59 +01:00
parent 076b6f1c82
commit be77882d70
2 changed files with 4 additions and 11 deletions

View File

@ -96,7 +96,6 @@ export function registerWidget(type, fn) {
function getCanvasWidget(id, options = {}) {
const { width = 500, height = 60, pixelRatio = window.devicePixelRatio } = options;
let canvas = document.getElementById(id) || document.createElement('canvas');
console.log('canvas', canvas);
canvas.width = width * pixelRatio;
canvas.height = height * pixelRatio;
canvas.style.width = width + 'px';
@ -105,25 +104,19 @@ function getCanvasWidget(id, options = {}) {
return canvas;
}
registerWidget('roll', (id, options = {}, pat) => {
registerWidget('_pianoroll', (id, options = {}, pat) => {
const ctx = getCanvasWidget(id, options).getContext('2d');
return pat.pianoroll({ fold: 1, ...options, ctx, id });
});
registerWidget('twist', (id, options = {}, pat) => {
registerWidget('_spiral', (id, options = {}, pat) => {
options = { width: 200, height: 200, size: 36, ...options };
const ctx = getCanvasWidget(id, options).getContext('2d');
return pat.spiral({ ...options, ctx, id });
});
registerWidget('osci', (id, options = {}, pat) => {
registerWidget('_scope', (id, options = {}, pat) => {
options = { width: 500, height: 60, pos: 0.5, scale: 1, ...options };
const ctx = getCanvasWidget(id, options).getContext('2d');
// TODO: find way to clear previous analysers to avoid memory leak
// .scope passes id to Pattern.analyze, which is picked up by superdough
// .. which calls getAnalyserById(analyze), creating a new analyzer (+buffer) for that key
// the id here is the col number where the osci function ends (as passed by the transpiler)
// effectively, this means for each evaluation of .osci on a unique col, a new analyser will be created
// the problem is that the old ones will never get deleted.. this might pile up some memory
return pat.scope({ ...options, ctx, id });
});

View File

@ -27,7 +27,7 @@ customElement('strudel-claviature', { options: '{}' }, (props, { element }) => {
);
});
registerWidget('claviature', (id, options = {}, pat) => {
registerWidget('_claviature', (id, options = {}, pat) => {
options = { range: ['A0', 'C8'], scaleY: 1, scaleY: 0.5, scaleX: 0.5, ...options };
const height = (options.upperHeight + options.lowerHeight) * options.scaleY;
const el = getSolidWidget('strudel-claviature', id, { ...options, height });