Table of Contents

Class LrcDocumentExtensions

Namespace
ModernLrc.Model
Assembly
ModernLrc.dll

Extension helpers for traversing and querying an LrcDocument. These are the playback hot path — a karaoke / lyric-display consumer typically calls FindLineAt(LrcDocument, TimeSpan) per video frame.

public static class LrcDocumentExtensions
Inheritance
LrcDocumentExtensions
Inherited Members

Methods

FindLineAt(LrcDocument, TimeSpan)

Currently-singing line: greatest line whose effective timestamp is ≤ position. O(log n) via binary search.

public static LrcLine? FindLineAt(this LrcDocument doc, TimeSpan position)

Parameters

doc LrcDocument

The document to search.

position TimeSpan

Playhead position (post-offset).

Returns

LrcLine

The matching line, or null if Lines is empty or position precedes every line. Returns the last line if position is at or after every line.

Examples

// Per video frame:
var current = doc.FindLineAt(player.Position);
if (current is LrcPlainLine plain) display.Show(plain.Text);

Exceptions

ArgumentNullException

doc is null.

GetEffectiveTime(LrcDocument, LrcTimestamp)

Apply the document offset to t. Returns TimeSpan (signed) because a large negative Offset can shift past zero — LrcTimestamp cannot represent that.

public static TimeSpan GetEffectiveTime(this LrcDocument doc, LrcTimestamp t)

Parameters

doc LrcDocument

The owning document.

t LrcTimestamp

A timestamp (typically from Timestamp).

Returns

TimeSpan

The effective time, with offset applied.

Examples

var ts = doc.Lines[0].Timestamp;
TimeSpan effective = doc.GetEffectiveTime(ts);

Exceptions

ArgumentNullException

doc is null.

GetText(LrcLine)

Concatenate the textual content of a line. For plain lines: returns Text. For enhanced lines: concatenates every Text in source order (including each word's trailing whitespace, so the result reproduces the source line exactly).

public static string GetText(this LrcLine line)

Parameters

line LrcLine

The line to flatten.

Returns

string

The concatenated text.

Exceptions

ArgumentNullException

line is null.

LinesInRange(LrcDocument, TimeSpan, TimeSpan)

Lines whose effective timestamp ∈ [start, end). Yielded in document order (sorted by timestamp; ties resolved by original index).

public static IEnumerable<LrcLine> LinesInRange(this LrcDocument doc, TimeSpan start, TimeSpan end)

Parameters

doc LrcDocument

The document to scan.

start TimeSpan

Inclusive lower bound (post-offset).

end TimeSpan

Exclusive upper bound (post-offset).

Returns

IEnumerable<LrcLine>

A lazy sequence of matching lines.

Exceptions

ArgumentNullException

doc is null.