Code Monkey home page Code Monkey logo

gabc2volpiano's Introduction

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

gabc2volpiano's People

Contributors

bacor avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.