nCoda Lychee Docs

MEI and Verovio

Unfortunately, the XML parser included in Verovio is not fully compliant with XML. If you are exporting a Lychee-MEI document for use with Verovio, please use the Verovio-specific converter.

MEI

Convert a Lychee-MEI document to a standard MEI document.

Danger

This module is not fully implemented yet.

Warning

This module is intended for internal Lychee use only, so the API may change without notice. If you wish to use this module outside Lychee, please contact us to discuss the best way.

Tip

We recommend that you use the converters indirectly. Refer to How to Use the Converters for more information.

Note

This is an outbound converter that does not emit signals directly. Refer to the lychee.signals.outbound module for more information.

lychee.converters.outbound.mei.convert(document, **kwargs)[source]

Convert a Lychee-MEI document into an MEI document.

Parameters:document (xml.etree.ElementTree.Element or xml.etree.ElementTree.ElementTree) – The Lychee-MEI document.
Returns:The corresponding MEI document.
Return type:xml.etree.ElementTree.Element or xml.etree.ElementTree.ElementTree
Raises:lychee.exceptions.OutboundConversionError when there is a forseeable error.
lychee.converters.outbound.mei.convert_raw(document)[source]

Convert a Lychee-MEI document into an MEI document without verifying that it is an MEI section.

lychee.converters.outbound.mei.create_measures(lmei_section)[source]

Convert a Lychee-MEI <section> without <measure> elements into an MEI section by adding <measure> elements at the expected place in the standard MEI hierarchy.

Parameters:lmei_section (xml.etree.ElementTree.Element) – The <section> to convert.
Returns:A converted <section>.
Return type:xml.etree.ElementTree.Element

Note

During conversion, the LMEI <section> is not modified.

Known Limitations

  • Does not process tuplets.
  • Uses one meter signature for all staves.
  • Uses one meter signature for the whole <section> (cannot change).
  • Assumes 4/4 meter unless indicated otherwise with @meter.count and @meter.unit on the first <staffDef>.
lychee.converters.outbound.mei.rewrite_beam_spans(m_section)[source]

Modify the given section to replace <beamSpan> with <beam>, because Verovio doesn’t support <beamSpan>.

The element passed in does not actually need to be a section. It can be any parent of the elements we’re interested in.

lychee.converters.outbound.mei.wrap_section_element(section)[source]

Wrap a <section> element in <score>, <mdiv>, <body>, <music>, and <mei> so that it can stand as an independent document.

Parameters:section (xml.etree.ElementTree.Element) – The <section> eleemnt to wrap.
Returns:The corresponding <mei> element.
Return type:xml.etree.ElementTree.Element

Verovio

Convert a Lychee-MEI document to a standard MEI document that Verovio will accept.

Danger

This module is not fully implemented yet.

Warning

This module is intended for internal Lychee use only, so the API may change without notice. If you wish to use this module outside Lychee, please contact us to discuss the best way.

Tip

We recommend that you use the converters indirectly. Refer to How to Use the Converters for more information.

This module runs the same conversions as lmei_to_mei, and makes the following two changes:

  1. Convert the document to a string with an XML declaration that uses double quotes. Note that, although the XML declaration is not strictly required, and although it may use single quote marks around the attribute values, Verovio will not accept such a document.
  2. Remove the “mei:” namespace from all tag names. In proper XML, such tag namespaces may be omitted in some situations, but Verovio again will not attempt to parse an MEI document where this is not the situation.

These limitations in Verovio likely arise from the “pugixml” library. They are trivial enough, and do not require breaking conformance with XML, so we’ll just work with what we have.

Note

This is an outbound converter that does not emit signals directly. Refer to the lychee.signals.outbound module for more information.

lychee.converters.outbound.verovio.convert(document, **kwargs)[source]

Convert a Lychee-MEI document into a Verovio-compliant MEI document.

Parameters:document (xml.etree.ElementTree.Element or xml.etree.ElementTree.ElementTree) – The Lychee-MEI document.
Returns:The corresponding Verovio-compliant MEI document.
Return type:unicode
Raises:lychee.exceptions.OutboundConversionError when there is a forseeable error.
lychee.converters.outbound.verovio.export_for_verovio(document)[source]

Run the LMEI-to-MEI conversion, then export to a string with XML declaration, and remove the “mei:” namespacing in all the tags.

Parameters:document (xml.etree.ElementTree.Element) – The LMEI document to convert to a Verovio-compliant XML string.
Returns:A string for Verovio.
Return type:unicode