accompy.songs#
Songs as backing-track input: a songleaf Song becomes a ChordSequence.
songleaf keeps a song as lyrics plus standoff chord annotations anchored on
syllables; it has no durations. song_to_chord_sequence() supplies them with
two simple, explicit heuristics:
beats_per_chord=N: every chord lastsNbeats;bars_per_line=N: every chord-carrying line lastsNbars, shared equally by the chords on it (so a two-chord line atbars_per_line=1gives each chord half a bar);neither (the default): every chord lasts one bar.
The converter reads a Song by shape (text, annotations of kind/start/
body, meta), so songleaf is not a dependency of accompy.
>>> from types import SimpleNamespace as NS
>>> song = NS(
... text="Hello there\nGoodbye now",
... annotations=[
... NS(kind="section", start=0, end=23, body={"label": "Verse"}),
... NS(kind="chord", start=0, end=0, body={"symbol": "C"}),
... NS(kind="chord", start=6, end=6, body={"symbol": "G"}),
... NS(kind="chord", start=12, end=12, body={"symbol": "Am"}),
... ],
... meta={"title": "Hi", "key": "C"},
... )
>>> cs = song_to_chord_sequence(song, bars_per_line=1)
>>> cs.chords
[('C', 2.0), ('G', 2.0), ('Am', 4.0)]
>>> cs.sections
[('Verse', 0, 3)]
Functions
|
Convert a songleaf-shaped |
- accompy.songs.song_to_chord_sequence(song, *, bars_per_line=None, beats_per_chord=None, beats_per_bar=4, tempo=120)[source]#
Convert a songleaf-shaped
songto aChordSequence.- Parameters:
song (
Any) – Anything withtext,annotationsandmetaas songleaf’sSong.bars_per_line (
Optional[float]) – Bars each chord-carrying line lasts, shared by its chords.beats_per_chord (
Optional[float]) – Beats every chord lasts. Exclusive withbars_per_line.beats_per_bar (
int) – Beats in a bar (the time signature’s numerator).tempo (
int) – Tempo in BPM (the song’smeta["tempo"]wins when it is a number).
- Return type:
- Returns:
A ChordSequence whose
sectionsfollow the song’ssectionannotations (ranges over the chords), with the song’s title and key.- Raises:
ValueError – if both
bars_per_lineandbeats_per_chordare given, or either is not positive.