Class WaveformView
- Namespace
- PluginUI
- Assembly
- PluginUI.dll
Sample display for samplers and audio editors: one lane per channel, zoom and scroll, start / end and loop markers (draggable, optionally bound to parameters), a selection, a play cursor and WAV file drop.
public class WaveformView : Control
- Inheritance
-
WaveformView
- Inherited Members
Examples
var wave = new WaveformView { AcceptFileDrop = true, ShowLoop = true, StartParameter = Parameters[model.Start] };
wave.Audio = WavReader.Read(@"C:\Samples\kick.wav");
wave.PlayPositionSource = () => processor.PlayPosition; // normalized, read every frame
Remarks
Mouse. Wheel scrolls, Ctrl + wheel zooms around the pointer, double-click on the background zooms to fit, dragging a marker moves it, Shift + drag selects a range.
Performance. A multi-resolution min/max summary (WaveformPeaks) is built once per channel, so even very long samples are drawn by reading a few values per pixel; when zoomed in to less than one sample per pixel the samples themselves are drawn as a line.
Markers. Positions are normalized (0 = first sample, 1 = last). When a marker parameter is set (StartParameter…), its normalized value is the position and drags send edit gestures.
Constructors
WaveformView()
Creates a waveform view.
public WaveformView()
Properties
AcceptFileDrop
Accepts audio files dropped from the Explorer (WAV files are decoded with WavReader).
public bool AcceptFileDrop { get; set; }
Property Value
Audio
The audio displayed (null = empty). Setting it zooms to fit and clears the selection.
[Browsable(false)]
public AudioData? Audio { get; set; }
Property Value
DefaultSize
Natural size used when no explicit size is given.
protected override Size DefaultSize { get; }
Property Value
EndParameter
Parameter holding the sample end.
public IParameter? EndParameter { get; set; }
Property Value
EndPosition
Sample end (normalized).
public double EndPosition { get; set; }
Property Value
Length
Number of frames of Audio.
[Browsable(false)]
public long Length { get; }
Property Value
LoopEnd
Loop end (normalized).
public double LoopEnd { get; set; }
Property Value
LoopEndParameter
Parameter holding the loop end.
public IParameter? LoopEndParameter { get; set; }
Property Value
LoopStart
Loop start (normalized).
public double LoopStart { get; set; }
Property Value
LoopStartParameter
Parameter holding the loop start.
public IParameter? LoopStartParameter { get; set; }
Property Value
PlayPosition
Play cursor position (normalized; NaN = hidden).
public double PlayPosition { get; set; }
Property Value
PlayPositionSource
Function polled every frame for the play cursor (e.g. a volatile value written by the audio thread).
[Browsable(false)]
public Func<double>? PlayPositionSource { get; set; }
Property Value
SelectionEnd
End frame (exclusive) of the selection; equal to SelectionStart when nothing is selected.
[Browsable(false)]
public long SelectionEnd { get; set; }
Property Value
SelectionStart
First frame of the selection.
[Browsable(false)]
public long SelectionStart { get; set; }
Property Value
ShowLoop
Shows (and allows dragging) the loop markers.
public bool ShowLoop { get; set; }
Property Value
ShowStartEnd
Shows (and allows dragging) the start and end markers.
public bool ShowStartEnd { get; set; }
Property Value
StartParameter
Parameter holding the sample start (normalized value = position).
public IParameter? StartParameter { get; set; }
Property Value
StartPosition
Sample start (normalized); ignored when StartParameter is set.
public double StartPosition { get; set; }
Property Value
ViewLength
Number of visible frames.
[Browsable(false)]
public double ViewLength { get; set; }
Property Value
ViewStart
First visible frame.
[Browsable(false)]
public double ViewStart { get; set; }
Property Value
WaveColor
Waveform color (null = theme accent).
public Color? WaveColor { get; set; }
Property Value
Methods
MoveMarker(WaveformMarker, double)
Moves a marker as the user would (constrained: start ≤ end, loop start ≤ loop end; bound parameters are edited).
public void MoveMarker(WaveformMarker marker, double position)
Parameters
markerWaveformMarkerThe marker.
positiondoubleNew normalized position.
OnAttached()
Called when the element joins a host (subscribe to external events here).
protected override void OnAttached()
OnCaptureLost()
The mouse capture was lost without a button release.
protected override void OnCaptureLost()
OnDetached()
Called when the element leaves its host (unsubscribe here).
protected override void OnDetached()
OnFilesDropped(FilesDroppedEventArgs)
Files dropped from the shell (requires AllowFileDrop on this element or an ancestor).
protected override void OnFilesDropped(FilesDroppedEventArgs e)
Parameters
OnMouseDown(MouseEventArgs)
Mouse button pressed over the element (or captured).
protected override void OnMouseDown(MouseEventArgs e)
Parameters
OnMouseMove(MouseEventArgs)
Mouse moved over the element (or captured).
protected override void OnMouseMove(MouseEventArgs e)
Parameters
OnMouseUp(MouseEventArgs)
Mouse button released.
protected override void OnMouseUp(MouseEventArgs e)
Parameters
OnMouseWheel(MouseEventArgs)
Mouse wheel over the element.
protected override void OnMouseWheel(MouseEventArgs e)
Parameters
RenderVector(DrawingContext, Rect, VectorStyle)
Vector rendering of the widget area.
protected override void RenderVector(DrawingContext dc, Rect widget, VectorStyle style)
Parameters
dcDrawingContextwidgetRectstyleVectorStyle
Zoom(double, double)
Zooms by a factor around a frame (factor < 1 zooms in).
public void Zoom(double factor, double aroundFrame)
Parameters
factordoubleRatio between the new and the current visible length.
aroundFramedoubleFrame that stays under the same pixel.
ZoomToFit()
Shows the whole sample.
public void ZoomToFit()
Events
AudioLoaded
Raised after a dropped WAV file was loaded (argument: path).
public event Action<WaveformView, string>? AudioLoaded
Event Type
FileDropped
Raised for dropped files that are not WAV, or WAV files that could not be decoded (argument: path).
public event Action<WaveformView, string>? FileDropped
Event Type
MarkerMoved
Raised after a marker was moved by the user.
public event Action<WaveformView, WaveformMarker>? MarkerMoved
Event Type
SelectionChanged
Raised after the user changed the selection.
public event Action<WaveformView>? SelectionChanged