Closed kemalkongar closed 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.
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).
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)
Very helpful, thank you.
We've pushed a draft version using ElementTree, I think this issue can be closed but up to you.
I think it can be closed too. Thank you for your work on it!
Of course!
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.