Table of Contents

Class SequencedMidiPlayer

Namespace
NAudio.Midi
Assembly
NAudio.Midi.dll

Plays an EventTimeline<T> of MIDI events on an IMidiInstrument, driven by a Transport. Unlike SequencedSampleProvider<T> (which spawns a sample provider per event into a mixer), this drives a single stateful polyphonic instrument: on each Read(Span<float>) it dispatches the buffer's MIDI events to the instrument at their exact frame offset, rendering the instrument in segments between events so timing is sample-accurate within the block.

public sealed class SequencedMidiPlayer : ISampleProvider
Inheritance
SequencedMidiPlayer
Implements
Inherited Members
Extension Methods

Remarks

The steady-state Read(Span<float>) path performs no heap allocations and takes no lock on the timeline: event queries run over EventTimeline<T>'s lock-free immutable snapshot, and the per-buffer event list and dispatch delegate are allocated once up front.

Constructors

SequencedMidiPlayer(Transport, EventTimeline<MidiEvent>, IMidiInstrument)

Creates the bridge. The instrument's sample rate must match the transport's.

public SequencedMidiPlayer(Transport transport, EventTimeline<MidiEvent> timeline, IMidiInstrument instrument)

Parameters

transport Transport
timeline EventTimeline<MidiEvent>
instrument IMidiInstrument

Properties

Instrument

The instrument the timeline plays.

public IMidiInstrument Instrument { get; }

Property Value

IMidiInstrument

Transport

The transport driving playback position.

public Transport Transport { get; }

Property Value

Transport

WaveFormat

Gets the WaveFormat of this Sample Provider.

public WaveFormat WaveFormat { get; }

Property Value

WaveFormat

The wave format.

Methods

Read(Span<float>)

Fill the specified buffer with 32 bit floating point samples

public int Read(Span<float> buffer)

Parameters

buffer Span<float>

The buffer to fill with samples.

Returns

int

The number of samples written. Return 0 to signal end of stream.