Skip to Content
Soundor Components
Components

LevelMeter

dB levels with a held peak and a latched clip.

Use LevelMeter for one or more channels. It exposes its level to assistive technology, and its clip indicator stays lit until pressed.

import { LevelMeter } from '@soundor/components';
import { useEffect, useState } from 'react';

export default function Demo() {
  const [levels, setLevels] = useState<[number, number]>([-18, -22]);
  useEffect(() => {
    let t = 0;
    const timer = setInterval(() => {
      t += 0.12;
      setLevels([
        -14 + Math.sin(t) * 12 + (Math.random() - 0.5) * 6,
        -18 + Math.sin(t * 1.3 + 1) * 12 + (Math.random() - 0.5) * 6,
      ]);
    }, 50);
    return () => clearInterval(timer);
  }, []);
  return (
    <LevelMeter
      label="Output"
      value={levels}
      min={-60}
      max={6}
      clipAt={0}
      orientation="horizontal"
      length={220}
    />
  );
}
level-meter.tsx, running in the web runtime.Source

Examples

Stereo master

Pass one value per channel. Peaks hold for peakHold seconds and then fall at fallRate dB per second; warningAt and clipAt change the colour. The indicator at the top latches when the level reaches clipAt, and a click on it clears it.

import { LevelMeter } from '@soundor/components';
import { useEffect, useState } from 'react';

export default function Demo() {
  const [levels, setLevels] = useState<[number, number]>([-20, -24]);
  useEffect(() => {
    let t = 0;
    const timer = setInterval(() => {
      t += 0.14;
      const hit = Math.max(0, Math.sin(t * 2)) ** 4;
      setLevels([
        -30 + hit * 34 + (Math.random() - 0.5) * 4,
        -32 + hit * 32 + (Math.random() - 0.5) * 4,
      ]);
    }, 50);
    return () => clearInterval(timer);
  }, []);
  // One value per channel; the peaks hold, then fall.
  return (
    <LevelMeter
      label="Master"
      value={levels}
      channelLabels={['left', 'right']}
      min={-60}
      max={6}
      warningAt={-6}
      clipAt={0}
      ticks={[-48, -36, -24, -12, -6, 0]}
      peakHold={1.5}
      fallRate={18}
      length={190}
    />
  );
}
level-meter-stereo.tsx, running in the web runtime.Source

Keyboard and accessibility

Each channel is announced as a progress bar with its label and level. The clip indicator is a separate toggle button, reachable with Tab and cleared with Enter or Space. Its pressed state indicates whether clipping is latched. See Keyboard and accessibility.

Use channelLabels to name channels in the same order as value. Names are appended to the meter's label, so the stereo example's progress bars are named "Master, left" and "Master, right". Missing or empty names fall back to "channel 1", "channel 2", and so on for multi-channel meters. An unnamed mono meter uses just label.

By default, clip-reset buttons are named "Master clip, left" and "Master clip, right" in the stereo example, or just "Master clip" for an unnamed mono meter. Use clipResetLabel to customize the full button name. It receives the supplied or numbered channel name, or undefined for unnamed mono.

<LevelMeter
  label="Output level"
  value={[left, right]}
  channelLabels={['left', 'right']}
  clipResetLabel={(channel) => `Reset output clip, ${channel}`}
/>

Props

Prop

Type

On this page