A simple tool to convert chords from text to musicxml. Musicxml files can be opened with most notation software (for example MuseScore, which is free and open source).
use pipx
pipx install txt2musicxml
pipe a string of chords into the cli
echo -n 'Cmaj7 A7 | Dm9 G7b9,13 |' | txt2musicxml
or redirect input/output from/to a file
txt2musicxml < path/to/Thriller.crd > path/to/Thriller.musicxml
Aguas de Marco - Elis Regina & Tom Jobim
---
Bb/Ab | % |
Bb/Ab | Gm6 Cm7b5/Gb |
Bbmaj7/F E9b5 | Ebmaj9 Ab9 |
Bbmaj7 Bb7 | C7/E Ebm6 |
Bbmaj7/F Bb7 | C7/E Ebm6 :||
- More info in SYNTAX.md
- More examples: ./examples/
Install MuseScore and make sure to add mscore
to your PATH. Tested with v4. %
doesn't work in v3, otherwise works fine.
TMPSUFFIX=.musicxml; mscore -o path/to/output.pdf =(txt2musicxml < path/to/input.crd)
Since the CLI is fully pipe-able, you can use cURL to pipe any text file hosted on the web, as long as it adheres to the syntax. Example:
curl https://raw.githubusercontent.com/noamtamir/chords/refs/heads/main/I%20heard%20it%20through%20the%20grapvine%20-%20ccr.crd | txt2musicxml
In order to change the grammer and regenerate lexer/parser/etc:
For other development:
- python ^3.9
- I suggest using pyenv to manage multiple python versions on your machine
- poetry - to manage virtual env
- Make - to help run useful commands
Grammer is defined in txt2musicxml/grammer/Chords.g4
and txt2musicxml/grammer/FrontMatter.g4
.
To generate antlr python classes (Lexer, Parser, Visitor, Listener) from the grammer file, run:
antlr4 -Dlanguage=Python3 txt2musicxml/grammer/Chords.g4 -visitor
antlr4 -Dlanguage=Python3 txt2musicxml/grammer/FrontMatter.g4 -visitor
Those classes are direct dependencies of the application, they must exist for the main program to run.
To use the built-in antlr GUI and debug your grammer, first compile those java classes, and then run the gui:
javac txt2musicxml/grammer/.antlr/Chords*.java
javac txt2musicxml/grammer/.antlr/FrontMatter*.java
cd txt2musicxml/grammer/.antlr && grun Chords sheet -gui
# or: cd txt2musicxml/grammer/.antlr && grun FrontMatter front_matter -gui
Then enter some text and hit ^D
(on mac) to indicate EOF, and see the parse tree get generated!
NOTE:
Chords
andsheet
are names unique to the program (grammer name, root element), if you change the grammer file, the commands you run should change as well.