songleaf.model¶
The linked-artifact model: a song is lyrics text plus standoff annotations.
A Song keeps its lyrics as one plain string and everything else as
Annotation records anchored on character offsets into that string.
The text is never marked up, so any number of annotation layers can coexist
and be added later without touching the lyrics (the standoff design of
lacing, over characters instead of seconds).
Kinds used so far:
"section": spans the section’s lines,body={"label": "Chorus"}. A label-only section (a bare[Chorus]marker meaning “repeat the chorus”) is empty (start == end), sits on an empty line of its own, and has"marker": Truein its body."chord": a point (start == end) on the first character of the syllable the chord lands on,body={"symbol": "G/B", "timing": "at"}.timingis"at"(the chord sounds with that syllable, the default) or"before"(it sounds ahead of it). Chords of a line with no lyrics (an intro, an instrumental bar) sit, in order, on an empty line of the text."score": a link to a score snippet for[start, end),body={"source": ..., "id": ..., "url": ..., "format": ...}.
>>> song = Song("Hello there", [chord(0, "C"), chord(6, "G")], meta={"title": "Hi"})
>>> [(a.start, a.body["symbol"]) for a in song.of_kind("chord")]
[(0, 'C'), (6, 'G')]
>>> Song.from_dict(song.to_dict()) == song
True
Module Attributes
When a chord sounds, relative to the syllable it is anchored on. |
Functions
|
A chord landing on the syllable that starts at offset |
|
A link from |
|
A section (verse, chorus, ...) spanning |
Classes
|
One annotation over |
|
One line of a song's text: |
|
Lyrics text plus annotations, metadata and provenance. |
- class songleaf.model.Annotation(kind, start, end, body=<factory>)[source]¶
Bases:
objectOne annotation over
Song.text[start:end]; a point whenstart == end.
- songleaf.model.CHORD_TIMINGS = ('at', 'before')¶
When a chord sounds, relative to the syllable it is anchored on.
- class songleaf.model.Line(start, end, text)[source]¶
Bases:
objectOne line of a song’s text:
text == song.text[start:end].
- class songleaf.model.Song(text, annotations=<factory>, meta=<factory>, provenance=<factory>)[source]¶
Bases:
objectLyrics text plus annotations, metadata and provenance.
- Parameters:
text (
str) – The lyrics, lines separated by"\n".annotations (
list[Annotation]) – Standoff annotations overtext(kept sorted by start).meta (
dict) – Descriptive fields:title,artist,capo,key, …provenance (
dict) – Where the song came from:source,id,url,license.
- songleaf.model.chord(at, symbol, *, timing='at')[source]¶
A chord landing on the syllable that starts at offset
at.- Return type:
- songleaf.model.score_link(start, end, *, source, id, url='', format='')[source]¶
A link from
[start, end)to a score snippet held by a source.- Return type: