transpose music xml

Introducing version 1.0.0. packed with transpose features… Along with some extra goodies.

We’re proud to introduce the new OSMD version – packed with Music XML transpose features! When we started our GitHub sponsorship, besides the initial goal of 50 sponsors, we set a 15 sponsor milestone goal. The milestone release is a plugin that enables sheet music developers to transpose sheet music by semitone. We decided to spice things up.

Current  Music XML Transpose Solutions

Transposition isn’t a big thing. Major sheet music editors like Musescore, Finale, Sibelius, etc., already enable transposing. The only “catch” is that current transposing solutions don’t offer live transposition. This means that you must edit the original Music XML, rather than doing it in the browser. OSMD is a browser renderer. We wanted to enable transposition without having to change the original MusicXML.

Transpose Features

Sheet music developers are now able to transpose a music sheet by any amount of semitones. The plugin transposes the notes up or down, as well as shifting any key signatures as needed. Now, you can change the sheet to any other key signature, or transpose by one or more octaves upwards or downwards.

Extra Features

The public release on the transposition plugin comes in the 1.0.0 release of OSMD! We’ve packed a lot into the follow-up of the previous OSMD version. Other than the transpose plugin and a lot of bug fixes (see the changelog), we also added a few new features as well:
  • Accidentals: Add support for three-quarter flats and sharps
  • Options: Add osmd.rules.FingeringPositionFromXML (#993)
  • Cursors: New options like highlighting the current measure, color and alpha value enable you to add several cursors.

The Build

Getting the plugin into Open Sheet Music Display public was pretty straightforward. Most of the development work was already done in our sponsor-exclusive repository. We had to make some minor tweaks and include the file into the original OSMD repo. This is pretty much the same thing as the sponsor audio transposition plugin but without the audio playback. Once we hit our 50 sponsors goal, that playback piece will go public as well!

The Code

The final TransposeCalculator class is only around 80 lines of code. A lot of thought has gone into its intricate algorithm. After many considerations, it ended up very concise. We had to consider many scenarios when devising a transposition algorithm:
  • new key signature after transposing
  • correct accidentals
  • octave overflows and underflows
As the transposing methods are being used by several classes within OSMD, the integration had to be precise. There are similar music XML transposing solutions with hundreds of lines of code, accomplishing the same thing

Install and Apply

The plugin in the OSMD repo. Find the installation details here.

Transposing Music XML

You can transpose only by semitone, for example, you can’t specify the key you want to transpose to. You’ll need to calculate the semitone difference and do it that way.  Features like “transposition to key” or “transpose by interval” aren’t available yet. Our community members expressed interest in implementing them, so they may come in the future!

Where does this leave OSMD?

We’re very satisfied with the current state of OSMD. There are only a handful of features missing to round up a full package for doing everything with MusicXML. We’re already looking at expanded feature sets and quality of life improvements like faster rendering. There’s always more room for improvement, so we’ll keep an eye on the future and consider our users’ needs. OSMD is also available as a free WordPress plugin, new features and releases are on the way. Get in the discussion or share with us your feedback over on our Discord channel.

Leave a Comment

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

Scroll to Top