inline multichannel scopes

This commit is contained in:
Felix Roos 2024-03-16 02:14:24 +01:00
parent d9d05e21c0
commit f4032dad22
3 changed files with 47 additions and 32 deletions

View file

@ -1,13 +1,21 @@
import { Pattern, clamp } from '@strudel/core';
import { getDrawContext } from '../draw/index.mjs';
import { analyser, getAnalyzerData } from 'superdough';
import { getAnalyzerData } from 'superdough';
export function drawTimeScope(
analyser,
{ align = true, color = 'white', thickness = 3, scale = 0.25, pos = 0.75, trigger = 0 } = {},
{
align = true,
color = 'white',
thickness = 3,
scale = 0.25,
pos = 0.75,
trigger = 0,
ctx = getDrawContext(),
id = 1,
} = {},
) {
const ctx = getDrawContext();
const dataArray = getAnalyzerData('time');
const dataArray = getAnalyzerData('time', id);
ctx.lineWidth = thickness;
ctx.strokeStyle = color;
@ -39,10 +47,9 @@ export function drawTimeScope(
export function drawFrequencyScope(
analyser,
{ color = 'white', scale = 0.25, pos = 0.75, lean = 0.5, min = -150, max = 0 } = {},
{ color = 'white', scale = 0.25, pos = 0.75, lean = 0.5, min = -150, max = 0, ctx = getDrawContext(), id = 1 } = {},
) {
const dataArray = getAnalyzerData('frequency');
const ctx = getDrawContext();
const dataArray = getAnalyzerData('frequency', id);
const canvas = ctx.canvas;
ctx.fillStyle = color;
@ -61,8 +68,7 @@ export function drawFrequencyScope(
}
}
function clearScreen(smear = 0, smearRGB = `0,0,0`) {
const ctx = getDrawContext();
function clearScreen(smear = 0, smearRGB = `0,0,0`, ctx = getDrawContext()) {
if (!smear) {
ctx.clearRect(0, 0, ctx.canvas.width, ctx.canvas.height);
} else {
@ -84,9 +90,10 @@ function clearScreen(smear = 0, smearRGB = `0,0,0`) {
* s("sawtooth").fscope()
*/
Pattern.prototype.fscope = function (config = {}) {
return this.analyze(1).draw(() => {
clearScreen(config.smear);
analyser && drawFrequencyScope(analyser, config);
let id = config.id ?? 1;
return this.analyze(id).draw(() => {
clearScreen(config.smear, '0,0,0', config.ctx);
analysers[id] && drawFrequencyScope(analyser, config);
});
};
@ -105,9 +112,10 @@ Pattern.prototype.fscope = function (config = {}) {
* s("sawtooth").scope()
*/
Pattern.prototype.tscope = function (config = {}) {
return this.analyze(1).draw(() => {
clearScreen(config.smear);
analyser && drawTimeScope(analyser, config);
let id = config.id ?? 1;
return this.analyze(id).draw(() => {
clearScreen(config.smear, '0,0,0', config.ctx);
analysers[id] && drawTimeScope(analysers[id], config);
});
};