Class EventTimeline<T>
- Namespace
- NAudio.Sequencing
- Assembly
- NAudio.Core.dll
An ordered set of timed events with a consumer-defined payload. Events are sorted by tick; events with the same tick preserve insertion order. Internally the timeline is an immutable snapshot array published copy-on-write: mutators (Add(long, T), Clear()) serialise on an internal lock and atomically publish a new array, while queries read the current snapshot lock-free and (via EventsInRangeSpan(long, long)) allocation-free. This trade-off favours the audio thread — timelines are queried every buffer but mutated rarely (user edits) — at the cost of an O(n) copy per mutation, and it means a UI-thread edit can never block or priority-invert the audio thread's per-buffer query.
public sealed class EventTimeline<T>
Type Parameters
TPayload type. See SequencerEvent<T>.
- Inheritance
-
EventTimeline<T>
- Inherited Members
Properties
Count
The number of events currently in the timeline.
public int Count { get; }
Property Value
FirstTick
The smallest tick at which an event lies, or null if empty.
public long? FirstTick { get; }
Property Value
- long?
LastTick
The largest tick at which an event lies, or null if empty.
public long? LastTick { get; }
Property Value
- long?
Methods
Add(SequencerEvent<T>)
Adds a pre-built event.
public void Add(SequencerEvent<T> ev)
Parameters
evSequencerEvent<T>
Add(long, T)
Adds an event at the given tick.
public void Add(long tick, T payload)
Parameters
ticklongpayloadT
Clear()
Removes all events.
public void Clear()
EventsInRange(long, long)
Returns the events whose tick lies in the half-open range [startTickInclusive,
endTickExclusive). Returns a snapshot so the caller can iterate while the
timeline is mutated concurrently. Allocates a fresh array per call; per-buffer audio-thread
callers should prefer the allocation-free EventsInRangeSpan(long, long).
public IReadOnlyList<SequencerEvent<T>> EventsInRange(long startTickInclusive, long endTickExclusive)
Parameters
Returns
EventsInRangeSpan(long, long)
The allocation-free, lock-free variant of EventsInRange(long, long): returns a span over
the timeline's current immutable snapshot covering the half-open tick range
[startTickInclusive, endTickExclusive).
public ReadOnlySpan<SequencerEvent<T>> EventsInRangeSpan(long startTickInclusive, long endTickExclusive)
Parameters
Returns
Remarks
Safe to call from the audio thread while another thread mutates the timeline: a mutation publishes a new snapshot array, so the returned span stays valid and internally consistent (it keeps the snapshot it was created from) but does not observe later edits. Take a fresh span per buffer to pick up edits.