[reportlab-users] Styling within platypus flowables

Nick Moffitt nick+chordlab at zork.net
Fri Feb 7 13:41:06 EST 2014


First of all, I do want to say thank you to everyone who responded!

Brenda J. Butler:

> Did I miss anything, Nick? Hopefully this is what you meant and I

> didn't completely misunderstand.


Thank you! Yes, your explanation is excellent. We tend to print the
chord names above the lyrics, but that's a detail :)

Andy Robinson:

> I presume that in these cases, one already has the text broken into

> separate lines, as I have never seem poems and song lyrics with lines

> so long that wrapping was a problem.


And yet, when parsing arbitrary user input, it's helpful to handle
problems gracefully.


> So, Nick, are we looking for magic code which knows enough English to

> work out at which character a syllable begins? How would you

> arrange the "information structure" at a Python level, before worrying

> about how to draw it? e.g. a list of words, some of them having

> chords applied at beginning, or end, or character 'n'? If you can

> express the 'input' as some list of words, symbols and offsets, I'm

> sure people here can come up with a nice way to render it.


The solution in use in all the tools I mentioned in my initial post is
called "chordpro" and it's been a semi-standardised format since at
least the 1990s. The clearest specification is this page from the
chordii manuals:

http://www.vromans.org/johan/projects/Chordii/chordpro/index.html

> Lines that are not directives are song lines. They contain the lyrics

> of the song. Between the lyrics the chords are specified between [ and

> ] (square brackets). Chords should immediately precede the syllable of

> text they apply to. For example:

>

> Swing [D]low, sweet [G]chari[D]ot,

>

> When processed, this results in:

>

> D G D

> Swing low, sweet chariot,


Basically I have a tokeniser written in Python already that does a
pretty reliable job of sussing out the structure. Here's an example
snippet of some debugging output:

('directive', '{start_of_chorus}')
('newline', '\n')
('lyric', 'well to')
('chord', '[Am]')
('lyric', 'day is grey ')
('chord', '[C]')
('lyric', 'skies')
('newline', '\n')
('lyric', 'to')
('chord', '[Dmaj7]')
('lyric', 'morrow is ')
('chord', '[Am]')
('lyric', 'tears')
('newline', '\n')
('lyric', "you'll ")
('chord', '[F]')
('lyric', 'have to wait till ')
('chord', '[E]')
('lyric', 'yesterday is ')
('chord', '[Am]')
('lyric', 'here')
('newline', '\n')
('directive', '{end_of_chorus}')
('newline', '\n\n')

So I basically can pack this up however I like for whatever method seems
best. I can do the chordlab approach and just render to the canvas,
save my positions, move around for the chord and pop back again to print
the next lyric, or I can do some parsing and zip structures up into
something more aggregated.

So really to me the only issue now is how to turn this knowledge of the
structured data into a reliably nice-looking page or slide.

Tim Roberts:

> Now, it's quite possible that the learning curve would be longer than

> just fixing up the ReportLab solution you already have, but it's

> something to consider.


Yeah, the advantage of the chordpro format is that any novice musician
who isn't proficient with complicated software can just send me an
e-mail saying "Swing [D]low, sweet [G]chari[D]ot" and I can turn it into
screen- and print-ready sheets for the weekly club meeting.

chordii/chordlab etc also print out graphical representations of the
fingering for any chords used in a given song, so that people who are
still learning their way around the fretboard can still pick it up as
they go. It's a very different way of doing things than a proper
musical score in staves.

--
01234567 <- The amazing* Indent-O-Meter!
^
*: Indent-O-Meter may not actually amaze.


More information about the reportlab-users mailing list