Class LrcDocumentExtensions
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
docLrcDocumentThe document to search.
positionTimeSpanPlayhead position (post-offset).
Returns
- LrcLine
The matching line, or
nullif Lines is empty orpositionprecedes every line. Returns the last line ifpositionis 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
docis 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
docLrcDocumentThe owning document.
tLrcTimestampA 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
docis 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
lineLrcLineThe line to flatten.
Returns
- string
The concatenated text.
Exceptions
- ArgumentNullException
lineis 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
docLrcDocumentThe document to scan.
startTimeSpanInclusive lower bound (post-offset).
endTimeSpanExclusive upper bound (post-offset).
Returns
- IEnumerable<LrcLine>
A lazy sequence of matching lines.
Exceptions
- ArgumentNullException
docis null.