Skip to main content

generating musicxml

Project description

musicxml is a python library for reading and writing musicxml files.

musicxml is also a part of library: musicscore2. Feel free to check out: https://github.com/alexgorji/musicxml https://musicscore2.readthedocs.io

INSTALLATION

  1. Check the version of python on your computer: python --version. This library has been developed with python 3.9. Possibly you have to install this version (for example via Homebrew or whatever way you choose.)

  2. Make a new folder and create a virtual environment for your project and install musicxml via pip:

    • mkdir
    • cd
    • python3 -m venv venv
    • source venv/bin/activate
    • pip install --upgrade pip
    • pip install musicxml

The SOURCECODE can be found on Github: https://github.com/alexgorji/musicxml

Each musicxml element can be created as an instance of a class which behaves (hopefully exactly!) as the musicxml schema (version 4, see musicxml_4_0.xsd in musicxml.generate_classes) specifies, e.g.:

pitch = XMLPitch()

Children can be added with method add_child():

pitch.add_child(XMLStep('G'))

As a shortcut it is possible to add, remove or change child with a dot operator:

pitch.xml_step = 'G'

is equivalent to:

pitch.xml_step = XMLStep('G')

change:

pitch.xml_step = 'F'

or remove:

pitch.xml_step = None

Dot operator can also be used as a shortcut to get a child:

print(pitch.xml_step.value)

The value of an element (which be translated to text of xml element) can be set during or after creation:

octave = pitch.add_child(XMLOctave())
octave.value = 3

Attributes also can be added during or after creation:

font = XMLFont(font_family='Arial')
font.font_size = 17.2

A variety of errors are thrown during creating an object (for example if you try to add a child of a wrong type or to add a wrong attribute) . The method to_string() calls an intern final check before exporting the xml element to a string to be sure you didn't forget any required children and attributes.

An existing musicxml file can be parsed easily with parser's parse_musicxml(file_path) function.

Each element creates a rather complicated tree format container with xsd indicator objects (XSDSequence, XSDChoice, XSDGroup, XSDElement) which represent their counterparts in a xsd structure to validate and order its children (take a peek inside the file musicxml_4_0.xsd in musicxml.generate_classes to get a feeling for its complexity). If a child is going to be added to an element it tries to 'hook' this child inside a XSDElement leaf of this container tree which has the same name as the child. For elements which use a choice indicator (XSDChoice) it can happen, that the current chosen path throws an error since this particular path does not have a XSDElement leaf with child's name, or it could for example require another not existing child in the final check. It these cases the parent element tries to attach its children to another choice path and see if the problem can be solved. On this account although some thorough testings have been done, there is yet no guaranty that in some cases the library does not behave as it should. Please let me know if you discover a bug!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

musicxml-1.1.tar.gz (283.2 kB view details)

Uploaded Source

Built Distribution

musicxml-1.1-py3-none-any.whl (303.4 kB view details)

Uploaded Python 3

File details

Details for the file musicxml-1.1.tar.gz.

File metadata

  • Download URL: musicxml-1.1.tar.gz
  • Upload date:
  • Size: 283.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/33.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.8

File hashes

Hashes for musicxml-1.1.tar.gz
Algorithm Hash digest
SHA256 b6f9d9274777104bee81c6dd05fb5b1181753e886224e17774aeb23a9cd6ba6b
MD5 8f343a504cbcb6dccbd4f657557376d3
BLAKE2b-256 48cf0876cadfbeecda10484aa68348d7d1999d50276c647db26e0ec764953597

See more details on using hashes here.

Provenance

File details

Details for the file musicxml-1.1-py3-none-any.whl.

File metadata

  • Download URL: musicxml-1.1-py3-none-any.whl
  • Upload date:
  • Size: 303.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/33.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.8

File hashes

Hashes for musicxml-1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c471c90336af4f3cac5fe83eaa7675b7d01fda3901ebe0fc69c4257bde3c194d
MD5 0c0c98396e3a2e5a66cae8780724fd41
BLAKE2b-256 517680152adcf09b2325d936b4b7b38cfbae5ddedd1d8c3f16a818691390102a

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page