small fixes to oscilloscope
This commit is contained in:
@ -116,6 +116,7 @@ export const drawEmptyBlinkers = (app: Editor) => {
|
|||||||
|
|
||||||
export interface OscilloscopeConfig {
|
export interface OscilloscopeConfig {
|
||||||
enabled: boolean;
|
enabled: boolean;
|
||||||
|
refresh: number;
|
||||||
color: string;
|
color: string;
|
||||||
thickness: number;
|
thickness: number;
|
||||||
fftSize: number; // multiples of 256
|
fftSize: number; // multiples of 256
|
||||||
@ -139,9 +140,18 @@ export const runOscilloscope = (
|
|||||||
const canvasCtx = canvas.getContext("2d")!;
|
const canvasCtx = canvas.getContext("2d")!;
|
||||||
const WIDTH = canvas.width;
|
const WIDTH = canvas.width;
|
||||||
const HEIGHT = canvas.height;
|
const HEIGHT = canvas.height;
|
||||||
|
let lastDrawTime = 0;
|
||||||
|
let frameInterval = 1000 / 30;
|
||||||
|
|
||||||
|
|
||||||
function draw() {
|
function draw() {
|
||||||
|
const currentTime = Date.now();
|
||||||
requestAnimationFrame(draw);
|
requestAnimationFrame(draw);
|
||||||
|
if (currentTime - lastDrawTime < frameInterval) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
lastDrawTime = currentTime;
|
||||||
|
|
||||||
if (!app.osc.enabled) {
|
if (!app.osc.enabled) {
|
||||||
canvasCtx.clearRect(0, 0, WIDTH, HEIGHT);
|
canvasCtx.clearRect(0, 0, WIDTH, HEIGHT);
|
||||||
return;
|
return;
|
||||||
@ -156,7 +166,9 @@ export const runOscilloscope = (
|
|||||||
|
|
||||||
canvasCtx.fillStyle = "rgba(0, 0, 0, 0)";
|
canvasCtx.fillStyle = "rgba(0, 0, 0, 0)";
|
||||||
canvasCtx.fillRect(0, 0, WIDTH, HEIGHT);
|
canvasCtx.fillRect(0, 0, WIDTH, HEIGHT);
|
||||||
canvasCtx.clearRect(0, 0, WIDTH, HEIGHT);
|
if (app.clock.time_position.pulse % app.osc.refresh == 0) {
|
||||||
|
canvasCtx.clearRect(0, 0, WIDTH, HEIGHT);
|
||||||
|
}
|
||||||
|
|
||||||
canvasCtx.lineWidth = app.osc.thickness;
|
canvasCtx.lineWidth = app.osc.thickness;
|
||||||
|
|
||||||
@ -202,6 +214,5 @@ export const runOscilloscope = (
|
|||||||
|
|
||||||
canvasCtx.stroke();
|
canvasCtx.stroke();
|
||||||
}
|
}
|
||||||
|
|
||||||
draw();
|
draw();
|
||||||
};
|
};
|
||||||
|
|||||||
@ -8,8 +8,8 @@ export const oscilloscope = (application: Editor): string => {
|
|||||||
You can turn on the oscilloscope to generate interesting visuals or to inspect audio. Use the <ic>scope()</ic> function to turn it on and off. The oscilloscope is off by default.
|
You can turn on the oscilloscope to generate interesting visuals or to inspect audio. Use the <ic>scope()</ic> function to turn it on and off. The oscilloscope is off by default.
|
||||||
|
|
||||||
${makeExample(
|
${makeExample(
|
||||||
"Oscilloscope configuration",
|
"Oscilloscope configuration",
|
||||||
`
|
`
|
||||||
scope({
|
scope({
|
||||||
enabled: true, // off by default
|
enabled: true, // off by default
|
||||||
color: "#fdba74", // any valid CSS color or "random"
|
color: "#fdba74", // any valid CSS color or "random"
|
||||||
@ -18,10 +18,11 @@ scope({
|
|||||||
orientation: "horizontal", // "vertical" or "horizontal"
|
orientation: "horizontal", // "vertical" or "horizontal"
|
||||||
is3D: false, // 3D oscilloscope
|
is3D: false, // 3D oscilloscope
|
||||||
size: 1, // size of the oscilloscope
|
size: 1, // size of the oscilloscope
|
||||||
|
refresh: 1 // refresh rate (in pulses)
|
||||||
})
|
})
|
||||||
`,
|
`,
|
||||||
true
|
true
|
||||||
)}
|
)}
|
||||||
|
|
||||||
Note that these values can be patterned as well! You can transform the oscilloscope into its own light show if you want. The picture is not stable anyway so you won't have much use of it for precision work :)
|
Note that these values can be patterned as well! You can transform the oscilloscope into its own light show if you want. The picture is not stable anyway so you won't have much use of it for precision work :)
|
||||||
|
|
||||||
|
|||||||
@ -63,6 +63,7 @@ export class Editor {
|
|||||||
enabled: false,
|
enabled: false,
|
||||||
color: "#fdba74",
|
color: "#fdba74",
|
||||||
thickness: 4,
|
thickness: 4,
|
||||||
|
refresh: 1,
|
||||||
fftSize: 256,
|
fftSize: 256,
|
||||||
orientation: "horizontal",
|
orientation: "horizontal",
|
||||||
is3D: false,
|
is3D: false,
|
||||||
|
|||||||
Reference in New Issue
Block a user