Obtaining Measure number while parsing through parts

15 views
Skip to first unread message

Taylor Akin

unread,
Feb 3, 2023, 4:59:54 PM2/3/23
to music21
Hello, I was hoping that someone could explain how I might go about recording measure number as I parse through a piece. To briefly explain what I'm doing, I'm grabbing each part and parsing through each element in the part.recurse(), as shown below:

for part in score:
     for element in part.recurse():
           record pitch, offset, etc.

I then add all of that to a dataframe, where each element is an entry in the database. What I've not been able to figure out is how to get the measure while I'm parsing through. I've thought about figuring it out with math, but that would depend on the entire piece being in the same time signature, and it must be in music21's model of the part somewhere I'm thinking, so do you guys have any suggestions?

Thank you in advance!

Best,
Taylor

Michael Scott Cuthbert

unread,
Feb 3, 2023, 5:23:25 PM2/3/23
to music...@googlegroups.com
element.measureNumber
there are other ways to do it too. Like .getContextByClass(stream.Measure) if there are no voices or score.contextInHierarchy(element, stream.Measure)

Best,
Michael

---
Sent from a phone (413-575-6024)
Apologies for typos or general brevity

On Feb 3, 2023, at 12:00, Taylor Akin <ta...@princeton.edu> wrote:

Hello, I was hoping that someone could explain how I might go about recording measure number as I parse through a piece. To briefly explain what I'm doing, I'm grabbing each part and parsing through each element in the part.recurse(), as shown below:
--
--
To Post: email music...@googlegroups.com
To Unsubscribe: email music21list...@googlegroups.com
Archives, Options, etc: http://groups.google.com/group/music21list

---
You received this message because you are subscribed to the Google Groups "music21" group.
To unsubscribe from this group and stop receiving emails from it, send an email to music21list...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/music21list/c82c8b40-6fcb-4fd2-8084-c4af5a58a954n%40googlegroups.com.

Taylor Akin

unread,
Feb 3, 2023, 5:33:23 PM2/3/23
to music21
I don't know how I never managed find that. Thank you!
Reply all
Reply to author
Forward
0 new messages