Table of Contents

Class LevelMeter

Namespace
PluginUI
Assembly
PluginUI.dll

Multi-channel level meter: vertical or horizontal, dB scale with marks, gradient / LED segments / solid bars, peak-hold markers, latched clip indicators (click to reset), optional RMS + peak dual display, gain-reduction mode.

public class LevelMeter : Control
Inheritance
LevelMeter
Inherited Members

Remarks

Feed it on the UI thread with SetLevels(params float[]) (and SetRmsLevels(params float[])), or give it PeakValue Sources written by the audio thread: they are polled on every frame.

Ballistics (instant attack, dB/s release, peak hold) come from LevelBallistics.

Constructors

LevelMeter()

Creates a stereo meter.

public LevelMeter()

Properties

ChannelCount

Number of channels.

public int ChannelCount { get; set; }

Property Value

int

ChannelGap

Gap between channel bars in DIPs.

public float ChannelGap { get; set; }

Property Value

float

ClipDb

Level at which the clip indicator latches (dB).

public float ClipDb { get; set; }

Property Value

float

DangerColor

High-level color (null = theme danger).

public Color? DangerColor { get; set; }

Property Value

Color?

DangerDb

Level where the gradient turns red (dB).

public float DangerDb { get; set; }

Property Value

float

DefaultSize

Natural size used when no explicit size is given.

protected override Size DefaultSize { get; }

Property Value

Size

HoldSeconds

Peak-hold time in seconds.

public float HoldSeconds { get; set; }

Property Value

float

InputUnit

Unit of the values passed to SetLevels(params float[]).

public LevelUnit InputUnit { get; set; }

Property Value

LevelUnit

LowColor

Low-level color (null = green).

public Color? LowColor { get; set; }

Property Value

Color?

MaxDb

Top of the scale in dB.

public float MaxDb { get; set; }

Property Value

float

MaxReductionDb

Full scale of the gain-reduction mode (dB).

public float MaxReductionDb { get; set; }

Property Value

float

MeterStyle

Drawing style.

public MeterStyle MeterStyle { get; set; }

Property Value

MeterStyle

MinDb

Bottom of the scale in dB.

public float MinDb { get; set; }

Property Value

float

Mode

Level or gain-reduction meter.

public MeterMode Mode { get; set; }

Property Value

MeterMode

Orientation

Bar orientation.

public Orientation Orientation { get; set; }

Property Value

Orientation

ReleaseDbPerSecond

Peak release speed in dB per second.

public float ReleaseDbPerSecond { get; set; }

Property Value

float

RmsSources

Optional audio-thread RMS sources (one per channel).

[Browsable(false)]
public IReadOnlyList<PeakValue>? RmsSources { get; set; }

Property Value

IReadOnlyList<PeakValue>

ScaleMarks

Scale marks in dB (null = automatic set).

public IReadOnlyList<float>? ScaleMarks { get; set; }

Property Value

IReadOnlyList<float>

SegmentGap

Gap between LED segments in DIPs.

public float SegmentGap { get; set; }

Property Value

float

SegmentLength

LED segment length in DIPs (segment style).

public float SegmentLength { get; set; }

Property Value

float

ShowClipIndicator

Draws latched clip indicators above the bars (click to reset).

public bool ShowClipIndicator { get; set; }

Property Value

bool

ShowPeakHold

Draws peak-hold markers.

public bool ShowPeakHold { get; set; }

Property Value

bool

ShowScale

Draws the dB scale (marks and labels) beside the bars.

public bool ShowScale { get; set; }

Property Value

bool

Sources

Audio-thread level sources polled every frame (one per channel; null = use SetLevels(params float[])).

[Browsable(false)]
public IReadOnlyList<PeakValue>? Sources { get; set; }

Property Value

IReadOnlyList<PeakValue>

WarningColor

Warning color (null = theme warning).

public Color? WarningColor { get; set; }

Property Value

Color?

WarningDb

Level where the gradient turns yellow (dB).

public float WarningDb { get; set; }

Property Value

float

Methods

ColorForDb(float)

Color of a level (gradient zones).

protected Color ColorForDb(float db)

Parameters

db float

Returns

Color

Fraction(float)

Position of a dB value along the bar, 0 (empty end) → 1 (full end).

protected float Fraction(float db)

Parameters

db float

Returns

float

GetDisplayedLevel(int)

Peak level (dB) currently displayed for a channel.

public float GetDisplayedLevel(int channel)

Parameters

channel int

Returns

float

IsClipped(int)

true if the channel's clip indicator is latched.

public bool IsClipped(int channel)

Parameters

channel int

Returns

bool

OnAttached()

Called when the element joins a host (subscribe to external events here).

protected override void OnAttached()

OnDetached()

Called when the element leaves its host (unsubscribe here).

protected override void OnDetached()

OnMouseDown(MouseEventArgs)

Mouse button pressed over the element (or captured).

protected override void OnMouseDown(MouseEventArgs e)

Parameters

e MouseEventArgs

OnRender(DrawingContext)

Draws the meter. With a Skin (for example a FilmStripSkin whose frame follows the level), the skin draws each channel in its own bar area: Value is the channel level mapped to [0, 1] over MinDb…MaxDb (or the reduction range in gain-reduction mode) and StateIndex is 1 while the channel's clip indicator is latched. The scale is still drawn.

protected override void OnRender(DrawingContext dc)

Parameters

dc DrawingContext

Drawing context.

RenderVector(DrawingContext, Rect, VectorStyle)

Vector rendering of the widget area.

protected override void RenderVector(DrawingContext dc, Rect widget, VectorStyle style)

Parameters

dc DrawingContext
widget Rect
style VectorStyle

Reset()

Resets levels, holds and clip indicators.

public void Reset()

ResetClip()

Resets the clip indicators.

public void ResetClip()

SetLevels(params float[])

Sets the current peak levels (UI thread), one per channel, in InputUnit. In gain-reduction mode, pass the reduction in positive dB (or linear gain ≤ 1).

public void SetLevels(params float[] levels)

Parameters

levels float[]

SetRmsLevels(params float[])

Sets the current RMS levels (enables the dual peak/RMS display).

public void SetRmsLevels(params float[] levels)

Parameters

levels float[]

Events

ClipReset

Raised when the user resets the clip indicators.

public event Action<LevelMeter>? ClipReset

Event Type

Action<LevelMeter>