DDMAL / MEI2Volpiano

An MEI to Volpiano converter for CWMN or Neume MEI files.
MIT License
0 stars 0 forks source link

Location of clef info on line not set #2

Closed kemalkongar closed 3 years ago

kemalkongar commented 3 years ago

The clef info location as found with the current algo is not secure. It's possible that they will not occupy spots -1 and -2 respectively.

martha-thomae commented 3 years ago

Yes, that is possible.

If you use libmei (or another python library for parsing xml), you could do something like this to find the <staffDef> element and retrieve the clef-related attributes:

This is pymei (the python binding for libmei) code:

import pymei

staffDef_array = pymei.getElementsByName("staffDef")
staffDef1 = staffDef_array [0]
clef_shape = staffDef1.getAttribute("clef.shape")
clef_line = staffDef1.getAttribute("clef.line")

In this way you don't have to go line by line processing the file (you can go directly to an element) and you also don't have to depend on the position of the attributes within a particular element.

The last slide on my MEI and LibMEI presentation has some of the most useful methods to edit an MEI file using this library.

martha-thomae commented 3 years ago

For information on libmei and how to install the python bindings, you would need to cover these two sections of the wiki:

You could use other Python xml-parsing libraries instead of libmei. They will offer similar functionalities and might be way easier to install (unfortunatelly, although libmei was designed to process MEI, it is complicated to install).

martha-thomae commented 3 years ago

For a Python xml-parsing library you could use the ElementTree XML API

You have methods findall(), find(), and get() that behave similar to libmei in the sense that you can access specific elements and look for their attributes (see section on Finding interesting elements that uses the example from the beginning of the page)

kemalkongar commented 3 years ago

Very helpful, thank you.

kemalkongar commented 3 years ago

We've pushed a draft version using ElementTree, I think this issue can be closed but up to you.

martha-thomae commented 3 years ago

I think it can be closed too. Thank you for your work on it!

kemalkongar commented 3 years ago

Of course!