Skip to content

GABC to Volpiano converter

License

Notifications You must be signed in to change notification settings

bacor/gabc2volpiano

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

41 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GABC2Volpiano

A Python package for converting GABC to Volpiano, two text-based formats for notating Gregorian chant.

The package expresses the GABC syntax as a parsing expression grammar (inspired by gabc-converter). The grammar can be found in gabc2volpiano/gabc.peg. We then use Arpeggio to parse GABC files and the resulting parse tree is then converted to a Volpiano string (the music) and a text string (the lyrics).

The gabc example files are copied from gabc-converter: "populus_sion.gabc is the canonical example in the gabc documentation, and the other examples are from gregobase."

Examples

Convert a GABC string:

>>> from gabc2volpiano import VolpianoConverter
>>> converter = VolpianoConverter()
>>> text, volpiano = converter.convert('(c3) He(f)llo(gf) world(ghgf)')
>>> text, volpiano
(' He-llo world', '1---h--jh---jkjh')

You can also convert complete file, to Volpiano JSON file: a simple JSON file describing an object with metadata, text and volpiano properties. For example, here's the gabc file kyrie.gabc:

name:Kyrie;
mode:1;
%%
(c4) KY(ixhi)ri(hg)e(hd..) *(,) e(fhGE'D)lé(c')i(d)son.(d.)

running

>>> converter.convert_file('kyrie.gabc', 'kyrie.json')

results in kyrie.json:

{
    "metadata": {
        "name": "Kyrie",
        "mode": "1"
    },
    "text": " KY-ri-e * e-l\u00e9-i-son.",
    "volpiano": "1---ihj--hg--hd---7---fhged--c--d--d"
}

You can also convert the contents of a gabc file, as follows:

>>> gabc = open('kyrie.gabc', 'r').read()
>>> header, text, volpiano = converter.convert_file_contents(gabc)
>>> header
{'name': 'Kyrie', 'mode': '1'}
>>> text, volpiano
(' KY-ri-e * e-lé-i-son.', '1---ihj--hg--hd---7---fhged--c--d--d')

Tests

The PEG grammar, parser and converter are all extensively tested. To run all tests:

$ python -m unittest discover tests/ "test_*.py" 

Dependencies