songleaf.snippets¶
Score snippets on the sheet (songleaf#12): which stretch of a song, and a small staff for it.
A snippet is a few bars of notation drawn above one line of the lyrics, for a sense of the melody or the rhythm. Three parts, each replaceable:
Which stretch:
choose_segment()picks a line by rule (the first line of the chorus, else the most repeated line, else the first line), andmark_segment()records the choice, with the notation, as the song’sscoreannotation (songleaf.model.score_link()). A recorded annotation wins over the rule, so it is how a choice is overridden.What to draw: a snippet provider,
song -> ScoreSnippet | None, is injected intosongleaf.render.render_sheet()(snippets=) and never imported by it.abc_snippet()draws the short ABC notation recorded on the annotation with reportlab lines only: one voice, treble staff, notes, rests, accidentals, bar lines and chord names (no clef is drawn). With thescoreextra,songleaf.engrave.engraved_snippet()engraves ABC, MusicXML or MEIproperly;
default_provider()picks it when installed.Where it goes: the
scorelayout option makes the renderer place the snippet as a row above its line; the font fit counts its height, so the lyrics shrink to make room.
ABC subset read by parse_abc(): notes A-G a-g with , / '
octave marks, ^ _ = accidentals, lengths 2 /2 3/2 /
(the unit is an eighth note), rests z, bar lines | || |] |:
:|, and "G" chord names over the next note. A length that needs a tie
(5) is refused. Header lines (K:G), decorations (!fermata!) and
anything else (ties, slurs, spaces) are skipped.
>>> [(n.pitch, n.length) for n in parse_abc("C2 D/2 z |").notes]
[(28, 0.25), (29, 0.0625), (None, 0.125)]
Module Attributes
The length of an unmarked ABC note, as a fraction of a whole note. |
|
The shortest and longest note lengths read, in whole notes. |
|
The shortest and longest note lengths read, in whole notes. |
|
a snippet is a few bars. |
|
The notation formats a score annotation may hold inline (all but |
|
What a provider-less recorded snippet is noted as. |
|
what the sheet draws for a song, or |
Functions
|
The default provider: the ABC notation recorded on the song's |
|
The line a snippet goes with: the first line of the chorus, else the most repeated line, else the first. |
The provider a |
|
|
A provider asking each of providers in turn: the first snippet wins. |
|
A |
|
A copy of song whose one |
|
The notes, rests and bars of a short ABC notation (see the module docstring). |
|
The song's first |
|
The 1-based lyric line (blank lines not counted) as a segment chosen by hand. |
Classes
|
A bar line ( |
|
One note ( |
|
A drawable snippet, sized in staff spaces, placed above the line holding |
|
A stretch of a song's text and the rule that chose it. |
|
A parsed snippet: notes, rests and bar lines in order. |
- class songleaf.snippets.Bar(kind='|')[source]¶
Bases:
objectA bar line (
kind:|,||,|],|:or:|).
- songleaf.snippets.INLINE_SOURCE = 'inline'¶
What a provider-less recorded snippet is noted as.
- songleaf.snippets.MAX_LENGTH = Fraction(4, 1)¶
The shortest and longest note lengths read, in whole notes.
- songleaf.snippets.MAX_NOTATION_CHARS = 400¶
a snippet is a few bars.
- Type:
Notations longer than this are refused
- songleaf.snippets.MIN_LENGTH = Fraction(1, 64)¶
The shortest and longest note lengths read, in whole notes.
- songleaf.snippets.NOTATION_FORMATS = ('abc', 'musicxml', 'mei')¶
The notation formats a score annotation may hold inline (all but
abcneed thescoreextra).
- class songleaf.snippets.Note(pitch, length, accidental='', chord='')[source]¶
Bases:
objectOne note (
pitcha diatonic number, C4 = 28) or rest (pitchNone).
- class songleaf.snippets.ScoreSnippet(width, height, draw, start=0)[source]¶
Bases:
objectA drawable snippet, sized in staff spaces, placed above the line holding
start.draw(canvas, left, bottom, space, *, color, font)draws it with its lower-left corner at(left, bottom),spacepoints per staff space; it then takeswidth * spacebyheight * spacepoints.
- class songleaf.snippets.Segment(start, end, rule)[source]¶
Bases:
objectA stretch of a song’s text and the rule that chose it.
- songleaf.snippets.SnippetProvider¶
what the sheet draws for a song, or
Nonefor no snippet.- Type:
A snippet provider
- class songleaf.snippets.Tune(events)[source]¶
Bases:
objectA parsed snippet: notes, rests and bar lines in order.
- songleaf.snippets.UNIT_LENGTH = Fraction(1, 8)¶
The length of an unmarked ABC note, as a fraction of a whole note.
- songleaf.snippets.abc_snippet(song)[source]¶
The default provider: the ABC notation recorded on the song’s
scoreannotation, drawn.Nonewhen the song has no such annotation, or its notation cannot be read.- Return type:
- songleaf.snippets.choose_segment(song)[source]¶
The line a snippet goes with: the first line of the chorus, else the most repeated line, else the first.
Nonefor a song with no lyric line.
- songleaf.snippets.default_provider()[source]¶
The provider a
scoresheet uses when none is injected.The engraved one (
songleaf.engrave.engraved_snippet()) when thescoreextra is installed, falling back toabc_snippet(); elseabc_snippet()alone.- Return type:
Callable[[Song],ScoreSnippet|None]
- songleaf.snippets.first_snippet(providers)[source]¶
A provider asking each of providers in turn: the first snippet wins.
- Return type:
Callable[[Song],ScoreSnippet|None]
- songleaf.snippets.layout_tune(tune)[source]¶
A
ScoreSnippetdrawing tune on one treble staff, with reportlab lines only.- Return type:
- songleaf.snippets.mark_segment(song, notation, *, segment=None, format='abc')[source]¶
A copy of song whose one
scoreannotation holds notation over segment.segment defaults to
choose_segment()’s. Earlierscoreannotations are replaced: the recorded one is what the sheet draws.- Return type:
- songleaf.snippets.parse_abc(notation)[source]¶
The notes, rests and bars of a short ABC notation (see the module docstring).
Raises
ValueErrorfor an empty or over-long notation, or one with no note.- Return type: