For when you can’t read the lyrics.
- About
- How does it work?
- API Reference – use on your website, for free!
- Download
About
Lyricant is a poorly coded solution to a problem I constantly face when rehearsing songs – the lyrics don’t all fit on one page when they easily could. You used this feature when browsing the fullscreen version of songs on this site.
More specifically, I was writing songs in a portrait-oriented word processor on a widescreen display. One page is hard enough to get maximized on the screen let alone 2 or 3 at a reasonable font size.
Sure, I could flip the document to landscape and add in columns, then manually typeset everything, but this gets tedious very quickly. Especially when computers can figure all this stuff out quite easily.
How does it work?
Lyricant’s goal is to maximize the font size without causing any word-wrapping on any of the lines. It does this by increasing the font size until wrapping occurs. Then it backs off the the font size so that wrapping doesn’t occur. Then it tries to add columns and increases the font size until wrapping occurs and backs it off. If the font size was bigger than one column then we go with that, otherwise we go with two columns and so on. This continues to find the best column fit that maximizes the font size.
Its not implemented perfectly and doesn’t work with all cases. Specifically, short 1 stanza stuff. And its stupidly a recursive algorithm but it has some patches in place so that it doesn’t run for too many cycles. Luckily for any song I throw at it it handles it so it works fine I guess.
API Reference
Lyricant uses a simple URL-based API schema.
https://publicdomainmusic.github.io/lyricant/##{Plaintext of song lyrics, LZ Compressed, Encoded as Base64}
To do the compression/encoding there is a handy library called LZString:
http://pieroxy.net/blog/pages/lz-string/index.html
I specifically used Version 1.4.4
Example
window.location = LZString144.compressToEncodedURIComponent(plainTextLyrics)
Download
You are also free to download the html file and it’s dependencies and host them or modify them however you see fit. To zip or not to zip