figured bass extension

102 views
Skip to first unread message

Moritz Heffter

unread,
Aug 6, 2022, 8:42:58 AM8/6/22
to music21
Good Afternoon from Europe,

I'm new to the list and using music21 to design tools for my music theory classes and to analyse mainly older music from the baroque era. With my students I work mainly in combination with MuseScore.

One thing that I was looking for in music21 is an even better access to figured bass notations in scores and I wanted to share some thoughts on how this could be done:

What I did so far, was adding a new subclass of the note/rest object, that can store information on figures directly, even multiple figures for one note object. I also added functions to parse and export musicxml figured-bass tags to and from the new note/rest object. With the upcoming MuseScore 4 several bugs of the xml import and export will be solved and thats a great chance.

Here is a short overview of the extensions:
  • Added FiguredBassNote to figuredBass.notation module
  • Added Parser function that handles fb-tag to musicxml.xmlToM21
  • Added Export function that creates musicxml fb-tag to musicxml.m21ToXml
In my basic tests this is working quite well so far. I attach a screenshot from my notebook. If anyone has similiar usecases or ideas on how to deal with figured bass information, it would be great to hear from you.
One question could be, whether it might be a better design option to e.g. separate the figured bass information to an extra part or voice. Lilypond is doing that this way.

If you want to take a look at the current state you can see it at my fork here in branch figuredBass-extended-support:


Best from Freiburg, Germany
Moritz

Bildschirmfoto 2022-08-06 um 14.42.14.png

Tristan Repolusk

unread,
Sep 18, 2022, 11:44:43 AM9/18/22
to music21
Hello Moritz,

I've also just joined the list due to the post you have made.

One question, I have tried to import MusicXML with the <figured-bass> tag, but it seems that the figured bass numbers did not have any effect on the piece imported to music21. Additionally, when importing the basso continuo examples under https://web.mit.edu/music21/doc/usersGuide/usersGuide_41_figuredBass.html , the figured bass is internally stored as lyrics. Do I understand correctly that your solution tackles this problem?

I have tried out the code from your repository with both a MusicXML containing figured bass from MuseScore, as well as your provided file test3.musicxml, but it doesn't show the figures as it does in your screenshot, neither does it have the attribute `figures`.

The code I've tried:
```
from music21figuredBass.music21 import *
s = converter.parse(r'music21figuredBass/test3.musicxml')
s.show()
for n in s.flat.notesAndRests:
    print(n.figures) # Also, this gives an AttributeError
```

Actually, I do not know what the requirements for active participation in music21 are, but after updating the repo to only contain changes associated with the figured bass feature and making sure it works out of the box, have you already considered to make a pull request at https://github.com/cuthbertLab/music21 ?

Greetings from Austria,
Tristan

Moritz Heffter

unread,
Sep 18, 2022, 1:48:00 PM9/18/22
to music21
Hi Tristan,

thanks for your answer. Yes, my aim was to be able to use an extra object for the figures. The solution to use lyrics has its limits when dealing with figures. So yes, you're right my proposal addresses this open issue. I thought about making a pull request, but wanted to post it here, to get some feedback.

I'm curious why your code isn't working, because when I run it here, your code works in my installation. Could you send me your testfile? And, have you tried the figuredBass-extended-support branch?

Will yu be at the GMTH Conference in Salzburg at the end of the month?
Best,
Moritz

Moritz Heffter

unread,
Feb 21, 2023, 7:03:46 PM2/21/23
to music21
Dear all,

I'm coming back to the figured bass support in music21. I have tried some options and I think they need discussion. Just two basic options:

(1) My first approach was to add a figured bass object to a note.
  • Pro: Direct connection to a pitch object and a duration
  • Con: There are e.g. repeated notes where the fgures usually aren't repeated but still are valid.
(2) Treat figured bass information as a separate layer or track in the score like it is done in many other encodings like lilypond or musicxml/MEI.
  • Pro: There is an independent track for the harmonic information which easily could be connected to the other parts of the score via its offset.
  • Con: music21 has, so far as I know, no really good „container“ object for this. I'm think of some stream.Part() „light“ object.
I am currently working on an implemention of the <harm> tag for the mei2m21 parser trying the second option. It works quite well. The first Option I was trying last summer doesn't seem too flexible to me.

If someone likes to give some feedback or is (still) also interested in this, I happy to hear from you.


Best,
Moritz

Michael Scott Cuthbert

unread,
Feb 22, 2023, 2:17:17 AM2/22/23
to music...@googlegroups.com
I think that attaching to notes has easy first results but quickly breaks down once you have a 7-6 suspension over a held bass note. 

So independent figure objects (with perhaps a reference to the bass note being considered) is almost certainly better. Look more closely at the stream model, for instance how ChordSymbol and RomanNumeral objects are represented and I think this will work well within the current representation.  There’s no need for a separate “track” (a concept foreign to music21). Insert them in a stream where they should go and they’ll be perfectly represented. 

Outputting to a commonly used notation format—that’s the challenge and why they’re not a standard m21 feature yet. Though Jose Cabal-Ugaz’s music21.figuredBass directly went a long way to making it a reality. 

Best,
Michael

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

On Feb 21, 2023, at 19:04, Moritz Heffter <mxo...@gmail.com> wrote:


--
--
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/af19b3de-bdfd-4f44-a9da-785cc961a5f0n%40googlegroups.com.

Moritz Heffter

unread,
Mar 2, 2023, 6:57:37 PM3/2/23
to music21
Dear Michael,

thank for your reply and sorry for not answering sooner. Meanwhile I was working on a representation in a score/stream and extended the mei parser and also the musicxml exporter.

What I could achieve so far is
  • a fairily good import of MEI,
  • a representation of a MEI <harm> tag in a M21 score based on the figuredBass.notation.Notation classes
  • and an export to Musicxml that works well with MuseScore 3 and 4. The xml is better than the Musescore 3 export, that had some problems with divisions.
 It works locally here quite well and I think I can use it for my next studies. I'd like to discuss further improvements and might create a pull request these days, after finishing and cleaning up a bit.

Best,
Moritz

Michael Scott Cuthbert

unread,
Mar 2, 2023, 8:37:30 PM3/2/23
to music21list
Hi Moritz (and to everyone on the list),

I think the best strategy for adding a major new feature to music21 is to first release it as a standalone library (hopefully one compatible w/ music21’s BSD license) that requires music21, and then once it’s been well tested and integrating well, to propose it as an addition to music21.

Over the past two decades, the Python standard library has moved more in this direction.  When I first used Python they were putting in just about anything that was useful (sunau, etc.) because “pip” wasn’t really there yet.  Now, they’re very cautious on what they add, because it’s easier for stakeholders to maintain and improve their own systems more rapidly if it’s not integrated into the core.

Some recent libraries based on or using music21 have been able to thrive by not being integrated in the (now lumbering) beast that is music21 (or any widely-used, large, middle-aged system), while some packages integrated in music21 early on (contour.py, sieve.py) have languished instead.

Best,
Myke



Moritz Heffter

unread,
Mar 4, 2023, 3:26:19 PM3/4/23
to music21
Hi Michael,

I was building a package for pip with my changes today. (I've never done this before and I was surprised how well it went.) It works for now but isn't published yet.

Nonetheless, I was wondering if this is a good option. My workflow before was based on the classical strategy of forking and merging changes back.
The changes in this case e.g. affect sometimes only single lines within the MEI parser and the m21ToXml Converter, which makes it hard to separate code in a clean way. To me an external module seems not very streamlined anymore.

You can see the changes I made on my fork on GitHub (https://github.com/cuthbertLab/music21/compare/master...mxordn:music21:mei-import-fb-support). I think the biggest new feature was adding a class in harmony.py called FiguredBassIndication. This class represents the figured bass elements in a score using the figuredBass.notation classes. The MEI and Musicxml parser create objects from this class.

On my TODO list there is one item left. It would be nice to add also an import routine for figures from musicxml files coming from MuseScore3.

After thinking it through I would prefer creating a pull request rather than making it seperatly available. For another project I'm currently working on and that is related to the figured bass import, I think the separate module is a good strategy.

Sorry for the long post…

Best,
Moritz
Message has been deleted

Moritz Heffter

unread,
Mar 6, 2023, 8:09:17 PM3/6/23
to music21
Short update:
  1. I fixed an issue with exporting musicxml with more than two figures over a single note.
  2. Musicxml import works now and is usable beside the MEI Import.
You'll find the latest version on this branch: https://github.com/mxordn/music21/tree/musicxml-fb-import

Best and good night from here,
Moritz

Moritz Heffter

unread,
Mar 22, 2023, 4:10:42 PM3/22/23
to music21
Hi everybody,

Again a short update:
I fixed some issues with prefixes and empty number tags and merged my changes into the master branch of my fork: https://github.com/mxordn/music21

Importing figured bass elements from MEI and musicxml files works as well as exporting M21 FiguredBassIndications to musixml. Even some complex figured bass writings like in Bach's Sonatas BWV 1021 and 1023 were ok. It works so far for me for the moment.

I'm preparing a pull request. Doing a separate package is complicated, because there are a lot of changes within the parsers and its difficult to separate the new functions in a clear way. Maybe you can test the new features and see what has changed finally.

Best,
Moritz
Reply all
Reply to author
Forward
0 new messages