Skip to content

Repository for a python music parser. This works with MusicXML as the input format which forms a tree of objects in memory representing the piece. This can be optionally outputted to lilypond which produces a PDF, or perused for your own uses.

License

Godley/MuseParse

Repository files navigation

============ MuseParse: Music Parser ============ .. image:: https://travis-ci.org/Godley/MuseParse.svg?branch=master :target: https://travis-ci.org/Godley/MuseParse

Code Climate

Test Coverage

Issue Count

Repository for a python music parser. This works with MusicXML as the input format which forms a tree of objects in memory representing the piece. This can be optionally outputted to lilypond which produces a PDF, or perused for your own uses. All classes are intentionally loosely coupled, so if you would like to put in another input or output format as may come later, please do suggest them in issues and if you want, work on it yourself. For now, MusicXML is a fairly standard format.

Written for python 3 only, python 2.7 support may come later but I'm not intending on doing that unless everything else is done.

Tested against Mac OSX Yosemite, GNU / Linux Ubuntu 14.04 Desktop and Windows 8.1 64 bit.

Originally written as part of my Final Year Project(or dissertation project) at university. I earned 93 % on this along with an application of this section so you'd hope it was good.

Installation

The current version is on pypi, so to get it you can just run:

Otherwise clone this repo and run these commands from inside the main folder:

To use the lilypond rendering portion, you will need to install lilypond from http://lilypond.org.

Please note, Linux users, that whilst lilypond is on apt - get, this library expects the version to be 1.18, whilst currently apt - get only has 1.14, so I would advise downloading from the website rather than using apt - get. ============ Usage ============ ************** Setting up************** To aid the process of setting up lilypond, a helper is provided which does the environment variable set up so that you can run lilypond from commandline without modifying the variables yourself. The following code provides an example:

from MuseParse.classes.Output.helpers import setupLilypondClean as setupLilypond

import os

default_path_to_lily = 'path/to/lilypond/install/bin'

setupLilypond(default_path_to_lily)

os.system('lilypond')

Assuming you provided the right path, you should see the default help text coming into STDOUT after os.system is ran. Various assumed paths for different operating systems are provided on the lilypond install instructions page

Parsing music

You can parse music from an xml file using the following code:

from MuseParse.classes.Input import MxmlParser

parser = MxmlParser.MxmlParser()

object_hierarchy = parser.parse(filename)

This will return a hierarchy of objects - please view the docs(link below) for more information on the objects in this hierarchy.

Outputting to PDF

To send it to lilypond:

render_obj = LilypondOutput.LilypondRenderer(object_hierarchy, filename)

render_obj.run()

To provide the lilypond runner class with your own lilypond script(see http: // lilypond.org installation page for more information on this):

from MuseParse.classes.Output import LilypondOutput

render_obj = LilypondOutput.LilypondRenderer(
    object_hierarchy, filename, lyscript="path/to/script")

render_obj.run()

2 example scripts, 1 for OSX and 1 for Windows 8.1, are provided in MuseParse / demo / lilypond_scripts. If no script is provided it will assume to use the default for that platform. Linux users do not need to provide a script in any circumstance so long as lilypond is already installed.

Demo python scripts of things you could do with this are located in MuseParse / demo

======= Documentation ======= Please see MuseParse @ docs.charlottegodley.co.uk

for the documentation of each class in this library, and do let me know if it could be improved or submit a pull request.

About

Repository for a python music parser. This works with MusicXML as the input format which forms a tree of objects in memory representing the piece. This can be optionally outputted to lilypond which produces a PDF, or perused for your own uses.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages