mirror of
https://github.com/eliasstepanik/strudel.git
synced 2026-01-11 13:48:40 +00:00
draw straight line when no analyser is defined yet
+ add todo for memory leak
This commit is contained in:
parent
dd78dc9606
commit
cdc200e1da
@ -15,13 +15,23 @@ export function drawTimeScope(
|
|||||||
id = 1,
|
id = 1,
|
||||||
} = {},
|
} = {},
|
||||||
) {
|
) {
|
||||||
const dataArray = getAnalyzerData('time', id);
|
|
||||||
|
|
||||||
ctx.lineWidth = thickness;
|
ctx.lineWidth = thickness;
|
||||||
ctx.strokeStyle = color;
|
ctx.strokeStyle = color;
|
||||||
|
let canvas = ctx.canvas;
|
||||||
|
|
||||||
|
if (!analyser) {
|
||||||
|
// if analyser is undefined, draw straight line
|
||||||
|
// it may be undefined when no sound has been played yet
|
||||||
|
ctx.beginPath();
|
||||||
|
let y = pos * canvas.height;
|
||||||
|
ctx.moveTo(0, y);
|
||||||
|
ctx.lineTo(canvas.width, y);
|
||||||
|
ctx.stroke();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const dataArray = getAnalyzerData('time', id);
|
||||||
|
|
||||||
ctx.beginPath();
|
ctx.beginPath();
|
||||||
let canvas = ctx.canvas;
|
|
||||||
|
|
||||||
const bufferSize = analyser.frequencyBinCount;
|
const bufferSize = analyser.frequencyBinCount;
|
||||||
let triggerIndex = align
|
let triggerIndex = align
|
||||||
@ -49,6 +59,14 @@ export function drawFrequencyScope(
|
|||||||
analyser,
|
analyser,
|
||||||
{ color = 'white', scale = 0.25, pos = 0.75, lean = 0.5, min = -150, max = 0, ctx = getDrawContext(), id = 1 } = {},
|
{ color = 'white', scale = 0.25, pos = 0.75, lean = 0.5, min = -150, max = 0, ctx = getDrawContext(), id = 1 } = {},
|
||||||
) {
|
) {
|
||||||
|
if (!analyser) {
|
||||||
|
ctx.beginPath();
|
||||||
|
let y = pos * canvas.height;
|
||||||
|
ctx.moveTo(0, y);
|
||||||
|
ctx.lineTo(canvas.width, y);
|
||||||
|
ctx.stroke();
|
||||||
|
return;
|
||||||
|
}
|
||||||
const dataArray = getAnalyzerData('frequency', id);
|
const dataArray = getAnalyzerData('frequency', id);
|
||||||
const canvas = ctx.canvas;
|
const canvas = ctx.canvas;
|
||||||
|
|
||||||
@ -119,7 +137,7 @@ Pattern.prototype.tscope = function (config = {}) {
|
|||||||
return this.analyze(id).draw(
|
return this.analyze(id).draw(
|
||||||
() => {
|
() => {
|
||||||
clearScreen(config.smear, '0,0,0', config.ctx);
|
clearScreen(config.smear, '0,0,0', config.ctx);
|
||||||
analysers[id] && drawTimeScope(analysers[id], config);
|
drawTimeScope(analysers[id], config);
|
||||||
},
|
},
|
||||||
{ id },
|
{ id },
|
||||||
);
|
);
|
||||||
|
|||||||
@ -25,5 +25,11 @@ registerWidget('twist', (id, options = {}, pat) => {
|
|||||||
registerWidget('osci', (id, options = {}, pat) => {
|
registerWidget('osci', (id, options = {}, pat) => {
|
||||||
options = { width: 500, height: 60, pos: 0.5, scale: 1, ...options };
|
options = { width: 500, height: 60, pos: 0.5, scale: 1, ...options };
|
||||||
const ctx = getCanvasWidget(id, options).getContext('2d');
|
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 });
|
return pat.scope({ ...options, ctx, id });
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user