XQuery and MusicXML

Earlier today,  I posted about my first experience with XQuery. I'd mentioned that I wanted to get my feet wet before I started trying to run queries on MusicXML documents.

Well, I'm an incredibly impatient person.

I couldn't wait to take a couple of simple queries for a test run, especially after reading the following paper from the 2008 International Conference on Music Information Retrieval hosted by ISMIR, the International Society for Music Information Retrieval:

Using XQuery on MusicXML Databases for Musicological Analysis
Joachim Ganseman, Paul Scheunders and Wim D’haes

Now, I've known for a while the tests have been done using XQuery on MusicXML documents, but this paper was getting at something that's been on my mind for a long time now: the day we can have digital libraries of sheet music, not as image files, but as encoded documents, allowing musicians and the like to have the same online ability to query music in the way that users of prose and literary documents now take for granted.

Anyway, on to my first XQuery and MusicXML experience …

For testing, I used a very silly little ditty I wrote called "MusicXML: I Heart Thee".

Here are its various manifestations:

The first query demonstrated in the paper (see page 3) is one to count the total notes in a digital library, in this case the Wikifonia collection of MusicXML docs.

I couldn't get it to work as written even after I adjusted the query to work on my test document. This is likely due to my own ignorance, but in the end it was a good thing because it forced me to write my own, simpler queries.

I'm using the Saxon query processor as described in my earlier post.

1. This query (in red) counts all the notes in my piece:

<ul>
{
for $i in doc("i_heart_thee.xml")/score-partwise
let $j :=count($i/part/measure/note)
return $j
}
</ul>

A line-by-line translation:

  • Open an unordered list.
  • Open the query syntax with the "{" character.
  • Let there be a variable called "i" that will start at the root element, <score-partwise>, of the document "i_heart_thee.xml".
  • Let there be a variable, "j", that executes the Count function on "i" for the <note> element which is a child of <measure> and a grandchild of <part>.
  • Print the value of "j".
  • Close the query syntax with the "}" character.
  • Close the unordered list.

2. This query (in red) counts all the notes in the vocal part (there are 3 parts altogether: voice, guitar, bass):

<ul>
{
for $i in doc("i_heart_thee.xml")/score-partwise
let $j :=count($i/part[@id='P1']/measure/note)
return $j
}
</ul>

A line-by-line translation:

  • Open an unordered list.
  • Open the query syntax with the "{" character.
  • Let there be a variable called "i" that will start at the root element, <score-partwise>, of the document "i_heart_thee.xml".
  • Let there be a variable, "j", that executes the Count function on "i" for the <note> element which is a child of <measure> and a grandchild of <part>, where the "ID" attribute of <part> is = to "P1". This is the vocal part of the score.
  • Print the value of "j".
  • Close the query syntax with the "}" character.
  • Close the unordered list.

If you run the first query you get the result "137" as in 137 notes, including rests – even the hidden rests in measures 1,5, and 9 that exist because both voices in the guitar part have rests, though it only displays as one rest each time on the image version of the score.

If you run the second query, you get 43 notes including rests and the tied notes.

I'm sure there are ways to subtract rests and tied notes, but I have to start somewhere, right?

🙂

--------------

Related Content:

3 Comments

  1. Jody DeRidder

    Nitin, this is terrific!
    Yes, everyone must start somewhere. I don't think I've ever seen anyone document so clearly each part of a query for other beginners — this will be very helpful to others.

    You *rock*! Your inquisitive nature and passion for your work is inspiring.
    –jody

    Reply
  2. slm

    I'm glad you're starting somewhere and not nowhere 😀

    Good work!

    Do I remember you saying (or writing) something about knowing a conference covering musicIR that you might present some of your findings over time? (and meet like minded folks 😉 )

    Reply

Leave a Comment

Your email address will not be published. Required fields are marked *

*