ptsefton / chordprobook

Script to convert collections of chordpro format song charts to PDF, HTML, and word processing doc formats
Other
29 stars 4 forks source link

chordprobook

What does this do? Formats song charts

This is a Python 3 script to convert collections of chordpro formatted song charts to PDF, HTML, epub, and word processing doc formats. You can convert a directory full of files to a single book, or a set of song-sheets. Uses Pandoc and wkhtmltopdf to do all the hard work.

NOTE: Unlike most chordpro software this does not display chords above the text (not yet anyway). Displaying chords inline is more compact. If it's good enough for Rob Weule and his Ukulele Club Songbook and for Richard G it's good enough for me.

Status

This is alpha code, until there are other people using it will continue to develop without branches and may make breaking changes. Let me know if you want a more stable release.

There are some (patchy) unit tests, I have been improving this with most of the changes I make.

Features

If you play with a group you can maintain a songbook for the group to play from, then create setlists which are ordered subsets of that book by typing abbreviated titles into a text file in markdown format, and generating a book from that. The setlists are added as pages you can put on the floor, like a real rock n roll band.

PDF

Word output (.docx / .odt)

HTML output

The HTML output is currently set up to create an A4 page per song (with optional multi-page songs using {new_page}). This HTML is used to generate a PDF, but it may be useful on its own.

Probably won't do

Audience

This is for people running a unix-like operating system who know how to install packaged software scripts and python modules.

Status: Alpha / mostly works for me on OS X 10.10.5.

Installation on OS X

Requires pandoc 1.15.0.6 or later and wkhtmltopdf installed on on your path.

NOTE: It is recommended that you use a Python 3 virtual environment.

Installation on other *nix platforms

Some installation notes courtesy of lpinner:

Just sharing some installation instructions that worked for me on Linux (and would possibly work on Win/MacOS as well)

  • Install conda (miniconda will do).
  • Create a conda environment, activate it and pip install chordprobook from github:

conda create -c conda-forge -n chordprobook python=3 pypandoc wkhtmltopdf pillow pyaml source activate chordprobook pip install git+https://github.com/ptsefton/chordprobook.git

Note: conda-forge channel is needed for wkhtmltopdf

The local dialect of Chordpro format

Chordpro format has no formal definition, and many different implementations. This implementation is designed to be relaxed and pragmatic about what it accepts.

Chordpro files are plain-text files with chords inline in square brackets, eg [C]. It uses formatting 'directives'.

Chords

Chords are anything in square brackets that starts with a capital C..G, followed by any mixture of lower case, slashes, and numbers. Eg:

[C] [Csus4] [C/B] [Cmaj7]

Note that when transposing, any capital A...G inside a chord will get transposed so don't write [CAug] use [Caug].

Some charts use ! and / inside chords to indicate a staccato chord or rhythm respectively. This works, and will be recognised for the purposes of transposing the song:

[C / / / ] [F / /] [C!]

Other formatting

Directives are lines beginning and ending with { and }, whitespae before and after the braces is ignored, but if there is text outside of them then the line is not treated as a directive.

None of the directives are case sensitive and they are all optional. Title, subtitle, key and transpose can be placed anywhere, but by convention are put at the top of the file.

Formatting / Directive Description Rendered as
{Title: \} {t: \} Song title A top-level heading
{Subtitle: \<Artist / songwriter name>} Subtitle, by convention this is the composer or artist An second-level heading
{key: \<A...G>} The key of the song Will be added to the title in brackets like (Key of G) if present.
{transpose: +1 +2 -2} A space seperated list of semitone deltas. In a song file, when called in single-song mode the software will automatically produce extra versions transposed as per the directive. In this case if the song is in C it would be transposed to C#, D and Bb. Can be used in a book file or a setlist file at the end of a line after a file-path or the title of the song, respectively.
{transpose: 0} In a book file, don't transpose the songs at all no change
{transpose: 1} In a book file, for each song use the first transposition specified using {transpose: } Song is transposed
{transpose: all} In a book file, add a song for the original key, and for each transposition specified using {transpose: } in the song Multiple songs in the book, in different keys, where they are specified
{C: Some comment} {Comment: Some comment} Notes on the song A third level heading
{instrument: } Name of an instrument you'd like to display chord grids for. Can occur multiple times in song or book files (not yet in setlists) A set of chord grids across the top of the song's first page, if the instrument is know to the software. chordpro.py --instruments will list the instruments known
{define: } In the context of an {instrument: } directove above will define fingering for a chord for that instrument. Uses the same conventions as over at uke-geeks except that here chords have to start with [A-G] Causes a chord grid (if chords are being rendered) to appear at the top of the song
{new+page}
{np}
New page A page break. When generating HTML and PDF the software will attempt to fill each page to the screen or paper size respectively as best it can.
{start_of_chorus} {soc} Start of chorus. Could be followed by some variant of {c: Chorus} Chorus is rendendered as an indendented block. TODO: make this configurable via stylesheets. In .docx format the chorus is rendered using Block Text style.
{start_of_bridge} {sob} Start of bridge. Usually followed by some variant of {c: Bridge} Same behaviour as chorus
{eoc} {end_of_chorus} End of chorus Everything between the {soc} and {eoc} is in an indented block
{eob} {end_of_bridge} End of bridge Same behviour as chorus
{sot} {start_of_tab} Start of tab (tablature) Rendered in a fixed width (monospace) font, as per the HTML \
 element. NOTE: Tabs that are acutal text-formatted representations of the fingerboard will not be transposed, although chords in square brackets will, so you can use tab-blocks to format intros or breaks where chords line up under each other
{eot} {end_of_tab} End of tab Finishes the fixed-width formatting
{book: path_to_book} For use in setlist files, a path to a book file relative to the setlist file or an absolute path
{files: } & {dirs: } A file-glob pattern to match, eg {files: *.cho} in a space separated list of directories For use in book files only, does a recursive search in the directories for files matching the pattern. If the song has a {transpose: } directive it will generate multiple pages, one for each transposition.
{version: } In book files. Put a version such as {version: v2.1}, and it will add v2.1 to the title and output filename. Or use {version: auto} for a time-stamped (to the millisecond!) version A suffix in the title and output file name

Implementation

This implementation will:

I am still undecided about:

Book files

A book file is a text file with a list of paths with and optional title (see samples/sample.book.txt).

To transpose the song, add a positive or negative integer at after the (partial) song name, separated by a space. eg: ./songs/my-song.cho {transpose: +2}

A book file may also have 'lazy' loading via directives on how to find song files.

Setlist files

The setlist consists of an optional {title: } directive, and optional {book: } directive followed by a list of songs, one per line. (see samples/sample.setlist.md).

If there is no {book: } directive then the setlist will be selected from the song files passed in as arguments: see the examples below.

Unlike book and song files, the setlist uses markdown format. Songs are second level headings starting with "##" and sets are first level headings. You can include any other (Pandoc) markdown markup you like. Identify songs by entering one or more words from the title, in order. So "## Amazing" will match "Amazing Grace" and "## Slot Baby" would match "Slot Machine Baby".

To transpose the song, add a positive or negative integer at after the path, separated by a space. eg: #My Song {transpose: +2}

usage

To see usage info, type:

mksong --help

And you'll see this:

Examples